Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753492AbeADWXa (ORCPT + 1 other); Thu, 4 Jan 2018 17:23:30 -0500 Received: from mail-io0-f173.google.com ([209.85.223.173]:38072 "EHLO mail-io0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751952AbeADWX1 (ORCPT ); Thu, 4 Jan 2018 17:23:27 -0500 X-Google-Smtp-Source: ACJfBosJZ5NIQfwIZ1pzqkpE58lKnmJiQPVOQrgI7mUjbIIw86Vh1ckHsKUBcEj7HKbWHMwi0Hsp3lyOnGBCAMolghk= MIME-Version: 1.0 In-Reply-To: References: <20180103223827.39601-1-mark.rutland@arm.com> <151502463248.33513.5960736946233335087.stgit@dwillia2-desk3.amr.corp.intel.com> <20180104010754.22ca6a74@alans-desktop> <20180104192648.GA10427@amd> From: Linus Torvalds Date: Thu, 4 Jan 2018 14:23:25 -0800 X-Google-Sender-Auth: HARwWWHmeIaBwxtIMI3oHGbWBLQ Message-ID: Subject: Re: [RFC PATCH] asm/generic: introduce if_nospec and nospec_barrier To: Dan Williams Cc: Pavel Machek , Julia Lawall , Alan Cox , Linux Kernel Mailing List , Mark Rutland , linux-arch@vger.kernel.org, Peter Zijlstra , Greg KH , Thomas Gleixner , Elena Reshetova , Alan Cox , Dan Carpenter Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Thu, Jan 4, 2018 at 2:20 PM, Linus Torvalds wrote: > > #define array_access(base, idx, max) ({ \ > union { typeof(base[0]) _val; unsigned long _bit; } __u;\ > unsigned long _i = (idx); \ > unsigned long _m = (max); \ > unsigned long _mask = _i < _m ? ~0 : 0; \ > OPTIMIZER_HIDE_VAR(_mask); \ > __u._val = base[_i & _mask]; \ > __u._bit &= _mask; \ > __u._val; }) That __u._val = base[_i & _mask]; thing would have to be READ_ONCE() to make it all ok for the special cases without locking etc. Linus