Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1073917lqj; Mon, 3 Jun 2024 09:21:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGM5qxqRmg5cFzHYqA3yrjZMDqaunh+/Q5YYTmPfDoJXboikKIGZYNqJqP0o8au4NxD/i5wt+4c2V/oMcTmIKrQrfhPLaVf/LbnhyNiw== X-Google-Smtp-Source: AGHT+IGj/hrUBuq3cMFZLpHNb4vh79LD98XLmMOpQaH4mPFoMJl4ulLJ8rfKaXYkTSoWFGRVCQDR X-Received: by 2002:a92:da4f:0:b0:374:a692:d5c4 with SMTP id e9e14a558f8ab-374a692d6d0mr10044755ab.20.1717431676566; Mon, 03 Jun 2024 09:21:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717431676; cv=pass; d=google.com; s=arc-20160816; b=pYSBWS6ZVvgjqLBhA/yrjE9Zbf4Aej8+3/5FljH1Vv+WtrktSVv4Kkl9N6KeG49YTJ /CD/Em1ZbRhNVexJ8AnuGVLYENu3lyZh+Y+xO37NI1JJqwz3q9YObVqA0pfXx92L5/7P t36ko/YdlorTV91XOZUB0WrSw781l9JfYV5DS4tqHfcs3GuWyHohQkAd7Xzs9aNeYVZD atU4ilaX6jn3PD/X/0RgcaNdjwQlj8bCWzfeDlqndI9fCvjVgDjRhcy8FIXYTT9kUu7p RuQgDjDR1F+gpw/vbGMw2s4ryYs6fMiz7m5SsyHreaNFgTfEOCB5cDLKF8H5NGN2SjLg EctQ== 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=wXyQsZpNIhV7YfkPDWeQ10552Fsy3kdrNbaiTAeqreE=; fh=bDDxpEm6k79VL8Fl/uzaGp/NdqoaFrnvfbje9hK7RHY=; b=fP0IJSnb4xq29QBLBqbQPxR77XQzEsmfTo9Th4UqAayJQ7jlVzIdJyAqyBqgDRWsjF fn8yU/IaTAM/njOKEFF+U17Mec1GRQrEEJi8nu/oS6bJokN2m/xe5oP6ruzwXiRREicL CoGIU5lAusRGxWaC/DWH11+ULxWMObGgnYpNciWMPUytNt27WWoCpuWJUaBSZPfj1DF9 XdCnjba9EpXMSI5Mors7Jz7KdZK2jjjwupT3skvWG7Xrrkn4KViWQATR6/SwMBns0Z6Z Wg14L8ySbQODqEylhrhGNX+p1H5r5hW7jL0JRE/wBis7jMzta9eGKSYsYkXldxUkMzYi ls3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kZVXbNpf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-199333-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199333-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c3c5fecf19si6543920a12.606.2024.06.03.09.21.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 09:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199333-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kZVXbNpf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-199333-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199333-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3D200283239 for ; Mon, 3 Jun 2024 15:01:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D757C122; Mon, 3 Jun 2024 15:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="kZVXbNpf" 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 60B9A391 for ; Mon, 3 Jun 2024 15:01:39 +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=1717426900; cv=none; b=Rgst7ZhReGXz/7h9hEurE91ENjq/wuo7wRb5YuNJBbm0zGZ2eMGGONovQrx1N8Cm/XRGEef0+lj7GFBWz286VYCCUEHf7wKhPJpHazbJJ8NE1SGkxVqr6GNgXL3kI96h6UfUHG07W9lZ+WUuC6ta0H8UGoZ/fwMpCi3bLxfV7tY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717426900; c=relaxed/simple; bh=8o10VpHMrb1mtP+6cygme2pqxmERvzP68d8JCGUocbQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YK375gTLz1c4bmcAAEznphbzdaH6/qDEiO2WMuZzHGlLaZbb69BA6tNiRlOHN9qiKqjR4mjI1mJ8JBOoZxKI76IEaWzzYiyE/ddcMskd5CNTbx01PxmB1fwVpJp/XQNkWYqdAVPr2s33CMMSUJc9IUIleuLHcrnMuSy5ZAUy70g= 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=kZVXbNpf; 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=wXyQsZpNIhV7YfkPDWeQ10552Fsy3kdrNbaiTAeqreE=; b=kZVXbNpfrIWVe/sMZLELAg9RMI zbp4TEZgUmVC4nfTsBuoWEmpQmUMNOg7sHzerT9ctiS+ySXgcKrJtp18J0Z+mX6+AnuOPkayDeAbf smp+4SqbbrILcY+mtGqfOX5fNekzEiqVoUmTB1VEIuIaKcVJFhVvOBbQsRGZYS++1LWSHzXPBHCRB CFwd0+SD0LjFqO4gXQOpzOgjpW8ig3CfPFm62KCXiaiBRECs8KfUgD9hQOWUW+jrvD9GmK+rVriV7 pz4u9ifYXvU9bHAn9EsOKYnbYDHBVJNp6VmxKWGiId39Sj0VJxDuMxJ+vJD8Hy5kW+Q4fp8OJEXEn 1yRSLitA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE9Bd-0000000EB68-1GVJ; Mon, 03 Jun 2024 15:01:25 +0000 Date: Mon, 3 Jun 2024 16:01:25 +0100 From: Matthew Wilcox To: David Hildenbrand Cc: Lance Yang , akpm@linux-foundation.org, ryan.roberts@arm.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: On Mon, Jun 03, 2024 at 04:56:05PM +0200, David Hildenbrand wrote: > On 03.06.24 16:43, Matthew Wilcox wrote: > > 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(). > > Yeah, likely we should also take a look at other folio_pte_batch() users > like copy_present_ptes() that pass the count as an int. Nothing should > really be broken, but we might not batch as much as we could, which is > unfortunate. You did include: VM_WARN_ON_FOLIO(!folio_test_large(folio) || max_nr < 1, folio); so at the least we have a userspace-triggerable warning.