Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1030479lqb; Wed, 29 May 2024 19:52:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbRY4WVrvr0qUQgrZxXA5DtVnp858bop4XJxvwc0H69mqNQtOQp4EXynBpR0Q7HRT5FBiP/8VpSQuixI5m8wWTOD5S4pqRFNsvosuJBw== X-Google-Smtp-Source: AGHT+IGv1ABZnJ20TPtntA9EH0dOxF6fskkCvim8uZ1V2NYmH8mbhY9cae5aAlnZ1X/2wdeYAqTL X-Received: by 2002:a2e:b5db:0:b0:2ea:7f9e:34dd with SMTP id 38308e7fff4ca-2ea8488a73emr2096121fa.47.1717037539080; Wed, 29 May 2024 19:52:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717037539; cv=pass; d=google.com; s=arc-20160816; b=D90/2syr+8SFAgw63OVnVqHQvIXX9tAe1CpRBMnLvtjAx4xkMFR8rNTKKWhuQjNAIS sKx+Ux1QWiMQxqW4iOsznfJJOmYzIpqsHP0wQdfZkox34rBOVpSrbURuGP/BBc4imqzs JF+h0+p2ZLlc2BJ88QGdkIeEmW2NEE++0tN+AWlxg0qKxUzWNNpXT32o4mfy20E7x2vj Ko8+PH2o/i+DFw6nrHje+AsBxx7tALgJfHl2R82gRRmOYUWrvoLK2716DDHanf1C6XP7 806eUzKSBunfC7AvccPLrc6p43ByCUemRaffD94O6Q8eUfhJXS8rb9hnS6Js4VvVntLV 5gkQ== 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=Wx19dqiKdoG1p+jNoool1OawKQICqiQ2zHkkkuus920=; fh=Ru0cW9CAb6Km+rWlQYqxBxS0Q1fkF1G4WQwVE5n+NMw=; b=gXWYor1qhvQk8bRuj6ITnHE0U/lyJKoRCjYmW8ttX+PiSqnyOMtoXBeBkdaGD2ur72 sR4iVz3+0KV6R8DpfrgFmuT91ZSDPj6oMLyGbrgX5ZWwDQFfmWDC/Fee3wb3q6Dl2K0h on9W0p8fxDLJRDuD3TSuoerAOoOqSU3XwWKxrfaySPySrRsZXH9pUTRhb+YCkX4gVsYM UWqw0a3+1rapH9fvouumGb77UGafD/nPGJrE9IeHiI9jpausOwJ9Itfp24GsGhaFi57g Kw8QxH24WaHRRtns8CTg6ZSmTDxMrqphk9wROuDBQz0de5eJJWe2Dg9YrWcbEEY7Gzbw gb/g==; 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-194898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194898-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-578687fe61dsi5582409a12.547.2024.05.29.19.52.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 19:52:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-194898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194898-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A1D5F1F23C30 for ; Thu, 30 May 2024 02:52:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A84B1CF94; Thu, 30 May 2024 02:52:08 +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 315C51B299 for ; Thu, 30 May 2024 02:52:03 +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=1717037528; cv=none; b=I5iujMbCV8Y21/Gdk+SAtJ/Yv5serxV5zWoL78vNEKR1vqiJ2ZJPmHF343kb/KKEdeb7xjjuYA/+aIAAQIjCLpDxMemSbbevUC/CsLNFcUJCQUZ748zM1j9X5LReG9KTusxZ94tNhpttuvPakDRUYl312L6ywob1d3Y5+VIjNIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717037528; c=relaxed/simple; bh=L+VwcrUtOg3D0hw2Yq3XaVTSIIofg97YslyP9RS1e+0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WXzbnbs6O28pLHwB6GgyhfJAnXAv7cz0JGBqgo222qODcMUY7tMduHujlHQTxbgi9bPYpCmKsoeZw2iB8sWwJLuOvZkJrwiC7PPuylvgveTCbokCNDQl2Gxz69JwgD9eiQSNP5qQZZ2rid4WHQBecVGd/eRUeqTYakP4GmSyPkI= 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 44U2poF8033765; Thu, 30 May 2024 10:51:50 +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 4VqVzk0NfKz2Mx64M; Thu, 30 May 2024 10:48:02 +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; Thu, 30 May 2024 10:51:48 +0800 From: "zhaoyang.huang" To: Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Baoquan He , , , Zhaoyang Huang , Subject: [PATCH] mm: fix incorrect vbq reference in purge_fragmented_block Date: Thu, 30 May 2024 10:51:44 +0800 Message-ID: <20240530025144.1570865-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 44U2poF8033765 From: Zhaoyang Huang Broken vbq->free reported on a v6.6 based system which is caused by invalid vbq->lock protect over vbq->free in purge_fragmented_block. This should be introduced by the Fixes below which ignored vbq->lock matter. Fixes: fc1e0d980037 ("mm/vmalloc: prevent stale TLBs in fully utilized blocks") Signed-off-by: Zhaoyang Huang --- mm/vmalloc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 22aa63f4ef63..112b50431725 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2614,9 +2614,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; + if (vb->free + vb->dirty != VMAP_BBMAP_BITS || vb->dirty == VMAP_BBMAP_BITS) return false; @@ -2625,6 +2626,8 @@ static bool purge_fragmented_block(struct vmap_block *vb, if (!(force_purge || vb->free < VMAP_PURGE_THRESHOLD)) return false; + vbq = container_of(addr_to_vb_xa(vb->va->va_start), + struct vmap_block_queue, vmap_blocks); /* prevent further allocs after releasing lock */ WRITE_ONCE(vb->free, 0); /* prevent purging it again */ @@ -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