Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1882585rda; Tue, 24 Oct 2023 06:21:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENPv+1+HwqhynYvkPg5EkRdygKGw8/LhxV3/iXQkSnQ6WuaLMJWhaTSX1jNAmztrE0319d X-Received: by 2002:a17:90a:df95:b0:27d:4249:4040 with SMTP id p21-20020a17090adf9500b0027d42494040mr8942730pjv.43.1698153694433; Tue, 24 Oct 2023 06:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698153694; cv=none; d=google.com; s=arc-20160816; b=r8O+UCbcJ4rqFNQ4DSI65zgeQnMl/YIghhVZDvetYcVPKV25IdbYTHbWrPDulgz5hE s2psti2TjoEH0mwvUZVMQB4yJhfspUowT7yr6pEg/9zu6jzdqpWsyLllUST9PsPHLSJe NTO4sT4uqIxAK2D8FmSdqF2ZJ9PgiEXjFWeAAc0Zkd1Eza9/WIckfq46DMC0RBZq1OEa hAdlnCZSKuMRmiMh8oigeH0f5mndZUqhWS2Hf/800wslMtfSJ0yt908xWEGaMlZpmhLT UWLfbmDZJyOtWEMhlF/gqjXMrxf+mREhO2fmSk1MtlKY9hnFaWTPiZJ9S/3LRWtr/Krp 0wNw== 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:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=DHzz0+pu/Bt+oTOij9+XCvthouCL+Q3kebi5Xyb+BW0=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=XyuiEmo/aUtiTpTBHFNhC7MvmoJAuF5KOuVzCjDOxuHu9uJLCZEHjNoRpq0WRUyzIk dVtkYyMPuNCSpUvU8dgOx3GQMGbVQqGK2kg9nItJ1FrybRnNRZOQi53N9KVmUhLH/OV7 szlNzoBwd4Q+DKDQcTnCnBCmdtvDiXqWd1PLAihfpboj3cxyH1xklvK8P7rP9W5X4Ust sJXj3ZYVvuopuu2ZLNh5qLv/s6Dnpfvd/kL+XI+JF2XF+xAlDDr+HIQPq/lF3u7wSYGN CUzOHZa0uljBjggspFaXPBt50y8eUnAt4BAmaejymqwYmomCELWsbkC9amPHDA+8oMMZ 53ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QCJl0h75; dkim=neutral (no key) header.i=@linutronix.de header.b=dVX3FEXy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d8-20020a170902654800b001c9ed124cd7si8194441pln.650.2023.10.24.06.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 06:21:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QCJl0h75; dkim=neutral (no key) header.i=@linutronix.de header.b=dVX3FEXy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E9916802C8CC; Tue, 24 Oct 2023 06:21:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234629AbjJXNVX (ORCPT + 99 others); Tue, 24 Oct 2023 09:21:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234491AbjJXNUz (ORCPT ); Tue, 24 Oct 2023 09:20:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B144CC; Tue, 24 Oct 2023 06:20:52 -0700 (PDT) Date: Tue, 24 Oct 2023 13:20:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1698153650; 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: in-reply-to:in-reply-to:references:references; bh=DHzz0+pu/Bt+oTOij9+XCvthouCL+Q3kebi5Xyb+BW0=; b=QCJl0h75L0nnclWUZfu7bKoespitIoBl/ynk0pSjtvEHqPtbdMTJPnP5ggvVsF7WEBndY0 2cRQO6lzTmfs70XYd1rtHeRUaiHEaSQTy5Sb4ZtNfCIEkKpl6xmd8lkW9hLkqaC6jFjOgB TYTEIYtGkS49HYzaLUEI8YZyX6MwrwCxXqRGyEtjMLgd85hc7KUm9X5h1WsALN4dlYX0RG xcCuvvRMXanrQmnD8lK0tew73CINBOAsg2awp+gtB3iGAQmI1C57srXVl1sG2l42k50Q3Q rTqyn4xXQq3hZRX0b6hS++5O3k10CruugNPxiGBhFX0iMyscLF199lNN22Igug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1698153650; 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: in-reply-to:in-reply-to:references:references; bh=DHzz0+pu/Bt+oTOij9+XCvthouCL+Q3kebi5Xyb+BW0=; b=dVX3FEXyB3m3opVTE1Y84UwGRcajmZwPWTBiYcxIyVmLQUh7cFaP6pOHCaiMvREHq3Se/H lNBaoD3Sr+/XqBDw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/microcode] x86/apic: Provide apic_force_nmi_on_cpu() Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115903.603100036@linutronix.de> References: <20231002115903.603100036@linutronix.de> MIME-Version: 1.0 Message-ID: <169815365016.3135.17531359789109646623.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 06:21:33 -0700 (PDT) The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 9cab5fb776d4367e26950cf759211e948335288e Gitweb: https://git.kernel.org/tip/9cab5fb776d4367e26950cf759211e948335288e Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 14:00:07 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 24 Oct 2023 15:05:55 +02:00 x86/apic: Provide apic_force_nmi_on_cpu() When SMT siblings are soft-offlined and parked in one of the play_dead() variants they still react on NMI, which is problematic on affected Intel CPUs. The default play_dead() variant uses MWAIT on modern CPUs, which is not guaranteed to be safe when updated concurrently. Right now late loading is prevented when not all SMT siblings are online, but as they still react on NMI, it is possible to bring them out of their park position into a trivial rendezvous handler. Provide a function which allows to do that. I does sanity checks whether the target is in the cpus_booted_once_mask and whether the APIC driver supports it. Mark X2APIC and XAPIC as capable, but exclude 32bit and the UV and NUMACHIP variants as that needs feedback from the relevant experts. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231002115903.603100036@linutronix.de --- arch/x86/include/asm/apic.h | 5 ++++- arch/x86/kernel/apic/apic_flat_64.c | 2 ++ arch/x86/kernel/apic/ipi.c | 8 ++++++++ arch/x86/kernel/apic/x2apic_cluster.c | 1 + arch/x86/kernel/apic/x2apic_phys.c | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 5af4ec1..17f2f28 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -276,7 +276,8 @@ struct apic { u32 disable_esr : 1, dest_mode_logical : 1, - x2apic_set_max_apicid : 1; + x2apic_set_max_apicid : 1, + nmi_to_offline_cpu : 1; u32 (*calc_dest_apicid)(unsigned int cpu); @@ -542,6 +543,8 @@ extern bool default_check_apicid_used(physid_mask_t *map, int apicid); extern void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap); extern int default_cpu_present_to_apicid(int mps_cpu); +void apic_send_nmi_to_offline_cpu(unsigned int cpu); + #else /* CONFIG_X86_LOCAL_APIC */ static inline unsigned int read_apic_id(void) { return 0; } diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c index 032a84e..cd16228 100644 --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -103,6 +103,7 @@ static struct apic apic_flat __ro_after_init = { .send_IPI_allbutself = default_send_IPI_allbutself, .send_IPI_all = default_send_IPI_all, .send_IPI_self = default_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_mem_read, .write = native_apic_mem_write, @@ -175,6 +176,7 @@ static struct apic apic_physflat __ro_after_init = { .send_IPI_allbutself = default_send_IPI_allbutself, .send_IPI_all = default_send_IPI_all, .send_IPI_self = default_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_mem_read, .write = native_apic_mem_write, diff --git a/arch/x86/kernel/apic/ipi.c b/arch/x86/kernel/apic/ipi.c index a44ba72..edad86f 100644 --- a/arch/x86/kernel/apic/ipi.c +++ b/arch/x86/kernel/apic/ipi.c @@ -97,6 +97,14 @@ sendmask: __apic_send_IPI_mask(mask, CALL_FUNCTION_VECTOR); } +void apic_send_nmi_to_offline_cpu(unsigned int cpu) +{ + if (WARN_ON_ONCE(!apic->nmi_to_offline_cpu)) + return; + if (WARN_ON_ONCE(!cpumask_test_cpu(cpu, &cpus_booted_once_mask))) + return; + apic->send_IPI(cpu, NMI_VECTOR); +} #endif /* CONFIG_SMP */ static inline int __prepare_ICR2(unsigned int mask) diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c index affbff6..a830608 100644 --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -251,6 +251,7 @@ static struct apic apic_x2apic_cluster __ro_after_init = { .send_IPI_allbutself = x2apic_send_IPI_allbutself, .send_IPI_all = x2apic_send_IPI_all, .send_IPI_self = x2apic_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_msr_read, .write = native_apic_msr_write, diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c index 788cdb4..c8ac1b1 100644 --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -166,6 +166,7 @@ static struct apic apic_x2apic_phys __ro_after_init = { .send_IPI_allbutself = x2apic_send_IPI_allbutself, .send_IPI_all = x2apic_send_IPI_all, .send_IPI_self = x2apic_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_msr_read, .write = native_apic_msr_write,