From patchwork Sat Dec 17 18:55:34 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: 34249 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1636432wrn; Sat, 17 Dec 2022 10:58:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf4GQW4Qp9ysOBoopP3+Fss0ud3TZUXHNgzusEO0vyf6hgX6IQcsD3399eYU+hnTJYLTyBui X-Received: by 2002:a17:906:4687:b0:7c0:deb1:bb8a with SMTP id a7-20020a170906468700b007c0deb1bb8amr27048777ejr.28.1671303530346; Sat, 17 Dec 2022 10:58:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671303530; cv=none; d=google.com; s=arc-20160816; b=RuLzHk7pJWiRO3mUHhVW/mG53hTpTKYmFlhrFG05fdjPazjTiZAfg28HyQ6qNWs3pH Ahh+3Ezigt824rW+0H6X+/z3MabFsRp5TiG7D6P+TJES6fIrT9yu90Jy9A4S8cyBC4xC X/+Ej2ud7np6aFenuDBI7Uon7hhIikdqVzsipRcVBpmpV8E+lcvyfreIXHFVGFDgtbND UWIFovqti25uHG3wfLsyuwE075L5IlP8cmY5Y8U7OUTdkTV1W33kTjOhJgujww3rA4kj 7Rlw4MtkPzOsxV3xGOI9KCyjKYVjZjPaDhy5YRsRaB5VM6EdPlL+P8OjgLR1raR9hQTZ +oGg== 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=4UoB+hK+tcdQDB/+PMZQER8XJJnoCS5xMMq8B0ZpXQA=; b=bYRVd/Hh59t4tljwAJVL3PoQsfZsyItafsvda7fH8XP1Z5Vot85lhT/Cf6O0w9Q7At NEN+iC7Xxz7OVr15Xg5plPEwOu3uKcH+WE4EQCsvikYDS2dGlITYHO7TWxWfSvvexxXG UJPd5K+K2pDamu5bfRVUnkzH0Ec1a+r6Rc688s8MLDhSsuAvjeYjh7enp9McTPBB3jjt I2abznmg8BWP0XNBn4pBNWx1XJ84vRurKRqSElvG7u7HI2A1Ln1M8wOnirIkJjGrrVZP jditD7/oWQ+9fvGQ3Ad6zjiBio9kGLCEjILr6wvJQ2Bq2iwEnuPBBo1VzDOjjSJpXLs9 QUbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=h9CeiDyV; dkim=neutral (no key) header.i=@linutronix.de header.b=OBtNw2XP; 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 du1-20020a17090772c100b007f40aafbdf5si2217966ejc.137.2022.12.17.10.58.25; Sat, 17 Dec 2022 10:58:50 -0800 (PST) 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=h9CeiDyV; dkim=neutral (no key) header.i=@linutronix.de header.b=OBtNw2XP; 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 S230476AbiLQS5l (ORCPT + 99 others); Sat, 17 Dec 2022 13:57:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbiLQSzk (ORCPT ); Sat, 17 Dec 2022 13:55:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16839113; Sat, 17 Dec 2022 10:55:38 -0800 (PST) Date: Sat, 17 Dec 2022 18:55:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1671303334; 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=4UoB+hK+tcdQDB/+PMZQER8XJJnoCS5xMMq8B0ZpXQA=; b=h9CeiDyVfCfWqMJH92+Zd7a7H5cgKGEhk6kwrC7tSbwCl7tf7LwLWf9RaqWSa+jKBYitHq 3UZXLEZaJv7tp5u4tLckmHNLL4jx1VetAFb0fUvsTvBjPe4F0PFE+4d9ewFH8JbWosp2dl MQT19ZuU0D6M+BPskfm6o9octM4JhtKklA9S0ft1ezq3GLA2TOwoQFd2EAahtXfDacZqcI yS9CmXffZb08H+t5AaXpij/4DMfABf09R+jDsvOFQTHR0cs17ATgtbao4mGL7HZ5iacjp1 17ytdNkCxW9M6ehdtG62+0YvaUSKjL1AzSr9t5IwBIOM4fsl9GvkEtpcbUtZ2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1671303334; 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=4UoB+hK+tcdQDB/+PMZQER8XJJnoCS5xMMq8B0ZpXQA=; b=OBtNw2XPBIJfMngkmskKem7bpcHIQHo+9+AZBHrTK4RRptAgWWibwBmN7CXR2bp/nnlOkP eeZAyLn8mqs45/DA== 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: <167130333403.4906.3606451945535020172.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?1752488770320861987?= X-GMAIL-MSGID: =?utf-8?q?1752488770320861987?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: fbfdec9989e69e0b17aa3bf32fcb22d04cc33301 Gitweb: https://git.kernel.org/tip/fbfdec9989e69e0b17aa3bf32fcb22d04cc33301 Author: Peter Zijlstra AuthorDate: Thu, 26 Nov 2020 17:02:29 +01:00 Committer: Dave Hansen CommitterDate: Thu, 15 Dec 2022 10:37:27 -08: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)