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 203D2C433FE for ; Tue, 15 Nov 2022 17:54:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50EE58E0001; Tue, 15 Nov 2022 12:54:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BE6E6B007B; Tue, 15 Nov 2022 12:54:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35F108E0001; Tue, 15 Nov 2022 12:54:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 271A46B0075 for ; Tue, 15 Nov 2022 12:54:17 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EB5D1AB5DD for ; Tue, 15 Nov 2022 17:54:16 +0000 (UTC) X-FDA: 80136425712.03.C3D05C8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 8DFAB14000C for ; Tue, 15 Nov 2022 17:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668534856; 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; bh=uzsXZUjzU9Tvku34iqNRXqR/c9ishDJ+OI6Nt0ZJdPc=; b=GHfMvwKCiB4WdnXT9xe7sOCgttwYq0EVrMvRAp98lLu66+GXPIBoZcIKMbpU48MKbhFerR 8RtDJ92sOYS7uF3GakiFaaea7UmZa6s821C7Rg8u+x19tHaKBRpVcwp7YudpbeEPW+inD3 fsBm7Qn8EyKRxK3vwLjYNA5eE7LcbP0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-253-zd7dKDdaPu6VkUTMV38eeg-1; Tue, 15 Nov 2022 12:54:12 -0500 X-MC-Unique: zd7dKDdaPu6VkUTMV38eeg-1 Received: by mail-wm1-f72.google.com with SMTP id z18-20020a05600c221200b003cf7fcc286aso3979769wml.1 for ; Tue, 15 Nov 2022 09:54:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization: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=uzsXZUjzU9Tvku34iqNRXqR/c9ishDJ+OI6Nt0ZJdPc=; b=vmMIKZ1+tob18p8ME2UeDiKS7Vt0QI6aptxlbw08OWLOJBJ7+W0b+oAczDZ4umciDO VGvicOf0TDE19+Jn1Q0EyPKCy/isCS4vBSa39oQMcDx8UjSxRKjbkyqX+oJ4thMJ+Szt JkKXNbkgiZ8qFyAEtbkJ9q84uCSvdosEmPwehRzYSUn4JtIUPP54YiqVA2J0+0Ri6Pfq pVA7/SGo1B1PsZB4hQE/8p7+koezdhYsKI9E/W1W33kaqZL6TQ9NGKQ+HVxMrWaZ3c+W H2m+s3QY+pLnXC82JyBcPLMNJ9q6ctap7G+SC60t6yyqKkSDnQThZSeMT+nMnmIvSZeJ AzSg== X-Gm-Message-State: ANoB5pkMPMG39qNRUeNedEhB88DsHeTdwjfyHiX/4ESCykyQk6dFKs6i b3rdYQ7GU8gAAnRKf8eboTLVxGN4sMIggiFyuzHl53uuiWc5+Jd0e3VS9LM4Asmw6qqgaXM/b7H KcriVwzFsbyM= X-Received: by 2002:a7b:c4c7:0:b0:3cf:d58f:f66e with SMTP id g7-20020a7bc4c7000000b003cfd58ff66emr1250030wmk.165.1668534851622; Tue, 15 Nov 2022 09:54:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6K+CGiRDbCQ2KRVGAKLsIuam+vG0fIXgaiakr/jVXt3paVvOZlfQEzsQil6+QkbVPr7qTsvg== X-Received: by 2002:a7b:c4c7:0:b0:3cf:d58f:f66e with SMTP id g7-20020a7bc4c7000000b003cfd58ff66emr1250008wmk.165.1668534851218; Tue, 15 Nov 2022 09:54:11 -0800 (PST) Received: from ?IPV6:2003:cb:c707:9d00:9303:90ce:6dcb:2bc9? (p200300cbc7079d00930390ce6dcb2bc9.dip0.t-ipconnect.de. [2003:cb:c707:9d00:9303:90ce:6dcb:2bc9]) by smtp.gmail.com with ESMTPSA id p14-20020a5d458e000000b0022eafed36ebsm12978003wrq.73.2022.11.15.09.54.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 09:54:10 -0800 (PST) Message-ID: <2ed12722-2359-cb07-53e7-566d959d311e@redhat.com> Date: Tue, 15 Nov 2022 18:54:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH v2 1/2] mm/migrate: Fix read-only page got writable when recover pte From: David Hildenbrand To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrea Arcangeli , Axel Rasmussen , Ives van Hoorne , Nadav Amit , Andrew Morton , Mike Rapoport , stable@vger.kernel.org References: <20221110203132.1498183-1-peterx@redhat.com> <20221110203132.1498183-2-peterx@redhat.com> <9af36be3-313b-e39c-85bb-bf30011bccb8@redhat.com> <82d7a142-8c78-4168-37e9-7b677b18987a@redhat.com> Organization: Red Hat In-Reply-To: <82d7a142-8c78-4168-37e9-7b677b18987a@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GHfMvwKC; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668534856; a=rsa-sha256; cv=none; b=WWEdcgAknhlPwocMdbf95BulR0uuUKfwQ7UNSp/NX6z460LnOnepvzMXyq3I/pUQYULFNM 16/DEcW00rC8/vtp8ac8+r7XDbfBHxA6H5ZPrI5nOCENDFvXMEKqVQqXkEzFzJPyn7sKO2 ATk+iT8pJ3nvxAYxwKI9mSv+D/Ja7WQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668534856; 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=uzsXZUjzU9Tvku34iqNRXqR/c9ishDJ+OI6Nt0ZJdPc=; b=ChIXzgV5iug4KLGLtpdQgNq6MErq8RcUqqNa8u0PjL77NYl2zKX0UKnbCaOE3JwzT/xrRh gdJ4mrArMNVAMRetWmHAmH780cG2MMqss/xMPIrWNBU3Te8NGTZRIgHTEFWjRJYXosWAyZ nWu2/z30Z4TNAGFsmr8/AhfY9PiC+Co= X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GHfMvwKC; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: ufikris51gdfuukm1yja63wgdh71mcx4 X-Rspamd-Queue-Id: 8DFAB14000C X-Rspamd-Server: rspam09 X-HE-Tag: 1668534856-379170 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: On 15.11.22 18:22, David Hildenbrand wrote: >>> I consider UFFD-wp a special case: while the default VMA protection might >>> state that it is writable, you actually want individual PTEs to be >>> write-protected and have to manually remove the protection. >>> >>> softdirty tracking is another special case: however, softdirty tracking is >>> enabled for the whole VMA. For remove_migration_pte() that should be fine (I >>> guess) because writenotify is active when the VMA needs to track softdirty >>> bits, and consequently vma->vm_page_prot has the proper default permissions. >>> >>> >>> I wonder if the following (valid), for example is possible: >>> >>> >>> 1) clear_refs() clears VM_SOFTDIRTY and pte_wrprotect() the pte. >>> -> writenotify is active and vma->vm_page_prot updated accordingly >>> >>> VM_SOFTDIRTY is reset due to VMA merging and vma->vm_page_prot is updated >>> accordingly. See mmap_region() where we set VM_SOFTDIRTY. >>> >>> If you now migrate the (still write-protected in the PTE) page, it was not >>> writable, but it can be writable on the destination. >> >> I didn't even notice merging could work with soft-dirty enabled, that's >> interesting to know. >> >> Yes I think it's possible and I agree it's safe, as VM_SOFTDIRTY is set for >> the merged vma so afaiu the write bit is safe to set. We get a bunch of >> false positives but that's how soft-dirty works. >> >> I think the whole problem is easier if we see this at a higher level. >> You're discussing this from vma pov and it's fair to do so, at least I >> agree with what you mentioned so far and I can't see anything outside >> uffd-wp that can be affected. However, it is also true when you noticed we >> already have quite a few paragraphs trying to discuss the safety for this >> and that, that's the part where I think we need justification and it's not >> that "natural". Forgot to reply to that part: No it isn't natural. But sneaking such a change into your fix seems wrong. Touching !uffd-wp code should be separate, if we want to do this at all (as we discussed, maybe the better/cleaner approach is to eliminate writable migration entries if possible). -- Thanks, David / dhildenb