From patchwork Tue Dec 13 11:36:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13071959 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 ED14AC4167B for ; Tue, 13 Dec 2022 11:37:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.460559.718488 (Exim 4.92) (envelope-from ) id 1p53al-0003b9-DD; Tue, 13 Dec 2022 11:36:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 460559.718488; Tue, 13 Dec 2022 11:36:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p53al-0003b2-9g; Tue, 13 Dec 2022 11:36:59 +0000 Received: by outflank-mailman (input) for mailman id 460559; Tue, 13 Dec 2022 11:36:58 +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 1p53ak-0003Zb-CY for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 11:36:58 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2054.outbound.protection.outlook.com [40.107.21.54]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cb1a4143-7ad9-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 12:32:15 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PR3PR04MB7338.eurprd04.prod.outlook.com (2603:10a6:102:80::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.11; Tue, 13 Dec 2022 11:36:55 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8%4]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 11:36:55 +0000 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: cb1a4143-7ad9-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fN4/pZmTQgWw1txxYV+1LbB33sHqWNIwsIblBjA55NZGUPEQnoYGKfpNwOuJwdKPtXJJTYf9lc/zv2Bhq2IJiziHvExkRL7HaOy2noyATpR2gVIGV+niCj8dzckT03WiaxdnvD4rTDmDeOTBXvpNkZoKmozG3tyUDroo+xGV7jXwk28BOKBVUfpuBQjwVFLG59WFrnVCOuF8u09DfOmlCrfwb0eJTOQ5+0oJltxCrPGvP6tONJkM00y1u3rbrTDCS4q1pZvh4sGnjhoy0itUQwkiwAQigxmBDsFkMQ1N/cf8M6rmuWNO+dTF9zd6fQwZ2jrZ8E4UKc/gt2Fr6pC4+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dI5yJpzzZtco6iDYZtvKt6sm4LVJzPtpRGFeBOoz680=; b=KjfyiTAk82DkBCrWwROjKYsgVUI5sUvr0ZR6t4FONez6HHAMheFVBKVOcy8ScADPWTRJ1/GNK/jCBrF/0ZnKwYlzJwF9huCVMSELIs7MyNZjorXAzTBWxDYUFWtA/Xo7CgT0aIIWCUqStdud5oNkzEsj7uvs+ZyspyMBnDe2aKXoNXT3hexYt+N/yH5bmKH7GJ/mQKFc0NiVFqLTCwS32kjlR/kfo/4eNJndcwWpc2BjmtXpCOBm3LtiSwO0+lgur62KqzwUzkvTQkRuB3T1VA2qZOC/TXxQW5NYSb+v4FysqoZHglAV45BM4Ek7IbKb8mKx4eyXhXL6IvEt7+uhsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dI5yJpzzZtco6iDYZtvKt6sm4LVJzPtpRGFeBOoz680=; b=bkEEYaYgSJTXLNsIqGj6g/db+KhPCmHmKJGWMsueOwFN6HEzUxmO/vOXa9cYbsmcV2F5Jzsl4qvfZM64dpvuCGVuzwJg73dKJcsHXsuceZoY9EdmcxYvxIZHaZwywDE3IvR2UZTJ/awgykfvYEeQeviuWiZOJXuecqUjynwLv8FuW/i3q7Gq1NRv4YnjAGcLwdQGWkOIyjDc8d6DyeyaXvgpXuYYNPcgLJoZ9/pYRXq4y4xxoUD6KjKB42hmgGdy2omNtuzSySIuUrnhHGO4diQkTAUaup6gZNXFd0tR6WAPTA5SOHk1rW0yweJHZS7uEEZwVB9NNfc4E0S4dsLiLQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 13 Dec 2022 12:36:54 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: [PATCH 1/2] x86/mm: avoid phys_to_nid() calls for invalid addresses Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= References: <471bd202-7bf0-81be-e8a5-780ea5975a70@suse.com> In-Reply-To: <471bd202-7bf0-81be-e8a5-780ea5975a70@suse.com> X-ClientProxiedBy: FR2P281CA0076.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9a::18) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|PR3PR04MB7338:EE_ X-MS-Office365-Filtering-Correlation-Id: 6a7ce60c-faca-4cae-28fc-08dadcfe564f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m3Sjf1HhILvpZMt6A0mEKHw4jP9Daq19apmaCvmO/ngfvnBm8bQvm1Jmv6xJiAgEMfnwW9a36ZNFJhdd0zZK+EkLyKQbsqOOEC89Rl4QEurl2qCBykcV97JXGzvddgjojBZdGbDmDgcV5HQ5UMEy8vCp30M4pl9fp1M4nTMNpN5aIiL0O7nC2Gz2b+9HF4ZIhACwZnoKk8XtzGk6VNllM0JXwEfK0lpE1DLl0pV7VdxLMgASsfKFxlAfpTcAIebDHKzOlqwwQ8Grtd2IrZjWQzfhxLEpFlc5t/f0sFwG4U4dUC1BWi5W7sDLeirBay00To5ZTsDPSEj36LPhG+cROA09Ga+h7q3uIhkSi7oM+gAIJetpo5WS4SohBi+5eY8BGA+LdYrSyjYZ9xBUUFEL0j2db6mcFwaAiPZTjhRb5a5Zaw+znX9I8zyFvlphWhHjV59jxma2s09LfXIQzU9ZsumtUGlE/8KPt0IwFbQ64Ta3Bb6d2ZQwPV91+zypiylJMTZvBAIXU+CQnpSC1cRZprFoilaHssbRgOwilgOXvcTo9TJA3NihE9arEk/vQ7ZhBUFXguzr9zcwvgWE+vYDoomfmKqH4W8GfDtrYlrX7GM3HKlVtx7oxc7v1XfBD+ic936FieyfS3w0dx/cba8i+JPLRoHnushM2Fe4Ir6/2smFN8XrNvQ2D1TTlDvyfPYsjmydFnhFARRDK/r40gBdicu582GJloInQ1gYBZXIcFo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(376002)(396003)(136003)(366004)(39860400002)(346002)(451199015)(38100700002)(83380400001)(31696002)(86362001)(8676002)(66946007)(66556008)(41300700001)(66476007)(54906003)(6916009)(316002)(4326008)(2906002)(8936002)(5660300002)(26005)(6512007)(186003)(2616005)(478600001)(6486002)(6506007)(31686004)(66899015)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bdVD8BHO3qpQqCBe/HquMsG7KqrG?= =?utf-8?q?tGeclbWqMWkr51wD0g7mkV9EGBxyhdZU53e+7IUlYDzpJE4sQovO4/RBn0dadKhZE?= =?utf-8?q?x70PoaZH1sP2rYO7C1yGhraAUHKvSwT3naFlLu2ErP7BgKVWHumvmj+J8l1IYFZ3J?= =?utf-8?q?EQLoOlvWXH59cRBr0On/0njOGl7WF+g3IQz1gaoIVJzC9nljZaC6LU1qGbf3jaSI5?= =?utf-8?q?hVl1jFL6DDVrxrXc1OF+t2njHRfxaU/3lE7gtQqJrw1QgcDhNNR17lAd3PS8RITsd?= =?utf-8?q?2J3GANh0mufU6QZoxJSsCGoakY9VOptoRJIBb+PF74T5AP8N1KPU4DSCJwphf0X5x?= =?utf-8?q?Ka9WYYo16y+ZLdgLBiaIXYV8CmhanBlhMyxe0cDyK0ujhR7UKPh2mbRwC5EWxdkrz?= =?utf-8?q?HagSHLrHg4D0Oh663kIxzb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c/Jtfdg0HSyr7P3SnKYnl3r1933fb1FNPJ?= =?utf-8?q?7LlN9K9tSZgmLXj0tkPxGqWuOdRGMObimgMDv8reXsn0g9x6IHwy21kety9BjqtpO?= =?utf-8?q?vKEF4Ns7H7n8a8sCukCfqaOM/6rJaWKHV4H0CzmXSmCUSlDcmH7qNl8vP0CmMb7EL?= =?utf-8?q?TenJ/SStdN+YQF8DqANKyMxuhjl3dgXNwbcFo2cywK/dyLoJiRHymLN6Ixaw03gkb?= =?utf-8?q?gwsui8+D7JRV?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a7ce60c-faca-4cae-28fc-08dadcfe564f X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 11:36:55.5741 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ofVMM9FV7JGgDo3i+iSk+XDQnprzSOAfTqmhBhmxTsbtcjGU+KaUfp2jSpjfjoxzsmGrcqeUi147fxfYHSmUnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7338 With phys_to_nid() now actively checking that a valid node ID is on record, the two uses in paging_init() can actually trigger at least the 2nd of the assertions there. They're used to calculate allocation flags, but the calculated flags wouldn't be used when dealing with an invalid (unpopulated) address range. Defer the calculations such that they can be done with a validated MFN in hands. This also does away with the artificial calculations of an address to pass to phys_to_nid(). Note that while the variable is provably written before use, at least some compiler versions can't actually verify that. Hence the variable also needs to gain a (dead) initializer. Fixes: e9c72d524fbd ("xen/x86: Use ASSERT instead of VIRTUAL_BUG_ON for phys_to_nid") Signed-off-by: Jan Beulich --- RFC: With small enough a NUMA hash shift it would still be possible to hit an SRAT hole, despite mfn_valid() passing. Hence, like was the original plan, it may still be necessary to relax the checking in phys_to_nid() (or its designated replacements). At which point the value of this change here would shrink to merely reducing the chance of unintentionally doing NUMA_NO_NODE allocations. --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -498,7 +498,7 @@ error: void __init paging_init(void) { unsigned long i, mpt_size, va; - unsigned int n, memflags; + unsigned int n, memflags = 0; l3_pgentry_t *l3_ro_mpt; l2_pgentry_t *pl2e = NULL, *l2_ro_mpt = NULL; struct page_info *l1_pg; @@ -547,8 +547,6 @@ void __init paging_init(void) { BUILD_BUG_ON(RO_MPT_VIRT_START & ((1UL << L3_PAGETABLE_SHIFT) - 1)); va = RO_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT); - memflags = MEMF_node(phys_to_nid(i << - (L2_PAGETABLE_SHIFT - 3 + PAGE_SHIFT))); if ( cpu_has_page1gb && !((unsigned long)pl2e & ~PAGE_MASK) && @@ -559,10 +557,15 @@ void __init paging_init(void) for ( holes = k = 0; k < 1 << PAGETABLE_ORDER; ++k) { for ( n = 0; n < CNT; ++n) - if ( mfn_valid(_mfn(MFN(i + k) + n * PDX_GROUP_COUNT)) ) + { + mfn = _mfn(MFN(i + k) + n * PDX_GROUP_COUNT); + if ( mfn_valid(mfn) ) break; + } if ( n == CNT ) ++holes; + else if ( k == holes ) + memflags = MEMF_node(phys_to_nid(mfn_to_maddr(mfn))); } if ( k == holes ) { @@ -593,8 +596,14 @@ void __init paging_init(void) } for ( n = 0; n < CNT; ++n) - if ( mfn_valid(_mfn(MFN(i) + n * PDX_GROUP_COUNT)) ) + { + mfn = _mfn(MFN(i) + n * PDX_GROUP_COUNT); + if ( mfn_valid(mfn) ) + { + memflags = MEMF_node(phys_to_nid(mfn_to_maddr(mfn))); break; + } + } if ( n == CNT ) l1_pg = NULL; else if ( (l1_pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER, @@ -663,15 +672,19 @@ void __init paging_init(void) sizeof(*compat_machine_to_phys_mapping)); for ( i = 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++, pl2e++ ) { - memflags = MEMF_node(phys_to_nid(i << - (L2_PAGETABLE_SHIFT - 2 + PAGE_SHIFT))); for ( n = 0; n < CNT; ++n) - if ( mfn_valid(_mfn(MFN(i) + n * PDX_GROUP_COUNT)) ) + { + mfn = _mfn(MFN(i) + n * PDX_GROUP_COUNT); + if ( mfn_valid(mfn) ) + { + memflags = MEMF_node(phys_to_nid(mfn_to_maddr(mfn))); break; + } + } if ( n == CNT ) continue; if ( (l1_pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER, - memflags)) == NULL ) + memflags)) == NULL ) goto nomem; map_pages_to_xen( RDWR_COMPAT_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT), From patchwork Tue Dec 13 11:38:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13071961 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 87D30C4332F for ; Tue, 13 Dec 2022 11:38:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.460567.718499 (Exim 4.92) (envelope-from ) id 1p53cD-0004BR-NC; Tue, 13 Dec 2022 11:38:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 460567.718499; Tue, 13 Dec 2022 11:38: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 1p53cD-0004BK-KV; Tue, 13 Dec 2022 11:38:29 +0000 Received: by outflank-mailman (input) for mailman id 460567; Tue, 13 Dec 2022 11:38:28 +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 1p53cC-0004BE-Bt for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 11:38:28 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2045.outbound.protection.outlook.com [40.107.7.45]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a89e90cb-7ada-11ed-91b6-6bf2151ebd3b; Tue, 13 Dec 2022 12:38:27 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM7PR04MB6773.eurprd04.prod.outlook.com (2603:10a6:20b:dc::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Tue, 13 Dec 2022 11:38:24 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8%4]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 11:38:24 +0000 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: a89e90cb-7ada-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LA0D0LxmkAf+yF3cRNmCoCHyzlkaPKqJajBO8dhpqQoSZihGVGi9KR5IXfMxda2Y+tE8zt/dD4Rt7dIOt+6vCA3rxqbDQ7T6U1DQtgmqpPDAf+cf1NJ7tRBypBwvC22CUkansP3Q3Cu5mz9HiylDTbPZa3RTepj5AzA5UpT4YB4V01ch/6pw3TlKBMXXAAc5K0HFl7bySuh0EUYlHhEeP/5LQsgqqu4KllZ9EhmoV6kkOPZ7WRXifaw9XUHH2KJLU/O6fHrYDbG/54l2GzoYMYJDVrc6ZrRkMBJzQyfxuoiJJVmXBFFyG2YCe67psGsUEf00kmN4vCnYSH3g6O2hcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2fKU73ItCQMSb+9aoT7onl24CYSr8frLerEBargv7u8=; b=h+YsQEDPYV3gG8zrouq8E37Q3ASRzFGj0KsyF7rFwqA0E2HEjoaBCJupFFmBh1kvGnoolxt3RbOwvsj6LATmYkzoA9ecD2v7PdYt+qxKL9rTGPpJit1Ti31ssAL5OvG7CZVSpg8rrshRJbPUyp62zof2X2nZa+NCDwxtOmUd4nQOilBCSiE8zO5u8PfCdz0aRwPCBPT/qjZd0ki1T9VHtX+/XCG4nIWFTK7mSX9sbVDThNklzFZIHyjuJiqTeVxpPsi2lqKukXz2cAGWlmn0eJ3H4RtcawCQ4KxBCchhHtKp5qLLIpGEO41YtNdcNRA3EmfnS7eBtgkWch96FkB7Cw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2fKU73ItCQMSb+9aoT7onl24CYSr8frLerEBargv7u8=; b=oVlhHI6GZ8s99s3Z5w/lhE3Xl4TA0Q67nHrKjTxWN0UDuhoTpd0jikCa9uoSiNTjiN/DAtOSx8xYngBfQw1zWTg3FI5/8txIDy/PddZ2gcrBIrjbT3UHSI3DYJ3oCUe8736VdRqReNYny+cJ8zqZnZkBDAlxGrkgo0tscb8ejO80ZuyhiVP3texo8LKjH+7LjIKPfYWGoqXWPTmgINHn6AFRQJYVP1s/Lx7TKOJCkHshVrMYcSa0T09cslHGScwpdaIIklotf6tFzaevmUUc0irMCZ4O6gK+rHoGTIxI7XI7FvcJOwLZc5RXYQ0Bw38GzdjvACjQslS6m7Zrg6s4WA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <670b7017-4a6e-fa9e-9d65-65013bd4ad80@suse.com> Date: Tue, 13 Dec 2022 12:38:22 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: [PATCH 2/2] NUMA: replace phys_to_nid() Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Bertrand Marquis , Volodymyr Babchuk References: <471bd202-7bf0-81be-e8a5-780ea5975a70@suse.com> In-Reply-To: <471bd202-7bf0-81be-e8a5-780ea5975a70@suse.com> X-ClientProxiedBy: FR2P281CA0139.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9e::10) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AM7PR04MB6773:EE_ X-MS-Office365-Filtering-Correlation-Id: e2e5c921-9d92-4a71-c6a3-08dadcfe8b42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4na9XTIPMtTlX9vSVrveEyO49QjKIJpTgCOD2IBT1ppehiI2tiDh/GBooHKmawJ+2jVYTsr1Prg4JJPY52nT9oRF1hu+u1w4WpPzVCjJgPW+Y+ZsIkoyq0RvlAEgYCgh0SQPSZjQlkjauEHwB8yH4FInvZdeD3m1gr3+z1VJFKySFAjJcGExAzICzbNJh9kbAv4OL+5Btj/QWROkL2yU3IySUN77JA+tGWxcNMuqZkg07BxY1yR/ZEh2j4YcMv1lsYujZRDhRDfihetqofnBm1BSZXbTWBOGNPZw6fnHi3FW8u5pcF9H4WH6KGXVY96+J8bwQ4KSpBQ35evZ/lU3S2AX+5Fk8onrqUQD1LMPLVjAa6lz9cxGwFZ/oMwVmqB9boUv1pV6acsPtbsK2tWYzYIiBHW4LGjEDTRKltuSdToc46cE4+Ed+k0xi5YzUegaGcKXO6D1HFEJpjOaxqlct+cMlrGg75BYleoYExP9H7GgKlMWjvvgF1Nf+cJtM9K1wOdz5SBVkUuDYuYQn78BCexN6S9Vjl382l/QAl0lQW4UaCZVNpScNElnXR27j2nJB0bf2Id7k/1W+uPnfH9594QwPjlG1Reo9M/hDKjbz0vzS8a2KD/Grt8++V01Q0+mUN44M7DQCWJYSiNNO8o1wZiZFCXoyXJjyTWs0a0RdIRbSulU+STNSM6FYuZnZ0u4BiaFjtCyE/u9oLkIP1/1S0qa6GZ0aoUMZA53SJNFkgQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(376002)(346002)(39860400002)(396003)(366004)(136003)(451199015)(38100700002)(31696002)(6486002)(86362001)(5660300002)(478600001)(66946007)(2906002)(41300700001)(66556008)(4326008)(8676002)(316002)(83380400001)(6506007)(186003)(26005)(8936002)(6512007)(66476007)(2616005)(31686004)(54906003)(6916009)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?YGNi8yNrAtEHlaYCEwfBmevku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PD?= =?utf-8?q?iuy2AxsllQyLf9GtNNLgTK0Bfwr18oQLAsIMAgxMi01MfrDHRAF/5Fx0Z/H1gQnRN?= =?utf-8?q?jMFsyzllVU91vt5UVxLRi4Pvatno5lEY8RsOLEV6sVMCiZUxqtNdphJFfkqqbY5d6?= =?utf-8?q?8mlon1kFc7aOtURLars3M/UpiwktVJ/tr1vzP44wcWzJ6PsKTey013be5ckOgR8lQ?= =?utf-8?q?htxFbTzH/OPjklNQEXjJ71VMaeLRyVNK0grmiFTbh1NWjqL0lcztbYlaCN01tFVy3?= =?utf-8?q?wa5N5n9WppdoS9iIqAba+mD7MtSX+WHmWZI4tfY2PbA3U8mKAWuWTavZ7h2MOW/cW?= =?utf-8?q?Agre8c3tqkOZ2PZHNpt4ji+zmspm9BHQEXEcmYXZJpg8HiAD8rD2GLGKLqGnnCR5v?= =?utf-8?q?xdKDGFJDs5ywL1+MWvUklN4VZWOqoCsKc/bQzk4oULROpUrxqLoH1bcZTXNCMTh8T?= =?utf-8?q?LCvMDIBBwqh6gMy4R8INIiTjPX5XMjA8+L7jO473RiJHcOwgdvQr6Vt/7uUnrM095?= =?utf-8?q?OVpx+YUsndHu/GdplOW5ktPdHh1fz2IneHIpk//mDzZzGnNDvwn/MSwal+c7M3dk9?= =?utf-8?q?yv1vKTG16rrsPjQdw0rDgrRraq2HS9acOmQ2+NJK0IJkr6sI755cuHuCQkzu8YbwW?= =?utf-8?q?2Mj1NtWbhgZV?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2e5c921-9d92-4a71-c6a3-08dadcfe8b42 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 11:38:24.3809 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6cCeR+a6vioXWRsXuMuLZbgpv5D8icjQ8jmW2a3eV1PNFEvr4mHNilgJC1/2VFWzOPksGINT0BQEgV52gDo57w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6773 All callers convert frame numbers (perhaps in turn derived from struct page_info pointers) to an address, just for the function to convert it back to a frame number (as the first step of paddr_to_pdx()). Replace the function by mfn_to_nid() plus a page_to_nid() wrapper macro. Replace call sites by the respectively most suitable one. While there also introduce a !NUMA stub, eliminating the need for Arm (and potentially other ports) to carry one individually. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper , albeit with one --- At the top of free_heap_pages() mfn_to_nid() could also be used, since the MFN is calculated immediately ahead. The choice of using page_to_nid() (for now at least) was with the earlier patch's RFC in mind, addressing of which may require to make mfn_to_nid() do weaker checking than page_to_nid(). --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -11,11 +11,6 @@ typedef u8 nodeid_t; #define cpu_to_node(cpu) 0 #define node_to_cpumask(node) (cpu_online_map) -static inline __attribute__((pure)) nodeid_t phys_to_nid(paddr_t addr) -{ - return 0; -} - /* * TODO: make first_valid_mfn static when NUMA is supported on Arm, this * is required because the dummy helpers are using it. --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -492,7 +492,7 @@ p2m_pod_offline_or_broken_replace(struct { struct domain *d; struct p2m_domain *p2m; - nodeid_t node = phys_to_nid(page_to_maddr(p)); + nodeid_t node = page_to_nid(p); if ( !(d = page_get_owner(p)) || !(p2m = p2m_get_hostp2m(d)) ) return; --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -565,7 +565,7 @@ void __init paging_init(void) if ( n == CNT ) ++holes; else if ( k == holes ) - memflags = MEMF_node(phys_to_nid(mfn_to_maddr(mfn))); + memflags = MEMF_node(mfn_to_nid(mfn)); } if ( k == holes ) { @@ -600,7 +600,7 @@ void __init paging_init(void) mfn = _mfn(MFN(i) + n * PDX_GROUP_COUNT); if ( mfn_valid(mfn) ) { - memflags = MEMF_node(phys_to_nid(mfn_to_maddr(mfn))); + memflags = MEMF_node(mfn_to_nid(mfn)); break; } } @@ -677,7 +677,7 @@ void __init paging_init(void) mfn = _mfn(MFN(i) + n * PDX_GROUP_COUNT); if ( mfn_valid(mfn) ) { - memflags = MEMF_node(phys_to_nid(mfn_to_maddr(mfn))); + memflags = MEMF_node(mfn_to_nid(mfn)); break; } } --- a/xen/common/numa.c +++ b/xen/common/numa.c @@ -671,15 +671,15 @@ static void cf_check dump_numa(unsigned for_each_online_node ( i ) { - paddr_t pa = pfn_to_paddr(node_start_pfn(i) + 1); + mfn_t mfn = _mfn(node_start_pfn(i) + 1); printk("NODE%u start->%lu size->%lu free->%lu\n", i, node_start_pfn(i), node_spanned_pages(i), avail_node_heap_pages(i)); - /* Sanity check phys_to_nid() */ - if ( phys_to_nid(pa) != i ) - printk("phys_to_nid(%"PRIpaddr") -> %d should be %u\n", - pa, phys_to_nid(pa), i); + /* Sanity check mfn_to_nid() */ + if ( node_spanned_pages(i) && mfn_to_nid(mfn) != i ) + printk("mfn_to_nid(%"PRI_mfn") -> %d should be %u\n", + mfn_x(mfn), mfn_to_nid(mfn), i); } j = cpumask_first(&cpu_online_map); @@ -721,7 +721,7 @@ static void cf_check dump_numa(unsigned spin_lock(&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { - i = phys_to_nid(page_to_maddr(page)); + i = page_to_nid(page); page_num_node[i]++; } spin_unlock(&d->page_alloc_lock); --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -971,7 +971,7 @@ static struct page_info *alloc_heap_page return NULL; } - node = phys_to_nid(page_to_maddr(pg)); + node = page_to_nid(pg); zone = page_to_zone(pg); buddy_order = PFN_ORDER(pg); @@ -1078,7 +1078,7 @@ static struct page_info *alloc_heap_page /* Remove any offlined page in the buddy pointed to by head. */ static int reserve_offlined_page(struct page_info *head) { - unsigned int node = phys_to_nid(page_to_maddr(head)); + unsigned int node = page_to_nid(head); int zone = page_to_zone(head), i, head_order = PFN_ORDER(head), count = 0; struct page_info *cur_head; unsigned int cur_order, first_dirty; @@ -1443,7 +1443,7 @@ static void free_heap_pages( { unsigned long mask; mfn_t mfn = page_to_mfn(pg); - unsigned int i, node = phys_to_nid(mfn_to_maddr(mfn)); + unsigned int i, node = page_to_nid(pg); unsigned int zone = page_to_zone(pg); bool pg_offlined = false; @@ -1487,7 +1487,7 @@ static void free_heap_pages( !page_state_is(predecessor, free) || (predecessor->count_info & PGC_static) || (PFN_ORDER(predecessor) != order) || - (phys_to_nid(page_to_maddr(predecessor)) != node) ) + (page_to_nid(predecessor) != node) ) break; check_and_stop_scrub(predecessor); @@ -1511,7 +1511,7 @@ static void free_heap_pages( !page_state_is(successor, free) || (successor->count_info & PGC_static) || (PFN_ORDER(successor) != order) || - (phys_to_nid(page_to_maddr(successor)) != node) ) + (page_to_nid(successor) != node) ) break; check_and_stop_scrub(successor); @@ -1574,7 +1574,7 @@ static unsigned long mark_page_offline(s static int reserve_heap_page(struct page_info *pg) { struct page_info *head = NULL; - unsigned int i, node = phys_to_nid(page_to_maddr(pg)); + unsigned int i, node = page_to_nid(pg); unsigned int zone = page_to_zone(pg); for ( i = 0; i <= MAX_ORDER; i++ ) @@ -1794,7 +1794,7 @@ static void _init_heap_pages(const struc bool need_scrub) { unsigned long s, e; - unsigned int nid = phys_to_nid(page_to_maddr(pg)); + unsigned int nid = page_to_nid(pg); s = mfn_x(page_to_mfn(pg)); e = mfn_x(mfn_add(page_to_mfn(pg + nr_pages - 1), 1)); @@ -1869,7 +1869,7 @@ static void init_heap_pages( #ifdef CONFIG_SEPARATE_XENHEAP unsigned int zone = page_to_zone(pg); #endif - unsigned int nid = phys_to_nid(page_to_maddr(pg)); + unsigned int nid = page_to_nid(pg); unsigned long left = nr_pages - i; unsigned long contig_pages; @@ -1893,7 +1893,7 @@ static void init_heap_pages( break; #endif - if ( nid != (phys_to_nid(page_to_maddr(pg + contig_pages))) ) + if ( nid != (page_to_nid(pg + contig_pages)) ) break; } @@ -1934,7 +1934,7 @@ void __init end_boot_allocator(void) { struct bootmem_region *r = &bootmem_region_list[i]; if ( (r->s < r->e) && - (phys_to_nid(pfn_to_paddr(r->s)) == cpu_to_node(0)) ) + (mfn_to_nid(_mfn(r->s)) == cpu_to_node(0)) ) { init_heap_pages(mfn_to_page(_mfn(r->s)), r->e - r->s); r->e = r->s; --- a/xen/include/xen/numa.h +++ b/xen/include/xen/numa.h @@ -1,6 +1,7 @@ #ifndef _XEN_NUMA_H #define _XEN_NUMA_H +#include #include #define NUMA_NO_NODE 0xFF @@ -68,12 +69,15 @@ struct node_data { extern struct node_data node_data[]; -static inline nodeid_t __attribute_pure__ phys_to_nid(paddr_t addr) +static inline nodeid_t __attribute_pure__ mfn_to_nid(mfn_t mfn) { nodeid_t nid; - ASSERT((paddr_to_pdx(addr) >> memnode_shift) < memnodemapsize); - nid = memnodemap[paddr_to_pdx(addr) >> memnode_shift]; + unsigned long pdx = mfn_to_pdx(mfn); + + ASSERT((pdx >> memnode_shift) < memnodemapsize); + nid = memnodemap[pdx >> memnode_shift]; ASSERT(nid < MAX_NUMNODES && node_data[nid].node_spanned_pages); + return nid; } @@ -102,6 +106,15 @@ extern bool numa_update_node_memblks(nod paddr_t start, paddr_t size, bool hotplug); extern void numa_set_processor_nodes_parsed(nodeid_t node); +#else + +static inline nodeid_t __attribute_pure__ mfn_to_nid(mfn_t mfn) +{ + return 0; +} + #endif +#define page_to_nid(pg) mfn_to_nid(page_to_mfn(pg)) + #endif /* _XEN_NUMA_H */