Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp992672rdb; Mon, 19 Feb 2024 00:00:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVVlteBbrMCF8ERyTBUpQ8fcAYJm1EBNfa74gvg1v82UatdmFoWoKKFEnZs/WJ82PFAOlB8AdtbzlwpQxeGyV5b1lgDZy7HOeYm5mLSgw== X-Google-Smtp-Source: AGHT+IHspz3WD2/9e0uRexROsa1zInt2Xw4WGhfeXGy6FgSS0CMEiI1FCNZoSFd16bw/Vh5pnoq8 X-Received: by 2002:a17:903:2448:b0:1dc:174:3dc1 with SMTP id l8-20020a170903244800b001dc01743dc1mr689955pls.58.1708329652775; Mon, 19 Feb 2024 00:00:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708329652; cv=pass; d=google.com; s=arc-20160816; b=Lv+gUpNCWXoYVNnzcNLB6kRR4F8qbHaYLOSdS/0gFszGgnjij+xC6AIUeC6y2kxphN ZfYnuBQITmP2VUArVOpQngeSDx6awbhXaKn69PMeVHvs9dekOW6zJEgrPt6j7HZdqZbI DIs9ObseMXVDaRgVW9wa1+SxRA/dQwfIBsulRNxy3PF8o6kGxInt3VrCEHcw/0TUyY4V 1JGKT4GQK07tA/HM532aOdzDNE8iW/k9RtIItw2k4Q6Z43Wy2FxzrZcLLwGo3wqnpadm Fguc6AQ3n4rmE39R66lcJfuA4I+4u/8yQgGl+P7sPNxnDmE/X1o/5vweb7c2UjI+5lhv akkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BO5cw1MjIiFMkpeteZ+oJt2+KT8RuY8LgEY3DV3O5YU=; fh=6bYtQoKQxNJSYrJA1a9vseXH6qHZpRYO7L/7krtpXA0=; b=nEu8keXQMQfg+IrumpbtUBfzKKwBIOmGrluLVw9FSQq0NzYN9aGZ6rmjRbw9yfomHp 8WTKRvPJZH9uiDbpQ1HYKAfKEuTe626D73UWyaMsLxuifEzlM7wSc6lxAVcDi+jk6vJt SP3gMFnOccO1mqFbhN+uGhnKafD0xy2d9+Jzi4QvU8pFRMkBLGai1sBLFxsie6Eskk6C LO/SXVY24x6pV0E8w1SArWewwouITJM5stP6ozpzBf+5pV9tCVIKk/MdQaFwre/onHG5 5TdBPFYUOyIPQfJU/86xbeRkHm4B8q4RPgPN3zZkwHgV6iN1MkbLC3GKzjPHzy/qk6Y0 WpWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lTH9M97n; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-70878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70878-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id me14-20020a170902fc4e00b001dba336154esi3984323plb.636.2024.02.19.00.00.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 00:00:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lTH9M97n; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-70878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70878-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9729BB237D9 for ; Mon, 19 Feb 2024 07:53:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAA16364CD; Mon, 19 Feb 2024 07:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lTH9M97n" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A39B42D627; Mon, 19 Feb 2024 07:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328873; cv=none; b=ZAy7ESdqaH7f8QapLJ9xDfjmfljR87KdUWbhH3y10okPLGsLbGGucRP9OeuznpND3tWB8anoBx2l9o/ryxe8S0KFuxDX0k2PH4phX5wENDIQYf3VjQGGN5EtjqqYl4yHshTybwwkbDN2opOEvHUJDmyk6H5rRH58oVzRdcfs4j8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328873; c=relaxed/simple; bh=sWkl7Z3XxOiuJFtnFAhcpB/qRiA1y0PFYes31RKezFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QKjFdkUMbMlzWc7252S2qVg0sZ/DHwubi1vjir2ytd+rCScaY1SyWdl07Un3WKJPEci9Bc/aWnQ4v5whNYB62S0K2QkozaH2CFZB0q4kQHQasxIyaGfqolIAP1MoBkH6+hC3LP2NfFm4QxSob2/OyY4QUwnchrv+EyQBcLxoNw0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lTH9M97n; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708328871; x=1739864871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sWkl7Z3XxOiuJFtnFAhcpB/qRiA1y0PFYes31RKezFo=; b=lTH9M97n9BU2W5/5FNjSZFQ+Fq5DK0ssFnfmMXcpBh2p2OoLxE2uSsGp oKpZzpk0N0WRpf3kmC44QoS1G8YEgXa4Fqr7CKXsTNNiYRohrInr8skn5 2xKHsoy7hzF9mi094PhAGnciJv434/y3TE3e7/29kDG+BlW8Jnw3rNJWt ZAGLRrjOvPjwJn8++J4Tq1gqXTrNjM2oNKXFlPiNM4iUqCv/gd4mKum77 pw/lLoWpcw/TuxAgtF/owZXHFQllGmPwC0+n8EhuEgSzuFnqs1elN7lYb oV4MBdY/XVphfI8vxU7wYtRu/uuMLaCScI9Oeax1cCjEw9cwk6kqRtLZm g==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="2535101" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="2535101" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:47:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="826966098" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="826966098" Received: from jf.jf.intel.com (HELO jf.intel.com) ([10.165.9.183]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:47:43 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com Subject: [PATCH v10 14/27] KVM: x86: Initialize kvm_caps.supported_xss Date: Sun, 18 Feb 2024 23:47:20 -0800 Message-ID: <20240219074733.122080-15-weijiang.yang@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240219074733.122080-1-weijiang.yang@intel.com> References: <20240219074733.122080-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Set original kvm_caps.supported_xss to (host_xss & KVM_SUPPORTED_XSS) if XSAVES is supported. host_xss contains the host supported xstate feature bits for thread FPU context switch, KVM_SUPPORTED_XSS includes all KVM enabled XSS feature bits, the resulting value represents the supervisor xstates that are available to guest and are backed by host FPU framework for swapping {guest,host} XSAVE-managed registers/MSRs. Signed-off-by: Yang Weijiang Reviewed-by: Maxim Levitsky Reviewed-by: Chao Gao --- arch/x86/kvm/x86.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b502d68a2576..60b574fc04d1 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -226,6 +226,8 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs; | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ | XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE) +#define KVM_SUPPORTED_XSS 0 + u64 __read_mostly host_efer; EXPORT_SYMBOL_GPL(host_efer); @@ -9737,12 +9739,13 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) host_xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK); kvm_caps.supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0; } + if (boot_cpu_has(X86_FEATURE_XSAVES)) { + rdmsrl(MSR_IA32_XSS, host_xss); + kvm_caps.supported_xss = host_xss & KVM_SUPPORTED_XSS; + } rdmsrl_safe(MSR_EFER, &host_efer); - if (boot_cpu_has(X86_FEATURE_XSAVES)) - rdmsrl(MSR_IA32_XSS, host_xss); - kvm_init_pmu_capability(ops->pmu_ops); if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) -- 2.43.0