Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4141985pxb; Mon, 8 Feb 2021 08:54:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJygaBsDf5CkWQ2JA3x8oS9m+4lsxi+Ba86RF2seTeEtjWP2Yfy1RUqB6LhZl3kDJ5FlZAKV X-Received: by 2002:a05:6402:2694:: with SMTP id w20mr18062748edd.200.1612803294073; Mon, 08 Feb 2021 08:54:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612803294; cv=none; d=google.com; s=arc-20160816; b=BP20kmBf5ZKDhLrTyVjSrD+s81EbkP+17ylbp2BmcU8iQPjGgQ8Ga641bbHZ1VVuJ/ zrtVr7XbDwIf0vkknrSNjQcNFe+kSpB/FMWDS6kt/kHEtciY17eNq3ZsyZzk59MBEY4e x18HZl9zHJ24Npy1UaHXy3Pnf6lYsGDgkdTBk5jGts+I3BIYc2h+x2izngEWgCai3CLK KIp2fOCdGhS3R6YsbjaAyLhmc6xN9Ix+9JiVkbMVLXRd1MdMrDLGpLJdOKIinrff2ccr DdXMG6Z7QY2hlzRc84X27bP4hQXPZUq0eUPcGmZMHXtIMAu9FPxAGkJETd1j4wytu3XG 0K1A== 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=KlvgpdoUb4C75+3mlF8Hub78YDJ4Toi7cBcHGelOpOM=; b=utO6sYMLiTKC38pjV59edJi/TmwX9E9GUu9SH8AapqwDuQJh63LL1hd/URo1S73ON1 GGPDsqsOOWLLQJhj6O6opJYFPCtpBBoau+nh/M6JJ+u0h8sayxty0iiv+5bF6axvjiqO g2znhxI0cNcLXprshfriHsAJSigABFQd9bYdgSm1AjEhtXZlwBA/eHsBJyvZH3K4UhUc IxocwtZJsEj7OFFiuA9PxnhbonKWUlS+9LWJlx8KW0eBuX9o/qCObeuCAsF6+2IyyCY6 dLLYgD5lI7QHW2E1Fk+MbUKWYrCwGr/G4aKX5eVeF4jV0J24DCSvSmfxsd/bzLfNsJXs /6Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qTm73FPG; 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 v5si12228663edc.346.2021.02.08.08.54.30; Mon, 08 Feb 2021 08:54:54 -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=qTm73FPG; 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 S234577AbhBHQu6 (ORCPT + 99 others); Mon, 8 Feb 2021 11:50:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:60182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233086AbhBHPRa (ORCPT ); Mon, 8 Feb 2021 10:17:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 22C5464EDC; Mon, 8 Feb 2021 15:11:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797120; bh=X5PD4eXLs9pxSyn0fEWADpvXyhUk0i2VaAEqHndORnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qTm73FPGedk5TdgsihSTgqPWUHAWB35TpJivxXJGdxjjwhi0nNdImM+RiZd+VKjfc Xe06yWckjA2fFkwHDTnNNxkPR7DSahCMW5/I12UL+7JJ46pSXyHZZHG1xWKBLsKVyJ J7Gkj/EYJTTSoxrqezxScr7/XkKZg9QycLfZv3EY= 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.4 50/65] mm: hugetlb: fix a race between isolating and freeing page Date: Mon, 8 Feb 2021 16:01:22 +0100 Message-Id: <20210208145812.156983398@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145810.230485165@linuxfoundation.org> References: <20210208145810.230485165@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 @@ -5175,9 +5175,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; }