Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1442205pxb; Fri, 6 Nov 2020 09:41:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJz65JcAe8dWmHydNpz2N16EQhzYbJeITGXKsug/on3dv9lBiwuETmdy+NAEEoOBQAv3R3GA X-Received: by 2002:a50:e705:: with SMTP id a5mr3198028edn.29.1604684500281; Fri, 06 Nov 2020 09:41:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604684500; cv=none; d=google.com; s=arc-20160816; b=OiZJElx1e4GKokcxNAU1QfWzE64U2x+8YM8t5K3yt1e7DEHp/cJdoeQtY8Z5u7irLe m5xpndcBmYgJpjB1CO4kIk9CtN4KlfFxYwwmxBNIiO5azDrubCAE9+hqc1/sOe6TciXg 17YNkAbtAOlCDPjwESgEeygu9kv/jHZyIzNjbgICMZJEj1mQ0Ajf0CMXmrycGC6R/Gas eNLZVz16/S25y7HJjI8UbyLQApGwYKETh0E8Wd5z2wQfHeU0sF1j3RBSIlujFvKcv2st EWBnVHC3bgwI34oEFuXLk9+KZWPdHUbeQLGFnqjaCtK2wjym6YIZZpLNGzSUy7a6TpqA jE4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QqZ++Pt3MZPl0c26h7esX3kKVTLpDd4DLyuldQOeJ6E=; b=VZYdIux+Gn9M029QxbBIV6cC7XGq3g5BgOvF51t9fGvDpfhsZ0Nfq5HLlJWM1wpOtg IYomHNmA9huGtSRVxdaOWFHpeQLZrFn1sIToxPONO8bLS3gPBQC/mR+gf9oe8ZcK/5Pk qXtyAJWBCFaAyflRoF4nn0fTOp3j5/3HMAYRk0mGH1tlxH585/BWFId7PQ3OilcytqWJ yQGnW3PhE9u60CEBc0HaHPvXhpdgD40PNde2msomcnAjQQ3I5WNN/U42XoJZdj7SAlMC 5kBzX5Mes/8ZmoX3Ly4vbH7EzsCoFkxmpmG2mqKm/H8Ut3us2othryUhR2prtjlSt1NH daMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=aVspDJwp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si1437759eds.412.2020.11.06.09.41.17; Fri, 06 Nov 2020 09:41:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=aVspDJwp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727352AbgKFRjh (ORCPT + 99 others); Fri, 6 Nov 2020 12:39:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbgKFRjg (ORCPT ); Fri, 6 Nov 2020 12:39:36 -0500 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43ADBC0613D2 for ; Fri, 6 Nov 2020 09:39:35 -0800 (PST) Received: by mail-qt1-x844.google.com with SMTP id 3so1313005qtx.3 for ; Fri, 06 Nov 2020 09:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QqZ++Pt3MZPl0c26h7esX3kKVTLpDd4DLyuldQOeJ6E=; b=aVspDJwpvtyG5+kighP26kbunhoVoDrk2g+dikuA78Pm3bA2qTEMgmEOIf1kZJzMIf jREWUhSOExSA/q/FCxqA4XBVE24zI+bsJoB1MfEIxBjq2vdyDXVafteyCmFKOVp6mNFr a+tx6++MRi2ULgDc9l1aIYs8bYmkHkHdREfE1OJi7rMzsOZFvHKvzXQ7XJqg4Rv2jtLq /+Dlp7JoggqKZn8R6W1cCZQ0admWy+NkyCMZtOTh144o5mkYSgGm7bfVWOa4R1qrCUIm 0U96w1WKj0KdQqF8ogG0DBvSehQPHSPP+p8q7o2QpQF4H1UThgaq/hW1ayZpgvaa/xXc nKQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QqZ++Pt3MZPl0c26h7esX3kKVTLpDd4DLyuldQOeJ6E=; b=uIjPGBwaBFBe1lM6QNA9mGD3uUND5m9uVhukrR3Gml9WTcE0PPE+WuhOP7ZvcM4ULb lgKXns1q6m0lM6dzGAaFE0VUK6RmgI0DJ5oYp/01tobtsb5DXUnIzpc5r0D7lnk9nRy9 ehumJpcCRLjd7zB6FrWWD+yLvBdrPzvk/46TuXg6GML0LH0MgxGcth75EYBA0ZCXvYil IVrJLoBgZdzWiADmNEkp4sPVeYNOmWp/S5UcpccouEYVdvbIcJGbMelIXgtM8yvHBQ4k FtltDcF/lr08pHg9zpPFrpoPA4VrP28Pg+n0p38wZgzpzCaWVh3xNaHbk8jZezh2IAjK Cjvg== X-Gm-Message-State: AOAM530OS4jWwownl3OrhgHByAl6lu7DuIRdVd1LvJF+nk+D2MItyf4E wzkZwFPK4dRKKJJaCEWo9yHocQ== X-Received: by 2002:ac8:1e84:: with SMTP id c4mr2651870qtm.340.1604684374450; Fri, 06 Nov 2020 09:39:34 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id o19sm1032238qko.3.2020.11.06.09.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 09:39:33 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kb5i0-000zRk-Qy; Fri, 06 Nov 2020 13:39:32 -0400 Date: Fri, 6 Nov 2020 13:39:32 -0400 From: Jason Gunthorpe To: Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Stephen Bates , Christoph Hellwig , Dan Williams , Christian =?utf-8?B?S8O2bmln?= , Ira Weiny , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter Subject: Re: [RFC PATCH 15/15] nvme-pci: Allow mmaping the CMB in userspace Message-ID: <20201106173932.GT36674@ziepe.ca> References: <20201106170036.18713-1-logang@deltatee.com> <20201106170036.18713-16-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201106170036.18713-16-logang@deltatee.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 06, 2020 at 10:00:36AM -0700, Logan Gunthorpe wrote: > Allow userspace to obtain CMB memory by mmaping the controller's > char device. The mmap call allocates and returns a hunk of CMB memory, > (the offset is ignored) so userspace does not have control over the > address within the CMB. > > A VMA allocated in this way will only be usable by drivers that set > FOLL_PCI_P2PDMA when calling GUP. And inter-device support will be > checked the first time the pages are mapped for DMA. > > Currently this is only supported by O_DIRECT to an PCI NVMe device > or through the NVMe passthrough IOCTL. > > Signed-off-by: Logan Gunthorpe > drivers/nvme/host/core.c | 11 +++++++++++ > drivers/nvme/host/nvme.h | 1 + > drivers/nvme/host/pci.c | 9 +++++++++ > 3 files changed, 21 insertions(+) > > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index f14316c9b34a..fc642aba671d 100644 > +++ b/drivers/nvme/host/core.c > @@ -3240,12 +3240,23 @@ static long nvme_dev_ioctl(struct file *file, unsigned int cmd, > } > } > > +static int nvme_dev_mmap(struct file *file, struct vm_area_struct *vma) > +{ > + struct nvme_ctrl *ctrl = file->private_data; > + > + if (!ctrl->ops->mmap_cmb) > + return -ENODEV; > + > + return ctrl->ops->mmap_cmb(ctrl, vma); > +} This needs to ensure that the VMA created is destroyed before the driver is unprobed - ie the struct pages backing the BAR memory is destroyed. I don't see anything that synchronizes this in the nvme_dev_release()? Many places do this by putting all the VMAs into an address space and zaping the address space when unprobing the driver to revoke the pages, but there is a tricky race here :\ https://lore.kernel.org/dri-devel/20201021125030.GK36674@ziepe.ca/ Jason