From patchwork Fri May 31 00:50:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13681014 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 BE3F6C25B76 for ; Fri, 31 May 2024 00:51:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19E026B0089; Thu, 30 May 2024 20:51:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14EE16B0092; Thu, 30 May 2024 20:51:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03C156B0093; Thu, 30 May 2024 20:51:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D8AED6B0089 for ; Thu, 30 May 2024 20:51:11 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6AC1480EF0 for ; Fri, 31 May 2024 00:51:11 +0000 (UTC) X-FDA: 82176861942.21.BF2C869 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf25.hostedemail.com (Postfix) with ESMTP id 272EEA0006 for ; Fri, 31 May 2024 00:51:06 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf25.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717116668; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=piCqxNTUSkIyTFM6mJXt/V1dBNluOpgh4D6VYilcNfE=; b=6J053FSR2gFNogJcw3S1hzKr3pJFYbizrf274/pCpgWidA7UxZ//at2RQhMxs0ah4PUmBV nJ1TKpTQJr9/YCQVw64qgIPvO8v/DKBxM0o+syBhMYgS3GTPfrTjc20h7+MHq2VulV8usN Z8vzH7oeUCK4/udB0uvGQZqDnRGnDbc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf25.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717116668; a=rsa-sha256; cv=none; b=VkyO9Nrdl2APX15yi8AMczZv5E13NSCUmNCqLeGWmbX7bkmJ/m/hNkBQCCXy7n/j79Pu/0 VOGsKTFp6OZUitsOY7iJj4rlTOjuSxkM5e8hkvQQk7QDl+5I+A3VQPB7NLpYsnMcswqJO8 i8uw+PFfJ/KgVo20E9IwaLMCDZejB6U= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 44V0oCZS010395; Fri, 31 May 2024 08:50:12 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Vr4Ds5lq3z2Mx64R; Fri, 31 May 2024 08:46:21 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 31 May 2024 08:50:09 +0800 From: "zhaoyang.huang" To: Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Baoquan He , Thomas Gleixner , hailong liu , , , Zhaoyang Huang , Subject: [PATCHv2] mm: fix incorrect vbq reference in purge_fragmented_block Date: Fri, 31 May 2024 08:50:07 +0800 Message-ID: <20240531005007.1600287-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.40] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 44V0oCZS010395 X-Rspamd-Queue-Id: 272EEA0006 X-Stat-Signature: m3pc61fx39e6nio5ohfk3gt4cf45ufem X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1717116666-555693 X-HE-Meta: U2FsdGVkX18i3JZsW9u3ENMSB1B5/69V9Nv3v0OQKQ6i3Bno5YypEC+6OdjqjZuEMYDimlBBgKxlpRKUglJ8g4Qzb9QXv1I6Pobj2kmmKDxW+h5mD4MpTcEQHvbzLcmR5ubbWrYGvWv78DQpC/rRjCYvSIkseHWJ5gf++wEL6rP+UinlxNNClYa4hveeCN1UHqhPuIcZgjs5FIur3IAcwvFtNF1D8fqiRGza4ox+peK6sruycD0XA8RUF76fxD4UeYSKHXHTzxdJQt2MSYdC6+cyzzmAoga9L7EAOIXy+1j0wnnS3y22ud1b+viBNJbGzMzIMLAV9T/p7/ygmJZO5vnlKWa33y8/99ZfpuTL695kv7w0+MfZ/6Bw/Q8pNTUhaDspejl8/ZPe171tY32c2L2SgPEgxRR0YyOBV8e3MKZmlD65TiZOr1FwqRT7QEk68nFH+cMZX2SXWvW4k/hhcXo5PklxRxlJefQFazAtHVnPYrP1Ev84Y0M53TIZFRfR6cQbTdF18j6BsyNbl1K2qKKP/xQN0BcYR8k8xoAG7PToktwN8R/Stl+SndmmffkNf4JUuEEiyjReOFdA7DnEv+rPrIOrsJk0kmYOU4MJZVpvZgcObl/G8tS0FdaxKgIVzd6GPU3lXDIaUx5H+WWmZZzTy283H3nbMAQi6p8PLhneuk4LmQA7lsaPnKq9VDKu36ASgdxKSz/svBmh2PI095GPKg0rWuSvwy/UwcVUf0kIeU0W/OAhxO6cEKujlbbOQnvyKvZgkurvPLeAqP37BOV+f3S6R2M80+ipnRn0yux3y8/H0SnFXtgWWSj7bXdMZWkLxWIiXWj3T6Aona7Cq36u6hau9PAaGNigucywBuUZSy7CfBqe3OVfd7qWVoBhcP003hul6A8hb0UcESnsJezZUgZRM+k2gVlq00IwdfXjydHl4g0dJFV2g/6v8EdUMtUI9nOz7FfNnYJZui8 gGEpBBmA RqOlTOqHhcvA69hLyc0mMZ+DkiL4z18zwg6/jlBs0ppV3m2A9h2sLCDhWTdbarl4Ki0/NulmV3msvkwFr0hlnVW8hYkAqrhMbi7rmVRyxWAngWZuoXqhyHPHwveJepnsd2anFfFguWM5GZmn9diG0qp2ZM6a8sAKiCgVYkmWP6vWXNhkgqaDrd47hEKDJb6AKdlS1z9xhXSV4nQpdFnuvnE2TNd+JHHk11vu8F/IbD0gsyJmkX2O+2tpE4w== 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: List-Subscribe: List-Unsubscribe: From: Zhaoyang Huang vmalloc area runs out in our ARM64 system during an erofs test as vm_map_ram failed[1]. By following the debug log, we find that vm_map_ram()->vb_alloc() will allocate new vb->va which corresponding to 4MB vmalloc area as list_for_each_entry_rcu returns immediately when vbq->free->next points to vbq->free. That is to say, 65536 times of page fault after the list's broken will run out of the whole vmalloc area. This should be introduced by one vbq->free->next point to vbq->free which makes list_for_each_entry_rcu can not iterate the list and find the BUG. [1] PID: 1 TASK: ffffff80802b4e00 CPU: 6 COMMAND: "init" #0 [ffffffc08006afe0] __switch_to at ffffffc08111d5cc #1 [ffffffc08006b040] __schedule at ffffffc08111dde0 #2 [ffffffc08006b0a0] schedule at ffffffc08111e294 #3 [ffffffc08006b0d0] schedule_preempt_disabled at ffffffc08111e3f0 #4 [ffffffc08006b140] __mutex_lock at ffffffc08112068c #5 [ffffffc08006b180] __mutex_lock_slowpath at ffffffc08111f8f8 #6 [ffffffc08006b1a0] mutex_lock at ffffffc08111f834 #7 [ffffffc08006b1d0] reclaim_and_purge_vmap_areas at ffffffc0803ebc3c #8 [ffffffc08006b290] alloc_vmap_area at ffffffc0803e83fc #9 [ffffffc08006b300] vm_map_ram at ffffffc0803e78c0 Fixes: fc1e0d980037 ("mm/vmalloc: prevent stale TLBs in fully utilized blocks") Signed-off-by: Zhaoyang Huang --- v2: introduce cpu in vmap_block to record the right CPU number --- --- mm/vmalloc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 22aa63f4ef63..ca962b554fa0 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2458,6 +2458,7 @@ struct vmap_block { struct list_head free_list; struct rcu_head rcu_head; struct list_head purge; + unsigned int cpu; }; /* Queue of free and dirty vmap blocks, for allocation and flushing purposes */ @@ -2574,6 +2575,7 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask) vb->dirty = 0; vb->dirty_min = VMAP_BBMAP_BITS; vb->dirty_max = 0; + vb->cpu = smp_processor_id(); bitmap_set(vb->used_map, 0, (1UL << order)); INIT_LIST_HEAD(&vb->free_list); @@ -2614,9 +2616,10 @@ static void free_vmap_block(struct vmap_block *vb) } static bool purge_fragmented_block(struct vmap_block *vb, - struct vmap_block_queue *vbq, struct list_head *purge_list, - bool force_purge) + struct list_head *purge_list, bool force_purge) { + struct vmap_block_queue *vbq = &per_cpu(vmap_block_queue, vb->cpu); + if (vb->free + vb->dirty != VMAP_BBMAP_BITS || vb->dirty == VMAP_BBMAP_BITS) return false; @@ -2664,7 +2667,7 @@ static void purge_fragmented_blocks(int cpu) continue; spin_lock(&vb->lock); - purge_fragmented_block(vb, vbq, &purge, true); + purge_fragmented_block(vb, &purge, true); spin_unlock(&vb->lock); } rcu_read_unlock(); @@ -2801,7 +2804,7 @@ static void _vm_unmap_aliases(unsigned long start, unsigned long end, int flush) * not purgeable, check whether there is dirty * space to be flushed. */ - if (!purge_fragmented_block(vb, vbq, &purge_list, false) && + if (!purge_fragmented_block(vb, &purge_list, false) && vb->dirty_max && vb->dirty != VMAP_BBMAP_BITS) { unsigned long va_start = vb->va->va_start; unsigned long s, e;