Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1486066pxb; Fri, 1 Oct 2021 11:38:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4TWGqHq/R0QQszws2F8NptDYXWvmKYeOrSK2z5vBq/+OiDMUK/3iDEqVXFYiH4W76yNkC X-Received: by 2002:a17:90a:1a42:: with SMTP id 2mr15099855pjl.202.1633113527524; Fri, 01 Oct 2021 11:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633113527; cv=none; d=google.com; s=arc-20160816; b=0reitJOgoDrpbyp7MWHzLvnwUpBgq4BWYeHjg9uaH6ROyyLUFqBFTaaKxAtfFy0Z0r 4MwuZ3zPjckvL2PEqXrdQZZPt57oy+7rdRmxX01eSHZvebtK+DxSsu4vH6mkIRQlJvXh gjtoRgVnFRl+8g8UENhrkVl1HZXfm2w6CCZQY9cjptqChYx78Red6ZeU00efjEEXx57P +I8IS+aZwDyhvMu22uilGvuVH9+wmRKqIW5VBTlflot3RfXdLFpZZU1lDvHBti/LLTxO b9p9dWOkW6348hL+2N0EAacVuxr1MPtB7G6BvaofYZbtDvoc7DhzN3S5UTMDPuj8C5El IHNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mLJXZg/AK8exgwy11myKbNG2EP5r3dwTA2aeYNXmgjs=; b=Pujd/VNwKkYhw8pIHbjU3smF3GWxADFphAp8O+lZRh+ZFrnNLHIifM1Z2bc7bJ0c45 UdIqwx6A5ZJxXSBINTIVamBv6FnHy7zI9SNXYo3l7BiKscWPg/+GZGHYGmok352GDlBJ +bWzWMPEFnV2x+tu0b5YhsLcmUlYJBqR11GFxM4K5MAXcCi+HeFoMlSQRGAeWqsWE56e snntVe7v2X7zbafcN8TaPDGJX2ommdb9Afu+8O4ScRExicCjiDh/Oo3lKRE9ROnQW/Zg wIw3Q1xTpDD220JJYhV4ctIGeAfcFjBhc4ttb1AZ+L79a9In45Nyl0SwGuUp9xqxULHt Z7vA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si7720050pgb.70.2021.10.01.11.38.21; Fri, 01 Oct 2021 11:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355103AbhJAPuc (ORCPT + 99 others); Fri, 1 Oct 2021 11:50:32 -0400 Received: from 8bytes.org ([81.169.241.247]:42980 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbhJAPuN (ORCPT ); Fri, 1 Oct 2021 11:50:13 -0400 Received: from cap.home.8bytes.org (p4ff2b5b0.dip0.t-ipconnect.de [79.242.181.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id 4F7D349B; Fri, 1 Oct 2021 17:48:27 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , hpa@zytor.com, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Joerg Roedel , Mike Rapoport , Andrew Morton , Brijesh Singh , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] x86/mm: Flush global TLB when switching to trampoline page-table Date: Fri, 1 Oct 2021 17:48:16 +0200 Message-Id: <20211001154817.29225-4-joro@8bytes.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211001154817.29225-1-joro@8bytes.org> References: <20211001154817.29225-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Move the switching code into a function so that it can be re-used and add a global TLB flush. This makes sure that usage of memory which is not mapped in the trampoline page-table is reliably caught. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/realmode.h | 1 + arch/x86/kernel/reboot.c | 12 ++---------- arch/x86/realmode/init.c | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index 5db5d083c873..331474b150f1 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -89,6 +89,7 @@ static inline void set_real_mode_mem(phys_addr_t mem) } void reserve_real_mode(void); +void load_trampoline_pgtable(void); #endif /* __ASSEMBLY__ */ diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 0a40df66a40d..fa700b46588e 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -113,17 +113,9 @@ void __noreturn machine_real_restart(unsigned int type) spin_unlock(&rtc_lock); /* - * Switch back to the initial page table. + * Switch to the trampoline page table. */ -#ifdef CONFIG_X86_32 - load_cr3(initial_page_table); -#else - write_cr3(real_mode_header->trampoline_pgd); - - /* Exiting long mode will fail if CR4.PCIDE is set. */ - if (boot_cpu_has(X86_FEATURE_PCID)) - cr4_clear_bits(X86_CR4_PCIDE); -#endif + load_trampoline_pgtable(); /* Jump to the identity-mapped low memory code */ #ifdef CONFIG_X86_32 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 31b5856010cb..b9802b18f504 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -17,6 +17,29 @@ u32 *trampoline_cr4_features; /* Hold the pgd entry used on booting additional CPUs */ pgd_t trampoline_pgd_entry; +void load_trampoline_pgtable(void) +{ +#ifdef CONFIG_X86_32 + load_cr3(initial_page_table); +#else + /* Exiting long mode will fail if CR4.PCIDE is set. */ + if (boot_cpu_has(X86_FEATURE_PCID)) + cr4_clear_bits(X86_CR4_PCIDE); + + write_cr3(real_mode_header->trampoline_pgd); +#endif + + /* + * The CR3 write above will not flush global TLB entries. + * Stale, global entries from previous sets of page tables may + * still be present. Flush those stale entries. + * + * This ensures that memory accessed while running with + * trampoline_pgd is *actually* mapped into trampoline_pgd. + */ + __flush_tlb_all(); +} + void __init reserve_real_mode(void) { phys_addr_t mem; -- 2.33.0