From patchwork Wed Sep 16 03:25:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 11778777 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2D90112E for ; Wed, 16 Sep 2020 03:27:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 8354821D94 for ; Wed, 16 Sep 2020 03:27:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dWE7TtX0"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iwzImUIL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8354821D94 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gVXnV9335INgrOhxf6lnhuuKbKVq1hC6QBUdxz8/rRQ=; b=dWE7TtX0vi6ceCgOTdo5EIADv DklhVPhpfkt8R+cOQ218xxYfRKuolXiTA13to69BYOBhu8u05Hg86zyIs7/kq9UMoDhyThmGTXD8W MtF2A5CAkRdUZobHYmkQNVLYgzZhTYByq9d/rDiC6e+zLCBr+AC+EvcMOZEVwl/CEU16Ol2XgpbHm 9WiE3BsYTTTuvJCRT3w4fyTcLsiQszR9MxMYMg+9CPHCPVBAzJfKHxpyvMP6XkthmvmDofY6BPHoL oqE5uFHpyEinRZrpkF/Z0KfR5nF+u0W4KWF6UkN/wCKt8iPmBomoJ54mW6uh7SbqpcfWsKzvQEx2P ATuCUh/Kg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIO5V-0007Qr-Rj; Wed, 16 Sep 2020 03:26:29 +0000 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120] helo=us-smtp-1.mimecast.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIO5R-0007Q0-2i for linux-arm-kernel@lists.infradead.org; Wed, 16 Sep 2020 03:26:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600226784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=havTeoYgtA9GOaGDzgKjIxi/dmZGW3kqKm8c6KarYTo=; b=iwzImUILXEtdLHpk0yXKXFGCKQ6DjHL+f8k/zSUPMmW7xFucJewrrMIpeh4r2YHbxvSgDU EzJv8PPx+JbCkbV3KOegqwDzpyfmFCn7eK2dbi3VaoM4zURoSIEKxpNNhxqXGbyMtKhzvD hZXCBs7mAEQNMLYqGqRCwDqQLjhETpc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466-XToUsRp5NduagaNb1qbCLQ-1; Tue, 15 Sep 2020 23:26:20 -0400 X-MC-Unique: XToUsRp5NduagaNb1qbCLQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3CF45104D3E1; Wed, 16 Sep 2020 03:26:19 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-108.bne.redhat.com [10.64.54.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 290287BE49; Wed, 16 Sep 2020 03:26:16 +0000 (UTC) From: Gavin Shan To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] arm64/mm: Introduce zero PGD table Date: Wed, 16 Sep 2020 13:25:22 +1000 Message-Id: <20200916032523.13011-2-gshan@redhat.com> In-Reply-To: <20200916032523.13011-1-gshan@redhat.com> References: <20200916032523.13011-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200915_232625_175626_967D094F X-CRM114-Status: GOOD ( 15.41 ) X-Spam-Score: -3.2 (---) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-3.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [205.139.110.120 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [205.139.110.120 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -3.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, shan.gavin@gmail.com, will@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The zero PGD table is used when TTBR_EL1 is changed. It's exactly the zero page. As the zero page(s) will be allocated dynamically when colored zero page feature is enabled in subsequent patch. the zero page(s) aren't usable during early boot stage. This introduces zero PGD table, which is decoupled from the zero page(s). Signed-off-by: Gavin Shan --- arch/arm64/include/asm/mmu_context.h | 6 +++--- arch/arm64/include/asm/pgtable.h | 2 ++ arch/arm64/kernel/setup.c | 2 +- arch/arm64/kernel/vmlinux.lds.S | 4 ++++ arch/arm64/mm/proc.S | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index f2d7537d6f83..6dbc5726fd56 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -36,11 +36,11 @@ static inline void contextidr_thread_switch(struct task_struct *next) } /* - * Set TTBR0 to empty_zero_page. No translations will be possible via TTBR0. + * Set TTBR0 to zero_pg_dir. No translations will be possible via TTBR0. */ static inline void cpu_set_reserved_ttbr0(void) { - unsigned long ttbr = phys_to_ttbr(__pa_symbol(empty_zero_page)); + unsigned long ttbr = phys_to_ttbr(__pa_symbol(zero_pg_dir)); write_sysreg(ttbr, ttbr0_el1); isb(); @@ -189,7 +189,7 @@ static inline void update_saved_ttbr0(struct task_struct *tsk, return; if (mm == &init_mm) - ttbr = __pa_symbol(empty_zero_page); + ttbr = __pa_symbol(zero_pg_dir); else ttbr = virt_to_phys(mm->pgd) | ASID(mm) << 48; diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index d5d3fbe73953..6953498f4d40 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -474,6 +474,8 @@ static inline bool pud_table(pud_t pud) { return true; } PUD_TYPE_TABLE) #endif +extern pgd_t zero_pg_dir[PTRS_PER_PGD]; +extern pgd_t zero_pg_end[]; extern pgd_t init_pg_dir[PTRS_PER_PGD]; extern pgd_t init_pg_end[]; extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 53acbeca4f57..7e83eaed641e 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -366,7 +366,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) * faults in case uaccess_enable() is inadvertently called by the init * thread. */ - init_task.thread_info.ttbr0 = __pa_symbol(empty_zero_page); + init_task.thread_info.ttbr0 = __pa_symbol(zero_pg_dir); #endif if (boot_args[1] || boot_args[2] || boot_args[3]) { diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 7cba7623fcec..3d3c155d10a4 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -137,6 +137,10 @@ SECTIONS /* everything from this point to __init_begin will be marked RO NX */ RO_DATA(PAGE_SIZE) + zero_pg_dir = .; + . += PAGE_SIZE; + zero_pg_end = .; + idmap_pg_dir = .; . += IDMAP_DIR_SIZE; idmap_pg_end = .; diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 796e47a571e6..90b135c366b3 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -163,7 +163,7 @@ SYM_FUNC_END(cpu_do_resume) .pushsection ".idmap.text", "awx" .macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2 - adrp \tmp1, empty_zero_page + adrp \tmp1, zero_pg_dir phys_to_ttbr \tmp2, \tmp1 offset_ttbr1 \tmp2, \tmp1 msr ttbr1_el1, \tmp2