lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAAFQd5CuNUKv2vEMzJA5dj5ZK6nyg5XBPy_EF3BdUON93TyfTw@mail.gmail.com>
Date: Thu, 24 Oct 2024 15:05:41 +0900
From: Tomasz Figa <tfiga@...omium.org>
To: Sergey Senozhatsky <senozhatsky@...omium.org>
Cc: Stanimir Varbanov <stanimir.k.varbanov@...il.com>, 
	Vikash Garodia <quic_vgarodia@...cinc.com>, "Bryan O'Donoghue" <bryan.odonoghue@...aro.org>, 
	linux-media@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] media: venus: sync with threaded IRQ during inst destruction

On Thu, Oct 24, 2024 at 2:46 PM Sergey Senozhatsky
<senozhatsky@...omium.org> wrote:
>
> On (24/10/24 14:18), Tomasz Figa wrote:
> > > @@ -1538,9 +1538,25 @@ static int venc_close(struct file *file)
> > >
> > >         venc_pm_get(inst);
> > >
> > > +       /*
> > > +        * First, remove the inst from the ->instances list, so that
> > > +        * to_instance() will return NULL.
> > > +        */
> > > +       hfi_session_destroy(inst);
> > > +       /*
> > > +        * Second, make sure we don't have IRQ/IRQ-thread currently running or
> > > +        * pending execution (disable_irq() calls synchronize_irq()), which
> > > +        * can race with the inst destruction.
> > > +        */
> > > +       disable_irq(inst->core->irq);
> > > +       /*
> > > +        * Lastly, inst is gone from the core->instances list and we don't
> > > +        * have running/pending IRQ/IRQ-thread, proceed with the destruction
> > > +        */
> > > +       enable_irq(inst->core->irq);
> > > +
> >
> > Thanks a lot for looking into this. Wouldn't it be enough to just call
> > synchronize_irq() at this point, since the instance was removed from
> > the list already? I guess the question is if that's the only way the
> > interrupt handler can get hold of the instance.
>
> Good question.
>
> synchronize_irq() waits for IRQ-threads, so if inst is accessed only from
> IRQ-thread then we are fine.  If, however, inst is also accessed from hard
> IRQ, then synchronize_irq() won't work, I guess, because it doesn't wait
> for "in flight hard IRQs".  disable_irq() OTOH "waits for completion", so
> we cover in-flight hard IRQs too.

Looking at the code, synchronize_irq() internally also calls
synchronize_hardirq() and that in turn waits for the
IRQD_IRQ_INPROGESS flag to be cleared before returning [1]. The flag
is set by handle_irq_event() before most of the IRQ handling is run
and cleared at the end of the function [2], which makes me believe
that it would actually ensure all the hardirq and threaded IRQ
handlers would be waited for.

[1] https://elixir.bootlin.com/linux/v6.11.5/source/kernel/irq/manage.c#L38
[2] https://elixir.bootlin.com/linux/v6.11.5/source/kernel/irq/handle.c#L202

Although I guess it would be the best if someone confirmed that,
because with all the IRQ handling complexities of SMP, nothing can be
certain today. :P

Best,
Tomasz

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ