public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Tejun Heo <tj@kernel.org>, Vipin Sharma <vipinsh@google.com>
Cc: "Michal Koutný" <mkoutny@suse.com>,
	seanjc@google.com, lizefan.x@bytedance.com, hannes@cmpxchg.org,
	dmatlack@google.com, jiangshanlai@gmail.com, kvm@vger.kernel.org,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KVM: Move VM's worker kthreads back to the original cgroups before exiting.
Date: Wed, 19 Jan 2022 19:02:53 +0100	[thread overview]
Message-ID: <7a0bc562-9f25-392d-5c05-9dbcd350d002@redhat.com> (raw)
In-Reply-To: <Yeclbe3GNdCMLlHz@slm.duckdns.org>

On 1/18/22 21:39, Tejun Heo wrote:
> So, these are normally driven by the !populated events. That's how everyone
> else is doing it. If you want to tie the kvm workers lifetimes to kvm
> process, wouldn't it be cleaner to do so from kvm side? ie. let kvm process
> exit wait for the workers to be cleaned up.

It does.  For example kvm_mmu_post_init_vm's call to
kvm_vm_create_worker_thread is matched with the call to
kthread_stop in kvm_mmu_pre_destroy_vm.
  
According to Vpin, the problem is that there's a small amount of time
between the return from kthread_stop and the point where the cgroup
can be removed.  My understanding of the race is the following:

user process			kthread			management
------------			-------			----------
							wait4()
exit_task_work()
   ____fput()
     kvm_mmu_pre_destroy_vm()
       kthread_stop();
         wait_for_completion();
				exit_signals()
				  /* set PF_EXITING */
				exit_mm()
				  exit_mm_release()
				    complete_vfork_done()
				      complete();
cgroup_exit()
   cgroup_set_move_task()
     css_set_update_populated()
exit_notify()
   do_notify_parent()
							<wakeup>
							rmdir()
							  cgroup_destroy_locked()
							    cgroup_is_populated()
							    return -EBUSY
				cgroup_exit()
				  cgroup_set_move_task()
				    css_set_update_populated()

I cannot find the code that makes it possible to rmdir a cgroup
if PF_EXITING is set.

Paolo


  reply	other threads:[~2022-01-19 18:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22 22:53 [PATCH v2] KVM: Move VM's worker kthreads back to the original cgroups before exiting Vipin Sharma
2021-12-28 17:17 ` Sean Christopherson
2022-01-18 19:53   ` Vipin Sharma
2022-01-05 18:04 ` Michal Koutný
2022-01-18 20:25   ` Vipin Sharma
2022-01-18 20:39     ` Tejun Heo
2022-01-19 18:02       ` Paolo Bonzini [this message]
2022-01-19 18:30         ` Tejun Heo
2022-01-19 18:49           ` Vipin Sharma
2022-01-19 19:05             ` Tejun Heo
2022-01-20 15:05           ` Michal Koutný
2022-02-16 17:37             ` Vipin Sharma
2022-02-16 19:48               ` Paolo Bonzini
2022-02-25 17:37               ` Michal Koutný

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=7a0bc562-9f25-392d-5c05-9dbcd350d002@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dmatlack@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=jiangshanlai@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=mkoutny@suse.com \
    --cc=seanjc@google.com \
    --cc=tj@kernel.org \
    --cc=vipinsh@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox