Skip to content

[PW_SID:1094650] RISC-V: KVM: Fix sign extension for MMIO loads#1931

Open
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__fixesfrom
pw1094650
Open

[PW_SID:1094650] RISC-V: KVM: Fix sign extension for MMIO loads#1931
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__fixesfrom
pw1094650

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 1094650 applied to workflow__riscv__fixes

Name: RISC-V: KVM: Fix sign extension for MMIO loads
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1094650
Version: 1

The kvm_riscv_vcpu_mmio_return() function handles MMIO read results
by writing the data back to the guest register. For signed load
instructions (LB, LH, LW on RV64), the value needs sign-extension
from a smaller integer to unsigned long.

The current code uses:
    (ulong)data << shift >> shift
but (ulong) makes the right shift a logical shift (zero-extend)
rather than an arithmetic shift (sign-extend), causing incorrect
results when the MMIO device returns a negative value. For example,
LB reading 0x80 would return 128 instead of -128.

Fix this by casting to (long) after the left shift so that the
subsequent right shift is arithmetic and correctly propagates
the sign bit:
    (long)((ulong)data << shift) >> shift

Additionally, remove the unnecessary shift assignment for LBU
(unsigned byte load) since it does not need sign extension.
This makes LBU consistent with LHU and LWU which already keep
shift = 0.

Fixes: b91f0e4 ("RISC-V: KVM: Factor-out instruction emulation into separate sources")
Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com>
Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn>
Assisted-by: OpenClaw:DeepSeek-V3.2
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 114.21 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1029.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1389.47 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 19.15 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 20.67 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.62 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 75.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
kdoc
Desc: Detects for kdoc errors
Duration: 0.72 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "RISC-V: KVM: Fix sign extension for MMIO loads"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.27 seconds
Result: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants