From: Mark Wielaard Date: Sat, 31 Aug 2024 17:47:27 +0000 (+0200) Subject: Implement stable variant of sync_file ioctls X-Git-Tag: VALGRIND_3_24_0~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eee8dd6461adb46e560f3e3981a069a6895cc241;p=thirdparty%2Fvalgrind.git Implement stable variant of sync_file ioctls We implemented an old staging android variant of the sync_file ioctls. But the data structures and ioctl numbers changed when these were upstreamed in the table linux kernel. This implements the SYNC_IOC_MERGE, SYNC_IOC_FILE_INFO and SYNC_IOC_SET_DEADLINE ioctls. And makes sure to record the new file descriptor created by SYNC_IOC_MERGE. https://bugs.kde.org/show_bug.cgi?id=492422 --- diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 453385599..901c32e95 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -7258,6 +7258,29 @@ PRE(sys_ioctl) PRE_FIELD_READ ("ioctl(SYNC_IOC_MERGE).fd2", data->fd2); PRE_MEM_RASCIIZ("ioctl(SYNC_IOC_MERGE).name", (Addr)(&data->name[0])); PRE_FIELD_WRITE("ioctl(SYNC_IOC_MERGE).fence", data->fence); + PRE_FIELD_READ("ioctl(SYNC_IOC_MERGE).flags", data->flags); + break; + } + + case VKI_SYNC_IOC_FILE_INFO: { + struct vki_sync_file_info* data = + (struct vki_sync_file_info*)(Addr)ARG3; + PRE_FIELD_READ ("ioctl(SYNC_IOC_FILE_INFO).flags", data->flags); + PRE_FIELD_READ ("ioctl(SYNC_IOC_FILE_INFO).num_fences", data->num_fences); + PRE_FIELD_WRITE("ioctl(SYNC_IOC_FILE_INFO).status", data->status); + if (data->num_fences) + PRE_MEM_WRITE("ioctl(SYNC_IOC_FILE_INFO).sync_fence_info", + (Addr)data->sync_fence_info, + (data->num_fences + * sizeof(sizeof(struct vki_sync_fence_info)))); + break; + } + + case VKI_SYNC_IOC_SET_DEADLINE: { + struct vki_sync_set_deadline* data = + (struct vki_sync_set_deadline*)(Addr)ARG3; + PRE_FIELD_READ ("ioctl(SYNC_IOC_SET_DEADLINE).deadline_ns", + data->deadline_ns); break; } @@ -10454,6 +10477,18 @@ POST(sys_ioctl) struct vki_sync_merge_data* data = (struct vki_sync_merge_data*)(Addr)ARG3; POST_FIELD_WRITE(data->fence); + if (VG_(clo_track_fds)) + ML_(record_fd_open_nameless) (tid, data->fence); + break; + } + + case VKI_SYNC_IOC_FILE_INFO: { + struct vki_sync_file_info* data = + (struct vki_sync_file_info*)(Addr)ARG3; + POST_FIELD_WRITE(data->status); + if (data->num_fences > 0 && (Addr)data->sync_fence_info != (Addr)NULL) + POST_MEM_WRITE(data->sync_fence_info, + data->num_fences * sizeof(struct vki_sync_fence_info)); break; } diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index 708a12b64..006f16d92 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -3859,29 +3859,37 @@ struct vki_ion_custom_data { _VKI_IOWR(VKI_ION_IOC_MAGIC, 6, struct vki_ion_custom_data) //---------------------------------------------------------------------- -// From linux-3.19-rc5/drivers/staging/android/uapi/sync.h +// From include/uapi/linux/sync_file.h 6.10.3 //---------------------------------------------------------------------- struct vki_sync_merge_data { - __vki_s32 fd2; char name[32]; + __vki_s32 fd2; __vki_s32 fence; + __vki_u32 flags; + __vki_u32 pad; }; -struct vki_sync_pt_info { - __vki_u32 len; +struct vki_sync_fence_info { char obj_name[32]; char driver_name[32]; __vki_s32 status; - __vki_u64 timestamp_ns; - __vki_u8 driver_data[0]; + __vki_u32 flags; + __vki_u64 timestamp_ns; }; -struct vki_sync_fence_info_data { - __vki_u32 len; +struct vki_sync_file_info { char name[32]; __vki_s32 status; - __vki_u8 pt_info[0]; + __vki_u32 flags; + __vki_u32 num_fences; + __vki_u32 pad; + __vki_u64 sync_fence_info; +}; + +struct vki_sync_set_deadline { + __vki_u64 deadline_ns; + __vki_u64 pad; }; #define VKI_SYNC_IOC_MAGIC '>' @@ -3890,10 +3898,13 @@ struct vki_sync_fence_info_data { _VKI_IOW(VKI_SYNC_IOC_MAGIC, 0, __vki_s32) #define VKI_SYNC_IOC_MERGE \ - _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 1, struct vki_sync_merge_data) + _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 3, struct vki_sync_merge_data) + +#define VKI_SYNC_IOC_FILE_INFO \ + _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 4, struct vki_sync_file_info) -#define VKI_SYNC_IOC_FENCE_INFO \ - _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 2, struct vki_sync_fence_info_data) +#define VKI_SYNC_IOC_SET_DEADLINE \ + _VKI_IOW(VKI_SYNC_IOC_MAGIC, 5, struct vki_sync_set_deadline) //---------------------------------------------------------------------- // From drivers/staging/lustre/lustre/include/lustre/lustre_user.h