Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3701424imu; Mon, 10 Dec 2018 06:34:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/U8bw3oELwNoOX1ml0GU0KJdlVgkF0AZIeo0VxpvmzPPGg1bcDBAgxGesu8s+ZH79ufHm+y X-Received: by 2002:a17:902:e08b:: with SMTP id cb11mr12452381plb.263.1544452450900; Mon, 10 Dec 2018 06:34:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544452450; cv=none; d=google.com; s=arc-20160816; b=0QKbPxgAF/4N4BGVkIVKOTrTueqj2zmb5sF1X56WR4Fq2Ps12k9I85/ZJRZN+sb4Lq L3skMnyDN+fWWAKh3e1lnghkJcS5EGohT3e4lJaje7Ygp6kJS+VKE7E6lBL+JP4NmgJg 7AFNXCTQgfqcaloCW458rivExMGZ9XoXICXMLR5ZHeR9Olpl93C43KEIY0AsFQjq/p5Q F5HUfwkY0NTcGhMA/YlSC5T7rgvP0us/HZ35xPKObNWAZzgaaeYeQ7cCe/kAmExwEukE OtEHVNQqx5JLR76Vx7IoIUpovfw6PLWnxsL447SPmeoxK4yY0hiT+xjmwhw8SL15Q3jK oYPg== 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=KhOQ+AuaeG/ceMhoOxeWGxq0n8ijfe66DuNJgBCarMg=; b=0kXUL2EVkIcIy52oJWlDn5TOEdfqyy0T1TFleD0BQo6h+0pGavMHlozso40uN6kCt/ AIlI84u0xhWHprfRA7MY2zKOOkkUORqgeKBM4711sRPtKdzrulhTNJmZBBJJKJpY23NC cAIuS/1JJeNMWPlTw2PQvi93IUpmXgjKPVNRwR4ov3nVP03m5EspE4jF/P1to5jz70XI q8gAcq88gztrWbd5nSXjABWeNk2tu8hez/qAyxGrQqS3vWF9RQQgcSh4Nqi3zcjoZR7b SABTyuq8dfJgr6MNEWqeTelq/j5kPCMo3s7tNciOrrKKjulpz+AXhQZDoL2gtyi4TPlE E3NA== 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 c32si10397376plj.38.2018.12.10.06.33.55; Mon, 10 Dec 2018 06:34:10 -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 S1726959AbeLJNHZ (ORCPT + 99 others); Mon, 10 Dec 2018 08:07:25 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:44474 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726209AbeLJNHW (ORCPT ); Mon, 10 Dec 2018 08:07:22 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wBAD4rND038956 for ; Mon, 10 Dec 2018 08:07:21 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p9nb4u7pr-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 10 Dec 2018 08:07:20 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Dec 2018 13:07:18 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 10 Dec 2018 13:07:15 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wBAD7ERG34013308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 10 Dec 2018 13:07:14 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 970B811C04A; Mon, 10 Dec 2018 13:07:14 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5167211C054; Mon, 10 Dec 2018 13:07:14 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 10 Dec 2018 13:07:14 +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 1/1] mm, memory_hotplug: Initialize struct pages for the full memory section Date: Mon, 10 Dec 2018 14:07:12 +0100 X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181210130712.30148-1-zaslonko@linux.ibm.com> References: <20181210130712.30148-1-zaslonko@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18121013-4275-0000-0000-000002EE7FE1 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18121013-4276-0000-0000-000037FB9AAA Message-Id: <20181210130712.30148-2-zaslonko@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-10_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-1812100120 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: 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 Fix the problem by initializing the last memory section of the highest 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2ec9cc407216..41ef5508e5f1 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5542,6 +5542,21 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, cond_resched(); } } +#ifdef CONFIG_SPARSEMEM + /* + * If there is no zone spanning 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). + */ + if (end_pfn == max_pfn) { + 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