From patchwork Mon Dec 27 10:29:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ohad Ben Cohen X-Patchwork-Id: 433821 X-Patchwork-Delegate: omar.ramirez@ti.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBRKCV7c025997 for ; Mon, 27 Dec 2010 20:15:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753452Ab0L0KaH (ORCPT ); Mon, 27 Dec 2010 05:30:07 -0500 Received: from mail-iw0-f174.google.com ([209.85.214.174]:46505 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753043Ab0L0KaG (ORCPT ); Mon, 27 Dec 2010 05:30:06 -0500 Received: by iwn9 with SMTP id 9so8487551iwn.19 for ; Mon, 27 Dec 2010 02:30:05 -0800 (PST) Received: by 10.231.34.205 with SMTP id m13mr11835767ibd.184.1293445805088; Mon, 27 Dec 2010 02:30:05 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.117.230 with HTTP; Mon, 27 Dec 2010 02:29:44 -0800 (PST) X-Originating-IP: [93.172.188.89] In-Reply-To: References: <1292870624-25450-1-git-send-email-felipe.contreras@nokia.com> From: Ohad Ben-Cohen Date: Mon, 27 Dec 2010 12:29:44 +0200 Message-ID: Subject: Re: [PATCH v2] staging: tidspbridge: protect dmm_map properly To: Felipe Contreras Cc: Felipe Contreras , linux-main , linux-omap , Greg KH , Omar Ramirez Luna , Fernando Guzman Lugo , Nishanth Menon , Ameya Palande , Hari Kanigeri Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 27 Dec 2010 20:15:02 +0000 (UTC) diff --git a/drivers/staging/tidspbridge/include/dspbridge/drv.h b/drivers/staging/tidspbridge/include/dspbridge/drv.h index c1f363e..cad0626 100644 --- a/drivers/staging/tidspbridge/include/dspbridge/drv.h +++ b/drivers/staging/tidspbridge/include/dspbridge/drv.h @@ -25,6 +25,7 @@ #include #include +#include #define DRV_ASSIGN 1 #define DRV_RELEASE 0 @@ -106,6 +107,7 @@ struct dmm_map_object { u32 num_usr_pgs; struct page **pages; struct bridge_dma_map_info dma_info; + atomic_t refcnt; }; /* Used for DMM reserved memory accounting */ diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c index b47d7aa..d060692 100644 --- a/drivers/staging/tidspbridge/rmgr/proc.c +++ b/drivers/staging/tidspbridge/rmgr/proc.c @@ -112,9 +112,37 @@ static s32 get_envp_count(char **envp); static char **prepend_envp(char **new_envp, char **envp, s32 envp_elems, s32 cnew_envp, char *sz_var); +/* Increase map_obj's reference count */ +static inline void map_obj_get(struct dmm_map_object *map_obj) +{ + atomic_inc(&map_obj->refcnt); +} + +/* Decrease map_obj's reference count */ +static inline void map_obj_put(struct dmm_map_object *map_obj) +{ + atomic_dec(&map_obj->refcnt); +} + +/** + * is_map_obj_used() - check out whether a given map_obj is still being used + * @map_obj: a dmm map object + * + * Returns 'true' if a given map_obj is being used, or 'false' otherwise. + * + * This function must be used while the dmm map list spinlock is taken, + * otherwise it is not safe to use its answer (if the list is not locked, + * someone can find and start using a map_obj immediately after this functions + * replys 'false'. + */ +static inline bool is_map_obj_used(struct dmm_map_object *map_obj) +{ + return atomic_read(&map_obj->refcnt) ? true : false; +} + /* remember mapping information */ -static struct dmm_map_object *add_mapping_info(struct process_context *pr_ctxt, - u32 mpu_addr, u32 dsp_addr, u32 size) +static struct dmm_map_object *create_mapping_info(u32 mpu_addr, u32 dsp_addr, + u32 size) { struct dmm_map_object *map_obj; @@ -144,11 +172,15 @@ static struct dmm_map_object *add_mapping_info(struct process_context *pr_ctxt, map_obj->size = size; map_obj->num_usr_pgs = num_usr_pgs; + return map_obj; +} + +static void add_mapping_info(struct process_context *pr_ctxt, + struct dmm_map_object *map_obj) +{ spin_lock(&pr_ctxt->dmm_map_lock); list_add(&map_obj->link, &pr_ctxt->dmm_map_list); spin_unlock(&pr_ctxt->dmm_map_lock); - - return map_obj; }