Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Janosch Frank <frankja@linux.ibm.com>
To: "Aaron M. Brown" <aaronmbr@linux.ibm.com>, kvm@vger.kernel.org
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	linux-s390@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Nitya Khamar <nkhamar@linux.ibm.com>
Subject: Re: [PATCH 3/6] KVM: s390: selftests: Add wait state and VM lifecycle tests
Date: Fri, 13 Nov 2026 11:37:08 +0100	[thread overview]
Message-ID: <e7ab806c-97ab-4e41-8649-bff248fd7c86@linux.ibm.com> (raw)
In-Reply-To: <20261110111619.61760-4-aaronmbr@linux.ibm.com>

On 11/10/26 12:16 PM, Aaron M. Brown wrote:
> Add two tests:
> 
> - Wait state: the guest loads a PSW with the wait bit (bit 14) set and
>    the I/O, external and machine-check masks (bits 6, 7, 13) clear.
>    Check for ICPT_WAIT and the wait bit in the PSW.
> - VM create and destroy: before the first KVM_RUN, check that
>    exit_reason is KVM_EXIT_UNKNOWN and immediate_exit is clear.
> 
> Co-developed-by: Nitya Khamar <nkhamar@linux.ibm.com>
> Signed-off-by: Nitya Khamar <nkhamar@linux.ibm.com>
> Signed-off-by: Aaron M. Brown <aaronmbr@linux.ibm.com>
> ---
>   tools/testing/selftests/kvm/s390/kvm_exit.c | 78 +++++++++++++++++++++
>   1 file changed, 78 insertions(+)
> 
> diff --git a/tools/testing/selftests/kvm/s390/kvm_exit.c b/tools/testing/selftests/kvm/s390/kvm_exit.c
> index 4a6f01ff14ca..2f73eae1954a 100644
> --- a/tools/testing/selftests/kvm/s390/kvm_exit.c
> +++ b/tools/testing/selftests/kvm/s390/kvm_exit.c
> @@ -27,6 +27,7 @@
>   #define IPA_DIAG 0x83
>   #define PSW_MASK_64BIT_DAT_OFF  0x0000000180000000ULL
>   #define PGM_CODE_SEGMENT_TRANSLATION 0x10
> +#define PSW_WAIT_BIT_MASK (1ULL << (63 - 14))

ptrace.h should have this covered, it even seems to typedef the psw.

>   #define PGM_CODE_GPA_ADDRESS 0x8e
>   #define PGM_CODE_MASK        0x7f
>   #define PGM_NEW_PSW_GPA 0x1d0
> @@ -308,6 +309,75 @@ static bool test_translation_exceptions(void)
>   	return true;
>   }
>   
> +static uint64_t psw_save[2] __aligned(16);

LPSWE needs a DW alignment, not a QW one, so 8 should be enough.

> +
> +static void guestcode_wait_state(void)
> +{
> +	register uint64_t *psw_ptr asm("r4") = psw_save;
> +
> +	asm volatile(
> +		"lghi  %%r3, 0x3333\n"
> +		"lgrl  %%r7, 1f\n"
> +		"stg   %%r7, 0(%%r4)\n"
> +		"xgr   %%r5, %%r5\n"
> +		"stg   %%r5, 8(%%r4)\n"
> +		"lpswe 0(%%r4)\n"

That's convoluted.
Have a look at the kernel's __load_psw_mask() and friends.

> +		".align 8\n"
> +		"1: .quad 0x0002000180000000\n"
> +		:
> +		: "d"(psw_ptr)
> +		: "r3", "r5", "r7", "memory"
> +	);
> +}
> +
> +static bool test_wait_state(void)
> +{
> +	struct kvm_parameters param = {};
> +	struct kvm_regs regs;
> +
> +	ksft_print_msg("Testing Wait State Exit\n");
> +	param.guest_code = guestcode_wait_state;
> +	param = create_vm_kvm_exit(param);
> +	vcpu_run(param.vcpu);
> +	param.run = param.vcpu->run;
> +	TEST_ASSERT(param.run->exit_reason == KVM_EXIT_S390_SIEIC,
> +		    "Expected KVM_EXIT_S390_SIEIC, got %u\n",
> +		    param.run->exit_reason);
> +	TEST_ASSERT(param.run->s390_sieic.icptcode == ICPT_WAIT,
> +		    "Failed with Unexpected Exit Reason of %u and icptcode of 0x%x\n",
> +		    param.run->exit_reason, param.run->s390_sieic.icptcode);
> +	vcpu_regs_get(param.vcpu, &regs);
> +	TEST_ASSERT(regs.gprs[3] == 0x3333,
> +		    "Expected 0x3333 but got 0x%llx\n", regs.gprs[3]);
> +	/* Check PSW wait bit (bit 14 from MSB = bit 63-14 from LSB) */
> +	TEST_ASSERT((param.run->psw_mask & PSW_WAIT_BIT_MASK) != 0,
> +		    "PSW wait bit not set, PSW Mask = 0x%llx\n",
> +		    param.run->psw_mask);
> +	cleanup_kvm(&param);
> +	return true;
> +}
> +
> +static void guestcode_nop(void)
> +{
> +	GUEST_DONE();
> +}
> +
> +static bool test_vm_create_and_destroy(void)
> +{
> +	struct kvm_parameters parameters = {.guest_code = guestcode_nop};
> +
> +	ksft_print_msg("Testing VM Closure without Running vCPU\n");
> +	parameters = create_vm_kvm_exit(parameters);
> +	TEST_ASSERT(parameters.vcpu->run->exit_reason == KVM_EXIT_UNKNOWN,
> +		    "Unexpected Exit Reason Before vCPU Execution: %u\n",
> +		    parameters.vcpu->run->exit_reason);
> +	TEST_ASSERT(parameters.vcpu->run->immediate_exit == 0,
> +		    "Immediate Exit Unexpected Behavior: %d\n",
> +		    parameters.vcpu->run->immediate_exit);

Does the setup code even sync kvm_run?
Are we testing zero initialization of memory?

> +	cleanup_kvm(&parameters);
> +	return true;
> +}
> +
>   static void test(void)
>   {
>   	int i;
> @@ -336,6 +406,14 @@ static void test(void)
>   			.name = "Testing Translation Exceptions",
>   			.test = test_translation_exceptions,
>   		},
> +		{
> +			.name = "Testing Wait State",
> +			.test = test_wait_state,
> +		},
> +		{
> +			.name = "Testing VM Create and Destroy",
> +			.test = test_vm_create_and_destroy,
> +		},
>   	};
>   
>   	ksft_print_header();


  reply	other threads:[~2026-11-13 10:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 11:16 [PATCH 0/6] KVM: s390: selftests: Add selftests for KVM exits on s390x Aaron M. Brown
2026-11-10 11:16 ` [PATCH 1/6] KVM: s390: selftests: Add kvm_exit test for instruction intercepts Aaron M. Brown
2026-11-12 13:45   ` Janosch Frank
2026-11-13  7:35     ` Aaron Brown
2026-11-10 11:16 ` [PATCH 2/6] KVM: s390: selftests: Add SIGP and program exception tests Aaron M. Brown
2026-11-13 10:21   ` Janosch Frank
2026-11-10 11:16 ` [PATCH 3/6] KVM: s390: selftests: Add wait state and VM lifecycle tests Aaron M. Brown
2026-11-13 10:37   ` Janosch Frank [this message]
2026-11-10 11:16 ` [PATCH 4/6] KVM: s390: selftests: Add ucontrol helpers and instruction tests Aaron M. Brown
2026-11-13 10:47   ` Janosch Frank
2026-11-10 11:16 ` [PATCH 5/6] KVM: s390: selftests: Add ucontrol storage key and immediate exit tests Aaron M. Brown
2026-11-10 11:16 ` [PATCH 6/6] KVM: s390: selftests: Add clock comparator interrupt test Aaron M. Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7ab806c-97ab-4e41-8649-bff248fd7c86@linux.ibm.com \
    --to=frankja@linux.ibm.com \
    --cc=aaronmbr@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nkhamar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox