Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1686415rwn; Thu, 15 Sep 2022 21:59:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7pG0+aS/QNFG3GqcSpI5Lhu28/EyZ5Uz361FFzOB4/SsCbg7bQyixp7S41KhZiCY2LMGyq X-Received: by 2002:a05:6a00:1a44:b0:528:6af7:ff4a with SMTP id h4-20020a056a001a4400b005286af7ff4amr3542712pfv.78.1663304371652; Thu, 15 Sep 2022 21:59:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663304371; cv=none; d=google.com; s=arc-20160816; b=SC2klYFTUffxzr8bDSu29dnhbY9vMa4i0iM5N/dEkr7YfSrsloWg78KzAE7+dWinOC 0TCWsRgYkqhlJ+wzfESvo1zC95zKPQe4YldZ/hV7DbdIVB8Y74AlL6IdFV51zCJTwZ4j wl9lCf3+ifGKi3bCvAwa2nqh5DRYTihhwI9zZfGgjHwNkLfYcg3tJabRP/gIvYfXRLEy xCD5aplq5WyIWqIuxpmetr3bWpkdyaU3SE77t8/zH7PoP0tuxqJCjZ8RO/G1hGfYeTT/ ofdE/z6lAEhPd9q/DyPkfYPX1Dd0kfDn6VN2cSjlX+BRcffqzjjFWnvqGRjs/Zz5ZoEH cOyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gvdjpHS/YRkH0vho3frtzgK80BilJG2+eEXjf2bW/zQ=; b=PKq8DFjx5QWGHyjpFCrV2IZB6nl+9nYohQuLiMC76hLFj17xLIabiXs/LtLV+J/h69 v2pivIZnglkkVo1ZwWu5eqpYfXS+4I+ZWcbnwxvFC2JpCFYls42aTDDIU3vWAymLJV/N mHVEDI3bqOPaXhZ5IQgTPLoGfrCd8cJU/urHvkp4/HdrX+YA0E/sH+TnVcylmTGjexqb HhBomgc69DwtTXk7MwN9q2aQD54aQTeVFq+p8Jr6eSAQtet9e8KT9GMu0mfW1kfvUgwU dqOGeIken8hT7DwOQkzSMFLLwJ8NseXkPL/93H2NbioZyqTsIKost6C4qzUgMBn1SHrP 90Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=JcV1gWeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s27-20020a63215b000000b00434ffe3cc11si20786588pgm.870.2022.09.15.21.59.19; Thu, 15 Sep 2022 21:59:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=JcV1gWeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbiIPEXs (ORCPT + 99 others); Fri, 16 Sep 2022 00:23:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbiIPEXo (ORCPT ); Fri, 16 Sep 2022 00:23:44 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60BFB6E883 for ; Thu, 15 Sep 2022 21:23:35 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id bh13so19241299pgb.4 for ; Thu, 15 Sep 2022 21:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=gvdjpHS/YRkH0vho3frtzgK80BilJG2+eEXjf2bW/zQ=; b=JcV1gWeBnsQpr8IFqM1+cNtK3uJZja8fNUZDQ9YI32sLk50HAJeJHl8CtuLS0PXkF1 bt8oDuJ+JN1bl77ccVAq5lwZQNC7l++U2iAztTCBPnoSxu1cTU+6Dr9hs2glfYM4yf09 8kmNhFJRFeOsax8NwX9CBfSKXbeMXz2OHU3cGE3e9PbAsbQTZ0v8JoOO+0yHnQXU5OtV GDf+DQDJjUGr4ucmj+WbBhKV8+M03WKpLvZR68yhxLFN6GhWtkPbT5jhahFYTtdPE2SX BYRR6rco9AMkf69xO+CGlY/878xxKJA3DNg3hv8A+uZwjXcyp64zU/wnKB7rLAqunwgu cBBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=gvdjpHS/YRkH0vho3frtzgK80BilJG2+eEXjf2bW/zQ=; b=2/WgK6QdNelYfLBQQqTmfd4aYGe7WxZcEBIaoCFWt2TH1Vilz3ciYg0QR+355yOUGr ymU9r5ilDslhv0U8LsuLRP4YLzd1Dh+yUsgtWxK7KLiDoXZKHiCK/580J9qZuxFCjVNU mM1PLjmFX7sGNsLrBzCthgImSCeVw5IG72UIqSgfh5ZPCHW11Q9rKOzK/HtMYy/HXnU5 20D773vfTIs2NqInGLQEmXNQihK2bg5kTQZUDLlbIpc3OR1D5apyTH1fzWg8QEK9bp39 eFnksgSUNKJbEZhwiQtADHO/wqzjUIHdW72y2QZ8UMuNSIv5pL4SK9s0x/Etjc6MA9ii S7zg== X-Gm-Message-State: ACrzQf1FirVSYT9Vvn669NmTU2kam//W3Yi1QOR8ILwq79riRg+WQMEO icpFKQ4RrwbxXh5PhkvL09/4ng== X-Received: by 2002:a65:56ca:0:b0:439:169f:f027 with SMTP id w10-20020a6556ca000000b00439169ff027mr2792866pgs.580.1663302214959; Thu, 15 Sep 2022 21:23:34 -0700 (PDT) Received: from vineet-framework.ba.rivosinc.com (c-24-4-73-83.hsd1.ca.comcast.net. [24.4.73.83]) by smtp.gmail.com with ESMTPSA id x4-20020a623104000000b0053e6eae9668sm13257286pfx.2.2022.09.15.21.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 21:23:34 -0700 (PDT) From: Vineet Gupta To: linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt , Christoph Muellner , linux@rivosinc.com, Vineet Gupta Subject: [PATCH v2] riscv: ztso: disallow elf binaries needing TSO Date: Thu, 15 Sep 2022 21:23:31 -0700 Message-Id: <20220916042331.1398823-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916030552.1396820-1-vineetg@rivosinc.com> References: <20220916030552.1396820-1-vineetg@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As of now the software stack needs work to support ztso. Until that work is finished, disallow binaries needing TSO. This patch is needed to help ztso ratification and prolifiration of tso bits in tooling. Signed-off-by: Vineet Gupta --- Changes since v1 - Build error (and boot tested on qemu) - Improved the comments a bit --- arch/riscv/include/asm/elf.h | 11 ++++++++++- arch/riscv/include/uapi/asm/elf.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index f53c40026c7a..b6b4542b3039 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -26,10 +26,19 @@ #define ELF_DATA ELFDATA2LSB +/* + * Make sure the elf being loaded is compatible with extensions. + * + * In the final incarnation this will get the extension list from DT and + * make sure elf can run on given hardware+kernel. + * For now disallow TSO built binaries. + */ +#define rv_ext_ok(x) (!((x)->e_flags & EF_RISCV_TSO)) + /* * This is used to ensure we don't load something for the wrong architecture. */ -#define elf_check_arch(x) ((x)->e_machine == EM_RISCV) +#define elf_check_arch(x) ((x)->e_machine == EM_RISCV && rv_ext_ok(x)) #define CORE_DUMP_USE_REGSET #define ELF_EXEC_PAGESIZE (PAGE_SIZE) diff --git a/arch/riscv/include/uapi/asm/elf.h b/arch/riscv/include/uapi/asm/elf.h index d696d6610231..fa9e4c52c7ac 100644 --- a/arch/riscv/include/uapi/asm/elf.h +++ b/arch/riscv/include/uapi/asm/elf.h @@ -32,6 +32,8 @@ typedef union __riscv_fp_state elf_fpregset_t; #define ELF_RISCV_R_TYPE(r_info) ELF32_R_TYPE(r_info) #endif +#define EF_RISCV_TSO (1 << 3) + /* * RISC-V relocation types */ -- 2.34.1