@@ -310,34 +310,71 @@ int uct_rocm_base_is_dmabuf_supported()
310310 struct utsname utsname ;
311311 char kernel_conf_file [128 ];
312312 char buf [256 ];
313+ const char * fmts [] = {
314+ "/boot/config-%s" ,
315+ "/usr/src/linux-%s/.config" ,
316+ "/usr/src/linux/.config" ,
317+ "/usr/lib/modules/%s/config" ,
318+ "/usr/lib/ostree-boot/config-%s" ,
319+ "/usr/lib/kernel/config-%s" ,
320+ "/usr/src/linux-headers-%s/.config" ,
321+ "/lib/modules/%s/build/.config"
322+ };
313323
314324 if (uname (& utsname ) == -1 ) {
315325 ucs_trace ("could not get kernel name" );
316326 goto out ;
317327 }
318328
319- ucs_snprintf_safe (kernel_conf_file , sizeof (kernel_conf_file ),
320- "/boot/config-%s" , utsname .release );
321- fp = fopen (kernel_conf_file , "r" );
329+ for (size_t i = 0 ; i < sizeof (fmts ) / sizeof (fmts [0 ]); ++ i ) {
330+ const char * path = fmts [i ];
331+ ucs_snprintf_safe (kernel_conf_file , sizeof (kernel_conf_file ), path , utsname .release );
332+ fp = fopen (path , "r" );
333+ if (fp != NULL ) {
334+ ucs_trace ("reading kernel config from %s" , path );
335+ break ;
336+ }
337+ ucs_trace ("could not open kernel conf file %s error: %m" , path );
338+ }
339+
340+ if (fp != NULL ) {
341+ while (fgets (buf , sizeof (buf ), fp ) != NULL ) {
342+ if (strstr (buf , kernel_opt1 ) != NULL ) {
343+ found_opt1 = 1 ;
344+ }
345+ if (strstr (buf , kernel_opt2 ) != NULL ) {
346+ found_opt2 = 1 ;
347+ }
348+ if (found_opt1 && found_opt2 ) {
349+ dmabuf_supported = 1 ;
350+ break ;
351+ }
352+ }
353+
354+ fclose (fp );
355+ return dmabuf_supported ;
356+ }
357+
358+ ucs_trace ("no kernel conf file found, trying /proc/kallsyms fallback" );
359+ fp = fopen ("/proc/kallsyms" , "r" );
360+
322361 if (fp == NULL ) {
323- ucs_trace ("could not open kernel conf file %s error: %m" ,
324- kernel_conf_file );
362+ ucs_trace ("no kernel conf or kallsyms file found" );
325363 goto out ;
326364 }
327365
328366 while (fgets (buf , sizeof (buf ), fp ) != NULL ) {
329- if (strstr (buf , kernel_opt1 ) != NULL ) {
330- found_opt1 = 1 ;
331- }
332- if (strstr (buf , kernel_opt2 ) != NULL ) {
333- found_opt2 = 1 ;
334- }
367+ if (!found_opt1 && strstr (buf , "dma_buf_move_notify" ) != NULL )
368+ found_opt1 = 1 ;
369+ if (!found_opt2 && strstr (buf , "pci_p2pdma" ) != NULL )
370+ found_opt2 = 1 ;
335371 if (found_opt1 && found_opt2 ) {
336372 dmabuf_supported = 1 ;
337373 break ;
338374 }
339375 }
340376 fclose (fp );
377+
341378#endif
342379out :
343380 return dmabuf_supported ;
0 commit comments