From patchwork Mon Aug 2 21:53:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12414797 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 1F76AC432BE for ; Mon, 2 Aug 2021 21:54:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A711760F9C for ; Mon, 2 Aug 2021 21:54:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A711760F9C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D351A8D0005; Mon, 2 Aug 2021 17:54:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CDF7F8D0002; Mon, 2 Aug 2021 17:54:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B806B8D0005; Mon, 2 Aug 2021 17:54:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 908598D0002 for ; Mon, 2 Aug 2021 17:54:16 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 462098249980 for ; Mon, 2 Aug 2021 21:54:16 +0000 (UTC) X-FDA: 78431494512.14.BBC03EC Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf28.hostedemail.com (Postfix) with ESMTP id E898D9009F2B for ; Mon, 2 Aug 2021 21:54:15 +0000 (UTC) Received: by mail-qk1-f181.google.com with SMTP id c18so18143258qke.2 for ; Mon, 02 Aug 2021 14:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=96Un8yzVfu7KwL+UKPbJdUfuiZIxSkwQ3ffVCXyGsJg=; b=fDKdvVvJFzZLoHCfTztgqUc8ghI0wc0uDmTwEByiClo9Fcrah9+JXI4wlANk0MLP0Z Baythc3XdKwhO6bqGBTm0LqWBDzhSfCqsmEOuAfGPKQbvlzFWkTHH8MV05CYMtSLUBFu 5A4BPjNQfVh86B1fU1SpksUzRvwB4KyS8V1IXEJSxY4A/NqPTIfGZvTSvoApGAai4N+D 40BkEUuNgNrDlgFfukt0M3Bu4OoAVKM1CuG4vnkAP7JypBRhYmitFffAs3WZCtDov+Kp IvrPNUTuRAk4TWlGmF2NZSw6CuXflGh3nUfgH6xcKGnBAyWnyq0R/Z6iB6Zw7gEswAFZ I/sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=96Un8yzVfu7KwL+UKPbJdUfuiZIxSkwQ3ffVCXyGsJg=; b=Ea8+TLCKbK1Yj8vjTRb7WpwyMqnFC9MEV5xmCDCfvIGkdiiR1PKFz+CsjldYJoPI0Q 9R+mR6PTZMXcuOgYqC5ocIrRopQaO6sWyMY5eutJM93aeGwIFYxgIY00PYu8yRQN2RKD LvdzjgNXX6rn+7IVdzBdXS10bTPVpmWelIZHgfmJmfKrPMkm7Z0xAclM52QyaO+DDAoB fxXmov5fWC1QuD1VSajbKFwMq2W2ZX0nnLY3TbPdXMvZ2OjFg7cGdOV9gF70cP9JJR4g cbJGoY8DFv8Z9jAHTpYan44CbDkN/l4WPMkvpfoRBphWnMA5jL+av0qfyC010k0SjiNQ 5v/A== X-Gm-Message-State: AOAM5334LrAgyiXROx24n4hSfM+18+gusJqUze8yfp9J3UXJIcG5emcM Dh66Q4MSv+1lD6fg14Uk7cax7g== X-Google-Smtp-Source: ABdhPJxxBXqSP3qMfUR18poVpxw/DGnsuk4IsHc07cmFedVkC3VWV8old/VTOr1+C7JPN//f26ZF2A== X-Received: by 2002:a05:620a:164b:: with SMTP id c11mr17543239qko.156.1627941255271; Mon, 02 Aug 2021 14:54:15 -0700 (PDT) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id v11sm5479216qtc.0.2021.08.02.14.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 14:54:14 -0700 (PDT) From: Pavel Tatashin To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, maz@kernel.org, james.morse@arm.com, vladimir.murzin@arm.com, matthias.bgg@gmail.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com, tyhicks@linux.microsoft.com, kernelfans@gmail.com, akpm@linux-foundation.org, madvenka@linux.microsoft.com Subject: [PATCH v16 03/15] arm64: hibernate: abstract ttrb0 setup function Date: Mon, 2 Aug 2021 17:53:56 -0400 Message-Id: <20210802215408.804942-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210802215408.804942-1-pasha.tatashin@soleen.com> References: <20210802215408.804942-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E898D9009F2B Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=fDKdvVvJ; dmarc=none; spf=pass (imf28.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Stat-Signature: u16ib158i9s6iqtfqetiqjsctfgrhiuc X-HE-Tag: 1627941255-149109 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: Currently, only hibernate sets custom ttbr0 with safe idmaped function. Kexec, is also going to be using this functionality when relocation code is going to be idmapped. Move the setup sequence to a dedicated cpu_install_ttbr0() for custom ttbr0. Suggested-by: James Morse Signed-off-by: Pavel Tatashin --- arch/arm64/include/asm/mmu_context.h | 24 ++++++++++++++++++++++++ arch/arm64/kernel/hibernate.c | 21 +-------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index eeb210997149..edb57e075abe 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -115,6 +115,30 @@ static inline void cpu_install_idmap(void) cpu_switch_mm(lm_alias(idmap_pg_dir), &init_mm); } +/* + * Load our new page tables. A strict BBM approach requires that we ensure that + * TLBs are free of any entries that may overlap with the global mappings we are + * about to install. + * + * For a real hibernate/resume/kexec cycle TTBR0 currently points to a zero + * page, but TLBs may contain stale ASID-tagged entries (e.g. for EFI runtime + * services), while for a userspace-driven test_resume cycle it points to + * userspace page tables (and we must point it at a zero page ourselves). + * + * We change T0SZ as part of installing the idmap. This is undone by + * cpu_uninstall_idmap() in __cpu_suspend_exit(). + */ +static inline void cpu_install_ttbr0(phys_addr_t ttbr0, unsigned long t0sz) +{ + cpu_set_reserved_ttbr0(); + local_flush_tlb_all(); + __cpu_set_tcr_t0sz(t0sz); + + /* avoid cpu_switch_mm() and its SW-PAN and CNP interactions */ + write_sysreg(ttbr0, ttbr0_el1); + isb(); +} + /* * Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD, * avoiding the possibility of conflicting TLB entries being allocated. diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index b96ef9060e4c..2758f75d6809 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -212,26 +212,7 @@ static int create_safe_exec_page(void *src_start, size_t length, if (rc) return rc; - /* - * Load our new page tables. A strict BBM approach requires that we - * ensure that TLBs are free of any entries that may overlap with the - * global mappings we are about to install. - * - * For a real hibernate/resume cycle TTBR0 currently points to a zero - * page, but TLBs may contain stale ASID-tagged entries (e.g. for EFI - * runtime services), while for a userspace-driven test_resume cycle it - * points to userspace page tables (and we must point it at a zero page - * ourselves). - * - * We change T0SZ as part of installing the idmap. This is undone by - * cpu_uninstall_idmap() in __cpu_suspend_exit(). - */ - cpu_set_reserved_ttbr0(); - local_flush_tlb_all(); - __cpu_set_tcr_t0sz(t0sz); - write_sysreg(trans_ttbr0, ttbr0_el1); - isb(); - + cpu_install_ttbr0(trans_ttbr0, t0sz); *phys_dst_addr = virt_to_phys(page); return 0;