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 42941C83F3E for ; Tue, 5 Sep 2023 12:29:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 434FD940012; Tue, 5 Sep 2023 08:29:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E5038E001A; Tue, 5 Sep 2023 08:29:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D3D0940012; Tue, 5 Sep 2023 08:29:07 -0400 (EDT) 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 1E1218E001A for ; Tue, 5 Sep 2023 08:29:07 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BDF88B3B53 for ; Tue, 5 Sep 2023 12:29:04 +0000 (UTC) X-FDA: 81202473408.21.30470EE Received: from outbound-smtp07.blacknight.com (outbound-smtp07.blacknight.com [46.22.139.12]) by imf28.hostedemail.com (Postfix) with ESMTP id CB80DC0021 for ; Tue, 5 Sep 2023 12:29:01 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.12 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693916942; 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; bh=72TC7zi/XdxQdch3MK/nnE3PpiwmeS9S7zJSBkYr9wc=; b=jBeldqFQreD3LAAEyYTt0MyatZf9rqVG08G+TDfjjzL2cLk6m25uuliVmr+zKa35f1TFcF /fcrw95rhCcxBgEWDjKGlabzZv7EjSVcOyouncys78ddGG/ls2aLjzqhxshda6ZSxa5nvv o0JchuIu9ZMHpDAZBK7sNFUz0U9415A= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.12 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693916942; a=rsa-sha256; cv=none; b=oKF1x5K5X1XLi3L653MERv8eeWGv+tnLc9noDcZOGPRND6/LOZ1ibBkfOTOsPQPAi2cWf9 A0wNsds51Fz8YtCHnUT4eUBqZi/l5NEBfs9T+7x8+PvB9iiwXJH9gta35nTo107iqpRhgs O+sG/Ci5+RpVF6k0BgFOjCn6/wYCoLs= Received: from mail.blacknight.com (pemlinmail03.blacknight.ie [81.17.254.16]) by outbound-smtp07.blacknight.com (Postfix) with ESMTPS id B90B61C397A for ; Tue, 5 Sep 2023 13:28:59 +0100 (IST) Received: (qmail 3911 invoked from network); 5 Sep 2023 12:28:59 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.20.191]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 5 Sep 2023 12:28:59 -0000 Date: Tue, 5 Sep 2023 13:28:57 +0100 From: Mel Gorman To: Vlastimil Babka Cc: Lecopzer Chen , 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 Subject: Re: [PATCH] mm: page_alloc: fix cma pageblock was stolen in rmqueue fallback Message-ID: <20230905122857.b3kwlxm6qxa2tgpb@techsingularity.net> References: <20230830111332.7599-1-lecopzer.chen@mediatek.com> <20230905090922.zy7srh33rg5c3zao@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: CB80DC0021 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: kpz4bh1bxh9s1gkyrz3557czaot5wkhw X-HE-Tag: 1693916941-501834 X-HE-Meta: U2FsdGVkX1+YjTa3reMFa/d8kz/8QZg5J4i0fbdmX7jiLI/4u6BtW1ZfBKPHwcHfzYlywB6XXZ6eoxXR9o66BELjQfXZ7p9Rgdj41acMK8QlrmtIZ1exJ8riHBBSaM14Am1L5VSwduRPrZxOmSQUG4jZy1dahhN8MrfyTnF5SJB3iuhMKtMoY/KnL3EuKwm3goUvYdlNq9YwGoW4rYcqs2e7O5h0SWsj9bv/7tmc0WHPRlzym2F7B1FJeYwy7I2p4P7KMIfdxtDSBqNrI7zgqKtZQpDEZ0s0JHM+Tso0aQ8ABO0wsvFDMimL1ra1KlPZJVfcpF+ez1+3aCtJrNXcWBysVqEAAJ/1KxtbtRRIJRpNX2lSo/dh7jneNFfasK8QFBt0nh9YIngYV6NQsfeuPjjWoJekslwLf+0IJ9lrR8VX4tyJrrj7OI24o6f00hK8XboPoaEXVvdoOmF06jXTHp1OSpCVupJSfFFU3C+QUcp/V9WvD+Q+bzTIFNYIo8euMK2sWrHAg8naV6rOsoxfu5oUm01VGXh7Vh03mxVi5EC217kvC3AE2jjGLR8W3moAo7qgQrocPUs0DZl5uMg8SMMpt6cvhe+SsMguYd531/ZGAChv4yDdMDdgmo+GLKanhh9dAA8KoEMDpRUXTz6qWsMZ5uCeuPuUkTwoNYftLSVzGHYaMH5ADqU5O+46y4ecHSv8tffav+biX4ZxG9gVFIWFpkbJuCN7x07uxbvca/GLlFFg2Po5/M5aMfSlmuC8IO+V0lDlCPmzAS3FxzUTqsVUBnyyi4L9DX/1c+Jp0vrNIji7vXZWetgYImNRTLibvJVFbij4BzOoWEHfnR0FdrBCNEOSAG55rbZaLwER2KRikf8IEq2aFwzxyLQut9I3V0xEV0FCNzfCj7ZB6vnHzMK9xQUgA1/kW4XFzSHZ67SJ0j0zuIt2IPMByYvGLcYdGRYZLNHP6IhhV/tQzu5 nXtlJ8WU 0QTmdiNg3CNtsB9+Ltr2f+NZ03KXp6y5e0rGmJvJ9Mu+NKaifEIMbAmVD32c8sqwF9I954eY4Wvkp0D9TGpRxJFfaC6/H1xBQ/2pmNsqmgYRVyxaQba3GFDu9sx0AI6l1MSu2zIWtnTarjbLVX5ZgbN6MEZPROAfPoVi8r9EDTZ2MIdVrynmPp1eOY2uUwcQw40yrusLtd2f6Tv+qU96rjAbPNj5ca2x6uqvFnk9ZjMEXI7k1fqzUl/GxjG26HDYKxmdKcAWbU3B8APU0+agx7Y4xaTcv1fGevmXGDsqxhSIaqnCRFbfKkSSQ/9CFHwVnUxcZL1qczVZYNoI= 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 Tue, Sep 05, 2023 at 11:37:30AM +0200, Vlastimil Babka wrote: > 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? > Yep. > > Reported-by: Joe Liu > > Signed-off-by: Mel Gorman > > Acked-by: Vlastimil Babka > Thanks. -- Mel Gorman SUSE Labs