Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp269686lqr; Wed, 5 Jun 2024 05:48:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXTuYAudutIvkJltD1q0KY4SgWQIjalEs0TXSZEdtRI3KCRY6ByGiowZmy5SGh5bJfXMCsYQci5l6fHD3gnwdOOrYhFDEt5AU3EDmJESA== X-Google-Smtp-Source: AGHT+IGQM81d0QQ/wUG9p5aCArxXT0cCKPXsjFW4EJnI2SyjHWUJbkhi+qeQ2ff/XvSXFXeqyy6H X-Received: by 2002:a05:6a00:2da2:b0:6ed:1c7:8c4d with SMTP id d2e1a72fcca58-703e5950b38mr2930091b3a.12.1717591711148; Wed, 05 Jun 2024 05:48:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717591711; cv=pass; d=google.com; s=arc-20160816; b=i90Fk5oUHExecOWlZANd7WK5677Y5ykXSnOB/R9uTy5dAPm8Up+86XZpUR294FmfDX Aj23fUoVptFX5QMKFPIDkpnwwFZpMPISvIwTJQhb/Bj65fT9ay40hSOb0DuhaT/Zsu/T BAq3v6oUN1SzLIDMezjNKsg4w8O6fHbpOzLA5a1UGwGFhAwe0LcQEUoxNmSxqzt435b2 vpDyb5NjRZVRCZI2bPPkDMpaz6EFHdlikTFQrY0kUrVBAcq3I50ebU2T0w/pt19V8PDi mNBcsXdn22/vFFW5zmbr0+8jmlJ8K5c62RPJ/tKkcB8aDDySveMjhAC5130jyT5la2C9 1aqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=sfU5RvgXa6noLSObezkjdqjtTZtf5TE3PhxYWpHDRm8=; fh=lk72TayQYyg3Xc4B4MVX1u8AokMhudr2Z5q6U7S4iWM=; b=Py0F5KF+E6UaoFZ88saYabZ/uVeWqqjWFZcMLeiJs8NUYsRNd1pp1HVglkJoBlwsMN 5r3KjUV0Qmb5kONvZcqPQtbCpDzcscfE4mvOMZ5FWq0SVjqUPydnB6GeABl6AWRFZl65 tIyKgjUyDsx2gQmnqfFGgJjg2o14bfT7Qx8tyo/8vrAsw3vUuFPvuE48FT3c5gD0JCxT wBWPAD7zfL6AOF1cbIiLSwAeqyWAJrXoXYkFNGGU+3SCo6rlgDRdO/2Yc4+hPx3az35T OiOxwqGKEWAgSKR4vEuGWNM8SWtnUaDDFAOPdocoP6+5K961FeRDFez7s9llwtigDMgh 8FWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WDMaeJy1; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-202493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c50c0cae44si9100946a12.192.2024.06.05.05.48.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:48:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WDMaeJy1; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-202493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 F089428445F for ; Wed, 5 Jun 2024 12:39:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90C5F1C5380; Wed, 5 Jun 2024 12:03:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WDMaeJy1" Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AED51A36A6 for ; Wed, 5 Jun 2024 12:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717589036; cv=none; b=Hg/uDL3smujcK0YmhJDvI9PbEhHFy9IBYo/SfaKChNm+Y6mRo76zT+9EtRf3yH6bKv7cjkWLOiWMwOm4uyqMEJ0l0EUPwxEUUgb3zNBAJS4s9kc4jQLBQtrcGp4tSHz/kfmLBs5OlH+usPf6uJmqtlJS5J/Csu/11v1vFQGONYc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717589036; c=relaxed/simple; bh=6XXxWiOiR+u276GHgRQbO10d9sLX/iCBmrOC3KZAeNQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=gjmqkPMmkjtDoUh4/n6LXfnoWty+pOB7BgtJ+7QBWwdd4uB/qpMy3fQjwjRLdsp4yEcsyoFgJnkTmKYqcrrFgI1CTOjavGk/2sl8HZN4qeBd4EKFqSyKvaja28uPzQi54OTL28XjWpazz/PLxLODr4f9GOH3tO/+EtHkEjqw4aw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WDMaeJy1; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3d1fd550871so1049186b6e.2 for ; Wed, 05 Jun 2024 05:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717589034; x=1718193834; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sfU5RvgXa6noLSObezkjdqjtTZtf5TE3PhxYWpHDRm8=; b=WDMaeJy10JNtsLcgTKRJ8T0lwwOqBMTHWF15IDYex+6uoaC8fhtwXm6+T+wawtlZP1 +fgW7WZCtHgO+GPERMuzbUJAb6nzV0SJYLLvfxizbEToQl/vxGGyNsbHwh7DACQVo6Oj oHegMfcFSzK3QW9b2REReGCLu41pmjriTRznNXDugI2kJnWY/D92KIuJH5rdmf8nrsJL aJ+mI89uk8BTTgAibAj3q2tl2Awbaqu4FfWhciRPikZYwO5hmAIzOuKPd2dmniY+QQMX 9+KvDlW6catdJrLz1HCBKWse6OaSctsp/jk58feW70ita/6If7ZFHMGwhMA/uosewtu7 POrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717589034; x=1718193834; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sfU5RvgXa6noLSObezkjdqjtTZtf5TE3PhxYWpHDRm8=; b=CS4xK4BVoQBVZNB7tYWWjxHUc3KCDt0OjmhbWRruHFAB81hsggEsW8UBw/cUuV1PZf DzImcYYmvfEovBu2lxTl2v82taFlzjTykFXRV5f3rf10ELP+7cG13RyWAF9Bsutz8eYK z+ZxdshLgKMvrTOA8+x53BykVA/R7bBOs1bq/dyP39CW4nO2iTsDFYU9uWDJGeF7SR9+ byZmaMJ0m0kArZcRxR/eMQAx/oBTmvQqV8j3PQm7qRTkpEKvPCRXdoxebfkkOmhGPVMm fKpCIxsx/b6KPe48m0pveFVou35rqeQ2zXwLMMXWxGzIfHmgGG04gCRcShWFL0+Sznuy IYLA== X-Forwarded-Encrypted: i=1; AJvYcCVtkVoM6/561Zn0Qg9yBQkKSrFanlZBchCilz6Xzx4RBrSalMdhYxOcNmjMPJ82c2BKpM9WBmcFZZ28kKarlyR5fg011ipG8/MVuswV X-Gm-Message-State: AOJu0YxrH2IAKuDVoKN90zXhaZGPh0i4p6fkePfI/7GpBOUGVLp/8P6z Iuc/e7xUn5nGaps2jQZXEZ672mW9kYKQyNSkkAaYeHzcUwtHjd7oKQV4SJjJPQ+7FKF5/TW5AwH jfXL0oerOTnYosVWsfd1WN2m3KoeI/SaTTNHc X-Received: by 2002:a05:6808:3081:b0:3d1:fe2e:f896 with SMTP id 5614622812f47-3d20429b7eemr2770398b6e.16.1717589033342; Wed, 05 Jun 2024 05:03:53 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240605-kvm-arm64-fix-pkvm-sve-vl-v1-0-680d6b43b4c1@kernel.org> <20240605-kvm-arm64-fix-pkvm-sve-vl-v1-2-680d6b43b4c1@kernel.org> In-Reply-To: <20240605-kvm-arm64-fix-pkvm-sve-vl-v1-2-680d6b43b4c1@kernel.org> From: Fuad Tabba Date: Wed, 5 Jun 2024 13:03:16 +0100 Message-ID: Subject: Re: [PATCH 2/4] arm64/fpsimd: Discover maximum vector length implemented by any CPU To: Mark Brown Cc: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Mark, On Wed, Jun 5, 2024 at 12:50=E2=80=AFPM Mark Brown wro= te: > > When discovering the vector lengths for SVE and SME we do not currently > record the maximum VL supported on any individual CPU. This is expected > to be the same for all CPUs but the architecture allows asymmetry, if we > do encounter an asymmetric system then some CPUs may support VLs higher > than the maximum Linux will use. Since the pKVM hypervisor needs to > support saving and restoring anything the host can physically set it > needs to know the maximum value any CPU could have, add support for > enumerating it and validation for late CPUs. > > Signed-off-by: Mark Brown > --- > arch/arm64/include/asm/fpsimd.h | 13 +++++++++++++ > arch/arm64/kernel/fpsimd.c | 26 +++++++++++++++++++++++++- > 2 files changed, 38 insertions(+), 1 deletion(-) Actually, I was working on fixing it and was about to send this, which I think might be a bit simpler than what you have. Let me know what you think and I'll send it as a proper patch if you agree: diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsim= d.h index bc69ac368d73..8bde13b7faa3 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -184,6 +184,9 @@ struct vl_info { int max_vl; int max_virtualisable_vl; + /* The maximum vl encountered for any cpu in the system. */ + int max_system_vl; + /* * Set of available vector lengths, * where length vq encoded as bit __vq_to_bit(vq): diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 82e8a6017382..e0af4c3c9a40 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1006,7 +1006,7 @@ int sme_get_current_vl(void) static void vec_probe_vqs(struct vl_info *info, DECLARE_BITMAP(map, SVE_VQ_MAX)) { - unsigned int vq, vl; + unsigned int vq, vl, max_vl =3D 0; bitmap_zero(map, SVE_VQ_MAX); @@ -1031,7 +1031,12 @@ static void vec_probe_vqs(struct vl_info *info, vq =3D sve_vq_from_vl(vl); /* skip intervening lengths */ set_bit(__vq_to_bit(vq), map); + + if (!max_vl) + max_vl =3D vl; } + + info->max_system_vl =3D max((int) max_vl, info->max_system_vl); } /* diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index 3fc8ca164dbe..9f751cce8081 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -52,7 +52,7 @@ int __init kvm_arm_init_sve(void) { if (system_supports_sve()) { kvm_sve_max_vl =3D sve_max_virtualisable_vl(); - kvm_host_sve_max_vl =3D sve_max_vl(); + kvm_host_sve_max_vl =3D vl_info[ARM64_VEC_SVE].max_system_v= l; kvm_nvhe_sym(kvm_host_sve_max_vl) =3D kvm_host_sve_max_vl; /*