From patchwork Thu Sep 30 14:31:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12528541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEB66C433F5 for ; Thu, 30 Sep 2021 14:34:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 9DA8C60FC2 for ; Thu, 30 Sep 2021 14:34:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9DA8C60FC2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QF5TuBiBN/+yiLm/EwWKfUv2MkDNSHsx8wzsgTu9sQo=; b=mLyUFCbT+ZeiBK t8Htto9GUqLa4CcGxLErvidJynGCsdCS1AUe9ZSHjSKsoyLFiYMVmFapH7PjjHBicNeiAI8FuuJLn prQKOPgd5IN7Tfw52WZH5fKn/shIrFXmxcMuOACqbcr5afA1/BpVrEG5ialqjg5ryHYhZbsluNg3i h4RddAr0kgSqiRCPXZtOMwL/yDYHA//Y4Io1fJmq1g06GUexpir5TmZ/DEhRchA4KtBLOeXHa9Wsg ymMTkYVohPdAwJBu57Ggz6clegFZhthVYXWvmx5A+8pC8inlaIlrySB7FRV5roONWi+vzDN49DjDI uskJxQ+WIfIsbxbNZvYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVx7Z-00Ei7b-Pb; Thu, 30 Sep 2021 14:33:14 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVx5j-00EhNz-Oq for linux-arm-kernel@lists.infradead.org; Thu, 30 Sep 2021 14:31:23 +0000 Received: by mail-qv1-xf31.google.com with SMTP id a14so3683790qvb.6 for ; Thu, 30 Sep 2021 07:31:19 -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=e39R8ZsIeIwklE8cpr9UY0qKnjifmGWiOSmlNRknozY=; b=Dvw31wgsS8G8oxRKiLY9AhC7vsIrGYUqnkg0rdzHudMErK/hqx/f2xKLuM+d+wFz94 JUmD5np8vuwG2sGXNGsbm1qYTnL5SwmKk3BvG6nraqjwNtTgysYN2X6REwY/fvMqNdAz WLoSnNhuaCUYjqopKhwffkXgoe7lX17Re98nrYZngFujO2+9S5P4HTM+0zeBJdgd5nLG 2YrkHbtNBlzYOOJByqwcPTwT9QKuRm31Mkw6DL6XZxRQc6JsHrc/vF3FUunfcRX4Tuxg zJNVbfpaez0v6k+uebd2NVVfyA93/+wABN7kKOsZMg78c45ftAn4QhH3QWl22IAt60Vj 3CeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e39R8ZsIeIwklE8cpr9UY0qKnjifmGWiOSmlNRknozY=; b=JJMMpvXPEnlmsW4UWp6J/PEOSwx1pj0PEmQIyHLdb7oVdTd4kPFGxPtS8Dlych9ZTE H7xKeWyJlkAS/fHJpQ81Nc0ExNqWGFc2LySsEdA8lQTwW4cLkTbp0hk0svvR8IBO6G8+ 4kQs5gON0Iyde+51bpVcoklg992pJvg/rhzbkcpNJVt7pcWUiFr/HNxIiyrr9gFbs3uH g4KUk3m7oG4G7M1smbwsJiyRbScTl8k4TxZBcA3O4Ndag9yE/SooF+cQiKEzEDNUkqJZ 3qzRgYzo9xx0gcToV48yQ9kKypKyzv1QAwy/tC7EV88gQlxfVYQG3AoBMhUlQfQ2xqGy n7iA== X-Gm-Message-State: AOAM5327TOek9QKATAER8fmdRDL0Hxijgwn02s9v5uf74B5d/nWbWRGw 9r+2xhAYakG3dGGqkYBS60bmFQ== X-Google-Smtp-Source: ABdhPJyKP/5js7mH/GPTqK5GuDttLVlJNJvbT8t4LfCfXnHZzGw54YFenib9JG+PlW6v9j7cikxMqQ== X-Received: by 2002:a05:6214:2d1:: with SMTP id g17mr5468778qvu.63.1633012278962; Thu, 30 Sep 2021 07:31:18 -0700 (PDT) Received: from soleen.c.googlers.com.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id l195sm1528731qke.98.2021.09.30.07.31.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 07:31:18 -0700 (PDT) From: Pasha Tatashin To: pasha.tatashin@soleen.com, 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, kernelfans@gmail.com, akpm@linux-foundation.org Subject: [PATCH v18 03/15] arm64: hibernate: abstract ttrb0 setup function Date: Thu, 30 Sep 2021 14:31:01 +0000 Message-Id: <20210930143113.1502553-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog In-Reply-To: <20210930143113.1502553-1-pasha.tatashin@soleen.com> References: <20210930143113.1502553-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210930_073119_885536_94B4A4CC X-CRM114-Status: GOOD ( 15.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: Pasha Tatashin Acked-by: Catalin Marinas --- 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 f4ba93d4ffeb..6770667b34a3 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;