{"id":2220781,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2220781/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-riscv/patch/20260407-riscv_insn_table-v1-9-54b4736a1e77@gmail.com/","project":{"id":70,"url":"http://patchwork.ozlabs.org/api/1.1/projects/70/?format=json","name":"Linux KVM RISC-V","link_name":"kvm-riscv","list_id":"kvm-riscv.lists.infradead.org","list_email":"kvm-riscv@lists.infradead.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260407-riscv_insn_table-v1-9-54b4736a1e77@gmail.com>","date":"2026-04-08T04:45:57","name":"[09/16] KVM: device: Add test device","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a50fa136e885fbea4ae0a9b8c3978bb9ddbaa846","submitter":{"id":92521,"url":"http://patchwork.ozlabs.org/api/1.1/people/92521/?format=json","name":"Charlie Jenkins via B4 Relay","email":"devnull+thecharlesjenkins.gmail.com@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/kvm-riscv/patch/20260407-riscv_insn_table-v1-9-54b4736a1e77@gmail.com/mbox/","series":[{"id":499063,"url":"http://patchwork.ozlabs.org/api/1.1/series/499063/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-riscv/list/?series=499063","date":"2026-04-08T04:45:48","name":"riscv: Generate riscv instruction functions","version":1,"mbox":"http://patchwork.ozlabs.org/series/499063/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2220781/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2220781/checks/","tags":{},"headers":{"Return-Path":"\n <kvm-riscv-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=HG0JbAaN;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=uzWNLKSz;\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=kvm-riscv-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 4fr9Wq6gv2z20wy\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 08 Apr 2026 14:46:47 +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 1wAKoP-00000008ElI-2vwE;\n\tWed, 08 Apr 2026 04:46:45 +0000","from sea.source.kernel.org ([172.234.252.31])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wAKoJ-00000008Ebf-2oJa;\n\tWed, 08 Apr 2026 04:46:41 +0000","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby sea.source.kernel.org (Postfix) with ESMTP id 44BA64458D;\n\tWed,  8 Apr 2026 04:46:37 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPS id 20BA8C4AF0D;\n\tWed,  8 Apr 2026 04:46:37 +0000 (UTC)","from aws-us-west-2-korg-lkml-1.web.codeaurora.org\n (localhost.localdomain [127.0.0.1])\n\tby smtp.lore.kernel.org (Postfix) with ESMTP id 1A759FD5F70;\n\tWed,  8 Apr 2026 04:46:37 +0000 (UTC)"],"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:Reply-To:List-Subscribe:List-Help:\n\tList-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:\n\tMessage-Id:MIME-Version:Subject:Date:From:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=AsueZXu4Qh9Fa307HFlP46yq6vW6Wasrs9OIsr6Hkq8=; b=HG0JbAaNBjNqyt\n\tu9eTGKdVjd2cP4rFflaEKAmrzi2eIcS18rpX8sXuJSLEDcZpsJqSoir04VWVCNc5OKt6Cndkcdw0n\n\tp6eN+pQuyRAVE+3qMjS81SxfqVGhRIz9PVst+qeSHzWzqsuDz7WRRlYoNbBNJvF8y79FhPeVnwKdF\n\tZGwRvGzwb+IPkoOdYCHzgmC6H/M0RTV13+bzK7/qDhP4qowe8GJJnZGnBCMn8NeQ8bfxzo7nDdS2p\n\tBkoqdmIn76T0Anl7jO7Nj0HEbjx1+yGBYjkIXgHQdtgJ3bHtTJ+HgfmaOWxE+nFxR3FDo5SWFsC5c\n\t3DN9a7LOvYnHbvFUQB5Q==;","v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1775623597;\n\tbh=4rkKpzRM+iL5DW5d8i7Gb0QM1Gb7i6+CJUfrUspb9+0=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From;\n\tb=uzWNLKSzAhTi6Ahozxerl0eEUN3LUv14i2hXo/oJKxgiu93fCYWgyKGoKHHpfUjYg\n\t 6+f9rrsfMXoIWtA9LcPvO5uS6ell428FdMsIMCKtr1vBlx0UpnYFK78dGSSKJCx4uM\n\t XCCeAGJWuDIB9/kBbpZaeLzBQRO7Wqn+3L/+kFs6TtO98AAHFrXQtZpgteIZdNe0FB\n\t RzHc1VoXFPGrrLBmaWETOA3WlVPtyCktYP0KvJfItFi8EQBeEXqaVpez3QhEcPzuSm\n\t k6ToGtaZ008xJeE7gEWqXMRJ+MHJbvjPt5aMsEEVXmcBWvmQkwWH6v6g96WaT3Nqis\n\t ZCRySpJBLuIJw=="],"From":"Charlie Jenkins via B4 Relay\n <devnull+thecharlesjenkins.gmail.com@kernel.org>","Date":"Tue, 07 Apr 2026 21:45:57 -0700","Subject":"[PATCH 09/16] KVM: device: Add test device","MIME-Version":"1.0","Message-Id":"<20260407-riscv_insn_table-v1-9-54b4736a1e77@gmail.com>","References":"<20260407-riscv_insn_table-v1-0-54b4736a1e77@gmail.com>","In-Reply-To":"<20260407-riscv_insn_table-v1-0-54b4736a1e77@gmail.com>","To":"Paul Walmsley <pjw@kernel.org>, Palmer Dabbelt <palmer@dabbelt.com>,\n Alexandre Ghiti <alex@ghiti.fr>, Anup Patel <anup@brainfault.org>,\n Atish Patra <atish.patra@linux.dev>, Conor Dooley <conor@kernel.org>,\n Paolo Bonzini <pbonzini@redhat.com>,\n Andrew Morton <akpm@linux-foundation.org>, Shuah Khan <shuah@kernel.org>","Cc":"linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,\n kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,\n linux-kselftest@vger.kernel.org,\n Charlie Jenkins <thecharlesjenkins@gmail.com>","X-Mailer":"b4 0.14.3","X-Developer-Signature":"v=1; a=ed25519-sha256; t=1775623594; l=6974;\n i=thecharlesjenkins@gmail.com; s=2026030; h=from:subject:message-id;\n bh=QpJ6SQoj8mJo2Tpd9rSMLwb1t2gleejCSJHykRZEP+I=;\n b=sr9oHdB3A54IHLnUQGX+jJlAhUeQ5WQiaw2xeIbsaTgW0FoX2Vbpbh03BeExP8+HGrVRt+yPb\n 6VhKUiq1d0yCDJ7D5vyyF0R9KYF4kgpVc2wDQJy++zH4H8y2TWkNwg0","X-Developer-Key":"i=thecharlesjenkins@gmail.com; a=ed25519;\n pk=vpF2USrG+aB6CTbSt34rzJKsAVe/l+GAXo1IomCMETk=","X-Endpoint-Received":"by B4 Relay for thecharlesjenkins@gmail.com/2026030\n with auth_id=663","X-Original-From":"Charlie Jenkins <thecharlesjenkins@gmail.com>","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260407_214639_781244_B18FC103 ","X-CRM114-Status":"GOOD (  21.50  )","X-Spam-Score":"-0.0 (/)","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: Charlie Jenkins Create a KVM test device to help\n verify\n    mmio reads and write emulation. This is a simple device that will store\n the\n    data in a buffer on writes and echo back that stored data on a read.\n Content analysis details:   (-0.0 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n  0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The\n                             query to Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                         [172.234.252.31 listed in\n sa-trusted.bondedsender.org]\n  0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to\n                              Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                             [172.234.252.31 listed in sa-accredit.habeas.com]\n  0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to\n                              Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                            [172.234.252.31 listed in\n bl.score.senderscore.com]\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_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\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]\n  2.1 FREEMAIL_FORGED_REPLYTO Freemail in Reply-To, but not From","X-BeenThere":"kvm-riscv@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"<kvm-riscv.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/kvm-riscv>,\n <mailto:kvm-riscv-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/kvm-riscv/>","List-Post":"<mailto:kvm-riscv@lists.infradead.org>","List-Help":"<mailto:kvm-riscv-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/kvm-riscv>,\n <mailto:kvm-riscv-request@lists.infradead.org?subject=subscribe>","Reply-To":"thecharlesjenkins@gmail.com","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"kvm-riscv\" <kvm-riscv-bounces@lists.infradead.org>","Errors-To":"kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"From: Charlie Jenkins <thecharlesjenkins@gmail.com>\n\nCreate a KVM test device to help verify mmio reads and write emulation.\nThis is a simple device that will store the data in a buffer on writes\nand echo back that stored data on a read.\n\nSigned-off-by: Charlie Jenkins <thecharlesjenkins@gmail.com>\n---\n include/uapi/linux/kvm.h |  2 +\n lib/Kconfig.debug        |  6 +++\n virt/kvm/Kconfig.debug   | 16 ++++++++\n virt/kvm/Makefile.kvm    |  1 +\n virt/kvm/kvm_main.c      |  8 ++++\n virt/kvm/mmio_test.c     | 95 ++++++++++++++++++++++++++++++++++++++++++++++++\n virt/kvm/mmio_test.h     | 18 +++++++++\n 7 files changed, 146 insertions(+)","diff":"diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h\nindex dddb781b0507..9e2918614246 100644\n--- a/include/uapi/linux/kvm.h\n+++ b/include/uapi/linux/kvm.h\n@@ -1209,6 +1209,8 @@ enum kvm_device_type {\n #define KVM_DEV_TYPE_LOONGARCH_EIOINTC\tKVM_DEV_TYPE_LOONGARCH_EIOINTC\n \tKVM_DEV_TYPE_LOONGARCH_PCHPIC,\n #define KVM_DEV_TYPE_LOONGARCH_PCHPIC\tKVM_DEV_TYPE_LOONGARCH_PCHPIC\n+\tKVM_DEV_TYPE_TEST,\n+#define KVM_DEV_TYPE_TEST\tKVM_DEV_TYPE_TEST\n \n \tKVM_DEV_TYPE_MAX,\n \ndiff --git a/lib/Kconfig.debug b/lib/Kconfig.debug\nindex ba36939fda79..7a4a23d1fc9e 100644\n--- a/lib/Kconfig.debug\n+++ b/lib/Kconfig.debug\n@@ -717,6 +717,12 @@ source \"net/Kconfig.debug\"\n \n endmenu # \"Networking Debugging\"\n \n+menu \"KVM Debugging\"\n+\n+source \"virt/kvm/Kconfig.debug\"\n+\n+endmenu # \"KVM Debugging\"\n+\n menu \"Memory Debugging\"\n \n source \"mm/Kconfig.debug\"\ndiff --git a/virt/kvm/Kconfig.debug b/virt/kvm/Kconfig.debug\nnew file mode 100644\nindex 000000000000..d24709f5bcbf\n--- /dev/null\n+++ b/virt/kvm/Kconfig.debug\n@@ -0,0 +1,16 @@\n+# SPDX-License-Identifier: GPL-2.0-only\n+\n+config KVM_MMIO_TEST\n+       bool \"Enable kvm mmio testing\"\n+       depends on KVM\n+       depends on KVM_MMIO\n+       default n\n+       help\n+         Enable testing for kvm mmio. This is a test-only mmio device that\n+         stores writes in a buffer and returns the buffered data on a read.\n+         \n+         This is useful for testing the kvm mmio emulation code. Enabling\n+         this does not run any tests, just builds in the support for the test\n+         device into the kernel.\n+\n+         If unsure, say N.\ndiff --git a/virt/kvm/Makefile.kvm b/virt/kvm/Makefile.kvm\nindex d047d4cf58c9..bd4da8c23923 100644\n--- a/virt/kvm/Makefile.kvm\n+++ b/virt/kvm/Makefile.kvm\n@@ -8,6 +8,7 @@ KVM ?= ../../../virt/kvm\n kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o\n kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o\n kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o\n+kvm-$(CONFIG_KVM_MMIO_TEST) += $(KVM)/mmio_test.o\n kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o\n kvm-$(CONFIG_HAVE_KVM_IRQ_ROUTING) += $(KVM)/irqchip.o\n kvm-$(CONFIG_HAVE_KVM_DIRTY_RING) += $(KVM)/dirty_ring.o\ndiff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c\nindex 5fcd401a5897..a0b143e71560 100644\n--- a/virt/kvm/kvm_main.c\n+++ b/virt/kvm/kvm_main.c\n@@ -59,6 +59,7 @@\n #include \"async_pf.h\"\n #include \"kvm_mm.h\"\n #include \"vfio.h\"\n+#include \"mmio_test.h\"\n \n #include <trace/events/ipi.h>\n \n@@ -6528,6 +6529,10 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)\n \tif (WARN_ON_ONCE(r))\n \t\tgoto err_vfio;\n \n+\tr = kvm_mmio_test_ops_init();\n+\tif (WARN_ON_ONCE(r))\n+\t\tgoto err_mmio_test;\n+\n \tr = kvm_gmem_init(module);\n \tif (r)\n \t\tgoto err_gmem;\n@@ -6555,6 +6560,8 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)\n err_gmem:\n \tkvm_vfio_ops_exit();\n err_vfio:\n+\tkvm_mmio_test_ops_exit();\n+err_mmio_test:\n \tkvm_async_pf_deinit();\n err_async_pf:\n \tkvm_irqfd_exit();\n@@ -6585,6 +6592,7 @@ void kvm_exit(void)\n \t\tfree_cpumask_var(per_cpu(cpu_kick_mask, cpu));\n \tkmem_cache_destroy(kvm_vcpu_cache);\n \tkvm_gmem_exit();\n+\tkvm_mmio_test_ops_exit();\n \tkvm_vfio_ops_exit();\n \tkvm_async_pf_deinit();\n \tkvm_irqfd_exit();\ndiff --git a/virt/kvm/mmio_test.c b/virt/kvm/mmio_test.c\nnew file mode 100644\nindex 000000000000..fa84c2b4c5fc\n--- /dev/null\n+++ b/virt/kvm/mmio_test.c\n@@ -0,0 +1,95 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+/*\n+ * mmio_test.c - Kernel module side for testing the KVM riscv mmio functionality.\n+ */\n+\n+#include <linux/kvm_host.h>\n+\n+#include <kvm/iodev.h>\n+#include \"mmio_test.h\"\n+\n+struct mmio_test {\n+\tstruct kvm *kvm;\n+\tstruct kvm_io_device dev;\n+\tunsigned long start;\n+\tunsigned long size;\n+\tchar cache[16];\n+};\n+\n+static struct mmio_test *kvm_to_mmio_test_dev(const struct kvm_io_device *dev)\n+{\n+\treturn container_of(dev, struct mmio_test, dev);\n+}\n+\n+static int mmio_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,\n+\t\t     gpa_t addr, int len, void *val)\n+{\n+\tstruct mmio_test *mmio_test = kvm_to_mmio_test_dev(dev);\n+\n+\tif ((addr - mmio_test->start) >= mmio_test->size)\n+\t\treturn -1;\n+\n+\t/* Write back cached value */\n+\tmemcpy(val, &mmio_test->cache[(addr - mmio_test->start)], len);\n+\treturn 0;\n+}\n+\n+static int mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,\n+\t\t      gpa_t addr, int len, const void *val)\n+{\n+\tstruct mmio_test *mmio_test = kvm_to_mmio_test_dev(dev);\n+\n+\tif ((addr - mmio_test->start) >= mmio_test->size)\n+\t\treturn -1;\n+\n+\t/* Cache value */\n+\tmemcpy(&mmio_test->cache[(addr - mmio_test->start)], val, len);\n+\treturn 0;\n+}\n+\n+static const struct kvm_io_device_ops mmio_ops = {\n+\t.read = mmio_read,\n+\t.write = mmio_write,\n+};\n+\n+static int mmio_test_create(struct kvm_device *dev, u32 type)\n+{\n+\tstruct mmio_test *mmio_test;\n+\n+\tmmio_test = kzalloc(sizeof(*mmio_test), GFP_KERNEL);\n+\tif (!mmio_test)\n+\t\treturn -ENOMEM;\n+\n+\tmmio_test->start = 0x20000000;\n+\tmmio_test->size = 0x16;\n+\n+\tdev->private = mmio_test;\n+\n+\tkvm_iodevice_init(&mmio_test->dev, &mmio_ops);\n+\tkvm_io_bus_register_dev(dev->kvm, KVM_MMIO_BUS, mmio_test->start,\n+\t\t\t\tmmio_test->size, &mmio_test->dev);\n+\n+\treturn 0;\n+}\n+\n+static void mmio_test_release(struct kvm_device *dev)\n+{\n+\tkfree(dev->private);\n+}\n+\n+struct kvm_device_ops kvm_riscv_mmio_test_device_ops = {\n+\t.name = \"kvm-riscv-mmio_test\",\n+\t.create = mmio_test_create,\n+\t.release = mmio_test_release,\n+};\n+\n+int kvm_mmio_test_ops_init(void)\n+{\n+\treturn kvm_register_device_ops(&kvm_riscv_mmio_test_device_ops,\n+\t\t\t\t\tKVM_DEV_TYPE_TEST);\n+}\n+\n+void kvm_mmio_test_ops_exit(void)\n+{\n+\tkvm_unregister_device_ops(KVM_DEV_TYPE_TEST);\n+}\ndiff --git a/virt/kvm/mmio_test.h b/virt/kvm/mmio_test.h\nnew file mode 100644\nindex 000000000000..49a6e900eec9\n--- /dev/null\n+++ b/virt/kvm/mmio_test.h\n@@ -0,0 +1,18 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+#ifndef __KVM_MMIO_TEST_H\n+#define __KVM_MMIO_TEST_H\n+\n+#ifdef CONFIG_KVM_MMIO_TEST\n+int kvm_mmio_test_ops_init(void);\n+void kvm_mmio_test_ops_exit(void);\n+#else\n+static inline int kvm_mmio_test_ops_init(void)\n+{\n+\treturn 0;\n+}\n+static inline void kvm_mmio_test_ops_exit(void)\n+{\n+}\n+#endif\n+\n+#endif\n","prefixes":["09/16"]}