linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] KVM: use list_for_each_entry_safe
@ 2016-01-01 11:47 Geliang Tang
  2016-01-01 11:47 ` [PATCH 2/4] KVM: x86: use list_for_each_entry* Geliang Tang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Geliang Tang @ 2016-01-01 11:47 UTC (permalink / raw)
  To: Gleb Natapov, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin
  Cc: Geliang Tang, x86, kvm, linux-kernel

Use list_for_each_entry_safe() instead of list_for_each_safe() to
simplify the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 virt/kvm/kvm_main.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 484079e..5b6df4f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -630,13 +630,10 @@ void *kvm_kvzalloc(unsigned long size)
 
 static void kvm_destroy_devices(struct kvm *kvm)
 {
-	struct list_head *node, *tmp;
+	struct kvm_device *dev, *tmp;
 
-	list_for_each_safe(node, tmp, &kvm->devices) {
-		struct kvm_device *dev =
-			list_entry(node, struct kvm_device, vm_node);
-
-		list_del(node);
+	list_for_each_entry_safe(dev, tmp, &kvm->devices, vm_node) {
+		list_del(&dev->vm_node);
 		dev->ops->destroy(dev);
 	}
 }
-- 
2.5.0



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

* [PATCH 2/4] KVM: x86: use list_for_each_entry*
  2016-01-01 11:47 [PATCH 1/4] KVM: use list_for_each_entry_safe Geliang Tang
@ 2016-01-01 11:47 ` Geliang Tang
  2016-01-01 11:47 ` [PATCH 3/4] KVM: x86: use list_last_entry Geliang Tang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2016-01-01 11:47 UTC (permalink / raw)
  To: Gleb Natapov, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin
  Cc: Geliang Tang, x86, kvm, linux-kernel

Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 arch/x86/kvm/assigned-dev.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/assigned-dev.c b/arch/x86/kvm/assigned-dev.c
index 9dc091a..308b859 100644
--- a/arch/x86/kvm/assigned-dev.c
+++ b/arch/x86/kvm/assigned-dev.c
@@ -51,11 +51,9 @@ struct kvm_assigned_dev_kernel {
 static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head,
 						      int assigned_dev_id)
 {
-	struct list_head *ptr;
 	struct kvm_assigned_dev_kernel *match;
 
-	list_for_each(ptr, head) {
-		match = list_entry(ptr, struct kvm_assigned_dev_kernel, list);
+	list_for_each_entry(match, head, list) {
 		if (match->assigned_dev_id == assigned_dev_id)
 			return match;
 	}
@@ -373,14 +371,10 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 
 void kvm_free_all_assigned_devices(struct kvm *kvm)
 {
-	struct list_head *ptr, *ptr2;
-	struct kvm_assigned_dev_kernel *assigned_dev;
-
-	list_for_each_safe(ptr, ptr2, &kvm->arch.assigned_dev_head) {
-		assigned_dev = list_entry(ptr,
-					  struct kvm_assigned_dev_kernel,
-					  list);
+	struct kvm_assigned_dev_kernel *assigned_dev, *tmp;
 
+	list_for_each_entry_safe(assigned_dev, tmp,
+				 &kvm->arch.assigned_dev_head, list) {
 		kvm_free_assigned_device(kvm, assigned_dev);
 	}
 }
-- 
2.5.0



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

* [PATCH 3/4] KVM: x86: use list_last_entry
  2016-01-01 11:47 [PATCH 1/4] KVM: use list_for_each_entry_safe Geliang Tang
  2016-01-01 11:47 ` [PATCH 2/4] KVM: x86: use list_for_each_entry* Geliang Tang
@ 2016-01-01 11:47 ` Geliang Tang
  2016-01-01 11:47 ` [PATCH 4/4] KVM: async_pf: use list_first_entry Geliang Tang
  2016-01-07 10:07 ` [PATCH 1/4] KVM: use list_for_each_entry_safe Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2016-01-01 11:47 UTC (permalink / raw)
  To: Gleb Natapov, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin
  Cc: Geliang Tang, x86, kvm, linux-kernel

To make the intention clearer, use list_last_entry instead of
list_entry.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 arch/x86/kvm/mmu.c | 4 ++--
 arch/x86/kvm/vmx.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index e7c2c14..5041ef0 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2380,8 +2380,8 @@ static bool prepare_zap_oldest_mmu_page(struct kvm *kvm,
 	if (list_empty(&kvm->arch.active_mmu_pages))
 		return false;
 
-	sp = list_entry(kvm->arch.active_mmu_pages.prev,
-			struct kvm_mmu_page, link);
+	sp = list_last_entry(&kvm->arch.active_mmu_pages,
+			     struct kvm_mmu_page, link);
 	kvm_mmu_prepare_zap_page(kvm, sp, invalid_list);
 
 	return true;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 44976a5..c43856f 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6377,8 +6377,8 @@ static struct loaded_vmcs *nested_get_current_vmcs02(struct vcpu_vmx *vmx)
 
 	if (vmx->nested.vmcs02_num >= max(VMCS02_POOL_SIZE, 1)) {
 		/* Recycle the least recently used VMCS. */
-		item = list_entry(vmx->nested.vmcs02_pool.prev,
-			struct vmcs02_list, list);
+		item = list_last_entry(&vmx->nested.vmcs02_pool,
+				       struct vmcs02_list, list);
 		item->vmptr = vmx->nested.current_vmptr;
 		list_move(&item->list, &vmx->nested.vmcs02_pool);
 		return &item->vmcs02;
-- 
2.5.0



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

* [PATCH 4/4] KVM: async_pf: use list_first_entry
  2016-01-01 11:47 [PATCH 1/4] KVM: use list_for_each_entry_safe Geliang Tang
  2016-01-01 11:47 ` [PATCH 2/4] KVM: x86: use list_for_each_entry* Geliang Tang
  2016-01-01 11:47 ` [PATCH 3/4] KVM: x86: use list_last_entry Geliang Tang
@ 2016-01-01 11:47 ` Geliang Tang
  2016-01-07 10:07 ` [PATCH 1/4] KVM: use list_for_each_entry_safe Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2016-01-01 11:47 UTC (permalink / raw)
  To: Gleb Natapov, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin
  Cc: Geliang Tang, x86, kvm, linux-kernel

To make the intention clearer, use list_first_entry instead of
list_entry.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 virt/kvm/async_pf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
index 77d42be..62c4857 100644
--- a/virt/kvm/async_pf.c
+++ b/virt/kvm/async_pf.c
@@ -110,8 +110,8 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu)
 	/* cancel outstanding work queue item */
 	while (!list_empty(&vcpu->async_pf.queue)) {
 		struct kvm_async_pf *work =
-			list_entry(vcpu->async_pf.queue.next,
-				   typeof(*work), queue);
+			list_first_entry(&vcpu->async_pf.queue,
+					 typeof(*work), queue);
 		list_del(&work->queue);
 
 #ifdef CONFIG_KVM_ASYNC_PF_SYNC
@@ -128,8 +128,8 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu)
 	spin_lock(&vcpu->async_pf.lock);
 	while (!list_empty(&vcpu->async_pf.done)) {
 		struct kvm_async_pf *work =
-			list_entry(vcpu->async_pf.done.next,
-				   typeof(*work), link);
+			list_first_entry(&vcpu->async_pf.done,
+					 typeof(*work), link);
 		list_del(&work->link);
 		kmem_cache_free(async_pf_cache, work);
 	}
-- 
2.5.0



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

* Re: [PATCH 1/4] KVM: use list_for_each_entry_safe
  2016-01-01 11:47 [PATCH 1/4] KVM: use list_for_each_entry_safe Geliang Tang
                   ` (2 preceding siblings ...)
  2016-01-01 11:47 ` [PATCH 4/4] KVM: async_pf: use list_first_entry Geliang Tang
@ 2016-01-07 10:07 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2016-01-07 10:07 UTC (permalink / raw)
  To: Geliang Tang, Gleb Natapov, Thomas Gleixner, Ingo Molnar, H. Peter Anvin
  Cc: x86, kvm, linux-kernel



On 01/01/2016 12:47, Geliang Tang wrote:
> Use list_for_each_entry_safe() instead of list_for_each_safe() to
> simplify the code.
> 
> Signed-off-by: Geliang Tang <geliangtang@163.com>
> ---
>  virt/kvm/kvm_main.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 484079e..5b6df4f 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -630,13 +630,10 @@ void *kvm_kvzalloc(unsigned long size)
>  
>  static void kvm_destroy_devices(struct kvm *kvm)
>  {
> -	struct list_head *node, *tmp;
> +	struct kvm_device *dev, *tmp;
>  
> -	list_for_each_safe(node, tmp, &kvm->devices) {
> -		struct kvm_device *dev =
> -			list_entry(node, struct kvm_device, vm_node);
> -
> -		list_del(node);
> +	list_for_each_entry_safe(dev, tmp, &kvm->devices, vm_node) {
> +		list_del(&dev->vm_node);
>  		dev->ops->destroy(dev);
>  	}
>  }
> 

These patches will be considered for 4.6.  Thanks!

Paolo

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

end of thread, other threads:[~2016-01-07 10:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-01 11:47 [PATCH 1/4] KVM: use list_for_each_entry_safe Geliang Tang
2016-01-01 11:47 ` [PATCH 2/4] KVM: x86: use list_for_each_entry* Geliang Tang
2016-01-01 11:47 ` [PATCH 3/4] KVM: x86: use list_last_entry Geliang Tang
2016-01-01 11:47 ` [PATCH 4/4] KVM: async_pf: use list_first_entry Geliang Tang
2016-01-07 10:07 ` [PATCH 1/4] KVM: use list_for_each_entry_safe Paolo Bonzini

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).