Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3308353pxj; Mon, 14 Jun 2021 20:40:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdsLMOJ3m4lNZkrBfpGW6LulpRS08kVIsHwRcvXoyUJnpIMhtHghYAlPDLX9wWdPQZTsZ9 X-Received: by 2002:a50:bf0f:: with SMTP id f15mr20423379edk.205.1623728423497; Mon, 14 Jun 2021 20:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623728423; cv=none; d=google.com; s=arc-20160816; b=DmTnXopwVlhlfk59JeHDfK5xQF+71Fl2qB/tD5MtdhH4wniDkiUM6bjpasmAiICl0L jm//JXDJTjadHhyaVcCk+4f6S2WtDbG4uBQv484+Kz9PXPXaLeVkvvgeUtpuqcCNYZcK HXIFcT2jYo/2DJO8nEPnarpWcXHVDA3REc+c6qmPBPI92pB9WV+yXQdN5ml6+lwgmu8S HdrOJcQLr5oF2Y0po+FPlFqM9P7Jf4ZVdw3uZ+oPoYVmMRwCcRpIJeoTXPj4Bu6Pj0kW 8nqwtg/wf1A3ZlkN0HNOXtxQx5iGakgzdGJYT0GXJTliWm/fk5YV0zC7fmUMjR4o0Z51 jnuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/XUOfUqfTAfZKjkDbz8URCssQM6wFC15YP6MEdCsnEs=; b=yNBKZ/DicXgSEQKXflRcsg6MqtDnCgMLIFlFDmaRDbZHjZ/11C7Eo9IugCySrqaenX khOsjnRvkr1bTpEM9dghTLDSx4rhgp1YZUgC2jC9ySRK4TGyy/u78HLeh12TFRA5TJ+q ruN9YjdRKBYXgUYJnPc9S7YJ4gxWjozFmk3wM5hL/IflIXWlVrNWshmIPfnG1sp9iP/h q+GnHzrO7yGJbsEpnQGc7SPa2LkvEtJbN4iKs/5PXZvgEHmNxD1sSllyk/+P0ISbYcXY JT30qocGTqz8LXhD20szEWM3o/Tk98PZUQL4LLCOGyQLwg1gixWW+xoqm2MzVIQi6Wdl hn9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V4AhZHiG; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 7si13344962ejd.558.2021.06.14.20.40.01; Mon, 14 Jun 2021 20:40:23 -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=@gmail.com header.s=20161025 header.b=V4AhZHiG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230360AbhFODk3 (ORCPT + 99 others); Mon, 14 Jun 2021 23:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbhFODk1 (ORCPT ); Mon, 14 Jun 2021 23:40:27 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21CF0C061574 for ; Mon, 14 Jun 2021 20:38:18 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id p15so3290782ybe.6 for ; Mon, 14 Jun 2021 20:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/XUOfUqfTAfZKjkDbz8URCssQM6wFC15YP6MEdCsnEs=; b=V4AhZHiGDcSAoKGd4li1VrGqwa0atky1ZWjy4PK8GFIfFPHtirrJIubkGA47nU5ngf FT3KHoby1zmeLQ0m5TnuP0N6Loa8o5p/9CINYfaNY4ZcowUpkG9XPYYHVSRU9dBR64IF WTgFAWAEZyyJ3xBf2hOlC+Q5kvPVN4kzIDkQX9ACe8SuZ0GS7SjLUE2Q0f3iRRWklCAd 41fmORPId7SGei4NTXqqe0LPWdvyfEpJaJ7ChsQjP3rEu2naKL4cssByUFoVrFKCdfza h/peepqZ8l6cBDS2dkyLcjpeeTtFWcGdYLDQwffy95gO0gFVxfaYDjo0YnvDbMN9290b 9aUQ== 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; bh=/XUOfUqfTAfZKjkDbz8URCssQM6wFC15YP6MEdCsnEs=; b=Ss0whzMQ1FeZcpwQIF3thSH9PCyconQ+WMm4r2VnQ4eeR3PMAA8xBkJdTb1aIJWde3 J93jiwUqtq+dJaNAxvJPI/d/xYCoXN+t6uowYnwRg9uGPeai7AXkzdektJrp7yBxzcyG xG/zl0MMh8uDgOcZ8Wd3juJrEBlio0bKd1EdOCzyZVQrO9uI/EFxNyoA8DpUD1s119ed rpq9YTh8VtbSTePF+4QVP1GMrh9YoE849ymKhiwqH6LapmaElubOnbmH/IL7gmQBSmX1 6SoGTR+noCEWvBGm5GBwkOw2FJSnmHCUv+BaE3sSspyIrnSkq4WDBTUG6uSpBdTax5ph KQSQ== X-Gm-Message-State: AOAM5325l2E6v4Z+Es1a7859a1iI0OS0n+QCAMdM+yP87+YphQBqIGPJ YfHlJ0ya1U5LGrZz179D2n6yDxK8CPrvHjN95bw= X-Received: by 2002:a25:694d:: with SMTP id e74mr4712799ybc.377.1623728297445; Mon, 14 Jun 2021 20:38:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jordan Niethe Date: Tue, 15 Jun 2021 13:38:06 +1000 Message-ID: Subject: Re: [PATCH v2 04/12] powerpc/inst: Avoid pointer dereferencing in ppc_inst_equal() To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "Naveen N. Rao" , linux-kernel@vger.kernel.org, linuxppc-dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 20, 2021 at 11:50 PM Christophe Leroy wrote: > > 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 > Reviewed by: Jordan Niethe