From nobody Sat Nov 30 03:40:29 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=1620056415; cv=none; d=zohomail.com; s=zohoarc; b=fHeb8QH5t1CdrZ0aC6bwO0YQ75TNsHIFPdshs1CeWrUn0BFkD9o4O+gRcl1uhh4M/dlQtHSuLdAdCtFxZTPpMoVczOooRFNZsLROUg/lTmh9Icm7aJpX/4TSpjztHm3iXfPgN7Pqr4/GiKvh7578IrUg6llCMeJlPCkIISIIWMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620056415; 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=G5VW+MBiRkXftSVFbiphieWQv3y7NMej8MRlAgIkqVM=; b=hmkjz+Ans6NorxMA3IrBNLrWo0QghqQiTGRiEl22zUqJR1B1eMloC5V0ZDQhKxvvo7qlBYqcCqNpaWPgYf0GUGQHz8/rPIlv8GlPSMpcPBlCbgaAsjWkjaUKJ0lmNJLnLHb/O9eYthfZgevdWpblXy5wD6380fDWNKXVd58nlGc= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620056415257413.8971267484618; Mon, 3 May 2021 08:40:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.121699.229526 (Exim 4.92) (envelope-from ) id 1ldafn-00019Y-UR; Mon, 03 May 2021 15:39:51 +0000 Received: by outflank-mailman (output) from mailman id 121699.229526; Mon, 03 May 2021 15:39:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ldafn-00019R-RO; Mon, 03 May 2021 15:39:51 +0000 Received: by outflank-mailman (input) for mailman id 121699; Mon, 03 May 2021 15:39:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ldafm-00019M-Uc for xen-devel@lists.xenproject.org; Mon, 03 May 2021 15:39:50 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 335820cc-7388-415e-bf6d-33d452fd8cb8; Mon, 03 May 2021 15:39:50 +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: 335820cc-7388-415e-bf6d-33d452fd8cb8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620056390; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w7Xo1CRX6LgQwvrOXLUtnY7XKHYy8vBzRGguf0D0ZzU=; b=V05TcB4VfeAvhuszyvDSWlXfCCwBPVr2ixm8fZ6G4uR8nSsn3k5WfUbj FNB/6G2wle/pD2af6UTqabFBpFN4P7dhS//xLdvxk8pS2ZF4pBOsvIN1T LNYnucFQsXoqRfILqHhA4TCkIOR/LK08BLHqjYKZiys6Uw/C1aYJegStK g=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: vAYGs1Hij7qrprczXNX/gUlo7yBa9ui7IFjWJMPWCgq/AWEMZ+Euoz2iNLBf7NBIRU3+e9qUsi BGNyXhKmtCemdtRJINHLmWFi165SmJDLpzOnkk/UmI6g/C8tVEEN52OI28sAl4pC7c+1UFuiP4 dRngxbWub4HGWauMHLjZdCQUd8w+b6gCyIliaGyFdSZk3je3Iw7NhCUqLnRfvAX1q47/UyJPJO Aqu1N+MkaT6b3Q958vwIoDcvHo3jd5mobTU/RvlQQrXziWw7SrEgCP9VSzX3SdKbVC2ni6udrv m7U= X-SBRS: 5.1 X-MesageID: 43332330 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:ECAIYKq21n+vdPLaZJjR6okaV5rUeYIsi2QD101hICF9WMqeis yogbAnxQb54Qx8ZFgMu/ClfJOBT3TV6IJv7eAqVouKcQH6tAKTQ71KwpDlx1TbdRHW0uJGz6 9vf+xfJbTLbWRSqcb/7E2GH807wN+BmZrIuc7kw31gTR5nZshbhm8SZzqzKFF8RwVNGPMCZf mhz/dAzgDQHEg/X4CWAWQEQviGh/CjruODXTc2QyQIrCWvoFqTmdzHLyQ= X-IronPort-AV: E=Sophos;i="5.82,270,1613451600"; d="scan'208";a="43332330" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 1/5] x86/xstate: Elide redundant writes in set_xcr0() Date: Mon, 3 May 2021 16:39:34 +0100 Message-ID: <20210503153938.14109-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210503153938.14109-1-andrew.cooper3@citrix.com> References: <20210503153938.14109-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) XSETBV is an expensive instruction as, amongst other things, it involves reconfiguring the instruction decode at the frontend of the pipeline. We have several paths which reconfigure %xcr0 in quick succession (the cont= ext switch path has 5, including the fpu save/restore helpers), and only a sing= le caller takes any care to try to skip redundant writes. Update set_xcr0() to perform amortisation automatically, and simplify the __context_switch() path as a consequence. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu --- xen/arch/x86/domain.c | 4 +--- xen/arch/x86/xstate.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 4dc27f798e..50a27197b5 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1977,9 +1977,7 @@ static void __context_switch(void) memcpy(stack_regs, &n->arch.user_regs, CTXT_SWITCH_STACK_BYTES); if ( cpu_has_xsave ) { - u64 xcr0 =3D n->arch.xcr0 ?: XSTATE_FP_SSE; - - if ( xcr0 !=3D get_xcr0() && !set_xcr0(xcr0) ) + if ( !set_xcr0(n->arch.xcr0 ?: XSTATE_FP_SSE) ) BUG(); =20 if ( cpu_has_xsaves && is_hvm_vcpu(n) ) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 3794d9a5a5..f82dae8053 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -55,11 +55,18 @@ static inline bool xsetbv(u32 index, u64 xfeatures) return lo !=3D 0; } =20 -bool set_xcr0(u64 xfeatures) +bool set_xcr0(u64 val) { - if ( !xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures) ) - return false; - this_cpu(xcr0) =3D xfeatures; + uint64_t *this_xcr0 =3D &this_cpu(xcr0); + + if ( *this_xcr0 !=3D val ) + { + if ( !xsetbv(XCR_XFEATURE_ENABLED_MASK, val) ) + return false; + + *this_xcr0 =3D val; + } + return true; } =20 --=20 2.11.0