lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YJrTs6LlHFWSdGc7@google.com>
Date:   Tue, 11 May 2021 18:57:55 +0000
From:   Sean Christopherson <seanjc@...gle.com>
To:     Ben Gardon <bgardon@...gle.com>
Cc:     linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
        Paolo Bonzini <pbonzini@...hat.com>,
        Peter Xu <peterx@...hat.com>, Peter Shier <pshier@...gle.com>,
        Yulei Zhang <yulei.kernel@...il.com>,
        Wanpeng Li <kernellwp@...il.com>,
        Xiao Guangrong <xiaoguangrong.eric@...il.com>,
        Kai Huang <kai.huang@...el.com>,
        Keqian Zhu <zhukeqian1@...wei.com>,
        David Hildenbrand <david@...hat.com>
Subject: Re: [PATCH v4 7/7] KVM: x86/mmu: Lazily allocate memslot rmaps

On Tue, May 11, 2021, Ben Gardon wrote:
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> @@ -10935,6 +10937,46 @@ static int memslot_rmap_alloc(struct kvm_memory_slot *slot,
>  	return 0;
>  }
>  
> +int alloc_all_memslots_rmaps(struct kvm *kvm)
> +{
> +	struct kvm_memslots *slots;
> +	struct kvm_memory_slot *slot;
> +	int r = 0;

No need to initialize r.  And then it makes sense to put i and r on the same
line.

> +	int i;
> +
> +	/*
> +	 * Check memslots_have_rmaps early before acquiring the
> +	 * slots_arch_lock below.
> +	 */
> +	if (smp_load_acquire(&kvm->arch.memslots_have_rmaps))
> +		return 0;
> +
> +	mutex_lock(&kvm->slots_arch_lock);
> +
> +	/*
> +	 * Read memslots_have_rmaps again, under the slots arch lock,
> +	 * before allocating the rmaps
> +	 */
> +	if (smp_load_acquire(&kvm->arch.memslots_have_rmaps))
> +		return 0;

This fails to drop slots_arch_lock.

> +
> +	for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
> +		slots = __kvm_memslots(kvm, i);
> +		kvm_for_each_memslot(slot, slots) {
> +			r = memslot_rmap_alloc(slot, slot->npages);
> +			if (r) {
> +				mutex_unlock(&kvm->slots_arch_lock);
> +				return r;
> +			}
> +		}
> +	}
> +
> +	/* Write rmap pointers before memslots_have_rmaps */
> +	smp_store_release(&kvm->arch.memslots_have_rmaps, true);
> +	mutex_unlock(&kvm->slots_arch_lock);
> +	return 0;
> +}
> +
>  static int kvm_alloc_memslot_metadata(struct kvm *kvm,
>  				      struct kvm_memory_slot *slot,
>  				      unsigned long npages)
> @@ -10949,7 +10991,8 @@ static int kvm_alloc_memslot_metadata(struct kvm *kvm,
>  	 */
>  	memset(&slot->arch, 0, sizeof(slot->arch));
>  
> -	if (kvm->arch.memslots_have_rmaps) {
> +	/* Read memslots_have_rmaps before allocating the rmaps */
> +	if (smp_load_acquire(&kvm->arch.memslots_have_rmaps)) {
>  		r = memslot_rmap_alloc(slot, npages);
>  		if (r)
>  			return r;
> -- 
> 2.31.1.607.g51e8a6a459-goog
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ