From patchwork Thu Mar 16 13:17:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13177615 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 9BCC7C6FD1F for ; Thu, 16 Mar 2023 13:19:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D11C900008; Thu, 16 Mar 2023 09:19:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 380E6900002; Thu, 16 Mar 2023 09:19:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2717B900008; Thu, 16 Mar 2023 09:19:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 172D2900002 for ; Thu, 16 Mar 2023 09:19:24 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C73DBA137F for ; Thu, 16 Mar 2023 13:19:23 +0000 (UTC) X-FDA: 80574817806.15.F9954D1 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf01.hostedemail.com (Postfix) with ESMTP id 9E72E40005 for ; Thu, 16 Mar 2023 13:19:21 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=67doldxY; dmarc=none; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678972761; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=FJiMvzYMyu/Jl0shijoaPEoelbzaHeC7FP2lygjwgCTIUyPG7vWMFwGT12q3V0LrNajLgV rMg6zjNA4uA+x9UkZUkLSmzoFJMurKqLmzUq6Vz7kwjahbPHz7z7cIpvQD+ictDIVtchTM S37phKmWdnt4Zxz6xi0zwI5I3x8lUeE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=67doldxY; dmarc=none; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678972761; a=rsa-sha256; cv=none; b=PBQyye5yaCV6qOQU9l5X3p+qZ7aH3OLn3TSvp1Ieb3/+W71ZDTynxj/R4z/HxzckqggyoC vaLEznUmNRJJsJ1LxTpRgJCkdl/ulkc2x1gE4UTe/28l6rtGtdv/fNaXEee2jf3TrY5Rsh xwMKwpX7obBKO9hTDzj02H0zjGTF50w= Received: by mail-wr1-f41.google.com with SMTP id m2so1513528wrh.6 for ; Thu, 16 Mar 2023 06:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678972760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=67doldxYgYKlU/XZ0kZu3+NOAqQ/2WbnP4mwdaTGI0McuaMhRPDAE/s74Wq3t6tF/V J0nRxluNtH5jyXjG6gwranylrEnecoP/DUWgaO9JZ4gg6xFffDGE08IwIc2KOUXaspal HHuTUIg4II4i6Oa5sRMFXG0qwnNOZQwEH5YClaHtl1ekxMRL+d17IM5dSSKvN8etH4o4 Gryhf8z+9DXYE61ol4wGcZdxrAPW2qatjZ5Q8iOQkHFCUmxFt43/+ApFfD1rBG+HZP3t j+M2PnF2oTfQycLOuf/WXwZevaBF66GgvGXiPTY9lyNMUBSV3fX9CsUSbPa1JK7AlIvp vKjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678972760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=tYaJtjo8IjDor7vLbgqsPZEImit77eeGczTlf0yw44c0mLRm7x9w/X/KdG7pPZjy97 dUDvsO2FqUFl934FGslzn65NAQp3MVF8vzpb6TdSYkQ9TWPWDmwFOR97oL2Wq3FZvAGo KsQm1qMhnIMJSJsvLni1oSLl0zLBsnhSAY7Jj5hz0ykgN2Jhb2CNQcJUAsHPb066Jxfa 2wgIo/D13dacsnjxox2vDJ3cj4PM7zCGXKp+p7QWMkFBcyvATz6TOee5yUPoowgXYQWW FfODJMTrok5gPDEEFUe9DXx49S3E7VNKx0Qw2he7BVtBpA1Y8XRSHk2adWrgipJ4845o HNUg== X-Gm-Message-State: AO0yUKVSIAx9Y1i/Wjr3Dd4jFM8ys3WLWZ7NGp0h12GuUPMUXp3jQhau ywGQVJRededAuQyeTCfpBaAPtg== X-Google-Smtp-Source: AK7set9ckwc+gnRj+k56d+SvgcefBu0ajEjl4o1f/HxCl/7FMrq5djA9ftFJ5OFMO4WJD/IRBsDEKA== X-Received: by 2002:a5d:49cc:0:b0:2c7:57e:633e with SMTP id t12-20020a5d49cc000000b002c7057e633emr4666191wrs.49.1678972760162; Thu, 16 Mar 2023 06:19:20 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (238.174.185.81.rev.sfr.net. [81.185.174.238]) by smtp.gmail.com with ESMTPSA id h5-20020a5d5485000000b002c5a1bd5280sm7210070wrv.95.2023.03.16.06.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 06:19:20 -0700 (PDT) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Mike Rapoport , 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 Cc: Alexandre Ghiti Subject: [PATCH v8 2/4] mm: Introduce memblock_isolate_memory Date: Thu, 16 Mar 2023 14:17:09 +0100 Message-Id: <20230316131711.1284451-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230316131711.1284451-1-alexghiti@rivosinc.com> References: <20230316131711.1284451-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9E72E40005 X-Stat-Signature: i5k8359wnyui1og4zgys5npxfzx5q7uy X-HE-Tag: 1678972761-735094 X-HE-Meta: U2FsdGVkX18impUBMWb7w9316u29j7XjRHAz72EI8FnnWD4zALURLxsRMxUdunqGKl3wQWlqoFkOsYl3F3MoTnskBvGjemYxab50siVXgUFu/K7eBG0RoW7D7F2SS4rn3ZnkdWxyb1X6hrHQmYBtPRH/Yi6WU5drlvlVBcEjO8vSjAX1US7w4c3Z8Xkf6E94bUglG2vPXdcYju3Cg/q1oiQLKc4ojbnlRdRWixmzveZ9xrIHDU3btR3s2iJZs3MG+SZk9n2aMcG1g84i83a0Irc2fnRC+ug5t844iClYjNG4+8H0Qc+IGuDQj+PSvLva3M3wZjRZJjOcA5QnC1ib/ESFOCgr2FC7LqlH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MsVrJKNr7Z4AR43PgpZL+cR8fPqs3cZtnSUstgviHPVxcMocEHOJVvbg1BedLnBpGmg/9RGLlPqHC/puJRG647moNxrokvPjvTgykES1PySl5HA5Diupg7kI5J3rqkkb3Lw74tO6ucpmnXUlBC2UMmun96zKdYC4vmzoO61je6Qwlh9+w5oNlZKDFla0hZYU3WEHsvHItYDnZ+WYQ= 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: 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. Signed-off-by: Alexandre Ghiti Reviewed-by: Anup Patel Tested-by: Anup Patel Acked-by: Mike Rapoport (IBM) --- 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) {