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 BF930C4332F for ; Tue, 15 Nov 2022 09:13:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 444786B0072; Tue, 15 Nov 2022 04:13:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F4608E0001; Tue, 15 Nov 2022 04:13:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294B86B0074; Tue, 15 Nov 2022 04:13:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1B4AE6B0072 for ; Tue, 15 Nov 2022 04:13:31 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C1E271604CB for ; Tue, 15 Nov 2022 09:13:30 +0000 (UTC) X-FDA: 80135113380.03.AC4E16F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 77CF3120009 for ; Tue, 15 Nov 2022 09:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668503608; 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=9bGG1jGVV02EQAPeqlOkm4CeIaBapLMU4o4CCV8AKv8=; b=YJWTO7+6Vvyz4p8oN9SZ0cGFgJSam+Dc2tLmJhXP6mjqdt7y8SjnKBMTJKxlFNHNTBRc5Y BaRjg5/NTABvsGXPmhmW6ZgxBwKNoSUG8IAUTlfx7vWdUavWFAehA0lHrctzLHPNs2GfZZ GnyF6BRNrpdSevZ3WWNqfCpvlxpJzek= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-74-FgzK0EU5NRupSX74CW4Y9w-1; Tue, 15 Nov 2022 04:13:27 -0500 X-MC-Unique: FgzK0EU5NRupSX74CW4Y9w-1 Received: by mail-wm1-f69.google.com with SMTP id u9-20020a05600c00c900b003cfb12839d6so3560120wmm.5 for ; Tue, 15 Nov 2022 01:13:27 -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=9bGG1jGVV02EQAPeqlOkm4CeIaBapLMU4o4CCV8AKv8=; b=rlzr2f2mkw1i+V0ZdpXFo5mLs4/DuJfjSI/+61aO53ipzGATXHyYioWjp0sup2yl1z yqBWT0b6jPHf8zTWukWrZqiYVzylnjvMrcxB6Qst7Nx2nyI2gXcBzUh9iBF1GOxEbHCu J3uhGYoZ4iY8w+YiH+EYTaa4VaiY9Tjg/YHx3m5dW0s/Db/gl67pY1EuSB2ndmFiepZv pcvDIsVLvcmldjfV5wtrhy3iup2rOezYpgMy9bW5KzkBmk7qNxdeYg548+IhUoufh+A3 I0aGeiovgM/PwSuEWN9vKHkteOY4AljdiCpyZh1HxkQKFANWd1hfhXZRrpgmNDq895KK w2Ww== X-Gm-Message-State: ANoB5plTO6cIChv66RR0eHOe9Y8Ob+ig/7ly1NR1s49COcMgqAYmUcsr yI/8Asc/CbvBlWS2nFPiIaZWdDyusi06eOLupUkhLbLEOHgnn2RHiQ9BbWNHqE9gJfgehQJcW+G Nhxh/BIFo+ZI= X-Received: by 2002:a05:6000:508:b0:236:5e77:b58e with SMTP id a8-20020a056000050800b002365e77b58emr10055804wrf.320.1668503606096; Tue, 15 Nov 2022 01:13:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf5fR1dfQFe+f3e2gDVTnKiSkgViBOihC6UfuqBQMHKFk8w9A4JPD9Sub6SLnzxINQNIwBlh9g== X-Received: by 2002:a05:6000:508:b0:236:5e77:b58e with SMTP id a8-20020a056000050800b002365e77b58emr10055771wrf.320.1668503605686; Tue, 15 Nov 2022 01:13:25 -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 b15-20020adff24f000000b002345cb2723esm11723317wrp.17.2022.11.15.01.13.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 01:13:25 -0800 (PST) Message-ID: Date: Tue, 15 Nov 2022 10:13:24 +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=1668503609; 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=9bGG1jGVV02EQAPeqlOkm4CeIaBapLMU4o4CCV8AKv8=; b=whBHtjobVvxK4MDRE+gD5o2XvPmFZcx18eaUajyLA9QevKtBYrTOm7KjZGD5bReDE9iT1x L3J5bmWRsY7tn0aYgz0u0vXtC5X/KeqELLvXDv4GBIIIudv0WL5G/GtPCG1RC9zx9E0d5c 9JyrTr1o2zBlnPAIc5qqLXdBLDIshyI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YJWTO7+6; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1668503609; a=rsa-sha256; cv=none; b=Jmc1mJCVUP9j6FdbZF/PNsz7IMpx0v54GFD1qzeabUun0v1YGn0gkKsmGPrGu9R6mnhaIB hDS5rYlMukiI6cWnX88hlD3uSz7J/q4XneqYUNHrwplA2vOBZagnwbfB8heflfKmiQMeYS uek7bP0WJIICrOdA2y3+y3AdL1YGvp0= X-Stat-Signature: dh8n5sfmbsfecr9k1w83goina4uijn3g X-Rspamd-Queue-Id: 77CF3120009 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YJWTO7+6; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.133.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: 1668503609-871466 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: >> >> Any particular reason why not to simply glue this to pte_swp_uffd_wp(), >> because only that needs special care: >> >> if (pte_swp_uffd_wp(*pvmw.pte)) { >> pte = pte_wrprotect(pte); >> pte = pte_mkuffd_wp(pte); >> } >> >> >> And that would match what actually should have been done in commit >> f45ec5ff16a7 -- only special-case uffd-wp. >> >> Note that I think there are cases where we have a PTE that was !writable, >> but after migration we can map it writable. > > The thing is recovering the pte into its original form is the safest > approach to me, so I think we need justification on why it's always safe to > set the write bit. > > Or do you perhaps have solid clue and think it's always safe The problem I am having with this broader change, is that this changes something independent of your original patch/problem. If we identify this to be an actual problem, it should most probably be separate fix + backport. My understanding is that vma->vm_page_prot always tells you what the default PTE protection in a mapping is. If the mapping is private, it is never writable (due to COW). Similarly, if the shared file mapping needs writenotify, it is never writable. 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. > >> >> BTW, does unuse_pte() need similar care? >> >> new_pte = pte_mkold(mk_pte(page, vma->vm_page_prot)); >> if (pte_swp_uffd_wp(*pte)) >> new_pte = pte_mkuffd_wp(new_pte); >> set_pte_at(vma->vm_mm, addr, pte, new_pte); > > I think unuse path is fine because unuse only applies to private mappings, > so we should always have the W bit removed there within mk_pte(). You're right, however, shmem swapping confuses me. Maybe that does not apply here. -- Thanks, David / dhildenb