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 X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD91CC43461 for ; Fri, 16 Apr 2021 18:51:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 25DC4613C7 for ; Fri, 16 Apr 2021 18:51:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25DC4613C7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 966866B0036; Fri, 16 Apr 2021 14:51:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93D6D6B006C; Fri, 16 Apr 2021 14:51:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DE1E6B0070; Fri, 16 Apr 2021 14:51:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 5C8576B0036 for ; Fri, 16 Apr 2021 14:51:43 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 101F782499A8 for ; Fri, 16 Apr 2021 18:51:43 +0000 (UTC) X-FDA: 78039124086.13.B00C305 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by imf12.hostedemail.com (Postfix) with ESMTP id 2E0CD135 for ; Fri, 16 Apr 2021 18:51:36 +0000 (UTC) Received: by mail-oi1-f174.google.com with SMTP id i18so7314990oii.2 for ; Fri, 16 Apr 2021 11:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=2r2vkwG9UCNB7xrSeMaXDYuTdlG3jHjzPkkxswC7vmg=; b=lcF00QwLC8PK7GTMRhPSub3JPTJ1qNCRqaoSkaih+zPeslAq7Ez+xOVPJCaYARn/9h XHrGmLWD6OZrRMoi2WQSve0KlJyB3BPniNNxHPTudpnkvj9c8UJf2GW6Y2GEvyKBSsgc JltwUxOpXH0FK0i0q2ScMVocYe4sBtWOoQYapC/U67iphGwTEv/lZwF2tbIKuRPVWoC3 hvc+SY8EFbsgAB9LWqY2WsfVhP03OYzL5pp+/QNiKegArHNkr0szL90g59fR0iHETA4R r9Q0+Tbcvb8uePaTFUgeOpsPJRrijUVhHveDagf9Vf/F7DAHV98Xkows9dL4YF8DBixd qDzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=2r2vkwG9UCNB7xrSeMaXDYuTdlG3jHjzPkkxswC7vmg=; b=mr3GLABg8c43n0Ue2admgUNKMu5J+M/CWN5sb0taU5I3n7cVqEWbqsHzWyZlpogYfA PzdcF2rvVg5Oly1KWXjl0LrhVBwF7zz4qJiC2DI/AxdX6cabsbLli2y+/i9Yt+JofA3O nAZDz6HmYNjfOiimLRJ7uZX4FOVXzyATTzB9kH8BXdY7kU1fsSxWS8Mprw3mJ4NwARhj e/H2TL3yUSEA5deqlh8BAagXXqYlsC3wMl4sBygGm7dFBcXVbNa9lZWbrBkYQ17/klga jhL5BjkYJDtD1tcK2L7k1wrZdYJEEnu8eGoWJh+lSM3hLiWKjR6Knv5eqETXok45/fLj fbig== X-Gm-Message-State: AOAM531j/YhOcnjUxIosVM45QACjaDL+Es7iDCqzqAp10FXNQhViquqm CEijkmOmvc/J4cwXTSHwLM4= X-Google-Smtp-Source: ABdhPJz9hVqfsgFcDqumj8Y7g+QmwdbvvK8f4T/Tz19SDlxLNY4HtR0EBBFy/mHjKN7ulNYRmXaO0Q== X-Received: by 2002:a05:6808:1444:: with SMTP id x4mr7654073oiv.142.1618599101889; Fri, 16 Apr 2021 11:51:41 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id y25sm1608634otj.64.2021.04.16.11.51.40 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Apr 2021 11:51:40 -0700 (PDT) Date: Fri, 16 Apr 2021 11:51:39 -0700 From: Guenter Roeck To: Alexandre Ghiti Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Arnd Bergmann , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v4 1/3] riscv: Move kernel mapping outside of linear mapping Message-ID: <20210416185139.GA42339@roeck-us.net> References: <20210409061500.14673-1-alex@ghiti.fr> <20210409061500.14673-2-alex@ghiti.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210409061500.14673-2-alex@ghiti.fr> User-Agent: Mutt/1.9.4 (2018-02-28) X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2E0CD135 X-Stat-Signature: ep9kk777wdjabofm5cfrmwz5wi5tzs7a Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf12; identity=mailfrom; envelope-from=""; helo=mail-oi1-f174.google.com; client-ip=209.85.167.174 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618599096-394741 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: On Fri, Apr 09, 2021 at 02:14:58AM -0400, Alexandre Ghiti wrote: > This is a preparatory patch for relocatable kernel and sv48 support. > > The kernel used to be linked at PAGE_OFFSET address therefore we could use > the linear mapping for the kernel mapping. But the relocated kernel base > address will be different from PAGE_OFFSET and since in the linear mapping, > two different virtual addresses cannot point to the same physical address, > the kernel mapping needs to lie outside the linear mapping so that we don't > have to copy it at the same physical offset. > > The kernel mapping is moved to the last 2GB of the address space, BPF > is now always after the kernel and modules use the 2GB memory range right > before the kernel, so BPF and modules regions do not overlap. KASLR > implementation will simply have to move the kernel in the last 2GB range > and just take care of leaving enough space for BPF. > > In addition, by moving the kernel to the end of the address space, both > sv39 and sv48 kernels will be exactly the same without needing to be > relocated at runtime. > > Suggested-by: Arnd Bergmann > Signed-off-by: Alexandre Ghiti In next-20210416, when booting a riscv32 image in qemu, this patch results in: [ 0.000000] Linux version 5.12.0-rc7-next-20210416 (groeck@desktop) (riscv32-linux-gcc (GCC) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #1 SMP Fri Apr 16 10:38:09 PDT 2021 [ 0.000000] OF: fdt: Ignoring memory block 0x80000000 - 0xa0000000 [ 0.000000] Machine model: riscv-virtio,qemu [ 0.000000] earlycon: uart8250 at MMIO 0x10000000 (options '115200') [ 0.000000] printk: bootconsole [uart8250] enabled [ 0.000000] efi: UEFI not found. [ 0.000000] Kernel panic - not syncing: init_resources: Failed to allocate 160 bytes [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.12.0-rc7-next-20210416 #1 [ 0.000000] Hardware name: riscv-virtio,qemu (DT) [ 0.000000] Call Trace: [ 0.000000] [<80005292>] walk_stackframe+0x0/0xce [ 0.000000] [<809f4db8>] dump_backtrace+0x38/0x46 [ 0.000000] [<809f4dd4>] show_stack+0xe/0x16 [ 0.000000] [<809ff1d0>] dump_stack+0x92/0xc6 [ 0.000000] [<809f4fee>] panic+0x10a/0x2d8 [ 0.000000] [<80c02b24>] setup_arch+0x2a0/0x4ea [ 0.000000] [<80c006b0>] start_kernel+0x90/0x628 [ 0.000000] ---[ end Kernel panic - not syncing: init_resources: Failed to allocate 160 bytes ]--- Reverting it fixes the problem. I understand that the version in -next is different to this version of the patch, but I also tried v4 and it still crashes with the same error message. Guenter