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 DEFC8C77B7A for ; Tue, 16 May 2023 12:40:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61C3F900006; Tue, 16 May 2023 08:40:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A5B1900002; Tue, 16 May 2023 08:40:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F93E900006; Tue, 16 May 2023 08:40:42 -0400 (EDT) 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 2CF46900002 for ; Tue, 16 May 2023 08:40:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 05245140233 for ; Tue, 16 May 2023 12:40:41 +0000 (UTC) X-FDA: 80796077124.02.2E15ABB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 8825C20009 for ; Tue, 16 May 2023 12:40:39 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XdVGe7jh; spf=pass (imf03.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=1684240839; 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=upbxxvOzNSBT926IBK9ZbKutV3zDXORRb/Sm2DRZKY8=; b=hXOmCAnxcKvU9AxmT1A2kdPbFGzWoCLYmcFIVMuWs/2XzOWjojq24e8jM/0QU+/a8Chd6M Nquls182WtdDTZaBSpFhUPPNj+kDcub0tDzjhZjWNHB/aAg2NtTl5CET60hFxbDcWVYu6V O/Ty64hFcdkVYnD4q2yC1QOmkqIzSN0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684240839; a=rsa-sha256; cv=none; b=OATusFDnZNoQ0rUhPdadVkzeNcTk0Q1FtP4ULbTPTcdyORmzjfhm0kpYiEp+nheMBYxwTe P+qkTVPtlN7WbiEcJW+23krBVr0KF7+RQNKY43wWK58iTQz/GdVBxg8MkCMuyIDPg6BYbn YRkgtLcTdtuNYdQzYFrxhqEAieKJmP0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XdVGe7jh; spf=pass (imf03.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684240838; 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=upbxxvOzNSBT926IBK9ZbKutV3zDXORRb/Sm2DRZKY8=; b=XdVGe7jhgs9vnGhX/+1277ahTUkuAnRwpBWokOrx58IdtKA5g7/g3GlVRYwm4dx69hOHn8 OayeowRvWM6eBwu1p4hteJxK6eMxh4/eNpWgDSOsLTz+tDax2IDQrzugEQUQHS6lxSjnN0 XASLq+cgzjE/htrC7EfXuD9saj9vKHI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-H06TfeWHMdqWuzQ26FtVJw-1; Tue, 16 May 2023 08:40:37 -0400 X-MC-Unique: H06TfeWHMdqWuzQ26FtVJw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f426d4944fso35223145e9.1 for ; Tue, 16 May 2023 05:40:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684240836; x=1686832836; 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=upbxxvOzNSBT926IBK9ZbKutV3zDXORRb/Sm2DRZKY8=; b=MYO9pugXDLXov7cM3GpCrM0pOPYI3KSN+XSJa+dOjrHUjT4M5pUkIfs+1jayS0va+5 yYG6DOVFgNgWQNY/M6+16AsojBYULsKP+aKWdlBiPAKdJZqEbw48flfUzuffrOiN5EmN 9iNbjYv0dz4Lt1y323qq1Xru3kX9We8NNMrrozEMClqwpSKRizNI5qXX11b+9KYsblSZ d+0y7JybeUDeJqk1mmH4A9BjfoklHKTnREhFteobMTvwBksagZaABQhMylINyew12ybz IoNOdO3Howre7rlNFA6aaItb2OhWzBZeAq2f0P9w/fe1is29y69508ARgACt/qjXdXhr jeUg== X-Gm-Message-State: AC+VfDxsF63rECvRuESOTBVZssV34JSSJaBybT7r3xbAdA8KxhVBox3H ijO/p2HSpKrNdg2wr4WWpguXyPtlLLGtP1N6Yg90PK0o0TJIifofQR9qPAfwYdyuchhYKny9eco 8au+tjQv6p6A= X-Received: by 2002:adf:e7ca:0:b0:306:4063:1aff with SMTP id e10-20020adfe7ca000000b0030640631affmr27980923wrn.30.1684240836285; Tue, 16 May 2023 05:40:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4AIRomaPkOHFiqyLi+kkY65j+brNGYH2HLoYKsCiqeVH2oIr9hQC43Db4GD6+O8ErBjUR0hA== X-Received: by 2002:adf:e7ca:0:b0:306:4063:1aff with SMTP id e10-20020adfe7ca000000b0030640631affmr27980889wrn.30.1684240835926; Tue, 16 May 2023 05:40:35 -0700 (PDT) Received: from ?IPV6:2003:cb:c74f:2500:1e3a:9ee0:5180:cc13? (p200300cbc74f25001e3a9ee05180cc13.dip0.t-ipconnect.de. [2003:cb:c74f:2500:1e3a:9ee0:5180:cc13]) by smtp.gmail.com with ESMTPSA id k5-20020a5d5185000000b0030497b3224bsm2513457wrv.64.2023.05.16.05.40.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 05:40:35 -0700 (PDT) Message-ID: Date: Tue, 16 May 2023 14:40:34 +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-Rspamd-Queue-Id: 8825C20009 X-Stat-Signature: 9mtfsumq38rg7kt3f5zim7keteuacpti X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1684240839-592590 X-HE-Meta: U2FsdGVkX19ADXYgpIejbSQ0yKqvnDwuI/HigrFvfF4l/SxjbcOpVI/cAz2zLyRnxiVf6JU/Uuvw52T4Z8d4BbtutnINoQNDiBxglYZoJQsmyitXDLjm6RxcEWgwYhZ2gDVD5GyA2u8nAHnu+JhG4SoRPOD1UpVMZh0TGAnNTk8rCwmcKSOiUnRTAOSZv5NlxQdC743NJ6sYy8QfUOgwJJAXu7Ike6f6p6Uek8hLeFLL6OmjuqN/Q+grRpTXrZehGeDqXSJH1GSgU4STVBR09TKmmGx7xcCJhmhq7nGtXr8+0VD4iezkpZL3Q/+tuLwWgAdoi9OnYp88uQRkHn6ft9v7P0VqyPLA1oPEijqRhMgeLWmULqpu0bJP8o4OwwFdyGZQ7lX+Tu/ZjLi1KM7hSxZwj+tAvDcg3T+2m7LbJlNHSOOAIUFtHzwpQGiEXgP7UqQhrxWzHMXfG7fRfr9b9VjHETPyPTY+GrqpHWaJp4FVUhxotd3ejTOPHKkl643PjQbskEsZfqtIvsyHnnvqBS5balbUU1ZoH0XZaV2MQez9TCzdgspMAAU0AUhNm712gJRPktrqhX30mDNVZwIvYsTFdmbSakSlREUpfuYrvt9ypyA+u1Fz9LpjrE2QjuELSM06l4UDZVnVFKyTZp7mfOrg03S9naJNA+ZVxKktAu5oCZ01uoL3a2DOLhPf2kdTBSCQCxfh5ZwZ5TxokM3/rtWz4HyHK7VCmjgmBoZjzSe2XLFSqAV9KWXkyzCMxfJpVgC/6ceABJnmHulJAAjyzSrWViK/OIXPWD2rvuTbhOdKWi6X789ZGzraat4rhpA3zjRf0w6Ab1Z9O5bbzTqJ2oCHlCrLFDIF+PyNb2BC10D2gGuOPAiuZY4Fg/YaMxOh9IahtcvIQ1TAXyFt0oySR5lnCMTNyG9mIO+XUXvG9mEGQBWZJg7PpvlrKJh2Xgkl4+izpg/zGWUoTk+0d2x Sa4zvOR/ nk0s8RPRe5kpIFIQ1oo87LXumDHVMW/DgrxqhqJPHjay8Ri15VEJ/xNjadfenY/doakjG+7BODiRF5qlhAABB7J+zjbZMCWRbo6zZ2wu3FrkHYNS5ZZg9rcybxwWtWybsOrpesOX9OU7FIji89+Xf0j9dz1g47Ef0OhRPngKGBUrlv46kcKSokoaaq8DoQBgs59mIFQWbPhhRpkEx4017yD0EPO62EJTFe3b74NGjP/6SCepDUIint97rO5I1FxKLdRSimuasILlR32GKcCb1kO7Gn2vTFv+Wi2D93d0Hwj6liNxpbLpE7NuS92Y8/aNC6yFemhlroIiuTJbu4X2c1gHQS4huiHPbLGa2YQ5bYgROqX/O0uWjG54t4+p8d3iPlnAx+d/L+tFJxIIY6WDgHXoqIKZb76fMkxTf9CBhIgZ5cERP/75d/0KnRxh1BX+FFguM+VVz+oJX1oQ6NcWUyTcO1qh47qiFcwbY7k1zVySikFeoHnm2o/eEken+Ehoe5Wv3UQ5MnsUWEiKRb0CEQIhBbiak8WjOK5Gramr0qaKsTuYEd8JoI/cWPnQ1DYigzPCWqFwiD8iH2dQffENbq0Fb4SwKOmyk0Y9vgi0cCC59u0EW+C+QM55wjEjadW5vC7E8Sdsl3j6gjxF85USmykBYU/ZUuFVfjXqk8HYKkB7DCyY= 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 02:16, 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. > Oh. That's indeed confusing. Maybe that should all be squashed to have one logical fix for the overall problem. It's especially confusing because this patch here fixes the other two issues touches code moved by c145e0b47c77. > - 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. Sometimes, it's a good idea to not specify a stable version and rather let the Fixes: tags imply that. -- Thanks, David / dhildenb