Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp2499395qtg; Thu, 23 Mar 2023 04:57:58 -0700 (PDT) X-Google-Smtp-Source: AK7set9JCwkKnCSn3v7AjNpbcIRJkLDUZ9csKqnoD0uEGxe5x8ivPokwjo4k+L+1s7X2lRhAggKx X-Received: by 2002:a17:906:35d5:b0:930:310:abc2 with SMTP id p21-20020a17090635d500b009300310abc2mr10494252ejb.35.1679572678231; Thu, 23 Mar 2023 04:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679572678; cv=none; d=google.com; s=arc-20160816; b=mhgfKbZkr7pNhIZkMCPXzZfq+z5/j4H8tr71GnetywTekat5OrSWtXhvIZSaAXCs/r y0Hh4MtAS5X8ubBLWsp8O3yI0LGzBWQ1oGnZmQ2tYGjOj+bgz192G9aXEH4Mzd2nhlW+ 6HhX9pOzUKGqrs8QPX3qnsmxAkY1YDTQXQ9fnMbJrQ7oW00OhIrK0JMyIUpIa7YsCb+C o8+hy6m71ZRJLelsFSK5KCxWvMor/p2yh8oYYU9RwEZVkKd/uiMx/bFImmnMVl3OsVHZ ks8zS14BdyxSuPhSlrEkcGQNFdPGXLUgKq6M0VqaFvuBWc7CtotxFZFBxEkaDacRLFkb mJ6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=XRLaSltD1gfvUlow3n1B98d+wq4lhGyetQ/57dj01w0=; b=G9lZS/CcqXPL7WY31+aByseiIzyK3SUyupGUfQ4MfJXbPsxTEkh9DGPQ2Ska5GSsgJ qCSuqJ7sT0FEymOofKk5yA1HDPJimtVNEdnFIyKYSOHJCQBMmXDg8DlAqcnuSWIcFk0w fxtmUYqAZw1btwsSk8JqtX2r0HH8PvFqetTGLMRww3eHVqitrcsYksDI1IHq4lfxGSh+ V07ipBfGYEsGtgXRJcKN4Md405m2WG+gAl7vuTYu+tFLT/F8XRswN8GAoARwbDX+Awmv Zv6roXpesGxehoA8cJahcVcdlN1hjaYQjhDmnrTkmhvZdsvVfjlwkHNhxGn0jbmQrKcW QQvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a170906974a00b00939ad825dd8si9458552ejy.837.2023.03.23.04.57.33; Thu, 23 Mar 2023 04:57:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231756AbjCWLwr (ORCPT + 99 others); Thu, 23 Mar 2023 07:52:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231636AbjCWLwp (ORCPT ); Thu, 23 Mar 2023 07:52:45 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 255EE3401E; Thu, 23 Mar 2023 04:52:43 -0700 (PDT) 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-Spam-Status: No, score=-0.7 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>>>