Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp352607rwb; Tue, 25 Jul 2023 17:12:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlHclp21kB1Z+W00gTDl8hcTjpehYcx4sBsrNHaRsjaapc1wYNBfWRhSG+7/fePcxUsucp2P X-Received: by 2002:a17:907:7892:b0:994:5659:1fa with SMTP id ku18-20020a170907789200b00994565901famr286872ejc.18.1690330333851; Tue, 25 Jul 2023 17:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690330333; cv=none; d=google.com; s=arc-20160816; b=zd+VM0U2VQddFcIxdAlm7Xfofcr7stxBPrzcurHHXb0/il2+TXQfaRU5Kko4wceZ6u fe5FtIvwLL5aIspkmwwKsUlVAJozx4A4BG53+J6vXqd9B7zM4SaWNiI6rwa3DJIi1bBY ATPVBOM5LYA2sQfJ4puBM98c9tQ82KkZP6KFKnLM799IZQXeaILmhHVE7mjTr84uhL1s dvGiLAVrkIRbTpyfKqe/bGjy8QbcjmOysj315nU0sfTjwCP+FC7F/3Do6QxZlV9iSfo7 W5u4GLMUBkSFlzRMPfmOB8Y59RyMrVYy+J0gEKAgMzMMYVJnv1aRjLDHJzXxy9MopLsY SmEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EDEX9aVJnl1ZNyzzx4SoR0ykR6GiPmKm6DctGomA3J0=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=E/kk0J01G+8qgBBEsOdhRRbMmdwsMFNEpexeFOy4BZRGT0DasB+7fbesCbhH+Gwpqv By9CzjiaLGet1bp1qlGhQYztY46CLhobOUOubhZbQ2dCKYr0xZ1SWycbZF6iO8UKYH8N 1lpk4D5fIEp3NPUTJ0MdP+05McrNhmF95gYvem3ZqiZbfiD+Ew7CWLiR1yp7lbdGy60g gBuX8f9w9s6vMkGe6Mi+lYkKes/K9IkhrlXNIYohiKXjAYez70Ff8dguxcaAf6dhizwA YKuAenv35WPFfvx3rnsAW77OvBMObWtKu4PmboqDvNMiyJkyQhF1phshLDcgbWblemMU BeQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PqQffRyl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa23-20020a170907b9d700b00992d2a0cd97si8503011ejc.932.2023.07.25.17.11.49; Tue, 25 Jul 2023 17:12:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PqQffRyl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232888AbjGYW0V (ORCPT + 99 others); Tue, 25 Jul 2023 18:26:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233380AbjGYWXw (ORCPT ); Tue, 25 Jul 2023 18:23:52 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35F1C26B6; Tue, 25 Jul 2023 15:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323569; x=1721859569; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oacKdQeMh8QuirRSr8ipRHm85rmLeDu5QPcTK7AXcqY=; b=PqQffRyldbnRumqqjYLFc4M1uBnuIfa5rDEBDQN2uQO06gmo0CMTFlqY B0V0ULRV3IjsxZ8OWtpbb3rr0m7T9Qf9bJzS3avWM6mfaaGB/9gpZ64nZ aFjUMp31P+7qHg1XPQ+TovhvERSxKcVpGN6WekmFFZsDxBlIHr38h+xXj BXGRsxbRmbag6l3AcnFdj2a6EGEejXZO0dIK601po+mgxoLQWn5SansEf YZk8nHFe2jUFcXaYYZNCw8szkHUwAr3gutMrDwQ4POu8KmroCH1Zvb9dq KwwnBfy70bA7emS69CARyekmn5s+lMB0z+qHyOedv+F+od4vHJ5YTKbFv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882800" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882800" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001978" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001978" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:12 -0700 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 , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v15 113/115] RFC: KVM: x86: Add x86 callback to check cpuid Date: Tue, 25 Jul 2023 15:15:04 -0700 Message-Id: <8787693c245ceeeada515fcca5ef78da3a1a7343.1690322424.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index ba9cc4ac9093..aaa7db45d809 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 291d36a668e5..304c01945115 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1590,6 +1590,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 09b83f7c228d..de10a2de1dd5 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -123,6 +123,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 @@ -150,7 +151,10 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu, if (!xfeatures) return 0; - return fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); + r = fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); + if (r) + return r; + 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