Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1564494 > unrolled thread

[PATCH 0/9] KVM: Fine-tuning for several function implementations

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2017-01-22 19:20 +0100
Last post2017-01-24 12:40 +0100
Articles 10 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/9] KVM: Fine-tuning for several function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-22 19:20 +0100
    [PATCH 1/9] KVM: Return directly after a failed copy_from_user() in  kvm_vm_compat_ioctl() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-22 19:20 +0100
    [PATCH 5/9] KVM: Improve size determinations in kvm_vcpu_ioctl() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-22 19:20 +0100
    [PATCH 3/9] KVM: Move error code settings in kvm_vcpu_compat_ioctl() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-22 19:20 +0100
    [PATCH 6/9] KVM: Return an error code only as a constant in  kvm_get_dirty_log_protect() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-22 19:20 +0100
    Re: [PATCH 0/9] KVM: Fine-tuning for several function implementations Paolo Bonzini <pbonzini@redhat.com> - 2017-01-23 10:30 +0100
      Re: KVM: Fine-tuning for several function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-23 10:50 +0100
        Re: KVM: Fine-tuning for several function implementations Paolo Bonzini <pbonzini@redhat.com> - 2017-01-23 15:10 +0100
        Re: KVM: Fine-tuning for several function implementations Bernd Petrovitsch <bernd@petrovitsch.priv.at> - 2017-01-24 03:40 +0100
          Re: KVM: Fine-tuning for several function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-24 12:40 +0100

#1564494 — [PATCH 0/9] KVM: Fine-tuning for several function implementations

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-22 19:20 +0100
Subject[PATCH 0/9] KVM: Fine-tuning for several function implementations
Message-ID<t2uUa-46y-13@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Jan 2017 19:06:54 +0100

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (9):
  Return directly after a failed copy_from_user() in kvm_vm_compat_ioctl()
  Move error code settings in kvm_vm_ioctl()
  Move error code settings in kvm_vcpu_compat_ioctl()
  Move error code settings in kvm_vcpu_ioctl()
  Improve size determinations in kvm_vcpu_ioctl()
  Return an error code only as a constant in kvm_get_dirty_log_protect()
  Return an error code only as a constant in kvm_get_dirty_log()
  Adjust seven checks for null pointers
  Improve another size determination in kvm_create_vm()

 virt/kvm/kvm_main.c | 278 +++++++++++++++++++++++-----------------------------
 1 file changed, 120 insertions(+), 158 deletions(-)

-- 
2.11.0

[toc] | [next] | [standalone]


#1564495 — [PATCH 1/9] KVM: Return directly after a failed copy_from_user() in kvm_vm_compat_ioctl()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-22 19:20 +0100
Subject[PATCH 1/9] KVM: Return directly after a failed copy_from_user() in kvm_vm_compat_ioctl()
Message-ID<t2uUa-46y-21@gated-at.bofh.it>
In reply to#1564494
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Jan 2017 11:30:21 +0100

* Return directly after a call of the function "copy_from_user" failed
  in a case block.

  This issue was detected by using the Coccinelle software.

* Delete the jump label "out" which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 virt/kvm/kvm_main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index de102cae7125..eeb340708d97 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3133,10 +3133,9 @@ static long kvm_vm_compat_ioctl(struct file *filp,
 		struct compat_kvm_dirty_log compat_log;
 		struct kvm_dirty_log log;
 
-		r = -EFAULT;
 		if (copy_from_user(&compat_log, (void __user *)arg,
 				   sizeof(compat_log)))
-			goto out;
+			return -EFAULT;
 		log.slot	 = compat_log.slot;
 		log.padding1	 = compat_log.padding1;
 		log.padding2	 = compat_log.padding2;
@@ -3148,8 +3147,6 @@ static long kvm_vm_compat_ioctl(struct file *filp,
 	default:
 		r = kvm_vm_ioctl(filp, ioctl, arg);
 	}
-
-out:
 	return r;
 }
 #endif
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1564497 — [PATCH 5/9] KVM: Improve size determinations in kvm_vcpu_ioctl()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-22 19:20 +0100
Subject[PATCH 5/9] KVM: Improve size determinations in kvm_vcpu_ioctl()
Message-ID<t2uUb-46y-35@gated-at.bofh.it>
In reply to#1564494
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Jan 2017 17:11:16 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 virt/kvm/kvm_main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9d463b7a3912..6a74a3796b3f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2569,7 +2569,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 	case KVM_GET_REGS: {
 		struct kvm_regs *kvm_regs;
 
-		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+		kvm_regs = kzalloc(sizeof(*kvm_regs), GFP_KERNEL);
 		if (!kvm_regs) {
 			r = -ENOMEM;
 			goto put_vcpu;
@@ -2577,7 +2577,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
 		if (r)
 			goto free_regs;
-		if (copy_to_user(argp, kvm_regs, sizeof(struct kvm_regs)))
+		if (copy_to_user(argp, kvm_regs, sizeof(*kvm_regs)))
 			r = -EFAULT;
 free_regs:
 		kfree(kvm_regs);
@@ -2598,7 +2598,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 	case KVM_GET_SREGS: {
 		struct kvm_sregs *kvm_sregs;
 
-		kvm_sregs = kzalloc(sizeof(struct kvm_sregs), GFP_KERNEL);
+		kvm_sregs = kzalloc(sizeof(*kvm_sregs), GFP_KERNEL);
 		if (!kvm_sregs) {
 			r = -ENOMEM;
 			goto put_vcpu;
@@ -2606,7 +2606,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, kvm_sregs);
 		if (r)
 			goto free_sregs;
-		if (copy_to_user(argp, kvm_sregs, sizeof(struct kvm_sregs)))
+		if (copy_to_user(argp, kvm_sregs, sizeof(*kvm_sregs)))
 			r = -EFAULT;
 free_sregs:
 		kfree(kvm_sregs);
@@ -2697,7 +2697,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 	case KVM_GET_FPU: {
 		struct kvm_fpu *fpu;
 
-		fpu = kzalloc(sizeof(struct kvm_fpu), GFP_KERNEL);
+		fpu = kzalloc(sizeof(*fpu), GFP_KERNEL);
 		if (!fpu) {
 			r = -ENOMEM;
 			goto put_vcpu;
@@ -2705,7 +2705,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, fpu);
 		if (r)
 			goto free_fpu;
-		if (copy_to_user(argp, fpu, sizeof(struct kvm_fpu)))
+		if (copy_to_user(argp, fpu, sizeof(*fpu)))
 			r = -EFAULT;
 free_fpu:
 		kfree(fpu);
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1564500 — [PATCH 3/9] KVM: Move error code settings in kvm_vcpu_compat_ioctl()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-22 19:20 +0100
Subject[PATCH 3/9] KVM: Move error code settings in kvm_vcpu_compat_ioctl()
Message-ID<t2uUb-46y-41@gated-at.bofh.it>
In reply to#1564494
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Jan 2017 13:57:40 +0100

* A local variable was set to an error code before a concrete error
  situation was detected. Thus move the corresponding settings
  into if branches to indicate a software failure there.

  This issue was detected by using the Coccinelle software.

* Return directly after a call of the function "copy_from_user"
  (or an other check) failed in a case block.

* Delete the jump label "out" which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 virt/kvm/kvm_main.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2773e5012948..62f24d8eaaa2 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2743,17 +2743,14 @@ static long kvm_vcpu_compat_ioctl(struct file *filp,
 		sigset_t sigset;
 
 		if (argp) {
-			r = -EFAULT;
 			if (copy_from_user(&kvm_sigmask, argp,
 					   sizeof(kvm_sigmask)))
-				goto out;
-			r = -EINVAL;
+				return -EFAULT;
 			if (kvm_sigmask.len != sizeof(csigset))
-				goto out;
-			r = -EFAULT;
+				return -EINVAL;
 			if (copy_from_user(&csigset, sigmask_arg->sigset,
 					   sizeof(csigset)))
-				goto out;
+				return -EFAULT;
 			sigset_from_compat(&sigset, &csigset);
 			r = kvm_vcpu_ioctl_set_sigmask(vcpu, &sigset);
 		} else
@@ -2763,8 +2760,6 @@ static long kvm_vcpu_compat_ioctl(struct file *filp,
 	default:
 		r = kvm_vcpu_ioctl(filp, ioctl, arg);
 	}
-
-out:
 	return r;
 }
 #endif
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1564505 — [PATCH 6/9] KVM: Return an error code only as a constant in kvm_get_dirty_log_protect()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-22 19:20 +0100
Subject[PATCH 6/9] KVM: Return an error code only as a constant in kvm_get_dirty_log_protect()
Message-ID<t2uUb-46y-51@gated-at.bofh.it>
In reply to#1564494
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Jan 2017 17:30:16 +0100

* Return an error code without storing it in an intermediate variable.

* Delete the local variable "r" and the jump label "out" which became
  unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 virt/kvm/kvm_main.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 6a74a3796b3f..a651a137ef21 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1156,24 +1156,22 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
 {
 	struct kvm_memslots *slots;
 	struct kvm_memory_slot *memslot;
-	int r, i, as_id, id;
+	int i, as_id, id;
 	unsigned long n;
 	unsigned long *dirty_bitmap;
 	unsigned long *dirty_bitmap_buffer;
 
-	r = -EINVAL;
 	as_id = log->slot >> 16;
 	id = (u16)log->slot;
 	if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_USER_MEM_SLOTS)
-		goto out;
+		return -EINVAL;
 
 	slots = __kvm_memslots(kvm, as_id);
 	memslot = id_to_memslot(slots, id);
 
 	dirty_bitmap = memslot->dirty_bitmap;
-	r = -ENOENT;
 	if (!dirty_bitmap)
-		goto out;
+		return -ENOENT;
 
 	n = kvm_dirty_bitmap_bytes(memslot);
 
@@ -1202,14 +1200,9 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
 	}
 
 	spin_unlock(&kvm->mmu_lock);
-
-	r = -EFAULT;
 	if (copy_to_user(log->dirty_bitmap, dirty_bitmap_buffer, n))
-		goto out;
-
-	r = 0;
-out:
-	return r;
+		return -EFAULT;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(kvm_get_dirty_log_protect);
 #endif
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1564812

FromPaolo Bonzini <pbonzini@redhat.com>
Date2017-01-23 10:30 +0100
Message-ID<t2J6O-4DB-7@gated-at.bofh.it>
In reply to#1564494

On 22/01/2017 19:09, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 22 Jan 2017 19:06:54 +0100
> 
> Several update suggestions were taken into account
> from static source code analysis.

Patches 1, 6 and 7 are acceptable.  The others are useless churn or they
make the result uselessly different from the rest of KVM code.

Paolo

> Markus Elfring (9):
>   Return directly after a failed copy_from_user() in kvm_vm_compat_ioctl()
>   Move error code settings in kvm_vm_ioctl()
>   Move error code settings in kvm_vcpu_compat_ioctl()
>   Move error code settings in kvm_vcpu_ioctl()
>   Improve size determinations in kvm_vcpu_ioctl()
>   Return an error code only as a constant in kvm_get_dirty_log_protect()
>   Return an error code only as a constant in kvm_get_dirty_log()
>   Adjust seven checks for null pointers
>   Improve another size determination in kvm_create_vm()
> 
>  virt/kvm/kvm_main.c | 278 +++++++++++++++++++++++-----------------------------
>  1 file changed, 120 insertions(+), 158 deletions(-)
> 

[toc] | [prev] | [next] | [standalone]


#1564822 — Re: KVM: Fine-tuning for several function implementations

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-23 10:50 +0100
SubjectRe: KVM: Fine-tuning for several function implementations
Message-ID<t2Jq9-4Km-7@gated-at.bofh.it>
In reply to#1564812
> Patches 1, 6 and 7 are acceptable.

Thanks for a bit of positive feedback.


> The others are useless churn or they make the result uselessly different
> from the rest of KVM code.

I got an other view about potential benefits around the suggested movements
for error code settings.
Would others like to help in approaches for checking corresponding run time changes
a bit more?

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


#1564990 — Re: KVM: Fine-tuning for several function implementations

FromPaolo Bonzini <pbonzini@redhat.com>
Date2017-01-23 15:10 +0100
SubjectRe: KVM: Fine-tuning for several function implementations
Message-ID<t2NtM-7rk-19@gated-at.bofh.it>
In reply to#1564822

On 23/01/2017 10:48, SF Markus Elfring wrote:
>> The others are useless churn or they make the result uselessly different
>> from the rest of KVM code.
>
> I got an other view about potential benefits around the suggested movements
> for error code settings.

I'll consider them when your emails stop looking like the output a
Markov chain.

Paolo

> Would others like to help in approaches for checking corresponding run time changes
> a bit more?

[toc] | [prev] | [next] | [standalone]


#1565445 — Re: KVM: Fine-tuning for several function implementations

FromBernd Petrovitsch <bernd@petrovitsch.priv.at>
Date2017-01-24 03:40 +0100
SubjectRe: KVM: Fine-tuning for several function implementations
Message-ID<t2ZbB-6F4-45@gated-at.bofh.it>
In reply to#1564822
On Mon, 2017-01-23 at 10:48 +0100, SF Markus Elfring wrote:
[...]
> > The others are useless churn or they make the result uselessly
> > different from the rest of KVM code.
> 
> I got an other view about potential benefits around the suggested
> movements for error code settings.

Which is not explained here.

> Would others like to help in approaches for checking corresponding
> run time changes a bit more?

You propose the patch and others should do the work to get it accepted?

Kind regards,
	Bernd
-- 
Bernd Petrovitsch                  Email : bernd@petrovitsch.priv.at
                     LUGA : http://www.luga.at

[toc] | [prev] | [next] | [standalone]


#1565794 — Re: KVM: Fine-tuning for several function implementations

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-24 12:40 +0100
SubjectRe: KVM: Fine-tuning for several function implementations
Message-ID<t37C9-3I5-13@gated-at.bofh.it>
In reply to#1565445
>> Would others like to help in approaches for checking corresponding
>> run time changes a bit more?
> 
> You propose the patch

I suggested additional changes which can get an usual mixture of agreements
and rejections.


> and others should do the work to get it accepted?

Not directly. - I imagine that there are further collaboration possibilities,
aren't there?

Which benchmarks (and test metrics) would you trust for the desired software evolution?

Regards,
Markus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web