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 1B49FC00140 for ; Fri, 5 Aug 2022 17:53:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.381468.616168 (Exim 4.92) (envelope-from ) id 1oK1VN-0002f1-82; Fri, 05 Aug 2022 17:53:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 381468.616168; Fri, 05 Aug 2022 17:53:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oK1VN-0002eu-4t; Fri, 05 Aug 2022 17:53:01 +0000 Received: by outflank-mailman (input) for mailman id 381468; Fri, 05 Aug 2022 17:53:00 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oK1VM-0002eo-F0 for xen-devel@lists.xenproject.org; Fri, 05 Aug 2022 17:53:00 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oK1VL-0006Sb-O0; Fri, 05 Aug 2022 17:52:59 +0000 Received: from 54-240-197-227.amazon.com ([54.240.197.227] helo=[192.168.9.179]) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oK1VL-0003UZ-Hr; Fri, 05 Aug 2022 17:52:59 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID; bh=HMYmHR92dY9g2PU3X0I7pTq+GPaKT03metYmkpUkEN4=; b=o1rUXxZDYyWsNHhTdtYfOT/8wa WVDZukrpPBJeS0b7UlNJZQHDE88bpxLlgN4TKjBphQulQPJlJGZF6wk5oO9Jl1HZnlZ6zHsiDzHVv Ia1IeO+ntYVynjTnzeGtC/+7c8auwlrlmvBd3otaB05uD0eRHXn2txByd68GRxl+9ZZs=; Message-ID: <6b81f1fe-f548-15de-eeb4-e635ef3f7955@xen.org> Date: Fri, 5 Aug 2022 18:52:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Subject: Re: [PATCH v9 3/8] xen: do not merge reserved pages in free_heap_pages() Content-Language: en-US To: Penny Zheng , xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Andrew Cooper , George Dunlap , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall References: <20220720054611.2695787-1-Penny.Zheng@arm.com> <20220720054611.2695787-4-Penny.Zheng@arm.com> From: Julien Grall In-Reply-To: <20220720054611.2695787-4-Penny.Zheng@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Penny, Sorry I only spotted a couple of typos in the commit message now. On 20/07/2022 06:46, Penny Zheng wrote: > The code in free_heap_pages() will try to merge pages with the > successor/predecessor if pages are suitably aligned. So if the pages > reserved are right next to the pages given to the heap allocator, > free_heap_pages() will merge them, and give the reserved pages to heap > allocator accidently as a result. s/accidently/accidentally/ I think. > > So in order to avoid the above scenario, this commit updates free_heap_pages() > to check whether the predecessor and/or successor has PGC_reserved set, s/PGC_reserved/PGC_staticmem/ I think both #1 and #3 can go in now. So I would be happy to handle the typoes on commit. > when trying to merge the about-to-be-freed chunk with the predecessor > and/or successor. > > Suggested-by: Julien Grall > Signed-off-by: Penny Zheng > Reviewed-by: Jan Beulich > Reviewed-by: Julien Grall > --- > v9 changes: > - no change > --- > v8 changes: > - no change > --- > v7 changes: > - no change > --- > v6 changes: > - adapt to PGC_static > --- > v5 changes: > - change PGC_reserved to adapt to PGC_staticmem > --- > v4 changes: > - no changes > --- > v3 changes: > - no changes > --- > v2 changes: > - new commit > --- > xen/common/page_alloc.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c > index a12622e921..45bd88a685 100644 > --- a/xen/common/page_alloc.c > +++ b/xen/common/page_alloc.c > @@ -1475,6 +1475,7 @@ static void free_heap_pages( > /* Merge with predecessor block? */ > if ( !mfn_valid(page_to_mfn(predecessor)) || > !page_state_is(predecessor, free) || > + (predecessor->count_info & PGC_static) || > (PFN_ORDER(predecessor) != order) || > (phys_to_nid(page_to_maddr(predecessor)) != node) ) > break; > @@ -1498,6 +1499,7 @@ static void free_heap_pages( > /* Merge with successor block? */ > if ( !mfn_valid(page_to_mfn(successor)) || > !page_state_is(successor, free) || > + (successor->count_info & PGC_static) || > (PFN_ORDER(successor) != order) || > (phys_to_nid(page_to_maddr(successor)) != node) ) > break; Cheers, -- Julien Grall