From nobody Wed Sep 10 11:30:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1757262067; cv=none; d=zohomail.com; s=zohoarc; b=FBN/m4yjitIVGmTH1KTrdO8e9apdfqKLcVVUTLIAtwcA2ySYPYeJohXNyGuVtbDtqcXtcS3ve8XyONQTTkUScsMh5RA7oTOPccGytfupYHDLbZSQU9cqk6JdoRlM2c1WyGdTDpJr8YkDYPx/uX4PL040ti5dprBiTLB3Vb+qHjQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757262067; h=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=vBTzAM9dJn/x75BZsxvktFF5ekUsBrdK+iYKuv7j92Y=; b=k3AEA4KmrJZTHtpn+WEsK9Lt1V++MVe9cyDC81c/TQ6/FkwtXvJdgzuMkfJghEpxDYxMuHLxev/RSkWTKt8sTLZG5uvYRbUg4+9UsMqZBdbpGUKprtNVYV+N/OBal7C5vD8Qp/haAQjKxdlhdphBKjuH0SdKEqcRyh2RWADF+0Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1757262067800475.49864868660325; Sun, 7 Sep 2025 09:21:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1114194.1461344 (Exim 4.92) (envelope-from ) id 1uvI8K-0004JQ-DA; Sun, 07 Sep 2025 16:20:52 +0000 Received: by outflank-mailman (output) from mailman id 1114194.1461344; Sun, 07 Sep 2025 16:20:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uvI8K-0004JB-8V; Sun, 07 Sep 2025 16:20:52 +0000 Received: by outflank-mailman (input) for mailman id 1114194; Sun, 07 Sep 2025 16:20:51 +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 1uvI42-00009z-Nd for xen-devel@lists.xenproject.org; Sun, 07 Sep 2025 16:16:26 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 00344c93-8c06-11f0-9809-7dc792cee155; Sun, 07 Sep 2025 18:16:25 +0200 (CEST) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-b046f6fb230so604182166b.1 for ; Sun, 07 Sep 2025 09:16:25 -0700 (PDT) Received: from MinisforumBD795m.phoenix-carat.ts.net ([2a02:1748:f7df:8cb1:5474:d7c3:6edd:e683]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b047b61cf00sm908263766b.15.2025.09.07.09.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Sep 2025 09:16:23 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 00344c93-8c06-11f0-9809-7dc792cee155 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1757261784; x=1757866584; 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=vBTzAM9dJn/x75BZsxvktFF5ekUsBrdK+iYKuv7j92Y=; b=Ehd7Nxq1zVQLYJAv33FDslPZN7BVOQLT/G0L4euiksG3FNcFkQ0utT+d1mf0dMLsEV K+1SeIu2+IakYyBvM2k+6mlxir91mMcQORLcJFiiv9AnAmuUKlVmeap/+Vttj6g1U1lr lKvqmT0A24Yf+zGEXN7UtgGI8nRpelsjoMgVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757261784; x=1757866584; 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=vBTzAM9dJn/x75BZsxvktFF5ekUsBrdK+iYKuv7j92Y=; b=iE9jbJd4dFA8ve0fXZfkI8An9z9BfuMcS+SEukz2Qdg58X90CMSluIDRO36NqBBxNi vhJvpCJQX/FcXvb6k1TYLtO/0YPjie0DJCE7TVsGMZT7hpgCXRK8CRPaFOQgI1UuKNiU oZOTpbZqUWX+j5TfCmXp2PKX0TGMZV+MK+IWez3rN+9nDRs/U18rKYf+oiovXZAgYbhG ZHpNdelNolHE8XmoAlT8/afMq5x3KVLSGNPPJllaWNZG2orbekyUDxmKjd4gKP26JBB2 UVsLarcyHYJR4rPGbD4QEnHvmHDSEwUvJOt6prIDKe/2RD8KQ4R7MBA2wPSWfjKg+G1J 11Fg== X-Gm-Message-State: AOJu0Yzj3jBlSERwNX7qLmAyMKapd0SNaBJFsqFegjbpbvewly0n2SkR QB5skVRTa9Db4fq/wlqWizs8nFpH28zui2bp9ImyjzsOAUqKG0qHBmr+g8Gnn2mR8vtuXaEwY2m n047UIUY= X-Gm-Gg: ASbGncsIzNlbmovo48jc4vgobIdQjBp/ENa1qIfqAqCGLX1do5k+d+tPvl1zMQW8zAY BmF39m30e+LwuiTmdzcV82ACHWj47JlK/GoOhGi4ZdZvf0ckv1r4KJNowS2pecXnfFTPVICG2A8 jpbZT1v35Rfnjl1+Oe0vKKVxro2AvkOGklQV3r6U9kozVxQfyKGvqtEvMVmMOWYicpeAvx93oNv vJEaeiqmO5VvH3wPnUqtr7tIVKbstKxYtp/CoZvHjBfa537elEgQcRn01LSxoqwYSR9E0KxQSqi ok/9cRCpfnp5LpDQsypQ2b9O1lk7C8ODcYSt34AxNTJfmNpuJQcb+kekGQ4zJzT1U8zMVJHz6AN 8uPbQT9YVH1v51fgyj276vGNienp97C60TBWymEvfl5cUnwJ3KeEIbwznHcbLf9hEvUMsZdybBw k4iA== X-Google-Smtp-Source: AGHT+IFNkJmollUYz0E9myq+0ab1Fzt9pFOg5uIHhtER2VpUj1FgGRJDBcAtjSl+tX9M37Qw/YC6FA== X-Received: by 2002:a17:907:805:b0:afe:94d7:7283 with SMTP id a640c23a62f3a-b04932a2452mr1010424466b.32.1757261784279; Sun, 07 Sep 2025 09:16:24 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v3 6/7] xen/page_alloc: Protect claimed memory against other allocations Date: Sun, 7 Sep 2025 18:15:21 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1757262073008124100 Content-Type: text/plain; charset="utf-8" Extend get_free_buddy() to only allocate from nodes with enough unclaimed memory left, unless the allocation is made by a domain with sufficient claims on this node to cover the allocation. Signed-off-by: Marcus Granado Signed-off-by: Alejandro Vallejo Signed-off-by: Bernhard Kaindl --- Changes in v3: Rewritten based on a check by Marcus Granado which needs to be inside the NUMA node loop of get_free_buddy() to only allow it to allocating from NUMA nodes with enough unclaimed memory. It was originally only intented for when looping over all NUMA nodes, but the check also needs to be done when falling back to other nodes: I updated the check to be generic: Now, it used for all requests by integrating the check of the claim of the domain from Alejandro's can_alloc() helper into it. This fixes the issue that when falling back from a nodemask to allocate from (based on MEMF_get_node(memflags) or from d->node_affinity): When falling back to other NUMA nodes, still only allocate from nodes with enough unclaimed memory left, unless the allocation is made by a domain with sufficient claims on this node to cover the allocation. This makes the can_alloc() helper function obsolete, as the needed checks are done for the NUMA nodes as they are considered, not only for the orignally requested NUMA node (not just before searching). --- xen/common/page_alloc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index ebf41a1b33..b866076b78 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -980,9 +980,19 @@ static struct page_info *get_free_buddy(unsigned int z= one_lo, { zone =3D zone_hi; do { - /* Check if target node can support the allocation. */ - if ( !avail[node] || (avail[node][zone] < (1UL << order)) ) - continue; + unsigned long request =3D 1UL << order; + /* + * Check if this node is currently suitable for this allocatio= n. + * 1. It has sufficient memory in the requested zone and the + * 2. request must fit in the unclaimed memory of the node min= us + * outstanding claims, unless the allocation is made by a d= omain + * with sufficient node-claimed memory to cover the allocat= ion. + */ + if ( !avail[node] || (avail[node][zone] < request) || + (insufficient_memory(node, request) && + (!d || node !=3D d->claim_node || /* a domain with c= laims */ + request > d->outstanding_pages)) ) /* claim covers requ= est */ + continue; /* next zone/node if insufficient memory or cla= ims */ =20 /* Find smallest order which can satisfy the request. */ for ( j =3D order; j <=3D MAX_ORDER; j++ ) --=20 2.43.0