From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com,
linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
arjan@linux.intel.com, bp@alien8.de,
richard.weinberger@gmail.com
Subject: Re: [PATCH 1/5] x86: Implement __WARN using UD0
Date: Tue, 21 Mar 2017 09:03:40 -0500 [thread overview]
Message-ID: <20170321140340.urru2lmjko6txwl5@treble> (raw)
In-Reply-To: <20170317212350.828368979@infradead.org>
On Fri, Mar 17, 2017 at 10:19:19PM +0100, Peter Zijlstra wrote:
> --- a/arch/x86/include/asm/bug.h
> +++ b/arch/x86/include/asm/bug.h
> @@ -1,36 +1,70 @@
> #ifndef _ASM_X86_BUG_H
> #define _ASM_X86_BUG_H
>
> +#include <linux/stringify.h>
> +
> #define HAVE_ARCH_BUG
>
> -#ifdef CONFIG_DEBUG_BUGVERBOSE
> +/*
> + * Since some emulators terminate on UD2, we cannot use it for WARN.
> + * Since various instruction decoders disagree on the length of UD1,
> + * we cannot use it either. So use UD0 for WARN.
> + *
> + * (binutils knows about "ud1" but {en,de}codes it as 2 bytes, whereas
> + * our kernel decoder thinks it takes a ModRM byte, which seems consistent
> + * with various things like the Intel SDM instruction encoding rules)
> + */
> +
> +#define ASM_UD0 ".byte 0x0f, 0xff"
> +#define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */
> +#define ASM_UD2 ".byte 0x0f, 0x0b"
Thas ASM_UD1 macro isn't used anywhere.
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -169,6 +169,41 @@ void ist_end_non_atomic(void)
> preempt_disable();
> }
>
> +int is_valid_bugaddr(unsigned long addr)
> +{
> + unsigned short ud;
> +
> +#ifdef CONFIG_X86_32
> + if (addr < PAGE_OFFSET)
> + return 0;
> +#else
> + if ((long)addr > 0)
> + return 0;
> +#endif
I think comparing with TASK_SIZE would be more correct and it wouldn't
need an ifdef.
> + if (probe_kernel_address((unsigned short *)addr, ud))
> + return 0;
> +
> + return ud == 0x0b0f || ud == 0xff0f;
> +}
This code would be easier to grok if these were defines IMO.
Also, now that some of the BUG-specific functions are now also related
to WARN, they should probably be renamed to describe their new purpose,
like:
"report_bug" -> "report_bug_or_warning"
"fixup_bug" -> "fixup_bug_or_warning"
On a related note, if warn and bug are going to continue to use two
separate ud instructions for the foreseeable future, report_bug() could
be cleaned up a bit: e.g., for a ud0 instruction, it doesn't make sense
to call find_bug().
> +
> +static int fixup_bug(struct pt_regs *regs, int trapnr)
> +{
> + if (trapnr != X86_TRAP_UD)
> + return 0;
> +
> + switch (report_bug(regs->ip, regs)) {
> + case BUG_TRAP_TYPE_NONE:
> + case BUG_TRAP_TYPE_BUG:
> + break;
> +
> + case BUG_TRAP_TYPE_WARN:
> + regs->ip += 2;
> + return 1;
For self-documentation purposes, maybe use a define for the length of
the ud0 instruction?
--
Josh
next prev parent reply other threads:[~2017-03-21 14:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-17 21:19 [PATCH 0/5] x86 optimizations Peter Zijlstra
2017-03-17 21:19 ` [PATCH 1/5] x86: Implement __WARN using UD0 Peter Zijlstra
2017-03-21 14:03 ` Josh Poimboeuf [this message]
2017-03-21 15:14 ` Peter Zijlstra
2017-03-21 15:17 ` Arjan van de Ven
2017-03-21 15:32 ` Josh Poimboeuf
2017-03-21 15:41 ` Peter Zijlstra
2017-03-22 8:47 ` Peter Zijlstra
2017-03-22 14:18 ` Josh Poimboeuf
2017-03-17 21:19 ` [PATCH 2/5] bug: Add _ONCE logic to report_bug() Peter Zijlstra
2017-03-17 21:19 ` [PATCH 3/5] atomic: Introduce atomic_try_cmpxchg() Peter Zijlstra
2017-03-17 21:19 ` [PATCH 4/5] refcount: Use atomic_try_cmpxchg() Peter Zijlstra
2017-03-17 21:19 ` [PATCH 5/5] x86,atomic: Use atomic_try_cmpxchg Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170321140340.urru2lmjko6txwl5@treble \
--to=jpoimboe@redhat.com \
--cc=arjan@linux.intel.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=richard.weinberger@gmail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).