From nobody Mon Feb 9 14:31:15 2026 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (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 98C8628726D for ; Mon, 26 Jan 2026 02:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769394469; cv=none; b=bp/KByLn3WtiJ3KNpQmqN0q0FAge/TN5CbPufTfFtAgY28SyElktfAzLnCIrjQshnD7/DlNeZCFWP+B4kNkT8EsvgUzenFEK52Y8Dx0Lu91p+taJIiK87Zv+AyjdRYqtpXQpDC6TK+JBzRjWh+97KU7V0Ga3wVvUiEFro0VRz9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769394469; c=relaxed/simple; bh=elLdawZdiNF3T78K+DA6DMPmbUn63JQVKocXOMorMwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSxX+uhRZ82i80mew0xweaD7dsegc41sxjVwW3oWEtD9yodVLcYxZ4578HwhI+ljPkiZBVZmZ0E+ERkJq0WAXxcS58iYVICBIElBMeau1dAXUi3cOfKYZUgHYXBG7lnoEaMoQrjvlu2qO3hEPjuzxlybwF0W3gbWd/Y/hadOqFk= 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=KSPmH/sM; arc=none smtp.client-ip=74.125.82.45 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.b="KSPmH/sM" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-12448c4d404so3978371c88.1 for ; Sun, 25 Jan 2026 18:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769394468; x=1769999268; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yuyRS9NwFd3elvIRvYUasvxQvQ9+X8/Y2dmyuDNlfJI=; b=KSPmH/sMAr/HOFG43/OysDUyiVMiYdgbkVnXZKOPH8d7a0c13eW8OeQ70FZe7+lnPE X2xVsgTqrz0QWmhQj6gMRK8ipTh2v8zbBEhvDtL3m6b8uQKmR0qEAApsq4CY9UMwEyW6 McNXdbzayMYeR0mVKUS7vQZvv8DENwON3kwbgQjKHrANXFDwLSKg26Ydl/vWvsJA6gbG wYwjbK3ikxsUbDtop2i/EWSpwLCjbk70Wy+lrxEqaTC6wbzTAwZs43fQWgN+xyIDqiuh YXBNhSm7RjQcrsxwArChGWdarK2rTRVb+0aLh49p5/gmqYmnM8KCZZ7ZzHhp/6VuS9Vz L1rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769394468; x=1769999268; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yuyRS9NwFd3elvIRvYUasvxQvQ9+X8/Y2dmyuDNlfJI=; b=jp99vEEGS3CB5lUreo9idKDZcGXx2Gl1h1pLN77Tw+tY7Z366sL2SLJZirlgBu96F3 AYDvfYsk5RFHkWUKtv8VBqC7HXbUa1yQcE97hfsUFK2iQpjvGjXgzFNxSb9ejz8hz4Fv yxxHB/eFrLU300AlKFEggTwW4RmZYdIK7BTDPa+LTfAxvnrxywUHBiSRGbQwuOoXAHrD FLiiCQMPCouY6SNkZtfvR551ml+45fBNcehelKS4QvDuIWH9fDF081+rMZSUmnYGxU/v OA4gZzoLauzFgeSnUC4LWxPZR0NfFLXhgGDMtykZ9qLxgxvqa5OQbQVh6u+6odgS+LhV U5Lg== X-Forwarded-Encrypted: i=1; AJvYcCXp3b9K2CAAl6rgeMUfMKRwDpUcTJSmlp8kmdPFwFusw25MozaI3kGc2rtPNO4J8+5Bbz6Yw+gCKVCePCM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/TAKJ/mjY3PNIhTyPrISprRKIdwnWLVzVy7OYARQO/uBqORxa 9ksWlpua3PDgM27o+tmEAPqlakN5L3EDJI437Gzq9sh+mRrXs3tsWB5w X-Gm-Gg: AZuq6aKAJLUnopIQpOKPZwO3h6vsm3zmmEnF5EUq1s60/EsozVcQDypZP/ravJYpqPI zsSBSeUc+9FmLnv4hNjoIgzo2sPpIsoy4Fnl3cBB/LnUYjpKVHIDi9xfAbhMG4A3AtsOkTDFQw4 CxS8IyIVgi+QBJGPkJaSxMN6W/uEHJRs7BEYJEQxY0n66Whx1OjUIBsr11AeTGO/ApEeO6uLKHT atlY3X9LD31A4sAV9g+yN8KYubvtb8kbyqBJaNnQsbbuBkiF44NE0UBnpJJRchsmNuppsckIKmb BLvL5FUpCYk4uIKZ2EFFJEFpjdjeXnn+EMHPJxCX54qffFeDuxvtVipn+NMrFetQwAUN4J7X3O9 Z+bdf+e2OcvTkknxoCAePY9MCwRFhM1Qx8HDDk2aj116VzQuu3umtikes8fuzmyid6zsUH1T4/Y al4Wa/XZbIOupaqVnuTUhuNvaJXIx8JmLWbGnsbgMgzyg7amPY1aDa X-Received: by 2002:a05:7022:497:b0:11d:f44c:ad97 with SMTP id a92af1059eb24-1248ec6916cmr1706255c88.24.1769394467722; Sun, 25 Jan 2026 18:27:47 -0800 (PST) Received: from luna.turtle.lan (static-23-234-93-211.cust.tzulo.com. [23.234.93.211]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1247d90cda6sm15266037c88.1.2026.01.25.18.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 18:27:47 -0800 (PST) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Xiubo Li , Ilya Dryomov Cc: Viacheslav Dubeyko , Christian Brauner , Milind Changire , Jeff Layton , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Sam Edwards , stable@vger.kernel.org Subject: [PATCH 1/2] ceph: free page array when ceph_submit_write() fails Date: Sun, 25 Jan 2026 18:27:14 -0800 Message-ID: <20260126022715.404984-2-CFSworks@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260126022715.404984-1-CFSworks@gmail.com> References: <20260126022715.404984-1-CFSworks@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If `locked_pages` is zero, the page array must not be allocated: ceph_process_folio_batch() uses `locked_pages` to decide when to allocate `pages`, and redundant allocations trigger ceph_allocate_page_array()'s BUG_ON(), resulting in a worker oops (and writeback stall) or even a kernel panic. Consequently, the main loop in ceph_writepages_start() assumes that the lifetime of `pages` is confined to a single iteration. The ceph_submit_write() function claims ownership of the page array on success (it is later freed when the write concludes). But failures only redirty/unlock the pages and fail to free the array, making the failure case in ceph_submit_write() fatal. Free the page array (and reset locked_pages) in ceph_submit_write()'s error-handling 'if' block so that the caller's invariant (that the array does not remain in ceph_wbc) is maintained unconditionally, making failures in ceph_submit_write() recoverable as originally intended. Fixes: 1551ec61dc55 ("ceph: introduce ceph_submit_write() method") Cc: stable@vger.kernel.org Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 63b75d214210..c3e0b5b429ea 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1470,6 +1470,14 @@ int ceph_submit_write(struct address_space *mapping, unlock_page(page); } =20 + if (ceph_wbc->from_pool) { + mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); + ceph_wbc->from_pool =3D false; + } else + kfree(ceph_wbc->pages); + ceph_wbc->pages =3D NULL; + ceph_wbc->locked_pages =3D 0; + ceph_osdc_put_request(req); return -EIO; } --=20 2.52.0 From nobody Mon Feb 9 14:31:15 2026 Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) (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 A0ADC29D260 for ; Mon, 26 Jan 2026 02:27:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769394472; cv=none; b=WyhrJxScOEOJxnAYS8zevCYZEr+2/0rHH6XCiuE2DZMc4UmKEwdllg69tFBcqBuFpnQYUfvwtG/X+qxJLz0V69ZSv27dkMAo4HneZqpgSNcNIMrzFgpamR4CMcanFaIazK84l0/8WNArzwFPdajDvwqrIsawX8VtpEnh1TE2H+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769394472; c=relaxed/simple; bh=VatR0ch63Gkeg6orcr79JOIcdXVHhBuf3GDTixsYryo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n6nf6J3J7pF4ivIEMu5aRA+0yz4Mr9qAvXY9rty2qtePZGtJZreWYfGKkKySVPlKd55ssjloEI48ofJMcP1hpbLyPkfKZ6SuVoaLMsXuZT4gO3HiMwwEYjk58sUdyBzCJtBTxlm9vRtcuf1wa8N0s73E8GYUzPcZ4G5ty3g6CWY= 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=A2NK3B7t; arc=none smtp.client-ip=74.125.82.44 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.b="A2NK3B7t" Received: by mail-dl1-f44.google.com with SMTP id a92af1059eb24-1233702afd3so5469091c88.0 for ; Sun, 25 Jan 2026 18:27:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769394470; x=1769999270; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vlGgkhnP8WsVCC5l4yVsMbASFDS3ivVR88ahQjlsei8=; b=A2NK3B7tllSfRev1c+ZIycYYlH+zcG0tJB5xrXphu92gEd/Zg4pEd1fAKuV0yA3LHb wrTKas/hwkacrnSAbgaui6WGWWnaaqsQIfNUjtLnE5UQ6EawzcEj0qlz5symFaMJBDe3 dd/5LDszkykvpAt/zXhjhlKx7ksJWiwe1UIoBaNI7V3nD8hJMn2E5uQat1Qxj+4LKOrA 5lDiu3H14CvbOFlCGSIf4jIdri9q+mB6UOC1pEGA0fX3GX0lufZN0wkeJOzxaAZPZfnl +rlFaf06LrC1v7QF9w9cnUFmVAG9sve/yLO2AAfT+VZNJs7X42j02r/QXCTmYnxRf8mv KvDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769394470; x=1769999270; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vlGgkhnP8WsVCC5l4yVsMbASFDS3ivVR88ahQjlsei8=; b=SJ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jEM3Y X-Received: by 2002:a05:7022:6189:b0:11b:9e5e:1a66 with SMTP id a92af1059eb24-1248ec0542amr1402757c88.14.1769394469589; Sun, 25 Jan 2026 18:27:49 -0800 (PST) Received: from luna.turtle.lan (static-23-234-93-211.cust.tzulo.com. [23.234.93.211]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1247d90cda6sm15266037c88.1.2026.01.25.18.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 18:27:48 -0800 (PST) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Xiubo Li , Ilya Dryomov Cc: Viacheslav Dubeyko , Christian Brauner , Milind Changire , Jeff Layton , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Sam Edwards Subject: [PATCH 2/2] ceph: split out page-array discarding to a function Date: Sun, 25 Jan 2026 18:27:15 -0800 Message-ID: <20260126022715.404984-3-CFSworks@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260126022715.404984-1-CFSworks@gmail.com> References: <20260126022715.404984-1-CFSworks@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Discarding a page array (i.e. after failure to submit it) is a little complex: - Every folio in the batch needs to be redirtied and unlocked. - Some folios are bounce pages created for fscrypt; the underlying plaintext folios also need to be redirtied and unlocked. - The array itself can come either from the mempool or general kalloc, so different free functions need to be used depending on which. Although currently only ceph_submit_write() does this, this logic is complex enough to warrant its own function. Move it to a new ceph_discard_page_array() function that is called by ceph_submit_write() instead. Suggested-by: Viacheslav Dubeyko Reviewed-by: Viacheslav Dubeyko Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 67 ++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index c3e0b5b429ea..28463b9a3bae 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1222,6 +1222,43 @@ void ceph_allocate_page_array(struct address_space *= mapping, ceph_wbc->len =3D 0; } =20 +static inline +void ceph_discard_page_array(struct writeback_control *wbc, + struct ceph_writeback_ctl *ceph_wbc) +{ + int i; + struct page *page; + + for (i =3D 0; i < folio_batch_count(&ceph_wbc->fbatch); i++) { + struct folio *folio =3D ceph_wbc->fbatch.folios[i]; + + if (!folio) + continue; + + page =3D &folio->page; + redirty_page_for_writepage(wbc, page); + unlock_page(page); + } + + for (i =3D 0; i < ceph_wbc->locked_pages; i++) { + page =3D ceph_fscrypt_pagecache_page(ceph_wbc->pages[i]); + + if (!page) + continue; + + redirty_page_for_writepage(wbc, page); + unlock_page(page); + } + + if (ceph_wbc->from_pool) { + mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); + ceph_wbc->from_pool =3D false; + } else + kfree(ceph_wbc->pages); + ceph_wbc->pages =3D NULL; + ceph_wbc->locked_pages =3D 0; +} + static inline bool is_folio_index_contiguous(const struct ceph_writeback_ctl *ceph_wbc, const struct folio *folio) @@ -1449,35 +1486,7 @@ int ceph_submit_write(struct address_space *mapping, BUG_ON(len < ceph_fscrypt_page_offset(page) + thp_size(page) - offset); =20 if (!ceph_inc_osd_stopping_blocker(fsc->mdsc)) { - for (i =3D 0; i < folio_batch_count(&ceph_wbc->fbatch); i++) { - struct folio *folio =3D ceph_wbc->fbatch.folios[i]; - - if (!folio) - continue; - - page =3D &folio->page; - redirty_page_for_writepage(wbc, page); - unlock_page(page); - } - - for (i =3D 0; i < ceph_wbc->locked_pages; i++) { - page =3D ceph_fscrypt_pagecache_page(ceph_wbc->pages[i]); - - if (!page) - continue; - - redirty_page_for_writepage(wbc, page); - unlock_page(page); - } - - if (ceph_wbc->from_pool) { - mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); - ceph_wbc->from_pool =3D false; - } else - kfree(ceph_wbc->pages); - ceph_wbc->pages =3D NULL; - ceph_wbc->locked_pages =3D 0; - + ceph_discard_page_array(wbc, ceph_wbc); ceph_osdc_put_request(req); return -EIO; } --=20 2.52.0