Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4092580pxb; Mon, 8 Feb 2021 07:47:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRbiqC5kxcLVFD2S449JTx+/AwKimZX3wNP91xTNgTnwsFlB1g/eVjvSGi3qRcKlty2rDr X-Received: by 2002:a17:907:20c4:: with SMTP id qq4mr16589991ejb.495.1612799221654; Mon, 08 Feb 2021 07:47:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612799221; cv=none; d=google.com; s=arc-20160816; b=Szoq7nFmtLTIHt+2R4IyzfFlMPxbwix2xktdwIJfxbB8N8gh+IzN+oCw4T9DimRRKK Tpxu+/UW5VzqVUQTfLJY3+QOi23eyvCRM8rJ8m3wpquc2hINenL+ikiI3ViEGmhiIJ+V fzRsfSwrwV+agk02ZXJxvYIRc1RZkHat+51YRcB1KlvMjzNxD270t3c/HWtWN7FAw4yp rZxlUFr4GyiCdi4unQHvRw/bi3ne6IA/k6lxw4XuyXZcOnkIT8ZJCXk491AW9gf2Bnax n3HKlImvoy//5WWPo4KE5HRbXPYPjEAsWxG1aDfM2VbzBkIMdCBcxm6YXBkvvhUqEI2k UOtg== 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=378yx44p6JwYYZoA+Moj5OX1o356T6afoolp2T1mjKo=; b=pZA9toQgjEDIX8LEDQl7DMg1k9cculjRHnjsrhwkPpJlrCET/3ubbRqBtAjB+urMUN aD+DC767xXVlxFNDuMrdh+TCOxJkjjHptX3x1tDAOfW4D8cTQjcEv9QYlPZVjFwEdy3R fcF76v4CZE3BFMQs8ahpeEVXlX5clJLkrBngRE850RcPR4AC6TQFyWhexL7w71KZxUl2 ZqdkkHs4ANOroTlnjbj9xv5pglCXluaTPDBjdlW8LdBTyFkpIBISo/f6GoeUe/Zebn9V BNJox8nGaJio/wf9vqa7Z67n8cYH8UWpf5LbCOKh1opQtM8Gxzx3jdBZV+bTjOpa6czT 0sAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BF3T4hzp; 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 d19si10714032edt.189.2021.02.08.07.46.37; Mon, 08 Feb 2021 07:47:01 -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=BF3T4hzp; 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 S233614AbhBHPpx (ORCPT + 99 others); Mon, 8 Feb 2021 10:45:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:52454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232783AbhBHPGa (ORCPT ); Mon, 8 Feb 2021 10:06:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA62B64EB7; Mon, 8 Feb 2021 15:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612796703; bh=fzqh2cU15B8Mzgi3D49ZwYmF10tjCwNHjdsPg4dqGxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BF3T4hzpZqgKwkumscpmwPr07+plUUhB1i3w3yxDx33fCEHDLiClC7QWrvwx+Zoyv NmMYnWttB15MkEiHswDX8xdocOiaf4LzC4ckq9fpY7F+8LAQ3uInm1QYt9Tzp6Xsv1 eYv2lcIUSf4LwqmKLSrce710oWfRZlSpragqrXWw= 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 4.9 35/43] mm: hugetlb: fix a race between isolating and freeing page Date: Mon, 8 Feb 2021 16:01:01 +0100 Message-Id: <20210208145807.733890017@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145806.281758651@linuxfoundation.org> References: <20210208145806.281758651@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 @@ -4657,9 +4657,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; }