Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp61255pxy; Wed, 21 Apr 2021 18:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf+poBJx4WG3BkfG/iklK191NzeJZr2jcNpNaMxaPZvHxZOVRku7kQQYg/xHukYS5W0kgK X-Received: by 2002:a17:90a:af8b:: with SMTP id w11mr1091986pjq.149.1619055144400; Wed, 21 Apr 2021 18:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619055144; cv=none; d=google.com; s=arc-20160816; b=0myafL9OOLrOG05rh9J4yBM7c+zp+B0AKAqUBvUM0iWX+CeMGuF1O1dawJOotI2nRJ tr7FsF/onDJ6riVoJykbKYbNxqI0TrDoeAzgK4k+dUUAFn9k1czs6OPGVs848pKBUlNu u0RoCsa0meMoRaO+mwYl6e2LsbOuLuHT2hAOmxjQ6i6+FV5fI7AXNZuhnOfBFTpI060c cLtOMrPsesAop0tyBmDNAjyWjCOhTAGGpQgz6pevn7A8KIa6MJ4R0MMZXBccscdC1IxT x/t6qufZ9AfBn3oVIp9fyxx4UQhnce8k8Eie0/2QYy6uvx0xeaKZgigNQPDh5TYo1IMy PoNA== 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=+y6x2KmR9DmMzgd0umtxzcK+z2fQYDMGZRmfOOmeeOk=; b=joX+LnKlbUv+NJc3wD3+PzWquRhqDtBL/AAikAKnGErd38kpIvyYen/YkpXpLZIp9z Xs8aCoj0bvFx35bA7CmOVrPH9DJCSQ52/iJhc5Y4LHL4GhAdxrRxK5u99kpLF5c4viEH O+U4oz0oxwmoIOWSuMDB4ZebyTQS/0MtG5e04ore5r/3Ku94V8shryn9f4wpeEpnK8H1 ScaGnTckX+SbvT7XnHOIURfpp97y6h7Yl+a59qBwL8WMssJbf/pIfJXJK8twmLWvk5zI 3wmxv5K6s95mYvjDXT5nuogWvV6ezjH1Xj/fUcpgl5VcBubERX2TrT3fx9ptBHcWCTXk CyGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Q2bBEcMj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si1375099pgw.437.2021.04.21.18.32.05; Wed, 21 Apr 2021 18:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Q2bBEcMj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239477AbhDVBSj (ORCPT + 99 others); Wed, 21 Apr 2021 21:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbhDVBSj (ORCPT ); Wed, 21 Apr 2021 21:18:39 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B750C06174A; Wed, 21 Apr 2021 18:18:04 -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=+y6x2KmR9DmMzgd0umtxzcK+z2fQYDMGZRmfOOmeeOk=; b=Q2bBEcMjl6hxoF++IHEUTUHMg5 S/EbsDe3Cmp4JGvsvBpRVn56BGW//MdYalQ7MSo3oTEuqUYY5zvHiz9vwLTTlD61OgbO5xak4KBSr rrbRjOb6SSNoTCwvzc3VmMJTMbE78D3RnmCwRrvwbR2XhnRQ4TPq6V6Vp6Gymlsu/Qb/DcqkUxlFA Ofvef2GT2PyTMhk8VRwCzEqtoxBYAQWdzyt/negf/nShmy6+E4do8X/tdaDJ5edQe6XjYvQh2fduh zAbym0tbkph7tdoxD5F6DR+Zk8UFH1Z5I9aHewiT522mk5ycWKIoSCIE/ME9dhefUG3dwdPmUpePE Jw1+iaYg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lZNxH-00HGun-AD; Thu, 22 Apr 2021 01:16:41 +0000 Date: Thu, 22 Apr 2021 02:16:31 +0100 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , William Kucharski , Christoph Hellwig , Jan Kara , Dave Chinner , Johannes Weiner , "Kirill A. Shutemov" , Yang Shi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 2/2] mm/filemap: fix mapping_seek_hole_data on THP & 32-bit Message-ID: <20210422011631.GL3596236@casper.infradead.org> References: 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-kernel@vger.kernel.org On Wed, Apr 21, 2021 at 05:39:14PM -0700, Hugh Dickins wrote: > No problem on 64-bit without huge pages, but xfstests generic/285 > and other SEEK_HOLE/SEEK_DATA tests have regressed on huge tmpfs, > and on 32-bit architectures, with the new mapping_seek_hole_data(). > Several different bugs turned out to need fixing. > > u64 casts added to stop unfortunate sign-extension when shifting > (and let's use shifts throughout, rather than mixed with * and /). That confuses me. loff_t is a signed long long, but it can't be negative (... right?) So how does casting it to an u64 before dividing by PAGE_SIZE help? > Use round_up() when advancing pos, to stop assuming that pos was > already THP-aligned when advancing it by THP-size. (But I believe > this use of round_up() assumes that any THP must be THP-aligned: > true while tmpfs enforces that alignment, and is the only fs with > FS_THP_SUPPORT; but might need to be generalized in the future? > If I try to generalize it right now, I'm sure to get it wrong!) No generalisation needed in future. Folios must be naturally aligned within a file. > @@ -2681,7 +2681,8 @@ loff_t mapping_seek_hole_data(struct add > > rcu_read_lock(); > while ((page = find_get_entry(&xas, max, XA_PRESENT))) { > - loff_t pos = xas.xa_index * PAGE_SIZE; > + loff_t pos = (u64)xas.xa_index << PAGE_SHIFT; > + unsigned int seek_size; I've been preferring size_t for 'number of bytes in a page' because I'm sure somebody is going to want a page larger than 2GB in the next ten years.