From patchwork Thu Feb 6 15:06:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13963193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA5F1C02198 for ; Thu, 6 Feb 2025 15:06:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.882922.1293013 (Exim 4.92) (envelope-from ) id 1tg3ST-00037i-PL; Thu, 06 Feb 2025 15:06:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 882922.1293013; Thu, 06 Feb 2025 15:06:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3ST-00036R-KP; Thu, 06 Feb 2025 15:06:25 +0000 Received: by outflank-mailman (input) for mailman id 882922; Thu, 06 Feb 2025 15:06:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SS-0002qa-T7 for xen-devel@lists.xenproject.org; Thu, 06 Feb 2025 15:06:24 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id edcfcb7a-e49b-11ef-b3ef-695165c68f79; Thu, 06 Feb 2025 16:06:23 +0100 (CET) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5dca468c5e4so2189388a12.1 for ; Thu, 06 Feb 2025 07:06:23 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dcf1b816basm1008818a12.41.2025.02.06.07.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 07:06:21 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: edcfcb7a-e49b-11ef-b3ef-695165c68f79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1738854382; x=1739459182; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hGR2Lv/mW9KuxkkD8t/npxcQHCyRBY4y4xXkUseCwDU=; b=IkncwZP3TwbFqWg02E2sbW8ztYt4EKPFTqGJtEobzDm0P2fbakQtuZwyYpLJt1o1BC N36AcJ6bWdXBmp8WIhpYMnzBY8OcDGPtujlLKAKJo9HI+sbb4o5LZ8EhpP0y12bWiVQZ saD70Xq8V3mVLZrPlNSQ303bP3T7FS7Rad2HQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738854382; x=1739459182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hGR2Lv/mW9KuxkkD8t/npxcQHCyRBY4y4xXkUseCwDU=; b=CPMgKpG5WIAHwDL9bMLcNIf8cbK+kxqZ36KZDuZmHx/eAqiUzjKIG7LNa76jGWQomm AgfsXQs7xcbf62Z+ht7ZKq2m/xuh1QRMshDnS7oOFdOJGin+RpwrGDO+TYLP3DsrVpDG lZh05+swp29Fusnr5oz7KpqQT18YuXaNp0W4t+LyH/cvZSepHWoRC/AQwvacH4cDmu39 wsTFjSTUuM0iKusR6PfpVvPNlbJ31uOhIwBZR1b8u1Vk13G3X1ZflsEL5AZ7nAnbQ79S iEUPM89OfuZaD0fJRBo24B5Rx0fBw8GF/Rz8VEXksmf+VNWx5dXDm0ei05khI5h3Jgev 7HUQ== X-Gm-Message-State: AOJu0YwxplqRvXyrm80yOdFGiYqxxFygfTjS1+uPaO4dQyNGwUIUHMwy 8g6AGMuEdI5Q5xjLuDEv14y5qEd7SVr5GNO/fHgwe2Wpa2lxNodM+9fUYX3SAvsON7yUW/jaJeR a X-Gm-Gg: ASbGnctnXJ5PlpdHxbyEqaNOFH1zfxGk98A1a1wUgRGkV4NOMm4lyIgnxCfbaIFyVG7 6Vf2dtdbGf7suTstfHOxjXgK6brduToLSvzaBl0aIR+t7S0ucort42GqvRFhzw/b/zrMV7OkqRq qoIga35n3ET/5meGPgO9jb0koAMdUZl11J1pvwd1xheQXy/gNP3KAndgeJO18iweCLlxAdcdWHo qfzS4buCvFL74mxm7sFhYqKpVNY9rcdk5nqxQV0o9rDCQqhxoztIyJl2bWkrs0UXZ4bmJJuFEdi ArhJtGGu4IikMTr1U5Lj X-Google-Smtp-Source: AGHT+IGAQFvH/dEQXRFyJlGVX4PdFvbiKiEftNxUwgnWUyHa10Cm0b86iWTYF5Hdextsdis3g/djew== X-Received: by 2002:a05:6402:321e:b0:5dc:88dd:38aa with SMTP id 4fb4d7f45d1cf-5dcdb7329d1mr6755060a12.8.1738854382242; Thu, 06 Feb 2025 07:06:22 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 1/5] x86/shutdown: offline APs with interrupts disabled on all CPUs Date: Thu, 6 Feb 2025 16:06:11 +0100 Message-ID: <20250206150615.52052-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250206150615.52052-1-roger.pau@citrix.com> References: <20250206150615.52052-1-roger.pau@citrix.com> MIME-Version: 1.0 The current shutdown logic in smp_send_stop() will disable the APs while having interrupts enabled on the BSP or possibly other APs. On AMD systems this can lead to local APIC errors: APIC error on CPU0: 00(08), Receive accept error Such error message can be printed in a loop, thus blocking the system from rebooting. I assume this loop is created by the error being triggered by the console interrupt, which is further stirred by the ESR handler printing to the console. Intel SDM states: "Receive Accept Error. Set when the local APIC detects that the message it received was not accepted by any APIC on the APIC bus, including itself. Used only on P6 family and Pentium processors." So the error shouldn't trigger on any Intel CPU supported by Xen. However AMD doesn't make such claims, and indeed the error is broadcasted to all local APICs when an interrupt targets a CPU that's already offline. To prevent the error from stalling the shutdown process perform the disabling of APs and the BSP local APIC with interrupts disabled on all CPUs in the system, so that by the time interrupts are unmasked on the BSP the local APIC is already disabled. This can still lead to a spurious: APIC error on CPU0: 00(00) As a result of an LVT Error getting injected while interrupts are masked on the CPU, and the vector only handled after the local APIC is already disabled. Note the NMI crash path doesn't have such issue, because disabling of APs and the caller local APIC is already done in the same contiguous region with interrupts disabled. There's a possible window on the NMI crash path (nmi_shootdown_cpus()) where some APs might be disabled (and thus interrupts targeting them raising "Receive accept error") before others APs have interrupts disabled. However the shutdown NMI will be handled, regardless of whether the AP is processing a local APIC error, and hence such interrupts will not cause the shutdown process to get stuck. Remove the call to fixup_irqs() in smp_send_stop(), as it doesn't achieve the intended goal of moving all interrupts to the BSP anyway, because when called the APs are still set as online in cpu_online_map. Signed-off-by: Roger Pau Monné --- Changes since v1: - Change the approach and instead rely on having interrupts uniformly disabled when offlining APs. --- xen/arch/x86/smp.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index 02a6ed7593f3..074baae2cc3b 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -345,6 +345,11 @@ void __stop_this_cpu(void) static void cf_check stop_this_cpu(void *dummy) { + const bool *stop_aps = dummy; + + while ( !*stop_aps ) + cpu_relax(); + __stop_this_cpu(); for ( ; ; ) halt(); @@ -357,16 +362,25 @@ static void cf_check stop_this_cpu(void *dummy) void smp_send_stop(void) { unsigned int cpu = smp_processor_id(); + bool stop_aps = false; + + /* + * Perform AP offlining and disabling of interrupt controllers with all + * CPUs on the system having interrupts disabled to prevent interrupt + * delivery errors. On AMD systems "Receive accept error" will be + * broadcasted to local APICs if interrupts target CPUs that are offline. + */ + if ( num_online_cpus() > 1 ) + smp_call_function(stop_this_cpu, &stop_aps, 0); + + local_irq_disable(); if ( num_online_cpus() > 1 ) { int timeout = 10; - local_irq_disable(); - fixup_irqs(cpumask_of(cpu), 0); - local_irq_enable(); - - smp_call_function(stop_this_cpu, NULL, 0); + /* Signal APs to stop. */ + stop_aps = true; /* Wait 10ms for all other CPUs to go offline. */ while ( (num_online_cpus() > 1) && (timeout-- > 0) ) @@ -375,13 +389,12 @@ void smp_send_stop(void) if ( cpu_online(cpu) ) { - local_irq_disable(); disable_IO_APIC(); hpet_disable(); __stop_this_cpu(); x2apic_enabled = (current_local_apic_mode() == APIC_MODE_X2APIC); - local_irq_enable(); } + local_irq_enable(); } void smp_send_nmi_allbutself(void) From patchwork Thu Feb 6 15:06:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13963195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3CF5AC02194 for ; Thu, 6 Feb 2025 15:06:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.882923.1293029 (Exim 4.92) (envelope-from ) id 1tg3SV-0003ZW-WB; Thu, 06 Feb 2025 15:06:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 882923.1293029; Thu, 06 Feb 2025 15:06:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SV-0003ZO-T1; Thu, 06 Feb 2025 15:06:27 +0000 Received: by outflank-mailman (input) for mailman id 882923; Thu, 06 Feb 2025 15:06:26 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SU-0002qa-If for xen-devel@lists.xenproject.org; Thu, 06 Feb 2025 15:06:26 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id eecf43c3-e49b-11ef-b3ef-695165c68f79; Thu, 06 Feb 2025 16:06:25 +0100 (CET) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5dca468c5e4so2189462a12.1 for ; Thu, 06 Feb 2025 07:06:25 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dcf9f952casm1005879a12.81.2025.02.06.07.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 07:06:23 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: eecf43c3-e49b-11ef-b3ef-695165c68f79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1738854384; x=1739459184; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xm1F4/LWDRjOr5tGbdwduMf0+aedjlnrUC4bJARj2yg=; b=sFfnaEWLqZLkMDbuQovuPTLXpoGdEffy6RW2iqJEWK4maqzmpxNbAXbkHCPoKDX76H 4JOxWMFk9DKq6y8IGJkhyg7+ztR1CAYHc2+Ur2Cb0eRuG06mxy3iETlnibl8oYKtRbhr ehhKIPWq2q7fvwzYvg8eSZgjDpW2RcdiGbdUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738854384; x=1739459184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xm1F4/LWDRjOr5tGbdwduMf0+aedjlnrUC4bJARj2yg=; b=lboFwGo0OaHri52/pWoMXYr4U+CGndHBq1X9GKel60EFu8KpubjiX/Wv1qIgYumzkr Q5ZXii49JPN2bYojLDp6XeAwgRb2zg7nAGk6HFDtdd5BoB1tUY6LbvtjIRe5tm4KvrzD L22g69M82NDy61uVp7UZ+WJz6DkgQmsSYx5te/7qCIiwxD4jUiWM0XrCVVDsp7wSwRin 0tnGCnq9o0exP1nR+s837ZIpnNVSnhDYk9i8VOCt11Vhd14hjLTK5HXz9B9b/B8Gfvmw lIQ6ndwsbklh4EFM6SNYcIfLX7SWCf2H0PtrjAGA6qSN0w+gFFcyW6Z5rTGrN2ySUbl6 DkoA== X-Gm-Message-State: AOJu0YzgBlbHVUMeHYR7mJHzzzOx2Tj0XrUQDchLiWVEm4duzJl03h/R sApKW1yvtuguk6xL+rKmu+RL014FcxCPQPUqmqp9N9J0C/fmgzpkYjuOZq7777YcyF+H2TS0RK/ 7 X-Gm-Gg: ASbGnctNbXqdbEFJesdAUc1wniGIHcP2KtuLaf8BWrucf9YSUNHl5VxfMr/dX2QfQ+E F0YdyJJPJqo2imTZ8QSmJQm1M2yf3mnGRtfXmunB9ct3/R1vxUBf5RHzQTTd4awYIAcCJAs+iAZ S084FtdNMZhPduk0vnr3OygYQHNNrxnVvg0iLD0SHr5vzqSEzD88mBIR2BIQggKxeY1OOKZI3DV QOUJAn24K9ip/cXTukRkZu0S899Xt8O3+3KMyy0eM/9qBho5GPoRZsCowudhs2LALC9abUzhCJQ ZyatKWYJYHEhFEA+/9QH X-Google-Smtp-Source: AGHT+IEqfzSJcLtiZZ7Gwzgf0wFdVc5OJNyojfhwDjWLvVeRVXVV3uduhSDKDO3D5BHocMUt9AX07g== X-Received: by 2002:a05:6402:3707:b0:5db:e7eb:1b4a with SMTP id 4fb4d7f45d1cf-5dcdb732c6amr8066409a12.10.1738854383971; Thu, 06 Feb 2025 07:06:23 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 2/5] x86/irq: drop fixup_irqs() parameters Date: Thu, 6 Feb 2025 16:06:12 +0100 Message-ID: <20250206150615.52052-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250206150615.52052-1-roger.pau@citrix.com> References: <20250206150615.52052-1-roger.pau@citrix.com> MIME-Version: 1.0 The solely remaining caller always passes the same globally available parameters. Drop the parameters and modify fixup_irqs() to use cpu_online_map in place of the input mask parameter, and always be verbose in its output printing. While there remove some of the checks given the single context where fixup_irqs() is now called, which should always be in the CPU offline path, after the CPU going offline has been removed from cpu_online_map. No functional change intended. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- There's more cleanup that can likely be done here, but it's best if such cleanup is done after the cpu_mask and old_cpu_mask irq_desc fields are converted from cpu masks to integers, as logic delivery mode should never be used for external interrupts now. --- xen/arch/x86/include/asm/irq.h | 4 ++-- xen/arch/x86/irq.c | 30 +++++++++++++----------------- xen/arch/x86/smpboot.c | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/xen/arch/x86/include/asm/irq.h b/xen/arch/x86/include/asm/irq.h index d3bc76806808..354868ba31ab 100644 --- a/xen/arch/x86/include/asm/irq.h +++ b/xen/arch/x86/include/asm/irq.h @@ -168,8 +168,8 @@ void free_domain_pirqs(struct domain *d); int map_domain_emuirq_pirq(struct domain *d, int pirq, int emuirq); int unmap_domain_pirq_emuirq(struct domain *d, int pirq); -/* Evacuate interrupts assigned to CPUs not present in the input CPU mask. */ -void fixup_irqs(const cpumask_t *mask, bool verbose); +/* Evacuate interrupts assigned to CPUs not present in the CPU online map. */ +void fixup_irqs(void); void fixup_eoi(void); int init_irq_data(void); diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index e56bacc88d84..ff3ac832f4b9 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -2590,17 +2590,21 @@ static int __init cf_check setup_dump_irqs(void) } __initcall(setup_dump_irqs); -/* Evacuate interrupts assigned to CPUs not present in the input CPU mask. */ -void fixup_irqs(const cpumask_t *mask, bool verbose) +/* Evacuate interrupts assigned to CPUs not present in the CPU online map. */ +void fixup_irqs(void) { + const unsigned int cpu = smp_processor_id(); unsigned int irq; static int warned; struct irq_desc *desc; + /* Only to be called from the context of a CPU going offline. */ + ASSERT(!cpu_online(cpu)); + for ( irq = 0; irq < nr_irqs; irq++ ) { bool break_affinity = false, set_affinity = true, check_irr = false; - unsigned int vector, cpu = smp_processor_id(); + unsigned int vector; cpumask_t *affinity = this_cpu(scratch_cpumask); if ( irq == 2 ) @@ -2644,12 +2648,6 @@ void fixup_irqs(const cpumask_t *mask, bool verbose) } if ( desc->arch.move_in_progress && - /* - * Only attempt to adjust the mask if the current CPU is going - * offline, otherwise the whole system is going down and leaving - * stale data in the masks is fine. - */ - !cpu_online(cpu) && cpumask_test_cpu(cpu, desc->arch.old_cpu_mask) ) { /* @@ -2691,16 +2689,17 @@ void fixup_irqs(const cpumask_t *mask, bool verbose) /* * Avoid shuffling the interrupt around as long as current target CPUs - * are a subset of the input mask. What fixup_irqs() cares about is - * evacuating interrupts from CPUs not in the input mask. + * are a subset of the online mask. What fixup_irqs() cares about is + * evacuating interrupts from CPUs not in the online mask. */ - if ( !desc->action || cpumask_subset(desc->arch.cpu_mask, mask) ) + if ( !desc->action || cpumask_subset(desc->arch.cpu_mask, + &cpu_online_map) ) { spin_unlock(&desc->lock); continue; } - if ( !cpumask_intersects(mask, desc->affinity) ) + if ( !cpumask_intersects(&cpu_online_map, desc->affinity) ) { break_affinity = true; cpumask_setall(affinity); @@ -2716,7 +2715,7 @@ void fixup_irqs(const cpumask_t *mask, bool verbose) * the interrupt, signal to check whether there are any pending vectors * to be handled in the local APIC after the interrupt has been moved. */ - if ( !cpu_online(cpu) && cpumask_test_cpu(cpu, desc->arch.cpu_mask) ) + if ( cpumask_test_cpu(cpu, desc->arch.cpu_mask) ) check_irr = true; if ( desc->handler->set_affinity ) @@ -2743,9 +2742,6 @@ void fixup_irqs(const cpumask_t *mask, bool verbose) spin_unlock(&desc->lock); - if ( !verbose ) - continue; - if ( !set_affinity ) printk("Cannot set affinity for IRQ%u\n", irq); else if ( break_affinity ) diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 79a79c54c304..891a29fca146 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -1282,7 +1282,7 @@ void __cpu_disable(void) /* It's now safe to remove this processor from the online map */ cpumask_clear_cpu(cpu, &cpu_online_map); - fixup_irqs(&cpu_online_map, 1); + fixup_irqs(); fixup_eoi(); } From patchwork Thu Feb 6 15:06:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13963194 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76B75C0219C for ; Thu, 6 Feb 2025 15:06:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.882924.1293033 (Exim 4.92) (envelope-from ) id 1tg3SW-0003d1-8p; Thu, 06 Feb 2025 15:06:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 882924.1293033; Thu, 06 Feb 2025 15:06:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SW-0003bh-32; Thu, 06 Feb 2025 15:06:28 +0000 Received: by outflank-mailman (input) for mailman id 882924; Thu, 06 Feb 2025 15:06:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SU-0002qU-Mm for xen-devel@lists.xenproject.org; Thu, 06 Feb 2025 15:06:26 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ef3b4ef6-e49b-11ef-a073-877d107080fb; Thu, 06 Feb 2025 16:06:25 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-ab34a170526so158449566b.0 for ; Thu, 06 Feb 2025 07:06:26 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab772f48882sm112961666b.19.2025.02.06.07.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 07:06:24 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ef3b4ef6-e49b-11ef-a073-877d107080fb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1738854385; x=1739459185; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YUB7j5PU81lCMl9pOkDJYuRzTQOkr6wGbhRdfM2H+aQ=; b=QP5hv4Dkr4v+E0E4oH93YA26iWgbymMz+SxINrM6iMzUYqja4G2oQHZdCFz0njJ8TM 1vXRiqnJh1x8h/txoVDePVbH0eBgEkaohh70jjsH4u0nGncP8aqCPMCAs6jMkppZKyn6 H0Smy8rMRHpd238SOJ3JbJyrBEgynGVXk/4LE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738854385; x=1739459185; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YUB7j5PU81lCMl9pOkDJYuRzTQOkr6wGbhRdfM2H+aQ=; b=LlD6FLT7YN661rU5XdSPJCKeuZvahvylA2EKsfHJYm2is7dqpvZqg6Is0jh4Fh/Wrp lPAg8uOe6K3w+el2XvrPO5QwPKyVBzekN2bKMPck0Vu9uiBab85r3hhbq7N3g4RAoq0T c4dBclyJrQnPaaadgGoHhcTC0JpaPAiR1TTuRktvnXA8keOA43iLMznBUtnC6W6lVBkd ZKz+4fYVqbmO0WafC+aNm7hNge9J4+aNKk4fgPB1xwkANXYx3fNtTQyqFxp01rw/c5JD s2ssLePpsfC8/SUSfjVWZQ7+T2xLLwtjwXgqQAScX/DTE9urgtg/tHPbm0ZXZpvq7OEP TwsQ== X-Gm-Message-State: AOJu0YyVW8p/e90osBihx9YSWV8xxKBZmCbh0OGU4xI0BhON+0/KkpXt 2eyqLxNnFIQ0DAj5oVJCtueQMokCqNrFuMGUVvoprHBgxmusdOQ8irpZ0fq48tZGA8Yfb3uXnsj n X-Gm-Gg: ASbGnctjFDpqreI0bUdZcwyDhnUWaEJIF9Ujnj3KnrpPaDKcHGLcwaENfKx4tLS/lAq MAZec9DgDbxcOqwjaELN9wOpglDvXaxCUYT2mWhy0PsLNEpqko6NeTNbbG6nuu0fotl8J+ROvHx 5JAtbS0laPPDOrCBFmZGWUJ0mFX02EXmbF8nrIK8rsJ1/SrStiyRbByWSWGz02gtEkmCjpCcw08 3ODFJOjzk/rCdZ0BeaHPdqV/s9JzJLOu6J6EWMSQL4v/vgh+0uUdfTXJJQVSBY0J07bcuqBqg75 UQoM6Hr4WGE/ihfXLZJU X-Google-Smtp-Source: AGHT+IHRcsWg/VLQDNL8qF0DeBnu7pa0bFWGB0fuxa9uaVmD76F8lAZOmrSiV6xDOUzUv866b59uRQ== X-Received: by 2002:a17:906:39cb:b0:ab7:6c50:5f19 with SMTP id a640c23a62f3a-ab76c505f30mr442729566b.31.1738854385294; Thu, 06 Feb 2025 07:06:25 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 3/5] x86/smp: perform disabling on interrupts ahead of AP shutdown Date: Thu, 6 Feb 2025 16:06:13 +0100 Message-ID: <20250206150615.52052-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250206150615.52052-1-roger.pau@citrix.com> References: <20250206150615.52052-1-roger.pau@citrix.com> MIME-Version: 1.0 Move the disabling of interrupt sources so it's done ahead of the offlining of APs. This is to prevent AMD systems triggering "Receive accept error" when interrupts target CPUs that are no longer online. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v1: - New in this version. --- xen/arch/x86/smp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index 074baae2cc3b..f931db0d71c6 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -374,6 +374,8 @@ void smp_send_stop(void) smp_call_function(stop_this_cpu, &stop_aps, 0); local_irq_disable(); + disable_IO_APIC(); + hpet_disable(); if ( num_online_cpus() > 1 ) { @@ -389,8 +391,6 @@ void smp_send_stop(void) if ( cpu_online(cpu) ) { - disable_IO_APIC(); - hpet_disable(); __stop_this_cpu(); x2apic_enabled = (current_local_apic_mode() == APIC_MODE_X2APIC); } From patchwork Thu Feb 6 15:06:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13963197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B33FBC0219D for ; Thu, 6 Feb 2025 15:06:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.882926.1293055 (Exim 4.92) (envelope-from ) id 1tg3Sa-0004BN-3q; Thu, 06 Feb 2025 15:06:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 882926.1293055; Thu, 06 Feb 2025 15:06:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SZ-0004AV-Rj; Thu, 06 Feb 2025 15:06:31 +0000 Received: by outflank-mailman (input) for mailman id 882926; Thu, 06 Feb 2025 15:06:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SY-0002qU-OI for xen-devel@lists.xenproject.org; Thu, 06 Feb 2025 15:06:30 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f155c01d-e49b-11ef-a073-877d107080fb; Thu, 06 Feb 2025 16:06:29 +0100 (CET) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5dcc38c7c6bso2054816a12.1 for ; Thu, 06 Feb 2025 07:06:29 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab772f491dcsm111083066b.22.2025.02.06.07.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 07:06:26 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f155c01d-e49b-11ef-a073-877d107080fb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1738854388; x=1739459188; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X0ovGj55iVS260GGwyIambmI1156khDmYHppn2PNqbM=; b=OfBcpQOiYku/j67p+tz8IqXEhVcGWQbt0hQ8uZdcPltFac7qSG+1NMdM7sJ1WzdeSS Sfa5YNAHZI3fsCGIyOfvVRW0rvpI6tnJ5QB+7Q6ZdAdExnqvtc5rf0SrX9t3b4Vgk2hr a+ZK+Wryn+srjZvgEbFUZVx4HVnDo+4hC1oLs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738854388; x=1739459188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X0ovGj55iVS260GGwyIambmI1156khDmYHppn2PNqbM=; b=S2hnegQN8DhIxNDW+uZF3Z3Q430ps6TNgxJhfDGBBbNMOSYHQ4Mdi/OxcQ5yB3KfIW wkhhwr8wTybtp+qlaaq1klvIIt8r7uwBNZ+7ZpezSEHYryDL0jmFQnc975FKf3fW/8Fz 7lMcmiWNKB3IMpiyWcZqk0KxjTrjOBc1ZxETx4W+dWRthqpsQ1eB9X282e0m+JdGrF9N uVb50PJmYVofkaKu7iVlH2batuYhEMwcPLR1LLMQ/XLryDIuV7i2fL/TFSIN7bh2hjWJ 8fX1BIYnIlqaycWFxDnFCEfb3mVc2az/fXD/iWdyda1KU+pslIvLNgVnhXuj2GPyAFBC akQA== X-Gm-Message-State: AOJu0YzhvHjfMwXSHmgm94PQX1qqDXIhUngiTfod0hOZfUtCwoYAI5+j Qq6fqDb8eC4ypmhYUBzfkXK3hXfV2+sPQQY/zn7m/eUvFZoCItvTxhE1s0bH2J7SA03skZyOufW l X-Gm-Gg: ASbGncvrDHZ3bqZFKp+zfcRvOJFBbZ4tW89KCc9Z5cJx4QydUCxlZqug1mIQGOjSEbK GhUVNRMe0V9k94LdN5kJd9lBupXQkZ+Dbl0u5zLUrbXOmslHLZZMmCkpn6egETZszoo6Sr9wSMB 73HQLcESqaJEkRx289hoO6RFA+6TmaIP43e2dHIIRK5EyMlPUCm1YP5TxhKXoNHSgRM6b6Bfny6 QHd1PpeLNunXRwZJgSQ06+Jv8Bium6uTRrQ956XxikeLgvCZxik21rUanmy8srCN1MW3n+CKrKT 8BP271CjjTXKlpRf/L3B X-Google-Smtp-Source: AGHT+IHGlVhkxHSOoLQK1U4QnHqyRKKxrQ9vlFjLukcvGvocJz0uyp3SQkcmSHcHzy+unuKq/hdrLQ== X-Received: by 2002:a17:907:2d22:b0:ab6:d7c4:fc7d with SMTP id a640c23a62f3a-ab75e35dc0dmr658202466b.39.1738854386398; Thu, 06 Feb 2025 07:06:26 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini Subject: [PATCH v2 4/5] x86/pci: disable MSI(-X) on all devices at shutdown Date: Thu, 6 Feb 2025 16:06:14 +0100 Message-ID: <20250206150615.52052-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250206150615.52052-1-roger.pau@citrix.com> References: <20250206150615.52052-1-roger.pau@citrix.com> MIME-Version: 1.0 Attempt to disable MSI(-X) capabilities on all PCI devices know by Xen at shutdown. Doing such disabling should facilitate kexec chained kernel from booting more reliably, as device MSI(-X) interrupt generation should be quiesced. It would also prevent "Receive accept error" being raised as a result of non-disabled interrupts targeting offline CPUs. Signed-off-by: Roger Pau Monné --- Changes since v1: - Split from bigger patch. - Iterate over all devices, even if the handler returns failure. --- xen/arch/x86/crash.c | 1 + xen/arch/x86/include/asm/msi.h | 1 + xen/arch/x86/msi.c | 18 ++++++++++++++++++ xen/arch/x86/smp.c | 1 + xen/drivers/passthrough/pci.c | 33 +++++++++++++++++++++++++++++++++ xen/include/xen/pci.h | 4 ++++ 6 files changed, 58 insertions(+) diff --git a/xen/arch/x86/crash.c b/xen/arch/x86/crash.c index a789416ca3ae..c946225c0b9b 100644 --- a/xen/arch/x86/crash.c +++ b/xen/arch/x86/crash.c @@ -177,6 +177,7 @@ static void nmi_shootdown_cpus(void) disable_IO_APIC(); hpet_disable(); + pci_disable_msi_all(); } } diff --git a/xen/arch/x86/include/asm/msi.h b/xen/arch/x86/include/asm/msi.h index 63adb19820e8..7f9e531f73e6 100644 --- a/xen/arch/x86/include/asm/msi.h +++ b/xen/arch/x86/include/asm/msi.h @@ -86,6 +86,7 @@ extern int pci_enable_msi(struct pci_dev *pdev, struct msi_info *msi, extern void pci_disable_msi(struct msi_desc *msi_desc); extern int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off); extern void pci_cleanup_msi(struct pci_dev *pdev); +extern void pci_disable_msi_all(void); extern int setup_msi_irq(struct irq_desc *desc, struct msi_desc *msidesc); extern int __setup_msi_irq(struct irq_desc *desc, struct msi_desc *msidesc, hw_irq_controller *handler); diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index e2360579deda..c9fe942c46f3 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -1248,6 +1248,24 @@ void pci_cleanup_msi(struct pci_dev *pdev) msi_free_irqs(pdev); } +static int cf_check disable_msi(struct pci_dev *pdev, void *arg) +{ + msi_set_enable(pdev, 0); + msix_set_enable(pdev, 0); + + return 0; +} + +/* Disable MSI and/or MSI-X on all devices known by Xen. */ +void pci_disable_msi_all(void) +{ + int rc = pci_iterate_devices(disable_msi, NULL); + + if ( rc ) + printk(XENLOG_ERR + "Failed to disable MSI(-X) on some devices: %d\n", rc); +} + int pci_reset_msix_state(struct pci_dev *pdev) { unsigned int pos = pdev->msix_pos; diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index f931db0d71c6..f58c8d3cafe1 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -376,6 +376,7 @@ void smp_send_stop(void) local_irq_disable(); disable_IO_APIC(); hpet_disable(); + pci_disable_msi_all(); if ( num_online_cpus() > 1 ) { diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 777c6b1a7fdc..945118383f45 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1803,6 +1803,39 @@ int iommu_do_pci_domctl( return ret; } +struct segment_iter { + int (*handler)(struct pci_dev *pdev, void *arg); + void *arg; + int rc; +}; + +static int cf_check iterate_all(struct pci_seg *pseg, void *arg) +{ + struct segment_iter *iter = arg; + struct pci_dev *pdev; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { + int rc = iter->handler(pdev, iter->arg); + + if ( !iter->rc ) + iter->rc = rc; + } + + return 0; +} + +int pci_iterate_devices(int (*handler)(struct pci_dev *pdev, void *arg), + void *arg) +{ + struct segment_iter iter = { + .handler = handler, + .arg = arg, + }; + + return pci_segments_iterate(iterate_all, &iter) ?: iter.rc; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index f784e9116059..983c592124a8 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -226,6 +226,10 @@ struct pci_dev *pci_get_pdev(const struct domain *d, pci_sbdf_t sbdf); struct pci_dev *pci_get_real_pdev(pci_sbdf_t sbdf); void pci_check_disable_device(u16 seg, u8 bus, u8 devfn); +/* Iterate without locking or preemption over all PCI devices known by Xen. */ +int pci_iterate_devices(int (*handler)(struct pci_dev *pdev, void *arg), + void *arg); + uint8_t pci_conf_read8(pci_sbdf_t sbdf, unsigned int reg); uint16_t pci_conf_read16(pci_sbdf_t sbdf, unsigned int reg); uint32_t pci_conf_read32(pci_sbdf_t sbdf, unsigned int reg); From patchwork Thu Feb 6 15:06:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13963196 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54FB0C02198 for ; Thu, 6 Feb 2025 15:06:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.882925.1293049 (Exim 4.92) (envelope-from ) id 1tg3SZ-00048F-Mi; Thu, 06 Feb 2025 15:06:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 882925.1293049; Thu, 06 Feb 2025 15:06:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SZ-000485-IX; Thu, 06 Feb 2025 15:06:31 +0000 Received: by outflank-mailman (input) for mailman id 882925; Thu, 06 Feb 2025 15:06:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tg3SX-0002qU-O8 for xen-devel@lists.xenproject.org; Thu, 06 Feb 2025 15:06:29 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f0e4c8fa-e49b-11ef-a073-877d107080fb; Thu, 06 Feb 2025 16:06:28 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-ab74ecfdae4so152183166b.2 for ; Thu, 06 Feb 2025 07:06:28 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab772f842a5sm112190766b.43.2025.02.06.07.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 07:06:27 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f0e4c8fa-e49b-11ef-a073-877d107080fb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1738854388; x=1739459188; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=54IsyjeaR6PU2ZI4fbX9EXq6TKKgpbduJj8jzthLGEQ=; b=KTONNa/aFGTpaMZ2NAR8UGdWKFP+X8YPa2nXwwoiZAqa4ihISBP5VpzQgUD8pbxzBl Y1PxK6WN8SaUQZ95GOt2ES0Al785ayrlHByUfzDJVORWOY4MK/QnC4VcVv/CCNUBwhQC wyLAey92/wIXDirHzIZR7/7Ks+i3vtTxpkVSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738854388; x=1739459188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=54IsyjeaR6PU2ZI4fbX9EXq6TKKgpbduJj8jzthLGEQ=; b=uXmrYqbS4x77jCAZD5AXGDzznXdERbNZWjn37JV53rhnGOpqRo1UZ1BqMwtf3XkKXi 6m3xfa+tBnsWESq+vAHP5dhqnwXUqM2aGhY4kfzRu/VMW/nvmRv5eQM6Jf3QeVitSGxA kkGJ86m5lDzKS7ks7loCYYtLQp/e0qZMPamNUZaiDLyg2zqvOBiskDBVXoNwG4CoCz5a eF7R88y4EOhXBfulSwIKyycnbatLNFb6HUjgiRNMjG3pgdpkR+gZ0/7+5VcH5/y1Byr3 Chu/2B6AhWsHSGmhyX5V5S3DIqEh7VW6/ceMw11PIU2Je2/k/6jsKQSnrpQ+5shIFpDB qLdQ== X-Gm-Message-State: AOJu0Yzv2eM3UC0awFw74N3lkhiaPqfYBPdEx99KOd/1do2UGIsQ4VyX mpvRNKTRWOjyh4elZ65zUmoNWJNj5arKixfYhPMGBPpwe2rt28zfNtAZ1Gn3KIzDhKnsQ+OIFlZ j X-Gm-Gg: ASbGncubV4To9soJ47E2V20H3WCunM6qc9VioOSKlxS1m3Y+6qKaT5bJAFjw+PfC334 VEfNq7M/qeI/ZXu8DK2m9T0Z2BuZb+YZ6Umj1m1rlzNgWs0G1vEJW1c+qQeDGr3ixP1xQSc79GV UQgCGWC5RfceSf2lDnhfpZqU4kqeJMc5dcn42Eon0T2fIA0PuKavb/kXyscQfqDBtHgeRM4HPxl 9NFa3JcfM3MYhxL6oLlAghIskWQ8J2LVx08SRwoK1lpvJQYGwBouYH2Ks1Ey7IqZ2SXq8sAX2kQ JxZVdD8aQ1/vl/esr5vr X-Google-Smtp-Source: AGHT+IE+G9fd4+/h481OwTZe16KfLx8FrIvqJv3B5R5S7j0ovNsKJOOtNzp56KhI3/IPrMbqjeCQaQ== X-Received: by 2002:a17:907:6e92:b0:aa6:9eac:4b8e with SMTP id a640c23a62f3a-ab75e2f6e43mr994010366b.41.1738854387948; Thu, 06 Feb 2025 07:06:27 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 5/5] x86/iommu: disable interrupts at shutdown Date: Thu, 6 Feb 2025 16:06:15 +0100 Message-ID: <20250206150615.52052-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250206150615.52052-1-roger.pau@citrix.com> References: <20250206150615.52052-1-roger.pau@citrix.com> MIME-Version: 1.0 Add a new hook to inhibit interrupt generation by the IOMMU(s). Note the hook is currently only implemented for x86 IOMMUs. The purpose is to disable interrupt generation at shutdown so any kexec chained image finds the IOMMU(s) in a quiesced state. It would also prevent "Receive accept error" being raised as a result of non-disabled interrupts targeting offline CPUs. Signed-off-by: Roger Pau Monné --- Changes since v1: - New in this version. --- xen/arch/x86/crash.c | 1 + xen/arch/x86/smp.c | 1 + xen/drivers/passthrough/amd/iommu.h | 1 + xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++++++++++++ xen/drivers/passthrough/amd/pci_amd_iommu.c | 1 + xen/drivers/passthrough/iommu.c | 6 ++++++ xen/drivers/passthrough/vtd/iommu.c | 19 +++++++++++++++++++ xen/include/xen/iommu.h | 3 +++ 8 files changed, 49 insertions(+) diff --git a/xen/arch/x86/crash.c b/xen/arch/x86/crash.c index c946225c0b9b..a5feed298d1e 100644 --- a/xen/arch/x86/crash.c +++ b/xen/arch/x86/crash.c @@ -178,6 +178,7 @@ static void nmi_shootdown_cpus(void) disable_IO_APIC(); hpet_disable(); pci_disable_msi_all(); + iommu_quiesce(); } } diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index f58c8d3cafe1..06c0e84d40b3 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -377,6 +377,7 @@ void smp_send_stop(void) disable_IO_APIC(); hpet_disable(); pci_disable_msi_all(); + iommu_quiesce(); if ( num_online_cpus() > 1 ) { diff --git a/xen/drivers/passthrough/amd/iommu.h b/xen/drivers/passthrough/amd/iommu.h index c32e9e9a1602..00e81b4b2ab3 100644 --- a/xen/drivers/passthrough/amd/iommu.h +++ b/xen/drivers/passthrough/amd/iommu.h @@ -292,6 +292,7 @@ extern unsigned long *shared_intremap_inuse; void cf_check amd_iommu_resume(void); int __must_check cf_check amd_iommu_suspend(void); void cf_check amd_iommu_crash_shutdown(void); +void cf_check amd_iommu_quiesce(void); static inline u32 get_field_from_reg_u32(u32 reg_value, u32 mask, u32 shift) { diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthrough/amd/iommu_init.c index 302362502033..2e60aef151b0 100644 --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -1611,3 +1611,20 @@ void cf_check amd_iommu_resume(void) invalidate_all_domain_pages(); } } + +void cf_check amd_iommu_quiesce(void) +{ + struct amd_iommu *iommu; + + for_each_amd_iommu ( iommu ) + { + if ( iommu->ctrl.int_cap_xt_en ) + { + iommu->ctrl.int_cap_xt_en = false; + writeq(iommu->ctrl.raw, + iommu->mmio_base + IOMMU_CONTROL_MMIO_OFFSET); + } + else + amd_iommu_msi_enable(iommu, IOMMU_CONTROL_DISABLED); + } +} diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index f96f59440bcc..d00697edb3a2 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -791,6 +791,7 @@ static const struct iommu_ops __initconst_cf_clobber _iommu_ops = { .crash_shutdown = amd_iommu_crash_shutdown, .get_reserved_device_memory = amd_iommu_get_reserved_device_memory, .dump_page_tables = amd_dump_page_tables, + .quiesce = amd_iommu_quiesce, }; static const struct iommu_init_ops __initconstrel _iommu_init_ops = { diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 9e74a1fc72fa..35c08ee0612c 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -663,6 +663,12 @@ void iommu_crash_shutdown(void) #endif } +void iommu_quiesce(void) +{ + if ( iommu_enabled ) + iommu_vcall(iommu_get_ops(), quiesce); +} + int iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt) { const struct iommu_ops *ops; diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index 9d7a9977a6a6..a1927d9f126d 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -3207,6 +3207,24 @@ static int cf_check intel_iommu_quarantine_init(struct pci_dev *pdev, return rc; } +static void cf_check vtd_quiesce(void) +{ + const struct acpi_drhd_unit *drhd; + + for_each_drhd_unit ( drhd ) + { + const struct vtd_iommu *iommu = drhd->iommu; + uint32_t sts = dmar_readl(iommu->reg, DMAR_FECTL_REG); + + /* + * Open code dma_msi_mask() to avoid taking the spinlock which could + * deadlock if called from crash context. + */ + sts |= DMA_FECTL_IM; + dmar_writel(iommu->reg, DMAR_FECTL_REG, sts); + } +} + static const struct iommu_ops __initconst_cf_clobber vtd_ops = { .page_sizes = PAGE_SIZE_4K, .init = intel_iommu_domain_init, @@ -3236,6 +3254,7 @@ static const struct iommu_ops __initconst_cf_clobber vtd_ops = { .iotlb_flush = iommu_flush_iotlb, .get_reserved_device_memory = intel_iommu_get_reserved_device_memory, .dump_page_tables = vtd_dump_page_tables, + .quiesce = vtd_quiesce, }; const struct iommu_init_ops __initconstrel intel_iommu_init_ops = { diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index b928c67e1995..77a514019cc6 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -314,6 +314,8 @@ struct iommu_ops { */ int (*dt_xlate)(device_t *dev, const struct dt_phandle_args *args); #endif + /* Inhibit all interrupt generation, to be used at shutdown. */ + void (*quiesce)(void); }; /* @@ -404,6 +406,7 @@ static inline int iommu_do_domctl(struct xen_domctl *domctl, struct domain *d, int __must_check iommu_suspend(void); void iommu_resume(void); void iommu_crash_shutdown(void); +void iommu_quiesce(void); int iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt); int iommu_quarantine_dev_init(device_t *dev);