Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1193732pxb; Fri, 21 Jan 2022 11:58:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdj/hHmE6zYqCPuuPm6lPqs3XNV8WI99hX0L0GGKjkUEgis0/xSn5G56ucuWSEYIzOXy5Z X-Received: by 2002:a17:90a:7c0b:: with SMTP id v11mr2264009pjf.180.1642795098963; Fri, 21 Jan 2022 11:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642795098; cv=none; d=google.com; s=arc-20160816; b=Iii0DgoJG01Hrt/LgTgTh8rMa7OR3c8FFR9LGPVJS/zsInqaY+5BsurE15RuDfS7Qj ytLKWwpvBaMH1Qi0Mt5bP0ROUWu0QUCXr+EkVWwEQxnEgbea6FLp95rfczfqB0MZGLbG VK0jH1pmMcdql5gco0O/hL5Pq+GKBu2jNC4uRsP+bzmLjC2qTNEgmFMKxYRdCSbGznkn P523IBuN0iMZkamh4mC7JSxucdnGuaKk8zZPnrVbG1todnqZ9lQAIwpY401D6IlKl12Z bRXuhPEMN9SH+t78+WeIng6DHvX/wap7tuyASzmeNmHSoP3m4fX7OTmvppq2EJ8Lae8p kmMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Wj3R0FRfn1yO5ogKeGc8aripFNfSyJxmajRu2on35kY=; b=Qq2iaxKQfkYxHgSghAcT++Iwbvwfr2g5liGAWMzQ4FcFx+r2gBkEeZNcUZ8Padhbia SzDxQvsT610W36HNAzLdWxDeuganmtyr//fUkaHyrwJbDDKcc1DU7eOjS7kFiG+znm+B AOQtEuglUZFSuG/ACP2Y5foBWx95Mext55CmWhQmql+ucHy40VKA14GTkGrddwTCZyWh PahXy2p1zXXuXCBej4ngCCG6Nr10QgnX01vIt7gm7FjwBERBEkckMT4g7RLzgyfBSyWW deZEwlnBwQmmTgo86k9BC56F3q3ntP5ATX20TGLcysmg3hqfUQYBj+oRkZlvdeh01obT /7Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=pe1iWhZi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b4si6593206plr.18.2022.01.21.11.58.06; Fri, 21 Jan 2022 11:58:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=pe1iWhZi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356918AbiASSuw (ORCPT + 99 others); Wed, 19 Jan 2022 13:50:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350117AbiASSui (ORCPT ); Wed, 19 Jan 2022 13:50:38 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52683C06173E for ; Wed, 19 Jan 2022 10:50:35 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id d3so11822332lfv.13 for ; Wed, 19 Jan 2022 10:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Wj3R0FRfn1yO5ogKeGc8aripFNfSyJxmajRu2on35kY=; b=pe1iWhZirUTGmhYFeMyFbD34nGrpS52XKubMcy7XhUsPHYDaweveoSSJ0xnTHhRHWK 20m5NC6R9tJIDsHjIbD1VFPqYLDmsG/N0Szv1UrZm9xhVPlG9AJJli7CV6iYMrgR6Rwu NhOEIJxv0osNjyejn4S6X35hD31YubMuEqCY2s7DYdDUc6uTefMSQbbc/Se0C5xs8nmB ccI4yd5EFGZv+k4tvN8+95FjVBq0L8Uub4f5y/1nX/vM3XeUsEW7Audld9eBL5dk72Yu AAkeVbwfhIrCNp+6Q4qlOOkWhGRMnA9Tb8TOCRMyLgl9GUZrTl+LJ2hRvgWNXwivZO25 2x+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Wj3R0FRfn1yO5ogKeGc8aripFNfSyJxmajRu2on35kY=; b=bkY290Qw495oPSbnGW71OIURJdX3x1Ds0f51b8MYhhkXBrI8w9M1KnqYuSOTloUmcD MhTQKiJ52awLupVbLCJKA4zv86FvE0lvLoAsFeHzd8KPgub1OxvhjZ/U7SQa53aG81VC 2r4N7ejeWMyPj8ykII6uhQB9gFckSQA9kFqULEcQG4XL4Kc8czKytQCokRf+HU3G/wHP eYljMNoAaKPaYUIqDqDRI9fhvb0ns1642EfXhzE/YfQC5Xq0p/w9ZIjLecmMgZ7UGDiB e8Hy2cAEVL6SToSvc+7AVb6/zDFpPURYlS6xkSzJkzmA/CUKo1Tm0UKmzQGB36HOffEr eKag== X-Gm-Message-State: AOAM531pD/VFIsfwqeSegm8fSn3s3/cZsSoSflIAPi8aKq5jkuoAqZvb t3Ds4aQ6CQwTHRViTXnmQwU5g8WhbOorE1vXRKvD9w== X-Received: by 2002:a05:6512:3b94:: with SMTP id g20mr28870780lfv.119.1642618233416; Wed, 19 Jan 2022 10:50:33 -0800 (PST) MIME-Version: 1.0 References: <20211222225350.1912249-1-vipinsh@google.com> <20220105180420.GC6464@blackbody.suse.cz> <7a0bc562-9f25-392d-5c05-9dbcd350d002@redhat.com> In-Reply-To: From: Vipin Sharma Date: Wed, 19 Jan 2022 10:49:57 -0800 Message-ID: Subject: Re: [PATCH v2] KVM: Move VM's worker kthreads back to the original cgroups before exiting. To: Tejun Heo Cc: Paolo Bonzini , =?UTF-8?Q?Michal_Koutn=C3=BD?= , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 19, 2022 at 10:30 AM Tejun Heo wrote: > > On Wed, Jan 19, 2022 at 07:02:53PM +0100, Paolo Bonzini wrote: > > 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: > > Okay, this is because kthread_stop piggy backs on vfork_done to wait for the > task exit intead of the usual exit notification, so it only waits till > exit_mm(), which is uhh... weird. So, migrating is one option, I guess, > albeit a rather ugly one. It'd be nicer if we can make kthread_stop() > waiting more regular but I couldn't find a good existing place and routing > the usual parent signaling might be too complicated. Anyone has better > ideas? > Sean suggested that we can use the real_parent of the kthread task which will always be kthreadd_task, this will also not require any changes in the cgroup API. I like that approach, I will give it a try. This will avoid changes in cgroup APIs completely.