From patchwork Wed Aug 1 20:04:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 143310 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1296132ljj; Wed, 1 Aug 2018 13:04:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdC74NgHFnm2tCmcmpvsdYRRIMg16wT/Azo7UmcFBGGfYVuA68hPpfZh1PvU7ui3yg/WSM6 X-Received: by 2002:a63:6a45:: with SMTP id f66-v6mr25411652pgc.81.1533153865555; Wed, 01 Aug 2018 13:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533153865; cv=none; d=google.com; s=arc-20160816; b=IrkBobtFxSxF9ykKmRJo+vLKRbsqmwXz8SxensGGxaD1ElycLVYzO9R58ZZCGUnVja XQyED0BePWLpSkLd5xUCnxMDJgc7qBQJ9wHcz3tLulFJHYZFDvZKKQxbSx20wL8SsxhK XJxbvLfalSqLI52AfX9ZwWglISBwa4rPJwCJfYxToeP9/tc6t5XKgw36+GvHyZtTYHFj NGWtNkbvZwXAO+jwgKTEpBkJRG73hOVffqCCSrFrHLz/UpQ/Dkz28IukdBCpVsdi1BwA FWUhK/z74VjBR5tfXEkjuT41rz59ncdo3EXeOJNdO1yX3BbdcRK4nT0HLZmQ4uuy9Ppw CVoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TFI8atSi0GM/69YvIddp/hRRVym9hvZ6DtSBz2AeF94=; b=F9LtTTGXwCnYmEhGPEYYxE1HBuNQG2k4BkuXNy/Ul8NatwSFw2n5AG/j8iZtj+U4yK nVCkIybzgkAKeOVkVniUUpYNyatH4+DlSa1X+06EzclujbW/4mXB1/BkMdz7ZvB6BYM3 gIs+Vi8WnsHiXgTex4zyToKA9N5pyp+aBHf1FVeM60XHQrlmq09Ivhlk7+vd8Z09gXHQ vxNhEqZbF3fM2VkejeKJ5CcjIfbWauRW6NWMPqv6aKZPWwN4pKiqNqq1iBQ+1mu+ABxH HXMTKHO2aoOXVoGLFUE1YqxKe50xTUU/NIdLoXVciQzGSHz6g6R2QpQ5Std1A5TWRvm5 x1SA== 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 b5-v6si16880999pfo.54.2018.08.01.13.04.25; Wed, 01 Aug 2018 13:04:25 -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 S2387547AbeHAVvt (ORCPT + 31 others); Wed, 1 Aug 2018 17:51:49 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:48666 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729647AbeHAVvr (ORCPT ); Wed, 1 Aug 2018 17:51:47 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE2EDED1; Wed, 1 Aug 2018 13:04:21 -0700 (PDT) Received: from beelzebub.austin.arm.com (beelzebub.austin.arm.com [10.118.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3B0143F5BA; Wed, 1 Aug 2018 13:04:21 -0700 (PDT) From: Jeremy Linton To: linux-mm@kvack.org Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, Punit.Agrawal@arm.com, Lorenzo.Pieralisi@arm.com, linux-arm-kernel@lists.infradead.org, bhelgaas@google.com, linux-kernel@vger.kernel.org, Jeremy Linton Subject: [RFC 1/2] slub: Avoid trying to allocate memory on offline nodes Date: Wed, 1 Aug 2018 15:04:17 -0500 Message-Id: <20180801200418.1325826-2-jeremy.linton@arm.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180801200418.1325826-1-jeremy.linton@arm.com> References: <20180801200418.1325826-1-jeremy.linton@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a user calls the *alloc_node() functions with an invalid node its possible to crash in alloc_pages_nodemask because NODE_DATA() returns a bad node, which propogates into the node zonelist in prepare_alloc_pages. This avoids that by not trying to allocate new slabs against offline nodes. (example backtrace) __alloc_pages_nodemask+0x128/0xf48 allocate_slab+0x94/0x528 new_slab+0x68/0xc8 ___slab_alloc+0x44c/0x520 __slab_alloc+0x50/0x68 kmem_cache_alloc_node_trace+0xe0/0x230 Signed-off-by: Jeremy Linton --- mm/slub.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.14.3 diff --git a/mm/slub.c b/mm/slub.c index 51258eff4178..e03719bac1e2 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2519,6 +2519,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (unlikely(!node_match(page, searchnode))) { stat(s, ALLOC_NODE_MISMATCH); deactivate_slab(s, page, c->freelist, c); + if (!node_online(searchnode)) + node = NUMA_NO_NODE; goto new_slab; } } From patchwork Wed Aug 1 20:04:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 143311 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1296161ljj; Wed, 1 Aug 2018 13:04:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdgFq/VQZhkrV8pHy57wpOyVEm60GZWBjD6uoS2MWGqVcTMOD8gbL5C3HgxcsM1SqogpgzY X-Received: by 2002:a63:7f16:: with SMTP id a22-v6mr25912864pgd.255.1533153867172; Wed, 01 Aug 2018 13:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533153867; cv=none; d=google.com; s=arc-20160816; b=i1XpfUFj3VbOUNQ9HvfBVkpldniBmAM6Ood4z6CCkunJUFSFneZxipjeCdNfh6Utcf EWud8AOb5jQX/EzJsGGhLvAQ2XBU2/OmheyJxQpueHmPJQcLjS7aWMYmMyaI+vL9v3Jb N2QtpIPrWqz6OdZA1wRLQSjON8izTmRg2HOdv1Z3Dij80HDjD+vS9aLHjfXVQ/eF33QZ QnT3nIVxJ2RzoEndMeTr1t9PLD5IwASe6RGiInqjGANW9pK0VxyrECbfV8G2fh0PMGLv EPzXOtS3b72Ly6n9Kbq1ahSgNJTO2W8wllbmj60/fN5v9mxjqM1sPyL8ZgP/Fyhj/PHf 7jig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=nwL45KZXQc3dyip/An/8rY2zR22RmCtB6f8mc8vZbW4=; b=cQoxpURCJbfOCHNUqDS+fugzdBbZfmO8G5ODJP4ESvPFlmHGkZOByONq7wfDVmUFUl XdgPRbo4d/+SlQd1vadnKX4BawKgTDOGpbdB/sbUF9sIhSDZW0sa3V11yRFQeewfvG79 lY2nd1oIljiIh6eW8y/H8FCFhqLg9R0P8qMH0+aMvhouryt4CuQFCP3aal6SIJFedwkh 1dNr8YbRVYcVFy6QEdwIHD0S8Bj0lBQ/svQcCMXX3aFm9TO1ij6sMYMyDqLtDUklt1m7 Ix3Seeou9Z64MAb7B7w1KTD5F1eLtNtDBJbNcQ2iZEYpSI9FhJqTpLsvxa5Q0YUM5FXv mJFA== 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 w68-v6si8468573pfw.308.2018.08.01.13.04.26; Wed, 01 Aug 2018 13:04:27 -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 S2387619AbeHAVvt (ORCPT + 31 others); Wed, 1 Aug 2018 17:51:49 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:48674 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731961AbeHAVvt (ORCPT ); Wed, 1 Aug 2018 17:51:49 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3D0AC1596; Wed, 1 Aug 2018 13:04:23 -0700 (PDT) Received: from beelzebub.austin.arm.com (beelzebub.austin.arm.com [10.118.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9717D3F5BA; Wed, 1 Aug 2018 13:04:22 -0700 (PDT) From: Jeremy Linton To: linux-mm@kvack.org Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, Punit.Agrawal@arm.com, Lorenzo.Pieralisi@arm.com, linux-arm-kernel@lists.infradead.org, bhelgaas@google.com, linux-kernel@vger.kernel.org, Jeremy Linton Subject: [RFC 2/2] mm: harden alloc_pages code paths against bogus nodes Date: Wed, 1 Aug 2018 15:04:18 -0500 Message-Id: <20180801200418.1325826-3-jeremy.linton@arm.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180801200418.1325826-1-jeremy.linton@arm.com> References: <20180801200418.1325826-1-jeremy.linton@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Its possible to crash __alloc_pages_nodemask by passing it bogus node ids. This is caused by NODE_DATA() returning null (hopefully) when the requested node is offline. We can harded against the basic case of a mostly valid node, that isn't online by checking for null and failing prepare_alloc_pages. But this then suggests we should also harden NODE_DATA() like this #define NODE_DATA(nid) ( (nid) < MAX_NUMNODES ? node_data[(nid)] : NULL) eventually this starts to add a bunch of generally uneeded checks in some code paths that are called quite frequently. Signed-off-by: Jeremy Linton --- include/linux/gfp.h | 2 ++ mm/page_alloc.c | 2 ++ 2 files changed, 4 insertions(+) -- 2.14.3 diff --git a/include/linux/gfp.h b/include/linux/gfp.h index a6afcec53795..17d70271c42e 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -436,6 +436,8 @@ static inline int gfp_zonelist(gfp_t flags) */ static inline struct zonelist *node_zonelist(int nid, gfp_t flags) { + if (unlikely(!NODE_DATA(nid))) //VM_WARN_ON? + return NULL; return NODE_DATA(nid)->node_zonelists + gfp_zonelist(flags); } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a790ef4be74e..3a3d9ac2662a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4306,6 +4306,8 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, { ac->high_zoneidx = gfp_zone(gfp_mask); ac->zonelist = node_zonelist(preferred_nid, gfp_mask); + if (!ac->zonelist) + return false; ac->nodemask = nodemask; ac->migratetype = gfpflags_to_migratetype(gfp_mask);