Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3608235pxb; Mon, 24 Jan 2022 13:25:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYjrhelHzB636WQuEG7tMKcfKt3rDjdS1WOdkZxXi3RpmlGRG1kCaGtLNo19hJylfDPJ+f X-Received: by 2002:a17:902:9001:b0:14a:a1b2:1e6d with SMTP id a1-20020a170902900100b0014aa1b21e6dmr15938590plp.124.1643059511211; Mon, 24 Jan 2022 13:25:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059511; cv=none; d=google.com; s=arc-20160816; b=nqWTiAW+iftX54niOisUE2nu5hW2+gjBDaoOpmTzPnbQybaQgMEbO46u3cXaGdaGU6 gG9hWqW3YMhSyOYEK3R0XvzTukkzbvuLPuJ4t/Od6v+Wk9Nwz+PMc66TjChE2UODlzWT bGhpUPZdBGXPA+uXAsHviQgLo4GsCVV2+xTsf2hMXFXubb/yzMJy7Z4BDOLYVjrX69w9 J4cXQwdajIQCZQA/ONcWW5Fr87pQi30LYx+Da3veSbQ5iUf74NHY3G3aYMrkh7xYD+G4 1zWSbPsTqdassmh0hpHJmgcscbYUNjavSFsQaIRlB5CwjeAbFH8t+5O2aul3nU2P1vca Hg7g== 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=kFitvFctEoWiQ/WUXuZcP3vtRa6AuoNurNtp07w374c=; b=ZwDwLEdBl8Jal+LEeqRiLpt9lNTr4XdiYpgQW2bn/Pvcgr7BQH2rChy6aYFt3a7bfc HF0NmLlP4ih8ZOe+cLovNWcLKcIwnY27pgMzcGAoPUWhkOy7wt5N5LOOfQGEHPpdglKK bWEPtyeBesy6hOUflXQAtxLbUAEcAEKLjDIoUAwW0ZAuQ5y8DbkXJ1C/o73lqsW5pNmC wKtfPMbqm2rftJaL/wMCH0tj1a4sw2X7jG3C/32mAzSFkUl9Z2/B51uaJnvHHchI63zt lgz/YEp/57E3iZqcf4e4XAMrnSv9aDevE0lcz8u9HmGbFt0RtCOhSAZ1nOKaR4N/sySW I6FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cSb9x6NH; 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 g23si5233960plo.142.2022.01.24.13.24.58; Mon, 24 Jan 2022 13:25:11 -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=cSb9x6NH; 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 S1359830AbiAXU6p (ORCPT + 99 others); Mon, 24 Jan 2022 15:58:45 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60394 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386662AbiAXUfs (ORCPT ); Mon, 24 Jan 2022 15:35:48 -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 DFF946152F; Mon, 24 Jan 2022 20:35:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5E38C340E5; Mon, 24 Jan 2022 20:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056547; bh=WW9YieQwk2clGKAZBRP8Uji/4Smq/3oUwh7LfdiSjSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cSb9x6NH71UZ+sN5DXlCqYzy6Lwzri63V0oU65gZSeMIY4fFX7fbw3rqLwU4GKxBB QRBLYaf6u6jPugu8FMpM69MYmo36hsc2aH308G5ohBT8PgIQKasz+5hD0CSAw+86pP h16/mV4LW6SHnCYK8QIVXHPYtNts8aI303AYG0yY= 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.15 521/846] x86/mm: Flush global TLB when switching to trampoline page-table Date: Mon, 24 Jan 2022 19:40:38 +0100 Message-Id: <20220124184118.991685745@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 d3eee1ebcf1d5..1d20ed4b28729 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