From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E435C282CD for ; Mon, 3 Mar 2025 13:55:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92DF46B0083; Mon, 3 Mar 2025 08:55:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DD8C6B0085; Mon, 3 Mar 2025 08:55:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A5416B0088; Mon, 3 Mar 2025 08:55:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5CB796B0083 for ; Mon, 3 Mar 2025 08:55:20 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0BF165180C for ; Mon, 3 Mar 2025 13:55:20 +0000 (UTC) X-FDA: 83180386800.29.477F86E Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf22.hostedemail.com (Postfix) with ESMTP id 204D1C0004 for ; Mon, 3 Mar 2025 13:55:17 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="ieHr9I/J"; spf=pass (imf22.hostedemail.com: domain of jackmanb@google.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=jackmanb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741010118; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w+Nhg1GuXJKivFMPeLjLk1SXPuuwLJQbXpnkpy0/hFw=; b=C9W8tUq7YscS68U/ChZ9soPuBMpyB7j4+vvZ2GGOXdaLlgg+bEq+vZKenRxLm5jifn/2WB gHCMD+TfqiXs8seN+KPXw+oVCS9RHo+hm+IHXs4xqswxeIjvn+KdEa/kpIji101tw59UBV TwKu7vOByhj56Og5k4L9dfxZKZzlhw0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="ieHr9I/J"; spf=pass (imf22.hostedemail.com: domain of jackmanb@google.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=jackmanb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741010118; a=rsa-sha256; cv=none; b=ygK7n89sLD9HPsl9DDAipWTQws97MBZugYuG1H4DapGb2np5m+Aek4x/JUTlxszC0s08hB Y79X7ZLJbg6HVnQlfKqOz07P1CHq+z+IX1KPh6D7r/KXB7tizMic1sSK5jWN/6DhX20JL3 Qyv2O0RoJYLDveuhd4vGCSs9vgHUZIA= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-43ba8a87643so86615e9.0 for ; Mon, 03 Mar 2025 05:55:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741010116; x=1741614916; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=w+Nhg1GuXJKivFMPeLjLk1SXPuuwLJQbXpnkpy0/hFw=; b=ieHr9I/JmM+IV7jTRIZlqe2jGprRask/h+wxproAN0VdpbVAp+s4ZkjzPGosjjPB9e /r4cKCaqLaC0M2qgditvMAGeWzzugJtgtmkWuomhFwRBBfF9GLLqgxJnUiECj2h54bAG MMiKuAYxa9TMRNGW2I+0c3jFPJW+vWrbY8crZWg037aFJAZxdA7GHwJGwruMgh2qts8Y VlE1XrZpCVIYjBarZZosoFx3llQ9PtwM+ba9aApZsrdKOl/iit7SLlayhkFrZY7Yf7h4 RX4e5YFUqedGePOIpAF3ALxI3AM1y7NLnfjr35YYvKMvyfIjduqxVAK40oGCdCMfFrQo JsDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741010116; x=1741614916; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=w+Nhg1GuXJKivFMPeLjLk1SXPuuwLJQbXpnkpy0/hFw=; b=n1kOZmqxVmWibwK8zXRZhy2N9n505TuGzI3o2sza/GrdMTBaYVgFkZcLNa+KiCQxlW SfFHCTGT/8WkG00IGWiLx3W7ozR5sOoEKCnCMFTWu1/legI5zIcd88UJKTHWNtDJ5RSo 72VQ+h9V1/FWKYqalbYkelMxr3H3WGuwgzSo6rzJ1klKngzARpxNNb/fgz9AEVrqlvFy RUrbTo2/yNdfxSIcaQavq44q2Abx0rar1Yhi5seRAi3h07CP1o/VrUVpB7ba1hIoVen/ ZacOXBOuHxqzrooLLZ97YDQV5lY5YZ1TIKX9AzS2Pllr42tXJh3oys7Vh9q9MzI4rAof 4Xtg== X-Forwarded-Encrypted: i=1; AJvYcCVUTk7AfvJ7f5vA8OEJn3ux8oU5IK8z3oE7N0JZz4zcoCZaOVCEuj/F1G3owPKm4UUf9V3MViGZUg==@kvack.org X-Gm-Message-State: AOJu0YwJjPthtBVrZOE6m1UIXTHRR7n0RhzTHewiLAHDR0poPuFHM0mB Y/Epotei32Wnwd93SoUyn6mQfZ7JuVGlKLgfLQJzvAsJuMpv3I/uD4W6UM650g== X-Gm-Gg: ASbGncvfyC9c7gDcxsAAti8HpGj8neURnQgg8SawcI7GB5waEi44ItCFctGba9LhtBj IPh2uqyMo6UD2L+djk3hGLJZRe2DTxcr7v4Z9Ab+QzaY7aboTgWfuSoH0fM7r8HV+R7Bav7bROV Lvooh3jd4nE6RKqcqA7PDKMH3hP3We7uaBUJ1U1Chc6UOMLA6iGkybp76/V6KN1oeYPRyZmKLgO m34uNuOmPmsMDb2qec2Olzs335URXrzaOBrKUrLaUS1KcqOlGc78ewtEypqgX5h9arSCehh6z8x 1qMJRmYZlFbVXuNfTbrfTmj0dMZUeQFqqAD3IVgJV5Xl9Annfjb1AeAL/kVQRLUPplDcHgKEyW4 qg916 X-Google-Smtp-Source: AGHT+IHAa7w6RixSNxrVTUkit3J59PlQoncx+lgIQm8IIFvB07cSe2Js5coLyQ9uGviuYVoLUWXybw== X-Received: by 2002:a05:600c:6b72:b0:439:7fc2:c7ad with SMTP id 5b1f17b1804b1-43baff12452mr2552905e9.7.1741010116420; Mon, 03 Mar 2025 05:55:16 -0800 (PST) Received: from google.com (44.232.78.34.bc.googleusercontent.com. [34.78.232.44]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e47b7d69sm14873656f8f.60.2025.03.03.05.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 05:55:15 -0800 (PST) Date: Mon, 3 Mar 2025 13:55:11 +0000 From: Brendan Jackman To: David Hildenbrand Cc: Andrew Morton , Oscar Salvador , Johannes Weiner , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/page_alloc: Add lockdep assertion for pageblock type change Message-ID: References: <20250303-pageblock-lockdep-v2-1-3fc0c37e9532@google.com> <4d0f0bca-3096-4fb4-9e8b-d4dcdf7eeb92@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4d0f0bca-3096-4fb4-9e8b-d4dcdf7eeb92@redhat.com> X-Rspam-User: X-Rspamd-Queue-Id: 204D1C0004 X-Rspamd-Server: rspam09 X-Stat-Signature: mkar5d9stxoinqygnemacsw8h91ug4kc X-HE-Tag: 1741010117-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LolcBQvDQ0Ns2lOEGzUM4AQ8wqQJhv+WSTfcwHeGNBJ0AYZJaOC3YUVcmgViw4WwiioLmlsdPaYal/FjqHEu20hqKZPnZ6zQXMkiRgFJ0EUS5wv7MIL9MovhDu7O6YdabVSrEc83O3HcyfCv3eNxp7hC2YC5Y9EmEDF39H48pBypbica9NeiEY+URkg6zsihQfiCuv5+tB5PrTT4cWiQj9HMp4Tr3LRFZV/KDB9DBm13yfzJ4xncA3sVE1aTAIWf7yEWkYOmuUMTrf3j9ZjMc7YKtr9ISvJzgutWCUSowueb2tTDPOA6Ak15emxr5qBcstezeMf9u9KSUz/gj1g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. So yeah I guess this synchronization isn't as ready as I thought for such a straightforwad "you need one of these locks here" assertion. My ulterior motive here is the series I'm working on where the pageblock records the ASI mapping status, so maybe I can find a weaker assertion that at least helps with that more specific logic.