Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp377096lqp; Mon, 10 Jun 2024 06:58:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCURbbqIyKfoy6E9yDjof+gWf/QityL8Jv7TSMf2H/UC/iaYM7YgGToUKAoIn5cGkPUVEkvLasVP9glRzKay8LWsKWc06jK4BKnbGFU8Fg== X-Google-Smtp-Source: AGHT+IGlseNRNaFDQgxy0RcuH99MK+cMpZtF4rDrS7ksSGV9FrdkpHID6Hq8gRwd/c7hRuqYrVCu X-Received: by 2002:a05:6359:45a8:b0:19f:5550:84b2 with SMTP id e5c5f4694b2df-19f555086b6mr236079155d.22.1718027909595; Mon, 10 Jun 2024 06:58:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718027909; cv=pass; d=google.com; s=arc-20160816; b=H9ohSZHvr5fDZAioRlOb/sXFkFnpjD+sc0AVPNAHe4nlNFi5fp1MCle70SAKHtTpp7 VgtonVDDY+Nfb3AoI8CnQjq9mDtD5x6Bh33PWEnHKi9s6+x6P8lp8TDXLxu2B870JrFO +6lxKYHjCi4yLdLK3ZRzUb/lhGvApCQghA6R63wmFnYuixC+zrttXWmcCS9CRuwxT/AL quUSGbGALobnT79mBEt6AsAXDLerGGkNqRyzH4qDKwqCmrKtFc8Af3Msrjiqu2qa/Xk4 EBZlW2jJ/jlj6pZHcrJSjYGBZn3ZH3Nn4zh3qUN/pkTPLDMSBEZXrNjd3/IjcGDmRI9z Th8Q== 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=kyd9Ww8DP8Hr9dCkzEBdMg4L8L7O1agogYPTIhYr6g8=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=QUBsAZrhBgn8Bl0IV/8L2Nt9iNB4TLsMRu8TWoYCAszdCV53EGztsDl9IsGkw7SbKY IPPvvATf6PbDqa1l+LBIVB71quuAibj0bo1IGMbcoTGyocrElQzfg4gx1sNvKFOxWLlr DC3P7buXG1u7uO2H2zE4mV6Mq09LYA5WegvYvA6NhnLUcqtklXixJhFhEVVnSJGqxiHD qIOeVWLqH0rzPS9+wOsoV6Qm63vu93WvttajpiMhc0Ab9eCz2/1GDGC0W2VxoJ4Re2O8 ZwOytchFK1476Es0SiSBf2ZM/bEPK0+EeJiyiyvTalxZiq0YMYT/lgf+Y7NrNp429226 uW6g==; 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-208288-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208288-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de29120aacsi4135658a12.660.2024.06.10.06.58.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:58:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208288-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-208288-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208288-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 560152856BF for ; Mon, 10 Jun 2024 13:55:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1739A158A1F; Mon, 10 Jun 2024 13:44:25 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CEBE158A0A; Mon, 10 Jun 2024 13:44:22 +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=1718027064; cv=none; b=aCtyJeHnNhdpNXHj/UX65w3cNROVC5Qz6zIudgJIfVFa+ShbzEOy+zmyBrxFh3UbOJH/rXOyiCOiTJLianVfAD3nlhTfEgm35fyPFgPaOMyK+HesH3Z4IoTWRQ3EqGWezvGRNYEAvtwF+D4pxhUni/bD8O/cqZTuYLcc9ENm9XM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027064; c=relaxed/simple; bh=lS2pv2PP2r00pTzCYP0YUTaHsWVzLQ8ez4wxurFxbHs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ff9VOc98X/rt6csblQDi7wldGfdw77/9zabjossPnOFMBAoh+lDDOPGOnqMNlKoCfLMIGyWi+M8fHtRvVAz0kC47XgAoS+sjP9QkUUNwN0wleZFq38mVYRN0fhpHAGswg1t1AWMoYBuJtPe3hS103DNhgHZGQSsusDbDg9UQaqk= 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 093861692; Mon, 10 Jun 2024 06:44:47 -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 14C3E3F58B; Mon, 10 Jun 2024 06:44:19 -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 v3 39/43] arm64: RME: Configure max SVE vector length for a Realm Date: Mon, 10 Jun 2024 14:41:58 +0100 Message-Id: <20240610134202.54893-40-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 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 c06098bc5392..e3366c9bdd9d 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 81964d87daa6..3f2e2aa4ceac 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -319,6 +319,44 @@ u64 kvm_realm_reset_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, u64 val) return val; } +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; @@ -366,6 +404,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