From patchwork Mon Jun 19 23:10:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13285011 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 BE495EB64DA for ; Mon, 19 Jun 2023 23:10:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68EF18D0007; Mon, 19 Jun 2023 19:10:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6174C8D0001; Mon, 19 Jun 2023 19:10:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 491A68D0007; Mon, 19 Jun 2023 19:10:57 -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 37B528D0001 for ; Mon, 19 Jun 2023 19:10:57 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 084E51A0498 for ; Mon, 19 Jun 2023 23:10:57 +0000 (UTC) X-FDA: 80921044554.03.E93B8B4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id ED9492000D for ; Mon, 19 Jun 2023 23:10:54 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dHz43Dvs; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687216255; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G5PvpMSc9PWeUNzovzE5WASqMyhgs2MBMMaZX0mlkro=; b=1VCrKra4fNzQ4w50UCZBR877Er4ZyXH80xZAD44+typbKFrcTeK65YRfZp83ZSBDZkujJ3 XNOPmgrrLfx7K7sLtnRC+cJFNcIJiXSkEzxCFf/3FMEW94Jyk46s2+pfG5mjwjNZTPoKUl LhDZR9JmIqtwsPsbDhKwtxS2OUPQ8fk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687216255; a=rsa-sha256; cv=none; b=if44t2r61LW0BhdxyJOUAmQHbD5R/Nn0wCekR3fAcoU6D9cHgR4JN2biSwJ8+IkpF52lO3 wD94zrdDK1RY137zH/XwDL32F4DakOVzysIPup9L8pEhmEKODbJMjkKt6WA8Oxd/WDJihw N27ygjc1JOOH1JzHF+z0ZCuf1zGsFCY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dHz43Dvs; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G5PvpMSc9PWeUNzovzE5WASqMyhgs2MBMMaZX0mlkro=; b=dHz43Dvsm4fBhwFd/2fhq2lpYbl+k9ATohWF3W8ZX6EEm6H6XbBp9+GIHdtb3Oy12bslfm pApvNUmrTsBCMWY0jtvm+iyGiF0sZMvHJrfvdo//H4euTi3WqxKHWtdIYg4z37A3DqgClf yvXMJj8995aobP/xeXWQZneS1XkyHMQ= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-Ap4qN-SHO-eY3drogcSGzw-1; Mon, 19 Jun 2023 19:10:53 -0400 X-MC-Unique: Ap4qN-SHO-eY3drogcSGzw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76077669a5aso105210885a.0 for ; Mon, 19 Jun 2023 16:10:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216252; x=1689808252; 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=G5PvpMSc9PWeUNzovzE5WASqMyhgs2MBMMaZX0mlkro=; b=euoBt+g7/uO9Tax/Hlcrx8WTPlbu1TbbtJszUdaL681eYVjL1msiqsp+RHC/CxoX+P kf9CbpfZe2WO6POGlvNFbSG1soimyE1sf7o+h+Wlf6SLHosZKCp4hN4ZsWEPtiohLIwO MnVqGw5vaNlLVJh8IfQk2thQddNKvGjYN4VTwTbqaqoWi/8qgNSB3bpxhQ0tBM7s/nm7 FUYNKJnphuoFaZ2/gcL7HaTWNY4AufczFShlD8UKzXaD0CtyQPpxNMQcfv8G9GIzD10W zmVpCWZnHLGqfbLvz9cxKZww4nFQ7PCQA/p0jHeERuuomAQFuzrYH4fiCfK/xXk/dDBD 6MdA== X-Gm-Message-State: AC+VfDyTgcDpyZOPKGGZLxfQgyP04h7KTQuReNJZ39DI/62eRBgiXJHe ArYpBh6yaPejAxXDP33qVv9A8SVcwdRO2STEZmVHP7iGc1cc8PuYHvLljH5JyqpawZ2GyWp2bEm Zr0lqXc15zd0QfqlBcZ1ghPfnKYH/16Otk8tKzPlm8zBT9nQoclY87S5bXh8CzxfIqUx9 X-Received: by 2002:a05:620a:800e:b0:763:b025:9f40 with SMTP id ee14-20020a05620a800e00b00763b0259f40mr146902qkb.7.1687216252621; Mon, 19 Jun 2023 16:10:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gUaxPapWXj9fyTcJWWnL1Kgv2ncFDRbyXTEYoD6E6DhEtoWY/2AMdIngB3HsMpWlNRnZ+zw== X-Received: by 2002:a05:620a:800e:b0:763:b025:9f40 with SMTP id ee14-20020a05620a800e00b00763b0259f40mr146867qkb.7.1687216252208; Mon, 19 Jun 2023 16:10:52 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id t15-20020a05620a034f00b007592f2016f4sm405864qkm.110.2023.06.19.16.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:51 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , Mike Rapoport , David Hildenbrand , Matthew Wilcox , Vlastimil Babka , John Hubbard , "Kirill A . Shutemov" , James Houghton , Andrew Morton , Lorenzo Stoakes , Hugh Dickins , Mike Kravetz , peterx@redhat.com, Jason Gunthorpe Subject: [PATCH v2 4/8] mm/gup: Cleanup next_page handling Date: Mon, 19 Jun 2023 19:10:40 -0400 Message-Id: <20230619231044.112894-5-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230619231044.112894-1-peterx@redhat.com> References: <20230619231044.112894-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: prioged9poxmyf571h68k5dx8n34yjos X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: ED9492000D X-Rspam-User: X-HE-Tag: 1687216254-508412 X-HE-Meta: U2FsdGVkX1/hu2tEcfgSw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R5jjn3FpXxKbgHs38/JUZpFoW6/fhbM3RtKTLYBI8f8nhuIlGbWj6XdN6zI8k4ytaki+9Dvstzs8audqEb1Yijx21APDSQqEE1/bB4NtAl4SI/s4IULcU0u+tQ02jy7OE9yWA2TzKfoityKbt6E2ociWa/UpeZ7DG23fXSMLrV0IJdWdJ0zQ9LsZ4iGDaopnoIAv+PrFHcL5FBttgsEvIk7oLxzObD4fyAWSvfwrxP5JhKQ8LJEtcBYDNkm9PbrFLFTfvvsQKxUpGA5NbIoogzVHvxvQVawwzGiAdWtgVnW32SAmI705ULUCptO05sF49t3ehlRfKZrnaXFQbrJbLIrxUFnbOX4A= 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: The only path that doesn't use generic "**pages" handling is the gate vma. Make it use the same path, meanwhile tune the next_page label upper to cover "**pages" handling. This prepares for THP handling for "**pages". Reviewed-by: Lorenzo Stoakes Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- mm/gup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 9fc9271cba8d..4a00d609033e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1124,7 +1124,7 @@ static long __get_user_pages(struct mm_struct *mm, if (!vma && in_gate_area(mm, start)) { ret = get_gate_page(mm, start & PAGE_MASK, gup_flags, &vma, - pages ? &pages[i] : NULL); + pages ? &page : NULL); if (ret) goto out; ctx.page_mask = 0; @@ -1194,19 +1194,18 @@ static long __get_user_pages(struct mm_struct *mm, ret = PTR_ERR(page); goto out; } - - goto next_page; } else if (IS_ERR(page)) { ret = PTR_ERR(page); goto out; } +next_page: if (pages) { pages[i] = page; flush_anon_page(vma, page, start); flush_dcache_page(page); ctx.page_mask = 0; } -next_page: + page_increm = 1 + (~(start >> PAGE_SHIFT) & ctx.page_mask); if (page_increm > nr_pages) page_increm = nr_pages;