Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3430063rdg; Tue, 17 Oct 2023 14:49:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHh1yUsRw2ns4DZzji3hGDWNb1QwDU8RYc+D3pzJI5JqX5yAOfotTXxVjG/lUBNAMLrsFgV X-Received: by 2002:a17:902:f549:b0:1b8:954c:1f6 with SMTP id h9-20020a170902f54900b001b8954c01f6mr4542103plf.36.1697579386654; Tue, 17 Oct 2023 14:49:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697579386; cv=none; d=google.com; s=arc-20160816; b=DgR26gzWprtjEIkII587aiMuuKc1/Xy7Npiy1UkIUfoneN0EdoL7uDcVnjoOMsHSb4 kYcBcBrA9Nr2sDDwTQCBV/wLw85RAb61eS2JUm8kq3VW9zt1QW4K/JTWr94F8Fipj4xd pa0wxVVI9WxVGpF3J2zmPRQG9y5Vs/2c4+ItYNXqiVW4qc3shKkmxprN/Us5oXjQNHXk LbRXXmMPP0hPoyU5cBtH/PYU0ECLosXJbskt4J6sEMX367gm+TbYVlz435VjJpIoC0kC dq3A7PLDOjpJlq0dW1oa2wJxI6VsHSnTE7HVZQwXEQRj92I8a4C7t+tWYdghi7C1mvUD dzvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=upCMQ/5CIR2zAhmP8hpPxpV8M1jyj+Jpzo+XS/jhO+0=; fh=8iy+GLBXZdpcs/hIddJ7mbUapYjefwP9Gb111pAzFms=; b=yC2JBuJeIDyJuRiHgs6f2SjFM9BUeXZY9mN04BRtu+cB5mh1b27kw1GUbrrFSLspwL e3lnuE4hVNiyGZN+OpoJ7nyQfo77Gler+cg4HEZHxe6j0Fbv293TZvoxFpz2xwaC9sc5 GLXP3a/L8JX9Bh4+QC53niNbX7hlO0h039+4hHxA0Mx7Ueyg8L4jENQ7QIX+ChhTTWdx F0VS435iYmGbHxlHb5yz+zAziqdYhZ/jeTZUX6EmtglpdCOyC3/9hEjA4pDwyApyIVnM DGbwSeQ5K2Q8c6L5dKlqCEICSzowR3/AJVdacdF7DMzqFLF619sR4FB88coNRHzOUuoK B3lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1PnSod6v; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id k8-20020a170902694800b001bf1005924csi2493340plt.321.2023.10.17.14.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 14:49:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1PnSod6v; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 17CD08027B49; Tue, 17 Oct 2023 14:49:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234147AbjJQVtg (ORCPT + 99 others); Tue, 17 Oct 2023 17:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbjJQVtf (ORCPT ); Tue, 17 Oct 2023 17:49:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D995EB0 for ; Tue, 17 Oct 2023 14:49:33 -0700 (PDT) Message-ID: <20231017211723.968077065@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697579372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=upCMQ/5CIR2zAhmP8hpPxpV8M1jyj+Jpzo+XS/jhO+0=; b=1PnSod6vZzDr9jJkGLsmQyMOGlxpyZVl325FufYwCF48Xw+wAgYWx9erUjmqms9yvST0sN KXyzLp4Ero8ZBtP9Gd33QYnedGX20/+CfN/HkPszzJ1mVsMCGd8a44Jfu+D7Tg3pdRqmk2 XxHeqONERElAlL31lC5cgBUcnKBWswAhk/ThxGBr+sugzm7uzI/Gkj8DE0y9JZUXMBQxZJ V5Jpx2QjnUSn7gF0fmdGsP0hIfelaX3MPsFNadzJ7T7Zo5QQYDU+Xp3nyl8J3oG+fT0JYT lcihwE8oqgaBhvRZYE+nMWD8VjwSN00MJZ47waqRDb9btSCWXdRZAdkERKO2uA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697579372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=upCMQ/5CIR2zAhmP8hpPxpV8M1jyj+Jpzo+XS/jhO+0=; b=SxAZKWhlYrQ2qxhOmlrf/Q5QqX8qsd/s9oTnpL6P42nkGhcv4nm1Q7girkdq3YhV4aNzcW ptj/64LlUFzwrGAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov Subject: [patch V5 36/39] x86/apic: Provide apic_force_nmi_on_cpu() References: <20231017200758.877560658@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 17 Oct 2023 23:24:13 +0200 (CEST) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 14:49:44 -0700 (PDT) From: Thomas Gleixner 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 --- 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(-) --- --- 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(ph 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; } --- 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_ .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_af .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, --- a/arch/x86/kernel/apic/ipi.c +++ b/arch/x86/kernel/apic/ipi.c @@ -97,6 +97,14 @@ void native_send_call_func_ipi(const str __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) --- 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 _ .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, --- 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 .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,