Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sohil Mehta <sohil.mehta@intel.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <kvm@vger.kernel.org>
Subject: Re: [PATCH v4 4/7] KVM: VMX: Implement LASS violation check
Date: Thu, 6 Aug 2026 18:42:21 -0700	[thread overview]
Message-ID: <cc0d6b41-7e5e-438a-9129-b71cd16be354@intel.com> (raw)
In-Reply-To: <20260806015225.3A1641F000E9@smtp.kernel.org>

On 8/5/2026 6:52 PM, sashiko-bot@kernel.org wrote:
>> @@ -8604,6 +8604,53 @@ gva_t vmx_get_untagged_addr(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags
>>  	return (sign_extend64(gva, lam_bit) & ~BIT_ULL(63)) | (gva & BIT_ULL(63));
>>  }
>>  
>> +bool vmx_is_lass_violation(struct kvm_vcpu *vcpu, gva_t gva,
>> +			   unsigned int size, unsigned int flags)
>> +{
>> +	const bool is_supervisor_address = !!(gva & BIT_ULL(63));
>> +	const bool implicit_supervisor = !!(flags & X86EMUL_F_IMPLICIT);
>> +	const bool fetch = !!(flags & X86EMUL_F_FETCH);
>> +
>> +	if (!kvm_is_cr4_bit_set(vcpu, X86_CR4_LASS) || !is_long_mode(vcpu))
>> +		return false;
> 
> [Severity: High]
> Should this check use is_64_bit_mode() instead of is_long_mode()?
> 

No, LASS applies only to IA-32e mode. So, I think the is_long_mode()
check here is correct.

> If a guest is in compatibility mode with LASS and SMAP enabled, a compatibility
> mode application might trigger an interrupt resulting in an implicit supervisor
> access to the IDT or TSS. Since compatibility-mode linear addresses are 32-bit,
> bit 63 is always 0.
> 

AFAIU, in IA-32e compatiblity mode, all the bases (GDTR, IDTR, LDTR, and
TR) hold the full 64-bit address. So, there isn't any truncation and an
implicit supervisor access should have bit 63 present (set as 1).


> Does using is_long_mode() cause the hypervisor to erroneously flag these as
> LASS violations for supervisor mode, breaking 32-bit execution?
> 

...

>> +
>> +	/*
>> +	 * LASS enforcement for supervisor-mode data accesses depends on SMAP
>> +	 * being enabled, and like SMAP ignores explicit accesses if RFLAGS.AC=1.
>> +	 */
>> +	if (!fetch) {
>> +		if (!kvm_is_cr4_bit_set(vcpu, X86_CR4_SMAP))
>> +			return false;
>> +
>> +		if (!implicit_supervisor && (kvm_get_rflags(vcpu) & X86_EFLAGS_AC))
>> +			return false;
>> +	}
> 
> [Severity: High]
> Does LASS enforcement for supervisor-mode instruction fetches require a check
> for SMEP being enabled here?
> > According to the architecture specification, LASS applies to supervisor
> instruction fetches only if SMEP is enabled, similar to how it requires
> SMAP for data accesses.
> 

No, an SMEP check is not needed during LASS enforcement. The SDM
specifically states that:

"LASS enforces the equivalent of supervisor-mode execution prevention
regardless of the setting of CR4.SMEP[bit 17]"

"A supervisor-mode instruction fetch causes a LASS violation if it would
accesses a linear address of which bit 63 is 0. (Unlike paging, this
behavior of LASS applies regardless of the setting of CR4.SMEP.)"

So, an SMEP check would actually be wrong.

> If a guest OS running in 64-bit mode with CR4.LASS = 1 and CR4.SMEP = 0
> performs a supervisor-mode instruction fetch from a user-mode address,
> will omitting a kvm_is_cr4_bit_set(vcpu, X86_CR4_SMEP) check when fetch
> is true cause a spurious #GP fault to be injected?
> 



  reply	other threads:[~2026-08-07  1:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  1:15 [PATCH v4 0/7] KVM: x86: Add LASS virtualization support Sohil Mehta
2026-08-06  1:15 ` [PATCH v4 1/7] KVM: x86: Add an emulator flag to differentiate branch targets from fetches Sohil Mehta
2026-08-06  1:15 ` [PATCH v4 2/7] KVM: x86: Use linear_read_system() to read the TSS I/O bitmap Sohil Mehta
2026-08-06  1:15 ` [PATCH v4 3/7] KVM: x86: Add LASS violation checks during instruction emulation Sohil Mehta
2026-08-06  1:15 ` [PATCH v4 4/7] KVM: VMX: Implement LASS violation check Sohil Mehta
2026-08-06  1:52   ` sashiko-bot
2026-08-07  1:42     ` Sohil Mehta [this message]
2026-08-06  1:15 ` [PATCH v4 5/7] KVM: x86: Virtualize LASS and advertise support to userspace Sohil Mehta
2026-08-06  1:15 ` [PATCH v4 6/7] KVM: selftests: Add coverage for LASS CPUID and CR4 handling Sohil Mehta
2026-08-06  1:15 ` [PATCH v4 7/7] selftests/x86: Add a userspace test for LASS enforcement Sohil Mehta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc0d6b41-7e5e-438a-9129-b71cd16be354@intel.com \
    --to=sohil.mehta@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox