Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1015716yba; Thu, 4 Apr 2019 02:29:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyD585mOh7NXYAcvjHmrPwuOOe6j4yPOqpCSmdlG21sQwPYHgcUvsAjEgOmYLKzjVibHgtX X-Received: by 2002:a63:475e:: with SMTP id w30mr4515185pgk.308.1554370151540; Thu, 04 Apr 2019 02:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370151; cv=none; d=google.com; s=arc-20160816; b=R5OZ8PegoA8pc9Jt+pVqiPbCiAwgZZTL6uBnZ/PXZnH36DcuzcsRVQja2uQJHHxwYb mgVJHK7EdndOWN1I7t5rji8USojd4okOyhmZbOL6KFq/nRMBC9I6gqdpn9r7oy06Rbew 8q1TVVkLAVVV0v+Fo34/QxIv+JCsr4vbMHoQb8iB4ZTSzp24YI4VOk4RrcF/WkVh7wYf o9oFtaLGKLM4XaUHHnQwEDYu5DgEQA15sIRTQMy3RuwMKwP5AY01aHg8nVxWCZKc++op vYx1hcjUq6IIi/mZOgaPExrZC4FfkNc/KUZYF1MDwRYWhgvoL2j10RV1bCl9JV3Pts6d eYmQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6C+tyjYeR4Y6Nfpn1JQw/PwmTcT8/vWOARoZAHk9zsY=; b=Tyb8Cq09Sr8VyQE9oBhlvI2LV+NhAcLfaFJJzxxRyGPn4ez2z1l0SL0baKa4Q6jYr4 SJwW6On5OwTqj54cN57plHvckMofbRQH7aEgMnY/WbuzUt5JCO7khutxAHwGXWoT4ONe JmNP5vXbJk/i2BFxcqYcSuK/mrXB9k/e/2VWbOUI4HfEK6YWr/IQJyNxmNHftNQDFm6o wIiZrEav1EQFK4B0BMVQby6/tRMnh66LefC2JEm3Z12Hzv1xEROqVj0SonJh0foqYdDP 8Vax23lwGraBXVcPt0g72mxhBUoe4D1xPwMmM2rlDLIrXAmO+XNxEM9dHLE0zPKPh+Re fW7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Bs7Vb++O; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 184si16660158pfd.233.2019.04.04.02.28.56; Thu, 04 Apr 2019 02:29:11 -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=@kernel.org header.s=default header.b=Bs7Vb++O; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387487AbfDDJ1D (ORCPT + 99 others); Thu, 4 Apr 2019 05:27:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:52998 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387454AbfDDJMs (ORCPT ); Thu, 4 Apr 2019 05:12:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC38120820; Thu, 4 Apr 2019 09:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369167; bh=8cxvyUW1oH7AEVOve6H9pqx5tNCWe76PYQ9jHcD3YUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bs7Vb++OfRZxMcm0eYDXwdYY2Th4AqRO7siGAwUBY+VzSXC15CPo1DbSYuHCU6w/h Sbwyux6jADgrkd/ZUdwH2FX3krUlhkjHQu4tlt36kIqhQtKURPf/E0OUqTbhKGAaSG g9yqpQmSl70rDn9Twon2Y71umX1/Qy/ztind5q/I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksandr Andrushchenko , Juergen Gross , Sasha Levin Subject: [PATCH 5.0 122/246] xen/gntdev: Do not destroy context while dma-bufs are in use Date: Thu, 4 Apr 2019 10:47:02 +0200 Message-Id: <20190404084623.427787398@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit fa13e665e02874c0a5f4d06d6967ae34a6cb3d6a ] If there are exported DMA buffers which are still in use and grant device is closed by either normal user-space close or by a signal this leads to the grant device context to be destroyed, thus making it not possible to correctly destroy those exported buffers when they are returned back to gntdev and makes the module crash: [ 339.617540] [] dmabuf_exp_ops_release+0x40/0xa8 [ 339.617560] [] dma_buf_release+0x60/0x190 [ 339.617577] [] __fput+0x88/0x1d0 [ 339.617589] [] ____fput+0xc/0x18 [ 339.617607] [] task_work_run+0x9c/0xc0 [ 339.617622] [] do_notify_resume+0xfc/0x108 Fix this by referencing gntdev on each DMA buffer export and unreferencing on buffer release. Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Boris Ostrovsky@oracle.com> Signed-off-by: Juergen Gross Signed-off-by: Sasha Levin --- drivers/xen/gntdev-dmabuf.c | 12 +++++++++++- drivers/xen/gntdev-dmabuf.h | 2 +- drivers/xen/gntdev.c | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c index cba6b586bfbd..d97fcfc5e558 100644 --- a/drivers/xen/gntdev-dmabuf.c +++ b/drivers/xen/gntdev-dmabuf.c @@ -80,6 +80,12 @@ struct gntdev_dmabuf_priv { struct list_head imp_list; /* This is the lock which protects dma_buf_xxx lists. */ struct mutex lock; + /* + * We reference this file while exporting dma-bufs, so + * the grant device context is not destroyed while there are + * external users alive. + */ + struct file *filp; }; /* DMA buffer export support. */ @@ -311,6 +317,7 @@ static void dmabuf_exp_release(struct kref *kref) dmabuf_exp_wait_obj_signal(gntdev_dmabuf->priv, gntdev_dmabuf); list_del(&gntdev_dmabuf->next); + fput(gntdev_dmabuf->priv->filp); kfree(gntdev_dmabuf); } @@ -423,6 +430,7 @@ static int dmabuf_exp_from_pages(struct gntdev_dmabuf_export_args *args) mutex_lock(&args->dmabuf_priv->lock); list_add(&gntdev_dmabuf->next, &args->dmabuf_priv->exp_list); mutex_unlock(&args->dmabuf_priv->lock); + get_file(gntdev_dmabuf->priv->filp); return 0; fail: @@ -834,7 +842,7 @@ long gntdev_ioctl_dmabuf_imp_release(struct gntdev_priv *priv, return dmabuf_imp_release(priv->dmabuf_priv, op.fd); } -struct gntdev_dmabuf_priv *gntdev_dmabuf_init(void) +struct gntdev_dmabuf_priv *gntdev_dmabuf_init(struct file *filp) { struct gntdev_dmabuf_priv *priv; @@ -847,6 +855,8 @@ struct gntdev_dmabuf_priv *gntdev_dmabuf_init(void) INIT_LIST_HEAD(&priv->exp_wait_list); INIT_LIST_HEAD(&priv->imp_list); + priv->filp = filp; + return priv; } diff --git a/drivers/xen/gntdev-dmabuf.h b/drivers/xen/gntdev-dmabuf.h index 7220a53d0fc5..3d9b9cf9d5a1 100644 --- a/drivers/xen/gntdev-dmabuf.h +++ b/drivers/xen/gntdev-dmabuf.h @@ -14,7 +14,7 @@ struct gntdev_dmabuf_priv; struct gntdev_priv; -struct gntdev_dmabuf_priv *gntdev_dmabuf_init(void); +struct gntdev_dmabuf_priv *gntdev_dmabuf_init(struct file *filp); void gntdev_dmabuf_fini(struct gntdev_dmabuf_priv *priv); diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 5efc5eee9544..7cf9c51318aa 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -600,7 +600,7 @@ static int gntdev_open(struct inode *inode, struct file *flip) mutex_init(&priv->lock); #ifdef CONFIG_XEN_GNTDEV_DMABUF - priv->dmabuf_priv = gntdev_dmabuf_init(); + priv->dmabuf_priv = gntdev_dmabuf_init(flip); if (IS_ERR(priv->dmabuf_priv)) { ret = PTR_ERR(priv->dmabuf_priv); kfree(priv); -- 2.19.1