From patchwork Tue Nov 21 03:44:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Feng X-Patchwork-Id: 10067623 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 7037B6022E for ; Tue, 21 Nov 2017 03:45:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D82528706 for ; Tue, 21 Nov 2017 03:45:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5193728802; Tue, 21 Nov 2017 03:45:12 +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=unavailable 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 9F47128706 for ; Tue, 21 Nov 2017 03:45:11 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=77RsiahulCcHX6O+AZ6J8qdnOE3J78VPOdF3eOqp0IY=; b=jyZzJhTuTaAAqB vaHk7A2YSgNK4N/ieS0CX/1EVp/C6vyD8t+VUH8HlZ5aak315rozFXCpQb7ccmhXk3vkAAGyzCeAF zzl69TKPpAxdWQYWgNhcFCJbGLbhdRIRcJ8eROBQKXyS0BfJ2zVMjf1tRNz820h1nCuWz3ueWvd0V Bu+UcDit43EBEPkEkYF25LWHJy9w+lKh82AQxDWxzHDHakc4cpRixF/5DAjcYTigSclNEd0NttjT6 Z6PLreyt0u34RroQveA13crxLH4bHBfP9Cg74Z+IxcZ9dtgaNTPIwNlp10EGyvuL2loqaolllddKj Z/NIQDzkIbSKd0NWOenw==; 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 1eGzUd-0008Ju-Cz; Tue, 21 Nov 2017 03:45:03 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eGzUY-00089D-A3 for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2017 03:45:01 +0000 Received: from 172.30.72.60 (EHLO DGGEMS411-HUB.china.huawei.com) ([172.30.72.60]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DLI98550; Tue, 21 Nov 2017 11:44:20 +0800 (CST) Received: from vm163-62.huawei.com (10.184.163.62) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.361.1; Tue, 21 Nov 2017 11:44:13 +0800 From: Chen Feng To: , , , , , Subject: [PATCH] arm64: kaslr: Fix kaslr end boundary of virt addr Date: Tue, 21 Nov 2017 11:44:13 +0800 Message-ID: <1511235853-8407-1-git-send-email-puck.chen@hisilicon.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.184.163.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.5A13A114.0094, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 5da194cbcaf321afd538e0dbcd64cd6b X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171120_194459_495076_0FFF0506 X-CRM114-Status: GOOD ( 10.19 ) 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: dan.zhao@hisilicon.com, chenxiang9@huawei.com, houyu3@huawei.com, suzhuangluan@hisilicon.com, xuyoujun4@huawei.com, xuyiping@hisilicon.com, chenya99@hisilicon.com 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 With kaslr and kasan enable both, I got the follow issue. [ 16.130523s]kasan: reg->base = 100000000, phys_end =1c0000000,start = ffffffff40000000, end = ffffffc000000000 [ 16.142517s]___alloc_bootmem_nopanic:257 [ 16.148284s]__alloc_memory_core_early:63, addr = 197fc7fc0 [ 16.155670s]__alloc_memory_core_early:65, virt = ffffffffd7fc7fc0 [ 16.163635s]__alloc_memory_core_early:67, toshow = ffffff8ffaff8ff8 [ 16.171783s]__alloc_memory_core_early:69, show_phy = ffffffe2649f8ff8 [ 16.180145s]Unable to handle kernel paging request at virtual address ffffff8ffaff8ff8 [ 16.189971s]pgd = ffffffad9c507000 [ 16.195220s][ffffff8ffaff8ff8] *pgd=0000000197fc8003, *pud=0000000197fc8003 *reg->base = 100000000, phys_end =1c0000000,start = ffffffff40000000, end = ffffffc000000000* memstart_addr 0 ARM64_MEMSTART_ALIGN 0x40000000 memstart_offset_seed 0xffc7 PHYS_OFFSET = 0 - memstart_addr = 0 - 3E40000000 = FFFFFFC1C0000000 reg->base = 0x100000000 -> 0xffffffff40000000 phys_end = 0x1c0000000 -> 0xffffffc000000000 This is confused, end less than start. And In memblock it use "start_addr + size" as the end addr. So in function kasan_init, if the start >= end, it will not map the hole block address. But the memory in this block is valid. And it can be allocated as well. So donot use the last memory region. Changing "range = range / ARM64_MEMSTART_ALIGN + 1" to range = range / ARM64_MEMSTART_ALIGN; Signed-off-by: Chen Feng Signed-off-by: Chen Xiang --- arch/arm64/mm/init.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 716d122..60112c0 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -267,11 +267,8 @@ void __init arm64_memblock_init(void) * margin, the size of the region that the available physical * memory spans, randomize the linear region as well. */ - if (memstart_offset_seed > 0 && range >= ARM64_MEMSTART_ALIGN) { - range = range / ARM64_MEMSTART_ALIGN + 1; - memstart_addr -= ARM64_MEMSTART_ALIGN * - ((range * memstart_offset_seed) >> 16); - } + if (memstart_offset_seed > 0 && range >= ARM64_MEMSTART_ALIGN) + memstart_addr -= (range * memstart_offset_seed) >> 16; } /*