From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CA551DDC22; Thu, 30 Jan 2025 14:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738246497; cv=none; b=byJFtEj6faZpOnXv8IWvIXyYeTUdbTWT7kqOk9MMLOmynFZR6BOqmpnVLQUoHC1n9HidOQcmd4LOcwVALhiFxiqhb6aB1IXXwalBi2QsBM1y/O+O/TJn96+ExcTTLInlPOKuUPJPZjS/6L0NeZ2qxzy76kJWuLuLE6pOcbEwB5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738246497; c=relaxed/simple; bh=62uvUPVokekdadvzzYgMQHmplXUKl1Kb/D+EIGlWRtw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UptKO7kOzH01IORiSWx1q/amMqjWgkFvJMN3qib3DnbGuAcVmUzb2/PBfEHhv73VG/fFjT7mmxhfvVhrjPs3w/wOARJX5UGwioZr3GHkIr9Z8ZbdzeMQAQG6TjDj+1UzwYmwx1a82q62WMlI8leiqkhXdLOQPc0LPc3obNAcdw0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 940B1497; Thu, 30 Jan 2025 06:15:14 -0800 (PST) Received: from [10.1.32.52] (e122027.cambridge.arm.com [10.1.32.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3BF713F694; Thu, 30 Jan 2025 06:14:45 -0800 (PST) Message-ID: <1356de81-2fa1-4ad5-80bd-d02440603288@arm.com> Date: Thu, 30 Jan 2025 14:14:43 +0000 Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 10/43] arm64: kvm: Allow passing machine type in KVM creation To: Gavin Shan , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: 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, Ganapatrao Kulkarni , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" References: <20241212155610.76522-1-steven.price@arm.com> <20241212155610.76522-11-steven.price@arm.com> From: Steven Price Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 29/01/2025 04:07, Gavin Shan wrote: > On 12/13/24 1:55 AM, Steven Price wrote: >> Previously machine type was used purely for specifying the physical >> address size of the guest. Reserve the higher bits to specify an ARM >> specific machine type and declare a new type 'KVM_VM_TYPE_ARM_REALM' >> used to create a realm guest. >> >> Reviewed-by: Suzuki K Poulose >> Signed-off-by: Steven Price >> --- >>   arch/arm64/kvm/arm.c     | 17 +++++++++++++++++ >>   arch/arm64/kvm/mmu.c     |  3 --- >>   include/uapi/linux/kvm.h | 19 +++++++++++++++---- >>   3 files changed, 32 insertions(+), 7 deletions(-) >> >> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c >> index c505ec61180a..73016e1e0067 100644 >> --- a/arch/arm64/kvm/arm.c >> +++ b/arch/arm64/kvm/arm.c >> @@ -207,6 +207,23 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned >> long type) >>       mutex_unlock(&kvm->lock); >>   #endif >>   +    if (type & ~(KVM_VM_TYPE_ARM_MASK | >> KVM_VM_TYPE_ARM_IPA_SIZE_MASK)) >> +        return -EINVAL; >> + >> +    switch (type & KVM_VM_TYPE_ARM_MASK) { >> +    case KVM_VM_TYPE_ARM_NORMAL: >> +        break; >> +    case KVM_VM_TYPE_ARM_REALM: >> +        kvm->arch.is_realm = true; >> +        if (!kvm_is_realm(kvm)) { >> +            /* Realm support unavailable */ >> +            return -EINVAL; >> +        } >> +        break; >> +    default: >> +        return -EINVAL; >> +    } >> + >>       kvm_init_nested(kvm); >>         ret = kvm_share_hyp(kvm, kvm + 1); > > Corresponding to comments for PATCH[6], the block of the code can be > modified > to avoid using kvm_is_realm() here. In this way, kvm_is_realm() can be > simplifed > as I commented for PATCH[6]. > >     case KVM_VM_TYPE_ARM_REALM: >         if (static_branch_unlikely(&kvm_rme_is_available)) >             return -EPERM;    /* -EPERM may be more suitable than - > EINVAL */ > >         kvm->arch.is_realm = true; >         break; Yes that's more readable. I'd used kvm_is_realm() because I wanted to keep the check on kvm_rme_is_available to one place, but coming back to the code there's definitely a "Huh?" moment from setting 'is_realm' and then testing if it's a realm! I also agree -EPERM is probably better to signify that the kernel supports realms but the hardware doesn't. Thanks, Steve