Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1365476pxb; Fri, 1 Oct 2021 09:07:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdNXw0zdLVZXb/0wL359wbg68hoUc8XyEPxGfdrOi/WXN9XXIBR4nw0pIKHw3KdpPNUELF X-Received: by 2002:a2e:a782:: with SMTP id c2mr10996940ljf.517.1633104473142; Fri, 01 Oct 2021 09:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633104473; cv=none; d=google.com; s=arc-20160816; b=PIKzhuXt5FKhJN9vyGERM/SzYsNwE6+AhKLe4UEQY7xOjigbjJe74XVWKjkTynfHrK uYBCk8BLsfU4snlxGVv/Uhv6pmDuiUmQ0pC52V5cdDdK+aI0CHn9XkXi0KrtfotMzTqa FT35RqO8U42c/rJLomAvtH7/CAaT+tSythboyVo3HP3knBaJAT/DN0WKsZQT7Inya4MR X6+uKKXTfx2lvzdSZZVXBjrZpRulHkcCE8xQ3XRXwMyXomeMQY5R56sgsRB0myIFX15V A5WHD1w+Hxu3cek3cGVTzUQN9rR6DfV1K+S8O85bTTJDqorLA1Oc34n0WQu1Y2lYN4SI V2UA== 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=Q+J6muuTdoi39iHQgpFVGy/QhbKMBKeaM+2thjUy+Ko=; b=bORx3ZlqAWbXDaMwwlcpS0fPNnKS4Vh5tYyU9i0ABbaFLdevlIQrAN6842FWWSQgJA W5YY8KhnvReDTtSvMJovoe2YZJs6Pj6A7BwuOkiNhZJcscsEFKJFugOuLAdd90PgqF31 WGX//SQWE4i2AqKqJZdr8nTeFBjvCmDk6yOHFRp19krwxO0/dYJIk9B0ux738MitTW4t 7sfyJEDZ+hpqiFBeFeg+pxW1laZEr9Xqd7UlmFMcDS6+GBpHi0qnd1uhABfE2R2iBDWg 4RKmhAnz0KYerLPopSqf5peKpDMcBIR1rpiFoMOacMbJmPh7zVdJNkCtg6CP42YDEkjt U+lA== 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 ds1si8974541edb.568.2021.10.01.09.07.25; Fri, 01 Oct 2021 09:07:53 -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 S1354420AbhJAPuU (ORCPT + 99 others); Fri, 1 Oct 2021 11:50:20 -0400 Received: from 8bytes.org ([81.169.241.247]:42958 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231545AbhJAPuM (ORCPT ); Fri, 1 Oct 2021 11:50:12 -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 E3807494; Fri, 1 Oct 2021 17:48:26 +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 2/4] x86/mm/64: Flush global TLB on boot and AP bringup Date: Fri, 1 Oct 2021 17:48:15 +0200 Message-Id: <20211001154817.29225-3-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 The AP bringup code uses the trampoline_pgd page-table, which establishes global mappings in the user range of the address space. Flush the global TLB entries after the indentity mappings are removed so no stale entries remain in the TLB. Signed-off-by: Joerg Roedel --- arch/x86/kernel/head64.c | 15 +++++++++++++++ arch/x86/kernel/head_64.S | 19 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index de01903c3735..cae21afe0922 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -457,6 +457,19 @@ static void __init copy_bootdata(char *real_mode_data) sme_unmap_bootdata(real_mode_data); } +/* + * The __flush_tlb_all() function uses all kinds of state which is not + * initialized that early and can not be used here. So the helper below is used + * to flush global TLB entries. + */ +static void __init early_flush_tlb_global(void) +{ + unsigned long cr4 = native_read_cr4(); + + native_write_cr4(cr4 ^ X86_CR4_PGE); + native_write_cr4(cr4); +} + asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data) { /* @@ -478,6 +491,8 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data) /* Kill off the identity-map trampoline */ reset_early_page_tables(); + early_flush_tlb_global(); + clear_bss(); clear_page(init_top_pgt); diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index d8b3ebd2bb85..bd4b6ebafdc3 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -166,9 +166,26 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) call sev_verify_cbit popq %rsi - /* Switch to new page-table */ + /* + * Switch to new page-table + * + * For the boot CPU this switches to early_top_pgt which still has the + * indentity mappings present. The secondary CPUs will switch to the + * init_top_pgt here, away from the trampoline_pgd and unmapping the + * indentity mapped ranges. + * + * Do a global TLB flush after the CR3 switch to make sure the TLB + * entries from the identity mapping are flushed. + */ movq %rax, %cr3 + /* Flush global TLB entries - only needed for secondary CPUs */ + movq %cr4, %rcx + movq %rcx, %rax + xorq $X86_CR4_PGE, %rcx + movq %rcx, %cr4 + movq %rax, %cr4 + /* Ensure I am executing from virtual addresses */ movq $1f, %rax ANNOTATE_RETPOLINE_SAFE -- 2.33.0