All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [patch 06/11] KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update
Date: Wed, 23 Dec 2009 14:32:55 +0200	[thread overview]
Message-ID: <4B320DF7.3070005@redhat.com> (raw)
In-Reply-To: <20091223114438.751996250@redhat.com>

On 12/23/2009 01:38 PM, Marcelo Tosatti wrote:
> Use two steps for memslot deletion: mark the slot invalid (which stops
> instantiation of new shadow pages for that slot, but allows destruction),
> then instantiate the new empty slot.
>
> Also simplifies kvm_handle_hva locking.
>
>
>   	r = kvm_arch_prepare_memory_region(kvm,&new, old, user_alloc);
>   	if (r)
>   		goto out_free;
>    

r == 0

>
> -	spin_lock(&kvm->mmu_lock);
> -	if (mem->slot>= kvm->memslots->nmemslots)
> -		kvm->memslots->nmemslots = mem->slot + 1;
> +#ifdef CONFIG_DMAR
> +	/* map the pages in iommu page table */
> +	if (npages)
> +		r = kvm_iommu_map_pages(kvm,&new);
> +		if (r)
> +			goto out_free;
>    

Bad indentation.

(still r == 0)

> +#endif
>
> -	*memslot = new;
> -	spin_unlock(&kvm->mmu_lock);
> +	slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
> +	if (!slots)
> +		goto out_free;
>    

goto out_free with r == 0.

Best to assign r = -ENOMEM each time, to avoid these headaches.

>
> +int memslot_id(struct kvm *kvm, gfn_t gfn)
>    

Should be either static or kvm_memslot_id().  But the source is already 
like that, so leave it.

> @@ -807,23 +808,18 @@ static int kvm_handle_hva(struct kvm *kv
>   			  int (*handler)(struct kvm *kvm, unsigned long *rmapp,
>   					 unsigned long data))
>   {
> -	int i, j;
> +	int i, j, idx;
>   	int retval = 0;
> -	struct kvm_memslots *slots = kvm->memslots;
> +	struct kvm_memslots *slots;
> +
> +	idx = srcu_read_lock(&kvm->srcu);
>    

Maybe a better place is in the mmu notifiers, so the code is shared 
(once other archs start to use mmu notifiers).


> @@ -3020,16 +3017,20 @@ nomem:
>    */
>   unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm)
>   {
> -	int i;
> +	int i, idx;
>   	unsigned int nr_mmu_pages;
>   	unsigned int  nr_pages = 0;
> +	struct kvm_memslots *slots;
>
> -	for (i = 0; i<  kvm->memslots->nmemslots; i++)
> -		nr_pages += kvm->memslots->memslots[i].npages;
> +	idx = srcu_read_lock(&kvm->srcu);
> +	slots = rcu_dereference(kvm->memslots);
> +	for (i = 0; i<  slots->nmemslots; i++)
> +		nr_pages += slots->memslots[i].npages;
>
>   	nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000;
>   	nr_mmu_pages = max(nr_mmu_pages,
>   			(unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
> +	srcu_read_unlock(&kvm->srcu, idx);
>
>    

Again, would like to move the srcu_locking to an outer scope.

> @@ -1503,10 +1504,18 @@ static void enter_pmode(struct kvm_vcpu
>   static gva_t rmode_tss_base(struct kvm *kvm)
>   {
>   	if (!kvm->arch.tss_addr) {
> -		gfn_t base_gfn = kvm->memslots->memslots[0].base_gfn +
> -				 kvm->memslots->memslots[0].npages - 3;
> +		struct kvm_memslots *slots;
> +		gfn_t base_gfn;
> +		int idx;
> +
> +		idx = srcu_read_lock(&kvm->srcu);
> +		slots = rcu_dereference(kvm->memslots);
> + 		base_gfn = slots->memslots[0].base_gfn +
> +				 slots->memslots[0].npages - 3;
> +		srcu_read_unlock(&kvm->srcu, idx);
>   		return base_gfn<<  PAGE_SHIFT;
>   	}
> +
>   	return kvm->arch.tss_addr;
>   }
>    

Shouldn't we already hold the srcu_lock as part of normal guest exit 
(similar to down_read() we do today)?

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2009-12-23 12:32 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-23 11:38 [patch 00/11] convert slotslock to SRCU Marcelo Tosatti
2009-12-23 11:38 ` [patch 01/11] KVM: modify memslots layout in struct kvm Marcelo Tosatti
2009-12-23 11:38 ` [patch 02/11] KVM: modify alias layout in x86s struct kvm_arch Marcelo Tosatti
2009-12-23 11:38 ` [patch 03/11] KVM: split kvm_arch_set_memory_region into prepare and commit Marcelo Tosatti
2009-12-23 11:38 ` [patch 04/11] KVM: introduce gfn_to_pfn_memslot Marcelo Tosatti
2009-12-23 12:09   ` Avi Kivity
2009-12-23 11:38 ` [patch 05/11] KVM: use gfn_to_pfn_memslot in kvm_iommu_map_pages Marcelo Tosatti
2009-12-23 11:38 ` [patch 06/11] KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update Marcelo Tosatti
2009-12-23 12:32   ` Avi Kivity [this message]
2009-12-23 14:19     ` Marcelo Tosatti
2009-12-23 14:33       ` Avi Kivity
2009-12-23 15:13         ` Marcelo Tosatti
2009-12-23 11:38 ` [patch 07/11] KVM: use SRCU for dirty log Marcelo Tosatti
2009-12-23 11:38 ` [patch 08/11] KVM: x86: switch kvm_set_memory_alias to SRCU update Marcelo Tosatti
2009-12-23 11:38 ` [patch 09/11] KVM: convert io_bus to SRCU Marcelo Tosatti
2009-12-23 11:38 ` [patch 10/11] KVM: switch vcpu context to use SRCU Marcelo Tosatti
2009-12-23 11:38 ` [patch 11/11] KVM: convert slots_lock to a mutex Marcelo Tosatti
2009-12-23 12:37 ` [patch 00/11] convert slotslock to SRCU Avi Kivity
2009-12-23 16:35 ` [patch 00/11] convert slotslock to SRCU v2 Marcelo Tosatti
2009-12-23 16:35   ` [patch 01/11] KVM: modify memslots layout in struct kvm Marcelo Tosatti
2009-12-23 16:35   ` [patch 02/11] KVM: modify alias layout in x86s struct kvm_arch Marcelo Tosatti
2009-12-23 16:35   ` [patch 03/11] KVM: split kvm_arch_set_memory_region into prepare and commit Marcelo Tosatti
2009-12-23 16:35   ` [patch 04/11] KVM: introduce gfn_to_pfn_memslot Marcelo Tosatti
2009-12-23 16:35   ` [patch 05/11] KVM: use gfn_to_pfn_memslot in kvm_iommu_map_pages Marcelo Tosatti
2009-12-23 16:35   ` [patch 06/11] KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update Marcelo Tosatti
2009-12-23 16:35   ` [patch 07/11] KVM: use SRCU for dirty log Marcelo Tosatti
2009-12-23 16:35   ` [patch 08/11] KVM: x86: switch kvm_set_memory_alias to SRCU update Marcelo Tosatti
2009-12-23 16:35   ` [patch 09/11] KVM: convert io_bus to SRCU Marcelo Tosatti
2009-12-23 16:35   ` [patch 10/11] KVM: switch vcpu context to use SRCU Marcelo Tosatti
2009-12-23 16:35   ` [patch 11/11] KVM: convert slots_lock to a mutex Marcelo Tosatti
2009-12-24  8:30   ` [patch 00/11] convert slotslock to SRCU v2 Avi Kivity
2009-12-24 14:56     ` Gleb Natapov
2009-12-25  7:24       ` Sheng Yang
2009-12-25 12:25         ` Marcelo Tosatti
2009-12-25 16:27           ` Avi Kivity
2009-12-25 18:22             ` Sheng Yang
2009-12-27 13:16 ` [patch 00/11] convert slotslock to SRCU Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B320DF7.3070005@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.