From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796145593; b=tfZHwZiwosu7RWzrQcExjDKnVhE4FJWHlvxLqun2VUs8XSXaPLTWXQRxc1Rj5uVgWbiC xCEd1HtfXXgai0eIFh5ZIdc8VhQxud1+ZkMVbtuehj+Y5VZ+wVcH6BQIsn4TjZ0Id6uqE H7DyXSqMyBudtCB0T6cLSszrIZWkwpF0PCBPPZqmD5V6bv1Z4yQwobUi9Kw95CiPzh7Gb K+lVh/jVR0cQIn7Ka2QInBYzmQbTRzHv9BcJRpn8yYCtVTq5Xr4KMScd3CM659+0JrJj2 +BJUzyWgWOkDYaQnEYUD6gw7E8LWMMKCVKDiWYGVZ4XyZ+umowXqR+JYNMMEXru6L9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796145593; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=mQG/IRL+JHT2MPd42PoA2OCzMEtJIt70GY5hJZYKc0BKcYuebd3dhEeTrqxHHKKBR0An Uz9wJleTro6ikdaozYQFErdCL8uBgHzCzOCVJVhrGtDdmsmp7InpLMePp+J8uwiH4+r10 LpMHlsS9DA+GocJRKVKO749sR4loMX5d/Y4fLXe5xl9r4AgJZpJfDmjJLCX0UcJK8EmGM vzl4/HgDGH6cZYBwH2mAJMxTmDI4rfwEQrJv9xcUbsbDWChnBqaiyy+djba82bX8whl6r hqe8cHCyHJ8G+LCj8gfTD5w/wmfPVt8SoEW2llTauwA4+6/xhl5wH9mu/lj6p0TPoGw== 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.170 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 F312A606A33A for ; Tue, 1 Dec 2026 17:19:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F312A606A33A 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-f170.google.com with SMTP id d2e1a72fcca58-8a594d313a3so7855618b3a.1 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=jzIexw15cs/VDJSxf18OQdZutS1HuyH/uFtIHMkx6S32EOmlqssfdeSFkd9SWb7NUk yrgwVsN6wGTG7Q+di/NBQtuBdBxbEJG18S/S0ggLY5lKPHQGZ8NHp5x+CB+uN/kVAPbJ uic2Y9YQbdNuuioW2RwXaEQhnio48Mr7iG2E6uXm/P40HEDO87XgfzPFawlJm9N/71m1 ufEEeUKQ1E8srUbRqXWg1f03J5aZomwlBThnB1jt2LWbovZCx+e88YNEwulagVdefeBx yKEpwkJ6y2AB78lYVkMMe6orwcPkqlmILAIaa6poaLO3Tqx9X/oWkBovLbfcctF1RRUY 3fuw== X-Forwarded-Encrypted: i=1; AL+hErGI4N5l0T6CEgUliCahY+VMVKkvjYq21ekwAUFEAoyLgk09ip6xNx3/1PN29YfqjM5qV5Lqz80=@vger.kernel.org X-Gm-Message-State: APuU4Z+FE5xdlHMZgURSZd9vFh8cTc/MUU1oBM4uNYwBudJ0nML7tvz6 XZ1yOBSoXdca+m8nC6NufmGlAaQLEgYkWcmMCGkv0BwLjd+fDDmDHX6y X-Gm-Gg: AZFdTZfaUhqVluu8koX0in6DKJ1FEO+vYAcR2lebmTjTj1FWr4/TVj4yf/7nq5YWIe2 d6UQGgg/wHN4ozzgWa6oiYphPT/2/1JS49X/xsxOVY7EniuF2e4otspF0evD1DjzZ4y08VTvhKP Jb748kZuFg0OvtcxPjCbx0awVoUzusXRI+IO2EPGMzmwsICyYI3AGsYAN5pJ0IEAJ3tRAsgVd85 zF4v/iooUHgOvdsXUUibAbZVOBs/TUTj8XPu3ryQ15tt8L58mtFPPxDOqseMN7hZfYSUU8eEWa7 mjKSbk5723S6RMIl515T/65N2NQoBa44mk37YWXB3yvHaB2xH2C1hbdLY5th9B7SnvZgsnAzeBK cx91qzJTNPGBTU57O/89MrEatuhU7FtbD0ndFsX00nYAHfJkC5XRNQbNJK8ENU8VUo6LWSjAjT9 OeLh79xh581A0dCQMB/e7GysbMDW+capaPUb4XANmWsQd+oyFaYmZLuzFhDeOkYb+nznrCyvjDW GeMNNbpJZ1BjJTppurW5/8ir7lldQMiv85n8SkdPl6xu/+UGkrkUYQ2u+PMCjsHSrYsoCpcuUFd zlJkBqyfiFJ4jA2HRRro1gwmb4lWErMREkWIPxBgckaO7KuM24QGV7pUNFSDQcuwgMqA1WV6xxv swlNM3uV7ttW9P8J4DHXWTxkO5yew+Dvdr/4Q+JdddxNsXA== 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: stable@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