From nobody Thu Dec 18 05:59:48 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 A3A0C82D91 for ; Fri, 28 Feb 2025 01:44:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740707066; cv=none; b=Tw/iGnqQF5AddNmpRn9WI7efoGceyARgky8T5DcvXfXlWL9XnrYxI+Y/kX0m1WDmqV84+CvesXySxKN4WKd77AOCXvoSSr5Nro84bgkysMYkodDuj4UpMLzQ5uprj0d5RSdUrAHJjXgrLW0hQxg7GYF/quoFUNaqop0jlEXp+hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740707066; c=relaxed/simple; bh=SF/I9f89+NInfP0I1/V1gnMqErGHupNTd82F7aq8pZQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GDg8vg/AU0lj0edNwgF0+zxp5L9hOlypgfC03K4+eiahgmxUtcL4aU9paaOaSyC9DmaLggGPdVeS7kgun6oBDDAJWfM6yS6hZTnieu+cVK+0gIu5JI93S4R51X7bD+ZHPF9lRBFf9MH+7ctBvWu/o05D2fFJPy042x5bdmq+ULQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vannapurve.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uDjTWwgj; arc=none smtp.client-ip=209.85.216.74 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--vannapurve.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uDjTWwgj" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2feb4648d4dso3099239a91.1 for ; Thu, 27 Feb 2025 17:44:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740707064; x=1741311864; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bPdyjIM3ZKqdo1hreqkAvh1ndzn/WZ8X4nW+LYOFom8=; b=uDjTWwgjJVPnPLAzmoD+MmHGt8Azgc499LrXPXKsidBOn7a6Y+/+2/tiVTAMOZXhuq avGW9VMMC5oZy2ZArQfpgczE1fbQ1Px/6rtfdWwEBSgN2Hs/8DlmZd80nYDy9mH7ZAUt c5p/Fk099eKQG5rEGwkdgUQRIBbxjxZoSjDqG54sC4UwbZ40peTBqDJAQ0Sh926Z9cuJ 2WH50zDM3pnKQ6zs/Qrfzb1GN2ga7pnKP2RjL2PCGll5gUcN0EUpbyKtZcId82cHJhdC HqZWp5N8DyEjS4q2gd7xLhlIk8X4k/Dueh3FMPL5+Y4xJ1KM1IqfGsu+7znYWagu9qbM ac9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740707064; x=1741311864; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bPdyjIM3ZKqdo1hreqkAvh1ndzn/WZ8X4nW+LYOFom8=; b=F8pF4/lVk2e78AWAngHyNYV6GmDCYlB4lzOYyDkDM65eh9wnPrXKelGEg7LFvhBwRo p/TbqQK0k+E3DoYgPKfAeJ/noaj5Nh1ea3h9cyqyMN81Ktn9twNaRgYU0t3i6lE6n3gi BRX8ndOfDi74tZ4XjqWZ/ViUONOfdQRw9Vas2yUcVZmWYswv82j1m5vddxkne3No3USD doeWuGUtknoCHIuG4Sy94hLP2aZ6rQVaBFwKDa4X7uoyv76QWbAHFYa8nDQzVg6Zo/4w QQZFJfYLIvHmNRiW8px69W6jrUAJt5sZrTj20A9COqxy7ZU6qgQGSc47iDMYOaE86mM9 Ma0g== X-Forwarded-Encrypted: i=1; AJvYcCVZ9PfGEHSgWsLNwa8oCpu/j1mBaSR8zEbKyyDBV+tTX2pwp3yyod9xtnwpUTv7320YsSU4xjBkheKEdaM=@vger.kernel.org X-Gm-Message-State: AOJu0YwYx30Boypr8v+xEDkN0J9CDsFKwMDDMpfzvN5CpTp/LUDwo5UP ZLCH5XvdrSvUcHgecWZ0zoE/d6pgtpIk7I506aZYR7/fob3bHG81+mOTcZkiflgwCwSpEPOLJJd +1cY1px9T87yFjzGZcw== X-Google-Smtp-Source: AGHT+IFL146WGwGxH8rcUARvhRczpknZZ9/9ZUf4ofMEkzBKaSyFtK1tsge5rPIqyDZqSBw/D8YZZ4pQkXMOQJUs X-Received: from pgct22.prod.google.com ([2002:a05:6a02:5296:b0:add:b1a5:fc76]) (user=vannapurve job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2d12:b0:1f1:432:5396 with SMTP id adf61e73a8af0-1f2f4d2253emr2225554637.22.1740707063939; Thu, 27 Feb 2025 17:44:23 -0800 (PST) Date: Fri, 28 Feb 2025 01:44:14 +0000 In-Reply-To: <20250228014416.3925664-1-vannapurve@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250228014416.3925664-1-vannapurve@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250228014416.3925664-2-vannapurve@google.com> Subject: [PATCH v7 1/3] x86/paravirt: Move halt paravirt calls under CONFIG_PARAVIRT From: Vishal Annapurve To: dave.hansen@linux.intel.com, kirill.shutemov@linux.intel.com, jgross@suse.com, ajay.kaher@broadcom.com, ak@linux.intel.com, tony.luck@intel.com, thomas.lendacky@amd.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, seanjc@google.com, kai.huang@intel.com, chao.p.peng@linux.intel.com, isaku.yamahata@gmail.com, sathyanarayanan.kuppuswamy@linux.intel.com, erdemaktas@google.com, ackerleytng@google.com, jxgao@google.com, sagis@google.com, afranji@google.com, kees@kernel.org, jikos@kernel.org, peterz@infradead.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, virtualization@lists.linux.dev, bcm-kernel-feedback-list@broadcom.com, stable@vger.kernel.org, Vishal Annapurve Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Kirill A. Shutemov" CONFIG_PARAVIRT_XXL is mainly defined/used by XEN PV guests. For other VM guest types, features supported under CONFIG_PARAVIRT are self sufficient. CONFIG_PARAVIRT mainly provides support for TLB flush operations and time related operations. For TDX guest as well, paravirt calls under CONFIG_PARVIRT meets most of its requirement except the need of HLT and SAFE_HLT paravirt calls, which is currently defined under CONFIG_PARAVIRT_XXL. Since enabling CONFIG_PARAVIRT_XXL is too bloated for TDX guest like platforms, move HLT and SAFE_HLT paravirt calls under CONFIG_PARAVIRT. Moving HLT and SAFE_HLT paravirt calls are not fatal and should not break any functionality for current users of CONFIG_PARAVIRT. Cc: stable@vger.kernel.org Fixes: bfe6ed0c6727 ("x86/tdx: Add HLT support for TDX guests") Co-developed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Reviewed-by: Juergen Gross Signed-off-by: Vishal Annapurve --- arch/x86/include/asm/irqflags.h | 40 +++++++++++++++------------ arch/x86/include/asm/paravirt.h | 20 +++++++------- arch/x86/include/asm/paravirt_types.h | 3 +- arch/x86/kernel/paravirt.c | 14 ++++++---- 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflag= s.h index cf7fc2b8e3ce..1c2db11a2c3c 100644 --- a/arch/x86/include/asm/irqflags.h +++ b/arch/x86/include/asm/irqflags.h @@ -76,6 +76,28 @@ static __always_inline void native_local_irq_restore(uns= igned long flags) =20 #endif =20 +#ifndef CONFIG_PARAVIRT +#ifndef __ASSEMBLY__ +/* + * Used in the idle loop; sti takes one instruction cycle + * to complete: + */ +static __always_inline void arch_safe_halt(void) +{ + native_safe_halt(); +} + +/* + * Used when interrupts are already enabled or to + * shutdown the processor: + */ +static __always_inline void halt(void) +{ + native_halt(); +} +#endif /* __ASSEMBLY__ */ +#endif /* CONFIG_PARAVIRT */ + #ifdef CONFIG_PARAVIRT_XXL #include #else @@ -97,24 +119,6 @@ static __always_inline void arch_local_irq_enable(void) native_irq_enable(); } =20 -/* - * Used in the idle loop; sti takes one instruction cycle - * to complete: - */ -static __always_inline void arch_safe_halt(void) -{ - native_safe_halt(); -} - -/* - * Used when interrupts are already enabled or to - * shutdown the processor: - */ -static __always_inline void halt(void) -{ - native_halt(); -} - /* * For spinlocks, etc: */ diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravir= t.h index 041aff51eb50..29e7331a0c98 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -107,6 +107,16 @@ static inline void notify_page_enc_status_changed(unsi= gned long pfn, PVOP_VCALL3(mmu.notify_page_enc_status_changed, pfn, npages, enc); } =20 +static __always_inline void arch_safe_halt(void) +{ + PVOP_VCALL0(irq.safe_halt); +} + +static inline void halt(void) +{ + PVOP_VCALL0(irq.halt); +} + #ifdef CONFIG_PARAVIRT_XXL static inline void load_sp0(unsigned long sp0) { @@ -170,16 +180,6 @@ static inline void __write_cr4(unsigned long x) PVOP_VCALL1(cpu.write_cr4, x); } =20 -static __always_inline void arch_safe_halt(void) -{ - PVOP_VCALL0(irq.safe_halt); -} - -static inline void halt(void) -{ - PVOP_VCALL0(irq.halt); -} - static inline u64 paravirt_read_msr(unsigned msr) { return PVOP_CALL1(u64, cpu.read_msr, msr); diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/p= aravirt_types.h index fea56b04f436..abccfccc2e3f 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -120,10 +120,9 @@ struct pv_irq_ops { struct paravirt_callee_save save_fl; struct paravirt_callee_save irq_disable; struct paravirt_callee_save irq_enable; - +#endif void (*safe_halt)(void); void (*halt)(void); -#endif } __no_randomize_layout; =20 struct pv_mmu_ops { diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 1ccaa3397a67..c5bb980b8a67 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -110,6 +110,11 @@ int paravirt_disable_iospace(void) return request_resource(&ioport_resource, &reserve_ioports); } =20 +static noinstr void pv_native_safe_halt(void) +{ + native_safe_halt(); +} + #ifdef CONFIG_PARAVIRT_XXL static noinstr void pv_native_write_cr2(unsigned long val) { @@ -125,11 +130,6 @@ static noinstr void pv_native_set_debugreg(int regno, = unsigned long val) { native_set_debugreg(regno, val); } - -static noinstr void pv_native_safe_halt(void) -{ - native_safe_halt(); -} #endif =20 struct pv_info pv_info =3D { @@ -186,9 +186,11 @@ struct paravirt_patch_template pv_ops =3D { .irq.save_fl =3D __PV_IS_CALLEE_SAVE(pv_native_save_fl), .irq.irq_disable =3D __PV_IS_CALLEE_SAVE(pv_native_irq_disable), .irq.irq_enable =3D __PV_IS_CALLEE_SAVE(pv_native_irq_enable), +#endif /* CONFIG_PARAVIRT_XXL */ + + /* Irq HLT ops. */ .irq.safe_halt =3D pv_native_safe_halt, .irq.halt =3D native_halt, -#endif /* CONFIG_PARAVIRT_XXL */ =20 /* Mmu ops. */ .mmu.flush_tlb_user =3D native_flush_tlb_local, --=20 2.48.1.711.g2feabab25a-goog