From nobody Wed Feb 15 16:43:04 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PH3m86fgQz3qXnD; Wed, 15 Feb 2023 16:43:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PH3m83T0Bz3npB; Wed, 15 Feb 2023 16:43:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676479384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=P37EmqZPlkp3aRDUBGMNg+EJvMrETzyUw0+UZYw16s0=; b=FZXAJoxf5XY48BpUacz9oeZHKZVn5Sx3YoXe0e+dSVH6gtCJFyY3t/fK3buP0Ir7UnrKB4 HaKXyWL6OrAHdwqZWJ/hnhwb9b9aROacTc7ZHozEDt0bczOKQnxIlqSfTGwb/wtrw06zdU RS3hQ7sjMLfXwPGIna1Ueloep5XWP12lHqMadruYqATy7JL0R5ddxDUNUMRCE7oIgPFoq1 sNsd5baQ/fNqpUnQJS2N2eEuvU9Wud+Ll9moqgEiim/fsQT+zqkEI56ztfoMDymIoLxfFx 2KoPMT0zSZOSfn28k10pY4DqY9i2h2xCf4FY36VRSuXvY5b2gxB6yK1/lCVnig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676479384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=P37EmqZPlkp3aRDUBGMNg+EJvMrETzyUw0+UZYw16s0=; b=J5r6W1pi8Dw6AWgG3rHq2jI0xhOOc5iJia8lD5cFeGUwL7nMap5PndyZ1AAcucs0SWTFUL fco/nVa/JX3PRO2eD9g7NVBr0oUSOypUX/29AwzTO5KLLc3wYuEHpwHVlEjQZY0RW1JQxH PPr3D8baKFNxqIkRf/UPGhyMnruSTCF464TizduD1HaJav9T5HIYmx13hKtODvlZut7kRh 9A/miu3JOSrRl8lQd9efGI2fC9zCmSZTrnVl7g2ZdHCjnGyxgm8yZ/Yxx2NnAz6sO3L16M ttMD+T7H3fIGdyH3PBuAY0/0NVJj39Kw/iNCLD0ag5LLqWAdfOtu2OnXMYcdUA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676479384; a=rsa-sha256; cv=none; b=BtHvldQQmvGaA+LyjfSU8UNRwEFThf7sdW4+LLloNR/Ruvzng/4OF9T6vC2BXXZ1Q6zSEc trHyI88MGfJJO0hElUytErnQn2yL2IyHasgbOMTB13JqtsuDfc1GRkfmXjpqtNlp4svyhb KCwbgPLDLJpymoazawfhgnvGsXrJvNP/j94jtsT7ajvbJ6NiAY7/aE7FYBsgIZ6iVbBY3i x88eZpWjNw4xpfY2RJ78tlxdBZTaxBOsO2+NEvBVYc15k9WfRbm3edhpANKpgHSpwyNJBG DQd5XaizRnzdqo27pz6WXn2+5waSj3DY1Rq80GcYJ6jtb5ASc7+yw+orXeIfmQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PH3m8244gzWr4; Wed, 15 Feb 2023 16:43:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31FGh4US002077; Wed, 15 Feb 2023 16:43:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31FGh4Zc002076; Wed, 15 Feb 2023 16:43:04 GMT (envelope-from git) Date: Wed, 15 Feb 2023 16:43:04 GMT Message-Id: <202302151643.31FGh4Zc002076@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 2f0fc9ab8912 - stable/13 - dtrace: handle page faults in riscv dtrace_trap() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2f0fc9ab8912d3446ba67ed28bc7f6d226b16144 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=2f0fc9ab8912d3446ba67ed28bc7f6d226b16144 commit 2f0fc9ab8912d3446ba67ed28bc7f6d226b16144 Author: Mitchell Horne AuthorDate: 2023-02-06 18:08:35 +0000 Commit: Mitchell Horne CommitDate: 2023-02-15 16:41:39 +0000 dtrace: handle page faults in riscv dtrace_trap() We must detect the correct amount to increment sepc, as it may have been a compressed instruction that triggered the fault. Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38299 (cherry picked from commit 06faad1de2c9aadcfd606d5f7121b201dbfbaa9d) --- sys/cddl/dev/dtrace/riscv/dtrace_subr.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sys/cddl/dev/dtrace/riscv/dtrace_subr.c b/sys/cddl/dev/dtrace/riscv/dtrace_subr.c index 1e24a88f6c75..f32bb3a2343e 100644 --- a/sys/cddl/dev/dtrace/riscv/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/riscv/dtrace_subr.c @@ -63,6 +63,8 @@ typedef struct dtrace_invop_hdlr { dtrace_invop_hdlr_t *dtrace_invop_hdlr; +static int match_opcode(uint32_t insn, int match, int mask); + int dtrace_invop(uintptr_t addr, struct trapframe *frame) { @@ -188,6 +190,8 @@ dtrace_gethrestime(void) int dtrace_trap(struct trapframe *frame, u_int type) { + uint16_t insn; + /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets @@ -196,9 +200,7 @@ dtrace_trap(struct trapframe *frame, u_int type) * flag is cleared and finally re-scheduling is enabled. * * Check if DTrace has enabled 'no-fault' mode: - * */ - if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { /* * There are only a couple of trap types that are expected. @@ -208,15 +210,24 @@ dtrace_trap(struct trapframe *frame, u_int type) case SCAUSE_LOAD_ACCESS_FAULT: case SCAUSE_STORE_ACCESS_FAULT: case SCAUSE_INST_ACCESS_FAULT: + case SCAUSE_INST_PAGE_FAULT: + case SCAUSE_LOAD_PAGE_FAULT: + case SCAUSE_STORE_PAGE_FAULT: /* Flag a bad address. */ cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; - cpu_core[curcpu].cpuc_dtrace_illval = 0; + cpu_core[curcpu].cpuc_dtrace_illval = frame->tf_stval; /* * Offset the instruction pointer to the instruction - * following the one causing the fault. + * following the one causing the fault. Check if the + * instruction is compressed or not. Standard + * instructions always have bits [1:0] == 11. */ - frame->tf_sepc += 4; + insn = *(uint16_t *)frame->tf_sepc; + if (match_opcode(insn, 0x3, 0x3)) + frame->tf_sepc += INSN_SIZE; + else + frame->tf_sepc += INSN_C_SIZE; return (1); default: