From patchwork Tue Jun 12 06:36:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupesh Sharma X-Patchwork-Id: 10459419 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 EDEA5601A0 for ; Tue, 12 Jun 2018 06:44:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC39028669 for ; Tue, 12 Jun 2018 06:44:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF1EC28671; Tue, 12 Jun 2018 06:44:37 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 4D6F428669 for ; Tue, 12 Jun 2018 06:44:37 +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: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=bX81KI+E3V3KElsJyKkObCZ9Ub8LcFDOLiIdcH88UjY=; b=M6j 20KeMIQyqNAJ788PRTgmqH519YN50Z2PaNKy/nzSoNG6T6cVTP5oDcNFQxIM8w0eH1kj865Bn2OqY PQk5I6BRT55Lret6D88xscumm7spSmt0LRjWK3MFYLWhVKQN0xFs6sE4rfSBY4tkuTMGfgtVqE+j4 /WPhPmN6aF9lo/2h7sMLhKBZ0Va+pxZ7gIbAv/hbVoNog88kHzWrqo+xAbG5JHhvPSNGXWpa4d/rR L2cpzjriBCzeHr0t6zhsrY5uAa8mREAdpEqxXbN7EMwwMDPY0kMPewFOavQqAZXhfqmz8YutF156x g5kEApHIWfsnn939S3XssWigIjIi5Wg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSd2U-0001Wd-1H; Tue, 12 Jun 2018 06:44:22 +0000 Received: from mail-pf0-f193.google.com ([209.85.192.193]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSd1z-0000xP-J3 for linux-arm-kernel@lists.infradead.org; Tue, 12 Jun 2018 06:44:18 +0000 Received: by mail-pf0-f193.google.com with SMTP id z24-v6so11561065pfe.7 for ; Mon, 11 Jun 2018 23:43:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5UgfCLcGJ2kMTpBaLZCCIu8RWQIPJFSGuYfacntFM0I=; b=A24gZLfOE7/U2wHU0AjUdJIIFeu2co080toxSbgT+NHhlx9uY0as78AeYZCl4EDBiv Ocw14YQXaycI85TIUZPCVqLF8+U6n2uGc0tZEnfSQL41y/kP2d2G9mvNByeS8a602iaj BabW3CJ+p0gwjUr7j1zxUvN7VySfMMrXWEMTy0o7AKxfvIBBOD0bKt1l6uul6vDgO4zy THjJaMBMt/LSNuYwyEB+XDffHh7/UTwARN7L6UrgnnHRBf8OZu5FkPGm2EqCssmp0N4R PLAlRt3V2qZRcYSpwz9tFa02ZXRa22Z1YRcDfl6K/YzJ6E6yW6dvkncrmrlIHwDdnVEL yyyQ== X-Gm-Message-State: APt69E1VXZ22rZH/WvUjaAf+sH4kOLoohZxP95/2Pt49Z6bQz6Zh7kP/ lL4yhL4MYmy646vXfOMfcyrK/i5ShVE= X-Google-Smtp-Source: ADUXVKLCbkRNW/6RrdKWHbcNoRxAu6wMzulI8f+fPwF5i6UY5ioXAc7ziKnNkFFF9cVPuZ4tvu8CaA== X-Received: by 2002:a63:5f54:: with SMTP id t81-v6mr2066603pgb.108.1528785379443; Mon, 11 Jun 2018 23:36:19 -0700 (PDT) Received: from localhost ([122.177.60.236]) by smtp.gmail.com with ESMTPSA id k15-v6sm430410pfi.37.2018.06.11.23.36.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 23:36:17 -0700 (PDT) From: Bhupesh Sharma To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64/mm: Introduce a variable to hold base address of linear region Date: Tue, 12 Jun 2018 12:06:01 +0530 Message-Id: <1528785361-24477-1-git-send-email-bhsharma@redhat.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180611_234351_644352_7A16DE14 X-CRM114-Status: GOOD ( 16.22 ) 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: Mark Rutland , Ard Biesheuvel , catalin.marinas@arm.com, Bhupesh Sharma , kexec@lists.infradead.org, Will Deacon , AKASHI Takahiro , James Morse , bhupesh.linux@gmail.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 The start of the linear region map on a KASLR enabled ARM64 machine - which supports a compatible EFI firmware (with EFI_RNG_PROTOCOL support), is no longer correctly represented by the PAGE_OFFSET macro, since it is defined as: (UL(1) << (VA_BITS - 1)) + 1) So taking an example of a platform with VA_BITS=48, this gives a static value of: PAGE_OFFSET = 0xffff800000000000 However, for the KASLR case, we use the 'memstart_offset_seed' to randomize the linear region - since 'memstart_addr' indicates the start of physical RAM, we randomize the same on basis of 'memstart_offset_seed' value. As the PAGE_OFFSET value is used presently by several user space tools (for e.g. makedumpfile and crash tools) to determine the start of linear region and hence to read addresses (like PT_NOTE fields) from '/proc/kcore' for the non-KASLR boot cases, so it would be better to use 'memblock_start_of_DRAM()' value (converted to virtual) as the start of linear region for the KASLR cases and default to the PAGE_OFFSET value for non-KASLR cases to indicate the start of linear region. I tested this on my qualcomm (which supports EFI_RNG_PROTOCOL) and apm mustang (which does not support EFI_RNG_PROTOCOL) arm64 boards and was able to use a modified user space utility (like kexec-tools and makedumpfile) to determine the start of linear region correctly for both the KASLR and non-KASLR boot cases. Cc: Ard Biesheuvel Cc: Mark Rutland Cc: Will Deacon Cc: AKASHI Takahiro Cc: James Morse Signed-off-by: Bhupesh Sharma --- arch/arm64/include/asm/memory.h | 3 +++ arch/arm64/kernel/arm64ksyms.c | 1 + arch/arm64/mm/init.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 49d99214f43c..bfd0915ecaf8 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -178,6 +178,9 @@ extern s64 memstart_addr; /* PHYS_OFFSET - the physical address of the start of memory. */ #define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; }) +/* the virtual base of the linear region. */ +extern s64 linear_reg_start_addr; + /* the virtual base of the kernel image (minus TEXT_OFFSET) */ extern u64 kimage_vaddr; diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c index d894a20b70b2..a92238ea45ff 100644 --- a/arch/arm64/kernel/arm64ksyms.c +++ b/arch/arm64/kernel/arm64ksyms.c @@ -42,6 +42,7 @@ EXPORT_SYMBOL(__arch_copy_in_user); /* physical memory */ EXPORT_SYMBOL(memstart_addr); +EXPORT_SYMBOL(linear_reg_start_addr); /* string / mem functions */ EXPORT_SYMBOL(strchr); diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 325cfb3b858a..29447adb0eef 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -60,6 +60,7 @@ * that cannot be mistaken for a real physical address. */ s64 memstart_addr __ro_after_init = -1; +s64 linear_reg_start_addr __ro_after_init = PAGE_OFFSET; phys_addr_t arm64_dma_phys_limit __ro_after_init; #ifdef CONFIG_BLK_DEV_INITRD @@ -452,6 +453,8 @@ void __init arm64_memblock_init(void) } } + linear_reg_start_addr = __phys_to_virt(memblock_start_of_DRAM()); + /* * Register the kernel text, kernel data, initrd, and initial * pagetables with memblock.