From patchwork Sun May 14 21:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13240575 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 D6937C7EE23 for ; Sun, 14 May 2023 21:27:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52157900007; Sun, 14 May 2023 17:27:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D11B900002; Sun, 14 May 2023 17:27:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34AF6900007; Sun, 14 May 2023 17:27:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 27D07900002 for ; Sun, 14 May 2023 17:27:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EF259A1263 for ; Sun, 14 May 2023 21:27:01 +0000 (UTC) X-FDA: 80790145842.14.00C3B36 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by imf22.hostedemail.com (Postfix) with ESMTP id 1C811C0009 for ; Sun, 14 May 2023 21:26:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="S/k6Ea9S"; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684099620; 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=6lZfZiVFWsAlcMWN5PRi30FiuIH4ExiR/doISXVhpnA=; b=Bk5I9CMm5yK3ZWkOqmOmSfhmlxE1/lSKMpVaWd4sbKghum1g/DHbNTjHsgDtKauJ5EdNFT M++t7ysoP+2r5IdBSsBz6JUXVqIG5cyvWlD+dYUzWkyFILyd56B7o4+5ezTRGcPnGAoLVo DoTV4qidGs6Tibd53FtmzPlj1bEBKkI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684099620; a=rsa-sha256; cv=none; b=dta09DGEMvp8PkyEa25zfQmSqWDLOW3sylEVLicHneooK7xG+gF+5s+GtfhMYn0zOfzwOl mCxE2Xax55Ozbd0CcBVRhZwdATTpyumhjYHjD3NQHdJtuuxAONDLefBRhgZlrb93tZIT17 PDkHxDb6eAas5YK3PBE+LTNY+jpM0F4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="S/k6Ea9S"; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-30786c87cdaso9252131f8f.2 for ; Sun, 14 May 2023 14:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684099618; x=1686691618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6lZfZiVFWsAlcMWN5PRi30FiuIH4ExiR/doISXVhpnA=; b=S/k6Ea9S7jTXAkegHdRNsYFunFJtyA0tD50ThbnkZoegODRr5kBExok5WQkHItiThy 9Eqit3HhgZkuqZV4o6mY1FgL3cOhKarBAgLlvy7XoFrsUNHYKuSScvJHno7LbQGZCSJL cBrDEg28rcrgcSohO93qC0JLzI4nT0W5ZizqecvOSJm1aw/HNhkd0n9haUp4X7OXZDhf pIn9jvFlyWIMW7YfXnnzqDAaYDey1Eeyv7BGnybQ19c2uJvcxJKmXwtrK2ijBLkqrwE2 OcSjIqGlL2tu6YE+rNveIHct+bjthi0raPd9ShK3wa4GpPLymWffn7c+Fva20QTttk3D mJgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684099618; x=1686691618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6lZfZiVFWsAlcMWN5PRi30FiuIH4ExiR/doISXVhpnA=; b=CZiSifLx3cuK5q+SRMmuQbOoJ2tjA+E7PR++tUmqqf0pijXPDlSVyACS5Ez5bviV1+ pOSCN2fwkypcXRkjSE6HY+QjcfJO/AuPr4plJRKaBML4PTDRZ8V9SiVZSognL0PvU6+T wcHh0a1wOiJauANCvEXS4vSbTNPTfJwZ9bFD9fw7vS3OJzwKjGMY1W2lescJSfHEAmtK IseQqGQ49ldYkjQ2V8RBkyBaxgpp+X8dtARRYeBjt8Rov5Ic0MhaHXm6xz0wtLFO+fSv m9T2h0RdVVhJFHC6W5ctFtqbiA+3zEh/9orxxtJb6HKllD3dD5vIjFYET71mGQuwn/Rg FlUQ== X-Gm-Message-State: AC+VfDxGvwMRTgUNbvFKDx4aKD6IL/AUAokuaMwnOlDxonVPR+DKiNnZ q8ZP159CIbsYEXMZ2mXuOK3oaFoZiGwvQQ== X-Google-Smtp-Source: ACHHUZ7xbzYrHEIBsBEOTfbuU9xONp4amC/jy4CMWdSN4lsoxtCis8o8qIA1MVHQab6pCBBaxEceNw== X-Received: by 2002:adf:f142:0:b0:306:36b5:8ada with SMTP id y2-20020adff142000000b0030636b58adamr24687541wro.29.1684099618096; Sun, 14 May 2023 14:26:58 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id z8-20020adfec88000000b003062675d4c9sm30253398wrn.39.2023.05.14.14.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 14:26:57 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org, Jason Gunthorpe , John Hubbard , Lorenzo Stoakes Subject: [PATCH v5 4/6] io_uring: rsrc: delegate VMA file-backed check to GUP Date: Sun, 14 May 2023 22:26:55 +0100 Message-Id: <642128d50f5423b3331e3108f8faf6b8ac0d957e.1684097002.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 57fcdjthtwqwir8x5mx6iztc6jdi1i3x X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 1C811C0009 X-HE-Tag: 1684099619-642310 X-HE-Meta: U2FsdGVkX19LaaE9QKL+/nk8LaqK7DosC4yaB3J7KvEL/xFOQx7GeypOnKP1Q74JS2RWHZJot8tl3qQWpzE5oTVb9G+9ofypExKUWPRBKNQm+aAfzUWRZs6KYmKMRnSRdWVpbg6NE7Otm8lLHxaCH3DSVvm/fZINTUIU/8Nl6MW0xMUDeFaGPk7CE79hsc08MzcYIAck74GbAVMt4at+7Ax8GRVPMEeiip+BtUDHRDInl5WX53m3/oyPXyaDHfd1HYXflc4XnfyaYG9HsfR1gvK91RnLOcKT+50vZQHOKstm2QQJxZDaZQvcqg5Y6yiAKkrM8YCrNjFgoK3PF9qnNbwfEtDHE5LxGeighoOsyrRlu4RL2mw7DgGbzeCgx7IUTrHHwAtKjp0MlxPQpNdFwTvOQOgmUZVdeT5nakvRamSafC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KaYYb22mQnVhDlW6tZ/yQnS 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: Now that the GUP explicitly checks FOLL_LONGTERM pin_user_pages() for broken file-backed mappings in "mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to file-backed mappings", there is no need to explicitly check VMAs for this condition, so simply remove this logic from io_uring altogether. Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig Reviewed-by: Jens Axboe Reviewed-by: David Hildenbrand --- io_uring/rsrc.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index d46f72a5ef73..b6451f8bc5d5 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1030,9 +1030,8 @@ static int io_buffer_account_pin(struct io_ring_ctx *ctx, struct page **pages, struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages) { unsigned long start, end, nr_pages; - struct vm_area_struct **vmas = NULL; struct page **pages = NULL; - int i, pret, ret = -ENOMEM; + int pret, ret = -ENOMEM; end = (ubuf + len + PAGE_SIZE - 1) >> PAGE_SHIFT; start = ubuf >> PAGE_SHIFT; @@ -1042,45 +1041,24 @@ struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages) if (!pages) goto done; - vmas = kvmalloc_array(nr_pages, sizeof(struct vm_area_struct *), - GFP_KERNEL); - if (!vmas) - goto done; - ret = 0; mmap_read_lock(current->mm); pret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM, - pages, vmas); - if (pret == nr_pages) { - /* don't support file backed memory */ - for (i = 0; i < nr_pages; i++) { - struct vm_area_struct *vma = vmas[i]; - - if (vma_is_shmem(vma)) - continue; - if (vma->vm_file && - !is_file_hugepages(vma->vm_file)) { - ret = -EOPNOTSUPP; - break; - } - } + pages, NULL); + if (pret == nr_pages) *npages = nr_pages; - } else { + else ret = pret < 0 ? pret : -EFAULT; - } + mmap_read_unlock(current->mm); if (ret) { - /* - * if we did partial map, or found file backed vmas, - * release any pages we did get - */ + /* if we did partial map, release any pages we did get */ if (pret > 0) unpin_user_pages(pages, pret); goto done; } ret = 0; done: - kvfree(vmas); if (ret < 0) { kvfree(pages); pages = ERR_PTR(ret);