From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Martin Subject: Re: [PATCH v7 22/27] KVM: arm/arm64: Add KVM_ARM_VCPU_FINALIZE ioctl Date: Thu, 4 Apr 2019 17:47:07 +0100 Message-ID: <20190404164707.GH3567@e103592.cambridge.arm.com> References: <1553864452-15080-1-git-send-email-Dave.Martin@arm.com> <1553864452-15080-23-git-send-email-Dave.Martin@arm.com> <20190404150709.ihxlndxc6mvuwomp@kamzik.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 2B9344A422 for ; Thu, 4 Apr 2019 12:47:15 -0400 (EDT) Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LSnhi0xkUzGA for ; Thu, 4 Apr 2019 12:47:13 -0400 (EDT) Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by mm01.cs.columbia.edu (Postfix) with ESMTP id CEF0D4A331 for ; Thu, 4 Apr 2019 12:47:12 -0400 (EDT) Content-Disposition: inline In-Reply-To: <20190404150709.ihxlndxc6mvuwomp@kamzik.brq.redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu To: Andrew Jones Cc: Okamoto Takayuki , Christoffer Dall , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , Zhang Lei , Julien Grall , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org List-Id: kvmarm@lists.cs.columbia.edu On Thu, Apr 04, 2019 at 05:07:09PM +0200, Andrew Jones wrote: > On Fri, Mar 29, 2019 at 01:00:47PM +0000, Dave Martin wrote: > > Some aspects of vcpu configuration may be too complex to be > > completed inside KVM_ARM_VCPU_INIT. Thus, there may be a > > requirement for userspace to do some additional configuration > > before various other ioctls will work in a consistent way. > > > > In particular this will be the case for SVE, where userspace will > > need to negotiate the set of vector lengths to be made available to > > the guest before the vcpu becomes fully usable. > > > > In order to provide an explicit way for userspace to confirm that > > it has finished setting up a particular vcpu feature, this patch > > adds a new ioctl KVM_ARM_VCPU_FINALIZE. > > > > When userspace has opted into a feature that requires finalization, > > typically by means of a feature flag passed to KVM_ARM_VCPU_INIT, a > > matching call to KVM_ARM_VCPU_FINALIZE is now required before > > KVM_RUN or KVM_GET_REG_LIST is allowed. Individual features may > > impose additional restrictions where appropriate. > > > > No existing vcpu features are affected by this, so current > > userspace implementations will continue to work exactly as before, > > with no need to issue KVM_ARM_VCPU_FINALIZE. > > > > As implemented in this patch, KVM_ARM_VCPU_FINALIZE is currently a > > placeholder: no finalizable features exist yet, so ioctl is not > > required and will always yield EINVAL. Subsequent patches will add > > the finalization logic to make use of this ioctl for SVE. > > > > No functional change for existing userspace. > > > > Signed-off-by: Dave Martin > > Reviewed-by: Julien Thierry > > Tested-by: zhang.lei > > > > --- > > > > Changes since v5: > > > > * Commit message, including subject line, rewritten. > > > > This patch is a rework of "KVM: arm/arm64: Add hook to finalize the > > vcpu configuration". The old subject line and commit message no > > longer accurately described what the patch does. However, the code > > is an evolution of the previous patch rather than a wholesale > > rewrite. > > > > * Added an explicit KVM_ARM_VCPU_FINALIZE ioctl, rather than just > > providing internal hooks in the kernel to finalize the vcpu > > configuration implicitly. This allows userspace to confirm exactly > > when it has finished configuring the vcpu and is ready to use it. > > > > This results in simpler (and hopefully more maintainable) ioctl > > ordering rules. > > --- > > arch/arm/include/asm/kvm_host.h | 4 ++++ > > arch/arm64/include/asm/kvm_host.h | 4 ++++ > > include/uapi/linux/kvm.h | 3 +++ > > virt/kvm/arm/arm.c | 18 ++++++++++++++++++ > > 4 files changed, 29 insertions(+) > > > > diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h > > index a49ee01..e80cfc1 100644 > > --- a/arch/arm/include/asm/kvm_host.h > > +++ b/arch/arm/include/asm/kvm_host.h > > @@ -19,6 +19,7 @@ > > #ifndef __ARM_KVM_HOST_H__ > > #define __ARM_KVM_HOST_H__ > > > > +#include > > #include > > #include > > #include > > @@ -411,4 +412,7 @@ static inline int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type) > > return 0; > > } > > > > +#define kvm_arm_vcpu_finalize(vcpu, what) (-EINVAL) > > +#define kvm_arm_vcpu_is_finalized(vcpu) true > > + > > We usually use inline functions for the stubs. I guess we could. The vcpu_has_sve() circular include problem applies here too if we put the actual function bodies here, which is why I ended up with this. Now that the bodies (for arm64) are out of line, it actually doesn't matter. > > #endif /* __ARM_KVM_HOST_H__ */ > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > > index 3e89509..98658f7 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -23,6 +23,7 @@ > > #define __ARM64_KVM_HOST_H__ > > > > #include > > +#include > > #include > > #include > > #include > > @@ -625,4 +626,7 @@ void kvm_arch_free_vm(struct kvm *kvm); > > > > int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type); > > > > +#define kvm_arm_vcpu_finalize(vcpu, what) (-EINVAL) > > +#define kvm_arm_vcpu_is_finalized(vcpu) true > > Same as above. Ditto > > + > > #endif /* __ARM64_KVM_HOST_H__ */ > > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > > index dc77a5a..c3b8e7a 100644 > > --- a/include/uapi/linux/kvm.h > > +++ b/include/uapi/linux/kvm.h > > @@ -1441,6 +1441,9 @@ struct kvm_enc_region { > > /* Available with KVM_CAP_HYPERV_CPUID */ > > #define KVM_GET_SUPPORTED_HV_CPUID _IOWR(KVMIO, 0xc1, struct kvm_cpuid2) > > > > +/* Available with KVM_CAP_ARM_SVE */ > > +#define KVM_ARM_VCPU_FINALIZE _IOW(KVMIO, 0xc2, int) > > + > > /* Secure Encrypted Virtualization command */ > > enum sev_cmd_id { > > /* Guest initialization commands */ > > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > > index c69e137..9edbf0f 100644 > > --- a/virt/kvm/arm/arm.c > > +++ b/virt/kvm/arm/arm.c > > @@ -545,6 +545,9 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) > > if (likely(vcpu->arch.has_run_once)) > > return 0; > > > > + if (!kvm_arm_vcpu_is_finalized(vcpu)) > > + return -EPERM; > > + > > vcpu->arch.has_run_once = true; > > > > if (likely(irqchip_in_kernel(kvm))) { > > @@ -1116,6 +1119,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp, > > if (unlikely(!kvm_vcpu_initialized(vcpu))) > > break; > > > > + r = -EPERM; > > + if (!kvm_arm_vcpu_is_finalized(vcpu)) > > + break; > > + > > What's the rationale for using EPERM? The finalized concept is very > similar to the initialized one. So why not also use ENOEXEC for it too? Hmm, I guess we could equally return ENOEXEC. Initially this felt like a more distinctive case. Assuming Marc is happy to take an ABI fix into kvmarm/next, I'm can change them. We're not absolutely committed until this hits mainline... > > r = -EFAULT; > > if (copy_from_user(®_list, user_list, sizeof(reg_list))) > > break; > > @@ -1169,6 +1176,17 @@ long kvm_arch_vcpu_ioctl(struct file *filp, > > > > return kvm_arm_vcpu_set_events(vcpu, &events); > > } > > + case KVM_ARM_VCPU_FINALIZE: { > > + int what; > > + > > + if (!kvm_vcpu_initialized(vcpu)) > > + return -ENOEXEC; > > + > > + if (get_user(what, (const int __user *)argp)) > > + return -EFAULT; > > + > > + return kvm_arm_vcpu_finalize(vcpu, what); > > Almost all the cases use the 'r = ...; break;' type of pattern, leaving > it to the 'return r' at the end of the function. I guess that's in case > at some point more stuff is added after the switch. The only cases that > don't do that are the most recent ones KVM_GET/SET_VCPU_EVENTS, which > should probably be changed to fit the pattern too, rather than this > new ioctl following there pattern. I have no strong opinion on this: it's basically a question of style. I followed KVM_GET/SET_VCPU_EVENTS, but you're right, the r = ...; break; style is used for the others. If there's an intention of putting stuff at the end of the function, it will make a difference. But this seems unlikely to happen: this function is really just a dispatcher. I'm happy to change it (and the others) if there are strong views. Cheers ---Dave From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2148BC4360F for ; Thu, 4 Apr 2019 16:47:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E4B2220693 for ; Thu, 4 Apr 2019 16:47:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RF+YXZMn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4B2220693 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SXwBln9RPJ6Q7oyuxbql1k9XzvMhzUdtPrkAVIHTOL8=; b=RF+YXZMnRkjrrR xMfv8ARSgl3nhoBGlFO0OMMPTqHsTnOupGu9hYb4EQzWkR72B5CnelYOmfgQiMdsGqn5rTBJQ56XC ZqvpaiyIiY4L2q6REN8ulxPgNn7QtjZYcRv8reM6/l5YAlSDd/VgOkYC5MTi5LrTubU7O7kOFs1mH tdwPjbBmgDZtdm3S3RYWnEQkOCMhaRoIoWL/9L/oswau0/EoBuBeuOTmmJpqi+bUMjSIaAp03dNJq FOYVTxIN1r/ZlygC8DB2dpg74wmA/2AEbASDYxPQcv3TsgDPYL9Kf/nSWsXHbz833l6htdy64x87M a2R80DghLwsthbyRpehQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hC5WG-000279-B3; Thu, 04 Apr 2019 16:47:16 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hC5WC-00025q-Ue for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 16:47:14 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4EDDE169E; Thu, 4 Apr 2019 09:47:12 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5A7A23F557; Thu, 4 Apr 2019 09:47:10 -0700 (PDT) Date: Thu, 4 Apr 2019 17:47:07 +0100 From: Dave Martin To: Andrew Jones Subject: Re: [PATCH v7 22/27] KVM: arm/arm64: Add KVM_ARM_VCPU_FINALIZE ioctl Message-ID: <20190404164707.GH3567@e103592.cambridge.arm.com> References: <1553864452-15080-1-git-send-email-Dave.Martin@arm.com> <1553864452-15080-23-git-send-email-Dave.Martin@arm.com> <20190404150709.ihxlndxc6mvuwomp@kamzik.brq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190404150709.ihxlndxc6mvuwomp@kamzik.brq.redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_094713_000669_93D265A9 X-CRM114-Status: GOOD ( 40.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Okamoto Takayuki , Christoffer Dall , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , Zhang Lei , Julien Grall , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 04, 2019 at 05:07:09PM +0200, Andrew Jones wrote: > On Fri, Mar 29, 2019 at 01:00:47PM +0000, Dave Martin wrote: > > Some aspects of vcpu configuration may be too complex to be > > completed inside KVM_ARM_VCPU_INIT. Thus, there may be a > > requirement for userspace to do some additional configuration > > before various other ioctls will work in a consistent way. > > > > In particular this will be the case for SVE, where userspace will > > need to negotiate the set of vector lengths to be made available to > > the guest before the vcpu becomes fully usable. > > > > In order to provide an explicit way for userspace to confirm that > > it has finished setting up a particular vcpu feature, this patch > > adds a new ioctl KVM_ARM_VCPU_FINALIZE. > > > > When userspace has opted into a feature that requires finalization, > > typically by means of a feature flag passed to KVM_ARM_VCPU_INIT, a > > matching call to KVM_ARM_VCPU_FINALIZE is now required before > > KVM_RUN or KVM_GET_REG_LIST is allowed. Individual features may > > impose additional restrictions where appropriate. > > > > No existing vcpu features are affected by this, so current > > userspace implementations will continue to work exactly as before, > > with no need to issue KVM_ARM_VCPU_FINALIZE. > > > > As implemented in this patch, KVM_ARM_VCPU_FINALIZE is currently a > > placeholder: no finalizable features exist yet, so ioctl is not > > required and will always yield EINVAL. Subsequent patches will add > > the finalization logic to make use of this ioctl for SVE. > > > > No functional change for existing userspace. > > > > Signed-off-by: Dave Martin > > Reviewed-by: Julien Thierry > > Tested-by: zhang.lei > > > > --- > > > > Changes since v5: > > > > * Commit message, including subject line, rewritten. > > > > This patch is a rework of "KVM: arm/arm64: Add hook to finalize the > > vcpu configuration". The old subject line and commit message no > > longer accurately described what the patch does. However, the code > > is an evolution of the previous patch rather than a wholesale > > rewrite. > > > > * Added an explicit KVM_ARM_VCPU_FINALIZE ioctl, rather than just > > providing internal hooks in the kernel to finalize the vcpu > > configuration implicitly. This allows userspace to confirm exactly > > when it has finished configuring the vcpu and is ready to use it. > > > > This results in simpler (and hopefully more maintainable) ioctl > > ordering rules. > > --- > > arch/arm/include/asm/kvm_host.h | 4 ++++ > > arch/arm64/include/asm/kvm_host.h | 4 ++++ > > include/uapi/linux/kvm.h | 3 +++ > > virt/kvm/arm/arm.c | 18 ++++++++++++++++++ > > 4 files changed, 29 insertions(+) > > > > diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h > > index a49ee01..e80cfc1 100644 > > --- a/arch/arm/include/asm/kvm_host.h > > +++ b/arch/arm/include/asm/kvm_host.h > > @@ -19,6 +19,7 @@ > > #ifndef __ARM_KVM_HOST_H__ > > #define __ARM_KVM_HOST_H__ > > > > +#include > > #include > > #include > > #include > > @@ -411,4 +412,7 @@ static inline int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type) > > return 0; > > } > > > > +#define kvm_arm_vcpu_finalize(vcpu, what) (-EINVAL) > > +#define kvm_arm_vcpu_is_finalized(vcpu) true > > + > > We usually use inline functions for the stubs. I guess we could. The vcpu_has_sve() circular include problem applies here too if we put the actual function bodies here, which is why I ended up with this. Now that the bodies (for arm64) are out of line, it actually doesn't matter. > > #endif /* __ARM_KVM_HOST_H__ */ > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > > index 3e89509..98658f7 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -23,6 +23,7 @@ > > #define __ARM64_KVM_HOST_H__ > > > > #include > > +#include > > #include > > #include > > #include > > @@ -625,4 +626,7 @@ void kvm_arch_free_vm(struct kvm *kvm); > > > > int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type); > > > > +#define kvm_arm_vcpu_finalize(vcpu, what) (-EINVAL) > > +#define kvm_arm_vcpu_is_finalized(vcpu) true > > Same as above. Ditto > > + > > #endif /* __ARM64_KVM_HOST_H__ */ > > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > > index dc77a5a..c3b8e7a 100644 > > --- a/include/uapi/linux/kvm.h > > +++ b/include/uapi/linux/kvm.h > > @@ -1441,6 +1441,9 @@ struct kvm_enc_region { > > /* Available with KVM_CAP_HYPERV_CPUID */ > > #define KVM_GET_SUPPORTED_HV_CPUID _IOWR(KVMIO, 0xc1, struct kvm_cpuid2) > > > > +/* Available with KVM_CAP_ARM_SVE */ > > +#define KVM_ARM_VCPU_FINALIZE _IOW(KVMIO, 0xc2, int) > > + > > /* Secure Encrypted Virtualization command */ > > enum sev_cmd_id { > > /* Guest initialization commands */ > > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > > index c69e137..9edbf0f 100644 > > --- a/virt/kvm/arm/arm.c > > +++ b/virt/kvm/arm/arm.c > > @@ -545,6 +545,9 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) > > if (likely(vcpu->arch.has_run_once)) > > return 0; > > > > + if (!kvm_arm_vcpu_is_finalized(vcpu)) > > + return -EPERM; > > + > > vcpu->arch.has_run_once = true; > > > > if (likely(irqchip_in_kernel(kvm))) { > > @@ -1116,6 +1119,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp, > > if (unlikely(!kvm_vcpu_initialized(vcpu))) > > break; > > > > + r = -EPERM; > > + if (!kvm_arm_vcpu_is_finalized(vcpu)) > > + break; > > + > > What's the rationale for using EPERM? The finalized concept is very > similar to the initialized one. So why not also use ENOEXEC for it too? Hmm, I guess we could equally return ENOEXEC. Initially this felt like a more distinctive case. Assuming Marc is happy to take an ABI fix into kvmarm/next, I'm can change them. We're not absolutely committed until this hits mainline... > > r = -EFAULT; > > if (copy_from_user(®_list, user_list, sizeof(reg_list))) > > break; > > @@ -1169,6 +1176,17 @@ long kvm_arch_vcpu_ioctl(struct file *filp, > > > > return kvm_arm_vcpu_set_events(vcpu, &events); > > } > > + case KVM_ARM_VCPU_FINALIZE: { > > + int what; > > + > > + if (!kvm_vcpu_initialized(vcpu)) > > + return -ENOEXEC; > > + > > + if (get_user(what, (const int __user *)argp)) > > + return -EFAULT; > > + > > + return kvm_arm_vcpu_finalize(vcpu, what); > > Almost all the cases use the 'r = ...; break;' type of pattern, leaving > it to the 'return r' at the end of the function. I guess that's in case > at some point more stuff is added after the switch. The only cases that > don't do that are the most recent ones KVM_GET/SET_VCPU_EVENTS, which > should probably be changed to fit the pattern too, rather than this > new ioctl following there pattern. I have no strong opinion on this: it's basically a question of style. I followed KVM_GET/SET_VCPU_EVENTS, but you're right, the r = ...; break; style is used for the others. If there's an intention of putting stuff at the end of the function, it will make a difference. But this seems unlikely to happen: this function is really just a dispatcher. I'm happy to change it (and the others) if there are strong views. Cheers ---Dave _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel