From patchwork Fri Mar 15 14:59:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10854953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83EEB15AC for ; Fri, 15 Mar 2019 14:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71F9C2A9C8 for ; Fri, 15 Mar 2019 14:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6580F2AA9A; Fri, 15 Mar 2019 14:59:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F9552A9C8 for ; Fri, 15 Mar 2019 14:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729320AbfCOO7q (ORCPT ); Fri, 15 Mar 2019 10:59:46 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38836 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729318AbfCOO7p (ORCPT ); Fri, 15 Mar 2019 10:59:45 -0400 Received: by mail-pg1-f196.google.com with SMTP id v1so1941544pgi.5 for ; Fri, 15 Mar 2019 07:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BPF7HYIndwYCravUgyQt5YZcBBFvcmqnVAdETebox5w=; b=WvisMBKbDsB+smLauX/MDEbJ1706Y11py46IH0eerWwAvAJ9bTtJ1oEdgPbWtGq7nu k/g8LcJ/CTUL7e1Rj3cfytt4llW3XQ1SME8m5rQD4ZR15RHrQ1pUlloJoO2NqBWp+2KE bYID6HOR1QW7sfq2WdPtDyWu8DxziePduW4buoGqSg4ep/uOXEREDkwsVgT3kgwVwkHF /p4oJoo2PjHsMqqQag3AvV7Bg/MFq4ztQ22xhMGs5zzLus1/hR9RwSQ7sQy1po4PeIFo JAkLH3/q9iAe95/Ma1cehtfMlDYysX4hZgQXLChGkfPvB3zBmyNXNnL/tzirIbQBATk6 U6hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BPF7HYIndwYCravUgyQt5YZcBBFvcmqnVAdETebox5w=; b=lJN4W9JlfCGJnLX5c6Y3aQ5KLwydo0115czzITCVADDXaSt+98WAjsdEUPXfU+CYl6 lFAWuiQA7Cx3PWfujaE9E7DdbLQwaHFy3U33ozFbCU5mMFwZbPHdYziCQuZLy11FZB7H 8FJEzEWFT6gTxzZMbHjfyASLnj9/2y9odgVcP21cMVXoDZjbJwL1ONUz1x25Gk6qs29k 0qP4G5JV+fh72iXN6DyQgeiHnZvuRaSy2cjtLK0Onp7qx9yYjKZUWep6cORS06qx2dcI s/ICVAmwCKut3i1toR5SBmpr1M2p8jglfseUwIT9B7ytP49x+ErOnoDq6mN99EHWygzw KmyA== X-Gm-Message-State: APjAAAUY4bqW6YXCF6JAoQXnmtKX8iDEe/FFUh0IS0QQfX0tM2f74O0m 1t4x9FQBvk82oRtj3wcyd7HxhGIiz8qcZQ== X-Google-Smtp-Source: APXvYqxXg87XrVTeTdWlDT7n6CgdvY8C2ocObXBjDXmAHzsUahS75D6fLAfOEDtnRjyxH7JcKzK6sA== X-Received: by 2002:a62:3890:: with SMTP id f138mr4568373pfa.148.1552661984006; Fri, 15 Mar 2019 07:59:44 -0700 (PDT) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id f28sm4287179pfh.178.2019.03.15.07.59.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 07:59:43 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: viro@ZenIV.linux.org.uk, Jens Axboe Subject: [PATCH 1/3] iov_iter: add ITER_BVEC_FLAG_NO_REF flag Date: Fri, 15 Mar 2019 08:59:36 -0600 Message-Id: <20190315145938.21516-2-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190315145938.21516-1-axboe@kernel.dk> References: <20190315145938.21516-1-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For ITER_BVEC, if we're holding on to kernel pages, the caller doesn't need to grab a reference to the bvec pages, and drop that same reference on IO completion. This is essentially safe for any ITER_BVEC, but some use cases end up reusing pages and uncondtionally dropping a page reference on completion. And example of that is sendfile(2), that ends up being a splice_in + splice_out on the pipe pages. Add a flag that tells us it's fine to not grab a page reference to the bvec pages, since that caller knows not to drop a reference when it's done with the pages. Signed-off-by: Jens Axboe --- fs/io_uring.c | 3 +++ include/linux/uio.h | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5be6e4f99a9e..f66a4a5daf35 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -862,6 +862,9 @@ static int io_import_fixed(struct io_ring_ctx *ctx, int rw, iov_iter_bvec(iter, rw, imu->bvec, imu->nr_bvecs, offset + len); if (offset) iov_iter_advance(iter, offset); + + /* don't drop a reference to these pages */ + iter->type |= ITER_BVEC_FLAG_NO_REF; return 0; } diff --git a/include/linux/uio.h b/include/linux/uio.h index ecf584f6b82d..4e926641fa80 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -23,14 +23,23 @@ struct kvec { }; enum iter_type { - ITER_IOVEC = 0, - ITER_KVEC = 2, - ITER_BVEC = 4, - ITER_PIPE = 8, - ITER_DISCARD = 16, + /* set if ITER_BVEC doesn't hold a bv_page ref */ + ITER_BVEC_FLAG_NO_REF = 2, + + /* iter types */ + ITER_IOVEC = 4, + ITER_KVEC = 8, + ITER_BVEC = 16, + ITER_PIPE = 32, + ITER_DISCARD = 64, }; struct iov_iter { + /* + * Bit 0 is the read/write bit, set if we're writing. + * Bit 1 is the BVEC_FLAG_NO_REF bit, set if type is a bvec and + * the caller isn't expecting to drop a page reference when done. + */ unsigned int type; size_t iov_offset; size_t count; @@ -84,6 +93,11 @@ static inline unsigned char iov_iter_rw(const struct iov_iter *i) return i->type & (READ | WRITE); } +static inline bool iov_iter_bvec_no_ref(const struct iov_iter *i) +{ + return (i->type & ITER_BVEC_FLAG_NO_REF) != 0; +} + /* * Total number of bytes covered by an iovec. *