From patchwork Mon Dec 4 14:13:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10090463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D708760329 for ; Mon, 4 Dec 2017 14:16:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C68F3288BE for ; Mon, 4 Dec 2017 14:16:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB220288CF; Mon, 4 Dec 2017 14:16:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 14BFB288BE for ; Mon, 4 Dec 2017 14:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=CALVDNyH3vOnVAXeqI5t2DdZCWyfs6Cwyt5sXseyVac=; b=FdrFUmpChiPdDxv4bDaxSt+D5Q VUm6z5osZCRBjjZ/Q6WWbn+1/rLJw5GyWmkVdWyptDrop3euYGk4qF4ecokW0bvFAzTotisF6lI/m Lk9MPJvKc/l7SLKdHfy/7cS1Lgnc4kIjVcKf7CrnWAEvmVmVRGjTvcp6e61LEjx/snR8KhQ3Uo6WO E854APEeUCLX9ASHUK4KwIMEVProH0ogzl52PTgVQg8Zy1Kj9i+/8RJXUhDblWwsAyCjeoFHxKVnp JWLYEeKl6pTid2eOc0N6lpujg8PvrIDrsj4N1QZPU0mK1ypTq0DaEluZuPiPzFp03IMwqtBy+x9ek RD/2qEIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLrXs-0000Np-8v; Mon, 04 Dec 2017 14:16:32 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLrVh-0004kG-KQ for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 14:14:38 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ED54C174E; Mon, 4 Dec 2017 06:13:42 -0800 (PST) Received: from capper-debian.emea.arm.com (unknown [10.37.7.145]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9D26C3F236; Mon, 4 Dec 2017 06:13:41 -0800 (PST) From: Steve Capper To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH 07/12] arm64: mm: Place kImage at bottom of VA space Date: Mon, 4 Dec 2017 14:13:08 +0000 Message-Id: <20171204141313.31604-8-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171204141313.31604-1-steve.capper@arm.com> References: <20171204141313.31604-1-steve.capper@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_061418_372702_0D96C3F3 X-CRM114-Status: UNSURE ( 9.64 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, ard.biesheuvel@linaro.org, Steve Capper , Suzuki.Poulose@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Re-arrange the kernel memory map s.t. the kernel image resides in the bottom 514MB of memory. With the modules, fixed map, PCI IO space placed above it. At the very bottom of the memory map we set aside a 2MB guard region to prevent ambiguity with PTR_ERR/ERR_PTR. Dynamically resizable objects such as KASAN shadow and sparsemem map are placed above the fixed size objects. This means that kernel addresses are now no longer directly dependent on VA space size. Signed-off-by: Steve Capper --- arch/arm64/include/asm/memory.h | 17 +++++++++-------- arch/arm64/include/asm/pgtable.h | 4 ++-- arch/arm64/mm/dump.c | 12 +++++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 0a912eb3d74f..ba80561c6ed8 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -68,14 +68,15 @@ #define PAGE_OFFSET (UL(0xffffffffffffffff) - \ (UL(1) << VA_BITS) + 1) #define PAGE_OFFSET_END (VA_START) -#define KIMAGE_VADDR (MODULES_END) -#define MODULES_END (MODULES_VADDR + MODULES_VSIZE) -#define MODULES_VADDR (VA_START + KASAN_SHADOW_SIZE) +#define KIMAGE_VSIZE (SZ_512M) +#define KIMAGE_VADDR (UL(0) - SZ_2M - KIMAGE_VSIZE) #define MODULES_VSIZE (SZ_128M) -#define VMEMMAP_START (-VMEMMAP_SIZE) -#define PCI_IO_END (VMEMMAP_START - SZ_2M) +#define MODULES_END (KIMAGE_VADDR) +#define MODULES_VADDR (MODULES_END - MODULES_VSIZE) +#define PCI_IO_END (MODULES_VADDR - SZ_2M) #define PCI_IO_START (PCI_IO_END - PCI_IO_SIZE) -#define FIXADDR_TOP (PCI_IO_START - SZ_2M) +#define FIXADDR_TOP (PCI_IO_START - PGDIR_SIZE) +#define VMEMMAP_START (FIXADDR_START - VMEMMAP_SIZE) #define KERNEL_START _text #define KERNEL_END _end @@ -292,10 +293,10 @@ static inline void *phys_to_virt(phys_addr_t x) #define _virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) #else #define __virt_to_pgoff(kaddr) (((u64)(kaddr) & ~PAGE_OFFSET) / PAGE_SIZE * sizeof(struct page)) -#define __page_to_voff(kaddr) (((u64)(kaddr) & ~VMEMMAP_START) * PAGE_SIZE / sizeof(struct page)) +#define __page_to_voff(kaddr) (((u64)(kaddr) - VMEMMAP_START) * PAGE_SIZE / sizeof(struct page)) #define page_to_virt(page) ((void *)((__page_to_voff(page)) | PAGE_OFFSET)) -#define virt_to_page(vaddr) ((struct page *)((__virt_to_pgoff(vaddr)) | VMEMMAP_START)) +#define virt_to_page(vaddr) ((struct page *)((__virt_to_pgoff(vaddr)) + VMEMMAP_START)) #define _virt_addr_valid(kaddr) pfn_valid((((u64)(kaddr) & ~PAGE_OFFSET) \ + PHYS_OFFSET) >> PAGE_SHIFT) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 054b37143a50..e8b4dcc11fed 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -30,8 +30,8 @@ * VMALLOC_END: extends to the available space below vmmemmap, PCI I/O space * and fixed mappings */ -#define VMALLOC_START (MODULES_END) -#define VMALLOC_END (- PUD_SIZE - VMEMMAP_SIZE - SZ_64K) +#define VMALLOC_START (VA_START + KASAN_SHADOW_SIZE) +#define VMALLOC_END (FIXADDR_TOP - PUD_SIZE) #define vmemmap ((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT)) diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c index b7b09c0fc50d..e5d1b5f432fe 100644 --- a/arch/arm64/mm/dump.c +++ b/arch/arm64/mm/dump.c @@ -36,17 +36,19 @@ static const struct addr_marker address_markers[] = { { KASAN_SHADOW_START, "Kasan shadow start" }, { KASAN_SHADOW_END, "Kasan shadow end" }, #endif - { MODULES_VADDR, "Modules start" }, - { MODULES_END, "Modules end" }, { VMALLOC_START, "vmalloc() Area" }, { VMALLOC_END, "vmalloc() End" }, +#ifdef CONFIG_SPARSEMEM_VMEMMAP + { VMEMMAP_START, "vmemmap start" }, + { VMEMMAP_START + VMEMMAP_SIZE, "vmemmap end"}, +#endif { FIXADDR_START, "Fixmap start" }, { FIXADDR_TOP, "Fixmap end" }, { PCI_IO_START, "PCI I/O start" }, { PCI_IO_END, "PCI I/O end" }, -#ifdef CONFIG_SPARSEMEM_VMEMMAP - { VMEMMAP_START, "vmemmap" }, -#endif + { MODULES_VADDR, "Modules start" }, + { MODULES_END, "Modules end" }, + { KIMAGE_VADDR, "kImage start"}, { -1, NULL }, };