From nobody Thu Oct 2 19:27:59 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 3CB7F2E717B for ; Fri, 12 Sep 2025 23:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757719478; cv=none; b=jXOlH6/Q/3PUwJ8g4EsBDy9oa6m+midFQIffclPBLXiwlvmrtxVS/wcuWzXIYWvbiJKC1Ew4szST7wvffGeZqvxfqN/bKz1cfRpilKh49ioLN2YwnraunR+S0EZqUWhVNzB0CJDeN3dnZbUVvZ41CWtsegBgHAj5EmymroR6OTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757719478; c=relaxed/simple; bh=40dl71ECyFWFXfkSw+70ZDfPeD3+mlVMScAldWN2Rms=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SJerejL9mBTWdOiUfBcueiisnv0gTdQGCXURpy27A+qg+W14kYaqVNz1ABex5+fzJNweFPv5zeIIquY3VvVinMZUTAROMbOdG7XRjqZ8e7LxSkduLtLgg1aMgNe2KOGhk2DQtjosxyDqbaN6loM/9oCMusYnoVn6VhT0dxu4b+M= 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=3mhunu8T; arc=none smtp.client-ip=209.85.214.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="3mhunu8T" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-24456ebed7bso32282215ad.0 for ; Fri, 12 Sep 2025 16:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757719476; x=1758324276; 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=4jmux4W5u0jC39lKwSsyN7sb7Ko3HpaGxf4gpZSmOsw=; b=3mhunu8T2K3siQmPTFmrVSrev6pslT/F3yvUHmeWNTVnF+I/bYXxpSHqsGYoMEhbXW W0Iv09YZJFzlK/jKRMSVgsMBvwQvtSlP4qCzacMBQLfmuuiJCL/wCx+rjNX8XmK/roBI 6oz75xQDRexEMbfowNYhr3bEt4zDtLzsEDLvzTePpiQ0EpT8nQbHZlsk+kzpegbKqH5c dpSr0gJEpsCq+zBUhMCZwJ+8dMFj59hu5FFnx253bfTaCWLEz1DD7PZBweVSdMdaEaxk HLy8QRg2W+iGyQauZM3iFVCrnErKPyleTm37aFVasuG2G2MOBNRSsVP62HqFxcp1dOKW lNcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757719476; x=1758324276; 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=4jmux4W5u0jC39lKwSsyN7sb7Ko3HpaGxf4gpZSmOsw=; b=o5vDNH2OMdzaJ1fElkEm2VC3Aw8C0CtBL74Yrq/rgDjgIFiqKXzhTQ16x82ZdB7857 kUK97jzPe2AaUw0Mx2xfE4JZTJIa1Y3ANKV7JtFQiMnGf7a0ShtfTQvrbefwPaSiyecc UWt5B/eUw9V9nlsOwzKWb9oQmMpz1+jx2B4sAgOXg35GBG7W0cnExjHMdRYjudvO9fPO 6o7r4PgcmX1mH7UPP7oCY0INqZETjgUp1etDVyGGeaL+NXccv3M+IAuBPjvvMZ8Ra9cg TcCLo3Wab/8HB4YosrTzh5VZkLhdc1tyE0IGrUrb+/yLoeDKPCPfwd9T362CZX1zXXUe Iefg== X-Forwarded-Encrypted: i=1; AJvYcCWgCamfagfKoTijjPkhOd5WA+rFwpMl1BeqdorS/jvcwb/9gTd6pvbMRvb2HaNRndh6olqR4tpwq3uBqCY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0SVfobtYWylWH6RkMdxS2Wkz5jKD9mVqpOROUUQ2lu0dYBy1g /0QcHXmUhsqq4tvpr4WpFHT5fbIr4u8FlqaIIXD5pKULLktSIyyOQvhyaKYT+Yl2AJPWmwpR577 Q6F/DOQ== X-Google-Smtp-Source: AGHT+IEncGKDA7ljh7ysYahjwxo7KpSwFokIz76a6WA8PrjcR8wVa/sRAtW8DiyFrY9OVvNiumSd5nTV54I= X-Received: from pjbsk9.prod.google.com ([2002:a17:90b:2dc9:b0:32d:bbf6:4b50]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e750:b0:24d:34:b9e7 with SMTP id d9443c01a7336-25bae8f39c5mr90704225ad.29.1757719476420; Fri, 12 Sep 2025 16:24:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 Sep 2025 16:23:18 -0700 In-Reply-To: <20250912232319.429659-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250912232319.429659-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250912232319.429659-41-seanjc@google.com> Subject: [PATCH v15 40/41] KVM: selftests: Verify MSRs are (not) in save/restore list when (un)supported From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Lendacky , Mathias Krause , John Allen , Rick Edgecombe , Chao Gao , Maxim Levitsky , Xiaoyao Li , Zhang Yi Z Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a check in the MSRs test to verify that KVM's reported support for MSRs with feature bits is consistent between KVM's MSR save/restore lists and KVM's supported CPUID. To deal with Intel's wonderful decision to bundle IBT and SHSTK under CET, track the "second" feature to avoid false failures when running on a CPU with only one of IBT or SHSTK. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86/msrs_test.c | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86/msrs_test.c b/tools/testing/se= lftests/kvm/x86/msrs_test.c index 6a956cfe0c65..442409e40da0 100644 --- a/tools/testing/selftests/kvm/x86/msrs_test.c +++ b/tools/testing/selftests/kvm/x86/msrs_test.c @@ -392,12 +392,32 @@ static void test_msrs(void) } =20 for (idx =3D 0; idx < ARRAY_SIZE(__msrs); idx++) { - if (msrs[idx].is_kvm_defined) { + struct kvm_msr *msr =3D &msrs[idx]; + + if (msr->is_kvm_defined) { for (i =3D 0; i < NR_VCPUS; i++) host_test_kvm_reg(vcpus[i]); continue; } =20 + /* + * Verify KVM_GET_SUPPORTED_CPUID and KVM_GET_MSR_INDEX_LIST + * are consistent with respect to MSRs whose existence is + * enumerated via CPUID. Note, using LM as a dummy feature + * is a-ok here as well, as all MSRs that abuse LM should be + * unconditionally reported in the save/restore list (and + * selftests are 64-bit only). Note #2, skip the check for + * FS/GS.base MSRs, as they aren't reported in the save/restore + * list since their state is managed via SREGS. + */ + TEST_ASSERT(msr->index =3D=3D MSR_FS_BASE || msr->index =3D=3D MSR_GS_BA= SE || + kvm_msr_is_in_save_restore_list(msr->index) =3D=3D + (kvm_cpu_has(msr->feature) || kvm_cpu_has(msr->feature2)), + "%s %s save/restore list, but %s according to CPUID", msr->name, + kvm_msr_is_in_save_restore_list(msr->index) ? "is" : "isn't", + (kvm_cpu_has(msr->feature) || kvm_cpu_has(msr->feature2)) ? + "supported" : "unsupported"); + sync_global_to_guest(vm, idx); =20 vcpus_run(vcpus, NR_VCPUS); --=20 2.51.0.384.g4c02a37b29-goog