From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0375CA0ED3 for ; Mon, 2 Sep 2024 10:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zaCnBoKysbnyn0ehV4gS5/QoP83damS/4vcHmMGjQg4=; b=lECfroMswgd1CFSYx4s5XVpG1z W1iOgcunJM9LZYnBEGd4Z0vJqCyxAh/iZmeTie0pZhVwc4p14t3MomWnfiulTsD/nAOs80sYFD1VU 8U7+4cD9/2yDC385bMP7dcqvwOhlb1U9XqFSp4RpkDLSgTt+QyLWcBQxHYLFb/AIwKrwQODEKCXyp B4xD4JTc6ZHgUY7KcSQTdMotbFSxubUF9wcVOm2fAWG8iI5xBa2PLrfVhWDP0JLWWx+oTb1sUyaNM UNAYeliqhZ6H6wWtGXgFbxU+A8u+uAc2n8F1xsQ+LLEIMC0nsjvW7ooV/+IWcMco00Dc31HBe4VbH RLSw/hcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sl4Ec-0000000Dthe-2G4e; Mon, 02 Sep 2024 10:24:34 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sl47f-0000000Ds89-38Xn for linux-arm-kernel@lists.infradead.org; Mon, 02 Sep 2024 10:17:26 +0000 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 71BE5FEC; Mon, 2 Sep 2024 03:17:46 -0700 (PDT) Received: from [10.57.74.147] (unknown [10.57.74.147]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0F6A63F66E; Mon, 2 Sep 2024 03:17:15 -0700 (PDT) Message-ID: Date: Mon, 2 Sep 2024 11:17:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 43/43] KVM: arm64: Allow activating realms To: "Aneesh Kumar K.V" , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: 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 References: <20240821153844.60084-1-steven.price@arm.com> <20240821153844.60084-44-steven.price@arm.com> From: Steven Price Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240902_031723_864534_054396BA X-CRM114-Status: GOOD ( 20.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 02/09/2024 06:13, Aneesh Kumar K.V wrote: > Steven Price writes: > >> 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 9f415411d3b5..1eeef9e15d1c 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); >> } >> >> +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; >> @@ -1343,6 +1357,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; >> @@ -1599,5 +1616,5 @@ void kvm_init_rme(void) >> if (rme_vmid_init()) >> return; >> >> - /* Future patch will enable static branch kvm_rme_is_available */ >> + static_branch_enable(&kvm_rme_is_available); >> > > like rsi_present, we might want to use this outside kvm, ex: for TIO. I'm struggling to think why rme_is_available would be needed outside KVM - what is "TIO"? > Can we move this outside module init so that we can have a helper > like is_rme_supported() It's obviously possible, but I'm not sure where in the code it would go - if there is an actual use case outside of KVM then presumably it would need to move completely outside of the KVM code. Can you elaborate on why you think it might be useful? Steve