Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4188364pxb; Mon, 8 Feb 2021 09:58:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0dxpHX1ryhHrBooK7wZ8KJyW0UQd/TO/OqiBwBBgF2xxFe8T37TJVXs7ZtY5ONV46bqmy X-Received: by 2002:a17:906:fb91:: with SMTP id lr17mr18145440ejb.186.1612807132908; Mon, 08 Feb 2021 09:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612807132; cv=none; d=google.com; s=arc-20160816; b=Fwg8g3r2W6wAaHu2Cn37vFzpFzZmol7vr3hwdVVeNV8zjCQxL61IukKQwFKIbOyshJ EaA2BPjPbKsoULRRe0HR2kYDc8D2PhVu4nx6xD536rfaMQmnNNdvsicj5eqzTfYwUcs1 gGGJEPfOQMHJ6Mlwi7VNc4phTXoa2RSBvMXOfvtxq2Ob8Bx5seFFYli3zM+9vCDrUXDH l/1xXEfZIFvscCn7GxD+E6kIlkLx+J5HaPjeUNe6PQJgsoQP4WWJqOuhJBB7TL2/dLLR KiDIlzNcR2K4zsQf7/87wE5GgUv9zcOhrUP6VnL9pj/j/G0uxoXjzStFSRO+reAmA/5B pcDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nuvbkfGlqw/vmFT92/8OMHoZlTbRTPmnB+LEE7I2S7E=; b=oeQRxnE4dh89e0uduRo6k7Wr/stP16nPaQBAJBCzao5XKGslvUJGtIG8/BBbNTbxMt GYO4xlJy+0PBMwZVdaUCZQ7kP7S6q2k5mS4OG8KdyhwXis8ZgjgEBE/YXe8MgelYKK7W 58vwyrI7Y3HhsDXHGrlNLkoZhfUKRbxQcD2Sx79IL42HkNOtUgeJR2PiaPXwaE5vqsuM oIuLVnLElSpkKtGg/+/S8wY0VAe2E7OiZ3zaSo/WXPvJjQNuL2jl9/d0r8TYJQaugxhh GGHYhxhuhU0JLNBcT/HU0NxAUm6i4Y8tpOhERUrsW5ng6vh20CpZr+RfEOoiVM2osBmS Akjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AxFFSbrk; 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=pass (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 sb11si10948785ejb.0.2021.02.08.09.58.28; Mon, 08 Feb 2021 09:58:52 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=AxFFSbrk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233618AbhBHR5Y (ORCPT + 99 others); Mon, 8 Feb 2021 12:57:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:37070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233768AbhBHPcQ (ORCPT ); Mon, 8 Feb 2021 10:32:16 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 93F3664F42; Mon, 8 Feb 2021 15:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797476; bh=Fjkmu67Q7FLaldn2F3+yo7jQuHb/a6aXn743zCIRBGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AxFFSbrkxjulEcxD5dhsk+IEjvamtkNsbqxPoQg5WEw/fdekfhvRKeBvFyo3E9Ye8 gybsBd2oQKyoHKX2L4Jb1OzN77YyLzWCmi3h4/PFGbTSoEQ6t6rbLV58ztGa3pC8FW SeNhMdXhUvFI530KM5bsE4s53l2vpbV+dhR1iwhU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Muchun Song , Mike Kravetz , Michal Hocko , Oscar Salvador , David Hildenbrand , Yang Shi , Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 100/120] mm: hugetlb: fix a race between isolating and freeing page Date: Mon, 8 Feb 2021 16:01:27 +0100 Message-Id: <20210208145822.361857278@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145818.395353822@linuxfoundation.org> References: <20210208145818.395353822@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Muchun Song commit 0eb2df2b5629794020f75e94655e1994af63f0d4 upstream. There is a race between isolate_huge_page() and __free_huge_page(). CPU0: CPU1: if (PageHuge(page)) put_page(page) __free_huge_page(page) spin_lock(&hugetlb_lock) update_and_free_page(page) set_compound_page_dtor(page, NULL_COMPOUND_DTOR) spin_unlock(&hugetlb_lock) isolate_huge_page(page) // trigger BUG_ON VM_BUG_ON_PAGE(!PageHead(page), page) spin_lock(&hugetlb_lock) page_huge_active(page) // trigger BUG_ON VM_BUG_ON_PAGE(!PageHuge(page), page) spin_unlock(&hugetlb_lock) When we isolate a HugeTLB page on CPU0. Meanwhile, we free it to the buddy allocator on CPU1. Then, we can trigger a BUG_ON on CPU0, because it is already freed to the buddy allocator. Link: https://lkml.kernel.org/r/20210115124942.46403-5-songmuchun@bytedance.com Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Reviewed-by: Oscar Salvador Cc: David Hildenbrand Cc: Yang Shi Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5595,9 +5595,9 @@ bool isolate_huge_page(struct page *page { bool ret = true; - VM_BUG_ON_PAGE(!PageHead(page), page); spin_lock(&hugetlb_lock); - if (!page_huge_active(page) || !get_page_unless_zero(page)) { + if (!PageHeadHuge(page) || !page_huge_active(page) || + !get_page_unless_zero(page)) { ret = false; goto unlock; }