From patchwork Wed Mar 27 15:23:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13606790 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 AE8A1C47DD9 for ; Wed, 27 Mar 2024 15:24:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E13426B00A0; Wed, 27 Mar 2024 11:24:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9BE66B00A1; Wed, 27 Mar 2024 11:24:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC7896B00A2; Wed, 27 Mar 2024 11:24:00 -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 98A856B00A0 for ; Wed, 27 Mar 2024 11:24:00 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6DC34120767 for ; Wed, 27 Mar 2024 15:24:00 +0000 (UTC) X-FDA: 81943189440.04.9D09155 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 58B1D40026 for ; Wed, 27 Mar 2024 15:23:58 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eey1M4R5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711553038; 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=0ClTZB7edrSwahK3rulsC63VROBcD1QOdNuRXa61Ddg=; b=jGC+pi4jabcEo+O+1RkKIOiYbaCYQURKKYTaH2yAmS2mTTeG2Kk5DrnP7M/H5oqF8nIxCk L+Xnrecew7rMsmMgz7071l9vFiqlPC85R1a6+o7SBOVbA0UFimH+fI3T2HZkwI+Ed0RmiT IUivXMgPo7wO7PW0uzgu+2z6WD5uvtE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eey1M4R5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711553038; a=rsa-sha256; cv=none; b=FZGxuDIXJunZyz50FogRaVXdsSwUDbFQB5fGTxePgRYbqt2daV2apsa5fuN8sDpXiz/jny lnfJvOFc8WfRTsAQtasfR1CbeDF+oSujzp59m420aQ3i43xid5hKwIG9dWhRUEZpZaOiim JieWncBtkKso8TKyA3yN/6SGZnyd2mk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553037; 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=0ClTZB7edrSwahK3rulsC63VROBcD1QOdNuRXa61Ddg=; b=eey1M4R5QdNvghzCyAdpKgxR3UFQrRHlhz9ErR5bJO0cPAVauYXEwkGN6HpoM+aBd2wFoC 9wWwEbFNUz4HELmc1fbrJj3MTjTXVnOwYJobAwPCNJH7XJatZhm9aJmpUAyKkjBVnpaElq OCsQp2h8LA6Ph/R33xnjDmPxFILHH+o= 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-70-D6PYM3rFOqK5OvUKrE_gPQ-1; Wed, 27 Mar 2024 11:23:56 -0400 X-MC-Unique: D6PYM3rFOqK5OvUKrE_gPQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-69672754479so14007386d6.1 for ; Wed, 27 Mar 2024 08:23:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711553035; x=1712157835; 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=0ClTZB7edrSwahK3rulsC63VROBcD1QOdNuRXa61Ddg=; b=QcV5E6ZHuyBSI79Zvwxr35B+NS4kGH2V2oS6eIyFck1jRmcV10acspgmfnwZjfuTaM oKGJgBAa//OdxK01aZZR0QjTtZtPuv4OLMiaSeKVTzIl4AxwKpJVxRv5jEmD8uRLLBmZ uEZ8ULurRxB98ozurCTAa+guu7sL/+an0aXAdXAs15j96RhGc6s/Tgkmhx1EfvxvR7HW rerzMcaKvCaRBBI1Ex0sgTgnijY+DaebAN7dRKKyLwuA2xgyG+HA/YUtN9LOpo55aMdF fjGZx6DDaT2a1qYYDAN7M8Fe9Ev1lasIY4O1JSq7QeG6osQC6hFa7lQyy3Xw34Z8Sa8t NsPg== X-Gm-Message-State: AOJu0Ywkyx4hQJl+wpNPQR+yT2Ykrh20XpbZCqGtHU7WQ++6E/uQejBC AwBPSx8XMplkcQ+R8qYLa4FBL3gWFujlqf/M1QZiJwciS0dpGmv6bvMkQ4gx+ntDSoQgC9vmNzI 6gfIFkxJnTxpgB+A2gYalLJdHtU3hUF2uQg9k0ZOXIddxGMq7uWjv72uL5Vmu+mJl/FEq3HQ4kU V215g63xOzYEJcscpZWSV9SSUZdiox1A== X-Received: by 2002:a05:6214:3d8c:b0:696:1892:c19f with SMTP id om12-20020a0562143d8c00b006961892c19fmr15035567qvb.3.1711553035194; Wed, 27 Mar 2024 08:23:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFT3GjlhPAIM0f0tWP3PNax9bFYBunh5winrPqMP8FazkZOSJ/P00xdKeX4lX2Up3S+10Z8OQ== X-Received: by 2002:a05:6214:3d8c:b0:696:1892:c19f with SMTP id om12-20020a0562143d8c00b006961892c19fmr15035509qvb.3.1711553034516; Wed, 27 Mar 2024 08:23:54 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hu4-20020a056214234400b00690dd47a41csm6412639qvb.86.2024.03.27.08.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:23:54 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yang Shi , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Michael Ellerman , peterx@redhat.com, Andrew Jones , Muchun Song , linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox , Rik van Riel , linux-arm-kernel@lists.infradead.org, Andrea Arcangeli , David Hildenbrand , "Aneesh Kumar K . V" , Vlastimil Babka , James Houghton , Jason Gunthorpe , Mike Rapoport , Axel Rasmussen Subject: [PATCH v4 09/13] mm/gup: Cache *pudp in follow_pud_mask() Date: Wed, 27 Mar 2024 11:23:28 -0400 Message-ID: <20240327152332.950956-10-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327152332.950956-1-peterx@redhat.com> References: <20240327152332.950956-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 58B1D40026 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: d8yhtizhcw7f7k7rzfnzintssenxrtzu X-HE-Tag: 1711553038-54553 X-HE-Meta: U2FsdGVkX1/dZhCZwpFdog4luMThc5gWgox+0Ye0waxmtX2VNuqIlNdhDoK9t9aIAaxVdotLNNLojg6HY7Tlo5AuovGyAWsujpLzak0TvJkP62saT4+PN+icKXHuxc3YD3ecE50VxUWhfpVeXBiiD3xE0ICDcATdCfJe8N9JxmkqDlA2n9zJ9b+72d75XegAxYAeqy08oD0WYpF6gMMGY//BI7TxuOFdM8/NE8ilmbrOhDkjAresYuV+MOv23trHnCJanNAB+yKjGddLi8rkMrzfqy7xCtBbJbNG+n96iQhD2yDEN3p30jZ9DuPYwbBydd1A/4bAcHFnUkjb7QlTbyuIJUTKqTn5PwR18Xddcosvy68l7VnXcbOncQXkcTp8/vonX8UwFmBuXnaXmPcAxCto1in7upgiqbEYge/Zp6QGVkKMIfUvd929PcGwzMx1yMx2uF9OZ0YcYXiY7OQC5wXtCsU159lAA6bk+UCj/08yoQEi/FFdsUaNbRBfSQFJMuiAGLsF6poeDGAlO6YD5zpOgabuR9UDatAD4MROXr9Ltbe3S+i7pnXiqeCeYykZ9g0+zPM5tQj/Ht80oeqQTTt0PglJFnvw/slOSMtYXA1WCVZbFNn4NcVVeS1g6jQayDb2CmbeJR6qXseRScdBgpCAlhf7bF6nbsEbTl86J1K5hJFdsuykYT72DbKva+75dRIPKDUN2nAtK5tfVaWRp2pulkwGtum4zTVeyukSrftaAwBj5VX0VpfD43KuWqZkS8/S9PE+/iLf9fMM38zTsrdr24YUDXIc9LQbgxUemAurya/VoCrAYetcLvluLs/wKrQuWSIVmDPpTMc4RiHtivvjSK4QHogNsN/iHAbd2BZLRcehrv6o79U3rXzs8+7HS7/92nH/tALR+RBRtEGVe8VKKSNEsA+RP3FioYiy0T3FoidVpSUcYJSN1G0mUUoX7eBaZbSEeS9mHKO8qiE hil+C6IV sG2GJ0rJKDuOFAk8VMLgd5L75Vh0dadMITKYnheqZQoeWnVukNW0dPO9L9LhUE+M3/HHqAKP60MFaQqDeoIZfJuU+9c7Ea3oLx3EnC7bfaV2zM+7ptmj1sFkDnmg30G1HNoBe4J+8OdGVgfLqiN7zvM8+TWadPlzSp42ZxnmeZCLEgnDax8l8GVwULrnuV2Er+xa+LSyJrws+AB19OVsOwfqBaPMECZwYlke6apo0xrJRj6SfkpV6hupJVMJT4dqrZCf2K419VXxlBh49Qwt0NmiL1MqwGKPPLdT7slPxFxPTEzkhlptZ3wX0TDYEpcy6SlyjcNxPDBn95TnW2wcztndH25xR117/ttTojYFg2xjaslkbzCEvvXcouVEN2VShbNHPw6snsF6r5PBKVHVsjksYGcxqQVmGcAtAYOsPh1zg8Py0YymfXmcHkVye0lWgKMc5j6/rhAn3xt6HvBOOvP3LKxvv6BJ2tTH5 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 ef46a7053e16..26b8cca24077 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,