From nobody Sun May 10 22:40:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61B56C433FE for ; Thu, 21 Apr 2022 18:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391267AbiDUSH4 (ORCPT ); Thu, 21 Apr 2022 14:07:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391237AbiDUSHo (ORCPT ); Thu, 21 Apr 2022 14:07:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE431194 for ; Thu, 21 Apr 2022 11:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650564291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qIkA5gS/4TcUB4YnwbAR5RigtqM4FKrO8JhqbEAAobM=; b=f7cEpDrSiJaxqQV0v35p0ntsv6D4XtLWS6EAyjHDw68hp+fHcRjD2D1ENOCx5/Fc2b0Z/M rZrg8X46PBM/KYGhZAa1M1Q2w+UfPa4HCvoypX2b/vk0rZ48MeSuiKS7OtJAcPSqtWYXUO ypDR/PmQB/vT7LF8G1pD/zTmxvw4tsw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-599-VEwMlOExPCGGZSZZiu9E-g-1; Thu, 21 Apr 2022 14:04:44 -0400 X-MC-Unique: VEwMlOExPCGGZSZZiu9E-g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 239B5801E67; Thu, 21 Apr 2022 18:04:44 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id E287E40E80F5; Thu, 21 Apr 2022 18:04:43 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: will@kernel.org, maz@kernel.org, apatel@ventanamicro.com, atishp@rivosinc.com, seanjc@google.com, pgonda@google.com Subject: [PATCH 1/4] KVM: x86: always initialize system_event.ndata Date: Thu, 21 Apr 2022 14:04:40 -0400 Message-Id: <20220421180443.1465634-2-pbonzini@redhat.com> In-Reply-To: <20220421180443.1465634-1-pbonzini@redhat.com> References: <20220421180443.1465634-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The KVM_SYSTEM_EVENT_NDATA_VALID mechanism that was introduced contextually with KVM_SYSTEM_EVENT_SEV_TERM is not a good match for ARM and RISC-V, which want to communicate information even for existing KVM_SYSTEM_EVENT_* constants. Userspace is not ready to filter out bit 31 of type, and fails to process the KVM_EXIT_SYSTEM_EVENT exit. Therefore, tie the availability of ndata to a system capability (which will be added once all architectures are on board). Userspace written for released versions of Linux has no reason to check flags, since it was never written, so it is okay to replace it with ndata and data[0] (on 32-bit kernels) or with data[0] (on 64-bit kernels). Signed-off-by: Paolo Bonzini --- arch/x86/kvm/svm/sev.c | 3 +-- arch/x86/kvm/x86.c | 2 ++ include/uapi/linux/kvm.h | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index a93f0d01bb90..51b963ec122b 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2739,8 +2739,7 @@ static int sev_handle_vmgexit_msr_protocol(struct vcp= u_svm *svm) reason_set, reason_code); =20 vcpu->run->exit_reason =3D KVM_EXIT_SYSTEM_EVENT; - vcpu->run->system_event.type =3D KVM_SYSTEM_EVENT_SEV_TERM | - KVM_SYSTEM_EVENT_NDATA_VALID; + vcpu->run->system_event.type =3D KVM_SYSTEM_EVENT_SEV_TERM; vcpu->run->system_event.ndata =3D 1; vcpu->run->system_event.data[1] =3D control->ghcb_gpa; =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4e7f3a8da16a..517c0228881c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10056,12 +10056,14 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) if (kvm_check_request(KVM_REQ_HV_CRASH, vcpu)) { vcpu->run->exit_reason =3D KVM_EXIT_SYSTEM_EVENT; vcpu->run->system_event.type =3D KVM_SYSTEM_EVENT_CRASH; + vcpu->run->system_event.ndata =3D 0; r =3D 0; goto out; } if (kvm_check_request(KVM_REQ_HV_RESET, vcpu)) { vcpu->run->exit_reason =3D KVM_EXIT_SYSTEM_EVENT; vcpu->run->system_event.type =3D KVM_SYSTEM_EVENT_RESET; + vcpu->run->system_event.ndata =3D 0; r =3D 0; goto out; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index dd1d8167e71f..5a57f74b4903 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -445,7 +445,6 @@ struct kvm_run { #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 #define KVM_SYSTEM_EVENT_SEV_TERM 4 -#define KVM_SYSTEM_EVENT_NDATA_VALID (1u << 31) __u32 type; __u32 ndata; __u64 data[16]; --=20 2.31.1 From nobody Sun May 10 22:40:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39A96C433FE for ; Thu, 21 Apr 2022 18:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391257AbiDUSH6 (ORCPT ); Thu, 21 Apr 2022 14:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391231AbiDUSHm (ORCPT ); Thu, 21 Apr 2022 14:07:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6CAC14B1FC for ; Thu, 21 Apr 2022 11:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650564290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E6dh0F8rlY2iLG036JSLaiRrNHBRLRC4zYjjDnhEuYs=; b=I51ez0RCsy4xJzlwcAlGhpky4j+echmpunkiNCh7sCdtOLxRAyY8dM/7l84xLS4t09QNsm PJ573B5gI3DSeY1rj+R2yypqMvqK0T8Ac2nGxdFriIjlCEogClygtJZZArJKgIGSog3b5T 5twN8FqZNWLl0TouSiBF8EWxFlJZmSk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-YrqlrF3aPsmwb-9ZeiHAQA-1; Thu, 21 Apr 2022 14:04:45 -0400 X-MC-Unique: YrqlrF3aPsmwb-9ZeiHAQA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 604E43C0F09E; Thu, 21 Apr 2022 18:04:44 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B47A40E80F5; Thu, 21 Apr 2022 18:04:44 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: will@kernel.org, maz@kernel.org, apatel@ventanamicro.com, atishp@rivosinc.com, seanjc@google.com, pgonda@google.com Subject: [PATCH 2/4] KVM: ARM: replace system_event.flags with ndata and data[0] Date: Thu, 21 Apr 2022 14:04:41 -0400 Message-Id: <20220421180443.1465634-3-pbonzini@redhat.com> In-Reply-To: <20220421180443.1465634-1-pbonzini@redhat.com> References: <20220421180443.1465634-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The flags datum for KVM_EXIT_SYSTEM_EVENT exits has been removed because it was defined incorrectly; no padding was introduced between the 32-bit type and the 64-bit flags, resulting in different definitions for 32-bit and 64-bit userspace. The replacement is a pair of fields, ndata and data[], with ndata saying how many items are valid in the data array. In the case of ARM that's one, as flags can be simply moved to data[0]. Signed-off-by: Paolo Bonzini --- arch/arm64/kvm/psci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index baac2b405f23..708d80e8e60d 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -181,7 +181,8 @@ static void kvm_prepare_system_event(struct kvm_vcpu *v= cpu, u32 type, u64 flags) =20 memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); vcpu->run->system_event.type =3D type; - vcpu->run->system_event.flags =3D flags; + vcpu->run->system_event.ndata =3D 1; + vcpu->run->system_event.data[0] =3D flags; vcpu->run->exit_reason =3D KVM_EXIT_SYSTEM_EVENT; } =20 --=20 2.31.1 From nobody Sun May 10 22:40:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17043C433F5 for ; Thu, 21 Apr 2022 18:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391242AbiDUSHq (ORCPT ); Thu, 21 Apr 2022 14:07:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391218AbiDUSHj (ORCPT ); Thu, 21 Apr 2022 14:07:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 599544B1DE for ; Thu, 21 Apr 2022 11:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650564288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5uIxmDi2O7UMGYDdP32IiG4VA/mcU5iBq1ojkCkRWbM=; b=OooGlWJSnc5SJlJwwhJDLi37vxm0mO+GCs0qZ0nICzcOuFlTZnrviCF01NX3BdG95OWmf5 bN4eJ4gUcTChXApTlq+AnYV42dsjLl3jtyV3YWSgAwLv0gY4e0hXdJQIKIEnalyMIo89f6 +XTyZDMJUFpfyZ6v5OaW6V+Uh93cDnw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-DHhvKqsyPk660OSQyqxA7A-1; Thu, 21 Apr 2022 14:04:45 -0400 X-MC-Unique: DHhvKqsyPk660OSQyqxA7A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D9811E1AE43; Thu, 21 Apr 2022 18:04:44 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6802E40E80F5; Thu, 21 Apr 2022 18:04:44 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: will@kernel.org, maz@kernel.org, apatel@ventanamicro.com, atishp@rivosinc.com, seanjc@google.com, pgonda@google.com Subject: [PATCH 3/4] KVM: RISC-V: replace system_event.flags with ndata and data[0] Date: Thu, 21 Apr 2022 14:04:42 -0400 Message-Id: <20220421180443.1465634-4-pbonzini@redhat.com> In-Reply-To: <20220421180443.1465634-1-pbonzini@redhat.com> References: <20220421180443.1465634-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The flags datum for KVM_EXIT_SYSTEM_EVENT exits has been removed because it was defined incorrectly; no padding was introduced between the 32-bit type and the 64-bit flags, resulting in different definitions for 32-bit and 64-bit userspace. The replacement is a pair of fields, ndata and data[], with ndata saying how many items are valid in the data array. In the case of RISC-V that's one for the SRST SBI call (with flags simply moved to data[0]) and zero for the legacy v0.1 call. Signed-off-by: Paolo Bonzini --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 2 +- arch/riscv/kvm/vcpu_sbi.c | 5 +++-- arch/riscv/kvm/vcpu_sbi_replace.c | 4 ++-- arch/riscv/kvm/vcpu_sbi_v01.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm= /kvm_vcpu_sbi.h index 83d6d4d2b1df..c4b10c25264a 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -30,7 +30,7 @@ struct kvm_vcpu_sbi_extension { void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run= ); void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu, struct kvm_run *run, - u32 type, u64 flags); + u32 type, bool have_reason, u64 reason); const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(unsigned long e= xtid); =20 #endif /* __RISCV_KVM_VCPU_SBI_H__ */ diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index a09ecb97b890..2019ca01b44b 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -83,7 +83,7 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, st= ruct kvm_run *run) =20 void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu, struct kvm_run *run, - u32 type, u64 flags) + u32 type, bool have_reason, u64 reason) { unsigned long i; struct kvm_vcpu *tmp; @@ -94,7 +94,8 @@ void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcp= u, =20 memset(&run->system_event, 0, sizeof(run->system_event)); run->system_event.type =3D type; - run->system_event.flags =3D flags; + run->system_event.ndata =3D have_reason; + run->system_event.data[0] =3D reason; run->exit_reason =3D KVM_EXIT_SYSTEM_EVENT; } =20 diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_re= place.c index 0f217365c287..a36414a5f59e 100644 --- a/arch/riscv/kvm/vcpu_sbi_replace.c +++ b/arch/riscv/kvm/vcpu_sbi_replace.c @@ -148,14 +148,14 @@ static int kvm_sbi_ext_srst_handler(struct kvm_vcpu *= vcpu, case SBI_SRST_RESET_TYPE_SHUTDOWN: kvm_riscv_vcpu_sbi_system_reset(vcpu, run, KVM_SYSTEM_EVENT_SHUTDOWN, - reason); + true, reason); *exit =3D true; break; case SBI_SRST_RESET_TYPE_COLD_REBOOT: case SBI_SRST_RESET_TYPE_WARM_REBOOT: kvm_riscv_vcpu_sbi_system_reset(vcpu, run, KVM_SYSTEM_EVENT_RESET, - reason); + true, reason); *exit =3D true; break; default: diff --git a/arch/riscv/kvm/vcpu_sbi_v01.c b/arch/riscv/kvm/vcpu_sbi_v01.c index da4d6c99c2cf..9598bc6b4c0e 100644 --- a/arch/riscv/kvm/vcpu_sbi_v01.c +++ b/arch/riscv/kvm/vcpu_sbi_v01.c @@ -66,7 +66,7 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu,= struct kvm_run *run, break; case SBI_EXT_0_1_SHUTDOWN: kvm_riscv_vcpu_sbi_system_reset(vcpu, run, - KVM_SYSTEM_EVENT_SHUTDOWN, 0); + KVM_SYSTEM_EVENT_SHUTDOWN, false, 0); *exit =3D true; break; case SBI_EXT_0_1_REMOTE_FENCE_I: --=20 2.31.1 From nobody Sun May 10 22:40:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB4C2C433FE for ; Thu, 21 Apr 2022 18:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391252AbiDUSHv (ORCPT ); Thu, 21 Apr 2022 14:07:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391224AbiDUSHk (ORCPT ); Thu, 21 Apr 2022 14:07:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F0D6F4B1CB for ; Thu, 21 Apr 2022 11:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650564288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RmDy0KiOypH0ED0Pq5HN43KAHX+Fo77jYIn7zRippJk=; b=OZUFsMinAR/PePZn7+NGJfp2ATWJluc/+QX0I6BanFv0wjlqVJxudurucvwEkR9b0OGupm Rlu+PNWerOE4NKb0DAc70n2QpB0DvDO6eqB9i3yL9FnJZ36m1J2cce5kATOSYREn0hcBwC hf2Z5RbSOqNVFnGVYDtnMoXAof0/W4A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-7Kl_lm7ZNimdk-Y0n1Mn8Q-1; Thu, 21 Apr 2022 14:04:45 -0400 X-MC-Unique: 7Kl_lm7ZNimdk-Y0n1Mn8Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA1FE101AA42; Thu, 21 Apr 2022 18:04:44 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id A555940E80F5; Thu, 21 Apr 2022 18:04:44 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: will@kernel.org, maz@kernel.org, apatel@ventanamicro.com, atishp@rivosinc.com, seanjc@google.com, pgonda@google.com Subject: [PATCH 4/4] KVM: tell userspace that system_event.ndata is valid Date: Thu, 21 Apr 2022 14:04:43 -0400 Message-Id: <20220421180443.1465634-5-pbonzini@redhat.com> In-Reply-To: <20220421180443.1465634-1-pbonzini@redhat.com> References: <20220421180443.1465634-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that all architectures are fixed, introduce a new capability so that userspace knows that it can look at the ndata and data[] members of run->system_event. Adjust the documentation. Signed-off-by: Paolo Bonzini --- Documentation/virt/kvm/api.rst | 29 ++++++++++++++++------------- include/uapi/linux/kvm.h | 1 + virt/kvm/kvm_main.c | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 72183ae628f7..fe5805ab0d75 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6089,21 +6089,18 @@ should put the acknowledged interrupt vector into t= he 'epr' field. #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 #define KVM_SYSTEM_EVENT_SEV_TERM 4 - #define KVM_SYSTEM_EVENT_NDATA_VALID (1u << 31) __u32 type; __u32 ndata; - __u64 flags; __u64 data[16]; } system_event; =20 If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered a system-level event using some architecture specific mechanism (hypercall or some special instruction). In case of ARM64, this is triggered using -HVC instruction based PSCI call from the vcpu. The 'type' field describes -the system-level event type. The 'flags' field describes architecture -specific flags for the system-level event. +HVC instruction based PSCI call from the vcpu. =20 -Valid values for bits 30:0 of 'type' are: +The 'type' field describes the system-level event type. +Valid values for 'type' are: =20 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the VM. Userspace is not obliged to honour this, and if it does honour @@ -6117,16 +6114,23 @@ Valid values for bits 30:0 of 'type' are: to ignore the request, or to gather VM memory core dump and/or reset/shutdown of the VM. - KVM_SYSTEM_EVENT_SEV_TERM -- an AMD SEV guest requested termination. - The guest physical address of the guest's GHCB is stored in `data[0]`. =20 -Valid flags are: +If KVM_CAP_SYSTEM_EVENT_DATA is present, the 'data' field can contain +architecture specific information for the system-level event. Only +the first `ndata` items (possibly zero) of the data array are valid. + + - for arm64, data[0] is set to KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 if + the guest issued a SYSTEM_RESET2 call according to v1.1 of the PSCI + specification. + + - for RISC-V, data[0] is set to the value of the second argument of the + ``sbi_system_reset`` call. =20 - - KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (arm64 only) -- the guest issued - a SYSTEM_RESET2 call according to v1.1 of the PSCI specification. + - for x86, KVM_SYSTEM_EVENT_SEV_TERM stores the guest physical address of= the + guest's GHCB in `data[0]`. =20 -Extra data for this event is stored in the `data[]` array, up to index -`ndata-1` included, if bit 31 is set in `type`. The data depends on the -`type` field. There is no extra data if bit 31 is clear or `ndata` is zer= o. +Previous versions of Linux defined a `flags` member in this struct. The +field however was never written. =20 :: =20 diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 5a57f74b4903..f76ffecda38a 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1147,6 +1147,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_PMU_CAPABILITY 212 #define KVM_CAP_DISABLE_QUIRKS2 213 #define KVM_CAP_VM_TSC_CONTROL 214 +#define KVM_CAP_SYSTEM_EVENT_DATA 215 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index dfb7dabdbc63..ac57fc2c935f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4333,6 +4333,7 @@ static long kvm_vm_ioctl_check_extension_generic(stru= ct kvm *kvm, long arg) return 0; #endif case KVM_CAP_BINARY_STATS_FD: + case KVM_CAP_SYSTEM_EVENT_DATA: return 1; default: break; --=20 2.31.1