From patchwork Wed Mar 3 00:22:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12113849 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.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_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 50211C433E0 for ; Wed, 3 Mar 2021 16:33:24 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 87E7A614A7 for ; Wed, 3 Mar 2021 16:33:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87E7A614A7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.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=desiato.20200630; 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=waz80f1KmrB1QOOAfkG8AGv+ji/sGDm7NLtMTFa1jBM=; b=gul9rWIoeQ7Bf5lSNJJ/GNRvT Jn2/PsD4g0FkON1BLon5oxH8J2gvJdFqcMFXOiIjaS/A1rz9XcTTAytL6XF/3wpYltJxk3pcgYvUo YVB9Gm7HBXCaocRMc1fwDI2CzhM2RTAvB2cFLUf7agQIqjN8NtB4JtDRa3ixiwXb2nVZ3iGt7lJGv BK22+uyhzMXcP0q/APDdJsTm0+UvaRDAJJXG/XIc5btB4BStLk6kZeNU4r7TGavntnlzuj9YUDpXL Quku7cm9rNTyqmVlu717KbtB8r/ioHfh3il72sDADAuS5RJIG6A2QJ3nwYYhwyifIAHb8zdeiHrBx U+KhoieRA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHUOy-005c32-B2; Wed, 03 Mar 2021 16:31:08 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSpn-005E2a-7y for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:50:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description; bh=PfFJiiZEssC2qRvy3KJXm7j/Y4Op5RWRizR2E1HngfE=; b=ZijYn5tru+2JPtvRCUYsSG9m2A I1+v3LA3qvric6v0UjLrS+cp+7Lzc8muO9sRJNU7UPPlZP2dCKFLwf9g684+FAg8EspKnd3FBdEFl efd+BoARMHkhjxVxiUWY73sJUcKzgcWuiB6qRT2XVvxsxblN0+H2szK6p2t8YDEyEojalQCYMzJy0 vIsMrOS/DHohr2Ya/hbAO5kRnAousOdtxNxQSWqu2BviGFdG9w5Im1dKh+qIrie3MmiX9Aq0f6gpM urZhkjI0JaMHX90xvUs/h035tRp892OM0gIGmnURczemlWFxRRtXDmQPGY152cdroufD8WtmLrLe5 ZhyGiGiw==; Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHFIv-000jcI-5E for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 00:23:53 +0000 Received: by mail-qk1-x731.google.com with SMTP id f124so4158664qkj.5 for ; Tue, 02 Mar 2021 16:23:42 -0800 (PST) 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=PfFJiiZEssC2qRvy3KJXm7j/Y4Op5RWRizR2E1HngfE=; b=jMDvuz/Zgmq1B1MpVMXtPYeQ4yIQVYunhOd0cuqlnPu73G25rI6A8bbQBy7YIsq+XL QLFaC6VqVzMJKOhhn6eYQS9l2TbV/YMXjSMgRvzpw+kAe19ABWobfO0KCffKshahDMdI bUlq1RwNGtmC7j7E3GIqW51fgJ+qLsCRs7WDT07CRyQw/7RmxffV2qQ5/UKUDv4FWBAd rEakxu/EEIwCQfy3eqO5Nq7V6xiG538snw78opWM2Sc0e/ol/nnofnFY7H9ogH44hG/Y QWBHfv7b8Hjc3HJ2evECDpilQuTYVfBG/XhchNb4WN/jfozGm70uSgAosPcJBkyAtyS7 tJWw== 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=PfFJiiZEssC2qRvy3KJXm7j/Y4Op5RWRizR2E1HngfE=; b=aQ4D6VRyumi5roYTBZOD7dq3HroL27NYmkvF/RS2CmS9/Ycf1Fw1uWuQoWsW62AB4/ FPUYYD9L+YQju2zvNMNDfFaG9bgh0uhP7+Kg5O4+/I9U61e0pVFrbkkQnLnSNpgb+MU/ nCsDNGy61QCaKUhD1t2h75eNI/cMJmLkqf9kbFSh+4GNBWGd+CKg7DVOBbpZJ9K56FID L6ubIdtS7BPd8KwLyAUxbNLIi5YH3QyT6E9W1xIRo8kGRLLwU/M2bdlZXGeg6SwvvQT/ RlYKc4tBmmuI+thvy3LAsezfck+HugnMS74skq8XhaDd4H7luEVV67gpsrLHcCvoLBJk Fh3w== X-Gm-Message-State: AOAM531EKh2rXyeDjVagYTFyvhoAHjT4U4kFT6GTYKAOY7t1cnxcpe1P weK4ynCQCc6JaY68gYNa481Q7g== X-Google-Smtp-Source: ABdhPJz+uVEaSRAvPV9aeu5i6C2Vj6mlXfoQyiLGMJfrnW+9tKudvptZdZIYZEjfRvwkDzISw2eE+Q== X-Received: by 2002:a37:4e01:: with SMTP id c1mr10344514qkb.16.1614730960877; Tue, 02 Mar 2021 16:22:40 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id r3sm16690512qkm.129.2021.03.02.16.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 16:22:40 -0800 (PST) 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 Subject: [PATCH v12 06/17] arm64: hibernate: abstract ttrb0 setup function Date: Tue, 2 Mar 2021 19:22:19 -0500 Message-Id: <20210303002230.1083176-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303002230.1083176-1-pasha.tatashin@soleen.com> References: <20210303002230.1083176-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-20210303_002353_735331_54777A08 X-CRM114-Status: GOOD ( 13.74 ) 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 functinality when relocation code is going to be idmapped. Move the setup seqeuence 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 70ce8c1d2b07..c6521c8c06ac 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -132,6 +132,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 0b8bad8bb6eb..ded5115bcb63 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -206,26 +206,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;