From patchwork Wed Jun 9 00:44:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12308457 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.6 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,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 B1F34C48BCF for ; Wed, 9 Jun 2021 00:44:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5251F613B9 for ; Wed, 9 Jun 2021 00:44:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5251F613B9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E8A696B0071; Tue, 8 Jun 2021 20:44:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E25F16B0072; Tue, 8 Jun 2021 20:44:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C06336B0073; Tue, 8 Jun 2021 20:44:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id 8AF396B0071 for ; Tue, 8 Jun 2021 20:44:27 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 23DC2A745 for ; Wed, 9 Jun 2021 00:44:27 +0000 (UTC) X-FDA: 78232339374.19.DCAE6CC Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by imf07.hostedemail.com (Postfix) with ESMTP id CEF0CA0001A9 for ; Wed, 9 Jun 2021 00:44:22 +0000 (UTC) Received: by mail-qk1-f175.google.com with SMTP id c18so7070076qkc.11 for ; Tue, 08 Jun 2021 17:44:26 -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=h7/0+77ndabR+mxgeXAoHMyf1o3rde7WHj0V90p1QaI=; b=IVvfQXHZK2mgQNL2VKhZdBH2cFdFVnvi67WIksJs+EJTPZ80DCLgf6x7V0AY/DP9n5 KPgwdo1s2mo3JDGJ5fuatqamvtcwaG4T8fEJK/Bw5QsiOjn1lOzxUTZKZAxJNUd24r8e A/aqF+NmNP+nGi30Dk5FMvJrh3Wz9//HGGRNayhIhz52mo5L9fGeviQ6LlXK55xH/WgF sUM6DamMUuZvFX8BQzFtBwq9U07uUGNbw1p4n9xg0w6r3BeQihTedZ0KERAwA+nav6oV +7aiaCkIUJGK6A8RasaLwtoBEykds2pKFqqfqW1vv0VeIfpvk+epR+C56PAYWG+NdO61 laPA== 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=h7/0+77ndabR+mxgeXAoHMyf1o3rde7WHj0V90p1QaI=; b=bRdxbkFT+qXx783nDdi/X1Wr4PAihxjlKRNSAaRvaQuz0G2P8Gm/w86t+l4acvuWkS aDRkvFqpEwO1e5G20EIm0dd6NYCr/O5c+jrNBqZfhWku+kOAVFL11FtI8dNvwdpUGjwM 1VfV33xL5OTmOcNp8lOtp5htmZDe1EVFEnC0KfYVg/pskDM33BqYrZF26xdANrYAqcHc srtKFiLu2nZhQ6sQI3xL/PutGLVso1TBlA9d4ObpqQGEIaTonJj2d7NpvwNCyPNPCIW8 6j6gYxkZdcUB+doGqLs3o3FxRnhQGuc10OQ9TubmEJQ7Zy04FwsfmP2mIire9m004fwF ug2w== X-Gm-Message-State: AOAM5337z9UDqffI2YLr5QxoMPjakbSFYew43eJZ/VJ2Vw34+2uWKpqT 17VcbieXCwxIeVsCzeAllzmFww== X-Google-Smtp-Source: ABdhPJziHWaxeJQaB1odr8nTuQIw3SApIPPJKWycUP6hFCST1MTMEPuGtiIWcoxNijhifWrDO7tqkg== X-Received: by 2002:ae9:ed91:: with SMTP id c139mr1724055qkg.454.1623199466063; Tue, 08 Jun 2021 17:44:26 -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 n194sm12869011qka.66.2021.06.08.17.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 17:44:25 -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 v15 03/15] arm64: hibernate: abstract ttrb0 setup function Date: Tue, 8 Jun 2021 20:44:07 -0400 Message-Id: <20210609004419.936873-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210609004419.936873-1-pasha.tatashin@soleen.com> References: <20210609004419.936873-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=IVvfQXHZ; dmarc=none; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.175 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Rspamd-Server: rspam02 X-Stat-Signature: a689yij4s4dkdmdbhdqh8niq5ke8d39d X-Rspamd-Queue-Id: CEF0CA0001A9 X-HE-Tag: 1623199462-379500 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 d3cef9133539..85eb92a2ffcb 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 fa2d1cb844a7..39f0da125876 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;