Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp371816lqp; Mon, 10 Jun 2024 06:49:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXgDaVyg3A8M5sM7ZAvkQjMePBto7iISWPC5yaIsY54+vIdRFMmd9T0aLyPWVMh8OIFkWamey7o/PXpr+Nj++/qUY2Q/bgnCSPP9nSNfw== X-Google-Smtp-Source: AGHT+IGoIfvYsGunmca4Hu/Bi2zX0elH2mP1AYkL75Pyy8qgOQo0gZRHvYNrVV8mtKPjiikfd9P0 X-Received: by 2002:a05:6e02:1a82:b0:374:9481:d19c with SMTP id e9e14a558f8ab-3758031fe21mr105352365ab.18.1718027361830; Mon, 10 Jun 2024 06:49:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718027361; cv=pass; d=google.com; s=arc-20160816; b=KVTFZbnhnw8nbMg3yPmAWDPUS4unvmoork76DKnJtyQiH+7FR+oSAgu02hSoJNcJqt ro+y90FZvpoMi9mAC1Fb5EQrjP7T0QgA5Ly1CGF0yhB+akqA60d9rlyubXEwh8d9jnom saRnI9JuZ7MKqznvCpY8Yiao2q9xg++c9zfNLxveHR3dGjv4LoxUibzTXwnrlRJ/g+dp hIJfa8Mw8wYjk0G6hv/r4thc9EHfKl/tmCLZTf3TDNr7GhJHsSE7rdjksgc7xIGVVzUy 763KYkTJa0W1pOkSysslpE4JEUp6jYFYL1SMKCdaWyPf9yvfBiEQ3I3fIX+cNLyOgMiV dlSg== 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=sS4xGmPIrzpQ0ELUibawD74c5nKV1sfpkCg4BPrX6iU=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=pB+MtRWgOsG1laHreqI7x8nJTgY/UxRFjGnmCX1nN7A2249QE12af9EpanDkdrfYVu OvYx29J4Y0Mi4FvXG4GZFQVwbmfJBchREVQDyHJWgFyA+bSy9Ew3qbRhdcf6rAu7vXIr J3fCDLZ0zHLa5prtl7mrqLd0FAyqbQqEPDW/ofe/BXGcdb8Dff9LCQPK5dL3kiOZoCLG kbLdQBabtJJok/Zk5VxZ4HL7+y3tkPAcW7WEAhWgfNRzEIYvaej3bGibq8V/7RN9NKPp PYmruY2Fh/yO7YyLe7ZkVBUMTKhHhaWP4XbBsjazIxm3j7U9rUChP/QB0rAbfa0yqKhe 3GbA==; 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-208258-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de20cfa43bsi4980120a12.62.2024.06.10.06.49.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:49:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208258-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-208258-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208258-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 91376B23B7C for ; Mon, 10 Jun 2024 13:45:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB441146D54; Mon, 10 Jun 2024 13:42:59 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CEEED1459EF; Mon, 10 Jun 2024 13:42:57 +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=1718026979; cv=none; b=mpYvwa3wD38ZO2HMOBV+YL6o/xhZdGqbslYp4st93S6hQJkXX7QHb9nGMnhGRr/i3Pl1xZD0Ye7iEX2Y3eqohvJJPNPQhdUA9Kp93Os8urxWWfVnOkyGm6SKRw+mi2GMZnqd89FVkJs9H3+y3GwU2NataMxdz0v4Z0/JtSUVlSk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718026979; c=relaxed/simple; bh=JigAcHGln6hr++S3UgkegapXFTiLXRDAQ1gED5VJICw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MXywCQ1byoSxuMq22BGzCvSerLCCSONiSdMUgWDAfZPC5pGZ/JjzXZQDIAHTGJ5DeT/f0F80grn8dqUEKVydDjfE02YF+6PzKn13oFoY3UsTaSCho13tfPOVjfxN4dq5MGB21g0Zh2A0iO+eWoPucY1Srt8qV7+yML48cYmvGxI= 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 A8F80169E; Mon, 10 Jun 2024 06:43:21 -0700 (PDT) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.35.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F134D3F58B; Mon, 10 Jun 2024 06:42:54 -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 v3 11/43] arm64: kvm: Allow passing machine type in KVM creation Date: Mon, 10 Jun 2024 14:41:30 +0100 Message-Id: <20240610134202.54893-12-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610134202.54893-1-steven.price@arm.com> References: <20240610134202.54893-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. 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 c37b563d1d66..b1df789e9013 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -196,6 +196,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 19df60fee8c8..93300491b31b 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 44c68e36f230..32cff22f0e4d 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