Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4CA2CD6E55 for ; Wed, 3 Jun 2026 12:29:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1326147.1591578 (Exim 4.92) (envelope-from ) id 1wUkiF-0004JS-Mv; Wed, 03 Jun 2026 12:28:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1326147.1591578; Wed, 03 Jun 2026 12:28:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUkiF-0004JL-Jp; Wed, 03 Jun 2026 12:28:47 +0000 Received: by outflank-mailman (input) for mailman id 1326147; Wed, 03 Jun 2026 12:28:46 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUkiE-0004JF-EJ for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 12:28:46 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUkiD-006dL6-Cb for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 14:28:45 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a201def-2eae-0a2a0a5409dd-0a2a450c88b0-38 for ; Wed, 03 Jun 2026 14:28:45 +0200 Received: from [209.85.128.42] (helo=mail-wm1-f42.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a201dfc-62f1-0a2a450c0019-d155802ac166-3 for ; Wed, 03 Jun 2026 14:28:45 +0200 Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-490b2b037d2so16070895e9.3 for ; Wed, 03 Jun 2026 05:28:45 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ed944sm7528208f8f.13.2026.06.03.05.28.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Jun 2026 05:28:43 -0700 (PDT) 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=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780489724; x=1781094524; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=rP22kDExa/ctfuohdGJtotFhk/gyIcpq1jo8pcUKPWY=; b=TqYZUISUizgM584nmrTEYKEPgO0e1CZJEbG1B7Mw4RYxKhgR5dO4eF2ELZiJOAkcNx Wl6l2FfnuO14WEyfXo0qfvZvNhxOiD5pBsIGUA2DP2RSUpBGSOqwJuS418YC9Vv+cx7C 2w5bWS2dltWtbDVn5uwAnzDtuwhqtRKTf6ZClV/E5y8AJDmJ7oCcYdns+U96Oo/SokLl R6ypDt9yjpH3eMQPYLJhLe8ZMlHuM4Xqz+W/PD944n3ddOCw/b+r505yE3HCVBziN66e 2d10PKb4BdjHqm5hFPkgOlCKUIqgH2nijQyL32fi9nzOkWqu1cK3mvcJkcOtR4c7p8V9 SwuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780489724; x=1781094524; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rP22kDExa/ctfuohdGJtotFhk/gyIcpq1jo8pcUKPWY=; b=Iep1J++FTJDQ+/vsxGOExfqoZjAdbjOif96QMkUHC6qqf0BITUm56Cmgj9wstBD8QO 7WmNKwZKMQ97iuIU0VLPWAOrD1IC1813ee8D9VaeHCsPbVbzedhzj0rkUvkvyZB4kQXc As6v21fyy9QIsy6CCP2VW+gO5UrgB/yLHkhmaVXPB88Ws5n+dFfbokOgG7S0uMK0gPiD k6ztv6f4oFOHmjgu1RjoLbBbDwl0OW4jZJXycyP4OTsRrk/7Au48sTmkie9br5gOW7dk LepgfCMQwNg251jsBHztV18eJ6OL03hUKl7qWrayLVdv5ob8ADmVPFD7NF+u4QTqb900 qRHQ== X-Forwarded-Encrypted: i=1; AFNElJ9AUKb4JRFt+rme2kKdV5VR4iBM7lPlYhr5zQMXEaJ4eKdfy2n73BXxH6pwqRLrKNEg1esoTYbRcBM=@lists.xenproject.org X-Gm-Message-State: AOJu0Yxzufov6PHEJGd+6qVDXKL3Ys1WHEb4obh+0wIwtSeVmblVAXAU o1AKfojc9GJNEVw0818Vgv7TC7lQwI31gWcuHmYaZGSkDAsmKYtUJ0e3vg8RSS2gcA== X-Gm-Gg: Acq92OGRYf2B0K2Wq2QUqzWi/L8uufB0/qXdJbXNeft+zjoMw0vhtX8qJHbeDd9lW18 0UwNIZB5dAGlqAHOvhnHtP+esq7XtOg5zeGpsaRbLf+wPq2B/ZpyGz1dXj4RzP94KKwMVv0x7A2 jBABHt2K95IAOp5aCTVDINFr9riU5PCWXqMVY4pE9PM0fCMnle09XWOIpNjosxnjRGYCdAnvf6f GB5Q6v+GaxTWeGgMjl3vCXIIaUcyD/VUcp/4Y/xSQBg6lmf3sYXvgWH4y7jN0Vzk12vDJ6AR5ra UwGXUe5Gkch314KRyNiILsSnk/ryHIfJCKZ4ou0PUEAlREfjGTPzof9mV1FvWInUDbT6XVAXq// SIahsaYt7O/CmF/ZpNips7KpK02/7KfW9lH5u3tbIJLzdAKp8S9cshi4koJtaeTe5zboPonEnrq IudztEbVHrbNE0vmC9ad4E+stWYwkYRvXYGozYRmeaCX0C28JMFolVFuXda/kJ1MoKmHG5+u0RI BUT5QmEb47Uxk+Jgsg4q+hKKg== X-Received: by 2002:a05:600c:1392:b0:490:b202:4772 with SMTP id 5b1f17b1804b1-490b5e95f69mr53422555e9.2.1780489724215; Wed, 03 Jun 2026 05:28:44 -0700 (PDT) Message-ID: <4f03728e-22a2-435c-8d80-eeccefdf3a31@suse.com> Date: Wed, 3 Jun 2026 14:28:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/4] xen/mm: Recall claims when offlining pages if needed To: Bernhard Kaindl Cc: Anthony PERARD , Andrew Cooper , Michal Orzel , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , xen-devel@lists.xenproject.org References: Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt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3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-purgate-ID: tlsNG-d25034/1780489725-E0766CF5-5528F1A8/0/0 X-purgate-type: clean X-purgate-size: 4027 On 20.04.2026 15:19, Bernhard Kaindl wrote: > Fix a bug where offlining pages could cause an unsigned underflow > in total_avail_pages - outstanding_claims, leading to incorrect > claim behavior. > > This issue arises when outstanding claims are close to the total > available pages. It occurse when domain_set_outstanding_claims() > and domain_install_claim_set effectively do this: > > unsigned long avail_pages = total_avail_pages - outstanding_claims; > > When this unsigned subtraction underflows, staking claims can succeed > even when there is insufficient unclaimed memory for the new claim. > This leads to a state where claims always succeed, regardless of > actual memory availability. > > To prevent this, recall claims when offlining pages if needed to maintain > equilibrium between `total_avail_pages` and outstanding claims for global > and for per-NUMA-node claims. > > Signed-off-by: Bernhard Kaindl First: This patch being a bug fix (which, btw, lacks a Fixes: tag), it wants to move ahead of the NUMA claims series, to facilitate backporting. > --- a/xen/common/page_alloc.c > +++ b/xen/common/page_alloc.c > @@ -1575,6 +1575,48 @@ static int reserve_offlined_page(struct page_info *head) > count++; > } > > + if ( count ) Why did you decide to put this in reserve_offlined_page()? The function has two callers, yet in one case the extra checking is entirely unneeded afaict. While in the other case we further know that it's exactly one page which is being offlined. > + { > + long recall_pages; > + struct domain *d; > + > + /* Ensure that claims on the node are in line with its free memory. */ > + recall_pages = node_outstanding_claims[node] - node_avail_pages[node]; > + if ( recall_pages > 0 ) > + /* > + * node_avail_pages slipped below node_outstanding_claims. > + * We need to recall claimed pages until the amount of claimed > + * memory is in line with the amount of available memory again. > + */ > + for_each_domain ( d ) Such loops need serializing against domain list modifications. Also we really don't want to loop over all domains twice. > + { > + if ( d->claims[node] ) > + { > + recall_pages -= deduct_node_claims(d, node, recall_pages); > + if ( recall_pages <= 0 ) > + break; > + } > + } So domains early on the list are penalized over ones later on the list? The only truly fair approach I can think of right away looks to be to discard all claims, requiring the toolstack to re-establish them. With the observation above the next best approach might be to cycle through domains, removing one page from their claim and recording where we left off (the per-node part would be slightly more involved). However, any reduction of a claim is likely to render that claim useless altogether. Hence requiring admin action (to re-establish claims) may still be the least bad option. Jan > + /* Ensure that outstanding claims are in line with available memory. */ > + recall_pages = outstanding_claims - total_avail_pages; > + if ( recall_pages > 0 ) > + /* > + * total_avail_pages slipped below outstanding_claims. > + * We need to recall claimed pages until the amount of claimed > + * memory is in line with the amount of available memory again. > + */ > + for_each_domain ( d ) > + { > + if ( d->global_claims ) > + { > + recall_pages -= deduct_global_claims(d, recall_pages); > + if ( recall_pages <= 0 ) > + break; > + } > + } > + } > + > return count; > } >