Received: by 10.213.65.68 with SMTP id h4csp1120433imn; Wed, 14 Mar 2018 10:09:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELsIC9/k750gfMgeyOE+Kno3Wqgh2OuQ72NkdhVJoLDzpY2qc15G0EToWl/AN5q5+/Kzpme4 X-Received: by 10.101.96.65 with SMTP id b1mr1834707pgv.340.1521047371251; Wed, 14 Mar 2018 10:09:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521047371; cv=none; d=google.com; s=arc-20160816; b=t3uu6jLeP7wBgg8FtWwOfqgt3HvADseaSX6f7AWPgGoLHSURb3tRfyHhjI9Y2lVFx1 hhiFEEfmGHXANC7Z5VlNkIW6Wf8fO64Fvr4nPZxz/zO5A7OWFgwF62xPbBMHCHVudNa7 PBcrCMBoW6ZkAH8BKiQN9nIp+hV/iN6TYK4IGvVQYSMKuxtnMkNpaNgHG3oBOpoYL42N /3nKx2KsRo8Ie5xawY13D5qLY8LqTFxGzEVPMCac9y5qA0sr6njiT3p30wG6xVSiGOju CVhast95oTsD4TwPYDq5BqMxgGXFwRLKzhZH7M/PhzI3tF+lNPkEI0L7Aeh0oPHNvDq1 ilhg== 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=MmMtYGCUlZU7MemXqlWpcEAM+UYbrgJ1TqTvvbYX2y0=; b=tJdxYm7lur/g3TsN2/5r+hVKpZVW00q0aLdnhOxUKRLBQQxCaNZaKNHd+UVSnrpxJR 5sBy4NQVmiwEdGgvIe5GPUwF4+C+i+KNYzVfxsWo0T2JcxisU93OiYdVJy2tDYMqJXt8 EXH8UFUL4ET416++5IPNY3s9P4oujf9wq9NvyTtYSY6qKaTHUR7tGWG1Glu7G520Tea5 Iz7gGoHmUwtwZCZJiSf96idmOZXHA1iQP7nNH5ZYZGWDW4AgXCFLkiPcbmsQ58qrZRYI VQVf92P8iznokgpZ9zkPZpK+svNLhSV1c9SxvbDLoBfROkr1BLmQL/aszVIDSXNXJzqA 1DBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=dcaanHZb; 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 t3-v6si2278257plm.240.2018.03.14.10.09.03; Wed, 14 Mar 2018 10:09:31 -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=dcaanHZb; 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 S1752341AbeCNRH4 (ORCPT + 99 others); Wed, 14 Mar 2018 13:07:56 -0400 Received: from mail-vk0-f66.google.com ([209.85.213.66]:40005 "EHLO mail-vk0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751492AbeCNRHw (ORCPT ); Wed, 14 Mar 2018 13:07:52 -0400 Received: by mail-vk0-f66.google.com with SMTP id x5so1236858vkd.7 for ; Wed, 14 Mar 2018 10:07:52 -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=MmMtYGCUlZU7MemXqlWpcEAM+UYbrgJ1TqTvvbYX2y0=; b=dcaanHZbkbXGQTOQoNmLZauQf+3qFwHPE68RWtWu4XM7a1yvDj3IU+THv83dxwNp0D T+YP15DG+nKAg5yAmXZ6ruOZGDAr0fO0M3WjHGUtsmUPU8MWpMALSCsCOrfXLkgbA0Wq txDBCa/dPT43pL+tCJU+c4OyumVeIiSDP0JKzmVwVk5jOLamYJ0u8KQJQK5H56reTvyP nl1Mf4qe8/VNvtnIfgr+KSGpShx6uML5CfMsTZnkNSfUPUjceRCitPpTq0ClB/J5N7+n B1crP4o6B6Y1aNkxzLRPXb5s5oGJ8zNdPwogGElOAfcODaP+nS020bRJGgZvt1K72DQq TcoQ== 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=MmMtYGCUlZU7MemXqlWpcEAM+UYbrgJ1TqTvvbYX2y0=; b=sw8b77lvn0Im/kfMQuqpXUULKrEfTQ9xCnt9T+iXjmqhbbpKRH5QAZ7yAxjVho4SmE HXBEaUlOB84XLfCAm+7oWSERfSVUrFvwpHU+MOAdsm6/bMNj5HQnZFxdXz3ZodWAQbGH VGxPOUF0v0i1lwg6LOa6Gdo00bPcfxsoDv8k7K91Pnw7zd4wRBHXXMSEvhFYtHrszbrA tMAN09Lto8cSEaERdgpOLmB7PuZinhzbl4FD2BqMeBTpCVo+TCAoA2+IdQ4kbDKCqDjA MBKw0KcyyAEy9Qu0HGcopFkLai5M6aSci35hhmWgt5eU3XRZdznl2Uw66QqMsXTAjMsh efiw== X-Gm-Message-State: AElRT7H/5Dq3ZjyhxIUAoWcbwgjrvjGSguDyhv/E2lb9IL7jGt6JTdf/ /kUVFfILwvCBRH3fExdfw2kEww== X-Received: by 10.31.41.130 with SMTP id p124mr733684vkp.8.1521047271844; Wed, 14 Mar 2018 10:07:51 -0700 (PDT) Received: from localhost ([65.153.83.185]) by smtp.gmail.com with ESMTPSA id l15sm1736678uaf.52.2018.03.14.10.07.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 10:07:51 -0700 (PDT) Date: Wed, 14 Mar 2018 10:07:51 -0700 (PDT) X-Google-Original-Date: Wed, 14 Mar 2018 10:03:39 PDT (-0700) Subject: Re: [PATCH 00/11] RISC-V: Resolve the issue of loadable module on 64-bit In-Reply-To: <87in9yzwr6.fsf@xps13.shealevy.com> CC: zong@andestech.com, albert@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, zong@andestech.com, zongbox@gmail.com, 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 05:07:09 PDT (-0700), shea@shealevy.com wrote: > Palmer Dabbelt writes: > >> On Tue, 13 Mar 2018 14:30:53 PDT (-0700), shea@shealevy.com wrote: >>> 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? >> >> We don't currently have any position-dependent RISC-V code models larger than >> "medany", in which all code and data must live within a single 32-bit >> addressable range. The PLT and GOT sort of provide an out here, so the code >> only needs to get to the table (which can then get anywhere via an indirection >> layer). >> >> This is relevant for Linux modules because it lets us load modules anywhere in >> the address space. It's also a bit of a headache, as it either requires a >> GOT+PLT per module (which is big) or merging tables (which is hard). > > I see, thanks! We only get this benefit if we actually do the relevanat > indirection in the table, right? And if we merge tables we still have to > have all modules within 32 bits of the common table? Is this how some > future "medlarge" code model will work, or is it more of a convenient > way to reuse existing techniques until other code models are worked out? The idea is that you'd merge the tables only when it's possible to do that correctly, which is the tricky part. It'd be called "largeany", the "med" part is what limits the code model to 32 bit offsets. We might just call it "large", as the "any" is kind of redundant.