From patchwork Mon Jun 20 02:30:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12886942 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD074C433EF for ; Mon, 20 Jun 2022 02:30:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E145A6B0071; Sun, 19 Jun 2022 22:30:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC3786B0073; Sun, 19 Jun 2022 22:30:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C63D36B0074; Sun, 19 Jun 2022 22:30:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B2CA56B0071 for ; Sun, 19 Jun 2022 22:30:40 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7F11E346C8 for ; Mon, 20 Jun 2022 02:30:40 +0000 (UTC) X-FDA: 79597035840.08.7AA8277 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf29.hostedemail.com (Postfix) with ESMTP id 60964120016 for ; Mon, 20 Jun 2022 02:30:39 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id r1so8496403plo.10 for ; Sun, 19 Jun 2022 19:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rKDkCWFLL2LKHrd0PY7oJwJSwDpD2T5oprcITiH4OoM=; b=caQjzPuBIHwA2jjjyPgS+SZbXzK2In7vHfu7aUGNIa+U/C2FXhNA3dChQV+bWaMcPG 7FlS2gMLACmKgYIq4Cw1zTdb3dP+si8wWFZJujAs2+n4ZdWgXCl0slFlOChKYG/fm1Yo nNGpEcLHuSYfPWoKClGZYjMWL/nz6ACorgOwJ1+S7jXI9N/gEVwENiHOwo8Tib8PlyqS ikEj1dZ27MGpqnNJ+1u0cCNmGqLMim/wVupR6XNaTcBIr4LFLQXuOFrkKkoI2App6+OX oarEM0yWQdccJgOLK+o6cEp/LX/iKe+L3kccp6rOvoUVdwwN9mx11+k0RgFN0y9iDfu/ oTiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rKDkCWFLL2LKHrd0PY7oJwJSwDpD2T5oprcITiH4OoM=; b=sA9cYJiftdjbIPPIzL4h6o6P15rB6YcEd8XuBdmNG1v7hp0/MG7RUuv0q6uDPuJrEF Pyw4hdkemDwJeLdcFy67iFzPRYs5wVtTB3JFKMRG7FWSQeRxdn2jPrrn3q3m6hjyqvFE BNLM+a0be0CZmUb/mfmyAvXUVEya+HLbuGqoMBTZAr8CaliVbq8njnihyMUj6bEoJK7k HkaMbwL4bzJOaQALoiZRMCrrntdWD+da/iRNorZnCrPss9qrpPm/5pyUSAmryCUaPUbm mG9lRM5NEugVKZhNXlY9p+2qJ6M1l2aMgwHNe2vQ7jim+jAW2EO+kp/xoGRKszz6OWDu ilnQ== X-Gm-Message-State: AJIora+uNM0RS4IZCORCf7DwnVxp4cVwCQ5DSR2chYQixn6Vri0yGsY2 8wrwppyZxfDf2jPtg9TNSAtA0A== X-Google-Smtp-Source: AGRyM1tG7Y4Ri55cxJYS8evvg2vI5g0ekaQOzL/vT2Lew/EEVtV27PGqa1e/oIscRqU39mMZiRtzsg== X-Received: by 2002:a17:903:2291:b0:164:95f:b512 with SMTP id b17-20020a170903229100b00164095fb512mr21978303plh.120.1655692238298; Sun, 19 Jun 2022 19:30:38 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id z7-20020a17090a8b8700b001ecb29de3e4sm153644pjn.49.2022.06.19.19.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 19:30:38 -0700 (PDT) From: Muchun Song To: akpm@linux-foundation.org, mike.kravetz@oracle.com Cc: duanxiongchun@bytedance.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , stable@vger.kernel.org Subject: [PATCH] mm: sparsemem: fix missing higher order allocation splitting Date: Mon, 20 Jun 2022 10:30:19 +0800 Message-Id: <20220620023019.94257-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655692240; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=rKDkCWFLL2LKHrd0PY7oJwJSwDpD2T5oprcITiH4OoM=; b=lsexJw4aMQ3AG7YdiDSti2M9Ii78XYY9ct5quzGiFEekdAghRrLtJdrCpYvHmSYFoZ2uRs ohx0TrAX4cAaBW85erWH9dGo61UTxbqAA8knRaAYtl1rzLSL/9xjXcOucrXNdZeJjOblhz UXP8QoQ7DaQhShCxD1AGkNZzdN63kuU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=caQjzPuB; spf=pass (imf29.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655692240; a=rsa-sha256; cv=none; b=hP+7xGLT9WTdFSrp2VBy1j2gFM+xYoRsYs6mEA19bRxmOqI6XSqfP+Vn0rf7sElFBqXo0W I+unLzQ+qEeR53fnI6+uV1eDSqPlZRiKFBscd/wXO3/A38w4EHk/SXzKXGG2mcVr3/bsMk DoD1M8XS4m3tjVy/WymsiY3Fnrv+OQI= X-Stat-Signature: erwzme5w5oa818q881fd3aa3xghjk37c X-Rspamd-Queue-Id: 60964120016 X-Rspamd-Server: rspam11 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=caQjzPuB; spf=pass (imf29.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-HE-Tag: 1655692239-83249 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: Higher order allocations for vmemmap pages from buddy allocator must be able to be treated as indepdenent small pages as they can be freed individually by the caller. There is no problem for higher order vmemmap pages allocated at boot time since each individual small page will be initialized at boot time. However, it will be an issue for memory hotplug case since those higher order vmemmap pages are allocated from buddy allocator without initializing each individual small page's refcount. The system will panic in put_page_testzero() when CONFIG_DEBUG_VM is enabled if the vmemmap page is freed. Fixes: d8d55f5616cf ("mm: sparsemem: use page table lock to protect kernel pmd operations") Cc: Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- mm/sparse-vmemmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 652f11a05749..ebb489fcf07c 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -78,6 +78,14 @@ static int __split_vmemmap_huge_pmd(pmd_t *pmd, unsigned long start) spin_lock(&init_mm.page_table_lock); if (likely(pmd_leaf(*pmd))) { + /* + * Higher order allocations from buddy allocator must be able to + * be treated as indepdenent small pages (as they can be freed + * individually). + */ + if (!PageReserved(page)) + split_page(page, get_order(PMD_SIZE)); + /* Make pte visible before pmd. See comment in pmd_install(). */ smp_wmb(); pmd_populate_kernel(&init_mm, pmd, pgtable);