Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2286572rwd; Wed, 17 May 2023 08:07:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4rAR5wK7K2O0KMQMBClZujxvhU/TcsabII6Jkr/i+W09OTs6Lunj07YtpnI0ft8WryF6sn X-Received: by 2002:a05:6a20:549c:b0:105:9ca9:56aa with SMTP id i28-20020a056a20549c00b001059ca956aamr16737393pzk.0.1684336056564; Wed, 17 May 2023 08:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684336056; cv=none; d=google.com; s=arc-20160816; b=AsFoJpovLqB1BcneyaHMGBFxfAvOkacssBZxqCjg4b23yJbsDF7MKNQTsb912LgbmI c4SfR1CSi8kpJm0vdRFgu350OqeePH6HGt606yUBR3VcuFvoQB4ITiZ/ILs/eADznysa evVOtUx3qfGGmXEEwxiq1UHwH3rK1SxrcwPkw8VtDTYUJgzCpf7WuHbVCzvXPtL3keaT QMr/HZLPxdNsadL/+b6lKro5iGF+S+q0fvE4HnI6t/2kUMMNFxGddhn4CSmQxJzGViAY jNrdn+yujYBH5+sjJAv0Mfdvag/abVvtWuNF9eTmECwMjzNeW/7oQeVqpiuuj0J6bZlx u+TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=+Zwx//lOdg6V9D63MW28GsqyK5yhFT+5Pyw49IqDxGo=; b=qSrLg8INSbEyziT2TCfrz/QYHtcx6PxsJn6B4+SJDl2tpAwqDsXPt7f6E3c6mKx2Pd BcmAOxBXLBV7N/UnhRhaTMInVOxT252FMyXzbSD9/MiON/bpKbdzXblfKwXS/CNuXHcR qurfPUJeaebmMqAnwBHrmmfEYGv+9vXRIg//v4IgYL5PwOIDDCGqPWyYD4x8STz3HAO2 nASe3unjxgMsoAC/OLxDf+lOpz3JY6bJe/QyC7oveEzA3+D3fYgtc17Zzg3JonGY7H+t JWy5ntgnDBpMEOH5kkWLd58T98uayWt6Qa5ULtazLPQUBnUVJRpJDvm3ki18y29qi19D LfTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a636e0e000000b0052c877d6a6bsi20717800pgc.827.2023.05.17.08.07.21; Wed, 17 May 2023 08:07:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbjEQO54 (ORCPT + 99 others); Wed, 17 May 2023 10:57:56 -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 X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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