Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5996209ybe; Tue, 10 Sep 2019 11:55:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKv1HrOdt4RIjtF+ZRk+h/xtgGDI4U1FxtnXkEfEMokNofPIDUrermrE5dt1sDe464bUlq X-Received: by 2002:a17:906:3583:: with SMTP id o3mr4266395ejb.224.1568141711646; Tue, 10 Sep 2019 11:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568141711; cv=none; d=google.com; s=arc-20160816; b=ew5cCH/9U8KkUSqlWG2P1mb4IT26necraIEvRmueFXk3cCiAAl58NnSDIunMX/Xyk0 B16y5XP96mtYgmQq9u7ALh67eK54WbmrXs3LdtyvtC9A37KskMK7tTO6LNjA+epOqsKt vmBmlGCETAtmgjB6a1WbhvGxGRG05Cqv1cOYlhiono+yztW7YvJ93zwbGEiGEoWNGNhX XM3Ho3GBAdTlKDEdhkMLfTsHaHZtTfwss09nso/IZASO32ZVUXN1DF+2Wlo9KvzkcWDI 0aKBmX3Au8BZTdRCyt4WBm5u31ZAQfXOKy5+SmtvBgFD13PReEzk4Gm/tlok5HUFtS/x m1Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:thread-index :content-transfer-encoding:mime-version:message-id:date:subject :in-reply-to:references:cc:to:from:dkim-signature; bh=HN24k4RcVTLdeF4gr9MwUdx0NyjhYnzLn1sAk+3MTPU=; b=lzOFsNWv5mJ0pkcHaYVygRssEpp6Un7Dyn1vEh2hXmWF17AwWXPbuNe72DOk/WaTj+ kHI9/2+ZNn6B2kQkcYszep1iIW0OISLgmxjCqcojpsQlzAIkj+jyALxDT+JiRD3gMa5z lAbHZyOsjzpQiMRSh0bVc9RkQ2deZNTQ/KA1Qs7ZW620s6bxlrdC5qb0VOwWEGCA8tea cJ32Ltk/Ay+/f0n54uL3u42vOil/Jzj4CKQM2Afy3Tlx4iDSZOOykTj6CLVNsC1/LRiE yojPNqsnW/HSh7QpKuj6lyX1K+o4wAm4kf+Vxtkp6VTT65+nMtTH9mgVJBe/f14PpCFp VmOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@d-silva.org header.s=201810a header.b=Y9HUa6rU; 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 c14si12854599eda.8.2019.09.10.11.54.47; Tue, 10 Sep 2019 11:55:11 -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; dkim=pass header.i=@d-silva.org header.s=201810a header.b=Y9HUa6rU; 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 S2390518AbfIJK2Z (ORCPT + 99 others); Tue, 10 Sep 2019 06:28:25 -0400 Received: from ushosting.nmnhosting.com ([66.55.73.32]:46528 "EHLO ushosting.nmnhosting.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730370AbfIJK2Z (ORCPT ); Tue, 10 Sep 2019 06:28:25 -0400 Received: from mail2.nmnhosting.com (unknown [202.169.106.97]) by ushosting.nmnhosting.com (Postfix) with ESMTPS id 249C42DC1B4F; Tue, 10 Sep 2019 06:28:23 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=d-silva.org; s=201810a; t=1568111304; bh=bZJVg57WDp2Ql9qxXpt8yM2FR4LlDfEfnLgk5E0mBjA=; h=From:To:Cc:References:In-Reply-To:Subject:Date:From; b=Y9HUa6rUcWPZXDNjUx9UVFKf8wDG0RtUHnj+l9W7NumR7SQJGy1XLM5YK3gertZ92 vFGraMB04wjETdXjP94vUyH8EJ7s/lTcxFvmMnsegsm7nSbdfRMIUEOMa3dZNUttZy 50L0muONHnEUU0AI9LYIAQw95RimaaguCo+MPVOm4XBPIyGMBBPlUBGshVoWpIAfdg fKj5ciigXPEul+6NQxOWjyHeubmbCjgkyoHIibpmc5bt6fU+TpyeJz9Dgr1vQ/8B+Y DK+mJIP+C0nJfDbvX7/cBHoifpMw2OO6S9LPVH9+zG9FPDnq///gL8B36sGpYSq7Af e2YAc1Gq8tjlanxCEhY3nH1v8UCin/0+LB5cNffu4FsRP6cFnm4nZTLMpeyvF6AUv6 wntItlOrrZkxAInF3Lt4xgZJD77QcRjacIdMK04u/bVybMXHdO3TzfPh+m70/uQ1ba 07OuYUb66j7d9GT1wBqCq5hXUYGUZtOkM+3MjVWfUK1+wIE6zPitYVAn0/cGNVIND6 Em+E2QlS8I9Dj8tDu5CQEu8ExC4HhTL2EdehhwTnNpEBJkPr0X0IdmU421BcCIbvgz 8fQ8mjWMfom4MB7nWhSfM/Zlcd2ykHIwU5mjyrvmrIoDE3Ehdmo9hjviorNHoPwCYp er5vqaPzE11ILn3icxx7z/is= Received: from Hawking (ntp.lan [10.0.1.1]) (authenticated bits=0) by mail2.nmnhosting.com (8.15.2/8.15.2) with ESMTPSA id x8AASKLp022591 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 10 Sep 2019 20:28:20 +1000 (AEST) (envelope-from alastair@d-silva.org) From: "Alastair D'Silva" To: "'Kirill A. Shutemov'" , "'Alastair D'Silva'" Cc: "'Andrew Morton'" , "'David Hildenbrand'" , "'Oscar Salvador'" , "'Michal Hocko'" , "'Pavel Tatashin'" , "'Wei Yang'" , "'Dan Williams'" , "'Qian Cai'" , "'Jason Gunthorpe'" , "'Logan Gunthorpe'" , "'Ira Weiny'" , , References: <20190910025225.25904-1-alastair@au1.ibm.com> <20190910025225.25904-2-alastair@au1.ibm.com> <20190910101502.2ioujfvopyr5krpq@box.shutemov.name> In-Reply-To: <20190910101502.2ioujfvopyr5krpq@box.shutemov.name> Subject: RE: [PATCH 1/2] memory_hotplug: Add a bounds check to check_hotplug_memory_range() Date: Tue, 10 Sep 2019 20:28:19 +1000 Message-ID: <05b301d567c2$772be760$6583b620$@d-silva.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQHvMJj7Zv4jgOWqcZIGTeYry0K56gHo4ebvAnkbkLemzhNyMA== Content-Language: en-au X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (mail2.nmnhosting.com [10.0.1.20]); Tue, 10 Sep 2019 20:28:20 +1000 (AEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Kirill A. Shutemov > Sent: Tuesday, 10 September 2019 8:15 PM > To: Alastair D'Silva > Cc: alastair@d-silva.org; Andrew Morton ; > David Hildenbrand ; Oscar Salvador > ; Michal Hocko ; Pavel Tatashin > ; Wei Yang ; > Dan Williams ; Qian Cai ; Jason > Gunthorpe ; Logan Gunthorpe ; Ira > Weiny ; linux-mm@kvack.org; linux- > kernel@vger.kernel.org > Subject: Re: [PATCH 1/2] memory_hotplug: Add a bounds check to > check_hotplug_memory_range() > > On Tue, Sep 10, 2019 at 12:52:20PM +1000, Alastair D'Silva wrote: > > From: Alastair D'Silva > > > > On PowerPC, the address ranges allocated to OpenCAPI LPC memory are > > allocated from firmware. These address ranges may be higher than what > > older kernels permit, as we increased the maximum permissable address > > in commit 4ffe713b7587 > > ("powerpc/mm: Increase the max addressable memory to 2PB"). It is > > possible that the addressable range may change again in the future. > > > > In this scenario, we end up with a bogus section returned from > > __section_nr (see the discussion on the thread "mm: Trigger bug on if > > a section is not found in __section_nr"). > > > > Adding a check here means that we fail early and have an opportunity > > to handle the error gracefully, rather than rumbling on and > > potentially accessing an incorrect section. > > > > Further discussion is also on the thread ("powerpc: Perform a bounds > > check in arch_add_memory"). > > > > Signed-off-by: Alastair D'Silva > > --- > > include/linux/memory_hotplug.h | 1 + > > mm/memory_hotplug.c | 19 ++++++++++++++++++- > > 2 files changed, 19 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/memory_hotplug.h > > b/include/linux/memory_hotplug.h index f46ea71b4ffd..bc477e98a310 > > 100644 > > --- a/include/linux/memory_hotplug.h > > +++ b/include/linux/memory_hotplug.h > > @@ -110,6 +110,7 @@ extern void > > __online_page_increment_counters(struct page *page); extern void > > __online_page_free(struct page *page); > > > > extern int try_online_node(int nid); > > +int check_hotplug_memory_addressable(u64 start, u64 size); > > > > extern int arch_add_memory(int nid, u64 start, u64 size, > > struct mhp_restrictions *restrictions); diff --git > > a/mm/memory_hotplug.c b/mm/memory_hotplug.c index > > c73f09913165..3c5428b014f9 100644 > > --- a/mm/memory_hotplug.c > > +++ b/mm/memory_hotplug.c > > @@ -1030,6 +1030,23 @@ int try_online_node(int nid) > > return ret; > > } > > > > +#ifndef MAX_POSSIBLE_PHYSMEM_BITS > > +#ifdef MAX_PHYSMEM_BITS > > +#define MAX_POSSIBLE_PHYSMEM_BITS MAX_PHYSMEM_BITS #endif > #endif > > + > > +int check_hotplug_memory_addressable(u64 start, u64 size) { #ifdef > > +MAX_POSSIBLE_PHYSMEM_BITS > > How can it be not defined? You've defined it 6 lines above. > It's only conditionally defined. I'll be following David H's advice and just using MAX_PHYSMEM_BITS in the next spin anyway. > > + if ((start + size - 1) >> MAX_POSSIBLE_PHYSMEM_BITS) > > + return -E2BIG; > > +#endif > > + > > + return 0; > > +} > > +EXPORT_SYMBOL_GPL(check_hotplug_memory_addressable); > > + > > static int check_hotplug_memory_range(u64 start, u64 size) { > > /* memory range must be block size aligned */ @@ -1040,7 +1057,7 > @@ > > static int check_hotplug_memory_range(u64 start, u64 size) > > return -EINVAL; > > } > > > > - return 0; > > + return check_hotplug_memory_addressable(start, size); > > } > > > > static int online_memory_block(struct memory_block *mem, void *arg) > > -- > > 2.21.0 > > > > -- > Kirill A. Shutemov > -- Alastair D'Silva mob: 0423 762 819 skype: alastair_dsilva msn: alastair@d-silva.org blog: http://alastair.d-silva.org Twitter: @EvilDeece