Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19529004rwd; Wed, 28 Jun 2023 10:27:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qFkkAum5nQLVlPjJWW5hZw/CT8gA0NDU2ERkbtmGZ26272Ts1KkGY2hYvIe7BRzyUL4b2 X-Received: by 2002:a05:6a20:7d9a:b0:12b:d525:2cac with SMTP id v26-20020a056a207d9a00b0012bd5252cacmr2636448pzj.17.1687973246511; Wed, 28 Jun 2023 10:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687973246; cv=none; d=google.com; s=arc-20160816; b=h6xFmnKkulkzXq+D5xgjMB+U79eFXk6rvSdNP2L+o7TwSBIQayJTnoS9i0iRT4s6NM 41eXVgZ0PGyBMa7zRKnZ1NZE51rMqhPl3Exntur0/kub+7T8H/9tmAvp1c3u0oJtJ48X pg6wVeoeE/6CvNX7k010qgUx4FjrIgHPSfhe0ivbKNl/Dh4zRLECGnyrv6yegp57PV4p U4+n+edW1zXjH8vPL0tgZhQ3BnLoXhviPaxL6pBIIQw3DmxfzHAHLQ3pxNjVlEktCHCV m93ar/kMg16LUI6GUNsQl+ErsRrvrAH/m/dSRELK6CeZrXcv2FQxt1s0lHPdCzVJhrxT I5XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wDiRitMBY2qfFL1Q5um2pQQcb/oUQxsoHUZqTuCvWq8=; fh=WWc1HXglz1tDMQHHS0gOmuW+EF0SSvZEvOJa5Z1Qhxg=; b=HpGKq5O/YwWY/d/FyNp+NdYYZNRAh3DABNjjk9hieirRUnW0ny1ibKsf7nuH2V5TdX bKtSmt+d0dHs75o0ySkv9OKNarTfOA/MvOtQmnjBbfsac4Np9/lVK/Zu55777BrqJ+GR SwLlyDVE/QAt+ajIpMVegtrpjwch9Pes94CAdL0CyY2SXTu7DBIu6yvgqEQQjJmO9lzw Ssoi58hAKSCddtqR8umlW900JxKY5MGZGBlj3o/3OZ/jGMfNem2mkGS+cYdcF8G7Kq6/ 1QPIbRSp1jwlSioLFzRvcAiREDrp3SvdPaX/yOncXuLgDSGEXhLWt6/RYXl1GbXRVbNF 7M9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iiC97+GX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020aa78882000000b0065dba8cc3a6si1123606pfe.376.2023.06.28.10.27.14; Wed, 28 Jun 2023 10:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iiC97+GX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231916AbjF1RPN (ORCPT + 99 others); Wed, 28 Jun 2023 13:15:13 -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> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; }