From patchwork Tue Jul 23 14:28:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 13740127 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 E6B6BC3DA63 for ; Tue, 23 Jul 2024 14:29:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.763299.1173556 (Exim 4.92) (envelope-from ) id 1sWGVn-0000PE-6i; Tue, 23 Jul 2024 14:29:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 763299.1173556; Tue, 23 Jul 2024 14:29:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWGVn-0000P7-3X; Tue, 23 Jul 2024 14:29:07 +0000 Received: by outflank-mailman (input) for mailman id 763299; Tue, 23 Jul 2024 14:29:05 +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 1sWGVl-0000OU-Dt for xen-devel@lists.xenproject.org; Tue, 23 Jul 2024 14:29:05 +0000 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e75f12f6-48ff-11ef-8776-851b0ebba9a2; Tue, 23 Jul 2024 16:29:02 +0200 (CEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 13EED1380340 for ; Tue, 23 Jul 2024 10:29:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 23 Jul 2024 10:29:00 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 23 Jul 2024 10:28:59 -0400 (EDT) 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: e75f12f6-48ff-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to; s=fm2; t=1721744940; x=1721831340; bh=YgfT7mscqH S498jIZyCl52XDbsmT1MApm9rfgZLU06I=; b=MAmkHJ+QxtVFm+jLrwOVp7rwJU n1TSa+zBFy1Xhfh8GgIJ6yvG161A/ZmG1lJu2/+qvsEmPwD4E4f23FIOPj3S17pC ZMotn526PZ/zwfeG4kRHZQPX4Ko0prPoGEPn+ZEt/LoXJS9z6nPVMpMic4vwAkKO HJeuT0oHgV7IKaofNOZM9EzGKS+6PaW2i5WXyeuAalkfwBEAcPWQDDvV/Ob9AYSH aBBcZG8oh80nRZU8DcQkhToKb2yjh/E7cXJhnIHQhqo9GryRE+mma3Sg1QmZ8SOi wvYShJv8SCfoY6Ua4YBucRULYWofkNPpH7wB6gn104YdrL7HE+ZcI1jGft7g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1721744940; x=1721831340; bh=YgfT7mscqHS498jIZyCl52XDbsmT1MApm9r fgZLU06I=; b=CYcDTvG2GF9t+w6hAAqeH3lNXyFeO9Jwm31DKSCVig8KLiMX3nq 39ZSlg2fS4GwQCXYXJ2RzGqhc9Zdsxzi6fw4mlf1wBW4bBJaPUE2oYJcrRWGj1ZX fuwp44JC+cwChNS2yGU7+aA6Ehm9u1b2Y62Y86NVEWxJb2OtauGKLNnxC4z3F9PN z1V7MaqtTmWnwsJUpI+N4y1pmheklLa7To2Jv1+gqNuo00cCwTytqPWM+leBqu8R dUkHWC+yf7beujh5XATLBfsQx72/3zbwdOLW05UsTpsB9v7nsCfBsrlXXbCEjhBk wy1QsYPPD7o/HEa4tcV93I3h0nwRfiwKvyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrheelgdejiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfggtggusehgtderredttd ejnecuhfhrohhmpeforghrvghkucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcu oehmrghrmhgrrhgvkhesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenuc ggtffrrghtthgvrhhnpedtudfgteduveduieevvefgteeujeelgffggffhhffhhedtffef fefgudeugeefhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmrghrmhgrrhgvkhesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhm pdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i1568416f:Fastmail Date: Tue, 23 Jul 2024 16:28:56 +0200 From: Marek =?utf-8?q?Marczykowski-G=C3=B3recki?= To: xen-devel Subject: Assertion failed at arch/x86/genapic/x2apic.c:38 on S3 resume nested in KVM on AMD Message-ID: MIME-Version: 1.0 Content-Disposition: inline Hi, I'm observing a crash like the one below when trying to resume from S3. It happens on Xen nested in KVM (QEMU 9.0, Linux 6.9.3) but only on AMD. The very same software stack on Intel works just fine. QEMU is running with "-cpu host,+svm,+invtsc -machine q35,kernel-irqchip=split -device amd-iommu,intremap=on -smp 2" among others. (XEN) Preparing system for ACPI S3 state. (XEN) Disabling non-boot CPUs ... (XEN) Broke affinity for IRQ1, new: {0-1} (XEN) Broke affinity for IRQ20, new: {0-1} (XEN) Broke affinity for IRQ22, new: {0-1} (XEN) Entering ACPI S3 state. (XEN) Finishing wakeup from ACPI S3 state. (XEN) Enabling non-boot CPUs ... (XEN) Assertion 'cpumask_test_cpu(this_cpu, per_cpu(cluster_cpus, this_cpu))' failed at arch/x86/genapic/x2apic.c:38 (XEN) ----[ Xen-4.20 x86_64 debug=y Not tainted ]---- (XEN) CPU: 1 (XEN) RIP: e008:[] x2apic.c#init_apic_ldr_x2apic_cluster+0x8a/0x1b9 (XEN) RFLAGS: 0000000000010096 CONTEXT: hypervisor (XEN) rax: ffff830278a25f50 rbx: 0000000000000001 rcx: ffff82d0405e1700 (XEN) rdx: 0000003233412000 rsi: ffff8302739da2d8 rdi: 0000000000000000 (XEN) rbp: 00000000000000c8 rsp: ffff8302739d7e78 r8: 0000000000000001 (XEN) r9: ffff8302739d7fa0 r10: 0000000000000001 r11: 0000000000000000 (XEN) r12: 0000000000000001 r13: 0000000000000001 r14: 0000000000000000 (XEN) r15: 0000000000000000 cr0: 000000008005003b cr4: 00000000007506e0 (XEN) cr3: 000000007fa7a000 cr2: 0000000000000000 (XEN) fsb: 0000000000000000 gsb: 0000000000000000 gss: 0000000000000000 (XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: 0000 cs: e008 (XEN) Xen code around (x2apic.c#init_apic_ldr_x2apic_cluster+0x8a/0x1b9): (XEN) cf 82 ff ff eb b7 0f 0b <0f> 0b 48 8d 05 9c fc 33 00 48 8b 0d a5 0a 35 00 (XEN) Xen stack trace from rsp=ffff8302739d7e78: (XEN) 0000000000000000 00000000000000c8 0000000000000001 0000000000000001 (XEN) 0000000000000000 ffff82d0402f1d83 ffff8302739d7fff 00000000000000c8 (XEN) 0000000000000001 0000000000000001 ffff82d04031adb9 0000000000000001 (XEN) 0000000000000000 0000000000000000 0000000000000000 ffff82d040276677 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) ffff88810037c000 0000000000000001 0000000000000246 deadbeefdeadf00d (XEN) 0000000000000001 aaaaaaaaaaaaaaaa 0000000000000000 ffffffff811d130a (XEN) deadbeefdeadf00d deadbeefdeadf00d deadbeefdeadf00d 0000010000000000 (XEN) ffffffff811d130a 000000000000e033 0000000000000246 ffffc900400b3ef8 (XEN) 000000000000e02b 000000000000beef 000000000000beef 000000000000beef (XEN) 000000000000beef 0000e01000000001 ffff8302739de000 0000003233412000 (XEN) 00000000007506e0 0000000000000000 0000000000000000 0000000200000000 (XEN) 0000000000000002 (XEN) Xen call trace: (XEN) [] R x2apic.c#init_apic_ldr_x2apic_cluster+0x8a/0x1b9 (XEN) [] S setup_local_APIC+0x26/0x449 (XEN) [] S start_secondary+0x1c4/0x37a (XEN) [] S __high_start+0x87/0xd0 (XEN) (XEN) (XEN) **************************************** (XEN) Panic on CPU 1: (XEN) Assertion 'cpumask_test_cpu(this_cpu, per_cpu(cluster_cpus, this_cpu))' failed at arch/x86/genapic/x2apic.c:38 (XEN) **************************************** On a release build, it hits "BUG" later on in the same file. I've tested the attached patch from Roger, but that assertion didn't fail (or it crashed before reaching that part). Reported-by: Marek Marczykowski-Górecki Signed-off-by: Jan Beulich Tested-by: Marek Marczykowski-Górecki diff --git a/xen/arch/x86/genapic/x2apic.c b/xen/arch/x86/genapic/x2apic.c index 371dd100c742..fe8e664e1b63 100644 --- a/xen/arch/x86/genapic/x2apic.c +++ b/xen/arch/x86/genapic/x2apic.c @@ -30,8 +30,11 @@ static inline u32 x2apic_cluster(unsigned int cpu) static void cf_check init_apic_ldr_x2apic_cluster(void) { unsigned int cpu, this_cpu = smp_processor_id(); + uint32_t id = apic_read(APIC_ID); + uint32_t ldr = apic_read(APIC_LDR); - per_cpu(cpu_2_logical_apicid, this_cpu) = apic_read(APIC_LDR); + ASSERT(x2apic_ldr_from_id(id) == ldr); + per_cpu(cpu_2_logical_apicid, this_cpu) = ldr; if ( per_cpu(cluster_cpus, this_cpu) ) { diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 9cfc82666ae5..2a010a6363b7 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -1064,11 +1064,6 @@ static const struct hvm_mmio_ops vlapic_mmio_ops = { .write = vlapic_mmio_write, }; -static uint32_t x2apic_ldr_from_id(uint32_t id) -{ - return ((id & ~0xf) << 12) | (1 << (id & 0xf)); -} - static void set_x2apic_id(struct vlapic *vlapic) { const struct vcpu *v = vlapic_vcpu(vlapic); diff --git a/xen/arch/x86/include/asm/apic.h b/xen/arch/x86/include/asm/apic.h index 7b5a0832c05e..8a892fa2fa5b 100644 --- a/xen/arch/x86/include/asm/apic.h +++ b/xen/arch/x86/include/asm/apic.h @@ -148,6 +148,11 @@ static inline void ack_APIC_irq(void) apic_write(APIC_EOI, 0); } +static inline uint32_t x2apic_ldr_from_id(uint32_t id) +{ + return ((id & ~0xf) << 12) | (1 << (id & 0xf)); +} + extern int get_maxlvt(void); extern void clear_local_APIC(void); extern void connect_bsp_APIC (void);