From nobody Sun Apr 28 08:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584024619; cv=none; d=zohomail.com; s=zohoarc; b=dRRgbzFt2BHhGHDDYWeC7loeS0eM6Etj1dhUDKz/gPUfSXhtBaxibKRl2TXZwkuOgONq6JscWNKsQyuNL7yohsJZ/aGqiFAAytzkWFr3R+sFXwM+o1aF2O6YNCLBcBMukWXvWnLbQtaor2WN8lhvXzs50DAu1l7aXClV/3XhA6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584024619; h=Content-Type: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=GLu8H9CcEppuVu3c+4VC6NvnXotc+p43aZdFEUFeBtE=; b=lCiF6gsEfBJynobSIe6NIgxsZqJGE2rzjrG2UQf+yfg6oavY7aswj3pMCmSRbNoA7/uwaHF/cEhzvKiUInykDbvM/cD8X5/Asr+qQuKkrAfrun/NcI/1UWLYC8wj3P/vYNZ+Qtqq5jwg1WS+BI0Q+sEn/spXn4VxdwvxuPkR+0o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) 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 1584024619174915.5927187858654; Thu, 12 Mar 2020 07:50:19 -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 1jCP9a-0000ZN-I9; Thu, 12 Mar 2020 14:49:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCOh1-0006XZ-T6 for xen-devel@lists.xenproject.org; Thu, 12 Mar 2020 14:20:11 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 94cb597b-646c-11ea-b19e-12813bfff9fa; Thu, 12 Mar 2020 14:20:11 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3CAA6B2F1; Thu, 12 Mar 2020 14:20:10 +0000 (UTC) X-Inumbo-ID: 94cb597b-646c-11ea-b19e-12813bfff9fa 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, 12 Mar 2020 15:20:06 +0100 Message-Id: <20200312142007.11488-2-mbenes@suse.cz> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200312142007.11488-1-mbenes@suse.cz> References: <20200312142007.11488-1-mbenes@suse.cz> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 14:49:40 +0000 Subject: [Xen-devel] [PATCH 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: x86@kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, xen-devel@lists.xenproject.org, Miroslav Benes , jslaby@suse.cz Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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. Signed-off-by: Miroslav Benes --- arch/x86/xen/xen-head.S | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index 1d0cee3163e4..642f346bfe02 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -35,7 +35,7 @@ SYM_CODE_START(startup_xen) rep __ASM_SIZE(stos) =20 mov %_ASM_SI, xen_start_info - mov $init_thread_union+THREAD_SIZE, %_ASM_SP + mov $init_thread_union+THREAD_SIZE-SIZEOF_PTREGS, %_ASM_SP =20 #ifdef CONFIG_X86_64 /* Set up %gs. @@ -51,7 +51,9 @@ SYM_CODE_START(startup_xen) wrmsr #endif =20 + push $1f jmp xen_start_kernel +1: SYM_CODE_END(startup_xen) __FINIT #endif --=20 2.25.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun Apr 28 08:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584024619; cv=none; d=zohomail.com; s=zohoarc; b=lrY4Dq+vES4TIUCHej5RFhNcbmxBxHWj7tXJPpanqIGUnNLSQR37EI/BwL55e0QaByiXfEMc8Q+pLDVAXkBwwNwqFybc0B/KTR1jvBvYX/cnEaX0omPjBMTAAjh3rein/MuDCum/QE+Fw2ZhFV3F9iKxcs5HUjssdwu0Swlu+ho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584024619; h=Content-Type: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=yQ8e1AvIKS0yVmV1YmjZrFzszv6jHmThLaYT1hIsyDA=; b=Aqu+MP+i4hVP3mUchw1D6fBwSkWMsatGsr3+J0hcz7jkJ6ZC/YNk9tO2mUTPFKUwKsu8f1Oh/4lFQwFU09xQ6ad12kU5Mo7qXeQiW43+h8cFJO3s7FCtd/wdjwlw3kALUz0905y2Ts1jQLaYcGQKeorkK8WMHjm7MEW4WOUlSwo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) 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 1584024619305903.7396665230962; Thu, 12 Mar 2020 07:50:19 -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 1jCP9b-0000ZZ-1t; Thu, 12 Mar 2020 14:49:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCOhB-0006YB-RA for xen-devel@lists.xenproject.org; Thu, 12 Mar 2020 14:20:21 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 953c387a-646c-11ea-b19e-12813bfff9fa; Thu, 12 Mar 2020 14:20:11 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CD2FCB2FA; Thu, 12 Mar 2020 14:20:10 +0000 (UTC) X-Inumbo-ID: 953c387a-646c-11ea-b19e-12813bfff9fa 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, 12 Mar 2020 15:20:07 +0100 Message-Id: <20200312142007.11488-3-mbenes@suse.cz> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200312142007.11488-1-mbenes@suse.cz> References: <20200312142007.11488-1-mbenes@suse.cz> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 14:49:40 +0000 Subject: [Xen-devel] [RFC PATCH 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: x86@kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, xen-devel@lists.xenproject.org, Miroslav Benes , jslaby@suse.cz Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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. RFC: I haven't found the way to teach the unwinder about the state of the stack there. Thus the ugly hack using assembly. Similar to what startup_xen() has got for boot CPU. It introduces objtool "unreachable instruction" warning just right after the jump to cpu_bringup_and_idle(). It should show the idea what needs to be done though, I think. Ideas welcome. Signed-off-by: Miroslav Benes --- 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..6b88cdcbef8f 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); +extern unsigned char asm_cpu_bringup_and_idle[]; =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 642f346bfe02..c9a9c0bb79ed 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -56,6 +56,16 @@ SYM_CODE_START(startup_xen) 1: SYM_CODE_END(startup_xen) __FINIT + +.pushsection .text +SYM_CODE_START(asm_cpu_bringup_and_idle) + UNWIND_HINT_EMPTY + + push $1f + jmp cpu_bringup_and_idle +1: +SYM_CODE_END(asm_cpu_bringup_and_idle) +.popsection #endif =20 .pushsection .text --=20 2.25.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel