{"id":2220779,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2220779/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-riscv/patch/20260407-riscv_insn_table-v1-8-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-8-54b4736a1e77@gmail.com>","date":"2026-04-08T04:45:56","name":"[08/16] riscv: kvm: Fix MMIO emulation for sign-extended insns","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6fcf4c9ad55ed635dec98892e57e3fc0622ff69a","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-8-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/2220779/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2220779/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=J7zr2r6P;\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=io0i1S8z;\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 4fr9Wr0sgNz20x0\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-00000008Eki-1dSH;\n\tWed, 08 Apr 2026 04:46:45 +0000","from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wAKoJ-00000008EbZ-2Tym;\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 2BC2B4448E;\n\tWed,  8 Apr 2026 04:46:37 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPS id 04222C2BC9E;\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 F143FFD5F73;\n\tWed,  8 Apr 2026 04:46:36 +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=rD0e8KyWsVyi+9xdQJFdVch2Samjxup2IMIYLtB/buE=; b=J7zr2r6P2k4H7N\n\t/cGkzMxC60mq59vBzsiYE80w0e+jD/MNVEZD70QQAMksTnC7IoXXftLtJkoumgIPn9ptoXN86t3gM\n\tbX9/ao5FhgjtauDlT656xIQI+lqpC5D7fymDlkwL1JOQjjCXnpU5c4GRsJ1Z/1SnQo/eaJKFIGaex\n\tLJSLSlNtBJ0DsfSSMpi2Q2wq4AG8tP7E3+QeZJ48IOqGBUEBiFHDdElwfSeGLFkJD3JyeTe8om6ZG\n\t37QWobiv4iunDufb6TMNFUY1ZCUEsA5Ib9AyBPTKW6o6h/2l5OjYqXhiHcoH9tL7l5JxiFUUd2sHq\n\tHG5GLMLvScJbQERZL0IQ==;","v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1775623597;\n\tbh=w9IsCz5C65o7SYnzaV255DXsVBXf9lMSVjahsf+0d3w=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From;\n\tb=io0i1S8zyNDeTdGN4yJaLqlYa3RQFwnmCi4dvTfsmB2ngjDUDhE/WQLWOWF+CeeJ9\n\t BAT8GTZW0ZcY3sps7tDwnjuoyZkimy2L7GSB2nrFrgBMUZAe5XHDUwBCwAOYRM0PAn\n\t +RrdMZ+Jy5VUxB0KUVMQDgjmiAxUOu4A7HUO40NJNu/BJUFxQb0+cdxCxyCK4fExlG\n\t T7rtuG0Y1EMKogDfx61PbO98rUM5xMdz4qZkXE4Nh/NVmic717s84V3Vc2PQQjj57X\n\t TxsbbHANRbqjMEk96gWw98BjyjLIr/0ATUvCFdK+V56MGGC9q/w7aYhDTaAaHrrhHw\n\t Zqlez72oIvsyw=="],"From":"Charlie Jenkins via B4 Relay\n <devnull+thecharlesjenkins.gmail.com@kernel.org>","Date":"Tue, 07 Apr 2026 21:45:56 -0700","Subject":"[PATCH 08/16] riscv: kvm: Fix MMIO emulation for sign-extended\n insns","MIME-Version":"1.0","Message-Id":"<20260407-riscv_insn_table-v1-8-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=1861;\n i=thecharlesjenkins@gmail.com; s=2026030; h=from:subject:message-id;\n bh=lGPhHeZyq2cBn6D6Rrw+L7g4NlITgLWo0A/2zvmf7AE=;\n b=db8eDgJl+Lxj01XnGSTnQdW6SSxHQwG8ehZ9ti7lZbKgg//zvLEF/VtHi7aOf3Qg/NPY9t3iw\n b6GSI/ckqNOCYdESWlISYlmDPk5zSHfsQP5PliI0bV5S5BiyNWqbc/M","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_703448_41881F5A ","X-CRM114-Status":"GOOD (  10.37  )","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 KVM MMIO emulation failed to sign\n extend\n    any signed reads and at the same time also unsuccessfully attempted to\n sign\n    extend reads using lbu. Remove the shifting for lbu to avoid sign\n extension\n    for tha [...]\n Content analysis details:   (-0.0 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\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\nKVM MMIO emulation failed to sign extend any signed reads and at the\nsame time also unsuccessfully attempted to sign extend reads using lbu.\nRemove the shifting for lbu to avoid sign extension for that\ninstruction and cast the data to a signed long instead of an unsigned\nlong to allow for sign extension.\n\nSigned-off-by: Charlie Jenkins <thecharlesjenkins@gmail.com>\n---\n arch/riscv/kvm/vcpu_insn.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)","diff":"diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c\nindex 62c4510a40af..311e2530f888 100644\n--- a/arch/riscv/kvm/vcpu_insn.c\n+++ b/arch/riscv/kvm/vcpu_insn.c\n@@ -416,7 +416,6 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,\n \t\tshift = 8 * (sizeof(ulong) - len);\n \t} else if ((insn & INSN_MASK_LBU) == INSN_MATCH_LBU) {\n \t\tlen = 1;\n-\t\tshift = 8 * (sizeof(ulong) - len);\n #ifdef CONFIG_64BIT\n \t} else if ((insn & INSN_MASK_LD) == INSN_MATCH_LD) {\n \t\tlen = 8;\n@@ -650,22 +649,22 @@ int kvm_riscv_vcpu_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)\n \tcase 1:\n \t\tdata8 = *((u8 *)run->mmio.data);\n \t\tSET_RD(insn, &vcpu->arch.guest_context,\n-\t\t\t(ulong)data8 << shift >> shift);\n+\t\t\t(long)data8 << shift >> shift);\n \t\tbreak;\n \tcase 2:\n \t\tdata16 = *((u16 *)run->mmio.data);\n \t\tSET_RD(insn, &vcpu->arch.guest_context,\n-\t\t\t(ulong)data16 << shift >> shift);\n+\t\t\t(long)data16 << shift >> shift);\n \t\tbreak;\n \tcase 4:\n \t\tdata32 = *((u32 *)run->mmio.data);\n \t\tSET_RD(insn, &vcpu->arch.guest_context,\n-\t\t\t(ulong)data32 << shift >> shift);\n+\t\t\t(long)data32 << shift >> shift);\n \t\tbreak;\n \tcase 8:\n \t\tdata64 = *((u64 *)run->mmio.data);\n \t\tSET_RD(insn, &vcpu->arch.guest_context,\n-\t\t\t(ulong)data64 << shift >> shift);\n+\t\t\t(long)data64 << shift >> shift);\n \t\tbreak;\n \tdefault:\n \t\treturn -EOPNOTSUPP;\n","prefixes":["08/16"]}