From patchwork Mon Mar 18 20:03:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13595761 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 D3A3BC54E58 for ; Mon, 18 Mar 2024 20:04:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6605A6B0082; Mon, 18 Mar 2024 16:04:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 610966B0083; Mon, 18 Mar 2024 16:04:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B0DA6B0085; Mon, 18 Mar 2024 16:04:14 -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 3A7DB6B0082 for ; Mon, 18 Mar 2024 16:04:14 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 19347402C5 for ; Mon, 18 Mar 2024 20:04:14 +0000 (UTC) X-FDA: 81911236428.08.1F6D884 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 01FEC20018 for ; Mon, 18 Mar 2024 20:04:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H9WSofPm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1710792252; 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=3D9LYre9es5Pr/ZmF0ksBqg/v+REJVkPqwZxeVyu2sc=; b=CUUeAuDaTFIA3zXKyqwMehsvYBbjjfUVCM4zDxLbH/G1+medsUQOuLCcuaEZG4DyLdwwtp v+P3UiHMCcOe9mu5QpQcrAswbekWhk192qIRIFwm37ntoXc1JOeSF3k/3Z/cgKDznOYE4W KGrA4m3ZqTVtaIsASOlIlZXlioosngA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H9WSofPm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1710792252; a=rsa-sha256; cv=none; b=6WvFVFNCZ/zlFcqjmw2mO9VIbJwvbton0tw1xkZr2Fri38FBdjcXnt3QmcYmzHZBWoqGRM RH4T7QpuzU6yUfoNOVWTeRlnh4/dC8w03ry2ZSX5iAZos1Zf2p2KMbiFIkDLz1ijBpQ+Ad vOCG9djI+rycpYDePUa+mu1PbqHIs3Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710792251; 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=3D9LYre9es5Pr/ZmF0ksBqg/v+REJVkPqwZxeVyu2sc=; b=H9WSofPmRGkqYfpr0CIOZPhF0qPkczJXvKMCEsoSlwPZT8Q+uaLj33Cyu8T4ZBMeUKZbul 3Qqe3gwJc450yt0zNvT9hZhjRPA2R27pvFvGlh4nHw/v7irUVNnjyEbhpIO5sleNtREiAi Z2hfegWHL3c+hyFdaiVghPAjjw603CE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-ssIyHP6_NfCiD4p5zsxggw-1; Mon, 18 Mar 2024 16:04:10 -0400 X-MC-Unique: ssIyHP6_NfCiD4p5zsxggw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-430c76df729so6672251cf.0 for ; Mon, 18 Mar 2024 13:04:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710792249; x=1711397049; 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=3D9LYre9es5Pr/ZmF0ksBqg/v+REJVkPqwZxeVyu2sc=; b=OKNDFZTniqlX1nIva4UWs3JAu/4GmdRPwFcQAe0DqhQ5IgD/VvbcBxCIcWM+V/Cu+W SvkgnRhmK81J44y3aFrpVWeRUN8GH4DDZrmeoNYYiFjjBZeSMF0v6NW2azzDFdP++ky2 RQ3MFpqr8HB28doQYJcqdYxpNK6yvzFJzRWRwcpqis6p9qKIVvlUlxAuC1ob0brKXbmC BMnNexlTxGRJzPV5oA9OmODuu7hPIVz8r2EMEFvsBio3tzSj6/rncNWWKUAkoybHyOO9 3ePmDplO0q4dE9aBrbHPFes3ya25M7qphkLjysJ3jsVPRcIkhan/ytaQ/3xZXlFR5BPE ASAA== X-Forwarded-Encrypted: i=1; AJvYcCVnaxJhaCzkAGuEOPbFrgFy7LZGE3My/td9FqHNauk+3saMXyVAI9WCuS0grlhzxrjs51bTt77aBpi/asGUtI2FZr8= X-Gm-Message-State: AOJu0YyFnM2HfaineZY7vRXwJEfJVbEhnrggmyzg0Mjlcj0GrvBYqWnZ Gyr6uSyIEjKrQC1lOGpf1NebXLUzXBpqADt2fTGJ2nL5NDC2uFqJ17ovteuifkOlDv5qDvRcZC8 ANBFHUmXZh7X8BiqL0SA5l6p7TldUBPTGYq+gfZFub0PJ9ULs X-Received: by 2002:ac8:5809:0:b0:430:9ec1:77f9 with SMTP id g9-20020ac85809000000b004309ec177f9mr12704570qtg.3.1710792249342; Mon, 18 Mar 2024 13:04:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbpoPvKLD658FrZMZUfa21VFbJZXAX/nOy5o3FQUuNePIa1lkPrmXkrLKWAEePy+S7Jq7UDQ== X-Received: by 2002:ac8:5809:0:b0:430:9ec1:77f9 with SMTP id g9-20020ac85809000000b004309ec177f9mr12704524qtg.3.1710792248947; Mon, 18 Mar 2024 13:04:08 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hj10-20020a05622a620a00b0042ebbc1196fsm3484491qtb.87.2024.03.18.13.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 13:04:08 -0700 (PDT) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , x86@kernel.org, Muchun Song , Mike Rapoport , Matthew Wilcox , sparclinux@vger.kernel.org, Jason Gunthorpe , linuxppc-dev@lists.ozlabs.org, Christophe Leroy , linux-arm-kernel@lists.infradead.org, peterx@redhat.com Subject: [PATCH v2 02/14] mm/gup: Cache p4d in follow_p4d_mask() Date: Mon, 18 Mar 2024 16:03:52 -0400 Message-ID: <20240318200404.448346-3-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318200404.448346-1-peterx@redhat.com> References: <20240318200404.448346-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 01FEC20018 X-Stat-Signature: 4p3eyo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cGG+HqqXyl60MybNi/gVCOISXvjHhfzgFZynS7K6QgHlTKQYiisM4W9xjYDD99YZLJKNsr+Z25Gcm7uZ2h6x0ccK7QedKZeYxDMzsWnyYgcAQy8gwst8pzCzKIOeuPGOTmtMNx/tSTo6/xumbLr5Y+CiKu2QGLv9jIQlyNYlR9hhUe3Koc/4MRO62CTHmAU5OCETz4bpRlhkoO4ResT4FXZdA0zFY1JaWsS9phqqwCalb32DSRLLbRMMnuGImAjc9WroTyWVmdihoowYmjAv9B0S0jy2Gk7OPKBg2MxGd43dWIgi/5wS24t1FrFwD2aU8tk5uNxcSaehfXgXKyxfftHYbucb9cpBheAHb88IzV+Gf6cH5JDZACE/XL+CquhV7E50ZkyIjYsjXk87tjDoFdCCXd4PQ== 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 Add a variable to cache p4d in follow_p4d_mask(). It's a good practise to make sure all the following checks will have a consistent view of the entry. Signed-off-by: Peter Xu --- mm/gup.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index df83182ec72d..69a777f4fc5c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -772,16 +772,17 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma, unsigned int flags, struct follow_page_context *ctx) { - p4d_t *p4d; + p4d_t *p4dp, p4d; - p4d = p4d_offset(pgdp, address); - if (p4d_none(*p4d)) + p4dp = p4d_offset(pgdp, address); + p4d = READ_ONCE(*p4dp); + if (p4d_none(p4d)) return no_page_table(vma, flags); - BUILD_BUG_ON(p4d_huge(*p4d)); - if (unlikely(p4d_bad(*p4d))) + BUILD_BUG_ON(p4d_huge(p4d)); + if (unlikely(p4d_bad(p4d))) return no_page_table(vma, flags); - return follow_pud_mask(vma, address, p4d, flags, ctx); + return follow_pud_mask(vma, address, p4dp, flags, ctx); } /**