From patchwork Thu Mar 21 22:07:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13599412 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 8017ACD11DC for ; Thu, 21 Mar 2024 22:08:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BB2E6B00A1; Thu, 21 Mar 2024 18:08:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 644AF6B00A3; Thu, 21 Mar 2024 18:08:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 449636B00A2; Thu, 21 Mar 2024 18:08:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2C9156B00A0 for ; Thu, 21 Mar 2024 18:08:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 03102A02CF for ; Thu, 21 Mar 2024 22:08:26 +0000 (UTC) X-FDA: 81922435854.24.A919B6C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id DB9CC8001D for ; Thu, 21 Mar 2024 22:08:24 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="e9d85gB/"; spf=pass (imf02.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=1711058905; 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=ha5DGM0IN3r6kIFCrMZt60pb/ho2ZGKh4AhFb2qqPrM=; b=nPJGb3ZMqrW+/qY4t0nKf1UKm051U4cUe1i4fB3Hldh8/fUMyjA0pDVcvd1geH6+BgPWxv xmJRhSNSiZn6Xv7eM6U1mOeB3t+errdSL5kvOv3livESsRbRI5b7/qWoiN11YTO/usBtN3 ycgvNvwooXRNwviD1shHNET1NKIN1qQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="e9d85gB/"; spf=pass (imf02.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711058905; a=rsa-sha256; cv=none; b=0AokjeQuKkwPuztmTk/8Aq80POOrKjU2/faA1yPlWkpRK8AzGfb6rpl8kzWj2im3nHE1q6 fc4yv+UmEJLbXvp33xxTui7/eKurb0IzPaRE5y61DFNGVCcobzvMJvUOakrU3c3dv/njVx BpJ/B5g4zm8sey2Isgx4fvkDxtNKVFQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058904; 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=ha5DGM0IN3r6kIFCrMZt60pb/ho2ZGKh4AhFb2qqPrM=; b=e9d85gB/q6xwWvHBnGgiFbZDtRuFI5RrBFwqr5vPp0DoSwRtq8PqA0pEeMbR1ue8bf3JMM OBpiZDGQC5jcL8RfkXaKj50xyNbggIGFeycxaOtduv0UgwvjfzU1Ly7hyGDxM3Be4TMMB7 dXV5yMYEsFgvmGVhg4uCFyzrcxDI91E= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-oWtd4jeMNv-qs1WIFWmAfg-1; Thu, 21 Mar 2024 18:08:22 -0400 X-MC-Unique: oWtd4jeMNv-qs1WIFWmAfg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-690d3f5af86so3057016d6.0 for ; Thu, 21 Mar 2024 15:08:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711058901; x=1711663701; 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=ha5DGM0IN3r6kIFCrMZt60pb/ho2ZGKh4AhFb2qqPrM=; b=YPjmu8C7uNn2qy9LOEZBd/P+DFWuzBS0KUsc8zIiujTzwhLC9r2E9QV5HHxsJ8CftH 6NUeHH3o4r1N4pXqFPh7as5Chr+FKiHLnFbr0zfrut5Njhxj53eZzxAzzGNd0m5OFe3k bvexFPeHbr3HUrz5BTvWHr/z6YMStPVLBut/H2bUnmaFEg51q/3PkbQ/NamoB4dCba+a gBwYX6+9a9HBD8X/GRvrUrN2BFyPDDA3IFHS+0XVIJZ+Nm9nvYOBvvYtJP5np59kHiX8 3/ktdAQW+p6qNMg3TWPaAkd2cWQMIg4OVECwAYDC9jpqFiRV7efYogK/EIjdZViMSboA oU0A== X-Gm-Message-State: AOJu0YyizpZXzSPzE3rbnWlwYUNZRcKIY6CL/AUwtrhnln7MpgLi8kNm rcdWECaLXXBvWjHqwk40WrU5l3YW13EnJ5HHa8A7Acx8JUPk+o0bFsNwEKcHnxwJ90Ku/HZNm0N Z5VkvOjM6gXteKy382MVWwc2CkDhXsJf8pih2L7fU/h1CvUVjoMQGQ8NENsSTZQRZc51ViCevxx JoMgwJtgQqaCKeNdc6CnOhBZsGchsXNw== X-Received: by 2002:a05:6214:3f89:b0:690:de72:316f with SMTP id ow9-20020a0562143f8900b00690de72316fmr214840qvb.1.1711058901004; Thu, 21 Mar 2024 15:08:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9Op81dSYI2sDIbFIL6Ox+mlvTFr9echbLfQb+zyBeeZ6FRPjC6M2m9xSIjZkrEy5V/lebFg== X-Received: by 2002:a05:6214:3f89:b0:690:de72:316f with SMTP id ow9-20020a0562143f8900b00690de72316fmr214791qvb.1.1711058900463; Thu, 21 Mar 2024 15:08:20 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id o6-20020a0562140e4600b00690baf5cde9sm351663qvc.118.2024.03.21.15.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 15:08:20 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Christophe Leroy , Matthew Wilcox , Rik van Riel , Lorenzo Stoakes , Axel Rasmussen , peterx@redhat.com, Yang Shi , John Hubbard , linux-arm-kernel@lists.infradead.org, "Kirill A . Shutemov" , Andrew Jones , Vlastimil Babka , Mike Rapoport , Andrew Morton , Muchun Song , Christoph Hellwig , linux-riscv@lists.infradead.org, James Houghton , David Hildenbrand , Jason Gunthorpe , Andrea Arcangeli , "Aneesh Kumar K . V" , Mike Kravetz Subject: [PATCH v3 08/12] mm/gup: Cache *pudp in follow_pud_mask() Date: Thu, 21 Mar 2024 18:07:58 -0400 Message-ID: <20240321220802.679544-9-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240321220802.679544-1-peterx@redhat.com> References: <20240321220802.679544-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: DB9CC8001D X-Rspam-User: X-Stat-Signature: 8se64j8yqojbbkfetzcpsj5ok36k99q7 X-Rspamd-Server: rspam01 X-HE-Tag: 1711058904-664370 X-HE-Meta: U2FsdGVkX19mIYa5gTF6tVSePBUlSkL1nBHZpiPOBHHFBxLehw9AwfqivMqXQLQLM0e5vVWSkpKv7cpJBwd0ret2IRNhxPOsS332a2phteZZwq/m0/A51ckTW1RddA+3RoLWJ8Cnxn9QjLQzLy0RfVqNLrBlgGJRY+zw/2zd5hGTm5cFBCEwfnK3O6uCpWPi/brsB7o19e7XlDL9e3LOddTAHkHWMogv+gIxX0Q223C/11iJfUgsp2h57GT4q3rKUdaitAMX7whXU+FYEh3PFF1IcqM695PmF/qjB8ug5+74ke61aTJTqbXksgML/1my2d1Tza97p3tmKMT7gVAhUtcKNgsJ7KA+KheZoD6/K2SXVm6fd2f1DVsfcVo/n5xzhvu9nhi0CnP85nzG9ZDIdXyVSBSYDSe8DmrCPVCwcr+M2fZ7aSZKHGyFSkPvXX3IjKDHX3T0aFY6XUePxEh9zlN9TYzHuJGupjK2InBQf8ThGgXg1EXIyZWHitBaMTkBp6OMVHUa0k8glGVOaPYyWNA9qEwYL03Nsz3jqXPUACQvgilBwWBWB+8fA8wHJC8RsSZosGBKkp01k3whm89TvbMcA0K06b4UEH1sZXUbjwbx1/P09FeVD4Mo0fgUQhE+WaKCuut+13CcrGH5zndQqFaPQg5U1KLSp8BpFKUypQ36XdR/w4IA8RdGK61pEVuXnkoXlhYbL4xOxb2zXMJJZmPNTAbgoLqJjYiUmKBuHS8bA/lCJYScQG8ffcwD2iY92ikgzzhVxZx06rR9ZtGxk4UQ2CpL0aWsqAY0ssuxafCoOFHaePuWoQl4LSeytKf0dSLNTAIcI0ngGc27IwuAXbGL7gaUhOg44QNk8Q6Q/UCtNcDtAhyRC79B2RYi81m+X/y5o63whdndfSEgS2lobi+xcrzYG24tWChoCmUZSdZIw36S/irEX+KrzhcnCacLryTxAQKqZ3DvrdUwRjv Shahkg8t VefYe8QXJMnTO0aI6uUvGrxpNPzIYblWUT9ONDMPw7wpt9iycTRiO2i2a5oy7Kt8d4Avrf36ASoKdIZQA1ZilZf/0MJa8RA9bVVxHTnUzN1RPz1Qx558AqJAkGOBTfPYIz8CHsE1f3Sg1EC8xMS7Afbte6Y7sc/vGJLKcZUmvswTiQHMc3plcL5wNOZ6/S/XQMajlDuFDD5hBBYLAYs4XXikE15fsyK53IVzSLJlsBULpLtJsZtVNH8c35HU4MQkniYlVXV4DaXWLZKR4ECV5SFChDJ5M+N1aa2ZIMaH9NX1Cjuh9Ns1+8oEPgParnMZoG9VeMldOKhPdxky2pLRw8x3fv3Bgrf3e0toZZNU36Xim1kLOmylEdl0i95SwA3s4yMbl0SJQNqaolV/dSs0+YxdV6256InfidEFtFM9uBS+DZv/UWhWCrLHQ7jSF4Z5cacheEhvbvUlveiNkWwzsGO2jI4Yndf92XrBf 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: List-Subscribe: List-Unsubscribe: From: Peter Xu Introduce "pud_t pud" in the function, so the code won't dereference *pudp multiple time. Not only because that looks less straightforward, but also because if the dereference really happened, it's not clear whether there can be race to see different *pudp values if it's being modified at the same time. Acked-by: James Houghton Reviewed-by: Jason Gunthorpe Signed-off-by: Peter Xu --- mm/gup.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 943671736080..a338944e4425 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -753,26 +753,27 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma, unsigned int flags, struct follow_page_context *ctx) { - pud_t *pud; + pud_t *pudp, pud; spinlock_t *ptl; struct page *page; struct mm_struct *mm = vma->vm_mm; - pud = pud_offset(p4dp, address); - if (pud_none(*pud)) + pudp = pud_offset(p4dp, address); + pud = READ_ONCE(*pudp); + if (pud_none(pud)) return no_page_table(vma, flags, address); - if (pud_devmap(*pud)) { - ptl = pud_lock(mm, pud); - page = follow_devmap_pud(vma, address, pud, flags, &ctx->pgmap); + if (pud_devmap(pud)) { + ptl = pud_lock(mm, pudp); + page = follow_devmap_pud(vma, address, pudp, flags, &ctx->pgmap); spin_unlock(ptl); if (page) return page; return no_page_table(vma, flags, address); } - if (unlikely(pud_bad(*pud))) + if (unlikely(pud_bad(pud))) return no_page_table(vma, flags, address); - return follow_pmd_mask(vma, address, pud, flags, ctx); + return follow_pmd_mask(vma, address, pudp, flags, ctx); } static struct page *follow_p4d_mask(struct vm_area_struct *vma,