Received: by 10.213.65.68 with SMTP id h4csp1120559imn; Wed, 14 Mar 2018 10:09:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELvA/AocJ5Tph4M6MQutGi47RpejrpQ6f7hSw6hgaioQlCt9HWnBFZidh8s+8m60unbOCGmc X-Received: by 10.99.154.18 with SMTP id o18mr4399858pge.344.1521047382380; Wed, 14 Mar 2018 10:09:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521047382; cv=none; d=google.com; s=arc-20160816; b=G8qF5gN1txXOABm3zAkOuLNNm+oSggIGpZb5MdZWOwzHKT7/pajVfTsNLE4MNQiIo+ hxygxpEyLtFOj52jlAyXTedICQFTxdMbWBOwHCS9ux2zwjXAl1SzpXYsrmssW1xbduoE E80oFgGROUOuengH/QlWS5dNqjdoPcxlI9/Hwq86OP0WENfSIJTN9cCvC8z8oH8YHufC KH3Y1josQIgF8+uWFRp6A8psuL/fHMI9qjCuJ4v9DV6TeIzx10bRmi6qCqr3VzPV9wUE vXwAJpKRlI3r6DFi5V7YaJ1uk4jBovpKNJa7fV7UPSOd37aVCzLLGIkqdWnI7ErM7WMg kpMA== 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:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature :arc-authentication-results; bh=D9J25h1w5qBJVKI3lL/Pna1dAIAubpRUkFxZ93wIP48=; b=WbiXjZwMBPEZBzO/DX5igp4mJEmi8m9HxNXvWPQ+jhg7WDsFIfs+0eckHZ7pcUIhhT x9jk8n5m6DKz32WjNWqyXHkmyGv7M9eee9l5XBBjUQlmK1n0ysKPt3EPLS70DBg8Yfot sO6GmZkY1RXN/iSU2lzYChzr3qvSLfRX199Q5vhYUKVv48/sIi9zYK3xUDUiVf6qlGJY esrjunpLpwmaF79trXPdWUW+eQAvbTsm78q3yjwSfiiN5Z3IXKTuKqJ8b1hCOXic0hfK 02p54XXYjVseWdPozV0kqPA9l7WUZcQefEpDlankrj5rJmZK5a7pj8leIyvzhcSecw8d Rqhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DKXafpYD; 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 y28si2387567pfk.273.2018.03.14.10.09.28; Wed, 14 Mar 2018 10:09:42 -0700 (PDT) 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=@sifive.com header.s=google header.b=DKXafpYD; 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 S1752168AbeCNRHx (ORCPT + 99 others); Wed, 14 Mar 2018 13:07:53 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:41047 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751447AbeCNRHu (ORCPT ); Wed, 14 Mar 2018 13:07:50 -0400 Received: by mail-vk0-f68.google.com with SMTP id l123so2440033vke.8 for ; Wed, 14 Mar 2018 10:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=D9J25h1w5qBJVKI3lL/Pna1dAIAubpRUkFxZ93wIP48=; b=DKXafpYDS0d4AxDS4VedgtMlthDMejBB/BvTAcORX4WUCIdGTOTFJg5Ec6I8+Lp2mu MCqZ7MJYrjVGE6ConNiJ6eX4tdPwtH8LDoxlM/u1+f7962vH59PLHFFlcP7i+L+Pazv6 6p8KVMTvzSeicLaQFD8QzRWxcl8jHFvucolfMKWQtDCjjMlRe6OMe1S9TJFC8L1UUWPn sK4Yxr0vDEoPmnu0diT1en8kog0U5IJD/YwJYjWilHUbTmRFZC3zdcx4Pso7ma99ErrY W7fFuBe8nZ8jjDpftcnsmA6QSFp5+pirMtJwRLr1YHa8siw7JyqbpGTC5w+AKlhnCvDb KfNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=D9J25h1w5qBJVKI3lL/Pna1dAIAubpRUkFxZ93wIP48=; b=scyi4wNYb8cE7SbwriNMHZejJe9NU4e4uw+z7ufKZiRV987v7UZAmS2KKwYjsL7h8+ DYtZGyFv6eH+E3gt8qhcgtXZdrJhJFC+uvhfPP3MpfSWmnrSD68Gxx5vm3hye585/MAN YHteHMasVeXD6cuIhUc9ZlOYg8QSH+8G+oy4OaBKBGUs3lrKGSjquPd/aKiBp+xPn5Dy vatP+0bw3LLzM0aDHuzKSyayhVfvGqwO9QGGWlc9LmYaV2ob/Ikc9y8XG3KTHQd5HkDx 7arbm0/neH/vBeT1zyIWZRhlAAdGy6KmUaegfSIsEirPbl45hnO+ht7MCzmqKdn2hcBg G/uA== X-Gm-Message-State: AElRT7F/Ah1MfCnhT8aPqtWDV8TqabD6cPsjWHU2QEorv1A64JsE8L9x IX//VY7Spz8R5xiNd0m+yP0sfQ== X-Received: by 10.31.5.141 with SMTP id 135mr3896299vkf.59.1521047269806; Wed, 14 Mar 2018 10:07:49 -0700 (PDT) Received: from localhost ([65.153.83.185]) by smtp.gmail.com with ESMTPSA id 5sm1423379vkl.4.2018.03.14.10.07.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 10:07:49 -0700 (PDT) Date: Wed, 14 Mar 2018 10:07:49 -0700 (PDT) X-Google-Original-Date: Wed, 14 Mar 2018 09:59:59 PDT (-0700) Subject: Re: [PATCH 00/11] RISC-V: Resolve the issue of loadable module on 64-bit In-Reply-To: <87o9jqzxcp.fsf@xps13.shealevy.com> CC: zongbox@gmail.com, zong@andestech.com, albert@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, greentime@andestech.com From: Palmer Dabbelt To: shea@shealevy.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 14 Mar 2018 04:54:14 PDT (-0700), shea@shealevy.com wrote: > Palmer Dabbelt writes: > >> On Tue, 13 Mar 2018 18:34:19 PDT (-0700), zongbox@gmail.com wrote: >>> 2018-03-14 5:30 GMT+08:00 Shea Levy : >>>> Hi Palmer, >>>> >>>> Palmer Dabbelt writes: >>>> >>>>> On Tue, 13 Mar 2018 01:35:05 PDT (-0700), zong@andestech.com wrote: >>>>>> These patches resolve the some issues of loadable module. >>>>>> - symbol out of ranges >>>>>> - unknown relocation types >>>>>> >>>>>> The reference of external variable and function symbols >>>>>> cannot exceed 32-bit offset ranges in kernel module. >>>>>> The module only can work on the 32-bit OS or the 64-bit >>>>>> OS with sv32 virtual addressing. >>>>>> >>>>>> These patches will generate the .got, .got.plt and >>>>>> .plt sections during loading module, let it can refer >>>>>> to the symbol which locate more than 32-bit offset. >>>>>> These sections depend on the relocation types: >>>>>> - R_RISCV_GOT_HI20 >>>>>> - R_RISCV_CALL_PLT >>>>>> >>>>>> These patches also support more relocation types >>>>>> - R_RISCV_CALL >>>>>> - R_RISCV_HI20 >>>>>> - R_RISCV_LO12_I >>>>>> - R_RISCV_LO12_S >>>>>> - R_RISCV_RVC_BRANCH >>>>>> - R_RISCV_RVC_JUMP >>>>>> - R_RISCV_ALIGN >>>>>> - R_RISCV_ADD32 >>>>>> - R_RISCV_SUB32 >>>>>> >>>>>> Zong Li (11): >>>>>> RISC-V: Add sections of PLT and GOT for kernel module >>>>>> RISC-V: Add section of GOT.PLT for kernel module >>>>>> RISC-V: Support GOT_HI20/CALL_PLT relocation type in kernel module >>>>>> RISC-V: Support CALL relocation type in kernel module >>>>>> RISC-V: Support HI20/LO12_I/LO12_S relocation type in kernel module >>>>>> RISC-V: Support RVC_BRANCH/JUMP relocation type in kernel modulewq >>>>>> RISC-V: Support ALIGN relocation type in kernel module >>>>>> RISC-V: Support ADD32 relocation type in kernel module >>>>>> RISC-V: Support SUB32 relocation type in kernel module >>>>>> RISC-V: Enable module support in defconfig >>>>>> RISC-V: Add definition of relocation types >>>>>> >>>>>> arch/riscv/Kconfig | 5 ++ >>>>>> arch/riscv/Makefile | 3 + >>>>>> arch/riscv/configs/defconfig | 2 + >>>>>> arch/riscv/include/asm/module.h | 112 +++++++++++++++++++++++ >>>>>> arch/riscv/include/uapi/asm/elf.h | 24 +++++ >>>>>> arch/riscv/kernel/Makefile | 1 + >>>>>> arch/riscv/kernel/module-sections.c | 156 ++++++++++++++++++++++++++++++++ >>>>>> arch/riscv/kernel/module.c | 175 ++++++++++++++++++++++++++++++++++-- >>>>>> arch/riscv/kernel/module.lds | 8 ++ >>>>>> 9 files changed, 480 insertions(+), 6 deletions(-) >>>>>> create mode 100644 arch/riscv/include/asm/module.h >>>>>> create mode 100644 arch/riscv/kernel/module-sections.c >>>>>> create mode 100644 arch/riscv/kernel/module.lds >>>>> >>>>> This is the second set of patches that turn on modules, and it has the same >>>>> R_RISCV_ALIGN problem as the other one >>>>> >>>>> http://lists.infradead.org/pipermail/linux-riscv/2018-February/000081.html >>>>> >>>>> It looks like this one uses shared libraries for modules instead of static >>>>> objects. I think using shared objects is the right thing to do, as it'll allow >>>>> us to place modules anywhere in the address space by having multiple GOTs and >>>>> PLTs. >>>> >>>> Can you expand on this? It was my understanding that outside of the >>>> context of multiple address spaces sharing code the GOT and PLT were >>>> simply unnecessary overhead, what benefit would they bring here? >>>> >>>>> That's kind of complicated, though, so we can start with something >>>>> simpler like this. >>> >>> Hi, >>> >>> The kernel module is a object file, it is not be linked by linker, the >>> GOT and PLT >>> sections will not be generated through -fPIC option, but it will >>> generate the relative >>> relocation type. As Palmer mention before, If we have GOT and PLT sections, >>> we can put the module anywhere, even we support the KASLR in the kernel. >> >> Sorry, I guess I meant PIC objects not shared objects (I keep forgetting about >> PIE). We'll probably eventually add large code model targets, but they might >> end up just being functionally equilivant to PIE with multi-GOT and multi-PLT >> so it might not matter. >> >> Either way, this is the sanest way to do it for now. >> >>> For the ALIGN problem, the kernel module loader is difficult to remove >>> or migrate >>> the module's code like relax doing, so the remnant nop instructions harm the >>> performance, I agree the point that adding the mno-relax option and checking >>> the alignment in ALIGN type in module loader. >> >> Sounds good. I just merged the mno-relax stuff, it'll show up when I get >> around to generating a 7.3.0 backport branch. For now I think you should just >> fail on R_RISCV_ALIGN and attempt to pass -mno-relax to the compiler (via >> something like "$(call cc-option,-mno-relax)", like we do for >> "-mstrict-align"). I don't think it's worth handling R_RISCV_ALIGN in the >> kernel, as that's essentially the same as full relaxation support. >> > > Should we unconditionally fail on R_RISCV_ALIGN or only if the code > isn't already aligned? Either way is OK for me. With '-mno-relax' there shouldn't be any R_RISCV_ALIGN relocations, so it shouldn't matter. >> >>>>> That's kind of complicated, though, so we can start with something >>>>> simpler like this. >>> >>> So what is the suggestion for that. >> >> Well, I'm not really sure -- essentially the idea of proper multi-GOT and >> multi-PLT support would be to merge the GOTs and PLTs of modules together when >> they're within range of each other. We haven't even figured this out in >> userspace yet, so it's probably not worth attempting for kernel modules for a >> bit. >> >> If I understand your code correctly, you're currently generating one GOT and >> one PLT per loaded module. If that's the case, then this is correct, it's just >> possible to save some memory by merging these tables. It's probably not worth >> the complexity for kernel modules for a while.