From nobody Wed Dec 17 03:02:27 2025 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 AB610C83F10 for ; Sun, 27 Aug 2023 21:06:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230240AbjH0VGT (ORCPT ); Sun, 27 Aug 2023 17:06:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjH0VF6 (ORCPT ); Sun, 27 Aug 2023 17:05:58 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347BE12D for ; Sun, 27 Aug 2023 14:05:56 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-401b393ddd2so24444295e9.0 for ; Sun, 27 Aug 2023 14:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693170354; x=1693775154; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GJAK2lEo2Ushg+QTBvqS02TVMVDEl0y6m3BBQOKXzGM=; b=FopJmSg7ZXozcyNB81zsjPNDv5AbQ9Ya0jOuSJcY0GLmMSsEpwREdij13eT186ZdWo IqMmJViX0DgTZfr7I5rRz6uN4nAG7DexDjeWzmcjIWOhH5jGL4mzHCSFyKDyCv5ib/PO 2XLf0/szlthiHRdTgbsS13jo6FSjZDgmx4JjbJa1oUVAwghZZOmlrN3tatpamsmThu91 ZdeSl/e/ayQO3VUjt95AM0uwKRAi2agjB+lIZgv0ceRUAgohi51TAn/wn14iMRw07PI+ EKwW1MstpvEKeYGIV/Mon71W+VW+nQOyPb80iPUH/UPsHTJFFz6FxEwABgkES1wMJHHc 6oMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693170354; x=1693775154; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GJAK2lEo2Ushg+QTBvqS02TVMVDEl0y6m3BBQOKXzGM=; b=O9Xz1jOgaH+RvgIZZoQhL2V8tcMUNOETywgUSCkzOlUVoCWMI8k18UKZOhYSktr9SA jMQpOT3O+w8+pwepQBnA51oI4zSakidcIBK/1NgqKeObN6AnB5JnDTLwJEF5fBwBw8Kj CTDD4ctUCDGGq3/pJ2aK6HR2y0333J1+/IKj4YvBkf8L1WR1mUd8hAF40cbs3SSjDwjA AU10uEuOjGpvKLhHgjacTX8frCxBGbaMuGkGQwtkxUOJTKRLyEDrVVk1TFt95BO9NHWb WdXhDfln4DLp8ayplxFwonWreOFgfWqp/ThX4AQ2rWeyS8vNlXre1TwmUdDrCjqD05LC t5ew== X-Gm-Message-State: AOJu0YyWvuzY8I330asxcA9FZf9zfHYdOSH2PL4WtYEc+3CdUagB/ax5 YuG02n+9rWfSpCs127CRWIxTONYSceo= X-Google-Smtp-Source: AGHT+IHP5M1qiNTQZpm6LuN89GbfBfpH51fArtUnAdfRI5sTiMPPAGKYSQphLdCYxaxDZABFQSyEUg== X-Received: by 2002:a17:907:a05c:b0:9a1:bd53:b23 with SMTP id gz28-20020a170907a05c00b009a1bd530b23mr12148538ejc.14.1693169811749; Sun, 27 Aug 2023 13:56:51 -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 z3-20020a1709064e0300b009a19fa8d2e9sm3799181eju.206.2023.08.27.13.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 13:56:51 -0700 (PDT) From: Nam Cao To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, bjorn@kernel.org, guoren@kernel.org Cc: Nam Cao Subject: [PATCH] riscv: provide riscv-specific is_trap_insn() Date: Sun, 27 Aug 2023 22:56:41 +0200 Message-Id: <20230827205641.46836-1-namcaov@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Tested-by: Bj=C3=B6rn T=C3=B6pel --- 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 =20 #include "decode-insn.h" =20 @@ -17,6 +18,15 @@ bool is_swbp_insn(uprobe_opcode_t *insn) #endif } =20 +bool is_trap_insn(uprobe_opcode_t *insn) +{ +#ifdef CONFIG_RISCV_ISA_C + 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); --=20 2.34.1