2022-05-11 07:39:53

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [RFCv2 04/10] x86/mm: Introduce X86_THREAD_LAM_U48 and X86_THREAD_LAM_U57

On Wed, May 11, 2022 at 05:27:45AM +0300, Kirill A. Shutemov wrote:

> +#define LAM_NONE 0
> +#define LAM_U57 1
> +#define LAM_U48 2

> +#define X86_THREAD_LAM_U48 0x1
> +#define X86_THREAD_LAM_U57 0x2

Seriously pick an order and stick with it. I would suggest keeping the
hardware order and then you can do:

> +static inline unsigned long lam_to_cr3(u8 lam)
> +{
> + switch (lam) {
> + case LAM_NONE:
> + return 0;
> + case LAM_U57:
> + return X86_CR3_LAM_U57;
> + case LAM_U48:
> + return X86_CR3_LAM_U48;
> + default:
> + WARN_ON_ONCE(1);
> + return 0;
> + }

return (lam & 0x3) << X86_CR3_LAM_U57;

> +}
> +
> +static inline u8 cr3_to_lam(unsigned long cr3)
> +{
> + if (cr3 & X86_CR3_LAM_U57)
> + return LAM_U57;
> + if (cr3 & X86_CR3_LAM_U48)
> + return LAM_U48;
> + return 0;


return (cr3 >> X86_CR3_LAM_U57) & 0x3;

> +}

and call it a day, or something.

I'm still not liking LAM(e), I'm thikning it's going to create more
problems than it solves.


2022-05-12 19:38:33

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [RFCv2 04/10] x86/mm: Introduce X86_THREAD_LAM_U48 and X86_THREAD_LAM_U57

On Wed, May 11 2022 at 09:02, Peter Zijlstra wrote:
> On Wed, May 11, 2022 at 05:27:45AM +0300, Kirill A. Shutemov wrote:
>
>> +#define LAM_NONE 0
>> +#define LAM_U57 1
>> +#define LAM_U48 2
>
>> +#define X86_THREAD_LAM_U48 0x1
>> +#define X86_THREAD_LAM_U57 0x2
>
> Seriously pick an order and stick with it. I would suggest keeping the
> hardware order and then you can do:
>
>> +static inline unsigned long lam_to_cr3(u8 lam)
>> +{
>
> return (lam & 0x3) << X86_CR3_LAM_U57;

This "works" because the hardware ignores LAM_U48 if LAM_U57 is set, but
I'd rather make that exclusive in the prctl() as setting both does not
make any sense.

> I'm still not liking LAM(e), I'm thikning it's going to create more
> problems than it solves.

Isn't that true for most new hardware features?

Thanks,

tglx

2022-05-14 03:09:56

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [RFCv2 04/10] x86/mm: Introduce X86_THREAD_LAM_U48 and X86_THREAD_LAM_U57

On Thu, May 12, 2022 at 02:24:22PM +0200, Thomas Gleixner wrote:
> On Wed, May 11 2022 at 09:02, Peter Zijlstra wrote:
> > On Wed, May 11, 2022 at 05:27:45AM +0300, Kirill A. Shutemov wrote:
> >
> >> +#define LAM_NONE 0
> >> +#define LAM_U57 1
> >> +#define LAM_U48 2
> >
> >> +#define X86_THREAD_LAM_U48 0x1
> >> +#define X86_THREAD_LAM_U57 0x2
> >
> > Seriously pick an order and stick with it. I would suggest keeping the
> > hardware order and then you can do:
> >
> >> +static inline unsigned long lam_to_cr3(u8 lam)
> >> +{
> >
> > return (lam & 0x3) << X86_CR3_LAM_U57;
>
> This "works" because the hardware ignores LAM_U48 if LAM_U57 is set, but
> I'd rather make that exclusive in the prctl() as setting both does not
> make any sense.

Yes, I was very much assuming the interface would not allow setting
both, that would be daft.