From nobody Mon Feb 06 19:28:07 2023 X-Original-To: dev-commits-src-main@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 4P9brl59Htz3n5Sw; Mon, 6 Feb 2023 19:28:07 +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 4P9brl4k8mz3lgD; Mon, 6 Feb 2023 19:28:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675711687; 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=6870ChMr/DaLGpvPvFWdD72anQLsyZdcxxgxzeeU+8g=; b=TWDEJhNilWJHVH6KDoUaaMF23K3Y5xHp6fEYRuz72XxRNVBU5OP+SJqIFVJHcgYiGehH4R ZDr/k7N6WwW92qsyNZ9TYN9tQwIBtGmxwQmjmaMks3LudUsx3kX/qebvnj8cTG3zS0G7lL oVTXrCkI/HLZaiToWOvJ6wmMBpprBnN9RZNNH+feK/8OawnR6RYTuVMigA/VR1knn5XHiT As90k6DYjxUuoNqs8wyECCaoxgIcJY/AogN4Wx5Ta623uXB1tu9yKVfhmpLJbk5rdYxE2S NOFG3tEnI5cSw12OloOAdDY8o+qxXxv4YS71qDJt+lGTXZI88bhN9W+xyOQBcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675711687; 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=6870ChMr/DaLGpvPvFWdD72anQLsyZdcxxgxzeeU+8g=; b=NNFyNukR8dBGY+Z5RjNYuZxlYQAt7b9QlG4xc+Fhl5T6sntNj9yXB/vsCqoNNIjVcQ66K8 emP247rHw11X+/FQyaJwvcVJuA5T/rUY0/4QO1u4WYDiKioQlMSpkz3qmD1uJstxSRVDai aq5La4XPFmfHUxgi91pbeE61/Yc+wjFCYUsTyvffHRBbJDMD2zlnBdvuTSa3khwAk4gmAn DgnuzwrNgwgXEjHBP2z4gsFSktMMrFr8ivfUb3VL6ShvLDD22ssSjaD31YtvTV/5SSmwX4 oBnmhZ1bDZX26bJGnESvX3G+sePe6mKIKglkhVEKHzVk+Y7oVfvs9f6cB0yUaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675711687; a=rsa-sha256; cv=none; b=tbGusuRChNIJGhqvtl2xSikxOV8R3kBO9xfWX05X1ZxdhYTDL70lPCUZD9j2KO3QFJO8Yl GfcW/FOklnTpgevHIjeKEGKIkFifs6/Tj5suQOWhEcH3/K82bKrWc4XEQTR037jt/w7k7i tjTYAhAJZ3kut1v+lgrpY0MyWjBMNWI/VuqgEMOcnm0gMpvcZzgpgHcARIrWedlW92zmeU BI5rkQDxGxZ9gv8E8Y73KTvtUWtgrsmqiO/2wJHhGsQWnK7OoX+uGmTS6vsWDixmj2HKTV RJM0XKjz8pi4dD3y8/SjMU/21tdFFOfe7o/Kd//Bli98DyKURNWDlQ3lf0S0Fg== 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 4P9brl3p7jzmt2; Mon, 6 Feb 2023 19:28:07 +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 316JS73C006444; Mon, 6 Feb 2023 19:28:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 316JS7af006443; Mon, 6 Feb 2023 19:28:07 GMT (envelope-from git) Date: Mon, 6 Feb 2023 19:28:07 GMT Message-Id: <202302061928.316JS7af006443@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 06faad1de2c9 - main - dtrace: handle page faults in riscv dtrace_trap() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 06faad1de2c9aadcfd606d5f7121b201dbfbaa9d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=06faad1de2c9aadcfd606d5f7121b201dbfbaa9d commit 06faad1de2c9aadcfd606d5f7121b201dbfbaa9d Author: Mitchell Horne AuthorDate: 2023-02-06 18:08:35 +0000 Commit: Mitchell Horne CommitDate: 2023-02-06 19:26:53 +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 --- 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: