From patchwork Tue Dec 19 07:55:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13497945 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 6E39FC41535 for ; Tue, 19 Dec 2023 07:57:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14CDE6B0082; Tue, 19 Dec 2023 02:57:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D3666B0083; Tue, 19 Dec 2023 02:57:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB7C86B0085; Tue, 19 Dec 2023 02:57:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D36E86B0082 for ; Tue, 19 Dec 2023 02:57:47 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AC1521A02A5 for ; Tue, 19 Dec 2023 07:57:47 +0000 (UTC) X-FDA: 81582813774.05.00D00CC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 0EF4B4000F for ; Tue, 19 Dec 2023 07:57:45 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q1YJROa1; spf=pass (imf27.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=1702972666; 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=7UtlH+qJqHqzo7Y62yc3egVvRJlUYI/8xtDdmttQSUc=; b=AJ0qZ5ZWrnVwtHcIWfs5ZB6DHRDSKj4f3NxRjDbzhqtKOLR9S+SdMUOCdvylh34P9psla2 9OL7AvYeHhyusvRK6LKtN/f/U8gOVVF6dVBXbuErSHsfWtyXokn2POKFPd/fKaczqIMV/P uUan2BNFZIGxx9aQrU3EOYhGtVPhvnI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q1YJROa1; spf=pass (imf27.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=1702972666; a=rsa-sha256; cv=none; b=dhPwO+wqwOTt+NbktvIElWeChYyEfEcWhzLcNr9+t0P+stXc8BH/mTE9xYCSD8JFUfPi1M RFh6raARatHrROHfEIb5L56IUSEk2ZV/6uk2py3ISvWOOn0QE/jK4NLAwWnV84HGQIrHjy oskbYMVDyX9PcZt4taR5trPFLtC51Qc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702972665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7UtlH+qJqHqzo7Y62yc3egVvRJlUYI/8xtDdmttQSUc=; b=Q1YJROa1/VmSgLjoxcAKyDOoR0WNKYkAvU7zteAfdWQ7TCbFo/lKGgOlCQDl63qLZvjhvK Ib2sNdp5Lv+tRirQmYL2+YTDFxtYGK/jIBhVfaFu0hSf0mYAH6nmo5xBfQ1Iw9CEqhlAZ8 6oivtRn2xw2SdfpQdW8DK7R9eZtqS0s= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-197-HHPXr_gTMGKJxc1F8Y3Vvw-1; Tue, 19 Dec 2023 02:57:42 -0500 X-MC-Unique: HHPXr_gTMGKJxc1F8Y3Vvw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 13EAF1C0513F; Tue, 19 Dec 2023 07:57:41 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id D699F2026D66; Tue, 19 Dec 2023 07:57:28 +0000 (UTC) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Christophe Leroy , Lorenzo Stoakes , David Hildenbrand , Vlastimil Babka , Mike Kravetz , Mike Rapoport , Christoph Hellwig , John Hubbard , Andrew Jones , linux-arm-kernel@lists.infradead.org, Michael Ellerman , "Kirill A . Shutemov" , linuxppc-dev@lists.ozlabs.org, Rik van Riel , linux-riscv@lists.infradead.org, Yang Shi , James Houghton , "Aneesh Kumar K . V" , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen Subject: [PATCH 09/13] mm/gup: Cache *pudp in follow_pud_mask() Date: Tue, 19 Dec 2023 15:55:34 +0800 Message-ID: <20231219075538.414708-10-peterx@redhat.com> In-Reply-To: <20231219075538.414708-1-peterx@redhat.com> References: <20231219075538.414708-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: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GkrOnJPx/UNK5wtFf7dl7uTDV8WicqBvRetGRQf0VmjPqRVhM oNauqqAx gnq2Pg2kHfSW8VE8a9HQ3hR58/X0HjGLeuZ4AfPbdSexKBHSEuaCbKK1ilSXL2vgd35reZe6KmAJi2P59MAd+RsUX2hUHY264D7TRT8FSVTlYiBNvs+FqQAgBXSZmDFYlo67Izc8TwOwJkPyzxXzIk2iRIyUjZQXBmIuncbKUKCpm0sqAU98Gs9F2AFmpUyZGVOsqjHiYJL0V3sS/8m6m4RaH9Q== 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. Signed-off-by: Peter Xu Acked-by: James Houghton --- mm/gup.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 6c0d82fa8cc7..97e87b7a15c3 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 = *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,