From nobody Sat Feb 7 20:30:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1618260003; cv=none; d=zohomail.com; s=zohoarc; b=PHp3HLq6hoNB4OFYNmsthV+qIzSZuk5VNmXMvo4he9C73QsThBjtJKjDqWRme1RU5RMko2c7iNryevXcdJ9Y/+GVFuAzN+y0KYMczVF2Z9QEJKtKAggBSFiwMHx0GjZWI5Enzw5sNhnAM9ZaRhBQPnCFRJ4Luz7QjXQkqINAaQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618260003; 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=zmcuRT2jX/yXLfR6YIvsNOAfz3LdH4nvw15WMc/srOA=; b=UqsdSz20tbBuzQmZgpDKZCuH8zZflK0IoevbhmSTJo8KcF5gzjqlZsSQKMJC0DVpqYnRjuQ6jjbdb1qWtHW1ctPNMak8/k8fm0WueRylLFeXLFutDUA3qn5FWrf5u7ca+2ZGrMWKoJvYKugVKuR9p4UPvs+jsnU+kRNFB6f5kAA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1618260003625219.30118627694117; Mon, 12 Apr 2021 13:40:03 -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-210-zEximCibN9ShyrF7cD4xtA-1; Mon, 12 Apr 2021 16:40:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 130088189CB; Mon, 12 Apr 2021 20:39:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA30C60C04; Mon, 12 Apr 2021 20:39:54 +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 181B844A60; Mon, 12 Apr 2021 20:39:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13CKc7Tu003754 for ; Mon, 12 Apr 2021 16:38:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id DE8285D6D1; Mon, 12 Apr 2021 20:38:07 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.195.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BA5C5D71D for ; Mon, 12 Apr 2021 20:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618260002; 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=zmcuRT2jX/yXLfR6YIvsNOAfz3LdH4nvw15WMc/srOA=; b=isd7iGccTQxudJXVthPtCFc4GNd2a8O3RuydCveyn/+Bjrh0koOLbwue01tK4DKVlI7pFf aEg6Qpi4GWEIzPmJ1+fdrx0dOAT4x5Xi1+LBcqP+RIdFy+4JaBWvZMW7II94v02oy5swbY 2FCGYrVvFboD/EUAyxr2x+9d423ZGu0= X-MC-Unique: zEximCibN9ShyrF7cD4xtA-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] vircgroupv2devices: refactor virCgroupV2DevicesRemoveProg Date: Mon, 12 Apr 2021 22:38:01 +0200 Message-Id: <83bae4da3569e66c8a4fccceeb483bb79f631969.1618259787.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.79 on 10.5.11.12 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When running on systemd host the cgroup itself is removed by machined so when we reach this code the directory no longer exist. If libvirtd was running the whole time between starting and destroying VM the detection is skipped because we still have both FD in memory. But if libvirtd was restarted and no operation requiring cgroup devices executed the FDs would be 0 and libvirt would try to detect them using the cgroup directory. This results in reporting following errors: libvirtd[955]: unable to open '/sys/fs/cgroup/machine.slice/machine-qem= u\x2d1\x2dguest.scope/': No such file or directory libvirtd[955]: Failed to remove cgroup for guest When running on non-systemd host where we handle cgroups manually this would not happen. When destroying VM it is not necessary to detect the BPF prog and map because the following code only closes the FDs without doing anything else. We could run code that would try to detach the BPF prog from the cgroup but that is not necessary as well. If the cgroup is removed and there is no other FD open to the prog kernel will cleanup the prog and map eventually. Reported-by: Eric Farman Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 2 +- src/util/vircgroupv2.c | 2 +- src/util/vircgroupv2devices.c | 14 ++++---------- src/util/vircgroupv2devices.h | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 119768496b..0ccde7e1b4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1963,12 +1963,12 @@ virCgroupV2Register; =20 # util/vircgroupv2devices.h virCgroupV2DevicesAvailable; +virCgroupV2DevicesCloseProg; virCgroupV2DevicesCreateProg; virCgroupV2DevicesDetectProg; virCgroupV2DevicesGetKey; virCgroupV2DevicesGetPerms; virCgroupV2DevicesPrepareProg; -virCgroupV2DevicesRemoveProg; =20 # util/vircommand.h virCommandAbort; diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 4664492c34..5bf087b39b 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -535,7 +535,7 @@ virCgroupV2Remove(virCgroupPtr group) if (virCgroupV2PathOfController(group, controller, "", &grppath) < 0) return 0; =20 - if (virCgroupV2DevicesRemoveProg(parent) < 0) + if (virCgroupV2DevicesCloseProg(parent) < 0) return -1; =20 return virCgroupRemoveRecursively(grppath); diff --git a/src/util/vircgroupv2devices.c b/src/util/vircgroupv2devices.c index 4bcc1d52fe..98ab6e8f5a 100644 --- a/src/util/vircgroupv2devices.c +++ b/src/util/vircgroupv2devices.c @@ -548,18 +548,12 @@ virCgroupV2DevicesPrepareProg(virCgroupPtr group) =20 =20 int -virCgroupV2DevicesRemoveProg(virCgroupPtr group) +virCgroupV2DevicesCloseProg(virCgroupPtr group) { - if (virCgroupV2DevicesDetectProg(group) < 0) - return -1; - - if (group->unified.devices.progfd <=3D 0 && group->unified.devices.map= fd <=3D 0) - return 0; - - if (group->unified.devices.mapfd >=3D 0) + if (group->unified.devices.mapfd > 0) VIR_FORCE_CLOSE(group->unified.devices.mapfd); =20 - if (group->unified.devices.progfd >=3D 0) + if (group->unified.devices.progfd > 0) VIR_FORCE_CLOSE(group->unified.devices.progfd); =20 return 0; @@ -629,7 +623,7 @@ virCgroupV2DevicesPrepareProg(virCgroupPtr group G_GNUC= _UNUSED) =20 =20 int -virCgroupV2DevicesRemoveProg(virCgroupPtr group G_GNUC_UNUSED) +virCgroupV2DevicesCloseProg(virCgroupPtr group G_GNUC_UNUSED) { return 0; } diff --git a/src/util/vircgroupv2devices.h b/src/util/vircgroupv2devices.h index 9d91256120..17ab07afa0 100644 --- a/src/util/vircgroupv2devices.h +++ b/src/util/vircgroupv2devices.h @@ -38,7 +38,7 @@ int virCgroupV2DevicesPrepareProg(virCgroupPtr group); =20 int -virCgroupV2DevicesRemoveProg(virCgroupPtr group); +virCgroupV2DevicesCloseProg(virCgroupPtr group); =20 uint32_t virCgroupV2DevicesGetPerms(int perms, --=20 2.30.2