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 60868C54E67 for ; Wed, 27 Mar 2024 13:48:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698556.1090368 (Exim 4.92) (envelope-from ) id 1rpTdu-0006UH-4C; Wed, 27 Mar 2024 13:48:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698556.1090368; Wed, 27 Mar 2024 13:48:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpTdu-0006UA-0K; Wed, 27 Mar 2024 13:48:38 +0000 Received: by outflank-mailman (input) for mailman id 698556; Wed, 27 Mar 2024 13:48:37 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpTdt-0006U0-5B for xen-devel@lists.xenproject.org; Wed, 27 Mar 2024 13:48:37 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpTdq-000792-QG; Wed, 27 Mar 2024 13:48:34 +0000 Received: from [15.248.2.236] (helo=[10.24.67.40]) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1rpTdq-0002v2-KY; Wed, 27 Mar 2024 13:48:34 +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=megaul14JSKhWrBzrhVIim2ZO+HBxbk+vEsvGwq28Yc=; b=glTCSP/je66+/cWNI+hbyoX9NU s8VNi9syLscN5ZAHOKcTORqNVFMTbpO1GikqevME4SlZnE2dXyYu4Fh9izJXWxpGyIRfqnj6LiU4s LZBfy/Wi9RzeHaMbRnZ9XXZJXFTa5yidw7U2MwVpSTlPupQ0IeZcxbJwwTUexI8XK230=; Message-ID: Date: Wed, 27 Mar 2024 13:48:32 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 08/14] xen/page_alloc: introduce preserved page flags macro Content-Language: en-GB To: Jan Beulich , Carlo Nonato Cc: Andrew Cooper , George Dunlap , Stefano Stabellini , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , xen-devel@lists.xenproject.org References: <20240315105902.160047-1-carlo.nonato@minervasys.tech> <20240315105902.160047-9-carlo.nonato@minervasys.tech> <3f615066-a792-493f-ba33-7667a6557c23@xen.org> <9e0f7ff3-5457-41e4-a1e4-bf75804fb900@xen.org> <255be735-f9fe-4e39-a24e-2f6aff91acc5@suse.com> <3427132d-9458-4447-b667-d2ef3c1f0569@suse.com> <54156e94-3630-49b1-8a22-5cd4206d565f@xen.org> From: Julien Grall In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 27/03/2024 13:38, Jan Beulich wrote: > On 27.03.2024 14:28, Julien Grall wrote: >> Hi Carlo, >> >> On 27/03/2024 11:10, Carlo Nonato wrote: >>> Hi guys, >>> >>>> Question is: How would you justify such a change? IOW I'm not convinced >>>> (yet) this wants doing there. >>> >>> You mean in this series? >>> >>>> Looking at the code, the flag is originally set in >>>> alloc_domheap_pages(). So I guess it would make sense to do it in >>>> free_domheap_pages(). >>> >>> We don't hold the heap_lock there. >> Regardless of the safety question (I will answer below), count_info is >> not meant to be protected by heap_lock. The lock is protecting the heap >> and ensure we are not corrupting them when there are concurrent call to >> free_heap_pages(). >> >> > Is it safe to change count_info without it? >> >> count_info is meant to be accessed locklessly. The flag PGC_extra cannot >> be set/clear concurrently because you can't allocate a page that has not >> yet been freed. >> >> So it would be fine to use clear_bit(..., ...); > > Actually we hardly ever use clear_bit() on count_info. Normally we use > ordinary C operators. I knew you would say that. I am not convince it is safe to always using count_info without any atomic operations. But I never got around to check all them. > Atomic (and otherwise lockless) updates are useful > only if done like this everywhere. You are right. But starting to use the bitops is not going to hurt anyone (other than maybe performance, but once we convert all of them, then this will become moot). In fact, it helps start to slowly move towards the aim to have count_info safe. Cheers, -- Julien Grall