From patchwork Fri Nov 8 11:31:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13868072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ACBD7D5E15A for ; Fri, 8 Nov 2024 11:32:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.832463.1247767 (Exim 4.92) (envelope-from ) id 1t9NE4-00064D-DM; Fri, 08 Nov 2024 11:32:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 832463.1247767; Fri, 08 Nov 2024 11:32:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t9NE4-00062t-9M; Fri, 08 Nov 2024 11:32:28 +0000 Received: by outflank-mailman (input) for mailman id 832463; Fri, 08 Nov 2024 11:32:27 +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 1t9NE2-00060g-Uw for xen-devel@lists.xenproject.org; Fri, 08 Nov 2024 11:32:26 +0000 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [2a00:1450:4864:20::531]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1fd71f02-9dc5-11ef-a0c6-8be0dac302b0; Fri, 08 Nov 2024 12:32:24 +0100 (CET) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5c9c28c1ecbso2548788a12.0 for ; Fri, 08 Nov 2024 03:32:24 -0800 (PST) Received: from localhost ([213.195.120.105]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0a4bfa1sm222698766b.74.2024.11.08.03.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 03:32:23 -0800 (PST) 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: 1fd71f02-9dc5-11ef-a0c6-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzEiLCJoZWxvIjoibWFpbC1lZDEteDUzMS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjFmZDcxZjAyLTlkYzUtMTFlZi1hMGM2LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxMDY1NTQ0LjQxNDI2OCwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731065543; x=1731670343; 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=QHfkhGUnT0xwCTLoRSPpeRbYmiIBgZ+v2c3CutALv3Q=; b=UGTfdHE+y6FJAYVUvdPy3bo0pnT7YQKiXvMCF/ptT3A9bl6cIxqmYI7o9oF5dfrPuz akhkwWqLUI4B7ThsevRCB/2u/aaSchE4vTdP069Lw4jXulbbW9X7e50bJtkx+a/cMW8P Dyf0i4WL+KjOoZaBVd0istTnSghe8VYd1eY98= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731065543; x=1731670343; 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=QHfkhGUnT0xwCTLoRSPpeRbYmiIBgZ+v2c3CutALv3Q=; b=m09SLWVKgye77AmfzFt9KgJQCegwCbewLUkoQjEb9H29SvjrT5alSeKo+4J1pPpE7F YmPgCthqZGoxeqxSL3VAqzNp9BB7elca06kPoLLBuMuCAch1GcIT4CYA0AXLkCs443vL CINI+nQ6+XiZ+TnJIuPybeZT5fpJV4b92bTz6+EhapBhqFVF9CQSIm+0U/2mULj0o3vQ Lgiemx7kA9QNwSPCgNBK9QCKBk91Lv0IuNbIV9jYPdUw3wO7zhXBsfY7jrvjfkgypUJh mkOrcKqWD6wXrIX0z4MPzxS0aKJRm1LC0QoSGG6cNXG+YW7fTA4Sre0qXhdy1me/BPuK FwWQ== X-Gm-Message-State: AOJu0YxLShpIEdOf4Ko1i1zzX4ReKZ1Luv5uDohCzlpLSqNCas7Hn2hc rVdXeUBdLHgEJLqV0sb4xVVzNCZvpNHJxudOlFBLGgYrAtPFPetxKOJYz/owO5AKeAcIV9DgRms A X-Google-Smtp-Source: AGHT+IHnGJLyrRZSvRtHSPlxNz38lSDP7tcz1Xe4EjKzGuTjisPpZiSaE51Jm9bXOiyEGBdeNYKQTQ== X-Received: by 2002:a17:907:3e9e:b0:a9a:8674:1739 with SMTP id a640c23a62f3a-a9ef0008cf0mr189975466b.53.1731065543284; Fri, 08 Nov 2024 03:32:23 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 1/4] x86/mm: introduce helpers to detect super page alignment Date: Fri, 8 Nov 2024 12:31:41 +0100 Message-ID: <20241108113144.83637-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108113144.83637-1-roger.pau@citrix.com> References: <20241108113144.83637-1-roger.pau@citrix.com> MIME-Version: 1.0 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é Reviewed-by: Jan Beulich --- Changes since v1: - Make the macros local to map_pages_to_xen(). - Some adjustments to macro logic. --- xen/arch/x86/mm.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index d537a799bced..8afb63c855b9 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5232,6 +5232,12 @@ int map_pages_to_xen( } \ } while (0) +/* 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); while ( nr_mfns != 0 ) @@ -5249,9 +5255,7 @@ int map_pages_to_xen( L3T_LOCK(current_l3page); ol3e = *pl3e; - 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 >= (1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) && !(flags & (_PAGE_PAT | MAP_SMALL_PAGES)) ) { @@ -5370,8 +5374,7 @@ int map_pages_to_xen( if ( !pl2e ) goto out; - if ( ((((virt >> PAGE_SHIFT) | mfn_x(mfn)) & - ((1u << PAGETABLE_ORDER) - 1)) == 0) && + if ( IS_L2E_ALIGNED(virt, mfn) && (nr_mfns >= (1u << PAGETABLE_ORDER)) && !(flags & (_PAGE_PAT|MAP_SMALL_PAGES)) ) { @@ -5541,9 +5544,7 @@ int map_pages_to_xen( check_l3: if ( cpu_has_page1gb && (flags == PAGE_HYPERVISOR) && - ((nr_mfns == 0) || - !(((virt >> PAGE_SHIFT) | mfn_x(mfn)) & - ((1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1))) ) + ((nr_mfns == 0) || IS_L3E_ALIGNED(virt, mfn)) ) { unsigned long base_mfn; const l2_pgentry_t *l2t; @@ -5587,6 +5588,9 @@ int map_pages_to_xen( } } +#undef IS_L3E_ALIGNED +#undef IS_L2E_ALIGNED +#undef IS_LnE_ALIGNED #undef flush_flags rc = 0; From patchwork Fri Nov 8 11:31:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13868068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F4095D5E12F for ; Fri, 8 Nov 2024 11:32:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.832464.1247783 (Exim 4.92) (envelope-from ) id 1t9NE5-0006T9-NB; Fri, 08 Nov 2024 11:32:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 832464.1247783; Fri, 08 Nov 2024 11:32:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t9NE5-0006T2-Iy; Fri, 08 Nov 2024 11:32:29 +0000 Received: by outflank-mailman (input) for mailman id 832464; Fri, 08 Nov 2024 11:32:28 +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 1t9NE4-00060f-GA for xen-devel@lists.xenproject.org; Fri, 08 Nov 2024 11:32:28 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 208faf58-9dc5-11ef-99a3-01e77a169b0f; Fri, 08 Nov 2024 12:32:25 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a9e71401844so243122866b.3 for ; Fri, 08 Nov 2024 03:32:25 -0800 (PST) Received: from localhost ([213.195.120.105]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0dc4c18sm223026666b.121.2024.11.08.03.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 03:32:24 -0800 (PST) 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: 208faf58-9dc5-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzAiLCJoZWxvIjoibWFpbC1lajEteDYzMC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjIwOGZhZjU4LTlkYzUtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxMDY1NTQ1LjM5NzUwNSwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731065544; x=1731670344; 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=6IDMV3cbJu3SgaSqePIjXkH0NqJWYaQKiZv2BBcuvU8=; b=IR1DSEDcXjvj+HYW6kXz9yCMmPXDGSUgwuDsbP3hB12ERb7gJUnd+rcXI72zYKch13 v3j6ieOP0ictKc7dhGsMTPGXnu/es0np1WJIAAEx34Hj8O5ekygkZr6vRHUEF8DJAoYr glB0e4Ox8uRr+RaEbfcvGIUVBKrI84by/nywA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731065544; x=1731670344; 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=6IDMV3cbJu3SgaSqePIjXkH0NqJWYaQKiZv2BBcuvU8=; b=U3m3zf8LqQGnUk+CfxAJ/L7Ve0SopklTpvKX7q9imeejjfEjma1KNEkeBNdK21Z9CG IYkaNutSq+asvHmBH2RxWrXLq4V7CovUoZPW0PVfI5ssyGfH09p3JdISvzYNcQDMgWs1 Ms8JIsDSmFX6WtzitdJWD2oY36Ru9StZgiv2M4yc6/LXP1u97lKY/mKln7ESD4zbIAp5 C4K5axckKu8u8v4QaOOuB99OSjX5EZL/+Y3qa03VEGjDZ0i2Y4pxj2JIIs3gqXxehDEq DXWaw04OxLve3F/B4KFqlTlE4V/g9B/ScpYxOFhjjhdIs+cZDjH8pGfAB7tbG+z60t0R vcpw== X-Gm-Message-State: AOJu0YwSJtaGHHDguoMOyeA+ClbSOi7cB8nOVwejz23eWDWNMXbiZ8YQ MGoJkIexHbTEWsT5OAQALkQIWvRZqS4blqnQKxeiJ20Zao20Q+KDs6dwvASQ9tS5LnQFTXinRbv 0 X-Google-Smtp-Source: AGHT+IHSdK76R8jeKdJ5/M0JC2X3Ik030Ae/Z3JqhChC/O5JSXgTzr2bxNCOlYsLEgjaaIsic5vWNw== X-Received: by 2002:a17:906:5f98:b0:a9e:f28c:374a with SMTP id a640c23a62f3a-a9ef28c3ba4mr125502766b.32.1731065544475; Fri, 08 Nov 2024 03:32:24 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 2/4] x86/mm: skip super-page alignment checks for non-present entries Date: Fri, 8 Nov 2024 12:31:42 +0100 Message-ID: <20241108113144.83637-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108113144.83637-1-roger.pau@citrix.com> References: <20241108113144.83637-1-roger.pau@citrix.com> MIME-Version: 1.0 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 alignment 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é Reviewed-by: Jan Beulich --- Changes since v1: - Detect non-present entries from the flags contents rather than checking the mfn parameter. --- xen/arch/x86/mm.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 8afb63c855b9..64b8054891da 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5232,9 +5232,17 @@ int map_pages_to_xen( } \ } while (0) -/* 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_ = 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) @@ -5255,7 +5263,8 @@ int map_pages_to_xen( L3T_LOCK(current_l3page); ol3e = *pl3e; - if ( cpu_has_page1gb && IS_L3E_ALIGNED(virt, mfn) && + if ( cpu_has_page1gb && + (!(flags & _PAGE_PRESENT) || IS_L3E_ALIGNED(virt, mfn)) && nr_mfns >= (1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) && !(flags & (_PAGE_PAT | MAP_SMALL_PAGES)) ) { @@ -5374,7 +5383,7 @@ int map_pages_to_xen( if ( !pl2e ) goto out; - if ( IS_L2E_ALIGNED(virt, mfn) && + if ( (!(flags & _PAGE_PRESENT) || IS_L2E_ALIGNED(virt, mfn)) && (nr_mfns >= (1u << PAGETABLE_ORDER)) && !(flags & (_PAGE_PAT|MAP_SMALL_PAGES)) ) { @@ -5544,7 +5553,8 @@ int map_pages_to_xen( check_l3: if ( cpu_has_page1gb && (flags == PAGE_HYPERVISOR) && - ((nr_mfns == 0) || IS_L3E_ALIGNED(virt, mfn)) ) + ((nr_mfns == 0) || !(flags & _PAGE_PRESENT) || + IS_L3E_ALIGNED(virt, mfn)) ) { unsigned long base_mfn; const l2_pgentry_t *l2t; From patchwork Fri Nov 8 11:31:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13868069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3057D5E15A for ; Fri, 8 Nov 2024 11:32:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.832465.1247793 (Exim 4.92) (envelope-from ) id 1t9NE7-0006iA-28; Fri, 08 Nov 2024 11:32:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 832465.1247793; Fri, 08 Nov 2024 11:32:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t9NE6-0006i1-UK; Fri, 08 Nov 2024 11:32:30 +0000 Received: by outflank-mailman (input) for mailman id 832465; Fri, 08 Nov 2024 11:32:29 +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 1t9NE5-00060f-NF for xen-devel@lists.xenproject.org; Fri, 08 Nov 2024 11:32:29 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2158ed38-9dc5-11ef-99a3-01e77a169b0f; Fri, 08 Nov 2024 12:32:26 +0100 (CET) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a9ed7d8c86cso355449366b.2 for ; Fri, 08 Nov 2024 03:32:26 -0800 (PST) Received: from localhost ([213.195.120.105]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0e2f45fsm221932666b.204.2024.11.08.03.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 03:32:25 -0800 (PST) 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: 2158ed38-9dc5-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzEiLCJoZWxvIjoibWFpbC1lajEteDYzMS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjIxNThlZDM4LTlkYzUtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxMDY1NTQ2LjcwMDIyOCwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731065546; x=1731670346; 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=b0FsFkoIjQtR5Yklh+Ux7paSLeD4eOoP2CsT3Yg/Cq0=; b=J7PbuHBopXB4U33tV0+XXTD8hEMcaKPwBkKGW/dal1QO8kG8K8x4cH7kw1KjDMJv0a nDXBxb2vQphbM3kQW+rhEETYLTLAg77jC6mheYvbAPgV6T8Y7hnqbTGRkC4pIfPOKR8d IjPe4zPzWXxNcys4R9S4hlt8F6uMtwIght0L4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731065546; x=1731670346; 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=b0FsFkoIjQtR5Yklh+Ux7paSLeD4eOoP2CsT3Yg/Cq0=; b=MJr5JE27Y/fCMQb+GxisTlqa6Nm2eCWMd5L304vqb0MsXVzKOsefxgzb0Zp0U+Geu9 oxXcSru52b3bSegKP2+Qi2edSPoSiSaq1Na1BEltGbrZnRi4I9s1HhNv2ubF7Cyqj2Km 7akSgS1v1jv/HV0e/Jxb/deMDpSVAOa56mwCKCb++vvT/OaWHKzMTpPICicGuJqXlwS4 RGqmzscI437R0tX37zxRndE6VWbIbONfD1S05wVnCIPhDHUvvX11DJoNeu5q3LhFDzeQ ctYKKHV1ytvrw4BKtO3OmBhha6DVWZpIG46XpqxH1ND1585Bqnt/5PvjhfL5q8tZWf84 mWEg== X-Gm-Message-State: AOJu0Yz9EEWHi1xMJxwpLPzFT4Ly8/iE8nGm5VkHgTIxn8JYjVfUsH1x PwTebNkg+XGY81Bt14N/TevrWg9GiIAGAELmdpwMxTVUbPUxE4YToDzhpq1DqZ7A33qGqxNH6tI h X-Google-Smtp-Source: AGHT+IFy4fnRmgbWrct3CZB3rKXTHBYaRMNiebB/Puw9Ue9WYq850IfO2FJ0xODFGojsIO+hspGLsA== X-Received: by 2002:a17:907:7243:b0:a9a:49a8:f1fa with SMTP id a640c23a62f3a-a9eefeed031mr220996966b.23.1731065545811; Fri, 08 Nov 2024 03:32:25 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v2 3/4] x86/setup: remove bootstrap_map_addr() usage of destroy_xen_mappings() Date: Fri, 8 Nov 2024 12:31:43 +0100 Message-ID: <20241108113144.83637-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108113144.83637-1-roger.pau@citrix.com> References: <20241108113144.83637-1-roger.pau@citrix.com> MIME-Version: 1.0 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é 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 eac8488c4ca5..be7ca26b3dd5 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -461,7 +461,9 @@ static void *__init bootstrap_map_addr(paddr_t start, paddr_t end) 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 = BOOTSTRAP_MAP_BASE; return NULL; } From patchwork Fri Nov 8 11:31:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13868070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2B74ED5E12F for ; Fri, 8 Nov 2024 11:32:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.832466.1247803 (Exim 4.92) (envelope-from ) id 1t9NE8-0006xk-8w; Fri, 08 Nov 2024 11:32:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 832466.1247803; Fri, 08 Nov 2024 11:32:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t9NE8-0006xd-5L; Fri, 08 Nov 2024 11:32:32 +0000 Received: by outflank-mailman (input) for mailman id 832466; Fri, 08 Nov 2024 11:32:30 +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 1t9NE6-00060f-Ql for xen-devel@lists.xenproject.org; Fri, 08 Nov 2024 11:32:30 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 22024e07-9dc5-11ef-99a3-01e77a169b0f; Fri, 08 Nov 2024 12:32:27 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5c9693dc739so2868034a12.3 for ; Fri, 08 Nov 2024 03:32:27 -0800 (PST) Received: from localhost ([213.195.120.105]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cf03b5d7f1sm1951138a12.8.2024.11.08.03.32.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 03:32:26 -0800 (PST) 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: 22024e07-9dc5-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmQiLCJoZWxvIjoibWFpbC1lZDEteDUyZC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjIyMDI0ZTA3LTlkYzUtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxMDY1NTQ3LjgyOTIxNCwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1731065547; x=1731670347; 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=Hy1rkOMw7x1rLXXuXX/nNUCuXlBj0Xy8KQUl33hR/Gg=; b=Ja4n9ROREEHM3ZMjA7sGNZqP+H4vdMeVgLmzDkWKzah3/TZih2RGK1fCnWk9zk0H72 yHf416R9Y2nGsycFfUcoVkQTKuNZtyidReQFATDW2HpbWlX58x2xy1zubLSWNseC7Kjm i7V4DfgtopXQ1veAY3HFEwmtX/7RvUxu3Ti9M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731065547; x=1731670347; 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=Hy1rkOMw7x1rLXXuXX/nNUCuXlBj0Xy8KQUl33hR/Gg=; b=BeeMjJwOIe6hXaC8Mkuzn/g7Km5m/JbwiigKa3EGMO9aCfm4zuntrczXM/2e4bMwoU Iwg93YsLdsTd6akGoIa+w/45AEbI86gUOUOLgabYW4Cg1fqNJ/sSKPEuobfaFhSSADZ5 uQjdwCnGY7FfbHMSqcavV8++OFfuZBEuigzfeCdzTbUws1PG2uaRkwTbT0MZHuqDcCj/ v+n2XCDeVTQJPyXIWgP4xARRVaK+CQepbYkbhn4GJJzWaT2DJZyX07jKEu+JrHXpDY+2 GEfXO3qh6pxGaM6tYtJIyPdboLiwot7xFvNZzQhHpfozpoHWN82LMKpO2bZnGVQF10BH GYhQ== X-Gm-Message-State: AOJu0YwdXd4kLIC4EZmCbO5hDW3yPJEfYDghbo8cfVQaNxkJYJu9MIDu ozGfnJ0prMzuvSngctN7Jn6seMNem7vVvxVAaA4u/IzSQ3CDerSb1Zo6AZ+FEiGBM9qPibXS9Br L X-Google-Smtp-Source: AGHT+IFjecNCao5lsL7w1bkyUj5XNZbq0NAXdF5qofiHRnPek57Q64WqXdld3mSVYG/gwB4xgXQT0Q== X-Received: by 2002:a05:6402:3547:b0:5cb:acfa:61ee with SMTP id 4fb4d7f45d1cf-5cf0a441833mr1683126a12.23.1731065546957; Fri, 08 Nov 2024 03:32:26 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 4/4] x86/mm: ensure L2 is always freed if empty Date: Fri, 8 Nov 2024 12:31:44 +0100 Message-ID: <20241108113144.83637-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108113144.83637-1-roger.pau@citrix.com> References: <20241108113144.83637-1-roger.pau@citrix.com> MIME-Version: 1.0 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 whole 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é 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 64b8054891da..489c71150255 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5731,7 +5731,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) v += 1UL << L2_PAGETABLE_SHIFT; v &= ~((1UL << L2_PAGETABLE_SHIFT) - 1); - continue; + goto check_l3; } if ( l2e_get_flags(*pl2e) & _PAGE_PSE )