Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp173227rdb; Mon, 22 Jan 2024 16:21:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDJrAVncRSZBT2AzAjMNHnTQCU9uje88sNuPp/lyDRjKlrG1nxqP6awpCEKLTZ7jJfCuUh X-Received: by 2002:a19:7512:0:b0:510:3c1:52dc with SMTP id y18-20020a197512000000b0051003c152dcmr182267lfe.69.1705969300487; Mon, 22 Jan 2024 16:21:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705969300; cv=pass; d=google.com; s=arc-20160816; b=uqCGiWrKOtL7WhRut+cbSI3FUKKl3n483v+1SS6jwU9sntkXl2BwgA7iRQ/KwyK/xf uSmm7XgLWTG0aUsWEhegkP5VLpdnHLhuux5O5DdR40ZPp0L0qA0KmCvR4tXrKC6mUAfi ob4xcDS0y1nXplz20s4EOQhm2/5ewPU6hYYO4OC/Gio5fYRPdi79QjrVeGcw8Dtfwzpt tpDQ2gAg72AKzoUCxtAR4s2gZCmwdTTcUo6c1dilKgc/rgEXfXgBoF3JkhAE6G/4JHE0 LFdKySC9e9ncwwAJY6HSwxPFUIZux1mwn67V4M+KnHAmU3feTFOcmxbDD1udIEqA33bN kk/w== 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=ROatKoKOz/AKTQVo2PtQiPI8ITBtN1ZojkSTqwfD5r0=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=CBC9j9dKnSdCq9DqMgpEV5InpdgUliz52hQYe+c9TTj94QwB+XPMHAz+MxKABpoKX4 YJ7CBBTgeVvTkBTq4wGwDijdUyVnQhbrNuyd5vuZyNAGaBbY23Ek+805/Li7wBnn3GEA cV+kIxQrjjmVC0AwfZsNgp8/iqt3ipcyESNbK+JgxAzFrqqa/NVLx2nP19SQWARMZ76y Vd/JBJGCCU9YXvzl7bkUWmVboV2yzZ/stsIuHd3zVbykjbNkDJw7bx+Kfhzjdt3e7+Rr NQmP8dOOYkPjRRVi39b99BK8m7Qvz6nR0Rj9t4fc+mnxzngbbrjDaLi+Lo8+0KxwvTLh xVZA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Oi4mCESm; 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-34425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f7-20020a17090660c700b00a2af8d78a90si10942254ejk.1033.2024.01.22.16.21.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:21:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Oi4mCESm; 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-34425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34425-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 126471F21EBC for ; Tue, 23 Jan 2024 00:21:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B12A82D87; Mon, 22 Jan 2024 23:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Oi4mCESm" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 BF50282D76; Mon, 22 Jan 2024 23:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967781; cv=none; b=TED1AN7zXK261BPKrQX59bP17cKguC1lKcvx/RF+YJBg+28GdC096B8hvh7LuFsPVEGBmsT9FDbz2Uj8cHFbQxmOzISTMfIfqwI5jlgZFjTgKTWyfOzbmh7G6033qkaLIsU8WV/GeU4Z9/ud9jeVHGO+zRpZypSnC8ZwaHRCF2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967781; c=relaxed/simple; bh=aUhdNswTSlh4dExBSB5iQ1sRamKjvsGJJ69O6iOhYK8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J8cag85w/DGB83B+W2jLDgs8lyFa10eX7yldufgNNf+nYnLVfMeT5gjyrr8CBhpyMdA+eN9wvkYJH2u5mdS+Kw0UgIiZEUUFBLb9GRNf0cR8BZGwOvsIz9+NnzVx1kFDHWAGcT9tKnTCaxY6ow2me2JLSkQ2nfe8Pvez7lC8Pro= 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=Oi4mCESm; arc=none smtp.client-ip=192.55.52.120 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=1705967779; x=1737503779; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aUhdNswTSlh4dExBSB5iQ1sRamKjvsGJJ69O6iOhYK8=; b=Oi4mCESm4HNoOUEcjkESGtYkzDkViB+YzwEKex5v7N/EFvJah1Kvd6bF qF5WlglCdU0OIzl47ctB7coYh0cgtzQBQ2iaipRXx6gt7ygTa+LfCh/l9 cW8d1/xg/jb2kx/Sxk4E2M4+ciGpeNosV9QfNMFub6erROgL9lg0tIPdH Y6k8oDjFE9Vu8+25bSOtbDMnqvbkBOcUBYOk5YVF9TfM9DwMk/oetMtn+ Sbz0is18XYjfaoc5J4f35VLGaWtepdjRjz7GpqCxHq+/Iu1yGujeQRHOp AIhZgw6h84NW5A3cYFgNcGQQT3SWCePVPQEnCKqev145AZjwflozQZyhl Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="400217966" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="400217966" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27818051" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:59 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 119/121] RFC: KVM: x86: Add x86 callback to check cpuid Date: Mon, 22 Jan 2024 15:54:35 -0800 Message-Id: <5f60a91ab6f0cb596ca37eb0f2365779dd59beb5.1705965635.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaku Yamahata The x86 backend should check the consistency of KVM_SET_CPUID2 because it has its constraint. Add a callback for it. The backend code will come as another patch. Suggested-by: Sean Christopherson Link: https://lore.kernel.org/lkml/ZDiGpCkXOcCm074O@google.com/ Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm-x86-ops.h | 2 ++ arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index ee0b82817c63..527db174d6b5 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -20,6 +20,8 @@ KVM_X86_OP(hardware_disable) KVM_X86_OP(hardware_unsetup) KVM_X86_OP_OPTIONAL_RET0(offline_cpu) KVM_X86_OP(has_emulated_msr) +/* TODO: Once all backend implemented this op, remove _OPTIONAL_RET0. */ +KVM_X86_OP_OPTIONAL_RET0(vcpu_check_cpuid) KVM_X86_OP(vcpu_after_set_cpuid) KVM_X86_OP(is_vm_type_supported) KVM_X86_OP_OPTIONAL(max_vcpus); diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 54ac65b75f18..b83a790b01c8 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1655,6 +1655,7 @@ struct kvm_x86_ops { void (*hardware_unsetup)(void); int (*offline_cpu)(void); bool (*has_emulated_msr)(struct kvm *kvm, u32 index); + int (*vcpu_check_cpuid)(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2, int nent); void (*vcpu_after_set_cpuid)(struct kvm_vcpu *vcpu); bool (*is_vm_type_supported)(unsigned long vm_type); diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 8cdcd6f406aa..b57006943247 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -136,6 +136,7 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu, { struct kvm_cpuid_entry2 *best; u64 xfeatures; + int r; /* * The existing code assumes virtual address is 48-bit or 57-bit in the @@ -155,15 +156,18 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu, * enabling in the FPU, e.g. to expand the guest XSAVE state size. */ best = cpuid_entry2_find(entries, nent, 0xd, 0); - if (!best) - return 0; - - xfeatures = best->eax | ((u64)best->edx << 32); - xfeatures &= XFEATURE_MASK_USER_DYNAMIC; - if (!xfeatures) - return 0; + if (best) { + xfeatures = best->eax | ((u64)best->edx << 32); + xfeatures &= XFEATURE_MASK_USER_DYNAMIC; + if (xfeatures) { + r = fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, + xfeatures); + if (r) + return r; + } + } - return fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); + return static_call(kvm_x86_vcpu_check_cpuid)(vcpu, entries, nent); } /* Check whether the supplied CPUID data is equal to what is already set for the vCPU. */ -- 2.25.1