Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5801287imu; Tue, 13 Nov 2018 11:59:25 -0800 (PST) X-Google-Smtp-Source: AJdET5cYRVYqxqVqUfIiczJZkPUf1U+Y90Gtd+ru/dd15YeWGXSK1UxG1HMIlC8rusAjB5qgXPuW X-Received: by 2002:a62:4786:: with SMTP id p6-v6mr1966068pfi.257.1542139165008; Tue, 13 Nov 2018 11:59:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542139164; cv=none; d=google.com; s=arc-20160816; b=BW9RApfdZ0GTgIbRvmELY0eo3URu8C/a1zZ1t3ndrpRRVfEnlzAr7x5d0u7AOFjAwU /T31D7U1Jni6L51U0SIpPnWTbPLCOvpq1vvLm0DGgRI74VHIHa39u5M9hGq6FvEoU763 vFl848RG9DakbFUYF8g30Qxm2CWi73bWrzh2nJtDM5WdjQUUIP1Px/GRYVx0qp+mafIY F7mpbgwuXVPxi/DubQNvTPg8uaLskIoA6Dhb0AeotukqmWhjQLHcFC0laCu7cvQumWIR trlbuBSsTgDpoO0KpF4TV2skqUc+R9HjNh+YTJGDkhwCY79cFUief7hUrPW03rJLO/6s 37vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=9UjJQcL0LDXt5kUGp9I8PhNAbrxDFqfFOMTobE/mshw=; b=05acJCJOEZT0l4BQl8rMnoq+2n2+sb4SmmgFlciHGcgjZpGvUCQfnl3H7lO8+rFfHs vDu0ZNCC+GNOQ6w1uWImuylBExfXv4yq9XVoUumZvzfBDpph5BSSz/LDMhW+1I4rFQq9 DZ8fRsSUGJ8Ot8y8x/Xcawz0B3m0QpoRwi6Bf0sb832PdBfi1qpPLo064B0+GnEiCZ3A 1IhM+y35b63yB4IjaS8P+hp3vafmHZdN1TmVsn4+xRJg2FQB0+ltSCVhAECT5wC1OVNe K5UGAiStmcEJT/xHav5MWit1nYyj/hKXf+YPLmbEscCMJEXsZquVD2Ohz6pkEl0o4GqZ mOXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r2-v6si19489010pgk.137.2018.11.13.11.59.09; Tue, 13 Nov 2018 11:59:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729768AbeKNF57 (ORCPT + 99 others); Wed, 14 Nov 2018 00:57:59 -0500 Received: from mail.binarylogic.ch ([88.198.23.72]:47876 "EHLO mail.binarylogic.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725748AbeKNF57 (ORCPT ); Wed, 14 Nov 2018 00:57:59 -0500 Received: from fortknox.localdomain (unknown [192.168.122.1]) by mail.binarylogic.ch (Postfix) with ESMTP id 49195DF386; Tue, 13 Nov 2018 20:58:18 +0100 (CET) From: =?UTF-8?q?Patrick=20St=C3=A4hlin?= To: linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?Patrick=20St=C3=A4hlin?= , Palmer Dabbelt , Albert Ou Subject: [RFC/RFT 0/2] RISC-V: kprobes/kretprobe support Date: Tue, 13 Nov 2018 20:58:02 +0100 Message-Id: <20181113195804.22825-1-me@packi.ch> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, this is first version of kprobes/kretprobe support for RISC-V. Most of the code is based on arm64 but obviously without the single-step functionality. It will insert a C.EBREAK instruction that is later being captured. The only instruction supported at the moment is C.ADDISP16 as this sets-up the stack frames for all the functions I've tested. I've tested this on QEMU with multiple CPUs but don't have any real hardware available for testing, and from experience that's when things start breaking. The plan is to expand compressed instructions to full ones and simulate those to reduce the decoding overhead per intercepted call. Please let me know if you have any objections to path I've chosen and which instructions you absolutely need for a first version. To enable this you need the following defines: CONFIG_FUNCTION_TRACER=y CONFIG_KPROBES=y CONFIG_MODULES=y The CONFIG_FUNCTION_TRACER is not strictly needed but makes testing easier using debugfs. After that, any example documented in Documentation/trace/kprobetrace.rst should work. Patrick Stählin (2): RISC-V: Implement ptrace regs and stack API RISC-V: kprobes/kretprobe support arch/riscv/Kconfig | 6 +- arch/riscv/include/asm/kprobes.h | 30 ++ arch/riscv/include/asm/probes.h | 26 ++ arch/riscv/include/asm/ptrace.h | 34 ++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/probes/Makefile | 3 + arch/riscv/kernel/probes/decode-insn.c | 38 ++ arch/riscv/kernel/probes/decode-insn.h | 23 + arch/riscv/kernel/probes/kprobes.c | 401 ++++++++++++++++++ arch/riscv/kernel/probes/kprobes_trampoline.S | 91 ++++ arch/riscv/kernel/probes/simulate-insn.c | 33 ++ arch/riscv/kernel/probes/simulate-insn.h | 8 + arch/riscv/kernel/ptrace.c | 99 +++++ arch/riscv/kernel/traps.c | 13 +- arch/riscv/mm/fault.c | 28 +- 15 files changed, 828 insertions(+), 6 deletions(-) create mode 100644 arch/riscv/include/asm/probes.h create mode 100644 arch/riscv/kernel/probes/Makefile create mode 100644 arch/riscv/kernel/probes/decode-insn.c create mode 100644 arch/riscv/kernel/probes/decode-insn.h create mode 100644 arch/riscv/kernel/probes/kprobes.c create mode 100644 arch/riscv/kernel/probes/kprobes_trampoline.S create mode 100644 arch/riscv/kernel/probes/simulate-insn.c create mode 100644 arch/riscv/kernel/probes/simulate-insn.h -- 2.17.1