Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3410027rdb; Tue, 29 Aug 2023 14:51:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhn1LWhB1exKGUcQ556jSnNcCnu/sFG3T6hOPC9cOjDIqndUtobZjdLfu0E5h/EpQNbFcZ X-Received: by 2002:a17:907:2671:b0:9a1:ecb5:732e with SMTP id ci17-20020a170907267100b009a1ecb5732emr152049ejc.71.1693345892618; Tue, 29 Aug 2023 14:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693345892; cv=none; d=google.com; s=arc-20160816; b=U1Psl4rmbJDux+SXLiTLvxx5HsxgOC66k5MqCNe0lyjsOX9FfIkYkJxt4RaS7PuLzc AETzoi1plsjT3qam5W9tQArpNejWOIZVYzRkUWwR2bxBm7gXytNuDiyj7jMP9jdkb1na bXzcjl0w7itDl4OXJxtESQ6Y+NlwQ1bxOlqRPK2Lp6oC64YrrtRQphkqnT24GXKl6yC+ iaauV55l/M0/qdFim7wheMgH8+kMLE0QV+DyU+zrQ/JTHOMdT1pwUfJEABE62hOChL30 yS7WcwtKVpQ33kZGDeqoZ+ah9IHCXaqS/aYtu9C/sySYRHqXT+M1u3a8yB2l+8ud5nxl 7L/g== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YzI1T+2NbKPa+ILrlCcTyXygxu+/4IOX+GwCCixXUy8=; fh=wBWR5AEikfzbDNmSz4B6s9wOErervbe7nJ93gqFXZ5Y=; b=oOLnJPs4XiyHQsfXKDHDt6mLguQTCNYuEgBXPLKH/00KUtGDdnqAcBpUdePimrhUQY xB2MdcTcsaxSypV7XUjGfusXDIVY2NmKDEHfL/7jF1Bf5RGOIyv74ARfl1dZmcCXX2Ck DCtsSZGb10rGAj/cBV8EWGVTlSugr4iRnZIrTYKLGQN+1uTZCQOGEBTZmaO3cXb20/uH sKqBB6foOxtspteVjx8Ck5cs/f1VsjrGZa8yFuPV4hYurSnAHfvQGfpIWWXlteqFq+kP SXE3G7rOIxCirgCjDxaI+dZ1t2R071M/fK7zenCuSLcKUu48u631CahZmJKKaS+MTTuZ v2Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NYqm+ES5; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rk25-20020a170907215900b0099cbe6d4e20si4768467ejb.112.2023.08.29.14.51.00; Tue, 29 Aug 2023 14:51:32 -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=@gmail.com header.s=20221208 header.b=NYqm+ES5; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233333AbjH2ITH (ORCPT + 99 others); Tue, 29 Aug 2023 04:19:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231528AbjH2ISh (ORCPT ); Tue, 29 Aug 2023 04:18:37 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6C42DF for ; Tue, 29 Aug 2023 01:18:33 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-986d8332f50so528598566b.0 for ; Tue, 29 Aug 2023 01:18:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693297112; x=1693901912; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=YzI1T+2NbKPa+ILrlCcTyXygxu+/4IOX+GwCCixXUy8=; b=NYqm+ES5G3BCmnDsMWFKt/TeHhfHzrc6N0RlaHKeosp2s3hMJvNTvhSuZLHZinQ3vz yyKfWl956ojMfRGxDPM8DrrHDUL/kggaWV09Xp20KzHpVoc+SHYxdipH+Yj2qG1TYadW B/HpKKdxxqKY4eo2sGjjYJwdpUe/SU4PcjPT6EkfeP0YIiXJiIHI00uQmG3wj/9T20bG Hfg5gMSaPLgoqmEGl72HQ/Cy1jdgdnZmRfcdywC+eyX9f+U91irMD1QbMTljUBbqcZ8I bkw83L0Z8SGXFoMEqhAkNmAQydx1VaqngfwyUn0m2NslBQNVNLN+/KaruZorZCfH6znq +BjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693297112; x=1693901912; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YzI1T+2NbKPa+ILrlCcTyXygxu+/4IOX+GwCCixXUy8=; b=SP0VZKqC0e0aixlOx8Q+KADmUYQo12XBg0pPleygUK5jes//zqFE6TNUFPtnlM4Zzm YIWGZI+G4K8n8w/1QuLmrxF6KxnimeyNcqdeYYQ9RWg2240UwVNpv0TfqjFJI0+1y5pa Fy03IA/Xo95QGNNkHBBJlmA2yA3DO6GhK9Cqpup/Czs0gAdiepYASrU5bnobvnvqedPU bv+gEB9iSLIxQI00v1fGeqjVJkRwdaOerFCFiCFcOTERFho/yrqJvxlhIU0BjZObx/Ds /xPtfTXAp4D2jje10ZQky6cQk9HVYPFwfhIWZjxinfB5fLsujmq3CdVa5jsWKetuZrfD guhw== X-Gm-Message-State: AOJu0Yw8eSlt0deaGC/4lmkSfDxdI/kNL/Vq+zChA64YMFn9GTbCe6Y8 +2RS87BLK1iS+j+63LrGCTc= X-Received: by 2002:a17:906:3193:b0:9a2:256a:65cd with SMTP id 19-20020a170906319300b009a2256a65cdmr10288792ejy.4.1693297112147; Tue, 29 Aug 2023 01:18:32 -0700 (PDT) Received: from nam-dell (ip-217-105-46-58.ip.prioritytelecom.net. [217.105.46.58]) by smtp.gmail.com with ESMTPSA id h11-20020a170906590b00b00992e14af9b9sm5643992ejq.134.2023.08.29.01.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 01:18:31 -0700 (PDT) Date: Tue, 29 Aug 2023 10:18:30 +0200 From: Nam Cao To: Conor Dooley Cc: Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, bjorn@kernel.org Subject: Re: [PATCH] riscv: provide riscv-specific is_trap_insn() Message-ID: References: <20230827205641.46836-1-namcaov@gmail.com> <20230829-unbridle-condense-2fc45a442bb6@wendy> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230829-unbridle-condense-2fc45a442bb6@wendy> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Tue, Aug 29, 2023 at 07:26:54AM +0100, Conor Dooley wrote: > On Tue, Aug 29, 2023 at 01:56:34PM +0800, Guo Ren wrote: > > On Mon, Aug 28, 2023 at 4:56 AM 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/probes/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. Sorry, was too quick that I missed the last sentence. Now I'm not sure what you mean. But I agree with Guo Ren here, users can use compressed instructions but kernel does not have it enabled. So we should always check c.ebreak regardless of RISCV_ISA_C. Best regards, Nam