Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp516332lqb; Wed, 17 Apr 2024 03:23:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX37mQTt9xcBEK9/RqFQpRSnNCuNwtJQ5cmUa4LInQs1plRX87PL/rGJ/jkWFVg8SpdFuxq5YJ3JVhbTeT2QYg6o3x10MvuoE3w9zYb1w== X-Google-Smtp-Source: AGHT+IFhE8TFW2izAv90pRmhjXZitkUmcAg2cixVPyqKHZhsLZQuW7cYQy5hL7PTugQPpBUipYiw X-Received: by 2002:a05:622a:606:b0:436:63ac:d0bf with SMTP id z6-20020a05622a060600b0043663acd0bfmr20151681qta.62.1713349393059; Wed, 17 Apr 2024 03:23:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713349393; cv=pass; d=google.com; s=arc-20160816; b=RaWIiVbywibKYhCx5eYITd6d3GSlp9DdBKM0QI5aBxuIItlb71GMKoqeii8qGypv/T UKxOcLspNbQhuvZnfnuDvnCPFpwNlHrX0nfJtd9z08t6JY/ny9vaE5w2ptepCA/3zeA5 7t03wwT6bPWH/tF1E2u+zvC798H6j1q7x5INYy52FERcZlRdr29C65/NRiMhuDEYscU+ 9dQi0xIJ8h5a9+0tKZYLszR/zcqPP3rykUBvlLie3iGfeIMfIc0wFIZrpSaedi6zdj2y lRHlBmJfc48i5r6ZzEsd+VUqn3EUhjxBN4e4EHDWrioxRLRpGYmY1GzGzhYghxo6ZnzI eseg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=ijH8ik1P+4oWLUmZvPzfHctuwQscvRM4guBv3LeBsb0=; fh=0oaqyrehKWuX1zrO9O/X/bfiNWa7uV4CK2uOUG2gOes=; b=dymc7FBRl3mv6to1SrQa16J3K6JvAcF9vTVu5TGjD4CyTd4H7pszuljzRPb0oRFXBQ 8sSZvSSyswaFHC+odkyBqHmxltWpBopG3hYqWFsB1G7yq5PFS9x41LwCxZEGDqzJnOBn SjyWuLeSP37mND7aQ3wc9giQMkA6cwf6+71Y4h56q4smScbqm62+LZ2llP8J+gyaHoXn 22/+/7DAYS+k5tB96AXh/sPk6uOW2d20D5vJAx6sr3HhWm93UJ/CzvQfGhN3Z2rGeTVO XHklD1LGbTQDQD412lRsxHUzMx03hMdF/hR+J298/Rgk/V/6WJ+O78QOMnemakj/QPeT hCjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148314-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148314-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x25-20020ae9f819000000b0078d5f5ff494si14275560qkh.708.2024.04.17.03.23.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:23:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148314-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148314-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148314-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B473A1C21182 for ; Wed, 17 Apr 2024 10:23:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE42F13DDB4; Wed, 17 Apr 2024 10:20:38 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C729413C83B; Wed, 17 Apr 2024 10:20:36 +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=1713349238; cv=none; b=rC4pXZEy1mHeo6QkSNjOG5AUoHQ1oxaME2RDH5xB/2RwBdZAkTGXYIRkDtaRocIyv1pBF/yPQfeYEanesT9PXwXzWxm0g2p+guxX2/sHucVkKAg43lgmVk/3sN3RtXqVgT8oyufH+qqnyfQxB0BSzSSqT5+7vKDPDzJxO/lrziM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713349238; c=relaxed/simple; bh=kvpTxfMFvPgem01ruuxJKhDVMFpsajEnyI7JrOnz7sY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZaIiFrhitZeRgkEvrepwoDzER8+tVd4KDvptmDpUrSnaLc2p48EaEk20d5COFfQ99nJPKsXAelkYmkRAuEkDcs+t9yCTmrnfUCCBtN/gFE2jMd1cgunIaJt0vGcJI4K77B395AUcDe6OQiSXuGn2VZ5+xiaoZ435V5C8Lb1X62o= 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 221B1339; Wed, 17 Apr 2024 03:21:04 -0700 (PDT) Received: from [10.1.39.28] (FVFF763DQ05P.cambridge.arm.com [10.1.39.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 34BC53F64C; Wed, 17 Apr 2024 03:20:33 -0700 (PDT) Message-ID: <711484c0-efae-45ff-8373-69d45dd88832@arm.com> Date: Wed, 17 Apr 2024 11:20:31 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 11/43] arm64: kvm: Allow passing machine type in KVM creation Content-Language: en-GB To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , 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 References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084309.1733783-1-steven.price@arm.com> <20240412084309.1733783-12-steven.price@arm.com> From: Suzuki K Poulose In-Reply-To: <20240412084309.1733783-12-steven.price@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/04/2024 09:42, 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. > > 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 22da6493912a..c5a6139d5454 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -173,6 +173,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; > + } > + > ret = kvm_share_hyp(kvm, kvm + 1); > if (ret) > return ret; > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index aae365647b62..af4564f3add5 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -877,9 +877,6 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu, unsigned long t > if (kvm_is_realm(kvm)) > ipa_limit = kvm_realm_ipa_limit(); > > - if (type & ~KVM_VM_TYPE_ARM_IPA_SIZE_MASK) > - return -EINVAL; > - > phys_shift = KVM_VM_TYPE_ARM_IPA_SIZE(type); > if (is_protected_kvm_enabled()) { > phys_shift = kvm_ipa_limit; > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > index a1147036d1bd..5153c837c8c7 100644 > --- a/include/uapi/linux/kvm.h > +++ b/include/uapi/linux/kvm.h > @@ -635,14 +635,25 @@ struct kvm_enable_cap { > #define KVM_S390_SIE_PAGE_OFFSET 1 > > /* > - * On arm64, machine type can be used to request the physical > - * address size for the VM. Bits[7-0] are reserved for the guest > - * PA size shift (i.e, log2(PA_Size)). For backward compatibility, > - * value 0 implies the default IPA size, 40bits. > + * On arm64, machine type can be used to request both the machine type and > + * the physical address size for the VM. > + * > + * Bits[11-8] are reserved for the ARM specific machine type. > + * > + * Bits[7-0] are reserved for the guest PA size shift (i.e, log2(PA_Size)). > + * For backward compatibility, value 0 implies the default IPA size, 40bits. > */ > +#define KVM_VM_TYPE_ARM_SHIFT 8 > +#define KVM_VM_TYPE_ARM_MASK (0xfULL << KVM_VM_TYPE_ARM_SHIFT) > +#define KVM_VM_TYPE_ARM(_type) \ > + (((_type) << KVM_VM_TYPE_ARM_SHIFT) & KVM_VM_TYPE_ARM_MASK) > +#define KVM_VM_TYPE_ARM_NORMAL KVM_VM_TYPE_ARM(0) > +#define KVM_VM_TYPE_ARM_REALM KVM_VM_TYPE_ARM(1) > + > #define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL > #define KVM_VM_TYPE_ARM_IPA_SIZE(x) \ > ((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK) > + > /* > * ioctls for /dev/kvm fds: > */ Looks good to me. Reviewed-by: Suzuki K Poulose