2021-05-11 16:47:43

by Dave Hansen

[permalink] [raw]
Subject: Re: [PATCH v2] KVM: x86: use wrpkru directly in kvm_load_{guest|host}_xsave_state

On 5/11/21 8:59 AM, Jon Kohler wrote:
> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
> index b1099f2d9800..20f1fb8be7ef 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -151,7 +151,7 @@ static inline void write_pkru(u32 pkru)
> fpregs_lock();
> if (pk)
> pk->pkru = pkru;
> - __write_pkru(pkru);
> + wrpkru(pkru);
> fpregs_unlock();
> }

This removes the:

if (pkru == rdpkru())
return;

optimization from a couple of write_pkru() users:
arch_set_user_pkey_access() and copy_init_pkru_to_fpregs().

Was that intentional? Those aren't the hottest paths in the kernel, but
copy_init_pkru_to_fpregs() is used in signal handling and exeve().


2021-05-11 16:52:19

by Jon Kohler

[permalink] [raw]
Subject: Re: [PATCH v2] KVM: x86: use wrpkru directly in kvm_load_{guest|host}_xsave_state



> On May 11, 2021, at 12:45 PM, Dave Hansen <[email protected]> wrote:
>
> On 5/11/21 8:59 AM, Jon Kohler wrote:
>> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
>> index b1099f2d9800..20f1fb8be7ef 100644
>> --- a/arch/x86/include/asm/pgtable.h
>> +++ b/arch/x86/include/asm/pgtable.h
>> @@ -151,7 +151,7 @@ static inline void write_pkru(u32 pkru)
>> fpregs_lock();
>> if (pk)
>> pk->pkru = pkru;
>> - __write_pkru(pkru);
>> + wrpkru(pkru);
>> fpregs_unlock();
>> }
>
> This removes the:
>
> if (pkru == rdpkru())
> return;
>
> optimization from a couple of write_pkru() users:
> arch_set_user_pkey_access() and copy_init_pkru_to_fpregs().
>
> Was that intentional? Those aren't the hottest paths in the kernel, but
> copy_init_pkru_to_fpregs() is used in signal handling and exeve().

That wasn’t intentional, I’ll take a look and send out a v3 pronto.

Thanks, Dave

2021-05-11 17:12:36

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH v2] KVM: x86: use wrpkru directly in kvm_load_{guest|host}_xsave_state

On 11/05/21 18:45, Dave Hansen wrote:
> On 5/11/21 8:59 AM, Jon Kohler wrote:
>> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
>> index b1099f2d9800..20f1fb8be7ef 100644
>> --- a/arch/x86/include/asm/pgtable.h
>> +++ b/arch/x86/include/asm/pgtable.h
>> @@ -151,7 +151,7 @@ static inline void write_pkru(u32 pkru)
>> fpregs_lock();
>> if (pk)
>> pk->pkru = pkru;
>> - __write_pkru(pkru);
>> + wrpkru(pkru);
>> fpregs_unlock();
>> }
>
> This removes the:
>
> if (pkru == rdpkru())
> return;
>
> optimization from a couple of write_pkru() users:
> arch_set_user_pkey_access() and copy_init_pkru_to_fpregs().
>
> Was that intentional? Those aren't the hottest paths in the kernel, but
> copy_init_pkru_to_fpregs() is used in signal handling and exeve().

Yeah, you should move it from __write_pkru() to write_pkru() but not
remove it completely.

Paolo

2021-05-11 17:13:51

by Jon Kohler

[permalink] [raw]
Subject: Re: [PATCH v2] KVM: x86: use wrpkru directly in kvm_load_{guest|host}_xsave_state



> On May 11, 2021, at 1:08 PM, Paolo Bonzini <[email protected]> wrote:
>
> On 11/05/21 18:45, Dave Hansen wrote:
>> On 5/11/21 8:59 AM, Jon Kohler wrote:
>>> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
>>> index b1099f2d9800..20f1fb8be7ef 100644
>>> --- a/arch/x86/include/asm/pgtable.h
>>> +++ b/arch/x86/include/asm/pgtable.h
>>> @@ -151,7 +151,7 @@ static inline void write_pkru(u32 pkru)
>>> fpregs_lock();
>>> if (pk)
>>> pk->pkru = pkru;
>>> - __write_pkru(pkru);
>>> + wrpkru(pkru);
>>> fpregs_unlock();
>>> }
>> This removes the:
>> if (pkru == rdpkru())
>> return;
>> optimization from a couple of write_pkru() users:
>> arch_set_user_pkey_access() and copy_init_pkru_to_fpregs().
>> Was that intentional? Those aren't the hottest paths in the kernel, but
>> copy_init_pkru_to_fpregs() is used in signal handling and exeve().
>
> Yeah, you should move it from __write_pkru() to write_pkru() but not remove it completely.
>
> Paolo

Thanks, Paolo. Just sent out a v3 with that fix up included, so all of
the previous callers should be at par and not notice any differences