Mailing List Archive

[PATCH 2/5] x86/asm: Split __wr{fs, gs}base() out of write_{fs, gs}_base()
To match the read side which is already split out. A future change will want
to use them.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>
---
xen/include/asm-x86/msr.h | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h
index 5e141ac5a5..16f95e7344 100644
--- a/xen/include/asm-x86/msr.h
+++ b/xen/include/asm-x86/msr.h
@@ -156,6 +156,24 @@ static inline unsigned long __rdgsbase(void)
return base;
}

+static inline void __wrfsbase(unsigned long base)
+{
+#ifdef HAVE_AS_FSGSBASE
+ asm volatile ( "wrfsbase %0" :: "r" (base) );
+#else
+ asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd0" :: "a" (base) );
+#endif
+}
+
+static inline void __wrgsbase(unsigned long base)
+{
+#ifdef HAVE_AS_FSGSBASE
+ asm volatile ( "wrgsbase %0" :: "r" (base) );
+#else
+ asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8" :: "a" (base) );
+#endif
+}
+
static inline unsigned long read_fs_base(void)
{
unsigned long base;
@@ -199,11 +217,7 @@ static inline unsigned long read_gs_shadow(void)
static inline void write_fs_base(unsigned long base)
{
if ( read_cr4() & X86_CR4_FSGSBASE )
-#ifdef HAVE_AS_FSGSBASE
- asm volatile ( "wrfsbase %0" :: "r" (base) );
-#else
- asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd0" :: "a" (base) );
-#endif
+ __wrfsbase(base);
else
wrmsrl(MSR_FS_BASE, base);
}
@@ -211,11 +225,7 @@ static inline void write_fs_base(unsigned long base)
static inline void write_gs_base(unsigned long base)
{
if ( read_cr4() & X86_CR4_FSGSBASE )
-#ifdef HAVE_AS_FSGSBASE
- asm volatile ( "wrgsbase %0" :: "r" (base) );
-#else
- asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8" :: "a" (base) );
-#endif
+ __wrgsbase(base);
else
wrmsrl(MSR_GS_BASE, base);
}
--
2.11.0
Re: [PATCH 2/5] x86/asm: Split __wr{fs,gs}base() out of write_{fs,gs}_base() [ In reply to ]
On 09.09.2020 11:59, Andrew Cooper wrote:
> To match the read side which is already split out. A future change will want
> to use them.
>
> No functional change.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
Of course ...

> --- a/xen/include/asm-x86/msr.h
> +++ b/xen/include/asm-x86/msr.h
> @@ -156,6 +156,24 @@ static inline unsigned long __rdgsbase(void)
> return base;
> }
>
> +static inline void __wrfsbase(unsigned long base)
> +{
> +#ifdef HAVE_AS_FSGSBASE
> + asm volatile ( "wrfsbase %0" :: "r" (base) );
> +#else
> + asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd0" :: "a" (base) );
> +#endif
> +}
> +
> +static inline void __wrgsbase(unsigned long base)
> +{
> +#ifdef HAVE_AS_FSGSBASE
> + asm volatile ( "wrgsbase %0" :: "r" (base) );
> +#else
> + asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8" :: "a" (base) );
> +#endif
> +}

... I'd have preferred if you had used just a single leading
underscore, despite realizing this would introduce an inconsistency
with the read sides.

Jan
Re: [PATCH 2/5] x86/asm: Split __wr{fs,gs}base() out of write_{fs,gs}_base() [ In reply to ]
On 10/09/2020 15:47, Jan Beulich wrote:
> On 09.09.2020 11:59, Andrew Cooper wrote:
>> To match the read side which is already split out. A future change will want
>> to use them.
>>
>> No functional change.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Acked-by: Jan Beulich <jbeulich@suse.com>
> Of course ...
>
>> --- a/xen/include/asm-x86/msr.h
>> +++ b/xen/include/asm-x86/msr.h
>> @@ -156,6 +156,24 @@ static inline unsigned long __rdgsbase(void)
>> return base;
>> }
>>
>> +static inline void __wrfsbase(unsigned long base)
>> +{
>> +#ifdef HAVE_AS_FSGSBASE
>> + asm volatile ( "wrfsbase %0" :: "r" (base) );
>> +#else
>> + asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd0" :: "a" (base) );
>> +#endif
>> +}
>> +
>> +static inline void __wrgsbase(unsigned long base)
>> +{
>> +#ifdef HAVE_AS_FSGSBASE
>> + asm volatile ( "wrgsbase %0" :: "r" (base) );
>> +#else
>> + asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8" :: "a" (base) );
>> +#endif
>> +}
> ... I'd have preferred if you had used just a single leading
> underscore, despite realizing this would introduce an inconsistency
> with the read sides.

You're welcome to change them if you wish.

As always, I value consistency far far higher than arbitrary rules which
don't impact us in practice.

~Andrew