amd_hsmp icon indicating copy to clipboard operation
amd_hsmp copied to clipboard

I also get an error w.r.t. copy_struct_from_user() but on RHEL 8.3 (4.18.0-240.el8.x86_64)

Open C-Newman opened this issue 3 years ago • 5 comments

# make
make -C /lib/modules/`uname -r`/build M=$PWD modules
make[1]: Entering directory '/usr/src/kernels/4.18.0-240.el8.x86_64'
  CC [M]  /root/downloads/amd_hsmp-master/amd_hsmp.o
/root/downloads/amd_hsmp-master/amd_hsmp.c: In function ‘hsmp_ioctl’:
/root/downloads/amd_hsmp-master/amd_hsmp.c:280:6: error: implicit declaration of function ‘copy_struct_from_user’; did you mean ‘copy_from_user’? [-Werror=implicit-function-declaration]
  if (copy_struct_from_user(&msg, sizeof(msg), arguser, sizeof(struct hsmp_message)))
      ^~~~~~~~~~~~~~~~~~~~~
      copy_from_user
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:322: /root/downloads/amd_hsmp-master/amd_hsmp.o] Error 1
make[1]: *** [Makefile:1544: _module_/root/downloads/amd_hsmp-master] Error 2
make[1]: Leaving directory '/usr/src/kernels/4.18.0-240.el8.x86_64'
make: *** [Makefile:16: default] Error 2

C-Newman avatar Mar 24 '22 19:03 C-Newman

Hi C-newman, kernel versions prior to v5.4 (where copy_struct_from_user() is not defined). You may have to use the following change in the driver.

-       if (copy_struct_from_user(&msg, sizeof(msg), arguser, sizeof(struct hsmp_message)))
+       if (copy_from_user(&msg, arguser, sizeof(struct hsmp_message)))

or backport patches to bring support for copy_struct_from_user()

Note: This driver is accepted in the upstream kernel https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/platform/x86/amd_hsmp.c

nchatrad avatar Apr 05 '22 04:04 nchatrad

Found that copy_to_user is also outdated for Linux version 4.14.313-235.533.amzn2.x86_64 using Amazon Linux 2 instances.

/home/ec2-user/amd_hsmp/amd_hsmp.c: In function ‘hsmp_ioctl’:
/home/ec2-user/amd_hsmp/amd_hsmp.c:264:6: error: implicit declaration of function ‘copy_struct_from_user’; did you mean ‘kstrtol_from_user’? [-Werror=implicit-function-declaration]
   if (copy_struct_from_user(&msg, sizeof(msg), arguser, sizeof(struct hsmp_message)))
      ^~~~~~~~~~~~~~~~~~~~~
      kstrtol_from_user
/home/ec2-user/amd_hsmp/amd_hsmp.c:307:7: error: implicit declaration of function ‘copy_to_user’; did you mean 
‘cpu_to_mem’? [-Werror=implicit-function-declaration]
   if (copy_to_user(arguser, &msg, sizeof(struct hsmp_message)))
       ^~~~~~~~~~~~
       cpu_to_mem

wkneewalden avatar Jun 08 '23 19:06 wkneewalden

Hi wkneewalden,

copy_to_user is available in 4.14 kernel. But, #include <linux/uaccess.h> needs to be added in amd_hsmp.c

From 5.2 kernel onwards, linux/uaccess.h is added by include/linux/sched/task.h file, so this was not needed to be added separately. Hence no compilation issue from 5.2 kernel onwards. giving below the header file inclusion list for your reference,

from ./include/linux/sched/task.h:11, from ./include/linux/sched/signal.h:9, from ./include/linux/rcuwait.h:6, from ./include/linux/percpu-rwsem.h:7, from ./include/linux/fs.h:33, from ./include/linux/huge_mm.h:8, from ./include/linux/mm.h:855, from ./include/linux/scatterlist.h:8, from ./include/linux/dmapool.h:14, from ./include/linux/pci.h:1554, from ./arch/x86/include/asm/amd_nb.h:6, from drivers/platform/x86/amd/hsmp.c:13:

But for kernels < 5.2 that header file inclusion is needed. So you will have to add below line in your amd_hsmp.c.

#include <linux/uaccess.h>

sumachidanand avatar Jun 09 '23 16:06 sumachidanand

Thanks! That solved the build issue. Tried installing and got errors in output:

make -C /lib/modules/`uname -r`/build M=$PWD modules_install
make[1]: Entering directory `/usr/src/kernels/4.14.314-238.539.amzn2.x86_64'
  INSTALL /home/ec2-user/amd_hsmp/amd_hsmp.ko
At main.c:167:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:182
sign-file: certs/signing_key.pem: No such file or directory
  DEPMOD  4.14.314-238.539.amzn2.x86_64
make[1]: Leaving directory `/usr/src/kernels/4.14.314-238.539.amzn2.x86_64'

Loading module gave this error:

modprobe: ERROR: could not insert 'amd_hsmp': No such device

Currently using a g4ad instance from AWS which supports GPU but is only 2nd generation AMD EPYC processors. No options are currently available that have GPU support and 3rd generation AMD if that is an issue.

wkneewalden avatar Jun 12 '23 22:06 wkneewalden

  • SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
  • SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:182 sign-file: certs/signing_key.pem: No such file or directory Looks like kernel config symbols related to KEYS are enabled. But, some packages required for the SSL functionality are missing in your environment.

modprobe: ERROR: could not insert 'amd_hsmp': No such device 2nd gen EPYC processors are not supported, hence the failure. This may not be related to the SSL errors above.

nchatrad avatar Jun 13 '23 04:06 nchatrad