From patchwork Mon Feb 15 09:28:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 61926 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp956589lbl; Mon, 15 Feb 2016 01:36:37 -0800 (PST) X-Received: by 10.66.62.195 with SMTP id a3mr22194085pas.28.1455528997778; Mon, 15 Feb 2016 01:36:37 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id f12si3879220pat.18.2016.02.15.01.36.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Feb 2016 01:36:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVFSq-0008Ek-JJ; Mon, 15 Feb 2016 09:29:04 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVFSm-00084d-9q for linux-arm-kernel@lists.infradead.org; Mon, 15 Feb 2016 09:29:02 +0000 Received: by mail-wm0-x22c.google.com with SMTP id a4so47203161wme.1 for ; Mon, 15 Feb 2016 01:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=8ILKlQQhBDKwcJGWm7a1Pad5GTtyDzHU52h9pEyQO8I=; b=iLzr/dFB4Kqw4GEv703rMYcl9mfNZFoJ+6J0r00unl4hjA9oWBc9q+YnQCyHHTFd1K Ki1a9I+OH8noedkh9xM/4NzpZbfap7AY4U2uouJklE3O5rW5L7aanooxyguy/NV5/VeD g8h6KXexL5tZQ6NDJv12+2FAp5TR59WI+hAbM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8ILKlQQhBDKwcJGWm7a1Pad5GTtyDzHU52h9pEyQO8I=; b=ZRh7v6pPLFy5Qc+P27hfn+2pFS+bEM2R0DS9D/ytTo5ohB+6usvIl+4Z1QVf2fFV0N d95dzDPgDvrIJc2DM9O0mF4EZ/MKdkEIDwZMw2MXOGMgRASNaMVC7Rrplpom+eBbVxgx XUDcDBk2m+pK8jNxrvxMM5brhgiIJu0AfC5L/3pv2kEWoTa+AebBi/xE2FBTxCG6l617 RJltS39GC3BWgJ1AV1PCIdqTAvRsPFya3+DYTtVkE0wg1Ekwq98+P+wyBQRRVtR0FeVA 6/DrHPY0pJwT+NxcYA0+snXCPKMipPcGsZx1gyJxl9kyizd95i82V+qoKD//CmYbvVJ6 gf6w== X-Gm-Message-State: AG10YORLdgUvaI8OQvOK72CeHYYt5X+VYdw9QAi6PeaBS/Q8JuBqJSTjp7acb/Wa3DyN8Y5k X-Received: by 10.194.249.42 with SMTP id yr10mr7130276wjc.12.1455528518853; Mon, 15 Feb 2016 01:28:38 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id uo9sm24382179wjc.49.2016.02.15.01.28.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Feb 2016 01:28:38 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, mark.rutland@arm.com, james.morse@arm.com Subject: [PATCH] arm64: mark kernel text segment as MEMBLOCK_NOMAP Date: Mon, 15 Feb 2016 10:28:32 +0100 Message-Id: <1455528512-32491-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160215_012900_623384_58279E24 X-CRM114-Status: GOOD ( 15.12 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:22c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Commit 752af28bd711 ("arm64: move kernel image to base of vmalloc area") moves the mapping of the kernel text and data segments out of the linear region, and takes care not to create a writable alias of the read-only kernel text segment by checking each memblock against overlap when the memblocks are mapped into the linear mapping. However, it is more correct, and much simpler, to mark the [_stext, _etext] interval as MEMBLOCK_NOMAP. This will also prevent the interval from being omitted from the linear region, but this fact will now also be reflected in the output of pfn_valid(), and so code that expects any pfn_valid() page to be mapped and accessible (which is a reasonable assumption) does not get surprised by the text segment being inaccessible via the linear mapping. Signed-off-by: Ard Biesheuvel --- This should hopefully address the issue reported by James, but I suppose more work is required on the hibernate side to ensure the unmapped text region is preserved, since it is no longer covered by the linear mapping. arch/arm64/mm/init.c | 1 + arch/arm64/mm/mmu.c | 39 ++------------------ 2 files changed, 4 insertions(+), 36 deletions(-) -- 2.5.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 023c41f22b5b..e895fb6ff9dd 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -218,6 +218,7 @@ void __init arm64_memblock_init(void) * pagetables with memblock. */ memblock_reserve(__pa(_text), _end - _text); + memblock_mark_nomap(__pa(_stext), _etext - _stext); #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start) { memblock_reserve(initrd_start, initrd_end - initrd_start); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 5d7e0b801ab7..5ca2f315ba9d 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -352,41 +352,6 @@ static void create_mapping_late(phys_addr_t phys, unsigned long virt, late_pgtable_alloc); } -static void __init __map_memblock(pgd_t *pgd, phys_addr_t start, phys_addr_t end) -{ - - unsigned long kernel_start = __pa(_stext); - unsigned long kernel_end = __pa(_etext); - - /* - * Take care not to create a writable alias for the - * read-only text and rodata sections of the kernel image. - */ - - /* No overlap with the kernel text */ - if (end < kernel_start || start >= kernel_end) { - __create_pgd_mapping(pgd, start, __phys_to_virt(start), - end - start, PAGE_KERNEL, - early_pgtable_alloc); - return; - } - - /* - * This block overlaps the kernel text mapping. Map the portion(s) which - * don't overlap. - */ - if (start < kernel_start) - __create_pgd_mapping(pgd, start, - __phys_to_virt(start), - kernel_start - start, PAGE_KERNEL, - early_pgtable_alloc); - if (kernel_end < end) - __create_pgd_mapping(pgd, kernel_end, - __phys_to_virt(kernel_end), - end - kernel_end, PAGE_KERNEL, - early_pgtable_alloc); -} - static void __init map_mem(pgd_t *pgd) { struct memblock_region *reg; @@ -401,7 +366,9 @@ static void __init map_mem(pgd_t *pgd) if (memblock_is_nomap(reg)) continue; - __map_memblock(pgd, start, end); + __create_pgd_mapping(pgd, start, __phys_to_virt(start), + end - start, PAGE_KERNEL, + early_pgtable_alloc); } }