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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F722C433E0 for ; Thu, 25 Jun 2020 11:38:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EAED820781 for ; Thu, 25 Jun 2020 11:37:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAED820781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 73DA56B0003; Thu, 25 Jun 2020 07:37:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EDA46B002B; Thu, 25 Jun 2020 07:37:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DC386B002C; Thu, 25 Jun 2020 07:37:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id 4201F6B0003 for ; Thu, 25 Jun 2020 07:37:59 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F03C6180AD81A for ; Thu, 25 Jun 2020 11:37:58 +0000 (UTC) X-FDA: 76967535036.20.hands11_300d4fe26e4c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id C8301180C07AF for ; Thu, 25 Jun 2020 11:37:58 +0000 (UTC) X-HE-Tag: hands11_300d4fe26e4c X-Filterd-Recvd-Size: 4139 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Thu, 25 Jun 2020 11:37:58 +0000 (UTC) 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 518051FB; Thu, 25 Jun 2020 04:37:57 -0700 (PDT) Received: from [192.168.1.179] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B3B933F73C; Thu, 25 Jun 2020 04:37:55 -0700 (PDT) Subject: Re: [PATCH v5 22/25] arm64: mte: Enable swap of tagged pages To: Catalin Marinas , linux-arm-kernel@lists.infradead.org Cc: linux-mm@kvack.org, linux-arch@vger.kernel.org, Will Deacon , Dave P Martin , Vincenzo Frascino , Szabolcs Nagy , Kevin Brodsky , Andrey Konovalov , Peter Collingbourne , Andrew Morton References: <20200624175244.25837-1-catalin.marinas@arm.com> <20200624175244.25837-23-catalin.marinas@arm.com> From: Steven Price Message-ID: Date: Thu, 25 Jun 2020 12:37:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200624175244.25837-23-catalin.marinas@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: C8301180C07AF X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 24/06/2020 18:52, Catalin Marinas wrote: > From: Steven Price > > When swapping pages out to disk it is necessary to save any tags that > have been set, and restore when swapping back in. Make use of the new > page flag (PG_ARCH_2, locally named PG_mte_tagged) to identify pages > with tags. When swapping out these pages the tags are stored in memory > and later restored when the pages are brought back in. Because shmem can > swap pages back in without restoring the userspace PTE it is also > necessary to add a hook for shmem. > > Signed-off-by: Steven Price > [catalin.marinas@arm.com: move function prototypes to mte.h] > [catalin.marinas@arm.com: drop '_tags' from arch_swap_restore_tags()] > Signed-off-by: Catalin Marinas > Cc: Andrew Morton > Cc: Will Deacon > --- > > Notes: > New in v4. > [...] > diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c > index 3e08aea56e7a..1712c504df15 100644 > --- a/arch/arm64/kernel/mte.c > +++ b/arch/arm64/kernel/mte.c > @@ -10,6 +10,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > > @@ -18,15 +20,30 @@ > #include > #include > > +static void mte_sync_page_tags(struct page *page, pte_t *ptep, bool check_swap) > +{ > + pte_t old_pte = READ_ONCE(*ptep); > + > + if (check_swap && is_swap_pte(old_pte)) { > + swp_entry_t entry = pte_to_swp_entry(old_pte); > + > + if (!non_swap_entry(entry) && mte_restore_tags(entry, page)) > + return; > + } > + > + mte_clear_page_tags(page_address(page)); > +} > + > void mte_sync_tags(pte_t *ptep, pte_t pte) > { > struct page *page = pte_page(pte); > long i, nr_pages = compound_nr(page); > + bool check_swap = nr_pages == 0; > > /* if PG_mte_tagged is set, tags have already been initialised */ > for (i = 0; i < nr_pages; i++, page++) { This is broken - for check_swap to be true, nr_pages==0, which means we never enter the loop and nothing happens... Except I don't believe compound_nr() will return 0 - it's defined as: static inline unsigned long compound_nr(struct page *page) { return 1UL << compound_order(page); } Changing it to nr_pages==1 works for me. Steve