Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1421142imm; Wed, 1 Aug 2018 15:58:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc189vhMm8o6nlHo5TQdhRdDqmhe4hcp926l7T3wFlMBeyx5ynbQiiQqXObYNvlL3V/UNB6 X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr300397pfa.238.1533164296866; Wed, 01 Aug 2018 15:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533164296; cv=none; d=google.com; s=arc-20160816; b=se+eIAfVO0576WbjCe6uzWUdjaj0n0j2mWr+Tg65bMz6Jy2p/1JihbMHEEj/iAdaQl 0WuQU/79YzVLDOElIsjPOQ3GsdcLqnM7tiUq123NElilEmG6ZkApd6pEd/gJ+uMHfwRZ 10ZrkyrJssGVTaS1IdPxZ5wJAaZR1gYd6OvjwnGaP8QmrmVSbM5tPgYsleNEavA9zlle 1pahVcXBzf/+Sl40wboa8QazB6aI5oTQTXqkXErpQp1EwfX03UsH1jrmOjz2yQ9lYCDh kMokI193yiQmvKLhfI1NGrjdTS2fRC7dMUigxN/L/d2a7R5ykk1cOHjhx5IyWoaYRLwk 5i/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=pC/1QpVrBnZda6DnrrH7ij1ESXwNBCE2kB9T6VbdfCs=; b=LsRk1sHkUKKO8jWRgusdM+tNOQvoY2NkmBfSo03HT8IAJbUhU5rwH0qNQSFzrJtKuD gTNwR1SA6y8ySXcfXZpYvy0kLFLHM43Q/Sv51HUaiWIlk+T9BYW26Q/eLTyGtAb5dGm5 g7KeSajrroJ8H+1tKh18Yy/tPT17BVn3Bl1nclQFcHEankPFPHU1uvIM4vHT5x927H3g 2UwTS6DWHR8SDliMfEzpI2Weyzo3Uz9CJsYJddPHNaMjWp9fHHKIFBjlew8mvUoGHnJL ChR6uJqpFePdB9YhW9KibeN58kotu/qD7TObzGD0OUpzsx2HG2oEUpBRT09dkUaikXI3 1HnQ== 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 y6-v6si215866pgr.684.2018.08.01.15.58.02; Wed, 01 Aug 2018 15:58:16 -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 S1732392AbeHBAoz (ORCPT + 99 others); Wed, 1 Aug 2018 20:44:55 -0400 Received: from foss.arm.com ([217.140.101.70]:50312 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726880AbeHBAoy (ORCPT ); Wed, 1 Aug 2018 20:44:54 -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 12F2D80D; Wed, 1 Aug 2018 15:56:48 -0700 (PDT) Received: from [192.168.100.241] (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E3783F2EA; Wed, 1 Aug 2018 15:56:47 -0700 (PDT) Subject: Re: [RFC 0/2] harden alloc_pages against bogus nid To: Andrew Morton Cc: linux-mm@kvack.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, 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 References: <20180801200418.1325826-1-jeremy.linton@arm.com> <20180801145020.8c76a490c1bf9bef5f87078a@linux-foundation.org> From: Jeremy Linton Message-ID: Date: Wed, 1 Aug 2018 17:56:46 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180801145020.8c76a490c1bf9bef5f87078a@linux-foundation.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 08/01/2018 04:50 PM, Andrew Morton wrote: > On Wed, 1 Aug 2018 15:04:16 -0500 Jeremy Linton wrote: > >> The thread "avoid alloc memory on offline node" >> >> https://lkml.org/lkml/2018/6/7/251 >> >> Asked at one point why the kzalloc_node was crashing rather than >> returning memory from a valid node. The thread ended up fixing >> the immediate causes of the crash but left open the case of bad >> proximity values being in DSDT tables without corrisponding >> SRAT/SLIT entries as is happening on another machine. >> >> Its also easy to fix that, but we should also harden the allocator >> sufficiently that it doesn't crash when passed an invalid node id. >> There are a couple possible ways to do this, and i've attached two >> separate patches which individually fix that problem. >> >> The first detects the offline node before calling >> the new_slab code path when it becomes apparent that the allocation isn't >> going to succeed. The second actually hardens node_zonelist() and >> prepare_alloc_pages() in the face of NODE_DATA(nid) returning a NULL >> zonelist. This latter case happens if the node has never been initialized >> or is possibly out of range. There are other places (NODE_DATA & >> online_node) which should be checking if the node id's are > MAX_NUMNODES. >> > > What is it that leads to a caller requesting memory from an invalid > node? A race against offlining? If so then that's a lack of > appropriate locking, isn't it? There were a couple unrelated cases, both having to do with the PXN associated with a PCI port. The first case AFAIK, the domain wasn't really invalid if the entire SRAT was parsed and nodes created even when there weren't associated CPUs. The second case (a different machine) is simply a PXN value that is completely invalid (no associated SLIT/SRAT/etc entries) due to firmware making a mistake when a socket isn't populated. There have been a few other suggested or merged patches for the individual problems above, this set is just an attempt at avoiding a full crash if/when another similar problem happens. > > I don't see a problem with emitting a warning and then selecting a > different node so we can keep running. But we do want that warning, so > we can understand the root cause and fix it? Yes, we do want to know when an invalid id is passed, i will add the VM_WARN in the first one. The second one I wasn't sure about as failing prepare_alloc_pages() generates a couple of error messages, but the system then continues operation. I guess my question though is which method (or both/something else?) is the preferred way to harden this up? Thanks for looking at this.