Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1737134pxa; Sat, 29 Aug 2020 01:10:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHI67evD5EcIpRrOZjUUSfhG7Z4xFFQAu49w/iOS8cJEud4S92bThtOHgOLAvSr8/uSi0m X-Received: by 2002:aa7:c4c8:: with SMTP id p8mr2364519edr.231.1598688614782; Sat, 29 Aug 2020 01:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598688614; cv=none; d=google.com; s=arc-20160816; b=d2sWowEBnMR4VQTVQAKI+8wRi4FtTUc+QTRbwt8XuWUFwguSGDBKJcV0C0cYu8L8iU LoBEjRJu3RUGeol+vjjDJKJ7LuUn7xbXxP0rDRfcjVKUxaODZWetJObDJDlHtodFUIX7 ySYFAnVlHg+Wc1nB5jv3kNhfUuO73JbAxTiRtAqVpikffa1TEk1ooQFKhytMLRW70cy9 8y8Pg6Qa013e64g+dgr1Kxk9NB46bvAa4H5C23IDcu22hT3vCEZRekZQF5jwu63A79DO vlQZggkN2AEMi3gQ+ynEf/T7CR84V2p0nK5VczLiR3I/bDs/0SorXpV9FSgFBR7aIBEM f4hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=f29+8U51sN7xD9DRBLq2nw+qMqJ1oMDZgC0r44yrcd4=; b=pbEzXRRJ3J8xpbN7R49mLm3BTcAxY7P2Zg6eb+8LJSkzRiXu0QxfCXt0l/cXkBIa00 ZThjaeoLVBWBr3kDxpUQWODoxp0mKYf/wWPfC7mHM5q0cPRNTxPiP9BW3Qq/wx85a8cT Kh31yIR56qOfLDiQkauZYRuXxMznWduZOtcY/fNd9whRN3SMnO1cSjt01G9dbTPh35DY MyU4OkBQYWzBbJsxpXGZg3z8jbMLGjORoG2YQYuxDsd9mZaicTW9TsO9z1uAU/pDiEMK Hkj6ez1zxBuIME+tResWHunJ22nKPMm3rRNKwahL3HfX6/wvzUzuF8iMX1he9kVSHV41 Ygqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=YgiZCIp7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si1445479ejc.530.2020.08.29.01.09.52; Sat, 29 Aug 2020 01:10:14 -0700 (PDT) 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=@nvidia.com header.s=n1 header.b=YgiZCIp7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727998AbgH2IJD (ORCPT + 99 others); Sat, 29 Aug 2020 04:09:03 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:6665 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727929AbgH2II4 (ORCPT ); Sat, 29 Aug 2020 04:08:56 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 29 Aug 2020 01:06:51 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Sat, 29 Aug 2020 01:08:55 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Sat, 29 Aug 2020 01:08:55 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 29 Aug 2020 08:08:54 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 29 Aug 2020 08:08:54 +0000 Received: from sandstorm.nvidia.com (Not Verified[10.2.50.252]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Sat, 29 Aug 2020 01:08:54 -0700 From: John Hubbard To: Andrew Morton CC: Alexander Viro , Christoph Hellwig , Ilya Dryomov , Jens Axboe , , , , , LKML , John Hubbard Subject: [PATCH v2 0/3] bio: Direct IO: convert to pin_user_pages_fast() Date: Sat, 29 Aug 2020 01:08:50 -0700 Message-ID: <20200829080853.20337-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1598688411; bh=f29+8U51sN7xD9DRBLq2nw+qMqJ1oMDZgC0r44yrcd4=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-NVConfidentiality:Content-Transfer-Encoding: Content-Type; b=YgiZCIp71QQJea8/vSz5N0nHpsgBzIi0hXzOJenMST3nt/uuXRZZSpoJHi9YtQct2 ezsZJUW49zUEDtxWGF0BDcHrlMkY5InjJbmU5P6x2EZcxc5VsRDP6RGKVWOPKj3w3w VvUaB/dBj0biYcaDSOqpPt7WUX6t/U7UEhLGAb+aM+5NsqAjnTRDIV1Q4TlwnruzD5 gaqWuWNVmyXMTI1YwrQORDgbYm7ROAvIH/Bm9+oVAo27XBmbLOrZrj/bb0bFrLG43I RrgkJsGFTbBX9G2561TGfdgMRKGid0ReqWDUxnaTvLzHDOJahcILSK6BkyOfTkVY07 KNzSt1O5kalQA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Changes since v1: * Now handles ITER_PIPE, by appying pin_user_page() to ITER_PIPE pages, on the Direct IO path. Thanks to Al Viro for pointing me in the right direction there. * Removed the ceph and BIO_FOLL_PIN patches: the ceph improvements were handled separately as a different patch entirely, by Jeff Layton. And the BIO_FOLL_PIN idea turned out to be completely undesirable here. Original cover letter, updated for v2: This converts the Direct IO block/bio layer over to use FOLL_PIN pages (those acquired via pin_user_pages*()). This effectively converts several file systems (ext4, for example) that use the common Direct IO routines. See "Remaining work", below for a bit more detail there. Quite a few approaches have been considered over the years. This one is inspired by Christoph Hellwig's July, 2019 observation that there are only 5 ITER_ types, and we can simplify handling of them for Direct IO [1]. After working through how bio submission and completion works, I became convinced that this is the simplest and cleanest approach to conversion. Design notes =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D This whole approach depends on certain concepts: 1) Each struct bio instance must not mix different types of pages: FOLL_PIN and non-FOLL_PIN pages. (By FOLL_PIN I'm referring to pages that were acquired and pinned via pin_user_page*() routines.) Fortunately, this is already an enforced constraint for bio's, as evidenced by the existence and use of BIO_NO_PAGE_REF. 2) Christoph Hellwig's July, 2019 observation that there are only 5 ITER_ types, and we can simplify handling of them for Direct IO [1]. Accordingly, this series implements the following pseudocode: Direct IO behavior: ITER_IOVEC: pin_user_pages_fast(); break; ITER_PIPE: for each page: pin_user_page(); break; ITER_KVEC: // already elevated page refcount, leave alone ITER_BVEC: // already elevated page refcount, leave alone ITER_DISCARD: // discard return -EFAULT or -ENVALID; ...which works for callers that already have sorted out which case they are in. Such as, Direct IO in the block/bio layers. Now, this does leave ITER_KVEC and ITER_BVEC unconverted, but on the other hand, it's not clear that these are actually affected in the real world, by the get_user_pages()+filesystem interaction problems of [2]. If it turns out to matter, then those can be handled too, but it's just more refactoring and surgery to do so. Testing =3D=3D=3D=3D=3D=3D=3D Performance: no obvious regressions from running fio (direct=3D1: Direct IO) on both SSD and NVMe drives. Functionality: selected non-destructive bare metal xfstests on xfs, ext4, btrfs, orangefs filesystems, plus LTP tests. Note that I have only a single x86 64-bit test machine, though. Remaining work =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Non-converted call sites for iter_iov_get_pages*() at the moment include: net, crypto, cifs, ceph, vhost, fuse, nfs/direct, vhost/scsi. However, it's not clear which of those really have to be converted, because some of them probably use ITER_BVEC or ITER_KVEC. About-to-be-converted sites (in a subsequent patch) are: Direct IO for filesystems that use the generic read/write functions. [1] https://lore.kernel.org/kvm/20190724061750.GA19397@infradead.org/ [2] "Explicit pinning of user-space pages": https://lwn.net/Articles/807108/ John Hubbard (3): mm/gup: introduce pin_user_page() iov_iter: introduce iov_iter_pin_user_pages*() routines bio: convert get_user_pages_fast() --> pin_user_pages_fast() block/bio.c | 24 +++++----- block/blk-map.c | 6 +-- fs/direct-io.c | 28 +++++------ fs/iomap/direct-io.c | 2 +- include/linux/mm.h | 2 + include/linux/uio.h | 5 ++ lib/iov_iter.c | 110 +++++++++++++++++++++++++++++++++++++++---- mm/gup.c | 30 ++++++++++++ 8 files changed, 169 insertions(+), 38 deletions(-) --=20 2.28.0