Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1135196pxj; Fri, 21 May 2021 07:16:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydZ1EWbzxdHbqQ+EqWzM1ge4gszFaKxZ3Yr2O8unqPxE6IVeurwhAlVx5PzxXsGire2glu X-Received: by 2002:a17:906:a88c:: with SMTP id ha12mr10599683ejb.129.1621606585598; Fri, 21 May 2021 07:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621606585; cv=none; d=google.com; s=arc-20160816; b=jjKjR6055ZODo3nO6nMDMSJWsg90OIibNSJZv5puF6fRQ3dJV5u2hk0lMtUu0y80PB q3gkefVvFxRlFTrkv0J9Ivsyrp78rPUqguKxKJpJFRiUttv4Jj2ivlowMhtUos/YPte4 ZvrgvorHisrLjTNnXNTQeaM3jN5zSrsdy3JXoKEeRy/lQWSO3qsOT9uP8RzEGINgJUsP TyglLEFWoGfk2X+HH6EMpyTEKuBA4tHRt5g6Q9EbUU3BB7rvYpjhRL1L7llowHCP2FKV jcXN577nG4banGK6pp/SZ3+8EVK2Z5CKoyyyyY+MCEEuzJPtCreEXGWZAy1jX8+1+6LN s6xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:cc:to:subject:from:references:in-reply-to :message-id; bh=hre1Jp6dRdl3P1vPubrUoi5ys7OpuRMqOFI1TgxD2AA=; b=AexKjvUbPTV4h8+AE+Bqc+x5l58d7tXn4pFIWEXzO/x9c7H9Dm+qLFr4148AEQdWp5 TPtR2CWEaOcQBeO5qVIyz1L8hB2n6xHi1NQB/61otzluukhrD7pjcDBybaTuPKuenx+m IQaRNmFG7FU4RJa35VxdqlM5LG9vrw3JnNhQizK8SLFo1wQ76cZA6tJpahXV3wboXp34 Ug5/iTcatV0zoMeIwrG8Gt2fwsnC5dJ1CxDpO4zY20aCqLMGMTa6npSlSJorX4/I972/ 3lF6kK6wjszuNahxAFM/HmAy8IJs5Oea598ts9UkQIDkTZXJfzIxownRiatyL9poGudM J42A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c6si5010741ede.388.2021.05.21.07.16.02; Fri, 21 May 2021 07:16:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241654AbhETNwR (ORCPT + 99 others); Thu, 20 May 2021 09:52:17 -0400 Received: from pegase2.c-s.fr ([93.17.235.10]:46505 "EHLO pegase2.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241642AbhETNwM (ORCPT ); Thu, 20 May 2021 09:52:12 -0400 Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4FmB2t15v4z9sTf; Thu, 20 May 2021 15:50:46 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 21_5S86CRXlc; Thu, 20 May 2021 15:50:46 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4FmB2n5yy8z9sTW; Thu, 20 May 2021 15:50:41 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8C4B88B814; Thu, 20 May 2021 15:50:41 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id j0dMyGrBYeQj; Thu, 20 May 2021 15:50:41 +0200 (CEST) Received: from po15610vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.105]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 693A98B808; Thu, 20 May 2021 15:50:41 +0200 (CEST) Received: by po15610vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 332F764C40; Thu, 20 May 2021 13:50:41 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 04/12] powerpc/inst: Avoid pointer dereferencing in ppc_inst_equal() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , naveen.n.rao@linux.vnet.ibm.com, jniethe5@gmail.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Thu, 20 May 2021 13:50:41 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid casting/dereferencing ppc_inst() as u64* , check each member of the struct when relevant. And remove the 0xff initialisation of the suffix for non prefixed instruction. An instruction with 0xff as a suffix might be invalid, but still is a prefixed instruction and has to be considered as this. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/inst.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/include/asm/inst.h b/arch/powerpc/include/asm/inst.h index fc6adef528a5..5a0740ebf132 100644 --- a/arch/powerpc/include/asm/inst.h +++ b/arch/powerpc/include/asm/inst.h @@ -61,7 +61,7 @@ static inline int ppc_inst_primary_opcode(struct ppc_inst x) } #ifdef CONFIG_PPC64 -#define ppc_inst(x) ((struct ppc_inst){ .val = (x), .suffix = 0xff }) +#define ppc_inst(x) ((struct ppc_inst){ .val = (x) }) #define ppc_inst_prefix(x, y) ((struct ppc_inst){ .val = (x), .suffix = (y) }) @@ -72,7 +72,7 @@ static inline u32 ppc_inst_suffix(struct ppc_inst x) static inline bool ppc_inst_prefixed(struct ppc_inst x) { - return ppc_inst_primary_opcode(x) == OP_PREFIX && ppc_inst_suffix(x) != 0xff; + return ppc_inst_primary_opcode(x) == OP_PREFIX; } static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x) @@ -93,11 +93,6 @@ static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr) } } -static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y) -{ - return *(u64 *)&x == *(u64 *)&y; -} - #else #define ppc_inst(x) ((struct ppc_inst){ .val = x }) @@ -124,13 +119,17 @@ static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr) return *ptr; } +#endif /* CONFIG_PPC64 */ + static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y) { - return ppc_inst_val(x) == ppc_inst_val(y); + if (ppc_inst_val(x) != ppc_inst_val(y)) + return false; + if (!ppc_inst_prefixed(x)) + return true; + return ppc_inst_suffix(x) == ppc_inst_suffix(y); } -#endif /* CONFIG_PPC64 */ - static inline int ppc_inst_len(struct ppc_inst x) { return ppc_inst_prefixed(x) ? 8 : 4; -- 2.25.0