Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp516780rdb; Tue, 23 Jan 2024 06:42:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhDqgKIiOhmW9QIuV9liDazXPH/3NjV2vOLP/a2ulNDMIkjNvIGanYW+yEfUENHpQlPb22 X-Received: by 2002:a05:6a20:4e1b:b0:199:dcb2:8756 with SMTP id gk27-20020a056a204e1b00b00199dcb28756mr6596055pzb.59.1706020926184; Tue, 23 Jan 2024 06:42:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706020926; cv=pass; d=google.com; s=arc-20160816; b=IusI7xOUJm23HlbdR6F0rKtKkgr4VHboN0MIp2nq6PmEUVT5am0gL1sILsPGmcCP3a Vj8Ba6l/mHvXafG9bf4XMyqk60Ppo3VTIb6slGnSC1qJjYrOfsAZAV2V5PT1eWQ3fEtz 0fo+MCQUe14cGlnHssmDhKC7qs47fkAn+UCqVXODo4eTJAZyU5NSCY/mkB63gNL4gny3 +gY956sp2rUfMMYrOdH2KlMBhYaG10GTq5KpQ/OVpVx1wxYNS388byxfrIPeroIw253T fod8IG/+T2wI9vn5qYYHMCZNkrSsYvQH6Ny5mniuVBrDjQPBfxz/kJCfv1Gcc/o4xug6 dfWA== 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 :references:cc:to:from:content-language:subject:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id:dkim-signature; bh=RwS+5giCvfOuuu1oeULF7LgReztaNbk26JYEakmOz0E=; fh=9VMDQ/UKJLnwnZ6CmYFxGfN8CgZ3YAgaG42Qqnv7mwQ=; b=M/lDIKc8ykyGtZbp8rZ9Kpr9IVTTzQjLexHVrqQSVnE3FHSi4LA3FJR+kiAfqXHm6Z gPHJ04G5EBzeGORJ9nMZNFsJQnxiZkzbNGpiiL3S+U+jxDP09XZSxTkKAKR1qeHHgqXF XhXpD8/tvBzrhA8Yn8ruDhrnGAs26LrDY7578AEse3n1XkyGNX9SiPba4DYGsrfS+26Y a1JHcKYbzZ1up8oYsa+S2uNielXsdZfllI7FAGbmSYWKINqIfvgMCLptr6h1zFbZ2CMs W8N1lM82+DUM4A0Av1NLj7tJNOYC8oJJ9KRyytHeBU9TQGCZqB4IDGATvhmXPMBPYT+y ljvA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HfXP3yTF; 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-35431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35431-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x37-20020a634865000000b005ce574756bfsi921441pgk.659.2024.01.23.06.42.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 06:42:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HfXP3yTF; 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-35431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35431-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EAABFB278F1 for ; Tue, 23 Jan 2024 14:14:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FACE5FF0C; Tue, 23 Jan 2024 14:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HfXP3yTF" 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 8E0845FDB4 for ; Tue, 23 Jan 2024 14:13:41 +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=1706019223; cv=none; b=gDYDeazg4iZmL1+mgtMre6Cnn48EP1PODVZbU5GUuiZW6kdDYD+5NWXcXWsUvZSVX7nG3+ag53v01WkQn7HXTAkAUK0xVy1F9lUntSObUr/jSDKaWhvP295SRwx/GR7muf/ZF4rntnLhvDrPxsRsl1NjhnQkk0J6HqbZTvJFHbQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706019223; c=relaxed/simple; bh=JXniqWhpXjjSE85A2+O+umaCKvwDugv6FvrDPXKER24=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=hps+BMTk6y8rszp9JhLqvwCWogoBkD3nMJChLDEiqSLXUxnoaey13/EqFGhLAkDXTWaVx79oy3QCbLuCmFe506QhFYmDrwTkzGc5dNEiI4eYuSaKp+hJa6xUmcgq2fNe3R0Y86W8QMgnBQB0PMRXBnWNeDnsTtxQpiGQABde2E0= 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=HfXP3yTF; 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=1706019220; 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=RwS+5giCvfOuuu1oeULF7LgReztaNbk26JYEakmOz0E=; b=HfXP3yTFCkfey2YRGQkmypRK4uBCWRDuymq743Vxogv6JUzRH7/IxlXKvoYzgIk1hvxN+K UuoE5tP1b5sAhuUaI3EWPJ0GBgr2fbcn5hK4rKDOHRvHabYbv+/rlS13b38BKbzew4K6AX bjQDQBZWzcRlZ8Rk4ZDkJXJQW7SnRyY= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-z5FTPziOPk2_0aGO1MrFIQ-1; Tue, 23 Jan 2024 09:13:38 -0500 X-MC-Unique: z5FTPziOPk2_0aGO1MrFIQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-337bf78ef28so1847441f8f.3 for ; Tue, 23 Jan 2024 06:13:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706019218; x=1706624018; h=content-transfer-encoding:in-reply-to:organization:autocrypt :references:cc:to:from:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=RwS+5giCvfOuuu1oeULF7LgReztaNbk26JYEakmOz0E=; b=C3bvl/3NAstHGjPBIS8G2P3zpGLg9Rk8NP6ZLJJWpBZAb2FVTxgXfdA65m/zanp2kH FG0ypZElmplAxnnnZ2QxpX9GNV3djM0ScuUbikFMath7ORHi7wfhE9at7bcfgYk61GAS oZqBR3svXSkl8blOqL+pu3EtvfIa8wHmCLyrnp77nyCB3sFyGOLUT5wHqWFYArpnwXEb vdWk9BmTRpus//WRf8k6C/TX212ZKp8V5LECWCF9SbAAh5MlVbJ0AaLSsZ3CUDJL1anr d79mOXFLBJqFpLWXJHd1xeGSYk2fc41NXovXhcg75HHqJafp9b96HazoROL9Nx/bBGH+ zrqQ== X-Gm-Message-State: AOJu0YxZ5rY4VialBoF/hFSmE2R2k3EkI2g+FTascy46L709sS17cZ5D NjxWd39dbBbScCJrozEWKvSiCVON+20H71w+2GACYgRfIFBA7R8cqnlp04dFqqhVavw7SbXzwI7 nepZadwSMQMM+u6BpNpTVnAcVa9hrk7zZe7VcNYoyTygMOD136zdMtPJULUiqZA== X-Received: by 2002:a5d:5886:0:b0:337:bf93:7596 with SMTP id n6-20020a5d5886000000b00337bf937596mr3834969wrf.85.1706019217861; Tue, 23 Jan 2024 06:13:37 -0800 (PST) X-Received: by 2002:a5d:5886:0:b0:337:bf93:7596 with SMTP id n6-20020a5d5886000000b00337bf937596mr3834939wrf.85.1706019217481; Tue, 23 Jan 2024 06:13:37 -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 cg13-20020a5d5ccd000000b0033927ccc725sm9100696wrb.50.2024.01.23.06.13.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jan 2024 06:13:37 -0800 (PST) Message-ID: <8eb5db8e-33cc-4cbf-a1bf-0da7af230fab@redhat.com> Date: Tue, 23 Jan 2024 15:13:35 +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 From: David Hildenbrand 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> Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1Im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BTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit >> 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. Oh, and regarding your race concern: it's undefined which page state would see if some write is racing with fork, so it also doesn't matter if we would copy the PTE dirty bit or not, if it gets set in a racy fashion. I'll not experiment with: From 14e83ff2a422a96ce5701f9c8454a49f9ed947e3 Mon Sep 17 00:00:00 2001 From: David Hildenbrand Date: Sat, 30 Dec 2023 12:54:35 +0100 Subject: [PATCH] mm/memory: ignore dirty/accessed/soft-dirty bits in folio_pte_batch() Let's always ignore the accessed/young bit: we'll always mark the PTE as old in our child process during fork, and upcoming users will similarly not care. Ignore the dirty bit only if we don't want to duplicate the dirty bit into the child process during fork. Maybe, we could just set all PTEs in the child dirty if any PTE is dirty. For now, let's keep the behavior unchanged. Ignore the soft-dirty bit only if the bit doesn't have any meaning in the src vma. Signed-off-by: David Hildenbrand --- mm/memory.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7690994929d26..9aba1b0e871ca 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -953,24 +953,44 @@ static __always_inline void __copy_present_ptes(struct vm_area_struct *dst_vma, set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr); } +/* Flags for folio_pte_batch(). */ +typedef int __bitwise fpb_t; + +/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */ +#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0)) + +/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bit. */ +#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) + +static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags) +{ + if (flags & FPB_IGNORE_DIRTY) + pte = pte_mkclean(pte); + if (likely(flags & FPB_IGNORE_SOFT_DIRTY)) + pte = pte_clear_soft_dirty(pte); + return 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. + * the accessed bit, dirty bit (with FPB_IGNORE_DIRTY) and soft-dirty bit + * (with FPB_IGNORE_SOFT_DIRTY). */ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, - pte_t *start_ptep, pte_t pte, int max_nr) + pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags) { 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), flags); 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), flags); if (!pte_same(pte, expected_pte)) break; @@ -1004,6 +1024,7 @@ copy_present_ptes(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma { struct page *page; struct folio *folio; + fpb_t flags = 0; int err, nr; page = vm_normal_page(src_vma, addr, pte); @@ -1018,7 +1039,12 @@ copy_present_ptes(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma * by keeping the batching logic separate. */ if (unlikely(!*prealloc && folio_test_large(folio) && max_nr != 1)) { - nr = folio_pte_batch(folio, addr, src_pte, pte, max_nr); + if (src_vma->vm_flags & VM_SHARED) + flags |= FPB_IGNORE_DIRTY; + if (!vma_soft_dirty_enabled(src_vma)) + flags |= FPB_IGNORE_SOFT_DIRTY; + + nr = folio_pte_batch(folio, addr, src_pte, pte, max_nr, flags); folio_ref_add(folio, nr); if (folio_test_anon(folio)) { if (unlikely(folio_try_dup_anon_rmap_ptes(folio, page, -- 2.43.0 -- Cheers, David / dhildenb