From nobody Sun Feb 8 03:27:05 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 D56A02D73B4 for ; Thu, 13 Nov 2025 23:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763075665; cv=none; b=ZzAmrY2dmil5DxwSLWHVrc6PQwPSdnzYvBpDZC5nGraQveHno35kv3bh7aCRjO0VgB4si8yLpZA4yaQxU8lvrn7RG1VOMa9wkOc5j/I+gtXHjJP/6pWQv7fsWN/FsnVhcrceRBMFENiPLHfPw/ohmPYEswWgxqyZdn18BNVZiR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763075665; c=relaxed/simple; bh=mn8GVQsW19Ick+Xm2YxzYB2fwo0JYhu91nF/XucEWIw=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=n4pFAuqFaKmh9sKPXePqLvZGCD111SaE2uZYs2XYwWSXsXHk8pLRKkEGcsZPb8bZ2QeYnRkRZ9ZXrVdvgPkATuceRbBbdFwo34WYXBzi7flz4TR7d9srS/evaSBOgVe3XIT+cMCP4YXyV9hcnSnxn6oYMAsA3FFUUPmpgXZ57aw= 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=1qM5XqUG; arc=none smtp.client-ip=209.85.216.73 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="1qM5XqUG" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-34377900dbcso1974461a91.2 for ; Thu, 13 Nov 2025 15:14:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763075663; x=1763680463; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=E5/UTn8bTtJTVg4Qd62Iha30XVgFf5+QbZgjq/H2S+M=; b=1qM5XqUGEr3eIGxJqE9jU3FvQXZjVhETxJUCtbW+VA64VjXkq9xrIY965rHDlBRXvO oHx0xV+rvZKfC88/7TWIIfeioHOIgmYyolFIa7jN4MCVT8n3UiERJsPHcqFSEXB44EGC aTk7PcjLrKZeJGJEV581EVH5ZdS1pT6CeG0rQbw2bKtkzWO8vicdaH2bq+b8GCcySdr2 c85/KqCM20WyNSvmsWw1sj3sFPjbGXOBN8E1L6LPkiSXHD4Lza/zuT2eXUmd9cTVpSa8 eP8YzLf3GJC3cZgf/LQTHslnIvuz8h7gG2dJk4TYghAUfiuTTNXW4dAiysx0wI3EZroj AfOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763075663; x=1763680463; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E5/UTn8bTtJTVg4Qd62Iha30XVgFf5+QbZgjq/H2S+M=; b=VzLKOMByZGQvKwOOlaPNxVRs5ZqWOEJCe+2haUcTqbFXlvHG92IYgSwcZKWxj9QFsa 5eVCBODJBtAw1KCTVmqiyxWg3QlPRCtvZe4nBrIioMzJy/paNhWO5TALlXbaMT3Kk1VD X9ZKiEa0RFJqQ4QTkIdwp5gKimSkr1hpPKrLlb6zCw2YCuMXBrtWE4PJSJFOiy1pTzpx LRBTRv+FU9U68n/OcwTLKUMKesCQb+ZuK6Bk5JtWOZwfVHrhEYH2vK4HSJRA9zWogxuu HlPXi8Oa7T8x7MeogOkcombI8Qd+i9bv4DlTUb/aJgEORWk7yMbPdI4OWVtrs/vEgcE5 DKzw== X-Forwarded-Encrypted: i=1; AJvYcCUrtYegDtSnwIR6W14w57HGSrXE9pep44MLqllpy2Ls//UjbM4FJVzMN6Tcr2d7Q+lHfFvgkz68yZ7EG64=@vger.kernel.org X-Gm-Message-State: AOJu0YxpYPCGfUKx5no4R0ZvAUQBobdQxgysUMKx3atPp3z+omGiheGk 3C5c7WYkpdOnEwKzVhr1QrwAeWR1SsEXXoHJlob6SHsYlFdtt9VPZtmKsg2vZjDTWNXtxN0mTE7 hvreGdA== X-Google-Smtp-Source: AGHT+IGNgmeFlzSISc40y3tWMWrs8kvowjPqYMHL4csER25f6Rt+Kd7D0+iRgGX7761r68Kab45/rCMo2Og= X-Received: from pjrn4.prod.google.com ([2002:a17:90a:b804:b0:340:ad90:c946]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3806:b0:340:5c27:a096 with SMTP id 98e67ed59e1d1-343f9e92a24mr1035029a91.6.1763075662950; Thu, 13 Nov 2025 15:14:22 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 13 Nov 2025 15:14:15 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251113231420.1695919-1-seanjc@google.com> Subject: [PATCH 0/5] KVM: SVM: Fix and clean up OSVW handling From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix a long-standing bug where KVM could clobber its OS-visible workarounds handling (not that anyone would notice), and then clean up the code to make it easier understand and maintain (I didn't even know what "osvw" stood for until I ran into this code when trying to moving actual SVM pieces of svm_enable_virtualization_cpu() out of KVM (for TDX purposes)). Tested by running in a VM and generating unique per-vCPU MSR values in the host (see below), and verifying KVM ended up with the right values. diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c9c2aa6f4705..d8b8eff733d8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4631,12 +4631,20 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struc= t msr_data *msr_info) case MSR_AMD64_OSVW_ID_LENGTH: if (!guest_cpu_cap_has(vcpu, X86_FEATURE_OSVW)) return 1; + + if (vcpu->vcpu_idx =3D=3D 64) + return 1; + msr_info->data =3D vcpu->arch.osvw.length; + if (vcpu->vcpu_idx < 64) + msr_info->data =3D max(vcpu->vcpu_idx, 8); break; case MSR_AMD64_OSVW_STATUS: if (!guest_cpu_cap_has(vcpu, X86_FEATURE_OSVW)) return 1; msr_info->data =3D vcpu->arch.osvw.status; + if (vcpu->vcpu_idx < 64) + msr_info->data |=3D BIT_ULL(vcpu->vcpu_idx); break; case MSR_PLATFORM_INFO: if (!msr_info->host_initiated && Sean Christopherson (5): KVM: SVM: Serialize updates to global OS-Visible Workarounds variables KVM: SVM: Skip OSVW MSR reads if KVM is treating all errata as present KVM: SVM: Extract OS-visible workarounds setup to helper function KVM: SVM: Skip OSVW variable updates if current CPU's errata are a subset KVM: SVM: Skip OSVW MSR reads if current CPU doesn't support the feature arch/x86/kvm/svm/svm.c | 72 ++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 28 deletions(-) base-commit: 16ec4fb4ac95d878b879192d280db2baeec43272 --=20 2.52.0.rc1.455.g30608eb744-goog