From patchwork Wed May 17 21:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 95576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp77477vqo; Wed, 17 May 2023 15:01:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7urfnrEB9JSWgViu+WVf2H6EKfQPrbkbECalpWXQtH4SpHOBsTC7F87cpJxaieomWo7/yv X-Received: by 2002:a17:902:e745:b0:1ae:4292:f1c0 with SMTP id p5-20020a170902e74500b001ae4292f1c0mr248039plf.47.1684360910435; Wed, 17 May 2023 15:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684360910; cv=none; d=google.com; s=arc-20160816; b=FtnSMgmI3REi5GppIWbPPCCpzSK160weG9sMPizHKkY287jZOAAo8cZIUnFU150U7O 3f8i4blZ/DvmeGAnO88YzNhqOLIl2vbn003dQVyqSz5y4HnLR2JXUiXh0RLoKGlOjCaD opuTuGIWtt8Ot44xTDuji32nmiSHd6Ihnh7s3RkfA7hMdCEweY0GCHql6lBfW9kZPjBl qiXypTTy+xe2TNcLOdeVFWYhis1rv8jXPFocFzgobhfecet4Zn0L7hunKt8JJakay3er C4ZhvTo3NJ9xTTRo/3gTN3WNJLSmUhI6i0YQbwNeTM6y2YKzzHmnh8SIt76uzRV77HC2 qu4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=ixxUzxjjfsnbP6oJRKzWVldOG+Bm+11hZ2PkJgmgdYo=; b=Rz4ywoBwwarYnMgSsMG+b7Apzby6Dwp/O9v/cIeB1VZn7hyVBWPdco/u32YkJrb+vJ sGv9GNgW/GU5I/WR/hgrFr9okzuHFaX/k9WnW04Ld5XL1vhEUEeYOp9hSuQ+VkBX1i66 UJZdXupZSaEGvc4mA2WnoxFaYMWooXb3kusBD662w9i3GNW0mZc3hpsplbLuLzSizoxh sADXOX19w0SGc4RXDCWIVeNSJY70uHNQm2giIjSL53wamXu4CqcwyQQPpXMmmBi4cYxz ra54bbxf6qIwGddj9bQhXzOTQ/euPjdNiU+NLbBHZb9axtclpsgMFktlFJOTgiyrGxBY h+Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0jGoR85a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=8cRGbrwb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a170902c20d00b001ac38646f0csi21030036pll.27.2023.05.17.15.01.14; Wed, 17 May 2023 15:01:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0jGoR85a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=8cRGbrwb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229571AbjEQV4l (ORCPT + 99 others); Wed, 17 May 2023 17:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjEQV4k (ORCPT ); Wed, 17 May 2023 17:56:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE13126B7; Wed, 17 May 2023 14:56:38 -0700 (PDT) Date: Wed, 17 May 2023 21:56:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684360596; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ixxUzxjjfsnbP6oJRKzWVldOG+Bm+11hZ2PkJgmgdYo=; b=0jGoR85aFzxhzq0tU9nBOSeJlTjohhXR30cVa78jqmA8BFU/7o2Gm/LIOdIptebzyc0R9I ypFG9a3f+++CV8qN60FyKVZKFwT6hp2iChUCq9YteuKKNDxSuznV0TnNn8l6GHyBKh49gq O6SqsyfkGbK06J1HUSPTpM3WCh6ytpyKKgCDaSB1QyiER1+wMPtgSMMetFP7PhZvAIpxRI UQ2NVTSZsDRnkYAHEX0SrZBBzMmiCsYCeKIu8tgxhkzA0Tbmk0tNO+MHdCTSBh2+m1JO/D /2gG6cSD5CY/7o5sVTOAGvOoC9jdJboVEiLgAWwIqU4EuWCSyhg379y+n0D81A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684360596; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ixxUzxjjfsnbP6oJRKzWVldOG+Bm+11hZ2PkJgmgdYo=; b=8cRGbrwbfKERg06qduq1ebGfr6WDUrf2Ubjey4aY/K8AWm1XUEyXflK0pk5WYC1tUDiaYO hsqNpRLd5KkLApAw== From: "tip-bot2 for Dave Hansen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/mm: Avoid incomplete Global INVLPG flushes Cc: Dave Hansen , Thomas Gleixner , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168436059559.404.13934972543631851306.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766180426342650378?= X-GMAIL-MSGID: =?utf-8?q?1766180426342650378?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: ce0b15d11ad837fbacc5356941712218e38a0a83 Gitweb: https://git.kernel.org/tip/ce0b15d11ad837fbacc5356941712218e38a0a83 Author: Dave Hansen AuthorDate: Tue, 16 May 2023 12:24:25 -07:00 Committer: Dave Hansen CommitterDate: Wed, 17 May 2023 08:55:02 -07:00 x86/mm: Avoid incomplete Global INVLPG flushes The INVLPG instruction is used to invalidate TLB entries for a specified virtual address. When PCIDs are enabled, INVLPG is supposed to invalidate TLB entries for the specified address for both the current PCID *and* Global entries. (Note: Only kernel mappings set Global=1.) Unfortunately, some INVLPG implementations can leave Global translations unflushed when PCIDs are enabled. As a workaround, never enable PCIDs on affected processors. I expect there to eventually be microcode mitigations to replace this software workaround. However, the exact version numbers where that will happen are not known today. Once the version numbers are set in stone, the processor list can be tweaked to only disable PCIDs on affected processors with affected microcode. Note: if anyone wants a quick fix that doesn't require patching, just stick 'nopcid' on your kernel command-line. Signed-off-by: Dave Hansen Reviewed-by: Thomas Gleixner Cc: stable@vger.kernel.org --- arch/x86/mm/init.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 3cdac0f..8192452 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -261,6 +262,24 @@ static void __init probe_page_size_mask(void) } } +#define INTEL_MATCH(_model) { .vendor = X86_VENDOR_INTEL, \ + .family = 6, \ + .model = _model, \ + } +/* + * INVLPG may not properly flush Global entries + * on these CPUs when PCIDs are enabled. + */ +static const struct x86_cpu_id invlpg_miss_ids[] = { + INTEL_MATCH(INTEL_FAM6_ALDERLAKE ), + INTEL_MATCH(INTEL_FAM6_ALDERLAKE_L ), + INTEL_MATCH(INTEL_FAM6_ALDERLAKE_N ), + INTEL_MATCH(INTEL_FAM6_RAPTORLAKE ), + INTEL_MATCH(INTEL_FAM6_RAPTORLAKE_P), + INTEL_MATCH(INTEL_FAM6_RAPTORLAKE_S), + {} +}; + static void setup_pcid(void) { if (!IS_ENABLED(CONFIG_X86_64)) @@ -269,6 +288,12 @@ static void setup_pcid(void) if (!boot_cpu_has(X86_FEATURE_PCID)) return; + if (x86_match_cpu(invlpg_miss_ids)) { + pr_info("Incomplete global flushes, disabling PCID"); + setup_clear_cpu_cap(X86_FEATURE_PCID); + return; + } + if (boot_cpu_has(X86_FEATURE_PGE)) { /* * This can't be cr4_set_bits_and_update_boot() -- the