From patchwork Wed Feb 27 20:20:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10832289 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 532B8188E for ; Wed, 27 Feb 2019 20:20:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 489432E6D6 for ; Wed, 27 Feb 2019 20:20:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D2582E7B4; Wed, 27 Feb 2019 20:20:28 +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 8724C2E6DA for ; Wed, 27 Feb 2019 20:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730151AbfB0UUP (ORCPT ); Wed, 27 Feb 2019 15:20:15 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35805 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730136AbfB0UUP (ORCPT ); Wed, 27 Feb 2019 15:20:15 -0500 Received: by mail-pf1-f196.google.com with SMTP id j5so8548834pfa.2 for ; Wed, 27 Feb 2019 12:20:14 -0800 (PST) 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=ZwCQgAWayhCK5mb6gyRTNwhT0ZUL37gK/m9X+xNNO/o=; b=N6iCyfDD5XOxZRxt7e9BVeu/3cZuoZ27HakIqY5Dhx0jeZnHGjSxr89i+QDR7kREM2 hZVsyvHb0zRo0NhB26NEuhe7gVQO+FlkYsvfWSLlyfivcAWWlq3mf4u2YLWQTvsANoxI 3GakPOG5BeLl1NmTiJOrzdE5CuOMfTJbVmFLbF5Ney6qsUfSPXi4PGMJdOJ2fZRPbJir SEIURh5Bk4haW2Tz07VySbEkGh/b5WPfnGiL0h0fW8o81aaqogdVdQiwSJV//FB+h6By sGHGcgkuwLtJy8bqBqtK9/X28qounQBjAkFDjEktyOU9hAsGDW4bzsqWDPGFUG6pVA2m zoKQ== 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=ZwCQgAWayhCK5mb6gyRTNwhT0ZUL37gK/m9X+xNNO/o=; b=JQNBpu2ST9haUCht1/3l3d04WJondbpU7/99/3uOEmxCUu9wks4KFhEufdck0f2Wrs Nd79hJNXr/5zXJmOut/VNn6nW4dQOaaGf8IAqukBslvIjChR53HdL+LlXg21KSdLqgdU Psdue3YMubxAZ+U4kFAdXf+4fqPeolQoODeP4kdvg53mW5AmGmVcMux/Tvyxn8NA2MYb +JNQ4e4i9ghuKviT7dpdkT49lTugkObVGyvad9JrWVyY7z/lyBkkE2/k2pyEGgmSXICa xll/SR6uf1w+VwelQOO6zqLPFo4Swgxs3XG0r+s1eCC81/aMlAuG0ZprXXDdtWG6NNLZ lMVg== X-Gm-Message-State: AHQUAuYaUvU+czbRVTDF4N+FOQ83Jo3PPNj6sT3k+GnRd4tum3+fyImR 7+9qSkUSFZbf43AknWhWkz1GST8hJhjtBg== X-Google-Smtp-Source: AHgI3IZr4tYfRUOw2Tb22oAXcFDtNo17F70chhMgcWwFzRtkXJ8sJzHKBEUb8ceX9tjpI+tL6OaqgQ== X-Received: by 2002:a63:cc43:: with SMTP id q3mr4766247pgi.387.1551298813670; Wed, 27 Feb 2019 12:20:13 -0800 (PST) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id d23sm22945959pfn.180.2019.02.27.12.20.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Feb 2019 12:20:12 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: hch@lst.de, viro@ZenIV.linux.org.uk, Jens Axboe Subject: [PATCH 1/2] iov_iter: add ITER_BVEC_FLAG_NO_REF flag Date: Wed, 27 Feb 2019 13:20:05 -0700 Message-Id: <20190227202006.18844-2-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190227202006.18844-1-axboe@kernel.dk> References: <20190227202006.18844-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 | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index f2df45bd61c3..6bdf280a7fb9 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -869,6 +869,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..ecc88378ec40 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -23,11 +23,15 @@ struct kvec { }; enum iter_type { - ITER_IOVEC = 0, - ITER_KVEC = 2, - ITER_BVEC = 4, - ITER_PIPE = 8, - ITER_DISCARD = 16, + /* iter types */ + ITER_IOVEC = 4, + ITER_KVEC = 8, + ITER_BVEC = 16, + ITER_PIPE = 32, + ITER_DISCARD = 64, + + /* set if ITER_BVEC doesn't hold a bv_page ref */ + ITER_BVEC_FLAG_NO_REF = 2, }; struct iov_iter { @@ -84,6 +88,11 @@ static inline unsigned char iov_iter_rw(const struct iov_iter *i) return i->type & (READ | WRITE); } +static inline const 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. *