Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp376257lqp; Mon, 10 Jun 2024 06:56:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvKNkcifGlyL59CDl1XAzEc9A0nnv/Nx23vygiWyNB8zCPpdgshhJR45GVesMAhFpxncirkcgoA4zx9KTet1t79TmsSKl859DQiiOgJQ== X-Google-Smtp-Source: AGHT+IHKoTtmVuBOXeazI/K50BI9yLPYQlQurB914RompyyuUrkbj+AXvug2lDMvTLtgfUxVis7i X-Received: by 2002:a25:8392:0:b0:df4:df29:bcc6 with SMTP id 3f1490d57ef6-dfaf64ee5ffmr9028363276.31.1718027817406; Mon, 10 Jun 2024 06:56:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718027817; cv=pass; d=google.com; s=arc-20160816; b=qCzrIVS8XCoUvaNlx5euqUjDWLyRZaM5QBOd8/Nj0eHu5K5Ts7pXlHvfqvLaPSzQFs siZSQiDfVgun1LYz4Ai1/ixsSgo5Qnm7C0tOwl4oS8tSqWaZ2b07ZVdeZCFaD5Ou1utA hOlFm7fOeRZtiQy64oKsv9lig7tcA0j1WRv6UVwLRRM4r8jhGTdn8Pm7DfhMk+olh4xx rUGANxFQXO57TPZVXfcbZczdnoaQpCG9x6AlERmoTH679eD6eTdO2r3mr39J/5WWw/wB kqAo5618P3YnGP3i/sdBG3Ofkdba7D4bAMTT5UidcAJCnG54h3EQ2C4FVfIrBCU6srUw UfiQ== 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=N8Cn343UuUsjYAEfXGTqUxFOccgnYr305DuTh5lCN20=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=uFkO85cLBhC0oOjxYW7zJ2YHIro9DQh9hiynX2TDnwURfuEe3cb/5HiTo7qDiva8Uc UyO9nNbmjj2Ikc7ZeDnpDadMHqKjcpTefdKTCjdfkqsmU0SGV/SOH9DnOOVZ46uRNdcv pgeoerKcKTHoL2Gt1fL31WVUR7rxSSwDLNUdF+poSkFG2ZtsPhCBPCfildsJ4xjTsG1S semF2uvIOBABcW4QdPC6vDLOSAQsbBYUNWCyPOAuTMLgx18pNGR5MKfn35gM5CrrBLMc fLA2EEOtD7zWkEylASqrkvUv4wDmHOI0VMLSFLfkzKJUZqDvtE+Yhw+Qsz7yM1DFP/1V jO5A==; 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-208292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-4405c5c7c12si53865751cf.631.2024.06.10.06.56.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-208292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208292-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D6BD71C2209E for ; Mon, 10 Jun 2024 13:56:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6E8E158DDF; Mon, 10 Jun 2024 13:44:37 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F6C1158DD2; Mon, 10 Jun 2024 13:44: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=1718027077; cv=none; b=moDAzQ4YGWMJI2wiHAaE6kdb4hx/k1WURbSUfBi6SmQE+bkdB/J+ZCAAHvCZV1TBsVVebEdgAohzgKncy+VaSfNQj1u9KJ3AkzSLjxQDbHhm610UeYhS3HHW5iRmd9JANejN9PqQXgvhukkFHq1/D9dGxJpBkdx81FFV2W5tZMM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027077; c=relaxed/simple; bh=uoNwxgt5fh5rXMXudi0G/6niClMESCEFp788rauQzyI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=irYpCx5lwc0Dtz8tTIkm9UtDeES0ENoLldbpubeN5pSKRzi8+Pl7w8e/YR2f0sS9LdXnXTXM3Hg2+1eqSHJJXLdXP3cBMRMSCqRcnkcA2Xgj8arhKl3qcpLpYqRFIsJMkRELUuUhPv2izIxeTUC9OT8aArZLQfw3t1+ILi8/R4I= 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 4F9EB106F; Mon, 10 Jun 2024 06:45:00 -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 A51F23F58B; Mon, 10 Jun 2024 06:44:32 -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 43/43] KVM: arm64: Allow activating realms Date: Mon, 10 Jun 2024 14:42:02 +0100 Message-Id: <20240610134202.54893-44-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 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 3f2e2aa4ceac..60b41b79db1b 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); } -- 2.34.1