From patchwork Tue Aug 28 09:05:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zaslonko Mikhail X-Patchwork-Id: 10578063 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 A378B14BD for ; Tue, 28 Aug 2018 09:05:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94131274A3 for ; Tue, 28 Aug 2018 09:05:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85AB029918; Tue, 28 Aug 2018 09:05:58 +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 3F64B274A3 for ; Tue, 28 Aug 2018 09:05:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 273BF6B454E; Tue, 28 Aug 2018 05:05:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 223AF6B454F; Tue, 28 Aug 2018 05:05:56 -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 1136D6B4550; Tue, 28 Aug 2018 05:05:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id A22716B454E for ; Tue, 28 Aug 2018 05:05:55 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id x24-v6so530000edm.13 for ; Tue, 28 Aug 2018 02:05:55 -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=neUTjPWbSbi3UoFaFKW0jzToJOkx/ITThR+b2p162og=; b=t9Rw7Ew7w/y6GuwAa39jcCkNRABnlhgX5wJYStqiJcHSULifbKWwZa1ZsRXbWUaNuO 4zqbqSs8Q9zHee75PTs65wCzOvedDHbdCNpOPPoHt405m30QHQCuD2IPnN3fGaNrf8+t Ovtu7umO+eC4jBExmQl24lQ0QjjI+K0kpWW6uHlrNuxY5dkGzIlLPZip4u+Kw2YPNLIr KC1iJzFee9YtC6kTNK9St+Y4Ye9kxYlHOKeWc4gaPmKFNameOJv9Qq5ypCMGc8lp9UKu 82i1RgKbyXAISE08O8C5wU0oJjm3UVFq81BfSmDf9ZaZtO5xlUDgYywbOwnPYdfH9Zn2 0jag== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.158.5 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: APzg51BO3eMRUoeKlc1AfILsT/eUqZj1MI0vRK2lzZDL6lVUIX8s8n4y 3Z76JpWigInVYp1p4IyjCH6IChy5iuJ8eN8Y0kS8kcg4MhM1F5079Uc0ZKEQJAg0KMn4RBcLuvo jCBa5001PWfiyKdfcJ50TcJW4cn/sNK2IWSA5kN/avG+ohIBJRmkPfCT91kExlMVvWg== X-Received: by 2002:a50:b702:: with SMTP id g2-v6mr1342957ede.139.1535447155152; Tue, 28 Aug 2018 02:05:55 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb0ITOsuQmYXWZqULTgQx0M18IFn7kMp7CXFiLt6IuiYChMhxA4PtQfVANhmDxpjkm7SyK3 X-Received: by 2002:a50:b702:: with SMTP id g2-v6mr1342891ede.139.1535447154267; Tue, 28 Aug 2018 02:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535447154; cv=none; d=google.com; s=arc-20160816; b=dr2cqyUzAtLcy3gTb99Xo79eYrRituzDXBOiF/oDXsm05Ysq1rNu4revmuurTAM3GN jWC2r92R8+8Kd8BNZm0x1Slfx0luEmKbMx+hPsqlEpjOnHJW1MzRXvHE5DPRdmEPnQH+ sn5aM+VI3hddlhCdy/Y9gA76PaKPPh4wWcnOul0BUZj40qDyJRGvnyzJHa3BogdA8ba0 dkg5rX6h0Cfoc7rG9JfEhzkz8/sm/7BfGW/hWP/HdW6gbkD88XALmu3LOQ9WUNfOJNBM ejevPRaUnuDJSkn8zqVQ+itN858djo58S39f3CLam8yOt2WAfeYlhjQpjj4sILZqCdGX mvTA== 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:arc-authentication-results; bh=neUTjPWbSbi3UoFaFKW0jzToJOkx/ITThR+b2p162og=; b=R0Fg3WIpxB03zw2o/L117JV+eIqkgDqd2XpEC8duJ3GfgtKzJT0jYFjabkv5pOhBi4 vuDkdUeStrYSnL6HsXnaODkKi2OLZaEpq0TbmgySpoTKuyACKwBA7/Bcw9tQe2S7qKtE xeC4vmKEKTfSEms96gN9mVhbOE0Rw2vheGgk7RzcCgBNV7R0uNiGW/xYynFPBUwjKTs+ e5+aUWCQzqSaEeeMZ/XNskCTu2jF/EXt5Oatb55D6xy1dUn+vGNddD4JxLwue9JKpEz8 H9iQqY2U4WTtC5D/fvg4zsmpyniJ+Glkm34pp07NcI0aHBfioGMhMNgXdYQbYsVS+UD1 QC6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.158.5 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 (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id c10-v6si757606edk.121.2018.08.28.02.05.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 02:05:54 -0700 (PDT) Received-SPF: pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of zaslonko@linux.ibm.com designates 148.163.158.5 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 (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7S94lig018564 for ; Tue, 28 Aug 2018 05:05:52 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2m503dg3je-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 28 Aug 2018 05:05:52 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 28 Aug 2018 10:05:43 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) 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) Tue, 28 Aug 2018 10:05:40 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w7S95eLw26214496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 28 Aug 2018 09:05:40 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D41FC4C050; Tue, 28 Aug 2018 12:05:38 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98D284C046; Tue, 28 Aug 2018 12:05:38 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 28 Aug 2018 12:05:38 +0100 (BST) From: Mikhail Zaslonko To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, pasha.tatashin@oracle.com, mhocko@kernel.org, zaslonko@linux.ibm.com Subject: [PATCH] memory_hotplug: fix kernel_panic on offline page processing Date: Tue, 28 Aug 2018 11:05:39 +0200 X-Mailer: git-send-email 2.16.4 X-TM-AS-GCONF: 00 x-cbid: 18082809-0016-0000-0000-000001FCB903 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18082809-0017-0000-0000-0000325328A0 Message-Id: <20180828090539.41491-1-zaslonko@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-28_03:,, 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=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808280094 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 Within show_valid_zones() the function test_pages_in_a_zone() should be called for online memory blocks only. Otherwise it might lead to the VM_BUG_ON due to uninitialized struct pages (when CONFIG_DEBUG_VM_PGFLAGS kernel option is set): page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) ------------[ cut here ]------------ Call Trace: ([<000000000038f91e>] test_pages_in_a_zone+0xe6/0x168) [<0000000000923472>] show_valid_zones+0x5a/0x1a8 [<0000000000900284>] dev_attr_show+0x3c/0x78 [<000000000046f6f0>] sysfs_kf_seq_show+0xd0/0x150 [<00000000003ef662>] seq_read+0x212/0x4b8 [<00000000003bf202>] __vfs_read+0x3a/0x178 [<00000000003bf3ca>] vfs_read+0x8a/0x148 [<00000000003bfa3a>] ksys_read+0x62/0xb8 [<0000000000bc2220>] system_call+0xdc/0x2d8 That VM_BUG_ON was triggered by the page poisoning introduced in mm/sparse.c with the git commit d0dc12e86b31 ("mm/memory_hotplug: optimize memory hotplug") With the same commit the new 'nid' field has been added to the struct memory_block in order to store and later on derive the node id for offline pages (instead of accessing struct page which might be uninitialized). But one reference to nid in show_valid_zones() function has been overlooked. Fixed with current commit. Also, nr_pages will not be used any more after test_pages_in_a_zone() call, do not update it. Fixes: d0dc12e86b31 ("mm/memory_hotplug: optimize memory hotplug") Cc: # v4.17+ Cc: Pavel Tatashin Signed-off-by: Mikhail Zaslonko Acked-by: Michal Hocko Reviewed-by: Pavel Tatashin --- drivers/base/memory.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index f5e560188a18..622ab8edc035 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -416,26 +416,24 @@ static ssize_t show_valid_zones(struct device *dev, struct zone *default_zone; int nid; - /* - * The block contains more than one zone can not be offlined. - * This can happen e.g. for ZONE_DMA and ZONE_DMA32 - */ - if (!test_pages_in_a_zone(start_pfn, start_pfn + nr_pages, &valid_start_pfn, &valid_end_pfn)) - return sprintf(buf, "none\n"); - - start_pfn = valid_start_pfn; - nr_pages = valid_end_pfn - start_pfn; - /* * Check the existing zone. Make sure that we do that only on the * online nodes otherwise the page_zone is not reliable */ if (mem->state == MEM_ONLINE) { + /* + * The block contains more than one zone can not be offlined. + * This can happen e.g. for ZONE_DMA and ZONE_DMA32 + */ + if (!test_pages_in_a_zone(start_pfn, start_pfn + nr_pages, + &valid_start_pfn, &valid_end_pfn)) + return sprintf(buf, "none\n"); + start_pfn = valid_start_pfn; strcat(buf, page_zone(pfn_to_page(start_pfn))->name); goto out; } - nid = pfn_to_nid(start_pfn); + nid = mem->nid; default_zone = zone_for_pfn_range(MMOP_ONLINE_KEEP, nid, start_pfn, nr_pages); strcat(buf, default_zone->name);