From nobody Sat Nov 23 13:46:45 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=1729849899; cv=none; d=zohomail.com; s=zohoarc; b=DB3YkyR2tIZGioqKaFPczSItwKtzNFjYetSrzvTF8L4W2NJR6acrI1dioJA2lbBdaPsf0UIUJnsf0Jnvz3oSF6Q2WbuaDsOtZo635/14e9H4VKC7GeLj3Q7jw3xUL8u82jl4ZEDl+yNBM4/fXf7qO53zlW7JvSs0FSfSHp5Mnno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729849899; 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=OlOKRb79JOR8Iox1AMMS2Z+x3IHOPW+Lic0/pCOh5GY=; b=Z3I0b7uwGV/iq8KEunHb4Y9UT97gqaqLrhhD83+VyClAel1DZfI5Ga3/MPoWJEzvgT+VHj5EfIDwVq+bgKzK2ky5rQF/HgKghz/14esR+/IGu3csBDSV/1Cro4/crfn8Go4RFzJAbt7cTp3nVmm9uJX2lO7X4oH0spmrRLqP4Ks= 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 1729849899272513.0600090916121; Fri, 25 Oct 2024 02:51:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.825712.1240070 (Exim 4.92) (envelope-from ) id 1t4GyC-0007qO-PK; Fri, 25 Oct 2024 09:51:00 +0000 Received: by outflank-mailman (output) from mailman id 825712.1240070; Fri, 25 Oct 2024 09:51:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t4GyC-0007q3-L4; Fri, 25 Oct 2024 09:51:00 +0000 Received: by outflank-mailman (input) for mailman id 825712; Fri, 25 Oct 2024 09:50:59 +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 1t4GyB-0006YL-Eb for xen-devel@lists.xenproject.org; Fri, 25 Oct 2024 09:50:59 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a25e8879-92b6-11ef-99a3-01e77a169b0f; Fri, 25 Oct 2024 11:50:57 +0200 (CEST) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5c9709c9b0cso2486869a12.1 for ; Fri, 25 Oct 2024 02:50:57 -0700 (PDT) Received: from carlo-ubuntu.home (dynamic-adsl-94-34-131-227.clienti.tiscali.it. [94.34.131.227]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb629e17dsm446938a12.34.2024.10.25.02.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 02:50:55 -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: a25e8879-92b6-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1729849857; x=1730454657; 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=OlOKRb79JOR8Iox1AMMS2Z+x3IHOPW+Lic0/pCOh5GY=; b=atH/LTHlQY7V30MGxu5y7uVPsh0mQ2Oj9nEgLqXqDMwTVzysU4+pDDkVZOmlf0hyP+ eFmgb0Lyssi23qPgsu/sA4fjQBQHlOeGWwzO2E8eHbmn49mUNRKYy09noYstUqeCYz1w Gjo7kNt/PMnPu0uit9ono6rVfVxGyFA1IjWuwRK/EbJgr7WVlM8AI8aO/z9Ap5ogDdND 7ncS+XqOyf6B2/++As7p7wl6ZwEBNfTLm3otSEY9juSIbWR82Uzjsbpol4nlM8RKqK4U 88E6+saf4p4J+Nz5bZenI8kkq91XQYNvESyw5E+PEZQhBngQ1mOqDDflN2W48jggBUUe v/RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729849857; x=1730454657; 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=OlOKRb79JOR8Iox1AMMS2Z+x3IHOPW+Lic0/pCOh5GY=; b=NcJZ82KzK28uPsOc+HKD7bzFfliows0npp7ftFmI2uMNQCaKRg9can1yFWl2QcFOU3 42Y6nZSIXi8XASCq77j0Abc9jitOzEYduwybgul9LyTiSGiwtHhQzSwcqz+U1MqSlkgQ cjrM5v5NuJFopVJvq5JBRcbPxiWUiMv9wX4jnKeXFLAZItl5QZrJSK9tZJMabx8OXjLL Gk1cSZeXkqgjTGPjNufp+GR8RJ8jbXjnPX7xcYxlAav0nPTCbyFk5lLqsiYqdiV3LJGJ XJ6zvjPW/gOxru6qnBPjJFSB5Wmxg+dx0hRcKXnmje59qM0A0jDWSzc3LlozOJY9+aW9 uVwg== X-Gm-Message-State: AOJu0YyNq+usEdasAmP2RcTBBTKg8biKvWO1sSkHl6I37LVDg3Qgss7A WkQL/j7d8inoSkH1qrfysR6WPHyCqFFaaFH1Z7vERoJ++GcQuyZBW5e8WLRqpvR9nVLSkKxjd+x 1q+s= X-Google-Smtp-Source: AGHT+IEjqy/lb5M+WgV6jHA4Q8noP62nrv1a7Mfyl0L/WVNWjwfPd7CThK7DV+GuDPNtkHq6pm4Kpg== X-Received: by 2002:a05:6402:34cc:b0:5cb:6c39:2306 with SMTP id 4fb4d7f45d1cf-5cb8ac3494cmr6440132a12.4.1729849856976; Fri, 25 Oct 2024 02:50:56 -0700 (PDT) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v9 08/13] xen/page_alloc: introduce preserved page flags macro Date: Fri, 25 Oct 2024 11:50:09 +0200 Message-ID: <20241025095014.42376-9-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241025095014.42376-1-carlo.nonato@minervasys.tech> References: <20241025095014.42376-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: 1729849900140116600 Content-Type: text/plain; charset="utf-8" PGC_static and PGC_extra needs to be preserved when assigning a page. Define a new macro that groups those flags and use it instead of or'ing 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 new pages as this is considered an error and can cause ASSERT violations. Signed-off-by: Carlo Nonato --- 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