Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Bingyu.Xian <shanbeeyoo@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] RISC-V: KVM: Fix spurious -EEXIST and clean up gstage fault path types
Date: Wed, 29 Jul 2026 07:17:21 +0000	[thread overview]
Message-ID: <20260729071722.6DE841F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729070749.730218-1-shanbeeyoo@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch fails to resolve the 34-bit GPA truncation on RV32 because the address calculation `(trap->htval << 2)` is still evaluated using 32-bit arithmetic before assignment.
--

--- Patch [1]: [PATCH] RISC-V: KVM: Fix spurious -EEXIST and clean up gstage fault path types ---
commit 9da8ae12634bbc92cd912d48c6458250997cb454
Author: Bingyu.Xian <shanbeeyoo@gmail.com>

RISC-V: KVM: Fix spurious -EEXIST and clean up gstage fault path types

This commit updates the G-stage page fault path to treat -EEXIST from
kvm_riscv_gstage_map_page() as a success, aligning RISC-V with other
architectures. It also updates the type of vma_pageshift to unsigned int
and fault_addr to gpa_t, intending to prevent 34-bit guest physical address
truncation on RV32.

[ ... ]

> diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
> index 6c8530b9f29ed..76cceecee5aba 100644
> --- a/arch/riscv/kvm/vcpu_exit.c
> +++ b/arch/riscv/kvm/vcpu_exit.c
> @@ -17,7 +17,8 @@ static int gstage_page_fault(struct kvm_vcpu *vcpu, struct kvm_run *run,
>  {
>  	struct kvm_gstage_mapping host_map;
>  	struct kvm_memory_slot *memslot;
> -	unsigned long hva, fault_addr;
> +	unsigned long hva;
> +	gpa_t fault_addr;

[Severity: High]
This is a pre-existing issue, but does the calculation for fault_addr still
truncate the address on RV32 before this assignment?

The commit message notes this type change is meant to prevent 34-bit guest
physical addresses from being truncated. However, looking further down in
gstage_page_fault(), the actual calculation is:

    fault_addr = (trap->htval << 2) | (trap->stval & 0x3);

Because trap->htval is an unsigned long, the shift (trap->htval << 2) is
evaluated as a 32-bit operation on RV32. This discards the upper bits of
the 34-bit guest physical address before the final result is widened and
stored in the new 64-bit gpa_t variable.

Should trap->htval be explicitly cast to gpa_t or u64 before the shift
operation to ensure the higher bits are preserved?

>  	bool writable;
>  	gfn_t gfn;
>  	int ret;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729070749.730218-1-shanbeeyoo@gmail.com?part=1

  reply	other threads:[~2026-07-29  7:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  7:07 [PATCH] RISC-V: KVM: Fix spurious -EEXIST and clean up gstage fault path types Bingyu.Xian
2026-07-29  7:17 ` sashiko-bot [this message]
2026-07-29  7:52 ` [PATCH v2] " Bingyu.Xian
2026-07-29  8:03   ` sashiko-bot
2026-07-29 12:07   ` [PATCH v3 0/3] RISC-V: KVM: G-stage fault path fix and cleanup Bingyu.Xian
2026-07-29 12:07     ` [PATCH v3 1/3] RISC-V: KVM: Treat -EEXIST from G-stage map as success Bingyu.Xian
2026-07-29 16:06       ` Anup Patel
2026-07-29 12:07     ` [PATCH v3 2/3] RISC-V: KVM: Use unsigned int for vma_pageshift Bingyu.Xian
2026-07-29 16:09       ` Anup Patel
2026-07-29 12:07     ` [PATCH v3 3/3] RISC-V: KVM: Widen G-stage fault address to gpa_t Bingyu.Xian
2026-07-29 16:21       ` Anup Patel
2026-07-29  8:05 ` [PATCH] RISC-V: KVM: Fix spurious -EEXIST and clean up gstage fault path types Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260729071722.6DE841F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shanbeeyoo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox