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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6623AC83F14 for ; Tue, 29 Aug 2023 06:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232704AbjH2G2A (ORCPT ); Tue, 29 Aug 2023 02:28:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233642AbjH2G1q (ORCPT ); Tue, 29 Aug 2023 02:27:46 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB7DA19A for ; Mon, 28 Aug 2023 23:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1693290464; x=1724826464; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=GGbqLGqMN9df8eATN/J3U86vb4CO2JuXfpoZHqXvJqY=; b=o85SCAItdje2Q5TR8aE1ZpjfSloL9TClfSys/8TRfL+pCZUUhq5EpPps PqnrXfbScWImitgNV97aLmL5et9KJ1XYDMY/Mt6qn8iAKj0s6iihDOTwG arQaQEsaAmgESTJgoQzhXFCVxmz/FuYvTnWbtSr0WPIftZOWc1q+LfTun CxDqjg+sCZaFWMkSAfOImR53g4ODCRXN/PqNPcIHzyaw8DAZDCdWUzOJr A8xG95y8+4FFm85bDES2aHHk7pmu6UgNdxR9+nB5L0czUVxyCO87JvhsO CWQYloBMbRUyHly6iXCS7RxjNFFfu+Di0RyWDel/s62FVWSUONQXAswFt A==; X-IronPort-AV: E=Sophos;i="6.02,208,1688454000"; d="asc'?scan'208";a="232227171" X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 28 Aug 2023 23:27:44 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 28 Aug 2023 23:27:37 -0700 Received: from wendy (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Mon, 28 Aug 2023 23:27:35 -0700 Date: Tue, 29 Aug 2023 07:26:54 +0100 From: Conor Dooley To: Guo Ren CC: Nam Cao , Paul Walmsley , Palmer Dabbelt , Albert Ou , , , Subject: Re: [PATCH] riscv: provide riscv-specific is_trap_insn() Message-ID: <20230829-unbridle-condense-2fc45a442bb6@wendy> References: <20230827205641.46836-1-namcaov@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Gejlf3F12x47mKDN" Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Gejlf3F12x47mKDN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 29, 2023 at 01:56:34PM +0800, Guo Ren wrote: > On Mon, Aug 28, 2023 at 4:56=E2=80=AFAM Nam Cao wrote: > > > > uprobes expects is_trap_insn() to return true for any trap instructions, > > not just the one used for installing uprobe. The current default > > implementation only returns true for 16-bit c.ebreak if C extension is > > enabled. This can confuse uprobes if a 32-bit ebreak generates a trap > > exception from userspace: uprobes asks is_trap_insn() who says there is= no > > trap, so uprobes assume a probe was there before but has been removed, = and > > return to the trap instruction. This cause an infinite loop of entering > > and exiting trap handler. > > > > Instead of using the default implementation, implement this function > > speficially for riscv which checks for both ebreak and c.ebreak. > > > > Fixes: 74784081aac8 ("riscv: Add uprobes supported") > > Signed-off-by: Nam Cao > > --- > > arch/riscv/kernel/probes/uprobes.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/pro= bes/uprobes.c > > index 194f166b2cc4..91f4ce101cd1 100644 > > --- a/arch/riscv/kernel/probes/uprobes.c > > +++ b/arch/riscv/kernel/probes/uprobes.c > > @@ -3,6 +3,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "decode-insn.h" > > > > @@ -17,6 +18,15 @@ bool is_swbp_insn(uprobe_opcode_t *insn) > > #endif > > } > > > > +bool is_trap_insn(uprobe_opcode_t *insn) > > +{ > > +#ifdef CONFIG_RISCV_ISA_C > Can we remove the CONFIG_RISCV_ISA_C? As you said, "uprobes expects > is_trap_insn() to return true for any trap instructions". So userspace > wouldn't be limited by CONFIG_RISCV_ISA_C. Isn't the RISCV_ISA_C required because there's a different encoding for EBREAK vs C_EBREAK? That said, this should be using IS_ENABLED() not #ifdef, since the definition for riscv_insn_is_c_ebreak() is provided unconditionally afaict. >=20 > > + if (riscv_insn_is_c_ebreak(*insn)) > > + return true; > > +#endif > > + return riscv_insn_is_ebreak(*insn); > > +} > > + > > unsigned long uprobe_get_swbp_addr(struct pt_regs *regs) > > { > > return instruction_pointer(regs); > > -- > > 2.34.1 > > --Gejlf3F12x47mKDN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZO2PrQAKCRB4tDGHoIJi 0sQOAQDv1oVj7wyYwRi92joynjdOE3DDV2OuEjEbpfrv+eqJjAD+LnNdnWqsf6EW vXpfa5K8Smd+td9s9Q04/KE8pPsWaAk= =+9ci -----END PGP SIGNATURE----- --Gejlf3F12x47mKDN--