From patchwork Wed Nov 2 09:12:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 14133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3504125wru; Wed, 2 Nov 2022 02:14:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7GJiGsrbQU5KdVeVlJ2aQFAoCQlBRXSp7BfPFSOjuqZvySElZPPcvfohR5fjtc67pjLhhj X-Received: by 2002:a17:902:e791:b0:186:dcc3:4f5a with SMTP id cp17-20020a170902e79100b00186dcc34f5amr24480779plb.130.1667380497205; Wed, 02 Nov 2022 02:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667380497; cv=none; d=google.com; s=arc-20160816; b=OpJaQJGQ0cET+5DumX+Tpodpo6rguGZ4hFSvIQwloJtKbRi3YqEjHXCaJf9FAp2P9d ucCs993BxjR+aO+fI0GCoB+bq3n3V1OjgzblJ37oS+f5EC0Ipf/fMXXPIFz9cfnatYJT gJX3fmLtpAwC1CI9Im3HeORXIwWvsv1z7HxM7eA+DATMSnnj/sWikMoMFyN/KktnUdZR fhVc5KaMBXkbfbx/lP3rR2VSdrNv7cL+b9cw+t7xwRnxBqhwPfzooikyA2USQox4A9mh yIqBCk4KWc7Z91D1Q8qCvwtmeJaB37NXyvl/BEmeCiUwwEO7RH++Pvf7NNEcwJBRv9MG UspQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=/hOgdQEqHCc4kXSqZe5ZrwcVNawTBjvm+c+P7ud1s2Q=; b=N6eo1ygZYnMifreAiH+wylKQNAvaA3hlbXceMQEqM4B4QciQ5TTO4ck59yxTEJJjwh +tMyyQa9LP7wo2soI81weTh8HkTyPhKg4DHYV/tErfP1iFSYVDIJDO9mU+Y7YtsNVtKK yA2spD4foUYVjSQBA1z/Ylt3faRtKUaXmkjl3QIxmaAvrBBlt6nTTIBXKMqPH9J0YsSj DJUSxKeS70Sr2m7qn23BE+mKH4ZcWH4IQKGUyUF6kolKvVX9ZFz2nV7FVoUaIJleggKd kF2VsXYmEAm8YMkNhWJedhs6JSq3+esYn4HcCEiDakiP9ynkBIyWxV/dxZRuqixU660b TpXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="1ckZz3/9"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u25-20020a62ed19000000b0056238741ba7si13563847pfh.174.2022.11.02.02.14.44; Wed, 02 Nov 2022 02:14:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="1ckZz3/9"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231534AbiKBJOd (ORCPT + 99 others); Wed, 2 Nov 2022 05:14:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbiKBJNI (ORCPT ); Wed, 2 Nov 2022 05:13:08 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED4C128E31; Wed, 2 Nov 2022 02:12:47 -0700 (PDT) Date: Wed, 02 Nov 2022 09:12:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667380366; h=from:from:sender:sender:reply-to: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; bh=/hOgdQEqHCc4kXSqZe5ZrwcVNawTBjvm+c+P7ud1s2Q=; b=1ckZz3/9tAdL/SLYmxBwfK1f81QtJno0voeIR4WF/H1LT+tBbcLuZAOQzU/IloR5dp+sEb PbweuQ0uiqSaeKOozKtWtn0/4+B39TBScbSIzzh9zcuU32ZocuKCsDwsLyWhEatH9eq4a/ CgIggUKC5C0UU0SipYqE7cYFtYq4OxJT7YRaGrvmIB/C7VBv87mbzLfyjgGkASFmXXoorm 3rc7ZpTIGipS2tkbHScd0vHIGeC2YYfaS4j/3/qU6tMezcPhSwIIcYoys508mZqPzunugM GltnCtmL9WcseoH1VdyQePOx6Pn9TRJBV1QP1+MLXSwDuxpdFQ9j2dGJj8vYJw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667380366; h=from:from:sender:sender:reply-to: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; bh=/hOgdQEqHCc4kXSqZe5ZrwcVNawTBjvm+c+P7ud1s2Q=; b=/xuwCnD2eMSxWRW8ZVFKmPjCYtGuYcPTCgv2q2lQC8qOYzU1bEBRzQLcQjU7PGtBa2nJPC mf0c0GPn759kYMDA== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/mm/pae: Make pmd_t similar to pte_t Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <166738036528.7716.4800701229121974327.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748375172323467399?= X-GMAIL-MSGID: =?utf-8?q?1748375172323467399?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: f8c40885e40fd8f5d96c58f4dfca7072fe09a37b Gitweb: https://git.kernel.org/tip/f8c40885e40fd8f5d96c58f4dfca7072fe09a37b Author: Peter Zijlstra AuthorDate: Thu, 26 Nov 2020 17:02:29 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 01 Nov 2022 13:44:00 +01:00 x86/mm/pae: Make pmd_t similar to pte_t Instead of mucking about with at least 2 different ways of fudging it, do the same thing we do for pte_t. Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20221022114424.580310787%40infradead.org --- arch/x86/include/asm/pgtable-3level.h | 42 ++++++-------------- arch/x86/include/asm/pgtable-3level_types.h | 7 +++- arch/x86/include/asm/pgtable_64_types.h | 1 +- arch/x86/include/asm/pgtable_types.h | 4 +-- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h index 28421a8..28556d2 100644 --- a/arch/x86/include/asm/pgtable-3level.h +++ b/arch/x86/include/asm/pgtable-3level.h @@ -87,7 +87,7 @@ static inline pmd_t pmd_read_atomic(pmd_t *pmdp) ret |= ((pmdval_t)*(tmp + 1)) << 32; } - return (pmd_t) { ret }; + return (pmd_t) { .pmd = ret }; } static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte) @@ -121,12 +121,11 @@ static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr, ptep->pte_high = 0; } -static inline void native_pmd_clear(pmd_t *pmd) +static inline void native_pmd_clear(pmd_t *pmdp) { - u32 *tmp = (u32 *)pmd; - *tmp = 0; + pmdp->pmd_low = 0; smp_wmb(); - *(tmp + 1) = 0; + pmdp->pmd_high = 0; } static inline void native_pud_clear(pud_t *pudp) @@ -162,25 +161,17 @@ static inline pte_t native_ptep_get_and_clear(pte_t *ptep) #define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp) #endif -union split_pmd { - struct { - u32 pmd_low; - u32 pmd_high; - }; - pmd_t pmd; -}; - #ifdef CONFIG_SMP static inline pmd_t native_pmdp_get_and_clear(pmd_t *pmdp) { - union split_pmd res, *orig = (union split_pmd *)pmdp; + pmd_t res; /* xchg acts as a barrier before setting of the high bits */ - res.pmd_low = xchg(&orig->pmd_low, 0); - res.pmd_high = orig->pmd_high; - orig->pmd_high = 0; + res.pmd_low = xchg(&pmdp->pmd_low, 0); + res.pmd_high = READ_ONCE(pmdp->pmd_high); + WRITE_ONCE(pmdp->pmd_high, 0); - return res.pmd; + return res; } #else #define native_pmdp_get_and_clear(xp) native_local_pmdp_get_and_clear(xp) @@ -199,17 +190,12 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, * anybody. */ if (!(pmd_val(pmd) & _PAGE_PRESENT)) { - union split_pmd old, new, *ptr; - - ptr = (union split_pmd *)pmdp; - - new.pmd = pmd; - /* xchg acts as a barrier before setting of the high bits */ - old.pmd_low = xchg(&ptr->pmd_low, new.pmd_low); - old.pmd_high = ptr->pmd_high; - ptr->pmd_high = new.pmd_high; - return old.pmd; + old.pmd_low = xchg(&pmdp->pmd_low, pmd.pmd_low); + old.pmd_high = READ_ONCE(pmdp->pmd_high); + WRITE_ONCE(pmdp->pmd_high, pmd.pmd_high); + + return old; } do { diff --git a/arch/x86/include/asm/pgtable-3level_types.h b/arch/x86/include/asm/pgtable-3level_types.h index 56baf43..8091134 100644 --- a/arch/x86/include/asm/pgtable-3level_types.h +++ b/arch/x86/include/asm/pgtable-3level_types.h @@ -18,6 +18,13 @@ typedef union { }; pteval_t pte; } pte_t; + +typedef union { + struct { + unsigned long pmd_low, pmd_high; + }; + pmdval_t pmd; +} pmd_t; #endif /* !__ASSEMBLY__ */ #define SHARED_KERNEL_PMD (!static_cpu_has(X86_FEATURE_PTI)) diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h index 04f3606..38bf837 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -19,6 +19,7 @@ typedef unsigned long pgdval_t; typedef unsigned long pgprotval_t; typedef struct { pteval_t pte; } pte_t; +typedef struct { pmdval_t pmd; } pmd_t; #ifdef CONFIG_X86_5LEVEL extern unsigned int __pgtable_l5_enabled; diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index aa174fe..447d4be 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -361,11 +361,9 @@ static inline pudval_t native_pud_val(pud_t pud) #endif #if CONFIG_PGTABLE_LEVELS > 2 -typedef struct { pmdval_t pmd; } pmd_t; - static inline pmd_t native_make_pmd(pmdval_t val) { - return (pmd_t) { val }; + return (pmd_t) { .pmd = val }; } static inline pmdval_t native_pmd_val(pmd_t pmd)