get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2216423/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2216423,
    "url": "http://patchwork.ozlabs.org/api/patches/2216423/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/opensbi/patch/20260326115517.2156-4-dave.patel@riscstar.com/",
    "project": {
        "id": 67,
        "url": "http://patchwork.ozlabs.org/api/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": "<20260326115517.2156-4-dave.patel@riscstar.com>",
    "list_archive_url": null,
    "date": "2026-03-26T11:55:17",
    "name": "[v2,3/3] lib: sbi: domain FP/Vector context support for context switch",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "b3b00f878e0f539844370c262a5989cff98d6710",
    "submitter": {
        "id": 92617,
        "url": "http://patchwork.ozlabs.org/api/people/92617/?format=api",
        "name": "Dave Patel",
        "email": "dave.patel@riscstar.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/opensbi/patch/20260326115517.2156-4-dave.patel@riscstar.com/mbox/",
    "series": [
        {
            "id": 497579,
            "url": "http://patchwork.ozlabs.org/api/series/497579/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/opensbi/list/?series=497579",
            "date": "2026-03-26T11:55:16",
            "name": "[v2,1/3] lib: sbi: Add RISC-V vector context save/restore support (eager switching)",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/497579/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2216423/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2216423/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=E3aIRjJo;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=riscstar-com.20230601.gappssmtp.com\n header.i=@riscstar-com.20230601.gappssmtp.com header.a=rsa-sha256\n header.s=20230601 header.b=mqzQZJRk;\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 4fhMgd3lPBz20KT\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 26 Mar 2026 22:56:25 +1100 (AEDT)",
            "from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w5jJx-00000005O2E-2mEH;\n\tThu, 26 Mar 2026 11:56:17 +0000",
            "from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w5jJt-00000005O0L-1McD\n\tfor opensbi@lists.infradead.org;\n\tThu, 26 Mar 2026 11:56:15 +0000",
            "by mail-wr1-x42e.google.com with SMTP id\n ffacd0b85a97d-43b8e8e7432so736931f8f.1\n        for <opensbi@lists.infradead.org>;\n Thu, 26 Mar 2026 04:56:12 -0700 (PDT)",
            "from localhost.localdomain ([78.41.211.48])\n        by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-43b9194311asm8932438f8f.10.2026.03.26.04.56.10\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 26 Mar 2026 04:56:10 -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=RKpSEETuB5zkBzyWfDyFNkE9IBnXpAerMf5Kc0j0UyU=; b=E3aIRjJosLx4xN\n\tLkauub1VIvDIfKxzqlf6M+OxEI2YXSQNvFltEKR4xMlcjj+U5UdJvkQQ9D9oXsD20mf21v1sUasus\n\tv1TUNaxX7cjVpI3V264GH6vgzwUsOltnl+8cPLcOI6sfGn7SbH9bCYIpV4DUreRcOmo1peWl0Qbtb\n\tIXpBtb7HFBKdUDOKOZgsoLhQQvuIp5e/sRWT6Zy8iX3UsjUvRhzBLXsYw1W2jW3jS8yK/WeDKb/1Y\n\tvzDrJPEN1V+isgfLIe4OP1jOmTUq29Y8xOrhopt8LYxHVQLRpafVG0JEsIKsj7M4E/AsUgeU22fCV\n\tRSmAsu4HPf5PgXW+zxdw==;",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1774526171;\n x=1775130971; 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=Ljgj4+32qHDwKQaMS54fpU6MtdzWuMBOcdg/hCIJvcs=;\n        b=mqzQZJRkMogIlWBW3LVmZJtc/lKCQisxB2mnZONXoSjQo5wwjJygf8R4j5ICWPpp7u\n         6Ds4rD3RFnW3uyimDbUStjitUWXJnf289dcxj0Bp9M35UGSbPWUPnbKXaILNUL9JWEZb\n         uqp7/NdEJdhqEwYQ05BSL8P7+JHYDpYqzA2dVXCKTQ9iGJnQ/vQjJqGVHXX6r1YUyHJh\n         6rZLYpjMFsL8KbAtz4hqxIRliCEJEA8XvJKIZ6O+kZLqTvjwIN4nV7QlIWqr+9L8qJ1H\n         VdfYGU2IQtzXxCzhAdRqVLbCzaVUffpr06EqhUG3bOdxMqa5EJx9rhlwvOuw+GcOGwgX\n         yzFA=="
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1774526171; x=1775130971;\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=Ljgj4+32qHDwKQaMS54fpU6MtdzWuMBOcdg/hCIJvcs=;\n        b=q5l1D8V7UEmQoBK1c1W7I2PmsZUaP5u/qMz+T5HHq3P0k0MOC1KMOqOZdA6VxpmEzt\n         Z2czV9MFh8oTurKQR5IaBulpNDmUkisyRpFBamQcZwDlihExgMR43o3iNLRYjniapBH5\n         fll3YHJgG1/BWeUHmLEArGXkhXJ/KGVHH53nnnnUDovwyDD6KJ+5RUOV1o0we5xNm/Zk\n         0azQYJhCLbyXBeILLFohQ5PZ12UbWNZ+fx0Xrjp+43Bh3JSD2Ju76nECj9JfrMGPaEeH\n         VxO2rDz1CKHvbiPUxMJ5vgbXlR0Ol1kzUw3p3GTITajXN4pQyMHVG2C08RvTjLdOmeQI\n         Fuyg==",
        "X-Forwarded-Encrypted": "i=1;\n AJvYcCUWQUUCmnHH689frKHbyKhjgsRSu1DD/N+oHGJM57KuGonXXLMG0eqcNZNSUhKG7hr7DBOeWyLj@lists.infradead.org",
        "X-Gm-Message-State": "AOJu0YzFfR/ALk7+h9i3JohjVvTg51rHiibjiplQNUsX8L8SV84l2zF1\n\tvdZ79o4l/1LcQsjbVvvmazhnsoJJM7cAu40DPnqJEtBH15h0Nnqx4ITXLwgLd7TbbkQ=",
        "X-Gm-Gg": "ATEYQzw3Dmbovzrm1gReFXZfAcWPON0CeVJ9TYgC+ypSvgAyUkCP05CuuHGrHNdzVDB\n\tI8daSfx+Jk1WAKm5TjN14H2yaRe83mAIM9Tbw2yTPr5EVmx17CyhLM18Lq0ayM4sjolxScNVlDN\n\tw57J2UKCiar37aM1cEh4CHvkTyWWGHOXkKLdF/gpT++GfCW5FWFQNrFLA/oZRCJ9v1bi4i1e0Sb\n\tv9qaqdB/tSLUDep2hMuHThj/bg5Dv3+YARVQ39R6YTSln5kGUJvky+m31QzmDghGgkpiHuJIgV7\n\tWytsUL51nSUmXWgp3F5S8uaAOdMqbtyJSvsL76xecHG80MWqJmAiL8GMX96CKvWOY8/n75suLWf\n\tz0qfMKKTvpNewWN3f7U0cYzqK7oPRAiDU1jtVeG62VW+gUqaKGOAg2kfi8dPGesHPaKZ3ldD9h5\n\tlGVBcosPX+70nMgplTYtUJgFGT7UQX2o6mvEVjBA==",
        "X-Received": "by 2002:a05:6000:2481:b0:43b:498f:dcec with SMTP id\n ffacd0b85a97d-43b8896ce55mr10606265f8f.3.1774526171230;\n        Thu, 26 Mar 2026 04:56:11 -0700 (PDT)",
        "From": "dave.patel@riscstar.com",
        "To": "Samuel Holland <samuel.holland@sifive.com>",
        "Cc": "Scott Bambrough <scott@riscstar.com>,\n\tRobin Randhawa <robin.randhawa@sifive.com>,\n\tAnup Patel <anup.patel@qti.qualcomm.com>,\n\tDave Patel <dave.patel@riscstar.com>,\n\tRay Mao <raymond.mao@riscstar.com>,\n\tAnup Patel <anuppate@qti.qualcomm.com>,\n\tDhaval <dhaval@rivosinc.com>,\n\tPeter Lin <peter.lin@sifive.com>,\n\topensbi@lists.infradead.org",
        "Subject": "[PATCH v2 3/3] lib: sbi: domain FP/Vector context support for context\n switch",
        "Date": "Thu, 26 Mar 2026 11:55:17 +0000",
        "Message-ID": "<20260326115517.2156-4-dave.patel@riscstar.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20260326115517.2156-1-dave.patel@riscstar.com>",
        "References": "<20260326115517.2156-1-dave.patel@riscstar.com>",
        "MIME-Version": "1.0",
        "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ",
        "X-CRM114-CacheID": "sfid-20260326_045613_919012_92E5588E ",
        "X-CRM114-Status": "GOOD (  19.47  )",
        "X-Spam-Score": "-1.9 (-)",
        "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:  From: Dave Patel <dave.patel@riscstar.com> This patch adds\n    proper support for per-domain floating-point (FP) and vector (V) contexts\n    in the domain context switch logic. Each domain now maintains its own FP\n   and vector state, which is saved and [...]\n Content analysis details:   (-1.9 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                             [2a00:1450:4864:20:0:0:0:42e listed in]\n                             [list.dnswl.org]\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n -0.0 SPF_PASS               SPF: sender matches SPF record\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\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": "From: Dave Patel <dave.patel@riscstar.com>\n\nThis patch adds proper support for per-domain floating-point (FP) and\nvector (V) contexts in the domain context switch logic. Each domain\nnow maintains its own FP and vector state, which is saved and restored\nduring domain switches.\n\nChanges include:\n\n- Added `fp_ctx` and `vec_ctx` members to `struct sbi_domain`.\n- Introduced `sbi_fp_domain_init/exit()` and `sbi_vector_domain_init/exit()`\n  to allocate and free per-domain FP and vector context.\n- Modified `sbi_domain_register()` to initialize FP/Vector context per domain.\n- Updated `switch_to_next_domain_context()` to save/restore FP and vector\n  contexts safely:\n    - Ensures FS/VS fields in `mstatus` are enabled (set to Initial) only if Off.\n    - Restores original FS/VS bits after context switch.\n    - Adds NULL checks to handle domains without FP or Vector extensions.\n- Updated domain context deinit to free FP and vector contexts per domain.\n- Added runtime checks for FP and vector extensions where needed.\n- Corrected handling of MSTATUS FS/VS bits to avoid unsafe full-bit writes.\n\nThis improves support for multi-domain systems with FP and Vector\nextensions, and prevents corruption of FP/Vector state during domain\nswitches.\n\nSigned-off-by: Dave Patel <dave.patel@riscstar.com>\n---\n include/sbi/sbi_domain.h     |  4 ++++\n include/sbi/sbi_fp.h         |  7 ++++++\n include/sbi/sbi_vector.h     |  5 +++++\n lib/sbi/sbi_domain.c         | 22 +++++++++++++++++++\n lib/sbi/sbi_domain_context.c | 42 ++++++++++++++++++++++++++++++++++++\n lib/sbi/sbi_fp.c             | 31 ++++++++++++++++++++++++++\n lib/sbi/sbi_vector.c         | 30 ++++++++++++++++++++++++++\n 7 files changed, 141 insertions(+)\n\n--\n2.43.0",
    "diff": "diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h\nindex 882b62c2..e68ec46d 100644\n--- a/include/sbi/sbi_domain.h\n+++ b/include/sbi/sbi_domain.h\n@@ -217,6 +217,10 @@ struct sbi_domain {\n \tbool fw_region_inited;\n \t/** per-domain wired-IRQ courier state */\n \tvoid *virq_priv;\n+    /** per-domain float context state */\n+    void *fp_ctx;\n+    /** per-domain vector context state */\n+    void *vec_ctx;\n };\n\n /** The root domain instance */\ndiff --git a/include/sbi/sbi_fp.h b/include/sbi/sbi_fp.h\nindex 5794b66f..2de9bf04 100644\n--- a/include/sbi/sbi_fp.h\n+++ b/include/sbi/sbi_fp.h\n@@ -9,6 +9,9 @@\n #define __SBI_FP_H__\n\n #include <sbi/riscv_encoding.h>\n+#include <sbi/sbi_domain.h>\n+#include <sbi/sbi_error.h>\n+#include <sbi/sbi_console.h>\n\n #if defined(__riscv_f) || defined(__riscv_d)\n\n@@ -25,6 +28,8 @@ struct sbi_fp_context {\n\n void sbi_fp_save(struct sbi_fp_context *dst);\n void sbi_fp_restore(const struct sbi_fp_context *src);\n+int  sbi_fp_domain_init(struct sbi_domain *dom);\n+void sbi_fp_domain_exit(struct sbi_domain *dom);\n\n #else /* No FP (e.g., Zve32x) */\n\n@@ -32,6 +37,8 @@ struct sbi_fp_context { };\n\n static inline void sbi_fp_save(struct sbi_fp_context *dst) { }\n static inline void sbi_fp_restore(const struct sbi_fp_context *src) { }\n+static inline int  sbi_fp_domain_init(struct sbi_domain *dom) { return SBI_OK;}\n+static inline void sbi_fp_domain_exit(struct sbi_domain *dom) {}\n\n #endif //defined(__riscv_f) || defined(__riscv_d)\n #endif //__SBI_VECTOR_H__\ndiff --git a/include/sbi/sbi_vector.h b/include/sbi/sbi_vector.h\nindex ae151406..c8295f05 100644\n--- a/include/sbi/sbi_vector.h\n+++ b/include/sbi/sbi_vector.h\n@@ -10,6 +10,9 @@\n #define __SBI_VECTOR_H__\n\n #include <sbi/sbi_types.h>\n+#include <sbi/sbi_domain.h>\n+#include <sbi/sbi_error.h>\n+#include <sbi/sbi_console.h>\n\n #ifdef CONFIG_SBI_MAX_VLENB\n #define SBI_MAX_VLENB CONFIG_SBI_MAX_VLENB\n@@ -30,6 +33,8 @@ struct sbi_vector_context {\n struct sbi_vector_context *sbi_current_vector_context(void);\n void sbi_vector_save(struct sbi_vector_context *dst);\n void sbi_vector_restore(const struct sbi_vector_context *src);\n+int  sbi_vector_domain_init(struct sbi_domain *dom);\n+void sbi_vector_domain_exit(struct sbi_domain *dom);\n\n #endif //__SBI_VECTOR_H__\n\ndiff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c\nindex 498a1d56..cdc416b4 100644\n--- a/lib/sbi/sbi_domain.c\n+++ b/lib/sbi/sbi_domain.c\n@@ -19,6 +19,8 @@\n #include <sbi/sbi_scratch.h>\n #include <sbi/sbi_string.h>\n #include <sbi/sbi_virq.h>\n+#include <sbi/sbi_vector.h>\n+#include <sbi/sbi_fp.h>\n\n SBI_LIST_HEAD(domain_list);\n\n@@ -703,6 +705,26 @@ int sbi_domain_register(struct sbi_domain *dom,\n \t\treturn rc;\n \t}\n\n+    /* Init per-domain floating context */\n+    rc = sbi_fp_domain_init(dom);\n+    if (rc) {\n+        sbi_printf(\"%s: fp init failed for %s (error %d)\\n\",\n+                __func__, dom->name, rc);\n+        sbi_list_del(&dom->node);\n+        return rc;\n+    }\n+\n+#ifdef __riscv_v\n+    /* Init per-domain vector context */\n+    rc = sbi_vector_domain_init(dom);\n+    if (rc) {\n+        sbi_printf(\"%s: vec init failed for %s (error %d)\\n\",\n+                __func__, dom->name, rc);\n+        sbi_list_del(&dom->node);\n+        return rc;\n+    }\n+#endif\n+\n     return 0;\n }\n\ndiff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c\nindex 158f4990..fb843a91 100644\n--- a/lib/sbi/sbi_domain_context.c\n+++ b/lib/sbi/sbi_domain_context.c\n@@ -18,6 +18,9 @@\n #include <sbi/sbi_domain_context.h>\n #include <sbi/sbi_platform.h>\n #include <sbi/sbi_trap.h>\n+#include <sbi/sbi_vector.h>\n+#include <sbi/sbi_fp.h>\n+\n\n /** Context representation for a hart within a domain */\n struct hart_context {\n@@ -143,6 +146,37 @@ static int switch_to_next_domain_context(struct hart_context *ctx,\n \tif (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))\n \t\tctx->srmcfg\t= csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);\n\n+    /* Read current mstatus */\n+    unsigned long mstatus = csr_read(CSR_MSTATUS);\n+    unsigned long new_mstatus = mstatus;\n+\n+    /* Ensure FS is enabled (not Off) */\n+    if ((mstatus & MSTATUS_FS) == 0)\n+        new_mstatus |= MSTATUS_FS;\n+\n+#ifdef __riscv_v\n+    /* Ensure VS is enabled (not Off) */\n+    if ((mstatus & MSTATUS_VS) == 0)\n+        new_mstatus |= MSTATUS_VS;\n+#endif\n+\n+    /* Update mstatus only if needed */\n+    if (new_mstatus != mstatus)\n+    csr_write(CSR_MSTATUS, new_mstatus);\n+\n+    /* Save current domain context and restore target domain's F and V context */\n+    sbi_fp_save(current_dom->fp_ctx);\n+    sbi_fp_restore(target_dom->fp_ctx);\n+#ifdef __riscv_v\n+    sbi_vector_save(current_dom->vec_ctx);\n+    sbi_vector_restore(target_dom->vec_ctx);\n+#endif\n+\n+    /* Restore original mstatus if we modified it */\n+    if (new_mstatus != mstatus) {\n+        csr_write(CSR_MSTATUS, mstatus);\n+    }\n+\n \t/* Save current trap state and restore target domain's trap state */\n \ttrap_ctx = sbi_trap_get_context(scratch);\n \tsbi_memcpy(&ctx->trap_ctx, trap_ctx, sizeof(*trap_ctx));\n@@ -286,5 +320,13 @@ int sbi_domain_context_init(void)\n\n void sbi_domain_context_deinit(void)\n {\n+    struct sbi_domain *dom;\n+    sbi_domain_for_each(dom) {\n+#ifdef __riscv_v\n+        sbi_vector_domain_exit(dom);\n+#endif\n+        sbi_fp_domain_exit(dom);\n+    }\n+\n \tsbi_domain_unregister_data(&dcpriv);\n }\ndiff --git a/lib/sbi/sbi_fp.c b/lib/sbi/sbi_fp.c\nindex b6651577..ee0782d1 100644\n--- a/lib/sbi/sbi_fp.c\n+++ b/lib/sbi/sbi_fp.c\n@@ -7,6 +7,7 @@\n  */\n\n #include <sbi/riscv_asm.h>\n+#include <sbi/sbi_heap.h>\n #include <sbi/riscv_encoding.h>\n #include <sbi/sbi_fp.h>\n\n@@ -185,4 +186,34 @@ void sbi_fp_restore(const struct sbi_fp_context *src)\n\n \tcsr_write(CSR_FCSR, src->fcsr);\n }\n+\n+int sbi_fp_domain_init(struct sbi_domain *dom)\n+{\n+    if (!dom)\n+        return SBI_EINVAL;\n+\n+    if (dom->fp_ctx)\n+        return SBI_OK;\n+\n+   sbi_printf(\"[FPU] Init FP Context \\n\");\n+\n+   struct sbi_fp_context *fp;\n+   fp = sbi_zalloc(sizeof(*fp));\n+   if (!fp)\n+       return SBI_ENOMEM;\n+\n+   dom->fp_ctx = fp;\n+\n+   return SBI_OK;\n+}\n+\n+void sbi_fp_domain_exit(struct sbi_domain *dom)\n+{\n+   if (!dom || !dom->fp_ctx)\n+        return;\n+\n+   sbi_free(dom->fp_ctx);\n+   dom->fp_ctx = NULL;\n+}\n+\n #endif // FP present\ndiff --git a/lib/sbi/sbi_vector.c b/lib/sbi/sbi_vector.c\nindex e14b658c..2dfb9fbf 100644\n--- a/lib/sbi/sbi_vector.c\n+++ b/lib/sbi/sbi_vector.c\n@@ -10,6 +10,7 @@\n #include <sbi/riscv_encoding.h>\n #include <sbi/riscv_asm.h>\n #include <sbi/sbi_vector.h>\n+#include <sbi/sbi_heap.h>\n\n static inline unsigned long vector_vlenb(void)\n {\n@@ -144,3 +145,32 @@ void sbi_vector_restore(const struct sbi_vector_context *src)\n\n #undef RESTORE_VREG\n }\n+\n+int sbi_vector_domain_init(struct sbi_domain *dom)\n+{\n+    if (!dom)\n+        return SBI_EINVAL;\n+\n+    if (dom->vec_ctx)\n+        return SBI_OK;\n+\n+   sbi_printf(\"[Vector] Init Vector Context \\n\");\n+\n+   struct sbi_vector_context *v;\n+   v = sbi_zalloc(sizeof(*v));\n+   if (!v)\n+       return SBI_ENOMEM;\n+\n+   dom->vec_ctx = v;\n+\n+   return SBI_OK;\n+}\n+\n+void sbi_vector_domain_exit(struct sbi_domain *dom)\n+{\n+   if (!dom || !dom->vec_ctx)\n+        return;\n+\n+   sbi_free(dom->vec_ctx);\n+   dom->vec_ctx = NULL;\n+}\n",
    "prefixes": [
        "v2",
        "3/3"
    ]
}