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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8597C433EF for ; Thu, 4 Nov 2021 06:24:35 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 97799611C9 for ; Thu, 4 Nov 2021 06:24:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 97799611C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:To:Subject:MIME-Version: Date:Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KR63YOpIoYkmN4i2ojxkS7PrfMvKyRsrSrvl0zMqI+c=; b=dPHBICr4wYm9If/Oi+M4hjAf0J 6Z4sAwRN7HOtYkCDYEB5qL8uUspvQpd4nGtn461DhL6re5AoG9/s1xLw+wtDMSoT4F78q3zxTpAb6 k3fzQbPOJVGLWK+iG14Vf79DPNy0KA7vjXk+8ATEF8zGzFl97CFnTYvQfy2czsXbVwhn0Ih35MQZu CmgmjkUrNgtnIKtu3VB8/Sx1wwc/rJB3EwQbaWdtd7oQA7qH0NkfU9eWIQKmHi6CNHCJ5v5CREqy8 sKNjmeE6WGD16NRNP+ijzrla6kJIKYSxe/cAhHoaTtd25pl2KByutqdxX9eIPcpA+3rUCPS7EBCUQ HAZqhonw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1miW9n-00813v-Pm; Thu, 04 Nov 2021 06:23:27 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1miW9i-00811S-Ur for linux-arm-kernel@lists.infradead.org; Thu, 04 Nov 2021 06:23:25 +0000 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HlD8r6ymgz90fm; Thu, 4 Nov 2021 14:23:08 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 4 Nov 2021 14:23:18 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.15; Thu, 4 Nov 2021 14:23:18 +0800 Message-ID: Date: Thu, 4 Nov 2021 14:23:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH] arm64: mm: Make randomization works again in some case Content-Language: en-US To: Catalin Marinas , Will Deacon , Ard Biesheuvel , References: <20211104062747.55206-1-wangkefeng.wang@huawei.com> From: Kefeng Wang In-Reply-To: <20211104062747.55206-1-wangkefeng.wang@huawei.com> X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggeme704-chm.china.huawei.com (10.1.199.100) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211103_232323_648057_8E8FD5E8 X-CRM114-Status: GOOD ( 21.51 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2021/11/4 14:27, 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. oh, should be CONFIG_MEMORY_HOTPLUG > > 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()); > + } > > /* > * If the size of the linear region exceeds, by a sufficient > * margin, the size of the region that the physical memory can > * span, randomize the linear region as well. > */ > - if (memstart_offset_seed > 0 && range >= (s64)ARM64_MEMSTART_ALIGN) { > - range /= ARM64_MEMSTART_ALIGN; > - memstart_addr -= ARM64_MEMSTART_ALIGN * > - ((range * memstart_offset_seed) >> 16); > + if (memstart_offset_seed > 0) { > + if (range < (s64)ARM64_MEMSTART_ALIGN) { > + pr_warn("linear mappings size is too small for KASLR\n"); > + } else { > + range /= ARM64_MEMSTART_ALIGN; > + memstart_addr -= ARM64_MEMSTART_ALIGN * > + ((range * memstart_offset_seed) >> 16); > + } > } > } > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel