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 EF1ADC4450F for ; Wed, 15 Jul 2026 14:32:02 +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: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=r6r13MC+Md2jLd7QAiyAsVZRBvoSKi+lyDT+GsFQBcw=; b=HbY2CkauQ25I9vOno2sZngKodX kFDS2JjFyzIXZjLpnmYZ/A8xZRpR738MHhnDbJCXBP9LEV0EJkrLmUFY/dm3r3f9oZOCyjUpmMxua tjKqc7KyhfbJBJXKgsCeclpO1P5Zlhcm7Cn7hx6JtKoo0EFsTSjliacylyv5B9KkRbMAZTONR706C hAq5iOHvX2oIgqqV514uvCJQRCkZGsUMS2ILNnGQn4nsO7eV1x3tvFvofYs1o6gxv+isCsZrjUWk6 1YoRhmyHSICy2oJL7A8jY6DweeX7LoKemNnhTxFGMP2bMdgWpoXGKy/7w0KUQkHLfIFZfDXdUWYSL j5SHMx4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wk0eS-0000000FAgE-1eeM; Wed, 15 Jul 2026 14:31:56 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wk0eC-0000000FASL-1xmC for linux-arm-kernel@bombadil.infradead.org; Wed, 15 Jul 2026 14:31:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=r6r13MC+Md2jLd7QAiyAsVZRBvoSKi+lyDT+GsFQBcw=; b=fJ356286fmJsTEX0fBT2KpwH/3 ERD4yU1pB51xHuSiWmcxAMPEhVdl7Tg/t41Llpy4Q3UM6d3UnwfU1vkE8gsHB/9cOqPtW7PS0LBIF m0sOtBaNHr/+z5oFS4DKoyS1PqGvPt4DSxG7npTaCB06Oct7uR/O1/koB2ft92QOZ93fYC4nDvmVo R3uh5Svua+yWDIXd2kMxZe31T8IZo6ZThWSBh0fW+tpBEjKL7PVefGMYFfehL98FgwrfxjApL7PEt MYFOrC9cTZ7Hnrwje+xnY3IHwUIV1I59i8+fsl9rpREEIXHeUvZ/gdKaH1B1f844wTAX4XrDyzagn jbexyLSg==; Received: from foss.arm.com ([217.140.110.172]) by desiato.infradead.org with esmtp (Exim 4.99.2 #2 (Red Hat Linux)) id 1wk0e9-0000000DN3V-11xH for linux-arm-kernel@lists.infradead.org; Wed, 15 Jul 2026 14:31:39 +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 507F61691; Wed, 15 Jul 2026 07:31:32 -0700 (PDT) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.25.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4B5BF3F7B4; Wed, 15 Jul 2026 07:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784125896; bh=75s4kczD+dOim03oKcXS3tFt0Hj0gRBWP1mDhFZaKv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljCXfhJBU0qVumMsidJciB7PkCPOSuN2jrjkN6dcegv0uY+8+XDnfL8G+xxtrByAD +FgSJHz/XvL8wioAFDBdscnD7/sXU3X12W/jwqptiJMnq8+zUNF1VxcpP5mjgNIeYY FAZmYjpoWxavAEcnMg1Kohhg+fcDo9ZDLs0Th2F8= From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Jean-Philippe Brucker , 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" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo Pieralisi , Steven Price Subject: [PATCH v15 34/37] KVM: arm64: CCA: Configure max SVE vector length for a Realm Date: Wed, 15 Jul 2026 15:28:36 +0100 Message-ID: <20260715142841.80544-35-steven.price@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260715142841.80544-1-steven.price@arm.com> References: <20260715142841.80544-1-steven.price@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260715_153137_669520_475B418F X-CRM114-Status: GOOD ( 17.80 ) 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 From: Jean-Philippe Brucker Obtain the max vector length configured by userspace on the vCPUs, and write it into the Realm parameters. By default the vCPU is configured with the max vector length reported by RMM, and userspace can reduce it with a write to KVM_REG_ARM64_SVE_VLS. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Steven Price --- Changes since v6: * Rename max_vl/realm_max_vl to vl/last_vl - there is nothing "maximum" about them, we're just checking that all realms have the same vector length --- arch/arm64/kvm/guest.c | 3 ++- arch/arm64/kvm/rmi.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index f48fc0d5a249..452cf5d3152e 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -361,7 +361,7 @@ static int set_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) if (!vcpu_has_sve(vcpu)) return -ENOENT; - if (kvm_arm_vcpu_sve_finalized(vcpu)) + if (kvm_arm_vcpu_sve_finalized(vcpu) || kvm_realm_is_created(vcpu->kvm)) return -EPERM; /* too late! */ if (WARN_ON(vcpu->arch.sve_state)) @@ -754,6 +754,7 @@ static bool validate_realm_set_reg(struct kvm_vcpu *vcpu, } else { switch (reg->id) { case KVM_REG_ARM_ID_AA64DFR0_EL1: + case KVM_REG_ARM64_SVE_VLS: return true; } } diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c index cc618608f128..3f1c6351b71a 100644 --- a/arch/arm64/kvm/rmi.c +++ b/arch/arm64/kvm/rmi.c @@ -492,6 +492,39 @@ static void realm_unmap_shared_range(struct kvm *kvm, start, end); } +static int realm_init_sve_param(struct kvm *kvm, struct realm_params *params) +{ + unsigned long i; + struct kvm_vcpu *vcpu; + int vl, last_vl = -1; + + if (!kvm_has_sve(kvm)) + return 0; + + /* + * Get the preferred SVE configuration, set by userspace with the + * KVM_ARM_VCPU_SVE feature and KVM_REG_ARM64_SVE_VLS pseudo-register. + */ + kvm_for_each_vcpu(i, vcpu, kvm) { + if (!kvm_arm_vcpu_sve_finalized(vcpu)) + return -EINVAL; + + vl = vcpu->arch.sve_max_vl; + + /* We need all vCPUs to have the same SVE config */ + if (last_vl >= 0 && last_vl != vl) + return -EINVAL; + + last_vl = vl; + } + + if (last_vl > 0) { + params->sve_vl = sve_vq_from_vl(last_vl) - 1; + params->flags0 |= RMI_REALM_PARAM_FLAG_SVE; + } + return 0; +} + static int realm_create_rd(struct kvm *kvm) { struct realm *realm = &kvm->arch.realm; @@ -539,6 +572,10 @@ static int realm_create_rd(struct kvm *kvm) if (kvm_lpa2_is_enabled()) params->flags0 |= RMI_REALM_PARAM_FLAG_LPA2; + r = realm_init_sve_param(kvm, params); + if (r) + goto out_undelegate_tables; + params_phys = virt_to_phys(params); if (rmi_realm_create(rd_phys, params_phys, realm->sro)) { -- 2.43.0