linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Matyukevich <geomatsi@gmail.com>
To: linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org,
	Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alexghiti@rivosinc.com>,
	Conor Dooley <conor.dooley@microchip.com>,
	Charlie Jenkins <charlie@rivosinc.com>,
	Shuah Khan <shuah@kernel.org>,
	Sergey Matyukevich <geomatsi@gmail.com>
Subject: [PATCH 2/2] riscv: vector: init vlenb in vector context allocation
Date: Thu, 21 Aug 2025 20:39:50 +0300	[thread overview]
Message-ID: <20250821173957.563472-2-geomatsi@gmail.com> (raw)
In-Reply-To: <20250821173957.563472-1-geomatsi@gmail.com>

Currently, vlenb in vstate is set to zero on vector context allocation
and remains zero until the first context switch. This can expose an
inconsistent vlenb value to user-space in early vector debug scenarios,
e.g. when ptrace attaches to a tracee after the first vector instruction
but before the first context switch. Fix this by setting the correct
vlenb value during vector context allocation. Simple reproducer has been
added to selftests:
- tools/testing/selftests/riscv/vector/v_ptrace.c

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
---
 arch/riscv/kernel/vector.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c
index 184f780c932d..6ba68568735b 100644
--- a/arch/riscv/kernel/vector.c
+++ b/arch/riscv/kernel/vector.c
@@ -120,6 +120,8 @@ static int riscv_v_thread_zalloc(struct kmem_cache *cache,
 
 	ctx->datap = datap;
 	memset(ctx, 0, offsetof(struct __riscv_v_ext_state, datap));
+	ctx->vlenb = riscv_v_vsize / 32;
+
 	return 0;
 }
 
-- 
2.50.1


      reply	other threads:[~2025-08-21 17:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 17:39 [PATCH 1/2] selftests: riscv: vector: add early ptrace test Sergey Matyukevich
2025-08-21 17:39 ` Sergey Matyukevich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250821173957.563472-2-geomatsi@gmail.com \
    --to=geomatsi@gmail.com \
    --cc=alexghiti@rivosinc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=charlie@rivosinc.com \
    --cc=conor.dooley@microchip.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).