Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp342396rdh; Mon, 18 Dec 2023 23:58:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPEESjktK/y2SxJ0Edt6pse5ajTF57y/Dr9xfJ+XZZ5py0uFIrwuaGUKZQWxJG+9c5Bsi7 X-Received: by 2002:a05:620a:1004:b0:77e:fba4:3a24 with SMTP id z4-20020a05620a100400b0077efba43a24mr21055229qkj.122.1702972729205; Mon, 18 Dec 2023 23:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702972729; cv=none; d=google.com; s=arc-20160816; b=WZS+JPv1E1ssXeOYaaV8f7/3SVuCARG8xLfeMepWiGFKKann+72EbYqq5hpdssIyaa nvMtvagnT+lhv2JR2k+3I2FQD6CVQ7NnUekceXd/TFlIcE7YmTlS4tz/FLm3awm1uiPp 4sbmGj129uQjVekYR8hN36kpIlzv3sf0wcqRQuzUb0vLknyV3UOL2QouaAqWVCpn8VB6 VgU7FXFjwh3kBw2Vn6E0Uv2IpyB9m9Fz0lp6nR3KAxMZPcG1ZEEo/L/U9nqhl4I+Iygd apgkuWcIUmuHX3U3YM2GDd7ks7BzS9hfa2AZe7+389b1nsv40v85+pd/Aalas83rV/bE PDvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7UtlH+qJqHqzo7Y62yc3egVvRJlUYI/8xtDdmttQSUc=; fh=3mpu6Yyr5hMzDKtkQvzcApl7ZSQGU4G8QyIY2BAU7VY=; b=VuFt5FunACto/Kk7ybmdsBk35t4lpQKoFL3hMmnIL1OoIM0/SL/ZVozvNjlauRQZhP ygVd+kvjgwVnwqzXA91ZolsFPFBxKj9xxvy6ohWi4DHk9YjbOSs0W0Om6jGqBkvM5/7w RZbGBQQ7qpnvykWwsoNWjtUsVo15uHQoepRwQIIkaAKLnHE3g8sSY4ucUhFn4gpq6+oy HHeAoZ3xDyKk3/hNHp5ZvIocGtTuV83dMXERCmqR0lNvNX10Hn4iyjplJ5frbWVXKKIz OYVCR5ip9/WjdyY14a4tNDz/jpfxwH+fEa8FayvYoQ/k5lBBpC/HchhyuXgVv0e790QW 2b9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y5b7wywr; spf=pass (google.com: domain of linux-kernel+bounces-4843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id qf8-20020a05620a660800b0077d85c98bb3si26467444qkn.194.2023.12.18.23.58.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 23:58:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y5b7wywr; spf=pass (google.com: domain of linux-kernel+bounces-4843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D4E8D1C23894 for ; Tue, 19 Dec 2023 07:58:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5719214A90; Tue, 19 Dec 2023 07:57:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y5b7wywr" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 413501429A for ; Tue, 19 Dec 2023 07:57:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702972666; 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=Y5b7wywrl16gpY3+tzbsVsuvPxD5fZXreYpvcGhI4HODV4jgYBqgD2MDW6GhvWJiEOdbc3 flgTQM1SNdI+rbNOjOc9rCpkh0EsCijIMtev+gG9mcLn2HnW+NZ4w1SSYyaR5XJfadxxHE KRe6IX2k5lPo69getGFoq8tln6Qpocg= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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 --- 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, -- 2.41.0