Received: by 10.213.65.68 with SMTP id h4csp725265imn; Tue, 13 Mar 2018 20:09:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELtYHK+ATgizp2VZeU/HyTBVLcKWoMJQh/hepELdi0yay7pZYp6XvqBtmDjvPbaCxGSd1SKD X-Received: by 10.98.98.194 with SMTP id w185mr262633pfb.206.1520996958536; Tue, 13 Mar 2018 20:09:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520996958; cv=none; d=google.com; s=arc-20160816; b=0hAJMv0qB0H6AR9UhkMR5zLARHxd7FPAG2ANebrqeLnDT5uLWdeXRDc5i2PfNnf0bF uy2gI4J8Z/y0PB3erCrKYmhmIXXQ6RdEkbD+XsfHpbF0WGd7v9lZNe1EAf27W7NwiX+Y /GzmqEUHx04sT4btqXlEa936mUmgatTbpyRMO/9zGCf/DGaCa7F4yb5Bj9nR/6JAPceu XOgqZhffAz+L9lf/Sw3V5yI1s3HXa0t2Q2IR42ntzDb2VTZ51rQHTkB+cnhSJuKoE4KE 5PqTd0wFt7CF7gmqxfe++4I6m3npqUOooGZFtYV7Gk+21dggIANsrLdJKtTUR3OtVZ82 qNxw== 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=jxdYgDETXgi1VXDbNQIuAWm3GRUYokGXqTDIcqHWzAU=; b=ffm6/QgLb2cbR7RdIoaqw3uezF0RbC5IXfv9/jin2oti5N6XOqP6nxGiAqEylhlsUj BkBBzeeixoWmpwGTnaMb+On3bBLvs6EAX2d/2SgaXvTlf6Top0rEEzVaZMsApRcJsYcY fcC7Tnhb7tRzC3WEJowsyRUopV4EKuxhoV5+jpoKP7IPE2FM7+n49J3fWxu9JUm6f6s6 ZNt/hSur9ufmJoLWfLOed6dwvkUoTWCHRmGJZJDzJjMn4pu8mRqiEs+u5yq3ZClLws4s 1OFsn1gDDbmnbLr4qavH9DwTxSYE8geZ9ZjH8ufM9eEp+D2Zq8Dd6/Ggyij2YnssDVKb a6kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=mQuAarI4; 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 89si1319002pfo.111.2018.03.13.20.09.04; Tue, 13 Mar 2018 20:09:18 -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=mQuAarI4; 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 S933363AbeCNDH4 (ORCPT + 99 others); Tue, 13 Mar 2018 23:07:56 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:40977 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933158AbeCNDHz (ORCPT ); Tue, 13 Mar 2018 23:07:55 -0400 Received: by mail-pf0-f193.google.com with SMTP id f80so813080pfa.8 for ; Tue, 13 Mar 2018 20:07:55 -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=jxdYgDETXgi1VXDbNQIuAWm3GRUYokGXqTDIcqHWzAU=; b=mQuAarI4Yt7Dw2XfCefr1AuSRwLtVDUwECchhtHDbJnVhAL4UfG9GRl3drqtXHOU4H O+NpO5BOxgrAmhdRIwL3uxyo/HwwEK9C2CRn1tN6EadSZ17cNZ9ZhyHmEES9M3MP/20X fneGANns+oyxRZ4nztY4kDUb8t0F4UjXSUG9caFkubykwSUcsgBG4BcoleCpbx6aHwVD 5j53A2sJ88AocN6u7lLeQxhx+ObHB4zLAUPqGNQ0xigCMPTarNF71GiTLpiQflp6L73t a4nPTKr7rwR+rNhUwqqqj4EuduTxXL28+8vhKxLVN49kbWMTdSZ9YLxQg6LkernY+FCx /wzQ== 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=jxdYgDETXgi1VXDbNQIuAWm3GRUYokGXqTDIcqHWzAU=; b=P+eaWX+RkeZKIt30bhmKz1jlJ94BBobHMQaLTzW9nysAumlJ4yEfa7gVxzdWL5sB8l uHb2WDkJadMOd54dA5kZKNSUJ5ADOEk5bF4WmSDsiuyix3lhdFKi/QRm0B22e57vYku+ Ha04yFkJqi9V3xJovm8R8THQumwK9v5Rg4HQu2Qcap7bQevuPQkb2e5GPIuTgG0d1Ilr /Yt6Djo1dpnXCsDHZg83ez8A3GE3y+vomQlOB3TvC4OYrPkubmvnNeQBF0WFBq2jNNJk 9575kWrhKO3G75ff8jSH+HpoJWh/DwSrQpwY0u8GL4Q1iVxiqThoOk9QifKRlSf2fas+ eluA== X-Gm-Message-State: AElRT7F6ufjOV81nweHZCdUpsPl5WZhgCBwCw1BIRLQkKcdrmN160XXu LGQM40lu7koiUPk9DWY7iqjmhQ== X-Received: by 10.101.77.142 with SMTP id p14mr2425456pgq.106.1520996874742; Tue, 13 Mar 2018 20:07:54 -0700 (PDT) Received: from localhost ([65.153.83.185]) by smtp.gmail.com with ESMTPSA id i11sm2014989pgq.34.2018.03.13.20.07.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 20:07:52 -0700 (PDT) Date: Tue, 13 Mar 2018 20:07:52 -0700 (PDT) X-Google-Original-Date: Tue, 13 Mar 2018 20:05:19 PDT (-0700) Subject: Re: [PATCH 00/11] RISC-V: Resolve the issue of loadable module on 64-bit In-Reply-To: CC: shea@shealevy.com, zong@andestech.com, albert@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, greentime@andestech.com From: Palmer Dabbelt To: zongbox@gmail.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 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. >>> 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.