From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F924212B0A for ; Mon, 3 Mar 2025 14:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741010821; cv=none; b=CXtUIIwxritPDlNJiRvPDmwSR/gW4uP2SHBtUEinpMGZC/T6TZJ1pEqybW/EBNbESpMIgdeoKIIx041OkLfl9O/hLUekujKWCfe0yfP/vCXTzGtca2jPOUXb8vFMbzwQ4iov1nz2DUKhg2lz9xw5cV7hl4xHQc0BPdZ10QM8cIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741010821; c=relaxed/simple; bh=bAX4nJtptqzVGzhMVWEvU2Vo1a4TfNKeNSRZoHICbTE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MIIdxWLviHKSlKNVo8UwOqGd+EeilqylzSM4+m5R2h87r8NrqNUW+CbCQKf+ZwG4MKUziZIo0MxcbB3B+05sANVnS+1wDbwJ35XMgNoRNjPaZ0lUUFBqsbQX6x0VyzRPwtl7QAx6gZ8r+8KH9nfDKbP6R5qSHvskDj9uUqWWmGU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CY+my+G0; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CY+my+G0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741010818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=ZbNj59zjmhBNc1+Y3UiFD4MOycUDZRwg2fQUZMSseuI=; b=CY+my+G0NPfXP6AVPl13K+f0ez6BPr7+Tg+mPR4ic3DH+Cs90xKBzaweefQDNbbB+DsfVL qcSeryRv0gLnbv7qUsrLpP7JguPWk4hpFZOpsdVLPnTxDHPSoHjMnEzKm1QFHeHFroQ693 tJH8Gw+aE13OvTOizfETa9UVZGGhE8M= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-b2FJO2HaPDeAjLFh487bXQ-1; Mon, 03 Mar 2025 09:06:57 -0500 X-MC-Unique: b2FJO2HaPDeAjLFh487bXQ-1 X-Mimecast-MFC-AGG-ID: b2FJO2HaPDeAjLFh487bXQ_1741010816 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43941ad86d4so19923085e9.2 for ; Mon, 03 Mar 2025 06:06:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741010816; x=1741615616; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=ZbNj59zjmhBNc1+Y3UiFD4MOycUDZRwg2fQUZMSseuI=; b=QyTnKX5k6pYt5XyLt5uHHL/cWhg9ean4gV/eUc991NZqYExgPZLRzsAcIRYfVGlDvm ox2h0HmimFOdK3LP9H/Oh7cothj+l1TvM8IMa5KHDXuFFXTSU6xPJIMPGslU2uiZMTOR lKNOK6PUVVsJcVl5sh+7Qe6UiY6S+8wgPt0YdHC3QIZSzjmRgD1W8ZCFLAml0kV3BrHQ VykyyrUvWA+tUC+PNdrbnLzZzvvVuUwmllEKWO6DrL03DngQdk9Wo7IrvQavkU1ylvjb pCy0R5WAJHUPshr83tUKGTPa37hSqZ44orxT6baOvqoJqCyYY04CO7JXirIwualvLgqK oQfA== X-Forwarded-Encrypted: i=1; AJvYcCVB/6RBH1VE4BTcHmmtGEhgo/ayo3qsFeER9xTn3+rbjGCtSpWCIT03F/D+RE9EZWRv6yddQ5YXjwpyd3g=@vger.kernel.org X-Gm-Message-State: AOJu0YwDaQLAmPk3fq6VvZGzbZhkl1/cQyX/TGplVbzrO6HMYR16WXcO pga6S32G8ZT94II6rGABLqMFHu1UO513l0A/c48tJRKm0dZX45MTxaMUVXeWSdUIBNs3ixhb3sR TkcN3oSriw3VuupDJzW4Hc3C4IoabHUnaDywa2lizFXOyUSG05ADrJJM0dUkD7A== X-Gm-Gg: ASbGnct1cEUGmdpv5b2KXB6cGwy3AQArZvE11x+P/bgmIcORMbVhRNPLCoefa9Dz4sO Hkx+Ql7dAKbwDxtZR0hOHLEESQa1av9zGbpaLSoXtderXsUAXJQBcOVfuT7q1pZ3ruKFHfBCr3r lVBwNLAdfkTeCiq0uiXSgt/665vn++IVh9SU9YI41ntNKos2Cn0J4X0v+mg/54stadnGdEK0bCE JI38O4F2/j7F3TaZPprErQ9a7j+o6tFJF4HKVVbkRoZDgbUmiI9Aro16PWSFqNMCjkx426Fl6mK GtAY7Z8wqD20kR7165az8rv4oVbcPFlwNasWeiq5u4Xh6Bp/Z+p+fEvpMfqvBHVpnALFnMi8lKG msD1htl+aeXQM4pIa66fLgFWGS//hsv+mgXHN68XBywk= X-Received: by 2002:a05:6000:2a1:b0:391:865:5aa8 with SMTP id ffacd0b85a97d-39108655d1amr4255876f8f.54.1741010816040; Mon, 03 Mar 2025 06:06:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMe6rYNOM1qtAY4H/zcbfK2YO8wdVNhdC2+hSh24NYQSxkXER6ttJ97UQPoaWhG2iYJrqOiw== X-Received: by 2002:a05:6000:2a1:b0:391:865:5aa8 with SMTP id ffacd0b85a97d-39108655d1amr4255809f8f.54.1741010815529; Mon, 03 Mar 2025 06:06:55 -0800 (PST) Received: from ?IPV6:2003:cb:c734:9600:af27:4326:a216:2bfb? (p200300cbc7349600af274326a2162bfb.dip0.t-ipconnect.de. [2003:cb:c734:9600:af27:4326:a216:2bfb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e47a5b96sm14521806f8f.29.2025.03.03.06.06.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Mar 2025 06:06:55 -0800 (PST) Message-ID: <3e66875e-a4d5-4802-85b3-f873b0aa3b06@redhat.com> Date: Mon, 3 Mar 2025 15:06:54 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/page_alloc: Add lockdep assertion for pageblock type change To: Brendan Jackman Cc: Andrew Morton , Oscar Salvador , Johannes Weiner , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250303-pageblock-lockdep-v2-1-3fc0c37e9532@google.com> <4d0f0bca-3096-4fb4-9e8b-d4dcdf7eeb92@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekB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sgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 03.03.25 14:55, Brendan Jackman wrote: > On Mon, Mar 03, 2025 at 02:11:23PM +0100, David Hildenbrand wrote: >> On 03.03.25 13:13, Brendan Jackman wrote: >>> Since the migratetype hygiene patches [0], the locking here is >>> a bit more formalised. >>> >>> For other stuff, it's pretty obvious that it would be protected by the >>> zone lock. But it didn't seem totally self-evident that it should >>> protect the pageblock type. So it seems particularly helpful to have it >>> written in the code. >> >> [...] >> >>> + >>> u64 max_mem_size = U64_MAX; >>> /* add this memory to iomem resource */ >>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>> index 579789600a3c7bfb7b0d847d51af702a9d4b139a..1ed21179676d05c66f77f9dbebf88e36bbe402e9 100644 >>> --- a/mm/page_alloc.c >>> +++ b/mm/page_alloc.c >>> @@ -417,6 +417,10 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, >>> void set_pageblock_migratetype(struct page *page, int migratetype) >>> { >>> + lockdep_assert_once(system_state == SYSTEM_BOOTING || >>> + in_mem_hotplug() || >>> + lockdep_is_held(&page_zone(page)->lock)); >>> + >> >> I assume the call chain on the memory hotplug path is mostly >> >> move_pfn_range_to_zone()->memmap_init_range()->set_pageblock_migratetype() >> >> either when onlining a memory block, or from pagemap_range() while holding >> the hotplug lock. >> >> But there is also the memmap_init_zone_device()->memmap_init_compound()->__init_zone_device_page()->set_pageblock_migratetype() >> one, called from pagemap_range() *without* holding the hotplug lock, and you >> assertion would be missing that. >> >> I'm not too happy about that assertion in general. > > Hmm, thanks for pointing that out. > > I guess if we really wanted the assertion the approach would be to > replace in_mem_hotplug() with some more fine-grained logic about the > state of the pageblock? But that seems like it would require rework > that isn't really justified. I was wondering if we could just grab the zone lock while initializing, then assert that we either hold that or are in boot. In move_pfn_range_to_zone() it should likely not cause too much harm, and we could just grab it around all zone modification stuff. memmap_init_zone_device() might take longer and be more problematic. But I am not sure why memmap_init_zone_device() would have to set the migratetype at all? Because migratetype is a buddy concept, and ZONE_DEVICE does not interact with the buddy to that degree. The comment in __init_zone_device_page states: "Mark the block movable so that blocks are reserved for movable at startup. This will force kernel allocations to reserve their blocks rather than leaking throughout the address space during boot when many long-lived kernel allocations are made." But that just dates back to 966cf44f637e where we copy-pasted that code. So I wonder if we could just diff --git a/mm/mm_init.c b/mm/mm_init.c index 57933683ed0d1..b95f545846e6e 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1002,19 +1002,11 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, page->zone_device_data = NULL; /* - * Mark the block movable so that blocks are reserved for - * movable at startup. This will force kernel allocations - * to reserve their blocks rather than leaking throughout - * the address space during boot when many long-lived - * kernel allocations are made. - * - * Please note that MEMINIT_HOTPLUG path doesn't clear memmap - * because this is done early in section_activate() + * Note that we leave pageblock migratetypes uninitialized, because + * they don't apply to ZONE_DEVICE. */ - if (pageblock_aligned(pfn)) { - set_pageblock_migratetype(page, MIGRATE_MOVABLE); + if (pageblock_aligned(pfn)) cond_resched(); - } /* * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released -- Cheers, David / dhildenb