From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796145592; b=TUm1IxMFiOW4f1/55xBXd5+rTGgwWFd8eRT+Q8QQa5Lsv7RZbllyHHparDYZowTnDxGi UF0CsYS4h7feQ9wndbgppdsp70m27cM+oqhIAH5/HRpoLo2UPLKWPGvOq+ipRXNGzcpDy OLtUyMcWliHbjPOU1NbN16JxRl9BczjGDNbo+yH3+RRCsct8i5nSSzjNm7YqvJAv2qVvr 9XM89L8LtS3lI4uCTeNtYK24aIT1321+0rjCrFJQoKWTUGJGfSsd2JKWflx06eIc5zgIC cqSUo110DtjrKZXNW4V8YRWFroemUBcU36SDa9JzQrGZAmdCnYvRW4WE90Bi9rVB4bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796145592; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=EF8TOZnjbL9ADZVaJHa0DGDJTCqP3o1X01NyHaKGR7w=; b=NuBFmkQN/DNyEDhIHjalwSLjzhGWagoofLVNubLRk+L1jCK8ZdrCA4bCjIUsxikeOTS4 ZXNFTqSI/hPidYGgQFkZnzEiMsY1WAEuJ4KlQNuOqylSl0F/39VhjYgS6shn4rILnYkV+ 7Z1KlARYpWd3N3FI68zU/N+KY6X2bf8ThGB5/n+qeL0XbvZg2YVAKPoWQY07pdRk+uHOo hzLsQ7VtXQdx3l+GRNNvPxIQT79tBM7iLCneIrvGgWlrhD6vh1YS2HlnxegrxhjbDDEfw +vYmLlEuFdyYrRYk4BQ8VAW89Bi+T8g4i1XQafoKuG8L5GBjQ4+caJ3dVGzZByiU9yQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZRJrsASI; arc=none smtp.remote-ip=209.85.210.179 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E527B606A339 for ; Tue, 1 Dec 2026 17:19:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E527B606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZRJrsASI Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8a052aff9e9so8589459b3a.0 for ; Tue, 01 Dec 2026 09:19:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796145591; x=1796750391; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=EF8TOZnjbL9ADZVaJHa0DGDJTCqP3o1X01NyHaKGR7w=; b=ZRJrsASIPVC0B37Ty4FTKrOaeTCO1PHYvRwBx26mvK4K1u9euDLTLqZb0SvymRTCqR ej4cr/IF/3InP9meGVlqc6jFgQTgqX2pVYUCRW9yxO+8ReMf3U8d6lSbbQKRyrLfeA6B qD6W5lf7G73VqYJNuHP5DSObCJF8TGH0GxH0cCRFDZgcr03Ste46mJEahVCnbCReLdci cXQHfCQYw4w8yfs+MfFpBPw7EweqNmTOVcAyZucGL8ZPtzoBdWMQM4c6s6ccIlmsGQx5 OGa6s5XSQ0AqtCaPIP5zSveI8eljtKaIPGfNU2IYOObk+6/4oBtdY+fazE9dnbOt4Ltp wGzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796145591; x=1796750391; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EF8TOZnjbL9ADZVaJHa0DGDJTCqP3o1X01NyHaKGR7w=; b=MLpCdXJlf6ODJnTmhtaRbB1aFrr/g1kjQMz7tG6pT8gcE9YsUY3QoRp4t5BoWfak3M IRB/+6a6TzJG/NGp2VLSN2XVqLIGrCZNX8xsO4H9X4zLq866YTkj/YZwtuvRPX9bwWsK zbpRlDK4THaqJgB3hwLYa7bEwWTCsYhhYrMyPjl4a+tw4Y2nX+b3nzdxzz89EpaL5d7q w99yTlx6S9iiLFhFN4tUEoBdTu+qKGO/IUox+UvyFv1SAv/IltVVXHYwEMJGgy9tFeYg GWZPmAbqVH2AH3SiiMCzQJcn5mc9n3IckjlFPu39dtdgoPzn/szl7/Fa4ZUZq8Rb6n+6 gxWg== X-Gm-Message-State: APuU4Z9316hDnSpQoQ85X9+HovYEKRjutvDS893qiVXPH52+fkCVLCLG qjfA50Ejrbb5dgEbsYTeyOwd3F3HqwQw+3O4eWpIqTEsuxNB6XBNiHLt8AEf/Q== X-Gm-Gg: AZFdTZf3n43SPbsZ0CC27Y2UZnj6Rr8eMz81aqQOVSVn/0uJ6gNectuJi4/ldI7osLr cg4R1PBbJ2UnlrHFm8HxAuaCzDqRCWGut1+9ksVA0Xx3l0QSzx1AQ9hF66U91jrTjCbX4OVwJkE dDBWQo31duxnoQSVc6SCYlJMFoc+iRPIiGrGw5sprFd54ftavF7NjCC66VlWN6rzEegqYT04Qkn FN7f5fUs9rXVg3rnEILL9o9gckvteiueX7hD1VDo3qivn/97JLF+pzMvfRj1B1ZmGmhB2JSeYMV OKMX/Kk8Eoe3oHpHeZg0tCHlg1GY06WblRPLIi1e9N2z9Jin5iLHEdW9VOBiCMhAa6tksnSLtYi JEd7tNS/RA+/7cmXrn6IRIX/BE7AohNYLWuauQrtnrqglKCRpp7GL2m0tCef9S+ZZcM/LxrjfOT u/KW6RMqx8BerodfoQwKkQKBGAo8Pulc9XXcLwdmJVGmq2qcEy5eOiK6NRegZVgi5Q+1gmY14Dl zzgK0ksR02u3azwpkokTz9J5eGEx4rZ14PL/U+bns92f7FM8BthmjQmg2exPpiRf7bRmCxtyL1Z osxF/+66nlSXsQl6ZBzy6jzzOlbDyEUnv833nqBnUOuU2rE5rlLEUYbFfATcRTKwMkGV9Dyu3bp j9XFhGV1iCQZZ8+GoqR5dYcWbc6NN5xsyb1s+Raty1iKpiw== X-Received: by 2002:a05:6a00:17a3:b0:8bb:1b05:dd39 with SMTP id d2e1a72fcca58-8c87bdb43aemr38184069b3a.11.1796145590953; Tue, 01 Dec 2026 09:19:50 -0800 (PST) Received: from f2fs-test.c.googlers.com.com (193.67.125.34.bc.googleusercontent.com. [34.125.67.193]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87420be40sm19997191b3a.57.2026.12.01.09.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 09:19:50 -0800 (PST) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong , stable@vger.kernel.org, Chao Yu Subject: [PATCH v2] f2fs: cover the checkpoint of device aliasing ioctls with gc_lock Date: Tue, 1 Dec 2026 09:19:44 -0800 Message-ID: <20261201171944.3919669-1-daeho43@gmail.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Daeho Jeong f2fs_ioc_reserve_dev_alias() and f2fs_ioc_release_dev_alias() write the checkpoint at their end after they released gc_lock. All the other callers of f2fs_write_checkpoint() on a mounted filesystem hold gc_lock, so only these two checkpoints can run while another task holds gc_lock. f2fs_ioc_reserve_dev_alias() is such a task: it moves the cursegs out of the range of the alias device with gc_lock held, before it takes f2fs_lock_op(). do_checkpoint() copies the positions of the cursegs into the checkpoint first and writes their summaries later. If the checkpoint of another alias ioctl is in progress and a curseg is moved in between, the checkpoint does not match it. Hold gc_lock for the checkpoint in both ioctls, as the other callers do. Test: two alias files, with a debug patch which makes do_checkpoint() of the release ioctl sleep after it copied the curseg positions. A reserve ioctl on the other alias file moved the warm data curseg during that sleep, and the checkpoint recorded the segment the curseg had left. With this patch, the reserve ioctl waits for the checkpoint and moves the curseg after it. Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device aliasing") Cc: stable@vger.kernel.org Suggested-by: Chao Yu Signed-off-by: Daeho Jeong --- v2: - cover the checkpoint of the two ioctls with gc_lock instead of taking f2fs_lock_op() before the cursegs are moved, as Chao suggested. With gc_lock held for every checkpoint, the cursegs cannot be moved during a checkpoint, so the change of v1 is not needed. - v1 was "f2fs: block checkpoint before moving cursegs for device aliasing", which is in dev-test. This one is based on dev and replaces it. With the same debug patch, F2FS_IOC_GARBAGE_COLLECT started f2fs_gc() during the checkpoint of the release ioctl with v1, and waits for the checkpoint with v2. v1: https://lore.kernel.org/linux-f2fs-devel/20261116000019.2299222-1-daeho43@gmail.com/ fs/f2fs/file.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c80dbbe76f8f..4f6e6d611642 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4160,7 +4160,12 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp) inode_unlock(inode); mnt_drop_write_file(filp); - return f2fs_write_checkpoint(sbi, &cpc); + /* Hold gc_lock for the checkpoint, as the other callers do. */ + f2fs_down_write_trace(&sbi->gc_lock, &glc); + err = f2fs_write_checkpoint(sbi, &cpc); + f2fs_up_write_trace(&sbi->gc_lock, &glc); + + return err; out_gc_unlock: spin_lock(&sbi->stat_lock); @@ -4250,7 +4255,12 @@ static int f2fs_ioc_release_dev_alias(struct file *filp) inode_unlock(inode); mnt_drop_write_file(filp); - return f2fs_write_checkpoint(sbi, &cpc); + /* Hold gc_lock for the checkpoint, as the other callers do. */ + f2fs_down_write_trace(&sbi->gc_lock, &glc); + err = f2fs_write_checkpoint(sbi, &cpc); + f2fs_up_write_trace(&sbi->gc_lock, &glc); + + return err; out_inode_unlock: inode_unlock(inode); -- 2.56.1.839.g22a8290db9-goog