Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp15465lql; Fri, 12 Apr 2024 02:01:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWc9kQjWa2jMeNfZG3CXv8u0u1+ep3RR6YqZFIvYH1qoekN+02fBq4tKTrt8TcHdgUYfmveJ7gUq0LUdpG2YkU63RhWRrxfp6zIzIdKVQ== X-Google-Smtp-Source: AGHT+IExFf3iLzRybFnrFZVT3R5KHNFAml/84/LQxx5ZCrvQ36oFiofcpQg0Asxc9g3xgluhCAs8 X-Received: by 2002:a17:906:c445:b0:a51:e43b:cb20 with SMTP id ck5-20020a170906c44500b00a51e43bcb20mr1495306ejb.41.1712912509462; Fri, 12 Apr 2024 02:01:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712912509; cv=pass; d=google.com; s=arc-20160816; b=fTYn/yiaywIBjNKCiruqPVi0B/Pv6f2DExZJUgag9EUGduF793CZBe8dTSlnN2vtcn ZG838RMQVy1EFCRzqdcGhdyAR1L0tZ9L0MqcqWB/G3T1w99suMESaXXv9xqx0M5KbT8c iXM6OjlPQ2xAZbikEagIZ+b9bpDGBV6Qln51yXqdE9scYYX24qzxsZPfQwd6p/whMOEz 4DpQt0GkSQcdM9MUe74T0Lb79TYbxQUhJbwWc+pSNsvLHZBU5MV+z3aS/j0wnebFpQXN i1eArTSjwlG2oD0P26DL11f3cl0EQ+0F8sw7DUssue7P+yxl+KsksnTEAHl7b9yvQ6ND v2ew== 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=mHrSYRATr0XM1CC8TQcO31V5OeqiiRP8J+ouJxD8HiM=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=MHZzXM1tDy4xNd0U5lunq5TkFuF6FZ0unpu7M1ycSPBeBfRp8yM2GPoLdyTzPx5NdZ wOgRHN7l0AzxbGpRDORRtJItIl/PYcltsy5WtIABw3aOj6cUjyLWfzAy3P/2BxNreQ1+ h/GDXD1yDcGG5UfNF8LCXcjlp71EBVD2Kw6WtJYZR030H+jYcJtNAC6HocY3tyZRTnBS QoKFlzS39C/o3TLZ4Gff15GusKRtid+lrrw6uiwRCkkhvJFSgipY5IsPdSHEb8K1vkaN TJxm/ijk1K6606ujsVtkG0CsR/xrCyILtHUjugL8aKIpkMHvZ99pq9jeC0ks0rCOJBye XP0g==; 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-142316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gt38-20020a1709072da600b00a5210afdacbsi1503337ejc.385.2024.04.12.02.01.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:01:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-142316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142316-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 31ACB1F21597 for ; Fri, 12 Apr 2024 09:01:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A84A135A6F; Fri, 12 Apr 2024 08:45:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCA20135A68; Fri, 12 Apr 2024 08:45:00 +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=1712911502; cv=none; b=lwEsVdjz2HicJDdTQBH0MmGa2afyGXrrbTpVPsI37kgM2BqJw6YaIV81qn4h5T4RfwgrFrem2bYOE6rdeeXlosHUyuWJp0QlLzLh26aGQcdh6oiaB5OUMFwgXYEOMvgdBh5oeAdI+kJemdC0rAi3X2u3r2MC3b7ZMI3ggKRl3t0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911502; c=relaxed/simple; bh=D/cy798s+xsV45CJTqoGeQMFhiJNyrqboCxmbKmTJgo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PHnmaLl2+1A6l28jQFqDvDdUEvvM+MskYS+YW9lxTBNuVjRAap51w40qg1oWZ7Q+P9o3cgdc5kd5maUl8UklNIAKzFlytpn8Sd4MuXTk+Ro3mhOZlmqQuTYnQrsLBWFL59q9xpHA53KjJIuptSTllqZTjlwRwQBvMqXdgtXNnrA= 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 B12CC339; Fri, 12 Apr 2024 01:45:29 -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 551093F6C4; Fri, 12 Apr 2024 01:44:58 -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 43/43] KVM: arm64: Allow activating realms Date: Fri, 12 Apr 2024 09:43:09 +0100 Message-Id: <20240412084309.1733783-44-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 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 93aab6caddf5..5901d57ca9d0 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -1167,6 +1167,20 @@ static int kvm_init_ipa_range_realm(struct kvm *kvm, return ret; } +static int kvm_activate_realm(struct kvm *kvm) +{ + struct realm *realm = &kvm->arch.realm; + + if (kvm_realm_state(kvm) != 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; @@ -1314,6 +1328,9 @@ int kvm_realm_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) r = kvm_populate_realm(kvm, &args); break; } + case KVM_CAP_ARM_RME_ACTIVATE_REALM: + r = kvm_activate_realm(kvm); + break; default: r = -EINVAL; break; @@ -1567,7 +1584,7 @@ int kvm_init_rme(void) if (ret) return ret; - /* Future patch will enable static branch kvm_rme_is_available */ + static_branch_enable(&kvm_rme_is_available); return 0; } -- 2.34.1