Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp531743imm; Thu, 31 May 2018 05:08:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ5sr27jBh9Pw9z74VgCgIRL98WwtrqvkMZlqnqiYPnjYNa3Im1vJHquJuYY3UBHR8Dyo9C X-Received: by 2002:a17:902:bb90:: with SMTP id m16-v6mr3981133pls.50.1527768534993; Thu, 31 May 2018 05:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527768534; cv=none; d=google.com; s=arc-20160816; b=vBRz6C6haG6ghwBPTdwMVRuwS3zkSvosRmSVzHOQWwRe1ThXCugTd3yn1es40+KPQ+ cCLxKZXZ34425lZaJ4MYNFFX6gagSCJe/3jknX1ShnjM57U4C5KQacFiqyhS6fc5BOud DMMHg4Mik7OiOLyHAmur5OsfoT2XDJ9KetN058o9/aZh1FcJbMiFJfT5hqEeCsln4n60 4lspNqVAFZ4fPJRNM+f9or9MtDi586ZFbu5FrBBEZh4ZEf00ABpZq62py+plXOGc1ljB s3y0PJDR+mbua2KBq2tcGDOoIu3kwf3s/LzuiecXTov+kndMmkEdnCBZ2PI+j4fENxvO hzTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=TFYtTeINCDQLhQyZOQsuIk6J6gZBJMDoqXa50Gzjps0=; b=FEyrdMjDx1HM3iKiL2KvDhfVeasETsHOWIHTXQr4aD0bXjYm5UrfutKOfC4p4qtauw sTXC6s6BJ5xzWcffN3H6C5AI+DtSGONQ6jZ0ODevhz1kEUVkIyxfq/sXO1EvGNYzolB/ S6Bc2r9ban4/ngp09sdMD8ixJYVRBLF+RKYwirCojcw+u1X4IFdqtpeK6UBGFAcZDmq4 xvKyVhloZRuxfzkMAlIGK+noJfzNzsNHHkqJYRxac4sJnnueqIwKxSC91WYOU3np9i5c ihhQ5reQWPsJghALI3CLSRmqYHNwtBsL32iwn2q9Sf8tY2zSRz9NS+e4iICe0HgIidKX pxTA== 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 m39-v6si37435954plg.371.2018.05.31.05.08.40; Thu, 31 May 2018 05:08:54 -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 S1754858AbeEaMIJ (ORCPT + 99 others); Thu, 31 May 2018 08:08:09 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:54508 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754197AbeEaMH6 (ORCPT ); Thu, 31 May 2018 08:07:58 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 93633B2410712; Thu, 31 May 2018 20:07:54 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:07:48 +0800 From: Xie XiuQi To: , , , , , CC: , , , , Subject: [PATCH 2/2] drivers: check numa node's online status in dev_to_node Date: Thu, 31 May 2018 20:14:39 +0800 Message-ID: <1527768879-88161-3-git-send-email-xiexiuqi@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527768879-88161-1-git-send-email-xiexiuqi@huawei.com> References: <1527768879-88161-1-git-send-email-xiexiuqi@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If dev->numa_node is not available (or offline), we should return NUMA_NO_NODE to prevent alloc memory on offline nodes, which could cause oops. For example, a numa node: 1) without memory 2) NR_CPUS is very small, and the cpus on the node are not brought up [ 27.851041] Unable to handle kernel NULL pointer dereference at virtual address 00001988 [ 27.859128] Mem abort info: [ 27.861908] ESR = 0x96000005 [ 27.864949] Exception class = DABT (current EL), IL = 32 bits [ 27.870860] SET = 0, FnV = 0 [ 27.873900] EA = 0, S1PTW = 0 [ 27.877029] Data abort info: [ 27.879895] ISV = 0, ISS = 0x00000005 [ 27.883716] CM = 0, WnR = 0 [ 27.886673] [0000000000001988] user address but active_mm is swapper [ 27.893012] Internal error: Oops: 96000005 [#1] SMP [ 27.897876] Modules linked in: [ 27.900919] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.17.0-rc6-mpam+ #116 [ 27.907865] Hardware name: Huawei D06/D06, BIOS Hisilicon D06 EC UEFI Nemo 2.0 RC0 - B306 05/28/2018 [ 27.916983] pstate: 80c00009 (Nzcv daif +PAN +UAO) [ 27.921763] pc : __alloc_pages_nodemask+0xf0/0xe70 [ 27.926540] lr : __alloc_pages_nodemask+0x184/0xe70 [ 27.931403] sp : ffff00000996f7e0 [ 27.934704] x29: ffff00000996f7e0 x28: ffff000008cb10a0 [ 27.940003] x27: 00000000014012c0 x26: 0000000000000000 [ 27.945301] x25: 0000000000000003 x24: ffff0000085bbc14 [ 27.950600] x23: 0000000000400000 x22: 0000000000000000 [ 27.955898] x21: 0000000000000001 x20: 0000000000000000 [ 27.961196] x19: 0000000000400000 x18: 0000000000000f00 [ 27.966494] x17: 00000000003bff88 x16: 0000000000000020 [ 27.971792] x15: 000000000000003b x14: ffffffffffffffff [ 27.977090] x13: ffffffffffff0000 x12: 0000000000000030 [ 27.982388] x11: 0101010101010101 x10: 7f7f7f7f7f7f7f7f [ 27.987686] x9 : 2e64716e622e7364 x8 : 7f7f7f7f7f7f7f7f [ 27.992984] x7 : 0000000000000000 x6 : ffff000008d73c08 [ 27.998282] x5 : 0000000000000000 x4 : 0000000000000081 [ 28.003580] x3 : 0000000000000000 x2 : 0000000000000000 [ 28.008878] x1 : 0000000000000001 x0 : 0000000000001980 [ 28.014177] Process swapper/0 (pid: 1, stack limit = 0x (ptrval)) [ 28.020863] Call trace: [ 28.023296] __alloc_pages_nodemask+0xf0/0xe70 [ 28.027727] allocate_slab+0x94/0x590 [ 28.031374] new_slab+0x68/0xc8 [ 28.034502] ___slab_alloc+0x444/0x4f8 [ 28.038237] __slab_alloc+0x50/0x68 [ 28.041713] __kmalloc_node_track_caller+0x100/0x320 [ 28.046664] devm_kmalloc+0x3c/0x90 [ 28.050139] pinctrl_bind_pins+0x4c/0x298 [ 28.054135] driver_probe_device+0xb4/0x4a0 [ 28.058305] __driver_attach+0x124/0x128 [ 28.062213] bus_for_each_dev+0x78/0xe0 [ 28.066035] driver_attach+0x30/0x40 [ 28.069597] bus_add_driver+0x248/0x2b8 [ 28.073419] driver_register+0x68/0x100 [ 28.077242] __pci_register_driver+0x64/0x78 [ 28.081500] pcie_portdrv_init+0x44/0x4c [ 28.085410] do_one_initcall+0x54/0x208 [ 28.089232] kernel_init_freeable+0x244/0x340 [ 28.093577] kernel_init+0x18/0x118 [ 28.097052] ret_from_fork+0x10/0x1c [ 28.100614] Code: 7100047f 321902a4 1a950095 b5000602 (b9400803) [ 28.106740] ---[ end trace e32df44e6e1c3a4b ]--- Signed-off-by: Xie XiuQi Tested-by: Huiqiang Wang Cc: Hanjun Guo Cc: Tomasz Nowicki Cc: Xishi Qiu --- include/linux/device.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/device.h b/include/linux/device.h index 4779569..2a4fb08 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1017,7 +1017,12 @@ extern __printf(2, 3) #ifdef CONFIG_NUMA static inline int dev_to_node(struct device *dev) { - return dev->numa_node; + int node = dev->numa_node; + + if (unlikely(node != NUMA_NO_NODE && !node_online(node))) + return NUMA_NO_NODE; + + return node; } static inline void set_dev_node(struct device *dev, int node) { -- 1.8.3.1