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 A54BDEB64D7 for ; Wed, 28 Jun 2023 17:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231781AbjF1RPM (ORCPT ); Wed, 28 Jun 2023 13:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231449AbjF1RPL (ORCPT ); Wed, 28 Jun 2023 13:15:11 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 992CD1BF2; Wed, 28 Jun 2023 10:15:09 -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=wDiRitMBY2qfFL1Q5um2pQQcb/oUQxsoHUZqTuCvWq8=; b=iiC97+GXjEvZxzDq6pPHDLjMGl hrwSBluBUtGF9rR7jH70ssuToh8NFbz2ksTY4Gyai3Cf0Gr1YV+hbCMtgkTnZ634B1pgdAf7iyYF1 O9nRkYDVg7qOp//mz8Qa3/takCuxFuOWiOVXgzOSjzitzNIZIzRWrEQ1pwKx7a7Tyy2u7f2VJPSC5 yCCnkjfEUedvJNmqHnubTlGoh/4xeUdWmx5xqZJvwtfzGAl1ed20BGd8Erib1ZAEN002ltGJFLPOQ TzyOZp/rBfvls8IeNLVShZ+Ru9AgiAXEQMWMMtRQjRGmOdj9UoOVhwdElCvWit1UgfQE0BYHItKIY tE/5A9GA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qEYky-0042IN-Bx; Wed, 28 Jun 2023 17:15:04 +0000 Date: Wed, 28 Jun 2023 18:15:04 +0100 From: Matthew Wilcox To: Sumitra Sharma Cc: Hans de Goede , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny , Fabio , Deepak R Varma Subject: Re: [PATCH] fs/vboxsf: Replace kmap() with kmap_local_{page, folio}() Message-ID: References: <20230627135115.GA452832@sumitra.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230627135115.GA452832@sumitra.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Here's a more comprehensive read_folio patch. It's not at all efficient, but then if we wanted an efficient vboxsf, we'd implement vboxsf_readahead() and actually do an async call with deferred setting of the uptodate flag. I can consult with anyone who wants to do all this work. I haven't even compiled this, just trying to show the direction this should take. diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c index 2307f8037efc..f1af9a7bd3d8 100644 --- a/fs/vboxsf/file.c +++ b/fs/vboxsf/file.c @@ -227,26 +227,31 @@ const struct inode_operations vboxsf_reg_iops = { static int vboxsf_read_folio(struct file *file, struct folio *folio) { - struct page *page = &folio->page; struct vboxsf_handle *sf_handle = file->private_data; - loff_t off = page_offset(page); - u32 nread = PAGE_SIZE; - u8 *buf; + loff_t pos = folio_pos(folio); + size_t offset = 0; int err; - buf = kmap(page); + do { + u8 *buf = kmap_local_folio(folio, offset); + u32 nread = PAGE_SIZE; - err = vboxsf_read(sf_handle->root, sf_handle->handle, off, &nread, buf); - if (err == 0) { - memset(&buf[nread], 0, PAGE_SIZE - nread); - flush_dcache_page(page); - SetPageUptodate(page); - } else { - SetPageError(page); - } + err = vboxsf_read(sf_handle->root, sf_handle->handle, pos, + &nread, buf); + if (nread < PAGE_SIZE) + memset(&buf[nread], 0, PAGE_SIZE - nread); + kunmap_local(buf); + if (err) + break; + offset += PAGE_SIZE; + pos += PAGE_SIZE; + } while (offset < folio_size(folio); - kunmap(page); - unlock_page(page); + if (!err) { + flush_dcache_folio(folio); + folio_mark_uptodate(folio); + } + folio_unlock(folio); return err; }