Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1102011lqj; Mon, 3 Jun 2024 10:07:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUf1BPEHSPFLbJKte0PXwSIEGl7/euPVG9Jdm0aqU74nDoF/fpM1lnJT9J0jrjDemKDg765Q/TrxtFgivOlYTcywElpHaMAmVKDQCX9Kw== X-Google-Smtp-Source: AGHT+IFEQH1t78nqaAkncgo0PG/gztXT+2ol2eekqODowhQceRjvUBXcr66u8NnKzIEazkf+VQdl X-Received: by 2002:a05:6a00:1802:b0:702:593a:89 with SMTP id d2e1a72fcca58-702593a04d9mr7655560b3a.34.1717434446434; Mon, 03 Jun 2024 10:07:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717434446; cv=pass; d=google.com; s=arc-20160816; b=CUk3v5BHV/yfYir3C7tQWI4tp60CI5PcjLPcMysYzSb0UEn5Y4naZF2TRkSt3SXAMi TAPdDMW601QXr6lgmrAHwuKpWndsWgAoqlfqJbhLV4hYuoh0tjcXBDCXR9ozmnVZiBy9 cEU6gMipKxg/Sw2kwiObuFFjqpNgryWS9V2LG6D3y9wulzyg2NvoOQWzFRYIl10oHcHy ZOmv4AV465Yu1pfOjdN9d2KPoJTzlp7DNf69GnxGkmnZNIDjzltifYHIPGvdunZd8fuQ jsyKeC7C6Hn4kqQCtlZ76xS/hMY2EsYqu5o3K1ahOQABq9DNEBRkOy0+GSXpHcPX/zku rEVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=t9yfn1hx0t4EDmkvA9VAFFm6UlGVc6snNAn9His+0pM=; fh=eVzMgsd4Mvjm+d1QDarjUJKLT2NFXBYhOGLy0fCT7fY=; b=nZ4MPp3Y0wm6TzxitG9rWr2Nmba0fJfFxMuYbYumQ1kcQR6pww5PKK51YaZwV4FuXL AQsj2SgZKzk7j4U6yDcGqvw44fKwQbTnnZd+DBp+8z34dD+Uoaqkjh7YWvfJXyAeynoL 5MuJ/bZmhQqKzCyj4dt6rdwdFZrrTSJugiF+ARsHcaXa0TV+UNDGQ1bGr4PItVAl9BoR 2Yesq2XhBqH7Yq1oS4GKcH320PJ5k8dptu22b/fSyEUIezp1ZicUKLHzW8ZS9wsHC3PZ rWQUCisW9qbaTOT4CmMbFuu9UF5mctqUQyyVbWG+dEXiTYYUdPoyExNwjA/RbROdgWAM VoQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HtlyqtbZ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-199308-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199308-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70242b0ff5asi6643554b3a.206.2024.06.03.10.07.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 10:07:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199308-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HtlyqtbZ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-199308-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199308-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0712DB25B66 for ; Mon, 3 Jun 2024 14:44:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 182E712FF8E; Mon, 3 Jun 2024 14:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="HtlyqtbZ" 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 64EA612F5BB for ; Mon, 3 Jun 2024 14:43:41 +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=1717425823; cv=none; b=C6OuHjmIAUlfY+fqKwUVG+sXBt0vF5Dsb/Nf7XXiTAWEfHdSCx7jjyZozR3Mix1SGTfmBCCrHPcgdd7v8EhQQyJ6dmGEsuU85gvIM54eA152pzyjav7CEa+LpTsNYAQOxBOifB4xfFD0hqH4g5s4mXYRsDnHorgHm49hN0DXA0U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717425823; c=relaxed/simple; bh=V1K2iLhhRnGy0zuSs0nLFR7k6ApIHp8T8Sj2TRondgc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tMobOZ8yG+dmddh3tngICTjHi9R8RpY01ScG96yj/9utphG/zkbwagg6/+8EG1bLuvNUi5Ed2IgJofSfcjMdxqT0WmdiLKJ35xYhjFEarVvaRjXAm8THh5fnT0/hujQ+MvlAduLsD2V628cD00PdTXN9C7AOJ9nfIrZgrivjBP8= 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=HtlyqtbZ; 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 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=t9yfn1hx0t4EDmkvA9VAFFm6UlGVc6snNAn9His+0pM=; b=HtlyqtbZUh3FHXZwUgc78xShF7 tPJva81XjQdsSgeJs1xN92rHK3zVnZiW4d9J5S6ZEyZc4S2Egw1Kqmfsgf1cTZyHDTA2PhQjj0KIF fYzh4D/lkAuWYS3cAkAQnzYpUyzu9+DH3gdphRjL2s/EQcwawIO+py4IOc7SUUG185v4/iRD4/rTv mW1uertN6alMsoKaTjw7dTdYcyY1AnCFiLjholY0VJH9JXc9YnGX+W5aMh/wWkpcY0oNa1GtIOQ27 ZHQqixIdwj50SWjF3MWN4n2YXiTwKptHFOSgXn5puHKkQo+JpjrlzGPJ0Kgm3MsOWTkpUHLPF4TIW +x354qpg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE8uE-0000000EAgX-0enb; Mon, 03 Jun 2024 14:43:26 +0000 Date: Mon, 3 Jun 2024 15:43:26 +0100 From: Matthew Wilcox To: Lance Yang Cc: akpm@linux-foundation.org, ryan.roberts@arm.com, david@redhat.com, 21cnbao@gmail.com, baolin.wang@linux.alibaba.com, ziy@nvidia.com, fengwei.yin@intel.com, ying.huang@intel.com, libang.li@antgroup.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/1] mm/mlock: implement folio_mlock_step() using folio_pte_batch() Message-ID: References: <20240603140745.83880-1-ioworker0@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240603140745.83880-1-ioworker0@gmail.com> On Mon, Jun 03, 2024 at 10:07:45PM +0800, Lance Yang wrote: > +++ b/mm/mlock.c > @@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio) > static inline unsigned int folio_mlock_step(struct folio *folio, > pte_t *pte, unsigned long addr, unsigned long end) > { > - unsigned int count, i, nr = folio_nr_pages(folio); > - unsigned long pfn = folio_pfn(folio); > + const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY; > + unsigned int count = (end - addr) >> PAGE_SHIFT; This is a pre-existing bug, but ... what happens if you're on a 64-bit system and you mlock() a range that is exactly 2^44 bytes? Seems to me that count becomes 0. Why not use an unsigned long here and avoid the problem entirely? folio_pte_batch() also needs to take an unsigned long max_nr in that case, because you aren't restricting it to folio_nr_pages().