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 970D4C83F33 for ; Tue, 5 Sep 2023 09:37:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 036D894000B; Tue, 5 Sep 2023 05:37:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F27FD8E001A; Tue, 5 Sep 2023 05:37:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E16EB94000B; Tue, 5 Sep 2023 05:37:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CE5E88E001A for ; Tue, 5 Sep 2023 05:37:35 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 96262C0BBA for ; Tue, 5 Sep 2023 09:37:35 +0000 (UTC) X-FDA: 81202041270.07.D85386D Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf13.hostedemail.com (Postfix) with ESMTP id 71AEB20016 for ; Tue, 5 Sep 2023 09:37:33 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="fLO/cA3Q"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=cTTm2fRd; spf=pass (imf13.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693906653; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rgzA2lkGR7u9l38VxfCRahVcWaK6R2rDt/8GaK7WDyY=; b=yX5gzm6zoPZGhNn24EsiQhjAjDTU/Ljr6LbqyJNvDBSDK3izLXKbaFUFUHus2EGU0xBto9 FA/3ZMMk4shKmWAe2EQc/AQGfT2h/SSarWjucuzHsHTj4nQRZTAf+ZAXjXFzGRaPZFqIK7 D4b97ZxAWrgbixKX/r+/H+I7+YkYWI0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="fLO/cA3Q"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=cTTm2fRd; spf=pass (imf13.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693906653; a=rsa-sha256; cv=none; b=VV7r3RrwOtjVl5fjlIj1AYIPf2rZQIn80viYPZilPuMV99qHM3uVLcJtnwgIRSxCoaFkhp En9JkPsR3V71IL7M0QWiqRG4Jes80w23wCwhAiXRJrAuCvrawWRE90Yzvb9K61lmCbAwhT PesgLtGGu0gEvrI3YW9ImZ8X9r4qOno= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 52A141F74D; Tue, 5 Sep 2023 09:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1693906651; h=from:from:reply-to: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; bh=rgzA2lkGR7u9l38VxfCRahVcWaK6R2rDt/8GaK7WDyY=; b=fLO/cA3Q41goLiXCtiWpMCNqpPoUbpG74GhGUMBole12sj9+OHoTrvQ8FhAmNGddh1MInY 7u7PO7jJ0FSu5cWxQ//jTrT7ScpvFeZJAwJNUWQguwGDX6CWTk11XXV2yjdFyajCAc5zZh rgJkccwlq213/iygP5NcEeYzzU0jd4k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1693906651; h=from:from:reply-to: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; bh=rgzA2lkGR7u9l38VxfCRahVcWaK6R2rDt/8GaK7WDyY=; b=cTTm2fRdVBhqKaHX/O1EvhxZYdYT3wKoglxZQvpY21cYFrLJDbWZhy3GwNtilDhUAABtb3 vc38Tyi5ZNzHpFAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2450513911; Tue, 5 Sep 2023 09:37:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4khQCNv29mQdNAAAMHmgww (envelope-from ); Tue, 05 Sep 2023 09:37:31 +0000 Message-ID: Date: Tue, 5 Sep 2023 11:37:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH] mm: page_alloc: fix cma pageblock was stolen in rmqueue fallback Content-Language: en-US To: Mel Gorman , Lecopzer Chen Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nsaenzju@redhat.com, yj.chiang@mediatek.com, Mark-pk Tsai , Joe Liu References: <20230830111332.7599-1-lecopzer.chen@mediatek.com> <20230905090922.zy7srh33rg5c3zao@techsingularity.net> From: Vlastimil Babka In-Reply-To: <20230905090922.zy7srh33rg5c3zao@techsingularity.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 71AEB20016 X-Rspam-User: X-Stat-Signature: bzbi5uqbny98ou6r5kc7nkfteso3dfxt X-Rspamd-Server: rspam01 X-HE-Tag: 1693906653-715300 X-HE-Meta: U2FsdGVkX1/57AWvquHZOVGPX/ZuHz3H2PtpDNB5f3Auf6nVjO60zOUBaGOCWMMl3feyEHy9MCn5XwOZ8zFER1JC99tGovZKhnrncbaP7lYNI5+r7x0tj9G22ww1TzxVjkJJvXx9Z93lNpj8riADzF/XH9/gooYFJOTTIpuBj11r6nhGL3pZg1kNeLA/dcXB/HPWUbVN4PHbgfBwWpWvgWz4ZjB0D94PaKfh8a0rJP0hpIRNigw+OUx4xdfLc5NJM2+w8FTrYjYA0+mKPVMTmijMYfxSxAQRR5rxwWwMovhv1t4p/YKbV5XToAOJtBxTxuNwrjKnA5jDgN6q9mpM8+htjJxPZgeuCOAlhZLMWOtVX1glfbbQvZwqNfg+jH7uVV8cootkC8pYIXNBupH/CfnI05uEo26MrqaBy89chODWkojH+0xQVrPUtQKHbbZD7NZy4ImKAuBDsAk8jpuy0+hxjfq1uPugjIsBl8yjh1NowLb2f2YWoM4PWoazmKGxsLb02BYW9YWRT/eKqLIcntOJ3NTmbfF12P1DjX8IdQXU6euXuJ/NA58cyVb+8ySaFyPnLHUhRrsCDAdGV31SGDZYWRLz6xTtPISRoavNLi5XeY0Htl5GWYflSWj8+NKnVjYLjjEWNIW+9TAiTJU6Y3qVSf5KyTouRir0bxlB4XCeuCI2tkEuTQKPVbM5KW44dmT7DA/8l/vueRb+YZGQY4SEWWAVzkiQ6jlj5iL2SJVCfncDMrGKCFtncvifNeTWAzWMp4AM7D4Qmd+Rg8fZt8kkdqwJ8sWLXcewaJAYnH3vrPcEKoYOD2Bdbl5Q1zeqEDcnLLn72kGL8iNFCyiJh7qAQM59nYOlrDPmtIqx1/T7y9PpD064wNj2wWaYbq+d2ZjFa1qdWMVV1zfugxZorlHLDV5lkxqffy7Pd8easdS8x1oVrDVEsEpXl/pec3wSkiTrPhOxhnK0hnD6VWA saKZhv4J LnkFdTElfVvffr/JHZzIFfHsmEupL+oKsWOEfp7bIMRH80G/HVLVRsuLE3hBBCxylZ80ssvtn/5XUYahz0O+2mW09iOm6/fJ3etJmg+yS2Tt2X5yH8OH20Eu4Dmh9FRhckJl75nFC91hIMWq2Nku9kXhkPFUyRwOMsSfTwUwlD2nArcsvCrd9h2iDzMwlD3sBeCvdv34r/BLxkaYCQU0AgN8Ro/CkfkimKbM6mHmK/j8+3BjJQxf0LwU6dypC/KHXGnc6X6WI5ivHUiRaBOvn5fxzboMHoOunJ1lNL0lc26REC/qYYjhcYoCgLjLZ0+Xv1bpNb7wS7nhzxrEnLbw/C5A57ewZOCRlkQ74j4lkjT9VDCo= 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: On 9/5/23 11:09, Mel Gorman wrote: > On Wed, Aug 30, 2023 at 07:13:33PM +0800, Lecopzer Chen wrote: >> commit 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a >> spinlock") fallback freeing page to free_one_page() if pcp trylock >> failed. This make MIGRATE_CMA be able to fallback and be stolen >> whole pageblock by MIGRATE_UNMOVABLE in the page allocation. >> >> PCP free is fine because free_pcppages_bulk() will always get >> migratetype again before freeing the page, thus this only happen when >> someone tried to put CMA page in to other MIGRATE_TYPE's freelist. >> >> Fixes: 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a spinlock") >> Reported-by: Joe Liu >> Signed-off-by: Lecopzer Chen >> Cc: Mark-pk Tsai >> Cc: Joe Liu > > Sorry for the long delay and thanks Lecopzer for the patch. > > This changelog is difficult to parse but the fix may also me too specific > and could be more robust against types other than CMA. It is true that > a failed PCP acquire may return a !is_migrate_isolate page to the wrong > list but it's more straight-forward to unconditionally lookup the PCP > migratetype of the spinlock is not acquired. > > How about this? It unconditionally looks up the PCP migratetype after > spinlock contention. It's build tested only > > --8<-- > mm: page_alloc: Free pages to correct buddy list after PCP lock contention > > Commit 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a spinlock") > returns pages to the buddy list on PCP lock contention. However, for > migratetypes that are not MIGRATE_PCPTYPES, the migratetype may have > been clobbered already for pages that are not being isolated. In > practice, this means that CMA pages may be returned to the wrong > buddy list. While this might be harmless in some cases as it is > MIGRATE_MOVABLE, the pageblock could be reassigned in rmqueue_fallback > and prevent a future CMA allocation. Lookup the PCP migratetype > against unconditionally if the PCP lock is contended. > > [lecopzer.chen@mediatek.com: CMA-specific fix] > Fixes: 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a spinlock") I think we should Cc: stable for the sake of 6.1 LTS? > Reported-by: Joe Liu > Signed-off-by: Mel Gorman Acked-by: Vlastimil Babka > --- > mm/page_alloc.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 452459836b71..4053c377fee8 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2428,7 +2428,13 @@ void free_unref_page(struct page *page, unsigned int order) > free_unref_page_commit(zone, pcp, page, migratetype, order); > pcp_spin_unlock(pcp); > } else { > - free_one_page(zone, page, pfn, order, migratetype, FPI_NONE); > + /* > + * The page migratetype may have been clobbered for types > + * (type >= MIGRATE_PCPTYPES && !is_migrate_isolate) so > + * must be rechecked. > + */ > + free_one_page(zone, page, pfn, order, > + get_pcppage_migratetype(page), FPI_NONE); > } > pcp_trylock_finish(UP_flags); > }