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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E9018C77B75 for ; Tue, 18 Apr 2023 10:07:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=khPFQgnJQHrCKSJYW10nQGbFzpvwRO2MpK8tKfFI2ao=; b=zACRLIITv2iPFh /8REp+yu116gS3EaAnrJug0aHL3VkIcljFNcER8p5QbGGFw5cEiYQdR810IHvAg5SQ/JtKYgSrL/U dYmDu+X1LORUGrRVQKeZaYYGBLdtS6qgg5bX1p/29suZWFwcHsBkstl6NIjxEBRJZGg4LLzOamLHc ZdDcUlm6ZphfdQ/eueP0Z+M8Q524F+KqZz3kpkMzmdJX4Y5pPY717OmDSQqQMCskzdXAhoz0k4Zql jc342slxvpQvEydvWsnDUP38cZuC7l81mkMV6EXARsQfA26+rk6TtXR8J4+aQ9VFT+epUyJzWTPf6 P68RMkHVc0BZFS/ca7Uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1poiEs-001aPY-1X; Tue, 18 Apr 2023 10:07:06 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1poiEp-001aP1-1v for linux-arm-kernel@lists.infradead.org; Tue, 18 Apr 2023 10:07:05 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 359D46284A for ; Tue, 18 Apr 2023 10:07:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F194C4339C for ; Tue, 18 Apr 2023 10:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681812422; bh=IpqtBKzf9jd+Nljizkl4Xo1RGy4fY1Qyg0ocePb4XCY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YiVTapmEjZox/MkVlLHf3hSUi1pPj2iQjM/6AVBM5JAhLu28lIzlYizDa9Hb9DHme hyL5Xlg98dTWCGfqzkix5sWpnbzpoYBQRTDMumn1AUKLWUC201CUVmqcIIzl0RmPGX yc2SIyozycabtRv54QU4E5ZBpuduW9VhzFMdy6JpJG+qP6NHx2KbcrPp6JJFecMrvS M1oblKTGhuadWqUJIPbn4QNts1yGxuZ/kwJhmyeaBkkqiGa5nAyi/LSEW7nCl0Pnmx IcTq3tMIkXxIkxqTIP3M3IlI4aesZtICYq1tkpPvhnORKKOq32v5eIennKw6rsICW4 OK1AU4mwu0Ftw== Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-4ec9ccab8bbso2073833e87.2 for ; Tue, 18 Apr 2023 03:07:02 -0700 (PDT) X-Gm-Message-State: AAQBX9fapsaRO/ZUck6ifVGNle9qKPQNf1XRB3+JPS9MIS2OD5hBc3n7 qgq5RSaoDTHHOl9yTs5se2XDF1g/HUfm7Ap3W1k= X-Google-Smtp-Source: AKy350b0kGxD66QXlx0N0+stzhTUHhDNwP/XTLdsSrqKNMK6HYltyv8D8s2FK2o0lFmOBrJ/WRmXsh4Z9gAH4PIQ7Q0= X-Received: by 2002:ac2:5691:0:b0:4eb:3f84:808b with SMTP id 17-20020ac25691000000b004eb3f84808bmr3016739lfr.3.1681812420640; Tue, 18 Apr 2023 03:07:00 -0700 (PDT) MIME-Version: 1.0 References: <20230307140522.2311461-1-ardb@kernel.org> <20230307140522.2311461-35-ardb@kernel.org> <775d92fc-9195-88bf-4a1c-51b74185c07d@arm.com> In-Reply-To: <775d92fc-9195-88bf-4a1c-51b74185c07d@arm.com> From: Ard Biesheuvel Date: Tue, 18 Apr 2023 12:06:49 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 34/60] arm64: head: Move early kernel mapping routines into C code To: Ryan Roberts Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230418_030703_708044_0E8383C3 X-CRM114-Status: GOOD ( 33.71 ) 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 18 Apr 2023 at 11:31, Ryan Roberts wrote: > > On 07/03/2023 14:04, Ard Biesheuvel wrote: > > The asm version of the kernel mapping code works fine for creating a > > coarse grained identity map, but for mapping the kernel down to its > > exact boundaries with the right attributes, it is not suitable. This is > > why we create a preliminary RWX kernel mapping first, and then rebuild > > it from scratch later on. > > > > So let's reimplement this in C, in a way that will make it unnecessary > > to create the kernel page tables yet another time in paging_init(). > > > > Signed-off-by: Ard Biesheuvel > > --- > > > [...] > > > diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_kernel.c > > new file mode 100644 > > index 0000000000000000..b573c964c7d88d1b > > --- /dev/null > > +++ b/arch/arm64/kernel/pi/map_kernel.c > > @@ -0,0 +1,171 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +// Copyright 2023 Google LLC > > +// Author: Ard Biesheuvel > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > + > > +#include "pi.h" > > + > > +extern const u8 __eh_frame_start[], __eh_frame_end[]; > > + > > +extern void idmap_cpu_replace_ttbr1(void *pgdir); > > + > > +static void map_segment(pgd_t *pg_dir, u64 *pgd, u64 va_offset, > > + void *start, void *end, pgprot_t prot, > > + bool may_use_cont, int root_level) > > +{ > > + map_range(pgd, ((u64)start + va_offset) & ~PAGE_OFFSET, > > + ((u64)end + va_offset) & ~PAGE_OFFSET, (u64)start, > > + prot, root_level, (pte_t *)pg_dir, may_use_cont, 0); > > I don't understand what you are doing with ~PAGE_OFFSET here. Is this intended > to be page alignment with PAGE_MASK? I'm guessing not, because you would want to > forward align the end address in that case. > start + va_offset will produce an address that has leading 1 bits set in positions that do not contribute to the translation. In order to index the page tables correctly, those bits need to be cleared. > > +} > > + > > +static void unmap_segment(pgd_t *pg_dir, u64 va_offset, void *start, > > + void *end, int root_level) > > +{ > > + map_segment(pg_dir, NULL, va_offset, start, end, __pgprot(0), > > + false, root_level); > > +} > > + > > > [...] > > > diff --git a/arch/arm64/kernel/pi/map_range.c b/arch/arm64/kernel/pi/map_range.c > > new file mode 100644 > > index 0000000000000000..61cbd6e82418c033 > > --- /dev/null > > +++ b/arch/arm64/kernel/pi/map_range.c > > @@ -0,0 +1,87 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +// Copyright 2023 Google LLC > > +// Author: Ard Biesheuvel > > + > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > + > > +#include "pi.h" > > + > > +/** > > + * map_range - Map a contiguous range of physical pages into virtual memory > > + * > > + * @pte: Address of physical pointer to array of pages to > > + * allocate page tables from > > + * @start: Virtual address of the start of the range > > + * @end: Virtual address of the end of the range (exclusive) > > + * @pa: Physical address of the start of the range > > + * @level: Translation level for the mapping > > + * @tbl: The level @level page table to create the mappings in > > + * @may_use_cont: Whether the use of the contiguous attribute is allowed > > + * @va_offset: Offset between a physical page and its current mapping > > + * in the VA space > > + */ > > +void __init map_range(u64 *pte, u64 start, u64 end, u64 pa, pgprot_t prot, > > + int level, pte_t *tbl, bool may_use_cont, u64 va_offset) > > va_offset is always 0 (because the memory at *pte is id-mapped). Can it be > dropped? Or perhaps you are using this function later, once the memory is no > longer id-mapped? > It will be used later. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel