kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [RFC PATCH] vfio: type1: fix kthread use case
       [not found] <20200706104915.11460-1-hdanton@sina.com>
@ 2020-07-06 11:32 ` Markus Elfring
       [not found] ` <20200706124241.4392-1-hdanton@sina.com>
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2020-07-06 11:32 UTC (permalink / raw)
  To: Hillf Danton, Alex Williamson, iommu
  Cc: Kevin Tian, Yan Zhao, kernel-janitors, linux-kernel, Christoph Hellwig

…
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2798,7 +2798,8 @@ static int vfio_iommu_type1_dma_rw_chunk
> -	bool kthread = current->mm == NULL;
> +	bool kthread = current->flags & PF_KTHREAD;
> +	bool use_mm = current->mm == NULL;
…

Can it be helpful to convert initialisations for these variables
into later assignments?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] vfio: type1: fix kthread use case
       [not found] ` <20200706124241.4392-1-hdanton@sina.com>
@ 2020-07-06 13:33   ` Markus Elfring
  2020-07-06 14:04   ` Markus Elfring
       [not found]   ` <20200707011420.1416-1-hdanton@sina.com>
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2020-07-06 13:33 UTC (permalink / raw)
  To: Hillf Danton, Alex Williamson, iommu
  Cc: Kevin Tian, Yan Zhao, kernel-janitors, linux-kernel, Christoph Hellwig

>> Can it be helpful to convert initialisations for these variables
>> into later assignments?
>
> Perhaps. Then it looks like the below.
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2798,9 +2798,12 @@ static int vfio_iommu_type1_dma_rw_chunk
> -	bool kthread = current->mm == NULL;
> +	bool kthread;
> +	bool use_mm;

I would prefer the following variable declarations then.

+	bool kthread, use_mm;


>  	size_t offset;
>
> +	kthread = current->flags & PF_KTHREAD;
> +	use_mm = current->mm == NULL;

I propose to move such assignments directly before the corresponding check.


…
>  	if (!mm)
>  		return -EPERM;


+	kthread = current->flags & PF_KTHREAD;
+	use_mm = !current->mm;

> -	if (kthread)
> +	if (kthread && use_mm)
>  		kthread_use_mm(mm);
…

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] vfio: type1: fix kthread use case
       [not found] ` <20200706124241.4392-1-hdanton@sina.com>
  2020-07-06 13:33   ` Markus Elfring
@ 2020-07-06 14:04   ` Markus Elfring
       [not found]   ` <20200707011420.1416-1-hdanton@sina.com>
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2020-07-06 14:04 UTC (permalink / raw)
  To: Hillf Danton, Alex Williamson, iommu
  Cc: Kevin Tian, Yan Zhao, kernel-janitors, linux-kernel, Christoph Hellwig

…
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2812,11 +2815,10 @@ static int vfio_iommu_type1_dma_rw_chunk
>  	if (!mm)
>  		return -EPERM;
>
> -	if (kthread)
> +	if (kthread && use_mm)

Can another design approach make sense here?

+	bool thread_use_mm = ((current->flags & PF_KTHREAD) && !current->mm);
+	if (thread_use_mm)


>  		kthread_use_mm(mm);
…

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] vfio: type1: fix kthread use case
       [not found]   ` <20200707011420.1416-1-hdanton@sina.com>
@ 2020-07-07  6:04     ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2020-07-07  6:04 UTC (permalink / raw)
  To: Hillf Danton, iommu
  Cc: Kevin Tian, Yan Zhao, kernel-janitors, linux-kernel,
	Alex Williamson, Christoph Hellwig

…
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2798,7 +2798,7 @@ static int vfio_iommu_type1_dma_rw_chunk
> -	bool kthread = current->mm == NULL;
> +	bool kthread_load_mm;
>  	size_t offset;

How do you think about to reduce the scope for such variables?
https://refactoring.com/catalog/reduceScopeOfVariable.html> @@ -2812,11 +2812,12 @@ static int vfio_iommu_type1_dma_rw_chunk
>  	if (!mm)
>  		return -EPERM;
> +	kthread_load_mm = current->flags & PF_KTHREAD &&
> +				current->mm == NULL;
…

Would you like to apply a more succinct code variant?

+	kthread_load_mm = current->flags & PF_KTHREAD && !current->mm;


Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-07  6:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200706104915.11460-1-hdanton@sina.com>
2020-07-06 11:32 ` [RFC PATCH] vfio: type1: fix kthread use case Markus Elfring
     [not found] ` <20200706124241.4392-1-hdanton@sina.com>
2020-07-06 13:33   ` Markus Elfring
2020-07-06 14:04   ` Markus Elfring
     [not found]   ` <20200707011420.1416-1-hdanton@sina.com>
2020-07-07  6:04     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).