Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2274030imc; Tue, 12 Mar 2019 10:21:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwacZG70CQcnBbEQKDqDvsitpb4VkvGmpvBHpsTzNU4DnkWNJh1kh32A1u7NHTXb0gX3Pa+ X-Received: by 2002:a65:62c5:: with SMTP id m5mr21078637pgv.77.1552411294077; Tue, 12 Mar 2019 10:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552411294; cv=none; d=google.com; s=arc-20160816; b=xj+lMqosv67ilwaJJIth6ga1CvzHw9R6UR9zo6De5cCk1OL4JbOckRxTaB7+qZXyEY 3/9dVwOXT51nkfXHQiLAeKMHV93psb+qHHBa5Lgppg375P7RYyL1/UZK1U2Z+2/v4qoi BJxpk/OBOXV+ld0rikdqr2LuXOvY+jJd7E4d0jT9cJBEIiVY+UzzgLsww7MXjKN0WO5Q buLr1PFJmvLJlrpa4RDpu/TxPOwc1Gs3VRMzOJtsmJFCosGyWq+DX/4RaEVXe1Rw0O7m sXz6XR5XDubfF+fvJ7I+n/7n1ze6a/2kBWslrPH82e6LVK8g5C/o4jtF7s0+qgFEoe5V qvdQ== 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=Ex2ht8r3Jlqi8a0tS5EfOTO01jncdwSIBGAMDxKJXD8=; b=nB5Ah2JYrYBFjrC20KJmUG0bxEYZjA1ku6BbwbQ30J7JrWhlxvHpOhuajL7FAZ/Huc /u+HbFxHePWi/naqV6kAC8tYxqFpmOeTJqngQUBQJVgcoT7PcocueawZF+BO34TF269v ZJD6k5RnFgrm0oXmiDnQZkVNCuXLZIYZhruTnHJkSYj7mWtzcPK4xOHKscar8dZZUDw7 RtTSlyLumsKzGJcW73N+FaVhy3PkYveshra3U6rNz7ra2c2EXxDxVf53kpPNNrNSFA1g bCMHxIXanbHMOLrW1YgHQM+jjFU5UvxphTX3824Q49CQidWD5F33i8eWkqcDMV2twlvO QYag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xXJRkPjm; 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 c15si8055516pgj.13.2019.03.12.10.21.18; Tue, 12 Mar 2019 10:21:34 -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=xXJRkPjm; 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 S1730097AbfCLRSa (ORCPT + 99 others); Tue, 12 Mar 2019 13:18:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:34664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729809AbfCLRR4 (ORCPT ); Tue, 12 Mar 2019 13:17:56 -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 60513217D4; Tue, 12 Mar 2019 17:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552411075; bh=jUK6kMOKYtUjTaTr1auy4+4etKCPLbjv9pKS6qP0X0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xXJRkPjmOSiwtJLdARvXaI+zHKNgxdMg3HWApHYMjkzshvI0sv75/ZUbNH2BTYfPp Bl/KVncD67Ty2ngEjK8hnGvgnMyXk01EPbc2UfuxkQlAvxvkxbY1pjMQDX7avJEf4Q s714Wy21SbmOvyEtPUeYMLm7wKV2k+C9eqJLut+g= 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.9 61/96] mm, memory_hotplug: test_pages_in_a_zone do not pass the end of zone Date: Tue, 12 Mar 2019 10:10:19 -0700 Message-Id: <20190312171039.153545928@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312171034.530434962@linuxfoundation.org> References: <20190312171034.530434962@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.9-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 a03a401f11b6..b4c8d7b9ab82 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1512,6 +1512,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