From: Janosch Frank <frankja@linux.ibm.com>
To: Thomas Huth <thuth@redhat.com>, kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com,
borntraeger@linux.ibm.com
Subject: Re: [PATCH] KVM: s390: Add capability that forwards operation exceptions
Date: Fri, 31 Oct 2025 09:45:27 +0100 [thread overview]
Message-ID: <5255f540-e723-47e5-8035-387bea9f6fa3@linux.ibm.com> (raw)
In-Reply-To: <8c25cc75-021d-4199-96de-83e06e16a514@redhat.com>
On 10/30/25 08:10, Thomas Huth wrote:
> On 29/10/2025 14.04, Janosch Frank wrote:
>> Setting KVM_CAP_S390_USER_OPEREXEC will forward all operation
>> exceptions to user space. This also includes the 0x0000 instructions
>> managed by KVM_CAP_S390_USER_INSTR0. It's helpful if user space wants
>> to emulate instructions which do not (yet) have an opcode.
>>
>> While we're at it refine the documentation for
>> KVM_CAP_S390_USER_INSTR0.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ...
>> +7.45 KVM_CAP_S390_USER_OPEREXEC
>> +----------------------------
>> +
>> +:Architectures: s390
>> +:Parameters: none
>> +
>> +When this capability is enabled KVM forwards all operation exceptions
>> +that it doesn't handle itself to user space. This also includes the
>> +0x0000 instructions managed by KVM_CAP_S390_USER_INSTR0. This is
>> +helpful if user space wants to emulate instructions which do not (yet)
>> +have an opcode.
>
> "which do not (yet) have an opcode" sounds a little bit weird. Maybe rather:
> "which are not (yet) implemented in the current CPU" or so?
How about:
...which are not (yet) implemented in hardware.
>
>> +This capability can be enabled dynamically even if VCPUs were already
>> +created and are running.
>> +
>> 8. Other capabilities.
>> ======================
> ...
>> diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
>> index c7908950c1f4..420ae62977e2 100644
>> --- a/arch/s390/kvm/intercept.c
>> +++ b/arch/s390/kvm/intercept.c
>> @@ -471,6 +471,9 @@ static int handle_operexc(struct kvm_vcpu *vcpu)
>> if (vcpu->arch.sie_block->ipa == 0xb256)
>> return handle_sthyi(vcpu);
>>
>> + if (vcpu->kvm->arch.user_operexec)
>> + return -EOPNOTSUPP;
>> +
>> if (vcpu->arch.sie_block->ipa == 0 && vcpu->kvm->arch.user_instr0)
>> return -EOPNOTSUPP;
>> rc = read_guest_lc(vcpu, __LC_PGM_NEW_PSW, &newpsw, sizeof(psw_t));
>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>> index 70ebc54b1bb1..56d4730b7c41 100644
>> --- a/arch/s390/kvm/kvm-s390.c
>> +++ b/arch/s390/kvm/kvm-s390.c
>> @@ -606,6 +606,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
>> case KVM_CAP_SET_GUEST_DEBUG:
>> case KVM_CAP_S390_DIAG318:
>> case KVM_CAP_IRQFD_RESAMPLE:
>> + case KVM_CAP_S390_USER_OPEREXEC:
>> r = 1;
>> break;
>> case KVM_CAP_SET_GUEST_DEBUG2:
>> @@ -921,6 +922,12 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap)
>> VM_EVENT(kvm, 3, "ENABLE: CAP_S390_CPU_TOPOLOGY %s",
>> r ? "(not available)" : "(success)");
>> break;
>> + case KVM_CAP_S390_USER_OPEREXEC:
>> + VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_OPEREXEC");
>> + kvm->arch.user_operexec = 1;
>> + icpt_operexc_on_all_vcpus(kvm);
>
> Maybe check cap->flags here and return with an error if any flag is set? ...
> otherwise, if we ever add flags here, userspace cannot check whether the
> kernel accepted a flag or not.
Check the top of the function :)
I can surely add a second check to be doubly sure.
int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap)
{
int r;
if (cap->flags)
return -EINVAL;
>> +/*
>> + * Run all tests above.
>> + *
>> + * Enablement after VCPU has been added is automatically tested since
>> + * we enable the capability after VCPU creation.
>> + */
>> +static struct testdef {
>> + const char *name;
>> + void (*test)(void);
>> +} testlist[] = {
>> + { "instr0", test_user_instr0 },
>> + { "operexec", test_user_operexec },
>> + { "operexec_combined", test_user_operexec_combined},
>> +};
>> +
>> +int main(int argc, char *argv[])
>> +{
>> + int idx;
>> +
>> + TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_USER_INSTR0));
>> +
>> + ksft_print_header();
>> + ksft_set_plan(ARRAY_SIZE(testlist));
>> + for (idx = 0; idx < ARRAY_SIZE(testlist); idx++) {
>> + testlist[idx].test();
>> + ksft_test_result_pass("%s\n", testlist[idx].name);
>> + }
>> + ksft_finished();
>> +}
>
> You could likely use the KVM_ONE_VCPU_TEST() macro and test_harness_run() to
> get rid of the boilerplate code here.
Is there a general directive to use KVM_ONE_VCPU_TEST?
To be honest I prefer the look as is since it doesn't hide things behind
macros and 95% of our tests use it.
next prev parent reply other threads:[~2025-10-31 8:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 13:04 [PATCH] KVM: s390: Add capability that forwards operation exceptions Janosch Frank
2025-10-29 14:07 ` Claudio Imbrenda
2025-10-29 16:32 ` Christian Borntraeger
2025-10-30 7:10 ` Thomas Huth
2025-10-31 8:45 ` Janosch Frank [this message]
2025-10-31 9:36 ` Thomas Huth
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=5255f540-e723-47e5-8035-387bea9f6fa3@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=thuth@redhat.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