Skip to contentSkip to conversation

use mmgrab

PATCH Applied Julia Lawall 8 participants 19 messages Dec 29, 2019 – Jan 31, 2020

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover use mmgrab

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a few remaining files.

---

 arch/openrisc/kernel/smp.c          |    2 +-
 drivers/misc/cxl/context.c          |    2 +-
 drivers/vfio/pci/vfio_pci_nvlink2.c |    2 +-
 drivers/vfio/vfio_iommu_spapr_tce.c |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
#1 lore raw

PATCH 1/4 misc: cxl: use mmgrab

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
 drivers/misc/cxl/context.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/cxl/context.c +1 -1
index aed9c445d1e2..fb2eff69e449 100644
@@ -352,7 +352,7 @@ void cxl_context_free(struct cxl_context *ctx)
 void cxl_context_mm_count_get(struct cxl_context *ctx)
 {
 	if (ctx->mm)
-		atomic_inc(&ctx->mm->mm_count);
+		mmgrab(ctx->mm);
 }
 
 void cxl_context_mm_count_put(struct cxl_context *ctx)
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] misc: cxl: use mmgrab

Quoted 7 lines · Julia Lawall

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

Quoted 7 lines

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

Thanks!

Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
#3 lore raw

Re: [PATCH 1/4] misc: cxl: use mmgrab

In reply to Julia Lawall
Quoted 7 lines · Julia Lawall

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

Quoted 7 lines

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/30e813cf46ccaeea6508607632e49b4a1d743d2a

cheers

#4 lore raw

PATCH 2/4 vfio: vfio_pci_nvlink2: use mmgrab

In reply to Julia Lawall

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
 drivers/vfio/pci/vfio_pci_nvlink2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +1 -1
index f2983f0f84be..43df10af7f66 100644
@@ -159,7 +159,7 @@ static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev,
 	data->useraddr = vma->vm_start;
 	data->mm = current->mm;
 
-	atomic_inc(&data->mm->mm_count);
+	mmgrab(data->mm);
 	ret = (int) mm_iommu_newdev(data->mm, data->useraddr,
 			vma_pages(vma), data->gpu_hpa, &data->mem);
 
Acked-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] vfio: vfio_pci_nvlink2: use mmgrab

Quoted 25 lines · On Sun, 29 Dec 2019 16:42:56 +0100 Julia Lawall <[email protected]> wrote:

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
 drivers/vfio/pci/vfio_pci_nvlink2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +0 -0
index f2983f0f84be..43df10af7f66 100644

drivers/vfio/pci/vfio_pci_nvlink2.c static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev, · line 165

Quoted 8 lines
drivers/vfio/pci/vfio_pci_nvlink2.c +1 -1
@@ -159,7 +159,7 @@ static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev,
 	data->useraddr = vma->vm_start;
 	data->mm = current->mm;
 
-	atomic_inc(&data->mm->mm_count);
+	mmgrab(data->mm);
 	ret = (int) mm_iommu_newdev(data->mm, data->useraddr,
 			vma_pages(vma), data->gpu_hpa, &data->mem);
 

Thanks! I'm assuming these will be routed via janitors tree, please let me know if you intend me to grab these two vfio patches from the series. Thanks,

Alex

#6 lore raw

Re: [PATCH 2/4] vfio: vfio_pci_nvlink2: use mmgrab

Quoted 6 lines · Alex Williamson

Thanks! I'm assuming these will be routed via janitors tree, please let me know if you intend me to grab these two vfio patches from the series. Thanks,

There isn't a janitors tree.

regards,
dan carpenter

#7 lore raw

Re: [PATCH 2/4] vfio: vfio_pci_nvlink2: use mmgrab

In reply to Alex Williamson
Quoted 39 lines · Alex Williamson
Quoted 25 lines · On Sun, 29 Dec 2019 16:42:56 +0100 Julia Lawall <[email protected]> wrote:

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
 drivers/vfio/pci/vfio_pci_nvlink2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +0 -0
index f2983f0f84be..43df10af7f66 100644

drivers/vfio/pci/vfio_pci_nvlink2.c static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev, · line 165

Quoted 8 lines
drivers/vfio/pci/vfio_pci_nvlink2.c +1 -1
@@ -159,7 +159,7 @@ static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev,
 	data->useraddr = vma->vm_start;
 	data->mm = current->mm;
 
-	atomic_inc(&data->mm->mm_count);
+	mmgrab(data->mm);
 	ret = (int) mm_iommu_newdev(data->mm, data->useraddr,
 			vma_pages(vma), data->gpu_hpa, &data->mem);
 
Quoted 3 lines

Thanks! I'm assuming these will be routed via janitors tree, please let me know if you intend me to grab these two vfio patches from the series. Thanks,

Please take them directly.

thanks,
julia

#8 lore raw

Re: [PATCH 2/4] vfio: vfio_pci_nvlink2: use mmgrab

Quoted 41 lines · On Tue, 7 Jan 2020 18:00:31 +0100 (CET) Julia Lawall <[email protected]>…
Quoted 39 lines · Alex Williamson
Quoted 25 lines · On Sun, 29 Dec 2019 16:42:56 +0100 Julia Lawall <[email protected]> wrote:

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
 drivers/vfio/pci/vfio_pci_nvlink2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +0 -0
index f2983f0f84be..43df10af7f66 100644

drivers/vfio/pci/vfio_pci_nvlink2.c static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev, · line 165

Quoted 8 lines
drivers/vfio/pci/vfio_pci_nvlink2.c +1 -1
@@ -159,7 +159,7 @@ static int vfio_pci_nvgpu_mmap(struct vfio_pci_device *vdev,
 	data->useraddr = vma->vm_start;
 	data->mm = current->mm;
 
-	atomic_inc(&data->mm->mm_count);
+	mmgrab(data->mm);
 	ret = (int) mm_iommu_newdev(data->mm, data->useraddr,
 			vma_pages(vma), data->gpu_hpa, &data->mem);
 
Quoted 5 lines
Quoted 3 lines

Thanks! I'm assuming these will be routed via janitors tree, please let me know if you intend me to grab these two vfio patches from the series. Thanks,

Please take them directly.

Ok, I'll queue patches 2 & 3 for v5.6. Thanks,

Alex

Reviewed-by on v1 2/4
#9 lore raw

Re: [PATCH 2/4] vfio: vfio_pci_nvlink2: use mmgrab

In reply to Julia Lawall
Quoted 13 lines · On Sun, 29 Dec 2019 16:42:56 +0100 Julia Lawall <[email protected]> wrote:

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

Quoted 5 lines
---
 drivers/vfio/pci/vfio_pci_nvlink2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#10 lore raw

PATCH 3/4 vfio/spapr_tce: use mmgrab

In reply to Julia Lawall

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
 drivers/vfio/vfio_iommu_spapr_tce.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/vfio_iommu_spapr_tce.c +1 -1
index 26cef65b41e7..16b3adc508db 100644
@@ -79,7 +79,7 @@ static long tce_iommu_mm_set(struct tce_container *container)
 	}
 	BUG_ON(!current->mm);
 	container->mm = current->mm;
-	atomic_inc(&container->mm->mm_count);
+	mmgrab(container->mm);
 
 	return 0;
 }
Acked-by on v1 3/4
#11 lore raw

Re: [PATCH 3/4] vfio/spapr_tce: use mmgrab

Quoted 25 lines · On Sun, 29 Dec 2019 16:42:57 +0100 Julia Lawall <[email protected]> wrote:

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
 drivers/vfio/vfio_iommu_spapr_tce.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/vfio_iommu_spapr_tce.c +0 -0
index 26cef65b41e7..16b3adc508db 100644

drivers/vfio/vfio_iommu_spapr_tce.c static long tce_iommu_mm_set(struct tce_container *container) · line 85

Quoted 8 lines
drivers/vfio/vfio_iommu_spapr_tce.c +1 -1
@@ -79,7 +79,7 @@ static long tce_iommu_mm_set(struct tce_container *container)
 	}
 	BUG_ON(!current->mm);
 	container->mm = current->mm;
-	atomic_inc(&container->mm->mm_count);
+	mmgrab(container->mm);
 
 	return 0;
 }
Reviewed-by on v1 3/4
#12 lore raw

Re: [PATCH 3/4] vfio/spapr_tce: use mmgrab

In reply to Julia Lawall
Quoted 13 lines · On Sun, 29 Dec 2019 16:42:57 +0100 Julia Lawall <[email protected]> wrote:

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

Quoted 5 lines
---
 drivers/vfio/vfio_iommu_spapr_tce.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#13 lore raw

PATCH 4/4 openrisc: use mmgrab

In reply to Julia Lawall

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a remaining file.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

<smpl>
@@ expression e; @@
- atomic_inc(&e->mm_count);
+ mmgrab(e);
</smpl>

---
I was not able to compile this file.

 arch/openrisc/kernel/smp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/openrisc/kernel/smp.c +1 -1
index 7d518ee8bddc..7bd6e0fc7a6d 100644
@@ -113,7 +113,7 @@ asmlinkage __init void secondary_start_kernel(void)
 	 * All kernel threads share the same mm context; grab a
 	 * reference and switch to it.
 	 */
-	atomic_inc(&mm->mm_count);
+	mmgrab(mm);
 	current->active_mm = mm;
 	cpumask_set_cpu(cpu, mm_cpumask(mm));
 
#14 lore raw

Re: [PATCH 4/4] openrisc: use mmgrab

I love your patch! Yet something to improve:

Hi Julia,

I love your patch! Yet something to improve:

[auto build test ERROR on vfio/next]
[also build test ERROR on char-misc/char-misc-testing v5.5-rc3 next-20191220] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Julia-Lawall/use-mmgrab/20191230-011611
base:   https://github.com/awilliam/linux-vfio.git next
config: openrisc-simple_smp_defconfig (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=openrisc

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

arch/openrisc/kernel/smp.c: In function 'secondary_start_kernel':

>> arch/openrisc/kernel/smp.c:116:2: error: implicit declaration of function 'mmgrab'; did you mean 'igrab'? [-Werror=implicit-function-declaration]
     116 |  mmgrab(mm);
         |  ^~~~~~
         |  igrab

cc1: some warnings being treated as errors

vim +116 arch/openrisc/kernel/smp.c

107
108 asmlinkage __init void secondary_start_kernel(void)
109 {
110 struct mm_struct *mm = &init_mm;
111 unsigned int cpu = smp_processor_id();
112 /*
113 * All kernel threads share the same mm context; grab a
114 * reference and switch to it.
115 */

 > 116		mmgrab(mm);

117 current->active_mm = mm;
118 cpumask_set_cpu(cpu, mm_cpumask(mm));
119
120 pr_info("CPU%u: Booted secondary processor\n", cpu);
121
122 setup_cpuinfo();
123 openrisc_clockevent_init();
124
125 notify_cpu_starting(cpu);
126
127 /*
128 * OK, now it's safe to let the boot CPU continue
129 */
130 complete(&cpu_running);
131
132 synchronise_count_slave(cpu);
133 set_cpu_online(cpu, true);
134
135 local_irq_enable();
136
137 preempt_disable();
138 /*
139 * OK, it's off to the idle thread for us
140 */
141 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
142 }
143

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation

maintainer
#15 lore raw

Re: [PATCH 4/4] openrisc: use mmgrab

Quoted 23 lines · kbuild test robot

Hi Julia,

I love your patch! Yet something to improve:

[auto build test ERROR on vfio/next]
[also build test ERROR on char-misc/char-misc-testing v5.5-rc3 next-20191220] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Julia-Lawall/use-mmgrab/20191230-011611
base:   https://github.com/awilliam/linux-vfio.git next
config: openrisc-simple_smp_defconfig (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=openrisc

If you fix the issue, kindly add following tag

Quoted 8 lines

All errors (new ones prefixed by >>):

arch/openrisc/kernel/smp.c: In function 'secondary_start_kernel':

Quoted 1 line
Quoted 1 line

arch/openrisc/kernel/smp.c:116:2: error: implicit declaration of function 'mmgrab'; did you mean 'igrab'? [-Werror=implicit-function-declaration]

     116 |  mmgrab(mm);
         |  ^~~~~~
         |  igrab

cc1: some warnings being treated as errors

Hi Julia,

It looks like this is just an include issue, do you want to revise the patch?

Once fixed, how do you plan to get this patch series merged? I can add the OpenRISC part to my queue or do you have a cleanups queue you can manage?

-Stafford

maintainer
#16 lore raw

Re: [PATCH 4/4] openrisc: use mmgrab

In reply to kbuild test robot
Quoted 63 lines · kbuild test robot

Hi Julia,

I love your patch! Yet something to improve:

[auto build test ERROR on vfio/next]
[also build test ERROR on char-misc/char-misc-testing v5.5-rc3 next-20191220] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Julia-Lawall/use-mmgrab/20191230-011611
base:   https://github.com/awilliam/linux-vfio.git next
config: openrisc-simple_smp_defconfig (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=openrisc

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

arch/openrisc/kernel/smp.c: In function 'secondary_start_kernel':

Quoted 1 line
Quoted 1 line

arch/openrisc/kernel/smp.c:116:2: error: implicit declaration of function 'mmgrab'; did you mean 'igrab'? [-Werror=implicit-function-declaration]

     116 |  mmgrab(mm);
         |  ^~~~~~
         |  igrab

cc1: some warnings being treated as errors

vim +116 arch/openrisc/kernel/smp.c

   107	
   108	asmlinkage __init void secondary_start_kernel(void)
   109	{
   110		struct mm_struct *mm = &init_mm;
   111		unsigned int cpu = smp_processor_id();
   112		/*
   113		 * All kernel threads share the same mm context; grab a
   114		 * reference and switch to it.
   115		 */
Quoted 1 line

116 mmgrab(mm);

   117		current->active_mm = mm;
   118		cpumask_set_cpu(cpu, mm_cpumask(mm));
   119	
   120		pr_info("CPU%u: Booted secondary processor\n", cpu);
   121	
   122		setup_cpuinfo();
   123		openrisc_clockevent_init();
   124	
   125		notify_cpu_starting(cpu);
   126	
   127		/*
   128		 * OK, now it's safe to let the boot CPU continue
   129		 */
   130		complete(&cpu_running);
   131	
   132		synchronise_count_slave(cpu);
   133		set_cpu_online(cpu, true);
   134	
   135		local_irq_enable();
Quoted 9 lines
   136	
   137		preempt_disable();
   138		/*
   139		 * OK, it's off to the idle thread for us
   140		 */
   141		cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
   142	}
   143	

Hello, FYI I have fixed this commit and queued it on my 5.7 branch.

-Stafford

#17 lore raw
In reply to Julia Lawall
Quoted 3 lines · Julia Lawall

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a few remaining files.

I wonder if there is an automatic way to generate these kind of Coccinelle scripts which use inlines instead of open coding. Like maybe make a list of one line functions, and then auto generate a recipe. Or the mmgrab() function could have multiple lines if the first few were just sanity checks for NULL or something...

regards,
dan carpenter

#18 lore raw
Quoted 10 lines · Dan Carpenter
Quoted 3 lines · Julia Lawall

Mmgrab was introduced in commit f1f1007644ff ("mm: add new mmgrab() helper") and most of the kernel was updated to use it. Update a few remaining files.

I wonder if there is an automatic way to generate these kind of Coccinelle scripts which use inlines instead of open coding. Like maybe make a list of one line functions, and then auto generate a recipe. Or the mmgrab() function could have multiple lines if the first few were just sanity checks for NULL or something...

I tried this at one point (10 years ago!):

https://pages.lip6.fr/Julia.Lawall/acp4is09-lawall.pdf

Perhaps it is worth reviving.

julia