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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD18AC77B75 for ; Wed, 17 May 2023 14:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbjEQO55 (ORCPT ); Wed, 17 May 2023 10:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjEQO5z (ORCPT ); Wed, 17 May 2023 10:57:55 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 102B8B8; Wed, 17 May 2023 07:57:47 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 620641FB; Wed, 17 May 2023 07:58:32 -0700 (PDT) Received: from [10.57.58.217] (unknown [10.57.58.217]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 66E9D3F73F; Wed, 17 May 2023 07:57:44 -0700 (PDT) Message-ID: <9b9e7fbd-6166-09ce-9aeb-be28e51eaf10@arm.com> Date: Wed, 17 May 2023 15:57:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v3 1/3] mm: Call arch_swap_restore() from do_swap_page() Content-Language: en-GB To: Peter Collingbourne , Catalin Marinas Cc: =?UTF-8?B?UXVuLXdlaSBMaW4gKOael+e+pOW0tCk=?= , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" , "david@redhat.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, stable@vger.kernel.org References: <20230517022115.3033604-1-pcc@google.com> <20230517022115.3033604-2-pcc@google.com> From: Steven Price In-Reply-To: <20230517022115.3033604-2-pcc@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/05/2023 03:21, 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. Fix it by adding a call to the arch_swap_restore() hook > before the call to swap_free(). > > Signed-off-by: Peter Collingbourne > Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965 > Cc: # 6.1 > Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") > Reported-by: Qun-wei Lin (林群崴) > Closes: https://lore.kernel.org/all/5050805753ac469e8d727c797c2218a9d780d434.camel@mediatek.com/ Reviewed-by: Steven Price > --- > v2: > - Call arch_swap_restore() directly instead of via arch_do_swap_page() > > mm/memory.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/mm/memory.c b/mm/memory.c > index f69fbc251198..fc25764016b3 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3932,6 +3932,13 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > } > } > > + /* > + * Some architectures may have to restore extra metadata to the page > + * when reading from swap. This metadata may be indexed by swap entry > + * so this must be called before swap_free(). > + */ > + arch_swap_restore(entry, folio); > + > /* > * Remove the swap entry and conditionally try to free up the swapcache. > * We're already holding a reference on the page but haven't mapped it