From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3828EC433EF for ; Fri, 10 Dec 2021 11:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lh8QVYIyKtsVkOLcebcs1v3pbef53tx9YtPdu7wTEUs=; b=Q778cHSGEUItGd THZXEz/YoPWsUQMbTM26lUoKn5t3SyP8KmJUiVZuANQY00ybR2f+7wWbp2gl2z6Q0B2Ldudmo36Xk 3LdwlqsRBFZl9tjqrRpEhmCq8UWLtEOj1TbpZwY1KDcqzieUZvz23yfvf3VzFGpx4t84oNk9iO7X3 7HjQ8SuKihXUyFBVYwnoW4ntWU3WK/D7FDAAxxy+dl23WFppuYb1270203O8OmcHsTTOmUED0rm2X IhrMK+ttf6sQoIfOqfGc56A4xYopTDTYRaTZ4C/YdC7s0MPKwn1pC9lfnW7ffAF7k3SDtY6FcydN3 5h8z0F7JYU6X25ZCjTxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mveWD-001kZd-Gy; Fri, 10 Dec 2021 11:56:53 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mveW9-001kZ9-Sf for linux-arm-kernel@lists.infradead.org; Fri, 10 Dec 2021 11:56:51 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8DF39B827E9; Fri, 10 Dec 2021 11:56:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74983C00446; Fri, 10 Dec 2021 11:56:46 +0000 (UTC) Date: Fri, 10 Dec 2021 11:56:43 +0000 From: Catalin Marinas To: Kefeng Wang Cc: Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] arm64: mm: Make randomization works again in some case Message-ID: References: <20211104062747.55206-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211104062747.55206-1-wangkefeng.wang@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211210_035650_085201_CE1D78B6 X-CRM114-Status: GOOD ( 24.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Nov 04, 2021 at 02:27:47PM +0800, Kefeng Wang wrote: > After commit 97d6786e0669 ("arm64: mm: account for hotplug memory when > randomizing the linear region"), the KASLR could not work well in some > case, eg, without memory hotplug and with va=39/pa=44, that is, linear > region size < CPU's addressable PA range, the KASLR fails now but could > work before this commit. Let's calculate pa range by memblock end/start > without CONFIG_RANDOMIZE_BASE. > > Meanwhile, let's add a warning message if linear region size is too small > for randomization. > > Signed-off-by: Kefeng Wang > --- > Hi Ard, one more question, the parange from mmfr0 register may also too large, > then even with this patch, the randomization still could not work. > > If we know the max physical memory range(including hotplug memory), could we > add a way(maybe cmdline) to set max parange, then we could make randomization > works in more cases, any thought? > > arch/arm64/mm/init.c | 30 +++++++++++++++++++++--------- > 1 file changed, 21 insertions(+), 9 deletions(-) > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index a8834434af99..27ec7f2c6fdb 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -284,21 +284,33 @@ void __init arm64_memblock_init(void) > > if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { > extern u16 memstart_offset_seed; > - u64 mmfr0 = read_cpuid(ID_AA64MMFR0_EL1); > - int parange = cpuid_feature_extract_unsigned_field( > - mmfr0, ID_AA64MMFR0_PARANGE_SHIFT); > - s64 range = linear_region_size - > - BIT(id_aa64mmfr0_parange_to_phys_shift(parange)); > + s64 range; > + > + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) { > + u64 mmfr0 = read_cpuid(ID_AA64MMFR0_EL1); > + int parange = cpuid_feature_extract_unsigned_field( > + mmfr0, ID_AA64MMFR0_PARANGE_SHIFT); > + range = linear_region_size - > + BIT(id_aa64mmfr0_parange_to_phys_shift(parange)); > + > + } else { > + range = linear_region_size - > + (memblock_end_of_DRAM() - memblock_start_of_DRAM()); > + } I'm not a big fan of making this choice depend on memory hotplug. Could we instead just limit the randomisation to the minimum of va bits and pa bits? We can keep the warning. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel