From nobody Sun May 5 15:05:58 2024 Delivered-To: importer@patchew.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; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1587394797; cv=none; d=zohomail.com; s=zohoarc; b=oD6pqRbo+1G38AGpkLT2TO+pnHfmTa0uNcZGfL2r7fYZGWVHyMVkB9ggsFV1wmicHe12cNMj14sKN6yr3ceQ7WIDc/n6O6OElRMsd7i+PG3ZZn/ifjXafGKg8Yf18QsFKjv5PREwTGKaV4otL522+P+ZYX9IScs78wWQNWCMOGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587394797; 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=XiLgm1CDd9bgzsosDG4bA/oz4Kkqt9BqxtPVPzG94HM=; b=c2nln6dbrzUrQsLAIEgrZB2TYVhZFHps8WmDBg9SXe36rj8IbJuP20Cws6gfs7v4LGnJCp5K+QXKUiae1eaNzDe5J8in8wy5WFoWfLOXMQRgH/UbUb/BuqcANs3WnuHViTej65bzMX7+hZ31YLgCVjwzqcfdehLlgs46m/dDGWw= ARC-Authentication-Results: i=1; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1587394797450128.4127510817142; Mon, 20 Apr 2020 07:59:57 -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 1jQXtH-0000iy-LM; Mon, 20 Apr 2020 14:59:19 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jQXtG-0000it-Ds for xen-devel@lists.xenproject.org; Mon, 20 Apr 2020 14:59:18 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 81b123fa-8317-11ea-9e09-bc764e2007e4; Mon, 20 Apr 2020 14:59:17 +0000 (UTC) X-Inumbo-ID: 81b123fa-8317-11ea-9e09-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1587394757; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7k2KgyXK5WCQysFCR3M6CGIKNQrfmIps/JCUPxhQK84=; b=fuPrV/8gcQcGvGSKsP1nfQSAaP3Qz2zirdRU5L5h1/+ROLiK5+tMDL+u qqtaBTvpn5dPOqa9am8dTfP6iGPCHwlSI6J1K3hY4uEgScH6+lAgYjJCK cOxDwWGCXAoybMy7KSFMumzqXyklmow/K2gA8FxD++pVBS3ZV9jKjxiwu c=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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; Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: vwgPRJFnJJ5HqRLjWI1kNt/Q3Duw63WpHzn+qiHtkUT6j++6JPoEI0IarP9Lwtfke8lXvLX57x HZN62iud0ZAumQDQWfc5qdZuJhq/+Rx7vbhfwTG6D3vB4UXx8RCx2GhGqlmXykfIE3yAM5BmRy nRnZ8KGR/KMlRjRAlKJB5YsxiIC0fRfW2SxKhrXkMSrRFt7MmwW4iY9N1c+qYir45bb+Dcd6FG kE2afj2hZrrAArxk6xvJn4hSjhDpAxsKaDRIVm6NGiiAGUINqahCk8ugKJVOgvDKNu5xkTS9cg QGg= X-SBRS: 2.7 X-MesageID: 15959931 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,406,1580792400"; d="scan'208";a="15959931" From: Andrew Cooper To: Xen-devel Subject: [PATCH 1/3] x86/S3: Use percpu_traps_init() rather than opencoding SYSCALL/SYSENTER restoration Date: Mon, 20 Apr 2020 15:59:09 +0100 Message-ID: <20200420145911.5708-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200420145911.5708-1-andrew.cooper3@citrix.com> References: <20200420145911.5708-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This make the S3 BSP path consistent with AP paths, and reduces the amount = of state needing stashing specially. Also, it takes care of re-setting up Xen= 's LBR configuration if requested, which was missing previously. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/acpi/suspend.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/acpi/suspend.c b/xen/arch/x86/acpi/suspend.c index 32d0f71ffd..1c2f1c470e 100644 --- a/xen/arch/x86/acpi/suspend.c +++ b/xen/arch/x86/acpi/suspend.c @@ -15,8 +15,6 @@ #include #include =20 -static unsigned long saved_lstar, saved_cstar; -static unsigned long saved_sysenter_esp, saved_sysenter_eip; static unsigned long saved_fs_base, saved_gs_base, saved_kernel_gs_base; static uint64_t saved_xcr0; =20 @@ -25,14 +23,6 @@ void save_rest_processor_state(void) saved_fs_base =3D rdfsbase(); saved_gs_base =3D rdgsbase(); rdmsrl(MSR_SHADOW_GS_BASE, saved_kernel_gs_base); - rdmsrl(MSR_CSTAR, saved_cstar); - rdmsrl(MSR_LSTAR, saved_lstar); - - if ( cpu_has_sep ) - { - rdmsrl(MSR_IA32_SYSENTER_ESP, saved_sysenter_esp); - rdmsrl(MSR_IA32_SYSENTER_EIP, saved_sysenter_eip); - } =20 if ( cpu_has_xsave ) saved_xcr0 =3D get_xcr0(); @@ -46,24 +36,13 @@ void restore_rest_processor_state(void) /* Restore full CR4 (inc MCE) now that the IDT is in place. */ write_cr4(mmu_cr4_features); =20 - /* Recover syscall MSRs */ - wrmsrl(MSR_LSTAR, saved_lstar); - wrmsrl(MSR_CSTAR, saved_cstar); - wrmsrl(MSR_STAR, XEN_MSR_STAR); - wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK); + /* (re)initialise SYSCALL/SYSENTER state, amongst other things. */ + percpu_traps_init(); =20 wrfsbase(saved_fs_base); wrgsbase(saved_gs_base); wrmsrl(MSR_SHADOW_GS_BASE, saved_kernel_gs_base); =20 - if ( cpu_has_sep ) - { - /* Recover sysenter MSRs */ - wrmsrl(MSR_IA32_SYSENTER_ESP, saved_sysenter_esp); - wrmsrl(MSR_IA32_SYSENTER_EIP, saved_sysenter_eip); - wrmsr(MSR_IA32_SYSENTER_CS, __HYPERVISOR_CS, 0); - } - if ( cpu_has_xsave && !set_xcr0(saved_xcr0) ) BUG(); =20 --=20 2.11.0 From nobody Sun May 5 15:05:58 2024 Delivered-To: importer@patchew.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; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1587394786; cv=none; d=zohomail.com; s=zohoarc; b=LobRSAJoRCUwhTvJEcQ7RjiTNatikQMX2DCTNF/G/EPQhdrILfY1tLAh5Ir/hfPMOJbqmS4sAoB/pc2yuJtB2cgm3s/cbiTHjawE/HDcew/c1z6r8Ce794FCsntHYNfqRadegKGW1ikWfODDIt2m8ofrTL5u9DowPAK/8fnX/DU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587394786; 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=BZAtE/NDnSXgXpea1KmvC8dBjlqNLwZe1BYT+fYO+zE=; b=Bp3mzn6xAPrKT2G/V1LCW0+QVcalq1+rXvtNTafUSU9q3DXLnJuBGXvRAuHR5aWTzJ1yHljitkmc/woXxPz95uB9LOVSZ5FTl8P7ofQv78fZF+1BngaHnyfYlNug5RAyBkLQ263aqLzPllMuczcpdR2Azt8v+zkMiMV4DDazJrg= ARC-Authentication-Results: i=1; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1587394786665205.58106842266147; Mon, 20 Apr 2020 07:59:46 -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 1jQXtM-0000jH-V7; Mon, 20 Apr 2020 14:59:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jQXtL-0000jA-Dy for xen-devel@lists.xenproject.org; Mon, 20 Apr 2020 14:59:23 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 826fb37e-8317-11ea-9e09-bc764e2007e4; Mon, 20 Apr 2020 14:59:18 +0000 (UTC) X-Inumbo-ID: 826fb37e-8317-11ea-9e09-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1587394758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0FMwLpqDC0VR7A4uGgKObYvkj59mRHa1JOdxdGTYGzg=; b=Aout0F85o8qaOSclzinxrlzka8Tjl96tYOCOdCfc/L1zh6twF0zY3gmc D/3TTlR3KSUmLh9IZvYlVh79JhjEPq8FKRMvNzjq9AP8JTM35Ui4/Ddfm SDHgpOe9kdOF2mdUkQiEpXcZLevEIsanj1VQR+I5R9iIxjejbOZ8nsV6G s=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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; Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 1mGYZCKyXlgwt18fLqgX04XEr+xWh5d5Y1kv8/xwox7zyJlXLBninIdrft4fV0zXKXMxc+Og+9 DZFWLcRnHh2peXEkJ+6LF5mgc7BUXzLmO/DdVwdRSmJ3RBYux+u4j8AUn7snkuOYbHKIIf/B9t KHXATJ78feEYdBIWFmVQaAx2aaYEmozn5NV6H3pzqJfcN8ZQNduu0+z1gWHpzZkRtlQb7FkqIH xWRKaqjZ29FTtQL1UgJ8+VwbQ/hjdZaSww/+2FdvfzoIOK1ZPewLGj8RUa2ezFbpr0hC19NCQF hQA= X-SBRS: 2.7 X-MesageID: 15959933 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,406,1580792400"; d="scan'208";a="15959933" From: Andrew Cooper To: Xen-devel Subject: [PATCH 2/3] x86/boot: Don't enable EFER.SCE for !CONFIG_PV builds Date: Mon, 20 Apr 2020 15:59:10 +0100 Message-ID: <20200420145911.5708-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200420145911.5708-1-andrew.cooper3@citrix.com> References: <20200420145911.5708-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Cooper , Kevin Tian , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This will cause all SYSCALL/SYSRET instructions to suffer #UD rather than following the MSR_{L,C}STAR pointers, allowing us to drop the star_enter() panic helper, allowing us to clean up the IST stacks in a subsequent patch. Drop the now-dead conditional SYSENTER logic in the middle of subarch_percpu_traps_init(). In addition, vmx_restore_host_msrs() need not restore any host state. (Regarding the asymmetric changes, VT-x automatically restores SYSENTER state on vmexit, and SVM restores both SYSCALL/SYSENTER state with the VMSAVE/VMLOAD instructions.) Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Reviewed-by: Kevin Tian --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Kevin Tian --- xen/arch/x86/boot/trampoline.S | 4 ++-- xen/arch/x86/efi/efi-boot.h | 3 ++- xen/arch/x86/hvm/vmx/vmx.c | 4 ++++ xen/arch/x86/x86_64/traps.c | 19 ++++++------------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/boot/trampoline.S b/xen/arch/x86/boot/trampoline.S index 18c6638924..928b4ad4ce 100644 --- a/xen/arch/x86/boot/trampoline.S +++ b/xen/arch/x86/boot/trampoline.S @@ -140,9 +140,9 @@ gdt_48: GLOBAL(trampoline_misc_enable_off) .quad 0 =20 -/* EFER OR-mask for boot paths. This gets adjusted with NX when available= . */ +/* EFER OR-mask for boot paths. SCE conditional on PV support, NX added w= hen available. */ GLOBAL(trampoline_efer) - .long EFER_LME | EFER_SCE + .long EFER_LME | (EFER_SCE * IS_ENABLED(CONFIG_PV)) =20 GLOBAL(trampoline_xen_phys_start) .long 0 diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index a13304201f..bf0fae4f89 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -238,7 +238,8 @@ static void __init noreturn efi_arch_post_exit_boot(voi= d) /* Set system registers and transfer control. */ asm volatile("pushq $0\n\tpopfq"); rdmsrl(MSR_EFER, efer); - efer |=3D EFER_SCE; + if ( IS_ENABLED(CONFIG_PV) ) + efer |=3D EFER_SCE; if ( cpu_has_nx ) efer |=3D EFER_NX; wrmsrl(MSR_EFER, efer); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 869339062b..3e4b2e9a58 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -496,6 +496,10 @@ static void vmx_vcpu_destroy(struct vcpu *v) */ static void vmx_restore_host_msrs(void) { + /* No PV guests? No need to set restore host SYSCALL infrastructure. = */ + if ( !IS_ENABLED(CONFIG_PV) ) + return; + /* Relies on the SYSCALL trampoline being at the start of the stubs. */ wrmsrl(MSR_STAR, XEN_MSR_STAR); wrmsrl(MSR_LSTAR, this_cpu(stubs.addr)); diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c index c3d4faea6b..93af0c5e87 100644 --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -299,17 +299,8 @@ static unsigned int write_stub_trampoline( =20 DEFINE_PER_CPU(struct stubs, stubs); =20 -#ifdef CONFIG_PV void lstar_enter(void); void cstar_enter(void); -#else -static void __cold star_enter(void) -{ - panic("lstar/cstar\n"); -} -#define lstar_enter star_enter -#define cstar_enter star_enter -#endif /* CONFIG_PV */ =20 void subarch_percpu_traps_init(void) { @@ -321,6 +312,10 @@ void subarch_percpu_traps_init(void) /* IST_MAX IST pages + at least 1 guard page + primary stack. */ BUILD_BUG_ON((IST_MAX + 1) * PAGE_SIZE + PRIMARY_STACK_SIZE > STACK_SI= ZE); =20 + /* No PV guests? No need to set up SYSCALL/SYSENTER infrastructure. */ + if ( !IS_ENABLED(CONFIG_PV) ) + return; + stub_page =3D map_domain_page(_mfn(this_cpu(stubs.mfn))); =20 /* @@ -338,10 +333,8 @@ void subarch_percpu_traps_init(void) { /* SYSENTER entry. */ wrmsrl(MSR_IA32_SYSENTER_ESP, stack_bottom); - wrmsrl(MSR_IA32_SYSENTER_EIP, - IS_ENABLED(CONFIG_PV) ? (unsigned long)sysenter_entry : 0); - wrmsr(MSR_IA32_SYSENTER_CS, - IS_ENABLED(CONFIG_PV) ? __HYPERVISOR_CS : 0, 0); + wrmsrl(MSR_IA32_SYSENTER_EIP, (unsigned long)sysenter_entry); + wrmsr(MSR_IA32_SYSENTER_CS, __HYPERVISOR_CS, 0); } =20 /* Trampoline for SYSCALL entry from compatibility mode. */ --=20 2.11.0 From nobody Sun May 5 15:05:58 2024 Delivered-To: importer@patchew.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; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1587394797; cv=none; d=zohomail.com; s=zohoarc; b=SQOzrYF8tb7cT80Flqxn35PdIrX1GYc1M/0GFAmciwzll4EAc9+AMLgaMrHxhVmOzVdxoNrGugniQ1Bv7PeitqQPN9Y87IpR0+Tj25+D7N+9mL9zJRw9uvgv0vhkT6Pk0ls1QiH0VwWe4fe8lEFMXK3h/WozENSqO4X/yO28Atc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587394797; 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=hmIbHOPff3Kr3A1sIpRrDLQiQw7C7SlYmWxbTt1y9rw=; b=mYPB9LgPYobx3wATmUQYohrBD5sJOilaXSnUKHyKAsfm44C9q2hHAtFouxo5Df5L+HscnFPNfup36MMCrR/2+9M08ipOYs92U7EkYKh2HPa7wUPJh9WfvLjs4cD9TyKCPmo9Gy2LAum6SRACkS1JDE4ilNL9I+m/zfV+dCnLOjM= ARC-Authentication-Results: i=1; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1587394797380583.9706256924757; Mon, 20 Apr 2020 07:59:57 -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 1jQXtS-0000kB-9A; Mon, 20 Apr 2020 14:59:30 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jQXtQ-0000jn-Da for xen-devel@lists.xenproject.org; Mon, 20 Apr 2020 14:59:28 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 830acb48-8317-11ea-83d8-bc764e2007e4; Mon, 20 Apr 2020 14:59:19 +0000 (UTC) X-Inumbo-ID: 830acb48-8317-11ea-83d8-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1587394760; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iey7aibL2jSId8nqzu63DXwhMLLiDYRA4/Czvj4kpsU=; b=Tz2eeTLmy+8ziwN7Ijk6Gs9G5+fpGFOmK8aHg4VeKvlbQJ7PRD1iLlV3 BW3IugEA6WBQus7IoyEX80Cn+n8zDromj15dV6WGv2hxBUsFYY654yyN4 0LY0KkwKUyszXzbQmVF8N7oA7HIEFp32+yoPPJTYeFIZ1C2sJbGz/owl4 k=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: jXdlcSAfrcGp+tNv0XgzI+aOKK8aoY9xYgjNRJQHnFyinUhTe6OPol6afEd5ZXugydxkKShrUk Q+Ky74EnxbZt1muA2edI2lzxIGBrWzSJS2vSkIjHz50xYultnsXQ9r0XZP3wjNQIIZkqOEb/yz u4FYiBm4RZSO5P/Zvbul0qYUGBdHW53WLbgYffkqfc93uEmJRyHSKOihQfA8hDc3ngAS7jBSeR 9HI5XPd4UiDBkx94FcmoIQwFbpVr/56hnQXGWvSZ0FRU9rweygq9gNlk+5cOM5VcHkhCKzClHb Tjc= X-SBRS: 2.7 X-MesageID: 15928930 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,406,1580792400"; d="scan'208";a="15928930" From: Andrew Cooper To: Xen-devel Subject: [PATCH 3/3] x86/pv: Don't use IST for NMI/#MC/#DB in !CONFIG_PV builds Date: Mon, 20 Apr 2020 15:59:11 +0100 Message-ID: <20200420145911.5708-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200420145911.5708-1-andrew.cooper3@citrix.com> References: <20200420145911.5708-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) ISTs are used to force a stack switch on CPL0=3D>0 interrupts/exceptions. = They however come with a nasty corner case in the case of reentrancy where the outer exception frame gets clobbered. When the SYSCALL/SYSRET instructions aren't used, there is no need to use I= ST for anything other than #DF, which reduces the number of corner cases. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/cpu/common.c | 8 +++++--- xen/include/asm-x86/processor.h | 12 +++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 7b093cb421..d45495c701 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -732,15 +732,17 @@ void load_system_tables(void) .rsp2 =3D 0x8600111111111111ul, =20 /* - * MCE, NMI and Double Fault handlers get their own stacks. + * #DF always uses a separate stack. NMI/#MC/#DB only need a + * separate stacks when PV guests are used. * All others poisoned. */ .ist =3D { - [IST_MCE - 1] =3D stack_top + IST_MCE * PAGE_SIZE, [IST_DF - 1] =3D stack_top + IST_DF * PAGE_SIZE, +#ifdef CONFIG_PV [IST_NMI - 1] =3D stack_top + IST_NMI * PAGE_SIZE, + [IST_MCE - 1] =3D stack_top + IST_MCE * PAGE_SIZE, [IST_DB - 1] =3D stack_top + IST_DB * PAGE_SIZE, - +#endif [IST_MAX ... ARRAY_SIZE(tss->ist) - 1] =3D 0x8600111111111111ul, }, diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processo= r.h index ea6e5497f4..33f2052c8e 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -441,12 +441,18 @@ struct tss_page { }; DECLARE_PER_CPU(struct tss_page, tss_page); =20 +/* + * Interrupt Stack Tables. Used to force a stack switch on a CPL0=3D>0 + * interrupt/exception. #DF uses IST all the time to detect stack overflo= ws + * cleanly. NMI/#MC/#DB only need IST to cover the SYSCALL gap, and there= fore + * only necessary with PV guests. + */ #define IST_NONE 0UL #define IST_DF 1UL #define IST_NMI 2UL #define IST_MCE 3UL #define IST_DB 4UL -#define IST_MAX 4UL +#define IST_MAX (IS_ENABLED(CONFIG_PV) ? 4ul : 1ul) =20 /* Set the Interrupt Stack Table used by a particular IDT entry. */ static inline void set_ist(idt_entry_t *idt, unsigned int ist) @@ -461,6 +467,8 @@ static inline void set_ist(idt_entry_t *idt, unsigned i= nt ist) static inline void enable_each_ist(idt_entry_t *idt) { set_ist(&idt[TRAP_double_fault], IST_DF); + if ( !IS_ENABLED(CONFIG_PV) ) + return; set_ist(&idt[TRAP_nmi], IST_NMI); set_ist(&idt[TRAP_machine_check], IST_MCE); set_ist(&idt[TRAP_debug], IST_DB); @@ -469,6 +477,8 @@ static inline void enable_each_ist(idt_entry_t *idt) static inline void disable_each_ist(idt_entry_t *idt) { set_ist(&idt[TRAP_double_fault], IST_NONE); + if ( !IS_ENABLED(CONFIG_PV) ) + return; set_ist(&idt[TRAP_nmi], IST_NONE); set_ist(&idt[TRAP_machine_check], IST_NONE); set_ist(&idt[TRAP_debug], IST_NONE); --=20 2.11.0