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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A4E6C6FD1C for ; Thu, 23 Mar 2023 11:52:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C836D6B0072; Thu, 23 Mar 2023 07:52:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C33B56B0074; Thu, 23 Mar 2023 07:52:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B23406B0075; Thu, 23 Mar 2023 07:52:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A362A6B0072 for ; Thu, 23 Mar 2023 07:52:47 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7D2661201D8 for ; Thu, 23 Mar 2023 11:52:47 +0000 (UTC) X-FDA: 80600001174.01.6EE0FBC Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by imf29.hostedemail.com (Postfix) with ESMTP id 9D5A4120025 for ; Thu, 23 Mar 2023 11:52:44 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=none (imf29.hostedemail.com: domain of alex@ghiti.fr has no SPF policy when checking 217.70.183.198) smtp.mailfrom=alex@ghiti.fr; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679572364; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XRLaSltD1gfvUlow3n1B98d+wq4lhGyetQ/57dj01w0=; b=iw7pfo4F2+lsr0lBY4RkcAoeFtwahhcSs/1cn1bKz7etVlplRPoxoR66zf4GfZvRP7QFRy 4dvAcFb87zw6ytHt+cixX7aAOhaps/exuike8VUdRVbq+BnMtVHBLv7tMclBhjYxyWpmnk qvVeSc3ahe959XShYGa5cz7unPQ9NSc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=none (imf29.hostedemail.com: domain of alex@ghiti.fr has no SPF policy when checking 217.70.183.198) smtp.mailfrom=alex@ghiti.fr; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679572364; a=rsa-sha256; cv=none; b=hXMRI5fuIGCwJNUd1Kc3VoSpaoWQRRlKJKxLnooBzTLfMuOkG4bMdCtEmY6WYMq+0GAEP9 x+9DaHPcHn4EI5Wa/OjxFIYZrdIsZ1LZQB5ePPaRUTCqQe6TSxcvO13stEDhjwlv+zB/Qs Mbx7rwGCTR300/AiOoZYUgyWiVBzVS4= Received: (Authenticated sender: alex@ghiti.fr) by mail.gandi.net (Postfix) with ESMTPSA id BCAA7C0006; Thu, 23 Mar 2023 11:52:36 +0000 (UTC) Message-ID: <67ba29ff-b03d-2d24-a844-7ae25ddca447@ghiti.fr> Date: Thu, 23 Mar 2023 12:52:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v8 2/4] mm: Introduce memblock_isolate_memory Content-Language: en-US To: Mike Rapoport Cc: Alexandre Ghiti , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Andrew Morton , Anup Patel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-mm@kvack.org References: <20230316131711.1284451-1-alexghiti@rivosinc.com> <20230316131711.1284451-3-alexghiti@rivosinc.com> From: Alexandre Ghiti In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: 8b13xdtcso9gt6mbddoyzx7d458m63te X-Rspam-User: X-Rspamd-Queue-Id: 9D5A4120025 X-Rspamd-Server: rspam06 X-HE-Tag: 1679572364-885073 X-HE-Meta: U2FsdGVkX1/gLmWJTLeGQBUeKy3BNgjM5bFJ+DK3g9JziVdb0XzcSr1EAA5Bjc4ZSbmBFA5+lIDpZUe25pVkCVPMPHwWpDP6iy9RRGJQ7/em/qPAsst1v0OeMvexqcXW0KIt24ygeW9c8/tLQ5OvxaqECzhCmY+s+gC63Xb5bUjwLDgRduaFwFmbK2VTP5tNTFH4UOB3Q05TzXeJAjXIygqasHcocCVZ54BAPFgJG9Bm9PnEKQ2X/5QIUAJyr9YPryD6GZUuODR9jL+wwD7JcP63qhOpIqg3voRVTBGfGciTC0YvU2EYkr9HRDTMI0JMH58ygsTtBWvF/LNl4EvuvPpkd7pG7VkD5dAmMjTtSoIFkgA5dDRFFV8fcGqyuT56x9I/yUy0XyHihgnv0+IV1Re5O9L0J4DkYWbc/mpvnNsRlAlQBClFCHXodRwOntAg72AvX3Ck624szdOZcXrlb4J1qHxKC/8a3l63A8wRGf97bySHYWvOXkuc977OyhTcQnCknoZ5DmkjkZQcrys74ENkOQEsYllDkNCbYh8B0/yvptkNLHH3ka97qwLAbHMM5PQBigllFnypEHfgNVg9uqoxzJ0wGuxnzm7mKl4G7cfm7qpx/WYEz/10zCeV3RXUmSTav/PXZR424puqREFwxCZoPd0K2NfsfwPWunZRnd3cyLkbhx+8Mu/O/vjTczZw4XJQxSEW4bZZgUUdKRFEuwu11Gvj9loucZKsZafcj5YcJMn5l15/G6wA8YdAIY9SoB4dmnThe0jKlw9digr1hxh0/VB3mZv75fxiZgWLqBtWTp8heyJvTTU7fYv+PT/7/gI6whieAkgjUkkEH5uPhjO5NGz9M2N6QE5dnUro89tO6QOo/bazUIdlC4yxmHuztj3pR1xai0erjYD1P6Y/Fg5PHperme7kbU0zlxAeeTXhJeNcIIY9favN22oiLwoGzA4W4n69jdPyUpi1NyH HklZPBPY M2d0Fm4vkicOJoivd3qHkr7H83j/KqQDqpNSWz/dkcpLNhhjKlDVFfRL9uKlchxZcdn2e7lgFNLgCrO3WW2c9PjVsLlBCL7Q3uLEX3wo30NGu1RGz8/zNig3LH1oCnvQYcC/nMBpIYkFRFzBMKABm0XW7i0clONzM4U1uprk63WCh2rZx34avZG25db4105uFH+FQ3eq3fdZPn+zUgi3NqdnX+R1g9U6fL9syfJXRlHbYk+wkQUZdWi9Zf6tW/b05IL0JOdnhLSVqslocCbNzsolDsGz9BF+USSUSo8Dpf9xr8L05yqkf90YwCp4qc3mXQArdSm2QeEb149f0+tZfFjgoLveIdIX3rQfgJVGXfVcALJ346Bv8Du9a4A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/20/23 18:44, Mike Rapoport wrote: > On Mon, Mar 20, 2023 at 11:54:14AM +0100, Alexandre Ghiti wrote: >> Hi Mike, >> >> On 3/16/23 21:12, Mike Rapoport wrote: >>> Hi Alexandre, >>> >>> On Thu, Mar 16, 2023 at 02:17:09PM +0100, Alexandre Ghiti wrote: >>>> This function allows to split a region in memblock.memory and will be >>>> useful when setting up the linear mapping with STRICT_KERNEL_RWX: it >>>> allows to isolate the kernel text/rodata and then avoid to map those >>>> regions with a PUD/P4D/PGD. >>> Sorry I've missed it last time. The changelog is fine in the context of >> >> No worries :) >> >> >>> this series, but if you look at it as a part of memblock changelog it >>> doesn't provide enough background on why memblock_isolate_memory() is >>> useful. >>> >>> Can you please add more context so it would be self explanatory? >> >> What about: "memblock.memory contains the list of memory regions and a >> memory region can cover memory that will be mapped with different >> permissions. So to ease the mapping process, allow to isolate those regions >> by introducing a new function called memblock_isolate_memory. This will be >> used in arch specific code to isolate the kernel text/rodata regions when >> STRICT_KERNEL_RWX is enabled so that we avoid mapping them with PUD/P4D/PGD >> mappings." > With this change > > ... STRICT_KERNEL_RWX is enabled so that they can be mapped with base pages. Actually they will get mapped with PMD mappings :) I'll just append: "or PMD mapping" to your sentence above if that's ok with you. > > Acked-by: Mike Rapoport (IBM) Thanks for your review, Alex > >> Thanks, >> >> Alex >> >> >>>> Signed-off-by: Alexandre Ghiti >>>> Reviewed-by: Anup Patel >>>> Tested-by: Anup Patel >>>> --- >>>> include/linux/memblock.h | 1 + >>>> mm/memblock.c | 20 ++++++++++++++++++++ >>>> 2 files changed, 21 insertions(+) >>>> >>>> diff --git a/include/linux/memblock.h b/include/linux/memblock.h >>>> index 50ad19662a32..2f7ef97c0da7 100644 >>>> --- a/include/linux/memblock.h >>>> +++ b/include/linux/memblock.h >>>> @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); >>>> int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); >>>> int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); >>>> int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); >>>> +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size); >>>> void memblock_free_all(void); >>>> void memblock_free(void *ptr, size_t size); >>>> diff --git a/mm/memblock.c b/mm/memblock.c >>>> index 25fd0626a9e7..e8c651a37012 100644 >>>> --- a/mm/memblock.c >>>> +++ b/mm/memblock.c >>>> @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type, >>>> return 0; >>>> } >>>> +/** >>>> + * memblock_isolate_memory - isolate given range in memblock.memory >>>> + * @base: base of range to isolate >>>> + * @size: size of range to isolate >>>> + * >>>> + * Isolates the given range in memblock.memory so that it does not share any >>>> + * region with other ranges. >>>> + * >>>> + * Return: >>>> + * 0 on success, -errno on failure. >>>> + */ >>>> + >>>> +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size) >>>> +{ >>>> + int start_rgn, end_rgn; >>>> + >>>> + return memblock_isolate_range(&memblock.memory, base, size, >>>> + &start_rgn, &end_rgn); >>>> +} >>>> + >>>> static int __init_memblock memblock_remove_range(struct memblock_type *type, >>>> phys_addr_t base, phys_addr_t size) >>>> { >>>> -- >>>> 2.37.2 >>>>