Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4185340ybc; Tue, 26 Nov 2019 05:16:59 -0800 (PST) X-Google-Smtp-Source: APXvYqzSM4MN8RaHB0oWPd1ii8YjAprUMdIXhODDj/kwRxj5kvH3ejb7F4VCuvP9WaGUqYYYrZTZ X-Received: by 2002:a17:906:1611:: with SMTP id m17mr44086544ejd.281.1574774219201; Tue, 26 Nov 2019 05:16:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574774219; cv=none; d=google.com; s=arc-20160816; b=f0FWOr4mapIZLaWw7tlVFMKq/LYJooK3TcJGZS2smu0C2qBCJok58Lzehh2SJAVS35 eDZZlHFAg4iHZvhrHtP9qcmiHXiAX7w7LCL9vPmoSC0h/Q/vOfSyu3FIF6Bz8vZfLfjk cBqM/Wv12t0M4CqOdv+qzYANAM9yOX4rv/kkmq3/CjZ5R/9B3GVodB0+3j9yXW9Gjyqe taKdWAemIaIPIusxF6QMzI0XglXl3l/ZVBXUuA4MlAxkZQOuq9N2vtRvizI7KiOV8IZz TL1hlecuECf3fiBKq3cR9EX8Y0B7dAHHnxS+cVYNS/8PKjPUPSRfBNFMqTcltccSz3eB uo+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=cpPxka1Pl27l5pcH6nCC6OburpGArFz8nhEvihO8xNg=; b=GvYKYQEgodLmdrF2kjlRN5nxFPnYf9ghwnrLJDKFdVsxyrVgjvoNzUhD2NIvaIUhQ2 BJXIdV54yMG9Sgzk3cekcs/HLF0vS20V4pmFbRPUt/Oe0fqZiCY5igodb4tgzcpgA1SC zxiThqKywA2ZLP5edpNcsyNAqD1FkUF/fMHlO4bg2IscP80aHE6Y7tsMsulw5LW0Fxje Cw0bfmPV+GAjJfSt2y1sWvzT5XUZi54S1/WL9ltgreD1oWOt4aN/qPplr7ke/ovPVdVI ORCnAb/ZPtnHbwRB7/+rIGNyzPFQwLBH6uVYzeLGUmsWrW+Uvb2q3EVQmEWGp+SQfwCC ngFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jTCV7l3j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n15si6935456ejr.94.2019.11.26.05.16.34; Tue, 26 Nov 2019 05:16:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jTCV7l3j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbfKZNOg (ORCPT + 99 others); Tue, 26 Nov 2019 08:14:36 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:41304 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbfKZNOg (ORCPT ); Tue, 26 Nov 2019 08:14:36 -0500 Received: by mail-qt1-f193.google.com with SMTP id 59so15805245qtg.8; Tue, 26 Nov 2019 05:14:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=cpPxka1Pl27l5pcH6nCC6OburpGArFz8nhEvihO8xNg=; b=jTCV7l3jNyoKkSnavBxPWKG7xXbsf4keKse9VtmD0UNTC7nV5MSXLWHd0M21Su28JI RpeGYfG41qyscMKZaydg8jOFeUnbC8By/o4moFV0MxKGBx+nGucowfb5GB0L3APzWQyq 9EGHVmXTkopcYKenWF9Wz3O7zkODFY1CUH9T7xHEEj6/BGMC57yPd2rGbwUYdnURqSO5 rIStZs8MhXX+xgyXc/vzRekBA7FhIvpi4pGN5YfNBQ6vUrw4vlRJJ4OK3E8FoqJMWqBk BXvtjClTgFEqzClQ4/ndvqzvyxUVegh0KnhdNNxYGatBtVopF6N0lCOKbsw5MXCnn+aR 6Y6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=cpPxka1Pl27l5pcH6nCC6OburpGArFz8nhEvihO8xNg=; b=kDFWXknBSDU+gejcZQxQk1XmiMexRNwh7ZsHNzS6xNotHSrSJocNMxoHJzFhB45sn+ WkkWv+h6TzO02MvAdeQpNMaD0FbddhE/MYrVM2ds0GBSQ6pi+ZdBhJAavOd04Sf1S0vp VKwTMcu6s00iiARQ5H19hkSYLvzO1wHntRc5h0ZSqThYGS9ESPKAHJ9iTo58x717nezG RzTtNjDxWYRiysVxyd2IYHfV0FE66i90eokWs7z0mSiy9g8EBqu1VXcyZ3Qlo2T0IrYQ PaaR6Pw1uYfVE4WTWgKAv+3Nbp9s/fPgktAUe4SZzhAJgvfw9C+A8hsipTqswZN7uFhy 7TzQ== X-Gm-Message-State: APjAAAVF5i2o8tu2nw89QA2CRSZgTCwZEMDL5Z7zaGqUwGv54K/4qBIO 8yj7U/0SZLrlFpsRJGO7MxdpAdaphVT6iZDTFtU= X-Received: by 2002:ac8:1bed:: with SMTP id m42mr17979158qtk.359.1574774074441; Tue, 26 Nov 2019 05:14:34 -0800 (PST) MIME-Version: 1.0 References: <87d0yoizv9.fsf@xps13.shealevy.com> <87zi19gjof.fsf@xps13.shealevy.com> In-Reply-To: <87zi19gjof.fsf@xps13.shealevy.com> From: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= Date: Tue, 26 Nov 2019 14:14:22 +0100 Message-ID: Subject: Re: [PATCH] RISC-V: Load modules within relative jump range of the kernel text. To: Shea Levy Cc: linux-riscv@lists.infradead.org, albert@sifive.com, LKML , Palmer Dabbelt , Paul Walmsley , Netdev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 9 May 2018 at 13:22, Shea Levy wrote: > > Hi Palmer, > > Shea Levy writes: > > > Hi Palmer, > > > > Palmer Dabbelt writes: > > > >> On Sun, 22 Apr 2018 05:53:56 PDT (-0700), shea@shealevy.com wrote: > >>> Hi Palmer, > >>> > >>> Shea Levy writes: > >>> > >>>> Signed-off-by: Shea Levy > >>>> --- > >>>> > >>>> Note that this patch worked in my old modules patchset and seems to = be > >>>> working now, but my kernel boot locks up on top of > >>>> riscv-for-linus-4.17-mw0 and I don't know if it's due to this patch = or > >>>> something else that's changed in the mean time. > >>>> > >>>> --- > >>>> arch/riscv/include/asm/pgtable.h | 9 +++++++++ > >>>> arch/riscv/kernel/module.c | 11 +++++++++++ > >>>> 2 files changed, 20 insertions(+) > >>>> > >>>> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/a= sm/pgtable.h > >>>> index 16301966d65b..b08ded13364a 100644 > >>>> --- a/arch/riscv/include/asm/pgtable.h > >>>> +++ b/arch/riscv/include/asm/pgtable.h > >>>> @@ -25,6 +25,7 @@ > >>>> #include > >>>> #include > >>>> #include > >>>> +#include > >>>> > >>>> #ifdef CONFIG_64BIT > >>>> #include > >>>> @@ -425,6 +426,14 @@ static inline void pgtable_cache_init(void) > >>>> #define TASK_SIZE VMALLOC_START > >>>> #endif > >>>> > >>>> +/* > >>>> + * The module space lives between the addresses given by TASK_SIZE > >>>> + * and PAGE_OFFSET - it must be within 2G of the kernel text. > >>>> + */ > >>>> +#define MODULES_SIZE (SZ_128M) > >>>> +#define MODULES_VADDR (PAGE_OFFSET - MODULES_SIZE) > >>>> +#define MODULES_END (VMALLOC_END) > >>>> + > >>>> #include > >>>> > >>>> #endif /* !__ASSEMBLY__ */ > >>>> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c > >>>> index 5dddba301d0a..1b382c7de095 100644 > >>>> --- a/arch/riscv/kernel/module.c > >>>> +++ b/arch/riscv/kernel/module.c > >>>> @@ -16,6 +16,8 @@ > >>>> #include > >>>> #include > >>>> #include > >>>> +#include > >>>> +#include > >>>> > >>>> static int apply_r_riscv_64_rela(struct module *me, u32 *location, = Elf_Addr v) > >>>> { > >>>> @@ -382,3 +384,12 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const= char *strtab, > >>>> > >>>> return 0; > >>>> } > >>>> + > >>>> +void *module_alloc(unsigned long size) > >>>> +{ > >>>> + return __vmalloc_node_range(size, 1, MODULES_VADDR, > >>>> + MODULES_END, GFP_KERNEL, > >>>> + PAGE_KERNEL_EXEC, 0, > >>>> + NUMA_NO_NODE, > >>>> + __builtin_return_address(0)); > >>>> +} > >>>> -- > >>>> 2.16.2 > >>> > >>> Any thoughts on this? > >> > >> The concept looks good, but does this actually keep the modules within= 2GiB of > >> the text if PAGE_OFFSET is large? > > > > It's been some time since I wrote this, but I thought PAGE_OFFSET was > > where the kernel text *started*? So unless the text itself is bigger > > than 2G - 128 M, in which case we're SOL anyway, it seems like this > > should work. Is there something better we can do, without a large memor= y > > model? > > > > Thanks, > > Shea > > Any further thoughts on this? > > Thanks, > Shea Shea, Waking up the dead (threads)! I'm hacking on call improvements for the RISC-V BPF JIT. module_alloc() is used under the hood of bpf_jit_binary_alloc(), which in turn is used to allocate the JIT image. The current JIT implementation has to to "load imm64 + jalr" to call kernel syms, since the relative offset is >32b. With your patch, I can use regular jal/auipc+jalr instead. IOW, it would be great if it could be merged. ;-) I'd prefer not having the patch in my BPF JIT series, since that will go through a different tree than Paul's RV one. Wdyt about brushing of the dust of the patch, and re-send it? Thanks! Bj=C3=B6rn