All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/pv: limit GDT and LDT mappings areas to max number of vCPUs
@ 2024-11-21 11:12 Roger Pau Monne
  2024-11-21 11:26 ` Andrew Cooper
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Roger Pau Monne @ 2024-11-21 11:12 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Jan Beulich, Andrew Cooper

The allocation of the paging structures in the per-domain area for mapping the
guest GDT and LDT can be limited to the maximum number of vCPUs the guest can
have.  The maximum number of vCPUs is available at domain creation since commit
4737fa52ce86.

Limiting to the actual number of vCPUs avoids wasting memory for paging
structures that will never be used.  Current logic unconditionally uses 513
pages, one page for the L3, plus 512 L1 pages.  For guests with equal or less
than 16 vCPUs only 2 pages are used (each guest vCPU GDT/LDT can only consume
32 L1 slots).

No functional change intended, all possible domain vCPUs should have the GDT
and LDT paging structures allocated and setup at domain creation, just like
before the change.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/pv/domain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index d5a8564c1cbe..e861e3ce71d9 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -346,7 +346,7 @@ void pv_domain_destroy(struct domain *d)
     pv_l1tf_domain_destroy(d);
 
     destroy_perdomain_mapping(d, GDT_LDT_VIRT_START,
-                              GDT_LDT_MBYTES << (20 - PAGE_SHIFT));
+                              d->max_vcpus << GDT_LDT_VCPU_SHIFT);
 
     XFREE(d->arch.pv.cpuidmasks);
 
@@ -377,7 +377,7 @@ int pv_domain_initialise(struct domain *d)
         goto fail;
 
     rc = create_perdomain_mapping(d, GDT_LDT_VIRT_START,
-                                  GDT_LDT_MBYTES << (20 - PAGE_SHIFT),
+                                  d->max_vcpus << GDT_LDT_VCPU_SHIFT,
                                   NULL, NULL);
     if ( rc )
         goto fail;
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-11-21 17:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-21 11:12 [PATCH] x86/pv: limit GDT and LDT mappings areas to max number of vCPUs Roger Pau Monne
2024-11-21 11:26 ` Andrew Cooper
2024-11-21 11:39   ` Roger Pau Monné
2024-11-21 11:32 ` Jan Beulich
2024-11-21 15:56 ` Roger Pau Monné
2024-11-21 16:03   ` Jan Beulich
2024-11-21 17:11     ` Roger Pau Monné

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.