kvm powerpc/book3s-apiv2: Add suite initialization to skip GSB tests without APIv2 support
Subsystems (3)
PATCH 1/1 kvm powerpc/book3s-apiv2: Add suite initialization to skip GSB tests without APIv2 support
The guest state buffer (GSB) test suite currently fails on systems that do not support the PAPR APIv2 nested virtualization. This happens because the tests attempt to use APIv2-specific functionality without first checking if the host supports it. This was recently reported [1] when test-guest-state-buffer kunit tests were being run on Qemu without enabling Qemu capability 'cap-nested-papr' which enabled APIv2 nested virtualization for PPC64 Pseries Qemu machine.
Add a suite_init callback that checks for APIv2 support by calling plpar_guest_get_capabilities(). If the host does not support APIv2 (indicated by H_SUCCESS not being returned), mark all test cases in the suite as KUNIT_SKIPPED. This prevents test failures on systems without APIv2 support while still allowing the tests to run on capable systems.
[1] https://lore.kernel.org/all/20260603064225.GC18149@sol/
--- arch/powerpc/kvm/test-guest-state-buffer.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
arch/powerpc/kvm/test-guest-state-buffer.c +19 -0
@@ -521,6 +521,24 @@ static void test_gs_hostwide_counters(struct kunit *test)kvmppc_gsb_free (gsb); } +static int init_gs_test_suite (struct kunit_suite *suite) +{ +long rc; +unsigned long host_capabilities; +struct kunit_case *test_case; + +/* Enable test suite only if APIv2 is supported */ + rc =plpar_guest_get_capabilities (0 , &host_capabilities); + +if (rc !=H_SUCCESS ) { +/* Skip all testcases if no APIv2 support */ +kunit_suite_for_each_test_case (suite, test_case) +WRITE_ONCE (test_case->status,KUNIT_SKIPPED ); + } + +return 0 ; +} +static struct kunit_case guest_state_buffer_testcases[] = {KUNIT_CASE (test_creating_buffer),KUNIT_CASE (test_adding_element),
@@ -535,6 +553,7 @@ static struct kunit_case guest_state_buffer_testcases[] = {static struct kunit_suite guest_state_buffer_test_suite = { .name ="guest_state_buffer_test" , .test_cases = guest_state_buffer_testcases, + .suite_init = init_gs_test_suite, };kunit_test_suites (&guest_state_buffer_test_suite);
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Unconditional hypercall execution in the test suite initialization will cause a kernel panic on…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Unconditional hypercall execution in the test suite initialization will cause a kernel panic on bare-metal (PowerNV) systems.
- [Medium] The capability check yields a false positive when compiled without CONFIG_PPC_PSERIES.
- [Medium] Skipping the entire test suite when APIv2 is unavailable disables purely memory-manipulation tests that do not depend on the hypervisor.
- [Low] Directly modifying the private status field of struct kunit_case violates the KUnit API.
--
commit 91f29321c74a3de9acc6e6b6af3b00cdee30f4f2
Author: Vaibhav Jain <[email protected]>
kvm powerpc/book3s-apiv2: Add suite initialization to skip GSB tests without APIv2 support
This commit adds a suite initialization callback to check for PAPR APIv2 nested virtualization support. If APIv2 is not supported, it marks all test cases in the suite as KUNIT_SKIPPED to prevent test failures.
Quoted 4 lines
arch/powerpc/kvm/test-guest-state-buffer.c +0
-0
[ ... ]
arch/powerpc/kvm/test-guest-state-buffer.c static void test_gs_hostwide_counters(struct kunit *test) · line 531
Quoted 12 lines
arch/powerpc/kvm/test-guest-state-buffer.c +8
-0@@ -521,6 +521,24 @@ static void test_gs_hostwide_counters(struct kunit *test)kvmppc_gsb_free (gsb); } +static int init_gs_test_suite (struct kunit_suite *suite) +{ +long rc; +unsigned long host_capabilities; +struct kunit_case *test_case; + +/* Enable test suite only if APIv2 is supported */ + rc =plpar_guest_get_capabilities (0 , &host_capabilities);
[Severity: High]
Could this unconditional hypercall execution cause a kernel oops on bare-metal (PowerNV) environments?
plpar_guest_get_capabilities() internally invokes plpar_hcall(), which issues an "sc 1" instruction. On bare-metal systems without an underlying hypervisor, executing this will trigger an Emulation Assistance exception.
Should this code verify that it is running as a guest by checking kvmhv_on_pseries() before issuing the hypercall, similar to how test_gs_hostwide_counters() is protected?
[Severity: Medium]
When the kernel is compiled without CONFIG_PPC_PSERIES, will this check yield a false positive?
In arch/powerpc/include/asm/plpar_wrappers.h, plpar_guest_get_capabilities() is defined as a stub that returns 0 (H_SUCCESS):
static inline long plpar_guest_get_capabilities(unsigned long flags,
unsigned long *capabilities)
{
return 0;
}Because it returns success, init_gs_test_suite() could incorrectly assume that PAPR APIv2 is supported and fail to skip the test suite on these builds.
arch/powerpc/kvm/test-guest-state-buffer.c static void test_gs_hostwide_counters(struct kunit *test) · line 535
Quoted 4 lines
arch/powerpc/kvm/test-guest-state-buffer.c +4
-0+ +if (rc !=H_SUCCESS ) { +/* Skip all testcases if no APIv2 support */ +kunit_suite_for_each_test_case (suite, test_case)
[Severity: Medium]
Does skipping the entire test suite unnecessarily bypass memory-based tests that do not depend on the hypervisor?
Out of the 7 tests in the suite, only test_gs_hostwide_counters() executes hypercalls. Tests such as test_creating_buffer(), test_adding_element(), and test_gs_parsing() are strictly memory-based unit tests.
Could this lead to a loss of test coverage for valid test cases in non-APIv2 environments?
arch/powerpc/kvm/test-guest-state-buffer.c static void test_gs_hostwide_counters(struct kunit *test) · line 536
Quoted 1 line
arch/powerpc/kvm/test-guest-state-buffer.c +1
-0+WRITE_ONCE (test_case->status,KUNIT_SKIPPED );
[Severity: Low]
Is it appropriate to directly modify the private status field of the struct kunit_case here?
In include/kunit/test.h, the status field is explicitly marked for internal use only:
struct kunit_case {
[ ... ]
/* private: internal use only. */ enum kunit_status status;
[ ... ]
};
Direct manipulation of framework internals from within an architecture's test module appears to violate the KUnit API.
Quoted 4 lines
arch/powerpc/kvm/test-guest-state-buffer.c +4
-0+ } + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Hi Vaibhav,
Thanks for the patch. Please find my comments inline.
Quoted 30 lines · Vaibhav Jain
The guest state buffer (GSB) test suite currently fails on systems that do not support the PAPR APIv2 nested virtualization. This happens because the tests attempt to use APIv2-specific functionality without first checking if the host supports it. This was recently reported [1] when test-guest-state-buffer kunit tests were being run on Qemu without enabling Qemu capability 'cap-nested-papr' which enabled APIv2 nested virtualization for PPC64 Pseries Qemu machine.
Add a
suite_initcallback that checks for APIv2 support by callingplpar_guest_get_capabilities(). If the host does not support APIv2 (indicated byH_SUCCESSnot being returned), mark all test cases in the suite asKUNIT_SKIPPED. This prevents test failures on systems without APIv2 support while still allowing the tests to run on capable systems.[1] https://lore.kernel.org/all/20260603064225.GC18149@sol/
Reported-by Eric Biggers <[email protected]>Signed-off-by Vaibhav Jain <[email protected]>Assisted-by Bob:Claude-3.7-Sonnet Bob-Shell--- arch/powerpc/kvm/test-guest-state-buffer.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)arch/powerpc/kvm/test-guest-state-buffer.c +0
-0@@ -521,6 +521,24 @@ static void test_gs_hostwide_counters(struct kunit *test)kvmppc_gsb_free (gsb);
arch/powerpc/kvm/test-guest-state-buffer.c static void test_gs_hostwide_counters(struct kunit *test) · line 531
Quoted 10 lines
arch/powerpc/kvm/test-guest-state-buffer.c +8
-0} +static int init_gs_test_suite (struct kunit_suite *suite) +{ +long rc; +unsigned long host_capabilities; +struct kunit_case *test_case; + +/* Enable test suite only if APIv2 is supported */ + rc =plpar_guest_get_capabilities (0 , &host_capabilities);
I believe we don't really need an hcall overhead to check the availability of APIv2. We could simply check:
arch/powerpc/kvm/test-guest-state-buffer.c +12 -0
@@ -521,6 +521,18 @@ static void test_gs_hostwide_counters(struct kunit *test)kvmppc_gsb_free (gsb); } +static int init_gs_test_suite (struct kunit_suite *suite) +{ +struct kunit_case *test_case; + +if (!kvmhv_is_nestedv2 ()) { +kunit_suite_for_each_test_case (suite, test_case) +WRITE_ONCE (test_case->status,KUNIT_SKIPPED ); + } + +return 0 ; +} +
Also, I understand that these tests exercise gsb related tests specific to APIv2 but I see that only 'test_gs_hostwide_counters' relies on an APIv2 specific 'H_GUEST_GET_STATE' hcall but rest of the tests just operate on in-memory gsb. So, do we really want to skip all the tests when APIv2 is not available?
If not, we could simply skip this one test as:
arch/powerpc/kvm/test-guest-state-buffer.c +4 -1
@@ -462,7 +462,10 @@ static void test_gs_hostwide_counters(struct kunit *test)int rc;if (!kvmhv_on_pseries ()) -kunit_skip (test,"This test need a kmv-hv guest" ); +kunit_skip (test,"This test need a kvm-hv guest" ); + +if (!kvmhv_is_nestedv2 ()) +kunit_skip (test,"This test needs an spapr nested APIv2 support" ); gsm =kvmppc_gsm_new (&gs_msg_test_hostwide_ops, &test_data,GSM_SEND ,GFP_KERNEL );
Please let me know your views.
Thanks,
Amit
Quoted 24 lines
arch/powerpc/kvm/test-guest-state-buffer.c +11
-0+ +if (rc !=H_SUCCESS ) { +/* Skip all testcases if no APIv2 support */ +kunit_suite_for_each_test_case (suite, test_case) +WRITE_ONCE (test_case->status,KUNIT_SKIPPED ); + } + +return 0 ; +} +static struct kunit_case guest_state_buffer_testcases[] = {KUNIT_CASE (test_creating_buffer),KUNIT_CASE (test_adding_element),@@ -535,6 +553,7 @@ static struct kunit_case guest_state_buffer_testcases[] = {static struct kunit_suite guest_state_buffer_test_suite = { .name ="guest_state_buffer_test" , .test_cases = guest_state_buffer_testcases, + .suite_init = init_gs_test_suite, };kunit_test_suites (&guest_state_buffer_test_suite);Signature · 1 line
2.54.0
Hi Amit,
Thanks for looking into this patch. My responses to your review comments inline below:
Quoted 54 lines · Amit Machhiwal
Hi Vaibhav,
Thanks for the patch. Please find my comments inline.
Quoted 30 lines · Vaibhav Jain
The guest state buffer (GSB) test suite currently fails on systems that do not support the PAPR APIv2 nested virtualization. This happens because the tests attempt to use APIv2-specific functionality without first checking if the host supports it. This was recently reported [1] when test-guest-state-buffer kunit tests were being run on Qemu without enabling Qemu capability 'cap-nested-papr' which enabled APIv2 nested virtualization for PPC64 Pseries Qemu machine.
Add a
suite_initcallback that checks for APIv2 support by callingplpar_guest_get_capabilities(). If the host does not support APIv2 (indicated byH_SUCCESSnot being returned), mark all test cases in the suite asKUNIT_SKIPPED. This prevents test failures on systems without APIv2 support while still allowing the tests to run on capable systems.[1] https://lore.kernel.org/all/20260603064225.GC18149@sol/
Reported-by Eric Biggers <[email protected]>Signed-off-by Vaibhav Jain <[email protected]>Assisted-by Bob:Claude-3.7-Sonnet Bob-Shell--- arch/powerpc/kvm/test-guest-state-buffer.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)arch/powerpc/kvm/test-guest-state-buffer.c +0
-0@@ -521,6 +521,24 @@ static void test_gs_hostwide_counters(struct kunit *test)kvmppc_gsb_free (gsb);arch/powerpc/kvm/test-guest-state-buffer.c static void test_gs_hostwide_counters(struct kunit *test) · line 531
Quoted 10 lines
arch/powerpc/kvm/test-guest-state-buffer.c +8
-0} +static int init_gs_test_suite (struct kunit_suite *suite) +{ +long rc; +unsigned long host_capabilities; +struct kunit_case *test_case; + +/* Enable test suite only if APIv2 is supported */ + rc =plpar_guest_get_capabilities (0 , &host_capabilities);I believe we don't really need an hcall overhead to check the availability of APIv2. We could simply check:
arch/powerpc/kvm/test-guest-state-buffer.c +0
-0
arch/powerpc/kvm/test-guest-state-buffer.c static void test_gs_hostwide_counters(struct kunit *test) · line 528
Quoted 8 lines
arch/powerpc/kvm/test-guest-state-buffer.c +5
-0@@ -521,6 +521,18 @@ static void test_gs_hostwide_counters(struct kunit *test)kvmppc_gsb_free (gsb); } +static int init_gs_test_suite (struct kunit_suite *suite) +{ +struct kunit_case *test_case; + +if (!kvmhv_is_nestedv2 ()) {
kvmhv_is_nestedv2() depends on a static-key which is only set in kvmhv_nested_init(). This kunit testcase however can be run before kvmhv_nested_init() is called thereby rendering this check ineffective.
Quoted 8 lines
arch/powerpc/kvm/test-guest-state-buffer.c +7
-0+kunit_suite_for_each_test_case (suite, test_case) +WRITE_ONCE (test_case->status,KUNIT_SKIPPED ); + } + +return 0 ; +} +
Quoted 5 lines
Also, I understand that these tests exercise gsb related tests specific to APIv2 but I see that only '
test_gs_hostwide_counters' relies on an APIv2 specific 'H_GUEST_GET_STATE' hcall but rest of the tests just operate on in-memory gsb. So, do we really want to skip all the tests when APIv2 is not available?
Fair point. However the GSB related code that these test-cases are exercising will never be executed in a non nested-papr APIv2 environment. To properly validate the GSB management it should be exercised with a hypervisor having support for nested-papr APIv2. Hence it makes sense to only run these test cases with the relevant support is available.
Quoted 8 lines
If not, we could simply skip this one test as:
arch/powerpc/kvm/test-guest-state-buffer.c +0
-0
arch/powerpc/kvm/test-guest-state-buffer.c static void test_gs_hostwide_counters(struct kunit *test) · line 468
Quoted 8 lines
arch/powerpc/kvm/test-guest-state-buffer.c +4
-1@@ -462,7 +462,10 @@ static void test_gs_hostwide_counters(struct kunit *test)int rc;if (!kvmhv_on_pseries ()) -kunit_skip (test,"This test need a kmv-hv guest" ); +kunit_skip (test,"This test need a kvm-hv guest" ); + +if (!kvmhv_is_nestedv2 ()) +kunit_skip (test,"This test needs an spapr nested APIv2 support" );
As mentioned previously test for 'kvmhv_is_nestedv2()' may not be correct when this kunit test is being executed.
Also I have proposed a minor change to kunit at [1] to address possibility of being able to skip a kunit-suite in its entirety. Will rework this patch if the proposed kunit changes are accepted.
[1] https://lore.kernel.org/all/[email protected]/
<snip>
Signature · 2 lines
Cheers ~ Vaibhav