From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 E594D230997 for ; Tue, 5 Aug 2025 07:47:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754380047; cv=none; b=SiYtUGb6VPVeN3AefKandO01vkEGfSx8hW1Ti1JKDbF6dq9tu3WztLDBpUgIsAoqJX36YxCZjmZxjZPEogyJhT3gT981jn/JTD2WyPuqk10/hyBWyiS17xJntF7KwmrEw6wMGk22QSfZJD2d4PvMD6zKYnzF1qcDN1M/l9WDpwA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754380047; c=relaxed/simple; bh=QdoM5jijl3U+bzt98WBSeNJn3NvpJT7uEM7WhHOfV2I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ESXui1vY7phtHRkw9x4P5gTjlZKVbWXT8I1i0gW8Uoqrt6RbzGB/1dBJFrfeq/F4AqzPloDnlW/7Oz3c7KsGPv46beXT6/Afwh2v4HLf5UURevBFSMdIea9uLmxQZwO763Mv6n+o7BCRdCQZCL3pVedH+6mKtbqaNH8ZE/iIJJU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DxyG/Idw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DxyG/Idw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754380044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=4FVZZvLwQ+yV12DH+flnf1KHJLBs63H0OjRwDryvigc=; b=DxyG/IdwHL+yA3StnxDXol0/vwaBq6PDe8Zslby3+hNkbnyVEm6AFc5xfVpKIHaGZYbbXO MwNbMxWfEtCkoC5/Kjel+aBN7UfpayhozUsuWzC5ufl7Gg9CJsGtFcI5Znws5RXPRdP8Uo C15OenqTNeJLnlliG5y3/OpD9dIx+4o= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-uqAphNPdMe6yfB3sGuyF7g-1; Tue, 05 Aug 2025 03:47:22 -0400 X-MC-Unique: uqAphNPdMe6yfB3sGuyF7g-1 X-Mimecast-MFC-AGG-ID: uqAphNPdMe6yfB3sGuyF7g_1754380041 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-459de0d5fb1so11717765e9.0 for ; Tue, 05 Aug 2025 00:47:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754380041; x=1754984841; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=4FVZZvLwQ+yV12DH+flnf1KHJLBs63H0OjRwDryvigc=; b=k76cOZFhvujCa94FqdDI7AS/BFM6OCeuxttKmwUfArY7J8Q22eSxWlC0MRS6ZAWmcl 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:a05:600c:1c12:b0:43c:ec0a:ddfd with SMTP id 5b1f17b1804b1-459e0f02dcbmr17622795e9.6.1754380041268; Tue, 05 Aug 2025 00:47:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHN1EeqY4x3j3RAtBvMc8UHTVzni5qYf4SXtqWIha76OhHDzRFGx3XTSbRwyXKYIlqHtsxFQg== X-Received: by 2002:a05:600c:1c12:b0:43c:ec0a:ddfd with SMTP id 5b1f17b1804b1-459e0f02dcbmr17622545e9.6.1754380040792; Tue, 05 Aug 2025 00:47:20 -0700 (PDT) Received: from ?IPV6:2003:d8:2f2b:b200:607d:d3d2:3271:1be0? (p200300d82f2bb200607dd3d232711be0.dip0.t-ipconnect.de. [2003:d8:2f2b:b200:607d:d3d2:3271:1be0]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-459e2a28bfasm12176375e9.21.2025.08.05.00.47.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Aug 2025 00:47:20 -0700 (PDT) Message-ID: <0a2e8593-47c6-4a17-b7b0-d4cb718b8f88@redhat.com> Date: Tue, 5 Aug 2025 09:47:18 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [GIT PULL] VFIO updates for v6.17-rc1 To: Alex Williamson , Linus Torvalds Cc: "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lizhe.67@bytedance.com" , Jason Gunthorpe References: <20250804162201.66d196ad.alex.williamson@redhat.com> <20250804185306.6b048e7c.alex.williamson@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umAL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ACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCaCwtJQUJG8aPFAAKCRBN3hD3AP+DWlDnD/4k2TW+HyOOOePVm23F5HOhNNd7nNv3 Vq2cLcW1DteHUdxMO0X+zqrKDHI5hgnE/E2QH9jyV8mB8l/ndElobciaJcbl1cM43vVzPIWn 01vW62oxUNtEvzLLxGLPTrnMxWdZgxr7ACCWKUnMGE2E8eca0cT2pnIJoQRz242xqe/nYxBB /BAK+dsxHIfcQzl88G83oaO7vb7s/cWMYRKOg+WIgp0MJ8DO2IU5JmUtyJB+V3YzzM4cMic3 bNn8nHjTWw/9+QQ5vg3TXHZ5XMu9mtfw2La3bHJ6AybL0DvEkdGxk6YHqJVEukciLMWDWqQQ RtbBhqcprgUxipNvdn9KwNpGciM+hNtM9kf9gt0fjv79l/FiSw6KbCPX9b636GzgNy0Ev2UV m00EtcpRXXMlEpbP4V947ufWVK2Mz7RFUfU4+ETDd1scMQDHzrXItryHLZWhopPI4Z+ps0rB CQHfSpl+wG4XbJJu1D8/Ww3FsO42TMFrNr2/cmqwuUZ0a0uxrpkNYrsGjkEu7a+9MheyTzcm vyU2knz5/stkTN2LKz5REqOe24oRnypjpAfaoxRYXs+F8wml519InWlwCra49IUSxD1hXPxO WBe5lqcozu9LpNDH/brVSzHCSb7vjNGvvSVESDuoiHK8gNlf0v+epy5WYd7CGAgODPvDShGN g3eXuA== Organization: Red Hat In-Reply-To: <20250804185306.6b048e7c.alex.williamson@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 05.08.25 02:53, Alex Williamson wrote: > On Mon, 4 Aug 2025 16:55:09 -0700 > Linus Torvalds wrote: > >> On Mon, 4 Aug 2025 at 15:22, Alex Williamson wrote: >>> >>> Li Zhe (6): >>> mm: introduce num_pages_contiguous() >> >> WHY? >> >> There is exactly *ONE* user, why the heck do we introduce this >> completely pointless "helper" function, and put it in a core header >> file like it was worth it? > > There was discussion here[1] where David Hildenbrand and Jason > Gunthorpe suggested this should be in common code and I believe there > was some intent that this would get reused. I took this as > endorsement from mm folks. This can certainly be pulled back into > subsystem code. Yeah, we ended up here after trying to go the folio-way first, but then realizing that code that called GUP shouldn't have to worry about folios, just to detect consecutive pages+PFNs. I think this helper will can come in handy even in folio context. I recall pointing Joanne at it in different fuse context. > >> And it's not like that code is some kind of work of art that we want >> to expose everybody to *anyway*. It's written in a particularly stupid >> way that means that it's *way* more expensive than it needs to be. >> >> And then it's made "inline" despite the code generation being >> horrible, which makes it all entirely pointless. >> >> Yes, I'm grumpy. This pull request came in late, I'm already >> traveling, and then I look at it and it just makes me *angry* at how >> bad that code is, and how annoying it is. > > Sorry, I usually try to get in later during the first week to let the > dust settle a bit from the bigger subsystems, I guess I'm running a > little behind this cycle. We'll get it fixed and I'll resend. Thanks, > > Alex > >> My builds are already slower than usual because they happen on my >> laptop while traveling, I do *not* need to see this kind of absolutely >> disgusting code that does stupid things that make the build even >> slower. >> >> So I refuse to pull this kind of crap. >> >> If you insist on making my build slower and exposing these kinds of >> helper functions, they had better be *good* helper functions. >> >> Hint: absolutely nobody cares about "the pages crossed a sparsemem >> border. If your driver cares about the number of contiguous pages, it >> might as well say "yeah, they are contiguous, but they are in >> different sparsemem chunks, so we'll break here too". The concern is rather false positives, meaning, you want consecutive PFNs (just like within a folio), but -- because the stars aligned -- you get consecutive "struct page" that do not translate to consecutive PFNs. So that's why the nth page stuff is not optional in the current implementation as far as I can tell. And because that nth_page stuff is so tricky and everyone gets it wrong all the time, I am actually in favor of having such a helper around. not buried in some subsystem. >> >> And at that point all you care about is 'struct page' being >> contiguous, instead of doing that disgusting 'nth_page'. I think stopping when we hit the end of a memory section in case of !CONFIG_SPARSEMEM_VMEMMAP could be done and documented. It's just that ... code gets more complicated: we end up really only optimizing for the unloved child sparsemem withoutCONFIG_SPARSEMEM_VMEMMAP: diff --git a/include/linux/mm.h b/include/linux/mm.h index 0d4ee569aa6b6..f080fa5a68d4a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1773,6 +1773,9 @@ static inline unsigned long page_to_section(const struct page *page) * the memory model, this can mean that the addresses of the "struct page"s * are not contiguous. * + * On sparsemem configs without CONFIG_SPARSEMEM_VMEMMAP, we will stop once we + * hit a memory section boundary. + * * @pages: an array of page pointers * @nr_pages: length of the array */ @@ -1781,8 +1784,16 @@ static inline unsigned long num_pages_contiguous(struct page **pages, { size_t i; + if (IS_ENABLED(CONFIG_SPARSEMEM) && + !IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP)) { + const unsigned long pfn = page_to_pfn(pages[0]); + + nr_pages = min_t(size_t, nr_pages, + PAGES_PER_SECTION - (pfn & PAGES_PER_SECTION)); + } + for (i = 1; i < nr_pages; i++) - if (pages[i] != nth_page(pages[0], i)) + if (pages[i] != pages[i - 1] + 1) break; Whether that helper should live in mm/utils.c is a valid point the bigger it gets. >> >> And then - since there is only *one* single user - you don't put it in >> the most central header file that EVERYBODY ELSE cares about. >> >> And you absolutely don't do it if it generates garbage code for no good reason! I understand the hate for nth_page in this context. But I rather hate it *completely* because people get it wrong all of the time. In any case, enjoy you travel Linus. -- Cheers, David / dhildenb