From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 572F6EE14C3 for ; Wed, 6 Sep 2023 19:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233266AbjIFTvy (ORCPT ); Wed, 6 Sep 2023 15:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbjIFTvx (ORCPT ); Wed, 6 Sep 2023 15:51:53 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7835B171A; Wed, 6 Sep 2023 12:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lYqvfUxrjJBI3W5sFQK8JINW4dgJBOR0soBLBY+UK1E=; b=igC4ioi+4p97koDXBrAP/oiqGk pOIvoHwFWFBftnB0pl86swEClAGjyHMnhl4d8aEfJDfaDsngXiBd6cP2cHkyB3UedGn8hsCEek4Xc CK9RMeGc6zFtss1QIbxX0pHMAwIMZpcCQh89aFFlt/VAU/YkLqgqG2gJMyqwSrj1frP+baLfXBaRU 6Ix+acVvbn01n9s25FQT2GE/bg7AXYXiRJJ5LS+enLHiASvnVEJioYIKy19J/pZ+J7N57cMWw08sQ 3CfwxmcqZoZ3OUxa6msPHaKlswK0uFrLMbgKBaHGTsQ7SBDckpADQaq8zgmwFBN/b9PR6ZwUZDKDw sDuFdXxg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qdyYu-0055PK-SO; Wed, 06 Sep 2023 19:51:40 +0000 Date: Wed, 6 Sep 2023 20:51:40 +0100 From: Matthew Wilcox To: Ritesh Harjani Cc: Theodore Ts'o , Zorro Lang , linux-ext4@vger.kernel.org, fstests@vger.kernel.org, regressions@lists.linux.dev, Andrew Morton , Jan Kara Subject: Re: [fstests generic/388, 455, 475, 482 ...] Ext4 journal recovery test fails Message-ID: References: <87wmx336ns.fsf@doe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Sep 06, 2023 at 01:38:23PM +0100, Matthew Wilcox wrote: > > Is this code path a possibility, which can cause above logs? > > > > ptr = jbd2_alloc() -> kmem_cache_alloc() > > <..> > > new_folio = virt_to_folio(ptr) > > new_offset = offset_in_folio(new_folio, ptr) > > > > And then I am still not sure what the problem really is? > > Is it because at the time of checkpointing, the path is still not fully > > converted to folio? > > Oh yikes! I didn't know that the allocation might come from kmalloc! > Yes, slab might use high-order allocations. I'll have to look through > this and figure out what the problem might be. I think the probable cause is bh_offset(). Before these patches, if we allocated a buffer at offset 9kB into an order-2 slab, we'd fill in b_page with the third page of the slab and calculate bh_offset as 1kB. With these patches, we set b_page to the first page of the slab, and bh_offset still comes back as 1kB so we read from / write to entirely the wrong place. With this redefinition of bh_offset(), we calculate the offset relative to the base page if it's a tail page, and relative to the folio if it's a folio. Works out nicely ;-) I have three other things I'm trying to debug right now, so this isn't tested, but if you have time you might want to give it a run. diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 6cb3e9af78c9..dc8fcdc40e95 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -173,7 +173,10 @@ static __always_inline int buffer_uptodate(const struct buffer_head *bh) return test_bit_acquire(BH_Uptodate, &bh->b_state); } -#define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK) +static inline unsigned long bh_offset(struct buffer_head *bh) +{ + return (unsigned long)(bh)->b_data & (page_size(bh->b_page) - 1); +} /* If we *know* page->private refers to buffer_heads */ #define page_buffers(page) \