Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2010776imm; Tue, 10 Jul 2018 11:33:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpehEzfiO86+iU6hWq+WirWZuw5JaMm/7fjYvF3ZCnNBkGbLb9JeMyrVwRqL7TOMNlDrpc7A X-Received: by 2002:a63:2c8e:: with SMTP id s136-v6mr15536352pgs.390.1531247583699; Tue, 10 Jul 2018 11:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531247583; cv=none; d=google.com; s=arc-20160816; b=dsQUkN+zxIp5pEMCmwFJ/SGV+oG9HkaE2p2W7y5DTVcc28CM2WhxeFVxgfyOf5I7hQ APcJ29gUApWmHE6jGLCjWr04BvS+mps2So5jBHYAJEtxOJl0G2eimLBcHXwWblmeIhR6 1LXaUMYIwXnpBegtSzoPnDfycv1wQRiHsa8Hy0hYRe8305gWkrMGiERx56IeA5zqczmo 5fo2iOmY/FDLO6CImVAoNWWsYBFh2qcyji9ctUnJzv32hj11qn/UaMteosGDwZOiqOF8 haMv91SH04n7zTJWQTTd7mHr6ZJyWW9P+CcmehrqvqcQxzPR4rDBdpFdZGySFpCVFxt6 BcUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AANVZdjDfKeFQXUsH8t8qnS4RfYlz1RkL/zlR3iaHfQ=; b=NFQBittUrfThGYMVt6ghkTWepo2dqr9tVRaGyRUuE9VEIQ/TWaNRBtWVN8aRpL3/NX slfwQxanxWluIncon8ZVNC93BlW6kn2lCD2JeUxAhVDvlw0KoLky5khFGuyD+qAmmKP1 QOk8ryVG7cGW1Om/duKP+PsSVx/vu7tGapajaU/8zFCZnLbvnP9PnrXOvspLUP/YNPe5 PqjCkzCi+1/oK/1QWS5FCrp95FPiBhViSBoyTl1dFJcOH5EsgJoy+SCBbn7z/4L9zbUs /j/iMr2uEdAsJwVIKMNXj0drZGX872XtKamciyf7tOp7jZpX/sir/tememMI4Xhwwaqp NwsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w19-v6si17491962pfn.160.2018.07.10.11.32.48; Tue, 10 Jul 2018 11:33:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388258AbeGJSbE (ORCPT + 99 others); Tue, 10 Jul 2018 14:31:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45712 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388248AbeGJSbD (ORCPT ); Tue, 10 Jul 2018 14:31:03 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 047EEEB4; Tue, 10 Jul 2018 18:30:50 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vlastimil Babka , Mel Gorman , Michal Hocko , David Rientjes , Joonsoo Kim , Andrew Morton , Linus Torvalds Subject: [PATCH 4.9 43/52] mm, page_alloc: do not break __GFP_THISNODE by zonelist reset Date: Tue, 10 Jul 2018 20:25:11 +0200 Message-Id: <20180710182453.398541459@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182449.285532226@linuxfoundation.org> References: <20180710182449.285532226@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vlastimil Babka commit 7810e6781e0fcbca78b91cf65053f895bf59e85f upstream. In __alloc_pages_slowpath() we reset zonelist and preferred_zoneref for allocations that can ignore memory policies. The zonelist is obtained from current CPU's node. This is a problem for __GFP_THISNODE allocations that want to allocate on a different node, e.g. because the allocating thread has been migrated to a different CPU. This has been observed to break SLAB in our 4.4-based kernel, because there it relies on __GFP_THISNODE working as intended. If a slab page is put on wrong node's list, then further list manipulations may corrupt the list because page_to_nid() is used to determine which node's list_lock should be locked and thus we may take a wrong lock and race. Current SLAB implementation seems to be immune by luck thanks to commit 511e3a058812 ("mm/slab: make cache_grow() handle the page allocated on arbitrary node") but there may be others assuming that __GFP_THISNODE works as promised. We can fix it by simply removing the zonelist reset completely. There is actually no reason to reset it, because memory policies and cpusets don't affect the zonelist choice in the first place. This was different when commit 183f6371aac2 ("mm: ignore mempolicies when using ALLOC_NO_WATERMARK") introduced the code, as mempolicies provided their own restricted zonelists. We might consider this for 4.17 although I don't know if there's anything currently broken. SLAB is currently not affected, but in kernels older than 4.7 that don't yet have 511e3a058812 ("mm/slab: make cache_grow() handle the page allocated on arbitrary node") it is. That's at least 4.4 LTS. Older ones I'll have to check. So stable backports should be more important, but will have to be reviewed carefully, as the code went through many changes. BTW I think that also the ac->preferred_zoneref reset is currently useless if we don't also reset ac->nodemask from a mempolicy to NULL first (which we probably should for the OOM victims etc?), but I would leave that for a separate patch. Link: http://lkml.kernel.org/r/20180525130853.13915-1-vbabka@suse.cz Signed-off-by: Vlastimil Babka Fixes: 183f6371aac2 ("mm: ignore mempolicies when using ALLOC_NO_WATERMARK") Acked-by: Mel Gorman Cc: Michal Hocko Cc: David Rientjes Cc: Joonsoo Kim Cc: Vlastimil Babka Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 1 - 1 file changed, 1 deletion(-) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3642,7 +3642,6 @@ retry: * orientated. */ if (!(alloc_flags & ALLOC_CPUSET) || (alloc_flags & ALLOC_NO_WATERMARKS)) { - ac->zonelist = node_zonelist(numa_node_id(), gfp_mask); ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, ac->high_zoneidx, ac->nodemask); }