Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2211591lqo; Sun, 19 May 2024 20:10:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVbsW8u6egMJDnvVqD66jwP9P/+cr2NZ5f7jIxt/oIectdcSsuIV5FDnuUJor/ha0D8N5K26LOVZm6H98TklIH01cN6STJfjk5jhRtaw== X-Google-Smtp-Source: AGHT+IGYW8fXq+50JWwztwOtek6tyM3cKET4KESiqKVCY8vD2M9BDo0KhRvA+1irRaqLwvvkpPAB X-Received: by 2002:a05:6122:252a:b0:4df:19c0:86e1 with SMTP id 71dfb90a1353d-4df88367ddbmr25916764e0c.13.1716174632448; Sun, 19 May 2024 20:10:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716174632; cv=pass; d=google.com; s=arc-20160816; b=jWSGWbuwYq5GVvCPT5GQIZn+/uozHcBlpbaD+d9/wMja1XMG1tsbLKH2+vYgMxGkr6 rqgDdgBahV7R0tJQ1svjCadGWo8zH/5tTzP6Hcw4YQHFxum1HYJfwZPsGPJ/atStBhza ZpGIJAOuDlHtr7lKfOMQQP0Ph3Wm64N0Q4slOEclTXUwm0CBY7PK0TasbjnLpU3TPeOf WP1HJ3bsdo8pYRLAB2GpuSiwnn7D+l3ZWLilqGkKF0HFddoDoOuZIQpZGZQxljR5pFpZ I+40tY+tQO0xnKk2tSLMnaFC7Ncc6mbFp6AbEgLx0ANeNh+q3zjITGSHMfcAUoduJ+fI qUPQ== 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:cc:to :from:dkim-signature; bh=ZVgUzdTRON7x3qceRHjQMiQNT1s+DpVTz0XvEqqtJsY=; fh=tK77jzFMeLU2SbzvgjXfdZ+k5Lzt1e/vUZ8P13f0zNU=; b=S4Ifq29tIbb8CsaWTphH3amKZMksMJ3wFAlW6rs6fSoIyRVe/iaSfMFjKI7G8ZyRdO fmDzJzfzRWib6NEhVhR61/6/feaSThB3mVwzyiIgSLKFzai+1GbPHZDhtSf+6QQgfUh4 2fdDCjqigNhucefTlxx7M4bkDLHWKOpZ5sLueoSQ5PAdWY6kVJQCGqFFtCAEKFD7Pi7B FVnOG3aFEgen7Xxplu6xFPdTIdYcEB+48MWbHIgRbdwUj9Js3fqLbS3mTZeHp+wiXQAG yHb9c89B7ict+Y/iyw0pJpOajT1uj7YmzznQpMvFQUsTcU8cUCdWmtlEDp3uGwTZL+4Y qDEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iDGxVKOz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-183373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df549ca22si29126651cf.157.2024.05.19.20.10.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 20:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iDGxVKOz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-183373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3205A1C21826 for ; Mon, 20 May 2024 03:10:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47278D2FE; Mon, 20 May 2024 03:10:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iDGxVKOz" Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ED014A33; Mon, 20 May 2024 03:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716174625; cv=none; b=AoiYOJ+S+k2Vu1LE7yFkRLNk1V1mWfjJKif5/BYKZW3A9zzHWBGH54PDbZf7WVtc1iO6s8DE2k2RvCwb9Vio47i8Y4/yw3qt6lju+bzrLQFZ2olafRwXfICbFyeK+E+HlFhXYWZ7I79d4JPzU7s51TLzzW7p/94flMnyowfCTuM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716174625; c=relaxed/simple; bh=4WqhMvI3Pf3B3fMZIlMXwBxz5QbKYJjAVHBs1SLNECg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MO7bGXANqqA5LibOyZmKaD0YyW3wxROPjMYg/YirYK2rlLgqzOdaGpJPZbqjAbaJISIMo746CF50IKjF9QvvWcGQGxf7OPWNvw5HDS+umL7yQIuRoS+Eo47NcahkPc+Pmy/T01IiNOHgTosFnQFXV602zoZdmvb4Exjp3k3HWXE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iDGxVKOz; arc=none smtp.client-ip=209.85.167.181 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 Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3c996526c69so1612657b6e.1; Sun, 19 May 2024 20:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716174623; x=1716779423; 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; bh=ZVgUzdTRON7x3qceRHjQMiQNT1s+DpVTz0XvEqqtJsY=; b=iDGxVKOzt6mOUEaXu3Ng8R7MIPOVxiRAxwcpVrI5V2n5s1MfM1idawAKLYifyUWMkV JPCUvWj42NhJWd1BYR7GuHM0JVB50yR3qk5+R06MQ76rE90pUJYtX6LojO+VR09G9W06 t23wp8bHrwFYwkIot2IbsRFKw8rCp7yqmEovcpj+K1CE3l6HuDyDqNhyogrJvSTrmvgI iVM6yGqSlb2NNMcYu+70fCH34LfsrtlYL5Fpgp8gRn8CVByPHnPrjbLsmNuJ1O+zq+rt wcGV7eT6SnFkwol+mHVrlUus4c/8DjRfUqrL336oh9q6UAu4v0WgwDAi9meu7YiwxOPN 6y0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716174623; x=1716779423; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZVgUzdTRON7x3qceRHjQMiQNT1s+DpVTz0XvEqqtJsY=; b=CvNnwOIdW8LlxsUjFcVPkLY2y4+4903xNSp+hpQCGQn0aIP/OWCIt1Lw/9/kCH6y7Y /lSCuDD0LRCLnR+s1fnZmd3vlZClSj9pk76fFI1cWFNnxEZKqKqZh5ZhDSsPBhGVgrah emKN1inr5JjesaJBlEBbm3/xXC92sj9QYSlSKhCotevz0ua3hkHvgwEijXQD3JEooZ3m QL/x2EBUlSKc6vX/gnqfykdRGmQdhDKeDXMlC+eZD21WhHdgu/EolrqiQHVMAQaVYvz8 6Yd1dC/5VWuWMdxATY+iHU6tl6YGOyYT6kXNbMcppNZjjqsK+D39vRac9xy7X874Ntnm 2Yww== X-Forwarded-Encrypted: i=1; AJvYcCXQl0eQdXphrWS9OhOV5ExIJuo0ZtTCRwmis3+M47F9r5ivyetS8BBRLokF7bQ/eIKZ2UZr/mYatcjh6/SqqKEWzVgJFINBy4ObTgDIOzRfk5Nge31RW65OPplzdSUf0dq0bVcE/jWZu+kaPJ8= X-Gm-Message-State: AOJu0Yz6Hn3dlWIPAsFo+TfrAehybSG9ibfjCLdfSDx4dkLyq6RnjgcN 9usDgHJUXSgSRBpo1hi33DGgF5j+Bz8aY4AfIun4w8bp5r1prZm+ X-Received: by 2002:a05:6808:2188:b0:3c9:93f1:c7b0 with SMTP id 5614622812f47-3c99705587fmr35557515b6e.20.1716174623126; Sun, 19 May 2024 20:10:23 -0700 (PDT) Received: from localhost.localdomain ([190.196.103.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4f2cdedb7sm14541111b3a.52.2024.05.19.20.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 20:10:22 -0700 (PDT) From: Camila Alvarez To: Kent Overstreet Cc: Brian Foster , linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org, Camila Alvarez , syzbot+10b936c5eaee2819b49b@syzkaller.appspotmail.com Subject: [PATCH v2] bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start() Date: Sun, 19 May 2024 22:57:34 -0400 Message-Id: <20240520025733.688425-1-cam.alvarez.i@gmail.com> X-Mailer: git-send-email 2.34.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 Values were left as the next possible sequence number when there were no entries. The fix involves updating the last_seq initial value and setting last_empty_seq to cur_seq - 1. Reported-by: syzbot+10b936c5eaee2819b49b@syzkaller.appspotmail.com Signed-off-by: Camila Alvarez --- Changes in v2: - Introduce a new variable to distinguish the last sequence number, from the last written sequence number - Abstract `cur_seq - 1` into a variable named `last_seq` - Reference to the last sequence number are changed from `cur_seq - 1` to `last_seq` --- fs/bcachefs/journal.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index adec8e1ea73e..99fc32f0382d 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -1195,8 +1195,8 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) struct journal_entry_pin_list *p; struct journal_replay *i, **_i; struct genradix_iter iter; - bool had_entries = false; - u64 last_seq = cur_seq, nr, seq; + bool had_entries = false; + u64 last_written_seq = cur_seq - 1, last_seq = cur_seq - 1, nr, seq; genradix_for_each_reverse(&c->journal_entries, iter, _i) { i = *_i; @@ -1204,11 +1204,11 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) if (journal_replay_ignore(i)) continue; - last_seq = le64_to_cpu(i->j.last_seq); + last_written_seq = le64_to_cpu(i->j.last_seq); break; } - nr = cur_seq - last_seq; + nr = cur_seq - last_written_seq; if (nr + 1 > j->pin.size) { free_fifo(&j->pin); @@ -1219,14 +1219,14 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) } } - j->replay_journal_seq = last_seq; + j->replay_journal_seq = last_written_seq; j->replay_journal_seq_end = cur_seq; - j->last_seq_ondisk = last_seq; - j->flushed_seq_ondisk = cur_seq - 1; - j->seq_ondisk = cur_seq - 1; - j->pin.front = last_seq; + j->last_seq_ondisk = last_written_seq; + j->flushed_seq_ondisk = last_seq; + j->seq_ondisk = last_seq; + j->pin.front = last_written_seq; j->pin.back = cur_seq; - atomic64_set(&j->seq, cur_seq - 1); + atomic64_set(&j->seq, last_seq); fifo_for_each_entry_ptr(p, &j->pin, seq) journal_pin_list_init(p, 1); @@ -1256,7 +1256,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) } if (!had_entries) - j->last_empty_seq = cur_seq; + j->last_empty_seq = last_seq; spin_lock(&j->lock); -- 2.34.1