From nobody Sun Feb 8 09:41:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1546438143505594.1740515407031; Wed, 2 Jan 2019 06:09:03 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F182E394D3C; Wed, 2 Jan 2019 14:09:00 +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 45EB8608D9; Wed, 2 Jan 2019 14:09:00 +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 8A9A33F602; Wed, 2 Jan 2019 14:08:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x02E8vBD000860 for ; Wed, 2 Jan 2019 09:08:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9BD29608DC; Wed, 2 Jan 2019 14:08:57 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21A76608D9 for ; Wed, 2 Jan 2019 14:08:56 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 2 Jan 2019 15:08:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/19] vircgroup: introduce virCgroupV2DevicesAvailable 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 02 Jan 2019 14:09:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There is no exact way how to figure out whether BPF devices support is compiled into kernel. One way is to check kernel configure options but this is not reliable as it may not be available. Let's try to do syscall to which will list BPF cgroup device programs. Signed-off-by: Pavel Hrdina --- src/Makefile.am | 1 + src/util/vircgroupv2.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index e2b89e27e8..3de926403f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -670,6 +670,7 @@ libvirt_setuid_rpc_client_la_SOURCES =3D \ util/viratomic.c \ util/viratomic.h \ util/virbitmap.c \ + util/virbpf.c \ util/virbuffer.c \ util/vircgroup.c \ util/vircgroupbackend.c \ diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index cd58491da1..0adc0d4d23 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -20,8 +20,13 @@ #include =20 #ifdef __linux__ +# include +# include # include # include +# include +# include +# include #endif /* __linux__ */ =20 #include "internal.h" @@ -29,6 +34,7 @@ #define LIBVIRT_VIRCGROUPPRIV_H_ALLOW #include "vircgrouppriv.h" =20 +#include "virbpf.h" #include "vircgroup.h" #include "vircgroupbackend.h" #include "vircgroupv2.h" @@ -280,6 +286,31 @@ virCgroupV2ParseControllersFile(virCgroupPtr group) } =20 =20 +static bool +virCgroupV2DevicesAvailable(virCgroupPtr group) +{ + bool ret =3D false; + int cgroupfd =3D -1; + unsigned int progCnt =3D 0; + + cgroupfd =3D open(group->unified.mountPoint, O_RDONLY); + if (cgroupfd < 0) { + VIR_DEBUG("failed to open cgroup '%s'", group->unified.mountPoint); + goto cleanup; + } + + if (virBPFQueryProg(cgroupfd, 0, BPF_CGROUP_DEVICE, &progCnt, NULL) < = 0) { + VIR_DEBUG("failed to query cgroup progs"); + goto cleanup; + } + + ret =3D true; + cleanup: + VIR_FORCE_CLOSE(cgroupfd); + return ret; +} + + static int virCgroupV2DetectControllers(virCgroupPtr group, int controllers) @@ -292,6 +323,8 @@ virCgroupV2DetectControllers(virCgroupPtr group, /* In cgroup v2 there is no cpuacct controller, the cpu.stat file alwa= ys * exists with usage stats. */ group->unified.controllers |=3D 1 << VIR_CGROUP_CONTROLLER_CPUACCT; + if (virCgroupV2DevicesAvailable(group)) + group->unified.controllers |=3D 1 << VIR_CGROUP_CONTROLLER_DEVICES; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) VIR_DEBUG("Controller '%s' present=3D%s", @@ -406,8 +439,10 @@ virCgroupV2MakeGroup(virCgroupPtr parent ATTRIBUTE_UNU= SED, continue; =20 /* Controllers that are implicitly enabled if available. */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_CPUACCT) + if (i =3D=3D VIR_CGROUP_CONTROLLER_CPUACCT || + i =3D=3D VIR_CGROUP_CONTROLLER_DEVICES) { continue; + } =20 if (virCgroupV2EnableController(parent, i) < 0) return -1; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list