From patchwork Thu Sep 16 23:13:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12500491 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=-17.1 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,USER_AGENT_GIT autolearn=unavailable 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 836B0C433F5 for ; Thu, 16 Sep 2021 23:17:50 +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 500036103C for ; Thu, 16 Sep 2021 23:17:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 500036103C 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=ic8fEhvSNX7zwK/taJa+p12JEuSOQ9NCIn7RCvRVSi4=; b=sA05s2eN37YF6y ZRXqF6IUCi0Jgq2trxiktJ3McMGGX+DwENWBIQsmfGb9mu6AQ72udhN2ppqYhUjN9g8uSL5bKqhUP S8St/vpwppxhY80HlSujns7uzEEgtY3G5QGR5viVRvYMChCG2ZCeWU54rrBRtLKeKQzy2RhDB0yqS FkP2h0s8CPCY/+ei+nvoHgQdXKDyXnhOTYf9zCJ1w5ak3JQgFqXCTwVKD6TU+giOZL3H3MAZbrdBp mE6NHeSKmjYhLwYgV+8OydM+3imJLUro4val2iDQJVd9D5mn4rzgPWaF1DDRkiTOxgu8XOplnHpmn dp1TstCMZTKsY8989aqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mR0bj-00Cb9S-8S; Thu, 16 Sep 2021 23:15:56 +0000 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mR0ZW-00Ca5q-NL for linux-arm-kernel@lists.infradead.org; Thu, 16 Sep 2021 23:13:41 +0000 Received: by mail-qt1-x829.google.com with SMTP id s15so7139373qta.10 for ; Thu, 16 Sep 2021 16:13:33 -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=vATAyacEN1RBZ4iY9UvfQznDv8XKXbprxPlso1XrO3s=; b=gZB9fgDcFd48xLYIrxyh+JGpbXTeFbm0ji1GBX7tm82vd7HFkYtLoMTXTT4IhnMlZ6 5bLx5mqq+ycUoQPIfP+lE4fs9sQqeYiIx3OdOmj1BVHNmMoSVaFjRhoDV9x7oDyQH0Ly EcUgOsZW+ExaRa+Ifjsyu9ljpRI7YFva8jH4Y/B14osyeDOz1EojnubioGqn4HrfXVmN QQ1EoGD+L/mRut1G/X5rQcThsMTcwmlq9t87oSm8rHbaGaEq0T6MgYJQ2PXCCfnE4KBC EzalqM8ViXMhxDwIfHp2282OL0rNPf1h1YEXmGPzTHQS7OWvI6nbW/Ow5/taEGoYgX5P jbqQ== 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=vATAyacEN1RBZ4iY9UvfQznDv8XKXbprxPlso1XrO3s=; b=j0xH+TUQCyv+lR1KHaxX4Mwk+dY33baklSERlmf9SP/YFtLa+joOVF5XgfdMZi7aDr Vj1SIC+a9hSujDUjhQArOfkqC2Ml2elFd4y4hZjAj5lEPz8w0Z29+1dgixpM9ICflVpS QiR+ycHShd/ZSJa6tAXhBC8wXR38YQ8r4lrtY6TSLG+Lm2HiKrrSLGRZzc509FmHlQYK CNhRy88LdKrTcXaJYqFOrs0FzobErS0rZNm2wAzhzHuxyj5W6CKOL1w/qXk9Dj8ArZIS 6Vx2PkvY6awyBwWkcVAanfmu1jcqGSsCMoT+fukOEN47LKxB1eeBVkOaFy4tSCKny1t2 0Uzw== X-Gm-Message-State: AOAM5301Vd+5K0HxTSvb5l71axEq5mzeQyz5/PbJDgzoxKuP4Tcy3Aih pCRho3JBl+Jk2FkB2k2MRmdjnA== X-Google-Smtp-Source: ABdhPJysMPROcVY9uVmXIYZZutZ8Tz1xrsOad/eRErKKPAsu10LVzfxhmRCZ46+JETnnHyeGrvmtDQ== X-Received: by 2002:a05:622a:199d:: with SMTP id u29mr7515959qtc.357.1631834012463; Thu, 16 Sep 2021 16:13:32 -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 az6sm3312891qkb.70.2021.09.16.16.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 16:13:32 -0700 (PDT) From: Pasha 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 v17 03/15] arm64: hibernate: abstract ttrb0 setup function Date: Thu, 16 Sep 2021 19:13:13 -0400 Message-Id: <20210916231325.125533-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210916231325.125533-1-pasha.tatashin@soleen.com> References: <20210916231325.125533-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-20210916_161338_836312_B67EDF86 X-CRM114-Status: GOOD ( 15.72 ) 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 --- 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;