Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1253559pxa; Thu, 20 Aug 2020 06:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyotGueR0+9ijr2g8UxqwgnQkOvRuHMS1E2yeu8BRqK/MT+gpdAL4sUh4GRamT2/yXcsMVk X-Received: by 2002:a17:906:e0ce:: with SMTP id gl14mr3547783ejb.393.1597931483773; Thu, 20 Aug 2020 06:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597931483; cv=none; d=google.com; s=arc-20160816; b=07dWKpBa9Je4Amffzy00+e0zo9RNkHWgwKjumr5pVY9MQ7F0HvGgKf+N6Md/IDZ2SG Gf3SnXyZ3/Yng3byFZCw26chNyQGwq7n78620PljhbFQaHAnG1RdA41RoMzBjAHOfD7s R8+xC8qpSpJmqVxe68AK4pCQiRt97SCe6Z5FUIP3eYo337P9fSS+F0wNu+v+g8RsD4IL UWyvEYj0PtXcXOvCWy+CmBEBkFuyqOpXa5AkqKP17J9TQr+SAtNXoyjldzYjpMNg9zub 3Qg58P6fmtTzMim0CfnDCe29l5Hy/RZvDV2cO7LzcbRnC+t9NM5o9fzYahl1fAD8g4z6 esuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JlF4wPDTORjcwsgDueJIinEX7ZPsBJCVAMm1NK8Tt/g=; b=zj31D3Nvbrl+DH+OzkMucxqNMlsUxToPUVf22gMD4kvyOkNS7U/zDGEuZDcHzNyJks B6+AYjVTg7SahHwwRZ8rmPUy0ywg3m2Q7GAGfnvBiViawGGKHdVM1W6Bkh1o5oDXxonb WEmbdial5Vrf2+vDA0WJ1eRqmREgY5Bkkr23sLyNK7RiV/qQbFeoFR2tswA85B9m/VTr tqUGdehwp/gqoEKyrjd0Vpq5UY1dNp9AR3B0f9OFf3lT8Y88bHKbgzQCjsFSFSy/PpM3 hfQBD9q2FBeRiB8dqM8JLPmYkyM8zzXNtMSM8ojMCnT7dnfLe0UN5BiQFvkwke7PyvDx VQPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0PSCRNIR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e12si1382697edn.431.2020.08.20.06.50.59; Thu, 20 Aug 2020 06:51:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0PSCRNIR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729856AbgHTNtv (ORCPT + 99 others); Thu, 20 Aug 2020 09:49:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:35748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726976AbgHTJ12 (ORCPT ); Thu, 20 Aug 2020 05:27:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A075222CB2; Thu, 20 Aug 2020 09:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915647; bh=3rhEvQdtaZVkjicRvpomqlnahjTQxYkIgWBGzz3QM9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0PSCRNIRdjkkhF9LId25pAzCo+NPBU/8MFCyCcxCplJWBccgP8Sm26ylqKt8efigL I72z5JMwfsPFhz4inmZte4P7g4wILyOnFRsiYSeMHiCS0T565jm7h33GuY3WhQhWqc LMYGD9+6uZ1J3lbKCgX1B9knDjEm00OyDIG45BlQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Kravetz , Andrew Morton , Roman Gushchin , Barry Song , Marek Szyprowski , Michal Nazarewicz , Kyungmin Park , Joonsoo Kim , Linus Torvalds Subject: [PATCH 5.8 086/232] cma: dont quit at first error when activating reserved areas Date: Thu, 20 Aug 2020 11:18:57 +0200 Message-Id: <20200820091616.985592986@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Kravetz commit 3a5139f1c5bb76d69756fb8f13fffa173e261153 upstream. The routine cma_init_reserved_areas is designed to activate all reserved cma areas. It quits when it first encounters an error. This can leave some areas in a state where they are reserved but not activated. There is no feedback to code which performed the reservation. Attempting to allocate memory from areas in such a state will result in a BUG. Modify cma_init_reserved_areas to always attempt to activate all areas. The called routine, cma_activate_area is responsible for leaving the area in a valid state. No one is making active use of returned error codes, so change the routine to void. How to reproduce: This example uses kernelcore, hugetlb and cma as an easy way to reproduce. However, this is a more general cma issue. Two node x86 VM 16GB total, 8GB per node Kernel command line parameters, kernelcore=4G hugetlb_cma=8G Related boot time messages, hugetlb_cma: reserve 8192 MiB, up to 4096 MiB per node cma: Reserved 4096 MiB at 0x0000000100000000 hugetlb_cma: reserved 4096 MiB on node 0 cma: Reserved 4096 MiB at 0x0000000300000000 hugetlb_cma: reserved 4096 MiB on node 1 cma: CMA area hugetlb could not be activated # echo 8 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] SMP PTI ... Call Trace: bitmap_find_next_zero_area_off+0x51/0x90 cma_alloc+0x1a5/0x310 alloc_fresh_huge_page+0x78/0x1a0 alloc_pool_huge_page+0x6f/0xf0 set_max_huge_pages+0x10c/0x250 nr_hugepages_store_common+0x92/0x120 ? __kmalloc+0x171/0x270 kernfs_fop_write+0xc1/0x1a0 vfs_write+0xc7/0x1f0 ksys_write+0x5f/0xe0 do_syscall_64+0x4d/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: c64be2bb1c6e ("drivers: add Contiguous Memory Allocator") Signed-off-by: Mike Kravetz Signed-off-by: Andrew Morton Reviewed-by: Roman Gushchin Acked-by: Barry Song Cc: Marek Szyprowski Cc: Michal Nazarewicz Cc: Kyungmin Park Cc: Joonsoo Kim Cc: Link: http://lkml.kernel.org/r/20200730163123.6451-1-mike.kravetz@oracle.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/cma.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) --- a/mm/cma.c +++ b/mm/cma.c @@ -93,17 +93,15 @@ static void cma_clear_bitmap(struct cma mutex_unlock(&cma->lock); } -static int __init cma_activate_area(struct cma *cma) +static void __init cma_activate_area(struct cma *cma) { unsigned long base_pfn = cma->base_pfn, pfn = base_pfn; unsigned i = cma->count >> pageblock_order; struct zone *zone; cma->bitmap = bitmap_zalloc(cma_bitmap_maxno(cma), GFP_KERNEL); - if (!cma->bitmap) { - cma->count = 0; - return -ENOMEM; - } + if (!cma->bitmap) + goto out_error; WARN_ON_ONCE(!pfn_valid(pfn)); zone = page_zone(pfn_to_page(pfn)); @@ -133,25 +131,22 @@ static int __init cma_activate_area(stru spin_lock_init(&cma->mem_head_lock); #endif - return 0; + return; not_in_zone: - pr_err("CMA area %s could not be activated\n", cma->name); bitmap_free(cma->bitmap); +out_error: cma->count = 0; - return -EINVAL; + pr_err("CMA area %s could not be activated\n", cma->name); + return; } static int __init cma_init_reserved_areas(void) { int i; - for (i = 0; i < cma_area_count; i++) { - int ret = cma_activate_area(&cma_areas[i]); - - if (ret) - return ret; - } + for (i = 0; i < cma_area_count; i++) + cma_activate_area(&cma_areas[i]); return 0; }