Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22766680rwd; Fri, 30 Jun 2023 12:18:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlGiIA9kb3bX+oxt4rKKybQzqlfvcbrxfA0g2LQ6M1I19ILwIfkpW0cttYBGMH3UBSM4FAM8 X-Received: by 2002:a05:6a00:21ca:b0:67f:e74a:d309 with SMTP id t10-20020a056a0021ca00b0067fe74ad309mr3830056pfj.30.1688152738306; Fri, 30 Jun 2023 12:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688152738; cv=none; d=google.com; s=arc-20160816; b=hNKb62ZQ0+k9nmVYLrBlzWvyl89aU+xBJ1bpwfDgaNW8DC5LvANZjKVHHq4XAJjeK/ EZX9oB3sF0gUxdKy1iMFUew5yat3MqT2SVzwPVTab+UJlIgbxMGlAAT9pOE/QDKt/FbW 0FxrKkQLZwPkBfUKhpiDa5sV88JurQLKPaQ46yeblWAIMrG93YlnhnSVsvDl5Nqgi6ug viu263/yK5J4+v88XXculIqcv9mmfsiFBPDu1pkiLD2rxxRv4cAvxSVe1LC68q0gAoh/ vI3rSv66OG1NzzyVuIuX4zNxoV1bkkAM/JLSp2vJItLkKcAQb3jfb9R3Ux/QXwr4abom q8Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=efJC8JRaVX1EZq3/RVDKwdHZtToEspwFR64oW0Opfw8=; fh=qQoCkl4TSVHivxfsz3qX3rcKtvWrmSrfCZ4J57YBKo0=; b=XukfuSkeAvzUZ44tKmd+rFJtkZJ+nViCEsANFeTSmWRA3b4RgYc6EzPqN1Xt+P0anN dL8d+tu9duP4w9MSQNa/+/bXNoIDhfFpTNENh2o/+PKTVwEPAhxa9MPzE1agN9UyXfv5 FtInzhttNOiZgUEZaGTALEKPhGqzYuu1wk09tEfm+TkyIRPvuPDNOjiBpZA10mPlhl32 ji+tiTLYZ+N0EAxx1jgldiBhpyHVgtnsmu5ov34A4li/IW7Rx1g11+ga+jcIVwsojZHd ChaGlUJ65B/XfvL+MpPlpOp1Yik9vVz5ZZIqTEAGJwZVBrEjZhhCSpJG+E/OEUriAhAn LZDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="oGWh90/1"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv12-20020a056a00414c00b00676fd3ad23dsi10259059pfb.384.2023.06.30.12.18.44; Fri, 30 Jun 2023 12:18:58 -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=@kernel.org header.s=k20201202 header.b="oGWh90/1"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230235AbjF3TD2 (ORCPT + 99 others); Fri, 30 Jun 2023 15:03:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbjF3TD1 (ORCPT ); Fri, 30 Jun 2023 15:03:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D6833C07 for ; Fri, 30 Jun 2023 12:03:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9FF48617E8 for ; Fri, 30 Jun 2023 19:03:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06AEBC433C0; Fri, 30 Jun 2023 19:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688151805; bh=V5IBn/evDQRFoADoP9GjVWUyd4RyxJcnLBcMQx5mzo0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oGWh90/19eaYQN9pgIkTZCQCl4pcbTwwaFzTnSoQo6bNF6+4kY10d9OdV08B2IAYX QjO9BwlyNzzHvkEnddAZJO8mIrCDIBMvmjz+dXRyrr8DLorU0BmMnf9ksTQtkQEp+L t8AKrR+CWrmeURGwKrDdlZRyER7vKOudccklPMvh2GGVSA9E00A7u/ChwJDZwBye68 BYzbBWOKqz3I432VFzWmihSrNqPxYieKRwFkV6qTN9++NUwsfIRIeYg9IiocaX3BPR Q+Gcrdg8tEVY2zhI9QR6wxYVmTGU2pmwGMi914tq1+z6M7NsmTttPAi2X/OZM8jUyd rBR2XqCdaMD7g== Date: Fri, 30 Jun 2023 20:03:20 +0100 From: Conor Dooley To: Sami Tolvanen Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Kees Cook , Nathan Chancellor , Nick Desaulniers , linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/6] riscv: Add CFI error handling Message-ID: <20230630-utopia-drizzle-df8c14558696@spud> References: <20230629234244.1752366-8-samitolvanen@google.com> <20230629234244.1752366-12-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2hnuImplXuBy7/70" Content-Disposition: inline In-Reply-To: <20230629234244.1752366-12-samitolvanen@google.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 --2hnuImplXuBy7/70 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hey Sami, On Thu, Jun 29, 2023 at 11:42:49PM +0000, Sami Tolvanen wrote: > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index b54a830eb5c6..20a40927175e 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -44,6 +44,7 @@ config RISCV > select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU > select ARCH_SUPPORTS_HUGETLBFS if MMU > select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU > + select ARCH_USES_CFI_TRAPS if CFI_CLANG Could you please add new entries in alphanumerical order? > select ARCH_USE_MEMTEST > select ARCH_USE_QUEUED_RWLOCKS > select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU > diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h > index 8d5c84f2d5ef..45bc485fcf3f 100644 > --- a/arch/riscv/include/asm/insn.h > +++ b/arch/riscv/include/asm/insn.h > @@ -63,6 +63,7 @@ > #define RVG_RS1_OPOFF 15 > #define RVG_RS2_OPOFF 20 > #define RVG_RD_OPOFF 7 > +#define RVG_RS1_MASK GENMASK(4, 0) > #define RVG_RD_MASK GENMASK(4, 0) > =20 > /* The bit field of immediate value in RVC J instruction */ > @@ -129,6 +130,7 @@ > #define RVC_C2_RS1_OPOFF 7 > #define RVC_C2_RS2_OPOFF 2 > #define RVC_C2_RD_OPOFF 7 > +#define RVC_C2_RS1_MASK GENMASK(4, 0) > =20 > /* parts of opcode for RVG*/ > #define RVG_OPCODE_FENCE 0x0f > @@ -258,6 +260,10 @@ static __always_inline bool riscv_insn_is_branch(u32= code) > #define RV_X(X, s, mask) (((X) >> (s)) & (mask)) > #define RVC_X(X, s, mask) RV_X(X, s, mask) > =20 > +#define RV_EXTRACT_RS1_REG(x) \ > + ({typeof(x) x_ =3D (x); \ > + (RV_X(x_, RVG_RS1_OPOFF, RVG_RS1_MASK)); }) > + > #define RV_EXTRACT_RD_REG(x) \ > ({typeof(x) x_ =3D (x); \ > (RV_X(x_, RVG_RD_OPOFF, RVG_RD_MASK)); }) > @@ -285,6 +291,10 @@ static __always_inline bool riscv_insn_is_branch(u32= code) > (RV_X(x_, RV_B_IMM_11_OPOFF, RV_B_IMM_11_MASK) << RV_B_IMM_11_OFF) | \ > (RV_IMM_SIGN(x_) << RV_B_IMM_SIGN_OFF); }) > =20 > +#define RVC_EXTRACT_C2_RS1_REG(x) \ > + ({typeof(x) x_ =3D (x); \ > + (RV_X(x_, RVC_C2_RS1_OPOFF, RVC_C2_RS1_MASK)); }) > + > #define RVC_EXTRACT_JTYPE_IMM(x) \ > ({typeof(x) x_ =3D (x); \ > (RVC_X(x_, RVC_J_IMM_3_1_OPOFF, RVC_J_IMM_3_1_MASK) << RVC_J_IMM_3_1_OF= F) | \ I was surprised that we didn't have these bits before, had to go looking. Think the optprobes series had handrolled copies of these, which is probably the source of my surprise. Reviewed-by: Conor Dooley # ISA bits --2hnuImplXuBy7/70 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZJ8m+AAKCRB4tDGHoIJi 0jBUAP0UMMzoYNXY5nsJHuteXP1BsQTrz11CKX9PQUFp3nlqBgEA6PNVMrlF90jy yn449Glx4Y4AQdasyKf/P30AlWM9hgo= =Vt5W -----END PGP SIGNATURE----- --2hnuImplXuBy7/70--