From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout09.his.huawei.com (canpmsgout09.his.huawei.com [113.46.200.224]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03F0939934D for ; Wed, 17 Jun 2026 07:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.224 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781681588; cv=none; b=duncL4jN97fZQyW74clWVQnTgwQ3PjTWFqkJcsvKvnu3g6mg/LnRAdlPp/s/QundpGAkhROR7LPHOmggp7pqYv1anhCYaW/yIOQTVT64qo/82ppSIzKNwdJofzTC8AESBANKjhfvuMJa0/V5JTrr1zTjXF3p1ZTltEV8R+g4+kY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781681588; c=relaxed/simple; bh=2e32M+Qy4wo3Y86eGJCTx/VBUIx4O24MaCjc1mOST3o=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=rGFfcpdhUGg3wnkpCy4mC0Ykh/ydrbUB+HQUgrZp7xuMXAToX7XII5Db6agyyaNNEC0nuHAxxo6fI5b8zAb0V6AyRuRWrdD0pd6ghXbV2Uh5CAIA7CtoIQp86tPDa7ehfttnV0rVqid2DepBfz8Rjep0Ootw9GlAv9Yufne/u7A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=4PvViPGF; arc=none smtp.client-ip=113.46.200.224 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="4PvViPGF" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=MU8cLNW4cs3+j2eOxJiKF6ANHGeeIXo1iPWKsVafUj0=; b=4PvViPGFBMXqKLhx5j6wvRohmp2ncVACO9EumK5IolLjCPHRUP8h3CVM4jdHfmb9IOLx0s+CH GHhiwVvqqtqbl9MfC1PYW3n9gK0letrx3B8YENNVd16HAnKmuxZ1sCd/oO9d5zCWAapstD6CqDh uA6c4ztoPwHWpzRLwl7Geig= Received: from mail.maildlp.com (unknown [172.19.163.163]) by canpmsgout09.his.huawei.com (SkyGuard) with ESMTPS id 4ggFk924s3z1cypL; Wed, 17 Jun 2026 15:25:05 +0800 (CST) Received: from kwepemr500001.china.huawei.com (unknown [7.202.194.229]) by mail.maildlp.com (Postfix) with ESMTPS id 89B11405D1; Wed, 17 Jun 2026 15:33:02 +0800 (CST) Received: from [10.174.178.9] (10.174.178.9) by kwepemr500001.china.huawei.com (7.202.194.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 17 Jun 2026 15:33:01 +0800 Message-ID: <7fa4b268-5c5b-4a69-ba47-40246ff933e0@huawei.com> Date: Wed, 17 Jun 2026 15:33:00 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: khugepaged: free xarray nodes left behind by failed collapse_file() To: Matthew Wilcox CC: Rik van Riel , , , , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Hugh Dickins , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , References: <20260616145413.1491961-1-riel@surriel.com> <8a4caadc-f414-4874-97d4-2fbaebe2af39@huawei.com> From: Jinjiang Tu In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemr500001.china.huawei.com (7.202.194.229) 在 2026/6/17 10:18, Matthew Wilcox 写道: > On Wed, Jun 17, 2026 at 10:00:59AM +0800, Jinjiang Tu wrote: >> 在 2026/6/16 23:29, Matthew Wilcox 写道: >>> On Tue, Jun 16, 2026 at 10:54:13AM -0400, Rik van Riel wrote: >>>> syzkaller reproduces it trivially with MADV_COLLAPSE on a sparse shmem >>>> mapping (collapse aborts with SCAN_TRUNCATED because the range is empty), >>>> and also via slab fault injection, which forces xas_create_range() down >>>> the xas_nomem() path before the same abort. kmemleak then reports the >>>> 576-byte struct xa_node objects allocated in xas_alloc()/xas_nomem(). >>> I think the ways to produce this problem are sufficiently rare/unlikely >> I can reproduce it easily with following steps. [1] >> 1) create file /tmp/test_madvise_collapse and ftruncate to 4MB size, and >> then mmap the file >> 2) memset for the first 2MB >> 3) madvise(MADV_COLLAPSE) for the second 2MB >> 4) unlink the file > Yes, but is there a problem? That is, do we need to clear this up > before we get to clear_inode()? A user cannot exhaust memory by continuously creating xa_node structures. So it is enough to free empty  xa_nodes in clear_inode(). We shouldn't free empty xa_nodes in collapse_file() rollback path, because we couldn't avoid a concurrent call of collapse_file(), which creates xa_nodes for the same region and may use these nodes.