Re: [PATCH V7 1/3] genirq: add device_has_managed_msi_irq

Varad Gautam
2021-10-11T18:23:21Z

Hi Ming,

On 8/18/21 4:44 PM, Ming Lei wrote:
> irq vector allocation with managed affinity may be used by driver, and
> blk-mq needs this info for draining queue because genirq core will shutdown
> managed irq when all CPUs in the affinity mask are offline.
>
> The info of using managed irq is often produced by drivers, and it is
> consumed by blk-mq, so different subsystems are involved in this info flow.
>
> Address this issue by adding one helper of device_has_managed_msi_irq()
> which is suggested by John Garry.
>
> Tested-by: Wen Xiong <wenxiong@us.ibm.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Suggested-by: John Garry <john.garry@huawei.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> include/linux/msi.h | 5 +++++
> kernel/irq/msi.c | 18 ++++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/include/linux/msi.h b/include/linux/msi.h
> index a20dc66b9946..b4511c606072 100644
> --- a/include/linux/msi.h
> +++ b/include/linux/msi.h
> @@ -59,10 +59,15 @@ struct platform_msi_priv_data;
> void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
> #ifdef CONFIG_GENERIC_MSI_IRQ
> void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
> +bool device_has_managed_msi_irq(struct device *dev);

This led me to the following build warning:

In file included from ../drivers/iommu/irq_remapping.c:6:0:
../include/linux/msi.h:23:40: warning: 'struct device' declared inside parameter list will not be visible outside of this definition or declaration

A forward declaration for struct device before the #ifdef
would fix this.

Regards,
Varad

> #else
> static inline void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
> {
> }
> +static inline bool device_has_managed_msi_irq(struct device *dev)
> +{
> + return false;
> +}
> #endif
>
> typedef void (*irq_write_msi_msg_t)(struct msi_desc *desc,
> diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
> index 00f89d5bd6f6..167bc1d8bf4a 100644
> --- a/kernel/irq/msi.c
> +++ b/kernel/irq/msi.c
> @@ -71,6 +71,24 @@ void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
> }
> EXPORT_SYMBOL_GPL(get_cached_msi_msg);
>
> +/**
> + * device_has_managed_msi_irq - Query if device has managed irq entry
> + * @dev: Pointer to the device for which we want to query
> + *
> + * Return true if there is managed irq vector allocated on this device
> + */
> +bool device_has_managed_msi_irq(struct device *dev)
> +{
> + struct msi_desc *desc;
> +
> + for_each_msi_entry(desc, dev) {
> + if (desc->affinity && desc->affinity->is_managed)
> + return true;
> + }
> + return false;
> +}
> +EXPORT_SYMBOL_GPL(device_has_managed_msi_irq);
> +
> #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
> static inline void irq_chip_write_msi_msg(struct irq_data *data,
> struct msi_msg *msg)
>