From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8CC4AC6FD1F for ; Thu, 21 Mar 2024 22:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qoU13PGoZpDRXkHUBotxWowri83FVemOj7s01kOpx9k=; b=m62R/rW7PyzkZW fyMnmhxr98JYVOrvxYF86h47AB9kPbUJuYn/PY30ntp4VBEFk10sKd9AYlt8kqlth3VkpRxd68x5w NX1nhndeb8jxKF0vk+99k0KxPr4tdbGkqCxth+2ErwYay+IABABGwhE+Fjf2SANnpPmOqeYZIGqlq j1vqoiRlECjz0ZRvPycMCbRhdkk4wslGU++XSInc8Y2dIziA4fcWmy35Kh7nCwlwZRQWFtJUp9tI6 gRiFW4Rm3tMzrV2ISZ+LYz8AOvb3hdNPtPF8Nk46RWWoh3jqVKvNztmIInEvehMpbKDZr9lRg71Oj zCR3J3bF8UzzUBKaUnlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnQcJ-00000004rv8-1H19; Thu, 21 Mar 2024 22:10:31 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnQaR-00000004qas-1dBG for linux-riscv@bombadil.infradead.org; Thu, 21 Mar 2024 22:08:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=ha5DGM0IN3r6kIFCrMZt60pb/ho2ZGKh4AhFb2qqPrM=; b=g1MUvdV3W8YxFTpOQXPvVxbOFz 3LX97qUU8vfzXKD6pFDFDB3UTCUPw+dj8rG73zKVOgXZxs2bmO2Z7cCu56D5i75wadNGx7Kn++jYp e3EY4967XMhyoqqy6RSkrnupGkoy9LHvhLWqc1raue10UnGX9Xy22wiexjrzbczABvS8QEl37C7p0 x+jMIj3i+xhsZrY4hU2z9WOz1P0aCVUVjZJZNOL1BYSuY0EdlwPwJzr2protw62QG/UI1aWLIBCtY uvuA6aQGB1HJbvL5s7a1xO3edd/m02HIWL00yK8dNY/GXZxGqsNkiwDHYr/fDSs4LcYeLWnN89tdE ThKGcnfw==; Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnQaL-0000000ESZu-3l4A for linux-riscv@lists.infradead.org; Thu, 21 Mar 2024 22:08:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058905; 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=ckOUdmzDPoMlV6BrrHRXMzbwIZQpg350yNfe4fPr6sUofOytxXlRCgta8KmyAO6kIPWEyY emsuB/M7x3Iu412R86bpBHI5PR9HbMlk0gUAo1zn7+9mXIVyPy0YoP4H8rcu4VYriu7Dib 2FLUXXUkr2FE7ZJNqz74q1YW4u28wl8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058905; 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=ckOUdmzDPoMlV6BrrHRXMzbwIZQpg350yNfe4fPr6sUofOytxXlRCgta8KmyAO6kIPWEyY emsuB/M7x3Iu412R86bpBHI5PR9HbMlk0gUAo1zn7+9mXIVyPy0YoP4H8rcu4VYriu7Dib 2FLUXXUkr2FE7ZJNqz74q1YW4u28wl8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-xWdZ55pTMqGCZJ_o9LCD6w-1; Thu, 21 Mar 2024 18:08:21 -0400 X-MC-Unique: xWdZ55pTMqGCZJ_o9LCD6w-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-690d3f5af86so3056926d6.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=mQSN1Qk7lMwe6QmUZHqVjqC4rEBNKzvsYJzubtk01D6TFrpgI8VgDo4T+JuIJfmVX+ gtjL1C94C/Js2wTcDFd06Q5w9mqLpmkX0R47sq32wWXmj3p8Pdxc8by7QHzivI9B7khi vLF0m1CQvjL0vlly+6+ilkcHKXiosLztKzl6/elYhGStRyUE/x1VSZM5JtX/HMyZX4nb ZCckOtx3y1x8M1LodGL0DjcZ4mW4O7m/rjzgO4E4kg+yocHKPOhDBYkXTeVduxdoHXQ7 So9AqpdqhOw05jon8a5G9Jk9o4hW5rrQrlVlgLlBRqgMNhAuohY/j/sH45py0VH5scoG JNUg== X-Forwarded-Encrypted: i=1; AJvYcCWvn0ES/Zd3sDWhVS5Ca4DbSvFg6MbuFp4eQzWGyVn212IbgT4242iRSzCL1dPnkD49UHpCWMI8gpwKzk5y/K+/fL8gmU4BqUZkjzynj/c2 X-Gm-Message-State: AOJu0YwwuNAIdA3eHaV+fWoFwziCso8MtiQcjPZmbLVy+lUZxmcTQmQE 2jCRCEOvQYUNa5K4MtHPbcPVWW1pOaL194+5pBjjKNCwCv6DfKgVi6UbLupu1wS9hPEBuDeCMb1 go70tuI0YqapTieN8DQFPWFDDPDp4N7zc3gfhB09far0qgH6rHc9tg2U/gs/cUfGWig== X-Received: by 2002:a05:6214:3f89:b0:690:de72:316f with SMTP id ow9-20020a0562143f8900b00690de72316fmr214818qvb.1.1711058900918; Thu, 21 Mar 2024 15:08:20 -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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_220830_573486_B5681F9F X-CRM114-Status: GOOD ( 12.73 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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, -- 2.44.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0366AC54E58 for ; Thu, 21 Mar 2024 22:15:50 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ckOUdmzD; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ckOUdmzD; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4V10CT50Wzz3vsD for ; Fri, 22 Mar 2024 09:15:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ckOUdmzD; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ckOUdmzD; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=peterx@redhat.com; receiver=lists.ozlabs.org) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4V1030180Bz3dBn for ; Fri, 22 Mar 2024 09:08:27 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058905; 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=ckOUdmzDPoMlV6BrrHRXMzbwIZQpg350yNfe4fPr6sUofOytxXlRCgta8KmyAO6kIPWEyY emsuB/M7x3Iu412R86bpBHI5PR9HbMlk0gUAo1zn7+9mXIVyPy0YoP4H8rcu4VYriu7Dib 2FLUXXUkr2FE7ZJNqz74q1YW4u28wl8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058905; 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=ckOUdmzDPoMlV6BrrHRXMzbwIZQpg350yNfe4fPr6sUofOytxXlRCgta8KmyAO6kIPWEyY emsuB/M7x3Iu412R86bpBHI5PR9HbMlk0gUAo1zn7+9mXIVyPy0YoP4H8rcu4VYriu7Dib 2FLUXXUkr2FE7ZJNqz74q1YW4u28wl8= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-Fep507ZnPuu3GnFTgtiRjA-1; Thu, 21 Mar 2024 18:08:21 -0400 X-MC-Unique: Fep507ZnPuu3GnFTgtiRjA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-690d3f5af86so3056876d6.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=QL0Rzwry/Id3h3onHjg1Toygq4ufmdbl3V+crNLv5Csu7Pz7Y89aU+BcVvMfeauH3z 8U/v9BwUM1DFthD6pEpcexFu3X+WLS8dJEIU8hDxHU4hv1Xopo1u19Pc6xTMGt681Fpa oGsXrXO1ryGNNX4AJZZmIopuouMsfycNk1r5LnTVnFg3J5FSjHdaylOr9qakuaIB15j1 0QJgNM6Hna+o4RNtzqUkrtMUUXZSMZKJVixR/jOj9txv1poTlUbOejSuAnB3vQy1YM2h ASaVyjyQXuXl8BY/BbF21AAOJW/YFqnVFDHORC6Jb3EPllg0jKJkkKcesNg93yy3GduV 32gg== X-Gm-Message-State: AOJu0YxjS9y+EKdT0vnDIZYxMOEM1uXCojUvNXYV6h4gXAZUAgzqprmE SE9I/xEHzZL29AHtsLhhZiKLwU04VtWm7uLhk47Ahxu0tkekGpsybjhrZUNS5e9orJoEjJoBxQr 8qPTJz64oy6xJwOXD4cb+tqArEYM/5YhsE62EIUfxhzizIa9kUn0V4MtYUwBtOhs= X-Received: by 2002:a05:6214:3f89:b0:690:de72:316f with SMTP id ow9-20020a0562143f8900b00690de72316fmr214836qvb.1.1711058900926; Thu, 21 Mar 2024 15:08:20 -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 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: James Houghton , David Hildenbrand , Yang Shi , peterx@redhat.com, Andrew Jones , linux-riscv@lists.infradead.org, Andrea Arcangeli , "Aneesh Kumar K . V" , Matthew Wilcox , Christoph Hellwig , linux-arm-kernel@lists.infradead.org, Jason Gunthorpe , Axel Rasmussen , Rik van Riel , John Hubbard , "Kirill A . Shutemov" , Vlastimil Babka , Lorenzo Stoakes , Muchun Song , Andrew Morton , linuxppc-dev@lists.ozlabs.org, Mike Rapoport , Mike Kravetz Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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, -- 2.44.0 From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0131AC54E58 for ; Thu, 21 Mar 2024 22:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QS6RVVFZo8O9VIU0qAGz4DmS0s7SDMAQm+E51XdHk4c=; b=RCv+RRKX5rw1Te fekuMbuEP5bGvDdpU9NaIFpulvEIgYH9hXzK+MSgJkR/k3w011RxvDumSsPT6DaGFUuPcg6RYS8IR 1Zb9psj6KIJ3FkZMbxCgS7uZ+9wB1HgooFFwDWjPXSUFqOiPQAg1ymbwRyHzVu3IglGFLcSg+9tHT VCueENEWepeTHxSnnnQQg0nGR6pcSriW8t+UWg06yR1slhdgAyvUsd35cKpR0UzWOzQopah65pJpF GEe6FdA4Rl6fD4pTyiUkO3+Z/noVrCYdssVVxdgRqKcSHtqpgkALGceJo3LU/Fx3NKjI7NoMSJ0K8 OHAnG/9kKkZsPb6izImA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnQbu-00000004raX-1MPF; Thu, 21 Mar 2024 22:10:08 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnQaF-00000004qSP-43qR for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2024 22:08:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058903; 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=WYbQULvCdsRYKlKDD5BP4GY1KzA7plXABU5GPnzQiK7z+ptsckKvti3JLcWw99lxR8Qx2s 5xqj/ytGLXplvE9wujJxHDYL4nVuhImK5ItB3Jwz4tXIM8C3O2T2mAjJqZ0P8MhqHleiyQ jYsc16IhehAIAr0YfQRok7hL+1iztkM= 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-619-acTDasCoMxSJ3h1SgGRFjQ-1; Thu, 21 Mar 2024 18:08:21 -0400 X-MC-Unique: acTDasCoMxSJ3h1SgGRFjQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-690d3f5af86so3056956d6.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=ftc/gFC8Y8gc06UllNn4455ixtckxPkaqZ1VsgDS1IkLdNWm9gcy6UkYBHlK/fzKrn umrjvbqdE8gOduxczVLJFLy7wvU/zuFnmjQ6psfQ9dmUJ7VOB1o7TZ5QVMYxwf3VFNfL xuOU7j9omba2Uof69Trls7zuaDqe9cyWjw7LjweTHkbXTicEiymoMq3zDqN58Fmib3aN Uj5YHP6TpxXnGL/GovdJ6SmdpVWiG8P7EFv6hKsxPw477YeO/fQwxD/ir6seSOd1byPz f6R3A4UVRN/UDkvGBy3+tUqD3oLtXQCnJ0Ktokpc8pN5yrBYNdm2A8qUPJfKVyc1jwgJ 7E1A== X-Forwarded-Encrypted: i=1; AJvYcCVd/h4Mld90VaWPZU3Cw+T9EvhjOAz4N9qLSMud4VdGHodK35I76YXy5JB4hjv4hzBcP4iP/cFHDfb0rnJAtJ3rFhcWOzfsFnF9w5cUllt8oAQXWAw= X-Gm-Message-State: AOJu0Yzo2exZUvwXmVJGNK40kGGgHEIOFzCqqaNcjl6oFeyftTl7493S bsRfLWCLqcTjctPoaImCEbK12Il7ZLNd50pdykfthXzstfD4QSS1+rCnGg8L2Tumatjxi6RhZWB OJUwRSBnFga5JCTeY40cfoLdSisrJdqGLl0YNWcAhGrWb0+aaAkSq5zBi0MiqeYU/F7d16eBI X-Received: by 2002:a05:6214:3f89:b0:690:de72:316f with SMTP id ow9-20020a0562143f8900b00690de72316fmr214834qvb.1.1711058900924; Thu, 21 Mar 2024 15:08:20 -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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_150824_714856_2F51A516 X-CRM114-Status: GOOD ( 14.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, -- 2.44.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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, -- 2.44.0