Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4483734ybc; Tue, 26 Nov 2019 09:36:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxbPpVZ1MJ2Jeyy7DZGVxGRnYcIF46XBa2I+C2ecvxUAJo4No8mAvPpCEKy7AGk1iFfsn9t X-Received: by 2002:a17:906:351b:: with SMTP id r27mr45253112eja.120.1574789782949; Tue, 26 Nov 2019 09:36:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574789782; cv=none; d=google.com; s=arc-20160816; b=g74EEStlHqdNtHGtF11zlQRdok6LJu4sQ2p5f0z3vKOALudh2yYp/PHE2PcUOK5sgW Z1/x5xSaRYG7lHHJ0fW0czn/t5ER0wrBxpU6nfiUpKI+SQCNAAUOKzp6RMEXavOjEUzn hfh8kBKc/zHruOdjBlQ0eeyxFdfvVlK1asxaWFh2rytRIa40KcvONoXt5aK5yLBMWvpV cQbVdnwJJ6lA7eQuQUvZULSK1KU1z4BwhiAuri7kO9sZKOHJKssyZPH/iREZjvK2yk9g uApbLIiljXkbWKK7FC2JfRg6eKLS6ohjYV457phXwNyuPrxebW6kqunr4ZcbMtlvqCqx 9Ugw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=ldUfAuym5TPEu+bYRv0FoVBpTNkLyF5Hk+n5WeB5urg=; b=Dspzu7/plTnroia/k1Ft3UEdt4CPgg1+f7lMOv3cxwUrIlc3rWQxCmuIOAX6F/s0Y0 VQ0YQnYc7NL0khV2aIhI2/VC24T4jg5IYa6XNMvLjh1Tth9d5KS6hfZwc8FiGUgUFm8b gaTrv+9a2qRvzd7sOi2pQy9xbB04qIz6MHnl+QWB4nrMmiigKKbf58Sn+eFjzchy5TBd TTBBdltILcJtV1xDprc7mm4a1uKNrYRvEsT5dGWRGr85cXRI8c7R8C+28qXVwv266F0J MhJKRgSpbBa8NAsxuZ/8AJXHcPdEMA49TN5h4lw9oXVF3cND6+KkWVd9mRj/+GcxqXH7 uOkw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12si7613378ejd.43.2019.11.26.09.35.54; Tue, 26 Nov 2019 09:36:22 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727385AbfKZNdO (ORCPT + 99 others); Tue, 26 Nov 2019 08:33:14 -0500 Received: from smtprelay0142.hostedemail.com ([216.40.44.142]:59889 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725900AbfKZNdO (ORCPT ); Tue, 26 Nov 2019 08:33:14 -0500 X-Greylist: delayed 468 seconds by postgrey-1.27 at vger.kernel.org; Tue, 26 Nov 2019 08:33:13 EST Received: from smtprelay.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by smtpgrave04.hostedemail.com (Postfix) with ESMTP id 94C3E1802623B; Tue, 26 Nov 2019 13:25:25 +0000 (UTC) Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 5A9C41800BEAB; Tue, 26 Nov 2019 13:25:24 +0000 (UTC) X-Session-Marker: 7368656140736865616C6576792E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,shea@shealevy.com,:::::::::::::,RULES_HIT:41:152:355:379:599:800:871:960:973:988:989:1000:1260:1313:1314:1345:1359:1431:1437:1516:1518:1535:1544:1575:1594:1605:1711:1730:1747:1777:1792:1801:1981:2194:2199:2393:2553:2559:2562:2693:2901:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3873:3874:4117:4250:4321:4362:4605:5007:6117:6119:6261:6506:6747:7281:7514:7875:7903:7909:8603:8660:9036:9040:10004:10848:11026:11232:11233:11473:11657:11658:11914:12043:12296:12297:12438:12555:12663:12740:12895:12986:13148:13230:14180:14181:14721:21060:21080:21325:21433:21451:21627:21740:30025:30054:30056:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: actor99_69506a9204f19 X-Filterd-Recvd-Size: 6817 Received: from localhost (unknown [75.112.159.170]) (Authenticated sender: shea@shealevy.com) by omf19.hostedemail.com (Postfix) with ESMTPA; Tue, 26 Nov 2019 13:25:23 +0000 (UTC) From: Shea Levy To: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= Cc: linux-riscv@lists.infradead.org, albert@sifive.com, LKML , Palmer Dabbelt , Paul Walmsley , Netdev Subject: Re: [PATCH] RISC-V: Load modules within relative jump range of the kernel text. In-Reply-To: References: <87d0yoizv9.fsf@xps13.shealevy.com> <87zi19gjof.fsf@xps13.shealevy.com> Date: Tue, 26 Nov 2019 08:25:21 -0500 Message-ID: <87o8wyojlq.fsf@xps13.shealevy.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Bj=C3=B6rn, Unfortunately I'm not sure what more is needed to get this in, and I'm in the middle of a move and won't have easy access to my RISC-V setup for testing. I don't think you can count on me for this one. Thanks, Shea Bj=C3=B6rn T=C3=B6pel writes: > 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/= asm/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, cons= t 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 withi= n 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 memo= ry >> > 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 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE6ESKvwKkwnxgMLnaXAvWlX2G/icFAl3dJ8EACgkQXAvWlX2G /iegUw//RFoBh407tMvoG6prgim8nj0qW2gGKFCKiCAaVK0h2XP/oQmMFT9LKQf+ ZjzdWx6TStG29g+JPBnHPgdIaXHDmFB6DK4z4rZkBgufog1k6kkIBsWaEu6q7/lP cOX31sGO+r4yljFg2f5KLQV0qkyd1sFFDxNwLTjwBLPV3PsGw2fjfMxCiLYgPg9N G1mcp/7PscyZErrgaysfBUOZ2sYyhjM9xFh8BJxq3vIVXEqf94zMgHD63mgVC1x8 gcv/3Fbe1pN/nXr7otX0XR16h04xIOojrnKnuZlDPqqppv4ywao4yci7SYQvM0lL xeuy7nTdu7CGNd+o8icrvQia8K5Hcbb5OqeESRKUg7z+TrftdK1r5Khny+fLIa1r QqK+at8W2t4JDkli+45IkL9KYPkPkdf1I/xEvksADLOjXFYKL1bwYAE7iyPdds37 uvXqWGOdio4pOyq34UM95AdDjbG0CrO4aTeTQBSDGTcSwfEPoVpPrF5zIsqQtmHr VULez79njycJMJaIsIABp2gpkFM5GvY3iFPudqbtcHOs/z2vTO/zVE8MwTP/AhAV l8PZ2dsD4csFAk0IHLoqLw4LERAtA9sT0veDJEcU2ikOwHe5a+6Br3zU7hvjNkR9 OOLJHeVePytK4GR3yJjDjZ1/B+9ihhOeKfqPefCLV3Dht7vmUAk= =thWq -----END PGP SIGNATURE----- --=-=-=--