From patchwork Fri Jan 15 12:49:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12022569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95479C433E0 for ; Fri, 15 Jan 2021 12:51:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4C6CE223E0 for ; Fri, 15 Jan 2021 12:51:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C6CE223E0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EA2C16B0139; Fri, 15 Jan 2021 07:51:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E52FB8D0163; Fri, 15 Jan 2021 07:51:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1B238D0162; Fri, 15 Jan 2021 07:51:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id B8F986B0139 for ; Fri, 15 Jan 2021 07:51:30 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8B3001E16 for ; Fri, 15 Jan 2021 12:51:30 +0000 (UTC) X-FDA: 77707995540.15.army64_50127c02752f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 6AEE71814B0D6 for ; Fri, 15 Jan 2021 12:51:30 +0000 (UTC) X-HE-Tag: army64_50127c02752f X-Filterd-Recvd-Size: 5122 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Jan 2021 12:51:29 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id md11so5013215pjb.0 for ; Fri, 15 Jan 2021 04:51:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DQl8rxWhauEyHy66Vw2doPr/OoHRTcPYRf3F3cd9RBM=; b=mIsdeXyKnr21oVN3m7ahGUHzVFAL4IKQyIJWWr/FkWMmfFnnyjTZGy7xsYs5jvm/+0 2YzpGRQ3MzcBg96rpOAMkIXVw5klf4pNbHvBCUAFgR41iB1BjIoXFbr/7513Ach6TuGb tITWWoEYi3sJITZiRlZnZFGSYDIIGDyFzhjSOPTzD3BeXGHtYTBKwJYKffNEXNWGxDRK CqFaae/nb+uE2iJYLGmGJiCDG537+2wCuGux4ofJsnJgycNmpTdnUbu0rkjrQIHiPzs5 r2vyyygnUARsYpZU/Ku5P/6pLAi0k8fktPSX0pqIBId7xjvIxgZlseTLzlukS+HFLkPC NN9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DQl8rxWhauEyHy66Vw2doPr/OoHRTcPYRf3F3cd9RBM=; b=S65rNrCTKQAa21VeWcWEMJpMf81iOjOMeq9bVcdLCOdwQ2In0L1Xa7qwzie6tNGT/w ARipYRYrfAXXqgXngZGifuZskRhhou4lk82nSn8I9iUlHeigD/7fewoGeGjvIrbJNu8K zxQ0Vf8nyTDUk1mdy2YNp9uoQi7/rVDiLZcucWUoMH8zj/Lw48QlPuNpmxeBZI9YRzuA go76tccFET0Mzx2UyRl2cQ8ABpoHDXNEcJZ5khBlQ66mOudzqVF1FXUAc65h3ot4Hws+ AKlQBNNXoDPpq9/Hmq5tUBljLrQ1WA/e9qEcPCu9qEyBM3oA5F+ujo5SaBD3lDDUdUjQ VECw== X-Gm-Message-State: AOAM533GFc4FfQreDo80tyuduDi2vRW61dXwngu3k9KhCX6AIfiXBCbf 9u/Qsd3xI4kxUOlKK6v1Fqlidg== X-Google-Smtp-Source: ABdhPJxzO1F+Kc413WL6P0dby5vR8c7bqbiw7shMdYNcdj83Zo+SOzQRLU5IUoiFalgATpr8wIPwPA== X-Received: by 2002:a17:90a:3cc6:: with SMTP id k6mr10434490pjd.204.1610715089021; Fri, 15 Jan 2021 04:51:29 -0800 (PST) Received: from localhost.localdomain ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id c5sm8193600pjo.4.2021.01.15.04.51.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jan 2021 04:51:28 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Michal Hocko , stable@vger.kernel.org Subject: [PATCH v6 4/5] mm: hugetlb: fix a race between isolating and freeing page Date: Fri, 15 Jan 2021 20:49:41 +0800 Message-Id: <20210115124942.46403-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210115124942.46403-1-songmuchun@bytedance.com> References: <20210115124942.46403-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Cc: stable@vger.kernel.org Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b99fe4a2b435..f2cef3cf1f85 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5572,9 +5572,9 @@ bool isolate_huge_page(struct page *page, struct list_head *list) { 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; }