From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A910ED6910B for ; Thu, 28 Nov 2024 13:37:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A8646B0083; Thu, 28 Nov 2024 08:37:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 257D66B0085; Thu, 28 Nov 2024 08:37:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F9A86B0088; Thu, 28 Nov 2024 08:37:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E79F56B0083 for ; Thu, 28 Nov 2024 08:37:26 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A6009160138 for ; Thu, 28 Nov 2024 13:37:26 +0000 (UTC) X-FDA: 82835605440.25.C37FAD6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 8158E14001A for ; Thu, 28 Nov 2024 13:37:19 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JgIGcj5o; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732801039; h=from:from:sender: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:dkim-signature; bh=o04VFkr20/CH9z+kvj5lbsSa3s1hEKBLK1i56NNGrfg=; b=VzlJ6y1yYNW+Bf5I2Bx4504nbgYQXad/eRK4wQDrU1VBmzUZoO4phiUjo23NJFt7qwiXv/ 0Y3jLSwStAdKA+S8W0Vcywabw89LWqRy2x65NyErMLFKaMagoEOTpX+V4pgkkKXYETJA0I g6XE2WT17ABhE5tt/qCFl2Xq6VrzrdQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732801039; a=rsa-sha256; cv=none; b=xRZYZodv3xVHWGZUk8QHIkMuTcntiQ6jOx2dblAel13BS34aOtcHlK9XSaorj24BYAMB5p PZnlOXFz+w5N6sT7Nm9+1ZGAomsnOgy9Xkwqz3zY7UicgqqzvvG0XXgUT6+VtCb86Fgdiy lGqEy0/8IAKBPs8kHaPfWdHAdPmtrP0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JgIGcj5o; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732801043; 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=o04VFkr20/CH9z+kvj5lbsSa3s1hEKBLK1i56NNGrfg=; b=JgIGcj5o5O7gtEGXfsybVxYrIBDkAuFMH81RsqJk80rZ12w517w4/HEJmQ8uAtHojYkR9K ocealrJpkV8KdC//cFcaeDaFilM7Yk9JXhVS4qHJZN2/PCqcK1mUwVJ3yNipfa+z0RCuGM RQrh0CmVzZKkD3JS1NArGe2JJsHmpak= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-48-3AUWcYilMd2nQbKq2COEOg-1; Thu, 28 Nov 2024 08:37:22 -0500 X-MC-Unique: 3AUWcYilMd2nQbKq2COEOg-1 X-Mimecast-MFC-AGG-ID: 3AUWcYilMd2nQbKq2COEOg Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2ffcd8a12e4so6408071fa.3 for ; Thu, 28 Nov 2024 05:37:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801041; x=1733405841; 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=o04VFkr20/CH9z+kvj5lbsSa3s1hEKBLK1i56NNGrfg=; b=C1m+dRVOqC3joG42fU3lB1h/0o2s42ri+cG2WPsr0R3xdBMK7e4wClTYTKiXaa7b2f 0HYjELDp768WqSalloEIQ7V8T/yiZgfWFXON9zfRehlTlngVZw0wqr88Y1z4IhUwG6MQ JQKAw/EFsP2FHPzMBzsI1T6z5KuG1YKMU+HaaEMtkA30bB4L0GwJHiFZxer8FaxpOzrX sSOxZoRK5DezYDnclXLB6c4KqQIPII4c0qWFr10XLo10bINWt7unBgDV14ZBtrAiKiCZ IJ5NAt3mjftSN+ptODaWj/pY1jSn3/8Ekf/3/FBUwod9zoaaCljnWrA7y8w6lAkoyGQJ PljA== X-Forwarded-Encrypted: i=1; AJvYcCV937fTGhe2nw9RTkwG96okgdNqUe0fNTISlEzQKJeolPk3rwQxhJaXkK5gt3KrHLJkMO1fIPZTWQ==@kvack.org X-Gm-Message-State: AOJu0YwidSRbETEPJ+UC4i2gM8VX7CmddUrQnCztnzpmDYLoI1qlnR4e 9b8guFSnPDSfHw2Q8Nxbs2Sm8VIRhOZXI0TPAnnfQycKCrkR6wrN9pl017RMg/NbIm86Fz4S/W+ GOQNEc9t13CjsoEO4kIPgkQH7dpNytDQ038pJnMEnrUjMPyXI X-Gm-Gg: ASbGncvGgVU+7NFNLOvwQkUJ2GQQawyJpRo8Yr7HEgI+BgNNU5zTQIrtsRv83NHoE5u 0n6sGRNsfUiArEvubzB/aZR71kF/U+mCqbDZWkuq8sv9wjIel2KSKdZoRwwbTbgCqzf95hwK1WE I7/CvpkEbfdXbxCllbKlZBXak+ZQJOEPuNSxs/dRKMJmvjhGmNZdCbRQN7aq4e3eow8hImT1wd2 c4/PHzaVYkyHoeLffWxe9KjI239LCV3Rg7A6qRIRkyTtT5klboEjoOF9srgA84d0VA8P6lFvIEX p0qVKm6zDI8ANDXOLowoqKkcWgARSKXDzj4J8hvOhyEJxYM5xnTNROc9tKp8wZtw8N3TNB/6DdE = X-Received: by 2002:a05:6512:3d19:b0:53d:de1b:f961 with SMTP id 2adb3069b0e04-53df00aa17dmr4595466e87.7.1732801040616; Thu, 28 Nov 2024 05:37:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlVggOKgnUUDhJhvbO+cgemu4YlM8B4APCzkh/YH3AlJBrHvwswzIp1g0/+LBPdEjMLJA7vg== X-Received: by 2002:a05:6512:3d19:b0:53d:de1b:f961 with SMTP id 2adb3069b0e04-53df00aa17dmr4595444e87.7.1732801040098; Thu, 28 Nov 2024 05:37:20 -0800 (PST) Received: from ?IPV6:2003:cb:c714:1600:f3b:67cc:3b88:620e? (p200300cbc71416000f3b67cc3b88620e.dip0.t-ipconnect.de. [2003:cb:c714:1600:f3b:67cc:3b88:620e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434b0d9bd06sm22776105e9.3.2024.11.28.05.37.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Nov 2024 05:37:18 -0800 (PST) Message-ID: <926b3829-784f-47b8-9903-ea7b9ad484ac@redhat.com> Date: Thu, 28 Nov 2024 14:37:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] perf: map pages in advance To: Lorenzo Stoakes Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox References: <20241128113714.492474-1-lorenzo.stoakes@oracle.com> <9f9fd840-6421-43b5-9a12-edfa96e067cc@redhat.com> <1af66528-0551-4735-87f3-d5feadadf33a@lucifer.local> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7M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g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <1af66528-0551-4735-87f3-d5feadadf33a@lucifer.local> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JaFKiAdt36LqTeUbeYeO-ial4Bde7QEcdnbG2j2s7s8_1732801041 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8158E14001A X-Stat-Signature: o7d4rut6axwuxffrdy85ysqiyzpe8ouc X-Rspam-User: X-HE-Tag: 1732801039-989501 X-HE-Meta: U2FsdGVkX1+wCdZtz/mPWBCEIn327oxWe85jnVBsCrTTAsDmno79vQWLARQUSl3A+QSSDsdlGzmkMZtVK6ICbQsK4Wes6UYj2Rz40iM9+FLy0rRnOV5X79evW+G3xzj+gAg/R0aYMUiOkRwmY6CqI1dn++K5hBTusz5Cm7JP10ZFFCiBfgtFOQiRAS1cuiBOTpHuD0AU/PIrHWbpiq59zkCoeNoo9R88C6rezWQA9xcvv2XzMKvHBa7T1bIX4rag3D+bONmn1kX6yfjHBilQ3/G9yJH9zWmnQKn8YU85iotHrpwPRVAl9fbbRHAaueQ6KDAGf0gmi7AkvPG0c9alTEFIaqRliS9dwh08P35Bd7qZelgeHPTM9eBJ2ubWn7gGOprpxPQVwpWzkVqh64aE6jBr6fyMnny7+mhoJcFL1XmxKSaEnPfs/8FgkZ1j1YCsccU2Rx7/pPI6ghi6g8BZ3DuqfpkuKfnqug6ylAtmk1c6GvMHcKREr7oAg0BxtTbimz32bMEcOsuvn2R36OlupAw5Qv2BDPOBnBkjPrpCqWTVtDAT4Ge/ieCLi5IjUXLg3DZmOm30BaaCfVOgy3J6bTG1YCKsNyo6Bv8Q37pxjrbkVRPTuedLW+cej9IM7UNDbhZyR7tQT5bRzKVbwZ3tXKZx9ICseTCWsG7NfR/0F5sqrjqzsbiry/v2Yw0DugB5YDPJhiE2XtJMoIVSixFdB9uBZukIpVxS+/mIzPPp0YEmJvViJPjTBB1mTpfLS3xtQYLJbramqE8IZ+7+nPglBrvA/QJwAsfwixlTlhOPIRrnBsl95SuHKAa0eHUdRvmk4zuRx0mmV/atQbgToXMbYmMD+l1BadwFH03+Q9FKRRKBSeWNjXjB79HzhFVJAngv/OC5LzeZW2jLhywZ/Gn9HDyDzZD/Im0rKfaTKGtuUwaSLMsc5syUqnt0008dbgc3J9GtO8Fd+ketQhjo7iU V8UrV8+e uODAXmkV3f3ijMu+3tpViNsACDfujbZR2epTRv7sDRQ0nkO9sZboYP6j0uexz0XvjAEUS/igBpf5I2VRVzulfEOg05LZO2hYExIkja9+MQ0bHHCUuqHiDSE52ZsA5nsroxttw1gNsNksHJ/X/I7+PapBI0tCx0kvJL3UWKI6J1aK3p87lulc82x7zTH+jbo1nF6oEzAC1rtqoDKjCuT2WNg4gk9PwgTKQvPnGF929+eZH4nBtDTuUPBpvocqYxQW218bCyHvcMSKetmcQpFRijeoQx+YnezvjZv4Rb86MDCbI84trGKxTZaBvAtgbOQZjGLAhujIU3aqQRHhNvvZUrn2ArsHfhiJxw17RrBNeHI0w5RWAs4u6/Zdm7PmFw8JBUuqWjo7zrwED/RXYaX8OiY92Gw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 28.11.24 14:20, Lorenzo Stoakes wrote: > On Thu, Nov 28, 2024 at 02:08:27PM +0100, David Hildenbrand wrote: >> On 28.11.24 12:37, Lorenzo Stoakes wrote: >>> We are current refactoring struct page to make it smaller, removing >>> unneeded fields that correctly belong to struct folio. >>> >>> Two of those fields are page->index and page->mapping. Perf is currently >>> making use of both of these, so this patch removes this usage as it turns >>> out it is unnecessary. >>> >>> Perf establishes its own internally controlled memory-mapped pages using >>> vm_ops hooks. The first page in the mapping is the read/write user control >>> page, and the rest of the mapping consists of read-only pages. >>> >>> The VMA is backed by kernel memory either from the buddy allocator or >>> vmalloc depending on configuration. It is intended to be mapped read/write, >>> but because it has a page_mkwrite() hook, vma_wants_writenotify() indicaets >>> that it should be mapped read-only. >>> >>> When a write fault occurs, the provided page_mkwrite() hook, >>> perf_mmap_fault() (doing double duty handing faults as well) uses the >>> vmf->pgoff field to determine if this is the first page, allowing for the >>> desired read/write first page, read-only rest mapping. >>> >>> For this to work the implementation has to carefully work around faulting >>> logic. When a page is write-faulted, the fault() hook is called first, then >>> its page_mkwrite() hook is called (to allow for dirty tracking in file >>> systems). >>> >>> On fault we set the folio's mapping in perf_mmap_fault(), this is because >>> when do_page_mkwrite() is subsequently invoked, it treats a missing mapping >>> as an indicator that the fault should be retried. >>> >>> We also set the folio's index so, given the folio is being treated as faux >>> user memory, it correctly references its offset within the VMA. >>> >>> This explains why the mapping and index fields are used - but it's not >>> necessary. >>> >>> We preallocate pages when perf_mmap() is called for the first time via >>> rb_alloc(), and further allocate auxiliary pages via rb_aux_alloc() as >>> needed if the mapping requires it. >>> >>> This allocation is done in the f_ops->mmap() hook provided in perf_mmap(), >>> and so we can instead simply map all the memory right away here - there's >>> no point in handling (read) page faults when we don't demand page nor need >>> to be notified about them (perf does not). >>> >>> This patch therefore changes this logic to map everything when the mmap() >>> hook is called, establishing a PFN map. It implements vm_ops->pfn_mkwrite() >>> to provide the required read/write vs. read-only behaviour, which does not >>> require the previously implemented workarounds. >>> >>> It makes sense semantically to establish a PFN map too - we are managing >>> the pages internally and so it is appropriate to mark this as a special >>> mapping. >> >> It's rather sad seeing more PFNMAP users where PFNMAP is not really required >> (-> this is struct page backed). >> >> Especially having to perform several independent remap_pfn_range() calls >> rather looks like yet another workaround ... >> >> Would we be able to achieve something comparable with vm_insert_pages(), to >> just map them in advance? > > Well, that's the thing, we can't use VM_MIXEDMAP as vm_insert_pages() and > friends all refer vma->vm_page_prot which is not yet _correctly_ established at > the point of the f_op->mmap() hook being invoked :) So all you want is a vm_insert_pages() variant where we can pass in the vm_page_prot? Or a way detect internally that it is not setup yet and fallback to vm_get_page_prot(vma->vm_flags & ~VM_SHARED)? Or a way to just remove write permissions? > > We set the field in __mmap_new_vma(), _but_ importantly, we defer the > writenotify check to __mmap_complete() (set in vma_set_page_prot()) - so if we > were to try to map using VM_MIXEDMAP in the f_op->mmap() hook, we'd get > read/write mappings, which is emphatically not what we want - we want them > read-only mapped, and for vm_ops->pfn_mkwrite() to be called so we can make the > first page read/write and the rest read-only. > > It's this requirement that means this is really the only way to do this as far > as I can tell. > > It is appropriate and correct that this is either a VM_PFNMAP or VM_MIXEDMAP > mapping, as the pages reference kernel-allocated memory and are managed by perf, > not put on any LRU, etc. > > It sucks to have to loop like this and it feels like a workaround, which makes > me wonder if we need a new interface to better allow this stuff on mmap... > > In any case I think this is the most sensible solution currently available that > avoids the pre-existing situation of pretending the pages are folios but > somewhat abusing the interface to allow page_mkwrite() to work correctly by > setting page->index, mapping. Yes, that page->index stuff is nasty. > > The alternative to this would be to folio-fy, but these are emphatically _not_ > folios, that is userland memory managed as userland memory, it's a mapping onto > kernel memory exposed to userspace. Yes, we should even move away from folios completely in the future for vm_insert_page(). > > It feels like probably VM_MIXEDMAP is a better way of doing it, but you'd need > to expose an interface that doesn't assume the VMA is already fully set > up... but I think one for a future series perhaps. If the solution to your problem is as easy as making vm_insert_pages() pass something else than vma->vm_page_prot to insert_pages(), then I think we should go for that. Like ... vm_insert_pages_prot(). Observe how we already have vmf_insert_pfn() vs. vmf_insert_pfn_prot(). But yes, in an ideal world we'd avoid having temporarily messed up vma->vm_page_prot. So we'd then document clearly how vm_insert_pages_prot() may be used. -- Cheers, David / dhildenb