Re: [PATCH V2 4/5] KVM: X86: Handle implicit supervisor access with SMAP

From: Paolo Bonzini
Date: Tue Mar 15 2022 - 17:05:00 EST


On 3/11/22 08:03, Lai Jiangshan wrote:
- unsigned long not_smap = (cpl - 3) & (rflags & X86_EFLAGS_AC);
- int index = (pfec >> 1) +
- (not_smap >> (X86_EFLAGS_AC_BIT - PFERR_RSVD_BIT + 1));
+ bool explicit_access = !(access & PFERR_IMPLICIT_ACCESS);
+ bool not_smap = (rflags & X86_EFLAGS_AC) && explicit_access;
+ int index = (pfec + (!!not_smap << PFERR_RSVD_BIT)) >> 1;

Also possible:

u64 implicit_access = access & PFERR_IMPLICIT_ACCESS;
bool not_smap = ((rflags & X86_EFLAGS_AC) | implicit_access) == X86_EFLAGS_AC;
int index = (pfec + (not_smap << PFERR_RSVD_BIT)) >> 1;

Paolo