Re: [PATCH kernel v4 6/8] genirq/irqdomain: Move hierarchical IRQ cleanup to kobject_release

2020-11-30 Thread Thomas Gleixner
Alexey,

On Tue, Nov 24 2020 at 17:17, Alexey Kardashevskiy wrote:
> This moves hierarchical domain's irqs cleanup into the kobject release
> hook to make irq_domain_free_irqs() as simple as kobject_put.

Truly simple: Simply broken in multiple ways.

CONFIG_SPARSE_IRQ=n is now completely buggered. It does not even compile
anymore. Running core code changes through a larger set of cross
compilers is neither rocket science nor optional.

For CONFIG_SPARSE_IRQ=y, see below.

> @@ -1675,14 +1679,11 @@ void irq_domain_free_irqs(unsigned int virq, unsigned 
> int nr_irqs)
>"NULL pointer, cannot free irq\n"))
>   return;
>  
> - mutex_lock(_domain_mutex);
> - for (i = 0; i < nr_irqs; i++)
> - irq_domain_remove_irq(virq + i);
> - irq_domain_free_irqs_hierarchy(data->domain, virq, nr_irqs);
> - mutex_unlock(_domain_mutex);
> + for (i = 0; i < nr_irqs; i++) {
> + struct irq_desc *desc = irq_to_desc(virq + i);
>  
> - irq_domain_free_irq_data(virq, nr_irqs);
> - irq_free_descs(virq, nr_irqs);
> + kobject_put(>kobj);

So up to this point both irq_dispose_mapping() _and_
irq_domain_free_irqs() invoked irq_free_descs().

Let's look at the call chains:

   irq_domain_free_irqs()
 irq_free_descs()
   mutex_lock(_irq_lock);
 for (i...)
   free_desc(from + i)
 irq_remove_debugfs_entry();
 unregister_irq_proc();
 irq_sysfs_del();
 delete_irq_desc();
 call_rcu();
   bitmap_clear(allocated_irqs, ...);
   mutex_unlock(_irq_lock);

with your modifications it does:

   irq_domain_free_irqs()
 for (i...)
  kobject_put(>kobj)
irq_kobj_release()
  if (desc->free_irq)
desc->free_irq(desc);
  irq_remove_debugfs_entry();
  unregister_irq_proc();
  delete_irq_desc();
  call_rcu();

Can you spot the wreckage? It's not even subtle, it's more than obvious.

1) None of the operations in irq_kobj_release() is protected by
   sparse_irq_lock anymore. There was a comment in free_desc() which
   explained what is protected. You removed parts of that comment
   and just left the sysfs portion of it above delete_irq_desc()
   which is completely bogus because you removed the irq_sysfs_del()
   call.

2) Nothing removes the freed interrupts from the allocation
   bitmap. Run this often enough and you exhausted the interrupt
   space.

And no, you cannot just go and invoke irq_free_descs() instead of
kobject_put(), simply because you'd create lock order inversion vs. the
free_irq() callback.

So no, it's not that simple and I'm not at all interested in another
respin of this with some more duct tape applied.

It can be done, but that needs way more thought, a proper design which
preserves the existing semantics completely and wants to be a fine
grained series where each patch does exactly ONE small thing which is
reviewable and testable on _ALL_ users of this code, i.e. _ALL_
architectures and irq chip implementations.  

Thanks,

tglx


Re: [PATCH kernel v4 6/8] genirq/irqdomain: Move hierarchical IRQ cleanup to kobject_release

2020-11-24 Thread kernel test robot
Hi Alexey,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.10-rc5 next-20201123]
[cannot apply to tip/irq/core tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Alexey-Kardashevskiy/genirq-irqdomain-Add-reference-counting-to-IRQs/20201124-142727
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
09162bc32c880a791c6c0668ce0745cf7958f576
config: alpha-randconfig-r013-20201124 (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/0day-ci/linux/commit/50199be6fbdf9f1f27ff037a6bd6c602e57f7a5f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Alexey-Kardashevskiy/genirq-irqdomain-Add-reference-counting-to-IRQs/20201124-142727
git checkout 50199be6fbdf9f1f27ff037a6bd6c602e57f7a5f
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=alpha 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   kernel/irq/irqdomain.c: In function 'irq_dispose_mapping':
>> kernel/irq/irqdomain.c:868:19: error: 'struct irq_desc' has no member named 
>> 'kobj'
 868 |  kobject_put(>kobj);
 |   ^~
   kernel/irq/irqdomain.c: In function 'irq_domain_free_irqs':
   kernel/irq/irqdomain.c:1685:20: error: 'struct irq_desc' has no member named 
'kobj'
1685 |   kobject_put(>kobj);
 |^~
   kernel/irq/irqdomain.c: At top level:
   kernel/irq/irqdomain.c:1907:13: warning: no previous prototype for 
'irq_domain_debugfs_init' [-Wmissing-prototypes]
1907 | void __init irq_domain_debugfs_init(struct dentry *root)
 | ^~~

vim +868 kernel/irq/irqdomain.c

   859  
   860  /**
   861   * irq_dispose_mapping() - Unmap an interrupt
   862   * @virq: linux irq number of the interrupt to unmap
   863   */
   864  void irq_dispose_mapping(unsigned int virq)
   865  {
   866  struct irq_desc *desc = irq_to_desc(virq);
   867  
 > 868  kobject_put(>kobj);
   869  }
   870  EXPORT_SYMBOL_GPL(irq_dispose_mapping);
   871  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip