From patchwork Thu Aug 29 09:29:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 172548 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp2072006ocp; Thu, 29 Aug 2019 02:29:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwa0VbigdJtj5beDyPaVrOpxU6O4TZ7jVCI63BfY1eGW6BfD8o22kTIF2i8mZHdjVIH1tS2 X-Received: by 2002:a17:902:e407:: with SMTP id ci7mr8991494plb.326.1567070982426; Thu, 29 Aug 2019 02:29:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567070982; cv=none; d=google.com; s=arc-20160816; b=QlmQsD/ge8jRaoS7RfUtZ6MA8dVP73pAE0lnShhkxbastRKmkHItngVPguq4NdqnZi K7OpYhm9YlD7uBdsoVurwSc7sc3Teky/OSyLGrTH/7DcfhD5/oVGAgdif6I4Yd643b69 OytsI9Qo8T+VmCAKF5GCO5mzbUMOYamM8X4xNLGRmV1RSviGxdi7nX7l//ogTFcfUW6i OkCSq4r1Wb8zPomNr1ldVqHcPwsLbSU26q9SppcyfYTjrru+5N3gZ1A/L+sPWJgg367u bwc2Ifs38uiDtlIcK3vkFPi+Ff///zM+TsYxOAxFB67fJWyqLqSn8BOBYL1NAU3QMsCV rlcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XU8VavFbVq1P6J4BGT7bqqCvGA+gvD1YtYfU7w8Ui4Y=; b=eZlUouAdbm7ER1BEnhQn7/XbFAwu/PzOHVtdNRYggXQO57TedOEB56PFmLI3TDoX1y rlp9Tvaj/c3gjFThd/6z1H+XZwoZBehb7yUxK/yURWMNLRv3ejPlnQ3wWT3hVQ5TjZ1R nacWWYb479DHUtu/W78kc7ic4vlyFwgdmrRNWjb/icw7RUh1mIHMEg5TRcLGGGJyhD0v gGh5NU3awvY0kUS/tLkr1CQtKEgEWbhLkeF8M0jig4JceXMrceGRUItp4U/SJro9r4VG C6ulKlw8VRE2vu4qq+VnT4MTXv3hIJolOjjU68Zb3o3vzQw0RVjahEI5NV9cQHaZc/uA bY4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y2Jad9If; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11si1741557pjv.95.2019.08.29.02.29.42; Thu, 29 Aug 2019 02:29:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y2Jad9If; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727122AbfH2J3l (ORCPT + 28 others); Thu, 29 Aug 2019 05:29:41 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39624 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbfH2J3i (ORCPT ); Thu, 29 Aug 2019 05:29:38 -0400 Received: by mail-wm1-f68.google.com with SMTP id n2so1667846wmk.4 for ; Thu, 29 Aug 2019 02:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XU8VavFbVq1P6J4BGT7bqqCvGA+gvD1YtYfU7w8Ui4Y=; b=y2Jad9If07L8NkCkwNdv8YZMdg76iweYq5gnyqU7ZDpAiemuWRrJjbuu5BLDeQUdNp ZPFbRWLdHenEAhkH9KAB4roQxHkuuhxayo9pCXmARueqQY7W1aLx41028c5b967Ih7H2 AbB11KjZHaaeJ4xTfjIhr3tFxpGTl4v6E0DJNc7N11Zf/8b7w1SXYelXiZ3nK7FdyqBm uCJjAeeobnr9UxrtXj7GJYMLGbG/Z6f40SIjgckg7xwUL9jFsAA4qGd2YKOskcCD//AG R3LIqRDSknSJvQGfk5Z3TL7kUjgA4D7Fw/ZYMH/+pN4KfAZCucq8iLiaSUFlWGf/Z/14 Q4eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XU8VavFbVq1P6J4BGT7bqqCvGA+gvD1YtYfU7w8Ui4Y=; b=dVgtd2TMGPMP5bwrYaFLARrmvvWfgE9mCBQlAgpMpqO0q2/BzqaDV/QFSJEemg0042 T3AWntOTxNaf2K0hbFO/HuLWcXHsdvMzAW1sl5mYtLz6J/AIl22Z84ik1WxcjfObyUYL 7J1BlIL8R9Z+rkTBTI/FN5dFt2tu//iKQp/p6wEzJ1tfkCRMHGTrJZj95GOJElJ3oYuS MSqH5BTb21WkshqPTOu7IrhG/FJ0rTWjsK5CyIZWdoB+sCCgjZPBHBNCvHj4YmlSXntu 04BMG3ZVy+4bG5i6Ap6Mr2eBrVUHr9TxViGkOa+cwiMr4o1HD77B//3Wd8lnfec7M4jk wW5A== X-Gm-Message-State: APjAAAVvFhL6O5UrEWoklXkX4j/WqMvS8AgbX4Ui7LgERB6c0sBfWfR/ HfoQ4qQTLJYb9iji3EEDR5ROfA== X-Received: by 2002:a1c:658a:: with SMTP id z132mr10210355wmb.98.1567070975588; Thu, 29 Aug 2019 02:29:35 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id f197sm3609512wme.22.2019.08.29.02.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 02:29:35 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Mayank Chopra , Abhinav Asati , Vamsi Singamsetty , Srinivas Kandagatla Subject: [PATCH v2 1/5] misc: fastrpc: Reference count channel context Date: Thu, 29 Aug 2019 10:29:22 +0100 Message-Id: <20190829092926.12037-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> References: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bjorn Andersson The channel context is referenced from the fastrpc user and might as user space holds the file descriptor open outlive the fastrpc device, which is removed when the remote processor is shutting down. Reference count the channel context in order to retain this object until all references has been relinquished. Signed-off-by: Bjorn Andersson Signed-off-by: Mayank Chopra Signed-off-by: Abhinav Asati Signed-off-by: Vamsi Singamsetty Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 43 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) -- 2.21.0 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index c790585da14c..c019e867e7fa 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -186,6 +186,7 @@ struct fastrpc_channel_ctx { struct idr ctx_idr; struct list_head users; struct miscdevice miscdev; + struct kref refcount; }; struct fastrpc_user { @@ -293,6 +294,25 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, return 0; } +static void fastrpc_channel_ctx_free(struct kref *ref) +{ + struct fastrpc_channel_ctx *cctx; + + cctx = container_of(ref, struct fastrpc_channel_ctx, refcount); + + kfree(cctx); +} + +static void fastrpc_channel_ctx_get(struct fastrpc_channel_ctx *cctx) +{ + kref_get(&cctx->refcount); +} + +static void fastrpc_channel_ctx_put(struct fastrpc_channel_ctx *cctx) +{ + kref_put(&cctx->refcount, fastrpc_channel_ctx_free); +} + static void fastrpc_context_free(struct kref *ref) { struct fastrpc_invoke_ctx *ctx; @@ -316,6 +336,8 @@ static void fastrpc_context_free(struct kref *ref) kfree(ctx->maps); kfree(ctx->olaps); kfree(ctx); + + fastrpc_channel_ctx_put(cctx); } static void fastrpc_context_get(struct fastrpc_invoke_ctx *ctx) @@ -422,6 +444,9 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( fastrpc_get_buff_overlaps(ctx); } + /* Released in fastrpc_context_put() */ + fastrpc_channel_ctx_get(cctx); + ctx->sc = sc; ctx->retval = -1; ctx->pid = current->pid; @@ -451,6 +476,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( spin_lock(&user->lock); list_del(&ctx->node); spin_unlock(&user->lock); + fastrpc_channel_ctx_put(cctx); kfree(ctx->maps); kfree(ctx->olaps); kfree(ctx); @@ -1123,6 +1149,7 @@ static int fastrpc_device_release(struct inode *inode, struct file *file) } fastrpc_session_free(cctx, fl->sctx); + fastrpc_channel_ctx_put(cctx); mutex_destroy(&fl->mutex); kfree(fl); @@ -1141,6 +1168,9 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) if (!fl) return -ENOMEM; + /* Released in fastrpc_device_release() */ + fastrpc_channel_ctx_get(cctx); + filp->private_data = fl; spin_lock_init(&fl->lock); mutex_init(&fl->mutex); @@ -1398,10 +1428,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) int i, err, domain_id = -1; const char *domain; - data = devm_kzalloc(rdev, sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; - err = of_property_read_string(rdev->of_node, "label", &domain); if (err) { dev_info(rdev, "FastRPC Domain not specified in DT\n"); @@ -1420,6 +1446,10 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) return -EINVAL; } + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + data->miscdev.minor = MISC_DYNAMIC_MINOR; data->miscdev.name = kasprintf(GFP_KERNEL, "fastrpc-%s", domains[domain_id]); @@ -1428,6 +1458,8 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) if (err) return err; + kref_init(&data->refcount); + dev_set_drvdata(&rpdev->dev, data); dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32)); INIT_LIST_HEAD(&data->users); @@ -1462,7 +1494,8 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) misc_deregister(&cctx->miscdev); of_platform_depopulate(&rpdev->dev); - kfree(cctx); + + fastrpc_channel_ctx_put(cctx); } static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, From patchwork Thu Aug 29 09:29:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 172549 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp2072147ocp; Thu, 29 Aug 2019 02:29:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdBKzUGGLu7obcTg7eNCQGz+s9+gEpC1qbRdOqBgWmIGSWLrZ2oWBttuNcqL+zgsSylKx3 X-Received: by 2002:a17:902:5a09:: with SMTP id q9mr8779468pli.191.1567070989182; Thu, 29 Aug 2019 02:29:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567070989; cv=none; d=google.com; s=arc-20160816; b=Rc0+85xBV9I3dOO3DnVFbV5+5qQplgMrpls5U57V5j0qjY7INemECZ4uRu9y5a97ts b05PuIu74SFj9X1UTdFuAMUfLufVOHJ/67eJrs9n8n/0KXcDH2BCO8KKp1JkHYZScusw NVZMSMLAbkMOO5fGaVj+ktKmlpQ53kOpw6RpKrat15Vw3BgwmYDnaCHqEcAyjQOTcg+1 SxzG4i0uoY/jS0VrS6egBM9Lf0x8kgeWV6hnzaz1rcWj8oJSaOBc5fLn9NN86jsE7PvZ q0skIZRE9VnmChtPhu5IoA5ZwuehwmK/x+jSAyKDlWOuDBOSJRpIP/gt6slV3CFMKJZy XRAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v2Fx0Pb0mc0UlpujkGqHHioGa7pg7ML7uA9l5iVY0Do=; b=SiGN+oHjYBr90qKfjsSFU7msizLjdReKdphQNktlcV0NKDD34/8tNEA2MnsBBFSlR4 Sg3GV62zGJDAyLSgG0qQxJ4Llh5pNfT10jA7hTtjOufz9K7TlvMqHzAKAwRScwLw/3bB hpI9kiaDDKm0fPnLIOoi+IPanukeFo20/9joS/jGtD9YopzUdbfCWdudFwwHoxKy56e7 TlkxycLNdDl6THAaiOGjrkr6ZnKNosyq0fsyM/4QXoGJsH2Rh1deQU/rx3tL4LpeUMpq bSXc8NOw75z5+/t5gNga4e96yC72ooapx0a4devqe5Hzqsu9J9pneMV0JmrSGOpdgb0h K5LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KdOAkYx4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a36si1433848pla.30.2019.08.29.02.29.48; Thu, 29 Aug 2019 02:29:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KdOAkYx4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727257AbfH2J3r (ORCPT + 28 others); Thu, 29 Aug 2019 05:29:47 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51887 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727020AbfH2J3j (ORCPT ); Thu, 29 Aug 2019 05:29:39 -0400 Received: by mail-wm1-f65.google.com with SMTP id k1so2941556wmi.1 for ; Thu, 29 Aug 2019 02:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v2Fx0Pb0mc0UlpujkGqHHioGa7pg7ML7uA9l5iVY0Do=; b=KdOAkYx4mUlEdOHRKmFg/Ohrw/cqTc8SxCG5fhUGBqFGvGPkr0MsZW1RTy99SSeksl DNDorcOie2Sf0FP5HI46t83xZtN20WwtU66qUQz2B+4y+zGoh9G745lhiJ7MxTJAlArB aRt2FRFjKd04Eu9HEfSgIrOnSTG6WlSqhL3TOsl8Ulm4d57y+cCTFmzDWkyG9igZVwHz I7n51NEHrGNiUH53mxrK4p+B2aNdN7xobvVCyWBSg5KNr076w2JuiLJ5/SEyvXNMMjs2 GkbqqSyP2HV2TltnILXR9Rvg8fizFYt5C2gChLXRARQKW02NK95+iY0cFNBqXbDv18Mp CbqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v2Fx0Pb0mc0UlpujkGqHHioGa7pg7ML7uA9l5iVY0Do=; b=bgkf2tFov3s3vDkVqpiAP+QiFXGbY5uX4JA28cExETXW6lH8pBjLzWo+E2KebnSvvB fThoFdr69KpZWTMjYHDSj/1QNzQ1jp6UjVvBT58lU1xeJyKt/U/iIfF6h3zTx0fKt5oZ sraOEU2zs7v/hTfIWXxvty+zrLt41qdnr2cx8bOqfElZPfaRUm0p6tgPGmmeygmRO3Nk O5Pfph2C10+y5p5K0muToaj0wtBPN7GCZ+uMl/y+0aRFrulJcZJzgBRjK4yv2oExsaqF gPL8X2bTO5kgzsp6I7gq9VLSzy6KePZTV7+tstMK7z++GSEIjK4dzF/RfTvBWkRWs7is H0tQ== X-Gm-Message-State: APjAAAVWQcJ1cIQYKt5LLuaaFaBKBHQO8suHhigJ6/IRSlHvc6m5M6+p vEk/W8zmgc2MXFdzC05y0YiTLg== X-Received: by 2002:a1c:356:: with SMTP id 83mr10609179wmd.40.1567070977941; Thu, 29 Aug 2019 02:29:37 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id f197sm3609512wme.22.2019.08.29.02.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 02:29:37 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Jorge Ramirez-Ortiz , Abhinav Asati , Vamsi Singamsetty , Srinivas Kandagatla Subject: [PATCH v2 3/5] misc: fastrpc: remove unused definition Date: Thu, 29 Aug 2019 10:29:24 +0100 Message-Id: <20190829092926.12037-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> References: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jorge Ramirez-Ortiz Remove unused INIT_MEMLEN_MAX define. Signed-off-by: Jorge Ramirez-Ortiz Signed-off-by: Abhinav Asati Signed-off-by: Vamsi Singamsetty Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 1 - 1 file changed, 1 deletion(-) -- 2.21.0 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 59ee6de26229..38829fa74f28 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -33,7 +33,6 @@ #define FASTRPC_INIT_HANDLE 1 #define FASTRPC_CTXID_MASK (0xFF0) #define INIT_FILELEN_MAX (64 * 1024 * 1024) -#define INIT_MEMLEN_MAX (8 * 1024 * 1024) #define FASTRPC_DEVICE_NAME "fastrpc" /* Retrives number of input buffers from the scalars parameter */ From patchwork Thu Aug 29 09:29:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 172551 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp2072344ocp; Thu, 29 Aug 2019 02:30:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNvchI7v8ngZ6sWzx+RiGgg9+wgm70xslP+HC5oBJn9HtlcgzD95y4/D9+BgiJ9caJ/z88 X-Received: by 2002:a63:3dcd:: with SMTP id k196mr7464706pga.45.1567071001184; Thu, 29 Aug 2019 02:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567071001; cv=none; d=google.com; s=arc-20160816; b=jRAF5oy4Ni24wi9fMPt9lxPV2WvzjAEekiHk0d66ImXJM6wtsJ9jP/gtJfLMblGT7g P8kwvNPXEx3DSP65sZpnTxzZw1B0G7Sexv7+peDzOJyGj1qzTw+STrCsNHu7r7+xLs1c sPdmEieNhaH+UW7cqOmCx9S5r8oyCF2WoJ56AnPC4K0u9YiMax0uk4vhldEnUtt+Rfmd IUsUVQaO1PPhB12MVWh9nrH1Kf3DFRlW/5cKrAQImQ2pDXIs7QiaHNWS5c4emcUMl2Ye rjAcGUbLfwwzgSHkuDLFj6NJuKbatXsd3X1bicCELjoKsCnqHxXwoMW3a641aYdzds6N n5Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7K2iZxOhWYqdpgu+ftGX/anH+28e+S9dJx0eG5WBrFs=; b=T+X3usbKM6fHr8n9rM31jwpX6gsR5IDDLMlRCsJzRlbKYZoCUOInli7M9J5IdOiIeH cI8Zy0jmYPeeAMpX3WPfB4kqcMOhqVlbDOMh/3PPyDpoZWhzyjVs7X2kDrSu8ceYL6sO jpeXTODwICRytsoVX0u8mOw0TKV7h53M0Zb3gBgJ83dofGu8PPgakrN8EBC/0S2VHJEF SUmZyw63LMN+TaW5BFI8h7mG1HZvC29xaLdAA01anT39tgJVcBXL0ppasuHANwrVfdcc TYvN5o6DyxAcLV7x1TdH4qj5WwdmvPxB59W6cCh1h8lKt/N+NphvuEvdKI6/Zqi+x0fh BU7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oiVT9zLm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si1460220pgf.256.2019.08.29.02.30.00; Thu, 29 Aug 2019 02:30:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oiVT9zLm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727213AbfH2J37 (ORCPT + 28 others); Thu, 29 Aug 2019 05:29:59 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34180 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbfH2J3k (ORCPT ); Thu, 29 Aug 2019 05:29:40 -0400 Received: by mail-wr1-f65.google.com with SMTP id s18so2706953wrn.1 for ; Thu, 29 Aug 2019 02:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7K2iZxOhWYqdpgu+ftGX/anH+28e+S9dJx0eG5WBrFs=; b=oiVT9zLmf1h4t60P+I9CdvSij40tIxqhF78DG2hIgxWZ5HKvR0HrJISlbt6lpEsCG5 fC+esGCCHY34XbPFe1pyBtp+Tvn2h3uf4qdcm0cUCom7AxdwXYpYD/zDkq3x6lLo5YU5 5YXxHItF+lOOR2mqLSIeA7402VJFl250EKAhM9Wo4iuNf5Z54WKxqAEbuyQzQjAdEOx3 GEXbr6w6bfk6hOFmFZ9klwRBzqw9EIFHZyMVzW7O+COGimlsjq1L5u2mdXfkzu6/p85M nadOZG8Dvj7AwH+BDwuyFr9TdmBsDlnc7Ct4okKhHKUiW+c2L4sq7Ks+SkPhHPN7asUz fPqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7K2iZxOhWYqdpgu+ftGX/anH+28e+S9dJx0eG5WBrFs=; b=L2XNSwhJh8l7rKkV4B7yv/9Qu7vSF63KTbYrBwdzrnQzMuF0EsawIwPQA9WsQm/qu/ uorSeh52tMSkpHw9/ukQQ9poWsq80sdDnud+NS/iA8gSwjSB6H0rnOnrDMnf/rW1CPSA CoYn6DcnciR+CCPuoHdoYb8kmlLnDuVCSkx0YTl5mkLNEgia6MpNoluTo/H112sXGumD sC6bBuWomuwPt/oaX5St9RvvKJsqUqpMFgCYWm/9uQ+B5LSEHS7u3DGHb949nXYEDwsU LwHJdC75WPZDkdwHZ3sLpNa5Nz3rb3MGlubiDy2rh3NdJNZNOTunA8dlnYYHWvRG/w4z bplA== X-Gm-Message-State: APjAAAVulDWZXBl4lnzHO1+O6IvGJmPhOBTTY79eFq1WpOXuZtdQqpm0 2EUEAfcT2wMG0nI0oJ4QrFlBEg== X-Received: by 2002:adf:ecc3:: with SMTP id s3mr10359603wro.302.1567070978988; Thu, 29 Aug 2019 02:29:38 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id f197sm3609512wme.22.2019.08.29.02.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 02:29:38 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla , Mayank Chopra , Jorge Ramirez-Ortiz Subject: [PATCH v2 4/5] misc: fastrpc: fix double refcounting on dmabuf Date: Thu, 29 Aug 2019 10:29:25 +0100 Message-Id: <20190829092926.12037-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> References: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dma buf refcount has to be done by the driver which is going to use the fd. This driver already does refcount on the dmabuf fd if its actively using it but also does an additional refcounting via extra ioctl. This additional refcount can lead to memory leak in cases where the applications fail to call the ioctl to decrement the refcount. So remove this extra refcount in the ioctl More info of dma buf usage at drivers/dma-buf/dma-buf.c Reported-by: Mayank Chopra Reported-by: Jorge Ramirez-Ortiz Tested-by: Jorge Ramirez-Ortiz Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 25 ------------------------- 1 file changed, 25 deletions(-) -- 2.21.0 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 38829fa74f28..eee2bb398947 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1198,26 +1198,6 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) return 0; } -static int fastrpc_dmabuf_free(struct fastrpc_user *fl, char __user *argp) -{ - struct dma_buf *buf; - int info; - - if (copy_from_user(&info, argp, sizeof(info))) - return -EFAULT; - - buf = dma_buf_get(info); - if (IS_ERR_OR_NULL(buf)) - return -EINVAL; - /* - * one for the last get and other for the ALLOC_DMA_BUFF ioctl - */ - dma_buf_put(buf); - dma_buf_put(buf); - - return 0; -} - static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_alloc_dma_buf bp; @@ -1253,8 +1233,6 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp) return -EFAULT; } - get_dma_buf(buf->dmabuf); - return 0; } @@ -1322,9 +1300,6 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, case FASTRPC_IOCTL_INIT_CREATE: err = fastrpc_init_create_process(fl, argp); break; - case FASTRPC_IOCTL_FREE_DMA_BUFF: - err = fastrpc_dmabuf_free(fl, argp); - break; case FASTRPC_IOCTL_ALLOC_DMA_BUFF: err = fastrpc_dmabuf_alloc(fl, argp); break;