From nobody Sat Apr 20 03:25:23 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=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1633975593; cv=none; d=zohomail.com; s=zohoarc; b=I3W+hfjx0ryX9byG2oeIX/QHbVmiM8S6+k7f6n1YFkpbBugdgX4Wl+g5XVyKqysT2JmWny7HJiTjSQpZuZSHbhIYfOn2Mn4wn5K7ywKItbVvJ0yLJfTesTkSH2ALmmKNXlatitbzDfw1RDtL/CwpFMpIejA9LeMlhL8ZFvfSfsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633975593; 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=d1JrCb0Cd4EJpDtCpimOK6vkwf9HX1uFyxWupgXcaL0=; b=N1nJd0v7XuF+tzh5WBFDWzLFjMAaeUfbCC/ZOo9N8leN4RF66yFeIhHd/HjrWkRIHEAkxHpeNktbv3lafZ3N8IeKI82L1Ugif86HU34UiVldJUbAaEwRwb6y6W+vgnUpkMDxKCly5J/CDgXwNKQ5F+bMj/YkYo7iD88V0X2YsFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1633975593285918.0880331715615; Mon, 11 Oct 2021 11:06:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.206447.362016 (Exim 4.92) (envelope-from ) id 1mZzgg-0005XR-Ii; Mon, 11 Oct 2021 18:06:10 +0000 Received: by outflank-mailman (output) from mailman id 206447.362016; Mon, 11 Oct 2021 18:06:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZzgg-0005XK-Fq; Mon, 11 Oct 2021 18:06:10 +0000 Received: by outflank-mailman (input) for mailman id 206447; Mon, 11 Oct 2021 18:06:09 +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.92) (envelope-from ) id 1mZzgf-0005XE-Eb for xen-devel@lists.xenproject.org; Mon, 11 Oct 2021 18:06:09 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e7c6baca-2abd-11ec-80ee-12813bfff9fa; Mon, 11 Oct 2021 18:06:07 +0000 (UTC) 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: e7c6baca-2abd-11ec-80ee-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1633975567; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lvswEG2MEMgg4mNzsuL0uRhvX1GUmpngDXemfCWI2+Y=; b=VAU48sNwEkxHhr543ia97cAAmOCuDR7Yj7rgRo5OieUtG3uguMKfCQun cw3yyXYIcA3XxvjUr4xFy5DReAsN76cohy2Og1axmLRGWFkhfu5lJy38V Zk4Fa1uQ9t89pTSW4xN7ADTA+cGgobx6ZiyI09FzWJzD3DQcpFtBS9VVi c=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: +E1KJLph8b3VPchHHtSA9U6zbm7shbOvPErQRtkWV2DS+DOgb6+K9Sxns+wAMqSJf+mKS7UR1T 8WW2PNErKAHgXrqCd1XEyD0xl3iaWS32BAjds4MazBUwl1zwGQjkuR4zO7JbqYN0KG2r8suypv O21HwnNpOWxc8yMhyjHOCF4GOAZ0k1JCQFQdjac5UYRahSKca5oHzPy2Al+60WjG2vQ3VAEydZ +7V2U6Fze/gwyRt15xBIGLzNKaIBvdtzQKStOrtdrbH1uic7vwvFAGpaBqH6oV4mgZHiirZ+33 iobJSDFmabgIxPXtbS8w14/t X-SBRS: 5.1 X-MesageID: 54940701 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:aUht/6x8L+5ruiKBG4d6t+f+wSrEfRIJ4+MujC+fZmUNrF6WrkUAx jBOWTqAbK2JYmDwLYh/OomwpBsGsZDXzodjTQE5pCAxQypGp/SeCIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnvopW1TYhSEUOZugH9IQM8aZfHAsLeNYYH1500s6w7dg2tQAbeWRWGthh /uj+6UzB3f9s9JEGjp8B3Wr8U4HUFza4Vv0j3RmDRx5lAa2e0o9VfrzEZqZPXrgKrS4K8bhL wr1IBNVyUuCl/slIovNfr8W6STmSJaKVeSFoiI+t6RPHnGuD8H9u0o2HKN0VKtZt9mGt9po4 9RosoSNdR9zZIjCpORGXURbGhgraMWq+JefSZS+mcmazkmAeHrw2fR+SkoxOOX0+M4uXzsIr 6ZBbmlQMFbT3Ipaw5riIgVoru0lINPmI8U0vXZ4wCuCJf0nXYrCU+PB4towMDIY25wfQa6BP 5NxhTxHQi7dbhBxIQ0rFLkcreyxvWKuUBlqkQfAzUYwyzeKl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vacc/Xzfbq5SAqjBLYkLtp133Aq2lEZdPUzSL3+qy nOpoV+6faQsl0ssR4b9exoVJPufZq+z/5ICOsqU4tKNTOO0AHEEGgI1+rf6gylNyri9vNMkY dMGpIObeEY1GIK7voSNjPIceod/A== X-IronPort-AV: E=Sophos;i="5.85,365,1624334400"; d="scan'208";a="54940701" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH] x86/pv: Split pv_hypercall() in two Date: Mon, 11 Oct 2021 19:05:41 +0100 Message-ID: <20211011180541.24501-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211011180541.24501-1-andrew.cooper3@citrix.com> References: <20211011180541.24501-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1633975594622100001 The is_pv_32bit_vcpu() conditionals hide four lfences, with two taken on any individual path through the function. There is very little code common between compat and native, and context-dependent conditionals predict very badly for a period of time after context switch. Move do_entry_int82() from pv/traps.c into pv/hypercall.c, allowing _pv_hypercall() to be static and forced inline. The delta is: add/remove: 0/0 grow/shrink: 1/1 up/down: 300/-282 (18) Function old new delta do_entry_int82 50 350 +300 pv_hypercall 579 297 -282 which is tiny, but the perf implications are large: Guest | Naples | Milan | SKX | CFL-R | ------+--------+--------+--------+--------+ pv64 | 17.4% | 15.5% | 2.6% | 4.5% | pv32 | 1.9% | 10.9% | 1.4% | 2.5% | These are percentage improvements in raw TSC detlas for a xen_version hypercall, with obvious outliers excluded. Therefore, it is an idealised b= est case improvement. The pv64 path uses `syscall`, while the pv32 path uses `int $0x82` so necessarily has higher overhead. Therefore, dropping the lfences is less o= ver an overall improvement. I don't know why the Naples pv32 improvement is so small, but I've double checked the numbers and they're correct. There's something we're doing whi= ch is a large overhead in the pipeline. On the Intel side, both systems are writing to MSR_SPEC_CTRL on entry/exit (SKX using the retrofitted microcode implementation, CFL-R using the hardware implementation), while SKX is suffering further from XPTI for Meltdown protection. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu --- xen/arch/x86/pv/hypercall.c | 24 +++++++++++++++++++----- xen/arch/x86/pv/traps.c | 11 ----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/pv/hypercall.c b/xen/arch/x86/pv/hypercall.c index 9765e674cf60..3579ba905c1c 100644 --- a/xen/arch/x86/pv/hypercall.c +++ b/xen/arch/x86/pv/hypercall.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include =20 @@ -109,15 +110,15 @@ const pv_hypercall_table_t pv_hypercall_table[] =3D { #undef COMPAT_CALL #undef HYPERCALL =20 -void pv_hypercall(struct cpu_user_regs *regs) +/* Forced inline to cause 'compat' to be evaluated at compile time. */ +static void always_inline +_pv_hypercall(struct cpu_user_regs *regs, bool compat) { struct vcpu *curr =3D current; - unsigned long eax; + unsigned long eax =3D compat ? regs->eax : regs->rax; =20 ASSERT(guest_kernel_mode(curr, regs)); =20 - eax =3D is_pv_32bit_vcpu(curr) ? regs->eax : regs->rax; - BUILD_BUG_ON(ARRAY_SIZE(pv_hypercall_table) > ARRAY_SIZE(hypercall_args_table)); =20 @@ -137,7 +138,7 @@ void pv_hypercall(struct cpu_user_regs *regs) =20 curr->hcall_preempted =3D false; =20 - if ( !is_pv_32bit_vcpu(curr) ) + if ( !compat ) { unsigned long rdi =3D regs->rdi; unsigned long rsi =3D regs->rsi; @@ -348,8 +349,21 @@ void pv_ring1_init_hypercall_page(void *p) *(u8 *)(p+ 7) =3D 0xc3; /* ret */ } } + +void do_entry_int82(struct cpu_user_regs *regs) +{ + if ( unlikely(untrusted_msi) ) + check_for_unexpected_msi((uint8_t)regs->entry_vector); + + _pv_hypercall(regs, true /* compat */); +} #endif =20 +void pv_hypercall(struct cpu_user_regs *regs) +{ + _pv_hypercall(regs, false /* native */); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c index 764773c02104..1e05a9f1cdad 100644 --- a/xen/arch/x86/pv/traps.c +++ b/xen/arch/x86/pv/traps.c @@ -24,22 +24,11 @@ #include #include =20 -#include #include #include #include #include =20 -#ifdef CONFIG_PV32 -void do_entry_int82(struct cpu_user_regs *regs) -{ - if ( unlikely(untrusted_msi) ) - check_for_unexpected_msi((uint8_t)regs->entry_vector); - - pv_hypercall(regs); -} -#endif - void pv_inject_event(const struct x86_event *event) { struct vcpu *curr =3D current; --=20 2.11.0