From nobody Mon May 6 11:33:40 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; dkim=fail; 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 1673534416867491.94916924697407; Thu, 12 Jan 2023 06:40:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.476207.738322 (Exim 4.92) (envelope-from ) id 1pFyjw-0004Ac-4I; Thu, 12 Jan 2023 14:39:36 +0000 Received: by outflank-mailman (output) from mailman id 476207.738322; Thu, 12 Jan 2023 14:39:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFyjv-0004AT-Vt; Thu, 12 Jan 2023 14:39:35 +0000 Received: by outflank-mailman (input) for mailman id 476207; Thu, 12 Jan 2023 14:39:35 +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 1pFyjv-0002av-69 for xen-devel@lists.xenproject.org; Thu, 12 Jan 2023 14:39:35 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id eda5cb2e-9286-11ed-b8d0-410ff93cb8f0; Thu, 12 Jan 2023 15:39:33 +0100 (CET) Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pFyjS-0040tF-12; Thu, 12 Jan 2023 14:39:06 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E5EEE30084B; Thu, 12 Jan 2023 15:39:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id B487C2CC8C6A5; Thu, 12 Jan 2023 15:39:12 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: eda5cb2e-9286-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=sHDPsq2uABjtfq0P5gTU9bTPKMFTr0x7rU8OwfasSIg=; b=LI9y8vBQdis0SSWa52KOS2vrQI DwEgo+snsApY9aPqeiehYRoGQAQPCfcXdVF/jnQvKmoDaZgOMjKpFPoGTQGrbyME7YpvvPqVAN8Au xhJ4YL/E4PAO+PAZBX22U4wBu1/QoMzS7R97C0oTdBAOCx8hnEzZ/GJ8x43Z2EedpvXr/NLaJ1WcW Xn4115CcVMUdvp59cZr83pNUcEW6riGQbkak/hhi3nIgdfg9mi2Jm6QWhhq8mm98rpvZdtPfTsVha Tn3o9kjumy/5q3a/JwjaPtKaLtr7A4nKrKiZq5C++dGVHnqAjuh5olHmuMnpLddjUizxu999OLs+z VmxWPwnQ==; Message-ID: <20230112143825.584639584@infradead.org> User-Agent: quilt/0.66 Date: Thu, 12 Jan 2023 15:31:42 +0100 From: Peter Zijlstra To: x86@kernel.org, Joan Bruguera Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Juergen Gross , "Rafael J. Wysocki" , xen-devel , Jan Beulich , Roger Pau Monne , Kees Cook , mark.rutland@arm.com Subject: [RFC][PATCH 1/6] x86/power: De-paravirt restore_processor_state() References: <20230112143141.645645775@infradead.org> MIME-Version: 1.0 X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1673534417431100007 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since Xen PV doesn't use restore_processor_state(), and we're going to have to avoid CALL/RET until at least GS is restored, de-paravirt the easy bits. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Juergen Gross --- arch/x86/power/cpu.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -197,25 +197,25 @@ static void notrace __restore_processor_ struct cpuinfo_x86 *c; =20 if (ctxt->misc_enable_saved) - wrmsrl(MSR_IA32_MISC_ENABLE, ctxt->misc_enable); + native_wrmsrl(MSR_IA32_MISC_ENABLE, ctxt->misc_enable); /* * control registers */ /* cr4 was introduced in the Pentium CPU */ #ifdef CONFIG_X86_32 if (ctxt->cr4) - __write_cr4(ctxt->cr4); + native_write_cr4(ctxt->cr4); #else /* CONFIG X86_64 */ - wrmsrl(MSR_EFER, ctxt->efer); - __write_cr4(ctxt->cr4); + native_wrmsrl(MSR_EFER, ctxt->efer); + native_write_cr4(ctxt->cr4); #endif - write_cr3(ctxt->cr3); - write_cr2(ctxt->cr2); - write_cr0(ctxt->cr0); + native_write_cr3(ctxt->cr3); + native_write_cr2(ctxt->cr2); + native_write_cr0(ctxt->cr0); =20 /* Restore the IDT. */ - load_idt(&ctxt->idt); + native_load_idt(&ctxt->idt); =20 /* * Just in case the asm code got us here with the SS, DS, or ES @@ -230,7 +230,7 @@ static void notrace __restore_processor_ * handlers or in complicated helpers like load_gs_index(). */ #ifdef CONFIG_X86_64 - wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base); + native_wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base); #else loadsegment(fs, __KERNEL_PERCPU); #endif @@ -246,15 +246,15 @@ static void notrace __restore_processor_ loadsegment(ds, ctxt->es); loadsegment(es, ctxt->es); loadsegment(fs, ctxt->fs); - load_gs_index(ctxt->gs); + native_load_gs_index(ctxt->gs); =20 /* * Restore FSBASE and GSBASE after restoring the selectors, since * restoring the selectors clobbers the bases. Keep in mind * that MSR_KERNEL_GS_BASE is horribly misnamed. */ - wrmsrl(MSR_FS_BASE, ctxt->fs_base); - wrmsrl(MSR_KERNEL_GS_BASE, ctxt->usermode_gs_base); + native_wrmsrl(MSR_FS_BASE, ctxt->fs_base); + native_wrmsrl(MSR_KERNEL_GS_BASE, ctxt->usermode_gs_base); #else loadsegment(gs, ctxt->gs); #endif From nobody Mon May 6 11:33:40 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; dkim=fail; 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 1673534412857626.9506384590484; Thu, 12 Jan 2023 06:40:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.476205.738298 (Exim 4.92) (envelope-from ) id 1pFyjr-0003UZ-H2; Thu, 12 Jan 2023 14:39:31 +0000 Received: by outflank-mailman (output) from mailman id 476205.738298; Thu, 12 Jan 2023 14:39: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 1pFyjr-0003T0-C2; Thu, 12 Jan 2023 14:39:31 +0000 Received: by outflank-mailman (input) for mailman id 476205; Thu, 12 Jan 2023 14:39:29 +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 1pFyjp-0002av-Ir for xen-devel@lists.xenproject.org; Thu, 12 Jan 2023 14:39:29 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e7f83730-9286-11ed-b8d0-410ff93cb8f0; Thu, 12 Jan 2023 15:39:25 +0100 (CET) Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pFyjS-0040tE-0z; Thu, 12 Jan 2023 14:39:06 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id EA5E2300C50; Thu, 12 Jan 2023 15:39:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id B77922CC949A1; Thu, 12 Jan 2023 15:39:12 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: e7f83730-9286-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=+hVGbhW+kq8WeUTnRFVIQ4y6xF6mTUDTY1iojLvcO/Q=; b=VD2YCgkTmE2CQ4Y8uw29qiC2TE R80ib0ot/jJ/vDVx1nc81VA/UdFYRNG0RCJX9If+JwIwax/MdSzvs+229sqAm51rlqFP4ZtmBL6KE ZGwzJaeaNt97uYlCPg3WWmvJH6/Qc2TRui52REAxdkfvawrPGc1AlBYy8r3QDtkibYhajuP5B7DDl e4VUHACu7Phw+gAfdvDwUrseQHxbEogW6ZFrf4DGNzODQW73kd/B4Gn8iBVxRaIIdPZwruHvk8R/J U+pz1lXQCECLx95TWt3y1l8JrPMkbqVDOu1nEJOjWfQjLPnHBvOtaLz8Bxx4rBAruF+c4Yb+M8UAF +VcR5hIg==; Message-ID: <20230112143825.644480983@infradead.org> User-Agent: quilt/0.66 Date: Thu, 12 Jan 2023 15:31:43 +0100 From: Peter Zijlstra To: x86@kernel.org, Joan Bruguera Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Juergen Gross , "Rafael J. Wysocki" , xen-devel , Jan Beulich , Roger Pau Monne , Kees Cook , mark.rutland@arm.com Subject: [RFC][PATCH 2/6] x86/power: Inline write_cr[04]() References: <20230112143141.645645775@infradead.org> MIME-Version: 1.0 X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1673534413435100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since we can't do CALL/RET until GS is restored and CR[04] pinning is of dubious value in this code path, simply write the stored values. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Kees Cook --- arch/x86/power/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -208,11 +208,11 @@ static void notrace __restore_processor_ #else /* CONFIG X86_64 */ native_wrmsrl(MSR_EFER, ctxt->efer); - native_write_cr4(ctxt->cr4); + asm volatile("mov %0,%%cr4": "+r" (ctxt->cr4) : : "memory"); #endif native_write_cr3(ctxt->cr3); native_write_cr2(ctxt->cr2); - native_write_cr0(ctxt->cr0); + asm volatile("mov %0,%%cr0": "+r" (ctxt->cr0) : : "memory"); =20 /* Restore the IDT. */ native_load_idt(&ctxt->idt); From nobody Mon May 6 11:33:40 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; dkim=fail; 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 1673534412458463.6736053956913; Thu, 12 Jan 2023 06:40:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.476201.738256 (Exim 4.92) (envelope-from ) id 1pFyjp-0002bN-D2; Thu, 12 Jan 2023 14:39:29 +0000 Received: by outflank-mailman (output) from mailman id 476201.738256; Thu, 12 Jan 2023 14:39:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFyjp-0002bG-8O; Thu, 12 Jan 2023 14:39:29 +0000 Received: by outflank-mailman (input) for mailman id 476201; Thu, 12 Jan 2023 14:39:27 +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 1pFyjm-0002au-Sz for xen-devel@lists.xenproject.org; Thu, 12 Jan 2023 14:39:27 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e8a2ca71-9286-11ed-91b6-6bf2151ebd3b; Thu, 12 Jan 2023 15:39:25 +0100 (CET) Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pFyjS-0040tD-11; Thu, 12 Jan 2023 14:39:06 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id EC89A300C6F; Thu, 12 Jan 2023 15:39:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id BAAF42CC8C6A1; Thu, 12 Jan 2023 15:39:12 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: e8a2ca71-9286-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=T4GElGxaw5tEx2Lk6kKh2cwaswlijZP7pkxV7zD03yo=; b=dWjbmZzwf1WthR8TZ23ii1la+e yq8CeiWkZUYxPcP3zDoAdsjLQyUEFEwNBnojffsrWtXWwvZrVG3BvxUWfoXFoIemIzZBR3dchks7+ 30N+pLzv0Pq6fFF2X2CREioQEU6u9ZSI0QUhXVxyjoBTLRnevuU+BOKb90OE9rtHZxNFKkdIcFvCY 0iBTtIbHpzJidWwd/VU+wg+DB3e1nBkUqzz+681wC9mH4sjUCyB8tmW0qAnc1AaOtsfRWMMqx6gco h5cNcMDHwQrxlAKs+W9Qc14+/gh6t51ElNBLBGLZWjnaQvksAwmhxVjKsZ7qqyNZZupTDL6qmnpHt IQaqbR8A==; Message-ID: <20230112143825.704223863@infradead.org> User-Agent: quilt/0.66 Date: Thu, 12 Jan 2023 15:31:44 +0100 From: Peter Zijlstra To: x86@kernel.org, Joan Bruguera Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Juergen Gross , "Rafael J. Wysocki" , xen-devel , Jan Beulich , Roger Pau Monne , Kees Cook , mark.rutland@arm.com Subject: [RFC][PATCH 3/6] x86/callthunk: No callthunk for restore_processor_state() References: <20230112143141.645645775@infradead.org> MIME-Version: 1.0 X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1673534413480100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joan Bruguera When resuming from suspend we don't have coherent CPU state, trying to do callthunks here isn't going to work. Specifically GS isn't set yet. Signed-off-by: Joan Bruguera Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20230109040531.7888-1-joanbrugueram@gmail.c= om --- arch/x86/kernel/callthunks.c | 5 +++++ arch/x86/power/cpu.c | 3 +++ 2 files changed, 8 insertions(+) --- a/arch/x86/kernel/callthunks.c +++ b/arch/x86/kernel/callthunks.c @@ -7,6 +7,7 @@ #include #include #include +#include =20 #include #include @@ -151,6 +152,10 @@ static bool skip_addr(void *dest) dest < (void*)hypercall_page + PAGE_SIZE) return true; #endif +#ifdef CONFIG_PM_SLEEP + if (dest =3D=3D restore_processor_state) + return true; +#endif return false; } From nobody Mon May 6 11:33:40 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; dkim=fail; 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 1673534407271289.0541962853175; Thu, 12 Jan 2023 06:40:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.476203.738265 (Exim 4.92) (envelope-from ) id 1pFyjp-0002kN-Vj; Thu, 12 Jan 2023 14:39:29 +0000 Received: by outflank-mailman (output) from mailman id 476203.738265; Thu, 12 Jan 2023 14:39:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFyjp-0002jB-Q6; Thu, 12 Jan 2023 14:39:29 +0000 Received: by outflank-mailman (input) for mailman id 476203; Thu, 12 Jan 2023 14:39:28 +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 1pFyjo-0002av-Gj for xen-devel@lists.xenproject.org; Thu, 12 Jan 2023 14:39:28 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e7f02495-9286-11ed-b8d0-410ff93cb8f0; Thu, 12 Jan 2023 15:39:23 +0100 (CET) Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFyjo-0057ze-0K; Thu, 12 Jan 2023 14:39:28 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E5F5E300BE3; Thu, 12 Jan 2023 15:39:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id BD2812CC8C6A4; Thu, 12 Jan 2023 15:39:12 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: e7f02495-9286-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=eW1eJS20PBPNIc/x7hkOEbhV5Z70C96GEP7VlPQr3GE=; b=aPU7lwsfmN0exgD06ro+v230ma inYN+4H37Om7tBqtVLzUL9CUNUKlfPza2KgcF/4PIvMJRSjjj182vbfZKCbWGWcbCIG45AgQgTeW2 fJfibscpsY63h5bZRqGsUf4OhsblkoP/Zw/BZA9PTJDZ2yDWPiuYKZy08myhK7w4NQ6zGvyAXLf0r M3tKHRiVoMc/WSOdEc6z2X8grpK42f1voLXiB5Pdc8Sqe2lHCgDtzs7he1s2s4NuaMwjujHi3zrRS ZFm27VOnMo7aZariMxE7kPw4B2ygcq5oEm7hLZK/tnd6ofcrPVD/UdjX1MVog7QR+UD+cBkfTdQE7 QKSVn4uQ==; Message-ID: <20230112143825.762830112@infradead.org> User-Agent: quilt/0.66 Date: Thu, 12 Jan 2023 15:31:45 +0100 From: Peter Zijlstra To: x86@kernel.org, Joan Bruguera Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Juergen Gross , "Rafael J. Wysocki" , xen-devel , Jan Beulich , Roger Pau Monne , Kees Cook , mark.rutland@arm.com Subject: [RFC][PATCH 4/6] x86/power: Sprinkle some noinstr References: <20230112143141.645645775@infradead.org> MIME-Version: 1.0 X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1673534409416100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Ensure no compiler instrumentation sneaks in while restoring the CPU state. Specifically we can't handle CALL/RET until GS is restored. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/power/cpu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -192,7 +192,7 @@ static void fix_processor_context(void) * The asm code that gets us here will have restored a usable GDT, although * it will be pointing to the wrong alias. */ -static void notrace __restore_processor_state(struct saved_context *ctxt) +static __always_inline void __restore_processor_state(struct saved_context= *ctxt) { struct cpuinfo_x86 *c; =20 @@ -235,6 +235,13 @@ static void notrace __restore_processor_ loadsegment(fs, __KERNEL_PERCPU); #endif =20 + /* + * Definitely wrong, but at this point we should have at least enough + * to do CALL/RET (consider SKL callthunks) and this avoids having + * to deal with the noinstr explosion for now :/ + */ + instrumentation_begin(); + /* Restore the TSS, RO GDT, LDT, and usermode-relevant MSRs. */ fix_processor_context(); =20 @@ -276,10 +283,12 @@ static void notrace __restore_processor_ * because some of the MSRs are "emulated" in microcode. */ msr_restore_context(ctxt); + + instrumentation_end(); } =20 /* Needed by apm.c */ -void notrace restore_processor_state(void) +void noinstr restore_processor_state(void) { __restore_processor_state(&saved_context); } From nobody Mon May 6 11:33:40 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; dkim=fail; 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 1673534413117590.6414314320351; Thu, 12 Jan 2023 06:40:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.476206.738311 (Exim 4.92) (envelope-from ) id 1pFyjs-0003pV-Qb; Thu, 12 Jan 2023 14:39:32 +0000 Received: by outflank-mailman (output) from mailman id 476206.738311; Thu, 12 Jan 2023 14:39: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 1pFyjs-0003p8-Kk; Thu, 12 Jan 2023 14:39:32 +0000 Received: by outflank-mailman (input) for mailman id 476206; Thu, 12 Jan 2023 14:39:30 +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 1pFyjq-0002av-J2 for xen-devel@lists.xenproject.org; Thu, 12 Jan 2023 14:39:30 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e82b8c26-9286-11ed-b8d0-410ff93cb8f0; Thu, 12 Jan 2023 15:39:25 +0100 (CET) Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pFyjT-0040tJ-0q; Thu, 12 Jan 2023 14:39:07 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 6DA1B30067B; Thu, 12 Jan 2023 15:39:13 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C69932CC949B5; Thu, 12 Jan 2023 15:39:12 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: e82b8c26-9286-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=w9+PAdJk73UH2Fl3uPAAs4wgk5kyO76VlH+ufUk/PX4=; b=dGCr6CbAN+FGZxrxNRDZdAytzQ ohdZmJ2pWqhrruEFxAeISbBJzfYzIpqoJ3L/tRSUW3gBGjkO2s4tKa2W7ElzbOgRY0hRHRAMqDn7v I08YMwa446QJGSFX9BK9EJUds/SAXIdeHq/1QrE0yC9DLJmA54/yUU0pMsKnK/GKurujDhdUdMZgy 2+E0yvI3gp0qTRUUgSCZVL/zjtjL6j9B4gmAO+rUVP/3waaiBSWmCmPLQGQ2RCXfbx35gYfLuHUHj rMAwsTWq/CMa37B4ktxnJOl8GYiROHox2K2kVc6oMMpelLmGsftbM+7NBgYgsXqBejFVKGscqqsL5 Y+V/ZZZg==; Message-ID: <20230112143825.822328168@infradead.org> User-Agent: quilt/0.66 Date: Thu, 12 Jan 2023 15:31:46 +0100 From: Peter Zijlstra To: x86@kernel.org, Joan Bruguera Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Juergen Gross , "Rafael J. Wysocki" , xen-devel , Jan Beulich , Roger Pau Monne , Kees Cook , mark.rutland@arm.com Subject: [RFC][PATCH 5/6] PM / hibernate: Add minimal noinstr annotations References: <20230112143141.645645775@infradead.org> MIME-Version: 1.0 X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1673534415423100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When resuming there must not be any code between swsusp_arch_suspend() and restore_processor_state() since the CPU state is ill defined at this point in time. Signed-off-by: Peter Zijlstra (Intel) --- kernel/power/hibernate.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -280,6 +280,32 @@ __weak int arch_resume_nosmt(void) return 0; } =20 +static noinstr int suspend_and_restore(void) +{ + int error; + + /* + * Strictly speaking swsusp_arch_suspend() should be noinstr too but it + * is typically written in asm, as such, assume it is good and shut up + * the validator. + */ + instrumentation_begin(); + error =3D swsusp_arch_suspend(); + instrumentation_end(); + + /* + * Architecture resume code 'returns' from the swsusp_arch_suspend() + * call and resumes execution here with some very dodgy machine state. + * + * Compiler instrumentation between these two calls (or in + * restore_processor_state() for that matter) will make life *very* + * interesting indeed. + */ + restore_processor_state(); + + return error; +} + /** * create_image - Create a hibernation image. * @platform_mode: Whether or not to use the platform driver. @@ -323,9 +349,7 @@ static int create_image(int platform_mod in_suspend =3D 1; save_processor_state(); trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true); - error =3D swsusp_arch_suspend(); - /* Restore control flow magically appears here */ - restore_processor_state(); + error =3D suspend_and_restore(); trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false); if (error) pr_err("Error %d creating image\n", error); From nobody Mon May 6 11:33:40 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; dkim=fail; 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 1673534405801201.6345515696969; Thu, 12 Jan 2023 06:40:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.476204.738276 (Exim 4.92) (envelope-from ) id 1pFyjq-0002rB-BK; Thu, 12 Jan 2023 14:39:30 +0000 Received: by outflank-mailman (output) from mailman id 476204.738276; Thu, 12 Jan 2023 14:39:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFyjq-0002nW-2V; Thu, 12 Jan 2023 14:39:30 +0000 Received: by outflank-mailman (input) for mailman id 476204; Thu, 12 Jan 2023 14:39:28 +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 1pFyjo-0002av-UJ for xen-devel@lists.xenproject.org; Thu, 12 Jan 2023 14:39:28 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e881a6da-9286-11ed-b8d0-410ff93cb8f0; Thu, 12 Jan 2023 15:39:24 +0100 (CET) Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFyjo-0057zn-9C; Thu, 12 Jan 2023 14:39:28 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 6E776300AFB; Thu, 12 Jan 2023 15:39:13 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id CB2472CC949B7; Thu, 12 Jan 2023 15:39:12 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: e881a6da-9286-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=LNbZyqdS6MCOXN5DhvrakKEz6kKRrs7/+Ia2/9U4HAc=; b=G5AA9h/yH9+nJcJaV99Ad2Ey8F k5XWYtZamnH9v88AQNk//cUWHI313YsUcDWkBRHwsEnZ3YwO8uX31UVbbHNGiSckhXek4//+Wnz8l sFL6gBapz0F4s5kPWpNrhL2lnWrU7jUGCNGjtvEK9GN2wjN3Qp6ppjE4WmTl7v9s6AsO4FwK2CMiy BksgEqIsTHg+IvsVuWE/RCyauvJNvXu9ihIdqTkl7iNXaBSeD4jwxobQPOMLpk/dWsh0TlC086R3I 6S5sM/g0/l5h+kcMN6smqUUGVPcaJ0N69KsfH2p+TSKM/cDaDIhyRd6fHrKzfHFtn9N3WXaseHucg 0YtdygGg==; Message-ID: <20230112143825.881829388@infradead.org> User-Agent: quilt/0.66 Date: Thu, 12 Jan 2023 15:31:47 +0100 From: Peter Zijlstra To: x86@kernel.org, Joan Bruguera Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Juergen Gross , "Rafael J. Wysocki" , xen-devel , Jan Beulich , Roger Pau Monne , Kees Cook , mark.rutland@arm.com Subject: [RFC][PATCH 6/6] x86/power: Seal restore_processor_state() References: <20230112143141.645645775@infradead.org> MIME-Version: 1.0 X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1673534407637100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Disallow indirect branches to restore_processor_state(). Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/suspend_64.h | 4 ++++ arch/x86/power/cpu.c | 2 +- arch/x86/power/hibernate_asm_64.S | 4 ++++ include/linux/suspend.h | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) --- a/arch/x86/include/asm/suspend_64.h +++ b/arch/x86/include/asm/suspend_64.h @@ -9,6 +9,7 @@ =20 #include #include +#include =20 /* * Image of the saved processor state, used by the low level ACPI suspend = to @@ -61,4 +62,7 @@ struct saved_context { extern char core_restore_code[]; extern char restore_registers[]; =20 +#define restore_processor_state restore_processor_state +extern __noendbr void restore_processor_state(void); + #endif /* _ASM_X86_SUSPEND_64_H */ --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -288,7 +288,7 @@ static __always_inline void __restore_pr } =20 /* Needed by apm.c */ -void noinstr restore_processor_state(void) +void __noendbr noinstr restore_processor_state(void) { __restore_processor_state(&saved_context); } --- a/arch/x86/power/hibernate_asm_64.S +++ b/arch/x86/power/hibernate_asm_64.S @@ -23,6 +23,10 @@ #include #include =20 +.pushsection .discard.noendbr +.quad restore_processor_state +.popsection + /* code below belongs to the image kernel */ .align PAGE_SIZE SYM_FUNC_START(restore_registers) --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -9,6 +9,7 @@ #include #include #include +#include =20 #ifdef CONFIG_VT extern void pm_set_vt_switch(int); @@ -483,7 +484,10 @@ extern struct mutex system_transition_mu =20 #ifdef CONFIG_PM_SLEEP void save_processor_state(void); + +#ifndef restore_processor_state void restore_processor_state(void); +#endif =20 /* kernel/power/main.c */ extern int register_pm_notifier(struct notifier_block *nb);