Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp484383rdb; Tue, 23 Jan 2024 05:55:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHYqUxUcPfnkfhzor93t9alR9fPYiNWxjMZGbZESfZ5+dY3tDwVnEQhAEGS3K3TWbyyqJr X-Received: by 2002:aa7:d4d9:0:b0:55a:5840:c649 with SMTP id t25-20020aa7d4d9000000b0055a5840c649mr861033edr.77.1706018126771; Tue, 23 Jan 2024 05:55:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706018126; cv=pass; d=google.com; s=arc-20160816; b=Cae9wHdQvWjT78sopXptUSveAd8vmfGgeZhmJA+OuMe9bhGh3WT/GweTwfFIk53PIR 0Luw8A4/O9PfFvO9OFJzQGBjqpNVHXTWianWlLo54IHIZVYXEmsdjPg2ZvYIU38+Bppm PUd29Y1Qa9+eGsnTSW06GedhncGnHho5HXj4IEAgGwKgKqMjmWzBUrKpm2KxNL5LKZZT 9dPDyVBFiFiTzwlyLIXAiPkN2erMs5H1ti2JIBqp8fxOLWe0IJQv29Nwr8eTPn0LVLVM 8wBj3eE4nnmCYw3ymfaZXAm96c+vTR6czT1XSWtbnKh6gqM3a+JaoFfGklj08u+GwdBR GWwg== 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 :references:cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=WbJQ58Ljpuy8Vw/B7ZBTw3hv4ANT/jjJ7tp8ylORPFw=; fh=9VMDQ/UKJLnwnZ6CmYFxGfN8CgZ3YAgaG42Qqnv7mwQ=; b=PpcmVAos0smw2mmfULsczG8pnUsGgQ18KsxeCMvqKHzY0ToAuN0VKhUpcUOnJmOh+l gj0ZhrPlCd6CWL07lUUlVoINsVGkIy79C7150YbgbfBA1pwfgYw1JxFmA4RW9UoTwae4 lSljwpxa7Jge+s9ozZEbgsNLjpc7use0ttKjmL1TeXTSYcALS/3CjN/cMXV0m2zQJXvx qNqAp9ZNFIlhfKuMVF6r0d4ITyr+ddVZ+KEjxmC1DaGsVEwTjdNOK2eCLagyNh1tFD+A 05Ly+kajUV24bp6xnbhVihf+nBdN4PAsX0bO1r7tHhRg2w0Rq4j/irn+UOGig8Ntd11O 8G/Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=asDsAfLj; 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-35410-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35410-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 x4-20020aa7dac4000000b0055c868c7d76si657790eds.333.2024.01.23.05.55.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 05:55:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35410-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=asDsAfLj; 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-35410-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35410-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 1FA011F25AAC for ; Tue, 23 Jan 2024 13:55:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D8435F578; Tue, 23 Jan 2024 13:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="asDsAfLj" 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 22BF45F56C for ; Tue, 23 Jan 2024 13:55:12 +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=1706018114; cv=none; b=S++g/AH4XK2stgNLBMOwop1NDUpA+kI6DAzBVCDLi5oZALJ3yB6+GItORQIeyns4rw9kVZdoMyS9USvhWIq2xm1q1Le0YrjXRF6m8B89lX8AaXToe24kPvRvzBpvLcggW6wpXEXul3qcABhEZVwvvGC+Q5LDvnDI4TzkR6kSas8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706018114; c=relaxed/simple; bh=H20HIdDwKk+Z1z3xGM1RE4qVtkFXkzG6kVrv6ifHtNw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NlZgIopTCmBtCLjet8817oiM6kY6uE3YHOdrFiCx1hZJlDnw2/eMOww48RovwGR+vLvWWIi0m2NTvIyShctIbvg7tnvsE/oo1G6Do59dEOCnn+fR37Z1TDCfGOotL37Mykwz7MRHmIlqgVvYdpty/d9MmCjN82ukOzDZZrXe+d4= 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=asDsAfLj; 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=1706018112; 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=WbJQ58Ljpuy8Vw/B7ZBTw3hv4ANT/jjJ7tp8ylORPFw=; b=asDsAfLjOMmV6XyLHJ3luV+vhSVP37HMPDmgq/625X5Qn/WPzA1lDPwwRuf0GZ1yM5keRp tLToJ352mN9Qq9d7qXvn6forUMJ1Q0z0Wem29U4qf7oqLcyrQtzZ8yUddOqgfLnJqZRxmD ylQni1S2kuNad4LRO98U9YPqXs7OBUE= 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-605-St9Px_8oOdC8EzvfwNtaHA-1; Tue, 23 Jan 2024 08:55:10 -0500 X-MC-Unique: St9Px_8oOdC8EzvfwNtaHA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-337d589ef4dso2964030f8f.0 for ; Tue, 23 Jan 2024 05:55:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706018109; x=1706622909; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WbJQ58Ljpuy8Vw/B7ZBTw3hv4ANT/jjJ7tp8ylORPFw=; b=evcnNdKW6fk/+04Hq/tjWvat24PPZojyA8hQrOKIF4/Ii9cDnP7C6zAgCImZ0Kbe6N FTalvxyGZlka2G0v4IjKrdZCVjmaMu2uN/p4UUAezsy6ws0zcnX5kTJfC596sKJs8hW8 Cs2roI08RevJptDRDPQoK9qciTxR1XOpUa9t2V/ZbYeDkZHxQtZXz0t5EesKlEPzSFqt 14/oETxI/JH2HzMdbVgc1eS7bYr0+uok9Sga+oc7Nwk+kjvZZpDSIjCaKtyKI+f6ICdI r6uhkbmofEk6tSzAsqi+fNgSGLjyfjcS19Xqp5ugF4EQYB8f3LV7HJIrwPP5o0rBDW/8 IQiA== X-Gm-Message-State: AOJu0Yy+ezJWR2f9hg8/sQ+6ZkvkBiONJX1gN+Qbrl5Ao8ePIRYKHf00 hLBQj49+JK94vyGACzd4CfTk2LJrwL+3b41wnv9m43Un4aSVyh3eXcnAbzy3IFiX7zQTxDmbO3l hvCVEM6bDn0sjJf7M7F3TdAEDPfDoDHT3nqpjAk8lUpLRa6qMG6ULErDvgnoxtg== X-Received: by 2002:adf:e501:0:b0:337:b53e:6065 with SMTP id j1-20020adfe501000000b00337b53e6065mr3769041wrm.41.1706018109547; Tue, 23 Jan 2024 05:55:09 -0800 (PST) X-Received: by 2002:adf:e501:0:b0:337:b53e:6065 with SMTP id j1-20020adfe501000000b00337b53e6065mr3769019wrm.41.1706018109107; Tue, 23 Jan 2024 05:55:09 -0800 (PST) Received: from ?IPV6:2003:cb:c741:de00:bf0f:cd46:dc1c:2de9? (p200300cbc741de00bf0fcd46dc1c2de9.dip0.t-ipconnect.de. [2003:cb:c741:de00:bf0f:cd46:dc1c:2de9]) by smtp.gmail.com with ESMTPSA id l11-20020a5d674b000000b003392c727cadsm7565717wrw.27.2024.01.23.05.55.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jan 2024 05:55:08 -0800 (PST) Message-ID: Date: Tue, 23 Jan 2024 14:55:06 +0100 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: [PATCH v1 10/11] mm/memory: ignore dirty/accessed/soft-dirty bits in folio_pte_batch() Content-Language: en-US To: Ryan Roberts , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org References: <20240122194200.381241-1-david@redhat.com> <20240122194200.381241-11-david@redhat.com> <59592b50-fe89-4b32-8490-2e6c296f972f@arm.com> <76740e33-9b52-4e23-b407-8ae38bac15ec@redhat.com> <94d33a07-c59a-4315-9c64-8b4d959ca1f4@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uO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sb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+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: <94d33a07-c59a-4315-9c64-8b4d959ca1f4@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 23.01.24 14:42, Ryan Roberts wrote: > On 23/01/2024 13:06, David Hildenbrand wrote: >> On 23.01.24 13:25, Ryan Roberts wrote: >>> On 22/01/2024 19:41, David Hildenbrand wrote: >>>> Let's ignore these bits: they are irrelevant for fork, and will likely >>>> be irrelevant for upcoming users such as page unmapping. >>>> >>>> Signed-off-by: David Hildenbrand >>>> --- >>>>   mm/memory.c | 10 ++++++++-- >>>>   1 file changed, 8 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/mm/memory.c b/mm/memory.c >>>> index f563aec85b2a8..341b2be845b6e 100644 >>>> --- a/mm/memory.c >>>> +++ b/mm/memory.c >>>> @@ -953,24 +953,30 @@ static __always_inline void __copy_present_ptes(struct >>>> vm_area_struct *dst_vma, >>>>       set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr); >>>>   } >>>>   +static inline pte_t __pte_batch_clear_ignored(pte_t pte) >>>> +{ >>>> +    return pte_clear_soft_dirty(pte_mkclean(pte_mkold(pte))); >>>> +} >>>> + >>>>   /* >>>>    * Detect a PTE batch: consecutive (present) PTEs that map consecutive >>>>    * pages of the same folio. >>>>    * >>>>    * All PTEs inside a PTE batch have the same PTE bits set, excluding the PFN. >>> >>> nit: last char should be a comma (,) not a full stop (.) >>> >>>> + * the accessed bit, dirty bit and soft-dirty bit. >>>>    */ >>>>   static inline int folio_pte_batch(struct folio *folio, unsigned long addr, >>>>           pte_t *start_ptep, pte_t pte, int max_nr) >>>>   { >>>>       unsigned long folio_end_pfn = folio_pfn(folio) + folio_nr_pages(folio); >>>>       const pte_t *end_ptep = start_ptep + max_nr; >>>> -    pte_t expected_pte = pte_next_pfn(pte); >>>> +    pte_t expected_pte = __pte_batch_clear_ignored(pte_next_pfn(pte)); >>>>       pte_t *ptep = start_ptep + 1; >>>>         VM_WARN_ON_FOLIO(!pte_present(pte), folio); >>>>         while (ptep != end_ptep) { >>>> -        pte = ptep_get(ptep); >>>> +        pte = __pte_batch_clear_ignored(ptep_get(ptep)); >>>>             if (!pte_same(pte, expected_pte)) >>>>               break; >>> >>> I think you'll lose dirty information in the child for private mappings? If the >>> first pte in a batch is clean, but a subsequent page is dirty, you will end up >>> setting all the pages in the batch as clean in the child. Previous behavior >>> would preserve dirty bit for private mappings. >>> >>> In my version (v3) that did arbitrary batching, I had some fun and games >>> tracking dirty, write and uffd_wp: >>> https://lore.kernel.org/linux-arm-kernel/20231204105440.61448-2-ryan.roberts@arm.com/ >>> >>> Also, I think you will currently either set soft dirty on all or none of the >>> pages in the batch, depending on the value of the first. I previously convinced >>> myself that the state was unimportant so always cleared it in the child to >>> provide consistency. >> >> Good points regarding dirty and soft-dirty. I wanted to avoid passing flags to >> folio_pte_batch(), but maybe that's just what we need to not change behavior. > > I think you could not bother with the enforce_uffd_wp - just always enforce > uffd-wp. So that's one simplification vs mine. Then you just need an any_dirty I think I'll just leave uffd-wp alone for now, corner case with fork/munmap that can be optimized later on top if really needed. Regarding soft-dirty (which is set automatically much more often), I can certainly ignore the bit if !vma_soft_dirty_enabled(vma) [which is true in most of the cases]. So that's easy to handle. But likely, soft-dirty for the child is completely unexpressive and should always be cleared. Have to double check what the vmflag will be for the child process. > flag following the same pattern as your any_writable. Then just set dirty on the > whole batch in the child if any were dirty in the parent. Regarding dirtying, I'm not 100% sure yet if we should just always dirty all ptes if any is dirty, or if we should preserve the state for private VMAs for now. > > Although now I'm wondering if there is a race here... What happens if a page in > the parent becomes dirty after you have checked it but before you write protect > it? Isn't that already a problem with the current non-batched version? Why do we > even to preserve dirty in the child for private mappings? I suspect, because the parent could zap the anon folio. If the folio is clean, but the PTE dirty, I suspect that we could lose data of the child if we were to evict that clean folio (swapout). So I assume we simply copy the dirty PTE bit, so the system knows that that folio is actually dirty, because one PTE is dirty. Touching only PTEs avoids having to mess with folio flags. But that's just pure speculation. E.g., fs/proc/task_mmu.c does some slightly different accounting if a PTE is dirty. But usually, it checks if either the PTE or the folios is dirty. I'll have to do some more digging. -- Cheers, David / dhildenb