Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp14873lql; Fri, 12 Apr 2024 02:00:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVK+cCBN1KpiyQwyDMXB7YmhhuLj87Tk4qXmmZOyvdQ/53tdTBxuG2kXCG8zmgKh8iWQ5trMGshozttM2+1xB4TKOA60rpFy23OA9KO8w== X-Google-Smtp-Source: AGHT+IGVEJpBCTYwTjrScZd106QMIVowLo5cWydjOCjKUOBQjoPSg+7gT7B29hRP1unTCkwHFEWj X-Received: by 2002:a05:6214:3206:b0:69b:51d7:b97d with SMTP id qj6-20020a056214320600b0069b51d7b97dmr3629764qvb.0.1712912450582; Fri, 12 Apr 2024 02:00:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712912450; cv=pass; d=google.com; s=arc-20160816; b=X1pyvzi3W7Np4tY+ak1CZMwBsTP0n1M+vfqQcu+eOtBKMwg9tHwrc4S2tuHxq88zIy 1LcsEaMmZBkKCsa8T/NZK3a16tMaQxirnFKV5tI7N1FF0TAAIcV/LoUoDpdWiSbcGawy nA5lrChOxwdmXKBjXrhRP70FaS+vL7bvxI29xQ48Gtc++s0BrWasnEMDisfv6LTmvcb1 ckhScJzXfAKVGVvhKOahdXUTwgQcjE/oI4aCgtwCM3GAdLEjtWLwaTQgkCsUSAJQJKWC +PX6w7yhP4cLVjKH/EWMnUwYq1GyEWljbZm/+WO+MO3v96UkzSDT8GXNOmD3OGny6KkB BG8w== 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=bEj7cTYEK4sSBwgFmW0t68jGoikPxHbR1M7n82HEI0k=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=FcbFbALVEofglpVkQjR+KxbAOSU1Z+MBzxelrvdAvN418KR+HP9vWGZo4o1JRhYpw4 yZUWGqYATwakGnI2awSQVPuwDeIpnL7eemzmYlDawSEz7j4JAAXtFoxiUw7BSZxF38vB vIXenAqhbZKpX+lCC3SVrpG9LBnJnhGyySeZ8HjgCR3fWS34+j5iyg/3BeTHHwacplMM +nva9CtB0Cf5hxOvVEhb4d1+D9ZU8+GURHViwfCGsMg7U0M/rtmEPeDlJspcAvkfDtl6 UGVTBVaJ60j6d8SEyWsjI9k3ne3dVO1beiH52G43xkYR8oUR9vRy4Z8bCvnBj/KGYQ84 FqNg==; 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-142312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142312-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. [147.75.199.223]) by mx.google.com with ESMTPS id s14-20020ad4438e000000b006992d3d4c15si3221366qvr.544.2024.04.12.02.00.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:00:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-142312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142312-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 0F6C21C240B3 for ; Fri, 12 Apr 2024 09:00:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EF5D134425; Fri, 12 Apr 2024 08:44:53 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6685D1332BE; Fri, 12 Apr 2024 08:44:51 +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=1712911492; cv=none; b=hyqMRNCNNzkw/Gpjxc61+fY0/oEdr4/8gjCidPxTKc0pNZO/dA3X/PIzC40iBPee2jpalGtq6xzB8bn42FjOoW29xuAa74my1bVwuSGbCTAM47Aht31O0K1TDAx9qHj7tdVSzi2s/vw7TglbNVeco4Kbn0kx2sOb2mQ+TEpFQK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911492; c=relaxed/simple; bh=jK3I1UttB3DMkSsQs5PTipMLeoFYFrmrDDLE2mQqeeM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WA84XAeLPeR9WLPfUBjxh/3ddS2MLN20lJXy+fk2mJOwel3L7mTNMYP7N6Nf2jzMhW3Hpw5FftXyOpKKFKhB62bZMPg0CGkGbXdNW72yHKsUIPpSkMNH5XBodbLOwQKFD37zOI/mULopQTjep4RD5jtFtH0CryqeEGlYnAeAgZk= 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 13347339; Fri, 12 Apr 2024 01:45:20 -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 913DD3F6C4; Fri, 12 Apr 2024 01:44:48 -0700 (PDT) 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 , Steven Price Subject: [PATCH v2 39/43] arm64: RME: Configure max SVE vector length for a Realm Date: Fri, 12 Apr 2024 09:43:05 +0100 Message-Id: <20240412084309.1733783-40-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 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 --- arch/arm64/kvm/guest.c | 3 ++- arch/arm64/kvm/rme.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index c62fda66cdc5..d72e59e79185 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -341,7 +341,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)) @@ -807,6 +807,7 @@ static bool validate_realm_set_reg(struct kvm_vcpu *vcpu, switch (reg->id) { case KVM_REG_ARM_PMCR_EL0: case KVM_REG_ARM_ID_AA64DFR0_EL1: + case KVM_REG_ARM64_SVE_VLS: return true; } } diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c index cd5b74aac092..93aab6caddf5 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -309,6 +309,44 @@ static int get_start_level(struct realm *realm) return 4 - stage2_pgtable_levels(realm->ia_bits); } +static int realm_init_sve_param(struct kvm *kvm, struct realm_params *params) +{ + int ret = 0; + unsigned long i; + struct kvm_vcpu *vcpu; + int max_vl, realm_max_vl = -1; + + /* + * 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) { + mutex_lock(&vcpu->mutex); + if (vcpu_has_sve(vcpu)) { + if (!kvm_arm_vcpu_sve_finalized(vcpu)) + ret = -EINVAL; + max_vl = vcpu->arch.sve_max_vl; + } else { + max_vl = 0; + } + mutex_unlock(&vcpu->mutex); + if (ret) + return ret; + + /* We need all vCPUs to have the same SVE config */ + if (realm_max_vl >= 0 && realm_max_vl != max_vl) + return -EINVAL; + + realm_max_vl = max_vl; + } + + if (realm_max_vl > 0) { + params->sve_vl = sve_vq_from_vl(realm_max_vl) - 1; + params->flags |= RMI_REALM_PARAM_FLAG_SVE; + } + return 0; +} + static int realm_create_rd(struct kvm *kvm) { struct realm *realm = &kvm->arch.realm; @@ -355,6 +393,10 @@ static int realm_create_rd(struct kvm *kvm) params->flags |= RMI_REALM_PARAM_FLAG_PMU; } + 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)) { -- 2.34.1