Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4780086rwl; Mon, 3 Apr 2023 09:26:57 -0700 (PDT) X-Google-Smtp-Source: AKy350Yt513GD6gsRMVYLEPzYY8eVcqTKc7GnJ/LPRDalAuM3v5597iQEbcDkHguIWh3l8bkur1E X-Received: by 2002:aa7:da82:0:b0:502:100c:53a with SMTP id q2-20020aa7da82000000b00502100c053amr37038993eds.41.1680539216759; Mon, 03 Apr 2023 09:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680539216; cv=none; d=google.com; s=arc-20160816; b=Aa+3fYSDMYvQF9jNhaBqlAy2PD3DtAYaO0qPPfCLATL6L74uf0yK4qqSdEDgJ9yMJM j2xNzFM7j+oxA3d6TwGL6KZAl7e9pdmkxt85auj0mGZKxUOXbdJPfqkC5VGANO5z77EX AkDo8Cku142G5VAemeLoSN65rf7nEC6LDN+CQ6z0hBURiFb/6RKnQMorx0U6h3NvgvKX A4u9CiEOs98zgRmt1r+smpSETmoFZqOERqKh1XFokJUWRCW+TqgegcY4vAjhTy/YItql jd3icL0x96KYl6mT7WKbozT5Aof05AyEdmmZZVNbXDxNizeCYuwN1tWwbyqeQz6/KYIR xRsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6afTO4oEQn+AHLNviC7P4YfdPdFleXN53RJrps7nDgM=; b=gv5yAaGXz2NIW/S/Mro1AH3SAJKBw/yDKghk0QVQCp5JHptHFbhF+NsELrLD0uUG+6 iXmA4Nw1PD0RpvzteNe9ICyDwL242gR80TpclMYyI24nG0ZwpH5N5npMA1ny3WiAX6bx I0SzdzfN2eSM+Eyr5sCWtFN1fgPBhe1WKyBGsCPEys4deQph8uHH7L/FHtKHdQfMObrG aew1/82w2g6/ndHLt0XebgJNFLuf2Wt1qpoDSBBq2D9ArppBQKx46uG2vOFD0I5xmpDK pYl0Gx9hjZTO5nU7vWWXBQbOUX7Qp8P6NPnuRfbFoyjTHma5e4bdscoyTqoPg9dRwySQ 79/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ItTLRmpc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o8-20020aa7c508000000b004fafc269d55si8441380edq.113.2023.04.03.09.26.32; Mon, 03 Apr 2023 09:26:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ItTLRmpc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232544AbjDCQVf (ORCPT + 99 others); Mon, 3 Apr 2023 12:21:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231836AbjDCQVd (ORCPT ); Mon, 3 Apr 2023 12:21:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC7F3170C for ; Mon, 3 Apr 2023 09:21:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 68D916211C for ; Mon, 3 Apr 2023 16:21:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 723CBC433EF; Mon, 3 Apr 2023 16:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680538891; bh=s/h9BxcKiHCWDLpRMf/OxHcfV+3/cmpO+wdtHk8dx9k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ItTLRmpc/AKSD7fGCTzArFPVOVs1SdvwB4iP5dIPOx7YxjQFjLCxCB6H5P757Z28V UJeH1fNjndM2vu0bFuSlGA99VEslIY01Vznl2H+fqiGQR//nBIG+MyMVnqC7IdwuSk S2GDdtpfhKhCx6OzrhJfwOF7rl24AzReK4x7Lm24JO96e0P6iAR5RKPc7R7idrIDiH CeSFMBuXf6GPzVwDaFJ3wBiRrY9WvNuRHFSRhlb7BQPVCZ0ApSiZG0AYoXswhe5CKM G3TKTVXi9WoVP0LsqpUM7aLMnbz6eVwgsqUAbh62Essc/tl4GVwhBLUJaOxi21w0qB 2sadR7e3s7Uuw== Date: Mon, 3 Apr 2023 17:21:27 +0100 From: Conor Dooley To: =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= Cc: Albert Ou , Paul Walmsley , Palmer Dabbelt , linux-riscv@lists.infradead.org, Guo Ren , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Heiko =?iso-8859-1?Q?St=FCbner?= , Yipeng Zou , linux-kernel@vger.kernel.org, Palmer Dabbelt , Heiko Stuebner Subject: Re: [PATCH] riscv: entry: Save a0 prior syscall_enter_from_user_mode() Message-ID: <20230403-crisping-animosity-04ed8a45c625@spud> References: <20230403065207.1070974-1-bjorn@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="R7iREP1gQeGxJksL" Content-Disposition: inline In-Reply-To: <20230403065207.1070974-1-bjorn@kernel.org> X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --R7iREP1gQeGxJksL Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 03, 2023 at 08:52:07AM +0200, Bj=F6rn T=F6pel wrote: > From: Bj=F6rn T=F6pel >=20 > The RISC-V calling convention passes the first argument, and the > return value in the a0 register. For this reason, the a0 register > needs some extra care; When handling syscalls, the a0 register is > saved into regs->orig_a0, so a0 can be properly restored for, > e.g. interrupted syscalls. >=20 > This functionality was broken with the introduction of the generic > entry patches. Here, a0 was saved into orig_a0 after calling > syscall_enter_from_user_mode(), which can change regs->a0 for some > paths, incorrectly restoring a0. >=20 > This is resolved, by saving a0 prior doing the > syscall_enter_from_user_mode() call. >=20 > Fixes: f0bddf50586d ("riscv: entry: Convert to generic entry") > Reviewed-by: Heiko Stuebner > Tested-by: Heiko Stuebner > Signed-off-by: Bj=F6rn T=F6pel As you pointed out, v12 did indeed have this ordering, so *deep breath* Reported-by: Conor Dooley Link: https://lore.kernel.org/linux-riscv/60ee7c26-1a70-427d-beaf-92e2989fc= 479@spud/ Reviewed-by: Conor Dooley Tested-by: Conor Dooley Thanks for fixing this Bj=F6rn! > --- > arch/riscv/kernel/traps.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > index 1f4e37be7eb3..8c258b78c925 100644 > --- a/arch/riscv/kernel/traps.c > +++ b/arch/riscv/kernel/traps.c > @@ -270,11 +270,11 @@ asmlinkage __visible __trap_section void do_trap_ec= all_u(struct pt_regs *regs) > if (user_mode(regs)) { > ulong syscall =3D regs->a7; > =20 > - syscall =3D syscall_enter_from_user_mode(regs, syscall); > - > regs->epc +=3D 4; > regs->orig_a0 =3D regs->a0; > =20 > + syscall =3D syscall_enter_from_user_mode(regs, syscall); > + > if (syscall < NR_syscalls) > syscall_handler(regs, syscall); > else >=20 > base-commit: d34a6b715a23ccd9c9d0bc7a475bea59dc3e28b2 > --=20 > 2.37.2 >=20 --R7iREP1gQeGxJksL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZCr9AwAKCRB4tDGHoIJi 0uChAP9U8xmkAUQFANUtusPF/nQKVwoeUIJlqkQQzmUlIl6dZQEA2Rg5robA6oPH 5h312z8HKnb5QE9lXkT3WQea0531eQA= =Ks/G -----END PGP SIGNATURE----- --R7iREP1gQeGxJksL--