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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8D4C2C7619A for ; Wed, 22 Mar 2023 11:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KoLmjJCe/jj5t2gXviaHzXjOk1R8lsioJdRaan0tzOo=; b=2nV6AjcQ3nktbT EWzhz8+vlt4/TRuhYbOKIiQuqYKo4QePLZn4SPquN0FYVYjNe2Qzsz/AN2UDau5myp7P/pM0WWRKx FiTHozekFAbwqFGYtMFygx0zC0urkiuQf2GXWZUd+WpQ6jg4/LmOEU+fj6G3KD2FLlR+Ti1EgRnj4 8ZwGuUD4YEho7RnRkUYLYLRSLxr0FD46+sEHg6ihNEETHrgK/xwhc6dFtZm2AToMHkqx8ZJEtaffH g2mz6Z1Fq3DbjwDVIfbm4r7BIz8r5X9QYDPXrt2YaD6/ziI+7kPBvslo+BIEmPWsvo5ot52lXI5Cb FW23LlAdxkjKX0bLR7fw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pex05-00Fp3x-1x; Wed, 22 Mar 2023 11:51:29 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pex02-00Fp2o-26 for linux-arm-kernel@lists.infradead.org; Wed, 22 Mar 2023 11:51:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D05F9AD7; Wed, 22 Mar 2023 04:52:08 -0700 (PDT) Received: from [10.57.53.137] (unknown [10.57.53.137]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EDC243F93E; Wed, 22 Mar 2023 04:51:21 -0700 (PDT) Message-ID: <3f4dcc1e-7679-0f7c-44ef-6b0824400259@arm.com> Date: Wed, 22 Mar 2023 11:51:20 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [RFC PATCH 16/28] arm64: RME: Allow populating initial contents Content-Language: en-GB To: Zhi Wang Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127112932.38045-1-steven.price@arm.com> <20230127112932.38045-17-steven.price@arm.com> <20230306193439.000048f2@gmail.com> <6c6ff608-2314-a49a-84ee-fac883c4e227@arm.com> <20230314173121.00006cfb@gmail.com> From: Steven Price In-Reply-To: <20230314173121.00006cfb@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230322_045126_782530_1AD5125E X-CRM114-Status: GOOD ( 24.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 14/03/2023 15:31, Zhi Wang wrote: > On Fri, 10 Mar 2023 15:47:16 +0000 > Steven Price wrote: > >> On 06/03/2023 17:34, Zhi Wang wrote: >>> On Fri, 27 Jan 2023 11:29:20 +0000 >>> Steven Price wrote: >>>> + if (kvm_realm_state(kvm) != REALM_STATE_NEW) >>>> + return -EBUSY; >>> >>> Maybe -EINVAL? The realm hasn't been created (RMI_REALM_CREATE is not called >>> yet). The userspace shouldn't reach this path. >> >> Well user space can attempt to populate in the ACTIVE state - which is >> where the idea of 'busy' comes from. Admittedly it's a little confusing >> when RMI_REALM_CREATE hasn't been called. >> >> I'm not particularly bothered about the return code, but it's useful to >> have a different code to -EINVAL as it's not an invalid argument, but >> calling at the wrong time. I can't immediately see a better error code >> though. >> > The reason why I feel -EBUSY is little bit off is EBUSY usually indicates > something is already initialized and currently running, then another > calling path wanna to operate it. > > I took a look on the ioctls in arch/arm64/kvm/arm.c. It seems people have > different opinions for calling execution path at a wrong time: > > For example: > > long kvm_arch_vcpu_ioctl() > ... > case KVM_GET_REG_LIST: { > struct kvm_reg_list __user *user_list = argp; > struct kvm_reg_list reg_list; > unsigned n; > > r = -ENOEXEC; > if (unlikely(!kvm_vcpu_initialized(vcpu))) > break; > > r = -EPERM; > if (!kvm_arm_vcpu_is_finalized(vcpu)) > break; > > If we have to choose one, I prefer -ENOEXEC as -EPERM is stranger. But > personally my vote goes to -EINVAL. Ok, I think you've convinced me - I'll change to -EINVAL. It is invalid use of the API and none of the other error codes seem a great fit. Although I do wish Linux had more descriptive error codes - I often end up peppering the kernel with a few printks when using a new API to find out what I'm doing wrong. Steve >> Steve >> >>>> + >>>> + if (!IS_ALIGNED(args->populate_ipa_base, PAGE_SIZE) || >>>> + !IS_ALIGNED(args->populate_ipa_size, PAGE_SIZE)) >>>> + return -EINVAL; >>>> + >>>> + ipa_base = args->populate_ipa_base; >>>> + ipa_end = ipa_base + args->populate_ipa_size; >>>> + >>>> + if (ipa_end < ipa_base) >>>> + return -EINVAL; >>>> + >>>> + return populate_par_region(kvm, ipa_base, ipa_end); >>>> +} >>>> + >>>> static int set_ipa_state(struct kvm_vcpu *vcpu, >>>> unsigned long ipa, >>>> unsigned long end, >>>> @@ -748,6 +1102,18 @@ int kvm_realm_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) >>>> r = kvm_init_ipa_range_realm(kvm, &args); >>>> break; >>>> } >>>> + case KVM_CAP_ARM_RME_POPULATE_REALM: { >>>> + struct kvm_cap_arm_rme_populate_realm_args args; >>>> + void __user *argp = u64_to_user_ptr(cap->args[1]); >>>> + >>>> + if (copy_from_user(&args, argp, sizeof(args))) { >>>> + r = -EFAULT; >>>> + break; >>>> + } >>>> + >>>> + r = kvm_populate_realm(kvm, &args); >>>> + break; >>>> + } >>>> default: >>>> r = -EINVAL; >>>> break; >>> >> > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel