Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp11818lql; Fri, 12 Apr 2024 01:52:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKyoL2Vg100PjHPimc8/B3H1CJ0/ZJ4owo0l3sLagRXD1G5NTB+oOsBTx2TchOhVmJqc3tUyFvg+SydwOe4oGBvHvTzc3M4nsthcRuFg== X-Google-Smtp-Source: AGHT+IGKTews63c7ppYhJ5M9FkbKNNUXx8RIJpHzKsvAwMYLvaO+6WmGwPyMWU+aowz0evO8aSOb X-Received: by 2002:a17:90a:fe8d:b0:2a6:e5d0:d42b with SMTP id co13-20020a17090afe8d00b002a6e5d0d42bmr1119111pjb.2.1712911924620; Fri, 12 Apr 2024 01:52:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712911924; cv=pass; d=google.com; s=arc-20160816; b=aNK21pq6x27mfCjnIHR+ldjc0DTMIFdilgsl88iaEDvklmvyQGQYy3u7N+anqJqRVZ e7Y/83bmR8o+BP71xdJLH8cPDi8FEI/GjqbKrs/ZcT8YvFXSh0yaqjMaN7a8gtadPavs 5hx69KXlu4fnDDZrYJmFxS7IFzGnvj7eOjh5Rlg2T9j433h3TRJ/iBUJAtw5pPzJqq7n dOgsJURQrefHkIDE8wr+K6kG80zyDj1m3NVE99bY23OxYkaDBktwGpZfU4D+xJ6xkXOn dj4sHQpH7kQ6deqEXoN76Vons/1tgGR61q26ZAH/or+QNyIXwav/8ecAhR5xl9q7RMU9 dqMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=erR9EIR4Gp8KQ7QpnvynNIeZlfok3fh28sJOaB+/1LQ=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=wbJDYvqHA2iCeDWz6UwZRaqNpV8tQ47DTeFDIdJcZ0S6MYnJWftZHGmOWGZKJdUH+G S7WBmMXAevnVuQWy8QlBaBW4B1vytgvx+UP364+EfeQYQeCjrJzkFESjKU8+wCpuP4ON LSfG+7JIgvA+db+kR3YGCC45zS3sGtxLN1ZTjZcAJrTMpnypwWPdaGwDnF2MuiLO29mE Id/UuYwV3Nz9lgxSQc9rjzWlNm2rpxwVj4fgqZgsOfj478kTiSVUVw8ng89h05FVbcXq kFjK2AXpMowGqtS13iX8C3crza0JNsjqaYpqHe6HqX5YioildskVs8auJLMEifvXH6qG H3og==; 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-142281-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id pg2-20020a17090b1e0200b002a606004eb8si3039099pjb.114.2024.04.12.01.52.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 01:52:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142281-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-142281-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142281-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A5863280A6D for ; Fri, 12 Apr 2024 08:51:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A563762FF; Fri, 12 Apr 2024 08:43:46 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A054C73174; Fri, 12 Apr 2024 08:43:44 +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=1712911426; cv=none; b=UvrqDqKMKG+wWToIzQovbaBFHI0K3AN/Jgw/Z+HJhAL9Z9GfdlUvb2JWIzvh1m8GeNadmIDTBzETVDCDIHnsCDRY9jukVCJ/Evypkf9NDB+2Zr4N3wXjYapx7B9Olqr73O6g8psmKCcct4F6jAvuZtsW6ITAFhuYfIv7vFxHtw0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911426; c=relaxed/simple; bh=diRGvclpTVGXAlQ5KlBu/fnxDm15CyZep6Wk185oW3s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WnVkSb7QwlsMyjRNARUKxPFItySgqzV9whwFGqbd7XCa1ErbUl5SPHxWVhPymJP8Oyto0nzl3vlXYEe4So6s5v/iQOhMY/Giv5lSyuK58A+ga9YdswkT11RluLm/e7Gr11TPSvCxlI0VYvcUvWHy13/VaBe3m3PJ/6VRvP69N6I= 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 60B37113E; Fri, 12 Apr 2024 01:44:13 -0700 (PDT) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0495A3F6C4; Fri, 12 Apr 2024 01:43:41 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , 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 Subject: [PATCH v2 11/43] arm64: kvm: Allow passing machine type in KVM creation Date: Fri, 12 Apr 2024 09:42:37 +0100 Message-Id: <20240412084309.1733783-12-steven.price@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412084309.1733783-1-steven.price@arm.com> References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084309.1733783-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: */ -- 2.34.1