From patchwork Mon Sep 9 15:51:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11138217 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93AD114E5 for ; Mon, 9 Sep 2019 15:53:16 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6EF3C20863 for ; Mon, 9 Sep 2019 15:53:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="YxAHxczZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EF3C20863 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7Lww-0001Dg-Jf; Mon, 09 Sep 2019 15:51: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 1i7Lwv-0001Da-3P for xen-devel@lists.xenproject.org; Mon, 09 Sep 2019 15:51:29 +0000 X-Inumbo-ID: af377e86-d319-11e9-b299-bc764e2007e4 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id af377e86-d319-11e9-b299-bc764e2007e4; Mon, 09 Sep 2019 15:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568044288; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Ycfzqz35S93BaQErjBwP7w2oj9qOE91COvvGMLxul2U=; b=YxAHxczZh3NidZzDBcL1DQrI/cZDu8ywi1Pxdnn27Bt5UbYhQXogShJE 8/QEQtMU7+A5t2cQ+rvM4Hz6S8fVzo4BX0V7UB0nN3xEQfoIJzfMZ/E77 lBQmGB76d00/oWMcHfPXxwdLcWQ4qpkF5BdmKO9Z2lexrnxRsXhXO8aBj g=; 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: 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 ~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: FxI18Hwn9w4BjhnhANnyPFkNF/UiB9+K9etwq3sDYsBgamVVUE6Q8CwvZdy+hHo5r3Myrqbde2 HCkBAysPKK5IpcXm5wOjhMCeKDoJcWX5pjiL1Eh0E9BTSrhrZQUOpvYt7PkG5bbXxJncJTasHc UeepQvlXkpa9i2h8AzLIZyca74bPySVWlyn5Jfrftz1Z4K40vb2FMzjYmQCgVElgb6+g/UsGIx nZPuI1OBCXICXSZGquut6FjcLISstkhFVPoSug41VZ07l66XtvB/JfYYWjyH97H4WfmGEPTbj4 hPA= X-SBRS: 2.7 X-MesageID: 5329688 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.64,486,1559534400"; d="scan'208";a="5329688" From: Andrew Cooper To: Xen-devel Date: Mon, 9 Sep 2019 16:51:24 +0100 Message-ID: <20190909155124.19942-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/cpuid: Fix handling of the CPUID.7[0].eax levelling MSR 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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 7a0 is an integer field, not a mask - taking the logical and of the hardware and policy values results in nonsense. Instead, take the policy value directly. Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monné Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné Even Rome hardware has 7[0].eax still as 0, and there is no sensible reason to set max_subleaf higher at this point, so this is only a latent bug for now. --- xen/arch/x86/domctl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 1e98fc8009..35ad8cb51c 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -218,11 +218,16 @@ static int update_domain_cpuid_info(struct domain *d, if ( is_pv_domain(d) && ((levelling_caps & LCAP_7ab0) == LCAP_7ab0) ) { uint64_t mask = cpuidmask_defaults._7ab0; - uint32_t eax = ctl->eax; - uint32_t ebx = p->feat._7b0; - if ( boot_cpu_data.x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON) ) - mask &= ((uint64_t)eax << 32) | ebx; + /* + * Leaf 7[0].eax is max_subleaf, not a feature mask. Take it + * wholesale from the policy, but clamp the features in 7[0].ebx + * per usual. + */ + if ( boot_cpu_data.x86_vendor & + (X86_VENDOR_AMD | X86_VENDOR_HYGON) ) + mask = (((uint64_t)p->feat.max_subleaf << 32) | + ((uint32_t)mask | p->feat._7b0)); d->arch.pv.cpuidmasks->_7ab0 = mask; }