Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2988083lqz; Wed, 3 Apr 2024 14:44:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWC2GloibGjlFC2E+rlp/NVdGVo7fBljaVzKJnfjKrPhBO6LojBhi1G2O9Vn1yYwBPFmjyZdyiDiW0bVIh5CN/Hk9Y0Dh7zbOrQxlFToA== X-Google-Smtp-Source: AGHT+IGSWTAYvMv/KDjgNBv8345L8j26rjEU7Unvn1U7WVf5GEraKwDCs1TAqO3lmFOnnxl2AE4L X-Received: by 2002:a05:6a00:3d02:b0:6ea:d004:33c9 with SMTP id lo2-20020a056a003d0200b006ead00433c9mr846051pfb.30.1712180698469; Wed, 03 Apr 2024 14:44:58 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s3-20020a056a0008c300b006ecdea272c2si561377pfu.189.2024.04.03.14.44.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 14:44:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b=IPTADyD+; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-130651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 168AC284402 for ; Wed, 3 Apr 2024 21:44:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81044156890; Wed, 3 Apr 2024 21:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IPTADyD+" 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 4A91218AF9 for ; Wed, 3 Apr 2024 21:44:00 +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=1712180642; cv=none; b=AzAF+puNYZ82TkzyvIcx5mdky7H5YnM1YUcrCZyWLxDWsF2Mz197q4RVxfcUBiP9kpKc3lmw6vaLpw0O5h0EBacwG4tKaCUrnE2DuQYFrMZLdqr2Akd6jxVBSYu7Wk/N4PmfXpRtjc1hm4qZjcMQhFC7mGsL02vomUIp/Lb/tys= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712180642; c=relaxed/simple; bh=ixtQYXBShbBMtdvtoLxpRU9Dd+YhiX6dI/WSVrySfHk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=N8pF7mKbXmhMkfZEDYBulhApGU3H7nfhV+d1aYwjJRRmjcYtEsN9eS0cpasbjQJ7MDRs4WiYCAhaCSjpVs7P+O58PQDr0rhQQ6GNxUflFvBNV0lbYQPsZVNPDVjKf3zzN5C5xOtNbFlGlSaWD+MM0T8WyEIo97sg8XMiN49OOBY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=IPTADyD+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712180639; 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=DR1VRM2YOLBnde8LCoWidizffjEaSuWiF6q/aH62up0=; b=IPTADyD+T3qhGXrll82iY2k7P0bltsCwdSt5iwK7+831dqfrKmjyqOsKd6Vcwm9ivIB7AF ANorhklIXMBbMxj9iAyctxfV5VMX77aBmbjpY1uEriVWRdTQ2uSF3UF+QOEPgHL+jEWK3h Erh8/g9NvZZ3pSxxew7EN9MzqOzGx8g= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-TKTkfv1hPHOXIBCAll1AJA-1; Wed, 03 Apr 2024 17:43:58 -0400 X-MC-Unique: TKTkfv1hPHOXIBCAll1AJA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3435b7d66c3so119885f8f.3 for ; Wed, 03 Apr 2024 14:43:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712180637; x=1712785437; 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=DR1VRM2YOLBnde8LCoWidizffjEaSuWiF6q/aH62up0=; b=I/m08JUwCr6/UatgdcGdZvpC0YVY24LeO4QWSyibU5gowidj4yb43kDrRIh2eX4dHz GOH2S1SlcywGMTskp5SeqKuM9zXPmBajspMjNPKyqQogoGSrX9k/iSrQztI7BYfiFkLX b4Cz3BIQxamAsCVc0hGdY9erm0RoAL17NeZXP4fT532vQqB1YV3GXde+dD7lk3pawaqq THoN2JduQF/YzfE/XhYSRNcvm222GzUxmooieDmb1HS8rBVzwCvYpqm3DNr7xVLCUDiM ihvRX227JuxcZtjnRNV5IvdtrUac1Q/0h+Z8ESuFOpIDfVZc6qOhX8cqUGqa7/3eVNmm eC0A== X-Forwarded-Encrypted: i=1; AJvYcCW4H3uk61cy7pjZG6kcQTRiGmcLkrJHiRvhXrWTEXP++4c7xrkPRXs1H3mGVoC3YOd5ZMfseEH8kDFEngwSQe6gvSeFkhNRbaEFTTRP X-Gm-Message-State: AOJu0YwiYdq9z+TATiZjGwzM5NBzrCAun9olBoXaD6OiiKlYkSzZCKYK 0EF7fmxm+9M3irLJIZKfKCSzJnGsnhXN1Y3gwOuTr5suqv/UkjjVyJG/DmjbLYaG9Rz0Yw0SmUJ Aw8EttP6Mjydh12kNqaoSQChd1VK0gRcheMZyojJ14at0pzoJ3Fld/Jfl2SnE2w== X-Received: by 2002:adf:f144:0:b0:343:7ed6:765b with SMTP id y4-20020adff144000000b003437ed6765bmr526511wro.39.1712180636810; Wed, 03 Apr 2024 14:43:56 -0700 (PDT) X-Received: by 2002:adf:f144:0:b0:343:7ed6:765b with SMTP id y4-20020adff144000000b003437ed6765bmr526495wro.39.1712180636347; Wed, 03 Apr 2024 14:43:56 -0700 (PDT) Received: from ?IPV6:2003:cb:c73b:3100:2d28:e0b7:1254:b2f6? (p200300cbc73b31002d28e0b71254b2f6.dip0.t-ipconnect.de. [2003:cb:c73b:3100:2d28:e0b7:1254:b2f6]) by smtp.gmail.com with ESMTPSA id ee6-20020a056000210600b00343826878e8sm3895991wrb.38.2024.04.03.14.43.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Apr 2024 14:43:55 -0700 (PDT) Message-ID: Date: Wed, 3 Apr 2024 23:43:55 +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: [RFC PATCH 0/4] KVM: x86/mmu: Rework marking folios dirty/accessed To: Sean Christopherson Cc: David Matlack , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Stevens , Matthew Wilcox References: <20240320005024.3216282-1-seanjc@google.com> <4d04b010-98f3-4eae-b320-a7dd6104b0bf@redhat.com> From: David Hildenbrand Content-Language: en-US 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+N42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5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 03.04.24 02:17, Sean Christopherson wrote: > On Tue, Apr 02, 2024, David Hildenbrand wrote: >> On 02.04.24 19:38, David Matlack wrote: >>> On Wed, Mar 20, 2024 at 5:56 AM David Hildenbrand wrote: >>>> Secondary page tables are different to ordinary GUP, and KVM ends up >>>> using GUP to some degree to simulate HW access; regarding NUMA-hinting, >>>> KVM already revealed to be very different to all other GUP users. [1] >>>> >>>> And I recall that at some point I raised that we might want to have a >>>> dedicate interface for these "mmu-notifier" based page table >>>> synchonization mechanism. >>>> >>>> But KVM ends up setting folio dirty/access flags itself, like other GUP >>>> users. I do wonder if secondary page tables should be messing with folio >>>> flags *at all*, and if there would be ways to to it differently using PTEs. >>>> >>>> We make sure to synchronize the secondary page tables to the process >>>> page tables using MMU notifiers: when we write-protect/unmap a PTE, we >>>> write-protect/unmap the SPTE. Yet, we handle accessed/dirty completely >>>> different. >>> >>> Accessed bits have the test/clear young MMU-notifiers. But I agree >>> there aren't any notifiers for dirty tracking. >> >> Yes, and I am questioning if the "test" part should exist -- or if having a >> spte in the secondary MMU should require the access bit to be set (derived >> from the primary MMU). (again, my explanation about fake HW page table >> walkers) >> >> There might be a good reason to do it like that nowadays, so I'm only >> raising it as something I was wondering. Likely, frequent clearing of the >> access bit would result in many PTEs in the secondary MMU getting >> invalidated, requiring a new GUP-fast lookup where we would set the access >> bit in the primary MMU PTE. But I'm not an expert on the implications with >> MMU notifiers and access bit clearing. > > Ya. KVM already does something similar this for dirty logging, where SPTEs are > write-protected, i.e. generate faults to track dirty status. But KVM x86 has a > lot of code to mitigates the resulting pain, e.g. has a lockless fast-path to > make the SPTE writable and propagate the dirty status to bitmaps, and userspace > is heavily/carefully optimized to balance harvesting/clearing dirty status against > guest activity. > > In general, assumptions that core MM makes about the cost of PTE modifications > tend to fall apart for KVM. Much of that comes down to mmu_notifiers invalidations > being an imperfect boundary between the primary MMU and secondary MMUs. E.g. > any prot changes (NUMA balancing in particular) can have disastrous impact on KVM > guests because those changes invalidate secondary MMUs at PMD granularity, and > effective force KVM to do a remote TLB for every PMD that is affected, whereas > the primary is able to batch TLB flushes until the entire VMA is processed. > > So yeah, forcing KVM to zap and re-fault SPTEs in order to do page aging would be > comically slow for KVM guests without a crazy amount of optimization. Right, so access bits are certainly special. Fortunately, they are not as important to get right as dirty bits. > >>> Are there any cases where the primary MMU transfers the PTE dirty bit >>> to the folio _other_ than zapping (which already has an MMU-notifier >>> to KVM). If not then there might not be any reason to add a new >>> notifier. Instead the contract should just be that secondary MMUs must >>> also transfer their dirty bits to folios in sync (or before) the >>> primary MMU zaps its PTE. >> >> Grepping for pte_mkclean(), there might be some cases. Many cases use MMU >> notifier, because they either clear the PTE or also remove write >> permissions. >> >> But these is madvise_free_pte_range() and >> clean_record_shared_mapping_range()...->clean_record_pte(), that might only >> clear the dirty bit without clearing/changing permissions and consequently >> not calling MMU notifiers. > > Heh, I was staring at these earlier today. They all are wrapped with > mmu_notifier_invalidate_range_{start,end}(), and KVM's hyper aggressive response > to mmu_notifier invalidations ensure all KVM SPTEs get dropped. > >> Getting a writable PTE without the dirty bit set should be possible. >> >> So I am questioning whether having a writable PTE in the secondary MMU with >> a clean PTE in the primary MMU should be valid to exist. It can exist today, >> and I am not sure if that's the right approach. > > I came to the same conclusion (that it can exist today). Without (sane) FOLL_TOUCH, > KVM could retrieve the new PTE (W=1,D=0) after an mmu_notifier invaliation, and > thus end up with a writable SPTE that isn't dirty in core MM. > > For MADV_FREE, I don't see how KVM's current behavior of marking the folio dirty > at zap time changes anything. Ah, try_to_unmap_one() checks folio_test_dirty() > *after* invoking mmu_notifier_invalidate_range_start(), which ensures that KVM's > dirty status is propagated to the folio, and thus try_to_unmap_one() keeps the > folio. Right, we have to check if it has been re-dirtied. And any unexpected reference (i.e., GUP) could dirty it. > > Aha! But try_to_unmap_one() also checks that refcount==mapcount+1, i.e. will > also keep the folio if it has been GUP'd. And __remove_mapping() explicitly states > that it needs to play nice with a GUP'd page being marked dirty before the > reference is dropped. > > * Must be careful with the order of the tests. When someone has > * a ref to the folio, it may be possible that they dirty it then > * drop the reference. So if the dirty flag is tested before the > * refcount here, then the following race may occur: > > So while it's totally possible for KVM to get a W=1,D=0 PTE, if I'm reading the > code correctly it's safe/legal so long as KVM either (a) marks the folio dirty > while holding a reference or (b) marks the folio dirty before returning from its > mmu_notifier_invalidate_range_start() hook, *AND* obviously if KVM drops its > mappings in response to mmu_notifier_invalidate_range_start(). > Yes, I agree that it should work in the context of vmscan. But (b) is certainly a bit harder to swallow than "ordinary" (a) :) As raised, if having a writable SPTE would imply having a writable+dirty PTE, then KVM MMU code wouldn't have to worry about syncing any dirty bits ever back to core-mm, so patch #2 would not be required. ... well, it would be replaces by an MMU notifier that notifies about clearing the PTE dirty bit :) .. because, then, there is also a subtle difference between folio_set_dirty() and folio_mark_dirty(), and I am still confused about the difference and not competent enough to explain the difference ... and KVM always does the former, while zapping code of pagecache folios does the latter ... hm Related note: IIRC, we usually expect most anon folios to be dirty. kvm_set_pfn_dirty()->kvm_set_page_dirty() does an unconditional SetPageDirty()->folio_set_dirty(). Doing a test-before-set might frequently avoid atomic ops. >>>> I once had the following idea, but I am not sure about all implications, >>>> just wanted to raise it because it matches the topic here: >>>> >>>> Secondary page tables kind-of behave like "HW" access. If there is a >>>> write access, we would expect the original PTE to become dirty, not the >>>> mapped folio. >>> >>> Propagating SPTE dirty bits to folios indirectly via the primary MMU >>> PTEs won't work for guest_memfd where there is no primary MMU PTE. In >>> order to avoid having two different ways to propagate SPTE dirty bits, >>> KVM should probably be responsible for updating the folio directly. >>> >> >> But who really cares about access/dirty bits for guest_memfd? >> >> guest_memfd already wants to disable/bypass all of core-MM, so different >> rules are to be expected. This discussion is all about integration with >> core-MM that relies on correct dirty bits, which does not really apply to >> guest_memfd. > > +1, this is one of many reasons I don't want to support swap/relcaim for guest_memfd. > The instant guest_memfd gets involved with anything LRU related, the interactions > and complexity skyrockets. Agreed ... but it's unfortunate :/ -- Cheers, David / dhildenb