Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11329420ybi; Thu, 25 Jul 2019 14:20:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCMYQQdMxe2v1dPFquwDygand3JlfbN6tsbOAlaYlGju10AJnK5nhIkB66hV0RP5Y74s2F X-Received: by 2002:a63:c0d:: with SMTP id b13mr87731948pgl.420.1564089604375; Thu, 25 Jul 2019 14:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564089604; cv=none; d=google.com; s=arc-20160816; b=PY6h4HehdyhGEeuIJJay3iSSYd0H8DrdXO6vc/1MVm4MzF7jKNNzxoxQ8W+zI7jmtv OQJzAk9/xZ3B90oVTXXVql3mqFPm0fJ4cNSZkxdu1uvYsnMgqPqFvatzH3N5T79r6Kyh e91C4qPpXsEpC9jIJQfIujhswRQSYHoG1JvBaaHxFsX2ca4RTrSWGpMk4zmc6NV5uOD/ sPpikOP3frIfHkJv21aeS0Bg9LsHwN2Ro3WsTM8nFkA8jl5Eev8NpV2Bl9XnjW3tSt1r I3AR9R7ybE8zt9VG5GDxS6iMafklgHhRcvPfv9RonlvoZzdgl4IsLjH4Wz4Z6mEx+Dn2 jvtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oCOvLgRqp/H6p2rloi89lXQefcpHDvjU3XE+e9cLRp8=; b=dwtcRj/9rASV2HEVsiGZFvmBKWgLhkDi7fYCNLmKUROG2elT+KxqEEkesipGYR0LHh UXkBgFyvLcs3EB6JxShwzYVO6M3xialGtb0Bh4qefHlp/iq2kVFShAU7xzbePijFD43a yyBWhN3UhQRiXd4AyCK4uXMHmVtYWQnrgqW9NnO7VM3vhlStz1N2CxiN2V34wgcsQqFy d8CcpmOq32zxihxXB1JQMYRbU2tyIXrgskCkhh1f5BturFjlkH3qE4uTo+ZkzEfMz++a YqGD8S4+IlFwDeu+mqQt504krqdQpvaZaNxdNQG5RiAZEUBF9Dh6N+6G4vsA6o/wsEKA SlwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UM+81dBO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si9382329pge.227.2019.07.25.14.19.49; Thu, 25 Jul 2019 14:20:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UM+81dBO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726693AbfGYVSj (ORCPT + 99 others); Thu, 25 Jul 2019 17:18:39 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37940 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbfGYVSj (ORCPT ); Thu, 25 Jul 2019 17:18:39 -0400 Received: by mail-wr1-f65.google.com with SMTP id g17so52210712wrr.5 for ; Thu, 25 Jul 2019 14:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oCOvLgRqp/H6p2rloi89lXQefcpHDvjU3XE+e9cLRp8=; b=UM+81dBOxoWwDeattozqijuWdhQVri7EW8M8P/xKZaTvSp0Fbk8cG8MimuIzFgWIej C/1Q5GKBICG26vm7i7zZ3hiKdN2I3XECd30EpmyTTyoY57lCZojamgNiNO5+JsYcXqrX zlS2OjKu6INOchJDfWB68ygUbrtxLI94E24Y8LfbW5HncoOzRAYGbZ2edvQiyFwiStkn s6Eqi5Hl43Ncg0lgDZ0Mg5QLhMRNwMPRaRDJ/4y1B5kRpoNMkiDikCGu05BW2ZQrkjg1 6q3FNmOi2FJaaXmWyD1IlMxeC/ic/9FY3GKX/RVCuS8HACBL+a5W8QvkovKsHSBhnS6e 9ZxQ== 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=oCOvLgRqp/H6p2rloi89lXQefcpHDvjU3XE+e9cLRp8=; b=q4sEdbeSUxiBL1d67Zhuzk70yryueRhxhCbKKAFSncZBJ+H50poRNfXHlNCkb4QI2S ht0KzP0+VLMqt73rf65sr9TIaa7iDoJKmnjqRT/kIFVxgZ/1YkeneoUNO4IJ0Gr636KA 75z+T2TS3bPihmGmbVx1jPyvyOf7YDF5gF6tmccI5zHbpQhsVY4IAQ951eb+L2Yq/ogj GL38cGJEQ32pfUBG/7mMuediCuDx6AF/6gI+ixy2k0lav70I429tvC+FXj2ZA2NAYU/M yfggwiPKQmKtBZMQW84NKfpuimiSdtBluh9XVRO15eTPezDjoZOjxXuLFR89ZJlqEVeT cGkA== X-Gm-Message-State: APjAAAXQenLsFo7CwvqrpamnRaE148LErq8b9Uo2sBPWsuSu82LzMk8/ 65rdK9H3osHEHuBK9lzGN+ViQ5FXI85a6FnBc46Oyg== X-Received: by 2002:a5d:6783:: with SMTP id v3mr96274748wru.318.1564089517070; Thu, 25 Jul 2019 14:18:37 -0700 (PDT) MIME-Version: 1.0 References: <20190724184512.162887-1-nums@google.com> <20190724184512.162887-4-nums@google.com> In-Reply-To: From: Ian Rogers Date: Thu, 25 Jul 2019 14:18:25 -0700 Message-ID: Subject: Re: [PATCH 3/3] Fix insn.c misaligned address error To: David Laight Cc: Numfor Mbiziwo-Tiapo , "peterz@infradead.org" , "mingo@redhat.com" , "acme@kernel.org" , "alexander.shishkin@linux.intel.com" , "jolsa@redhat.com" , "namhyung@kernel.org" , "songliubraving@fb.com" , "mbd@fb.com" , "linux-kernel@vger.kernel.org" , "eranian@google.com" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 25, 2019 at 6:06 AM David Laight wrote: > > From: Numfor Mbiziwo-Tiapo > > Sent: 24 July 2019 19:45 > > > > The ubsan (undefined behavior sanitizer) version of perf throws an > > error on the 'x86 instruction decoder - new instructions' function > > of perf test. > > > > To reproduce this run: > > make -C tools/perf USE_CLANG=1 EXTRA_CFLAGS="-fsanitize=undefined" > > > > then run: tools/perf/perf test 62 -v > > > > The error occurs in the __get_next macro (line 34) where an int is > > read from a potentially unaligned address. Using memcpy instead of > > assignment from an unaligned pointer. > ... > > #define __get_next(t, insn) \ > > - ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) > > + ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); \ > > + insn->next_byte += sizeof(t); r; }) > > Isn't there a get_unaligned_u32() (or similar) that can be used? memcpy is a compiler intrinsic. get_unaligned_u32 would mean either a 'if (sizeof(t) == sizeof(u32)) get_unaligned_u32(.. ' for all sizes or changing all call sites of __get_next. Numfor's change feels right as it is the least invasive. Thanks, Ian Rogers (resent to make plain text) > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)