From patchwork Mon Sep 10 12:35:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zaslonko Mikhail X-Patchwork-Id: 10594111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF7FB921 for ; Mon, 10 Sep 2018 12:35:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD43828EBF for ; Mon, 10 Sep 2018 12:35:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D025128EC6; Mon, 10 Sep 2018 12:35:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5686128EBF for ; Mon, 10 Sep 2018 12:35:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 016048E0002; Mon, 10 Sep 2018 08:35:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F05EB8E0001; Mon, 10 Sep 2018 08:35:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1E568E0002; Mon, 10 Sep 2018 08:35:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by kanga.kvack.org (Postfix) with ESMTP id B675D8E0001 for ; Mon, 10 Sep 2018 08:35:36 -0400 (EDT) Received: by mail-oi0-f70.google.com with SMTP id y135-v6so26477178oie.11 for ; Mon, 10 Sep 2018 05:35:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=lmXRCGMjY5acPen/DwTsqdE2DP4qg0MchOAuaYrHEC8=; b=i8O3jVrbThA492r03GJQiyQhrvgBq2lxBu2myD5ssSxTWmhW4h31uGY+4DWGIddpTA ypAU0W0kPLDgBatZDObJiEbaJAzIc5QUl2SoSjMfV00ZOzdNuBe2yTBAR0qTXvFTpQhW JqAY5VqkoEJl4+byvyvtroGNFuLx4kF1DyaeBT+uZwG8KA5cLTCx7Gev1rEOgwprYe8e f2qUq84poVXcgEhIBnfht0WZz3A9lEJxCE5llj0iuTSBa0rilbe+uF6FoFLWkQN+8Dw8 c4gl6qV+PkpoqrpFb8NB1rt9xWwaitQ/iI8MGpedpt2d4v78AFbOc/AX2aXVUdVYvakN uxuA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=zaslonko@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: APzg51CATja0H2q2l4infW7VrYVRuKiUFg3ACJnVhePXSi4RLnX6Izf3 wu93WUh/H/XGH9JHRngeMSRqgSg0Yw1Dkl6Bi6IIXs1FJ5wFjG6ng/wbvTds3EzAhWAmr4yBoKO A/FOhKLjPs2cOXva3VnKnojLISNLf5LNXRJOjMiRUf8uNkgANPs32vvjITLWie7nbMw== X-Received: by 2002:aca:1802:: with SMTP id h2-v6mr21252361oih.353.1536582936416; Mon, 10 Sep 2018 05:35:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdahyzYmYY7+NjN1TRZGtPP2/VmA8LC1zfVZ1k3Y/dMtd7jtKCJTIykPj2d5nPvkjYYuz75G X-Received: by 2002:aca:1802:: with SMTP id h2-v6mr21252259oih.353.1536582934914; Mon, 10 Sep 2018 05:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536582934; cv=none; d=google.com; s=arc-20160816; b=GYUS/7YvAa6g/yCt6GWzfPnshT/UlhLjVlq2PHX4QM998hZhRaNm4QQWi1FOQNvqsF bNNrZoIsD+WskRfWmRbeurN/e5yPZ6WOudxUPCMnDp1EyelmsqvoXW+N/qH8RHa5Rn7d SyN32jFkNbOWNiLeTezceXuM3elqcAZjL8H5nkbGHR5gcTVKqE0bLY6gG2bVxecIBOoJ BcUVO5FfXJajuFnq065epTHN/zpqDVGuIHMbnvGmsBENeX44ocPCJXeW2v95nuT0o3Jk YdRrGF1exL7zgX3DuZw8HI756xTjDut3icZHeOIymxZ1OCNJZ+lRApqGD9f6xL8zyDTW fKHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=lmXRCGMjY5acPen/DwTsqdE2DP4qg0MchOAuaYrHEC8=; b=zUuxB2eHXwsoIW3Tjn6gthzNcx86MAaqU8rGy7QoFBjnkcld673kgl0loUZKASozxQ /w76skOdNY2afAXh0YwK0d58/xyXR3sQqSyfxAUAlmbNeU3rXVTu2F0uJeZMKqQbL70W 2j/Zk39Frh0R3kdPz3qTk2wjaZ9zmsHzw9PfqOvaGeBumE1R3F9wj7pTTdwbyGv5yvFS IZSer74ASBsQ8Ns7F5JRHxvCwsgV+blta5D/glDRW78/vRfpX6PSdU/7sGDMICIsTHUR HynE0gSyZvH8YqXgNcUW/K3C7ANJs6yVtxn23p/wpN+0jMKGKa5i+T/be+wKpDEbyj8I pDwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=zaslonko@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id b5-v6si10367170oic.185.2018.09.10.05.35.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 05:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=zaslonko@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8ACYYp6038897 for ; Mon, 10 Sep 2018 08:35:34 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mdrc0927a-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 10 Sep 2018 08:35:33 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Sep 2018 13:35:31 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 10 Sep 2018 13:35:29 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8ACZS5b66584732 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 10 Sep 2018 12:35:28 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 817414C046; Mon, 10 Sep 2018 15:35:20 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F0F44C040; Mon, 10 Sep 2018 15:35:20 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 10 Sep 2018 15:35:20 +0100 (BST) From: Mikhail Zaslonko To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, Pavel.Tatashin@microsoft.com, osalvador@suse.de, gerald.schaefer@de.ibm.com, zaslonko@linux.ibm.com Subject: [PATCH] memory_hotplug: fix the panic when memory end is not on the section boundary Date: Mon, 10 Sep 2018 14:35:27 +0200 X-Mailer: git-send-email 2.16.4 X-TM-AS-GCONF: 00 x-cbid: 18091012-0012-0000-0000-000002A6A04C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18091012-0013-0000-0000-000020DAD849 Message-Id: <20180910123527.71209-1-zaslonko@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-10_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=970 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809100130 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP If memory end is not aligned with the linux memory section boundary, such a section is only partly initialized. This may lead to VM_BUG_ON due to uninitialized struct pages access from is_mem_section_removable() or test_pages_in_a_zone() function. Here is one of the panic examples: CONFIG_DEBUG_VM_PGFLAGS=y kernel parameter mem=3075M page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) ------------[ cut here ]------------ Call Trace: ([<000000000039b8a4>] is_mem_section_removable+0xcc/0x1c0) [<00000000009558ba>] show_mem_removable+0xda/0xe0 [<00000000009325fc>] dev_attr_show+0x3c/0x80 [<000000000047e7ea>] sysfs_kf_seq_show+0xda/0x160 [<00000000003fc4e0>] seq_read+0x208/0x4c8 [<00000000003cb80e>] __vfs_read+0x46/0x180 [<00000000003cb9ce>] vfs_read+0x86/0x148 [<00000000003cc06a>] ksys_read+0x62/0xc0 [<0000000000c001c0>] system_call+0xdc/0x2d8 This fix checks if the page lies within the zone boundaries before accessing the struct page data. The check is added to both functions. Actually similar check has already been present in is_pageblock_removable_nolock() function but only after the struct page is accessed. Signed-off-by: Mikhail Zaslonko Reviewed-by: Gerald Schaefer Cc: --- mm/memory_hotplug.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 9eea6e809a4e..8e20e8fcc3b0 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1229,9 +1229,8 @@ static struct page *next_active_pageblock(struct page *page) return page + pageblock_nr_pages; } -static bool is_pageblock_removable_nolock(struct page *page) +static bool is_pageblock_removable_nolock(struct page *page, struct zone **zone) { - struct zone *zone; unsigned long pfn; /* @@ -1241,15 +1240,14 @@ static bool is_pageblock_removable_nolock(struct page *page) * We have to take care about the node as well. If the node is offline * its NODE_DATA will be NULL - see page_zone. */ - if (!node_online(page_to_nid(page))) - return false; - - zone = page_zone(page); pfn = page_to_pfn(page); - if (!zone_spans_pfn(zone, pfn)) + if (*zone && !zone_spans_pfn(*zone, pfn)) return false; + if (!node_online(page_to_nid(page))) + return false; + *zone = page_zone(page); - return !has_unmovable_pages(zone, page, 0, MIGRATE_MOVABLE, true); + return !has_unmovable_pages(*zone, page, 0, MIGRATE_MOVABLE, true); } /* Checks if this range of memory is likely to be hot-removable. */ @@ -1257,10 +1255,11 @@ bool is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages) { struct page *page = pfn_to_page(start_pfn); struct page *end_page = page + nr_pages; + struct zone *zone = NULL; /* Check the starting page of each pageblock within the range */ for (; page < end_page; page = next_active_pageblock(page)) { - if (!is_pageblock_removable_nolock(page)) + if (!is_pageblock_removable_nolock(page, &zone)) return false; cond_resched(); } @@ -1296,6 +1295,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)) + return 0; page = pfn_to_page(pfn + i); if (zone && page_zone(page) != zone) return 0;