Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2161914ybg; Thu, 30 Jul 2020 11:55:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx211OVeWVk3r2LCGiq2ZLQbXO0h9s+beghEm6CokPRtUy4DYuP+uSib4XeM6XLDzNKzTHh X-Received: by 2002:a17:906:e251:: with SMTP id gq17mr446381ejb.445.1596135304385; Thu, 30 Jul 2020 11:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596135304; cv=none; d=google.com; s=arc-20160816; b=e7jTHYuLkNpwOaH45Vz9H57m7FZWiJQUowcsChAwQZ/l3ov+z+hZXJ8g1XK1K082Cb e3jTf9CufBAlKJDs+dL8eyUj2/o8FyIwqI23/aoAZwO0lgNXPMkArlRUi6mfr05BnBH1 cdaTKAZIx5AxizndqAOaYhOPlT/4lohiDmZnJ9J9BvKAUQiuYZYQ/v2JZ9N5IILaEoNA t0tTwpjHzxTYpA1nGkurj5Iq6TDplzKEqdF/CKrvrZoQJ5SL45jRawp096vUG5rc+ZxX Ou7It9ZuHrns/3pUh108KRBq2THfZ70BdNPgZRY6C1NN9OqieXd0kSQahnUlFoBUYtg3 Fxxg== 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=42l4ctj1Gypy+YF97+QpYMW91oh26x5wOMqUsgssC6s=; b=s/vxk6MwS3od+WkAlmzT4U70is/e4mjYWweynLUJsICk4z9QdiI+wwQEjPTIm2CXj3 hDMRbAIvviGD1mbHKwjqiXCoKZok/DaRL35l9pWGjJmou4xVl26QMIPwaCHyH4AJiy7K cv5oWaPrwGL/8Ku+k4D2wG9UqCGZoYScZvlOrxVaSOcnv4PYi9nWqo6ge2Yvzs45hwHZ SLG0W29Z4OZDTwqjRM59/FimB9g9jwAqkExqA8eH9B4Ve7YIrpSnNDHywYDf5KSKboe3 ZgVEeuvxX8ctnbbEU4QMr18UrL94ueq19JRSC8w35OfR3B7UXVYVO9lgit0eIXOgUNE/ OGDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cs.washington.edu header.s=goo201206 header.b=aNmEAluR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cs.washington.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id op6si3769300ejb.72.2020.07.30.11.54.41; Thu, 30 Jul 2020 11:55:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cs.washington.edu header.s=goo201206 header.b=aNmEAluR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cs.washington.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730324AbgG3SxS (ORCPT + 99 others); Thu, 30 Jul 2020 14:53:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728560AbgG3SxR (ORCPT ); Thu, 30 Jul 2020 14:53:17 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DD3CC061574 for ; Thu, 30 Jul 2020 11:53:17 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id c16so11547996ils.8 for ; Thu, 30 Jul 2020 11:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=42l4ctj1Gypy+YF97+QpYMW91oh26x5wOMqUsgssC6s=; b=aNmEAluRstld+RIo7hQUz4NM8ImkejUWF/fEJtMXvDNc1ZLsHGVAj1sX3XZx8SHsBT DQnU61itpM1kTzbT6mU+RlB4m8Oj08Z/4BRq1prQZadsUGnlY7giifhAe0vxUFe3EFyZ bFf7SgKzakHLoGV7Jfie/FBaf3nE9fJVIOMJE= 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=42l4ctj1Gypy+YF97+QpYMW91oh26x5wOMqUsgssC6s=; b=PdRjgHA91WNeMjIEtGmerbMogMGPtAyaJ/gBG65jDCfl2N1TQdKtlKM3MEHg3so+Bw R+MQXJCN4x+mvaNsT5GBFPBggErhjVTuFb71zgE9Em3BUPd+cyhiS4zbU2ZfZ/gqvk/C xtnQ4qaSzGF+QIlJh3l0o5LpCCswu0N8lXnTzfZbR4zjYWjRYGnjK+qNYZ0UuC28N/hC fecPGVtnm4YJ0nkwbBdDxNVRyMrdlHQ6DyaCx2I57GPjiPtW5amrhJ+O1GWNq64uTYcB OW8V1arYRGglNzkhW21XmiJbH/bnTWkcjUJuC7B50Sa+RVvWIu3XFykmUc5zd24Zqdr+ cWLQ== X-Gm-Message-State: AOAM531VEHD08GlKoZPmM4ClIeYMhvXBmgcpBrnZwTT64sFCf28rzeD8 N5T9PLxNSxV7jXduz+loprA1jlZMUYEhXEzzvu7M8A== X-Received: by 2002:a92:918b:: with SMTP id e11mr29802679ill.201.1596135196772; Thu, 30 Jul 2020 11:53:16 -0700 (PDT) MIME-Version: 1.0 References: <20200722152422.72532-1-kernel@esmil.dk> <20200722152422.72532-2-kernel@esmil.dk> In-Reply-To: <20200722152422.72532-2-kernel@esmil.dk> From: Luke Nelson Date: Thu, 30 Jul 2020 11:53:06 -0700 Message-ID: Subject: Re: [PATCH v1 2/2] riscv: Clean up module relocations To: Emil Renner Berthing Cc: linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Zong Li , Andreas Schwab , LKML , Xi Wang 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 Thanks for the patch! > Also RISC-V has a number of instruction pairs to > generate 32bit immediates or jump/call offsets. Eg.: > > lui rd, hi20 > addi rd, rd, lo12 On RV64, both hi20 from lui and lo12 from addi are sign-extended to 64 bits= . This means that there are some 32-bit signed offsets (in the range [2^31-2^11, 2^31-1]) that are not encodable using (lui+addi), (auipc+jalr), etc. (see discussion at [1]). The following note is from the ISA manual: >>> Note that the set of address offsets that can be formed by pairing LUI = with LD, >>> AUIPC with JALR, etc. in RV64I is [=E2=88=922^31=E2=88=922^11, 2^31=E2= =88=922^11=E2=88=921]. The existing code and the new code both seem buggy if the offset happens to be a 32-bit int but falls outside of the encodable range. > + if (offset !=3D (s32)offset) { > [...] > + if (offset !=3D (s32)offset) { > [...] These checks should probably be replaced with something similar to what's used in the RV64 BPF JIT here: [2], except that this code should check if using RV32 or RV64, since the encodable range differs for each. > My hope is that we can eventually factor out the code to generate > immediates and instructions so it can be reused both here, in the > jump-label code and in the bpf-jit code, but let's take it > one step at a time. This sounds great! Having fewer copies of RISC-V encoding logic around will hopefully decrease the likelihood of bugs :) Some other archs already have shared infrastructure for doing instruction encoding (e.g., in arch/arm64/kernel/insn.c); we should consider doing something similar for RISC-V. - Luke Nelson [1]: https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/bwW= FhBnnZFQ [2]: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id= =3D489553dd13a88d8a882db10622ba8b9b58582ce4