From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE9BA2C21F4 for ; Sat, 13 Jun 2026 00:04:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781309045; cv=none; b=LBDt00qryRc4RUwHGGfe+DLZlWFM0RyV5n6KW4N6pfYdZcmmIen1yGTKS94ipSXMWjYNI7vX4+/z8S3icCkzRoTsqlMdceaZxI5wJ7rB/mgTXwrDYG7FJTWeF1OMd39Oegd8uam7VAJMQx5HR0ZnwsLEo/MhuH/PeZmO1No48Fc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781309045; c=relaxed/simple; bh=Uua8NoReLZwg+KtTDEAKtFGq6YCkul3qgJGQ39pG+U0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=K+hh0FOyPUl32k/1sK5WJdN06abwktdtNBUqKw6yFZKAIbN9BdCWefHaaFfAw65BssN5sjSoSfBV2uSJcrj37M2FaBDeG634OELlckBqAJCiIzZ57MmasHCtY/uT0RuC7GXrjtW+atBF8hgm7Qpa6hgOkd7n+Lo3Ood8BGTDf+0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Kme6ZnaQ; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Kme6ZnaQ" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2c2b64850easo28395185ad.1 for ; Fri, 12 Jun 2026 17:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781309043; x=1781913843; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=yMmgBRMgDm3PgTUcsZS0pmZjV2CvUFeUFMjem5CthKU=; b=Kme6ZnaQYaI9jcf+lssVROyVHS1rOJ+Z9534AhjrKnjOA/w65GxNu9HId5ZWBFnlri 0GbPSq7vhqKtSTofq3m7Q7d5x3HCgNwKMZ2nubEaEEyK5Yl7C9YHcDSZ8M8gNlmmUTlc 4jdV+XmFMJmDQlHA/lmigDTg2heBgb0wgBamtdjsCbEyCxIR2o5b2ECR0ihwoOW1wLS2 o0UrLwWxVbz7z4djrwetKxjvs78vVe4Mt+TgDw6mQyf0126AXJ1p8KLaFGpDtoY00UEc 7soB8gAfOQBWeiti/suumSeIvFgBOhSVGpz5ehu1gXfV412ickELuFWxI8QvAy8btO07 tNSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781309043; x=1781913843; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yMmgBRMgDm3PgTUcsZS0pmZjV2CvUFeUFMjem5CthKU=; b=C1r+B0txURbDwcwA0H8XS4XOg7hl9xfhSls5WpoaqZ1yorpRHyGpg+piT+pLSc3GG1 GWG3p6pwIwzS+zOGtjNJQXt5V3mEigQ3K89rZ3yIWX9nU8BlKYTQyFTNFKacpF3K8Mn9 MF4mdWB1HPdEN0Hbj4RsLGtnSb1skdgjNcOgZwS/50pD4LMeF7WyEs0moNsjiaGaebPT UPZeXiW+zYzmrQFtiixUQjEDjuC6Y3u6XQNHywO4CJxn2s8Ty1LkLKCXAH43Df88p4x8 sNaF3sT1lc9OVuSkZw9Ip5OKGgvH8E0Fx1tZYpNUr0mfld0VV8z5lMYaF8xzyZVHWRAh KhOw== X-Forwarded-Encrypted: i=1; AFNElJ9PTINOZxdxqtR9lzcojfhV3p8OGJYCiVCAT9C1Z/V6mwldJav0MDqDb8+Mxll98oeqvIGtXYbIjE7aulg=@vger.kernel.org X-Gm-Message-State: AOJu0YyjMTx33efYSX2F0SllvCJ1F7+zhvKXPcCtOQJZ/85XTChmpVM9 jB1565R76t1+zuuVrYGA3teztAeT9HFukBjTFyR8gWsudAjY8L+wpzybGj/pYUii1rzIytuRV16 bOcQFQw== X-Received: from plps24.prod.google.com ([2002:a17:902:9898:b0:2c0:d81c:b06a]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e790:b0:2c0:b4f5:41ea with SMTP id d9443c01a7336-2c66424305emr17166115ad.17.1781309042887; Fri, 12 Jun 2026 17:04:02 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 Jun 2026 17:03:20 -0700 In-Reply-To: <20260613000329.732085-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260613000329.732085-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260613000329.732085-22-seanjc@google.com> Subject: [PATCH v4 21/30] KVM: x86: Move LLDT assembly wrappers into VMX From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Kai Huang Content-Type: text/plain; charset="UTF-8" Move kvm_{load,read}_ldt() into vmx.c, as vmx_{load,store}_ldt(), as they are exclusively used by VMX to save/restore host state, and have no business being globally visible. Ideally, KVM-specific helpers wouldn't exist at all, as they are nothing more than assembly wrappers for SLDT and LLDT, i.e. should be provided by the kernel, not by KVM. Punt that cleanup to the future, as arch/x86/include/asm/desc.h _does_ provide helpers, but load_ldt() is only available for CONFIG_PARAVIRT_XXL=n builds, and both {load,store}_ldt() unnecessarily constrain the operands to memory. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 12 ------------ arch/x86/kvm/vmx/vmx.c | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 1dd231ecf4b2..d1fdb2c3fdfa 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2312,18 +2312,6 @@ static inline void kvm_dec_apicv_irq_window_req(struct kvm *kvm) #define kvm_arch_has_readonly_mem(kvm) (!(kvm)->arch.has_protected_state) -static inline u16 kvm_read_ldt(void) -{ - u16 ldt; - asm("sldt %0" : "=g"(ldt)); - return ldt; -} - -static inline void kvm_load_ldt(u16 sel) -{ - asm("lldt %0" : : "rm"(sel)); -} - #ifdef CONFIG_X86_64 static inline unsigned long read_msr(unsigned long msr) { diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index c548f22375ad..2c120ff47790 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1186,6 +1186,18 @@ static void vmx_remove_autostore_msr(struct vcpu_vmx *vmx, u32 msr) vmx_remove_auto_msr(&vmx->msr_autostore, msr, VM_EXIT_MSR_STORE_COUNT); } +static u16 vmx_store_ldt(void) +{ + u16 ldt; + asm("sldt %0" : "=g"(ldt)); + return ldt; +} + +static void vmx_load_ldt(u16 sel) +{ + asm("lldt %0" : : "rm"(sel)); +} + #ifdef CONFIG_X86_32 /* * On 32-bit kernels, VM exits still load the FS and GS bases from the @@ -1203,7 +1215,7 @@ static unsigned long segment_base(u16 selector) table = get_current_gdt_ro(); if ((selector & SEGMENT_TI_MASK) == SEGMENT_LDT) { - u16 ldt_selector = kvm_read_ldt(); + u16 ldt_selector = vmx_store_ldt(); if (!(ldt_selector & ~SEGMENT_RPL_MASK)) return 0; @@ -1358,7 +1370,7 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu) * Set host fs and gs selectors. Unfortunately, 22.2.3 does not * allow segment selectors with cpl > 0 or ti == 1. */ - host_state->ldt_sel = kvm_read_ldt(); + host_state->ldt_sel = vmx_store_ldt(); #ifdef CONFIG_X86_64 savesegment(ds, host_state->ds_sel); @@ -1405,7 +1417,7 @@ static void vmx_prepare_switch_to_host(struct vcpu_vmx *vmx) rdmsrq(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); #endif if (host_state->ldt_sel || (host_state->gs_sel & 7)) { - kvm_load_ldt(host_state->ldt_sel); + vmx_load_ldt(host_state->ldt_sel); #ifdef CONFIG_X86_64 load_gs_index(host_state->gs_sel); #else -- 2.54.0.1136.gdb2ca164c4-goog