@@ -77,27 +77,47 @@ int rocm_memory_init(struct memory_ctx *ctx) {
7777
7878#ifdef HAVE_ROCM_DMABUF
7979 if (rocm_ctx -> use_dmabuf ) {
80- int dmabuf_supported = 0 ;
80+ int dmabuf_supported = 0 ;
8181 const char kernel_opt1 [] = "CONFIG_DMABUF_MOVE_NOTIFY=y" ;
8282 const char kernel_opt2 [] = "CONFIG_PCI_P2PDMA=y" ;
8383 int found_opt1 = 0 ;
8484 int found_opt2 = 0 ;
85- FILE * fp ;
85+
86+ const char * config_path_fmts [] = {
87+ "/boot/config-%s" ,
88+ "/usr/src/linux-%s/.config" ,
89+ "/usr/src/linux/.config" ,
90+ "/usr/lib/modules/%s/config" ,
91+ "/usr/lib/ostree-boot/config-%s" ,
92+ "/usr/lib/kernel/config-%s" ,
93+ "/usr/src/linux-headers-%s/.config" ,
94+ "/lib/modules/%s/build/.config" ,
95+ };
96+ size_t num_paths = sizeof (config_path_fmts ) /
97+ sizeof (config_path_fmts [0 ]);
8698 struct utsname utsname ;
87- char kernel_conf_file [128 ];
99+ char kernel_conf_file [256 ];
88100 char buf [256 ];
101+ FILE * fp = NULL ;
102+ size_t i ;
89103
90104 if (uname (& utsname ) == -1 ) {
91- printf ("could not get kernel name" );
105+ printf ("could not get kernel name\n " );
92106 return FAILURE ;
93107 }
94108
95- snprintf (kernel_conf_file , sizeof (kernel_conf_file ),
96- "/boot/config-%s" , utsname .release );
97- fp = fopen (kernel_conf_file , "r" );
109+ for (i = 0 ; i < num_paths ; i ++ ) {
110+ snprintf (kernel_conf_file , sizeof (kernel_conf_file ),
111+ config_path_fmts [i ], utsname .release );
112+ fp = fopen (kernel_conf_file , "r" );
113+ if (fp != NULL ) {
114+ break ;
115+ }
116+ }
117+
98118 if (fp == NULL ) {
99- printf ("could not open kernel conf file %s error: %m" ,
100- kernel_conf_file );
119+ printf ("could not open any kernel config file to "
120+ "verify dmabuf support\n" );
101121 return FAILURE ;
102122 }
103123
@@ -114,6 +134,21 @@ int rocm_memory_init(struct memory_ctx *ctx) {
114134 }
115135 }
116136 fclose (fp );
137+
138+ // Fallback, works inside Docker containers where /boot/config-* is unavailable.
139+ if (!dmabuf_supported ) {
140+ fp = fopen ("/proc/kallsyms" , "r" );
141+ if (fp != NULL ) {
142+ int o1 = 0 , o2 = 0 ;
143+ while (fgets (buf , sizeof (buf ), fp ) != NULL ) {
144+ if (!o1 && strstr (buf , " dma_buf_move_notify\n" )) o1 = 1 ;
145+ if (!o2 && strstr (buf , " pci_p2pdma" )) o2 = 1 ;
146+ if (o1 && o2 ) break ;
147+ }
148+ fclose (fp );
149+ dmabuf_supported = (o1 && o2 );
150+ }
151+ }
117152
118153 if (dmabuf_supported == 0 ) {
119154 return FAILURE ;
0 commit comments