lkml.org 
[lkml]   [2020]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH RFC V2 04/17] x86/pks: Preserve the PKRS MSR on context switch
On Fri, Jul 17, 2020 at 10:59:54AM +0200, Peter Zijlstra wrote:
> On Fri, Jul 17, 2020 at 12:20:43AM -0700, ira.weiny@intel.com wrote:
> > +/*
> > + * Write the PKey Register Supervisor. This must be run with preemption
> > + * disabled as it does not guarantee the atomicity of updating the pkrs_cache
> > + * and MSR on its own.
> > + */
> > +void write_pkrs(u32 pkrs_val)
> > +{
> > + this_cpu_write(pkrs_cache, pkrs_val);
> > + wrmsrl(MSR_IA32_PKRS, pkrs_val);
> > +}
>
> Should we write that like:
>
> void write_pkrs(u32 pkr)
> {
> u32 *pkrs = get_cpu_ptr(pkrs_cache);
> if (*pkrs != pkr) {
> *pkrs = pkr;
> wrmsrl(MSR_IA32_PKRS, pkr);
> }
> put_cpu_ptrpkrs_cache);
> }
>
> given that we fundamentally need to serialize againt schedule() here.

Yes. That seems better.

That also means pks_sched_in() can be simplified to just

static inline void pks_sched_in(void)
{
write_pkrs(current->thread.saved_pkrs);
}

Because of the built WRMSR avoidance.

However, pkrs_cache is static so I think I need to use {get,put}_cpu_var() here
don't I?

Thanks!
Ira

\
 
 \ /
  Last update: 2020-07-18 00:35    [W:0.128 / U:0.804 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site