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 A80D0C433FE for ; Tue, 15 Nov 2022 17:22:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23DFE6B0073; Tue, 15 Nov 2022 12:22:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EE066B0074; Tue, 15 Nov 2022 12:22:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B5B26B0075; Tue, 15 Nov 2022 12:22:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F1E1D6B0073 for ; Tue, 15 Nov 2022 12:22:09 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CDFDE1C32D0 for ; Tue, 15 Nov 2022 17:22:09 +0000 (UTC) X-FDA: 80136344778.20.87DD3DF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id EFD3318000C for ; Tue, 15 Nov 2022 17:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668532928; 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=m8l4pIGrlIpw/sxoSKlU1ZG63LGDo4ZciEpI8QjHdn0=; b=REjm43rG1kStr1lG0116jUobaWMYAxG6/vUaYu/5O7/pNRiGngviGXMLxylW31B2GoniYd JfbEoQhpTbbXQKO7FzwYb+d1x3K/GqSxHiMnHLFONdvvu5PJBhzddkOf+o862ImgIF/wTx qcBOshnaAfP+N0OrrbUMIcU+gIRRfow= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-155-pm9nclYdPW-JJZ5MYTqLeQ-1; Tue, 15 Nov 2022 12:22:07 -0500 X-MC-Unique: pm9nclYdPW-JJZ5MYTqLeQ-1 Received: by mail-wm1-f71.google.com with SMTP id j2-20020a05600c1c0200b003cf7397fc9bso8582232wms.5 for ; Tue, 15 Nov 2022 09:22:06 -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:subject:organization:from :content-language:references:cc:to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=m8l4pIGrlIpw/sxoSKlU1ZG63LGDo4ZciEpI8QjHdn0=; b=eg4QadDY3qPzotZybI4vB+wplnTw6/Vxvpv4vHn7tikGgjffaKyC+6n3iCGsMb940V OMK/+FxBEKFFXrz5WL5/hPfRCiv6VdvtfugPjxNiJpc/X8YMNDn69gvCDDGQo8aQlu/z CNM9yI1lO+2DMb22l3dht9YrGIabcbR8aJV7nd8618H86tdNxl83qzSGZYNVOWdXbcuY /NAg2euMagwi6ieTGJZm6/4KAdb5my0gvw2w0M2gtNpcTrLY8tZ9nyNeAUdaiQCvor7U 2DLKYJNqokVi/xTVXzX0rvTE0BdHTdo49UVIh9tlrRBZJ28utHTVWAiAjxbCK5tA0I5e 5/Iw== X-Gm-Message-State: ANoB5pm208PE4zznJkIf7o3FDfO+ALaijCyD7fRLpyty/D02yJsQBfox u/FIGepFH1LcwExffIztw6XZVQgeQEyrsMY+SdLzXk5AzYWpnHO0xUOFTzSPFzqX5adKbwLdOND Lw2O6bCxi8TE= X-Received: by 2002:adf:bb43:0:b0:22e:6f0d:d69 with SMTP id x3-20020adfbb43000000b0022e6f0d0d69mr11781324wrg.134.1668532925865; Tue, 15 Nov 2022 09:22:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7FOlUtjvvU7F7kEfxG6kLCcch/2duEN2plX5JnnVuNV6ZxayUzFm3GisnIqxJlCULGLioKDg== X-Received: by 2002:adf:bb43:0:b0:22e:6f0d:d69 with SMTP id x3-20020adfbb43000000b0022e6f0d0d69mr11781292wrg.134.1668532925275; Tue, 15 Nov 2022 09:22:05 -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 r11-20020a5d694b000000b0023691d62cffsm12679101wrw.70.2022.11.15.09.22.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 09:22:04 -0800 (PST) Message-ID: <82d7a142-8c78-4168-37e9-7b677b18987a@redhat.com> Date: Tue, 15 Nov 2022 18:22:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 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> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 1/2] mm/migrate: Fix read-only page got writable when recover pte In-Reply-To: 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668532929; 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=m8l4pIGrlIpw/sxoSKlU1ZG63LGDo4ZciEpI8QjHdn0=; b=g3uiOVWddYi7YpVcf1iqH23o/5mjm/taKYGQON3iO/PoQOW+RE7Mjs48PYb1Uo8iSEGjG9 LUC5x90jXe1kJ2XsRmenFoKDYagmY+bVEAyRhjBbQ/YPQ8+vJdnal3rhfa6D6cb9efTqJn b+0Q16Vvv3o0BuN93rqFt04ZPfrEo+4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=REjm43rG; spf=pass (imf16.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=1668532929; a=rsa-sha256; cv=none; b=CjMOxiH5VLu7KYVL9HxCQ/eMHIO4tuFZZwyndnYZOCCVVng/8szzCjPz+q/cNXtLue3QhD ImV3gQahIOxzckpxlHvFOmw3Lg2kRZgtR7cbvx5qiUJxoIWMXiR2RxiYsKjWWEQ1ijmDyc vJXptWsmVURxtf8RFQRaUThYN5lhL2w= X-Stat-Signature: qj3b9d5yxg8hkjcz6bq43yo6y94wimjo X-Rspamd-Queue-Id: EFD3318000C Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=REjm43rG; spf=pass (imf16.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-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1668532928-216429 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: >> 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". > > For "natural", I meant fundamentally we're talking about page migrations > here. The natural way (at least to me) for page migration to happen as a > fundamental rule is that, we leverag the migration pte to make sure the pte > being stable so we can do the migration work, then we "recover" the pte to > present either by a full recovery or just (hopefully) only replace the pfn, > keeping all the rest untouched. > > One thing to prove that is we have two migration entries not one (I'm > temporarily put the exclusive read one aside since that's solving different > problems): MIGRATION_READ and MIGRATION_WRITE. If we only rely on vma > flags logically we don't need MIGRATION_READ and MIGRATION_WRITE, we only > need MIGRATION generic swap pte then we recover the write bit from vma > flags and other things (like uffd-wp, currently we have the bit set in swap > pte besides the swap entry type). > > So maybe one day we can use two migration types rather than three > (MIGRATION and MIGRATION_EXCLUSIVE)? I can't tell, but hopefully that > shows what I meant, that we need further justification to grant write bit > only base on vma, rather than recovering write bit based on migration entry > type. That's precisely what I had in mind recently, and I am happy to hear that you have similar idea: https://lkml.kernel.org/r/20221108174652.198904-6-david@redhat.com " Note that we don't optimize for the actual migration case: (1) When migration succeeds the new PTE will not be writable because the source PTE was not writable (protnone); in the future we might just optimize that case similarly by reusing can_change_pte_writable()/can_change_pmd_writable() when removing migration PTEs. " Currently, "readable_migration_entry" is even wrong: it might be PROT_NONE and not even readable. -- Thanks, David / dhildenb