Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2280173imc; Tue, 12 Mar 2019 10:29:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqybO9vnZlA+R/8fhKOuZYCHdQZ2gRVjKGvPTWJTeCp2cCCfq20dQ6sfwPJb76gY4h27giY1 X-Received: by 2002:a65:49c4:: with SMTP id t4mr36543297pgs.421.1552411746062; Tue, 12 Mar 2019 10:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552411746; cv=none; d=google.com; s=arc-20160816; b=HEsYuUHZKIgMvNytNJNMoLJAoYlMU6seYOv24ClVKQ6YnwMkxrr0s73RJi89HabmvI dGAQtFIOAnkh34DeONOgmDspb/jhTVKZBBb5SshXxaMktYTwmDIv7MHI2vU0Dys8iWSO XKlOVziC0+sssgWGptHEEo4Iw607JGxbWtny1AcMNFlpOw7x9fmx5celWWQl763VlhJ8 dSjQJSgevDWQ6M4uvJZE8t60aKhGm08+o0qhgfofMmPpSGBb0S712SI2s6Luyd/6JBui bBVIlNDqUMVFKlUTweTe9YfSEN0bndT+IPzoxm+/FC3CVaYfuPu/ALEM1pNcVs1v69mY t2fA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+TOIGjCKra4FPcJScI9f+xKA7aFF4KuPuGAF8a88ND4=; b=AayIbM3AfzTcP1ZcCTUZmY6cF4EvWSxqjdwYmMkGfiunN5enpOtdgmYM+ufTcjvyTQ sZSxqaNwpAdsItG3HyqKad5CxlSL0ej01XU02Wm1WZNCVic3MRC/5oHY6RAr3vcG7nYi h2LrxOguXGdrdirxKbjdk1Y49t6g5Z4Ffc88V6eqe5e6lN0ZS9ynG3ITfr7nyHdJ7Sbc KW7dKoZgu7cTMKGAoPfkOCimtVkwc0jFApLspYvPGOoF7Rtcnx76mpyiyscwSS6e9bFq sffZ3GKcSr8EsVyK/dtmixokZFDvOnR0rMn5bzTm9nv/b0q02OnBirVsul7ZwsGISUu8 dH4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="lf/tDmwJ"; 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 t20si7317276pgv.550.2019.03.12.10.28.50; Tue, 12 Mar 2019 10:29:06 -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=@kernel.org header.s=default header.b="lf/tDmwJ"; 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 S1729664AbfCLRRg (ORCPT + 99 others); Tue, 12 Mar 2019 13:17:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:58576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbfCLRQ2 (ORCPT ); Tue, 12 Mar 2019 13:16:28 -0400 Received: from localhost (unknown [104.133.8.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D86C62171F; Tue, 12 Mar 2019 17:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410987; bh=YdFE62X/kOG4YsuzA6E0MHrF1dcChtd2+jp0/vI8tMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lf/tDmwJmPV3v0+LLIUrHNteVBNhHS6JU5shExYVWPBMqFaDXF4wy+6wmMoGVjlC8 VA/En17PBF1MU7fpMJonrOKKg5ESBhdn7OVCiHcNsjrv9TJtIJRe9G6GDRPGSVOTMB 2DXkhjz3cxSSA1H2pRXTdC27Dfmkyz7MSO4pdeYo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Hocko , Mikhail Zaslonko , Mikhail Gavrilov , Oscar Salvador , Gerald Schaefer , Heiko Carstens , Martin Schwidefsky , Pavel Tatashin , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 082/135] mm, memory_hotplug: test_pages_in_a_zone do not pass the end of zone Date: Tue, 12 Mar 2019 10:08:49 -0700 Message-Id: <20190312170348.732008948@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170341.127810985@linuxfoundation.org> References: <20190312170341.127810985@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 24feb47c5fa5b825efb0151f28906dfdad027e61 ] If memory end is not aligned with the sparse memory section boundary, the mapping of such a section is only partly initialized. This may lead to VM_BUG_ON due to uninitialized struct pages access from test_pages_in_a_zone() function triggered by memory_hotplug sysfs handlers. Here are the the panic examples: CONFIG_DEBUG_VM_PGFLAGS=y kernel parameter mem=2050M -------------------------- page:000003d082008000 is uninitialized and poisoned page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) Call Trace: test_pages_in_a_zone+0xde/0x160 show_valid_zones+0x5c/0x190 dev_attr_show+0x34/0x70 sysfs_kf_seq_show+0xc8/0x148 seq_read+0x204/0x480 __vfs_read+0x32/0x178 vfs_read+0x82/0x138 ksys_read+0x5a/0xb0 system_call+0xdc/0x2d8 Last Breaking-Event-Address: test_pages_in_a_zone+0xde/0x160 Kernel panic - not syncing: Fatal exception: panic_on_oops Fix this by checking whether the pfn to check is within the zone. [mhocko@suse.com: separated this change from http://lkml.kernel.org/r/20181105150401.97287-2-zaslonko@linux.ibm.com] Link: http://lkml.kernel.org/r/20190128144506.15603-3-mhocko@kernel.org [mhocko@suse.com: separated this change from http://lkml.kernel.org/r/20181105150401.97287-2-zaslonko@linux.ibm.com] Signed-off-by: Michal Hocko Signed-off-by: Mikhail Zaslonko Tested-by: Mikhail Gavrilov Reviewed-by: Oscar Salvador Tested-by: Gerald Schaefer Cc: Heiko Carstens Cc: Martin Schwidefsky Cc: Mikhail Gavrilov Cc: Pavel Tatashin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memory_hotplug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 39db89f3df65..c9d3a49bd4e2 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1297,6 +1297,9 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn, i++; if (i == MAX_ORDER_NR_PAGES || pfn + i >= end_pfn) continue; + /* Check if we got outside of the zone */ + if (zone && !zone_spans_pfn(zone, pfn + i)) + return 0; page = pfn_to_page(pfn + i); if (zone && page_zone(page) != zone) return 0; -- 2.19.1