From nobody Mon Feb 9 10:50:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618817107; cv=none; d=zohomail.com; s=zohoarc; b=KC4hLykLlxThSVzdOxQS0d9reWhtHAGKIeulZqwzwrBhzhlrOff/Zd0apSLaZQAWy+JycuWyBLKno3Ww6X7kc6QibB4i15iX5TC3+/kae+kpIrs21x4gjotqmLWmDZh7o8OSh4mjate/4JyG3nEnurh1ODRUaYM2+GDKvdn7lA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618817107; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TpuyqK5B61bOW/x1ZCDbWviePL7Io7GQg+I0mLWgiac=; b=PMtN9eiuUE7j5fRELne29t1js4SUOCT6jHTUp8EAPyjukrbOr2/j2Hz3QOsIsdrlg4LaxiDA8g7p5cTPbPGuqlbVSCtKTuqokTDU6XHepSKMFf5zgiewQQB3VOA2bWwQJS/m6ixBa8nmkBuBp8KHBCwHC8DRPzs1YGigQfejzx8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618817107188711.1926016702731; Mon, 19 Apr 2021 00:25:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-343-HGJBj3TmMKOcQgPREizf_Q-1; Mon, 19 Apr 2021 03:24:25 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 86432874998; Mon, 19 Apr 2021 07:24:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D6701F055; Mon, 19 Apr 2021 07:24:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 266991806D1C; Mon, 19 Apr 2021 07:24:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13J7KRiV016929 for ; Mon, 19 Apr 2021 03:20:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2F73E5D9F0; Mon, 19 Apr 2021 07:20:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F1A65D9CD for ; Mon, 19 Apr 2021 07:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618817106; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TpuyqK5B61bOW/x1ZCDbWviePL7Io7GQg+I0mLWgiac=; b=LllwnTJw6Kce/0u4f2zUaEA8TreBWcwEDSpBqNVT1Noo4W5cRFdVVIwLn3JHPiuFTLNdx2 zR6IqwTewFneUvFkpVfU28B/rcOt2eZq0PHGyexTGPjPQRtgnpREk89xbLO7QkwN5/LuKU MyneZdju8LG9vld4ObDQzLjH7EMgc8U= X-MC-Unique: HGJBj3TmMKOcQgPREizf_Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] vircgroup: Fix virCgroupKillRecursive() wrt nested controllers Date: Mon, 19 Apr 2021 09:20:18 +0200 Message-Id: <5e54f0317551b6873fc914f50507d4c4704b5449.1618816726.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) I've encountered the following bug, but only on Gentoo with systemd and CGroupsV2. I've started an LXC container successfully but destroying it reported the following error: error: Failed to destroy domain 'amd64' error: internal error: failed to get cgroup backend for 'pathOfController' Debugging showed, that CGroup hierarchy is full of surprises: /sys/fs/cgroup/machine.slice/machine-lxc\x2d861\x2damd64.scope/ =E2=94=94=E2=94=80=E2=94=80 libvirt =E2=94=9C=E2=94=80=E2=94=80 dev-hugepages.mount =E2=94=9C=E2=94=80=E2=94=80 dev-mqueue.mount =E2=94=9C=E2=94=80=E2=94=80 init.scope =E2=94=9C=E2=94=80=E2=94=80 sys-fs-fuse-connections.mount =E2=94=9C=E2=94=80=E2=94=80 sys-kernel-config.mount =E2=94=9C=E2=94=80=E2=94=80 sys-kernel-debug.mount =E2=94=9C=E2=94=80=E2=94=80 sys-kernel-tracing.mount =E2=94=9C=E2=94=80=E2=94=80 system.slice =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 console-getty.service =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 dbus.service =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 system-getty.slice =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 system-modprobe.slice =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 systemd-journald.serv= ice =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 systemd-logind.service =E2=94=82=C2=A0=C2=A0 =E2=94=94=E2=94=80=E2=94=80 tmp.mount =E2=94=94=E2=94=80=E2=94=80 user.slice For comparison, here's the same container on recent Rawhide: /sys/fs/cgroup/machine.slice/machine-lxc\x2d13550\x2damd64.scope/ =E2=94=94=E2=94=80=E2=94=80 libvirt Anyway, those nested directories should not be a problem, because virCgroupKillRecursiveInternal() removes them recursively, right? Sort of. The function really does remove nested directories, but it assumes that every directory has the same controller as the rest. Just take a look at virCgroupV2KillRecursive() - it gets 'Any' controller (the first one it found in ".scope") and then passes it to virCgroupKillRecursiveInternal(). This assumption is not true though. The controllers found in ".scope" are the following: cpuset cpu io memory pids while "libvirt" has fewer: cpuset cpu io memory Up until now it's not problem, because of how we order controllers internally - "cpu" is the first and thus picking "Any" controller returns just that. But the rest of directories has no controllers, their "cgroup.controllers" is just empty. What fixes the bug is dropping @controller argument from virCgroupKillRecursiveInternal() and letting each iteration work pick its own controller. Signed-off-by: Michal Privoznik --- src/util/vircgroup.c | 25 +++++++++++++++++++++++-- src/util/vircgrouppriv.h | 1 - src/util/vircgroupv1.c | 7 +------ src/util/vircgroupv2.c | 7 +------ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 96280a0a4e..37dde2a5ed 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1477,6 +1477,24 @@ virCgroupHasController(virCgroup *cgroup, int contro= ller) } =20 =20 +static int +virCgroupGetAnyController(virCgroup *cgroup) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (!cgroup->backends[i]) + continue; + + return cgroup->backends[i]->getAnyController(cgroup); + } + + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to get any controller")); + return -1; +} + + int virCgroupPathOfController(virCgroup *group, unsigned int controller, @@ -2715,11 +2733,11 @@ int virCgroupKillRecursiveInternal(virCgroup *group, int signum, GHashTable *pids, - int controller, const char *taskFile, bool dormdir) { int rc; + int controller; bool killedAny =3D false; g_autofree char *keypath =3D NULL; g_autoptr(DIR) dp =3D NULL; @@ -2728,6 +2746,9 @@ virCgroupKillRecursiveInternal(virCgroup *group, VIR_DEBUG("group=3D%p signum=3D%d pids=3D%p taskFile=3D%s dormdir=3D%d= ", group, signum, pids, taskFile, dormdir); =20 + if ((controller =3D virCgroupGetAnyController(group)) < 0) + return -1; + if (virCgroupPathOfController(group, controller, "", &keypath) < 0) return -1; =20 @@ -2760,7 +2781,7 @@ virCgroupKillRecursiveInternal(virCgroup *group, return -1; =20 if ((rc =3D virCgroupKillRecursiveInternal(subgroup, signum, pids, - controller, taskFile, tru= e)) < 0) + taskFile, true)) < 0) return -1; if (rc =3D=3D 1) killedAny =3D true; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 00193fb101..caf7ed84db 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -135,6 +135,5 @@ int virCgroupRemoveRecursively(char *grppath); int virCgroupKillRecursiveInternal(virCgroup *group, int signum, GHashTable *pids, - int controller, const char *taskFile, bool dormdir); diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 2cc7dd386a..8a04bb2e4a 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -812,12 +812,7 @@ virCgroupV1KillRecursive(virCgroup *group, int signum, GHashTable *pids) { - int controller =3D virCgroupV1GetAnyController(group); - - if (controller < 0) - return -1; - - return virCgroupKillRecursiveInternal(group, signum, pids, controller, + return virCgroupKillRecursiveInternal(group, signum, pids, "tasks", false); } =20 diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index e555217355..8881d3a88a 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -577,12 +577,7 @@ virCgroupV2KillRecursive(virCgroup *group, int signum, GHashTable *pids) { - int controller =3D virCgroupV2GetAnyController(group); - - if (controller < 0) - return -1; - - return virCgroupKillRecursiveInternal(group, signum, pids, controller, + return virCgroupKillRecursiveInternal(group, signum, pids, "cgroup.threads", false); } =20 --=20 2.26.3