From patchwork Wed May 17 19:25:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13245602 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 8C021C77B7A for ; Wed, 17 May 2023 19:25:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A59F280004; Wed, 17 May 2023 15:25:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2559C280001; Wed, 17 May 2023 15:25:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FAFA280004; Wed, 17 May 2023 15:25:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DE803280001 for ; Wed, 17 May 2023 15:25:48 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A8646AE046 for ; Wed, 17 May 2023 19:25:48 +0000 (UTC) X-FDA: 80800726776.03.2F8B1DB Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf22.hostedemail.com (Postfix) with ESMTP id AEEF4C0014 for ; Wed, 17 May 2023 19:25:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=dcn4x8zm; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.52 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=1684351546; 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=IDPgbDXgNpmFaT/Xq61rTSESXh922Cqn8VFjEHQlO/U=; b=kkgTTN1JRIgDOFYjc0fGXZ8CvGlxbqf/hVA/GlDorYNlRy0or2wPShH+1GF748habNQ3xI YRTegftkRLOGlGuRgl+zPLZHq0EoPyv0MjOH1pObjkSyap+uEUr88ofmW0uGm79t/Dw/Dk c58UAAegaUoq3FQq9VeaEHpBR/DDhkU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=dcn4x8zm; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684351546; a=rsa-sha256; cv=none; b=vd2C1usMUo2hVCkEiE7j67J5GXrq+SY924UhTvZMZfmXHRsihV3EDk7P609ejCgedJDqqh u5P0FCQ1qnBRWK3zm4QMkFMZhWPMuEmUDiyjnG/GsVBFUYZJcANy6wAXP8z5Kaq2TLHtwn koxPw5Spv2BL2M6kmjTpKfbGnvMhG1w= Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3078aa0b152so821854f8f.3 for ; Wed, 17 May 2023 12:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684351545; x=1686943545; 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=IDPgbDXgNpmFaT/Xq61rTSESXh922Cqn8VFjEHQlO/U=; b=dcn4x8zmZYzMdxqkxin+0Kp7oATcck21D2y26zDzpSXi6bO9bOBrwUasI9ojQYvRQA Zi713T2NPyPIzQBAXspWoX4abLIAfZM/Hag4DsUoyq9FLSKw83Xnw4kJhDkspxU1p62K vVaoFNdRZIAhuKmQttjFmCmDyC572QHulp1NowyT8iq/Nvyci8UUJp55j4wCgmf0x+HA NC0uwt++BTCQqq8HDts1cBcme23dDYfw3Tg0t0eNYYibcHvjK+2B2QjCBcx5Xjgtwhr7 qtiINwWlapVJ3KpKa0fevqyxxIICgFQbRh/pFOxP564gguNmk1v+f2g4r5eMslZkWV72 e5Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684351545; x=1686943545; 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=IDPgbDXgNpmFaT/Xq61rTSESXh922Cqn8VFjEHQlO/U=; b=GuwQxBI4nNq6zbrrgpvQjikvHT1FZsf7KvviyRTU8JawXRDRmPjOZep+vJrdb+F6Hm lU9V+apDK9/g6K4A5NRMwkePuFOaUTlJXqpBx550xEESUPd4Unbg7KyDIWwN69SyezDt 7hXNge0xK94YLHqq/dnlZE/dVM5Pwo4OCrBdljxCpEfvWL+XImglakGhFBpoqtvmBkrx GZI4RFzXB7VW20K3LVYkmu0S7ysL4jE5NqqvtApILO9Ve46JqwJlCs2J4ei+vBM4SjeY HcRRnZD120IaybB166a7czdLWtt7hQacfir2zOixVqeBn+2/kgCQKtTOjkae9iisy+2u 06kg== X-Gm-Message-State: AC+VfDzHCSVvIda/BfC7clgumMIvaxmAJy7aDU1EuQ2Ad3sS2F1D6x1o krVewN0h6FqQWBJPSZ8jlXkVA+QhLj0rgw== X-Google-Smtp-Source: ACHHUZ5gUIunrgcLQA5O73BeJ9za8lFR9tf5MVp4yuOnPxdVTT9mfQ+v0R4XrZy+Pi+kpOanAXPPSw== X-Received: by 2002:adf:e58a:0:b0:2f6:a8dd:f088 with SMTP id l10-20020adfe58a000000b002f6a8ddf088mr1148050wrm.62.1684351544804; Wed, 17 May 2023 12:25:44 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id f26-20020a1c6a1a000000b003f4272c2d0csm3076037wmc.36.2023.05.17.12.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 12:25:43 -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 , Christoph Hellwig Subject: [PATCH v6 4/6] io_uring: rsrc: delegate VMA file-backed check to GUP Date: Wed, 17 May 2023 20:25:42 +0100 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: a5kas787dr8pw6qf1nw16w39ttgafnqa X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AEEF4C0014 X-Rspam-User: X-HE-Tag: 1684351546-576236 X-HE-Meta: U2FsdGVkX18lP986o4/boZ5UOKy4M7FBz8ih75CCnozGQ2nv6yhrREuBSvsUhg5nqCJtaXMSRyjiyx0J8TqBi6vXufcWdrBHnfpDMmvl3Wh8gCLnqFeiR333r8JNr2epLEtvKdOwFWplTKxkUCmGUnY/PXDyiFeTVCBRU3PHd14C1GsUUcoAqIzArwJDCcQLan0KKP7aclUhGcil4hyRPCY3HkSkWUZZw+rsgUMoxwWeX3dtPU4s+2bcNPxEJFEoX52wbJBqkSZC2j1NhVDMkv/pPpgsSsbCBDhgjbOzaR0fJE7TMtVhY34hI1FCyAn2eO37zadbY3sSu3w3g7Ddt7QoAalwm0Vf5s+agqKnvZVBwwqOKPPmzTifWXy9QZE7mCkBu7+XYXfEooAzWdSqwwG8iNAgVRAYZnCUOIyOQJm8H8+ZxGFvvHCRMsYNfvEhZ/NU3/7YtYyTDMxrGWOvRic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k7Fk8dwkQml4XHmAPV2bgyhyP2LmnkI= 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. Reviewed-by: Christoph Hellwig Reviewed-by: Jens Axboe Reviewed-by: David Hildenbrand Signed-off-by: Lorenzo Stoakes --- 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);