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 E24A8331202 for ; Fri, 20 Feb 2026 12:05:44 +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=1771589146; cv=none; b=JPfNoDsyN7kZLpC4IqZDsbqD/WLuBKuT6d9nmgO6Jr4Zqn3iFZ4FP2GDSJI19dKsqmcgMD6I1Zpmdt6CZ+IqVeF4VlccDlj/dBWuRpRUeJ0KwaOiRvMrs9Dk0rGWg2oNLvyuPbLujIGDiMF+c2EZfQzv6tVaeh2Z0UQwd+HwF4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771589146; c=relaxed/simple; bh=Vfs9NdFNv1OD4VZVzFVTDaqcNUPu5kp9C5nvcoPoKTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qa/13jM0fKaCl/bpDN5YytEKoeItirTt/CNN6xeXFvba6r6xf+LYq+OypmRPDQrGo2VmuQLsDlbkQ1VO5JHFcDDuTClPaaYBOy3lbool3kR9TWscKrvEOhc0UFMj/dACIfZupF3t0Lfo8OQLQ7YVuqXS7JEZILh3anD0wOHhKv4= 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=WhP+nez8; 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="WhP+nez8" 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=NOCB5rc+/MqVMQ2gpfFTPWp6TLt69GgXOtFQ8vwY+8g=; b=WhP+nez8GgqCigWNbUrlADeJZG OlqLlzzLvWvViMuVZTSvc/yxUD3ZZ5gte1E7vzovpUt/5F3P2doDCiu9jV6qppNFJOCX8RvLtmsUv r7EfxDAity9FyXFzdd/BW0q3vh41yz8OcRGEFrkF3VRsWB1/YdQu/SY9kA6kETirEmgHp6VjOnevM CWHK7bft2AUlgUxdEru1SxunL1N0D2JRy+lme+32V7zOuYPnYQQDUA/BjqAbP4s7aw4tXSKmSka45 Mb7BtS6pCYELsLVWk0P8jB26Lp1hR45W4VciZaer+7vhPdZxkUBLm/7bT9NO4HwbetI7xhzVsBfGs bxlI50oQ==; 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 1vtPGR-002v1j-0N; Fri, 20 Feb 2026 13:05:43 +0100 From: Tvrtko Ursulin To: criu@lists.linux.dev Cc: David Francis , Tvrtko Ursulin Subject: [RFC 25/26] plugins/amdgpu: Hack to save a fd number which works for vma restore Date: Fri, 20 Feb 2026 12:05:13 +0000 Message-ID: <20260220120514.4540-26-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 Another problem with VMA restore inside a forked process is that the file descriptor plugin creates to pass to CRIU core to mmap() against is present only in the process enumerating the VMAs. If there is a child process this fd will be invalid and the restore will fail. In this patch we work around that by trying to guess the real (restored) file descriptor associated with this VMA and store that in the VMA metadata used for restore. This works for a simple case when processes have identical set of file descriptor in a linear growing order, but probably not much more that that. To fix this properly a deeper discussion on the design is required. Signed-off-by: Tvrtko Ursulin --- plugins/amdgpu/amdgpu_plugin.c | 17 +++++++++++++++-- plugins/amdgpu/amdgpu_plugin_drm.c | 4 ++-- plugins/amdgpu/amdgpu_plugin_drm.h | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/plugins/amdgpu/amdgpu_plugin.c b/plugins/amdgpu/amdgpu_plugin.c index 83d16272237f..239eeebc5111 100644 --- a/plugins/amdgpu/amdgpu_plugin.c +++ b/plugins/amdgpu/amdgpu_plugin.c @@ -1863,7 +1863,7 @@ static int amdgpu_plugin_restore_drm_file(int id, bool *retry_needed) CriuRenderNode *rd; unsigned char *buf; size_t img_size; - int fd, ret; + int probed_fd, fd, ret; /* This is restorer plugin for renderD nodes. Criu doesn't guarantee * that they will be called before the plugin is called for kfd file @@ -1963,7 +1963,20 @@ static int amdgpu_plugin_restore_drm_file(int id, bool *retry_needed) return -1; } - ret = amdgpu_plugin_drm_restore_file(fd, rd); + /* + * HACK! to figure out the final/restored fd we need to restore vmas. + * It will not work if non-linear fd space, neither inside a forked + * process which inherits the vma but does not have the same device + * kept open or under the same fd. + */ + probed_fd = dup(fd); + if (probed_fd < 0) { + pr_perror("Failed to probe fd\n"); + return -1; + } + close(probed_fd); + + ret = amdgpu_plugin_drm_restore_file(fd, rd, probed_fd); if (ret == 1) *retry_needed = true; if (ret < 0) { diff --git a/plugins/amdgpu/amdgpu_plugin_drm.c b/plugins/amdgpu/amdgpu_plugin_drm.c index 30a0626b7b5f..6fb523e31720 100644 --- a/plugins/amdgpu/amdgpu_plugin_drm.c +++ b/plugins/amdgpu/amdgpu_plugin_drm.c @@ -453,7 +453,7 @@ exit: return ret; } -int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd) +int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd, int probed_fd) { int ret = 0; bool retry_needed = false; @@ -551,7 +551,7 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd) } ret = save_vma_updates(boinfo->offset, boinfo->addr, - mmap_args.out.addr_ptr, fd); + mmap_args.out.addr_ptr, probed_fd); if (ret < 0) goto exit; } diff --git a/plugins/amdgpu/amdgpu_plugin_drm.h b/plugins/amdgpu/amdgpu_plugin_drm.h index f76e29f7f73f..7a05e01dcebc 100644 --- a/plugins/amdgpu/amdgpu_plugin_drm.h +++ b/plugins/amdgpu/amdgpu_plugin_drm.h @@ -24,7 +24,7 @@ int amdgpu_plugin_drm_handle_device_vma(int fd, const struct stat *drm); */ int amdgpu_plugin_drm_dump_file(int fd, int id, struct stat *drm); -int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd); +int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd, int probed_fd); int amdgpu_plugin_drm_unpause_file(int fd); -- 2.52.0