Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2256372lqz; Tue, 2 Apr 2024 11:31:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVJhQ7Q1P7uNJnR+WkJUinPRZDuiSjeFv3IMjfLThTBL0LPzxaL9YtPEXbjEbSdGON2OLakkKUblLITMPFq4kPS1zs6qNRGImqiyhbeuQ== X-Google-Smtp-Source: AGHT+IFNcFKvadyL+9dm+E/T8enCnPKfX/si/fgq7e5kwdPbmfwYQa7kFwFvuFBxzEjxTMhPVgGK X-Received: by 2002:a17:906:2705:b0:a46:de64:c479 with SMTP id z5-20020a170906270500b00a46de64c479mr8246025ejc.69.1712082712847; Tue, 02 Apr 2024 11:31:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712082712; cv=pass; d=google.com; s=arc-20160816; b=LmoxtpiMOGjhypj3cQhSI3ZBaVxqOPN7k6ylfUwo1Couvru00stpFgdTHWruJuSOpJ mey732QiHp8DpElAh/IEE86ZKGik2+tJiTOw+obI+4Pheyj4V4k0qk30UkyZYKBgxuCp KypVD5QyQI9ueVok+DfaepeZPdt8KOs+3+xMXSmIQCxtFGXMiNGVj+qqr2MUzZAypZ7R 8DFIp1bc4Kk5pCFSHH/qOPElOeHTWaGGM16pi37NRUzcGS4jcIQAEAKbSNvZCrbzi3mF aH8HVeA5Imi0iMb57rTq1QKChbOIK4KQFX3SlHxekZJm8dSO1cxlK858YUuAZR0G9cnJ bvhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=lMrQ/HyPcTUexiexGuHGYoI8R6rk48hQ9GiX28Xmjeo=; fh=B2crwvww53JbOElXROAr+743WbmTohQTT24xX4kufjM=; b=LU+4WQajAt1VaDxhvWM/SvvxzLJ/g9zjh0rDSLQP8aI7PYkbf4GVNUOO7HeDnqPH2J yxiI5PzyuAygUGTzVPX2lmiCMdk1/pzAJ+QupxrPoWAWjlxZHYNZMR8J1HydXuQrw91f 3Nqti0vyv+BfwFh+Ca7pSNpgm72hVzeoVP7yJFEaIqLU44ElSmSw1zEykIBBETLx2a9p IJP0JhLRTGjrYJphZUIiM//SLJQnXYshlTNIy6YKkgHLviPGePHzl2MyfJ6T3DjB++lQ dT6MdgUSrylxZCquNqDuq6sQPNO1CKk/+hhGKe+vnFWASMaJPeksykiH2oQnSLdamUr3 NElw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gueSDceB; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-128504-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h5-20020a17090619c500b00a44444998ebsi5947728ejd.215.2024.04.02.11.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 11:31:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128504-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gueSDceB; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-128504-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 am.mirrors.kernel.org (Postfix) with ESMTPS id 693E71F22DFC for ; Tue, 2 Apr 2024 18:31:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFBE315B125; Tue, 2 Apr 2024 18:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gueSDceB" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 0CBD32E62E for ; Tue, 2 Apr 2024 18:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712082702; cv=none; b=PkUqwQJiFbd9fjRTt3+1dobR4tEYnxRA5hcECYINrSjiKKcLgyNjJhr1jhzDfOxtKhmyKXLieaAEMqFtQWerOn0tv+/0T3wnFf9HfPM21QYXBKIlf18LJVIIKdyjpHo9Jk9l1C84kYDi4y6fnkI/YyMuFtOgsBbR+QOSlpm1XI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712082702; c=relaxed/simple; bh=qDApzRLT64Qi6pbqkdTWjmJkL9+/WQNfFdxV94XLxFk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bH5fxqK4TuUlUtTwFS/A2lcps92u7/ZpM+ZY08mTWTgiaV+V8bzf+0D7cyRJnlQp3PGvpyQcqyv3fRvgc5yci8MV90mRqquCMVGb8hXEoUzdQicYwiROOopJ/9cn0bj4VuAiLlOADOJDvrSkYSo4q2cRncAEOLXjJ0yVnZnA7Xo= 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=gueSDceB; arc=none smtp.client-ip=170.10.133.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=1712082700; 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=lMrQ/HyPcTUexiexGuHGYoI8R6rk48hQ9GiX28Xmjeo=; b=gueSDceBOKrXll08xBP7p1ZoAY4dQKfSrd3zJ9fahLT1NrZA0YCgbnus2Wm/KgUL2zJ5ze j6VRVfNd1WhoYoipzU/wRS5ncTLXnVS9WzeimD4h+e6FGixSrPFP6Ow907ENU+76/nBEWI x7jmUH93f/yRaePIALXFVyaHXqquKjk= 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-608-MTugMRCoPAKTLtGFsbj1tw-1; Tue, 02 Apr 2024 14:31:38 -0400 X-MC-Unique: MTugMRCoPAKTLtGFsbj1tw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-341cdbcbd62so2064692f8f.1 for ; Tue, 02 Apr 2024 11:31:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712082697; x=1712687497; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language: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=lMrQ/HyPcTUexiexGuHGYoI8R6rk48hQ9GiX28Xmjeo=; b=S+Vj9wN3uI6iqVtREYib7wmDLc3h/Y+WeUI/l88UqDjZ+l5lXlhziyZ9IOFLMrjlIe r4xkHtMz8ODe6LtpQA86DLWDy2VDYLibjsKDD2Otf0ZBsGvLf/p2vqo/QweC0QhHF6lr LarD1+1S7LJzUX5+P1BZdek3XfKsCc21BuX6ZoCAl9vyO7ULaN93dzIsce31Srj0Stim M/TLRifIEWQriAM8VQEnsVVYUI4pc+cS5uTHALSZ240ttbWFUox3M7ijDvdLQYHJxt5i ndOyyVNxZvRx7MHHx4hrXLcFB9MFmeeCEAOvWhf8R0rdqep8Vl3zp4foWjZci/BBPyYK 59IQ== X-Forwarded-Encrypted: i=1; AJvYcCUFy+Y96KgIRRNIfulBC1kltYMhno7m3WHJAQDWwoi56njorVOkJmzVkIHg11KPBEPqY68FtQdShSxzEJ6+DaHPaX8Ojdz7s42EL8yl X-Gm-Message-State: AOJu0Yy3XZeKHVFBDZVocub+DauykNJNhlE/qcL49uDpyTsg9kHKByBR dFlfQbEJoshF+LxAzMIxFYlon4z2TFjcrFAHhrS9A0baByG8f9JMG18WPAwNU4uErWsaP4wNAq3 ew2p8rGCEAt/SLpfka6MGlX8+pEQt1tPIMubw9+MNosMsFsfEA8Z5xzHc+WIXoQ== X-Received: by 2002:adf:b1da:0:b0:33e:ce15:85bb with SMTP id r26-20020adfb1da000000b0033ece1585bbmr7829884wra.59.1712082697491; Tue, 02 Apr 2024 11:31:37 -0700 (PDT) X-Received: by 2002:adf:b1da:0:b0:33e:ce15:85bb with SMTP id r26-20020adfb1da000000b0033ece1585bbmr7829869wra.59.1712082696983; Tue, 02 Apr 2024 11:31:36 -0700 (PDT) Received: from ?IPV6:2003:cb:c732:e600:4982:2903:710f:f20a? (p200300cbc732e60049822903710ff20a.dip0.t-ipconnect.de. [2003:cb:c732:e600:4982:2903:710f:f20a]) by smtp.gmail.com with ESMTPSA id bq24-20020a5d5a18000000b0033e45930f35sm15122595wrb.6.2024.04.02.11.31.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Apr 2024 11:31:36 -0700 (PDT) Message-ID: Date: Tue, 2 Apr 2024 20:31:35 +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: David Matlack Cc: Sean Christopherson , 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> Content-Language: en-US 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 WhVhd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X8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+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 02.04.24 19:38, David Matlack wrote: > On Wed, Mar 20, 2024 at 5:56 AM David Hildenbrand wrote: >> >> On 20.03.24 01:50, Sean Christopherson wrote: >>> Rework KVM to mark folios dirty when creating shadow/secondary PTEs (SPTEs), >>> i.e. when creating mappings for KVM guests, instead of when zapping or >>> modifying SPTEs, e.g. when dropping mappings. >>> >>> The motivation is twofold: >>> >>> 1. Marking folios dirty and accessed when zapping can be extremely >>> expensive and wasteful, e.g. if KVM shattered a 1GiB hugepage into >>> 512*512 4KiB SPTEs for dirty logging, then KVM marks the huge folio >>> dirty and accessed for all 512*512 SPTEs. >>> >>> 2. x86 diverges from literally every other architecture, which updates >>> folios when mappings are created. AFAIK, x86 is unique in that it's >>> the only KVM arch that prefetches PTEs, so it's not quite an apples- >>> to-apples comparison, but I don't see any reason for the dirty logic >>> in particular to be different. >>> >> >> Already sorry for the lengthy reply. >> >> >> On "ordinary" process page tables on x86, it behaves as follows: >> >> 1) A page might be mapped writable but the PTE might not be dirty. Once >> written to, HW will set the PTE dirty bit. >> >> 2) A page might be mapped but the PTE might not be young. Once accessed, >> HW will set the PTE young bit. >> >> 3) When zapping a page (zap_present_folio_ptes), we transfer the dirty >> PTE bit to the folio (folio_mark_dirty()), and the young PTE bit to >> the folio (folio_mark_accessed()). The latter is done conditionally >> only (vma_has_recency()). >> >> BUT, when zapping an anon folio, we don't do that, because there zapping >> implies "gone for good" and not "content must go to a file". >> >> 4) When temporarily unmapping a folio for migration/swapout, we >> primarily only move the dirty PTE bit to the folio. >> >> >> GUP is different, because the PTEs might change after we pinned the page >> and wrote to it. We don't modify the PTEs and expect the GUP user to do >> the right thing (set dirty/accessed). For example, >> unpin_user_pages_dirty_lock() would mark the page dirty when unpinning, >> where the PTE might long be gone. >> >> So GUP does not really behave like HW access. >> >> >> 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. > 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. 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 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. -- Cheers, David / dhildenb