From nobody Sun Feb 8 00:12:28 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 1867626F2A1 for ; Fri, 21 Nov 2025 19:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763753734; cv=none; b=uvagz99/50bRDz3oi+Upjk34HMb7JSHIhsirkuyz1vVkkk8z1b7w7bk9HEe8tuBypfIuzfD/WQ0an9qq3UA/7xUX6ItkUMNToCl9ckZy7WiyhgBBOf3N3uiGOjKDHwl61tLpIoeWCQi/hwAAFh+Ayuju0KN0CJwR+62xMxiSd7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763753734; c=relaxed/simple; bh=ssd7trdwb//a6L+Sw+uaGiYPGmeNiBfsFciGwGcYoA0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=KV1ox+tw69excDVTkAX2Sky3qgHRGfofSkm0V1vL5HSMelcmc5jiY1P7KxAmmZdIfMmqMkXdWHcxryVt+GHmXaKVaKMst1yYh3VljzAMaL3a28MqpSn7TVcb7CP/jDzUpG4s4h+fg9nweNNfvGj743aiNkqJzFQn84V5HfUQrME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=M+IcW/BP; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M+IcW/BP" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4779d47be12so18812885e9.2 for ; Fri, 21 Nov 2025 11:35:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763753730; x=1764358530; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UpgOvXCNlXgopds0RDI/6vX/kTvFLO9tMaU8rBilFFA=; b=M+IcW/BPfzLS1c1LGDZjRIwa64c59WAaFJpRWc84ntkvLHGbCHLUtQjZodxf0iqhuA GOQc1Yf8RvEQDPb1riThTX7h3Uny1sVFwF6PWK6F0+M3uEBuGIvMCNm8LVhhq9Jzh90E pC35kQCa1NoTPSwH0Khi9w/88KrQ4lsjM78GdqJswc8ui2W/XK73V/lmhGopRAHl84sI mZA4ytZJiGC1XV8K9TuzjNKD0fTpyv7cky+iZOrR3x6GS8LrsTCVSUZrgbuZuHy7+yGn WHcbieL3gXb1u1E9Un6Eb/TYuHauokFT+39Ax9TCu1MP/ctadvE7+PZ3TZJkKKwHRA6g ReaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763753730; x=1764358530; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UpgOvXCNlXgopds0RDI/6vX/kTvFLO9tMaU8rBilFFA=; b=vUVAgCFoCMWO+H67oP7w0KjV+AowrxZ+tLdbInvzKe4660wLzlXEiltkXiQOO9l5M2 6atSfAyTsxsRk/AsptC2b3P92ijVOQPklws5/l4FhEH6pdGEsgAFh5V5HS2Zn6Et+5G4 g9dNm/bPmHj97quJI2727nYbwHxqBAgwFVNY247CFgUcFelac+gyRxN6gzx6ep+t5gKR oSf1vGMazf/FQ8dBIu9wE0b/bCnG3ABy7CyqDs8q7PemY8MHJfIJLDRcwaivDaTV8rFa SSjsE6PYjAelF++2m4XWokiPjR4DmLWtY7sX1Xdm0MBS8IEFxAyT5H9jr6yP8W69U+v5 hk3A== X-Forwarded-Encrypted: i=1; AJvYcCWCD97mvMrGr5zIIdfoqVKfhmYpOJL/Wte75zFg2750z6u4mthx77OJ67dXZhJgRcJvJEKoGikStL2qYZg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/izp2ToL/TzlIzqw2d24SLOJJ/7K1X+wCtrmstqIW2SMFsZjA YdrdZjHiA/Q/grU3GYp/wYA/JRpKYhmI9DXHxQ1wRoEB74O3iQLtqGhN X-Gm-Gg: ASbGncvxOpQSiVnaeSmCOVRWlA5JyZmISyrbFS6ccy0nZ90y2vk008KElavQGmz+v5K hrmXEDVzDvrwuaiyiuuqgmf5SY9UGc2t5ARYSwZUbyfUn8pwe2OKNuT2P0en3cDIzKCoVCDL8cK R5TjwxZysXsbNZnOFotfCG6jefPZMx9qxMF9zc76qZ4iHPVUXGaS++2a8J9d1VY+GXq49QYn686 twu0ILGd4ScGqMCvpBXYGHtJWMTq1HShYyBq9c9eQLeI6VVaaUOPEA8LsRo2J+VIDKOQj2rTOHi 9q4SG7BdP6RRs4OBwwRLJ0rq5fe0/xaQBoriWcbiv3L7OGhm/8gJbq2lcW6s0CFcGikctZ0hok9 Yw3I1RSh8x82MMVIP+Z3IUfkh/gGgDX5MgOS2yeMTAgpinNwcvL47LorUJx0+UtmHa2TSPFmoh7 tXsBYi X-Google-Smtp-Source: AGHT+IGHmJQ/SUK/Uv0tWBBylSXC+SBhd5okhyM0xJCUkSd/MynCjS9RE29tfg6Rpn0kSFhSmIpQiA== X-Received: by 2002:a05:600c:4443:b0:475:da1a:5418 with SMTP id 5b1f17b1804b1-477c017484bmr38877365e9.1.1763753729949; Fri, 21 Nov 2025 11:35:29 -0800 (PST) Received: from curiosity ([80.211.22.60]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-477bf3af0e1sm55186045e9.10.2025.11.21.11.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 11:35:29 -0800 (PST) From: Sergey Matyukevich To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: Charlie Jenkins , Conor Dooley , Andrew Jones , linux-riscv@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Matyukevich Subject: [PATCH] riscv: hwprobe: expose vector register length in bytes Date: Fri, 21 Nov 2025 22:35:10 +0300 Message-ID: <20251121193524.1813200-1-geomatsi@gmail.com> X-Mailer: git-send-email 2.51.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The vector register length can be obtained from the read-only CSR vlenb. However reading this CSR may be undesirable in some cases. XTheadVector extension is one example: existing implementations may not provide this register. On such platforms, vlenb is specified as device-tree property. Reading vlenb also initializes the application=E2=80=99s vector context, ev= en though the application may decide not to use the vector extension based on the reported length. Meanwhile the kernel already determines vlenb at boot, either from the CSR or from the device tree. So add RISCV_HWPROBE_KEY_VECTOR_REG_LENGTH to expose the vector register length already known to the kernel. Signed-off-by: Sergey Matyukevich --- Documentation/arch/riscv/hwprobe.rst | 3 +++ arch/riscv/include/asm/hwprobe.h | 2 +- arch/riscv/include/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 6 ++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/risc= v/hwprobe.rst index 06c5280b728a..14437fe79276 100644 --- a/Documentation/arch/riscv/hwprobe.rst +++ b/Documentation/arch/riscv/hwprobe.rst @@ -379,3 +379,6 @@ The following keys are defined: =20 * :c:macro:`RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE`: An unsigned int which represents the size of the Zicbop block in bytes. + +* :c:macro:`RISCV_HWPROBE_KEY_VECTOR_REG_LENGTH`: An unsigned int which + represents the vector registers length in bytes. diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hwpr= obe.h index 8c572a464719..b10311c9a44c 100644 --- a/arch/riscv/include/asm/hwprobe.h +++ b/arch/riscv/include/asm/hwprobe.h @@ -8,7 +8,7 @@ =20 #include =20 -#define RISCV_HWPROBE_MAX_KEY 15 +#define RISCV_HWPROBE_MAX_KEY 16 =20 static inline bool riscv_hwprobe_key_is_valid(__s64 key) { diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uap= i/asm/hwprobe.h index 1edea2331b8b..bd6cd97c81f9 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -110,6 +110,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_KEY_VENDOR_EXT_SIFIVE_0 13 #define RISCV_HWPROBE_KEY_VENDOR_EXT_MIPS_0 14 #define RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE 15 +#define RISCV_HWPROBE_KEY_VECTOR_REG_LENGTH 16 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ =20 /* Flags */ diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprob= e.c index 0f701ace3bb9..3007432fbdf1 100644 --- a/arch/riscv/kernel/sys_hwprobe.c +++ b/arch/riscv/kernel/sys_hwprobe.c @@ -328,6 +328,12 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pai= r, hwprobe_isa_vendor_ext_mips_0(pair, cpus); break; =20 + case RISCV_HWPROBE_KEY_VECTOR_REG_LENGTH: + pair->value =3D 0; + if (has_vector() || has_xtheadvector()) + pair->value =3D riscv_v_vsize / 32; + break; + /* * For forward compatibility, unknown keys don't fail the whole * call, but get their element key set to -1 and value set to 0 --=20 2.51.2