Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1887026pxv; Fri, 2 Jul 2021 15:11:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxENVOP6dSL3jgcfa+hxR6l6AM5bTRdGaz9EBLqq99Ecf6BCD3/CxoMG9Emvj/JEjL+NRdY X-Received: by 2002:a17:907:9690:: with SMTP id hd16mr1898924ejc.251.1625263882578; Fri, 02 Jul 2021 15:11:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263882; cv=none; d=google.com; s=arc-20160816; b=KArCoEC21bz8I1u7QkFn6/X8TfZCpOWmTZmt7snegT1orZA9BWqk/aKCoQYIMReIEv JWFIvOCQpTLE4C49ALYig7cfy4ZWXejHQF1eEIvHd2ckVyRyVno25eJ5ApJQJnT+Spp8 /fAmCeE9thMle9sYYPXFKwEUw0j4yPg9Q1rKS9GTfpZxUV+lupcqEi+XhcAg/iyTH+FX olyrF4HVURucTMsFOcZo/Z6Idk7VQkP4SsRvmRUhYlQAf4OYFDkrYItDHaeE868puIKh a5ITJ/mzQ6UF1+lSnDrKs/k5Jts+2SPWroxKv7LiBQ/PsQzsDyTWIr97X5kR0kmbLrYg ROWw== 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; bh=IoKgX1Lxr4vUmdDhzmZvZh7BgOGwiFmw9XugWpYoHxM=; b=GVHCfAOvZnt1imLSSWBdlYQT9ZAGTOdDjLDQt4khUmbNYdP3iUcNwXm9A3b21braSF 8dR/dod7SM2trnwQDIrYWYLsdooZ6RCU/UxFP5gm5AY1HAm2mmLQNswOlhCDDBzxgja0 EWVNHwvYChCV064GAaip27QxVy+pC47HT9DRpa3yC+FiN3td2vZxxO7F3+5AStSKl2Nw OALwHJCZgHSnkj2YHtc0GRkuL7vzWU4yp3tw98RSoEVgiydtgzCCByttNLhlClU0hXJ5 hMaQ2em7qTFDoL7+V6MkDhVxt8Zguc65CcIRFLfktbG2uQbvnY2ZJK0cM/uehZDjzJR5 A6Fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si4504698ede.18.2021.07.02.15.10.59; Fri, 02 Jul 2021 15:11:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233786AbhGBWKP (ORCPT + 99 others); Fri, 2 Jul 2021 18:10:15 -0400 Received: from mga12.intel.com ([192.55.52.136]:50197 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233131AbhGBWH5 (ORCPT ); Fri, 2 Jul 2021 18:07:57 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="188472732" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="188472732" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:24 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814756" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:23 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson , Kai Huang Subject: [RFC PATCH v2 26/69] KVM: x86: Add flag to disallow #MC injection / KVM_X86_SETUP_MCE Date: Fri, 2 Jul 2021 15:04:32 -0700 Message-Id: <456e910585c72e5dfdff30bfea63afa874965479.1625186503.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Add a flag to disallow MCE injection and reject KVM_X86_SETUP_MCE with -EINVAL when set. TDX doesn't support injecting exceptions, including (virtual) #MCs. Co-developed-by: Kai Huang Signed-off-by: Kai Huang Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index be329f0a7054..09e51c5e86b3 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1064,6 +1064,7 @@ struct kvm_arch { bool bus_lock_detection_enabled; bool irq_injection_disallowed; + bool mce_injection_disallowed; /* Deflect RDMSR and WRMSR to user space when they trigger a #GP */ u32 user_space_msr_mask; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4070786f17d1..681fc3be2b2b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4319,15 +4319,16 @@ static int vcpu_ioctl_tpr_access_reporting(struct kvm_vcpu *vcpu, static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, u64 mcg_cap) { - int r; unsigned bank_num = mcg_cap & 0xff, bank; - r = -EINVAL; + if (vcpu->kvm->arch.mce_injection_disallowed) + return -EINVAL; + if (!bank_num || bank_num > KVM_MAX_MCE_BANKS) - goto out; + return -EINVAL; if (mcg_cap & ~(kvm_mce_cap_supported | 0xff | 0xff0000)) - goto out; - r = 0; + return -EINVAL; + vcpu->arch.mcg_cap = mcg_cap; /* Init IA32_MCG_CTL to all 1s */ if (mcg_cap & MCG_CTL_P) @@ -4337,8 +4338,7 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, vcpu->arch.mce_banks[bank*4] = ~(u64)0; static_call(kvm_x86_setup_mce)(vcpu); -out: - return r; + return 0; } static int kvm_vcpu_ioctl_x86_set_mce(struct kvm_vcpu *vcpu, -- 2.25.1