From patchwork Thu May 30 02:51:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13679726 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 2C61DC25B75 for ; Thu, 30 May 2024 02:52:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 756746B0092; Wed, 29 May 2024 22:52:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DF7B6B0096; Wed, 29 May 2024 22:52:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5803D6B0098; Wed, 29 May 2024 22:52:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 369E76B0092 for ; Wed, 29 May 2024 22:52:35 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C95A7140B29 for ; Thu, 30 May 2024 02:52:34 +0000 (UTC) X-FDA: 82173539028.16.E60DBD0 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf25.hostedemail.com (Postfix) with ESMTP id 169ABA0002 for ; Thu, 30 May 2024 02:52:31 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717037553; 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=Wx19dqiKdoG1p+jNoool1OawKQICqiQ2zHkkkuus920=; b=Rtklt54JJwGSV5KBHOguMDcMahL+3iEqauSAkJVTpfbz/ZLcmZUnHuuaJS2+JElSyq90Dw PkLKcreYFY0gQ+HxXgGli/nBucSe3JGf9Ic4bZBcf9NjiLtWeaoapI0YrZzO3lab80DZbb DM6aJkxqD1iC74dABRa2iK1RcqU4GI8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717037553; a=rsa-sha256; cv=none; b=SOo/Wjoahg8ve/1bHcuLhVyrhW8OgTZUteOUrS8EttK6pZczDdLnNkrKe5T2gpS6OqKrEt RJWnSpfeuVavjH4NY9MyHAxGO8Prpt5T9tybpRsTbqL6DxPX9yimq6OdaPjXy7tF9ezc9X nNCj8b6knDsCbMsz+RXAanLEkRdg7uI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=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; dmarc=none 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 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 44U2poF8033765 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 169ABA0002 X-Rspam-User: X-Stat-Signature: w9fj6oy3c9k8fbf8aouzaqdjf7ub84pb X-HE-Tag: 1717037551-221408 X-HE-Meta: U2FsdGVkX1+EVjPdyYF9MdAjZh2lnpGHtp/zfXSiwCvcZf8JYoz6ERWjfNiRX5fJ0xyPSbSb81PoUyn0W9RqT8a7xui1Br4DiNp5BVn0on9N9yMuxrJCyg8LNThwyr5wOPd3yJ7I6SebeR0oHPSgLgdnhXbq/dwRTKVw10+jT5aGIezAXG2HhmbUtfKZ1CgfplQ7J8kHyucJ+vZhffPYP759UB3ksLHbMKVk9YaGTAY4cZrnfLjF4+0V66lHoaE139AXk1sK1MXI8HTR5RvyM9eSzjlqq2U81167ghCTSbeaSAnbPei+I20jVnQ8MQnRBCkH1iPWGDASZeqXtsax4WNSjsPkZTeVyeXb8etHWMIAo6xlK9webcnFHP8MXitOEur1FqZj7PwxfN8H9byJGCWS36RRA5PDsuGEF0sJ18CiuSZbGJiHCEyx1GJjApT6bwjIB59x3iTyxiNv6Pphx2SnF7jgipRowYgQra28D12Ad76JX+27dUzkWNvn42Ccj/qk+cDvVGo/8Xal4j4Vva/Zga40Z1Bj3eDf4yOfXjxNCIDXgdewpR2xTZ9drpcfwZo11/ilwD3uRDuxAa6vM2FHNbhBZU18wcnPYjv286VffW4DgiL2d0dj2+/LOwCOJEz3EiEtxU1Jky5+za0/SZafEnwtPpCa74rCWDflYtrH5m93bZy5cJ2Apfclez7C+y/7c4f8itlNXe6rZIuycWsWrJVVzqT4r/7Nh0nyEkrANrpwUAvmCsezrIGzg2wueb6gUHU/nmsB+s8wF0MblGJF8C1L0de3xtPP/OBNZBc7lSFZKUHIjgDwlgGu+mo9ahcSy3vxMV5JsIMbwgsToodTBGJFU3y0XK4OYzMjAcfYeyJuRQaU3Qt6vDzinzclFLuUT+j81+Gytc9GhuuuggQ1hvIBmDk0iF2FOod1h1ndgmBzAcZnpSHZjw4gq3JrwmvYAslj78aub+OZQXJ 2vi+7ksv nQ8+eGq+kxhF5Vr68yYD7Exh0I97niNiEKG7/16E8zyjzwvWKTtJ3eKwFVQ6qDmghOTtppc7jWQC61Cv23SX9BVrG0j57/42bIP5nB12+6J2NLUpelqvHUxnqNb1x8+CxBCrJOFUhhySZyjWbm6afSQ5sfD4QSY6YPZdIJu9pecpy5id9s26zed4NjeLExG9+91zVjypMYQuWkSxYNmai1elhhD/ZrxyLBHl4sUI/GuiTNzk= 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 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;