[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8760874x26.fsf@xmission.com>
Date: Thu, 11 Jan 2018 20:42:41 -0600
From: ebiederm@...ssion.com (Eric W. Biederman)
To: Dan Williams <dan.j.williams@...el.com>
Cc: linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org,
kernel-hardening@...ts.openwall.com,
Catalin Marinas <catalin.marinas@....com>, x86@...nel.org,
Will Deacon <will.deacon@....com>,
Alexei Starovoitov <ast@...nel.org>,
Russell King <linux@...linux.org.uk>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>, tglx@...utronix.de,
torvalds@...ux-foundation.org, akpm@...ux-foundation.org,
alan@...ux.intel.com
Subject: Re: [PATCH v2 06/19] asm-generic/barrier: mask speculative execution flows
Dan Williams <dan.j.williams@...el.com> writes:
> diff --git a/include/linux/nospec.h b/include/linux/nospec.h
> new file mode 100644
> index 000000000000..5c66fc30f919
> --- /dev/null
> +++ b/include/linux/nospec.h
> @@ -0,0 +1,71 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright(c) 2018 Intel Corporation. All rights reserved.
> +
> +#ifndef __NOSPEC_H__
> +#define __NOSPEC_H__
> +
> +#include <linux/jump_label.h>
> +#include <asm/barrier.h>
> +
> +#ifndef array_ptr_mask
> +#define array_ptr_mask(idx, sz) \
> +({ \
> + unsigned long mask; \
> + unsigned long _i = (idx); \
> + unsigned long _s = (sz); \
> + \
> + mask = ~(long)(_i | (_s - 1 - _i)) >> (BITS_PER_LONG - 1); \
> + mask; \
> +})
> +#endif
This could really use a comment that explains it generates 0
for out of bound accesses and -1L aka 0xffffffffffffffff for
all other accesses.
The code is clever enough which values it generates is not obvious.
Eric
Powered by blists - more mailing lists