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 71101C77B7A for ; Wed, 17 May 2023 08:34:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B4C3900008; Wed, 17 May 2023 04:34:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06595900006; Wed, 17 May 2023 04:34:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E485C900008; Wed, 17 May 2023 04:34:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D52DF900006 for ; Wed, 17 May 2023 04:34:49 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 90E161C7092 for ; Wed, 17 May 2023 08:34:49 +0000 (UTC) X-FDA: 80799086298.24.6683B3D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 6C31A140017 for ; Wed, 17 May 2023 08:34:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K1pZIcFP; spf=pass (imf23.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684312487; 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=WoyE4KJMZkzKP/aXFBkcgtSqzW5vCFF351V1GgKfqTs=; b=Ci67EKyW6FiAFjg7kHffWOTRBt3XZpENpaRcbhQFsNuZ0trArp2ID21EWnyB6z8JFA/wX6 FcIpvjthIwQVeiYSydndAOhej0plusNTk1l0r6a5iaS384Vyvx5LdPvcW8flGUrMhGtBIm S+KZiGzU/GGKL80g3SLBp7gHGtGVHB4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K1pZIcFP; spf=pass (imf23.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=1684312487; a=rsa-sha256; cv=none; b=EvwMfbtTwZuHZMLm+TgtaC6lNuI2sbn1ZDE43i0ifWMFYYMiVCQoDg8iaz0ILVrs1YFZD9 Bvmov0BSAjssW27G84rQkN7y0N3Y+Pq1hcSq5MkYyYA4KCLFlzJqO9ke+t4uo6lziINdHQ YjiZvUssWz+BvOLgVsPMv2I++iBTQ9I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684312486; 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=WoyE4KJMZkzKP/aXFBkcgtSqzW5vCFF351V1GgKfqTs=; b=K1pZIcFPbED6EDpwG2Wx+TZzAosf3CUEOD0cI7FdjjDNSwjy3ZgXwWvZFw72zpROwEqiSx j1Iml5RxmYlbAjzdroUSxiXjPkm01E38cgI5pWySx3PgKMxMcL/LF73RsU5wBMaN9lwk7b Gd899R4pkM1ca9MugHFnag4lCMPTYDA= 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_256_GCM_SHA384) id us-mta-264-HdpVMYPCP8KmllVxu0HWjw-1; Wed, 17 May 2023 04:34:45 -0400 X-MC-Unique: HdpVMYPCP8KmllVxu0HWjw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f518f2900eso3484155e9.2 for ; Wed, 17 May 2023 01:34:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684312484; x=1686904484; h=content-transfer-encoding:in-reply-to:organization: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=WoyE4KJMZkzKP/aXFBkcgtSqzW5vCFF351V1GgKfqTs=; b=XEGaMZ7lnj7X+kC6mHpXEgE3mBN5cGljMvLUOmIubK7kfFih+HViS3VSUf9Y3bjOSa vT5eSFioc8DODrL5N1MiVrFHs+5kyI0Hoz13j8iCbbjqBa69OgIhNox0r6F/R6WIpc31 /0ywcJMtQNFxojAQr4dCsboQ+KgosoB9Mkk61CBZV5CTB9HqgThF4s2Z6CdkC2juj8lF e/rXCeVjyH7nDiT7P6n6zBJVOSWEkzCPxzVVsIo2QsIuJx1eKUeoIuvZCXh684/dOm4a +27azxStwA/TQeO98KxfhyCKx1r5LuOzXIak9lIE6lJItkApsKBAT2492kDlsmZkujfj 3kdQ== X-Gm-Message-State: AC+VfDyO6pfAcCISGH9bAMCygGHTgtiqen665v6oroHnmlaX1iZ45AGK irBs2BEBAgywDkd4OwsPMhHhp4MbYlQUolocAGIry2MY50qJthskjLM2oV5XXZ1B1UrzZ+oxTIx zt7p6wRRFJWyG3kCi+Qg= X-Received: by 2002:a05:600c:2307:b0:3f4:2cf3:a542 with SMTP id 7-20020a05600c230700b003f42cf3a542mr18563296wmo.6.1684312483861; Wed, 17 May 2023 01:34:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69xCz2yc3tWerUY2z+evrEEbLpsBdhPCID8fyE+1EMtIzuO7zBap/5z+L7vWNzh3MQYaHFXA== X-Received: by 2002:a05:600c:2307:b0:3f4:2cf3:a542 with SMTP id 7-20020a05600c230700b003f42cf3a542mr18563263wmo.6.1684312483462; Wed, 17 May 2023 01:34:43 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:3900:757e:83f8:a99d:41ae? (p200300cbc7073900757e83f8a99d41ae.dip0.t-ipconnect.de. [2003:cb:c707:3900:757e:83f8:a99d:41ae]) by smtp.gmail.com with ESMTPSA id 7-20020a05600c028700b003f182cc55c4sm1505469wmk.12.2023.05.17.01.34.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 May 2023 01:34:43 -0700 (PDT) Message-ID: Date: Wed, 17 May 2023 10:34:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 1/3] mm: Move arch_do_swap_page() call to before swap_free() To: Peter Collingbourne Cc: Catalin Marinas , =?UTF-8?B?UXVuLXdlaSBMaW4gKOael+e+pOW0tCk=?= , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" , =?UTF-8?B?Q2hpbndlbiBDaGFuZyAo5by16Yym5paHKQ==?= , "kasan-dev@googlegroups.com" , =?UTF-8?B?S3Vhbi1ZaW5nIExlZSAo5p2O5Yag56mOKQ==?= , =?UTF-8?B?Q2FzcGVyIExpICjmnY7kuK3mpq4p?= , "gregkh@linuxfoundation.org" , vincenzo.frascino@arm.com, Alexandru Elisei , will@kernel.org, eugenis@google.com, Steven Price , stable@vger.kernel.org References: <20230512235755.1589034-1-pcc@google.com> <20230512235755.1589034-2-pcc@google.com> <7471013e-4afb-e445-5985-2441155fc82c@redhat.com> From: David Hildenbrand Organization: Red Hat 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 X-Stat-Signature: xkkysnx3wk5ebkj7wf19gqanurwg8i4m X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6C31A140017 X-Rspam-User: X-HE-Tag: 1684312487-191316 X-HE-Meta: U2FsdGVkX1+MRkHbYl08CIfNT81Ec9/GwQUxYX2pvBYiXgrNBpP6xGt0a6rHkXVwucGRkhOtFOwjrAOYu2zpAgtsyXE9lk/diCKb6w89d2RpXIO/Unc06ju/K5UK0PRzxqIseS6wZWsTwNnDFJvMhAdTPJuL4KOWfNlfCmBcC9/wN4xQE6Rc8CDMvJRKq1V7aUVrtWmYboSlv/DlbPx/8WBGODSpzbjyMKI3IGPwRMToOKG3EbKaljR8NsvNqs3oc549lf8GRIBpxhGm22f+zETqcmVPo7KIKcfEqHd55Xk8QOwKZi7Bwwv4Xka/5tff8W8fnZwzy6VxznPF1kLfAlvmuxQyBzY/qpKkmsTFy+GoNIKWGZxgmT48yMtc6Lj7egyRSMYpYBrfxmSnpUMiBXicByuj4bl9w6kHnR2Gx18M4MuEfSRWk+an+HVfjR2eDecF892XsSHIP+uB/XceEuQTubQkPmi0NmVNWCOmtNJdhztvs0aTk7GXQr9Zj3WOHpoAlk1M7jLEVDVykl7twhbohSGg9K7zz8OQbT1BsPPAKBC76uWV7avtU2D6vd/6MFFmZ4S7Goa/35H8DEoYHFdmgLQQQv6UPF/nU5xUF/i7zPLMmippHHxpSHZsoFtSllnm/Bo/pQiqdYx8ZwaK/meW5yrJGSbYxyqJ9/hnGuAqwEIs+JZrowKt7UwgyNaNFtnNZo0kXM9mUldKaQLgOMGZYvB3hVsT4zMghxesgQBird3rBEL+a0R7GT+28IOLP8ktuNV9grMiQg/fRE8nfAcGSAsv6lM/ImsFluk4HoEejoY4dk7998+XuXQBHQH9V5dWNp2BNrN4PS618rmF3kIH0ujTyS6u787YcBx34V/hAxqjD2Lx+Cr015TFrgg4eC19O2lVVSSKztxhwFsE+817tbN6rVPO5pJnXpnOQ2Hm0A1L6VVLyfwR1XgzGtz2Lr1FoHk7KijUaR4vE72 5MQBzD52 9BCiLgt10W1hxDjLEyvaHGvnPk6vY/S/0ejze4vcz7c3iRTkKc5HOPLVZfhVzw33our8h2/O3XR/1gMsto6MMytp39UVTZn02FINo7Tons8fIDasBmpp3JJsE8HZOFV02cgAVnNdPc8TD362kffMR5FEUlEaccUQHa0U6HqFg+YFVXaQ5tHBGM3WHwDIWTYgDIUjPoIXKZbJPnvOzEHbu+bej0Om9W0Sod4bAGojWgPE2QLo1fFn3Md3HCXinksGgIHjNlc6ksB7moTpMvbY36hQCZwU820FuloD0VbcpXZGi33RgkoUtr/4XmK5N2hUHZsJdfL1z9RKqmHrw6m391kUVhJ3yJqPRLTeGeVf9qdr6FX2YauZnrnCgjPSrmrsVOyUc5dlqJ7RFyc7BaWAIFVQHjIP9Z1Pm//PMmiSydl+ZHTRFqtjDiyvUSWKnDp6S2bnh7Lruqq9zin469tHBzfpZ/1zC+GuH5gpVQ1GVXNgDZejem1zz+kFt7JA9HCfZI4iOn/yPVg+gPR8XDJBHYruI1D4B6LR2CAFIToZ6RIY9JkwYfY7o8Py4w0W6LD1vs8liQPKZeSkhfpqrTif3GgTf+mk0lWxNUJ8zPTnc9/vSaeiGcCoK/mFXeiRSn3xIanPPGS/GV5/5/Z9w0S3r1g+hQ/xLk1rZiha2KhTOzyhdT37IK+pOeJFiKqdbPhnjxn5m 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 16.05.23 04:35, Peter Collingbourne wrote: > On Mon, May 15, 2023 at 05:16:09PM -0700, Peter Collingbourne wrote: >> On Sat, May 13, 2023 at 05:29:53AM +0200, David Hildenbrand wrote: >>> On 13.05.23 01:57, Peter Collingbourne wrote: >>>> Commit c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") moved >>>> the call to swap_free() before the call to set_pte_at(), which meant that >>>> the MTE tags could end up being freed before set_pte_at() had a chance >>>> to restore them. One other possibility was to hook arch_do_swap_page(), >>>> but this had a number of problems: >>>> >>>> - The call to the hook was also after swap_free(). >>>> >>>> - The call to the hook was after the call to set_pte_at(), so there was a >>>> racy window where uninitialized metadata may be exposed to userspace. >>>> This likely also affects SPARC ADI, which implements this hook to >>>> restore tags. >>>> >>>> - As a result of commit 1eba86c096e3 ("mm: change page type prior to >>>> adding page table entry"), we were also passing the new PTE as the >>>> oldpte argument, preventing the hook from knowing the swap index. >>>> >>>> Fix all of these problems by moving the arch_do_swap_page() call before >>>> the call to free_page(), and ensuring that we do not set orig_pte until >>>> after the call. >>>> >>>> Signed-off-by: Peter Collingbourne >>>> Suggested-by: Catalin Marinas >>>> Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965 >>>> Cc: # 6.1 >>>> Fixes: ca827d55ebaa ("mm, swap: Add infrastructure for saving page metadata on swap") >>>> Fixes: 1eba86c096e3 ("mm: change page type prior to adding page table entry") >>> >>> I'm confused. You say c145e0b47c77 changed something (which was after above >>> commits), indicate that it fixes two other commits, and indicate "6.1" as >>> stable which does not apply to any of these commits. >> >> Sorry, the situation is indeed a bit confusing. >> >> - In order to make the arch_do_swap_page() hook suitable for fixing the >> bug introduced by c145e0b47c77, patch 1 addresses a number of issues, >> including fixing bugs introduced by ca827d55ebaa and 1eba86c096e3, >> but we haven't fixed the c145e0b47c77 bug yet, so there's no Fixes: >> tag for it yet. >> >> - Patch 2, relying on the fixes in patch 1, makes MTE install an >> arch_do_swap_page() hook (indirectly, by making arch_swap_restore() >> also hook arch_do_swap_page()), thereby fixing the c145e0b47c77 bug. >> >> - 6.1 is the first stable version in which all 3 commits in my Fixes: tags >> are present, so that is the version that I've indicated in my stable >> tag for this series. In theory patch 1 could be applied to older kernel >> versions, but it wouldn't fix any problems that we are facing with MTE >> (because it only fixes problems relating to the arch_do_swap_page() >> hook, which older kernel versions don't hook with MTE), and there are >> some merge conflicts if we go back further anyway. If the SPARC folks >> (the previous only user of this hook) want to fix these issues with ADI, >> they can propose their own backport. >> >>>> @@ -3959,7 +3960,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) >>>> VM_BUG_ON(!folio_test_anon(folio) || >>>> (pte_write(pte) && !PageAnonExclusive(page))); >>>> set_pte_at(vma->vm_mm, vmf->address, vmf->pte, pte); >>>> - arch_do_swap_page(vma->vm_mm, vma, vmf->address, pte, vmf->orig_pte); >>>> folio_unlock(folio); >>>> if (folio != swapcache && swapcache) { >>> >>> >>> You are moving the folio_free_swap() call after the folio_ref_count(folio) >>> == 1 check, which means that such (previously) swapped pages that are >>> exclusive cannot be detected as exclusive. >> >> Ack. I will fix this in v2. > > I gave this some thought and concluded that the added complexity needed > to make this hook suitable for arm64 without breaking sparc probably > isn't worth it in the end, and as I explained in patch 2, sparc ought > to be moving away from this hook anyway. So in v2 I replaced patches 1 > and 2 with a patch that adds a direct call to the arch_swap_restore() > hook before the call to swap_free(). As a side note, I recall that sparc code might be a bit fragile and eventually broken already (arch_unmap_one()): https://lkml.kernel.org/r/d98bd1f9-e9b7-049c-7bde-3348b074eb18@redhat.com -- Thanks, David / dhildenb