Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2101306imu; Wed, 12 Dec 2018 09:29:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/VqdYFLPonRMeA2iirtfRQ8Zhx9PTDWPz5QB/Q+cJ9Q7YZqBkvrnqK5PfuLLdi2cZmzlf9D X-Received: by 2002:a17:902:8306:: with SMTP id bd6mr20859201plb.217.1544635786554; Wed, 12 Dec 2018 09:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544635786; cv=none; d=google.com; s=arc-20160816; b=CbQRC7rdJVAFxiv8jXr99Q2DcAumBClh/5GqJKFcuk6hrcSszJP3n2N9Gc8tqnYxmF 3qmJab7Db/hbP7NcJvquCgoOEx+inodXYnqvqj5JuGj2l7xENooe3ewISsirIM4D+XX9 9/plp2zt7IRm7Gop9s3ZwsE++LEMuBLQWKLpb/BK+Ng+YQDL9OFAWKdnE5TsP/n2TEUY 7OMtYa7dje70KAYJfiPgmYbKuQ3gQWQldcoXKJbtiX84jnnqDe9GiTj3bgnw2PpRQZp3 ykB/Kui8Y38rfectES8+6yRO7hdA4TmMFm6S0hGfRUFZV2j6pMr9La21lDIoMUYRpU14 kgIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=UOuQMSwbuFkCTymfS8EUdr6ubeMd/WILOfqhQz58s5A=; b=EnraZGcpx2uuZVzR39v1k+Vm+N2XXG5ZfK5KJBuW19fC2bx/3Oufrz5JEywW5R6MV/ yWFPzhqw+HhdWRyjKDlpHdaNSYzakLPEWAvU4WDWlbUQMLAXga/nFtaqtO5ByxbFg6w6 ryy1rremB5OQ49D5kSg+aorvrLxf41W+QnUIEu59Yz2R2T3wuzry9msjc8d/SVvEg91D CHGWYyUBmwplbmoLb6kGHvF5CjRusQTPfOVysy126SgqPEOfICCKrc7nOqV9nsvbfMev 4KmSL6M7e5ulrKdTbQFv8XM8EnIc0D9T98ZW1YAZonU0PmE8L0hvuwThPpCpStOCNymT Drlw== 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 t19si15708050pgk.163.2018.12.12.09.29.31; Wed, 12 Dec 2018 09:29:46 -0800 (PST) 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 S1728076AbeLLR1X (ORCPT + 99 others); Wed, 12 Dec 2018 12:27:23 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56286 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727927AbeLLR1V (ORCPT ); Wed, 12 Dec 2018 12:27:21 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wBCHJgPM078101 for ; Wed, 12 Dec 2018 12:27:20 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2pb4wvdjct-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 12 Dec 2018 12:27:20 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 12 Dec 2018 17:27:18 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 12 Dec 2018 17:27:14 -0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wBCHRET46422914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 12 Dec 2018 17:27:14 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E897A4203F; Wed, 12 Dec 2018 17:27:13 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A1A6642045; Wed, 12 Dec 2018 17:27:13 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 12 Dec 2018 17:27:13 +0000 (GMT) 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, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, gerald.schaefer@de.ibm.com, zaslonko@linux.ibm.com Subject: [PATCH v2 1/1] mm, memory_hotplug: Initialize struct pages for the full memory section Date: Wed, 12 Dec 2018 18:27:12 +0100 X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181212172712.34019-1-zaslonko@linux.ibm.com> References: <20181212172712.34019-1-zaslonko@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18121217-0016-0000-0000-000002358E66 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18121217-0017-0000-0000-0000328DC382 Message-Id: <20181212172712.34019-2-zaslonko@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-12_04:,, 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812120149 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 page access from is_mem_section_removable() or test_pages_in_a_zone() function triggered by memory_hotplug sysfs handlers: Here are the the panic examples: CONFIG_DEBUG_VM=y 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: ([<0000000000385b26>] test_pages_in_a_zone+0xde/0x160) [<00000000008f15c4>] show_valid_zones+0x5c/0x190 [<00000000008cf9c4>] dev_attr_show+0x34/0x70 [<0000000000463ad0>] sysfs_kf_seq_show+0xc8/0x148 [<00000000003e4194>] seq_read+0x204/0x480 [<00000000003b53ea>] __vfs_read+0x32/0x178 [<00000000003b55b2>] vfs_read+0x82/0x138 [<00000000003b5be2>] ksys_read+0x5a/0xb0 [<0000000000b86ba0>] system_call+0xdc/0x2d8 Last Breaking-Event-Address: [<0000000000385b26>] test_pages_in_a_zone+0xde/0x160 Kernel panic - not syncing: Fatal exception: panic_on_oops kernel parameter mem=3075M -------------------------- page:000003d08300c000 is uninitialized and poisoned page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) Call Trace: ([<000000000038596c>] is_mem_section_removable+0xb4/0x190) [<00000000008f12fa>] show_mem_removable+0x9a/0xd8 [<00000000008cf9c4>] dev_attr_show+0x34/0x70 [<0000000000463ad0>] sysfs_kf_seq_show+0xc8/0x148 [<00000000003e4194>] seq_read+0x204/0x480 [<00000000003b53ea>] __vfs_read+0x32/0x178 [<00000000003b55b2>] vfs_read+0x82/0x138 [<00000000003b5be2>] ksys_read+0x5a/0xb0 [<0000000000b86ba0>] system_call+0xdc/0x2d8 Last Breaking-Event-Address: [<000000000038596c>] is_mem_section_removable+0xb4/0x190 Kernel panic - not syncing: Fatal exception: panic_on_oops Fix the problem by initializing the last memory section of each zone in memmap_init_zone() till the very end, even if it goes beyond the zone end. Signed-off-by: Mikhail Zaslonko Reviewed-by: Gerald Schaefer Cc: --- mm/page_alloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2ec9cc407216..e2afdb2dc2c5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5542,6 +5542,18 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, cond_resched(); } } +#ifdef CONFIG_SPARSEMEM + /* + * If the zone does not span the rest of the section then + * we should at least initialize those pages. Otherwise we + * could blow up on a poisoned page in some paths which depend + * on full sections being initialized (e.g. memory hotplug). + */ + while (end_pfn % PAGES_PER_SECTION) { + __init_single_page(pfn_to_page(end_pfn), end_pfn, zone, nid); + end_pfn++; + } +#endif } #ifdef CONFIG_ZONE_DEVICE -- 2.16.4