From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (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 5A2F02C325C for ; Fri, 19 Jun 2026 08:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781858054; cv=none; b=jLivU0mo4xCb5LQ+THaibcju7VKYh8XjHtkZoD4aekmTkh3YaFX2eQzPue8QSXNWJnhV5svhGbkV4aV0T+ugcFqSlxtBsylmbfcUIRf+KqEXxTRf8Lg019PywvQ0kvXLZv5kep5hxczc27HmmE5ZbuHFY5r8sTmLbvPy14hxdUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781858054; c=relaxed/simple; bh=oDdfQq+2RWZfRVCbhl8jsrlZ6HGBAbyeRb1sunGI77E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XK8gxfXiysRF98FWh9qXt+e1mSEEcTGXRfwNmWyt2cuxXmVvZwJIYUVYtjzLirbVvS3u7DaKXxEmtaYjn9iB5PZr6noayfAmQxspxQO2UkUBBVHwn3v//qrh8TToILzrUEE5RpbLYJQBTsux0tKId3OyONULPyOtcGRvizVfo7g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=TaKgJS0v; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="TaKgJS0v" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1781858049; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=JpqedkrDdgoz3/52vJ+BbHyq7NbFH+iEvNMFiuwcoTs=; b=TaKgJS0vFrNVTJLj7PQwVZ6T0LrhhtQS7gdt0xiJ38QlBR7ssAfYoIEuwLc3IUW2jZ/rkZtsyuBcS+ART/CHYo88Vwsla8TYH/IYIZL32oB1rzmlxweaHszHBkYuN9DEzhuc5hm9GOmr44PfIBEAZJo7fnmdA9PsMLBOHfdgEfQ= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0X59MGOl_1781858044; Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0X59MGOl_1781858044 cluster:ay36) by smtp.aliyun-inc.com; Fri, 19 Jun 2026 16:34:08 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , oliver.yang@linux.alibaba.com, Gao Xiang Subject: [PATCH] erofs: simplify RCU read critical sections Date: Fri, 19 Jun 2026 16:34:03 +0800 Message-ID: <20260619083403.3993627-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit - use scoped_guard() for RCU read critical section in z_erofs_decompress_kickoff(); - simplify the RCU critical section loop in z_erofs_pcluster_begin(). Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index c6240dccbb0f..1c65b741b288 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -806,6 +806,7 @@ static int z_erofs_pcluster_begin(struct z_erofs_frontend *fe) struct super_block *sb = fe->inode->i_sb; struct z_erofs_pcluster *pcl = NULL; void *ptr = NULL; + bool needretry; int ret; DBG_BUGON(fe->pcl); @@ -825,19 +826,16 @@ static int z_erofs_pcluster_begin(struct z_erofs_frontend *fe) } ptr = map->buf.page; } else { - while (1) { + do { rcu_read_lock(); pcl = xa_load(&EROFS_SB(sb)->managed_pslots, map->m_pa); - if (!pcl || z_erofs_get_pcluster(pcl)) { - DBG_BUGON(pcl && map->m_pa != pcl->pos); - rcu_read_unlock(); - break; - } + needretry = pcl && !z_erofs_get_pcluster(pcl); rcu_read_unlock(); - } + } while (needretry); } if (pcl) { + DBG_BUGON(map->m_pa != pcl->pos); fe->pcl = pcl; ret = -EEXIST; } else { @@ -1459,21 +1457,19 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io, if (sbi->sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO) sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON; #ifdef CONFIG_EROFS_FS_PCPU_KTHREAD - struct kthread_worker *worker; + scoped_guard(rcu) { + struct kthread_worker *worker; - rcu_read_lock(); - worker = rcu_dereference( + worker = rcu_dereference( z_erofs_pcpu_workers[raw_smp_processor_id()]); - if (!worker) { - INIT_WORK(&io->u.work, z_erofs_decompressqueue_work); - queue_work(z_erofs_workqueue, &io->u.work); - } else { - kthread_queue_work(worker, &io->u.kthread_work); + if (worker) { + kthread_queue_work(worker, &io->u.kthread_work); + return; + } } - rcu_read_unlock(); -#else - queue_work(z_erofs_workqueue, &io->u.work); + INIT_WORK(&io->u.work, z_erofs_decompressqueue_work); #endif + queue_work(z_erofs_workqueue, &io->u.work); return; } gfp_flag = memalloc_noio_save(); -- 2.43.5