From nobody Thu Nov 21 12:20:31 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=1731596319; cv=none; d=zohomail.com; s=zohoarc; b=gFIloZ1GKZTE0LOXNfRxGtwICQz01JZCBGo+oziFmsWP2oQbRzM7Y8k+0msivSa7S/5jTvvvgn6XtAllD0E/n4YSBW4CkPcTwUexy0ititN0m/049pjsZZRm/6+QD3XllySPoWZQB5nr3rhnwD5mhTPbStQDuLDKeHjSS1zL9M8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731596319; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wfQMcfiQzj+ufcVDBKz5TVkZtEEiPvugKRbHnXB/lrQ=; b=DCBaba2UmVcsQPw9YqGT4qcSpDN/kqZkG/OjMbYtWJ2jznJDS+3YtO0LBbDiUqxjCVTHWs8dOn0Sd9Y0s/xLNoJcSUTW3s7AdEgT9ij08ooSUgTI0Yk+/cnzVaLfeiJEnvVzemVnnlbrT3VsQ3NJiYExt94ItrES1DWT5mj3qLo= 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 1731596319650131.0162547885974; Thu, 14 Nov 2024 06:58:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.836525.1252421 (Exim 4.92) (envelope-from ) id 1tBbIY-0007Ng-U0; Thu, 14 Nov 2024 14:58:18 +0000 Received: by outflank-mailman (output) from mailman id 836525.1252421; Thu, 14 Nov 2024 14:58:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBbIY-0007NU-QE; Thu, 14 Nov 2024 14:58:18 +0000 Received: by outflank-mailman (input) for mailman id 836525; Thu, 14 Nov 2024 14:58:17 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBbIX-0007K7-3l for xen-devel@lists.xenproject.org; Thu, 14 Nov 2024 14:58:17 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dfa8dea0-a298-11ef-a0c7-8be0dac302b0; Thu, 14 Nov 2024 15:58:14 +0100 (CET) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5cf872ecce7so259578a12.1 for ; Thu, 14 Nov 2024 06:58:14 -0800 (PST) Received: from localhost ([213.195.123.63]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e08128csm70554166b.175.2024.11.14.06.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:58:12 -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: dfa8dea0-a298-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmMiLCJoZWxvIjoibWFpbC1lZDEteDUyYy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImRmYThkZWEwLWEyOTgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNTk2Mjk0LjQ1MjI3MSwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731596293; x=1732201093; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wfQMcfiQzj+ufcVDBKz5TVkZtEEiPvugKRbHnXB/lrQ=; b=FzGlNjucZDjpw0AijRclFEIT7DSg7BRDzJ/BochpDLQVK7W08SNHm+9rmOnfbGqssm hg0og/CvK9ew/TevL/mVK/ffmttwP4Sp3bhbpwo3FR8/1KiHNLg+YxQiRjlhlzhV7VBd dQEKE28UM4lzkxMuF6EQVZuIGlZwNuEj9yCnA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731596293; x=1732201093; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wfQMcfiQzj+ufcVDBKz5TVkZtEEiPvugKRbHnXB/lrQ=; b=cksGIP6DfYYo49iOtnYd6afpzUoIR7IyIApaaJsHyw46B/a0rwdEZNDyR1EFEeXbze uEhNluAsNUK88eDZ7ELI1PPyQsU/kiknlgMDuJ+ezpv8w078egGQj9dAw/j+QiPrOx1P ZGkW/En8Yp0qbpZ/7/GyStxCJT6Xu1ttk1el32w5jD85LTVt0vi8+MSdsBoWVFn/y2jf vg3DEC9NAEskLq4Mlb0piv7gzjmjE/4v4aoqkXOWs1tIXcatv9ysVUX1WofkQ3xxFm5x u4IRsLUwhGLf6GYlAoUvOhlzSDRtvChq0eAxjklluidxWEU/WBjlMBVQ30gIrsHN4WD9 SyPg== X-Gm-Message-State: AOJu0YzzMIX2xD3waLRIoQVo6wc0olT/PdbrKnqzHloqd8EP7kb+YNqw v5kNzh8UnZ/ovRXN7/wDS3eNsrMRvQdUeXC0ZvJZKrYTtTaUkPSeN2xbiw8ySbM/LbXV2qTKomy 1 X-Google-Smtp-Source: AGHT+IE0ZQ6RvAcMJ6lX5tXnowlkxGMbF/MoZJdwPsvl+DQl93dO5jjfxqCZnfnU6zmcnaQjskVLqg== X-Received: by 2002:a17:907:72c8:b0:a9a:1739:91e9 with SMTP id a640c23a62f3a-a9eefeebe72mr2495033866b.24.1731596293067; Thu, 14 Nov 2024 06:58:13 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v3 1/4] x86/mm: introduce helpers to detect super page alignment Date: Thu, 14 Nov 2024 15:57:12 +0100 Message-ID: <20241114145715.59777-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241114145715.59777-1-roger.pau@citrix.com> References: <20241114145715.59777-1-roger.pau@citrix.com> 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: 1731596322019116600 Split the code that detects whether the physical and linear address of a mapping request are suitable to be used in an L3 or L2 slot. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v2: - Fix parenthesization of macro parameter. - Add another usage of IS_L2E_ALIGNED(). Changes since v1: - Make the macros local to map_pages_to_xen(). - Some adjustments to macro logic. --- xen/arch/x86/mm.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 11933321a3d5..ebb50a7836ac 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5493,6 +5493,13 @@ int map_pages_to_xen( } \ } while (0) =20 +/* Check if a (virt, mfn) tuple is aligned for a given slot level. */ +#define IS_LnE_ALIGNED(v, m, n) \ + IS_ALIGNED(PFN_DOWN(v) | mfn_x(m), \ + (1UL << (PAGETABLE_ORDER * ((n) - 1))) - 1) +#define IS_L2E_ALIGNED(v, m) IS_LnE_ALIGNED(v, m, 2) +#define IS_L3E_ALIGNED(v, m) IS_LnE_ALIGNED(v, m, 3) + L3T_INIT(current_l3page); =20 while ( nr_mfns !=3D 0 ) @@ -5510,9 +5517,7 @@ int map_pages_to_xen( L3T_LOCK(current_l3page); ol3e =3D *pl3e; =20 - if ( cpu_has_page1gb && - !(((virt >> PAGE_SHIFT) | mfn_x(mfn)) & - ((1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1)) && + if ( cpu_has_page1gb && IS_L3E_ALIGNED(virt, mfn) && nr_mfns >=3D (1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) && !(flags & (_PAGE_PAT | MAP_SMALL_PAGES)) ) { @@ -5631,8 +5636,7 @@ int map_pages_to_xen( if ( !pl2e ) goto out; =20 - if ( ((((virt >> PAGE_SHIFT) | mfn_x(mfn)) & - ((1u << PAGETABLE_ORDER) - 1)) =3D=3D 0) && + if ( IS_L2E_ALIGNED(virt, mfn) && (nr_mfns >=3D (1u << PAGETABLE_ORDER)) && !(flags & (_PAGE_PAT|MAP_SMALL_PAGES)) ) { @@ -5749,9 +5753,7 @@ int map_pages_to_xen( nr_mfns -=3D 1UL; =20 if ( (flags =3D=3D PAGE_HYPERVISOR) && - ((nr_mfns =3D=3D 0) || - ((((virt >> PAGE_SHIFT) | mfn_x(mfn)) & - ((1u << PAGETABLE_ORDER) - 1)) =3D=3D 0)) ) + ((nr_mfns =3D=3D 0) || IS_L2E_ALIGNED(virt, mfn)) ) { unsigned long base_mfn; const l1_pgentry_t *l1t; @@ -5802,9 +5804,7 @@ int map_pages_to_xen( check_l3: if ( cpu_has_page1gb && (flags =3D=3D PAGE_HYPERVISOR) && - ((nr_mfns =3D=3D 0) || - !(((virt >> PAGE_SHIFT) | mfn_x(mfn)) & - ((1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1))) ) + ((nr_mfns =3D=3D 0) || IS_L3E_ALIGNED(virt, mfn)) ) { unsigned long base_mfn; const l2_pgentry_t *l2t; @@ -5848,6 +5848,9 @@ int map_pages_to_xen( } } =20 +#undef IS_L3E_ALIGNED +#undef IS_L2E_ALIGNED +#undef IS_LnE_ALIGNED #undef flush_flags =20 rc =3D 0; --=20 2.46.0 From nobody Thu Nov 21 12:20:31 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=1731596327; cv=none; d=zohomail.com; s=zohoarc; b=a8EvA0uHSEv6IZ335zfyNI5KiLFVEL6ihDsFzU3MMbzleRVYGpFXntL9kBCsOV/VWxGNBd+a9dQsfGjsT/s1lNfMk7c7VOJzEGaPhozrQUKpGgTuk9xxWR8x0ia5C3BlvYn962RqE03LlT9/oGV97S7HxIizoqr1VCzNlQD8vEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731596327; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s0to/rSIeQG19u7kDm67YYj3X5UuL0xhfI5HLy/Vz4M=; b=Ny4nIH7XLvQSHxhcQWDQ9+MsYBaD83qbXjKd38WlVuvXWqUDhYhZruD8Xnq7k3Ow/jHIHvPjCYxF21avulyU0SKZOL2e9d+rzH5ksnCwKaMZIFF5hwvGmSbacpIO9qxM5E6wH+/kqNvic+Env1B2nDVwyOIO5DRvOHDJg6QAFKU= 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 17315963270615.020022420940677; Thu, 14 Nov 2024 06:58:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.836526.1252428 (Exim 4.92) (envelope-from ) id 1tBbIZ-0007Ue-9J; Thu, 14 Nov 2024 14:58:19 +0000 Received: by outflank-mailman (output) from mailman id 836526.1252428; Thu, 14 Nov 2024 14:58:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBbIZ-0007T6-2I; Thu, 14 Nov 2024 14:58:19 +0000 Received: by outflank-mailman (input) for mailman id 836526; Thu, 14 Nov 2024 14:58:17 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBbIX-0007K7-P5 for xen-devel@lists.xenproject.org; Thu, 14 Nov 2024 14:58:17 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e034466f-a298-11ef-a0c7-8be0dac302b0; Thu, 14 Nov 2024 15:58:15 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a9f1c590ecdso114203266b.1 for ; Thu, 14 Nov 2024 06:58:15 -0800 (PST) Received: from localhost ([213.195.123.63]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e043b84sm70827666b.137.2024.11.14.06.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:58:13 -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: e034466f-a298-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MmYiLCJoZWxvIjoibWFpbC1lajEteDYyZi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImUwMzQ0NjZmLWEyOTgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNTk2Mjk1LjM2Mzg3LCJzZW5kZXIiOiJyb2dlci5wYXVAY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731596294; x=1732201094; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s0to/rSIeQG19u7kDm67YYj3X5UuL0xhfI5HLy/Vz4M=; b=TMuMJdOdC24ZHi+Zeo0nuMzuMGbJ+69aD1o8CQJm5a2J0IcGUjO4piZC8vR5d2VYAN Tc5HT1XWBTSGzey876OnJenpp493/yNnR9hqoswQfFPkUsRlVxwE6oXCcREpE8trIPH0 JQ22f0oTT5sVPFORlAp7/EVxN8d8ZG9XtJsZo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731596294; x=1732201094; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s0to/rSIeQG19u7kDm67YYj3X5UuL0xhfI5HLy/Vz4M=; b=U9+ThsGfCBM89s0a50q720IQf7B4aPmkLRk/paLEC/WG++vAFBGowb+t79XbK8CZVp PPM+ym/msWM2u2jOiTJ7VHXnPRAbResGVFvamxVBoWtAQ6O4K/umVNCCebojHn01MOSg blte40vi2KS/wW0yLBnLzh19y+HfVWIBGoPGfaUg//XTIjjU7e87wEyqPxCr6xXQHWzi C++vZtH/VLAgeo2l2UmpcyrxzKKq2uPR0yyr4t9CkkqrZfwyCoE3LZR9wAQhkuKZ0uU3 MDRO2kN3K7fdFzHYRL6ttEwguc/b/9v7nW2OpCSefFKCVx5O9KRwVpmx0xlIi7fHmCEW Dn9g== X-Gm-Message-State: AOJu0Yw+r3v6AcRCLVY7pVX21fL8/bPiLjhDLMeDeDnc7st2I3QhLtML /k5m4fHXWkN9WW5uaTzGtXTspUK9F3AAsSFsrZBGQY4VflO1f7+lRt+89xlbRk1Fw55BQNARf3c 3 X-Google-Smtp-Source: AGHT+IGKKQHAG7a56T4kdnuzwe2XbLvwv4+S+QVF2rSjaUcvZ4lKxDXe7Zjdq7m8cVYXZqj3UQW8Jw== X-Received: by 2002:a17:907:3e99:b0:a9a:e6:a031 with SMTP id a640c23a62f3a-aa1f813e6edmr719623766b.59.1731596294423; Thu, 14 Nov 2024 06:58:14 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v3 2/4] x86/mm: skip super-page alignment checks for non-present entries Date: Thu, 14 Nov 2024 15:57:13 +0100 Message-ID: <20241114145715.59777-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241114145715.59777-1-roger.pau@citrix.com> References: <20241114145715.59777-1-roger.pau@citrix.com> 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: 1731596327878116600 INVALID_MFN is ~0, so by it having all bits as 1s it doesn't fulfill the super-page address alignment checks for L3 and L2 entries. Skip the alignm= ent checks if the new entry is a non-present one. This fixes a regression introduced by 0b6b51a69f4d, where the switch from 0= to INVALID_MFN caused all super-pages to be shattered when attempting to remove mappings by passing INVALID_MFN instead of 0. Fixes: 0b6b51a69f4d ('xen/mm: Switch map_pages_to_xen to use MFN typesafe') Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changees since v2: - Remove unneeded page present check. Changes since v1: - Detect non-present entries from the flags contents rather than checking = the mfn parameter. --- xen/arch/x86/mm.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index ebb50a7836ac..b9a2234b53e1 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5493,10 +5493,17 @@ int map_pages_to_xen( } \ } while (0) =20 -/* Check if a (virt, mfn) tuple is aligned for a given slot level. */ -#define IS_LnE_ALIGNED(v, m, n) \ - IS_ALIGNED(PFN_DOWN(v) | mfn_x(m), \ - (1UL << (PAGETABLE_ORDER * ((n) - 1))) - 1) +/* + * Check if a (virt, mfn) tuple is aligned for a given slot level. m must = not + * be INVALID_MFN, since alignment is only relevant for present entries. + */ +#define IS_LnE_ALIGNED(v, m, n) ({ \ + mfn_t m_ =3D m; \ + \ + ASSERT(!mfn_eq(m_, INVALID_MFN)); \ + IS_ALIGNED(PFN_DOWN(v) | mfn_x(m_), \ + (1UL << (PAGETABLE_ORDER * ((n) - 1))) - 1); \ +}) #define IS_L2E_ALIGNED(v, m) IS_LnE_ALIGNED(v, m, 2) #define IS_L3E_ALIGNED(v, m) IS_LnE_ALIGNED(v, m, 3) =20 @@ -5517,7 +5524,8 @@ int map_pages_to_xen( L3T_LOCK(current_l3page); ol3e =3D *pl3e; =20 - if ( cpu_has_page1gb && IS_L3E_ALIGNED(virt, mfn) && + if ( cpu_has_page1gb && + (!(flags & _PAGE_PRESENT) || IS_L3E_ALIGNED(virt, mfn)) && nr_mfns >=3D (1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) && !(flags & (_PAGE_PAT | MAP_SMALL_PAGES)) ) { @@ -5636,7 +5644,7 @@ int map_pages_to_xen( if ( !pl2e ) goto out; =20 - if ( IS_L2E_ALIGNED(virt, mfn) && + if ( (!(flags & _PAGE_PRESENT) || IS_L2E_ALIGNED(virt, mfn)) && (nr_mfns >=3D (1u << PAGETABLE_ORDER)) && !(flags & (_PAGE_PAT|MAP_SMALL_PAGES)) ) { --=20 2.46.0 From nobody Thu Nov 21 12:20:31 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=1731596323; cv=none; d=zohomail.com; s=zohoarc; b=fuCbRFWcMaQXiW36L0Xruv1Rh3p+aTd3Cs2b+RvANX0Se12Zku6TCEaaYOkRpzdTemWk7eMxRL826tmyjgq8aD4v+g0k/NJJe8EI6eElgallrRC5pJv2aSKSI1SwUIqDj4hZLC8blNuEU2u9IK5Ph6d43ublc8YQNwNhXqAB2r0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731596323; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tXR4cctauxXAgvzXe72aJg/wf4uD+JeIO0+1UeL6XbI=; b=RNyU5q9+UX3NpaX8IcXlaznD3FDvpizgSL8f2dT8q+ZfckLg0J62V0gvJFHdeZ82aHiCxV6K5MpDCZZGrTI2I8XFW7JxwTjNq4v5N24km9exElqXScUKzOcahIIceHMRrN7Nw22k2V09tpc/xVkO7/3DgjHv7uF0Uyqvd5fg/1Q= 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 1731596323234308.6200096478076; Thu, 14 Nov 2024 06:58:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.836527.1252447 (Exim 4.92) (envelope-from ) id 1tBbIa-00080w-G0; Thu, 14 Nov 2024 14:58:20 +0000 Received: by outflank-mailman (output) from mailman id 836527.1252447; Thu, 14 Nov 2024 14:58:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBbIa-00080i-Ap; Thu, 14 Nov 2024 14:58:20 +0000 Received: by outflank-mailman (input) for mailman id 836527; Thu, 14 Nov 2024 14:58:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBbIZ-0007K7-PK for xen-devel@lists.xenproject.org; Thu, 14 Nov 2024 14:58:19 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e0ecac41-a298-11ef-a0c7-8be0dac302b0; Thu, 14 Nov 2024 15:58:16 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-aa20944ce8cso158622466b.0 for ; Thu, 14 Nov 2024 06:58:16 -0800 (PST) Received: from localhost ([213.195.123.63]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e08617esm71581366b.182.2024.11.14.06.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:58:15 -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: e0ecac41-a298-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzQiLCJoZWxvIjoibWFpbC1lajEteDYzNC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImUwZWNhYzQxLWEyOTgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNTk2Mjk2LjU5ODI0Niwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731596296; x=1732201096; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tXR4cctauxXAgvzXe72aJg/wf4uD+JeIO0+1UeL6XbI=; b=uF09amAJXlqVYrgoAWLuUBYzKfcIc45iT0ezUuDADzGua0wyqEdMZkOKb/ABIUl8kc jAJmMVOTHB+fJk/urct8yo9tEcxNamIwXYBXTcHSECNeNB89KfbdhuNHnqnRrJGOdxci Mgvf0381fXjpVvVjvX6GMWCSNLK7cMciAcZAY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731596296; x=1732201096; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tXR4cctauxXAgvzXe72aJg/wf4uD+JeIO0+1UeL6XbI=; b=tBsijn9hFeZraqfDFQf9GpjZlyzR6Yiy21YqHsOpJ7eVsFmIiweeBvufXucr8dknth TrD4Svsg5n7YTJPHjRFtLB3/OH9d5jNH0NL+I5EipUs81whdEnJ0DGJ7N/nYZcjQxLLO oImT/wY7nz0vqp0UFBuDPRWnLMcT812/os/SxsuLN1OEfISE4Sbh4zN/yMvVFrpQbDdj N/sh3nQQOkorjXgQana4AB34Ekou0kZgS42Szw5FRU2zl1c7QctpvtsxK2v0jKiYPmjY iKyfbl+CT0HXJOnsM37I9J7E0lp3ybOTglpMGhYDmzrNAhQQhKkGPN6oSp24Af1fgR26 PWKQ== X-Gm-Message-State: AOJu0YyhhazsqtuHJLngsDLpwAMAJDeQGWFSRqwxo6sVvCEKbB3Fz0VE V9doXqQ5kU8nc6FQ3Rr87I7rvkkxBp5aHaBxw3BbRsDQ+iPF37cjk9t0bOtZfTK/p3iCtobW288 0 X-Google-Smtp-Source: AGHT+IELVxnRGrnCdIZBOFpbty878I4Sr+GUKmoDscJGaVSHTdvBbe+YWejESTrHfW/xUoW/c+B2XA== X-Received: by 2002:a17:907:1ca2:b0:a9a:cea7:1294 with SMTP id a640c23a62f3a-aa2077daa13mr300791866b.21.1731596295726; Thu, 14 Nov 2024 06:58:15 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 3/4] x86/setup: remove bootstrap_map_addr() usage of destroy_xen_mappings() Date: Thu, 14 Nov 2024 15:57:14 +0100 Message-ID: <20241114145715.59777-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241114145715.59777-1-roger.pau@citrix.com> References: <20241114145715.59777-1-roger.pau@citrix.com> 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: 1731596323691116600 bootstrap_map_addr() needs to be careful to not remove existing page-table structures when tearing down mappings, as such pagetable structures might be needed to fulfill subsequent mappings requests. The comment ahead of the function already notes that pagetable memory shouldn't be allocated. Fix this by using map_pages_to_xen(), which does zap the page-table entries, but does not free page-table structures even when empty. Fixes: 4376c05c3113 ('x86-64: use 1GB pages in 1:1 mapping if available') Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v1: - Adjust commit message. --- xen/arch/x86/setup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 4feef9f2e05a..5da1c6a34519 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -462,7 +462,9 @@ static void *__init bootstrap_map_addr(paddr_t start, p= addr_t end) =20 if ( !end ) { - destroy_xen_mappings(BOOTSTRAP_MAP_BASE, BOOTSTRAP_MAP_LIMIT); + map_pages_to_xen(BOOTSTRAP_MAP_BASE, INVALID_MFN, + PFN_DOWN(map_cur - BOOTSTRAP_MAP_BASE), + _PAGE_NONE); map_cur =3D BOOTSTRAP_MAP_BASE; return NULL; } --=20 2.46.0 From nobody Thu Nov 21 12:20:31 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=1731596329; cv=none; d=zohomail.com; s=zohoarc; b=hdgRjR4n9Oq/LU0wEOk+SkhiR0vJ1MCUf5B5xqYnmeuu0hMSyEbjnOQ6/pkLh11RAHGZyH5OipO1u0WvFc8r803LxB18FY3N2NRY2ON0YEUj6U+f/B2ySiOKWwp9I2tB+IOOWRer7uIEJs//dE1q69qDooJK+1hgIxCOlT2Yo44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731596329; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cfpsHIVO6Ujko5JTUzFKmfq4KuJWIJOR8vcz6fn/jLQ=; b=IeCM0qcjH3aiNuFqDvti3lh+iANv5AfqI6FMnYwhH3kkp1SkJ9qCJZ+fLG73ezEFyk1xPlC13edqH/dFezggZGVjS+Lpcb5n9tSHWK0BgmO8nsqv3bq+Sc/Px8Empw2iei7EWvKW1F2ufZAeKW8W87/RbxuBxIiVG+xDeVxFawQ= 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 1731596329960407.00476953198574; Thu, 14 Nov 2024 06:58:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.836528.1252457 (Exim 4.92) (envelope-from ) id 1tBbId-0008Is-Qd; Thu, 14 Nov 2024 14:58:23 +0000 Received: by outflank-mailman (output) from mailman id 836528.1252457; Thu, 14 Nov 2024 14:58:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBbId-0008Il-NN; Thu, 14 Nov 2024 14:58:23 +0000 Received: by outflank-mailman (input) for mailman id 836528; Thu, 14 Nov 2024 14:58:22 +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 1tBbIc-0007K6-K6 for xen-devel@lists.xenproject.org; Thu, 14 Nov 2024 14:58:22 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e1c922a2-a298-11ef-99a3-01e77a169b0f; Thu, 14 Nov 2024 15:58:18 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5ceb75f9631so930257a12.0 for ; Thu, 14 Nov 2024 06:58:18 -0800 (PST) Received: from localhost ([213.195.123.63]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cf79b89d47sm644059a12.16.2024.11.14.06.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:58:16 -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: e1c922a2-a298-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmIiLCJoZWxvIjoibWFpbC1lZDEteDUyYi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImUxYzkyMmEyLWEyOTgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNTk2Mjk4LjAzNTMxNywic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731596297; x=1732201097; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cfpsHIVO6Ujko5JTUzFKmfq4KuJWIJOR8vcz6fn/jLQ=; b=cnqcxds1qtP2pyFMnL1MG8tLPF3qWU7iJ6g/gj8AM6qVeLZKvBKDUDIkOlUI9uL1G6 2Aq//huKlP3fogmcHWI7btFlFAyCShbYS1EsV7lEnspOeVes3zx1/Ja34qlQOuHif9N6 jTQfoFZnCEPgFwTFDPKiu3px3EicagwuFqs4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731596297; x=1732201097; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cfpsHIVO6Ujko5JTUzFKmfq4KuJWIJOR8vcz6fn/jLQ=; b=vNvvkyTYGwp3Kl+7QLv3BN24UCNpmiwnvMhTUz/JzF2feHdI6V1CPrp2a5yiJ15sap vXTaME7IkFit7CPvFyO+8RhPBN+kTO/KWEWHHgXpYYZRyv0HsTjePgOjvHomRF8/Jsag IlpSg6spAmB3vCjfs3eVu65y8yVrW9hF7MkCdRFzBud4wrdM/7k0aBGNMgYNLzP0z7LU UfNOcbD5N0Q1exxt8XR7P+wfbm5Cox7KlEocjyRYmhfU/JmHvnJd2GHhVEYCDuDLNBhK ODbWd4Bgpn8aXRQi6bHs8uFdPVSTgAco1i18ZnFcFvKizumIO5tnNJV4uh2aDQEZx7SF VRYw== X-Gm-Message-State: AOJu0Yzc2gpNAHdymXc/gkOhwL5GnWQ6s5tqcnlJ/jqJlt+T3s4rlwK0 SWQ9uiwqG5PDZYDEqAQC7QMMQTCfq819xB9q5pfbO+z3EazcP7nFkIg4mg1lPUJb68AtSk4A4zJ 4 X-Google-Smtp-Source: AGHT+IGAixFOlUsgApJqtZWaUF0eQhjY3/QjMY1cv8HYc0dJtkEutXuf3diur3jYqzlxSNZQxau3Bw== X-Received: by 2002:a05:6402:2794:b0:5ce:dc4e:57ff with SMTP id 4fb4d7f45d1cf-5cf0a43ee61mr19861825a12.24.1731596297164; Thu, 14 Nov 2024 06:58:17 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v3 4/4] x86/mm: ensure L2 is always freed if empty Date: Thu, 14 Nov 2024 15:57:15 +0100 Message-ID: <20241114145715.59777-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241114145715.59777-1-roger.pau@citrix.com> References: <20241114145715.59777-1-roger.pau@citrix.com> 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: 1731596331691116600 The current logic in modify_xen_mappings() allows for fully empty L2 tables= to not be freed and unhooked from the parent L3 if the last L2 slot is not populated. Ensure that even when an L2 slot is empty the logic to check whether the wh= ole L2 can be removed is not skipped. Fixes: 4376c05c3113 ('x86-64: use 1GB pages in 1:1 mapping if available') Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- xen/arch/x86/mm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index b9a2234b53e1..5d7e8d78718c 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5989,7 +5989,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) =20 v +=3D 1UL << L2_PAGETABLE_SHIFT; v &=3D ~((1UL << L2_PAGETABLE_SHIFT) - 1); - continue; + goto check_l3; } =20 if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) --=20 2.46.0