[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DD12CB44-457E-4FE1-8240-B334B785A93C@amacapital.net>
Date: Mon, 23 Nov 2020 07:15:18 -0800
From: Andy Lutomirski <luto@...capital.net>
To: Jürgen Groß <jgross@...e.com>
Cc: Andy Lutomirski <luto@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Stefano Stabellini <sstabellini@...nel.org>,
"VMware, Inc." <pv-drivers@...are.com>, X86 ML <x86@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
Linux Virtualization <virtualization@...ts.linux-foundation.org>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>,
xen-devel <xen-devel@...ts.xenproject.org>,
Thomas Gleixner <tglx@...utronix.de>,
Boris Ostrovsky <boris.ostrovsky@...cle.com>
Subject: Re: [PATCH v2 05/12] x86: rework arch_local_irq_restore() to not use popf
> On Nov 22, 2020, at 9:22 PM, Jürgen Groß <jgross@...e.com> wrote:
>
> On 22.11.20 22:44, Andy Lutomirski wrote:
>>> On Sat, Nov 21, 2020 at 10:55 PM Jürgen Groß <jgross@...e.com> wrote:
>>>
>>> On 20.11.20 12:59, Peter Zijlstra wrote:
>>>> On Fri, Nov 20, 2020 at 12:46:23PM +0100, Juergen Gross wrote:
>>>>> +static __always_inline void arch_local_irq_restore(unsigned long flags)
>>>>> +{
>>>>> + if (!arch_irqs_disabled_flags(flags))
>>>>> + arch_local_irq_enable();
>>>>> +}
>>>>
>>>> If someone were to write horrible code like:
>>>>
>>>> local_irq_disable();
>>>> local_irq_save(flags);
>>>> local_irq_enable();
>>>> local_irq_restore(flags);
>>>>
>>>> we'd be up some creek without a paddle... now I don't _think_ we have
>>>> genius code like that, but I'd feel saver if we can haz an assertion in
>>>> there somewhere...
>>>>
>>>> Maybe something like:
>>>>
>>>> #ifdef CONFIG_DEBUG_ENTRY // for lack of something saner
>>>> WARN_ON_ONCE((arch_local_save_flags() ^ flags) & X86_EFLAGS_IF);
>>>> #endif
>>>>
>>>> At the end?
>>>
>>> I'd like to, but using WARN_ON_ONCE() in include/asm/irqflags.h sounds
>>> like a perfect receipt for include dependency hell.
>>>
>>> We could use a plain asm("ud2") instead.
>> How about out-of-lining it:
>> #ifdef CONFIG_DEBUG_ENTRY
>> extern void warn_bogus_irqrestore();
>> #endif
>> static __always_inline void arch_local_irq_restore(unsigned long flags)
>> {
>> if (!arch_irqs_disabled_flags(flags)) {
>> arch_local_irq_enable();
>> } else {
>> #ifdef CONFIG_DEBUG_ENTRY
>> if (unlikely(arch_local_irq_save() & X86_EFLAGS_IF))
>> warn_bogus_irqrestore();
>> #endif
>> }
>
> This couldn't be a WARN_ON_ONCE() then (or it would be a catch all).
If you put the WARN_ON_ONCE in the out-of-line helper, it should work reasonably well.
> Another approach might be to open-code the WARN_ON_ONCE(), like:
>
> #ifdef CONFIG_DEBUG_ENTRY
> extern void warn_bogus_irqrestore(bool *once);
> #endif
>
> static __always_inline void arch_local_irq_restore(unsigned long flags)
> {
> if (!arch_irqs_disabled_flags(flags))
> arch_local_irq_enable();
> #ifdef CONFIG_DEBUG_ENTRY
> {
> static bool once;
>
> if (unlikely(arch_local_irq_save() & X86_EFLAGS_IF))
> warn_bogus_irqrestore(&once);
> }
> #endif
> }
>
I don’t know precisely what a static variable in an __always_inline function will do, but I imagine it will be, at best, erratic, especially when modules are involved.
>
> Juergen
> <OpenPGP_0xB0DE9DD628BF132F.asc>
Powered by blists - more mailing lists