From patchwork Tue Aug 29 08:36:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 13368685 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2CA93C83F16 for ; Tue, 29 Aug 2023 08:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Ovnpg/mty/iTxSgeknhpf6Xo3RCXsthzqIjtOOPjxzk=; b=zZsGEPpFNl1ZP+ YjQi0BDbVcWylk1QSX75LltS5O6ULSLshFVf2oYcWPs+fN1zdzi7lzVJTPz+nQmptJu3HmeFeHkUO e5/6xpB9BilYbOed539LYZUk+iT+F6a8/bqmbdOxM4pPYu2JwWabWA0kHpg5eSkRFmo9GoqD7HP1M R9VdMq9RTOdpQNAC8IJW7G2bd11MWD7obf4ECXNeJTW50LNFC4/zYO7tlmcHibjAV8yS31fZJJ/Y4 4e/rvce9RtKVEEAMii+s+fHbfq4Fn8Qjtt2SUVJuTbL7sJLXmraTfznBygmk15TFs3NLBLdaN92li YXUJtE/wYCHrf86uE2+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qauDz-00B2xj-2r; Tue, 29 Aug 2023 08:37:23 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qauDw-00B2xN-3A for linux-riscv@lists.infradead.org; Tue, 29 Aug 2023 08:37:22 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-99357737980so526340266b.2 for ; Tue, 29 Aug 2023 01:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693298239; x=1693903039; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Z9iMpNXmIevE0BgwMDd4WWAnKWJLVfTLbZLwahfl61w=; b=bHALBVKUf3mzqjp5qBc54g26ErG0SAuQJGsGxNfmi9t4X8AcX1imw+RSpS5Z3Kh6h8 ZkfFCO6U50LasBNoPW2zybtvb7zbV9y4T5QgXyYGXfSXJF17AW4lL+vt1eosQK4/KEAI zcK+Pcoc6yEtAQriLTCNQdPRF09WbFebyIw8+z1M4f3a/rpgdDZr6ofwLAaJukTjfx4X TQ92HdRCuqDNpVmSeeAycj931QggLaB+ifyEYj969j89qnKHfIdkVFN7ssU+XWKVY3o9 Ey4JzgHaVZnyWMZSPgekXDJFuIqRjG4ygfOFH8DEbmfxXPGFrmOeEGF5CAZFzd9ZaFya CVHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693298239; x=1693903039; 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=Z9iMpNXmIevE0BgwMDd4WWAnKWJLVfTLbZLwahfl61w=; b=cSqfPAGJTa8FkhpOhk5rxj4fCSf/wAW6BTlK1cDjtnIPpB+DEIPFhe462gHVSTOxDC VrWyBHc/w3z5eIds5+F2JSDCGCvZWV8NOxe6zTMPHd2XAWw2eNGwaZ1ECHGpzv1WOjF0 G8YdyAmyUiPZ0cGSIFSeZELXnk9YNY5g78LqlWoHA7y8mq0qKA5tG0ulO+wucXOkLO3S +rD9OZ3T6JgOIw2Usmcn57lzO5zKdZi0eTz5gtiinyBZZxon8RylQSfX3mRCEKeWmOaG S7Io8W2GiF0BGoGwMa7GCsQf5/bDDfkuIbBrJlS0uW/mWklAQk+pbBaPKsR2meZzaXDm 7DTA== X-Gm-Message-State: AOJu0Yy9oo/V+yF4gyaknhkEd+8wl4bOfte8hezvum3KcO0WLR5RIxM+ nhUnI+3OK0T7bSL5ivNO104= X-Google-Smtp-Source: AGHT+IG2AEi8AUkfv4qjEMaIGKPkcicN1p+fKc05evfp7vAQ8dWGFeUa2PUha7EV15lGbyxAZQ5UAg== X-Received: by 2002:a17:906:7699:b0:9a2:1e03:1573 with SMTP id o25-20020a170906769900b009a21e031573mr11068276ejm.65.1693298238863; Tue, 29 Aug 2023 01:37:18 -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 lx16-20020a170906af1000b0098de7d28c34sm5706257ejb.193.2023.08.29.01.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 01:37:18 -0700 (PDT) From: Nam Cao To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: bjorn@kernel.org, guoren@kernel.org, conor.dooley@microchip.com, Nam Cao , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= Subject: [PATCH v2] riscv: provide riscv-specific is_trap_insn() Date: Tue, 29 Aug 2023 10:36:15 +0200 Message-Id: <20230829083614.117748-1-namcaov@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230829_013721_026583_FE7B62E5 X-CRM114-Status: GOOD ( 10.35 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 causes an infinite loop of entering and exiting trap handler. Instead of using the default implementation, implement this function speficially for riscv with checks for both ebreak and c.ebreak. Fixes: 74784081aac8 ("riscv: Add uprobes supported") Signed-off-by: Nam Cao Tested-by: Björn Töpel Reviewed-by: Guo Ren --- v2: remove #ifdef CONFIG_RISCV_ISA_C (Guo Ren) arch/riscv/kernel/probes/uprobes.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probes/uprobes.c index 194f166b2cc4..4b3dc8beaf77 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,11 @@ bool is_swbp_insn(uprobe_opcode_t *insn) #endif } +bool is_trap_insn(uprobe_opcode_t *insn) +{ + return riscv_insn_is_ebreak(*insn) || riscv_insn_is_c_ebreak(*insn); +} + unsigned long uprobe_get_swbp_addr(struct pt_regs *regs) { return instruction_pointer(regs);