Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3644703pxb; Mon, 24 Jan 2022 14:16:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlvig5lJz8rSeT3yB5TfDd0w0xT9bc/AdvGJ20div+Xt04tREmVxJR/u1zcK+aOOdl0d5+ X-Received: by 2002:a17:90a:db90:: with SMTP id h16mr413266pjv.66.1643062616861; Mon, 24 Jan 2022 14:16:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643062616; cv=none; d=google.com; s=arc-20160816; b=j43E49qjtqS4CFvQAziiWDaNoMhP2VVABIcIFCvKHp3bkt4zd9E/Tp3/dbKHFObhF4 C7Z+lhPo77DWYuywMkMpDEEd+iTJ65ExXjMXYL3O3nqQk77EOhkts9vs5cYSpypiTu82 U4qwcVkDLCnlhNUbJjn3JBzbzHVDaXeSVfrsX9jdGkysRXruC07hGddGLeIDf5WgMhgr daeCFqJeFTj15eN7t1ys5s90h+A/awfVweCVw/yIotktJ4xV6PYW1n4jmtJUTdCPXzjL Bm3ro/USov6ueZxwK4bBfqcmrbvCbsBAOtAcP2vfnq2Ea5M4XsHq5YHSjOETZ7SXOPmK 1qCA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZGKjW0SlT4JaYNDVZEvM9zXNJaXJzo450vQ/ILiuX5U=; b=N8WwgkAWOtF+krEbapyGVDD7ufZUs4iK1i39QVEjqp9VNFGAKG1uS/FejawwkS5wVi NE+2u5TaRTclEUzMOZvfKwyTrWlkRKAT4ETNgboD1TRLUhW/dnrx+vrFnTUgLOk4pdeJ Nblj5jntPhg9nPPI+gaWIiXfR714sdhmaTIIpoR75rKLTiHFs/6A3RrKfdqSoBVSrkcq Nrz4uE3grTWwEOOSc+zyP8nLCQZHqsJuBadgMPbkGG0odKuHFjYiM9aiT6D4ELgZBDrE a5bneKyCrJxixQzjrNN2zDSg8/LpV7AD/4IdJURy3rU4fHLmQ4eTPSM61FHBdt213piw n1Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mQLzhIJj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bj8si5873197pgb.745.2022.01.24.14.16.42; Mon, 24 Jan 2022 14:16:56 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mQLzhIJj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354811AbiAXWGa (ORCPT + 99 others); Mon, 24 Jan 2022 17:06:30 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:44548 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1452090AbiAXVYC (ORCPT ); Mon, 24 Jan 2022 16:24:02 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D357361028; Mon, 24 Jan 2022 21:24:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD9E6C340E4; Mon, 24 Jan 2022 21:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059441; bh=8viDxICTwBj3X3U5m2jJ0FeAwvjTGlqTSlf2o/uWmFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mQLzhIJjlcodCzw0JTf+UOP4S2aZw3S/L0GaDet4uIde67dr2yrV73FuBXJsbxyEm mDiq1UbKTHD09XnBnjh3JXq6fEx4GAYONbzoSd8jR9CS++G4DOhN697xWMJUknG3/P gB/cWBAH/6oy9heWodBhJGly9tOmEI3QhhrnFIoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joerg Roedel , Borislav Petkov , Sasha Levin Subject: [PATCH 5.16 0615/1039] x86/mm: Flush global TLB when switching to trampoline page-table Date: Mon, 24 Jan 2022 19:40:04 +0100 Message-Id: <20220124184146.011973490@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel [ Upstream commit 71d5049b053876afbde6c3273250b76935494ab2 ] 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. Also move the clearing of CR4.PCIDE before the CR3 switch because the cr4_clear_bits() function will access data not mapped into the trampoline page-table. Signed-off-by: Joerg Roedel Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20211202153226.22946-4-joro@8bytes.org Signed-off-by: Sasha Levin --- arch/x86/include/asm/realmode.h | 1 + arch/x86/kernel/reboot.c | 12 ++---------- arch/x86/realmode/init.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index 5db5d083c8732..331474b150f16 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 0a40df66a40de..fa700b46588e0 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 38d24d2ab38b3..c5e29db02a469 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -17,6 +17,32 @@ 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 + /* + * This function is called before exiting to real-mode and that will + * fail with CR4.PCIDE still 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 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.34.1