Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp824701pxb; Wed, 29 Sep 2021 10:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylv3KrJgel8wpGsyaAyTyFycaoni/FIEFGh0N36oAQNBODUn1RUJ5uefb3XtgXqSgVBJTo X-Received: by 2002:a17:906:3395:: with SMTP id v21mr1131396eja.210.1632936239892; Wed, 29 Sep 2021 10:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632936239; cv=none; d=google.com; s=arc-20160816; b=EfNPDWmjG06g/PAgNtBZolgmzN2wg4Q/qkpOkBUhNmOjyo+c47wem4WYc2Q+D4VDYS txTlKs3huJnJM+tJoBwXfKLo/CmV6kqX8vX6c4h4aeMIrjB/Entyxln3sDFmVoMmpGCQ Be0Mi+wAzwosW/UlO4pQAwwFDhcn0qlnSrFf1W8XkThMy094Zp7LjaT9jnwhg6MPgJ27 h/O56nYRJImy8c8aOTPveafKEh2cVJjdIavrDF5l34MTR3AMzV6kDmxJmpx3wZMllvUC J3O67EpLZyhQrt9BYGnKwYOlWM4E3MO+zQLqP6/UTMGL3erTWumHX0mF6RB7wbPeMD9m MLoQ== 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=y+sN/Yq2dedKDW+aFD7KcCDfNIn1LLa/Vp5Kqsjd8b8=; b=DisQBPo8Ojh5d+W//6EpwdkCx32fs2exXeTdb8gepIQnYTmDhlzlcSMl0CEb6sx16y nh63YDCGPmiuUUdapJBdY5aNBcu9SRYHwwEPiSdkdPtcxjefYwQrELbGjaIE1Dzp6oXu VUDrHxzvpm6mZk9UpfTmQqgg7RyAtLtdeAjg2bH6U8+S10fhijH7ygydwy88JiqRwRk3 20suSw8Wx8iDiga8k/S6/d2gjJEQIgK3Dip8xFg03gB+Ro/yAK1J+N0K7kjrsCaVjwYn n4e6g89APabI+q4+U00NCVlwapAkQCv6cs3wOiBSN3j6h3xFCziZFZ58ihAcGhtumd1a C99w== 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 s9si196708edh.633.2021.09.29.10.23.34; Wed, 29 Sep 2021 10:23:59 -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 S1344824AbhI2O5P (ORCPT + 99 others); Wed, 29 Sep 2021 10:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344809AbhI2O5L (ORCPT ); Wed, 29 Sep 2021 10:57:11 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E104EC061760 for ; Wed, 29 Sep 2021 07:55:30 -0700 (PDT) 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 F034B1043; Wed, 29 Sep 2021 16:55:23 +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 v2 3/4] x86/mm: Flush global TLB when switching to trampoline page-table Date: Wed, 29 Sep 2021 16:55:00 +0200 Message-Id: <20210929145501.4612-4-joro@8bytes.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210929145501.4612-1-joro@8bytes.org> References: <20210929145501.4612-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 | 19 +++++++++++++++++++ 3 files changed, 22 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..0cfe1046cec9 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -17,6 +17,25 @@ 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 + + /* + * Flush global TLB entries to catch any bugs where code running on the + * trampoline_pgd uses memory not mapped into the trampoline page-table. + */ + __flush_tlb_all(); +} + void __init reserve_real_mode(void) { phys_addr_t mem; -- 2.33.0