Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp148533lqh; Thu, 30 May 2024 17:52:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXh8D1gxeJV3WFxQBinPkRwC7CwSx7EjdmhXRdc7515+6R8k8DHff+mppv/ApJDFDIPXZT65pcNWr8pyODrye3qizWG7rOSWXLRSZoM4A== X-Google-Smtp-Source: AGHT+IGYSNyR+pd8aIzL9spQih7Xs9Nb4BXCGRIS5/uMwcnfO4M8QEPK6zTEOuPDccAwOBSWnab3 X-Received: by 2002:a05:6808:2202:b0:3c9:6beb:7832 with SMTP id 5614622812f47-3d1e34a55b4mr520394b6e.27.1717116724674; Thu, 30 May 2024 17:52:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717116724; cv=pass; d=google.com; s=arc-20160816; b=1KzXHha9s6VJ8sb8RPq6ftEl6t7G95Id6j+VNLL5t++ueWtYUmU1NtEre7FX7G2xZm eLcFN4NNCkWNzZzjtX4SYXA6LejF8wGmUYVcmE549drWGg7oC5Gc38RAyn9bq3iOtSgd A74OzV/wFJjGrokZfcZ7rPlgouZZCdshZkUrsBwzysSAIXa/S27PAAw3Qrhca4KC5AlC D22R6oOWvg79MvP9G0aFmrBzV03ZvJNwpX3mK51+HKUAcW5nG1Jy55o1wrN7E9cspQKg x1RhN73qZ/KwTH1HDeHJlUpqrwBELxq2fSBXnFE8fJtKmyeDg9sert/+1uMobXY4GXnR hbWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from; bh=piCqxNTUSkIyTFM6mJXt/V1dBNluOpgh4D6VYilcNfE=; fh=jhil3a7FRkga0QTzFsfEAYwrAVZnRmNgrjY9b9TN0Nc=; b=BygEOtskMBja2aXQwRfgMLPA5o9flgbyPf4MbwdjEEU6kDGIqW7frmvsw6hWep90cq dtSqxjY1BmEyXuMieGSx5lB0rJzJxhaXRavcvspg3HndEZHuml17U2skOqbqwiSaxGca ShoyjZ8qmiz0K4ESkujJ9NvU7vT+YbGAvbgPGT/MyzTLrAfy4OUkmv94R+1YwunvMvhv ofrLC8ohGPj5J4ihGLvdN/UWfL7RLrhGBr5GSgtkDWZFLgtoKYasdCkqP364w4bn5tSt DLEyxsvyjsJmap7TxANi5wbE11U8HdlQpIIjHXz0rAhFnGBhFD8VYJ5Qh8HBmJstqY1E pQ/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-196104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196104-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35d6949b0si519671a12.820.2024.05.30.17.52.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 17:52:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-196104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196104-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AEF62B238C8 for ; Fri, 31 May 2024 00:51:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB8CA211C; Fri, 31 May 2024 00:50:46 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 2DB96F4F1 for ; Fri, 31 May 2024 00:50:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717116646; cv=none; b=kZJmabvfSpvj786UYDkL4EJXOprvtR9lidL1rjJusGi6H+R7yVK93ZMP7wKw8WdTNQNmnC6uchr4L5VXIgx6uFvPbZ2shOmhP4bY5h3qlSfWdA7YUSgIxiE0/CACZ/W2SV/4v2WhobqK3QEofNff/AU+nEBTgr4tFB9/SaNWkzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717116646; c=relaxed/simple; bh=PXP3qouM95Yb/Z4GJB6s+wDC+hU13simptL+d3AX5Oo=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=jJ95ZkQJYJebgtPHo1mg4nN7rX8TwE+Qm0hkiNoz72ihqW/4o4GO6COEj4KtxdZbQHsHmZ5b9Siv/bAIecQQhCJrahv36EWdt3THMINf4elmzKo2qKIDKIYuNFGkz86gwQ+w4kqFmm8znrV5sWkiwTmrqJu/0No/Uzod1jwXVbc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL:SHSQR01.spreadtrum.com 44V0oCZS010395 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; -- 2.25.1