Re: [PATCH v2 0/2] KVM: riscv: Unify and optimize FP register loops
From: Anup Patel
Date: Sun Nov 29 2026 - 00:22:11 EST
On Thu, Oct 29, 2026 at 4:13 AM Paul White <paul.white.kernel@xxxxxxxxx> wrote:
>
> The change to both patches in this series is a
> structural/architectural one. Both functions set_reg and get_reg use
> identical code to locate the register the application specified in the
> token even though they do different things with that location
> information: the set_reg function adds data the application requested
> to send to that identified location (in the copy_from_user function)
> while the get_reg function retrieves what data is at that identified
> location and sends it to the application (using the copy_to_user
> function). Everything else is the same. That is the only difference
> between the code.
>
> Therefore I was able to apply the same solution to both of the
> function's finding-the-requested-register parts (which is everything
> up until the final if statement) which were filled with redundancy.
> The solution I came up with is to create local variables for the
> entire function for all the variables of the original code that would
> be different, depending on the floating point type. Then once I ask
> whether it is a double floating point or single floating point mode, I
> assign the aforementioned variables to the values they should have for
> that mode so that when I go through the if statements that ask whether
> the requested register number is a status control register or data
> register, I only have to go through it once because the respective
> floating point values/addresses would have been assigned to the
> aforementioned local variables, so the whole code kind of changes or
> is tailored to the floating point type.
>
> This architectural change/solution will make the cpu execute the code
> faster (as the cpu will have less decisions to make and the bare-metal
> math used to figure out the address of the register is executed faster
> by the cpu than looking up object properties and array indexes), is
> more maintainable, and is more readable.
>
> ---
> v2:
> - Both patches had the same flawed line of code. The checking if the
> token's size was 32 or 64 bits line allowed token's with mismatched
> sizes & types to pass. I fixed this by checking it had the right
> size for its type by replacing the u32/u64 parts with a
> mode-dependent local variable, byte_offset.
>
> Paul White (2):
> KVM: riscv: Eliminate redundancy in get_reg function via pointers
> KVM: riscv: Eliminate redundancy in set_reg function via pointers
No need to have separate patch for get_reg and set_reg function
because the overall idea and approach is same which is also reflected
in the commit description.
Create a single patch with the following subject:
"KVM: riscv: Eliminate redundancy in get/set_reg_fp functions"
Please also address issue pointed by sashiko-bot in PATCH2
Regards,
Anup