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 CE9B1C43334 for ; Mon, 18 Jul 2022 10:25:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.369517.600961 (Exim 4.92) (envelope-from ) id 1oDNw0-0002zU-BY; Mon, 18 Jul 2022 10:25:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 369517.600961; Mon, 18 Jul 2022 10:25:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oDNw0-0002zN-8e; Mon, 18 Jul 2022 10:25:04 +0000 Received: by outflank-mailman (input) for mailman id 369517; Mon, 18 Jul 2022 10:25:03 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oDNvz-0002zH-7e for xen-devel@lists.xenproject.org; Mon, 18 Jul 2022 10:25:03 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oDNvw-00040O-4G; Mon, 18 Jul 2022 10:25:00 +0000 Received: from 54-240-197-231.amazon.com ([54.240.197.231] helo=[10.7.237.21]) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oDNvv-00013F-Td; Mon, 18 Jul 2022 10:25:00 +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=RfLkMiU8Rc3aS7KcPMgPRlsIWsww1erp3QPFr18f9WY=; b=gucXQqQC1e7viY65H94J1K7UDj xzDcTkEf+WJgpaZgk6XdvOy5gwXwhaSPfHs0TtbFSsIus5T0c3YizYKEEh/nWx2HPpEU64oz/c3HK RGAx+BfpzqPHGytabbJ7i+JYhPkgh4hNvduj199CYhzgb+TFpGAI2JX83r87P2H0u8UQ=; Message-ID: Date: Mon, 18 Jul 2022 11:24:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2 3/3] xen/heap: pass order to free_heap_pages() in heap init To: Jan Beulich Cc: Hongyan Xia , Andrew Cooper , George Dunlap , Stefano Stabellini , Wei Liu , Julien Grall , xen-devel@lists.xenproject.org References: <20220715170312.13931-1-julien@xen.org> <20220715170312.13931-4-julien@xen.org> <0242a659-fcf9-74cc-102c-df775123b7ac@suse.com> From: Julien Grall In-Reply-To: <0242a659-fcf9-74cc-102c-df775123b7ac@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Jan, On 18/07/2022 10:43, Jan Beulich wrote: > On 15.07.2022 19:03, Julien Grall wrote: >> @@ -1806,8 +1806,22 @@ static void _init_heap_pages(const struct page_info *pg, >> >> while ( s < e ) >> { >> - free_heap_pages(mfn_to_page(_mfn(s)), 0, need_scrub); >> - s += 1UL; >> + /* >> + * For s == 0, we simply use the largest increment by checking the >> + * MSB of the region size. For s != 0, we also need to ensure that the >> + * chunk is properly sized to end at power-of-two alignment. We do this >> + * by checking the LSB of the start address and use its index as >> + * the increment. Both cases need to be guarded by MAX_ORDER. > > s/guarded/bounded/ ? > >> + * Note that the value of ffsl() and flsl() starts from 1 so we need >> + * to decrement it by 1. >> + */ >> + int inc_order = min(MAX_ORDER, flsl(e - s) - 1); > > unsigned int, since ... MAX_ORDER, flsl(), ffsl() are both returning signed value. So inc_order should be 'int' to avoid any compilation issue. > >> + if ( s ) >> + inc_order = min(inc_order, ffsl(s) - 1); >> + free_heap_pages(mfn_to_page(_mfn(s)), inc_order, need_scrub); > > ... that's what the function parameter says, and the value also can go > negative? AFAICT, none of the values are negative. But per above, if we use min() then the local variable should be 'int'. The two possible alternatives are: 1) Use min_t() 2) Update MAX_ORDER, flsl(), ffsl() to return an unsigned value The ideal would be #2 but it will require at least an extra patch and effort. If we use #1, then they use may become stale if we implement #2. So I would prefer to keep min(). That said, I would be open to use min_t() if you strongly prefer it. > Preferably with these adjustments > Reviewed-by: Jan Beulich Thanks! Cheers, -- Julien Grall