From nobody Thu Oct 30 22:46:57 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=1755343266; cv=none; d=zohomail.com; s=zohoarc; b=ckzadA1pHKzLtk+JYS46p4vzlVUbW8m+Wu9RPnxC2KCGKvCh4ay0WoeYvuDU6xi9tjWnarMlYm6a8C4Nj65SiYIOCdVnRi/UHcvF0R0cOx9PyB1k19nePYcZZpRg2Lcm4wUD7THKGaZAHJTu5xwu+zP9lxpZiuZcW5LqYgPPNBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343266; 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=5WfLnf5/kvCLxvLOEfumWxUHPhaPlVs8I4oO2kdVd+M=; b=kECDgVD3dRJQZq8U1qUIMcSdDGd5Ofr8L9b3+CdIdkjT+FCkRg2PPRSN0je1ZWg9j2IfaFgrMmhSu0aHHdtCsb3ceEIqW/N6V/7l8y0/KgGvTDXLC1ZZLQzOnkU/oJ1pNf7ox8v61VbznTB18DULR8uxOhzDjkSuK1F5N2oRjmQ= 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 1755343266533437.47390288736665; Sat, 16 Aug 2025 04:21:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084446.1443594 (Exim 4.92) (envelope-from ) id 1unExx-0006KD-8Z; Sat, 16 Aug 2025 11:20:53 +0000 Received: by outflank-mailman (output) from mailman id 1084446.1443594; Sat, 16 Aug 2025 11:20:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1unExx-0006K6-5p; Sat, 16 Aug 2025 11:20:53 +0000 Received: by outflank-mailman (input) for mailman id 1084446; Sat, 16 Aug 2025 11:20:52 +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 1unExw-0006Jf-6x for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:20:52 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1113acd7-7a93-11f0-a328-13f23c93f187; Sat, 16 Aug 2025 13:20:51 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-45a1abf5466so14764555e9.0 for ; Sat, 16 Aug 2025 04:20:51 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:20:50 -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: 1113acd7-7a93-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343251; x=1755948051; 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=5WfLnf5/kvCLxvLOEfumWxUHPhaPlVs8I4oO2kdVd+M=; b=LLQThDwUqjnplM/TESg62YCQZHjTwCzdqLtdNiKRmPVtDRIXhpWlOPEmtlqyTVpB/L CrNy6dZJcpjTD3nc8A+2efqgeoFyZ6psZglYAaCDZbo3dgQO0z4eOfJlJ/S18+eD/bgT VqhavyxEgG9Q9j/+UjPz0zWTMbFdfumse41Dg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343251; x=1755948051; 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=5WfLnf5/kvCLxvLOEfumWxUHPhaPlVs8I4oO2kdVd+M=; b=M/P0ptWKFNRKcVJjUPzDEKSX7xsnIvEH+Va4IBMa/aRoFK0qsMzESi2+le6wa3HKQ/ rxKv4C1S7FMj2+GX3uySYrDRbwq9Mb3CBY52Ytz1nXO885dD5l8P9H7VusQ/BUP3/IH8 irrqYIj684vO70mK/u424YEo8c5/YP+1MOT6mr5Als9r0Eg16mwpgCtajzmQ3i0NVoZP SAJrcMiXntlUBh/YpA7nbyN8WG3V/+0PB+BiWlp+f13en6eJrTX+nDMNjg0BO9Vye5Cg c3NUPh+p6XTN4iBo/q6NcquQnDwUYaMFUePc5cve5Vox7EgucmuGPXw+ea3zYr/UF4bg LqNA== X-Gm-Message-State: AOJu0YxvqMCyTBEqbDHpNwZRHenTo/wulEUpvYioGcW4ULP6UlTqSJA5 zgBnc3rQoEPsaa0UqARHyT5OvSikaAczYQRMxIkN2YL5bDc4BnAp6cEgcaNoHuzYhMenL9ebmHl JeFhMf+c= X-Gm-Gg: ASbGncs429WUsPzqvlpMLTpif8xOKbtXkgMDnwr/TiMvpUpbhsMaN2eIoP/kNfOJSz1 Uzjyb7NEWFCvsKSjGP+QSPeh6xTUppomSaQLt5qgPQ3/DN5TN++TOrqcFgnBS72W9d6fbyH6o1d WN7NxgTH1idijEpmjWIaHR7CFRrSxQqEam4nz7Dfqoj9QUPfTCPVZNNUIvPX7WODM38u3O17g77 zkjl6ClW2ZJNqBlpQGMdmuQtRa9fy+FubzIJYyaqk60EbkrgaErarvRIZbi7kpTILI8fc7pwTCo 9pOvDhSU4DokahAS54zYANup7aFkwz2fGaeoUWK3xCGesoHvvSexMQcJrPHHQC3grOfJSz3FwlH KO76CkzeBhBhtsvokVN/zfqAdP2gWN5XE6q96lh8tjU/LyNlW+Kx6XicHFZ9NE99mpg== X-Google-Smtp-Source: AGHT+IEzPs9FkQ63BOLIzEufxuBLYDjBbOgrJbqFTH4gdP1GhoFRqjout6kGca2aCgD/lZWY9mSK7Q== X-Received: by 2002:a05:600c:8b05:b0:459:eeee:2759 with SMTP id 5b1f17b1804b1-45a1b6c7e20mr80482885e9.14.1755343250703; Sat, 16 Aug 2025 04:20:50 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Alejandro Vallejo Subject: [PATCH v2 1/7] xen/page_alloc: Simplify domain_adjust_tot_pages for future changes Date: Sat, 16 Aug 2025 13:19:27 +0200 Message-ID: <5f417fea5ca8e4da0d4b9679103c3eff4bc92900.1755341947.git.bernhard.kaindl@cloud.com> 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: 1755343268595124100 Content-Type: text/plain; charset="utf-8" domain_adjust_tot_pages() is used to update the domain's total pages after allocating and freeing memory. Simplify the design for updating it for single and even more so for multi-node claims regarding the case where we could have allocated more memory than we had claims left. Replace it with min() to avoid reducing the outstadings claims by more than we had left to claim: When domain memory is freed, we skip changing the claim. Thus, this only handles reducing the claims after allocating. So, min() is fine. Signed-off-by: Bernhard Kaindl Cc: Alejandro Vallejo --- xen/common/page_alloc.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index ec9dec365e..e1ac22b9ed 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -510,8 +510,14 @@ static unsigned long avail_heap_pages( return free_pages; } =20 +/* + * Update the total number of pages and outstanding claims of a domain. + * - When pages were freed, we do not increase outstanding claims. + */ unsigned long domain_adjust_tot_pages(struct domain *d, long pages) { + unsigned long adjustment; + ASSERT(rspin_is_locked(&d->page_alloc_lock)); d->tot_pages +=3D pages; =20 @@ -519,23 +525,22 @@ unsigned long domain_adjust_tot_pages(struct domain *= d, long pages) * can test d->outstanding_pages race-free because it can only change * if d->page_alloc_lock and heap_lock are both held, see also * domain_set_outstanding_pages below + * + * If the domain has no outstanding claims (or we freed pages instead), + * we don't update outstanding claims and skip the claims adjustment. */ if ( !d->outstanding_pages || pages <=3D 0 ) goto out; =20 spin_lock(&heap_lock); BUG_ON(outstanding_claims < d->outstanding_pages); - if ( d->outstanding_pages < pages ) - { - /* `pages` exceeds the domain's outstanding count. Zero it out. */ - outstanding_claims -=3D d->outstanding_pages; - d->outstanding_pages =3D 0; - } - else - { - outstanding_claims -=3D pages; - d->outstanding_pages -=3D pages; - } + /* + * Reduce claims by outstanding claims or pages (whichever is smaller): + * If allocated > outstanding, reduce the claims only by outstanding p= ages. + */ + adjustment =3D min(d->outstanding_pages, (unsigned int)pages); + d->outstanding_pages -=3D adjustment; + outstanding_claims -=3D adjustment; spin_unlock(&heap_lock); =20 out: --=20 2.43.0 From nobody Thu Oct 30 22:46:57 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=1755343302; cv=none; d=zohomail.com; s=zohoarc; b=bfSu1ylsQNVXFOlYZbL0xccCF75Zv7wPhwNRMgfPEbHo89xZWfkzqM7sT6+u39bDAlKW5fHXb5Skp3FxQb1mSX0XF/YYOpCQbdESyPcQwa+NzAxM+jd0KnXsInVhfy6F4jeNodYomUTIrv4gbMDnfPlggGye6jS11/WWWoSTPHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343302; 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=NqLgWRTfSlSShI6W9CQEOmln3SxcjiGyydtrE7lJ0Xc=; b=aSubJvcSlHAG9M8ubTCQgLlLB7mX99AvTXsDLjm+9gozFaxPmC31IycnvKNhBbbzOPstkU6dQFp1ei/rg3clicFxjjMhqmI9GmqCEEEsCq0fZWT7A7GEj6bJA4Rxk5OGr4uxOBLdaH41J8QImIUwhVNRnypG8YxvAFdwO+xbroc= 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 1755343302937187.49053947392133; Sat, 16 Aug 2025 04:21:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084461.1443606 (Exim 4.92) (envelope-from ) id 1unEyY-0006uz-Jc; Sat, 16 Aug 2025 11:21:30 +0000 Received: by outflank-mailman (output) from mailman id 1084461.1443606; Sat, 16 Aug 2025 11:21:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1unEyY-0006us-Ej; Sat, 16 Aug 2025 11:21:30 +0000 Received: by outflank-mailman (input) for mailman id 1084461; Sat, 16 Aug 2025 11:21:29 +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 1unEyX-0006Jf-2O for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:21:29 +0000 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [2a00:1450:4864:20::32d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 27346c8e-7a93-11f0-a328-13f23c93f187; Sat, 16 Aug 2025 13:21:28 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-45a1b004a31so17014015e9.0 for ; Sat, 16 Aug 2025 04:21:28 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:21:27 -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: 27346c8e-7a93-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343288; x=1755948088; 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=NqLgWRTfSlSShI6W9CQEOmln3SxcjiGyydtrE7lJ0Xc=; b=iuSi+WBNoGCyrzKsXH7w+Dj28YWN+kRyNfTt1uUI+LfCzbNIoCpZjlrPnEn+eozYB7 cf2uX8lOVxvLeriHSgYY0gti2N6K/ghCf0tPm6ktIerHx6K5XCu1AeDqG45bWZto5l/t 3xoNlybI+UKeaiGJfGbIqZy+SaLlBrM/qtF5I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343288; x=1755948088; 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=NqLgWRTfSlSShI6W9CQEOmln3SxcjiGyydtrE7lJ0Xc=; b=jCxiPEAO3L/ZSuwUrTF+ES/IBd1MaFZr25r5urWWzoJqjHyCbIlYXsUwpQvjBUeM0m KX4U6TNFSH/8zgsiNX3g+5HDvDb4Vsy9TjB830YpoDKDTuj4VN5y67WmwvCl2u7hIW7c IWERYrSGxlgSVPRP/4RmHP2vEXbLZ+HW4lKKL62LDJWHWSp2UesAgziCfFu4EqQjfO+7 /DKSYgm7N75x4DL6pqNgtGlQFPtgw1ki8wvzagB9ZHjdAXQIX7KXUuamikDzHO0c75Ht 6eANI2LUUhaNJnPrYv0Px36svWqnNUHC64u4PMuD8uVz0BJNesoNzVmnfs3wr/BSfE47 DCMQ== X-Gm-Message-State: AOJu0YwnZwvGdzaa0ObZE/cdkIIoiAQB6IVm7l9ltjthzZpZPHroJqWu PGHpsYIRcg5GOxA8+mldL9FGqIoNTIj1Fwhvu0CyJ8fRHuE1jvMe9CWsV9UMbWmHwvO3Rao+zji bc4gCPXU= X-Gm-Gg: ASbGnctxcXXUV1dBJs0TZxr4iKgDdqJOIvXOpn8L2Phkfbv2XUSgBQ7BDcENhIG2KtH +3U04co1vgVavHkalf54/eNs7QZxVAOFk0UYMEQdjnXhMe2w0jryBVfYy3dEc9zhEjBRHtdYxVK L+ZWJspMasMTydqTa9J+K8mR3Rkx1anolp9sUCkAgeZh4vFbTrXKBIUBGTBYcEvsv0LmOZ+THyu pXuZ6U0NxJdYq/GB/AqsiCgJHsvufbj92/R27rdIUvRVIq7fjrF+D24j++IA6hbXHb5416WsB4W 2MYGGNvRwtOLedvSnA3s/PDOIZW+RCELAPn6jiBUBiWu1+nE3gWSVYYKq6X0fiGniJP91E540Gx YITs8U3ZWbe4tXuL9NjvHxeFpwWlT3owaTcT3gXsjYEveX3u29kaugE0= X-Google-Smtp-Source: AGHT+IEvBr5RnjHc3muBzso6mPDrnMFo7IOsVkET3qV1DzWggzJ+Lw/himDguhJV2TPdNORgbLRSIQ== X-Received: by 2002:a05:600c:4ed3:b0:459:dc92:b95f with SMTP id 5b1f17b1804b1-45a23323e44mr38796815e9.5.1755343287774; Sat, 16 Aug 2025 04:21:27 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Alejandro Vallejo Subject: [PATCH v2 2/7] xen/page_alloc: Remove `claim` from domain_set_outstanding_pages() Date: Sat, 16 Aug 2025 13:19:28 +0200 Message-ID: <73dc08d9ec628823309acc40a2603e9138bdd4b1.1755341947.git.bernhard.kaindl@cloud.com> 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: 1755343304822116600 Content-Type: text/plain; charset="utf-8" With a single global count for the claims it is easy to substract domain_tot_pages() from the claim so the number given in the hypercall is the real reservation of the domain. This is the current behaviour. However, a later patch introduces node-specific claims and those interact very poorly with such a scheme. Since accounting domain_tot_pages() in one case but not the other seems strictly worse than not accounting them at all (which is at least consistent), this patch stops substracting tot_pages from the claim and instead checks that claimed memory + allocated memory don't exceed max_mem. Arguably it's also clearer for the caller to align the amount of claimed memory with that of the requested claim. xl/libxenguest code never updated an existing claim: It stakes a claim, allocates all domain memory, cancels a possible leftover claim, finishes building the domain and unpauses it. Signed-off-by: Bernhard Kaindl Signed-off-by: Alejandro Vallejo --- xen/common/page_alloc.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index e1ac22b9ed..7e90b9cc1e 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -550,7 +550,7 @@ out: int domain_set_outstanding_pages(struct domain *d, unsigned long pages) { int ret =3D -ENOMEM; - unsigned long claim, avail_pages; + unsigned long avail_pages; =20 /* * take the domain's page_alloc_lock, else all d->tot_page adjustments @@ -576,28 +576,21 @@ int domain_set_outstanding_pages(struct domain *d, un= signed long pages) goto out; } =20 - /* disallow a claim not exceeding domain_tot_pages() or above max_page= s */ - if ( (pages <=3D domain_tot_pages(d)) || (pages > d->max_pages) ) + /* Don't claim past max_pages */ + if ( (domain_tot_pages(d) + pages) > d->max_pages ) { ret =3D -EINVAL; goto out; } =20 /* how much memory is available? */ - avail_pages =3D total_avail_pages; + avail_pages =3D total_avail_pages - outstanding_claims; =20 - avail_pages -=3D outstanding_claims; - - /* - * Note, if domain has already allocated memory before making a claim - * then the claim must take domain_tot_pages() into account - */ - claim =3D pages - domain_tot_pages(d); - if ( claim > avail_pages ) + if ( pages > avail_pages ) goto out; =20 /* yay, claim fits in available memory, stake the claim, success! */ - d->outstanding_pages =3D claim; + d->outstanding_pages =3D pages; outstanding_claims +=3D d->outstanding_pages; ret =3D 0; =20 --=20 2.43.0 From nobody Thu Oct 30 22:46:57 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=1755343871; cv=none; d=zohomail.com; s=zohoarc; b=ZqzrvTxdZg1sIHgBh7E3sLBqT27jlNIn6sBmSE6auTTBymrrrlbfVIWDYLY3Hslky+oHmyXRRM3UJx76mVBnKPvIDaJmO+cymRr4E5WWiYOTw86NrdQb7F4Zxv6BZwl6dmMQlVP0DMnzSIK41HmSDUabTudn57rlNzN5F7ljuTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343871; 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=itB6W5Mjw83eiGRv4d1CzarPcdxe/AwYbDWU2IVujVI=; b=BZfJxvRLxtPT40f6tDCIuByEyqUnERo+YtOakEdNaW8W2ZWQZQBstLCutuFZ1p7L/EcZarQ5UsE8FCPDYzFJLMg2teA5Bo6e5Pkr64rQFyu/Jl2ad2WUJAvfcxy/EJORSA/TK5iRLU0vFeL/4wwyjz4hDXoH+5bKxOjhcUWWW0Q= 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 1755343871195617.388000825089; Sat, 16 Aug 2025 04:31:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084507.1443655 (Exim 4.92) (envelope-from ) id 1unF7g-00022P-Fg; Sat, 16 Aug 2025 11:30:56 +0000 Received: by outflank-mailman (output) from mailman id 1084507.1443655; Sat, 16 Aug 2025 11:30:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1unF7g-00022G-CI; Sat, 16 Aug 2025 11:30:56 +0000 Received: by outflank-mailman (input) for mailman id 1084507; Sat, 16 Aug 2025 11:30:54 +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 1unEz5-0005tK-OJ for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:22:03 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3b1be4e5-7a93-11f0-b898-0df219b8e170; Sat, 16 Aug 2025 13:22:02 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-45a1ac7c066so14730565e9.1 for ; Sat, 16 Aug 2025 04:22:02 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:22:00 -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: 3b1be4e5-7a93-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343321; x=1755948121; 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=itB6W5Mjw83eiGRv4d1CzarPcdxe/AwYbDWU2IVujVI=; b=H9aa13Zl2XFOwQv2tYNg0vEUbg2Wa5rh1EeZi32NcT0xjXqwCVUvgceMI/VvXqrxhW 4/FRYVZqNPmaIW/b0InIdyQQSPF9N+KfhPZofKU2rJfY6n2UJ2M6is6SF25e+8lyc61o Rvv5eKcXCWHoJKd5K7fpTfxuIyZO7GP+K6es8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343321; x=1755948121; 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=itB6W5Mjw83eiGRv4d1CzarPcdxe/AwYbDWU2IVujVI=; b=LG1gxb9qYFdPewX2Hh3kGJPakyVE8q01hmwld4Wp2d0l84ARCSeSfAAmrkg2vq3bQQ mzJoMYvP06QxKRbcQvhE4zpZY+ANFboIHZK1QJd1BxIxENe5RKxLaG1do7QU+C+iXgdF MvduA4KSnJz+lX3sT8WSgl8eEXSZlRtwQnmCU2QsOw2oXSZvkgI/v8mwwKMio5jmgYwC YspVgPawXBQT4SAhKtU1l34h7V9XTfhf3KfVCqJoe+qD3xUExQ/TqV9Mx0uGUPqU03Tb 8JWKCtlKSkl4JY2i2R7VvVLbP17wHYFKB7D4SnJ1ihpLfA8HSev4pWpkrDMNP//ipvfO qXQg== X-Gm-Message-State: AOJu0Yw5i1hmQfUwbLgSpuHO1B31Wp3U+X1W2VTMOdnNlK0voUOLSIpB bTaoGNvF1nD0GC1ccrXhDaRM9aaalC9Wc8HXnvXPf2/lThTP1kf+tTrmOmXIu9RF+Bjdb/zYgVc kivp7PKE= X-Gm-Gg: ASbGncsQu4oeMO6nDYoCfQGDUydez3eX5hjy1cT9++afCXzHWX6OzyjoDDFK+wDaM6A Y2qAJwcSdP8hFUCM3UXh5JTyqc/4O68xLRSoW35wPlL3s9I9ASMGAklNW2/uJ3dTbKgUDpzOQcY 4atEUMCeaUDT/fTFlLP/S3QXRm6kpEON9pJ52GT4phK6swkNY52CRO3+KHVOHSIj0lELTCdPIbb yKXlLJRZuLohFTydyWwG8irh8B9TO1slS0HyW+VmLEbZD2y44UEeKHLJ/+tHSO+diLTVgT5ZIDA xYl/tkbHdl4CMhMr9j32LTurQ5o0ZKvH6+mWznADZZXuq9x8/zGXxMgwnVUOA49QHi9jCja5LIf Sbvp7BVWmGAzz/SlqwT5tUAJ7nVYW5NYP1OVGFjZ9TmxujWHl7S1yfgc= X-Google-Smtp-Source: AGHT+IGNf35gMUVzvlqFV29NkNPtqAgDj/10uCjjHdVaqfSJq9g6oY9WCZuroUHFpKy4ygpelHlvQQ== X-Received: by 2002:a05:600c:c104:b0:43c:ed33:a500 with SMTP id 5b1f17b1804b1-45a1b819ca7mr54173995e9.10.1755343321278; Sat, 16 Aug 2025 04:22:01 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Alejandro Vallejo Subject: [PATCH v2 3/7] xen/page_alloc: Add static per-NUMA-node counts of free pages Date: Sat, 16 Aug 2025 13:19:29 +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: 1755343873462124100 Content-Type: text/plain; charset="utf-8" The static per-NUMA-node count of free pages is the sum of free memory in all zones of a node. It's an optimisation to avoid doing that operation frequently in the following patches that introduce per-NUMA-node claims. --- Changed since v1: - Added ASSERT(per_node_avail_pages[node] >=3D request) as requested during review by Roger: Comment by me: As we have ASSERT(avail[node][zone] >=3D request); directly before it, request is already valid, so this checks that per_node_avail_pages[node] is not mis-accounted too low. Signed-off-by: Bernhard Kaindl Signed-off-by: Alejandro Vallejo --- xen/common/page_alloc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 7e90b9cc1e..43de9296fd 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -486,6 +486,9 @@ static unsigned long node_need_scrub[MAX_NUMNODES]; static unsigned long *avail[MAX_NUMNODES]; static long total_avail_pages; =20 +/* Per-NUMA-node counts of free pages */ +static unsigned long per_node_avail_pages[MAX_NUMNODES]; + static DEFINE_SPINLOCK(heap_lock); static long outstanding_claims; /* total outstanding claims by all domains= */ =20 @@ -1066,6 +1069,8 @@ static struct page_info *alloc_heap_pages( =20 ASSERT(avail[node][zone] >=3D request); avail[node][zone] -=3D request; + ASSERT(per_node_avail_pages[node] >=3D request); + per_node_avail_pages[node] -=3D request; total_avail_pages -=3D request; ASSERT(total_avail_pages >=3D 0); =20 @@ -1226,6 +1231,8 @@ static int reserve_offlined_page(struct page_info *he= ad) continue; =20 avail[node][zone]--; + ASSERT(per_node_avail_pages[node] > 0); + per_node_avail_pages[node]--; total_avail_pages--; ASSERT(total_avail_pages >=3D 0); =20 @@ -1550,6 +1557,7 @@ static void free_heap_pages( } =20 avail[node][zone] +=3D 1 << order; + per_node_avail_pages[node] +=3D 1 << order; total_avail_pages +=3D 1 << order; if ( need_scrub ) { --=20 2.43.0 From nobody Thu Oct 30 22:46:57 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=1755343375; cv=none; d=zohomail.com; s=zohoarc; b=nxxc/8B1iy+U1HknStzHtjNW+NsJZ0ivI2uKGNGga0HJu6CfVXfi6Jbx69slmCycI7BGFndl9t5cBsPeCMDw9U8V4oEnjcpBqXCPMkfjfZ9xy3QhFviCJTIKKmejUYex/3dACeMFs7Ux/8TCWnHaIoFjWNJ471f8XW0DzpaOlrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343375; 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=M8oXwoujm1GIgXMxJFvaFemEOtGYUi/CM14piShTTxU=; b=YByqmywot3j2SB8cpVxU0KQU8LJRf2t8mQhA5keuXkXdQ+Tzp8qsqJ1L6r2Ruu0KNPHYmZRoasObxp4cjpkSIb68oI4drK1IzAJQnMlyx6jSq31szZlICSYDMdFUYxzWWGUi8sfk7Y87dj9n4/4Q9ndcypuLxc1YW9c6X/ozw/8= 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 1755343375795170.84883565600023; Sat, 16 Aug 2025 04:22:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084467.1443615 (Exim 4.92) (envelope-from ) id 1unEzh-0007Sc-S3; Sat, 16 Aug 2025 11:22:41 +0000 Received: by outflank-mailman (output) from mailman id 1084467.1443615; Sat, 16 Aug 2025 11:22: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 1unEzh-0007SV-OK; Sat, 16 Aug 2025 11:22:41 +0000 Received: by outflank-mailman (input) for mailman id 1084467; Sat, 16 Aug 2025 11:22: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 1unEzg-0007SI-8v for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:22:40 +0000 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [2a00:1450:4864:20::42c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 51644001-7a93-11f0-a328-13f23c93f187; Sat, 16 Aug 2025 13:22:39 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3b9d41bea3cso2756514f8f.0 for ; Sat, 16 Aug 2025 04:22:39 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:22:38 -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: 51644001-7a93-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343359; x=1755948159; 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=M8oXwoujm1GIgXMxJFvaFemEOtGYUi/CM14piShTTxU=; b=SVUQFVvhpdlwrQXYe4za5lQgmImZyaJz+8K7c5K2VjxpFNyW2nMGhz1oZg9ijWnflI V5XE2wDrmfCfxh5yox4X+kDF6872ugIOZZej6EVXDdlakwLd3P/G3kbuiMoScO4Lq/YL rIkjbHAZyrbu5M5lLrmWEwVRdZkYcMYFdimo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343359; x=1755948159; 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=M8oXwoujm1GIgXMxJFvaFemEOtGYUi/CM14piShTTxU=; b=oWs23u6a04WOiFXCFL9U4d+iwxoYsQ30oqVEzkvq3Y9RyBvGBlXz1To67bqD6Z9LPI D9i7gQwjmYxubzBR8+mKrtfkUt6q+Q536JjZcbjJ982JyWKbvks+Gu0qb76QaL9J/5ZN v/hWAGlrQ6DFmftTA0Itrw4UlBO83HsZNHCGYZci5X1qsPYqKkoZZH/tcseMDYoSGu4e az+DMzxNeMTZdMLeM9wq4VgSlYKcQfxBcEs4anBdtwFM+VGfvnOkIKr+6dlDGC0O9euS Q01YtnGM5neGnnzARJnyDkOFE2GKkpApTxazUYY0BxC/Jl6+Xp/H7xBAVlmENZDAYIdm s7CQ== X-Gm-Message-State: AOJu0YzW3PMzgrOjkHOa85oytOyj9JzaAPUKoFaCgbam6onV/P+9QMVP tvzP752CU/piTwDlWBlehQb1qIR2hydyYMdMdqmIJAz8evUzmtQpoNj00vfdd2tP7yk+Fo1AasI RBtJl0ts= X-Gm-Gg: ASbGncv0J2HFyr6vQ/z5jYY5VXpP2V24NNV1/A87/cMPO5K18RkMH8gMzyTPW0AExE3 DJK9NpGtHYDB+kkM148bqmMrM/Jcc6B92LumFuaruXrxYucqUs3wFjdvb0puma6XNhp8XthG684 Q/yrGxREGhHD5fwBuCm/JNRVM2FDJJs3Ai1nYfLL0ky+QDaM1WUgMD17k68uLAz8YmW5tUtSvz6 B62kYqYWoYdHuzCViWMns33RgXmz44TNqysOg8ioqL1oNheyVrxcSZAlQSBSTIktn+DLHcc53tL 4KVymju9hDIu8rFJVOphkcD1k/HnN690up6bStNjScaqv9BRa7sCq/e2EMICoZtGz2Je5zX/58h 1EGKtXXlcAAEzIcmYAUoHLYetumniR2yoxVguDd7rPryVEJE2g3BGqGo= X-Google-Smtp-Source: AGHT+IFgS9YcmZerlWfp+2PGSbboes1eTWmA6Ks71Yh8olqHY0310RWySPPUycVu5rm2nESIrRRkyQ== X-Received: by 2002:a05:6000:381:b0:3a4:f72a:b18a with SMTP id ffacd0b85a97d-3bb676c9d2fmr3802460f8f.26.1755343358475; Sat, 16 Aug 2025 04:22:38 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini , Tamas K Lengyel , Alejandro Vallejo Subject: [PATCH v2 4/7] xen/page_alloc: Add node argument to domain_{adjust_tot_pages,set_outstanding_pages}() Date: Sat, 16 Aug 2025 13:19:30 +0200 Message-ID: <62a9612c4f9d507184c50f720b5fe22f4921e85e.1755341947.git.bernhard.kaindl@cloud.com> 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: 1755343377656124100 Content-Type: text/plain; charset="utf-8" domain_adjust_tot_pages() adjusts the total pages of a domain after allocating or freeing memory. When allocating, it also reduces the outstanding claims of a domain as pages are allocated. When adding the node argument, we pass the node from which the pages were allocated. When pages are freed, we simply pass NUMA_NO_NODE as when freeing, the outstanding claims are not updated anyways. domain_set_outstanding_pages() sets the amount of outstanding claims of a domain. We pass the node on which to to stake an claim, or NUMA_NO_NODE for host-wide claims. No functional change, as neither function uses the arguments for anything yet. It's a prerequisite to simplify for the next patch that introduces per-node claim counts. Changed since v1: - Fix for the correct indentation of line with '-dec_count));' Signed-off-by: Bernhard Kaindl Signed-off-by: Alejandro Vallejo --- xen/arch/x86/mm.c | 3 ++- xen/arch/x86/mm/mem_sharing.c | 4 ++-- xen/common/domain.c | 2 +- xen/common/grant_table.c | 4 ++-- xen/common/memory.c | 6 ++++-- xen/common/page_alloc.c | 17 ++++++++++++----- xen/include/xen/mm.h | 6 ++++-- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index e7fd56c7ce..effc67c6ba 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4444,7 +4444,8 @@ int steal_page( page_list_del(page, &d->page_list); =20 /* Unlink from original owner. */ - if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1)= ) + if ( !(memflags & MEMF_no_refcount) && + !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1) ) drop_dom_ref =3D true; =20 nrspin_unlock(&d->page_alloc_lock); diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index da28266ef0..2551c0d86e 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -720,7 +720,7 @@ static int page_make_sharable(struct domain *d, if ( !validate_only ) { page_set_owner(page, dom_cow); - drop_dom_ref =3D !domain_adjust_tot_pages(d, -1); + drop_dom_ref =3D !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1); page_list_del(page, &d->page_list); } =20 @@ -766,7 +766,7 @@ static int page_make_private(struct domain *d, struct p= age_info *page) ASSERT(page_get_owner(page) =3D=3D dom_cow); page_set_owner(page, d); =20 - if ( domain_adjust_tot_pages(d, 1) =3D=3D 1 ) + if ( domain_adjust_tot_pages(d, page_to_nid(page), 1) =3D=3D 1 ) get_knownalive_domain(d); page_list_add_tail(page, &d->page_list); nrspin_unlock(&d->page_alloc_lock); diff --git a/xen/common/domain.c b/xen/common/domain.c index 5241a1629e..1beadb05e1 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1239,7 +1239,7 @@ int domain_kill(struct domain *d) rspin_barrier(&d->domain_lock); argo_destroy(d); vnuma_destroy(d->vnuma); - domain_set_outstanding_pages(d, 0); + domain_set_outstanding_pages(d, NUMA_NO_NODE, 0); /* fallthrough */ case DOMDYING_dying: rc =3D domain_teardown(d); diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index cf131c43a1..8fea75dbb2 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -2405,7 +2405,7 @@ gnttab_transfer( } =20 /* Okay, add the page to 'e'. */ - if ( unlikely(domain_adjust_tot_pages(e, 1) =3D=3D 1) ) + if ( unlikely(domain_adjust_tot_pages(e, page_to_nid(page), 1) =3D= =3D 1) ) get_knownalive_domain(e); =20 /* @@ -2431,7 +2431,7 @@ gnttab_transfer( * page in the page total */ nrspin_lock(&e->page_alloc_lock); - drop_dom_ref =3D !domain_adjust_tot_pages(e, -1); + drop_dom_ref =3D !domain_adjust_tot_pages(e, NUMA_NO_NODE, -1); nrspin_unlock(&e->page_alloc_lock); =20 if ( okay /* i.e. e->is_dying due to the surrounding if() */ ) diff --git a/xen/common/memory.c b/xen/common/memory.c index 3688e6dd50..b8cf4bd23d 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -775,7 +775,8 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_= memory_exchange_t) arg) =20 nrspin_lock(&d->page_alloc_lock); drop_dom_ref =3D (dec_count && - !domain_adjust_tot_pages(d, -dec_count)); + !domain_adjust_tot_pages(d, NUMA_NO_NODE, + -dec_count)); nrspin_unlock(&d->page_alloc_lock); =20 if ( drop_dom_ref ) @@ -1682,7 +1683,8 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE= _PARAM(void) arg) rc =3D xsm_claim_pages(XSM_PRIV, d); =20 if ( !rc ) - rc =3D domain_set_outstanding_pages(d, reservation.nr_extents); + rc =3D domain_set_outstanding_pages(d, NUMA_NO_NODE, + reservation.nr_extents); =20 rcu_unlock_domain(d); =20 diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 43de9296fd..e8ba21dc46 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -517,7 +517,8 @@ static unsigned long avail_heap_pages( * Update the total number of pages and outstanding claims of a domain. * - When pages were freed, we do not increase outstanding claims. */ -unsigned long domain_adjust_tot_pages(struct domain *d, long pages) +unsigned long domain_adjust_tot_pages(struct domain *d, nodeid_t node, + long pages) { unsigned long adjustment; =20 @@ -550,7 +551,8 @@ out: return d->tot_pages; } =20 -int domain_set_outstanding_pages(struct domain *d, unsigned long pages) +int domain_set_outstanding_pages(struct domain *d, nodeid_t node, + unsigned long pages) { int ret =3D -ENOMEM; unsigned long avail_pages; @@ -2620,6 +2622,8 @@ int assign_pages( =20 if ( !(memflags & MEMF_no_refcount) ) { + nodeid_t node =3D page_to_nid(&pg[0]); + if ( unlikely(d->tot_pages + nr < nr) ) { gprintk(XENLOG_INFO, @@ -2631,7 +2635,9 @@ int assign_pages( goto out; } =20 - if ( unlikely(domain_adjust_tot_pages(d, nr) =3D=3D nr) ) + ASSERT(node =3D=3D page_to_nid(&pg[nr - 1])); + + if ( unlikely(domain_adjust_tot_pages(d, node, nr) =3D=3D nr) ) get_knownalive_domain(d); } =20 @@ -2764,7 +2770,8 @@ void free_domheap_pages(struct page_info *pg, unsigne= d int order) } } =20 - drop_dom_ref =3D !domain_adjust_tot_pages(d, -(1 << order)); + drop_dom_ref =3D !domain_adjust_tot_pages(d, NUMA_NO_NODE, + -(1 << order)); =20 rspin_unlock(&d->page_alloc_lock); =20 @@ -2970,7 +2977,7 @@ void free_domstatic_page(struct page_info *page) =20 arch_free_heap_page(d, page); =20 - drop_dom_ref =3D !domain_adjust_tot_pages(d, -1); + drop_dom_ref =3D !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1); =20 unprepare_staticmem_pages(page, 1, scrub_debug); =20 diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 93c037d618..f977e73b1c 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -130,8 +131,9 @@ mfn_t xen_map_to_mfn(unsigned long va); int populate_pt_range(unsigned long virt, unsigned long nr_mfns); /* Claim handling */ unsigned long __must_check domain_adjust_tot_pages(struct domain *d, - long pages); -int domain_set_outstanding_pages(struct domain *d, unsigned long pages); + nodeid_t node, long pages); +int domain_set_outstanding_pages(struct domain *d, nodeid_t node, + unsigned long pages); void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pa= ges); =20 /* Domain suballocator. These functions are *not* interrupt-safe.*/ --=20 2.43.0 From nobody Thu Oct 30 22:46:57 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=1755343433; cv=none; d=zohomail.com; s=zohoarc; b=UdUjrxt8YQ3GSJQtxbOoVgwzv44h18/tWE4NzhPvZuWxchQyrQoSLkP7lQvFDCq54yTGIthsyBEd6kV19CZIabQemPOepwIArErEyEqLy2wWtmr4cxAPt8Csov/M/5w8GfREBCJuEO1H7mZqOyZXVxU8fyqWC8dzMA8tIkCemdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343433; 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=I+05UXLfbMsAgarpS2s46Loi9+DfuxXq2X3Fj022QKo=; b=XA5ooc+U2Jp0ewE78+kivYfBzMzkessh8kh1MmFE+v9jLpomfYXfOaTyjKtCnVugd9h03T5jdGiuWaQaZsC1x6jFSqLL1sCwg7FnZzMgc1FjHymkkT3/eoFmYDsVVl/qxMwtIN1gXnI5UdqGjNkavi482eDUezjCzL7WwqH/8QU= 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 1755343433152942.7865062033943; Sat, 16 Aug 2025 04:23:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084480.1443625 (Exim 4.92) (envelope-from ) id 1unF0d-0007zF-5Z; Sat, 16 Aug 2025 11:23:39 +0000 Received: by outflank-mailman (output) from mailman id 1084480.1443625; Sat, 16 Aug 2025 11:23:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1unF0d-0007z8-2Q; Sat, 16 Aug 2025 11:23:39 +0000 Received: by outflank-mailman (input) for mailman id 1084480; Sat, 16 Aug 2025 11:23:38 +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 1unF0c-0007SI-3o for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:23:38 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7423fa02-7a93-11f0-a328-13f23c93f187; Sat, 16 Aug 2025 13:23:37 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-45a1b00f187so11183025e9.0 for ; Sat, 16 Aug 2025 04:23:37 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:23:36 -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: 7423fa02-7a93-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343417; x=1755948217; 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=I+05UXLfbMsAgarpS2s46Loi9+DfuxXq2X3Fj022QKo=; b=kDoUhMPGZWSzXRA7TmKOko1MdKJAEHbmqa+jGeU7BEP8GtxlFMpCr5t2fNbCPNW981 OdzJG62MM6ks3UQtlWcIb73vBCjxujBFuYdzFu824MahvhoRaCyuil2XUkhbrOTqaHf/ +j+MpkEwItqBCuEsqfkPiw3aUehdYbv7s2L/I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343417; x=1755948217; 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=I+05UXLfbMsAgarpS2s46Loi9+DfuxXq2X3Fj022QKo=; b=RjZ1C5wzeqD2oM3C4lZ47JmSaxF2rvboRt7A4kgS+ULenob4Z/hKw+/s1HFoA5H0WF cv7ktnahzippxW7pXR8ovTUjjqY1yVzNkupHiGy4fGZGxaTAFA2u3aAmN3n5+x5ugG4F g+va2nf41qJouG4buUWONJaaWBdPGSQqfq6XUv2/X2moLrghyntSTpCGI2zsScVyFyFn mys4id2JQjQipPowkps4RG4UCgsj/BISHU2KixQyghvQubf+kYbf2N11HRwuUoFP9a0A MW9018Qp8UeF9Qfuh5VYjHctCvuTiRj0P9ReObIA5DTZoxodCKBJmXgfathsrnkbHW8n FAQA== X-Gm-Message-State: AOJu0YzDursj2uGaSVDuFvqZi7y72fXw3tXvBDzMY3HPI5QOOjsuFAeY xb8H7DBeTS0BKnwL8dHxlYzn1luCA6YzUeQ4nRu+fJF1KobVGxWUepYYauBZ62nXAVkL7MgpQz9 WlnLlD9I= X-Gm-Gg: ASbGnctOeYRuq+mke9OOWMTsgME0zdQFkFTaPanBiibG845d6iX8DD1Vggvb1Nvt03C 7wC1gXQ7lAyMibquSy/G/6uaRX02TxDuQF5HXE1w/FMcVce4BHq1hw3KW5YtIgLIYsKibtyrPtg eG+BhPtpKgiCtnk66kizLn4MAyKgHo/8x+Bhza+83v1+Ana667B6BTdo1vUGX8T2Cp92Cnq6vw6 Npbz6a3BS+gaTww1gMYAdMhcG9tFEYWqdSZWs+A+7bczOhL5Rwe/vhy/Rt1J7wlENvOWkw2AjHX 0iZBH+oqIOz7roL+UIfHJIfUBuhRE2rY/ziDLng6d/A0qYYn+EYOFZnx9uEtFDWmKQmU+9ByZTp HEy76vLYL7XVBA0VITVSufICWk6uj2jvm94gpUKQ5GJaYODmnp449exw= X-Google-Smtp-Source: AGHT+IGqX6lX+0qjwd3ZJHWzwevLA3gtpXVk7B4Wh5fM2DAlWP2x0QefOv/95gtbzlo0eDDvBzZfBQ== X-Received: by 2002:a05:600c:b90:b0:459:eeaf:d6c7 with SMTP id 5b1f17b1804b1-45a218578fbmr38391925e9.26.1755343416867; Sat, 16 Aug 2025 04:23:36 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Marcus Granado , Alejandro Vallejo Subject: [PATCH v2 5/7] xen/page_alloc: Create per-node outstanding claims Date: Sat, 16 Aug 2025 13:19:31 +0200 Message-ID: <646f3bdbbfef5ace7902ca18c532b5518612f36e.1755341947.git.bernhard.kaindl@cloud.com> 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: 1755343436368124100 Content-Type: text/plain; charset="utf-8" Extend domain_set_outstanding_claims() to allow staking claims on a specific NUMA node instead of host-wide: A claim on a specific NUMA node is the amount of d->outstanding_claims where the new field d->claim_node field is not NUMA_NO_NODE. We use the most straightforward implementation to minimise the amount of changes in this commit and the rest of the series: In the next series that converts the claims handling the multi-node claims, this will of course be converted into another structure. It helps to keep this commit focused on the central challenge of the new type of claim and leaves extending claims to multi-node claims for the next series. Also extend get_free_buddy() for when it circles round-robin over nodes: Make it skip NUMA nodes that do not have enough unclaimed memory left. --- Changes since v1: - Join all conditions into a single if clause - Improve the function description and comments - Use const when passing struct domain when applicable - Renamed pernode_oc[] to per_node_outstanding_claims[] - Reject invalid node IDs in domain_set_outstanding_pages() - Use nodeid_t instead of unsigned int for the claim_node field. - Removed dependency on MEMF_EXACT_NODE (checked in get_free_buddy()) - Added awareness for honoring NUMA claims to get_free_buddy() Signed-off-by: Bernhard Kaindl Signed-off-by: Marcus Granado Signed-off-by: Alejandro Vallejo --- xen/common/page_alloc.c | 37 +++++++++++++++++++++++++++++++++++-- xen/include/xen/sched.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index e8ba21dc46..63ecd74dcc 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -491,6 +491,7 @@ static unsigned long per_node_avail_pages[MAX_NUMNODES]; =20 static DEFINE_SPINLOCK(heap_lock); static long outstanding_claims; /* total outstanding claims by all domains= */ +static unsigned long per_node_outstanding_claims[MAX_NUMNODES]; =20 static unsigned long avail_heap_pages( unsigned int zone_lo, unsigned int zone_hi, unsigned int node) @@ -532,8 +533,12 @@ unsigned long domain_adjust_tot_pages(struct domain *d= , nodeid_t node, * * If the domain has no outstanding claims (or we freed pages instead), * we don't update outstanding claims and skip the claims adjustment. + * + * Also don't update outstanding claims when the domain has node-speci= fic + * claims, but the memory allocation was from a different NUMA node. */ - if ( !d->outstanding_pages || pages <=3D 0 ) + if ( !d->outstanding_pages || pages <=3D 0 || + (d->claim_node !=3D NUMA_NO_NODE && d->claim_node !=3D node) ) goto out; =20 spin_lock(&heap_lock); @@ -544,6 +549,8 @@ unsigned long domain_adjust_tot_pages(struct domain *d,= nodeid_t node, */ adjustment =3D min(d->outstanding_pages, (unsigned int)pages); d->outstanding_pages -=3D adjustment; + if ( d->claim_node !=3D NUMA_NO_NODE ) /* adjust the static per-node c= laims */ + per_node_outstanding_claims[d->claim_node] -=3D adjustment; outstanding_claims -=3D adjustment; spin_unlock(&heap_lock); =20 @@ -557,6 +564,9 @@ int domain_set_outstanding_pages(struct domain *d, node= id_t node, int ret =3D -ENOMEM; unsigned long avail_pages; =20 + if ( node !=3D NUMA_NO_NODE && !node_online(node) ) + return -EINVAL; + /* * take the domain's page_alloc_lock, else all d->tot_page adjustments * must always take the global heap_lock rather than only in the much @@ -569,6 +579,10 @@ int domain_set_outstanding_pages(struct domain *d, nod= eid_t node, if ( pages =3D=3D 0 ) { outstanding_claims -=3D d->outstanding_pages; + + if ( d->claim_node !=3D NUMA_NO_NODE ) + per_node_outstanding_claims[d->claim_node] -=3D d->outstanding= _pages; + d->outstanding_pages =3D 0; ret =3D 0; goto out; @@ -591,12 +605,26 @@ int domain_set_outstanding_pages(struct domain *d, no= deid_t node, /* how much memory is available? */ avail_pages =3D total_avail_pages - outstanding_claims; =20 + /* This check can't be skipped for the NUMA case, or we may overclaim = */ if ( pages > avail_pages ) goto out; =20 + if ( node !=3D NUMA_NO_NODE ) + { + avail_pages =3D per_node_avail_pages[node] - per_node_outstanding_= claims[node]; + + if ( pages > avail_pages ) + goto out; + } + /* yay, claim fits in available memory, stake the claim, success! */ d->outstanding_pages =3D pages; outstanding_claims +=3D d->outstanding_pages; + d->claim_node =3D node; + + if ( node !=3D NUMA_NO_NODE ) + per_node_outstanding_claims[node] +=3D pages; + ret =3D 0; =20 out: @@ -934,7 +962,12 @@ 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)) ) + if ( !avail[node] || (avail[node][zone] < (1UL << order)) || + /* For host-wide allocations, skip nodes without enough + * unclaimed memory. */ + (req_node =3D=3D NUMA_NO_NODE && outstanding_claims && + ((per_node_avail_pages[node] - + per_node_outstanding_claims[node]) < (1UL << order)))= ) continue; =20 /* Find smallest order which can satisfy the request. */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index fd5c9f9333..9535ed7a6a 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -406,6 +406,7 @@ struct domain unsigned int max_pages; /* maximum value for domain_tot_pa= ges() */ unsigned int extra_pages; /* pages not included in domain_to= t_pages() */ =20 + nodeid_t claim_node; /* NUMA_NO_NODE for host-wide clai= ms */ #ifdef CONFIG_MEM_SHARING atomic_t shr_pages; /* shared pages */ #endif --=20 2.43.0 From nobody Thu Oct 30 22:46:57 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=1755343455; cv=none; d=zohomail.com; s=zohoarc; b=J6dIZYQoZGpUhfPmrVWivIasxYkbiRJTCnkoUh1iQ2UVizF9wZba6jONOJ/sad43ewnCtT2R7Z8ezSOxUuxYS0q1YySTrcZr1qrwG8wu/4Ug33iOEzVS6RjEclMZaus1edf/3zsVU7CRNiXcmr6RYXWcLtzxb+43MqyrgA9iUOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343455; 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=j1iRU9m3XRpby6RHQR14UBdcIiWltVXdQcuwow+h8HQ=; b=kTcDyvuN+usFl6+hi6XR9wd4NHErZdwlfodtSyOwzWa+68p9aBW4OAvXiDWVxyapaFgc6T4nBhHp4PQ42xRzT5D3R//jItROQX7rx4RwL96SKhUJoCpGtp2Cmj4BqrN5Dla7syApSC7zqJdQOPujrVqavj3thrj2jT70zgX0RF8= 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 175534345572025.221375248385243; Sat, 16 Aug 2025 04:24:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084487.1443635 (Exim 4.92) (envelope-from ) id 1unF11-0008SD-Hc; Sat, 16 Aug 2025 11:24:03 +0000 Received: by outflank-mailman (output) from mailman id 1084487.1443635; Sat, 16 Aug 2025 11:24: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 1unF11-0008S6-Ek; Sat, 16 Aug 2025 11:24:03 +0000 Received: by outflank-mailman (input) for mailman id 1084487; Sat, 16 Aug 2025 11:24:02 +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 1unF10-0008R6-K2 for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:24:02 +0000 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [2a00:1450:4864:20::329]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 81d79ddb-7a93-11f0-b898-0df219b8e170; Sat, 16 Aug 2025 13:24:00 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-45a20c51c40so9827955e9.3 for ; Sat, 16 Aug 2025 04:24:00 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:23:59 -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: 81d79ddb-7a93-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343440; x=1755948240; 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=j1iRU9m3XRpby6RHQR14UBdcIiWltVXdQcuwow+h8HQ=; b=KOIjoCAr0Sxnt+5/pP7qUZkTaiR80CdOm3salZhyK0CroBJdXUKihkiLnOoyzpnc7Y 0jM+qFffx/bynmC2RuNYImpxB+JOCMWZ1PuMGAkHiGzriBazVX0JWqgJ5Ro42vb12MSX zw1syGXb1P9fC5tQpBMI3xTT+4Hvkuv4og2cc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343440; x=1755948240; 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=j1iRU9m3XRpby6RHQR14UBdcIiWltVXdQcuwow+h8HQ=; b=anU55+AWg35f0+5o5HzxrESLc+wmb15LQOSEs2Xn9DzV/m6RZaI7lylLDk1Y0abGCo Kr/OMhFZdHRy4kixcB1xVDu+nN8a/0spawYRnJ+fzDkSzhXV179P7gFLvSeHdAZt5KaB 1WaPRLfRUhuaDn33ensiknvyD5qAztq8s7EXC+7ut+Ri3x9Oc5kE7q3L6UTt2rqwAC2t gmd1efzuVg61WZhrSkYJTYZRKyLHdN4nSygk9PqFhzPOQHUsCyfVtGaw7QYLbfc3qGuR RtWxGFMtLoGVJV6xpdPtIMSb04WTswNZTICWdAnXYKOr+6GNwMdqVhGUEu1i/t1nw+Pz wjcQ== X-Gm-Message-State: AOJu0YzsmM9MIKnHgyc+eD6zlA6dFK+xzKL4gL5h92wtOoMqIZWZPQHw w8xWPZaO/JRGIzdrLcbqH0RMQC625FT3ESRHQD/RKv9v+UJU1N/EnE8+zJm5s9dWJXrMW7lObKu +YcoYFLg= X-Gm-Gg: ASbGncsEqcVkFQvhWuBEBStLytdHhobuzb6ZO0I0a8jVj5jIeLyYitwyC1275msgMpl hMKLSDqLW3Rcxf7NaCruLteKKputKlVLBWI5ZxN2q4Qxu5N3MSW/z8EEhP/hwwGR5eEEI1SyBkU N3MDxLIVPHwXAMfmOewQxY7HIIT+vwJK5VIGaTlY19jECmxqBYzn54aGgQBgFXHxT118Vc09dzG C1ud4vHDSVOh14UxYs9MqjYkmA+l4/Qqp0yRZGXmtv1OpxLT8CTzZopWkQplpXzzccshmg7Piga 0vwSVbpJxqUV/gGU65zsEWqy2aPgxv9jIMBg5qbg/U+7pC03mAG85oeepowMEVwYYyF50QrbLxB DEqU1ujhev9l/pWl/P3zGK3M+62yRxr9B0dZkDaJACoTnJXZgQf2yhOc= X-Google-Smtp-Source: AGHT+IHuOtR+8eaxNX0/XVwzU9erg7D0dXe6omoAZOyWtG0EUecSpWYLLhu2OalCdVzZ7D5v8sX4gA== X-Received: by 2002:a05:600c:4691:b0:456:1ac8:cace with SMTP id 5b1f17b1804b1-45a217fd7aemr50051845e9.12.1755343439803; Sat, 16 Aug 2025 04:23:59 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Alejandro Vallejo Subject: [PATCH v2 6/7] xen/page_alloc: Check per-node claims in alloc_heap_pages() Date: Sat, 16 Aug 2025 13:19:32 +0200 Message-ID: <3836533d5424baa470e69838bac89862e14d44e0.1755341947.git.bernhard.kaindl@cloud.com> 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: 1755343458108116600 Content-Type: text/plain; charset="utf-8" Extend the claim checks in alloc_heap_pages() to NUMA claims. Signed-off-by: Bernhard Kaindl Signed-off-by: Alejandro Vallejo --- Changes since v1: - No longer require the memflags & MEMF_exact_node for using claims - If the NUMA node is not passed in memflags, get the NUMA node to conume claims from using the claim itself and confirm it using the domain's d->node_affinity, which is where get_free_buddy will allocate from. This also eases the conversion to multi-node claim usage as memflags in inherently single-node. --- xen/common/page_alloc.c | 46 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 63ecd74dcc..12e1d6a049 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1027,6 +1027,48 @@ static void init_free_page_fields(struct page_info *= pg) page_set_owner(pg, NULL); } =20 +/* + * Check if a heap allocation is allowed (helper for alloc_heap_pages) + */ +static bool can_alloc(const struct domain *d, unsigned int memflags, + unsigned long request) +{ + nodeid_t node =3D MEMF_get_node(memflags); + + /* + * If memflags don't define a node to allocate from, get_free_buddy() = will + * use d->node_affinity for the allocation: Allow the allocation to + * take advantage of it when the claimed node is exactly d->node_affin= ity: + */ + if ( node =3D=3D NUMA_NO_NODE && d && d->claim_node !=3D NUMA_NO_NODE ) + { + nodemask_t claim_node =3D nodemask_of_node(d->claim_node); + + if (nodes_equal(d->node_affinity, claim_node)) + node =3D d->claim_node; + } + + if ( outstanding_claims + request <=3D total_avail_pages && /* host-wi= de, */ + (node =3D=3D NUMA_NO_NODE || /* if the alloc is node-specific, th= en also */ + per_node_outstanding_claims[node] + request <=3D /* check per-no= de */ + per_node_avail_pages[node]) ) + return true; + + /* + * The requested allocation can only be satisfied by outstanding claim= s. + * Claimed memory is considered unavailable unless the request + * is made by a domain with sufficient unclaimed pages. + * + * Only allow if the allocation matches the available claims of the do= main. + * For host-wide allocs and claims, node =3D=3D d->claim_node =3D=3D N= UMA_NO_NODE. + * + * Only refcounted allocs attributed to domains may have been claimed: + * Not refcounted allocs cannot consume claimed memory. + */ + return d && d->claim_node =3D=3D node && d->outstanding_pages >=3D req= uest && + !(memflags & MEMF_no_refcount); +} + /* Allocate 2^@order contiguous pages. */ static struct page_info *alloc_heap_pages( unsigned int zone_lo, unsigned int zone_hi, @@ -1057,9 +1099,7 @@ static struct page_info *alloc_heap_pages( * Claimed memory is considered unavailable unless the request * is made by a domain with sufficient unclaimed pages. */ - if ( (outstanding_claims + request > total_avail_pages) && - ((memflags & MEMF_no_refcount) || - !d || d->outstanding_pages < request) ) + if ( !can_alloc(d, memflags, request) ) { spin_unlock(&heap_lock); return NULL; --=20 2.43.0 From nobody Thu Oct 30 22:46:57 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=1755343871; cv=none; d=zohomail.com; s=zohoarc; b=VXT5eW+tv8f8fs85tdHmcFJMh5uEmmv9mrrPZqvGSjQ71nUM2SVcjSP0SuydSHV62M/Y2LIhln2ZPmVfVSO3h+aHXOZJMyyKoSacsKIbFaAKgS/M0tVJ+C+LWynoK2tS2TIojagFd8kfnvoIjeQ3zzEFL8MbP/Evtjr6ZSHvakQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343871; 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=Wt3Ep5ObVZ9RSrrf4fRGSI8+1rgfl6o5cNaA3eQGhXk=; b=QodaCMAX1Nf2EQJ7iBz0fBBfWo1FUIz9yaimNIbY3lHnsul8jsDxXJyQD1Nf1anLKICWzoJkpZZhq6BcqLSN8DbvDHc7VfrQjaymvnOYRus5HaKLhYr2ytS58yK7pzdzYChsDBN0vMku/615z84HUicQ632pk8Ax6jqdb7t2U+U= 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 1755343870992523.2117796520746; Sat, 16 Aug 2025 04:31:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084500.1443644 (Exim 4.92) (envelope-from ) id 1unF7f-0001om-7d; Sat, 16 Aug 2025 11:30:55 +0000 Received: by outflank-mailman (output) from mailman id 1084500.1443644; Sat, 16 Aug 2025 11:30:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1unF7f-0001of-4t; Sat, 16 Aug 2025 11:30:55 +0000 Received: by outflank-mailman (input) for mailman id 1084500; Sat, 16 Aug 2025 11:30:53 +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 1unF1b-0008R6-0x for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:24:39 +0000 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [2a00:1450:4864:20::32f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9792924d-7a93-11f0-b898-0df219b8e170; Sat, 16 Aug 2025 13:24:37 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-45a1b00a65fso12970895e9.0 for ; Sat, 16 Aug 2025 04:24:37 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:24:35 -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: 9792924d-7a93-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343476; x=1755948276; 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=Wt3Ep5ObVZ9RSrrf4fRGSI8+1rgfl6o5cNaA3eQGhXk=; b=g1nekSbXX9b6SbxlLRKch3bi1y8sj2M60B6HKXQS5Cny3dgT1I4moic1OAzn4NXl+2 RYS90EsPUfNoXVqvSGV1jyLCrlW7yCAm2DKgwdMhqtSuiR8xv9qEScMh5EJv3VfKJHb1 P0tnrzcYNxJzA3vw7Q6DXmiR8OgFu87yKLC9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343476; x=1755948276; 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=Wt3Ep5ObVZ9RSrrf4fRGSI8+1rgfl6o5cNaA3eQGhXk=; b=WMug1XEMNNEs00zY1w7ioj7QogON+8C/USHNyTNhdEqBK019fqwQiFdHiWjXJbQaFI atAqXuIqh4lOg+Jh8foY3sak2zmNw0k/2BoC7Sz2eaiRdFbgs8p65MRW1yK3PleQSB4C 09GHXLFnMXvkfrxmYfwEt0EnpVTbaxmNEaENXsAOulovR/9R1vX2A5fOMbFTE2MNViEz bDomJHHpTYun7CbVcVl1Nba4RJspb47wqcSN3/rTKBp0DQYsAtnKtI9IucCnJsqCFSmn EPFBILijADmia/i3XQM/8jYaBvaFu8InmfLGhsy3cuSgV4Gj0vAS9FOsXU0sCnTxhn2o iqFA== X-Gm-Message-State: AOJu0Yx1svJPV1mprcbF9pOaAhiMWOR+2XLGE6TklK7STMsXxYLPVUGP /1x3cQDCPmuT8DdzRYywH9cC+InJPHmYa3QSMSLxWyqGZVhp30wz5jZug565gDCDHaIZDzYJ/uD v5vlyYKQ= X-Gm-Gg: ASbGncu/glfkXjt7POIxwRMt4+f0YxDhHP2QnImxcJctQnh9LEAZVDKuiJzocKPawlm NGkW9OWe/jc39Ebou4Ctc9pwiQwodywXFIqLyEldBrMVj2aaRiYd+tq9R5q5Un+QCeG4ykBR2CV PTDW8dfkJUVrX/WmS4U05dDSTjJTdagqV3oSDuae8ortZLUmQ2S0pJrtUcWBzw2CulFfE7VHgNt ILUln1KytEa++cUvQSL+Oq5mkRP+yC7Nd2qwDu6wpPtMBYBKAGjnw+xxqHjPw9BI5NyH8ypeQeP dSW9Fgv4zORlWIdxAYtySYD31usZ+VNKoO6wiUMqQG2RhtPcfC4ulE/39WegfcYhQzMhif9u4TJ Yck3kKhoQHiwDFnZd3rwaD29/T130ClYGLBLXEsCJ6NlEvERGueBQ6qw= X-Google-Smtp-Source: AGHT+IFgURo8r1ge/HnYI3T0kx/VEtXSw1AoZBylv9ZwyhZqA6n1wDRJZ6lnLl7S0mPy4UCT+3KL/w== X-Received: by 2002:a05:600c:198d:b0:459:e094:92cb with SMTP id 5b1f17b1804b1-45a218095eemr45110205e9.12.1755343476320; Sat, 16 Aug 2025 04:24:36 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , "Daniel P. Smith" , Anthony PERARD , Andrew Cooper , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Juergen Gross , Christian Lindig , David Scott , Alejandro Vallejo Subject: [PATCH v2 7/7] xen: New API to claim memory for a domain using XEN_DOMCTL_claim_memory Date: Sat, 16 Aug 2025 13:19:33 +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: 1755343872147116600 Content-Type: text/plain; charset="utf-8" Add the new hypercall requested during the review of the v1 series do not require changing the API for multi-node claims. The hypercall receives a number of claims, intented to be one claim per NUMA node, and limited to one claim for now. The changes to update the NUMA claims management to handle updating the claims for multiple NUMA nodes of a domain at once are deferred to the next series. Signed-off-by: Bernhard Kaindl Cc: Alejandro Vallejo Acked-by: Christian Lindig --- tools/flask/policy/modules/dom0.te | 1 + tools/flask/policy/modules/xen.if | 1 + tools/include/xenctrl.h | 4 +++ tools/libs/ctrl/xc_domain.c | 42 +++++++++++++++++++++++++++++ tools/ocaml/libs/xc/xenctrl.ml | 9 +++++++ tools/ocaml/libs/xc/xenctrl.mli | 9 +++++++ tools/ocaml/libs/xc/xenctrl_stubs.c | 21 +++++++++++++++ xen/common/domain.c | 30 +++++++++++++++++++++ xen/common/domctl.c | 8 ++++++ xen/include/public/domctl.h | 17 ++++++++++++ xen/include/xen/domain.h | 2 ++ xen/xsm/flask/hooks.c | 3 +++ xen/xsm/flask/policy/access_vectors | 2 ++ 13 files changed, 149 insertions(+) diff --git a/tools/flask/policy/modules/dom0.te b/tools/flask/policy/module= s/dom0.te index ad2b4f9ea7..8801cb24f2 100644 --- a/tools/flask/policy/modules/dom0.te +++ b/tools/flask/policy/modules/dom0.te @@ -105,6 +105,7 @@ allow dom0_t dom0_t:domain2 { get_cpu_policy dt_overlay get_domain_state + claim_memory }; allow dom0_t dom0_t:resource { add diff --git a/tools/flask/policy/modules/xen.if b/tools/flask/policy/modules= /xen.if index ef7d8f438c..8e2dceb505 100644 --- a/tools/flask/policy/modules/xen.if +++ b/tools/flask/policy/modules/xen.if @@ -98,6 +98,7 @@ define(`create_domain_common', ` vuart_op set_llc_colors get_domain_state + claim_memory }; allow $1 $2:security check_context; allow $1 $2:shadow enable; diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 4955981231..1059629d94 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2660,6 +2660,10 @@ int xc_domain_set_llc_colors(xc_interface *xch, uint= 32_t domid, const uint32_t *llc_colors, uint32_t num_llc_colors); =20 +int xc_domain_claim_memory(xc_interface *xch, uint32_t domid, + uint32_t nr_claims, + const memory_claim_t *claims); + #if defined(__arm__) || defined(__aarch64__) int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, uint32_t overlay_fdt_size, uint8_t overlay_op); diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index 2ddc3f4f42..370917d877 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -2229,6 +2229,48 @@ out: =20 return ret; } + +/* + * Claim memory for a domain. A Domain can only have one type of claim: + * + * If the number of claims is 0, existing claims are cancelled. + * Updating claims is not supported, cancel the existing claim first. + * + * Memory allocations consume the outstanding claim and if not enough memo= ry is + * free, the allocation must be satisfied from the remaining outstanding c= laim. + */ +int xc_domain_claim_memory(xc_interface *xch, uint32_t domid, + uint32_t nr_claims, + const memory_claim_t *claims) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_claim_memory, + .domain =3D domid, + .u.claim_memory.nr_claims =3D nr_claims, + }; + int ret; + DECLARE_HYPERCALL_BUFFER(struct xen_domctl_claim_memory, buffer); + + /* Use an array to not need changes for multi-node claims in the futur= e */ + if ( nr_claims ) + { + size_t bytes =3D sizeof(memory_claim_t) * nr_claims; + + buffer =3D xc_hypercall_buffer_alloc(xch, buffer, bytes); + if ( buffer =3D=3D NULL ) + { + PERROR("Could not allocate memory for xc_domain_claim_memory"); + return -1; + } + memcpy(buffer, claims, bytes); + set_xen_guest_handle(domctl.u.claim_memory.claims, buffer); + } + + ret =3D do_domctl(xch, &domctl); + xc_hypercall_buffer_free(xch, buffer); + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 7e1aabad6c..cb1c18481b 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -369,6 +369,15 @@ external domain_deassign_device: handle -> domid -> (i= nt * int * int * int) -> u external domain_test_assign_device: handle -> domid -> (int * int * int * = int) -> bool =3D "stub_xc_domain_test_assign_device" =20 +type claim =3D + { + node: int; + nr_pages: int64; + } + +external domain_claim_memory: handle -> domid -> int -> claim array -> unit + =3D "stub_xc_domain_claim_memory" + external version: handle -> version =3D "stub_xc_version_version" external version_compile_info: handle -> compile_info =3D "stub_xc_version_compile_info" diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.= mli index f44dba61ae..32786a5f7f 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -296,6 +296,15 @@ external domain_deassign_device: handle -> domid -> (i= nt * int * int * int) -> u external domain_test_assign_device: handle -> domid -> (int * int * int * = int) -> bool =3D "stub_xc_domain_test_assign_device" =20 +type claim =3D + { + node: int; + nr_pages: int64; + } + +external domain_claim_memory: handle -> domid -> int -> claim array -> unit + =3D "stub_xc_domain_claim_memory" + external version : handle -> version =3D "stub_xc_version_version" external version_compile_info : handle -> compile_info =3D "stub_xc_version_compile_info" diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index b51fd66788..c27e6c4683 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -1424,6 +1424,27 @@ CAMLprim value stub_xc_watchdog(value xch_val, value= domid, value timeout) CAMLreturn(Val_int(ret)); } =20 +/* Claim memory for a domain. See xc_domain_claim_memory() for details. */ +CAMLprim value stub_xc_domain_claim_memory(value xch_val, value domid, + value num_claims, value desc) +{ + CAMLparam4(xch_val, domid, num_claims, desc); + xc_interface *xch =3D xch_of_val(xch_val); + int i, retval, nr_claims =3D Int_val(num_claims); + memory_claim_t claim[nr_claims]; + + for (i =3D 0; i < nr_claims; i++) { + claim[i].node =3D Int_val(Field(desc, i*2)); + claim[i].nr_pages =3D Int64_val(Field(desc, i*2 + 1)); + } + + retval =3D xc_domain_claim_memory(xch, Int_val(domid), nr_claims, claim); + if (retval < 0) + failwith_xc(xch); + + CAMLreturn(Val_unit); +} + /* * Local variables: * indent-tabs-mode: t diff --git a/xen/common/domain.c b/xen/common/domain.c index 1beadb05e1..dcfad4ab15 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -267,6 +267,36 @@ int get_domain_state(struct xen_domctl_get_domain_stat= e *info, struct domain *d, return rc; } =20 +/* XEN_DOMCTL_claim_memory: Claim an amount of memory for a domain */ +int claim_memory(struct domain *d, const struct xen_domctl_claim_memory *u= info) +{ + memory_claim_t claim; + int rc; + + switch ( uinfo->nr_claims ) + { + case 0: + /* Cancel existing claim. */ + rc =3D domain_set_outstanding_pages(d, 0, 0); + break; + + case 1: + /* Only single node claims supported at the moment. */ + if ( copy_from_guest(&claim, uinfo->claims, 1) ) + return -EFAULT; + + rc =3D domain_set_outstanding_pages(d, claim.node, + claim.nr_pages); + break; + + default: + rc =3D -EOPNOTSUPP; + break; + } + + return rc; +} + static void __domain_finalise_shutdown(struct domain *d) { struct vcpu *v; diff --git a/xen/common/domctl.c b/xen/common/domctl.c index f2a7caaf85..e7576ae00b 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -894,6 +894,14 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_= domctl) ret =3D get_domain_state(&op->u.get_domain_state, d, &op->domain); break; =20 + case XEN_DOMCTL_claim_memory: + ret =3D xsm_claim_pages(XSM_PRIV, d); + if ( ret ) + break; + + ret =3D claim_memory(d, &op->u.claim_memory); + break; + default: ret =3D arch_do_domctl(op, d, u_domctl); break; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 0c75d9d27f..5e924abd85 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1273,6 +1273,21 @@ struct xen_domctl_get_domain_state { uint64_t unique_id; /* Unique domain identifier. */ }; =20 +struct xen_memory_claim { + unsigned int node; /* NUMA node, XC_NUMA_NO_NODE for a host claim= */ + unsigned long nr_pages; /* Number of pages to claim */ +}; +typedef struct xen_memory_claim memory_claim_t; +DEFINE_XEN_GUEST_HANDLE(memory_claim_t); + +/* XEN_DOMCTL_claim_memory: Claim an amount of memory for a domain */ +struct xen_domctl_claim_memory { + /* IN: array of memory claims */ + XEN_GUEST_HANDLE_64(memory_claim_t) claims; + /* IN: number of claims */ + unsigned int nr_claims; +}; + struct xen_domctl { /* Stable domctl ops: interface_version is required to be 0. */ uint32_t cmd; @@ -1365,6 +1380,7 @@ struct xen_domctl { #define XEN_DOMCTL_gsi_permission 88 #define XEN_DOMCTL_set_llc_colors 89 #define XEN_DOMCTL_get_domain_state 90 /* stable interface */ +#define XEN_DOMCTL_claim_memory 91 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1433,6 +1449,7 @@ struct xen_domctl { #endif struct xen_domctl_set_llc_colors set_llc_colors; struct xen_domctl_get_domain_state get_domain_state; + struct xen_domctl_claim_memory claim_memory; uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index e10baf2615..bd5f37bd64 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -192,4 +192,6 @@ extern bool vmtrace_available; =20 extern bool vpmu_is_available; =20 +int claim_memory(struct domain *d, const struct xen_domctl_claim_memory *u= info); + #endif /* __XEN_DOMAIN_H__ */ diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index b0308e1b26..6b2535b666 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -853,6 +853,9 @@ static int cf_check flask_domctl(struct domain *d, unsi= gned int cmd, case XEN_DOMCTL_set_llc_colors: return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_LLC_COLO= RS); =20 + case XEN_DOMCTL_claim_memory: + return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__CLAIM_MEMORY= ); + default: return avc_unknown_permission("domctl", cmd); } diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/acc= ess_vectors index 51a1577a66..87338b5c2a 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -259,6 +259,8 @@ class domain2 set_llc_colors # XEN_DOMCTL_get_domain_state get_domain_state +# XEN_DOMCTL_claim_memory + claim_memory } =20 # Similar to class domain, but primarily contains domctls related to HVM d= omains --=20 2.43.0