Re: [PATCH v4] KVM: selftests: Add a test for gPAT handling in L2

From: Yosry Ahmed

Date: Thu May 28 2026 - 20:47:46 EST


> +int main(int argc, char *argv[])
> +{
> + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM));
> + TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE));
> + TEST_REQUIRE(kvm_check_cap(KVM_CAP_DISABLE_QUIRKS2) &
> + KVM_X86_QUIRK_NESTED_SVM_SHARED_PAT);
> +
> + if (!kvm_cpu_has(X86_FEATURE_NPT))
> + goto skip_npt;
> +
> + gpat_test("Invalid gPAT", l1_guest_code_invalid_gpat, npt_enabled = true);
> + gpat_test("Nested NPT enabled", l1_guest_code, npt_enabled = true);
> +skip_npt:
> + gpat_test("Nested NPT disabled", l1_guest_code, npt_enabled = false);
> + return 0;
> +}

The goto is really unnecessary here:

if (kvm_cpu_has(X86_FEATURE_NPT)) {
gpat_test("Invalid gPAT", l1_guest_code_invalid_gpat,
npt_enabled = true);
gpat_test("Nested NPT enabled", l1_guest_code, npt_enabled = true);
}
gpat_test("Nested NPT disabled", l1_guest_code, npt_enabled = false);