From nobody Mon Feb 9 03:30:27 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 ARC-Seal: i=1; a=rsa-sha256; t=1556178303; cv=none; d=zoho.com; s=zohoarc; b=NJTQ0Nz/0/DQ3KifSCZmZwt2ExX5fy5cmqT0fZBJETDYf5OyAP+BbWFDITNEtVZ7rGbHFEQtZSoL4SIZQoPwiy/Aks+jUKbYHydhxwXyN2M1BJgoL+5bONkXTNQzzHyo/dG3Sw0Sym5tyS2Za1wVFScJzt6KrG+lFvp+qD3HbJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556178303; 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:ARC-Authentication-Results; bh=mybJIYG5Njg+DKDC5VtfxSo07hTAzk9V4/O5AFaa12M=; b=EvNNp0TrliwczXvqKBYt8gsIhgDnCpza/y4OMeQnXFnPVRsA07kzty9S6dJdRXEFOb2XRc3eY4Za7oQCEvW08PyjqeirNu9WvphK99Ye/LuOP7FjIpqLcN7WG/px8d1ZtmhAcsfz8fondjyaXmWY3OYQJaN1HkV3rqRx/wjdAWE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1556178303721867.9365617175614; Thu, 25 Apr 2019 00:45:03 -0700 (PDT) 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 7400B88ABE; Thu, 25 Apr 2019 07:45:01 +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 48EB5648B5; Thu, 25 Apr 2019 07:45:01 +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 F2D5A181B9ED; Thu, 25 Apr 2019 07:45:00 +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 x3P7ifVw007905 for ; Thu, 25 Apr 2019 03:44:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED826648AD; Thu, 25 Apr 2019 07:44:41 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7508A648A2 for ; Thu, 25 Apr 2019 07:44:41 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 25 Apr 2019 09:44:27 +0200 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 v3 10/15] vircgroup: introduce virCgroupV2AllowDevice 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.26]); Thu, 25 Apr 2019 07:45:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In order to allow device we need to create key and value which will be used to update BPF map. virBPFUpdateElem() can override existing entries in BPF map so we need to check if that entry exists in order to track number of entries in our map. This can add rule for specific device but major and minor can be both -1 which follows the same behavior as in cgroup v1. Signed-off-by: Pavel Hrdina Reviewed-by: J=C3=A1n Tomko --- src/util/vircgroupv2.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index ce19169fe7..9f9802bb2f 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -30,6 +30,7 @@ #include "vircgrouppriv.h" =20 #include "viralloc.h" +#include "virbpf.h" #include "vircgroup.h" #include "vircgroupbackend.h" #include "vircgroupv2.h" @@ -1638,6 +1639,35 @@ virCgroupV2GetCpusetCpus(virCgroupPtr group, } =20 =20 +static int +virCgroupV2AllowDevice(virCgroupPtr group, + char type, + int major, + int minor, + int perms) +{ + uint64_t key =3D virCgroupV2DevicesGetKey(major, minor); + uint32_t val =3D virCgroupV2DevicesGetPerms(perms, type); + int rc; + + if (virCgroupV2DevicesPrepareProg(group) < 0) + return -1; + + rc =3D virBPFLookupElem(group->unified.devices.mapfd, &key, NULL); + + if (virBPFUpdateElem(group->unified.devices.mapfd, &key, &val) < 0) { + virReportSystemError(errno, "%s", + _("failed to update device in BPF cgroup map"= )); + return -1; + } + + if (rc < 0) + group->unified.devices.count++; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1687,6 +1717,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getMemSwapHardLimit =3D virCgroupV2GetMemSwapHardLimit, .getMemSwapUsage =3D virCgroupV2GetMemSwapUsage, =20 + .allowDevice =3D virCgroupV2AllowDevice, + .setCpuShares =3D virCgroupV2SetCpuShares, .getCpuShares =3D virCgroupV2GetCpuShares, .setCpuCfsPeriod =3D virCgroupV2SetCpuCfsPeriod, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list