From patchwork Tue Apr 23 16:53:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13640372 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EFD813D637 for ; Tue, 23 Apr 2024 16:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891214; cv=none; b=D4SMuXGMlgIiJ8BB/AaMnXZbCA1wfmylu2GykijuvtR2VotPA4bZG9WGf+WUQ+vkGbz1FIYBy9CqPDc6ZR8lODYsEdgPyE7DSOtohV6Vb63JvL2J8TMV3mOLKdWuyNVzZh3fGZmfGJryB1wSYBKRUbyE+HrbRsZKqPXPdJnAiu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891214; c=relaxed/simple; bh=IIA0cZD11SCgBB3seks1sD5Tm1ngX7ytjSsIqj8LB4M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jP7oFZ8wHXJsHnc7QaHKs/Vq20RupngWm2a8v07xqvlkcu90lkM0cbBN8Qc0gX6lRAO/sZQK18tGXM+Q/ZrEhoO8cT5Ttzm+wlk0IP4vVuk7MwZ002hKXqZuWqzW8iDF80QeP0XnEYUlu0HS1ck8gwIpDecdFd/4Gzqf9G6Z05w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zXi2Kof8; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zXi2Kof8" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5fff63b4a87so2031740a12.0 for ; Tue, 23 Apr 2024 09:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713891212; x=1714496012; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ftFQzTSwFXT1TIp1fPDslrbqn6nx3jYtj/iibVlTl4A=; b=zXi2Kof83cYMXmR1e3PcChCblyi65SbjE9NWdj5+XpI9OQZuvJxlWSV7zOdHgvZ/uh 7vU6o8jgwBk6cDfjUwIhYEVA03W0gfv8CaZpZeaphtVwwTpIbDkPMOBg7ahyiKvdytSh fCScGGmzm/4CQmZz1W5YC+lTimbEomsOxzCjH7TpiiLeYo37i+6jZaCrC/u/c5ZtydmK 4VTNX2Ve1iJuYmi4gchGjUbfspBr+BDJyLb7H8gtCv+dPIXOXyLRMCzNqCX1xXBiaQlc 0SAUdlGxWQOKjzZzkhmOsMP2jG9OUdrfAJXuh0qpt04eyAHnfHWN206Gh6iemk9ELGhj kdeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891212; x=1714496012; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ftFQzTSwFXT1TIp1fPDslrbqn6nx3jYtj/iibVlTl4A=; b=BsIbDQyaIrNxUl28o54+xJJJ9vVfRV4V6SzMXfS125o6S8WC4PMhAhrRMlLo/T6bSc rVucHGA2Cqg0W5SRHcGprW4Srpb5FAbsdSUgwvOJpdSKvXQ+gEteTVrp8dDAD7tHO/rs haQ1Qr5H1UMA4u/dC3U1ZWL2duiBPXdDm1eydjU2nPLkM/I0bLn14q4d1LUaByNeagwg uswCLrkoaY0+8DoDAhg7KMNgPDKNJTmsf+n2AEAQ4pQi6IiZ590k/6x7X0YaOWbAtFFM jjqeZ3M+R/WO0/fQvnT4sCkeverfvH34AAzhEGQIdD7gmZQI6cUgU1qKim1r+VOq/OsB KelA== X-Gm-Message-State: AOJu0YyTpLXgqWslUWXAmkDSJVcKhZzX3SkcVw2GP91szqBmv5uqWayR HntAoqNccanqPR4avIcSrpNVHOPGj0m2xhm8Dre0qjFns8bqLoG8fyDth2/4gIGSZ4QwJ9V7BHJ 7/Q== X-Google-Smtp-Source: AGHT+IHMKvgcg5vLMtiLvLskSs3bQ87rsfU5twomg9UnoRcDVBw7UM6yzMuwcxiHO8TKCzQ1vo/xo09ouPs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:2ccb:0:b0:5dc:eb5:19db with SMTP id s194-20020a632ccb000000b005dc0eb519dbmr1690pgs.0.1713891212528; Tue, 23 Apr 2024 09:53:32 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 23 Apr 2024 09:53:26 -0700 In-Reply-To: <20240423165328.2853870-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240423165328.2853870-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240423165328.2853870-2-seanjc@google.com> Subject: [PATCH 1/3] KVM: x86: Fully re-initialize supported_vm_types on vendor module load From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Recompute the entire set of supported VM types when a vendor module is loaded, as preserving supported_vm_types across vendor module unload and reload can result in VM types being incorrectly treated as supported. E.g. if a vendor module is loaded with TDP enabled, unloaded, and then reloaded with TDP disabled, KVM_X86_SW_PROTECTED_VM will be incorrectly retained. Ditto for SEV_VM and SEV_ES_VM and their respective module params in kvm-amd.ko. Fixes: 2a955c4db1dd ("KVM: x86: Add supported_vm_types to kvm_caps") Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2d2619d3eee4..a65a1012d878 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -94,7 +94,6 @@ struct kvm_caps kvm_caps __read_mostly = { .supported_mce_cap = MCG_CTL_P | MCG_SER_P, - .supported_vm_types = BIT(KVM_X86_DEFAULT_VM), }; EXPORT_SYMBOL_GPL(kvm_caps); @@ -9776,6 +9775,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) if (r) goto out_free_percpu; + kvm_caps.supported_vm_types = BIT(KVM_X86_DEFAULT_VM); + if (boot_cpu_has(X86_FEATURE_XSAVE)) { host_xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK); kvm_caps.supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0; From patchwork Tue Apr 23 16:53:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13640373 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F05E13DB96 for ; Tue, 23 Apr 2024 16:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891216; cv=none; b=tyqZMpVppTrGgbApgnadxTTGvC0cihjv+9AtcxVrZnvE63Hd0emHvWiAyqN2oAcHRBxRxWEWdzMBZDZfQmFaxK5On5LsQp22GwgEM31uhviXtoLWJ+SDB5Y6PQ58QcyJVnZ255VPBzSHKtMOh0qX+CX/mWp8nDPzLaMjyFjbImk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891216; c=relaxed/simple; bh=ub/c4lMzNuQE/ASob0hO2P7pr3tW5fJO73ybbxmtQhA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lkuQMXuS8pPoH308bIg5Hiwy0SF75+M1bazns1uSc9DmkE0OqZOJ+iz6kE+YFEe/nMBqZPc7lScNpFZwwtwbxVv1a/QQVd8gnGvFfDTCG7J+kn7XFv75818JiDIdXmGY/OyE6h4/f0cKPGPAZ5fisFka85nvGIvjrRCDilCyvok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XgZ44Gix; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XgZ44Gix" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-6ed0e1f8faeso22740b3a.1 for ; Tue, 23 Apr 2024 09:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713891214; x=1714496014; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=vs27nCM79m201+PPivEr2AY28j47w3WHEEMcLDKrspA=; b=XgZ44GixJQ56Rr1DZ8+JUONi1f4avXxmyBl2ogq4Me4fhOEAZxoCd+3MCGKyF/B26c dJ4Y1zPD17A5Tfpeyr5Beuk+DUmZFsmBunhpd4SOM2DPRsArfxlVd8NxxqXGZBYJdymT yolZhpjMscF0OYTyWidp6Goj/Jvmzl9V4xtupqPrKRy94IsX4DehR7wj8t7NxM4dM7fS 2QIvN7h9Tm+baWyNRrNYHNiECgVvqC55mU7xocTTLC6DKzm8uNMOd9LtH1E3a4wwsOxV qDpRJqSdttdlNRUokduMT4td83RjlEPIRpaaFmDSBlqxNtMSfvxoKeMB1cKbkqS2mFZk Hc0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891214; x=1714496014; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vs27nCM79m201+PPivEr2AY28j47w3WHEEMcLDKrspA=; b=PuVJNDi1VVOe9KSjkA8GVhh1HHvdV+naGvmFiq+k1fTxKb6WWYtIuQ6e88a+s9iwiU LB/q7JziqSDrinwEHsrqk2y8YoO0uAMlyNqK6TcAMbXzTHG56xX7rCrhAbsxJWqKe2sr IQip0oTQ1TTulJ8nllHaKqJxloDC8n9hLAiZX7EkozXbkOLNPDypjYbHWpeBtw5SW6Bn iQdq6BkNmUV2n3wMnf+RB2YYWLqhof/+xudD1U8cT7hKiYSu4v1tuVoRyqg1hgbf8nFG Y+/Rt3AANvaLDMGPZVmywoPiMmyGXm8Wj8diswP8JJVoIRr9zfdKrUGWdFsZT6LJuYk5 ONJA== X-Gm-Message-State: AOJu0Yw/2hJoQ24QXAgo+I8vy3M95j7xEFHfbKOYdCrtlAiALHjhyxBn fJ1nkZ6agcdBoIy0Ubrp50BL3WgPxtI6JuVCQ7QX9gYm71ZquUguH5lC0vDCUmIByy/wnP1PnWg aUw== X-Google-Smtp-Source: AGHT+IHHss4tWuFp3utLNINOqa+jKnoNwBJ+RlJYWs9fS6z+DNT3QK/uQRUw/WQrJokPWQezfnz2mAbl10I= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:4ba4:b0:6ea:e009:1815 with SMTP id kt4-20020a056a004ba400b006eae0091815mr33967pfb.3.1713891214344; Tue, 23 Apr 2024 09:53:34 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 23 Apr 2024 09:53:27 -0700 In-Reply-To: <20240423165328.2853870-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240423165328.2853870-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240423165328.2853870-3-seanjc@google.com> Subject: [PATCH 2/3] KVM: x86: Fully re-initialize supported_mce_cap on vendor module load From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Effectively reset supported_mce_cap on vendor module load to ensure that capabilities aren't unintentionally preserved across module reload, e.g. if kvm-intel.ko added a module param to control LMCE support, or if someone somehow managed to load a vendor module that doesn't support LMCE after loading and unloading kvm-intel.ko. Practically speaking, this bug is a non-issue as kvm-intel.ko doesn't have a module param for LMCE, and there is no system in the world that supports both kvm-intel.ko and kvm-amd.ko. Fixes: c45dcc71b794 ("KVM: VMX: enable guest access to LMCE related MSRs") Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a65a1012d878..44ce187bad89 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -92,9 +92,7 @@ #define MAX_IO_MSRS 256 #define KVM_MAX_MCE_BANKS 32 -struct kvm_caps kvm_caps __read_mostly = { - .supported_mce_cap = MCG_CTL_P | MCG_SER_P, -}; +struct kvm_caps kvm_caps __read_mostly; EXPORT_SYMBOL_GPL(kvm_caps); #define ERR_PTR_USR(e) ((void __user *)ERR_PTR(e)) @@ -9776,6 +9774,7 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) goto out_free_percpu; kvm_caps.supported_vm_types = BIT(KVM_X86_DEFAULT_VM); + kvm_caps.supported_mce_cap = MCG_CTL_P | MCG_SER_P; if (boot_cpu_has(X86_FEATURE_XSAVE)) { host_xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK); From patchwork Tue Apr 23 16:53:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13640374 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86F5B13E038 for ; Tue, 23 Apr 2024 16:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891218; cv=none; b=knnQ0S+odnMxr+dIWhtekgb5jMOytsISGCI3G4pBjI6IY3/6KzPk0ALyvJNtKI1geNkFqvBR+re/Sui66vwGY8IMLcjfyWgvkO1FCHSMOcWFUGJACd3HW7oUj61f8zVoW/gqlGHBPfz6tM1amL6qR/UGq6mtPr/da4kTyPug1R4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891218; c=relaxed/simple; bh=F6jaJv52CDprALPzgiY8c/9fYHL9o+SM83T+9ypBoLM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f/fpqMXMGQyeKyh0+orRRJ88YA1S64xiBwENyDA6IBhu8kXmfkTDAe8/UpGwaFX006HVrVvuVJevpM8+olua83DHdIh5sGEYbLxJizXpaWIkb2BCHbX1rJxblHulicqCLSnuW02I3lfAA/+/jV+ZdklyB+BeI/WJGifuC+xIcfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rtPE/21M; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rtPE/21M" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61b028ae5easo116874917b3.3 for ; Tue, 23 Apr 2024 09:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713891216; x=1714496016; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=sV9yNB6aR8W90fYMIdgt/s8o7GSizOulqAtOjmc/hB4=; b=rtPE/21MiptS2MvgASuGbodmcY5nlHuZ+1sB3J/zzGr0tfGryJFjx1HacGf8AhAhya YAfIH9TOjpgsqdhgFW2RfOMny0bO6DZuM6emVJLXum5BWcl+r4x7tn5BS5hIU4LlWf6g 7PkfcK+Le8ajAIoT4UzlaU28C8Xncb/x+fREVYhAHk1Yn43B3HHjsB9OCpTGD8EUTKDY eyNB91vhXTL5cBvL2Ar9mUldsQNe/05FR1rI0U/xZ/SHfXEeayO5uaCq4ZCY24LpbrE2 gBtdVpsPwxEl0LZERIid/W+aiaIHbhwuydLOj1hkY9wkBg0jOwBR4tvlVV6aSAufTjKI huaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891216; x=1714496016; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sV9yNB6aR8W90fYMIdgt/s8o7GSizOulqAtOjmc/hB4=; b=F6qhV5Fu3akmwsr4ZABw4xN7+oHA75ul4NiQbjYjh3/aySzmkVa05bjpeCR+BVmlZp RVRTIa9nPxWIYi4xkMr7H85fhTD8ddXw7dc5fx67uJ716M1XkSCBS/0+sFiLLKLfq5re qgoRSdGWoQ9eoYXQYAEIf5p0HilGWEO0wtT+Wjj4tis9y7Dqb4/d/fCqX4axsB3hz+2Z buE4c6uAR9UxJ0uhHl529eZ7q6G/+PRknF508Wwe2g9lSJW6XA84haw9ZrO/v5lLAYhh xIL/Eb/fcjrPiF7D82Hj6tGfS4tUv3lV+5sbGygEugibjLilNVbBtQGrHthFlP8thI+X sQeQ== X-Gm-Message-State: AOJu0Yzi3+o7lh6PSodxfNO8vg0eG8ikkN3CCg8StlPbwxRjWF3avt5F 0e3qko76x0UUBEz4Ltfbfvu0RSNL7lsUVoTHPSH8nYge/m41bsLDmMvLCHsFX4249ouQAkDH+rV spA== X-Google-Smtp-Source: AGHT+IEKtvFjeB+RwGhO/xxjR9keN4d9sjRQVzhkBfwnys03punNsGEp7Y1n5s+Kg7LT6FmELNYfr5dM7rE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:10c2:b0:dd9:3a6b:11f8 with SMTP id w2-20020a05690210c200b00dd93a6b11f8mr38570ybu.5.1713891216480; Tue, 23 Apr 2024 09:53:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 23 Apr 2024 09:53:28 -0700 In-Reply-To: <20240423165328.2853870-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240423165328.2853870-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240423165328.2853870-4-seanjc@google.com> Subject: [PATCH 3/3] KVM: x86: Explicitly zero kvm_caps during vendor module load From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Zero out all of kvm_caps when loading a new vendor module to ensure that KVM can't inadvertently rely on global initialization of a field, and add a comment above the definition of kvm_caps to call out that all fields needs to be explicitly computed during vendor module load. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 44ce187bad89..8f3979d5fc80 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -92,6 +92,11 @@ #define MAX_IO_MSRS 256 #define KVM_MAX_MCE_BANKS 32 +/* + * Note, kvm_caps fields should *never* have default values, all fields must be + * recomputed from scratch during vendor module load, e.g. to account for a + * vendor module being reloaded with different module parameters. + */ struct kvm_caps kvm_caps __read_mostly; EXPORT_SYMBOL_GPL(kvm_caps); @@ -9755,6 +9760,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) return -EIO; } + memset(&kvm_caps, 0, sizeof(kvm_caps)); + x86_emulator_cache = kvm_alloc_emulator_cache(); if (!x86_emulator_cache) { pr_err("failed to allocate cache for x86 emulator\n");