From patchwork Wed Nov 6 12:29:24 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: 13864612 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 AF98FD44D54 for ; Wed, 6 Nov 2024 12:29:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830876.1245973 (Exim 4.92) (envelope-from ) id 1t8fAK-0004O2-JQ; Wed, 06 Nov 2024 12:29:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830876.1245973; Wed, 06 Nov 2024 12:29:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8fAK-0004N3-Fl; Wed, 06 Nov 2024 12:29:40 +0000 Received: by outflank-mailman (input) for mailman id 830876; Wed, 06 Nov 2024 12:29:39 +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 1t8fAJ-0004J0-83 for xen-devel@lists.xenproject.org; Wed, 06 Nov 2024 12:29:39 +0000 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [2a00:1450:4864:20::130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c872ffdc-9c3a-11ef-99a3-01e77a169b0f; Wed, 06 Nov 2024 13:29:35 +0100 (CET) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-539f4d8ef84so8426919e87.0 for ; Wed, 06 Nov 2024 04:29:35 -0800 (PST) Received: from localhost ([213.195.124.162]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9eb17ceb1dsm279896566b.101.2024.11.06.04.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 04:29:34 -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: c872ffdc-9c3a-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzAiLCJoZWxvIjoibWFpbC1sZjEteDEzMC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImM4NzJmZmRjLTljM2EtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwODk2MTc1LjgwMzA5Nywic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730896174; x=1731500974; 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=PzbBlr96+9j+wwmKx3UJvbDOiCZlb8PgkREFn+hF5mw=; b=rnN0oUGGrrmNNe0Uqqy0+bHsLGUdvkyIjcSi739LRb8jsKM27uWAnS9gIP/vcbuPhu 4SkGIJxYTQskl2LpUIFRqJbxL1aAUJZkJq406+Bw4+U6RuI7wK3CsTSaG46GRzjFQ13f Krz1UX+hMQyTEKbuCNJFAiu+HZP4Oql1AKM1o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730896174; x=1731500974; 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=PzbBlr96+9j+wwmKx3UJvbDOiCZlb8PgkREFn+hF5mw=; b=rFHyt8uEcvs/tyOb+JRkE0r1QOiB1SfJykbK3BQf3Axc8A90DvrV4eNIFX1ZOYaaWK L+smo1Ip9X4Gz/2oYkAaes6QD33KlslFE2cBS+2/byQTKUzLQ7n1vrDHX5aVHe7i3tr9 IPTkEcmJFB3mSLUY0KfrYYIW5UD4KCIVmHcXqdOWuLH3FaoFDzwyyA1UaOQ2NW7/D861 NiiEMyDcjr+/Vkfc3Ha5oH4Bgjn/gyGtT99DEFzyi0F2KUSykelxzCrrkLoVyVZHGrGf OcpNBl4Tbga2xgcCyYl9eUKiErzoJv0ZjGaBQezie6oC9Mfi1zgWMvbrJbCOqxDdGgYj 7C2w== X-Gm-Message-State: AOJu0YyNTTjzsrtKk+w5oY0Kx3envJ0QJJE68wil6C9iDr7AaOcnUK8+ cYwrzIBu2yuALq24p4Ix9SiOa8bb0SaCVMqBiCdcyy92dPLSNtuVSvTa4wO523Sm6bqkHZ0+a1c B X-Google-Smtp-Source: AGHT+IEP3IuYlL8NsaTGkDIQ+BpLLRbxnDOeFPrYMtdnosljz5T5fScqD2EAyqOeWgLhYKHVfDJMvw== X-Received: by 2002:a05:6512:10c7:b0:539:f06c:6f1d with SMTP id 2adb3069b0e04-53c79ea5346mr11836174e87.55.1730896174360; Wed, 06 Nov 2024 04:29:34 -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: Wed, 6 Nov 2024 13:29:24 +0100 Message-ID: <20241106122927.26461-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241106122927.26461-1-roger.pau@citrix.com> References: <20241106122927.26461-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é --- xen/arch/x86/include/asm/page.h | 6 ++++++ xen/arch/x86/mm.c | 11 +++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/include/asm/page.h b/xen/arch/x86/include/asm/page.h index e01af28916b0..6970916d61d5 100644 --- a/xen/arch/x86/include/asm/page.h +++ b/xen/arch/x86/include/asm/page.h @@ -200,6 +200,12 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) #define l4_table_offset(a) \ (((a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1)) +/* Check if an address is aligned for a given slot level. */ +#define SLOT_IS_ALIGNED(v, m, s) \ + IS_ALIGNED(PFN_DOWN(v) | mfn_x(m), (1UL << ((s) - PAGE_SHIFT)) - 1) +#define IS_L3E_ALIGNED(v, m) SLOT_IS_ALIGNED(v, m, L3_PAGETABLE_SHIFT) +#define IS_L2E_ALIGNED(v, m) SLOT_IS_ALIGNED(v, m, L2_PAGETABLE_SHIFT) + /* Convert a pointer to a page-table entry into pagetable slot index. */ #define pgentry_ptr_to_slot(_p) \ (((unsigned long)(_p) & ~PAGE_MASK) / sizeof(*(_p))) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index d537a799bced..8f7c397a82d4 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5249,9 +5249,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 +5368,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 +5538,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; From patchwork Wed Nov 6 12:29:25 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: 13864611 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 E2923D44D58 for ; Wed, 6 Nov 2024 12:29:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830877.1245982 (Exim 4.92) (envelope-from ) id 1t8fAL-0004Xx-4a; Wed, 06 Nov 2024 12:29:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830877.1245982; Wed, 06 Nov 2024 12:29:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8fAK-0004Wc-TV; Wed, 06 Nov 2024 12:29:40 +0000 Received: by outflank-mailman (input) for mailman id 830877; Wed, 06 Nov 2024 12:29:39 +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 1t8fAJ-0004JA-Lz for xen-devel@lists.xenproject.org; Wed, 06 Nov 2024 12:29:39 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c9162f31-9c3a-11ef-a0c6-8be0dac302b0; Wed, 06 Nov 2024 13:29:37 +0100 (CET) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5c937b5169cso1540556a12.1 for ; Wed, 06 Nov 2024 04:29:37 -0800 (PST) Received: from localhost ([213.195.124.162]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm2737214a12.4.2024.11.06.04.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 04:29:35 -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: c9162f31-9c3a-11ef-a0c6-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzYiLCJoZWxvIjoibWFpbC1lZDEteDUzNi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImM5MTYyZjMxLTljM2EtMTFlZi1hMGM2LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODk2MTc3LjEyNDk3OSwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730896176; x=1731500976; 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=dVmpTHSgje6W+FK+mwA0AzNEEu9akSw4GNptWHLi0AU=; b=v+1ZrkB7ugtesCaDuz9xhooq+J/lbyyKn17F9mmPD9sTAxIjrZWOggBfsyirSpBcHa Og3yQrpG4k+FdHrWDO87Nr8Lcnl4blhSqeiIwN5dAqKn4Xv685jkFQUfeKfSrN4HYh3a TRwjyJPDAEUuaLbWQOFOdUe0/bLqF4tfItIWs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730896176; x=1731500976; 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=dVmpTHSgje6W+FK+mwA0AzNEEu9akSw4GNptWHLi0AU=; b=njQeCGGioYv0AUFoN+hOeabq92CWQvXQIjvCmxj59+BqETc3/fAIhNw/SV9B2c3LrX rfysXIk5Kb3/j3VT4l7mpa97ax5mKNwDaA0bK6mCSpbndZEBkOeBtbWKGJ6ik0bMT+pm /WVaDcK8/6Y2IV5ndKHmDvf+ePZRG+oOR77RCayefpsIzGCRcYsw0GIAPdLTO/3wzkoy QnxihOiDdMztfIMrfeIL4jcdKUpTPGFKsKhmaUbLnCEAiqdAyGiUC4XVWWqlAysF1i5u /V9jNg1YaAmwY9NgroBC2WOg2Q99C1pMgsX/B+RPOMfocgpz/6dx5yRWGDfBlq5mf8rM MkYA== X-Gm-Message-State: AOJu0YwrJoMTR2JS573cXg/VFT+wfhUnyYR9IETd8cokTUkKi93eQW/k UY3D97+oF5IW7Q4V7m4obfz8of+F5S94aYKYqEXEZxy7XOl3rmJpdWHZXBSHEXJdePLJAopgcdk g X-Google-Smtp-Source: AGHT+IGWypOahahjNMwCperhYdLFPDNdZfP9EDfyRg9KmLtg0WaUKP4pjUlvv0nPncgde8ZPmp+Y3A== X-Received: by 2002:a50:d55e:0:b0:5ce:fa33:6c56 with SMTP id 4fb4d7f45d1cf-5cefa336cbcmr564742a12.4.1730896175936; Wed, 06 Nov 2024 04:29:35 -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: special case super page alignment detection for INVALID_MFN Date: Wed, 6 Nov 2024 13:29:25 +0100 Message-ID: <20241106122927.26461-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241106122927.26461-1-roger.pau@citrix.com> References: <20241106122927.26461-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. Special case INVALID_MFN so it's considered to be aligned for all slots. 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é --- xen/arch/x86/include/asm/page.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/include/asm/page.h b/xen/arch/x86/include/asm/page.h index 6970916d61d5..2fa4061dc77a 100644 --- a/xen/arch/x86/include/asm/page.h +++ b/xen/arch/x86/include/asm/page.h @@ -202,7 +202,8 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) /* Check if an address is aligned for a given slot level. */ #define SLOT_IS_ALIGNED(v, m, s) \ - IS_ALIGNED(PFN_DOWN(v) | mfn_x(m), (1UL << ((s) - PAGE_SHIFT)) - 1) + IS_ALIGNED(PFN_DOWN(v) | (mfn_eq(m, INVALID_MFN) ? 0 : mfn_x(m)), \ + (1UL << ((s) - PAGE_SHIFT)) - 1) #define IS_L3E_ALIGNED(v, m) SLOT_IS_ALIGNED(v, m, L3_PAGETABLE_SHIFT) #define IS_L2E_ALIGNED(v, m) SLOT_IS_ALIGNED(v, m, L2_PAGETABLE_SHIFT) From patchwork Wed Nov 6 12:29:26 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: 13864610 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 3A13DD44D57 for ; Wed, 6 Nov 2024 12:29:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830878.1245999 (Exim 4.92) (envelope-from ) id 1t8fAM-00050z-9A; Wed, 06 Nov 2024 12:29:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830878.1245999; Wed, 06 Nov 2024 12:29:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8fAM-00050G-5r; Wed, 06 Nov 2024 12:29:42 +0000 Received: by outflank-mailman (input) for mailman id 830878; Wed, 06 Nov 2024 12:29:40 +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 1t8fAK-0004JA-OJ for xen-devel@lists.xenproject.org; Wed, 06 Nov 2024 12:29:40 +0000 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [2a00:1450:4864:20::22c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ca10e52a-9c3a-11ef-a0c6-8be0dac302b0; Wed, 06 Nov 2024 13:29:38 +0100 (CET) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2f7657f9f62so56949101fa.3 for ; Wed, 06 Nov 2024 04:29:38 -0800 (PST) Received: from localhost ([213.195.124.162]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a9a42asm2651723a12.18.2024.11.06.04.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 04:29:37 -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: ca10e52a-9c3a-11ef-a0c6-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoyMmMiLCJoZWxvIjoibWFpbC1sajEteDIyYy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImNhMTBlNTJhLTljM2EtMTFlZi1hMGM2LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODk2MTc4LjYyNjQ1Mywic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730896178; x=1731500978; 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=BcaVEltxEnxyr1CO9t1j4OvKSjNdZa22JUuN+LyK/nw=; b=D5rVW28cromVCQheO1PJKkr+WQJB0Ttj4DGC5vwzQgETSzpsCxfvDupu6YfP6pYPbd eJLR41CNCx9JALx2lfGmINXOhObPvVh2yc+2fQFtMWOXs2Uh3z9PFYseUunD/p2oC51W CL1NTMLVoWbkETzOtHSOmLR/mle7lXGr/DJ10= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730896178; x=1731500978; 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=BcaVEltxEnxyr1CO9t1j4OvKSjNdZa22JUuN+LyK/nw=; b=DJubesFFo49bt/XtDJz5WtYv4VWIZAw2VO1a9Em+QvOh3szMBY4olpRGQ4Nf07D8Af y1J+IaCG3+21p+GorZOQALxaquZd+OxzbqqNNDwvhYRPJgz/MlbP53YZcI3ruzrqWDiH 6qyVJ0LdIyFUAZtpIjyXmwLMgvwiOUFwah3Nbd0vi6kGWdza/v2xiWtC4eCgEaLxh+rj /a2BTXjiPUpRROOJn+FUKK92ZCTQ7ibqmdQ0fTavEP0pBvwUSJMK9UyOH3PUuxL0rB3V CrXpAUVgtMopar+73IY1owWAaug4m/3xehukRe0Xf4Qu2+4XLDqFQQXksl+kz5Z3SIAh kC7w== X-Gm-Message-State: AOJu0Yw+TGLjyvyWjZftnmiRgQ2Dvo0IzXs2FLUcXPiRlsrRWljfiVQP Qo+3DRm0ptRUxZWBOsMKjoOag2fFhw5gVFjfxe0thlhO/NIr6tozfFk3mCDFffaPb5viON/dIXZ 3 X-Google-Smtp-Source: AGHT+IEFjGTqghs/TdsB9cSFSKBeL7oEkX8qGPdc5XOODpnBxogvgGl8TtwpM6RgS/hg+ei7Ok/TfA== X-Received: by 2002:a05:651c:553:b0:2fb:6169:c431 with SMTP id 38308e7fff4ca-2fcbdf69596mr202631541fa.9.1730896177689; Wed, 06 Nov 2024 04:29:37 -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: Wed, 6 Nov 2024 13:29:26 +0100 Message-ID: <20241106122927.26461-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241106122927.26461-1-roger.pau@citrix.com> References: <20241106122927.26461-1-roger.pau@citrix.com> MIME-Version: 1.0 bootstrap_map_addr() top level comment states that it doesn't indented to remove the L2 tables, as the same L2 will be re-used to create further 2MB mappings. It's incorrect for the function to use destroy_xen_mappings() which will free empty L2 tables. 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é --- The fixes tag reflects the fact that if 4376c05c3113 freed the L2 correctly when empty, it would have become obvious that bootstrap_map_addr() shouldn't be using it if it wants to keep the L2. 4376c05c3113 should have switched bootstrap_map_addr() to not use destroy_xen_mappings(). --- 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 177f4024abca..815b8651ba79 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -456,7 +456,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 Wed Nov 6 12:29:27 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: 13864613 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 50C24D44D57 for ; Wed, 6 Nov 2024 12:30:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830879.1246008 (Exim 4.92) (envelope-from ) id 1t8fAO-0005Lo-I3; Wed, 06 Nov 2024 12:29:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830879.1246008; Wed, 06 Nov 2024 12:29:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8fAO-0005Lh-Eq; Wed, 06 Nov 2024 12:29:44 +0000 Received: by outflank-mailman (input) for mailman id 830879; Wed, 06 Nov 2024 12:29:42 +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 1t8fAM-0004JA-GE for xen-devel@lists.xenproject.org; Wed, 06 Nov 2024 12:29:42 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cb314818-9c3a-11ef-a0c6-8be0dac302b0; Wed, 06 Nov 2024 13:29:40 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5ceca0ec4e7so5259529a12.0 for ; Wed, 06 Nov 2024 04:29:40 -0800 (PST) Received: from localhost ([213.195.124.162]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6ab10d4sm2682195a12.27.2024.11.06.04.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 04:29:39 -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: cb314818-9c3a-11ef-a0c6-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzIiLCJoZWxvIjoibWFpbC1lZDEteDUzMi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImNiMzE0ODE4LTljM2EtMTFlZi1hMGM2LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODk2MTgwLjQ0MjEzOSwic2VuZGVyIjoicm9nZXIucGF1QGNsb3VkLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730896179; x=1731500979; 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=4qHELgAq1nN/UXJ9bkfqeoULYcH/rWuJ4SStRsxggRI=; b=og54/+ebibxUwSvlYnffQ0gEm3nLbtM5ufHn6FndVD2PjdnPRUaqGXIRmQAw5aikGX 5k9PMoEvFsU3UBclrmivLopxdg/CxvYG+1rFMUABALBRMf5FbHC9BvkNxN98hfaBArV/ zzWzUEc33OJ6JrZQAfbHM7Bm3NXG13Skajm0I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730896179; x=1731500979; 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=4qHELgAq1nN/UXJ9bkfqeoULYcH/rWuJ4SStRsxggRI=; b=Hlwn5x8i+D2VyQIXZ3yyxZvj7qNM8grCasm9E1iF4ytZU837pNXm2UGjGg3AXTKCw1 KTGK/uL7CSvPbSevgDlNhdqyidthS8dzB9xedA6HadH0YpREYYLEeUX54oigSCxrr4Dk jYtsLZQQ37Sr9hZCPJoBYr8cfLQOoZDqCDA67BI2TpOr6qy6mEW///9UYL7pT0fer2mG un4I1n/vZw8OJBWfQglUwHNLcrzAeHROs3LMLO3CKD1u5dYcTwgI4dsOyvFBf09V9qs6 NArvTq5zy/1KAhLUe0v6F0FoNEAqQNguyDnFkrLLGJfqP/3e0lnVyxWzSaUsP8MjrVJn UxrQ== X-Gm-Message-State: AOJu0YzO17SKQdJ1QkX0WJrTVTCit0Y5fiZUyOUIsAmLOaS330ilMlKq K7RAHKzh9yiyZxZKyyoDLIH3MNvtLdHUCfXbh28SFu0EQh0FdGDbduDmmFvPLaVIjknpPg3uW7+ S X-Google-Smtp-Source: AGHT+IFQg/goUaMDwivI0dHrgfSpC+FBj2jDnE6V14jWVDhd0u+uAbDhiS+3oq9lLxJyn3ZMKEXu1Q== X-Received: by 2002:a05:6402:5203:b0:5ca:14e5:b685 with SMTP id 4fb4d7f45d1cf-5cbbf888bcemr29831951a12.3.1730896179560; Wed, 06 Nov 2024 04:29:39 -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: Wed, 6 Nov 2024 13:29:27 +0100 Message-ID: <20241106122927.26461-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241106122927.26461-1-roger.pau@citrix.com> References: <20241106122927.26461-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 8f7c397a82d4..05d3ba095627 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5712,7 +5712,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 )