Re: [PATCH 5/6] x86/paravirt: Switch MSR access pv_ops functions to instruction interfaces

2025-06-13 Thread Xin Li
On 6/11/2025 5:58 AM, Juergen Gross wrote: Here is a patch I cooked.  I added an ALTERNATIVE() hack because the new instructions can't be more than 6 bytes long.  But with the patch you just sent, it shouldn't be needed. I have meanwhile dropped the patch copying the original indirect call. R

Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-05-19 Thread Xin Li
On 5/12/2025 1:45 AM, Xin Li (Intel) wrote: Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type conversions when a u64 MSR value is splitted into two u32. Signed-off-by: Xin Li (Intel) --- arch/x86/coco/sev/core.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions

[PATCH v1A 2/3] x86/xen/msr: Fix uninitialized symbol 'err'

2025-05-17 Thread Xin Li (Intel)
ned-off-by: Xin Li (Intel) --- Change in v1A: *) Drop setting err to 0 in xen_do_read_msr() initially and set err to 0 in all callers (Jürgen Groß). --- arch/x86/xen/enlighten_pv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/enlighten_pv.c b/ar

Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-05-17 Thread Xin Li
On 5/17/2025 6:21 AM, Ingo Molnar wrote: Ah, indeed, it's also a startup code wrapper, which wrmsrq() doesn't have at the moment. Fair enough. So you want me to drop this patch then? No, patch #3 is fine as-is in its -v1 form Thanks for confirming. I'll just update patch #2 as version v1A th

Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'

2025-05-17 Thread Xin Li
On 5/16/2025 6:42 AM, Jürgen Groß wrote: On 15.05.25 20:11, Xin Li wrote: On 5/15/2025 8:29 AM, Ingo Molnar wrote: * Xin Li (Intel) wrote: xen_read_msr_safe() currently passes an uninitialized argument err to xen_do_read_msr().  But as xen_do_read_msr() may not set the argument

Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-05-17 Thread Xin Li
>>> On 5/15/2025 10:54 AM, Xin Li wrote: >>> On 5/15/2025 8:27 AM, Ingo Molnar wrote: >>>> >>>> * Xin Li (Intel) wrote: >>>> >>>>> Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type >>>>&

Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-05-16 Thread Xin Li
On 5/15/2025 10:54 AM, Xin Li wrote: On 5/15/2025 8:27 AM, Ingo Molnar wrote: * Xin Li (Intel) wrote: Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type conversions when a u64 MSR value is splitted into two u32. BTW., at this point we should probably just replace

Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'

2025-05-15 Thread Xin Li
On 5/15/2025 8:29 AM, Ingo Molnar wrote: * Xin Li (Intel) wrote: xen_read_msr_safe() currently passes an uninitialized argument err to xen_do_read_msr(). But as xen_do_read_msr() may not set the argument, xen_read_msr_safe() could return err with an unpredictable value. To ensure

Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-05-15 Thread Xin Li
On 5/15/2025 8:27 AM, Ingo Molnar wrote: * Xin Li (Intel) wrote: Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type conversions when a u64 MSR value is splitted into two u32. BTW., at this point we should probably just replace sev_es_wr_ghcb_msr() calls with direct

Re: [PATCH 5/6] x86/paravirt: Switch MSR access pv_ops functions to instruction interfaces

2025-05-15 Thread Xin Li
On 5/13/2025 3:24 PM, H. Peter Anvin wrote: On May 12, 2025 11:06:02 PM PDT, "Jürgen Groß" wrote: On 13.05.25 07:55, Xin Li wrote: On 5/12/2025 4:24 AM, Juergen Gross wrote: Now with the mentioned patch really attached. :-) Does it allow patching with an instruction more than 6

Re: [PATCH 5/6] x86/paravirt: Switch MSR access pv_ops functions to instruction interfaces

2025-05-13 Thread Xin Li
On 5/12/2025 4:20 AM, Jürgen Groß wrote: On 09.05.25 10:18, Xin Li wrote: On 5/6/2025 2:20 AM, Juergen Gross wrote: I'm trying to evaluate how to add the immediate form MSR instructions on top of this patch set.  And I'm close to get it done. There is something to consider when ru

Re: [PATCH 5/6] x86/paravirt: Switch MSR access pv_ops functions to instruction interfaces

2025-05-12 Thread Xin Li
On 5/12/2025 11:06 PM, Jürgen Groß wrote: On 13.05.25 07:55, Xin Li wrote: On 5/12/2025 4:24 AM, Juergen Gross wrote: Now with the mentioned patch really attached. :-) Does it allow patching with an instruction more than 6 bytes long? The immediate form MSR instructions are 9 bytes long

Re: [PATCH 5/6] x86/paravirt: Switch MSR access pv_ops functions to instruction interfaces

2025-05-12 Thread Xin Li
On 5/12/2025 4:24 AM, Juergen Gross wrote: Now with the mentioned patch really attached. :-) Does it allow patching with an instruction more than 6 bytes long? The immediate form MSR instructions are 9 bytes long. Thanks! Xin

[PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'

2025-05-12 Thread Xin Li (Intel)
ed-by: Dan Carpenter Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/ Signed-off-by: Xin Li (Intel) --- arch/x86/xen/enlighten_pv.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_

[PATCH v1 1/3] x86/msr: Remove a superfluous inclusion of

2025-05-12 Thread Xin Li (Intel)
The following commit: efef7f184f2e ("x86/msr: Add explicit includes of ") added a superfluous inclusion of to drivers/acpi/processor_throttling.c. Remove it. Signed-off-by: Xin Li (Intel) --- drivers/acpi/processor_throttling.c | 1 - 1 file changed, 1 deletion(-) diff --git

[PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-05-12 Thread Xin Li (Intel)
Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type conversions when a u64 MSR value is splitted into two u32. Signed-off-by: Xin Li (Intel) --- arch/x86/coco/sev/core.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/x86/coco/sev/core.c b/arch

[PATCH v1 0/3] MSR fixes and cleanups after last round of MSR cleanups

2025-05-12 Thread Xin Li (Intel)
ange the function type of native_read_msr_safe()"). 3) Convert a native_wrmsr() use to native_wrmsrq() in arch/x86/coco/sev/core.c. Xin Li (Intel) (3): x86/msr: Remove a superfluous inclusion of x86/xen/msr: Fix uninitialized symbol 'err' x86/msr: Convert a native_wrmsr() us

Re: [PATCH 5/6] x86/paravirt: Switch MSR access pv_ops functions to instruction interfaces

2025-05-09 Thread Xin Li
On 5/6/2025 2:20 AM, Juergen Gross wrote: Instead of having callback functions for rdmsr/wrmsr on native, switch to inline the respective instructions directly in order to avoid overhead with the call interface. To me, this is a beneficial addition to the existing pvops MSR code. This requir

Re: [PATCH v4 02/15] x86/msr: Move rdtsc{,_ordered}() to

2025-05-02 Thread Xin Li
On 5/2/2025 1:02 AM, Ingo Molnar wrote: * Xin Li (Intel) wrote: index 94408a784c8e..13335a130edf 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -7,7 +7,81 @@ #include #include -#include + +/* + * both i386 and x86_64 returns 64-bit value in edx:eax

Re: [PATCH v4 02/15] x86/msr: Move rdtsc{,_ordered}() to

2025-05-02 Thread Xin Li
On 5/2/2025 1:18 AM, Ingo Molnar wrote: * Xin Li (Intel) wrote: For some reason, there are some TSC-related functions in the MSR ^^^ header even though there is a tsc.h header. The real reason is that the rdtsc{,_ordered}() methods use the EAX_EDX_*() macros to optimize

Re: [PATCH v4 02/15] x86/msr: Move rdtsc{,_ordered}() to

2025-05-02 Thread Xin Li
On 5/2/2025 1:52 AM, Ingo Molnar wrote: * Xin Li (Intel) wrote: For some reason, there are some TSC-related functions in the MSR header even though there is a tsc.h header. Relocate rdtsc{,_ordered}() from to , and subsequently remove the inclusion of in . Signed-off-by: Xin Li (Intel

Re: [PATCH v4A 01/15] x86/msr: Add missing includes of

2025-05-02 Thread Xin Li
On 5/2/2025 6:13 AM, Ilpo Järvinen wrote: diff --git a/arch/x86/kernel/trace_clock.c b/arch/x86/kernel/trace_clock.c index b8e7abe00b06..708d61743d15 100644 --- a/arch/x86/kernel/trace_clock.c +++ b/arch/x86/kernel/trace_clock.c @@ -4,7 +4,7 @@ */ #include #include -#include +#include

[PATCH v4A 01/15] x86/msr: Add missing includes of

2025-04-30 Thread Xin Li (Intel)
: Xin Li (Intel) Acked-by: Dave Hansen Acked-by: Peter Zijlstra (Intel) Acked-by: Ilpo Järvinen --- Change in v4A: *) Use "git grep -l -e $PATTERN | grep -v -f <(git grep -l -e 'asm/msr\.h')" to ensure ALL required *direct* inclusion of (Ilpo Järvinen). Change in v4:

Re: [PATCH v4 01/15] x86/msr: Add missing includes of

2025-04-30 Thread Xin Li
On 4/30/2025 2:17 AM, Ilpo Järvinen wrote: While this is not my subsystem so don't have the final say here, you had to explain quite much to prove that (and reviewer would have to go through the same places to check). Wouldn't it be much simpler for all if all those .c files would just include d

Re: [PATCH v4 01/15] x86/msr: Add missing includes of

2025-04-30 Thread Xin Li
On 4/29/2025 9:20 PM, Michael Kelley wrote: Also under hyperv/ not all files are covered but I'm a bit hesitant to suggest a change there since I'm not sure if they (hypervisors) do something special w.r.t. msr. I've worked on the Hyper-V code in Linux for 8 years or so, first as a Microsoft emp

Re: [PATCH v4 01/15] x86/msr: Add missing includes of

2025-04-30 Thread Xin Li
On 4/29/2025 2:45 AM, Ilpo Järvinen wrote: arch/x86/events/msr.c | 3 +++ arch/x86/events/perf_event.h | 1 + arch/x86/events/probe.c | 2 ++ Under arch/x86/events/ a few files seem

Re: [PATCH v4 01/15] x86/msr: Add missing includes of

2025-04-29 Thread Xin Li
On 4/29/2025 2:45 AM, Ilpo Järvinen wrote: On Sun, 27 Apr 2025, Xin Li (Intel) wrote: For some reason, there are some TSC-related functions in the MSR header even though there is a tsc.h header. To facilitate the relocation of rdtsc{,_ordered}() from to and to eventually eliminate the

[PATCH v4 01/15] x86/msr: Add missing includes of

2025-04-27 Thread Xin Li (Intel)
: Xin Li (Intel) Acked-by: Dave Hansen Acked-by: Peter Zijlstra (Intel) --- Change in v4: *) Add missing includes in a different patch (Ilpo Järvinen). *) Add all necessary direct inclusions for msr.h (Ilpo Järvinen). Change in v3: * Add a problem statement to the changelog (Dave Hansen

[PATCH v4 02/15] x86/msr: Move rdtsc{,_ordered}() to

2025-04-27 Thread Xin Li (Intel)
For some reason, there are some TSC-related functions in the MSR header even though there is a tsc.h header. Relocate rdtsc{,_ordered}() from to , and subsequently remove the inclusion of in . Signed-off-by: Xin Li (Intel) Acked-by: Dave Hansen Acked-by: Peter Zijlstra (Intel) --- Change

[PATCH v4 08/15] x86/msr: Add the native_rdmsrq() helper

2025-04-27 Thread Xin Li (Intel)
() is directly used when it needs to return an MSR value in a u64 integer. Add the native_rdmsrq() helper, which is simply an alias of __rdmsr(), to make native_rdmsr() and native_rdmsrq() a pair of MSR read APIs. Signed-off-by: Xin Li (Intel) Acked-by: Peter Zijlstra (Intel) --- Change in v2

Re: [PATCH v3 09/14] x86/xen/msr: Remove calling native_{read,write}_msr{,_safe}() in pmu_msr_{read,write}()

2025-04-27 Thread Xin Li
On 4/27/2025 2:21 AM, Mi, Dapeng wrote: Reviewed-by: Dapeng Mi Thanks! I just sent out v4, so unless a v5 is needed, leave it to our x86 maintainers.

[PATCH v4 11/15] x86/xen/msr: Remove pmu_msr_{read,write}()

2025-04-27 Thread Xin Li (Intel)
hile at it, convert the data type of MSR index to u32 in functions called in pmu_msr_chk_emulated(). Suggested-by: H. Peter Anvin (Intel) Suggested-by: Juergen Gross Signed-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross Acked-by: Peter Zijlstra (Intel) --- Change in v4: *) Remove two &quo

[PATCH v4 03/15] x86/msr: Remove rdpmc()

2025-04-27 Thread Xin Li (Intel)
rdpmc() is not used anywhere, remove it. Signed-off-by: Xin Li (Intel) Acked-by: Dave Hansen Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/msr.h | 7 --- arch/x86/include/asm/paravirt.h | 7 --- 2 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/msr.h

[PATCH v4 04/15] x86/msr: Rename rdpmcl() to rdpmc()

2025-04-27 Thread Xin Li (Intel)
Now that rdpmc() is gone, i.e. rdpmcl() is the sole PMC read helper, simply rename rdpmcl() to rdpmc(). Signed-off-by: Xin Li (Intel) Acked-by: Dave Hansen Acked-by: Peter Zijlstra (Intel) --- Changes in v3: *) Explain the reason of the renaming in the changelog (Dave Hansen). *) Use shorter

[PATCH v4 09/15] x86/msr: Convert __rdmsr() uses to native_rdmsrq() uses

2025-04-27 Thread Xin Li (Intel)
ve the way for improving MSR API names, convert __rdmsr() uses to native_rdmsrq() to ensure consistent usage. Later, these APIs can be renamed to better reflect their implications, such as native or pvops, with or without trace, and safe or non-safe. No functional change intended. Signed-off-by:

[PATCH v4 00/15] MSR code cleanup part one

2025-04-27 Thread Xin Li (Intel)
1-...@zytor.com/ This patch series is based on: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/msr Xin Li (Intel) (15): x86/msr: Add missing includes of x86/msr: Move rdtsc{,_ordered}() to x86/msr: Remove rdpmc() x86/msr: Rename rdpmcl() to rdpmc() x86/msr: Convert the rdp

[PATCH v4 06/15] x86/xen/msr: Return u64 consistently in Xen PMC read functions

2025-04-27 Thread Xin Li (Intel)
The pv_ops PMC read API is defined as: u64 (*read_pmc)(int counter); But Xen PMC read functions return unsigned long long, make them return u64 consistently. Signed-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross Acked-by: Peter Zijlstra (Intel) --- arch/x86/xen/pmu.c | 6

[PATCH v4 12/15] x86/xen/msr: Remove the error pointer argument from set_seg()

2025-04-27 Thread Xin Li (Intel)
safe APIs. Remove the error pointer argument. Signed-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross Acked-by: Peter Zijlstra (Intel) --- Change in v3: *) Fix a typo: set_reg() => set_seg() (Juergen Gross). --- arch/x86/xen/enlighten_pv.c | 16 +--- 1 file changed, 5 inserti

[PATCH v4 13/15] x86/pvops/msr: refactor pv_cpu_ops.write_msr{,_safe}()

2025-04-27 Thread Xin Li (Intel)
, refactor pv_cpu_ops.write_msr{_safe}() to accept an MSR value in a single u64 argument, replacing the current dual u32 arguments. No functional change intended. Signed-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross Acked-by: Peter Zijlstra (Intel) --- Change in v2: * Spell out the reason why use a

[PATCH v4 15/15] x86/msr: Change the function type of native_read_msr_safe()

2025-04-27 Thread Xin Li (Intel)
way. While at it, convert leftover MSR data type "unsigned int" to u32. Signed-off-by: Xin Li (Intel) Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/msr.h| 21 +++-- arch/x86/include/asm/paravirt.h | 19 --- arch/x86/i

[PATCH v4 10/15] x86/xen/msr: Remove calling native_{read,write}_msr{,_safe}() in pmu_msr_{read,write}()

2025-04-27 Thread Xin Li (Intel)
native_write_msr{,_safe}(), which has now been removed. [1]: https://lore.kernel.org/lkml/0ec48b84-d158-47c6-b14c-3563fd14b...@zytor.com/ Suggested-by: H. Peter Anvin (Intel) Sign-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross Acked-by: Peter Zijlstra (Intel) --- Change in v3: *) Rename pmu_msr_{read

[PATCH v4 07/15] x86/msr: Convert __wrmsr() uses to native_wrmsr{,q}() uses

2025-04-27 Thread Xin Li (Intel)
enamed to better reflect their implications, such as native or pvops, with or without trace, and safe or non-safe. No functional change intended. Signed-off-by: Xin Li (Intel) Acked-by: Peter Zijlstra (Intel) --- Change in v2: * Use native_wrmsr() where natural [rmid_p, closid_p] high/lo para

[PATCH v4 14/15] x86/msr: Replace wrmsr(msr, low, 0) with wrmsrq(msr, low)

2025-04-27 Thread Xin Li (Intel)
The third argument in wrmsr(msr, low, 0) is unnecessary. Instead, use wrmsrq(msr, low), which automatically sets the higher 32 bits of the MSR value to 0. Signed-off-by: Xin Li (Intel) Acked-by: Peter Zijlstra (Intel) --- arch/x86/hyperv/hv_apic.c | 6 +++--- arch/x86/include

[PATCH v4 05/15] x86/msr: Convert the rdpmc() macro into an always inline function

2025-04-27 Thread Xin Li (Intel)
the returned value, further enhancing readability. Signed-off-by: Xin Li (Intel) Acked-by: Dave Hansen Acked-by: Peter Zijlstra (Intel) --- Change in v3: *) Add a changelog even it's obvious (Dave Hansen). --- arch/x86/events/amd/uncore.c | 2 +- arch/x86/events/c

Re: [PATCH v3 10/14] x86/xen/msr: Remove pmu_msr_{read,write}()

2025-04-26 Thread Xin Li
On 4/25/2025 3:08 AM, Jürgen Groß wrote: Can you please remove the two "else" instances above? With directly returning form the "if" clause they are no longer needed. I thought about it but forgot to do it later. With that you can add my: Reviewed-by: Juergen Gross Thanks a lot!

Re: [PATCH v3 01/14] x86/msr: Move rdtsc{,_ordered}() to

2025-04-26 Thread Xin Li
On 4/25/2025 8:45 AM, Ilpo Järvinen wrote: To me this looks really a random set of source files, maybe it helped some build success but it's hard for me to review this because there are still cases that depend on indirect include chains. Could you just look into solving all missing msr.h include

[PATCH v3 10/14] x86/xen/msr: Remove pmu_msr_{read,write}()

2025-04-25 Thread Xin Li (Intel)
hile at it, convert the data type of MSR index to u32 in functions called in pmu_msr_chk_emulated(). Suggested-by: H. Peter Anvin (Intel) Suggested-by: Juergen Gross Signed-off-by: Xin Li (Intel) --- Change in v3: *) Remove the "emul" argument of pmu_msr_chk_emulated() (Juergen Gross

[PATCH v3 01/14] x86/msr: Move rdtsc{,_ordered}() to

2025-04-25 Thread Xin Li (Intel)
-off-by: Xin Li (Intel) Acked-by: Dave Hansen --- Change in v3: * Add a problem statement to the changelog (Dave Hansen). --- arch/x86/events/msr.c | 3 + arch/x86/events/perf_event.h | 1 + arch/x86/events/probe.c | 2 + arch/x86

[PATCH v3 13/14] x86/msr: Replace wrmsr(msr, low, 0) with wrmsrq(msr, low)

2025-04-25 Thread Xin Li (Intel)
The third argument in wrmsr(msr, low, 0) is unnecessary. Instead, use wrmsrq(msr, low), which automatically sets the higher 32 bits of the MSR value to 0. Signed-off-by: Xin Li (Intel) --- arch/x86/hyperv/hv_apic.c | 6 +++--- arch/x86/include/asm/apic.h | 2

[PATCH v3 03/14] x86/msr: Rename rdpmcl() to rdpmc()

2025-04-25 Thread Xin Li (Intel)
Now that rdpmc() is gone, i.e. rdpmcl() is the sole PMC read helper, simply rename rdpmcl() to rdpmc(). Signed-off-by: Xin Li (Intel) Acked-by: Dave Hansen --- Changes in v3: *) Explain the reason of the renaming in the changelog (Dave Hansen). *) Use shorter name rdpmc() instead of rdpmcq

[PATCH v3 12/14] x86/pvops/msr: refactor pv_cpu_ops.write_msr{,_safe}()

2025-04-25 Thread Xin Li (Intel)
, refactor pv_cpu_ops.write_msr{_safe}() to accept an MSR value in a single u64 argument, replacing the current dual u32 arguments. No functional change intended. Signed-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross --- Change in v2: * Spell out the reason why use a single u64 argument to pass the

[PATCH v3 11/14] x86/xen/msr: Remove the error pointer argument from set_seg()

2025-04-25 Thread Xin Li (Intel)
safe APIs. Remove the error pointer argument. Signed-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross --- Change in v3: *) Fix a typo: set_reg() => set_seg() (Juergen Gross). --- arch/x86/xen/enlighten_pv.c | 16 +--- 1 file changed, 5 insertions(+), 11 deletions(-) diff --gi

[PATCH v3 09/14] x86/xen/msr: Remove calling native_{read,write}_msr{,_safe}() in pmu_msr_{read,write}()

2025-04-25 Thread Xin Li (Intel)
native_write_msr{,_safe}(), which has now been removed. [1]: https://lore.kernel.org/lkml/0ec48b84-d158-47c6-b14c-3563fd14b...@zytor.com/ Suggested-by: H. Peter Anvin (Intel) Sign-off-by: Xin Li (Intel) --- Change in v3: *) Rename pmu_msr_{read,write}() to pmu_msr_{read,write}_emulated() (Dapeng Mi

[PATCH v3 02/14] x86/msr: Remove rdpmc()

2025-04-25 Thread Xin Li (Intel)
rdpmc() is not used anywhere, remove it. Signed-off-by: Xin Li (Intel) Acked-by: Dave Hansen --- arch/x86/include/asm/msr.h | 7 --- arch/x86/include/asm/paravirt.h | 7 --- 2 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h

[PATCH v3 06/14] x86/msr: Convert __wrmsr() uses to native_wrmsr{,q}() uses

2025-04-25 Thread Xin Li (Intel)
enamed to better reflect their implications, such as native or pvops, with or without trace, and safe or non-safe. No functional change intended. Signed-off-by: Xin Li (Intel) --- Change in v2: * Use native_wrmsr() where natural [rmid_p, closid_p] high/lo parameters can be used, without the

[PATCH v3 14/14] x86/msr: Change the function type of native_read_msr_safe()

2025-04-25 Thread Xin Li (Intel)
way. While at it, convert leftover MSR data type "unsigned int" to u32. Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h| 21 +++-- arch/x86/include/asm/paravirt.h | 19 --- arch/x86/include/asm/paravirt_types.h | 6 +++---

[PATCH v3 00/14] MSR code cleanup part one

2025-04-25 Thread Xin Li (Intel)
linux/kernel/git/tip/tip.git x86/msr Xin Li (Intel) (14): x86/msr: Move rdtsc{,_ordered}() to x86/msr: Remove rdpmc() x86/msr: Rename rdpmcl() to rdpmc() x86/msr: Convert the rdpmc() macro into an always inline function x86/msr: Return u64 consistently in Xen PMC read functions x8

[PATCH v3 08/14] x86/msr: Convert __rdmsr() uses to native_rdmsrq() uses

2025-04-25 Thread Xin Li (Intel)
ve the way for improving MSR API names, convert __rdmsr() uses to native_rdmsrq() to ensure consistent usage. Later, these APIs can be renamed to better reflect their implications, such as native or pvops, with or without trace, and safe or non-safe. No functional change intended. Signed-off-by:

[PATCH v3 05/14] x86/msr: Return u64 consistently in Xen PMC read functions

2025-04-25 Thread Xin Li (Intel)
The pv_ops PMC read API is defined as: u64 (*read_pmc)(int counter); But Xen PMC read functions return unsigned long long, make them return u64 consistently. Signed-off-by: Xin Li (Intel) Reviewed-by: Juergen Gross --- arch/x86/xen/pmu.c | 6 +++--- arch/x86/xen/xen-ops.h | 2

[PATCH v3 04/14] x86/msr: Convert the rdpmc() macro into an always inline function

2025-04-25 Thread Xin Li (Intel)
the returned value, further enhancing readability. Signed-off-by: Xin Li (Intel) Acked-by: Dave Hansen --- Change in v3: *) Add a changelog even it's obvious (Dave Hansen). --- arch/x86/events/amd/uncore.c | 2 +- arch/x86/events/core.c| 2 +- arch/x86/e

[PATCH v3 07/14] x86/msr: Add the native_rdmsrq() helper

2025-04-25 Thread Xin Li (Intel)
() is directly used when it needs to return an MSR value in a u64 integer. Add the native_rdmsrq() helper, which is simply an alias of __rdmsr(), to make native_rdmsr() and native_rdmsrq() a pair of MSR read APIs. Signed-off-by: Xin Li (Intel) --- Change in v2: * Split into two changes and add the

Re: [RFC PATCH v2 12/34] x86/msr: Remove pmu_msr_{read,write}()

2025-04-24 Thread Xin Li
By the way, this patch should have "xen" in its subject tag. Right, I should add it.

Re: [RFC PATCH v2 13/34] x86/xen/msr: Remove the error pointer argument from set_reg()

2025-04-24 Thread Xin Li
On 4/24/2025 3:11 AM, Jürgen Groß wrote: set_seg(), please (further up, too). Good catch, thanks a lot!

Re: [RFC PATCH v2 12/34] x86/msr: Remove pmu_msr_{read,write}()

2025-04-24 Thread Xin Li
On 4/24/2025 3:05 AM, Jürgen Groß wrote: May I suggest to get rid of the "emul" parameter of pmu_msr_chk_emulated()? It has no real value, as pmu_msr_chk_emulated() could easily return false in the cases where it would set *emul to false. Good idea! The function type is a bit of weird but I

Re: [RFC PATCH v2 21/34] x86/msr: Utilize the alternatives mechanism to write MSR

2025-04-24 Thread Xin Li
On 4/23/2025 9:05 AM, Jürgen Groß wrote: It's not a major change, but when it is patched to use the immediate form MSR write instruction, it's straightforwardly streamlined. It should be rather easy to switch the current wrmsr/rdmsr paravirt patching locations to use the rdmsr/wrmsr instructi

Re: [RFC PATCH v2 12/34] x86/msr: Remove pmu_msr_{read,write}()

2025-04-24 Thread Xin Li
On 4/24/2025 12:43 AM, Mi, Dapeng wrote: These 2 patches are not complicated, it won't be difficult to review if merging them into one as long as the commit message mentions it clearly. Anyway I'm fine if you hope to keep them into two patches. Simple Small Steps...

Re: [RFC PATCH v2 12/34] x86/msr: Remove pmu_msr_{read,write}()

2025-04-24 Thread Xin Li
On 4/23/2025 11:33 PM, Mi, Dapeng wrote: Could we merge this patch and previous patch into a single patch? It's unnecessary to just modify the pmu_msr_read()/pmu_msr_write() in previous patch and delete them immediately. It just wastes the effort. No, it's not wasting effort, it's for easier re

Re: [RFC PATCH v2 11/34] x86/msr: Remove calling native_{read,write}_msr{,_safe}() in pmu_msr_{read,write}()

2025-04-24 Thread Xin Li
On 4/23/2025 11:25 PM, Mi, Dapeng wrote: -bool pmu_msr_read(unsigned int msr, uint64_t *val, int *err) +bool pmu_msr_read(u32 msr, u64 *val) The function name is some kind of misleading right now. With the change, this function only read PMU MSR's value if it's emulated, otherwise it won't rea

Re: [RFC PATCH v2 08/34] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-04-23 Thread Xin Li
On 4/23/2025 8:51 AM, Dave Hansen wrote: On 4/22/25 01:21, Xin Li (Intel) wrote: static __always_inline void sev_es_wr_ghcb_msr(u64 val) { - u32 low, high; - - low = (u32)(val); - high = (u32)(val >> 32); - - native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low

Re: [RFC PATCH v2 03/34] x86/msr: Rename rdpmcl() to rdpmcq()

2025-04-23 Thread Xin Li
On 4/23/2025 8:06 AM, Dave Hansen wrote: On 4/23/25 07:28, Sean Christopherson wrote: Now that rdpmc() is gone, i.e. rdpmcl/rdpmcq() is the only helper, why not simply rename rdpmcl() => rdpmc()? I see no point in adding a 'q' qualifier; it doesn't disambiguate anything and IMO is pure noise.

Re: [RFC PATCH v2 01/34] x86/msr: Move rdtsc{,_ordered}() to

2025-04-23 Thread Xin Li
On 4/23/2025 7:13 AM, Dave Hansen wrote: On 4/22/25 01:21, Xin Li (Intel) wrote: Relocate rdtsc{,_ordered}() from to , and subsequently remove the inclusion of in . Consequently, must be included in several source files that previously did not require it. I know it's mildly obviou

Re: [RFC PATCH v2 08/34] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

2025-04-23 Thread Xin Li
On 4/23/2025 8:51 AM, Dave Hansen wrote: On 4/22/25 01:21, Xin Li (Intel) wrote: static __always_inline void sev_es_wr_ghcb_msr(u64 val) { - u32 low, high; - - low = (u32)(val); - high = (u32)(val >> 32); - - native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low

Re: [RFC PATCH v2 22/34] x86/msr: Utilize the alternatives mechanism to read MSR

2025-04-23 Thread Xin Li
On 4/22/2025 4:12 AM, Jürgen Groß wrote: + +static __always_inline bool __rdmsrq(u32 msr, u64 *val, int type) +{ +    bool ret; + +#ifdef CONFIG_XEN_PV +    if (cpu_feature_enabled(X86_FEATURE_XENPV)) +    return __xenpv_rdmsrq(msr, val, type); I don't think this will work for the Xen PV ca

Re: [RFC PATCH v2 10/34] x86/msr: Convert __rdmsr() uses to native_rdmsrq() uses

2025-04-23 Thread Xin Li
On 4/22/2025 8:09 AM, Sean Christopherson wrote: On Tue, Apr 22, 2025, Xin Li (Intel) wrote: __rdmsr() is the lowest level primitive MSR read API, and its direct use is NOT preferred. Doesn't mean it's wrong. I wouldn't go so far as to claim that it's wrong :-) Use

Re: [RFC PATCH v2 21/34] x86/msr: Utilize the alternatives mechanism to write MSR

2025-04-23 Thread Xin Li
On 4/22/2025 2:57 AM, Jürgen Groß wrote: On 22.04.25 10:22, Xin Li (Intel) wrote: The story started from tglx's reply in [1]:    For actual performance relevant code the current PV ops mechanics    are a horrorshow when the op defaults to the native instruction.    look at w

Re: [RFC PATCH v2 06/34] x86/msr: Use the alternatives mechanism to read PMC

2025-04-23 Thread Xin Li
On 4/22/2025 2:28 AM, Juergen Gross wrote: I have worked rather hard to make it less intrusive, especially by removing the paravirt specific code patching (now all done via alternative patching) and by removing 32-bit Xen PV mode. I looked at the optimization, and it is a nice improvement.

Re: [RFC PATCH v2 00/34] MSR refactor with new MSR instructions support

2025-04-22 Thread Xin Li
On 4/22/2025 8:03 AM, Sean Christopherson wrote: On Tue, Apr 22, 2025, Xin Li (Intel) wrote: base-commit: f30a0c0d2b08b355c01392538de8fc872387cb2b This commit doesn't exist in Linus' tree or the tip tree, and the series doesn't apply cleanly on any of the "obvious"

Re: [RFC PATCH v2 22/34] x86/msr: Utilize the alternatives mechanism to read MSR

2025-04-22 Thread Xin Li
On 4/22/2025 1:59 AM, Jürgen Groß wrote: On 22.04.25 10:22, Xin Li (Intel) wrote: To eliminate the indirect call overhead introduced by the pv_ops API, utilize the alternatives mechanism to read MSR: 1) When built with !CONFIG_XEN_PV, X86_FEATURE_XENPV becomes a     disabled feature

Re: [RFC PATCH v2 06/34] x86/msr: Use the alternatives mechanism to read PMC

2025-04-22 Thread Xin Li
On 4/22/2025 1:38 AM, Jürgen Groß wrote: On 22.04.25 10:21, Xin Li (Intel) wrote: To eliminate the indirect call overhead introduced by the pv_ops API, use the alternatives mechanism to read PMC: Which indirect call overhead? The indirect call is patched via the alternative mechanism to a

[RFC PATCH v2 02/34] x86/msr: Remove rdpmc()

2025-04-22 Thread Xin Li (Intel)
rdpmc() is not used anywhere, remove it. Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h | 7 --- arch/x86/include/asm/paravirt.h | 7 --- 2 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 2caa13830e11

[RFC PATCH v2 29/34] x86/msr: Rename native_rdmsrq() to native_rdmsrq_no_trace()

2025-04-22 Thread Xin Li (Intel)
native_rdmsrq() doesn't do trace thus can be used in noinstr context, rename it to native_rdmsrq_no_trace() to make it explicit. Signed-off-by: Xin Li (Intel) --- arch/x86/boot/startup/sme.c | 4 ++-- arch/x86/events/amd/brs.c | 2 +- arch/x86/hyperv/hv_

[RFC PATCH v2 20/34] x86/extable: Implement EX_TYPE_FUNC_REWIND

2025-04-22 Thread Xin Li (Intel)
alternatives pattern, possibly invoking a different exception handling pattern there, or at least indicating the "real" location of the fault. Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/asm.h | 6 + arch/x86/include/a

[RFC PATCH v2 28/34] x86/msr: Rename native_write_msr_safe() to native_wrmsrq_safe()

2025-04-22 Thread Xin Li (Intel)
Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h | 4 ++-- arch/x86/kvm/svm/svm.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 72a1c3301d46..a1c63bed14be 100644 --- a/arch/x86/include/asm

[RFC PATCH v2 30/34] x86/msr: Rename native_rdmsr() to native_rdmsr_no_trace()

2025-04-22 Thread Xin Li (Intel)
native_rdmsr() doesn't do trace thus can be used in noinstr context, rename it to native_rdmsr_no_trace() to make it explicit. Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/microcode.h | 2 +- arch/x86/include/asm/msr.h| 8 arch/x86/kernel/cpu/microcode/

[RFC PATCH v2 00/34] MSR refactor with new MSR instructions support

2025-04-22 Thread Xin Li (Intel)
n handling pattern there, or at least indicating the "real" location of the fault. patches 21 and 22 refactor the code to use the alternatives mechanism to read and write MSR. Patches 23 ~ 34 are afterwards cleanups. H. Peter Anvin (Intel) (1): x86/extable: Implement EX_TYPE_FUNC_REWIND

[RFC PATCH v2 24/34] x86/mce: Use native MSR API __native_{wr,rd}msrq()

2025-04-22 Thread Xin Li (Intel)
Use native MSR API __native_{wr,rd}msrq() instead of MSR assemely. Signed-off-by: Xin Li (Intel) --- arch/x86/kernel/cpu/mce/core.c | 55 +- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce

[RFC PATCH v2 34/34] x86/msr: Convert native_rdmsr_no_trace() uses to native_rdmsrq_no_trace() uses

2025-04-22 Thread Xin Li (Intel)
Convert native_rdmsr_no_trace() uses to native_rdmsrq_no_trace() uses cleanly with the use of struct msr, and remove native_rdmsr_no_trace(). Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/microcode.h | 6 +++--- arch/x86/include/asm/msr.h| 13 +++-- arch/x86

[RFC PATCH v2 25/34] x86/msr: Rename native_wrmsrq() to native_wrmsrq_no_trace()

2025-04-22 Thread Xin Li (Intel)
native_wrmsrq() doesn't do trace thus can be used in noinstr context, rename it to native_wrmsrq_no_trace() to make it explicit. Signed-off-by: Xin Li (Intel) --- arch/x86/events/amd/brs.c | 2 +- arch/x86/hyperv/ivm.c | 2 +- arch/x86/include/asm/a

[RFC PATCH v2 21/34] x86/msr: Utilize the alternatives mechanism to write MSR

2025-04-22 Thread Xin Li (Intel)
ism is also used to choose the new immediate form MSR write instruction when it's available. Consequently, remove the pv_ops MSR write APIs and the Xen callbacks. [1]: https://lore.kernel.org/lkml/87y1h81ht4.ffs@tglx/ Originally-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li (Intel) -

[RFC PATCH v2 26/34] x86/msr: Rename native_wrmsr() to native_wrmsr_no_trace()

2025-04-22 Thread Xin Li (Intel)
native_wrmsr() doesn't do trace thus can be used in noinstr context, rename it to native_wrmsr_no_trace() to make it explicit. Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h| 8 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 ++-- 2 files chang

[RFC PATCH v2 31/34] x86/msr: Rename native_read_msr() to native_rdmsrq()

2025-04-22 Thread Xin Li (Intel)
Signed-off-by: Xin Li (Intel) --- arch/x86/hyperv/ivm.c | 2 +- arch/x86/include/asm/msr.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index dfddf522e838..8860c6c0f013 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch

[RFC PATCH v2 27/34] x86/msr: Rename native_write_msr() to native_wrmsrq()

2025-04-22 Thread Xin Li (Intel)
Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h | 4 ++-- arch/x86/kernel/kvmclock.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 2a62a899f7a5..72a1c3301d46 100644 --- a/arch/x86/include/asm

[RFC PATCH v2 32/34] x86/msr: Rename native_read_msr_safe() to native_rdmsrq_safe()

2025-04-22 Thread Xin Li (Intel)
Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h | 4 ++-- arch/x86/kvm/svm/svm.c | 10 +- arch/x86/xen/pmu.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 4c7aa9e7fbac

[RFC PATCH v2 33/34] x86/msr: Move the ARGS macros after the MSR read/write APIs

2025-04-22 Thread Xin Li (Intel)
Since the ARGS macros are no longer used in the MSR read/write API implementation, move them after their definitions. Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h | 38 +- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/arch

[RFC PATCH v2 10/34] x86/msr: Convert __rdmsr() uses to native_rdmsrq() uses

2025-04-22 Thread Xin Li (Intel)
ed to change, but the approaches how they perform MSR operations are binary patched during boot time upon availability of MSR instructions. Signed-off-by: Xin Li (Intel) --- arch/x86/boot/startup/sme.c | 4 ++-- arch/x86/events/amd/brs.c | 2 +- arch/x86/hyperv/hv_

[RFC PATCH v2 15/34] x86/msr: Replace wrmsr(msr, low, 0) with wrmsrq(msr, low)

2025-04-22 Thread Xin Li (Intel)
Signed-off-by: Xin Li (Intel) --- arch/x86/hyperv/hv_apic.c | 6 +++--- arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/switch_to.h | 2 +- arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 8

[RFC PATCH v2 17/34] x86/cpufeatures: Add a CPU feature bit for MSR immediate form instructions

2025-04-22 Thread Xin Li (Intel)
feature bit for MSR immediate form instructions. Suggested-by: Borislav Petkov (AMD) Signed-off-by: Xin Li (Intel) --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c| 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86

[RFC PATCH v2 03/34] x86/msr: Rename rdpmcl() to rdpmcq()

2025-04-22 Thread Xin Li (Intel)
Signed-off-by: Xin Li (Intel) --- arch/x86/events/amd/uncore.c | 2 +- arch/x86/events/core.c| 2 +- arch/x86/events/intel/core.c | 4 ++-- arch/x86/events/intel/ds.c| 2 +- arch/x86/include/asm/msr.h| 2 +- arch

[RFC PATCH v2 12/34] x86/msr: Remove pmu_msr_{read,write}()

2025-04-22 Thread Xin Li (Intel)
As pmu_msr_{read,write}() are now wrappers of pmu_msr_chk_emulated(), remove them and use pmu_msr_chk_emulated() directly. While at it, convert the data type of MSR index to u32 in functions called in pmu_msr_chk_emulated(). Suggested-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li (Intel

[RFC PATCH v2 01/34] x86/msr: Move rdtsc{,_ordered}() to

2025-04-22 Thread Xin Li (Intel)
Relocate rdtsc{,_ordered}() from to , and subsequently remove the inclusion of in . Consequently, must be included in several source files that previously did not require it. Signed-off-by: Xin Li (Intel) --- arch/x86/boot/startup/sme.c | 1 + arch/x86/events/msr.c

  1   2   3   4   5   >