From nobody Thu Nov 28 05:47:59 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 664E61E32B1; Fri, 4 Oct 2024 15:31: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=1728055897; cv=none; b=lfpmPTqhvKTcHrS6t838aJRw7WUM95v7MxhMeEMTn0SeOKhWk55QRTMfL/98ocsA/uJdKzd61eZLr4BQKExdA0Zoru8O9xQcoaO6zEk2fCzLI99docslDo51S/4tMqwh4hJlAHBQXVPWNFOfvaK0ka88lB+JVJoDg3gmKD102l4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728055897; c=relaxed/simple; bh=v7Zre/YaKbj6+fKD4qjivVod2+NDqTOIOtfVJGW7Y7o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WhYhj30ykwmF9w5oeQsCnNcctK+1QAl/SSh05QTmsr1BWpqmy8o2UAWJtwVWlLbWT7tQ7r/qyGpcnSC8h7wlJ5xuEMqonODZp3WH2psQ4UatB7VWaKvNp+BNcIru/soLzrfOWqEFvvCo1UTaC8DTdkA4DSR3yMwGURGIeJaDRBs= 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 73CFE153B; Fri, 4 Oct 2024 08:32:05 -0700 (PDT) Received: from e122027.cambridge.arm.com (unknown [10.1.25.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B6B2C3F7C5; Fri, 4 Oct 2024 08:31:31 -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 , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" Subject: [PATCH v5 43/43] KVM: arm64: Allow activating realms Date: Fri, 4 Oct 2024 16:28:04 +0100 Message-Id: <20241004152804.72508-44-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241004152804.72508-1-steven.price@arm.com> References: <20241004152804.72508-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: quoted-printable Content-Type: text/plain; charset="utf-8" Add the ioctl to activate a realm and set the static branch to enable access to the realm functionality if the RMM is detected. Signed-off-by: Steven Price --- arch/arm64/kvm/rme.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c index 1c67d2ccdaa9..d8e0a447e0cc 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -1194,6 +1194,20 @@ static int kvm_init_ipa_range_realm(struct kvm *kvm, return realm_init_ipa_state(realm, addr, end); } =20 +static int kvm_activate_realm(struct kvm *kvm) +{ + struct realm *realm =3D &kvm->arch.realm; + + if (kvm_realm_state(kvm) !=3D REALM_STATE_NEW) + return -EINVAL; + + if (rmi_realm_activate(virt_to_phys(realm->rd))) + return -ENXIO; + + WRITE_ONCE(realm->state, REALM_STATE_ACTIVE); + return 0; +} + /* Protects access to rme_vmid_bitmap */ static DEFINE_SPINLOCK(rme_vmid_lock); static unsigned long *rme_vmid_bitmap; @@ -1343,6 +1357,9 @@ int kvm_realm_enable_cap(struct kvm *kvm, struct kvm_= enable_cap *cap) r =3D kvm_populate_realm(kvm, &args); break; } + case KVM_CAP_ARM_RME_ACTIVATE_REALM: + r =3D kvm_activate_realm(kvm); + break; default: r =3D -EINVAL; break; @@ -1607,5 +1624,5 @@ void kvm_init_rme(void) if (rme_vmid_init()) return; =20 - /* Future patch will enable static branch kvm_rme_is_available */ + static_branch_enable(&kvm_rme_is_available); } --=20 2.34.1