From nobody Thu Apr 18 11:44:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1585214799; cv=none; d=zohomail.com; s=zohoarc; b=TSPRrO4oiZqyY//00F5V3tltmJYZ+qhO9b/EOIKRaKq8hKMGqObUw+qAiWpx2ta1OaqTG9EvaY1p4/xNM2JTAYQ6OwTCHG6I8kKyh0cjumRw1hDS+nP9xFYO9q2bmI42dFMIdmWEHi7EBOPveGMq86QbZg5KMAjLj526jZFgRx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585214799; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YIO1LnFh59KD1Hrk2OrSxKTVnVnN3EQY2GlgHBivQDA=; b=hffzfm93nCphtkCc8nJeXxRpREG5EQqVKOPEdRRm/CHfuAU758U/0DckRv8oc2ZjwAke5Apf82JD4AdSuNLJyMulmdW/UAVf7yGDPNFc+HoXkMfBTnrz1LeTUWUbVYHLbAWPveKv8AZSGviFpc24zDtwLTZh1MwG0txWKYMkyoM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585214799847100.32651617585782; Thu, 26 Mar 2020 02:26:39 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHOmA-0007JS-1p; Thu, 26 Mar 2020 09:26:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHOm8-0007J9-Lc for xen-devel@lists.xenproject.org; Thu, 26 Mar 2020 09:26:08 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d2215608-6f43-11ea-bec1-bc764e2007e4; Thu, 26 Mar 2020 09:26:07 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6BD77AD08; Thu, 26 Mar 2020 09:26:06 +0000 (UTC) X-Inumbo-ID: d2215608-6f43-11ea-bec1-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Miroslav Benes To: boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, jpoimboe@redhat.com Date: Thu, 26 Mar 2020 10:26:02 +0100 Message-Id: <20200326092603.7230-2-mbenes@suse.cz> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200326092603.7230-1-mbenes@suse.cz> References: <20200326092603.7230-1-mbenes@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v3 1/2] x86/xen: Make the boot CPU idle task reliable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: andrew.cooper3@citrix.com, x86@kernel.org, linux-kernel@vger.kernel.org, jbeulich@suse.com, live-patching@vger.kernel.org, xen-devel@lists.xenproject.org, Miroslav Benes , jslaby@suse.cz Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" The unwinder reports the boot CPU idle task's stack on XEN PV as unreliable, which affects at least live patching. There are two reasons for this. First, the task does not follow the x86 convention that its stack starts at the offset right below saved pt_regs. It allows the unwinder to easily detect the end of the stack and verify it. Second, startup_xen() function does not store the return address before jumping to xen_start_kernel() which confuses the unwinder. Amend both issues by moving the starting point of initial stack in startup_xen() and storing the return address before the jump, which is exactly what call instruction does. Signed-off-by: Miroslav Benes Reviewed-by: Juergen Gross --- arch/x86/xen/xen-head.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index 1d0cee3163e4..d63806e1ff7a 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -35,7 +35,11 @@ SYM_CODE_START(startup_xen) rep __ASM_SIZE(stos) =20 mov %_ASM_SI, xen_start_info - mov $init_thread_union+THREAD_SIZE, %_ASM_SP +#ifdef CONFIG_X86_64 + mov initial_stack(%rip), %rsp +#else + mov pa(initial_stack), %esp +#endif =20 #ifdef CONFIG_X86_64 /* Set up %gs. @@ -51,7 +55,7 @@ SYM_CODE_START(startup_xen) wrmsr #endif =20 - jmp xen_start_kernel + call xen_start_kernel SYM_CODE_END(startup_xen) __FINIT #endif --=20 2.25.1 From nobody Thu Apr 18 11:44:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1585214802; cv=none; d=zohomail.com; s=zohoarc; b=V/ex0MGeSRxMX4Y+TgW5l6tMTMS3vDTAu8faFBvdWmvwI6XYO26cizshNpetD7JYMHyPqaE8feiRAHBXbzJQIJARozIREv9fs/+siGKvCUP5+wnhYIvY0/MLFEl4H5IGc7EOw5lrJid1RZLGwdtkwDsui4nG533+UB4LtCBnN9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585214802; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+g6i+D67Llrp0b7Mxr20dKIBdtEuXCUKG/W0ZdcV2XI=; b=cYId/JVT8g5DVyLbD6/uibVwQxUYSseyMNQyt6Zxg8k3/PR591kBuTpM025QGC5RxowkwMKOkdmblC2ikBea1+OA/DsS7Ak2k6oUEmpSt/U86snky4QnIr+aVwEVw6YGVnYOQUyC451YNAXvGuyBAxwAI4KPKENR2t7LklhLxGY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585214802976354.5631300574786; Thu, 26 Mar 2020 02:26:42 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHOmF-0007LY-Af; Thu, 26 Mar 2020 09:26:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHOmD-0007L8-MN for xen-devel@lists.xenproject.org; Thu, 26 Mar 2020 09:26:13 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d28a29c6-6f43-11ea-b34e-bc764e2007e4; Thu, 26 Mar 2020 09:26:07 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 17520AF2C; Thu, 26 Mar 2020 09:26:07 +0000 (UTC) X-Inumbo-ID: d28a29c6-6f43-11ea-b34e-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Miroslav Benes To: boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, jpoimboe@redhat.com Date: Thu, 26 Mar 2020 10:26:03 +0100 Message-Id: <20200326092603.7230-3-mbenes@suse.cz> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200326092603.7230-1-mbenes@suse.cz> References: <20200326092603.7230-1-mbenes@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v3 2/2] x86/xen: Make the secondary CPU idle tasks reliable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: andrew.cooper3@citrix.com, x86@kernel.org, linux-kernel@vger.kernel.org, jbeulich@suse.com, live-patching@vger.kernel.org, xen-devel@lists.xenproject.org, Miroslav Benes , jslaby@suse.cz Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" The unwinder reports the secondary CPU idle tasks' stack on XEN PV as unreliable, which affects at least live patching. cpu_initialize_context() sets up the context of the CPU through VCPUOP_initialise hypercall. After it is woken up, the idle task starts in cpu_bringup_and_idle() function and its stack starts at the offset right below pt_regs. The unwinder correctly detects the end of stack there but it is confused by NULL return address in the last frame. Introduce a wrapper in assembly, which just calls cpu_bringup_and_idle(). The return address is thus pushed on the stack and the wrapper contains the annotation hint for the unwinder regarding the stack state. Signed-off-by: Miroslav Benes Reviewed-by: Juergen Gross --- arch/x86/xen/smp_pv.c | 3 ++- arch/x86/xen/xen-head.S | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index 802ee5bba66c..8fb8a50a28b4 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -53,6 +53,7 @@ static DEFINE_PER_CPU(struct xen_common_irq, xen_irq_work= ) =3D { .irq =3D -1 }; static DEFINE_PER_CPU(struct xen_common_irq, xen_pmu_irq) =3D { .irq =3D -= 1 }; =20 static irqreturn_t xen_irq_work_interrupt(int irq, void *dev_id); +void asm_cpu_bringup_and_idle(void); =20 static void cpu_bringup(void) { @@ -309,7 +310,7 @@ cpu_initialize_context(unsigned int cpu, struct task_st= ruct *idle) * pointing just below where pt_regs would be if it were a normal * kernel entry. */ - ctxt->user_regs.eip =3D (unsigned long)cpu_bringup_and_idle; + ctxt->user_regs.eip =3D (unsigned long)asm_cpu_bringup_and_idle; ctxt->flags =3D VGCF_IN_KERNEL; ctxt->user_regs.eflags =3D 0x1000; /* IOPL_RING1 */ ctxt->user_regs.ds =3D __USER_DS; diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index d63806e1ff7a..7d1c4fcbe8f7 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -58,6 +58,16 @@ SYM_CODE_START(startup_xen) call xen_start_kernel SYM_CODE_END(startup_xen) __FINIT + +#ifdef CONFIG_XEN_PV_SMP +.pushsection .text +SYM_CODE_START(asm_cpu_bringup_and_idle) + UNWIND_HINT_EMPTY + + call cpu_bringup_and_idle +SYM_CODE_END(asm_cpu_bringup_and_idle) +.popsection +#endif #endif =20 .pushsection .text --=20 2.25.1