[libvirt] [PATCH 0/2] Couple of virbpf related fixes

Both are trivial and fix a build issue on my 32bit machine so I've pushed them already. Michal Prívozník (2): vircgroupv2devices: Fix format string for size_t variable virbpf: Fix typecast to __aligned_u64 type src/util/virbpf.c | 32 ++++++++++++++++---------------- src/util/vircgroupv2devices.c | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) -- 2.23.0

In virCgroupV2DevicesReallocMap() we are debug printing both arguments passed to the function. However, the @size argument is type of size_t but '%lu' is used to format it. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/vircgroupv2devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/vircgroupv2devices.c b/src/util/vircgroupv2devices.c index 6b4ea3142f..dcf8925b18 100644 --- a/src/util/vircgroupv2devices.c +++ b/src/util/vircgroupv2devices.c @@ -456,7 +456,7 @@ virCgroupV2DevicesReallocMap(int mapfd, int ret = -1; VIR_AUTOCLOSE newmapfd = virCgroupV2DevicesCreateMap(size); - VIR_DEBUG("realloc devices map mapfd:%d, size:%lu", mapfd, size); + VIR_DEBUG("realloc devices map mapfd:%d, size:%zu", mapfd, size); if (newmapfd < 0) return -1; -- 2.23.0

In functions implemented here we fill this attr union (type of bpf_attr) and just pass it to syscall(2). Thing is that some of the union members are type of __aligned_u64. This is not regular uint64_t. This one is explicitly aligned to 8 bytes, while uint64_t can be aligned to 4 bytes (on 32 bits). We've used explicit typecast to uint64_t to shut compiler which would otherwise complain of assigning a pointer into an integer. Well, we have uintptr_t just for that. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virbpf.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/util/virbpf.c b/src/util/virbpf.c index 44f13fb485..dec8d0133a 100644 --- a/src/util/virbpf.c +++ b/src/util/virbpf.c @@ -65,10 +65,10 @@ virBPFLoadProg(struct bpf_insn *insns, memset(&attr, 0, sizeof(attr)); attr.prog_type = progType; - attr.insn_cnt = (uint32_t)insnCnt; - attr.insns = (uint64_t)insns; - attr.license = (uint64_t)"GPL"; - attr.log_buf = (uint64_t)logbuf; + attr.insn_cnt = insnCnt; + attr.insns = (uintptr_t)insns; + attr.license = (uintptr_t)"GPL"; + attr.log_buf = (uintptr_t)logbuf; attr.log_size = LOG_BUF_SIZE; attr.log_level = 1; @@ -130,7 +130,7 @@ virBPFQueryProg(int targetfd, attr.query.target_fd = targetfd; attr.query.attach_type = attachType; attr.query.prog_cnt = maxprogids; - attr.query.prog_ids = (uint64_t)progids; + attr.query.prog_ids = (uintptr_t)progids; rc = syscall(SYS_bpf, BPF_PROG_QUERY, &attr, sizeof(attr)); @@ -166,7 +166,7 @@ virBPFGetProgInfo(int progfd, attr.info.bpf_fd = progfd; attr.info.info_len = sizeof(struct bpf_prog_info); - attr.info.info = (uint64_t)info; + attr.info.info = (uintptr_t)info; rc = syscall(SYS_bpf, BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)); if (rc < 0) @@ -180,12 +180,12 @@ virBPFGetProgInfo(int progfd, memset(info, 0, sizeof(struct bpf_prog_info)); info->nr_map_ids = maplen; - info->map_ids = (uint64_t)retmapIDs; + info->map_ids = (uintptr_t)retmapIDs; memset(&attr, 0, sizeof(attr)); attr.info.bpf_fd = progfd; attr.info.info_len = sizeof(struct bpf_prog_info); - attr.info.info = (uint64_t)info; + attr.info.info = (uintptr_t)info; rc = syscall(SYS_bpf, BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)); if (rc < 0) @@ -221,7 +221,7 @@ virBPFGetMapInfo(int mapfd, attr.info.bpf_fd = mapfd; attr.info.info_len = sizeof(struct bpf_map_info); - attr.info.info = (uint64_t)info; + attr.info.info = (uintptr_t)info; return syscall(SYS_bpf, BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)); } @@ -237,8 +237,8 @@ virBPFLookupElem(int mapfd, memset(&attr, 0, sizeof(attr)); attr.map_fd = mapfd; - attr.key = (uint64_t)key; - attr.value = (uint64_t)val; + attr.key = (uintptr_t)key; + attr.value = (uintptr_t)val; return syscall(SYS_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); } @@ -254,8 +254,8 @@ virBPFGetNextElem(int mapfd, memset(&attr, 0, sizeof(attr)); attr.map_fd = mapfd; - attr.key = (uint64_t)key; - attr.next_key = (uint64_t)nextKey; + attr.key = (uintptr_t)key; + attr.next_key = (uintptr_t)nextKey; return syscall(SYS_bpf, BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr)); } @@ -271,8 +271,8 @@ virBPFUpdateElem(int mapfd, memset(&attr, 0, sizeof(attr)); attr.map_fd = mapfd; - attr.key = (uint64_t)key; - attr.value = (uint64_t)val; + attr.key = (uintptr_t)key; + attr.value = (uintptr_t)val; return syscall(SYS_bpf, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); } @@ -287,7 +287,7 @@ virBPFDeleteElem(int mapfd, memset(&attr, 0, sizeof(attr)); attr.map_fd = mapfd; - attr.key = (uint64_t)key; + attr.key = (uintptr_t)key; return syscall(SYS_bpf, BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); } -- 2.23.0
participants (1)
-
Michal Privoznik