From nobody Thu Dec 26 10:43:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1732187591; cv=none; d=zohomail.com; s=zohoarc; b=kVgeJR8wr34LDvFe/nSppp6kPyrcSyIf2RIMXyTj0z8b6MnZF5E3DDDDKBdstIay+PFh6e4lDX8WywHdJNf4KuY7qZZ03CUUxDdjc2hQB6ZLVF5d+8aROaeAFXYadxt5wMwdM45gIJiy0PV+FxaGA1n89lR5A9+ObOfg1vgU2l4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732187591; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tfW8sK5CwWflaMl6LKuOhOmD5Yp50rt2vxii7w2V5/s=; b=ihVilEqSetNXYlkyVdZeUiBTOixa244w9X09ztLoqLd0iZdsep0Vc4Wqvc79b+iHDwIieAMWryibJVd4eWvEGE1uezHo7MPQI1qDy40iFQrvtbnUtQvZfOTSNxU+6dt1UEg/XoxUCkYq82nkX8tf4jcZ7uj/Q1CDIK8EIrX+zzA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1732187591470228.94243577621125; Thu, 21 Nov 2024 03:13:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.841365.1256849 (Exim 4.92) (envelope-from ) id 1tE57E-0003Vw-3M; Thu, 21 Nov 2024 11:12:52 +0000 Received: by outflank-mailman (output) from mailman id 841365.1256849; Thu, 21 Nov 2024 11:12:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tE57E-0003Vp-0O; Thu, 21 Nov 2024 11:12:52 +0000 Received: by outflank-mailman (input) for mailman id 841365; Thu, 21 Nov 2024 11:12:50 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tE57C-0003Vj-1i for xen-devel@lists.xenproject.org; Thu, 21 Nov 2024 11:12:50 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 895967f3-a7f9-11ef-99a3-01e77a169b0f; Thu, 21 Nov 2024 12:12:46 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a9a0ef5179dso143634766b.1 for ; Thu, 21 Nov 2024 03:12:46 -0800 (PST) Received: from localhost ([213.195.123.63]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa4f4152b6dsm68468266b.7.2024.11.21.03.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 03:12:45 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 895967f3-a7f9-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzMiLCJoZWxvIjoibWFpbC1lajEteDYzMy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6Ijg5NTk2N2YzLWE3ZjktMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyMTg3NTY2LjY4ODI1Niwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1732187566; x=1732792366; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tfW8sK5CwWflaMl6LKuOhOmD5Yp50rt2vxii7w2V5/s=; b=LyIzyMUXPNryhXfA9HK5pJeZ9WH62VUaOYi6PzCWVK+2KvlEhKrHcwufWnUwhgnOAp xFApZhvcH7ufSD9JrsG+YFBRV7xA7L154XRuNX/ydgv1NKVeWzeO72ALoKDdCFLCAKuS +WicH/FkU2iFlnp1WJSJV/e4C9LzfD0sfkshU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732187566; x=1732792366; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tfW8sK5CwWflaMl6LKuOhOmD5Yp50rt2vxii7w2V5/s=; b=D161E69t2SfJnaNHe+4I77XL8GcHVQcmna0vS78qOOz67XBDeLpo1VQSiFKy9kPMwq HTcNRCpoyTieUw7AhGjMla7C6mxCiWf6K+ZBawljWndF4M42xREzD522fvZ3/vb3kK9O 7bqTuoPEFGg+X4dbTzXu4hgx0BT3zyQAxI3qbg9XcJtw9Oj4Qm8su7dD6hsVJv28hTHf 9KDtAv01VfgmyRQQb+LDyYHtsbINk2/Ao+SCC6T5TPokl0e3+sn+wIDUCjR5w/1D1oH7 7zacdzfdOgDEaPdRH87g9VFX2CoRqCNg4FVNsUnI8PMvij2WSf6aG0+JlbyRAnLfGyf8 CUZA== X-Gm-Message-State: AOJu0Yw/FtfFBjSJRTr1PRNHX5NlEeioOP8xO9mjNXLr5JswKN6m+DFk MLJeihe/oFF1qqgSNlEv/J0thZv2PswuJBOG67C8IFNFX9S034X40tNT4PoeLhQm4t74iJErimR n X-Gm-Gg: ASbGncujHJ5qGQ5GoVTzJ+Je0dK76FIRQCV3MszmUkDN7tW6lD4IapgNPvuAN2yhncl X32Y0GCYh3GXuFtCkEitekCpY1vQN8KWpcX5xFyGHNzpcOSQWItG8FwIjbttOQNV0hHAVF3qVHT FLc1Uqou+eupiJILR4s6x9SoI0lcdoqMmvAMcK0HZCH8aQtRzbUxxYwNzns2v7sPMSoi7/83ad6 w4ZWSHPvktiQBxYxLkp3H4LDTLzuojbgtGMRgIeTmVWPTBIvWxC/ur7wkY= X-Google-Smtp-Source: AGHT+IHRF2CXIiAi+N3StihUf8aAGLidqvRRyY5TSCgv/k5EI2l7sqT6fWhj+z6oIsvRZ6wA5qyPkw== X-Received: by 2002:a17:907:2cc2:b0:a9a:bbcd:e63 with SMTP id a640c23a62f3a-aa4dd54842cmr620018666b.14.1732187565771; Thu, 21 Nov 2024 03:12:45 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH] x86/pv: limit GDT and LDT mappings areas to max number of vCPUs Date: Thu, 21 Nov 2024 12:12:18 +0100 Message-ID: <20241121111218.50984-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1732187592754116600 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 c= an have. The maximum number of vCPUs is available at domain creation since co= mmit 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 le= ss than 16 vCPUs only 2 pages are used (each guest vCPU GDT/LDT can only consu= me 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=C3=A9 Reviewed-by: Jan Beulich --- 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); =20 destroy_perdomain_mapping(d, GDT_LDT_VIRT_START, - GDT_LDT_MBYTES << (20 - PAGE_SHIFT)); + d->max_vcpus << GDT_LDT_VCPU_SHIFT); =20 XFREE(d->arch.pv.cpuidmasks); =20 @@ -377,7 +377,7 @@ int pv_domain_initialise(struct domain *d) goto fail; =20 rc =3D 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; --=20 2.46.0