Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp690511pxb; Tue, 5 Apr 2022 18:56:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOMv8HSQnV30pUx28LTmcgfL9HYWQJ7g2ZWBRtWoQEaOosz/2nS9/XGgNLSXfyIlV/TgRb X-Received: by 2002:a65:53cc:0:b0:382:8506:f1a6 with SMTP id z12-20020a6553cc000000b003828506f1a6mr5271651pgr.44.1649210198470; Tue, 05 Apr 2022 18:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210198; cv=none; d=google.com; s=arc-20160816; b=lfejS7KkcZXGMzaXWncNoRLTbezcrjFFfr3uOySw+GPwfuzJ8x2Fj4f4ExjWYL+/e4 hRbHe2ZzZH/QIwhvvSO1uP8nHItgIggnM8gKt3VyE1CoW5E6lJuyKp0lCMGa3NSVx/h0 gnlNsLl8nkAu0+6TSaQs0fkDcU2l2VB+om4+wnn2n8cg2FPGTdw23y6qBKpFdv6uUHKK r4eoDz/bgEPsLUs9YZW3SHI8zp+YuHW1eRVulPnG3ePtUlPX/ljoKuP0hoGA88duZD9R lEd/p9E516Th/LsA5P1VbFRx9IUIGv8vB4EtOoNEBJ8ZhKhv6f+t9SLfNtq7i02bnTfg AqKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=u4ufmOvcBd8WxXRAGdIylLrYDsxCdd1WX9c/6/gklQY=; b=IaeSCU8JThThnikrUNHXXAfnymy+5fQE/TJhuuunCJxHi89jMnnGs794OO1deMdO8y w5D9L59oCSnzfluE+F9FI5tW6c+OFVuXdAArG10bht7DmX8VbEUam1qkbuvaMPYJWs0s uErbxItIJU5Pp059MmracAbVGjyFtiRcLmT+yN0U1xG4WhUg3zgDu7X6ReTDKMX9kQWe pefPjwrKX4VSbk70T3FUDu7auLVHDvKMc44YIPT37u1j9enJMJQCjAZC52831dMMbJ5u 08aUpDzUVgODJI8c+klGt3NAPwYkV2+VZRxdBFXUeZYVfE/Rbbw8gGC5XNl+BvrnmHvp 5d7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=exLlX5qd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a621c13000000b004fa771ab36asi13060438pfc.265.2022.04.05.18.56.24; Tue, 05 Apr 2022 18:56:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=exLlX5qd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232320AbiDEHu2 (ORCPT + 99 others); Tue, 5 Apr 2022 03:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232449AbiDEHqf (ORCPT ); Tue, 5 Apr 2022 03:46:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF869232A; Tue, 5 Apr 2022 00:42:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3A385616C2; Tue, 5 Apr 2022 07:42:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 472FFC340EE; Tue, 5 Apr 2022 07:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144537; bh=baIIUl0pgpGJEPx8RwPn551PnuHYveXQFnVQUiQciBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=exLlX5qdQwh3x2DEtCDO1CAj/BsTgjSWsUoqTuutJ0mVeFc1IMSvZ1zJ8A3BgvMLD 8IOW4Q5WEWdGd6PzGeUTEKnKk1LWEL60dyecjBxDX9isNukJqtnw7oslzU9CYmIa/4 CH+CU+WUr/BKlZ/ajchb4QHqxAP+M1TBUQeIk8ak= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hugh Dickins , Oleg Nesterov , "Liam R. Howlett" , Vlastimil Babka , Andrew Morton , Linus Torvalds Subject: [PATCH 5.17 0080/1126] mempolicy: mbind_range() set_policy() after vma_merge() Date: Tue, 5 Apr 2022 09:13:47 +0200 Message-Id: <20220405070409.918037488@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hugh Dickins commit 4e0906008cdb56381638aa17d9c32734eae6d37a upstream. v2.6.34 commit 9d8cebd4bcd7 ("mm: fix mbind vma merge problem") introduced vma_merge() to mbind_range(); but unlike madvise, mlock and mprotect, it put a "continue" to next vma where its precedents go to update flags on current vma before advancing: that left vma with the wrong setting in the infamous vma_merge() case 8. v3.10 commit 1444f92c8498 ("mm: merging memory blocks resets mempolicy") tried to fix that in vma_adjust(), without fully understanding the issue. v3.11 commit 3964acd0dbec ("mm: mempolicy: fix mbind_range() && vma_adjust() interaction") reverted that, and went about the fix in the right way, but chose to optimize out an unnecessary mpol_dup() with a prior mpol_equal() test. But on tmpfs, that also pessimized out the vital call to its ->set_policy(), leaving the new mbind unenforced. The user visible effect was that the pages got allocated on the local node (happened to be 0), after the mbind() caller had specifically asked for them to be allocated on node 1. There was not any page migration involved in the case reported: the pages simply got allocated on the wrong node. Just delete that optimization now (though it could be made conditional on vma not having a set_policy). Also remove the "next" variable: it turned out to be blameless, but also pointless. Link: https://lkml.kernel.org/r/319e4db9-64ae-4bca-92f0-ade85d342ff@google.com Fixes: 3964acd0dbec ("mm: mempolicy: fix mbind_range() && vma_adjust() interaction") Signed-off-by: Hugh Dickins Acked-by: Oleg Nesterov Reviewed-by: Liam R. Howlett Cc: Vlastimil Babka Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mempolicy.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -786,7 +786,6 @@ static int vma_replace_policy(struct vm_ static int mbind_range(struct mm_struct *mm, unsigned long start, unsigned long end, struct mempolicy *new_pol) { - struct vm_area_struct *next; struct vm_area_struct *prev; struct vm_area_struct *vma; int err = 0; @@ -801,8 +800,7 @@ static int mbind_range(struct mm_struct if (start > vma->vm_start) prev = vma; - for (; vma && vma->vm_start < end; prev = vma, vma = next) { - next = vma->vm_next; + for (; vma && vma->vm_start < end; prev = vma, vma = vma->vm_next) { vmstart = max(start, vma->vm_start); vmend = min(end, vma->vm_end); @@ -817,10 +815,6 @@ static int mbind_range(struct mm_struct anon_vma_name(vma)); if (prev) { vma = prev; - next = vma->vm_next; - if (mpol_equal(vma_policy(vma), new_pol)) - continue; - /* vma_merge() joined vma && vma->next, case 8 */ goto replace; } if (vma->vm_start != vmstart) {