Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2093988ybi; Sun, 16 Jun 2019 21:38:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOvPV0AKy27FnejQCjaXyh4Bwo1udoriMGItV9l3Hh/1hSAsjG3cjPh2r00aqPeyyH09Y6 X-Received: by 2002:a62:1b0c:: with SMTP id b12mr108326354pfb.230.1560746317193; Sun, 16 Jun 2019 21:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560746317; cv=none; d=google.com; s=arc-20160816; b=0qjccDXzU+/tYevG+tGRbwmHuKDu2w+G7/NlD36M9tR/lD8oJ2T9fujB7rfEnNgDze ibLhpdksBzJTm/AM+4TFGaecqPhGAHFKRrxWsuDSlN/Jj2e9kRvYzsyXnKQfOfHBo0Mq rgrn4XARVV53xqxr4/Y/idU47jNxL7z0JJlv8W1TUQ2EC3ctUPrxUlzIC57L2jxLBGES OztRdSzX8TJK8Fuwsogc7kR5nKyS8PR2fzYIItqb9HuC4xqP1hPqCTm5ZRRoSxxQeFJU 868k1YCl8eZb0Oj67JV81gykzRhdvvVc/Jlu0ZoPZ30MuPcF8XG85aNIHypyx58FKuya an2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=DFBoyGt+R8NmTOF963r77w/ya+w4JVWfsRrNAxQkV7c=; b=MiN7C+cCy+K0UzNBRrzXg6OC4L9L45rIkc3KLHQ2+H44d0ona/qrW06yfYUZEP8evJ xxN6ymvc5GZFpfrLnXjv5pWTZoabm2FM4xy1A+4zD8xi6QAluCJ+F5gzvZiO81IOpWmF oRbzCvBvI87iWnM3xKa+U/Uwr5exbRqz5pPV2+Y8r8Uso2mUjNeUGS91LiEvv2kNdHbT zyl2yF0FbXRSAU8mHmJE9WAtDG8Cacm+tTmZ218bxISRYWqOLNUcKwgbi90Dp7WqcS7l 3UWtsmL1YFS3jdVHOwTJOmsw99WfEMREXK44ImXej1r+PHf4BZa5Qfh3HXsvKi+eZ0Lf q7xA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20si8614827plz.314.2019.06.16.21.38.20; Sun, 16 Jun 2019 21:38:37 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725884AbfFQEiN (ORCPT + 99 others); Mon, 17 Jun 2019 00:38:13 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41396 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725823AbfFQEiM (ORCPT ); Mon, 17 Jun 2019 00:38:12 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5H4bu9h169525 for ; Mon, 17 Jun 2019 00:38:11 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2t63fm0wrc-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 Jun 2019 00:38:10 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 17 Jun 2019 05:38:08 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 17 Jun 2019 05:38:02 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x5H4c1mv37093562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Jun 2019 04:38:01 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6CEAC11C058; Mon, 17 Jun 2019 04:38:01 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 14A0211C050; Mon, 17 Jun 2019 04:38:01 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Jun 2019 04:38:01 +0000 (GMT) Received: from adsilva.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 01A97A0208; Mon, 17 Jun 2019 14:38:00 +1000 (AEST) From: "Alastair D'Silva" To: alastair@d-silva.org Cc: Andrew Morton , Oscar Salvador , David Hildenbrand , Michal Hocko , Pavel Tatashin , Wei Yang , Juergen Gross , Qian Cai , Thomas Gleixner , Ingo Molnar , Josh Poimboeuf , Konrad Rzeszutek Wilk , Jiri Kosina , Peter Zijlstra , Mukesh Ojha , Arun KS , Mike Rapoport , Baoquan He , Logan Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] mm: don't hide potentially null memmap pointer in sparse_remove_one_section Date: Mon, 17 Jun 2019 14:36:28 +1000 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617043635.13201-1-alastair@au1.ibm.com> References: <20190617043635.13201-1-alastair@au1.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19061704-0020-0000-0000-0000034AAC29 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19061704-0021-0000-0000-0000219DEF16 Message-Id: <20190617043635.13201-3-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-17_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=547 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906170042 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alastair D'Silva By adding offset to memmap before passing it in to clear_hwpoisoned_pages, is hides a potentially null memmap from the null check inside clear_hwpoisoned_pages. This patch passes the offset to clear_hwpoisoned_pages instead, allowing memmap to successfully peform it's null check. Signed-off-by: Alastair D'Silva --- mm/sparse.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 104a79fedd00..66a99da9b11b 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -746,12 +746,14 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn, kfree(usemap); __kfree_section_memmap(memmap, altmap); } + return ret; } #ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_FAILURE -static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) +static void clear_hwpoisoned_pages(struct page *memmap, + unsigned long map_offset, int nr_pages) { int i; @@ -767,7 +769,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) if (atomic_long_read(&num_poisoned_pages) == 0) return; - for (i = 0; i < nr_pages; i++) { + for (i = map_offset; i < nr_pages; i++) { if (PageHWPoison(&memmap[i])) { atomic_long_sub(1, &num_poisoned_pages); ClearPageHWPoison(&memmap[i]); @@ -775,7 +777,8 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) } } #else -static inline void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) +static inline void clear_hwpoisoned_pages(struct page *memmap, + unsigned long map_offset, int nr_pages) { } #endif @@ -822,8 +825,7 @@ void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, ms->pageblock_flags = NULL; } - clear_hwpoisoned_pages(memmap + map_offset, - PAGES_PER_SECTION - map_offset); + clear_hwpoisoned_pages(memmap, map_offset, PAGES_PER_SECTION); free_section_usemap(memmap, usemap, altmap); } #endif /* CONFIG_MEMORY_HOTREMOVE */ -- 2.21.0