From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E475ED7360A for ; Sat, 30 Nov 2024 21:47:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75DEB6B007B; Sat, 30 Nov 2024 16:47:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E6826B0082; Sat, 30 Nov 2024 16:47:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5610E6B0083; Sat, 30 Nov 2024 16:47:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 33C096B007B for ; Sat, 30 Nov 2024 16:47:50 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BB6CC418D3 for ; Sat, 30 Nov 2024 21:47:49 +0000 (UTC) X-FDA: 82844098764.23.F8EFE47 Received: from flow-a8-smtp.messagingengine.com (flow-a8-smtp.messagingengine.com [103.168.172.143]) by imf24.hostedemail.com (Postfix) with ESMTP id 54CDB180008 for ; Sat, 30 Nov 2024 21:47:46 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=coelacanthus.name header.s=fm2 header.b=s88kO2yd; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="g/y39pAy"; spf=pass (imf24.hostedemail.com: domain of uwu@coelacanthus.name designates 103.168.172.143 as permitted sender) smtp.mailfrom=uwu@coelacanthus.name; dmarc=pass (policy=quarantine) header.from=coelacanthus.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733003260; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Ug6noMxJx4D0HoGkjMXTBxp/QR93meFjQxG2sTCVytQ=; b=KGqoi4g9ALzhfgxjZJ/b7reqAd7/p4SCh8QWLqBHoc7g42a8A8me2Tz94VPFC91Lt6xBJ8 HZ5yNM7Q8zJ0UzZdTvVI80ITGhNHlRddtqf2uaNNJKKNCrjCfGPsdFaAODW84ktPTB5sRk 0C8WNu+raE27iZupBBDIkzW6hLXypu8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=coelacanthus.name header.s=fm2 header.b=s88kO2yd; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="g/y39pAy"; spf=pass (imf24.hostedemail.com: domain of uwu@coelacanthus.name designates 103.168.172.143 as permitted sender) smtp.mailfrom=uwu@coelacanthus.name; dmarc=pass (policy=quarantine) header.from=coelacanthus.name ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733003260; a=rsa-sha256; cv=none; b=ohiJhGkWqszPSimwANsdgwhvR/u/u7/LlQgpTrgRzNgseOaiB312OcFmIURTpKYnpc0wzu erpf6CIZ0MgchuWN+w1eKt+oLUs3mlA1qhrlJvALbOlmLt4KTuO9ELeZwPFQCsuZclAM3c R0o2TsyoXEi6JtLGSrBtrgSSlqrBZ8o= Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailflow.phl.internal (Postfix) with ESMTP id AE3CC2004D6; Sat, 30 Nov 2024 16:47:46 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Sat, 30 Nov 2024 16:47:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= coelacanthus.name; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm2; t=1733003266; x=1733006866; bh=Ug6noMxJx4D0HoGkjMXTBxp/QR93meFj QxG2sTCVytQ=; b=s88kO2ydw0gUoGi6fFxuPvR48rCYB3tFg/sjJaKqsyrIc3fd gnXoRVp6n3e3b5NgXRiXawcjxmyVHctiNpDX4KoxOn97RTWUK8vjdfz15oFCDbAq VpRbtESgpl2t6uNSEbLtPNWS+7KBMX0bWs2FR6aJHXBjX/O9t3/OLmK8TUipYgT4 cWC4YpjG1PyTKpS4GpDlJ3nFfjffP95ZLOdw9dk6JMVF9SvClSMfzHqUH+tzuZhD eg0781XkO51wBjQTzG1rEyc3JdKQzRzcomLehnPf9WH+oBY9H1vU714Uy80cEicV 83vJhNQEcyiLuY84gw9U5uJje0OL4Vo8xUX0hQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1733003266; x=1733006866; bh=Ug6noMxJx4D0HoGkjMXTBxp/QR93 meFjQxG2sTCVytQ=; b=g/y39pAydNgDkiGRZAQbYD5gYCCvFAB5Ija8HT/8PLr9 otNL/G+UlSvp3vDkKxY1DjfG/TVqjUPMNNAtlHDUChfxgb8JA0jryLtOfLO3Yyne x1l4NmhVHGU4sgqtNYLayVXp2QEH8PStVP/hktZHdCKHkGFaf5lchQA2EUf+KkZs bYE3qQZWJsL5xj50QzblhXYunA4PSbI58hWbKSePiFHcofAe/dxicya1+D616hok +UFu7+4OuTJPLDq+DLbT6HATHGika7XxEOXmd4B/ECru2FLfs0s0ItkAN6+n/BSU rFJb8TKPyinCtffcSMDXGEpaSTm+xeok4RY0D81Q8Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrheehgdduhedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkffvvefosehtjeertdertdejnecu hfhrohhmpeevvghlvghsthgvucfnihhuuceouhifuhestghovghlrggtrghnthhhuhhsrd hnrghmvgeqnecuggftrfgrthhtvghrnhepjeffleetjeeigfehfeeghfdugedtjeekledu heetudejffdtveevueeuffejfeefnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehufihusegt ohgvlhgrtggrnhhthhhushdrnhgrmhgvpdhnsggprhgtphhtthhopedvfedpmhhouggvpe hsmhhtphhouhhtpdhrtghpthhtohepthhglhigsehlihhnuhhtrhhonhhigidruggvpdhr tghpthhtoheplhhinhhugidqrhhishgtvheslhhishhtshdrihhnfhhrrgguvggrugdroh hrghdprhgtphhtthhopeholhgvghesrhgvughhrghtrdgtohhmpdhrtghpthhtohepghhu ohhrvghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehshhhiqhhisehishhrtgdrih hstggrshdrrggtrdgtnhdprhgtphhtthhopehufihusegtohgvlhgrtggrnhhthhhushdr nhgrmhgvpdhrtghpthhtohepiihihigrohesughishhrohhothdrohhrghdprhgtphhtth hopehlihhnuhigqdhmmheskhhvrggtkhdrohhrghdprhgtphhtthhopegvsghivgguvghr mhesgihmihhsshhiohhnrdgtohhm X-ME-Proxy: Feedback-ID: i95c648bc:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 30 Nov 2024 16:47:42 -0500 (EST) From: Celeste Liu Date: Sun, 01 Dec 2024 05:47:13 +0800 Subject: [PATCH] riscv/ptrace: add new regset to get original a0 register MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20241201-riscv-new-regset-v1-1-c83c58abcc7b@coelacanthus.name> X-B4-Tracking: v=1; b=H4sIAOCHS2cC/x3MMQqAMAxA0atIZgNt0KFeRRzUxpqlSiIqiHe3O L7h/weMVdigqx5QPsVkywW+rmBex5wYJRYDOWo8OY8qNp+Y+ULlZHxgbClMoaUxuggl25UXuf9 lP7zvB7f1anFiAAAA X-Change-ID: 20241201-riscv-new-regset-d529b952ad0d To: Oleg Nesterov , Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook Cc: Alexandre Ghiti , "Dmitry V. Levin" , Andrea Bolognani , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , Thomas Gleixner , Ron Economos , Felix Yan , Ruizhe Pan , Shiqi Zhang , Guo Ren , Yao Zi , Han Gao , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Celeste Liu X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3224; i=uwu@coelacanthus.name; h=from:subject:message-id; bh=tgFlapvT7VwQsZiO6n4iEi3XFX6DBlZjgTPZF2GhaDs=; b=owJ4nJvAy8zAJeafov85RWVtBeNptSSGdO/27+ejT67U17uYOJXz/fmPjJbrjI9p7nS4Ghh+I OvZwwgJVqeOUhYGMS4GWTFFlrwSlp+cl8527+3Y3gUzh5UJZAgDF6cATOTCe4b/mc2h98Ufndho syS/aQlXObP6vhNPbXcoqUzXOZr2OXAnB8P/4kuX7G7s7O9s/NO72mx2j+n+jpB2o1bBCWsCbxg vF9nGBwChJ0wk X-Developer-Key: i=uwu@coelacanthus.name; a=openpgp; fpr=892EBC7DC392DFF9C9C03F1D15F4180E73787863 X-Rspamd-Queue-Id: 54CDB180008 X-Rspamd-Server: rspam12 X-Stat-Signature: 9kf5dbsm8mnjqh4krizo384ho9mdjeed X-Rspam-User: X-HE-Tag: 1733003266-669659 X-HE-Meta: U2FsdGVkX1/msSWUDrkTDkcmccMAH7+yJ99+R7jEy+eCWlKelrh09DU0MnU5PMuW/psPzBG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M5mtBlJN083VdlyoROZUxJ0QQLIQ9QLGGEXzxzdpopWVH4n4x4wHF/A4zol4gJQ0a5ECqdEWFhlAHDNn3+vHDp0QVCx6QW/HvWvPEDdoEFx2/sBfjtM7m6b5iNt/pMd3d29CiJBmOqXnEsk0jVrgOsmwztWlIorFPyPjbObKBmnE1aZwD8oqmDYW4SUlGf7yM0hnoLTntR6NTNleP/2pRY+yKSoAgnxKzLJ/IbPBDryfpP1IPcXbb9wN1X/z87Kjt1WM1YDkov+uKD+s7hdHJhECEXFAyWtZRDX2Qff6lCVxl0fU220ybJb1X8q6Y X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The orig_a0 is missing in struct user_regs_struct of riscv, and there is no way to add it without breaking UAPI. (See Link tag below) Like NT_ARM_SYSTEM_CALL do, we add a new regset name NT_RISCV_ORIG_A0 to access original a0 register from userspace via ptrace API. Link: https://lore.kernel.org/all/59505464-c84a-403d-972f-d4b2055eeaac@gmail.com/ Signed-off-by: Celeste Liu --- arch/riscv/kernel/ptrace.c | 33 +++++++++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 2 files changed, 34 insertions(+) diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c index ea67e9fb7a583683b922fe2c017ea61f3bc848db..faa46de9000376eb445a32d43a40210d7b846844 100644 --- a/arch/riscv/kernel/ptrace.c +++ b/arch/riscv/kernel/ptrace.c @@ -31,6 +31,7 @@ enum riscv_regset { #ifdef CONFIG_RISCV_ISA_SUPM REGSET_TAGGED_ADDR_CTRL, #endif + REGSET_ORIG_A0, }; static int riscv_gpr_get(struct task_struct *target, @@ -184,6 +185,30 @@ static int tagged_addr_ctrl_set(struct task_struct *target, } #endif +static int riscv_orig_a0_get(struct task_struct *target, + const struct user_regset *regset, + struct membuf to) +{ + return membuf_store(&to, task_pt_regs(target)->orig_a0); +} + +static int riscv_orig_a0_set(struct task_struct *target, + const struct user_regset *regset, + unsigned int pos, unsigned int count, + const void *kbuf, const void __user *ubuf) +{ + int orig_a0 = task_pt_regs(target)->orig_a0; + int ret; + + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &orig_a0, 0, -1); + if (ret) + return ret; + + task_pt_regs(target)->orig_a0 = orig_a0; + return ret; +} + + static const struct user_regset riscv_user_regset[] = { [REGSET_X] = { .core_note_type = NT_PRSTATUS, @@ -224,6 +249,14 @@ static const struct user_regset riscv_user_regset[] = { .set = tagged_addr_ctrl_set, }, #endif + [REGSET_ORIG_A0] = { + .core_note_type = NT_RISCV_ORIG_A0, + .n = 1, + .size = sizeof(elf_greg_t), + .align = sizeof(elf_greg_t), + .regset_get = riscv_orig_a0_get, + .set = riscv_orig_a0_set, + }, }; static const struct user_regset_view riscv_user_native_view = { diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h index b44069d29cecc0f9de90ee66bfffd2137f4275a8..390060229601631da2fb27030d9fa2142e676c14 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -452,6 +452,7 @@ typedef struct elf64_shdr { #define NT_RISCV_CSR 0x900 /* RISC-V Control and Status Registers */ #define NT_RISCV_VECTOR 0x901 /* RISC-V vector registers */ #define NT_RISCV_TAGGED_ADDR_CTRL 0x902 /* RISC-V tagged address control (prctl()) */ +#define NT_RISCV_ORIG_A0 0x903 /* RISC-V original a0 register */ #define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers */ #define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and status registers */ #define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD Extension registers */ --- base-commit: 0e287d31b62bb53ad81d5e59778384a40f8b6f56 change-id: 20241201-riscv-new-regset-d529b952ad0d Best regards, -- Celeste Liu