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=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 0E0BDC433E0 for ; Mon, 8 Feb 2021 18:57:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC69764E73 for ; Mon, 8 Feb 2021 18:57:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC69764E73 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eWG/sXl+GR1e11nF2+IHGYtO7ef5bI1VNwTVan7bGjA=; b=J+fWKXvgf9w7C0iNwI56O0kAB F/jyeM6oP8xqmTtzYB8GLHP3CQyYoLgiWeABc/kLsEbHSg2ZKk2Z/NYQaBQhpYg9fitbNuFWTtLmu rldDbnW9Y75NzQsBBQDH64qZc4buPULRkxnInNwkWvS4S/fd+8MmUbXT+UBY5P45LGeMwuumYj6i+ 6cZw2qXb1i/IOjwWhIqxHnvXwIFmCfj8GV4ig3UfGPRek4pVW7Cy/eVL1AX/TecXrfGSxKG/FMZfK 2IwOSoNwCbZs2XJz2j9aB28rF6v9/iHF/kW9E3xgA3MgxevHVg/rDEHhJFVe6I1IY1y02Zuu/UNCm X3Yg/P6cQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l9BiJ-0001k5-SW; Mon, 08 Feb 2021 18:56:47 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l9BiH-0001jZ-2Y for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2021 18:56:46 +0000 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 A471D1042; Mon, 8 Feb 2021 10:56:42 -0800 (PST) Received: from e121166-lin.cambridge.arm.com (e121166-lin.cambridge.arm.com [10.1.196.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DCE713F73D; Mon, 8 Feb 2021 10:56:40 -0800 (PST) Date: Mon, 8 Feb 2021 18:56:35 +0000 From: Lorenzo Pieralisi To: Vincenzo Frascino Subject: Re: [PATCH v12 6/7] arm64: mte: Save/Restore TFSR_EL1 during suspend Message-ID: <20210208185635.GA13187@e121166-lin.cambridge.arm.com> References: <20210208165617.9977-1-vincenzo.frascino@arm.com> <20210208165617.9977-7-vincenzo.frascino@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210208165617.9977-7-vincenzo.frascino@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210208_135645_265112_A212277B X-CRM114-Status: GOOD ( 26.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Branislav Rankov , Marco Elver , Catalin Marinas , Evgenii Stepanov , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Alexander Potapenko , Dmitry Vyukov , Andrey Konovalov , Andrey Ryabinin , Andrew Morton , Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Feb 08, 2021 at 04:56:16PM +0000, Vincenzo Frascino wrote: > When MTE async mode is enabled TFSR_EL1 contains the accumulative > asynchronous tag check faults for EL1 and EL0. > > During the suspend/resume operations the firmware might perform some > operations that could change the state of the register resulting in > a spurious tag check fault report. > > Save/restore the state of the TFSR_EL1 register during the > suspend/resume operations to prevent this to happen. > > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Lorenzo Pieralisi > Signed-off-by: Vincenzo Frascino > --- > arch/arm64/include/asm/mte.h | 4 ++++ > arch/arm64/kernel/mte.c | 22 ++++++++++++++++++++++ > arch/arm64/kernel/suspend.c | 3 +++ > 3 files changed, 29 insertions(+) > > diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h > index 237bb2f7309d..2d79bcaaeb30 100644 > --- a/arch/arm64/include/asm/mte.h > +++ b/arch/arm64/include/asm/mte.h > @@ -43,6 +43,7 @@ void mte_sync_tags(pte_t *ptep, pte_t pte); > void mte_copy_page_tags(void *kto, const void *kfrom); > void flush_mte_state(void); > void mte_thread_switch(struct task_struct *next); > +void mte_suspend_enter(void); > void mte_suspend_exit(void); > long set_mte_ctrl(struct task_struct *task, unsigned long arg); > long get_mte_ctrl(struct task_struct *task); > @@ -68,6 +69,9 @@ static inline void flush_mte_state(void) > static inline void mte_thread_switch(struct task_struct *next) > { > } > +static inline void mte_suspend_enter(void) > +{ > +} > static inline void mte_suspend_exit(void) > { > } > diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c > index 3332aabda466..5c440967721b 100644 > --- a/arch/arm64/kernel/mte.c > +++ b/arch/arm64/kernel/mte.c > @@ -25,6 +25,7 @@ > > u64 gcr_kernel_excl __ro_after_init; > > +static u64 mte_suspend_tfsr_el1; IIUC you need this per-CPU (core loses context on suspend-to-RAM but also CPUidle, S2R is single threaded but CPUidle runs on every core idle thread). Unless you sync/report it on enter/exit (please note: I am not familiar with MTE so it is just a, perhaps silly, suggestion to avoid saving/restoring it). Lorenzo > static bool report_fault_once = true; > > /* Whether the MTE asynchronous mode is enabled. */ > @@ -295,12 +296,33 @@ void mte_thread_switch(struct task_struct *next) > mte_check_tfsr_el1(); > } > > +void mte_suspend_enter(void) > +{ > + if (!system_supports_mte()) > + return; > + > + /* > + * The barriers are required to guarantee that the indirect writes > + * to TFSR_EL1 are synchronized before we save the state. > + */ > + dsb(nsh); > + isb(); > + > + /* Save SYS_TFSR_EL1 before suspend entry */ > + mte_suspend_tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1); > +} > + > void mte_suspend_exit(void) > { > if (!system_supports_mte()) > return; > > update_gcr_el1_excl(gcr_kernel_excl); > + > + /* Resume SYS_TFSR_EL1 after suspend exit */ > + write_sysreg_s(mte_suspend_tfsr_el1, SYS_TFSR_EL1); > + > + mte_check_tfsr_el1(); > } > > long set_mte_ctrl(struct task_struct *task, unsigned long arg) > diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c > index a67b37a7a47e..16caa9b32dae 100644 > --- a/arch/arm64/kernel/suspend.c > +++ b/arch/arm64/kernel/suspend.c > @@ -91,6 +91,9 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) > unsigned long flags; > struct sleep_stack_data state; > > + /* Report any MTE async fault before going to suspend. */ > + mte_suspend_enter(); > + > /* > * From this point debug exceptions are disabled to prevent > * updates to mdscr register (saved and restored along with > -- > 2.30.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel