Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2231074/?format=api
{ "id": 2231074, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2231074/?format=api", "web_url": "http://patchwork.ozlabs.org/project/opensbi/patch/20260430102313.95249-2-zhangzhanpeng.jasper@bytedance.com/", "project": { "id": 67, "url": "http://patchwork.ozlabs.org/api/1.1/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": "" }, "msgid": "<20260430102313.95249-2-zhangzhanpeng.jasper@bytedance.com>", "date": "2026-04-30T10:23:12", "name": "[1/2] lib: sbi: sse: fix KVM context corruption", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "aa519afa13dcb75acbd8d4d77255211ac6283aaa", "submitter": { "id": 93288, "url": "http://patchwork.ozlabs.org/api/1.1/people/93288/?format=api", "name": "Zhanpeng Zhang", "email": "zhangzhanpeng.jasper@bytedance.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/opensbi/patch/20260430102313.95249-2-zhangzhanpeng.jasper@bytedance.com/mbox/", "series": [ { "id": 502269, "url": "http://patchwork.ozlabs.org/api/1.1/series/502269/?format=api", "web_url": "http://patchwork.ozlabs.org/project/opensbi/list/?series=502269", "date": "2026-04-30T10:23:11", "name": "lib: sbi: sse: fix interrupted context corruption", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/502269/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2231074/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2231074/checks/", "tags": {}, "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=ZMe9uT0a;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256\n header.s=desiato.20200630 header.b=CqvDW4pf;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=bytedance.com header.i=@bytedance.com\n header.a=rsa-sha256 header.s=google header.b=DU7NktAZ;\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 4g5qyb72Hhz1yGq\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 30 Apr 2026 20:23:48 +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 1wIOYW-00000005BkD-1086;\n\tThu, 30 Apr 2026 10:23:40 +0000", "from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wIOYU-00000005Bjv-3SX6\n\tfor opensbi@bombadil.infradead.org;\n\tThu, 30 Apr 2026 10:23:38 +0000", "from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030])\n\tby desiato.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wIOYR-000000077NN-27jo\n\tfor opensbi@lists.infradead.org;\n\tThu, 30 Apr 2026 10:23:37 +0000", "by mail-pj1-x1030.google.com with SMTP id\n 98e67ed59e1d1-35fb16e56efso452510a91.2\n for <opensbi@lists.infradead.org>;\n Thu, 30 Apr 2026 03:23:35 -0700 (PDT)", "from FJ7FR2JRQ3.bytedance.net ([139.177.225.247])\n by smtp.gmail.com with ESMTPSA id\n 98e67ed59e1d1-364dbeb2db0sm321070a91.10.2026.04.30.03.23.30\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Thu, 30 Apr 2026 03:23:32 -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=9XeF62DrnqKCVYF46Xun9+MAG0kkRBFvv82Z/68yWyo=; b=ZMe9uT0aqMNxp7\n\thhM53bmVYZbVVuIMG5AJY2NZEHgCOalrPDQ85yiwW16mONSR3OM7mwBqTnl7RZhF39ots+F41jYaT\n\tthGwMSir0ARgd1OOzfcdiPPgKJ2XGKYOV4yJwjEu686Uu2uwQiWIyy1fM/sANlPvMtC1rhOF1dzeY\n\teuHkamsDotqaN6UsTWINDfPKVVjR+xTtUt+zuGnyBO9+v5/gDCOngwijKBRJxc1f9R+EShZI7Jlb6\n\tqaNFpL+eqVCCVJ7a+MCUYqxNqFJcbwlun20nbbWtACH1zmaMgs6jqHwAHReqhSx3WTgzjMgzNgeZ+\n\tBS+Evw7B+gsG2rrWRzvA==;", "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version\n\t:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:\n\tContent-Type:Content-ID:Content-Description;\n\tbh=8BgGYh3OdD8cFpgNoQy0g+rCyOpzePwhfsUs3zFLRGw=; b=CqvDW4pfBfxHuszPn+vXeVWk4k\n\t+jodopOc6SYgoMjDpXTyJNZKg2d04r4tXhChKLMbEhs7ybXH5gwjLSHd40KmrdvGZIHoakmS2wHSs\n\tRM+aH+9q1zLR4eBCAi6UKPgm1zyUINofa8eadjvVowqkbzbacgjN7gEqgwpqxHnFEwTVvcoDvffbQ\n\te0KNbBXqoeBlYfNgyYPAQNE9ttF6tpMJJ+ThQKE6MZRjDK1oX2xinen1DPfXyERz6xCGkZ4n01Rnp\n\tVZH91BmDB8MhPsH+9zpWc3VTcfMv3YSDmUVfa1fflTp+9D3mHEHgF+fmBuhcm0YxlNHUZRLQwPYB3\n\te4t0+nIw==;", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=bytedance.com; s=google; t=1777544613; x=1778149413;\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=8BgGYh3OdD8cFpgNoQy0g+rCyOpzePwhfsUs3zFLRGw=;\n b=DU7NktAZ4U8te3/EOkTWPOf1tgcw0Jx0uY0bTB8mITb+uXmH0OBE7w9OgftuUJ3y6T\n ClVHVgTNjGfUt2OxDIqHfZXtUoro75VA8tis+4U9QgOy5FmOc8RrrJ8YTNW3UiINeqe7\n Y5IeBYtDM8pgS4GwIYdh3uwciqZE1mWTwj7Yf7kNDflQm3rHOaJt4NBL5JLYdyf/cUMf\n 4B1vVp1nwG71CWSOSbu14JjxYEEHvnz60x4r5i5EaFhfQK3NcDzk6tJxlmLf/4iNVO9U\n pjGVhXX+aXcxN2XZUDg5+08/T7cPp19nEvtXPMo/g4CtXCR5gWBtC2/op5vvP7qEB2OX\n KC4w==" ], "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777544613; x=1778149413;\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=8BgGYh3OdD8cFpgNoQy0g+rCyOpzePwhfsUs3zFLRGw=;\n b=Rs2NsBaKnu6bOJNkV8XHqsLt5agezVzkP81f+GPfMeGE2YeXXxdV4GOJKrgSm2ZI1x\n /w36PLEUGB541FGLimQ82EGLUKKeUbWWTeBTVtUUa+FNjC7gUh9+riZ7D0+R0CxTnNI3\n cZpRiLi4x2OLhuzuuUhXpZccMsjPBXAIpMGWL8EIJwN3MrAnS0jzxQakHbY/7O/q77g0\n /rhnZJs6f/QI1BJuQxqnF+eny0M91G8VNt7N5sEeUYDOlV0xqZ7bM7Heedve1HZm/Vjq\n 6s/d/4i6JPHEbUCeXWdVEUQS6309W1cG1QVNCeiN0Ji25lRiWyaPwxBpxIJlUWWl8rzk\n eeRQ==", "X-Gm-Message-State": "AOJu0YyoD9w74UtB25giA+U18DoZrakzs97ejPrTaRQpuNJF3ABQmmaB\n\tckj7tP701JKEZkpYk/pqt5Rfe0/UBrQvexjXfARuUI4c6rdbcU/a9z5pi6rdtgz+lmTeECMmGkD\n\tILNXT", "X-Gm-Gg": "AeBDiesojavcVxOKX30PP0Mjlaj6m7e9fM9YNM1hoi5ItStOHvxvexp7CG9TwYRXeB/\n\tkoMjS76pox3P3btD0j/NCul4EVdKMMxf8WrSCrMiwOaC4pw20cjDfy/FsJ/22JksbqNLqsGOprv\n\tmSNHgIx+haJWLTfR1r99JRIA0wwmC5xPXZmIZI4c0LmdOAOhlzZXj5HINc64b0h22jM8untNBzt\n\tHq/mgIoEOqCTMhWW2pvVLlS7aQcSVIjZlDcsRQGz+ohhcmMHQ+CB0b0zDrMjyTxiGCCgZ6wENX7\n\tyyj6fFcYZTl3G+c5BEauUzRfx+NrICj2Ugb0Efqd4SgdnN87uhaQyYSIxKk9zW+zrGFaD1RDx5V\n\tSl0WeupAG7VQ/YY+GmlJHjQEz3qVCQQBHNlnFwYZt0G244vMYAl2ZtmqxysbI3e6DLmu3Ot6jRX\n\ttbxdFboKSQjFS9+SO7/f/HkTOw+mybHPj5vNsj6XbBSUz8oWWu6lQM+BhfLJ4KxdYYvRjNg9u4F\n\tEuZd/6iRQ==", "X-Received": "by 2002:a17:90b:4c87:b0:35a:1762:92fc with SMTP id\n 98e67ed59e1d1-364c30ff6e9mr2462447a91.26.1777544613385;\n Thu, 30 Apr 2026 03:23:33 -0700 (PDT)", "From": "Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>", "To": "opensbi@lists.infradead.org", "Cc": "cleger@rivosinc.com,\n\tanup@brainfault.org,\n\tatishp@atishpatra.org,\n\tcuiyunhui@bytedance.com,\n\tyuanzhu@bytedance.com,\n\tZhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>", "Subject": "[PATCH 1/2] lib: sbi: sse: fix KVM context corruption", "Date": "Thu, 30 Apr 2026 18:23:12 +0800", "Message-ID": "<20260430102313.95249-2-zhangzhanpeng.jasper@bytedance.com>", "X-Mailer": "git-send-email 2.50.1", "In-Reply-To": "<20260430102313.95249-1-zhangzhanpeng.jasper@bytedance.com>", "References": "<20260430102313.95249-1-zhangzhanpeng.jasper@bytedance.com>", "MIME-Version": "1.0", "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ", "X-CRM114-CacheID": "sfid-20260430_112335_831320_1B87D376 ", "X-CRM114-Status": "GOOD ( 15.62 )", "X-Spam-Score": "-0.2 (/)", "X-Spam-Report": "Spam detection software,\n running on the system \"desiato.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: SSE injection builds a synthetic S-mode context to enter\n the\n registered S-mode handler. If the interrupted context belongs to KVM guest\n execution, OpenSBI must not let that synthetic context overwrite [...]\n Content analysis details: (-0.2 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:1030 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_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_EF Message has a valid DKIM or DK signature from\n envelope-from domain\n -0.1 DKIM_VALID Message has at least one valid DKIM or DK\n signature", "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": "SSE injection builds a synthetic S-mode context to enter the registered\nS-mode handler. If the interrupted context belongs to KVM guest\nexecution, OpenSBI must not let that synthetic context overwrite the\nvirtualization state needed to resume the interrupted context.\n\nKVM Context Corruption happens because the old complete path rebuilt\nhstatus SPV/SPVP from interrupted flags and derived MPV from\nhandler-visible hstatus. However, this is insufficient on\nvirtualization-enabled systems: hstatus carries more H-mode state, and\nMPV must come from the state captured before OpenSBI prepares the\nsynthetic handler-entry context. Reconstructing these values from\nhandler-visible state can corrupt the KVM resume context.\n\nSave the complete hstatus value and the interrupted MPV state in\nOpenSBI's private SSE resume state before constructing the handler\ncontext. The state is stored in sbi_sse_event because it should persist\nfrom injection to completion, but it must not be part of the ABI-visible\nSSE attributes that the S-mode handler can update.\n\nThis is the OpenSBI side of the KVM context corruption fix. The related\nLinux side should preserve the kernel stvec in do_sse() to help protect\nthe virtualization context.\n\nLink: https://lore.kernel.org/r/9290f53d-3545-4299-9781-c1c558f71158@rivosinc.com\nFixes: c8cdf01d8f3a (\"lib: sbi: Add support for Supervisor Software Events extension\")\nSigned-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>\n---\n lib/sbi/sbi_sse.c | 53 ++++++++++++++++++++++++++++-------------------\n 1 file changed, 32 insertions(+), 21 deletions(-)", "diff": "diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c\nindex 818afb87..0544449d 100644\n--- a/lib/sbi/sbi_sse.c\n+++ b/lib/sbi/sbi_sse.c\n@@ -70,6 +70,19 @@ struct sse_ipi_inject_data {\n \tuint32_t event_id;\n };\n \n+/*\n+ * OpenSBI-private state used to resume the interrupted context after the SSE\n+ * event handler completes. Keep this separate from SSE attributes: S-mode can\n+ * update attributes before completion, while these fields preserve\n+ * M-mode-owned state.\n+ */\n+struct sse_resume_state {\n+\t/* Complete hstatus value, used to restore H-mode virtualization state. */\n+\tunsigned long hstatus;\n+\t/* MPV bit from mstatus/mstatusH, used to restore virtualization state. */\n+\tbool prev_virt;\n+};\n+\n struct sbi_sse_event_attrs {\n \tunsigned long status;\n \tunsigned long prio;\n@@ -100,6 +113,7 @@ assert_field_offset(interrupted.a7, SBI_SSE_ATTR_INTERRUPTED_A7);\n \n struct sbi_sse_event {\n \tstruct sbi_sse_event_attrs attrs;\n+\tstruct sse_resume_state resume;\n \tuint32_t event_id;\n \tu32 hartindex;\n \tstruct sse_event_info *info;\n@@ -545,6 +559,7 @@ static void sse_event_inject(struct sbi_sse_event *e,\n \t\t\t struct sbi_trap_regs *regs)\n {\n \tstruct sse_interrupted_state *i_ctx = &e->attrs.interrupted;\n+\tstruct sse_resume_state *r_ctx = &e->resume;\n \n \tsse_event_set_state(e, SBI_SSE_STATE_RUNNING);\n \n@@ -552,9 +567,10 @@ static void sse_event_inject(struct sbi_sse_event *e,\n \n \ti_ctx->a6 = regs->a6;\n \ti_ctx->a7 = regs->a7;\n-\ti_ctx->flags = sse_interrupted_flags(regs->mstatus);\n \ti_ctx->sepc = csr_read(CSR_SEPC);\n \n+\tr_ctx->prev_virt = sbi_regs_from_virt(regs);\n+\n \tregs->mstatus &= ~(MSTATUS_SPP | SSTATUS_SPIE);\n \tif (regs->mstatus & MSTATUS_MPP)\n \t\tregs->mstatus |= MSTATUS_SPP;\n@@ -563,22 +579,24 @@ static void sse_event_inject(struct sbi_sse_event *e,\n \n \tif (misa_extension('H')) {\n \t\tunsigned long hstatus = csr_read(CSR_HSTATUS);\n+\t\tunsigned long prev_mode = (regs->mstatus & MSTATUS_MPP) >>\n+\t\t\t\t\t MSTATUS_MPP_SHIFT;\n \n-#if __riscv_xlen == 64\n-\t\tif (regs->mstatus & MSTATUS_MPV)\n-#elif __riscv_xlen == 32\n-\t\tif (regs->mstatusH & MSTATUSH_MPV)\n-#else\n-#error \"Unexpected __riscv_xlen\"\n-#endif\n+\t\tr_ctx->hstatus = hstatus;\n+\n+\t\tif (r_ctx->prev_virt)\n \t\t\thstatus |= HSTATUS_SPV;\n+\t\telse\n+\t\t\thstatus &= ~HSTATUS_SPV;\n \n \t\thstatus &= ~HSTATUS_SPVP;\n-\t\tif (hstatus & HSTATUS_SPV && regs->mstatus & SSTATUS_SPP)\n-\t\t\t\thstatus |= HSTATUS_SPVP;\n+\t\tif ((hstatus & HSTATUS_SPV) && prev_mode == PRV_S)\n+\t\t\thstatus |= HSTATUS_SPVP;\n \n \t\tcsr_write(CSR_HSTATUS, hstatus);\n \t}\n+\n+\ti_ctx->flags = sse_interrupted_flags(regs->mstatus);\n \tcsr_write(CSR_SEPC, regs->mepc);\n \n \t/* Setup entry context */\n@@ -608,6 +626,7 @@ static void sse_event_resume(struct sbi_sse_event *e,\n \t\t\t struct sbi_trap_regs *regs)\n {\n \tstruct sse_interrupted_state *i_ctx = &e->attrs.interrupted;\n+\tstruct sse_resume_state *r_ctx = &e->resume;\n \n \tregs->mepc = csr_read(CSR_SEPC);\n \n@@ -616,26 +635,18 @@ static void sse_event_resume(struct sbi_sse_event *e,\n \t\tregs->mstatus |= (PRV_S << MSTATUS_MPP_SHIFT);\n \n \tif (misa_extension('H')) {\n-\t\tunsigned long hstatus = csr_read(CSR_HSTATUS);\n #if __riscv_xlen == 64\n \t\tregs->mstatus &= ~MSTATUS_MPV;\n-\t\tif (hstatus & HSTATUS_SPV)\n+\t\tif (r_ctx->prev_virt)\n \t\t\tregs->mstatus |= MSTATUS_MPV;\n #elif __riscv_xlen == 32\n \t\tregs->mstatusH &= ~MSTATUSH_MPV;\n-\t\tif (hstatus & HSTATUS_SPV)\n+\t\tif (r_ctx->prev_virt)\n \t\t\tregs->mstatusH |= MSTATUSH_MPV;\n #else\n #error \"Unexpected __riscv_xlen\"\n #endif\n-\t\thstatus &= ~(HSTATUS_SPV | HSTATUS_SPVP);\n-\t\tif (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV)\n-\t\t\thstatus |= HSTATUS_SPV;\n-\n-\t\tif (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP)\n-\t\t\thstatus |= HSTATUS_SPVP;\n-\n-\t\tcsr_write(CSR_HSTATUS, hstatus);\n+\t\tcsr_write(CSR_HSTATUS, r_ctx->hstatus);\n \t}\n \n \tregs->mstatus &= ~MSTATUS_SIE;\n", "prefixes": [ "1/2" ] }