Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/2231984/?format=api
{ "id": 2231984, "url": "http://patchwork.ozlabs.org/api/1.2/patches/2231984/?format=api", "web_url": "http://patchwork.ozlabs.org/project/opensbi/patch/20260501211627.3293126-5-evvoevod@tenstorrent.com/", "project": { "id": 67, "url": "http://patchwork.ozlabs.org/api/1.2/projects/67/?format=api", "name": "OpenSBI development", "link_name": "opensbi", "list_id": "opensbi.lists.infradead.org", "list_email": "opensbi@lists.infradead.org", "web_url": "https://github.com/riscv/opensbi", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "https://github.com/riscv/opensbi/commit/{}" }, "msgid": "<20260501211627.3293126-5-evvoevod@tenstorrent.com>", "list_archive_url": null, "date": "2026-05-01T21:16:26", "name": "[v2,4/5] lib: sbi: Create a spot to place Smrnmi detection before traps and after DT is ready", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "8c3be9151f3a499cbad944fee2443fbe90b5b5b3", "submitter": { "id": 92832, "url": "http://patchwork.ozlabs.org/api/1.2/people/92832/?format=api", "name": "Evgeny Voevodin", "email": "evvoevod@tenstorrent.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/opensbi/patch/20260501211627.3293126-5-evvoevod@tenstorrent.com/mbox/", "series": [ { "id": 502498, "url": "http://patchwork.ozlabs.org/api/1.2/series/502498/?format=api", "web_url": "http://patchwork.ozlabs.org/project/opensbi/list/?series=502498", "date": "2026-05-01T21:16:26", "name": "Add RISC-V Smrnmi extension support", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/502498/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2231984/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2231984/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lfEKO8uA;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=tenstorrent.com header.i=@tenstorrent.com\n header.a=rsa-sha256 header.s=google header.b=M6LWSVBW;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g6kPf6wGJz1yK9\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 02 May 2026 07:16:51 +1000 (AEST)", "from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wIvE8-00000007grA-0qaj;\n\tFri, 01 May 2026 21:16:48 +0000", "from mail-dy1-x1330.google.com ([2607:f8b0:4864:20::1330])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wIvE5-00000007gp8-3wTm\n\tfor opensbi@lists.infradead.org;\n\tFri, 01 May 2026 21:16:47 +0000", "by mail-dy1-x1330.google.com with SMTP id\n 5a478bee46e88-2d89bbca7b5so82565eec.3\n for <opensbi@lists.infradead.org>;\n Fri, 01 May 2026 14:16:45 -0700 (PDT)", "from ausc-rvsw-c-02.tenstorrent.com ([38.104.49.66])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2ee3b29b2casm5879308eec.14.2026.05.01.14.16.44\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 01 May 2026 14:16:44 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=vdb8/kh2oPViJ5EqvR0W8qY93j9q0DkoODozfCUm4Rw=; b=lfEKO8uArji+7z\n\tWWIiJd3ixilUKlt9rzVsFpIa4R1KwAxTFobQFGt6mW0GaQEgXqwk8Y9lSJuktfiAoo/xcXwLvry67\n\tznYXr0vIbuXidvC2qvhcTgBQ52PfqK6v0Lo915uSwNkjII1FN/OCJqztg7jng90Nnhy/O7lc4quzu\n\tz6XJFezjy7ljwSXFiJNX3FTSdku9bRM4xFmGkSiwyBr3EifGRSkQh2GRMwjoC9LnlAcryCQ2k+lJq\n\t5GxwrK9rxSiy/I7Sif0NVauZSWB6DUe3lHEqalb/HjW9zgs2B6o+yYdTQtVTM2/fUkYKmiYJ3oIhx\n\tVJrVnr4wii4BO6Mf0jAg==;", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=tenstorrent.com; s=google; t=1777670205; x=1778275005;\n darn=lists.infradead.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=evtpahHgey/LViSW9orNGKIgfTTrmbI9FkmZnQYePjk=;\n b=M6LWSVBWW17x0cg8Xny99MPbW7Kyw232D8gHfXjU4KDND3lt7UnmakZM71S5mN+1aP\n WK0FFYzl9JiE1PAisUYl21jLLtF31Of06d1RNlsd9qrwSqWin5Y0b08yQI8iEGN5stHv\n lT733g6JGv07+k5pQosZei2YnrBptrywUOoZ0whlXVyKCYO9bYZNeinUdoxCsC+v6LSz\n 1o4468HvNYSi0/fP7SUU182kXPSBsQh8RGIaFNs1WJ9pnhR4TQtsTGYU6mrPp7xuLkaL\n p+cJIh1427V9EZAEumUoiif9/4lQPHwyff29dJ9I4dVrHbeiW2+XNHPhx0ULSyn4hLLE\n MJyg==" ], "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777670205; x=1778275005;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=evtpahHgey/LViSW9orNGKIgfTTrmbI9FkmZnQYePjk=;\n b=H2niJSioXU0oLT8THzyTwLsnPDShcKX3WdtHeCykDzkAXQMphVuTuplIuWhDudN7oL\n U6xIKwIJdVqfo0BHd+KHCqjDhf89EiZrd48M6mr01hopyVoXMwWI8WgEhyz5kcMEsyJC\n NcGTLs+RB4c0oW4zzIH+qjikpGbI+Pfqa/qfnVUS7wPAQ0Z9XNGqSYYh0JE7naLcOF2/\n XgsTsb3nKXMMOJJZ06vd6Kvy4d02z+z4tGLArrcs9QrpgdDr4fX22zhxggsjzslykv1J\n 8Mlb67n/ScrTR9mEMEOFNnJZGcWK+M7ZuHj3qj3Bkq9dnJbtdWHeWkxqDXz0JFSmF71N\n GOCg==", "X-Gm-Message-State": "AOJu0YwQ80Jl2qttu6IIr7qsDZstN/vDPkiThYNeJW+tw3z9wmSG6ddM\n\tAQukVATs0MlgE14pBgj76X2daqqLzcJyX7+uEKuUMvuSzp5WNrZsC2NhtclMxpX0Idd3MWOBqwJ\n\t5cznM", "X-Gm-Gg": "AeBDievJepUsvNndz0jAnxTL1EJfvS4yXhgxaW4/ANXcCZRagZJ5gBsfMn7ZpNSG2pH\n\tGYRgLj5/gzVhCqY7gSF0mOdN/5HdMRsFhEPBTtpGtuZibjKfxtNemYn+hEolcyF916+41jMY9W+\n\t1CM7kBbmt7Hk0hwieP/Md9UEi74znWYd+D59dm8EQkBd6XRmHNr/K1HvchMPHxPLDkj/tsYK+/e\n\tSmoPQ6wMAoAaBj255lE0o6JN5csH83I7+9GnmA9N/gGllDtIhEh63Ix4/EQOgKlnI74whnBBj2l\n\tsoYjNamlFWHwRp/hlSqwVBhWg+Nik4xIM5umCm4i7ZxyATZCVwgmywvVSBxBi/hLD8z+mjap1HE\n\tHAOFhn26kidF4vIejM5GqaBDTaFtjp2pvniyHzJku1wbfPZhJqxtzFxHg1WlzK4DmcoeLimxscY\n\tDW9uMe0IP36op04FoX4DqSsiFnMASueDXWQ863jaHreCXgMCpGKwR4Sj64excR", "X-Received": "by 2002:a05:7300:6c29:b0:2dd:5641:ef0 with SMTP id\n 5a478bee46e88-2efba176588mr183748eec.6.1777670204698;\n Fri, 01 May 2026 14:16:44 -0700 (PDT)", "From": "Evgeny Voevodin <evvoevod@tenstorrent.com>", "To": "opensbi@lists.infradead.org", "Cc": "Anup Patel <anup@brainfault.org>,\n\tNylon Chen <nylon.chen@sifive.com>,\n\tevvoevod@tenstorrent.com", "Subject": "[PATCH v2 4/5] lib: sbi: Create a spot to place Smrnmi detection\n before traps and after DT is ready", "Date": "Fri, 1 May 2026 21:16:26 +0000", "Message-ID": "<20260501211627.3293126-5-evvoevod@tenstorrent.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20260501211627.3293126-1-evvoevod@tenstorrent.com>", "References": "<20260501211627.3293126-1-evvoevod@tenstorrent.com>", "MIME-Version": "1.0", "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ", "X-CRM114-CacheID": "sfid-20260501_141645_982930_04B7E69E ", "X-CRM114-Status": "GOOD ( 16.58 )", "X-Spam-Score": "-2.1 (--)", "X-Spam-Report": "Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam. The original\n message has been attached to this so you can view it or label\n similar future email. If you have any questions, see\n the administrator of that system for details.\n Content preview: Since Smrnmi is detected from the device tree,\n move sbi_platform_extensions_init()\n before trap-based feature detection so the extension is known when the\n next\n commit acts on it. The Zkr seed-CSR access can trap if Zkr is not\n implemented.\n On Smrnmi platforms NMIE=0 by default after reset, which routes that trap\n to NMEVEC rather than MTVEC. Until Smrnmi handlers are installed a [...]\n Content analysis details: (-2.1 points, 5.0 required)\n pts rule name description\n ---- ----------------------\n --------------------------------------------------\n -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no\n trust\n [2607:f8b0:4864:20:0:0:0:1330 listed in]\n [list.dnswl.org]\n -0.0 SPF_PASS SPF: sender matches SPF record\n 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record\n -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from\n envelope-from domain\n -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from\n author's\n domain\n 0.1 DKIM_SIGNED Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID Message has at least one valid DKIM or DK\n signature\n -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1%\n [score: 0.0000]", "X-BeenThere": "opensbi@lists.infradead.org", "X-Mailman-Version": "2.1.34", "Precedence": "list", "List-Id": "<opensbi.lists.infradead.org>", "List-Unsubscribe": "<http://lists.infradead.org/mailman/options/opensbi>,\n <mailto:opensbi-request@lists.infradead.org?subject=unsubscribe>", "List-Archive": "<http://lists.infradead.org/pipermail/opensbi/>", "List-Post": "<mailto:opensbi@lists.infradead.org>", "List-Help": "<mailto:opensbi-request@lists.infradead.org?subject=help>", "List-Subscribe": "<http://lists.infradead.org/mailman/listinfo/opensbi>,\n <mailto:opensbi-request@lists.infradead.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Sender": "\"opensbi\" <opensbi-bounces@lists.infradead.org>", "Errors-To": "opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org" }, "content": "Since Smrnmi is detected from the device tree, move\nsbi_platform_extensions_init() before trap-based feature detection so\nthe extension is known when the next commit acts on it.\n\nThe Zkr seed-CSR access can trap if Zkr is not implemented. On Smrnmi\nplatforms NMIE=0 by default after reset, which routes that trap to\nNMEVEC rather than MTVEC. Until Smrnmi handlers are installed and\nNMIE=1, no NMEVEC handler is in place, so an early-boot trap there\nwould crash. Refactor the inline seed loop in fw_base.S into a\ncallable __stack_chk_guard_init function and invoke it from\ninit_coldboot() after sbi_hart_init() returns; the next commit makes\nsbi_hart_init() install Smrnmi handlers and set NMIE=1, so by the time\n__stack_chk_guard_init runs the trap path is safe.\n\nSigned-off-by: Evgeny Voevodin <evvoevod@tenstorrent.com>\n---\n firmware/fw_base.S | 64 +++++++++++++++++++++++++++++-----------------\n lib/sbi/sbi_hart.c | 16 +++++++-----\n lib/sbi/sbi_init.c | 10 ++++++++\n 3 files changed, 60 insertions(+), 30 deletions(-)", "diff": "diff --git a/firmware/fw_base.S b/firmware/fw_base.S\nindex 043de7d7..ebecfecc 100644\n--- a/firmware/fw_base.S\n+++ b/firmware/fw_base.S\n@@ -107,30 +107,6 @@ _bss_zero:\n \tadd\ts4, s4, __SIZEOF_POINTER__\n \tblt\ts4, s5, _bss_zero\n \n-\t/* Trying to initialize the stack guard via the Zkr extension */\n-\tlla\tt0, __stack_chk_guard_done\n-\tcsrw\tCSR_MTVEC, t0\n-\tli\tt0, 0\n-\tli\tt3, SEED_OPTS_ES16\n-\tli\tt4, SEED_ENTROPY_MASK\n-\tli\tt5, __SIZEOF_POINTER__\n-__stack_chk_guard_loop:\n-\tcsrrw\tt1, CSR_SEED, x0\n-\tli\tt2, SEED_OPTS_MASK\n-\tand\tt2, t2, t1\n-\tbgtu\tt2, t3, __stack_chk_guard_done\n-\tbltu\tt2, t3, __stack_chk_guard_loop\n-\tand\tt1, t1, t4\n-\tslli\tt0, t0, 16\n-\tor\tt0, t0, t1\n-\taddi\tt5, t5, -2\n-\tbgtz\tt5, __stack_chk_guard_loop\n-\tlla\tt1, __stack_chk_guard\n-\tREG_S\tt0, 0(t1)\n-\tj\t__stack_chk_guard_done\n-\t.align 3\n-__stack_chk_guard_done:\n-\n \t/* Setup temporary trap handler */\n \tlla\ts4, _start_hang\n \tcsrw\tCSR_MTVEC, s4\n@@ -895,6 +871,46 @@ __stack_chk_fail:\n \tla\ta0, .Lstack_corrupt_msg\n \tcall\tsbi_panic\n \n+\t/*\n+\t * Initialize __stack_chk_guard from the Zkr seed CSR. Called from C\n+\t * after Smrnmi has been enabled (NMIE=1), so that a missing-Zkr\n+\t * illegal-instruction trap is delivered to MTVEC normally and is\n+\t * caught by our temporary MTVEC redirect below.\n+\t */\n+\t.align 3\n+\t.globl __stack_chk_guard_init\n+\t.type __stack_chk_guard_init, %function\n+__stack_chk_guard_init:\n+\t/* Save current MTVEC so we can restore it on return */\n+\tcsrr\tt6, CSR_MTVEC\n+\n+\t/* Redirect MTVEC to local skip target for Zkr-not-supported case */\n+\tlla\tt0, 1f\n+\tcsrw\tCSR_MTVEC, t0\n+\n+\tli\tt0, 0\n+\tli\tt3, SEED_OPTS_ES16\n+\tli\tt4, SEED_ENTROPY_MASK\n+\tli\tt5, __SIZEOF_POINTER__\n+2:\n+\tcsrrw\tt1, CSR_SEED, x0\n+\tli\tt2, SEED_OPTS_MASK\n+\tand\tt2, t2, t1\n+\tbgtu\tt2, t3, 1f\n+\tbltu\tt2, t3, 2b\n+\tand\tt1, t1, t4\n+\tslli\tt0, t0, 16\n+\tor\tt0, t0, t1\n+\taddi\tt5, t5, -2\n+\tbgtz\tt5, 2b\n+\tlla\tt1, __stack_chk_guard\n+\tREG_S\tt0, 0(t1)\n+\tj\t1f\n+\t.align 3\n+1:\n+\tcsrw\tCSR_MTVEC, t6\n+\tret\n+\n \t/* Initial value of the stack guard variable */\n \t.section .data\n \t.align 3\ndiff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c\nindex 4aefb759..781161e5 100644\n--- a/lib/sbi/sbi_hart.c\n+++ b/lib/sbi/sbi_hart.c\n@@ -522,6 +522,16 @@ static int hart_detect_features(struct sbi_scratch *scratch)\n \thfeatures->mhpm_mask = 0;\n \thfeatures->priv_version = SBI_HART_PRIV_VER_UNKNOWN;\n \n+\t/*\n+\t * Parse device tree extensions early, before any trap-based checks.\n+\t * Needed to detect Smrnmi and install NMI handlers before CSR probes\n+\t * that may trigger traps.\n+\t */\n+\trc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(),\n+\t\t\t\t\t hfeatures);\n+\tif (rc)\n+\t\treturn rc;\n+\n #define __check_hpm_csr(__csr, __mask) \t\t\t\t\t \\\n \toldval = csr_read_allowed(__csr, &trap);\t\t\t \\\n \tif (!trap.cause) {\t\t\t\t\t\t \\\n@@ -676,12 +686,6 @@ __pmp_skip:\n \n #undef __check_csr_existence\n \n-\t/* Let platform populate extensions */\n-\trc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(),\n-\t\t\t\t\t hfeatures);\n-\tif (rc)\n-\t\treturn rc;\n-\n \t/* Zicntr should only be detected using traps */\n \t__sbi_hart_update_extension(hfeatures, SBI_HART_EXT_ZICNTR,\n \t\t\t sbi_hart_has_csr(scratch, SBI_HART_CSR_CYCLE) &&\ndiff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c\nindex aae035e1..644f62cb 100644\n--- a/lib/sbi/sbi_init.c\n+++ b/lib/sbi/sbi_init.c\n@@ -36,6 +36,8 @@\n #include <sbi/sbi_version.h>\n #include <sbi/sbi_unit_test.h>\n \n+extern void __stack_chk_guard_init(void);\n+\n #define BANNER \\\n \t\" ____ _____ ____ _____\\n\" \\\n \t\" / __ \\\\ / ____| _ \\\\_ _|\\n\" \\\n@@ -269,6 +271,14 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)\n \tif (rc)\n \t\tsbi_hart_hang();\n \n+\t/*\n+\t * Initialize stack-guard canary now that hart_detect_features()\n+\t * has enabled Smrnmi (NMIE=1). Done from a __noreturn function so\n+\t * the canary mutation doesn't trip our own exit check. The asm\n+\t * helper saves and restores MTVEC around its operation.\n+\t */\n+\t__stack_chk_guard_init();\n+\n \trc = sbi_timer_init(scratch, true);\n \tif (rc)\n \t\tsbi_hart_hang();\n", "prefixes": [ "v2", "4/5" ] }