From patchwork Thu Aug 25 15:24:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 12955011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A64DC64990 for ; Thu, 25 Aug 2022 15:24:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A50B94000A; Thu, 25 Aug 2022 11:24:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9333A94000B; Thu, 25 Aug 2022 11:24:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A4D194000A; Thu, 25 Aug 2022 11:24:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2DB6D940007 for ; Thu, 25 Aug 2022 11:24:47 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F058AC0973 for ; Thu, 25 Aug 2022 15:24:46 +0000 (UTC) X-FDA: 79838487372.09.D70ED06 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by imf22.hostedemail.com (Postfix) with ESMTP id 79A88C0002 for ; Thu, 25 Aug 2022 15:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=mLYWjwjaacuhTQSD3LMzZRV3Gg44uzd/+90ZlUZOo0E=; b=JlA02I9mYM/1XyzPhpPhzA8jen fB0btV3snf/z9KW6dTxn6u/abas7864PAvz+ynWXFzPL1rlGI2s0oRw7UP5yTir5n890MUigIrDsk zA3uu2g8QdinM4+B36OB6W5BEPoH1yqALmoP39OJfN4rqGUrjdfTbLcsqUme4Z8t54ow3fe5lfC/c Fl9hCoKvjhE1chLSEIBX9qOh/De48gdBzb/HewRblhZ8sJd79WaorHbd18g64W02PKJcBAlkL+Lii 02q17F11RI0GEWM8Baan/tqBiUlho3AxoVa7WA6H4kQJXp8aOTGBtLmwjDzjftTk2ncaWEi5g6yYK Qt6fGg3Q==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oREim-0086MB-Bp; Thu, 25 Aug 2022 09:24:41 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1oREie-0001ei-J0; Thu, 25 Aug 2022 09:24:32 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org Cc: Christoph Hellwig , Greg Kroah-Hartman , Dan Williams , Jason Gunthorpe , =?utf-8?q?Christian_K=C3=B6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Stephen Bates , Logan Gunthorpe Date: Thu, 25 Aug 2022 09:24:22 -0600 Message-Id: <20220825152425.6296-6-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825152425.6296-1-logang@deltatee.com> References: <20220825152425.6296-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, hch@lst.de, gregkh@linuxfoundation.org, jgg@ziepe.ca, christian.koenig@amd.com, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, jason@jlekstrand.net, dave.hansen@linux.intel.com, helgaas@kernel.org, dan.j.williams@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, ira.weiny@intel.com, robin.murphy@arm.com, martin.oliveira@eideticom.com, ckulkarnilinux@gmail.com, jhubbard@nvidia.com, rcampbell@nvidia.com, sbates@raithlin.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH v9 5/8] block: set FOLL_PCI_P2PDMA in __bio_iov_iter_get_pages() X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661441086; a=rsa-sha256; cv=none; b=UtS8EZS+60GVN2vPmOhCGbGHOwiOQLNWi3DQ4UprWYciijtlGjhDmpXDlVcPIeUh9HMSLB isDUVRdR7cY/mkBLbVu1DzvygdNbYDiCxJbu8kEMZIQDDx7pOZdR1La0Yt1y5yLAIWwzwx g0iSPC4jbwqTILGaFFGJisFgIy9hxEE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=deltatee.com header.s=20200525 header.b=JlA02I9m; spf=pass (imf22.hostedemail.com: domain of gunthorp@deltatee.com designates 204.191.154.188 as permitted sender) smtp.mailfrom=gunthorp@deltatee.com; dmarc=pass (policy=none) header.from=deltatee.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661441086; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mLYWjwjaacuhTQSD3LMzZRV3Gg44uzd/+90ZlUZOo0E=; b=QAO7kQqIPS/inmUJW6FWiK/U81jtPGeAVfhMttxzq/4RioDWNuyczBVrsRT3WI+nPkU7ju tbVKtH997obxEdvdBQF4uTGZPCAkh64pB7R8QqwKdA0R0lFxh2cM6yPTp26qiz/EhPxk2O nHlJbSE67MVIDJuIOthDwZ2P2n+jmcc= X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=deltatee.com header.s=20200525 header.b=JlA02I9m; spf=pass (imf22.hostedemail.com: domain of gunthorp@deltatee.com designates 204.191.154.188 as permitted sender) smtp.mailfrom=gunthorp@deltatee.com; dmarc=pass (policy=none) header.from=deltatee.com X-Rspamd-Server: rspam12 X-Stat-Signature: 7ipwr6w6uk9cm7atgrwiwp1gkm9maodr X-Rspamd-Queue-Id: 79A88C0002 X-HE-Tag: 1661441085-36183 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: When a bio's queue supports PCI P2PDMA, set FOLL_PCI_P2PDMA for iov_iter_get_pages_flags(). This allows PCI P2PDMA pages to be passed from userspace and enables the O_DIRECT path in iomap based filesystems and direct to block devices. Signed-off-by: Logan Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- block/bio.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/block/bio.c b/block/bio.c index 969607bc1f4d..ca09d79a0683 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1200,6 +1200,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) unsigned short entries_left = bio->bi_max_vecs - bio->bi_vcnt; struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt; struct page **pages = (struct page **)bv; + unsigned int flags = 0; ssize_t size, left; unsigned len, i = 0; size_t offset, trim; @@ -1213,6 +1214,10 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) BUILD_BUG_ON(PAGE_PTRS_PER_BVEC < 2); pages += entries_left * (PAGE_PTRS_PER_BVEC - 1); + if (bio->bi_bdev && bio->bi_bdev->bd_disk && + blk_queue_pci_p2pdma(bio->bi_bdev->bd_disk->queue)) + flags |= FOLL_PCI_P2PDMA; + /* * Each segment in the iov is required to be a block size multiple. * However, we may not be able to get the entire segment if it spans @@ -1220,8 +1225,9 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) * result to ensure the bio's total size is correct. The remainder of * the iov data will be picked up in the next bio iteration. */ - size = iov_iter_get_pages2(iter, pages, UINT_MAX - bio->bi_iter.bi_size, - nr_pages, &offset); + size = iov_iter_get_pages_flags(iter, pages, + UINT_MAX - bio->bi_iter.bi_size, + nr_pages, &offset, flags); if (unlikely(size <= 0)) return size ? size : -EFAULT;