Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp696285pxb; Wed, 29 Sep 2021 07:53:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8B8a26ISiYUNdGZ0Lr1bqEARDiW5IuvikVQt+ECYA3HHgoYUF+U5ApQIIEuFeq3cNIPyE X-Received: by 2002:a17:906:6011:: with SMTP id o17mr122926ejj.157.1632927230274; Wed, 29 Sep 2021 07:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632927230; cv=none; d=google.com; s=arc-20160816; b=S0saqwchs47n1FXDX1a6hbO1+WJxVhp6wDXYNcpSgG2bf2PEeHQjgmjMXs264lW6XC KsDHMvnDaXmFOvNcCJSvUt+AlIy46rTJi5OUCglZ101ueEE5ZwYT2imGOc9DjT3ikaX6 kVQ6MiDuiWuIoEfef9KuCjs+kU8in/AxLeRD4sP8cvKXDmGJPJnY+0oN3+UkcuDpYkYc VzupN8eq9I5S+g0LRFnIAz1QCnYB6TSyREVzSfJEZrZngHKoUFnTdKeGSFtLEUtzrimH TgiR9Ys6VaojwuGG8suUpSuH22ogLqfCzTDD7syJiPXJBV3a7Ae2spiFOV4QVv4rAPHl fwiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/TquUrfUmr5oNmyuO1+Qsp/eD8gniIfYD04SJchk9B4=; b=Q1Y6VZIfqV89iIownPufimOkgfL4FxRDPB/1a9wss9yhjcyCsm9fwnXL0msJrqbsPn lJhqBUdr9p5aLt+pvTu6NlJzmq8q8KndyGwsaPnsRwfT3eYNgnQWke1kUSurV5PE50a2 n1NQCpvqR3g9i92L97cL+0b8ut9F/S4tcYHpx5L9UbvIZOsO+DJYsxzFZAqg8v942GqV WTcIXfL86b/uQXNEdb5RtWrXNNaounwy3iwJWILyHk+9lD9GUTbxqxx4Zzx++w5iGUB3 JyiGazFbCCSd0R1wlaSXF5LVpnT5CmgSQOQONsII+05CI/DqRdeji1BXHgVf1wxewdfi fZOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=l64xjmVD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f21si98576ejl.103.2021.09.29.07.53.25; Wed, 29 Sep 2021 07:53:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=l64xjmVD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344750AbhI2OxS (ORCPT + 99 others); Wed, 29 Sep 2021 10:53:18 -0400 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:59832 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344735AbhI2OxQ (ORCPT ); Wed, 29 Sep 2021 10:53:16 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 4D48240600 for ; Wed, 29 Sep 2021 14:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632927094; bh=/TquUrfUmr5oNmyuO1+Qsp/eD8gniIfYD04SJchk9B4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=l64xjmVD9Me1aQvDrLSL5/3KuStRLNN/GJqX33pJnIviY41iMVPuuKlQzaPGAPf5t Gh1e71BREzfxpb5yIGPnmhZCdxJEqds4mDHU9A2EvjzRtDIaaXs7NJIMSdHa1ILBgC ywh9fAxziQHZ2TATcAf+RUJ/soub4Q9Y9mVHbgut9mgoQZU9FLTQ+lj4HGrkGS220p uRR/jS8lIc3FsxekKiqAMZJljRivDYgWUKL+axoBt1d04heUGoQTMcE+XcuyztsGlc eFoNom2i+aE39YF0Re5JwiWzEnLKM0+igemByAiIGMcN39inUobt9ViTl451NQgwI6 c31ELpX2pZbTQ== Received: by mail-wr1-f72.google.com with SMTP id u7-20020adfed47000000b0016061b6caa8so687636wro.16 for ; Wed, 29 Sep 2021 07:51:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/TquUrfUmr5oNmyuO1+Qsp/eD8gniIfYD04SJchk9B4=; b=ffwoGjJPrpKrX/v13mj3OTmwPwnZDYcQYe9vfBVtD1lemRVzPGgUc08dK1zdHhed3R +G2WXHIz5kjgHnbnunoBE3mRAZV0Jr2Q3aRG9EeT9yHmXb+lwjRzZv9lmZkbmEI3pjbB GFyNLTSUdAsHQQGNzflXq5wTcaEJnODYrKvmMzcbHEqzvPAZaaheeyuzIB8EGQTmHasK Vt7gZscdlW1pNyciYFdofWutX8RbbQqfcctBt+BD1V20X7UI4hCaG/VYeUigkZceNCnW 3Lz7JNEniMf0RfQAT/inFNuuIIy+sAlWYlxRfJp/Phm7w+dvURlG25ILhlRqDqQ1uPVG Xadg== X-Gm-Message-State: AOAM530M4t+d/R33Ln4qSiuvdwZAFaexHERItRMLES4iALMuBbKqjZHc snnX61ekgjVh0SWlp5saRQDpTHS/U6of0TuCeP4yYjwdeDOiyymsalhUT6R5YzfH6wg2TlpiQ5P k8aGb5BGriFir8t1kcafIlTyeONmto3sBTpcTRJ24ig== X-Received: by 2002:a05:600c:4e86:: with SMTP id f6mr11084959wmq.52.1632927093808; Wed, 29 Sep 2021 07:51:33 -0700 (PDT) X-Received: by 2002:a05:600c:4e86:: with SMTP id f6mr11084945wmq.52.1632927093654; Wed, 29 Sep 2021 07:51:33 -0700 (PDT) Received: from alex.home (lfbn-lyo-1-470-249.w2-7.abo.wanadoo.fr. [2.7.60.249]) by smtp.gmail.com with ESMTPSA id q7sm129478wrc.55.2021.09.29.07.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 07:51:33 -0700 (PDT) From: Alexandre Ghiti To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Zong Li , Anup Patel , Atish Patra , Christoph Hellwig , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Ard Biesheuvel , Arnd Bergmann , Kees Cook , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v2 00/10] Introduce sv48 support without relocatable kernel Date: Wed, 29 Sep 2021 16:51:03 +0200 Message-Id: <20210929145113.1935778-1-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patchset allows to have a single kernel for sv39 and sv48 without being relocatable. The idea comes from Arnd Bergmann who suggested to do the same as x86, that is mapping the kernel to the end of the address space, which allows the kernel to be linked at the same address for both sv39 and sv48 and then does not require to be relocated at runtime. This implements sv48 support at runtime. The kernel will try to boot with 4-level page table and will fallback to 3-level if the HW does not support it. Folding the 4th level into a 3-level page table has almost no cost at runtime. Tested on: - qemu rv64 sv39: OK - qemu rv64 sv48: OK - qemu rv64 sv39 + kasan: OK - qemu rv64 sv48 + kasan: OK - qemu rv32: OK - Unmatched: OK Changes in v2: - Rebase onto for-next - Fix KASAN - Fix stack canary - Get completely rid of MAXPHYSMEM configs - Add documentation Alexandre Ghiti (10): riscv: Allow to dynamically define VA_BITS riscv: Get rid of MAXPHYSMEM configs asm-generic: Prepare for riscv use of pud_alloc_one and pud_free riscv: Implement sv48 support riscv: Use pgtable_l4_enabled to output mmu_type in cpuinfo riscv: Explicit comment about user virtual address space size riscv: Improve virtual kernel memory layout dump Documentation: riscv: Add sv48 description to VM layout riscv: Initialize thread pointer before calling C functions riscv: Allow user to downgrade to sv39 when hw supports sv48 Documentation/riscv/vm-layout.rst | 36 ++ arch/riscv/Kconfig | 35 +- arch/riscv/configs/nommu_k210_defconfig | 1 - .../riscv/configs/nommu_k210_sdcard_defconfig | 1 - arch/riscv/configs/nommu_virt_defconfig | 1 - arch/riscv/include/asm/csr.h | 3 +- arch/riscv/include/asm/fixmap.h | 1 + arch/riscv/include/asm/kasan.h | 2 +- arch/riscv/include/asm/page.h | 10 + arch/riscv/include/asm/pgalloc.h | 40 +++ arch/riscv/include/asm/pgtable-64.h | 108 +++++- arch/riscv/include/asm/pgtable.h | 30 +- arch/riscv/include/asm/sparsemem.h | 6 +- arch/riscv/kernel/cpu.c | 23 +- arch/riscv/kernel/head.S | 4 +- arch/riscv/mm/context.c | 4 +- arch/riscv/mm/init.c | 323 +++++++++++++++--- arch/riscv/mm/kasan_init.c | 91 +++-- drivers/firmware/efi/libstub/efi-stub.c | 2 + include/asm-generic/pgalloc.h | 24 +- include/linux/sizes.h | 1 + 21 files changed, 615 insertions(+), 131 deletions(-) -- 2.30.2