From patchwork Wed Aug 14 19:59:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13763890 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEBCB1BE25F for ; Wed, 14 Aug 2024 19:59:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665570; cv=none; b=AbkKimWGvPoRRAplT0p4Zg+lJNDHXubEEJmbMuH2UmE7aMoEbj8xvRi7paFEaNVRds/HiUxwaXWlgx9MtsZJ5mB3LtPRZ1q3vaHEQahzh5EISISqiaAql38EMJv9Y2sq7U+nRcWF+TUZynlneF9d2nRxNz8IgGTThmiziBXuiT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665570; c=relaxed/simple; bh=BSaYuwvct14w0//WzUN0uVvVTt/gVfRWrZKuvROpa2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WWvw9MY2DfQxO2OmBLWaLScOErxaQE19jRZK0NB4tZxZk0zuOo3blJ76EPVom0TEiNt79fUupVhyLTrKFQO8kDGN0rKk8zfJtgnoZXmXi4gmtzdtW2RVVOZAe3A8BjF2joxiuZOSM/VRygndMAMbKBLoUMweNCF5gDsLCbdnygI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=SGFb0Nic; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="SGFb0Nic" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=uV7LvP5jjpQvvHUMOkXdyRNLpd4GhyRBEzDrKs36E8E=; b=SGFb0NicM17bE+zbq2q5jZZYCD /GBwKgJIIP/hbRdOG1WGoXdJ5DdEfgth0jh/39pUVpyQhxYPie5+FTOLVR078rN0bAu7ExOx/UOol 2b5VYXeM+C5wB0JXKk8sFeiiPicgoazGG28RBAYPbpGR4dv/AShtC2us/E8STtD+VbCOQBO4sXcr9 H15cTZrg/g1FGmulIiiPTfZ10cu6j9VRXt9VQDPHHCV/fl9e2316jCJ11pcDx6BV3ck8UujZQW0J9 GwrIAWNJk8kkQAHZ5c/i105XBcKBaW5erjDNvWyZT/6XxqZx/5KVQ4r5hqDGjBgoutGi0AL3rrI4Q usm15/5w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1seK9Q-0000000130U-2HO5; Wed, 14 Aug 2024 19:59:20 +0000 From: "Matthew Wilcox (Oracle)" To: David Woodhouse Cc: "Matthew Wilcox (Oracle)" , Richard Weinberger , linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, Christian Brauner Subject: [PATCH 1/2] jffs2: Convert jffs2_do_readpage_nolock to take a folio Date: Wed, 14 Aug 2024 20:59:12 +0100 Message-ID: <20240814195915.249871-2-willy@infradead.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240814195915.249871-1-willy@infradead.org> References: <20240814195915.249871-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both callers now have a folio, so pass it in. No effort is made here to support large folios. Removes several hidden calls to compound_head(), two references to page->index and a use of kmap. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Zhihao Cheng --- fs/jffs2/file.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index ada572c466f8..13c18ccc13b0 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c @@ -77,29 +77,27 @@ const struct address_space_operations jffs2_file_address_operations = .write_end = jffs2_write_end, }; -static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg) +static int jffs2_do_readpage_nolock(struct inode *inode, struct folio *folio) { struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); - unsigned char *pg_buf; + unsigned char *kaddr; int ret; jffs2_dbg(2, "%s(): ino #%lu, page at offset 0x%lx\n", - __func__, inode->i_ino, pg->index << PAGE_SHIFT); + __func__, inode->i_ino, folio->index << PAGE_SHIFT); - BUG_ON(!PageLocked(pg)); + BUG_ON(!folio_test_locked(folio)); - pg_buf = kmap(pg); - /* FIXME: Can kmap fail? */ - - ret = jffs2_read_inode_range(c, f, pg_buf, pg->index << PAGE_SHIFT, + kaddr = kmap_local_folio(folio, 0); + ret = jffs2_read_inode_range(c, f, kaddr, folio->index << PAGE_SHIFT, PAGE_SIZE); + kunmap_local(kaddr); if (!ret) - SetPageUptodate(pg); + folio_mark_uptodate(folio); - flush_dcache_page(pg); - kunmap(pg); + flush_dcache_folio(folio); jffs2_dbg(2, "readpage finished\n"); return ret; @@ -107,7 +105,7 @@ static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg) int __jffs2_read_folio(struct file *file, struct folio *folio) { - int ret = jffs2_do_readpage_nolock(folio->mapping->host, &folio->page); + int ret = jffs2_do_readpage_nolock(folio->mapping->host, folio); folio_unlock(folio); return ret; } @@ -221,7 +219,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping, */ if (!folio_test_uptodate(folio)) { mutex_lock(&f->sem); - ret = jffs2_do_readpage_nolock(inode, &folio->page); + ret = jffs2_do_readpage_nolock(inode, folio); mutex_unlock(&f->sem); if (ret) { folio_unlock(folio); From patchwork Wed Aug 14 19:59:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13763891 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD9E71BF317 for ; Wed, 14 Aug 2024 19:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665570; cv=none; b=R+9h4Uw9g2CsSDnyP64O4fVI8fN2wqPqj0FNhKstkhd1pQwsQ8+iOri3JLd4ihFB8AdjnGSdgz39kSUpYJ9TvQnbspiEomwKVS5/vg0yimG6Y7L4eC9YOPuvXq5UuUsepxagD+/6FGpztMRzPTRqPIv8yZlbSAR3FxGE2h5Y+po= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665570; c=relaxed/simple; bh=A/XdVMK28JL9n5NkOrpuRxuu4y5RDd31yoFVZJm3/aA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XruSnom09vkWoT0Mv6ruaXBYtPaj76UM1UK9qvvLJTzrOuniy8mORX2XSmY1M37ooZ5/eSCGZg+aw5YHu3wtyNPze8q1GSt085OTIxE3gtlZ3NONctRoBcYq7XHgLQaxFQcvahJ8uvLuRxv6VTQV4oirVxUPuOeOUv25F3jXAFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=VRCUv56r; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VRCUv56r" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=dyVdPuVZWPTtj3niivHVjJclPba065VEMrZlN/1509Y=; b=VRCUv56rDLppLTGlOUP6XX06FM U6UYnFzNg7mdEV7rTY/CqOvFfZj/ZatHbLwxZpWyCDXb6Fda9RgdR8K9Il9fGt3ZNeWgIg2rIhLxY 9lzbxOEuRHQu5GaMDh8TDnJHCzP/ntxAiS1dpjY6beTXgrD7XRmh+gifXKhEohiwwx1voWmop2zHp r6d7rBmbyQW/WpXE6CLHAhTQl/fMXupuGcsC82Xq8VWKi3+37Xi6C2/NshcGOFmYO1NW94PpH7JTk YIgSoU1YTqi6jsJzd2YTYMVltGqO578+0efmzfUUCay0y/WXGGZjv//3CcXQGhd2Lfp1uv+iqB91P OJTfWX8w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1seK9Q-0000000130W-2f8i; Wed, 14 Aug 2024 19:59:20 +0000 From: "Matthew Wilcox (Oracle)" To: David Woodhouse Cc: "Matthew Wilcox (Oracle)" , Richard Weinberger , linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, Christian Brauner Subject: [PATCH 2/2] jffs2: Use a folio in jffs2_garbage_collect_dnode() Date: Wed, 14 Aug 2024 20:59:13 +0100 Message-ID: <20240814195915.249871-3-willy@infradead.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240814195915.249871-1-willy@infradead.org> References: <20240814195915.249871-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Call read_cache_folio() instead of read_cache_page() to get the folio containing the page. No attempt is made here to support large folios as I assume that will never be interesting for jffs2. Includes a switch from kmap to kmap_local which looks safe. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Zhihao Cheng --- fs/jffs2/gc.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c index 5c6602f3c189..822949d0eb00 100644 --- a/fs/jffs2/gc.c +++ b/fs/jffs2/gc.c @@ -1171,7 +1171,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era uint32_t alloclen, offset, orig_end, orig_start; int ret = 0; unsigned char *comprbuf = NULL, *writebuf; - struct page *page; + struct folio *folio; unsigned char *pg_ptr; memset(&ri, 0, sizeof(ri)); @@ -1317,25 +1317,25 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era BUG_ON(start > orig_start); } - /* The rules state that we must obtain the page lock *before* f->sem, so + /* The rules state that we must obtain the folio lock *before* f->sem, so * drop f->sem temporarily. Since we also hold c->alloc_sem, nothing's * actually going to *change* so we're safe; we only allow reading. * * It is important to note that jffs2_write_begin() will ensure that its - * page is marked Uptodate before allocating space. That means that if we - * end up here trying to GC the *same* page that jffs2_write_begin() is - * trying to write out, read_cache_page() will not deadlock. */ + * folio is marked uptodate before allocating space. That means that if we + * end up here trying to GC the *same* folio that jffs2_write_begin() is + * trying to write out, read_cache_folio() will not deadlock. */ mutex_unlock(&f->sem); - page = read_cache_page(inode->i_mapping, start >> PAGE_SHIFT, + folio = read_cache_folio(inode->i_mapping, start >> PAGE_SHIFT, __jffs2_read_folio, NULL); - if (IS_ERR(page)) { - pr_warn("read_cache_page() returned error: %ld\n", - PTR_ERR(page)); + if (IS_ERR(folio)) { + pr_warn("read_cache_folio() returned error: %ld\n", + PTR_ERR(folio)); mutex_lock(&f->sem); - return PTR_ERR(page); + return PTR_ERR(folio); } - pg_ptr = kmap(page); + pg_ptr = kmap_local_folio(folio, 0); mutex_lock(&f->sem); offset = start; @@ -1400,7 +1400,6 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era } } - kunmap(page); - put_page(page); + folio_release_kmap(folio, pg_ptr); return ret; }