From nobody Thu Apr 2 22:25:45 2026 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; arc=pass (i=1 dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1774515142; cv=pass; d=zohomail.com; s=zohoarc; b=G4oTgfr4W+YkN2EcfaOSCoyNnqzJm978KESftJTzppfAs2spJeS9+LDfar/MD/vQ7+mCaEtFYvBTpDvQAyPfjrsMXHZiVwUyhirFEMt7V3NaRetYwoSkgAGHPBvhg/3nvZNg9MW3PyI0qZQQoziru9qzWAsjcAqzWN2MH01m63Q= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774515142; 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=kZ1xpzEDrW0cINW1Khcas9uTksBFZTXi7/cO4ecCji4=; b=aTsj9k1PTXsJOg9ftil2zTLnegTuSoNvDdYNkvb4xa07vzw/JxG5o+ECL9Dc+et879Xns7dkA+oJpi+PL6I5gCGHmiL/62otWWFWRagw7XltjkXxdNxrawjzlu14cGmZVHlZy8spTmlh5/6J9xNC92cL8LJ0fRz7r7wJFFmq8I8= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=citrix.com); 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 1774515142575726.0199211449136; Thu, 26 Mar 2026 01:52:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1263521.1555439 (Exim 4.92) (envelope-from ) id 1w5gRf-0003dk-8D; Thu, 26 Mar 2026 08:52:03 +0000 Received: by outflank-mailman (output) from mailman id 1263521.1555439; Thu, 26 Mar 2026 08:52:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w5gRf-0003dd-3z; Thu, 26 Mar 2026 08:52:03 +0000 Received: by outflank-mailman (input) for mailman id 1263521; Thu, 26 Mar 2026 08:52:02 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w5gRd-0003QQ-Vb for xen-devel@lists.xenproject.org; Thu, 26 Mar 2026 08:52:02 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w5gRd-00FZYJ-Bb for xen-devel@lists.xenproject.org; Thu, 26 Mar 2026 09:52:01 +0100 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c4f3ab-5cb7-0a2a0a5109dd-0a2a45049bf0-14 for ; Thu, 26 Mar 2026 09:52:01 +0100 Received: from [40.93.201.24] (helo=CY3PR05CU001.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c4f3ae-c823-0a2a45040019-285dc9187e5b-4 for ; Thu, 26 Mar 2026 09:52:00 +0100 Received: from CH7PR03MB7860.namprd03.prod.outlook.com (2603:10b6:610:24e::14) by CH0PR03MB6130.namprd03.prod.outlook.com (2603:10b6:610:b9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.21; Thu, 26 Mar 2026 08:51:58 +0000 Received: from CH7PR03MB7860.namprd03.prod.outlook.com ([fe80::f5ba:35df:1c9f:b343]) by CH7PR03MB7860.namprd03.prod.outlook.com ([fe80::f5ba:35df:1c9f:b343%4]) with mapi id 15.20.9745.022; Thu, 26 Mar 2026 08:51:58 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ixNEF9S7/WD2t0p0E7Z2MvBrV7GdDsKKRz8FkckyZGJP4qRjLaoP1eYWKjC1QSaxntUQKxCtY6EzlxLh06jV8VCInL6b4tXOqeQ1he75eqXTVxFzjJ2wHOEudzHHk3KT3C5PG3Q3wUWV7y8Xux0jmqetK5wqAZiuog8mapRWJh2IE/LEXwf1VjN5gFxSCyBjJ7di83AgdMbOmCI++j2XDETMZLjCpfIKTmSZoAaTMFySnAHJ7+UMhWOI+lfQZnLv+5aZsqQOuVqCt63sfHRkTghrsph3yumOb1iAwf9WRo3s685W8SHU1DDLAtGwx2oUGYf/WfQefZitVJs1brV/pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=kZ1xpzEDrW0cINW1Khcas9uTksBFZTXi7/cO4ecCji4=; b=eNcuihLyHMR5QnKVmbBTmAEA9LPuhmFCy1aMHWrU2U2ZlCkGtlNoLp3vLvV9YvLfBsHVfWflSQ+VvZHhivnUvJWw/tfJaATee3pE5AaDwErjXWizeKVPAuTx9dUC9TwBcGP9hPzlHFI/+Fvto3e8TdBNigTPGvzrRG90sA90Bigpp6+hqt2yQxMAZD2Hu9JlX2uVJVGaW8M5VV/RqXr7hlUOxKAE2Nb3YAPJ9WeXzp8lEYH+X1GHv8pIQHx3CTDscaCH6tNOCn1sVSJOG896DzF91j/Jl0xPQNqzGfZfzzN8QISg7bh3+k02ZOdAC1iXoQsEMDFLGSrprm8+l6Bttg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kZ1xpzEDrW0cINW1Khcas9uTksBFZTXi7/cO4ecCji4=; b=G/e2I45xT77TvltnP5wP9pgjYa1e1EIpAItskEtqV6JJKwDR5UUwzNHCQeb4/Y/ZmWpOXJb255FVodNa+Q0NRB23NUGnwWN5OvZb31uZGWIebdZoWu49K8H2MfZRv6EknAUuXMWr/X1o1dsKyU+o0PZ531xgZudeO48EQTf9Wjc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini , Ayden Bottos Subject: [PATCH v2 1/3] xen/mm: don't unconditionally clear PGC_need_scrub in alloc_heap_pages() Date: Thu, 26 Mar 2026 09:51:43 +0100 Message-ID: <20260326085145.61380-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260326085145.61380-1-roger.pau@citrix.com> References: <20260326085145.61380-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR1P264CA0016.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:2e::21) To CH7PR03MB7860.namprd03.prod.outlook.com (2603:10b6:610:24e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH7PR03MB7860:EE_|CH0PR03MB6130:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c3f3dd9-fd7e-429c-f791-08de8b14f01b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: k8chdTFuHChl3+OOkx+z92ASZPXRafM8TWB9CztnM9KfInOSXYqUrBa9H5XuZCfeGQklStr+xrqQ2sOkaQN/yYbZ9MSSZiXjseuzU3GwnZMaQb1SfhFZj9YaiH98oTqHM+u1oSmPjjbZs8k6RGfYDZ5qVfs8D5ow4Ormp5iqDBNchAzX1As5N+BnbtuMQfDFFSUJIkYqplA4cda8izKR0TJv1zkHxpP1LQNRciKdtJscV5TS0YaEwM4T+FP8AIGYnXz3lbyCqGRx0gXA6AHQGgljrFe8eyfNhy37GdFWzaOJp4xCEgrnGi38z+AA5LIUmSoBx9iI7nnJAbwj2eJyCvGlfF84UwxR//cM3Yzf8q2RULH7rNFKoq2pX8h68oIiz6Z3Y/b+bbIFF4wNG/Jpd1KeG0eQTb9ky2IjNUsc3FDKKYxFfmUVMtSSqdfm+Kc7tvLHQjjKqd2S3ErPHh227Fqm85LhUjf4hDHDdAswO0ggZn+7mX7ad2RgdFBbWoGTS0iOW48gW8wPE1Dv5fDWMnepE9UcB9kgkFb7nOb0xEQSy6FLHNbIKPohlFLhkvLDdjdBuSJtDx2RJgvJ/phvYxrnUkZFY0O3R6byEkDX/9eZtcvc4a58YWbl71ju6AQsz74CpBiDzvfvKxNJymN6UdomdbP4mwL297OIXLDk/YOJB9uHG+ppepVAz3nu+k0gCvNCiDPKWihSWIzMrsUXCz4akBTwUCBjFBhJ2PUzzco= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH7PR03MB7860.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VjliVEg2c2JNNUswa1dDa3ZXdFVaYjh2Qyszc2NERmtEOHFSaWV0Z0kyS09X?= =?utf-8?B?cXpHQnR5SlJRUTArSnpiZ2VqUmdMcVpEbGdzY0NxalhiUlRBRTNwS0VkTUR6?= =?utf-8?B?Umo4UExvTmVwRm1nOElaRmdvVWJZV0FhaUt5NFliTEdRVm9QaUp6aVhzM2pp?= =?utf-8?B?UlcxSzJqcUU5eVh0RHNJOVU2UFVtSXJEUFNzQ2pJcGRJbFZLOWxoZzVMTmFx?= =?utf-8?B?b2FxZFlkY3VwNnRCcEo0THNGMFg0M1ZKMng1SVUxbGlzY2RvQksvQTcwYXVz?= =?utf-8?B?eFpaL3MxdUsxSk96dm1mQWIxUFNpQ1JUSXR0NFBBaE1CeUNCUlNha3RQb2FQ?= =?utf-8?B?eXJWaEpGbnlVN3I0MkV2Q2xYZEJaVDV6UUU5aFlpeTF1WU81QWRTZlc5cjMw?= =?utf-8?B?R2VOWTg1aytwYllpb2Z2QjZFR2xNQTNBd0xNaDVieVZDME0zREMwSC9sNU9u?= =?utf-8?B?bzhLQXhLZWNGMm54VWVQNHlWZnl3TldEUDlqZGQwdGNsQjRFNmU3RVlVc0xH?= =?utf-8?B?Y3U2V0FCRjIwamVXQURUakJSWnJaL0l1eG4xNjRuc0ZXOEhNNWdWM0k5bVVO?= =?utf-8?B?U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CrossTenant-Network-Message-Id: 2c3f3dd9-fd7e-429c-f791-08de8b14f01b X-MS-Exchange-CrossTenant-AuthSource: CH7PR03MB7860.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2026 08:51:57.9096 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9aN7lAJfHuYPPSfC8K0YJZNq6nj9q9AFX532+4S7I99SwafmnCLtCHi70BAh3uvH3CW0O9dbQWyMDKK7ntUwVg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR03MB6130 X-purgate-ID: tlsNG-ebf023/1774515121-B3A969D1-C722C90D/0/0 X-purgate-type: clean X-purgate-size: 4706 X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1774515143987154100 alloc_heap_pages() will unconditionally clear PGC_need_scrub, even when MEMF_no_scrub is requested. This is kind of expected as otherwise some callers will assert on seeing non-expected flags set on the count_info field. Introduce a new MEMF bit to signal to alloc_heap_pages() that non-scrubbed pages should keep the PGC_need_scrub bit set. This fixes returning dirty pages from alloc_domheap_pages() without the PGC_need_scrub bit set for populate_physmap() to consume. With the above change alloc_domheap_pages() needs an adjustment to cope with allocated pages possibly having the PGC_need_scrub set. Fixes: 83a784a15b47 ("xen/mm: allow deferred scrub of physmap populate allo= cated pages") Reported-by: Ayden Bottos Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- xen/common/memory.c | 3 ++- xen/common/page_alloc.c | 31 ++++++++++++++++++++++--------- xen/include/xen/mm.h | 3 +++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 918510f287a0..f0ff1311881c 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -345,7 +345,8 @@ static void populate_physmap(struct memop_args *a) unsigned int scrub_start =3D 0; unsigned int memflags =3D a->memflags | (d->creation_finished ? 0 - : MEMF_no_scrub); + : (MEMF_no_scrub | + MEMF_keep_scrub= )); nodeid_t node =3D (a->memflags & MEMF_exact_node) ? MEMF_get_node(a->mem= flags) : NUMA_NO_NODE; diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 588b5b99cbc7..1316dfbd15ee 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -989,6 +989,8 @@ static struct page_info *alloc_heap_pages( ASSERT(zone_lo <=3D zone_hi); ASSERT(zone_hi < NR_ZONES); =20 + ASSERT(!(memflags & MEMF_keep_scrub) || (memflags & MEMF_no_scrub)); + if ( unlikely(order > MAX_ORDER) ) return NULL; =20 @@ -1110,17 +1112,26 @@ static struct page_info *alloc_heap_pages( { bool cold =3D d && d !=3D current->domain; =20 - for ( i =3D 0; i < (1U << order); i++ ) + if ( !(memflags & MEMF_no_scrub) ) { - if ( test_and_clear_bit(_PGC_need_scrub, &pg[i].count_info) ) + for ( i =3D 0; i < (1U << order); i++ ) { - if ( !(memflags & MEMF_no_scrub) ) + if ( test_and_clear_bit(_PGC_need_scrub, &pg[i].count_info= ) ) + { scrub_one_page(&pg[i], cold); - - dirty_cnt++; + dirty_cnt++; + } + else + check_one_page(&pg[i]); } - else if ( !(memflags & MEMF_no_scrub) ) - check_one_page(&pg[i]); + } + else + { + for ( i =3D 0; i < (1U << order); i++ ) + if ( (memflags & MEMF_keep_scrub) + ? test_bit(_PGC_need_scrub, &pg[i].count_info) + : test_and_clear_bit(_PGC_need_scrub, &pg[i].count_in= fo) ) + dirty_cnt++; } =20 if ( dirty_cnt ) @@ -2696,8 +2707,10 @@ struct page_info *alloc_domheap_pages( =20 for ( i =3D 0; i < (1UL << order); i++ ) { - ASSERT(!pg[i].count_info); - pg[i].count_info =3D PGC_extra; + ASSERT(!(pg[i].count_info & + ~((memflags & MEMF_keep_scrub) ? PGC_need_scrub + : 0UL))); + pg[i].count_info |=3D PGC_extra; } } if ( assign_page(pg, order, d, memflags) ) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index d80bfba6d393..5e786c874a73 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -208,6 +208,9 @@ struct npfec { #define MEMF_no_refcount (1U<<_MEMF_no_refcount) #define _MEMF_populate_on_demand 1 #define MEMF_populate_on_demand (1U<<_MEMF_populate_on_demand) +/* MEMF_keep_scrub is only valid when specified together with MEMF_no_scru= b. */ +#define _MEMF_keep_scrub 2 +#define MEMF_keep_scrub (1U << _MEMF_keep_scrub) #define _MEMF_no_dma 3 #define MEMF_no_dma (1U<<_MEMF_no_dma) #define _MEMF_exact_node 4 --=20 2.51.0 From nobody Thu Apr 2 22:25:45 2026 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; arc=pass (i=1 dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1774515148; cv=pass; d=zohomail.com; s=zohoarc; b=IVwxXmdgCyGuO5ZLqTxCKPDF1SpDuRO3JJ1C1UkLFDoAjY5JwCvhmLwRO9v5Lh+Q14igMyIVS0WocPu09apakhHzEfljkanJsunscy1RPPc1r169fVbFPcBYr/TL0K0xYZ2wSDBJ6xRVgXQ269VexMpmZVZkNr1EpVQrT603XDs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774515148; 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=UlSCfR/RG1m/YuILyUlHdFZCze5KGIHSmla47GQ4Db0=; b=aIMfAb5Q6vzunXzXfhCKpDjxj3IFgUp8UJPBcAOfDUn0qGfF81zSICcndcCVNRrpQGswpkh7H5hCYiKwxCFirgWhoZqE62UObHdQgcjAQ8lYJEHdy1rg2gcMxuqjStC6uy0L8jZHWyolt2aT/O4kdu9XSl/HTPtZET9uCXXxsfI= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=citrix.com); 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 1774515148081716.3437078895955; Thu, 26 Mar 2026 01:52:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1263522.1555447 (Exim 4.92) (envelope-from ) id 1w5gRl-0003uv-EY; Thu, 26 Mar 2026 08:52:09 +0000 Received: by outflank-mailman (output) from mailman id 1263522.1555447; Thu, 26 Mar 2026 08:52:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w5gRl-0003uo-BH; Thu, 26 Mar 2026 08:52:09 +0000 Received: by outflank-mailman (input) for mailman id 1263522; Thu, 26 Mar 2026 08:52:07 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w5gRj-0003t7-Lo for xen-devel@lists.xenproject.org; Thu, 26 Mar 2026 08:52:07 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w5gRj-00HEad-1f for xen-devel@lists.xenproject.org; Thu, 26 Mar 2026 09:52:07 +0100 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c4f3b0-e002-0a2a0a5209dd-0a2a4509a5ea-24 for ; Thu, 26 Mar 2026 09:52:07 +0100 Received: from [40.107.208.54] (helo=PH0PR06CU001.outbound.protection.outlook.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c4f3b5-e484-0a2a45090019-286bd03694a7-3 for ; Thu, 26 Mar 2026 09:52:06 +0100 Received: from CH7PR03MB7860.namprd03.prod.outlook.com (2603:10b6:610:24e::14) by CH0PR03MB6130.namprd03.prod.outlook.com (2603:10b6:610:b9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.21; Thu, 26 Mar 2026 08:52:02 +0000 Received: from CH7PR03MB7860.namprd03.prod.outlook.com ([fe80::f5ba:35df:1c9f:b343]) by CH7PR03MB7860.namprd03.prod.outlook.com ([fe80::f5ba:35df:1c9f:b343%4]) with mapi id 15.20.9745.022; Thu, 26 Mar 2026 08:52:02 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ypyo5p1GneAEZA85Iprm2bHy7hSS2X072Tjh9AxAe6WTc56oZ73GQFkKNk4IqqM/stpgDH5LgdmTWrjZ2bMk2CHWyobl9+/WAHrCUOI9Fp2BXN2so5QBtfL8iRV57U46ZdgMuz/MUmTmq80jJEhC7fWN6aDJuTDl6W25GezvUqF7FTQ6TmxeMdf6vIiWyvuyfnoED4/d14UrPKVgsZmD13Cx4rQjZ1sELSD+dTyAQsY7LqfkBl42BYlRvg2fDdvIvh1Yw4tdK9KvkjBjGWn5Xk9OUYxrIA8nbg/hRfnxiJ9Q70TcnzNf+F5qQuVzOAXIt5Z/I4mXtwewlg5sfJg1IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=UlSCfR/RG1m/YuILyUlHdFZCze5KGIHSmla47GQ4Db0=; b=dXWNYkjW4lk/u1FME7PpmB3q2Z52+W4YUOTz+mic1b8oNG93kq+FHSzQq2uPj5l2rjd8v8nyqljEbHjio96/Ppwmp1gAGUbNH1RCf6Opih8MDfksbU/NQ9dHnEAh6FY3sGQ2pdJsDNipU76rzMcCZJ71wmLBubcOASyiD6r63rxY4wBBWBM6S5q2J2GyA6Vl8d6tefFEHGdZggAg61EzyDektUmpr0as+fpYJ//hCSMnzqDvi8bD6av7cDQhOlp+Ax0ryPtV+cyMN2zMSeDqCkMOxUUm4zgiSKpGFQs5HOGko+Td3GZzD12FZWAs7RBCu0A5Qbtyu1KEC79DfafCMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UlSCfR/RG1m/YuILyUlHdFZCze5KGIHSmla47GQ4Db0=; b=cCWrBBg6ll8zBbg6N17LqB+kJJxU9QEofK/9uPFMFNs5I8SfOXBc3LmDRxR+cXpeBYiowo32QOn8GC7sILwvrs+FQ0qpoqUZCCg3jcd9pjkdADQVaZFByXBBt2gJZYAzHacvCM/ZYzW2wM0sITo+QPn4eetf+sLO5xAUb7e8khk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v2 2/3] xen/mm: do not assign pages to a domain until they are scrubbed Date: Thu, 26 Mar 2026 09:51:44 +0100 Message-ID: <20260326085145.61380-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260326085145.61380-1-roger.pau@citrix.com> References: <20260326085145.61380-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR1P264CA0048.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:3e::17) To CH7PR03MB7860.namprd03.prod.outlook.com (2603:10b6:610:24e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH7PR03MB7860:EE_|CH0PR03MB6130:EE_ X-MS-Office365-Filtering-Correlation-Id: 9615aa61-7a6e-4f46-1807-08de8b14f29a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: cl4vQFqyQr76WQPmHdlwPfeLTC3aZ1pYsqdqtnzIRkpkUF+f2SIV7xWoafNjjg/ec0jYsAb4YIOtX/1EHV60nt6iERSORSpdU4jcX6gpLZ33U9bXq1DGf45tXNpvcslpsNvwz+b3XBiwf7FsY3xfyo+gclpmZvbjAhTUWT9DDZC711peDvgJuo5UtXyCwG5oT8buWg8gQQaaDJr0Dj6F7cfsjQLBu3fRJ5fpszuNR1MuBg6xt0MVyeOYxftDzKvUCcftb5h77vXTBP8SeUQQnMHgKdHbu/mvhDmQv0ji81DbZAhys/t8nsDms2hpbMOHhii6+aJyqocJMD4IRpbJbwksjf5VgEufkL9JrDA4MWYxv8H7ebCp1XIwE6gPIzhGqm3O3rgobSB0GhBpfOGTAa/qU01Gv5V8LnNm2JoEQDFA6q9rdYMyJrtfO4aUOgjmIeFKI4z09Fh5vNCdu1BeYahFh80/6VOWCbHkVXhCoTPr1dyA/KvqDCz3W9XB/gLzlR3afZ9rZtTI2tEhwAe/X5oVOx2X6wFym10C9T71ROyRBEY/ESGwjzIGM43kPRQ4G91cZQ04+WGyINbJWuGt8qO9Yc0LIxwY3hstTjWCRT6YmEwLPvD9+lxFc3eHgswxLREMJuVx8rF+5RifgMAj2HggaMu+FkQK503yb43D2ft/pGbly9u9tjt8aABFkn04Qr9wSJnKVy6CK+Sj+uzi3Pki6n9uRe7PFv8WEycFFLE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH7PR03MB7860.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?S01XZ3c2WFZNckl5d21BcWF6WkNZVHJkZEd0c1pHWHNsMTNsaTRFS1M4ODdE?= =?utf-8?B?VklqMFZnQ3pVWFMxOG1kdEtrKzE3dG9CWVFMdkJIdC9KK3FxZ2NCV3p3Y3VI?= =?utf-8?B?OWFUMkVGRUVtcVk4UnRObU1VdmdjRGxvZjVGUTU5QkFpcUk5dHZjdUlTZ21F?= =?utf-8?B?TEFVVkVCRlZiYzBud1RGbFNKQmRDb3duSDJZcUIvL3ZweG80YlBtRTg3VE1C?= =?utf-8?B?Ym5DSHBRNDlnem92S2tXVTd2UFJF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?= =?utf-8?B?RVFyTmRnZGtEQk0zbEFZZWFUK2xZWmpxWWNaVTArZklTWXRJaisrOGJGMzVG?= =?utf-8?B?Y1ZuZzg0SW55REl4Z1BRUmVyOXhxZUJzaXEvMWpIcDU3UHdQZzJ3bkYwRUJY?= =?utf-8?B?QnEwbkNjcVN2dEVjZ3NjV0M4SEF2dGNCUGhtTlJWZ0FQNkRrWUhKZHM0a2Zl?= =?utf-8?B?VENVQjcvOUlvM3VUTitQank2VkNiVW1GNWI3cmRzRUdMZ1ZINjVnZFk0RTJY?= =?utf-8?B?Z1ArcXQ1RWpVTTAvSEVCYUxQZXZoZ0FIemZnV1Jub3RCVkVGZ0k1QT09?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9615aa61-7a6e-4f46-1807-08de8b14f29a X-MS-Exchange-CrossTenant-AuthSource: CH7PR03MB7860.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2026 08:52:02.0813 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Hc7UuGB1w+HlWGIzLPILOsocM/k5wcPGTF/yoXgj9fgrSyBp1m008D3yaQKwVc6ZAJF+zVlxgk7pMmH1nGekag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR03MB6130 X-purgate-ID: tlsNG-bad1c0/1774515126-61AB4A73-5CF8E391/0/0 X-purgate-type: clean X-purgate-size: 3789 X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1774515149591158500 Assigning pages to a domain make them the possible target of hypercalls like XENMEM_decrease_reservation ahead of such pages being scrubbed in populate_physmap() when the guest is running in PV mode. This might allow pages to be freed ahead of being scrubbed for example, as a stubdomain already running could target them by guessing their MFNs. It's also possible other action could set the page type ahead of scrubbing, which would be problematic. Prevent the pages pending scrub from being assigned to the domain, and only do the assign once the scrubbing has finished. This has the disadvantage that the allocated pages will be removed from the free pool, but not yet accounted towards the domain consumed page quota. However there can only be one stashed page in that state, and it's maximum size is bounded by the memop-max-order option. This is not too different from the current logic, where assigning pages to a domain (and thus checking whether such domain doesn't overflow it's quota) is also done after the memory has been allocated and removed from the pool of free pages. Fixes: 83a784a15b47 ("xen/mm: allow deferred scrub of physmap populate allo= cated pages") Reported-by: Jan Beulich Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- xen/common/memory.c | 6 ++++++ xen/common/page_alloc.c | 9 ++++++++- xen/include/xen/mm.h | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index f0ff1311881c..1ad4b51c5b02 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -388,6 +388,12 @@ static void populate_physmap(struct memop_args *a) goto out; } } + + if ( assign_page(page, a->extent_order, d, memflags) ) + { + free_domheap_pages(page, a->extent_order); + goto out; + } } =20 if ( unlikely(a->memflags & MEMF_no_tlbflush) ) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 1316dfbd15ee..b1edef87124f 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2713,7 +2713,14 @@ struct page_info *alloc_domheap_pages( pg[i].count_info |=3D PGC_extra; } } - if ( assign_page(pg, order, d, memflags) ) + /* + * Don't add pages with the PGC_need_scrub bit set to the domain, = the + * caller must clean the bit and then manually call assign_pages(). + * Otherwise pages still subject to scrubbing would be reachable u= sing + * get_page(). + */ + if ( !(memflags & MEMF_keep_scrub) && + assign_page(pg, order, d, memflags) ) { free_heap_pages(pg, order, memflags & MEMF_no_scrub); return NULL; diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 5e786c874a73..b80bec00c124 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -208,7 +208,12 @@ struct npfec { #define MEMF_no_refcount (1U<<_MEMF_no_refcount) #define _MEMF_populate_on_demand 1 #define MEMF_populate_on_demand (1U<<_MEMF_populate_on_demand) -/* MEMF_keep_scrub is only valid when specified together with MEMF_no_scru= b. */ +/* + * MEMF_keep_scrub is only valid when specified together with MEMF_no_scru= b. + * Allocations with this flag never assign the pages to the domain, the ca= ller + * must call assign_page() after the PGC_need_scrub bit is cleared if + * required. + */ #define _MEMF_keep_scrub 2 #define MEMF_keep_scrub (1U << _MEMF_keep_scrub) #define _MEMF_no_dma 3 --=20 2.51.0 From nobody Thu Apr 2 22:25:45 2026 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; arc=pass (i=1 dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1774515146; cv=pass; d=zohomail.com; s=zohoarc; b=dGfXu2KKUVEEGFOPhj4YtWtREfqNPHkzMqIVwG+rO0VpeT2w3tFOVx4dWC4LPbUMiXQmgOiCRCMjHnvNQrS3xkUqjN4H8YG1w8speP2WXbCavXpaXRCXZAhIQIIPDfOAryYkpnrKAJodBlE+0jy2iXOqMuNixdlzTwNv2fLtwWE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774515146; 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=NRuxAg7+DFWaBUvv3afEF63Z3k/Yz3QGkGiV9EBbvyo=; b=ec13OffXcULuH2dnQot96mQD7zP2j8iqBf7g9qWwAO+2Aoufk5uXTuuEeMFcAdYxIRsrfkQijiC8xlgXstX3gDehlakb/uGiYhKO5R20qvmhV41ZDydo54kEbaWGspAmxlmWn+UZNuepFXaX8Eoa5duL4fyOabNCEQr+GKcdopI= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=citrix.com); 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 1774515146173265.3345733359637; Thu, 26 Mar 2026 01:52:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1263524.1555456 (Exim 4.92) (envelope-from ) id 1w5gRm-000492-L8; Thu, 26 Mar 2026 08:52:10 +0000 Received: by outflank-mailman (output) from mailman id 1263524.1555456; Thu, 26 Mar 2026 08:52:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w5gRm-00048v-Hx; Thu, 26 Mar 2026 08:52:10 +0000 Received: by outflank-mailman (input) for mailman id 1263524; Thu, 26 Mar 2026 08:52:08 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w5gRk-0003uC-Nu for xen-devel@lists.xenproject.org; Thu, 26 Mar 2026 08:52:08 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w5gRk-00HEad-3y for xen-devel@lists.xenproject.org; Thu, 26 Mar 2026 09:52:08 +0100 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c4f3b0-e002-0a2a0a5209dd-0a2a4509a5ea-32 for ; Thu, 26 Mar 2026 09:52:08 +0100 Received: from [40.107.208.54] (helo=PH0PR06CU001.outbound.protection.outlook.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c4f3b5-e484-0a2a45090019-286bd03694a7-4 for ; Thu, 26 Mar 2026 09:52:07 +0100 Received: from CH7PR03MB7860.namprd03.prod.outlook.com (2603:10b6:610:24e::14) by CH0PR03MB6130.namprd03.prod.outlook.com (2603:10b6:610:b9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.21; Thu, 26 Mar 2026 08:52:05 +0000 Received: from CH7PR03MB7860.namprd03.prod.outlook.com ([fe80::f5ba:35df:1c9f:b343]) by CH7PR03MB7860.namprd03.prod.outlook.com ([fe80::f5ba:35df:1c9f:b343%4]) with mapi id 15.20.9745.022; Thu, 26 Mar 2026 08:52:05 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BAl/0Wo4RO6Dp5ROoPlzt2DYDukI7FQdftIE2AUZlW+rG8i+XLNuwpd/zp//KogPrEjEsTpvfwiZqM0lfurctsITp1FsN4FJPaZQI2/D8dEad+WJpbzUBNSagoXkOrVDzM95qxC7w0fM38LzfZp6FdoXBeDdTr2z0t3W40Db6skaxshgJDZfkhRllrnyRNa16jS3RabdMFTMw+ZE3HxIMLkiKFQ7HG+FRZDAKKDxapJUsS9yQIzluCmxJhR4BHqZ/dbY2ZLf4E8YjOE0mYiRxYpHs/sDlRHiiwwJvTY1SCDvIfUdmTpTEfiwoIDSpqocQLEHxQh1TFiSipB2DeKOjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=NRuxAg7+DFWaBUvv3afEF63Z3k/Yz3QGkGiV9EBbvyo=; b=s5+9rhvNzvmH1pLCTsvebd9eznNYEASebndo8oYJ9M+0SylPkUwlMP0Jr20F8XlHh/HMTbZCEcKmljZszi4o17kp8PW2neywoK+8OJqbaHO3cJ5T3gE2ghc80sazKvGLVFrbJvzDyIUQfR9NiI5jCNGZZi6EMrCbIXoExStrcETaJYzN7OhfBq5E42FGOj9GJUHe4CWEQsqZyIlOZkQtpZ3/B5kary7zaY16WSzocF1RMWe1HqVTTT7dU9DjT4olBsJwe4VMBjwbMZhuRzl04Ilz9x5AteHxUfxmlvBtN3u4zH4Ld0qAo+J9gB43eUiXF1MAiVnGxYpRSeX5kQ6p+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NRuxAg7+DFWaBUvv3afEF63Z3k/Yz3QGkGiV9EBbvyo=; b=UNPL776QEzAfGZ26fR+oewYCQHcDyEtQFg2hhiYk0tuoSnT1Dr+lEp1jxeoGa4QkS8DHoYXXSovrGUej4X7Gi5+TwqBx/AdgqysBKP462mOArhDGjNPs0IMzy4sp/lOgCCSvJCZL7V0mLDfwnpAErFVexOEUqlDk4A24w+ahnLE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v2 3/3] xen/mm: improve freeing of partially scrubbed pages Date: Thu, 26 Mar 2026 09:51:45 +0100 Message-ID: <20260326085145.61380-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260326085145.61380-1-roger.pau@citrix.com> References: <20260326085145.61380-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR1P264CA0143.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:51::22) To CH7PR03MB7860.namprd03.prod.outlook.com (2603:10b6:610:24e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH7PR03MB7860:EE_|CH0PR03MB6130:EE_ X-MS-Office365-Filtering-Correlation-Id: b663659f-4802-4fa5-0797-08de8b14f4e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: xv5Fl0CrAzzSXUVDivKF/tsc1hLgXDFeu+CVRRJZTErI+TRzZtJC890FzyDf3FbSUz8G0B+tzrNqQDUOedyFsEkiX84TPqTqpJfGP8Fxf75U/VIsdDWOJ95Jc8orR1zW6fIQAhyLoRO+U1MXvxdWnP11FvF66hXG8zCCXzK+mCycr4Qyz/iRHG/sxHCdNvV4/h6SjyeluRTXAfbjCCejejj63txpEmKmEA5rR95o9eljNaWEmqZeD+m6iva8Rb3pDqQIeRw1W+XocD3Rebnymg85iI7Pjr1VFoiAlOu2sCVf6G/oi4V7oBX0+bAFf3xmGGYy4L+t6dS8qBeKVek88ZDUF7xOhFvBjlRvLOXua3JcxcAUgu0AwB1WSDH1SZ+L4jPYMuAGE36EFdpzZM5PPhNWBC5sHmnNaOLCmkIN5Fw9GNLisaoD6bSMww3B7NIV8mBbhAIGwlbYc0q7wvq9RTE4qWSaxEXI9LUO9V5V8INJiGVldoYy0L+WS1nLczoNdKeWsCKjeoVgKfyk37UDPorzze+W0bekwSROh7VQs10Z25gXjCjIBH4X/xVYBcSvXwPazesYBQQ70epxsUSc12f360/iraHjLaFvTUY2wyR33zj7rl4sJfpO6/AHhwKYpc5o2oWvLf3VTnltg4QRxWoVAiOydn1NFMt2AdyLqGBftCwiryig9K73eres3Yw3v9EyNUg1/dyc+BR/cx+mEmddJTdqKgvDGXhiGMqmvcU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH7PR03MB7860.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SVhvUWdXOFZyNmZvdEUyVmQ3b3Z1dUpYby8xRDNxZXNZbDlTdHBTdjhWbjZh?= =?utf-8?B?S2p1aEE2ekFtcU1PZ3hEZWFMU09vZHE3ZHVxS2RUV2F2NTJjYTZzb0p2UGZV?= =?utf-8?B?c1JUamQyMkxMSVZuQUZ5MHZ1TFlkVW1Wa21KbFcwT2JYMGRZV0duQXFEVzdi?= =?utf-8?B?MXZDQlJrNGlHUmZMZnI5dENabzRjZEFHa3hWWXdZNkFCajJQVXFXVmx4M2Rt?= =?utf-8?B?cU1FRWVkREpqeFRnOERaQm9IblU4QTRrKzkva2ZLZjkyOTc5dzF5dnZtM0RE?= =?utf-8?B?Smp5cGpEd2llZDRmeW1EZkVQZTR5K3hRUXoxY3B1QlgyWHhSdmIzYzNLQ0k4?= =?utf-8?B?eUZ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TBpWllDTHN4dG9tbVlHM2RPOW5lWVhWTzVu?= =?utf-8?B?WmI2dURUNUVlNzNweElrZEJxZmxDclcxWEFTd3h2WitSNFNKUElsVmZIZzEw?= =?utf-8?B?bi9oTHpQQjFQTkgxWXlRcU8wZDBDenNXZklnaWRtQ21tdnQ3MFQxbEdHSExy?= =?utf-8?B?NjA0SXFCS014dzlYTVJCa2tiQk8vMDYxYlNodlBJeURDbWVZQUsvZz09?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: b663659f-4802-4fa5-0797-08de8b14f4e1 X-MS-Exchange-CrossTenant-AuthSource: CH7PR03MB7860.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2026 08:52:05.8482 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8UZrsKbBut4UlHxfk5eRXaaT5Nw3TpY57mY4aOV2rnOoJW2xJ0cPeTlue3Pq1PEZVD9RDcGxdVovRjJ0fCybRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR03MB6130 X-purgate-ID: tlsNG-bad1c0/1774515128-5AAACA73-DF0D5578/0/0 X-purgate-type: clean X-purgate-size: 4597 X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1774515147583154100 When freeing possibly partially scrubbed pages in populate_physmap() the whole page is marked as dirty, but that's not fully accurate. Since the PGC_need_scrub bit is preserved for the populate_physmap() allocation we can use those when freeing to detect which pages need scrubbing instead of marking the whole page as dirty. This requires exposing free_heap_pages() globally, and switching populate_physmap() to use it instead of free_domheap_pages(). Suggested-by: Jan Beulich Signed-off-by: Roger Pau Monn=C3=A9 --- Jan: I'm not sure if that's what you suggested in the review of v1. I've added your Suggested-by but I can drop it if that's not what you were thinking of. --- xen/common/memory.c | 6 +++--- xen/common/page_alloc.c | 16 +++++++++++++--- xen/include/xen/mm.h | 6 ++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 1ad4b51c5b02..68eef8291571 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -177,7 +177,7 @@ static void stash_allocation(struct domain *d, struct p= age_info *page, * interface is designed to be used for single-threaded domain creatio= n. */ if ( d->pending_scrub || d->is_dying ) - free_domheap_pages(page, order); + free_heap_pages(page, order, false); else { d->pending_scrub_index =3D scrub_index; @@ -210,7 +210,7 @@ static struct page_info *get_stashed_allocation(struct = domain *d, *scrub_index =3D d->pending_scrub_index; } else - free_domheap_pages(d->pending_scrub, d->pending_scrub_order); + free_heap_pages(d->pending_scrub, d->pending_scrub_order, fals= e); =20 /* * The caller now owns the page or it has been freed, clear stashed @@ -391,7 +391,7 @@ static void populate_physmap(struct memop_args *a) =20 if ( assign_page(page, a->extent_order, d, memflags) ) { - free_domheap_pages(page, a->extent_order); + free_heap_pages(page, a->extent_order, false); goto out; } } diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index b1edef87124f..8fc9b5a27f1b 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1529,13 +1529,13 @@ static bool mark_page_free(struct page_info *pg, mf= n_t mfn) static void free_color_heap_page(struct page_info *pg, bool need_scrub); =20 /* Free 2^@order set of pages. */ -static void free_heap_pages( - struct page_info *pg, unsigned int order, bool need_scrub) +void free_heap_pages(struct page_info *pg, unsigned int order, bool need_s= crub) { unsigned long mask; mfn_t mfn =3D page_to_mfn(pg); unsigned int i, node =3D mfn_to_nid(mfn); unsigned int zone =3D page_to_zone(pg); + unsigned int first_dirty =3D INVALID_DIRTY_IDX, dirty_cnt =3D 0; bool pg_offlined =3D false; =20 ASSERT(order <=3D MAX_ORDER); @@ -1552,6 +1552,13 @@ static void free_heap_pages( pg[i].count_info |=3D PGC_need_scrub; poison_one_page(&pg[i]); } + else if ( test_bit(_PGC_need_scrub, &pg[i].count_info) ) + { + /* The caller might have returned pages pending scrub. */ + if ( first_dirty =3D=3D INVALID_DIRTY_IDX ) + first_dirty =3D i; + dirty_cnt++; + } =20 if ( pg->count_info & PGC_colored ) { @@ -1571,7 +1578,10 @@ static void free_heap_pages( pg->u.free.first_dirty =3D 0; } else - pg->u.free.first_dirty =3D INVALID_DIRTY_IDX; + { + node_need_scrub[node] +=3D dirty_cnt; + pg->u.free.first_dirty =3D first_dirty; + } =20 /* Merge chunks as far as possible. */ while ( order < MAX_ORDER ) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index b80bec00c124..0b192caa07bc 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -153,6 +153,12 @@ unsigned long avail_node_heap_pages(unsigned int nodei= d); } while ( false ) #define FREE_DOMHEAP_PAGE(p) FREE_DOMHEAP_PAGES(p, 0) =20 +/* + * Most callers should use free_{xen,dom}heap_pages() instead of directly + * calling free_heap_pages(). + */ +void free_heap_pages(struct page_info *pg, unsigned int order, bool need_s= crub); + void scrub_one_page(const struct page_info *pg, bool cold); =20 int online_page(mfn_t mfn, uint32_t *status); --=20 2.51.0