From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFBB3C388F2 for ; Fri, 6 Nov 2020 17:39:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3AA2E217A0 for ; Fri, 6 Nov 2020 17:39:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="aVspDJwp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AA2E217A0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8C3E16B005D; Fri, 6 Nov 2020 12:39:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 873936B0068; Fri, 6 Nov 2020 12:39:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 793BB6B006C; Fri, 6 Nov 2020 12:39:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 41FFE6B005D for ; Fri, 6 Nov 2020 12:39:49 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6732A349B for ; Fri, 6 Nov 2020 17:39:44 +0000 (UTC) X-FDA: 77454705888.08.stem77_2704a80272d4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 9C8911819E798 for ; Fri, 6 Nov 2020 17:39:35 +0000 (UTC) X-HE-Tag: stem77_2704a80272d4 X-Filterd-Recvd-Size: 5399 Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Nov 2020 17:39:34 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id n63so1319015qte.4 for ; Fri, 06 Nov 2020 09:39:34 -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=m6B04mph8WKkTZC0IrbQR7zO4JccC3St9Moft1akLevraqpgZYJaf8fD+RtJ1dqsf7 BsXHoDnR7YEhdYdXFaRIN30GXeE+SiqhV37HN3nceY+r1vCDtkTKLQKni2xBMFebrq+e LBb+xwYoLwpHCXTI7M6dpYiWEjqRcKh4/0xNGUytJxZ3+xrBSRfrhX8FLEARRiN9yUx8 g6aHcxDrRGSV9txjV6joA4K0FXJv/LKn5P918wtnTcNRXKx5V0YIZSufEAomg3z4pDXP GNeKzu1HXDV8TEYxmIZjyRRQgXAHSDtX/8mQyC4iaqwhrHD4alb0ox3XRMPcWO5x7hMS ZhoA== X-Gm-Message-State: AOAM532s94GHslPm+sIrkBj3CfQLoM9AUxGZ0b3hj8yq7GB+2uTJWEYJ KGlCUjBp8vFl1ATvII5uIoOG9Q== X-Google-Smtp-Source: ABdhPJwk/LVr/ux401xFB0f8tEBQvqxB/lNHOmPBnGlIZGn/taGrIczG0r9kVyPbYEVYIeCjEKrF7Q== 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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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