Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1132832ybt; Tue, 7 Jul 2020 08:29:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvHU84UxiOTJbXd9KdceWg0RTeAebuTe2iu55AneL0vYBeaEAb77NQa8AJWCbeIeVqHRHB X-Received: by 2002:aa7:c3d6:: with SMTP id l22mr61322100edr.148.1594135749555; Tue, 07 Jul 2020 08:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594135749; cv=none; d=google.com; s=arc-20160816; b=jZwThF/2aqCh4BovjTthcAdrCD8jYz+ZbZBW1CL5IEhSOEznxenpzWLdnOIB+3yNfc G1/o+WJk+JQ9fB8J6GNsrTtp2DnCEpEJd1+KMP8CozCy3jS6AswWwtXfnzCZ/PXTsw7K C9EYx7toM0Ox8t01LFBSqc7zAtlPqpKCnlPgY9uuK/VqVjMQMqNvCZljti9h0T2jwlru BF8AsCZqL8JIcfvRanNaqcVsvgei8N9BJm48YdJVKTFDZidfCXcSiJig8f85aWcoUYIk uQoBLHrKgClKdPgT+wosWy4CmAh9nbiOWxg4z2elVvpQpUExearLVLJY2iHYm3LP4HEx ox9g== 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=fimeiB5wihVCLjxdabMi4iJF3gnz31Fjhb+XHrL3bB4=; b=h/08fA5d08Z/daOCcCU7FwstC23W5+p9sO18yCYaHz0rFcQnAu1SkBYKFK0wkC/nSB /YufjjD4rFlhI7e5xjdPdzUy1NGsrUBjtLRhAtTX2yPKyu0rhGrDRTUKuDEESiNHR+ZQ k8k3Eo28NDPBEVz7+3JF+irgRFTln8LaDl0PfnVBNNrtCble9asw1So9uJXMx1etamz8 PAaf/fyTtnn3ISEB/bNKlL22Yy9e/zo61DS0ep6B1qW1cDLKhmFPmDTtSQ6jtK3XNhXm 4U1lfU5eVcKMJqasCLb4yXI4JXnZK6X2ZWZN4pK2H5EepEWwSG01IeoJf6q3QOAVI8gj nACw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mZEo3jv3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp8si20397338ejc.281.2020.07.07.08.28.46; Tue, 07 Jul 2020 08:29:09 -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=mZEo3jv3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729207AbgGGP1A (ORCPT + 99 others); Tue, 7 Jul 2020 11:27:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:41282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730320AbgGGP04 (ORCPT ); Tue, 7 Jul 2020 11:26:56 -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 AE4FD2083B; Tue, 7 Jul 2020 15:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135615; bh=Q++ieKZs+FggROOSYsXHB3svrim3c2FEmtSU7gHAQUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mZEo3jv3vhPGpPNAJgJjs56X9JWVNUYwDYJYjb1HZw8RZ8oB+izoZGTj1iwMrhtOh wue+HuWLk2Y30Moky6KkfSoK52fimhzw/wwlom3iRkD3rieljoed5nlgLBONignULU 9YY/5Z1OKnePcnN8dEdD4BWjzXwtj5vMcKqqGH0U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Barry Song , Andrew Morton , Roman Gushchin , Jonathan Cameron , Aslan Bakirov , Michal Hocko , Andreas Schaufler , Mike Kravetz , Rik van Riel , Joonsoo Kim , Robin Murphy , Linus Torvalds Subject: [PATCH 5.7 110/112] mm/cma.c: use exact_nid true to fix possible per-numa cma leak Date: Tue, 7 Jul 2020 17:17:55 +0200 Message-Id: <20200707145806.202446239@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145800.925304888@linuxfoundation.org> References: <20200707145800.925304888@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: Barry Song commit 40366bd70bbbbf822ca224dfc227a8c8e868c44f upstream. Calling cma_declare_contiguous_nid() with false exact_nid for per-numa reservation can easily cause cma leak and various confusion. For example, mm/hugetlb.c is trying to reserve per-numa cma for gigantic pages. But it can easily leak cma and make users confused when system has memoryless nodes. In case the system has 4 numa nodes, and only numa node0 has memory. if we set hugetlb_cma=4G in bootargs, mm/hugetlb.c will get 4 cma areas for 4 different numa nodes. since exact_nid=false in current code, all 4 numa nodes will get cma successfully from node0, but hugetlb_cma[1 to 3] will never be available to hugepage will only allocate memory from hugetlb_cma[0]. In case the system has 4 numa nodes, both numa node0&2 has memory, other nodes have no memory. if we set hugetlb_cma=4G in bootargs, mm/hugetlb.c will get 4 cma areas for 4 different numa nodes. since exact_nid=false in current code, all 4 numa nodes will get cma successfully from node0 or 2, but hugetlb_cma[1] and [3] will never be available to hugepage as mm/hugetlb.c will only allocate memory from hugetlb_cma[0] and hugetlb_cma[2]. This causes permanent leak of the cma areas which are supposed to be used by memoryless node. Of cource we can workaround the issue by letting mm/hugetlb.c scan all cma areas in alloc_gigantic_page() even node_mask includes node0 only. that means when node_mask includes node0 only, we can get page from hugetlb_cma[1] to hugetlb_cma[3]. But this will cause kernel crash in free_gigantic_page() while it wants to free page by: cma_release(hugetlb_cma[page_to_nid(page)], page, 1 << order) On the other hand, exact_nid=false won't consider numa distance, it might be not that useful to leverage cma areas on remote nodes. I feel it is much simpler to make exact_nid true to make everything clear. After that, memoryless nodes won't be able to reserve per-numa CMA from other nodes which have memory. Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages using cma") Signed-off-by: Barry Song Signed-off-by: Andrew Morton Acked-by: Roman Gushchin Cc: Jonathan Cameron Cc: Aslan Bakirov Cc: Michal Hocko Cc: Andreas Schaufler Cc: Mike Kravetz Cc: Rik van Riel Cc: Joonsoo Kim Cc: Robin Murphy Cc: Link: http://lkml.kernel.org/r/20200628074345.27228-1-song.bao.hua@hisilicon.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/cma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/cma.c +++ b/mm/cma.c @@ -339,13 +339,13 @@ int __init cma_declare_contiguous_nid(ph */ if (base < highmem_start && limit > highmem_start) { addr = memblock_alloc_range_nid(size, alignment, - highmem_start, limit, nid, false); + highmem_start, limit, nid, true); limit = highmem_start; } if (!addr) { addr = memblock_alloc_range_nid(size, alignment, base, - limit, nid, false); + limit, nid, true); if (!addr) { ret = -ENOMEM; goto err;