From patchwork Fri Jan 27 11:39:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787450wrn; Fri, 27 Jan 2023 03:44:29 -0800 (PST) X-Google-Smtp-Source: AK7set8JOkkFjGHl3z8J9xbZITXA21OB/2QSaravydyWdIerul6PrQB0t7rCtzC0HO8fJb+gPv4O X-Received: by 2002:a17:90a:1ca:b0:22c:491b:2cd7 with SMTP id 10-20020a17090a01ca00b0022c491b2cd7mr2500959pjd.34.1674819869550; Fri, 27 Jan 2023 03:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819869; cv=none; d=google.com; s=arc-20160816; b=vf/pb7lkbU0NEgZNtLrvCJrrZPGCLrQzwfQjepKllaowiEB2066bbX+b9htqBDQM6i ceurE6cLngIiLUsE8uy2Ny4SWCJ2cR3IjJgddADIo1a5cOc6KbEtGA3b9879/57wQqr9 OdwSYo5vbbQDXXwmJvu7IQXMGwNMJrx3aMzyNrdtZXGwmlbyfp8V5HnMNKaeUu3phZ6P PcrXN8Nu774zOPBhcJOraWCBHuxo/ccKgeV79niNQ0xbdHWyJFo0h+YXBym1pnd62yfN gf31CZpMB3trJ/Dcpiw8iZKMKYpP1h6abLNx5/jkehlqRgUc2jOjvwLDJlY1L/awleN3 FMsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0ARYFgRneShivPkrtFFWMnz/Btm+510ZFPhm33jy+fM=; b=il6vceXXp/jlACHgFVDufhiQv/apyRMgUf++3MoDFUmUsb3asiPJkTL1DuuCVBr2/f DDLsGz2NR0HsFQvYub8IDgrx5LuxYjTb5X9rDNJ+2n4S1grrOqckz/nhNgx98QwFG9X3 yVaMYOSPlHRxtJIK06d9qsGPtDhI6XQaq5XMfsiwJI9usJRxIBRYqZYvDlIiQSdKtaib 7y04Xbv+xz+sIiyGfGKVlYgXZZAuecGp3ai6WI9W9uNbwElanz1c3OV9Csstzp+VzZcl cvUBgU2bkKazNpySDlp4ewICTvp11cZ6/bNkURESYDUz7zbDPpCwkDsq/wzpgaJz9dFV savg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p28-20020a637f5c000000b004e0d688fb84si805605pgn.847.2023.01.27.03.44.16; Fri, 27 Jan 2023 03:44:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231996AbjA0LmA (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232834AbjA0Ll2 (ORCPT ); Fri, 27 Jan 2023 06:41:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E971C78ACD; Fri, 27 Jan 2023 03:41:05 -0800 (PST) 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 6EDC71763; Fri, 27 Jan 2023 03:41:16 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E5B2D3F64C; Fri, 27 Jan 2023 03:40:31 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 16/31] arm64: Add support for specifying the SVE vector length for Realm Date: Fri, 27 Jan 2023 11:39:17 +0000 Message-Id: <20230127113932.166089-17-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175919583242915?= X-GMAIL-MSGID: =?utf-8?q?1756175919583242915?= Add option to specify SVE vector length for realms. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 6 ++++-- arm/aarch64/kvm.c | 23 +++++++++++++++++++++++ arm/aarch64/realm.c | 21 +++++++++++++++++++++ arm/include/arm-common/kvm-arch.h | 1 + arm/include/arm-common/kvm-config-arch.h | 1 + 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index f2e659ad..0f42c2c2 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -29,8 +29,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Realm Measurement algorithm, default: sha256"),\ OPT_STRING('\0', "realm-pv", &(cfg)->realm_pv, \ "personalisation value", \ - "Personalisation Value (only) for Realm VMs"), - + "Personalisation Value (only) for Realm VMs"), \ + OPT_U64('\0', "sve-vl", &(cfg)->sve_vl, \ + "SVE Vector Length the VM" \ + "(only supported for Realms)"), #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 4798e359..fca1410b 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -51,13 +51,19 @@ static void validate_mem_cfg(struct kvm *kvm) } } +#define SVE_VL_ALIGN 128 + static void validate_realm_cfg(struct kvm *kvm) { + u32 sve_vl; + if (!kvm->cfg.arch.is_realm) { if (kvm->cfg.arch.measurement_algo) die("--measurement-algo valid only with --realm"); if (kvm->cfg.arch.realm_pv) die("--realm-pv valid only with --realm"); + if (kvm->cfg.arch.sve_vl) + die("--sve-vl valid only with --realm"); return; } @@ -76,6 +82,23 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; } + sve_vl = kvm->cfg.arch.sve_vl; + if (sve_vl) { + if (kvm->cfg.arch.disable_sve) + die("SVE VL requested when SVE is disabled"); + if (!IS_ALIGNED(sve_vl, SVE_VL_ALIGN)) + die("SVE VL is not aligned to %dbit\n", SVE_VL_ALIGN); + kvm->arch.sve_vq = (sve_vl / SVE_VL_ALIGN) - 1; + } else { + /* + * Disable SVE for Realms, if a VL is not requested. + * The SVE VL will be measured as part of the parameter + * and we do not want to add an unknown entity to the + * measurement. + */ + kvm->cfg.arch.disable_sve = true; + } + if (kvm->cfg.arch.realm_pv) { if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) die("Invalid size for Realm Personalization Value\n"); diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 2e0be982..fc7f8d6a 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -42,10 +42,31 @@ static void realm_configure_rpv(struct kvm *kvm) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV"); } +static void realm_configure_sve(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item sve_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_SVE, + .sve_vq = kvm->arch.sve_vq, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&sve_cfg, + }; + + if (kvm->cfg.arch.disable_sve) + return; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) SVE"); +} + static void realm_configure_parameters(struct kvm *kvm) { realm_configure_hash_algo(kvm); realm_configure_rpv(kvm); + realm_configure_sve(kvm); } void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index 68224b1c..41b31f11 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -114,6 +114,7 @@ struct kvm_arch { cpu_set_t *vcpu_affinity_cpuset; u64 measurement_algo; + u64 sve_vq; }; #endif /* ARM_COMMON__KVM_ARCH_H */ diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 80a3b18e..d923fd9e 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -19,6 +19,7 @@ struct kvm_config_arch { u64 fw_addr; bool no_pvtime; bool disable_sve; + u64 sve_vl; }; int irqchip_parser(const struct option *opt, const char *arg, int unset);