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 AB071C47422 for ; Thu, 18 Jan 2024 13:01:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B3E56B007D; Thu, 18 Jan 2024 08:01:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 23D626B00A2; Thu, 18 Jan 2024 08:01:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 042786B00A3; Thu, 18 Jan 2024 08:01:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DE2616B007D for ; Thu, 18 Jan 2024 08:01:50 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 63C821C16D5 for ; Thu, 18 Jan 2024 13:01:49 +0000 (UTC) X-FDA: 81692443938.12.32346DC Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf30.hostedemail.com (Postfix) with ESMTP id 0D49F80033 for ; Thu, 18 Jan 2024 13:01:45 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=OlV5dZkE; dmarc=none; spf=pass (imf30.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.218.44 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=1705582906; 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:dkim-signature; bh=CV99ndMBEnv7+i0KgO9Jy4dZrWznQQ7WCTJP40FuP9k=; b=jWM8AbxOvD3qFCJ+0nJISmoEZ6n5ImMxgL8qezFA7QpLDK8xjV/NquotPccsCa4uRnymPk 19/H36qBT3NWs0U1io/IGCmIjWu/WGNlgqBt2j+FsFIKjPMS2oSlIlWL+VHicYcEVfwJpy Ppo0bOQDJLKBCvz6zuW3fjKgvRSrsvM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=OlV5dZkE; dmarc=none; spf=pass (imf30.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705582906; a=rsa-sha256; cv=none; b=QGC878W6SG5PGL46J+E8miwZFN6XuQLYnof47tPt7PO31U2cy45oyzD1D5+Ik983ubbltP R/RC/FEJ18U8fGDm9Q60CM9htfSTHYSlgMdaBEeQTCiYBghacDEbGKm8qLFrl0LrMr+POI LW4M90/7tPPmoAHBnwELZrLRdbm26jU= Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a2eb5c4dad6so163706766b.1 for ; Thu, 18 Jan 2024 05:01:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705582904; x=1706187704; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CV99ndMBEnv7+i0KgO9Jy4dZrWznQQ7WCTJP40FuP9k=; b=OlV5dZkEeYbXNfBTwVZrCxXzr9CMyhRYaJKdjNkXm+A3LsAiapSEckf68rqeKQTX6f WvOzFoFzsyiWf5WDQ18nVOO88uuCM+lAOHUiOEuGXEQ7RG7Y4bSHQ8upxrG+Wb8m9P2T XRvOGcYxL2BqH4FI3SucGZyvjw6/HnvZ+IMVlVvSql8IxVQiXN9wyz6opxXBl+IujZ1x BwnxUFC3R5OzSgbOsjOp9cEGGbCR8QNA5mIA3yNrXqWbDgxSN+T6S5ZDW6UufdhWgrDU kQZ+ZwdbP0UD4dbdhhR/aRJZncKvthQpDhrtYrX4mKbp5gnpEoT3K4pB2dzdz4un5OM8 sRPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705582904; x=1706187704; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CV99ndMBEnv7+i0KgO9Jy4dZrWznQQ7WCTJP40FuP9k=; b=KwnPLV7gg4oOS0A3QFxGK5/xIBAnfR+y+xdl8Gfgy7mklJHqZ5hW1nBd4SQsyyjNxU p+kcJBP3c1zv4X8od7NwL5j8PLxp68TBsyeleykXwj2ezx2K+D840taBI8m6ur5tBYt2 ApKWLo5s4YEcqC0+6nFAhRJ6xEss4Vco7HIr8LYOqlDS4KiXbqLIvL2AjU6wf4fC33YZ a4YNdP3/Un5hUf6HLAhcnY4nu4hCwfeS+A7yaYPSKGKBNLx1B3KKe2RS4Xpao5ntGx4p 5EVOxThIZIVQ/GpaPGCNZm056k9CEeeWYtKfZNMWvS0GCRSQVEXKFhm4W2zaG/+epbKf qL4w== X-Gm-Message-State: AOJu0YxmsMsP/Upj5ixxhe3h2iDuQUeI4VUFg1ydHmHuA3R/ZkEINTAt hjEVG2OgF7qWc4smxM2kZ8aR/DPjU+D0MUQg2eaZ6baWtolX0McW1zCqh+85THM0NUOWxz8IL2j qbg8PMQ5x3ymQ0frVntEk9lmgFRlY1vKEGzn5fQ== X-Google-Smtp-Source: AGHT+IGXHWuAbZf6vP7bFyGlIWm/V3xNm9G1zzWXciRpuQQcls3Pd1mtfB3eXcJXawXwCc8Me/YMNC+4PA9rLOOa3OQ= X-Received: by 2002:a17:906:3b10:b0:a2c:b0a6:8b6 with SMTP id g16-20020a1709063b1000b00a2cb0a608b6mr488211ejf.1.1705582904215; Thu, 18 Jan 2024 05:01:44 -0800 (PST) MIME-Version: 1.0 References: <20230316131711.1284451-1-alexghiti@rivosinc.com> <20240118082346.GB31078@hsinchu15> In-Reply-To: <20240118082346.GB31078@hsinchu15> From: Alexandre Ghiti Date: Thu, 18 Jan 2024 14:01:33 +0100 Message-ID: Subject: Re: Fwd: [PATCH v8 0/4] riscv: Use PUD/P4D/PGD pages for the linear mapping To: Nylon Chen Cc: alex@ghiti.fr, apatel@ventanamicro.com, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh+dt@kernel.org, frowand.list@gmail.com, rppt@kernel.org, akpm@linux-foundation.org, anup@brainfault.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-mm@kvack.org, zong.li@sifive.com, nylon7717@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0D49F80033 X-Stat-Signature: 117ocs6taapzk8gpz9x3jb5w59comd7b X-HE-Tag: 1705582905-413126 X-HE-Meta: U2FsdGVkX1/BLaHxll6T8rZTrdeVrFfPTG1fJZ+bhfVMsJiCw3wG7hPbBMRI34H08XcdCklqHmKd7iZTgZ4n48ekkIGoBQe8ExmSYI5Ju4PgQh+Crgx6zRc2YdfuWZns5aAkvMrBgFBGTQLKjil+QqEOwrFUl5drIJrwkhtLLCYDpsUkvXgz6a0Qg3J0QUpnTzZaCHJm3pCaPSkx/1K/akWGB1p/HvClCODpPZG6wE1o1JtJRPwETLSAdYOoze2LvbwOgw0p/MZi0t6qPcSAbNSW+OfFuy+I//ALRDf9Vy0UvSGcZFdfAzxd+RxMneG/3Fxx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PVcIMe6kTYSzkCaRVokhboI5QdrQsJ8E16j/qHJ4zQxhOCFwKz3sIVRR02uzszZHUtOmzb+yfOE32KmC/4MiG4r4qpHe++Ho+JLN8Y4TigwMQbjuZc85ljb+LDMtDU9h9im8GdImlcjv90nk0vsk8omxSrbVgfiPHInt3NT1stRXu15Q/eD43LUMRqruUaravtej+wqLZQmaciAWKt8cDg8jM0k0RAm7s6unLh90nX9vCiA14Bwor5hEA== 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: List-Subscribe: List-Unsubscribe: Hi Nylon, On Thu, Jan 18, 2024 at 9:23=E2=80=AFAM Nylon Chen = wrote: > > > On 3/23/23 15:55, Anup Patel wrote: > > > On Thu, Mar 23, 2023 at 6:24=E2=80=AFPM Alexandre Ghiti wrote: > > >> Hi Anup, > > >> > > >> On Thu, Mar 23, 2023 at 1:18=E2=80=AFPM Anup Patel wrote: > > >>> Hi Alex, > > >>> > > >>> On Thu, Mar 16, 2023 at 6:48=E2=80=AFPM Alexandre Ghiti wrote: > > >>>> This patchset intends to improve tlb utilization by using hugepage= s for > > >>>> the linear mapping. > > >>>> > > >>>> As reported by Anup in v6, when STRICT_KERNEL_RWX is enabled, we m= ust > > >>>> take care of isolating the kernel text and rodata so that they are= not > > >>>> mapped with a PUD mapping which would then assign wrong permission= s to > > >>>> the whole region: it is achieved by introducing a new memblock API= . > > >>>> > > >>>> Another patch makes use of this new API in arm64 which used some s= ort of > > >>>> hack to solve this issue: it was built/boot tested successfully. > > >>>> > > >>>> base-commit-tag: v6.3-rc1 > > >>>> > > >>>> v8: > > >>>> - Fix rv32, as reported by Anup > > >>>> - Do not modify memblock_isolate_range and fixes comment, as sugge= sted by Mike > > >>>> - Use the new memblock API for crash kernel too in arm64, as sugge= sted by Andrew > > >>>> - Fix arm64 double mapping (which to me did not work in v7), but e= nds up not > > >>>> being pretty at all, will wait for comments from arm64 reviewer= s, but > > >>>> this patch can easily be dropped if they do not want it. > > >>>> > > >>>> v7: > > >>>> - Fix Anup bug report by introducing memblock_isolate_memory which > > >>>> allows us to split the memblock mappings and then avoid to map = the > > >>>> the PUD which contains the kernel as read only > > >>>> - Add a patch to arm64 to use this newly introduced API > > >>>> > > >>>> v6: > > >>>> - quiet LLVM warning by casting phys_ram_base into an unsigned lon= g > > >>>> > > >>>> v5: > > >>>> - Fix nommu builds by getting rid of riscv_pfn_base in patch 1, th= anks > > >>>> Conor > > >>>> - Add RB from Andrew > > >>>> > > >>>> v4: > > >>>> - Rebase on top of v6.2-rc3, as noted by Conor > > >>>> - Add Acked-by Rob > > >>>> > > >>>> v3: > > >>>> - Change the comment about initrd_start VA conversion so that it f= its > > >>>> ARM64 and RISCV64 (and others in the future if needed), as sugg= ested > > >>>> by Rob > > >>>> > > >>>> v2: > > >>>> - Add a comment on why RISCV64 does not need to set initrd_start/e= nd that > > >>>> early in the boot process, as asked by Rob > > >>>> > > >>>> Alexandre Ghiti (4): > > >>>> riscv: Get rid of riscv_pfn_base variable > > >>>> mm: Introduce memblock_isolate_memory > > >>>> arm64: Make use of memblock_isolate_memory for the linear mappi= ng > > >>>> riscv: Use PUD/P4D/PGD pages for the linear mapping > > >>> Kernel boot fine on RV64 but there is a failure which is still not > > >>> addressed. You can see this failure as following message in > > >>> kernel boot log: > > >>> 0.000000] Failed to add a System RAM resource at 80200000 > > >> Hmmm I don't get that in any of my test configs, would you mind > > >> sharing yours and your qemu command line? > > > Try alexghiti_test branch at > > > https://github.com/avpatel/linux.git > > > > > > I am building the kernel using defconfig and my rootfs is > > > based on busybox. > > > > > > My QEMU command is: > > > qemu-system-riscv64 -M virt -m 512M -nographic -bios > > > opensbi/build/platform/generic/firmware/fw_dynamic.bin -kernel > > > ./build-riscv64/arch/riscv/boot/Image -append "root=3D/dev/ram rw > > > console=3DttyS0 earlycon" -initrd ./rootfs_riscv64.img -smp 4 > > > > > > So splitting memblock.memory is the culprit, it "confuses" the resource= s > > addition and I can only find hacky ways to fix that... > Hi Alexandre, > > We encountered the same error as Anup. After adding your patch > (3335068f87217ea59d08f462187dc856652eea15), we will not encounter the > error again. > > What I have observed so far is > > - before your patch > When merging consecutive memblocks, if the memblock types are different, > they will be merged into reserved > - after your patch > When consecutive memblocks are merged, if the memblock types are > different, they will be merged into memory. > > Such a result will cause the memory location of OpenSBI to be changed > from reserved to memory. Will this have any side effects? I guess it will end up in the memory pool and pages from openSBI region will be allocated, so we should see very quickly bad stuff happening (either PMP violation or M-mode ecall never returning/trapping/etc). But I don't observe the same thing, I always see the openSBI region being reserved: reserved[0x0] [0x0000000080000000-0x000000008007ffff], 0x0000000000080000 bytes flags: 0x0 Can you elaborate a bit more about "When consecutive memblocks are merged, if the memblock types are different, they will be merged into memory"? Where/when does this merge happen? Can you give me a config file and a kernel revision so that I can take a look? Thanks, Alex > > > > So given that the arm64 patch with the new API is not pretty and that > > the simplest solution is to re-merge the memblock regions afterwards > > (which is done by memblock_clear_nomap), I'll drop the new API and the > > arm64 patch to use the nomap API like arm64: I'll take advantage of tha= t > > to clean setup_vm_final which I have wanted to do for a long time. > > > > @Mike Thanks for you reviews! > > > > @Anup Thanks for all your bug reports on this patchset, I have to > > improve my test flow (it is in the work :)). > > > > > > > Regards, > > > Anup > > > > > >> Thanks > > >> > > >>> Regards, > > >>> Anup > > >>> > > >>>> arch/arm64/mm/mmu.c | 25 +++++++++++------ > > >>>> arch/riscv/include/asm/page.h | 19 +++++++++++-- > > >>>> arch/riscv/mm/init.c | 53 ++++++++++++++++++++++++++++-= ------ > > >>>> arch/riscv/mm/physaddr.c | 16 +++++++++++ > > >>>> drivers/of/fdt.c | 11 ++++---- > > >>>> include/linux/memblock.h | 1 + > > >>>> mm/memblock.c | 20 +++++++++++++ > > >>>> 7 files changed, 119 insertions(+), 26 deletions(-) > > >>>> > > >>>> -- > > >>>> 2.37.2 > > >>>> > > > _______________________________________________ > > > linux-riscv mailing list > > > linux-riscv@lists.infradead.org > > > http://lists.infradead.org/mailman/listinfo/linux-riscv > > > > _______________________________________________ > > linux-riscv mailing list > > linux-riscv@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-riscv