From nobody Mon Feb 9 16:08:25 2026 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 1FD4C28C5B1 for ; Sat, 8 Nov 2025 19:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762630953; cv=none; b=IMRtwgGlB+Q8ibmLuHzat00flGakQT+lKJWo4patjV1Xap6hWlrp/6oz+wEZTQYPJAMtpIRnaWDfG+svmSo+fo2a2T9Lk6k/PAlR3cHaDgZLJWVILxHYX+aUocPjgr8Wcd/eeJ+uZfOIXdN92mpHjCYfL93tU4cpQw/VgWLoW5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762630953; c=relaxed/simple; bh=6M9dbLxONjUxBoLDP2RqBwNW90OBNkAA0tpnRglr6DQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tqoRe0EY8xl4wzYgFaqaeAVc2NCYBywyn6NB2hmC672PNwyT3/WpXUI6OBwI9PQfRfVB87iHROodH3W5XhU4VE+k2+Uq9WgzGGvQqIgBiNKO5yAAYlAEUONySvFkB7L0mz8z7ATirp1qZ8yUpVzVwYg+MHvrkstSj5M7s7xG2Tg= 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=OG/RK3gi; arc=none smtp.client-ip=209.85.208.172 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="OG/RK3gi" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-37a3340391cso17513341fa.3 for ; Sat, 08 Nov 2025 11:42:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762630950; x=1763235750; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J2IQTBuXBoLRQZMsUEB0GbuKpDZXigWMmDpUz8gyE1g=; b=OG/RK3giQINbAX1PH1yW022rwXk1SebbL6cnKfff44FGVQK+osDSDcalDyA4RAIdSM 2yD1zpee5CAlFrWYH7YuG13kpZcpW6Kk4uJtkOzCZ0Zcn4+k8CSZGPCrMQxAkr1tvWF5 L07KHpHx2JK/AjWYdoCv9+RPNvbY+g2knycCiv/Kh+LRg2smltKTWJl3kKJQTa0yF5rS KHRSA8kcUlLgAqWV9RB3516yC2NWrjnR/Dlr6J6J4ZxIunHmmV3PpLZwE/Nvgw7SAe3C 3my97CEo/5QvwbuEvOIrJ/rZgKn0C4YkudDqEqCdkZAbE14wKycRzxu5soo4M2QqmAEW YaKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762630950; x=1763235750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=J2IQTBuXBoLRQZMsUEB0GbuKpDZXigWMmDpUz8gyE1g=; b=h1ALhDOX+hrxjEKwqwS/uUwJ/yYuDipgsK703rGUH40Jtg1m8teZggk4vff+Tb6n89 Bj/220W0j9HXg3OHi9RFE0cqAzIFVvAo25EqtUqQhrgObBA86LGE588zMH8q1g15fNp7 21rdbMkyc3N//gConPYoQQaiahFS0yk9j/Ozb7auC7YlyFJO3ybtZxEqc3CADQi30beq AXPSP09nVtYjIScs+BBVZ1edQUvxWBbOGWeW90OQJQIvZts/PyZg/toLG0CVyP/0DUK0 tFIS1QWHBJ0gJkQioHSoVRy1KjBLk0V6RXCkLa7sjNyU2oMi30e/Uw6kL0/Xs1pJpTSm mohA== X-Forwarded-Encrypted: i=1; AJvYcCWA1o86+vwgwd9FGDdexxj+b9+gc+qgzJm87MOc/IJnfKct+OP61CWzeRrwcUjzyzQMj/1y1M53CasXqsA=@vger.kernel.org X-Gm-Message-State: AOJu0YwolLxt5QPcmuOUMZ8wQur8BRXPPmA1OL4kwaJ+/UOF50VUiQzf fgmP1JiUrdpL5VHscdqFpDBvEhKEWdRUug0lpjobsJ+n6rHGmRE7q4B1 X-Gm-Gg: ASbGncseeWUghRlettZnhK19JjAm22s1o2T7eMGZBbDdOjFvXs4D3aG+JtS37WpVNGI r3cDq3o1SLQia5olXJJVZbSLd5ESA5MOiUwA2Dq2swibdcR4vMvWgjtuA6Smzz87ixrnIRPYoER 1Ptb08JVmcfX9cEW4RMwfS5NKrJsyZjgDIq0/ReF6bVQxnBcdR6tghGPQXWtFrkYvnn85oY4F9W 9IsZk+cex/P5emmxvr411TL3/ff4mavPufTb2W0gfygePX/EI4tP2TU3s+xnozfRDZsCoUSmlgR 2IdDTwIz60B1RUSHRBm4cUXSmJo2vlYU9WlCj1Y+T/U9ktJywndJ+FH0+Zvn1ggUTnLC8Rbhe6f Y5PSwb8j5VzXQiQwkTXJZzDw1tBrCkultSxtwHM4wONNxszWAK6ao2HUHRxR/0STqKGPXctYezf h9sI1LgCFz4R+B X-Google-Smtp-Source: AGHT+IFf6dK7lptakI4133tJJcZvJ7D5ljXgoiEFcd+YznP8qQqw2s3Ui5u0H2YIH/FT8lwi1hx0Gw== X-Received: by 2002:a2e:8a96:0:b0:37a:2dca:cfb6 with SMTP id 38308e7fff4ca-37a7b1bede2mr8423251fa.21.1762630950197; Sat, 08 Nov 2025 11:42:30 -0800 (PST) Received: from curiosity ([5.188.167.4]) by smtp.googlemail.com with ESMTPSA id 38308e7fff4ca-37a5f0edac3sm22115421fa.38.2025.11.08.11.42.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 11:42:28 -0800 (PST) From: Sergey Matyukevich To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Paul Walmsley , Palmer Dabbelt , Alexandre Ghiti , Oleg Nesterov , Shuah Khan , Thomas Huth , Charlie Jenkins , Andy Chiu , Samuel Holland , Joel Granados , Conor Dooley , Yong-Xuan Wang , Heiko Stuebner , Sergey Matyukevich Subject: [PATCH v4 4/9] riscv: vector: init vector context with proper vlenb Date: Sat, 8 Nov 2025 22:41:43 +0300 Message-ID: <20251108194207.1257866-5-geomatsi@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251108194207.1257866-1-geomatsi@gmail.com> References: <20251108194207.1257866-1-geomatsi@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The vstate in thread_struct is zeroed when the vector context is initialized. That includes read-only register vlenb, which holds the vector register length in bytes. This zeroed state persists until mstatus.VS becomes 'dirty' and a context switch saves the actual hardware values. This can expose the zero vlenb value to the user-space in early debug scenarios, e.g. when ptrace attaches to a traced process early, before any vector instruction except the first one was executed. Fix this by specifying proper vlenb on vector context init. Signed-off-by: Sergey Matyukevich --- arch/riscv/kernel/vector.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index 901e67adf576..34048c4c26dc 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -109,8 +109,8 @@ bool insn_is_vector(u32 insn_buf) return false; } =20 -static int riscv_v_thread_zalloc(struct kmem_cache *cache, - struct __riscv_v_ext_state *ctx) +static int riscv_v_thread_ctx_alloc(struct kmem_cache *cache, + struct __riscv_v_ext_state *ctx) { void *datap; =20 @@ -120,13 +120,15 @@ static int riscv_v_thread_zalloc(struct kmem_cache *c= ache, =20 ctx->datap =3D datap; memset(ctx, 0, offsetof(struct __riscv_v_ext_state, datap)); + ctx->vlenb =3D riscv_v_vsize / 32; + return 0; } =20 void riscv_v_thread_alloc(struct task_struct *tsk) { #ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE - riscv_v_thread_zalloc(riscv_v_kernel_cachep, &tsk->thread.kernel_vstate); + riscv_v_thread_ctx_alloc(riscv_v_kernel_cachep, &tsk->thread.kernel_vstat= e); #endif } =20 @@ -212,12 +214,14 @@ bool riscv_v_first_use_handler(struct pt_regs *regs) * context where VS has been off. So, try to allocate the user's V * context and resume execution. */ - if (riscv_v_thread_zalloc(riscv_v_user_cachep, ¤t->thread.vstate)) { + if (riscv_v_thread_ctx_alloc(riscv_v_user_cachep, ¤t->thread.vstate= )) { force_sig(SIGBUS); return true; } + riscv_v_vstate_on(regs); riscv_v_vstate_set_restore(current, regs); + return true; } =20 --=20 2.51.0