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] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 31 May 2017 14:54:19 +0100
From:   Marc Zyngier <marc.zyngier@....com>
To:     Thomas Gleixner <tglx@...utronix.de>,
        LKML <linux-kernel@...r.kernel.org>
Cc:     jeffy <jeffy.chen@...k-chips.com>,
        Brian Norris <briannorris@...omium.org>, dianders@...omium.org,
        tfiga@...omium.org
Subject: Re: [patch 1/2] genirq: Handle NOAUTOEN interrupt setup proper

Hi Thomas,

On 31/05/17 10:58, Thomas Gleixner wrote:
> If an interrupt is marked NOAUTOEN then request_irq() installs the action,
> but does not enable the interrupt via startup_irq().  The interrupt is
> enabled via enable_irq() later from the driver. enable_irq() calls
> irq_enable().
> 
> That means that for interrupts which have a irq_startup() callback this
> callback is never invoked. Neither is irq_domain_activate_irq() invoked for
> such interrupts.
> 
> If an interrupt depends on irq_startup() or irq_domain_activate_irq() then
> the enable via irq_enable() is not enough.
> 
> Add a status flag IRQD_IRQ_STARTED_UP and use this to select the proper
> mechanism in enable_irq(). Use the flag also to avoid pointless calls into
> the low level functions.
> 
> Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
> ---
>  include/linux/irq.h    |    6 ++++
>  kernel/irq/chip.c      |   73 +++++++++++++++++++++++++++++++++++++------------
>  kernel/irq/internals.h |    1 
>  kernel/irq/manage.c    |    2 -
>  4 files changed, 64 insertions(+), 18 deletions(-)
> 
> --- a/include/linux/irq.h
> +++ b/include/linux/irq.h
> @@ -216,6 +216,7 @@ enum {
>  	IRQD_WAKEUP_ARMED		= (1 << 19),
>  	IRQD_FORWARDED_TO_VCPU		= (1 << 20),
>  	IRQD_AFFINITY_MANAGED		= (1 << 21),
> +	IRQD_IRQ_STARTED_UP		= (1 << 22),
>  };
>  
>  #define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
> @@ -329,6 +330,11 @@ static inline void irqd_clr_activated(st
>  	__irqd_to_state(d) &= ~IRQD_ACTIVATED;
>  }
>  
> +static inline bool irqd_is_started_up(struct irq_data *d)

nit: since we have set/clr_started, consider making this is_started
(without the up)? Or add the _up to clr/set?

> +{
> +	return __irqd_to_state(d) & IRQD_IRQ_STARTED_UP;
> +}
> +
>  #undef __irqd_to_state
>  
>  static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
> --- a/kernel/irq/chip.c
> +++ b/kernel/irq/chip.c
> @@ -185,37 +185,71 @@ static void irq_state_set_masked(struct
>  	irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
>  }
>  
> +static void irq_state_clr_started(struct irq_desc *desc)
> +{
> +	irqd_clear(&desc->irq_data, IRQD_IRQ_STARTED_UP);
> +}
> +
> +static void irq_state_set_started(struct irq_desc *desc)
> +{
> +	irqd_set(&desc->irq_data, IRQD_IRQ_STARTED_UP);
> +}
> +
>  int irq_startup(struct irq_desc *desc, bool resend)
>  {
>  	int ret = 0;
>  
> -	irq_state_clr_disabled(desc);
> +	if (irqd_is_started_up(&desc->irq_data))
> +		return 0;
> +

How about:
	if (irqd_is_started_up(&desc->irq_data)) {
		irq_enable(desc);
		return 0;
	}

>  	desc->depth = 0;
>  
>  	irq_domain_activate_irq(&desc->irq_data);
>  	if (desc->irq_data.chip->irq_startup) {
>  		ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
> +		irq_state_clr_disabled(desc);
>  		irq_state_clr_masked(desc);
>  	} else {
>  		irq_enable(desc);
>  	}
> +	irq_state_set_started(desc);
> +
>  	if (resend)
>  		check_irq_resend(desc);
> +
>  	return ret;
>  }
>  
> +static void __irq_disable(struct irq_desc *desc, bool mask);
> +
>  void irq_shutdown(struct irq_desc *desc)
>  {
> -	irq_state_set_disabled(desc);
> -	desc->depth = 1;
> -	if (desc->irq_data.chip->irq_shutdown)
> -		desc->irq_data.chip->irq_shutdown(&desc->irq_data);
> -	else if (desc->irq_data.chip->irq_disable)
> -		desc->irq_data.chip->irq_disable(&desc->irq_data);
> -	else
> -		desc->irq_data.chip->irq_mask(&desc->irq_data);
> +	if (irqd_is_started_up(&desc->irq_data)) {
> +		desc->depth = 1;
> +		if (desc->irq_data.chip->irq_shutdown) {
> +			desc->irq_data.chip->irq_shutdown(&desc->irq_data);
> +			irq_state_set_disabled(desc);
> +			irq_state_set_masked(desc);
> +		} else {
> +			__irq_disable(desc, true);
> +		}
> +		irq_state_clr_started(desc);
> +	}
> +	/*
> +	 * This must be called even if the interrupt was never started up,
> +	 * because the activation can happen before the interrupt is
> +	 * available for request/startup. It has it's own state tracking so
> +	 * it's safe to call it unconditonally.

                                unconditionally?

> +	 */
>  	irq_domain_deactivate_irq(&desc->irq_data);
> -	irq_state_set_masked(desc);
> +}
> +
> +void irq_enable_or_startup(struct irq_desc *desc)
> +{
> +	if (!irqd_is_started_up(&desc->irq_data))
> +		irq_startup(desc, false);
> +	else
> +		irq_enable(desc);

get rid of this new function...

>  }
>  
>  void irq_enable(struct irq_desc *desc)
> @@ -228,6 +262,17 @@ void irq_enable(struct irq_desc *desc)
>  	irq_state_clr_masked(desc);
>  }
>  
> +static void __irq_disable(struct irq_desc *desc, bool mask)
> +{
> +	irq_state_set_disabled(desc);
> +	if (desc->irq_data.chip->irq_disable) {
> +		desc->irq_data.chip->irq_disable(&desc->irq_data);
> +		irq_state_set_masked(desc);
> +	} else if (mask) {
> +		mask_irq(desc);
> +	}
> +}
> +
>  /**
>   * irq_disable - Mark interrupt disabled
>   * @desc:	irq descriptor which should be disabled
> @@ -250,13 +295,7 @@ void irq_enable(struct irq_desc *desc)
>   */
>  void irq_disable(struct irq_desc *desc)
>  {
> -	irq_state_set_disabled(desc);
> -	if (desc->irq_data.chip->irq_disable) {
> -		desc->irq_data.chip->irq_disable(&desc->irq_data);
> -		irq_state_set_masked(desc);
> -	} else if (irq_settings_disable_unlazy(desc)) {
> -		mask_irq(desc);
> -	}
> +	__irq_disable(desc, irq_settings_disable_unlazy(desc));
>  }
>  
>  void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
> --- a/kernel/irq/internals.h
> +++ b/kernel/irq/internals.h
> @@ -68,6 +68,7 @@ extern void __enable_irq(struct irq_desc
>  
>  extern int irq_startup(struct irq_desc *desc, bool resend);
>  extern void irq_shutdown(struct irq_desc *desc);
> +extern void irq_enable_or_startup(struct irq_desc *desc);
>  extern void irq_enable(struct irq_desc *desc);
>  extern void irq_disable(struct irq_desc *desc);
>  extern void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu);
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -533,7 +533,7 @@ void __enable_irq(struct irq_desc *desc)
>  			goto err_out;
>  		/* Prevent probing on this irq: */
>  		irq_settings_set_noprobe(desc);
> -		irq_enable(desc);
> +		irq_enable_or_startup(desc);

and make this irq_startup(desc, false)?

>  		check_irq_resend(desc);
>  		/* fall-through */
>  	}
> 
> 

Otherwise:

Acked-by: Marc Zyngier <marc.zyngier@....com>

	M.
-- 
Jazz is not dead. It just smells funny...

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ