From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90F5315886D; Wed, 15 Jan 2025 16:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736959891; cv=none; b=G73LRNdHio9w85AgYJdr8+paFHCB9VghFxmwKhDaK1X3+vtEbNwDj0UoFhsfEv0PmcRJ/rq07wfSDVbBGieBm1YDipVVa7pjDQSoxvY8yDLPXLq+Shb56++4/UAVJN55PRLTDkNCLTvPKXAyZxSD5hJ76AF7r2+/JUbTMq71IzA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736959891; c=relaxed/simple; bh=XMPQKBQIrMsLOkkhKRMdJJP0GfR9abGvFF+fnKukqz0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZG4HQNToYSA30pM+CyYU2KJPhOtbOCFIwAK1ANai/ZrTB3pkar+2kcQW/JRvebaBaANv/KU4GH2ynNPGli4ME7jFfaq9fqRxqT56JKjSoqWwyQYycmfJEBZfcvIzdSnRKm7jndWznndNsV9ptEpSw+bm/85Ol4xXj7SgWPlq/dA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pwNmXlBF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pwNmXlBF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 777F9C4CED1; Wed, 15 Jan 2025 16:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736959891; bh=XMPQKBQIrMsLOkkhKRMdJJP0GfR9abGvFF+fnKukqz0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pwNmXlBFD+nXyAYIkktuAyEBUeQh5x0NwidEb+wkiUgV04OBBcLvqqogzZdCCDkHA /40M2kz5yIagvaP/iIjLLxuTXRd67529CR44TytjJijItZUl1KWwPldTAf7x/KuUIv h05NRcOqM1szDZ2ROoSt/TZH8BRGf2ueKnvqQQwal8UNFbUo2kADK3CALJ9j+/4mMH OeB/EDXfwn9xn4MekzPtBoduP7dC3CFNmMlYX16HrroxWBEMr0SeCbSzKW1bizpnyA VrDi96XqbbrKZq6s0bVkdbUMT8GqS4tcBiZgLQNNSSwxF8maZgsz1ibbaZ+5eEOOhu LbYWLfPJSLkjg== Date: Wed, 15 Jan 2025 09:51:28 -0700 From: Keith Busch To: Sean Christopherson Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, michael.christie@oracle.com, Tejun Heo , Luca Boccassi Subject: Re: [PATCH] KVM: x86: switch hugepage recovery thread to vhost_task Message-ID: References: <20241108130737.126567-1-pbonzini@redhat.com> <0862979d-cb85-44a8-904b-7318a5be0460@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jan 14, 2025 at 07:06:20PM -0800, Sean Christopherson wrote: > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > > index 2401606db2604..422b6b06de4fe 100644 > > > --- a/arch/x86/kvm/mmu/mmu.c > > > +++ b/arch/x86/kvm/mmu/mmu.c > > > @@ -7415,6 +7415,8 @@ int kvm_mmu_post_init_vm(struct kvm *kvm) > > > { > > > if (nx_hugepage_mitigation_hard_disabled) > > > return 0; > > > + if (kvm->arch.nx_huge_page_recovery_thread) > > > + return 0; > > ... > > > > kvm->arch.nx_huge_page_last = get_jiffies_64(); > > > kvm->arch.nx_huge_page_recovery_thread = vhost_task_create( > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > > index c79a8cc57ba42..263363c46626b 100644 > > > --- a/arch/x86/kvm/x86.c > > > +++ b/arch/x86/kvm/x86.c > > > @@ -11463,6 +11463,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > > > struct kvm_run *kvm_run = vcpu->run; > > > int r; > > > + r = kvm_mmu_post_init_vm(vcpu->kvm); > > > + if (r) > > > + return r; > > The only lock held at this point is vcpu->mutex, the obvious choices for guarding > the per-VM task creation are kvm->lock or kvm->mmu_lock, but we definitely don't > want to blindly take either lock in KVM_RUN. Thanks for the feedback. Would this otherwise be okay if I use a different mechanism to ensure the vhost task creation happens only once per kvm instance? Or are you suggesting the task creation needs to be somewhere other than KVM_RUN? My other initial concern was that this makes kvm_destroy_vm less symmetrical to kvm_create_vm, but that part looks okay: the vcpu that's being run holds a reference preventing kvm_destroy_vm from being called.