Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp14565lql; Fri, 12 Apr 2024 02:00:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV0sHP3EenBugrfqzYSGJGHxuPG4CU4R+0IWL8KKYhFmmCC6LERJRI3fMw339RKckTpkWfI8rzurq8WSgUjDuDiQBOZt3XOm1RxOCjOFw== X-Google-Smtp-Source: AGHT+IF+RbfQcg4rnDD0nGXioNi2GWQf++quvwyZiGU4op1Y3abKUBm0T1I2xoiVwkJ3qBPmPiXG X-Received: by 2002:a05:6512:e8b:b0:512:e02f:9fa7 with SMTP id bi11-20020a0565120e8b00b00512e02f9fa7mr2014326lfb.1.1712912424386; Fri, 12 Apr 2024 02:00:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712912424; cv=pass; d=google.com; s=arc-20160816; b=w6KiZFkVP1+VIP4JjV64sU349JpS1z2RRjkJK+K/Ox98LhqU8iqcTjIMwfzLwEhvrW wP+CH9pYpBklgavOl+NKHwc4IiufClom0lZR1mDriUMNdwheKbPlxDK5kI7VrB+jII2b 60esQzfF1N/2MjLtWBwt/s6cjjYsbb2IURBQq4eehi+zmQk9mEwQ0/MeCIwlv++I2ueL WJZoTQKY68oNn8URxf7cIOB8zBpmlJTq+LnkrFU9W4txFCzR8Y5I0gG1tpP/lKFxuk40 Qc4Xor8m0DibdxhulfUAUjx53ffwky9ooseWbr+0uQfcb5XJGl0dboiZsMHnwNwTuyLS jHzw== 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=xHe6mbJDRiYHDzNJzwpBfJ3uB3jvyZ9AR2jMlR+nqxo=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=reOlJeLq9dKTnSQ+WrITTiLCClEKK7cWj/V4UuNI5qSlSrdt6EPcx8NRdi1fUaxj9D YlYOcWEO5kJkgiWuCDPTOWLf6lr+aD2c0SKY7llXtmuNkzqOtb+YeQOffumffgVxeoTr uepChTMffNzc1phV5TTkgiBCLNtnIS3QXZi6UIUzDZmGa/v+r5rPysVYJgX2WP091Oec hpHA28YkZFNciTV/Q1k8RyaG7SE3ryve1GL8MgMQ2o+BzDn8appLgjbMwiYYVyx9PIqU 9oAKUNNzAXmi9RKtP7pfNjDiyVF2pBq4ADD+pRxIDxik2Hr9Gw+ZR3ql9yAQjFRhnNnZ cTJg==; 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-142311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142311-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 ga38-20020a1709070c2600b00a51dc7f6d40si1507323ejc.1026.2024.04.12.02.00.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:00:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142311-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-142311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142311-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 1FF231F22EDF for ; Fri, 12 Apr 2024 09:00:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37C0F1332B5; Fri, 12 Apr 2024 08:44:51 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9DF6132C17; Fri, 12 Apr 2024 08:44:48 +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=1712911490; cv=none; b=tnDbglNEeco5Sk0KwmeD9+ssx7cFkWNv65vrssp4Jl5D6dRPoVDmyKm1Ivthj+wDokbtRQL0vHI//7fU10FTDEgr4e9Ss/ujsUw+kkI/wXFAD1hic95jK1dOkcc9AjHz5bZeXsMC7URRxzK3p/lGgKM5jxNmMFWM/9yqVSI8MXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911490; c=relaxed/simple; bh=m+9cJgjGzA7LdPc3k84LebPV2YwdwuGE6OTMivgQDLU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lmj4XfzPhjR7Y65w5/uNUFNJLLFGNGVaOhXZy/5FgX7DOwzmPV87vqsUiuI2Qy5p774SwK5L/bfptXmZw9Ri9Z8UGaI2qyn8x2n8w4DcINWg11b1qUrgqcblKMuhOEVaA2W7VVHC4gVhlK5sgur78Ty6cyHgrtWQO18cDPZD7BE= 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 9AB65339; Fri, 12 Apr 2024 01:45:17 -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 200173F6C4; Fri, 12 Apr 2024 01:44:46 -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 38/43] arm64: RME: Propagate max SVE vector length from RMM Date: Fri, 12 Apr 2024 09:43:04 +0100 Message-Id: <20240412084309.1733783-39-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 RMM provides the maximum vector length it supports for a guest in its feature register. Make it visible to the rest of KVM and to userspace via KVM_REG_ARM64_SVE_VLS. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/include/asm/kvm_rme.h | 1 + arch/arm64/kvm/guest.c | 2 +- arch/arm64/kvm/reset.c | 12 ++++++++++-- arch/arm64/kvm/rme.c | 6 ++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index f7ac40ce0caf..902923402f6e 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -76,8 +76,8 @@ static inline enum kvm_mode kvm_get_mode(void) { return KVM_MODE_NONE; }; DECLARE_STATIC_KEY_FALSE(userspace_irqchip_in_use); -extern unsigned int __ro_after_init kvm_sve_max_vl; int __init kvm_arm_init_sve(void); +unsigned int kvm_sve_get_max_vl(struct kvm *kvm); u32 __attribute_const__ kvm_target_cpu(void); void kvm_reset_vcpu(struct kvm_vcpu *vcpu); diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h index 9c00bcb018f8..be24be001aaa 100644 --- a/arch/arm64/include/asm/kvm_rme.h +++ b/arch/arm64/include/asm/kvm_rme.h @@ -89,6 +89,7 @@ struct realm_rec { int kvm_init_rme(void); u32 kvm_realm_ipa_limit(void); u8 kvm_realm_max_pmu_counters(void); +unsigned int kvm_realm_sve_max_vl(void); u64 kvm_realm_reset_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, u64 val); bool kvm_rme_supports_sve(void); diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index f9a47ce71a26..c62fda66cdc5 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -355,7 +355,7 @@ static int set_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) if (vq_present(vqs, vq)) max_vq = vq; - if (max_vq > sve_vq_from_vl(kvm_sve_max_vl)) + if (max_vq > sve_vq_from_vl(kvm_sve_get_max_vl(vcpu->kvm))) return -EINVAL; /* diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index 6e6eb4a15095..a90b7c2d35bb 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -45,7 +45,7 @@ static u32 __ro_after_init kvm_ipa_limit; #define VCPU_RESET_PSTATE_SVC (PSR_AA32_MODE_SVC | PSR_AA32_A_BIT | \ PSR_AA32_I_BIT | PSR_AA32_F_BIT) -unsigned int __ro_after_init kvm_sve_max_vl; +static unsigned int __ro_after_init kvm_sve_max_vl; int __init kvm_arm_init_sve(void) { @@ -73,9 +73,17 @@ int __init kvm_arm_init_sve(void) return 0; } +unsigned int kvm_sve_get_max_vl(struct kvm *kvm) +{ + if (kvm_is_realm(kvm)) + return kvm_realm_sve_max_vl(); + else + return kvm_sve_max_vl; +} + static void kvm_vcpu_enable_sve(struct kvm_vcpu *vcpu) { - vcpu->arch.sve_max_vl = kvm_sve_max_vl; + vcpu->arch.sve_max_vl = kvm_sve_get_max_vl(vcpu->kvm); /* * Userspace can still customize the vector lengths by writing diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c index 1bd97e206846..cd5b74aac092 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -276,6 +276,12 @@ u8 kvm_realm_max_pmu_counters(void) return u64_get_bits(rmm_feat_reg0, RMI_FEATURE_REGISTER_0_PMU_NUM_CTRS); } +unsigned int kvm_realm_sve_max_vl(void) +{ + return sve_vl_from_vq(u64_get_bits(rmm_feat_reg0, + RMI_FEATURE_REGISTER_0_SVE_VL) + 1); +} + u64 kvm_realm_reset_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, u64 val) { u32 bps = u64_get_bits(rmm_feat_reg0, RMI_FEATURE_REGISTER_0_NUM_BPS); -- 2.34.1