From nobody Fri Dec 27 14:28:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1732025641; cv=none; d=zohomail.com; s=zohoarc; b=TXFp5n+yDONnZK+59Xzfuv1oC2nyFXyP2MVTV16echwQdu5DUksiMZwVLzEgC3QXDHu8ITjsaNF168lZAeOm9AowbWJITNwAiLALJoi2RBAUW2ZddL5Vz9Iu1fq/DYGnD8bARSzmwWEm2FV0OHSlQBVVkIrnSQOq9OEH0PWiCAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732025641; 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=uer5hFgR43ABSJ0pS6NmbiLoEW2DGJcmVhOAoFMQvSI=; b=b4X+gI0cMBDSSOyhul9oHtmQJjpJyBj5xxWbXOIU8ZiN9r0nu8WXc4rprglzc/ndoWuG5QR0iENfP0gPXRoBnT0pDfqhpn/c6Cqx8px4VPYBSCSoBL0b2obxwnya9dF7M+SGfK8ednfoNS3ow5o2o/cjUUWOV+OsmCJFFTAsQ4w= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1732025641876632.8048434524172; Tue, 19 Nov 2024 06:14:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.840128.1255963 (Exim 4.92) (envelope-from ) id 1tDOzB-0000k1-3w; Tue, 19 Nov 2024 14:13:45 +0000 Received: by outflank-mailman (output) from mailman id 840128.1255963; Tue, 19 Nov 2024 14:13:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tDOzA-0000im-Pp; Tue, 19 Nov 2024 14:13:44 +0000 Received: by outflank-mailman (input) for mailman id 840128; Tue, 19 Nov 2024 14:13:43 +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 1tDOz8-0007nQ-Rd for xen-devel@lists.xenproject.org; Tue, 19 Nov 2024 14:13:42 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7a1e6284-a680-11ef-a0ca-8be0dac302b0; Tue, 19 Nov 2024 15:13:40 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5cfadf851e2so4527804a12.2 for ; Tue, 19 Nov 2024 06:13:40 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df4e7bfsm655228166b.42.2024.11.19.06.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 06:13:39 -0800 (PST) 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: 7a1e6284-a680-11ef-a0ca-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzIiLCJoZWxvIjoibWFpbC1lZDEteDUzMi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjdhMWU2Mjg0LWE2ODAtMTFlZi1hMGNhLThiZTBkYWMzMDJiMCIsInRzIjoxNzMyMDI1NjIwLjgxMDAyNSwic2VuZGVyIjoiY2FybG8ubm9uYXRvQG1pbmVydmFzeXMudGVjaCIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1732025620; x=1732630420; 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=uer5hFgR43ABSJ0pS6NmbiLoEW2DGJcmVhOAoFMQvSI=; b=ndVbMCmDXLre9XSlOBgDiMX/74K7JHmCu4CMFpsaMlhLpD2urExZAsvk18H/k0ZPCQ JRuMgyRQOArILSC2bTgQqInC9qQd/BDwPxgNIEB4PMz7gaBs1tSq3J/I8q7+hDBOo36F A9FJbR/k4i1X226ewCGOjAi71852p7xduwMX3Ibm52ZyocLdwnf/bLyfBnJleiFYJnEC LAfEaw6W5NBufkVUQSMHk568dmpC4prSdPjbj+EtnVu0MOYXwzk40q+HSK2leqz2GfXL sTA6tGJCe2xfetaiHPa/1uroghehoFOOBNcjBaoLmBCLmtBh/M8ZpMm7DuDbviK/BncO tf2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732025620; x=1732630420; 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=uer5hFgR43ABSJ0pS6NmbiLoEW2DGJcmVhOAoFMQvSI=; b=bdl9c8Zgi7rUflWeW5LuGkEgnefPONso2TGzN8LBF4ycxl7vcCKL1Owxft4l/+Dqvd 512BjQ6O6KMepkzES+WLh1jBN3xMIBJBcJlwk8HSdhB9oqtCKjweJotj5NP0TZLNkq0D xdKkAQEF9su4SfXlcmytuZhpoaiED501NmNLcTbPK3cr+F6jhuTDYwU6OXHPXpXwQvYz hBYyTkgZsnKZpDqb1oGP9SEJsAnB22iKeK99BFXgY7Mi7CyEqCjb+NZgMo+qc4TSFA2A mEknlZtvnZg+PQsMpTtTAmVIs1gzu5A94jztRBYK0BfF0F01q1GgFY8PyOt+JfWEATLu i3vA== X-Gm-Message-State: AOJu0YzBgA03Iuieov9WvNAMx4wc0wqkw0SaSRyInV6EVJW9SnJRkQB3 U1+Ljdbrl2RUDmCQvS/1WvvDpLZyoDoARVdWL/IV5MsWKAipaLWMgYeDoZiI+auGDqQUvKNXS/5 3 X-Google-Smtp-Source: AGHT+IH+9A7o5Ci7KbPH6cwZ0XuRuZEcmB8xC+Qsc7y118QKANgbRI7cqELzvF0XD8c7z0NIxCbZHQ== X-Received: by 2002:a05:6402:50cf:b0:5cf:c99d:2db3 with SMTP id 4fb4d7f45d1cf-5cfc99d2e36mr5847632a12.29.1732025620020; Tue, 19 Nov 2024 06:13:40 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v10 08/12] xen/page_alloc: introduce preserved page flags macro Date: Tue, 19 Nov 2024 15:13:25 +0100 Message-ID: <20241119141329.44221-9-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241119141329.44221-1-carlo.nonato@minervasys.tech> References: <20241119141329.44221-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1732025644086116600 Content-Type: text/plain; charset="utf-8" PGC_static, PGC_extra and PGC_broken need to be preserved when assigning a page. Define a new macro that groups those flags and use it instead of or'i= ng every time. To make preserved flags even more meaningful, they are kept also when switching state in mark_page_free(). Enforce the removal of PGC_extra before freeing domain pages as this is considered an error and can cause ASSERT violations. Signed-off-by: Carlo Nonato --- v10: - fixed commit message v9: - add PGC_broken to PGC_preserved - clear PGC_extra in alloc_domheap_pages() only if MEMF_no_refcount is set v8: - fixed PGC_extra ASSERT fail in alloc_domheap_pages() by removing PGC_extra before freeing v7: - PGC_preserved used also in mark_page_free() v6: - preserved_flags renamed to PGC_preserved - PGC_preserved is used only in assign_pages() v5: - new patch --- xen/common/page_alloc.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 7b911b5ed9..34cd473150 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -160,6 +160,7 @@ #endif =20 #define PGC_no_buddy_merge PGC_static +#define PGC_preserved (PGC_extra | PGC_static | PGC_broken) =20 #ifndef PGT_TYPE_INFO_INITIALIZER #define PGT_TYPE_INFO_INITIALIZER 0 @@ -1427,12 +1428,11 @@ static bool mark_page_free(struct page_info *pg, mf= n_t mfn) { case PGC_state_inuse: BUG_ON(pg->count_info & PGC_broken); - pg->count_info =3D PGC_state_free; + pg->count_info =3D PGC_state_free | (pg->count_info & PGC_preserve= d); break; =20 case PGC_state_offlining: - pg->count_info =3D (pg->count_info & PGC_broken) | - PGC_state_offlined; + pg->count_info =3D (pg->count_info & PGC_preserved) | PGC_state_of= flined; pg_offlined =3D true; break; =20 @@ -2366,7 +2366,7 @@ int assign_pages( =20 for ( i =3D 0; i < nr; i++ ) { - ASSERT(!(pg[i].count_info & ~(PGC_extra | PGC_static))); + ASSERT(!(pg[i].count_info & ~PGC_preserved)); if ( pg[i].count_info & PGC_extra ) extra_pages++; } @@ -2426,7 +2426,7 @@ int assign_pages( page_set_owner(&pg[i], d); smp_wmb(); /* Domain pointer must be visible before updating refcn= t. */ pg[i].count_info =3D - (pg[i].count_info & (PGC_extra | PGC_static)) | PGC_allocated = | 1; + (pg[i].count_info & PGC_preserved) | PGC_allocated | 1; =20 page_list_add_tail(&pg[i], page_to_list(d, &pg[i])); } @@ -2485,6 +2485,14 @@ struct page_info *alloc_domheap_pages( } if ( assign_page(pg, order, d, memflags) ) { + if ( memflags & MEMF_no_refcount ) + { + unsigned long i; + + for ( i =3D 0; i < (1UL << order); i++ ) + pg[i].count_info &=3D ~PGC_extra; + } + free_heap_pages(pg, order, memflags & MEMF_no_scrub); return NULL; } @@ -2539,6 +2547,7 @@ void free_domheap_pages(struct page_info *pg, unsigne= d int order) { ASSERT(d->extra_pages); d->extra_pages--; + pg[i].count_info &=3D ~PGC_extra; } } =20 --=20 2.43.0