Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AB0E340D9A for ; Fri, 20 Feb 2026 12:05:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771589137; cv=none; b=YCB9iNe/Co/OYYv38Tz6WqPtmsqQJnZ/RHhOcajXqUpv8QsUdO6qyHEKEQCiZq0/Hyx37OesHn63wKyZMaCcY0Col1YkpC2u6NzJIRlx6GIrIf0uNQn5iyLYcXpEPPlG98NNS1bs53tuCsrYAHptp4JEpnHocBHDkR7+iyRYXSc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771589137; c=relaxed/simple; bh=g/lx29E4C8TdWDKHMryzA+ZFgTOeBD8B4qmJmQrNsoc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AsyJnEwQeM1g77rRRyum+n0/Y+t7jIoINf87H6bZIvIRHU7MXBKYKt6P6uIZVXwA0PUCnQ+LnQGYL83zH0civWqu1oqQsyQ2Sk971GQKnxOy9f4cIe5jQHyOBu5ikEerUGZn0vOZ0PoUFF7GXZFU+KBu3RdkGaMSWhInYx2tqpo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=aYxI/1J8; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="aYxI/1J8" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=NsMXA2BqD5mW0w2tZuN6bw+YpzDghlcniRbSxqaVRgk=; b=aYxI/1J8jR6qFotQAbpXdu4MYl BXAmpfasJKx5W4uafXSIpssOcmkrqwImCL2t/4qyT0FbK98XRLApAKo73tEUy20sYFCoEd5BHMeV1 WGoRIrS9U2GBPY6K6PipS4vTbyPbMA8bMkAaCKDI9XE94SNfmr/0dzoxF+oJhghQkXIRs/JhEhxO7 jUAuXlL5rTQsgUNpn+q9U5qsfD2wVMUo/WOoG1okKuWO6X3VFU3LAuKn5CpD740IqD/c09JI5x5Fy x1mjej9nySlGwOF/iNrWyteSc3j9/NovPJSvY3ObNEd78NWLOVwSYqSm0BGBERYGeRohQcFhm/l6+ 1AJ9PagA==; Received: from [90.240.106.137] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1vtPGI-002uzm-Ez; Fri, 20 Feb 2026 13:05:34 +0100 From: Tvrtko Ursulin To: criu@lists.linux.dev Cc: David Francis , Tvrtko Ursulin Subject: [RFC 13/26] plugins/amdgpu: Consolidate vm_info collection Date: Fri, 20 Feb 2026 12:05:01 +0000 Message-ID: <20260220120514.4540-14-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260220120514.4540-1-tvrtko.ursulin@igalia.com> References: <20260220120514.4540-1-tvrtko.ursulin@igalia.com> Precedence: bulk X-Mailing-List: criu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Instead of open coding the same ioctl twice we can put it in a loop from which we break out once we have allocated enough space for all objects. While at it we add error handling for the memory allocation. Signed-off-by: Tvrtko Ursulin --- plugins/amdgpu/amdgpu_plugin_drm.c | 47 ++++++++++++++++-------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/plugins/amdgpu/amdgpu_plugin_drm.c b/plugins/amdgpu/amdgpu_plugin_drm.c index 9df755450dc9..baa560537813 100644 --- a/plugins/amdgpu/amdgpu_plugin_drm.c +++ b/plugins/amdgpu/amdgpu_plugin_drm.c @@ -302,8 +302,7 @@ int amdgpu_plugin_drm_dump_file(int fd, int id, struct stat *drm) for (int i = 0; i < num_bos; i++) { int num_vm_entries = 8; - struct drm_amdgpu_gem_vm_entry *vm_info_entries; - struct drm_amdgpu_gem_op vm_info_args = { 0 }; + struct drm_amdgpu_gem_vm_entry *vm_info_entries = NULL; DrmBoEntry *boinfo = rd->bo_entries[i]; struct drm_amdgpu_gem_list_handles_entry handle_entry = list_handles_entries[i]; union drm_amdgpu_gem_mmap mmap_args = { 0 }; @@ -333,32 +332,36 @@ int amdgpu_plugin_drm_dump_file(int fd, int id, struct stat *drm) boinfo->offset = mmap_args.out.addr_ptr; - vm_info_entries = xzalloc(sizeof(struct drm_amdgpu_gem_vm_entry) * num_vm_entries); - vm_info_args.handle = handle_entry.gem_handle; - vm_info_args.num_entries = num_vm_entries; - vm_info_args.value = (uintptr_t)vm_info_entries; - vm_info_args.op = AMDGPU_GEM_OP_GET_MAPPING_INFO; - ret = drmIoctl(fd, DRM_IOCTL_AMDGPU_GEM_OP, &vm_info_args); - if (ret) { - pr_perror("Failed to call vm info ioctl"); - goto exit; - } + for (;;) { + struct drm_amdgpu_gem_op vm_info_args = { + .handle = handle_entry.gem_handle, + .num_entries = num_vm_entries, + .op = AMDGPU_GEM_OP_GET_MAPPING_INFO, + }; + + if (vm_info_entries) + xfree(vm_info_entries); + vm_info_entries = xzalloc(sizeof(*vm_info_entries) * + num_vm_entries); + if (!vm_info_entries) { + ret = -ENOMEM; + goto exit; + } - if (vm_info_args.num_entries > num_vm_entries) { - num_vm_entries = vm_info_args.num_entries; - xfree(vm_info_entries); - vm_info_entries = xzalloc(sizeof(struct drm_amdgpu_gem_vm_entry) * num_vm_entries); - vm_info_args.handle = handle_entry.gem_handle; - vm_info_args.num_entries = num_vm_entries; vm_info_args.value = (uintptr_t)vm_info_entries; - vm_info_args.op = AMDGPU_GEM_OP_GET_MAPPING_INFO; - ret = drmIoctl(fd, DRM_IOCTL_AMDGPU_GEM_OP, &vm_info_args); + ret = drmIoctl(fd, DRM_IOCTL_AMDGPU_GEM_OP, + &vm_info_args); if (ret) { pr_perror("Failed to call vm info ioctl"); goto exit; } - } else { - num_vm_entries = vm_info_args.num_entries; + + if (vm_info_args.num_entries <= num_vm_entries) { + num_vm_entries = vm_info_args.num_entries; + break; + } else { + num_vm_entries = vm_info_args.num_entries; + } } boinfo->num_of_vms = num_vm_entries; -- 2.52.0