Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753703AbbG0Pgm (ORCPT ); Mon, 27 Jul 2015 11:36:42 -0400 Received: from mail-db3on0085.outbound.protection.outlook.com ([157.55.234.85]:43456 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752554AbbG0Pgl (ORCPT ); Mon, 27 Jul 2015 11:36:41 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; ezchip.com; dkim=none (message not signed) header.d=none; From: Chris Metcalf To: Andrew Morton , Yasuaki Ishimatsu , Pekka Enberg , "Paul McQuade" , Tang Chen , "Mel Gorman" , , CC: Chris Metcalf Subject: [PATCH v2] bootmem: avoid freeing to bootmem after bootmem is done Date: Mon, 27 Jul 2015 11:36:06 -0400 Message-ID: <1438011366-11474-1-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <20150727105951.GO2561@suse.de> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD048;1:X6Wn6RQEG2gzh4Wyy19ZM+3bA57iSPFKkKlvVvVA9zhQobZQkRn84VuA/iQPUe8WWGyRFTi8Ub3Yehcs2Pf0EbQSggCqNzsMSCPhURw0bCgKWwj8Hx0TqZPIN3XwGfezvqmkAtg6R/VJf7esWy37I4J6xh1Lahsa2xLCdRSGeSx78PzLXZIXGLvk6pAuO2HY7VM5hU2bdfNuTd7YIyYha76eN6J2ZDgx6XrAxS+y8RWnQS0HvkgWFVeEa9iI2Lv8Iz4dSbifC3UyG/zoaThpnLUbajc29CxClTuyAWIGoi52kxoCw9RLjLpBcvEeuahicXRDtC4oj7+e5tkbusTHVQ== X-Forefront-Antispam-Report: CIP:12.216.194.146;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(339900001)(199003)(189002)(106466001)(48376002)(19580395003)(86362001)(6806004)(42186005)(50986999)(47776003)(33646002)(2201001)(46102003)(85426001)(229853001)(50466002)(19580405001)(104016003)(87936001)(189998001)(36756003)(92566002)(50226001)(77156002)(62966003)(5001920100001)(5003940100001)(5001770100001)(2950100001)(107886002)(4001430100001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM2PR02MB0770;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;AM2PR02MB0770;2:yR7M+CEBmvShHxC9ATO6Uao+IWWE2GSpvbIwePb03Ton542bQq6OkotHw+ru3PN9DTEVZpmOROqyMahp8l+SAbO4bMwBaPSIN8aDKeNRNyzWYcn6ITlvfCfGqQW3d4g7LAuI65loiI7633OOuAnvS3gOtDBqzndEQfiFgVdf+zw=;3:Wqu4/u55NDALK4paXKcZNQe0GgPX/4ifXEs+vN2kl386swpivSk5kC6cq/UP+SraaUFTEprm38EYqXQvuyt1gqke4P7jrGmp91l/Enqu4PlzWwIWGOdodY8QmKUTulwJ8QgMX32jAar9RXrpMhy/DNlX79kMZ/MHFAn+jjHa+90v5caQFOS3hgebxoUnEbaQshqARqm/JUkWCIwNuUciSCTuho3bDQMDTOHx9thyR3FfEUAt0P+QGLjM1lTD+L2t;25:hjpKzF4+Nb1U1Udnk4a52+BoIe4XlYjU5fcfo4/yYPjt/ZhzEkDGx0FmPJtmfGqtdq53p2wyEvBpx8WYXwDVE9ZmKSluwBteiTCARCLWzblArYQnRbcAonf1xQCbTziI8f5rLMAiMa0VMQyLS95gEHdtvqnwrKzGBrS9TCjr57gMIE+8vyEUnIjmEPeBfRXuth953ZOAHXTDEhmjCwC9Fr/AV74PBj6NZ5eZP5BGf3iEhA2IaidCeFBhI1V1beBI;20:P1JBaWAhag7fztSvEjaFIVcVKdXo4Blansj5EFTn60oBIDDcSnIPfxFLL7cxaMYW1TsFgtWbEOtVIYEdYL1vm79JcZfUcOwS6N6BiQlTpNWbe1zbvdsVF0/Kc7vyCXgfljOiNJOrsc0zocE4ytpQ1kMiUc7Afr4TJAPHRM/XZ74= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM2PR02MB0770; AM2PR02MB0770: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:AM2PR02MB0770;BCL:0;PCL:0;RULEID:;SRVR:AM2PR02MB0770; X-Microsoft-Exchange-Diagnostics: 1;AM2PR02MB0770;4:j3NSWl3C54R6lZDJU+yjrC0lMiXparRdR6NQ/fjMbGCdFbKMdbcWzEfUi9TXtmuRp/jwPd/74nlIaV2Gn8xPjPlkDVl9/ZKUx2C+2anl3ua5jNefhNF+NXGx2bUCxodRyiXoiWVZiql1WTC+s6wQ1ooX7OFW97MHw5iUE7PJfviUUbjROeP9lU7B/BHHRGf/iSkMyV1gF1Wep8/ThI664jv7W7eP4YJ5LXDXvJD1wAcfEuewOx6xkz+SpYMdGaaT8Qn12zDEAtLFGsiMdmzrUhtUjorGsnEoybBbcS2cceE= X-Forefront-PRVS: 0650714AAA X-Microsoft-Exchange-Diagnostics: 1;AM2PR02MB0770;23:pI8yVRXj52IPptRGs8mZc6oxGmXvxyny7z5MFzQtQegoW5bA1QliF3WyjOQL8f9LU4meHmSfX+IYF565HmIPZ/vC+syBZLsvTFY7rADYV0EM6rFN3pUPTeteuRielEPltC6x1hTtRXkWscgSFFPmnh+cQpMrWxGO/iQd5H3AoUWxslYnizRuKKWxqdmvMz4jSxUYTN5Oy/o3oXoFpDJeTLXazNuhM1KMCf+wSgHXW4OPxkjbbG7GnouTDB/2YBgvcoLN+R4x7AuNA9Y7xc/YoPeGRAknaxl2LHRPeqq+RnKPE9jVwTm1C2CkCFd80q2bVZSALHPYsVBJdLu/TZFcrDYKZuACM8y0VT8RpY05kH5VCdJaLFOLkmhigbvvrvOMAiq5/wMoZDQ3vt3tIkW6U89SqFGO7AYzdJExQRvLU+DG/vax+O9v8L36n3pXtDVv93Y0CWT75dUfye5nI6qpH8K54JQKG7r/44RaGPTH9qR/hzEHlId5vpi9C1IpaD6lrY59X6D2ZkCptcK38+Arr8nHZPf2DDDdfWXq+mKUjBKqp312QjF77r28X4WT+E6/bykUdKoZ/HwU2PLlV3Sh+nm5Uz4avd7weeSkqemIBFZRFbBBv+MB8bADqiAWpu/+H/uCGB49eP8IUtqB5VrS/fxxa2xoV1k5O549XvvABWHa1dsNQuOfMZ6Ck0TZGrTmhcuw2AV7QmZDq/MIrWoBugekqYykWLbCVK5oa8pmjrgV6nQup/kg+GLvvS4FWWxGcQfP4dM8F7bGsYkKSZqCmLQhoa+/pIDzq1KuAn3v3xj9r5NJKUM/iuxocTKq4HYw6Y/ji9/qUC0Wc01FFsFTVQNi+znWjDup8ezSNE7+rYaqy+8TWUiZwI8e5OoK0Aubwli3FaKJ7UQ5YzfQpb3YPDYdADEM073YO0C8HZSeDDIW8nbQN7oQhcnGE6QKn9H8 X-Microsoft-Exchange-Diagnostics: 1;AM2PR02MB0770;5:8ZJDav4dTkgpJAPEBEegAADkRwdv7UuabLG+EmRcrvj75Wwfr21OmoZtZqrwewR69xADFyqdN1DKO9DK/w0eA4nvFgmgWTrGiLbM+8P8Cnju+0Ml2Hxl1kCW58b88LjYZVJ6UD33uWsc9Q2VBtLWqA==;24:DSUf70HDqEFj8BK/dCzxDFtt6rzaQUGe2PjCJmdkuJOcyjjbUVJHtRIUha+PmR5Rmd9oFSudcqiGlzWHiKi65OLqGA/HLH3hEo+W1ZHcs0A=;20:746RbNAfi/T3j04JT8a92FZ1LRK7TBJUMvjnoEILSr+J23ShjFaCspT6DdlEfgtY84EZ4a22F4lgO57KIDd2+Q== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2015 15:36:36.9964 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR02MB0770 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1885 Lines: 57 Bootmem isn't popular any more, but some architectures still use it, and freeing to bootmem after calling free_all_bootmem_core() can end up scribbling over random memory. Instead, make sure the kernel generates a warning in this case by ensuring the node_bootmem_map field is non-NULL when are freeing or marking bootmem. An instance of this bug was just fixed in the tile architecture ("tile: use free_bootmem_late() for initrd") and catching this case more widely seems like a good thing. Signed-off-by: Chris Metcalf --- v2: use WARN_ON() instead of BUG_ON() [Mel Gorman] mm/bootmem.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/bootmem.c b/mm/bootmem.c index a23dd1934654..3b6380784c28 100644 --- a/mm/bootmem.c +++ b/mm/bootmem.c @@ -236,6 +236,7 @@ static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata) count += pages; while (pages--) __free_pages_bootmem(page++, cur++, 0); + bdata->node_bootmem_map = NULL; bdebug("nid=%td released=%lx\n", bdata - bootmem_node_data, count); @@ -294,6 +295,9 @@ static void __init __free(bootmem_data_t *bdata, sidx + bdata->node_min_pfn, eidx + bdata->node_min_pfn); + if (WARN_ON(bdata->node_bootmem_map == NULL)) + return; + if (bdata->hint_idx > sidx) bdata->hint_idx = sidx; @@ -314,6 +318,9 @@ static int __init __reserve(bootmem_data_t *bdata, unsigned long sidx, eidx + bdata->node_min_pfn, flags); + if (WARN_ON(bdata->node_bootmem_map == NULL)) + return 0; + for (idx = sidx; idx < eidx; idx++) if (test_and_set_bit(idx, bdata->node_bootmem_map)) { if (exclusive) { -- 2.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/