Message ID | 20230119184349.74072-2-bchalios@amazon.es (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Herbert Xu |
Headers | show |
Series | virtio-rng entropy leak reporting feature | expand |
Hi Babis, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on char-misc/char-misc-testing] [also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.2-rc4 next-20230119] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Babis-Chalios/virtio-rng-implement-entropy-leak-feature/20230120-024631 patch link: https://lore.kernel.org/r/20230119184349.74072-2-bchalios%40amazon.es patch subject: [PATCH 1/2] virtio-rng: implement entropy leak feature config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230120/202301200407.n4URhGEQ-lkp@intel.com/config) compiler: hppa-linux-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/686114cbba5005584d458ad44164b4a4b88135f5 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Babis-Chalios/virtio-rng-implement-entropy-leak-feature/20230120-024631 git checkout 686114cbba5005584d458ad44164b4a4b88135f5 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=parisc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=parisc SHELL=/bin/bash drivers/char/hw_random/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): In file included from include/linux/err.h:8, from drivers/char/hw_random/virtio-rng.c:8: >> arch/parisc/include/uapi/asm/errno.h:7: warning: "ENOMSG" redefined 7 | #define ENOMSG 35 /* No message of desired type */ | In file included from drivers/char/hw_random/virtio-rng.c:7: include/uapi/asm-generic/errno.h:23: note: this is the location of the previous definition 23 | #define ENOMSG 42 /* No message of desired type */ | >> arch/parisc/include/uapi/asm/errno.h:8: warning: "EIDRM" redefined 8 | #define EIDRM 36 /* Identifier removed */ | include/uapi/asm-generic/errno.h:24: note: this is the location of the previous definition 24 | #define EIDRM 43 /* Identifier removed */ | >> arch/parisc/include/uapi/asm/errno.h:9: warning: "ECHRNG" redefined 9 | #define ECHRNG 37 /* Channel number out of range */ | include/uapi/asm-generic/errno.h:25: note: this is the location of the previous definition 25 | #define ECHRNG 44 /* Channel number out of range */ | >> arch/parisc/include/uapi/asm/errno.h:10: warning: "EL2NSYNC" redefined 10 | #define EL2NSYNC 38 /* Level 2 not synchronized */ | include/uapi/asm-generic/errno.h:26: note: this is the location of the previous definition 26 | #define EL2NSYNC 45 /* Level 2 not synchronized */ | >> arch/parisc/include/uapi/asm/errno.h:11: warning: "EL3HLT" redefined 11 | #define EL3HLT 39 /* Level 3 halted */ | include/uapi/asm-generic/errno.h:27: note: this is the location of the previous definition 27 | #define EL3HLT 46 /* Level 3 halted */ | >> arch/parisc/include/uapi/asm/errno.h:12: warning: "EL3RST" redefined 12 | #define EL3RST 40 /* Level 3 reset */ | include/uapi/asm-generic/errno.h:28: note: this is the location of the previous definition 28 | #define EL3RST 47 /* Level 3 reset */ | >> arch/parisc/include/uapi/asm/errno.h:13: warning: "ELNRNG" redefined 13 | #define ELNRNG 41 /* Link number out of range */ | include/uapi/asm-generic/errno.h:29: note: this is the location of the previous definition 29 | #define ELNRNG 48 /* Link number out of range */ | >> arch/parisc/include/uapi/asm/errno.h:14: warning: "EUNATCH" redefined 14 | #define EUNATCH 42 /* Protocol driver not attached */ | include/uapi/asm-generic/errno.h:30: note: this is the location of the previous definition 30 | #define EUNATCH 49 /* Protocol driver not attached */ | >> arch/parisc/include/uapi/asm/errno.h:15: warning: "ENOCSI" redefined 15 | #define ENOCSI 43 /* No CSI structure available */ | include/uapi/asm-generic/errno.h:31: note: this is the location of the previous definition 31 | #define ENOCSI 50 /* No CSI structure available */ | >> arch/parisc/include/uapi/asm/errno.h:16: warning: "EL2HLT" redefined 16 | #define EL2HLT 44 /* Level 2 halted */ | include/uapi/asm-generic/errno.h:32: note: this is the location of the previous definition 32 | #define EL2HLT 51 /* Level 2 halted */ | >> arch/parisc/include/uapi/asm/errno.h:17: warning: "EDEADLK" redefined 17 | #define EDEADLK 45 /* Resource deadlock would occur */ | include/uapi/asm-generic/errno.h:7: note: this is the location of the previous definition 7 | #define EDEADLK 35 /* Resource deadlock would occur */ | >> arch/parisc/include/uapi/asm/errno.h:19: warning: "ENOLCK" redefined 19 | #define ENOLCK 46 /* No record locks available */ | include/uapi/asm-generic/errno.h:9: note: this is the location of the previous definition 9 | #define ENOLCK 37 /* No record locks available */ | >> arch/parisc/include/uapi/asm/errno.h:20: warning: "EILSEQ" redefined 20 | #define EILSEQ 47 /* Illegal byte sequence */ | include/uapi/asm-generic/errno.h:67: note: this is the location of the previous definition 67 | #define EILSEQ 84 /* Illegal byte sequence */ | >> arch/parisc/include/uapi/asm/errno.h:22: warning: "ENONET" redefined 22 | #define ENONET 50 /* Machine is not on the network */ | include/uapi/asm-generic/errno.h:47: note: this is the location of the previous definition 47 | #define ENONET 64 /* Machine is not on the network */ | >> arch/parisc/include/uapi/asm/errno.h:23: warning: "ENODATA" redefined 23 | #define ENODATA 51 /* No data available */ | include/uapi/asm-generic/errno.h:44: note: this is the location of the previous definition 44 | #define ENODATA 61 /* No data available */ | >> arch/parisc/include/uapi/asm/errno.h:24: warning: "ETIME" redefined 24 | #define ETIME 52 /* Timer expired */ | include/uapi/asm-generic/errno.h:45: note: this is the location of the previous definition 45 | #define ETIME 62 /* Timer expired */ | >> arch/parisc/include/uapi/asm/errno.h:25: warning: "ENOSR" redefined 25 | #define ENOSR 53 /* Out of streams resources */ | include/uapi/asm-generic/errno.h:46: note: this is the location of the previous definition 46 | #define ENOSR 63 /* Out of streams resources */ | >> arch/parisc/include/uapi/asm/errno.h:26: warning: "ENOSTR" redefined 26 | #define ENOSTR 54 /* Device not a stream */ | include/uapi/asm-generic/errno.h:43: note: this is the location of the previous definition 43 | #define ENOSTR 60 /* Device not a stream */ | >> arch/parisc/include/uapi/asm/errno.h:27: warning: "ENOPKG" redefined 27 | #define ENOPKG 55 /* Package not installed */ | include/uapi/asm-generic/errno.h:48: note: this is the location of the previous definition 48 | #define ENOPKG 65 /* Package not installed */ | >> arch/parisc/include/uapi/asm/errno.h:29: warning: "ENOLINK" redefined 29 | #define ENOLINK 57 /* Link has been severed */ | include/uapi/asm-generic/errno.h:50: note: this is the location of the previous definition 50 | #define ENOLINK 67 /* Link has been severed */ | arch/parisc/include/uapi/asm/errno.h:30: warning: "EADV" redefined 30 | #define EADV 58 /* Advertise error */ | include/uapi/asm-generic/errno.h:51: note: this is the location of the previous definition 51 | #define EADV 68 /* Advertise error */ | arch/parisc/include/uapi/asm/errno.h:31: warning: "ESRMNT" redefined 31 | #define ESRMNT 59 /* Srmount error */ | include/uapi/asm-generic/errno.h:52: note: this is the location of the previous definition 52 | #define ESRMNT 69 /* Srmount error */ | arch/parisc/include/uapi/asm/errno.h:32: warning: "ECOMM" redefined 32 | #define ECOMM 60 /* Communication error on send */ | include/uapi/asm-generic/errno.h:53: note: this is the location of the previous definition 53 | #define ECOMM 70 /* Communication error on send */ | arch/parisc/include/uapi/asm/errno.h:33: warning: "EPROTO" redefined 33 | #define EPROTO 61 /* Protocol error */ | include/uapi/asm-generic/errno.h:54: note: this is the location of the previous definition 54 | #define EPROTO 71 /* Protocol error */ | arch/parisc/include/uapi/asm/errno.h:35: warning: "EMULTIHOP" redefined 35 | #define EMULTIHOP 64 /* Multihop attempted */ | include/uapi/asm-generic/errno.h:55: note: this is the location of the previous definition 55 | #define EMULTIHOP 72 /* Multihop attempted */ | arch/parisc/include/uapi/asm/errno.h:37: warning: "EDOTDOT" redefined 37 | #define EDOTDOT 66 /* RFS specific error */ | include/uapi/asm-generic/errno.h:56: note: this is the location of the previous definition 56 | #define EDOTDOT 73 /* RFS specific error */ | arch/parisc/include/uapi/asm/errno.h:38: warning: "EBADMSG" redefined 38 | #define EBADMSG 67 /* Not a data message */ | include/uapi/asm-generic/errno.h:57: note: this is the location of the previous definition 57 | #define EBADMSG 74 /* Not a data message */ | arch/parisc/include/uapi/asm/errno.h:39: warning: "EUSERS" redefined 39 | #define EUSERS 68 /* Too many users */ | include/uapi/asm-generic/errno.h:70: note: this is the location of the previous definition 70 | #define EUSERS 87 /* Too many users */ | arch/parisc/include/uapi/asm/errno.h:40: warning: "EDQUOT" redefined 40 | #define EDQUOT 69 /* Quota exceeded */ | include/uapi/asm-generic/errno.h:105: note: this is the location of the previous definition 105 | #define EDQUOT 122 /* Quota exceeded */ | arch/parisc/include/uapi/asm/errno.h:41: warning: "ESTALE" redefined 41 | #define ESTALE 70 /* Stale file handle */ | include/uapi/asm-generic/errno.h:99: note: this is the location of the previous definition 99 | #define ESTALE 116 /* Stale file handle */ | arch/parisc/include/uapi/asm/errno.h:42: warning: "EREMOTE" redefined 42 | #define EREMOTE 71 /* Object is remote */ | include/uapi/asm-generic/errno.h:49: note: this is the location of the previous definition 49 | #define EREMOTE 66 /* Object is remote */ | arch/parisc/include/uapi/asm/errno.h:43: warning: "EOVERFLOW" redefined 43 | #define EOVERFLOW 72 /* Value too large for defined data type */ | include/uapi/asm-generic/errno.h:58: note: this is the location of the previous definition 58 | #define EOVERFLOW 75 /* Value too large for defined data type */ | arch/parisc/include/uapi/asm/errno.h:47: warning: "EBADE" redefined 47 | #define EBADE 160 /* Invalid exchange */ | include/uapi/asm-generic/errno.h:33: note: this is the location of the previous definition 33 | #define EBADE 52 /* Invalid exchange */ | arch/parisc/include/uapi/asm/errno.h:48: warning: "EBADR" redefined 48 | #define EBADR 161 /* Invalid request descriptor */ | include/uapi/asm-generic/errno.h:34: note: this is the location of the previous definition 34 | #define EBADR 53 /* Invalid request descriptor */ | arch/parisc/include/uapi/asm/errno.h:49: warning: "EXFULL" redefined 49 | #define EXFULL 162 /* Exchange full */ | include/uapi/asm-generic/errno.h:35: note: this is the location of the previous definition 35 | #define EXFULL 54 /* Exchange full */ | arch/parisc/include/uapi/asm/errno.h:50: warning: "ENOANO" redefined 50 | #define ENOANO 163 /* No anode */ | include/uapi/asm-generic/errno.h:36: note: this is the location of the previous definition 36 | #define ENOANO 55 /* No anode */ vim +/ENOMSG +7 arch/parisc/include/uapi/asm/errno.h ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 6 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @7 #define ENOMSG 35 /* No message of desired type */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @8 #define EIDRM 36 /* Identifier removed */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @9 #define ECHRNG 37 /* Channel number out of range */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @10 #define EL2NSYNC 38 /* Level 2 not synchronized */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @11 #define EL3HLT 39 /* Level 3 halted */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @12 #define EL3RST 40 /* Level 3 reset */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @13 #define ELNRNG 41 /* Link number out of range */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @14 #define EUNATCH 42 /* Protocol driver not attached */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @15 #define ENOCSI 43 /* No CSI structure available */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @16 #define EL2HLT 44 /* Level 2 halted */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @17 #define EDEADLK 45 /* Resource deadlock would occur */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 18 #define EDEADLOCK EDEADLK ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @19 #define ENOLCK 46 /* No record locks available */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @20 #define EILSEQ 47 /* Illegal byte sequence */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 21 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @22 #define ENONET 50 /* Machine is not on the network */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @23 #define ENODATA 51 /* No data available */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @24 #define ETIME 52 /* Timer expired */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @25 #define ENOSR 53 /* Out of streams resources */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @26 #define ENOSTR 54 /* Device not a stream */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @27 #define ENOPKG 55 /* Package not installed */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 28 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @29 #define ENOLINK 57 /* Link has been severed */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @30 #define EADV 58 /* Advertise error */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @31 #define ESRMNT 59 /* Srmount error */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @32 #define ECOMM 60 /* Communication error on send */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @33 #define EPROTO 61 /* Protocol error */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 34 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @35 #define EMULTIHOP 64 /* Multihop attempted */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 36 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @37 #define EDOTDOT 66 /* RFS specific error */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @38 #define EBADMSG 67 /* Not a data message */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @39 #define EUSERS 68 /* Too many users */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @40 #define EDQUOT 69 /* Quota exceeded */ 0ca43435188b9f arch/parisc/include/uapi/asm/errno.h Eric Sandeen 2013-11-12 @41 #define ESTALE 70 /* Stale file handle */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @42 #define EREMOTE 71 /* Object is remote */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @43 #define EOVERFLOW 72 /* Value too large for defined data type */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 44 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 45 /* these errnos are defined by Linux but not HPUX. */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 46 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @47 #define EBADE 160 /* Invalid exchange */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @48 #define EBADR 161 /* Invalid request descriptor */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @49 #define EXFULL 162 /* Exchange full */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @50 #define ENOANO 163 /* No anode */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @51 #define EBADRQC 164 /* Invalid request code */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @52 #define EBADSLT 165 /* Invalid slot */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @53 #define EBFONT 166 /* Bad font file format */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @54 #define ENOTUNIQ 167 /* Name not unique on network */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @55 #define EBADFD 168 /* File descriptor in bad state */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @56 #define EREMCHG 169 /* Remote address changed */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @57 #define ELIBACC 170 /* Can not access a needed shared library */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @58 #define ELIBBAD 171 /* Accessing a corrupted shared library */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @59 #define ELIBSCN 172 /* .lib section in a.out corrupted */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @60 #define ELIBMAX 173 /* Attempting to link in too many shared libraries */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @61 #define ELIBEXEC 174 /* Cannot exec a shared library directly */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @62 #define ERESTART 175 /* Interrupted system call should be restarted */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @63 #define ESTRPIPE 176 /* Streams pipe error */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @64 #define EUCLEAN 177 /* Structure needs cleaning */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @65 #define ENOTNAM 178 /* Not a XENIX named type file */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @66 #define ENAVAIL 179 /* No XENIX semaphores available */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @67 #define EISNAM 180 /* Is a named type file */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @68 #define EREMOTEIO 181 /* Remote I/O error */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @69 #define ENOMEDIUM 182 /* No medium found */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @70 #define EMEDIUMTYPE 183 /* Wrong medium type */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @71 #define ENOKEY 184 /* Required key not available */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @72 #define EKEYEXPIRED 185 /* Key has expired */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @73 #define EKEYREVOKED 186 /* Key has been revoked */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @74 #define EKEYREJECTED 187 /* Key was rejected by service */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 75 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 76 /* We now return you to your regularly scheduled HPUX. */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 77 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 78 #define ENOSYM 215 /* symbol does not exist in executable */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @79 #define ENOTSOCK 216 /* Socket operation on non-socket */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @80 #define EDESTADDRREQ 217 /* Destination address required */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @81 #define EMSGSIZE 218 /* Message too long */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @82 #define EPROTOTYPE 219 /* Protocol wrong type for socket */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @83 #define ENOPROTOOPT 220 /* Protocol not available */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @84 #define EPROTONOSUPPORT 221 /* Protocol not supported */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @85 #define ESOCKTNOSUPPORT 222 /* Socket type not supported */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @86 #define EOPNOTSUPP 223 /* Operation not supported on transport endpoint */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @87 #define EPFNOSUPPORT 224 /* Protocol family not supported */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @88 #define EAFNOSUPPORT 225 /* Address family not supported by protocol */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @89 #define EADDRINUSE 226 /* Address already in use */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @90 #define EADDRNOTAVAIL 227 /* Cannot assign requested address */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @91 #define ENETDOWN 228 /* Network is down */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @92 #define ENETUNREACH 229 /* Network is unreachable */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @93 #define ENETRESET 230 /* Network dropped connection because of reset */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @94 #define ECONNABORTED 231 /* Software caused connection abort */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @95 #define ECONNRESET 232 /* Connection reset by peer */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @96 #define ENOBUFS 233 /* No buffer space available */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @97 #define EISCONN 234 /* Transport endpoint is already connected */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @98 #define ENOTCONN 235 /* Transport endpoint is not connected */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @99 #define ESHUTDOWN 236 /* Cannot send after transport endpoint shutdown */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @100 #define ETOOMANYREFS 237 /* Too many references: cannot splice */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @101 #define ETIMEDOUT 238 /* Connection timed out */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @102 #define ECONNREFUSED 239 /* Connection refused */ 3eb53b20d7bd13 arch/parisc/include/uapi/asm/errno.h Helge Deller 2016-08-20 103 #define EREFUSED ECONNREFUSED /* for HP's NFS apparently */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 104 #define EREMOTERELEASE 240 /* Remote peer released connection */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @105 #define EHOSTDOWN 241 /* Host is down */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @106 #define EHOSTUNREACH 242 /* No route to host */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 107 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @108 #define EALREADY 244 /* Operation already in progress */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @109 #define EINPROGRESS 245 /* Operation now in progress */ f5a408d53edef3 arch/parisc/include/uapi/asm/errno.h Guy Martin 2014-01-16 110 #define EWOULDBLOCK EAGAIN /* Operation would block (Not HPUX compliant) */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @111 #define ENOTEMPTY 247 /* Directory not empty */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @112 #define ENAMETOOLONG 248 /* File name too long */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @113 #define ELOOP 249 /* Too many symbolic links encountered */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 @114 #define ENOSYS 251 /* Function not implemented */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 115 ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 116 #define ECANCELLED 253 /* aio request was canceled before complete (POSIX.4 / HPUX) */ 05aa10de701409 include/asm-parisc/errno.h Grant Grundler 2005-10-21 @117 #define ECANCELED ECANCELLED /* SuSv3 and Solaris wants one 'L' */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 118 4750e2c0c59e0c include/asm-parisc/errno.h Joe Korty 2005-05-01 119 /* for robust mutexes */ 4750e2c0c59e0c include/asm-parisc/errno.h Joe Korty 2005-05-01 @120 #define EOWNERDEAD 254 /* Owner died */ 4750e2c0c59e0c include/asm-parisc/errno.h Joe Korty 2005-05-01 @121 #define ENOTRECOVERABLE 255 /* State not recoverable */ 4750e2c0c59e0c include/asm-parisc/errno.h Joe Korty 2005-05-01 122 7d217d7ffc3433 arch/parisc/include/asm/errno.h Alexander Beregalov 2009-06-07 @123 #define ERFKILL 256 /* Operation not possible due to RF-kill */ ^1da177e4c3f41 include/asm-parisc/errno.h Linus Torvalds 2005-04-16 124 69ebb83e13e514 arch/parisc/include/asm/errno.h Huang Ying 2011-01-30 @125 #define EHWPOISON 257 /* Memory page has hardware error */ 69ebb83e13e514 arch/parisc/include/asm/errno.h Huang Ying 2011-01-30 126
Hi Babis, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on char-misc/char-misc-testing] [also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.2-rc4 next-20230119] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Babis-Chalios/virtio-rng-implement-entropy-leak-feature/20230120-024631 patch link: https://lore.kernel.org/r/20230119184349.74072-2-bchalios%40amazon.es patch subject: [PATCH 1/2] virtio-rng: implement entropy leak feature config: x86_64-randconfig-s021 (https://download.01.org/0day-ci/archive/20230120/202301200941.fE9QkyE3-lkp@intel.com/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.4-39-gce1a6720-dirty # https://github.com/intel-lab-lkp/linux/commit/686114cbba5005584d458ad44164b4a4b88135f5 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Babis-Chalios/virtio-rng-implement-entropy-leak-feature/20230120-024631 git checkout 686114cbba5005584d458ad44164b4a4b88135f5 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/char/hw_random/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> sparse warnings: (new ones prefixed by >>) >> drivers/char/hw_random/virtio-rng.c:59:5: sparse: sparse: symbol 'add_fill_on_leak_request' was not declared. Should it be static? >> drivers/char/hw_random/virtio-rng.c:73:5: sparse: sparse: symbol 'virtrng_fill_on_leak' was not declared. Should it be static? >> drivers/char/hw_random/virtio-rng.c:94:5: sparse: sparse: symbol 'add_copy_on_leak_request' was not declared. Should it be static? >> drivers/char/hw_random/virtio-rng.c:113:5: sparse: sparse: symbol 'virtrng_copy_on_leak' was not declared. Should it be static?
On Thu, Jan 19, 2023 at 07:43:47PM +0100, Babis Chalios wrote: > Implement the virtio-rng feature that allows a guest driver to request > from the device to perform certain operations in the event of an > "entropy leak", such as when taking a VM snapshot or restoring a VM from > a snapshot. The guest can request one of two operations: (i) fill a > buffer with random bytes, or (ii) perform a memory copy between two > bytes. > > The feature is similar to Microsoft's Virtual Machine Generation ID and > it can be used to (1) avoid the race-condition that exists in our > current VMGENID implementation, between the time vcpus are resumed and > the ACPI notification is being handled and (2) provide mechanisms for > notifying user-space about snapshot-related events. > > This commit implements the protocol between guest and device. > Additionally, it makes sure there is always a request for random bytes > in the event of entropy leak in-flight. Once such an event is observed, > the driver feeds these bytes to as entropy using > `add_device_randomness`. > > Keep in mind that this commit does not solve the race-condition issue, > it adds fresh entropy whenever the driver handles the used buffer from > the fill-on-leak request. In order to close the race window, we need to > expose some API so that other kernel subsystems can request directly > notifications from the device. > > Signed-off-by: Babis Chalios <bchalios@amazon.es> > --- > drivers/char/hw_random/virtio-rng.c | 200 +++++++++++++++++++++++++++- > include/uapi/linux/virtio_rng.h | 3 + > 2 files changed, 197 insertions(+), 6 deletions(-) > > diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c > index a6f3a8a2aca6..389a091a8801 100644 > --- a/drivers/char/hw_random/virtio-rng.c > +++ b/drivers/char/hw_random/virtio-rng.c > @@ -4,12 +4,14 @@ > * Copyright (C) 2007, 2008 Rusty Russell IBM Corporation > */ > > +#include "asm-generic/errno.h" Why are you pulling this in? If you really need errno the thing to include is linux/errno.h checkpatch has a rule to catch such cases: # warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes # itself <asm/foo.h> (uses RAW line) did you run checkpatch? > #include <linux/err.h> > #include <linux/hw_random.h> > #include <linux/scatterlist.h> > #include <linux/spinlock.h> > #include <linux/virtio.h> > #include <linux/virtio_rng.h> > +#include <linux/random.h> > #include <linux/module.h> > #include <linux/slab.h> > > @@ -18,6 +20,12 @@ static DEFINE_IDA(rng_index_ida); > struct virtrng_info { > struct hwrng hwrng; > struct virtqueue *vq; > + /* Leak queues */ > + bool has_leakqs; > + struct virtqueue *leakq[2]; > + spinlock_t lock; > + int active_leakq; > + > char name[25]; > int index; > bool hwrng_register_done; > @@ -29,27 +37,159 @@ struct virtrng_info { > /* minimal size returned by rng_buffer_size() */ > #if SMP_CACHE_BYTES < 32 > u8 data[32]; > + u8 leak_data[32]; > #else > u8 data[SMP_CACHE_BYTES]; > + u8 leak_data[SMP_CACHE_BYTES]; > #endif > }; > > +/* Swaps the queues and returns the new active leak queue. */ > +static struct virtqueue *swap_leakqs(struct virtrng_info *vi) > +{ > + vi->active_leakq = 1 - vi->active_leakq; > + return vi->leakq[vi->active_leakq]; > +} > + > +static struct virtqueue *get_active_leakq(struct virtrng_info *vi) > +{ > + return vi->leakq[vi->active_leakq]; > +} > + > +int add_fill_on_leak_request(struct virtrng_info *vi, struct virtqueue *vq, void *data, size_t len) > +{ > + struct scatterlist sg; > + int ret; > + > + sg_init_one(&sg, data, len); > + ret = virtqueue_add_inbuf(vq, &sg, 1, data, GFP_KERNEL); > + if (ret) > + goto err; > + > +err: > + return ret; > +} > + > +int virtrng_fill_on_leak(struct virtrng_info *vi, void *data, size_t len) > +{ > + struct virtqueue *vq; > + unsigned long flags; > + int ret; > + > + if (!vi->has_leakqs) > + return -EOPNOTSUPP; > + > + spin_lock_irqsave(&vi->lock, flags); > + > + vq = get_active_leakq(vi); > + ret = add_fill_on_leak_request(vi, vq, data, len); > + if (ret) > + virtqueue_kick(vq); > + > + spin_unlock_irqrestore(&vi->lock, flags); > + > + return ret; > +} > + > +int add_copy_on_leak_request(struct virtrng_info *vi, struct virtqueue *vq, > + void *to, void *from, size_t len) > +{ > + int ret; > + struct scatterlist out, in, *sgs[2]; > + > + sg_init_one(&out, from, len); > + sgs[0] = &out; > + sg_init_one(&in, to, len); > + sgs[1] = ∈ > + > + ret = virtqueue_add_sgs(vq, sgs, 1, 1, to, GFP_KERNEL); > + if (ret) > + goto err; > + > +err: > + return ret; > +} > + > +int virtrng_copy_on_leak(struct virtrng_info *vi, void *to, void *from, size_t len) > +{ > + struct virtqueue *vq; > + unsigned long flags; > + int ret; > + > + if (!vi->has_leakqs) > + return -EOPNOTSUPP; > + > + spin_lock_irqsave(&vi->lock, flags); > + > + vq = get_active_leakq(vi); > + ret = add_copy_on_leak_request(vi, vq, to, from, len); > + if (ret) > + virtqueue_kick(vq); > + > + spin_unlock_irqrestore(&vi->lock, flags); > + > + return ret; > +} > + > +static void entropy_leak_detected(struct virtqueue *vq) > +{ > + struct virtrng_info *vi = vq->vdev->priv; > + struct virtqueue *activeq; > + unsigned int len; > + unsigned long flags; > + void *buffer; > + bool kick_activeq = false; > + > + spin_lock_irqsave(&vi->lock, flags); > + > + activeq = get_active_leakq(vi); > + /* Drain all the used buffers from the queue */ > + while ((buffer = virtqueue_get_buf(vq, &len)) != NULL) { > + if (vq == activeq) { > + pr_debug("%s: entropy leak detected!", vi->name); > + activeq = swap_leakqs(vi); > + } > + > + if (buffer == vi->leak_data) { > + add_device_randomness(vi->leak_data, sizeof(vi->leak_data)); > + > + /* Ensure we always have a pending request for random bytes on entropy > + * leak. Do it here, after we have swapped leak queues, so it gets handled > + * with the next entropy leak event. > + */ > + add_fill_on_leak_request(vi, activeq, vi->leak_data, sizeof(vi->leak_data)); > + kick_activeq = true; > + } > + } > + > + if (kick_activeq) > + virtqueue_kick(activeq); > + > + spin_unlock_irqrestore(&vi->lock, flags); > +} > + > static void random_recv_done(struct virtqueue *vq) > { > struct virtrng_info *vi = vq->vdev->priv; > + unsigned long flags; > > + spin_lock_irqsave(&vi->lock, flags); > /* We can get spurious callbacks, e.g. shared IRQs + virtio_pci. */ > if (!virtqueue_get_buf(vi->vq, &vi->data_avail)) > - return; > + goto unlock; > > vi->data_idx = 0; > > complete(&vi->have_data); > + > +unlock: > + spin_unlock_irqrestore(&vi->lock, flags); > } > > static void request_entropy(struct virtrng_info *vi) > { > struct scatterlist sg; > + unsigned long flags; > > reinit_completion(&vi->have_data); > vi->data_avail = 0; > @@ -57,10 +197,12 @@ static void request_entropy(struct virtrng_info *vi) > > sg_init_one(&sg, vi->data, sizeof(vi->data)); > > + spin_lock_irqsave(&vi->lock, flags); > /* There should always be room for one buffer. */ > virtqueue_add_inbuf(vi->vq, &sg, 1, vi->data, GFP_KERNEL); > > virtqueue_kick(vi->vq); > + spin_unlock_irqrestore(&vi->lock, flags); > } > > static unsigned int copy_data(struct virtrng_info *vi, void *buf, > @@ -126,6 +268,40 @@ static void virtio_cleanup(struct hwrng *rng) > complete(&vi->have_data); > } > > +static int init_virtqueues(struct virtrng_info *vi, struct virtio_device *vdev) > +{ > + int ret = -ENOMEM, total_vqs = 1; > + struct virtqueue *vqs[3]; > + const char *names[3]; > + vq_callback_t *callbacks[3]; > + > + if (vi->has_leakqs) > + total_vqs = 3; > + > + callbacks[0] = random_recv_done; > + names[0] = "input"; > + if (vi->has_leakqs) { > + callbacks[1] = entropy_leak_detected; > + names[1] = "leakq.1"; > + callbacks[2] = entropy_leak_detected; > + names[2] = "leakq.2"; > + } > + > + ret = virtio_find_vqs(vdev, total_vqs, vqs, callbacks, names, NULL); > + if (ret) > + goto err; > + > + vi->vq = vqs[0]; > + > + if (vi->has_leakqs) { > + vi->leakq[0] = vqs[1]; > + vi->leakq[1] = vqs[2]; > + } > + > +err: > + return ret; > +} > + > static int probe_common(struct virtio_device *vdev) > { > int err, index; > @@ -152,18 +328,24 @@ static int probe_common(struct virtio_device *vdev) > }; > vdev->priv = vi; > > - /* We expect a single virtqueue. */ > - vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input"); > - if (IS_ERR(vi->vq)) { > - err = PTR_ERR(vi->vq); > - goto err_find; > + vi->has_leakqs = virtio_has_feature(vdev, VIRTIO_RNG_F_LEAK); > + if (vi->has_leakqs) { > + spin_lock_init(&vi->lock); > + vi->active_leakq = 0; > } > > + err = init_virtqueues(vi, vdev); > + if (err) > + goto err_find; > + > virtio_device_ready(vdev); > > /* we always have a pending entropy request */ > request_entropy(vi); > > + /* we always have a fill_on_leak request pending */ > + virtrng_fill_on_leak(vi, vi->leak_data, sizeof(vi->leak_data)); > + > return 0; > > err_find: > @@ -246,7 +428,13 @@ static const struct virtio_device_id id_table[] = { > { 0 }, > }; > > +static unsigned int features[] = { > + VIRTIO_RNG_F_LEAK, > +}; > + > static struct virtio_driver virtio_rng_driver = { > + .feature_table = features, > + .feature_table_size = ARRAY_SIZE(features), > .driver.name = KBUILD_MODNAME, > .driver.owner = THIS_MODULE, > .id_table = id_table, > diff --git a/include/uapi/linux/virtio_rng.h b/include/uapi/linux/virtio_rng.h > index c4d5de896f0c..d9774951547e 100644 > --- a/include/uapi/linux/virtio_rng.h > +++ b/include/uapi/linux/virtio_rng.h > @@ -5,4 +5,7 @@ > #include <linux/virtio_ids.h> > #include <linux/virtio_config.h> > > +/* The feature bitmap for virtio entropy device */ > +#define VIRTIO_RNG_F_LEAK 0 > + > #endif /* _LINUX_VIRTIO_RNG_H */ > -- > 2.38.1 > > Amazon Spain Services sociedad limitada unipersonal, Calle Ramirez de Prado 5, 28045 Madrid. Registro Mercantil de Madrid . Tomo 22458 . Folio 102 . Hoja M-401234 . CIF B84570936
On 20/1/23 13:32, Michael S. Tsirkin wrote: > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe. > > > > On Thu, Jan 19, 2023 at 07:43:47PM +0100, Babis Chalios wrote: >> Implement the virtio-rng feature that allows a guest driver to request >> from the device to perform certain operations in the event of an >> "entropy leak", such as when taking a VM snapshot or restoring a VM from >> a snapshot. The guest can request one of two operations: (i) fill a >> buffer with random bytes, or (ii) perform a memory copy between two >> bytes. >> >> The feature is similar to Microsoft's Virtual Machine Generation ID and >> it can be used to (1) avoid the race-condition that exists in our >> current VMGENID implementation, between the time vcpus are resumed and >> the ACPI notification is being handled and (2) provide mechanisms for >> notifying user-space about snapshot-related events. >> >> This commit implements the protocol between guest and device. >> Additionally, it makes sure there is always a request for random bytes >> in the event of entropy leak in-flight. Once such an event is observed, >> the driver feeds these bytes to as entropy using >> `add_device_randomness`. >> >> Keep in mind that this commit does not solve the race-condition issue, >> it adds fresh entropy whenever the driver handles the used buffer from >> the fill-on-leak request. In order to close the race window, we need to >> expose some API so that other kernel subsystems can request directly >> notifications from the device. >> >> Signed-off-by: Babis Chalios <bchalios@amazon.es> >> --- >> drivers/char/hw_random/virtio-rng.c | 200 +++++++++++++++++++++++++++- >> include/uapi/linux/virtio_rng.h | 3 + >> 2 files changed, 197 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c >> index a6f3a8a2aca6..389a091a8801 100644 >> --- a/drivers/char/hw_random/virtio-rng.c >> +++ b/drivers/char/hw_random/virtio-rng.c >> @@ -4,12 +4,14 @@ >> * Copyright (C) 2007, 2008 Rusty Russell IBM Corporation >> */ >> >> +#include "asm-generic/errno.h" > Why are you pulling this in? > If you really need errno the thing to include > is linux/errno.h > > checkpatch has a rule to catch such cases: > > # warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes > # itself <asm/foo.h> (uses RAW line) > > did you run checkpatch? > You are right, this is wrong. I think my LSP client pulled this in and I missed it because, strangely enough, I did ran checkpatch but it didn't complain about it. >> #include <linux/err.h> >> #include <linux/hw_random.h> >> #include <linux/scatterlist.h> >> #include <linux/spinlock.h> >> #include <linux/virtio.h> >> #include <linux/virtio_rng.h> >> +#include <linux/random.h> >> #include <linux/module.h> >> #include <linux/slab.h> >> >> @@ -18,6 +20,12 @@ static DEFINE_IDA(rng_index_ida); >> struct virtrng_info { >> struct hwrng hwrng; >> struct virtqueue *vq; >> + /* Leak queues */ >> + bool has_leakqs; >> + struct virtqueue *leakq[2]; >> + spinlock_t lock; >> + int active_leakq; >> + >> char name[25]; >> int index; >> bool hwrng_register_done; >> @@ -29,27 +37,159 @@ struct virtrng_info { >> /* minimal size returned by rng_buffer_size() */ >> #if SMP_CACHE_BYTES < 32 >> u8 data[32]; >> + u8 leak_data[32]; >> #else >> u8 data[SMP_CACHE_BYTES]; >> + u8 leak_data[SMP_CACHE_BYTES]; >> #endif >> }; >> >> +/* Swaps the queues and returns the new active leak queue. */ >> +static struct virtqueue *swap_leakqs(struct virtrng_info *vi) >> +{ >> + vi->active_leakq = 1 - vi->active_leakq; >> + return vi->leakq[vi->active_leakq]; >> +} >> + >> +static struct virtqueue *get_active_leakq(struct virtrng_info *vi) >> +{ >> + return vi->leakq[vi->active_leakq]; >> +} >> + >> +int add_fill_on_leak_request(struct virtrng_info *vi, struct virtqueue *vq, void *data, size_t len) >> +{ >> + struct scatterlist sg; >> + int ret; >> + >> + sg_init_one(&sg, data, len); >> + ret = virtqueue_add_inbuf(vq, &sg, 1, data, GFP_KERNEL); >> + if (ret) >> + goto err; >> + >> +err: >> + return ret; >> +} >> + >> +int virtrng_fill_on_leak(struct virtrng_info *vi, void *data, size_t len) >> +{ >> + struct virtqueue *vq; >> + unsigned long flags; >> + int ret; >> + >> + if (!vi->has_leakqs) >> + return -EOPNOTSUPP; >> + >> + spin_lock_irqsave(&vi->lock, flags); >> + >> + vq = get_active_leakq(vi); >> + ret = add_fill_on_leak_request(vi, vq, data, len); >> + if (ret) >> + virtqueue_kick(vq); >> + >> + spin_unlock_irqrestore(&vi->lock, flags); >> + >> + return ret; >> +} >> + >> +int add_copy_on_leak_request(struct virtrng_info *vi, struct virtqueue *vq, >> + void *to, void *from, size_t len) >> +{ >> + int ret; >> + struct scatterlist out, in, *sgs[2]; >> + >> + sg_init_one(&out, from, len); >> + sgs[0] = &out; >> + sg_init_one(&in, to, len); >> + sgs[1] = ∈ >> + >> + ret = virtqueue_add_sgs(vq, sgs, 1, 1, to, GFP_KERNEL); >> + if (ret) >> + goto err; >> + >> +err: >> + return ret; >> +} >> + >> +int virtrng_copy_on_leak(struct virtrng_info *vi, void *to, void *from, size_t len) >> +{ >> + struct virtqueue *vq; >> + unsigned long flags; >> + int ret; >> + >> + if (!vi->has_leakqs) >> + return -EOPNOTSUPP; >> + >> + spin_lock_irqsave(&vi->lock, flags); >> + >> + vq = get_active_leakq(vi); >> + ret = add_copy_on_leak_request(vi, vq, to, from, len); >> + if (ret) >> + virtqueue_kick(vq); >> + >> + spin_unlock_irqrestore(&vi->lock, flags); >> + >> + return ret; >> +} >> + >> +static void entropy_leak_detected(struct virtqueue *vq) >> +{ >> + struct virtrng_info *vi = vq->vdev->priv; >> + struct virtqueue *activeq; >> + unsigned int len; >> + unsigned long flags; >> + void *buffer; >> + bool kick_activeq = false; >> + >> + spin_lock_irqsave(&vi->lock, flags); >> + >> + activeq = get_active_leakq(vi); >> + /* Drain all the used buffers from the queue */ >> + while ((buffer = virtqueue_get_buf(vq, &len)) != NULL) { >> + if (vq == activeq) { >> + pr_debug("%s: entropy leak detected!", vi->name); >> + activeq = swap_leakqs(vi); >> + } >> + >> + if (buffer == vi->leak_data) { >> + add_device_randomness(vi->leak_data, sizeof(vi->leak_data)); >> + >> + /* Ensure we always have a pending request for random bytes on entropy >> + * leak. Do it here, after we have swapped leak queues, so it gets handled >> + * with the next entropy leak event. >> + */ >> + add_fill_on_leak_request(vi, activeq, vi->leak_data, sizeof(vi->leak_data)); >> + kick_activeq = true; >> + } >> + } >> + >> + if (kick_activeq) >> + virtqueue_kick(activeq); >> + >> + spin_unlock_irqrestore(&vi->lock, flags); >> +} >> + >> static void random_recv_done(struct virtqueue *vq) >> { >> struct virtrng_info *vi = vq->vdev->priv; >> + unsigned long flags; >> >> + spin_lock_irqsave(&vi->lock, flags); >> /* We can get spurious callbacks, e.g. shared IRQs + virtio_pci. */ >> if (!virtqueue_get_buf(vi->vq, &vi->data_avail)) >> - return; >> + goto unlock; >> >> vi->data_idx = 0; >> >> complete(&vi->have_data); >> + >> +unlock: >> + spin_unlock_irqrestore(&vi->lock, flags); >> } >> >> static void request_entropy(struct virtrng_info *vi) >> { >> struct scatterlist sg; >> + unsigned long flags; >> >> reinit_completion(&vi->have_data); >> vi->data_avail = 0; >> @@ -57,10 +197,12 @@ static void request_entropy(struct virtrng_info *vi) >> >> sg_init_one(&sg, vi->data, sizeof(vi->data)); >> >> + spin_lock_irqsave(&vi->lock, flags); >> /* There should always be room for one buffer. */ >> virtqueue_add_inbuf(vi->vq, &sg, 1, vi->data, GFP_KERNEL); >> >> virtqueue_kick(vi->vq); >> + spin_unlock_irqrestore(&vi->lock, flags); >> } >> >> static unsigned int copy_data(struct virtrng_info *vi, void *buf, >> @@ -126,6 +268,40 @@ static void virtio_cleanup(struct hwrng *rng) >> complete(&vi->have_data); >> } >> >> +static int init_virtqueues(struct virtrng_info *vi, struct virtio_device *vdev) >> +{ >> + int ret = -ENOMEM, total_vqs = 1; >> + struct virtqueue *vqs[3]; >> + const char *names[3]; >> + vq_callback_t *callbacks[3]; >> + >> + if (vi->has_leakqs) >> + total_vqs = 3; >> + >> + callbacks[0] = random_recv_done; >> + names[0] = "input"; >> + if (vi->has_leakqs) { >> + callbacks[1] = entropy_leak_detected; >> + names[1] = "leakq.1"; >> + callbacks[2] = entropy_leak_detected; >> + names[2] = "leakq.2"; >> + } >> + >> + ret = virtio_find_vqs(vdev, total_vqs, vqs, callbacks, names, NULL); >> + if (ret) >> + goto err; >> + >> + vi->vq = vqs[0]; >> + >> + if (vi->has_leakqs) { >> + vi->leakq[0] = vqs[1]; >> + vi->leakq[1] = vqs[2]; >> + } >> + >> +err: >> + return ret; >> +} >> + >> static int probe_common(struct virtio_device *vdev) >> { >> int err, index; >> @@ -152,18 +328,24 @@ static int probe_common(struct virtio_device *vdev) >> }; >> vdev->priv = vi; >> >> - /* We expect a single virtqueue. */ >> - vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input"); >> - if (IS_ERR(vi->vq)) { >> - err = PTR_ERR(vi->vq); >> - goto err_find; >> + vi->has_leakqs = virtio_has_feature(vdev, VIRTIO_RNG_F_LEAK); >> + if (vi->has_leakqs) { >> + spin_lock_init(&vi->lock); >> + vi->active_leakq = 0; >> } >> >> + err = init_virtqueues(vi, vdev); >> + if (err) >> + goto err_find; >> + >> virtio_device_ready(vdev); >> >> /* we always have a pending entropy request */ >> request_entropy(vi); >> >> + /* we always have a fill_on_leak request pending */ >> + virtrng_fill_on_leak(vi, vi->leak_data, sizeof(vi->leak_data)); >> + >> return 0; >> >> err_find: >> @@ -246,7 +428,13 @@ static const struct virtio_device_id id_table[] = { >> { 0 }, >> }; >> >> +static unsigned int features[] = { >> + VIRTIO_RNG_F_LEAK, >> +}; >> + >> static struct virtio_driver virtio_rng_driver = { >> + .feature_table = features, >> + .feature_table_size = ARRAY_SIZE(features), >> .driver.name = KBUILD_MODNAME, >> .driver.owner = THIS_MODULE, >> .id_table = id_table, >> diff --git a/include/uapi/linux/virtio_rng.h b/include/uapi/linux/virtio_rng.h >> index c4d5de896f0c..d9774951547e 100644 >> --- a/include/uapi/linux/virtio_rng.h >> +++ b/include/uapi/linux/virtio_rng.h >> @@ -5,4 +5,7 @@ >> #include <linux/virtio_ids.h> >> #include <linux/virtio_config.h> >> >> +/* The feature bitmap for virtio entropy device */ >> +#define VIRTIO_RNG_F_LEAK 0 >> + >> #endif /* _LINUX_VIRTIO_RNG_H */ >> -- >> 2.38.1 >> >> Amazon Spain Services sociedad limitada unipersonal, Calle Ramirez de Prado 5, 28045 Madrid. Registro Mercantil de Madrid . Tomo 22458 . Folio 102 . Hoja M-401234 . CIF B84570936 Amazon Spain Services sociedad limitada unipersonal, Calle Ramirez de Prado 5, 28045 Madrid. Registro Mercantil de Madrid . Tomo 22458 . Folio 102 . Hoja M-401234 . CIF B84570936
> > +#include "asm-generic/errno.h" > > Why are you pulling this in? > If you really need errno the thing to include > is linux/errno.h > > checkpatch has a rule to catch such cases: > > # warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes > # itself <asm/foo.h> (uses RAW line) It's only looking for asm, not variations like asm-generic.
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index a6f3a8a2aca6..389a091a8801 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -4,12 +4,14 @@ * Copyright (C) 2007, 2008 Rusty Russell IBM Corporation */ +#include "asm-generic/errno.h" #include <linux/err.h> #include <linux/hw_random.h> #include <linux/scatterlist.h> #include <linux/spinlock.h> #include <linux/virtio.h> #include <linux/virtio_rng.h> +#include <linux/random.h> #include <linux/module.h> #include <linux/slab.h> @@ -18,6 +20,12 @@ static DEFINE_IDA(rng_index_ida); struct virtrng_info { struct hwrng hwrng; struct virtqueue *vq; + /* Leak queues */ + bool has_leakqs; + struct virtqueue *leakq[2]; + spinlock_t lock; + int active_leakq; + char name[25]; int index; bool hwrng_register_done; @@ -29,27 +37,159 @@ struct virtrng_info { /* minimal size returned by rng_buffer_size() */ #if SMP_CACHE_BYTES < 32 u8 data[32]; + u8 leak_data[32]; #else u8 data[SMP_CACHE_BYTES]; + u8 leak_data[SMP_CACHE_BYTES]; #endif }; +/* Swaps the queues and returns the new active leak queue. */ +static struct virtqueue *swap_leakqs(struct virtrng_info *vi) +{ + vi->active_leakq = 1 - vi->active_leakq; + return vi->leakq[vi->active_leakq]; +} + +static struct virtqueue *get_active_leakq(struct virtrng_info *vi) +{ + return vi->leakq[vi->active_leakq]; +} + +int add_fill_on_leak_request(struct virtrng_info *vi, struct virtqueue *vq, void *data, size_t len) +{ + struct scatterlist sg; + int ret; + + sg_init_one(&sg, data, len); + ret = virtqueue_add_inbuf(vq, &sg, 1, data, GFP_KERNEL); + if (ret) + goto err; + +err: + return ret; +} + +int virtrng_fill_on_leak(struct virtrng_info *vi, void *data, size_t len) +{ + struct virtqueue *vq; + unsigned long flags; + int ret; + + if (!vi->has_leakqs) + return -EOPNOTSUPP; + + spin_lock_irqsave(&vi->lock, flags); + + vq = get_active_leakq(vi); + ret = add_fill_on_leak_request(vi, vq, data, len); + if (ret) + virtqueue_kick(vq); + + spin_unlock_irqrestore(&vi->lock, flags); + + return ret; +} + +int add_copy_on_leak_request(struct virtrng_info *vi, struct virtqueue *vq, + void *to, void *from, size_t len) +{ + int ret; + struct scatterlist out, in, *sgs[2]; + + sg_init_one(&out, from, len); + sgs[0] = &out; + sg_init_one(&in, to, len); + sgs[1] = ∈ + + ret = virtqueue_add_sgs(vq, sgs, 1, 1, to, GFP_KERNEL); + if (ret) + goto err; + +err: + return ret; +} + +int virtrng_copy_on_leak(struct virtrng_info *vi, void *to, void *from, size_t len) +{ + struct virtqueue *vq; + unsigned long flags; + int ret; + + if (!vi->has_leakqs) + return -EOPNOTSUPP; + + spin_lock_irqsave(&vi->lock, flags); + + vq = get_active_leakq(vi); + ret = add_copy_on_leak_request(vi, vq, to, from, len); + if (ret) + virtqueue_kick(vq); + + spin_unlock_irqrestore(&vi->lock, flags); + + return ret; +} + +static void entropy_leak_detected(struct virtqueue *vq) +{ + struct virtrng_info *vi = vq->vdev->priv; + struct virtqueue *activeq; + unsigned int len; + unsigned long flags; + void *buffer; + bool kick_activeq = false; + + spin_lock_irqsave(&vi->lock, flags); + + activeq = get_active_leakq(vi); + /* Drain all the used buffers from the queue */ + while ((buffer = virtqueue_get_buf(vq, &len)) != NULL) { + if (vq == activeq) { + pr_debug("%s: entropy leak detected!", vi->name); + activeq = swap_leakqs(vi); + } + + if (buffer == vi->leak_data) { + add_device_randomness(vi->leak_data, sizeof(vi->leak_data)); + + /* Ensure we always have a pending request for random bytes on entropy + * leak. Do it here, after we have swapped leak queues, so it gets handled + * with the next entropy leak event. + */ + add_fill_on_leak_request(vi, activeq, vi->leak_data, sizeof(vi->leak_data)); + kick_activeq = true; + } + } + + if (kick_activeq) + virtqueue_kick(activeq); + + spin_unlock_irqrestore(&vi->lock, flags); +} + static void random_recv_done(struct virtqueue *vq) { struct virtrng_info *vi = vq->vdev->priv; + unsigned long flags; + spin_lock_irqsave(&vi->lock, flags); /* We can get spurious callbacks, e.g. shared IRQs + virtio_pci. */ if (!virtqueue_get_buf(vi->vq, &vi->data_avail)) - return; + goto unlock; vi->data_idx = 0; complete(&vi->have_data); + +unlock: + spin_unlock_irqrestore(&vi->lock, flags); } static void request_entropy(struct virtrng_info *vi) { struct scatterlist sg; + unsigned long flags; reinit_completion(&vi->have_data); vi->data_avail = 0; @@ -57,10 +197,12 @@ static void request_entropy(struct virtrng_info *vi) sg_init_one(&sg, vi->data, sizeof(vi->data)); + spin_lock_irqsave(&vi->lock, flags); /* There should always be room for one buffer. */ virtqueue_add_inbuf(vi->vq, &sg, 1, vi->data, GFP_KERNEL); virtqueue_kick(vi->vq); + spin_unlock_irqrestore(&vi->lock, flags); } static unsigned int copy_data(struct virtrng_info *vi, void *buf, @@ -126,6 +268,40 @@ static void virtio_cleanup(struct hwrng *rng) complete(&vi->have_data); } +static int init_virtqueues(struct virtrng_info *vi, struct virtio_device *vdev) +{ + int ret = -ENOMEM, total_vqs = 1; + struct virtqueue *vqs[3]; + const char *names[3]; + vq_callback_t *callbacks[3]; + + if (vi->has_leakqs) + total_vqs = 3; + + callbacks[0] = random_recv_done; + names[0] = "input"; + if (vi->has_leakqs) { + callbacks[1] = entropy_leak_detected; + names[1] = "leakq.1"; + callbacks[2] = entropy_leak_detected; + names[2] = "leakq.2"; + } + + ret = virtio_find_vqs(vdev, total_vqs, vqs, callbacks, names, NULL); + if (ret) + goto err; + + vi->vq = vqs[0]; + + if (vi->has_leakqs) { + vi->leakq[0] = vqs[1]; + vi->leakq[1] = vqs[2]; + } + +err: + return ret; +} + static int probe_common(struct virtio_device *vdev) { int err, index; @@ -152,18 +328,24 @@ static int probe_common(struct virtio_device *vdev) }; vdev->priv = vi; - /* We expect a single virtqueue. */ - vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input"); - if (IS_ERR(vi->vq)) { - err = PTR_ERR(vi->vq); - goto err_find; + vi->has_leakqs = virtio_has_feature(vdev, VIRTIO_RNG_F_LEAK); + if (vi->has_leakqs) { + spin_lock_init(&vi->lock); + vi->active_leakq = 0; } + err = init_virtqueues(vi, vdev); + if (err) + goto err_find; + virtio_device_ready(vdev); /* we always have a pending entropy request */ request_entropy(vi); + /* we always have a fill_on_leak request pending */ + virtrng_fill_on_leak(vi, vi->leak_data, sizeof(vi->leak_data)); + return 0; err_find: @@ -246,7 +428,13 @@ static const struct virtio_device_id id_table[] = { { 0 }, }; +static unsigned int features[] = { + VIRTIO_RNG_F_LEAK, +}; + static struct virtio_driver virtio_rng_driver = { + .feature_table = features, + .feature_table_size = ARRAY_SIZE(features), .driver.name = KBUILD_MODNAME, .driver.owner = THIS_MODULE, .id_table = id_table, diff --git a/include/uapi/linux/virtio_rng.h b/include/uapi/linux/virtio_rng.h index c4d5de896f0c..d9774951547e 100644 --- a/include/uapi/linux/virtio_rng.h +++ b/include/uapi/linux/virtio_rng.h @@ -5,4 +5,7 @@ #include <linux/virtio_ids.h> #include <linux/virtio_config.h> +/* The feature bitmap for virtio entropy device */ +#define VIRTIO_RNG_F_LEAK 0 + #endif /* _LINUX_VIRTIO_RNG_H */
Implement the virtio-rng feature that allows a guest driver to request from the device to perform certain operations in the event of an "entropy leak", such as when taking a VM snapshot or restoring a VM from a snapshot. The guest can request one of two operations: (i) fill a buffer with random bytes, or (ii) perform a memory copy between two bytes. The feature is similar to Microsoft's Virtual Machine Generation ID and it can be used to (1) avoid the race-condition that exists in our current VMGENID implementation, between the time vcpus are resumed and the ACPI notification is being handled and (2) provide mechanisms for notifying user-space about snapshot-related events. This commit implements the protocol between guest and device. Additionally, it makes sure there is always a request for random bytes in the event of entropy leak in-flight. Once such an event is observed, the driver feeds these bytes to as entropy using `add_device_randomness`. Keep in mind that this commit does not solve the race-condition issue, it adds fresh entropy whenever the driver handles the used buffer from the fill-on-leak request. In order to close the race window, we need to expose some API so that other kernel subsystems can request directly notifications from the device. Signed-off-by: Babis Chalios <bchalios@amazon.es> --- drivers/char/hw_random/virtio-rng.c | 200 +++++++++++++++++++++++++++- include/uapi/linux/virtio_rng.h | 3 + 2 files changed, 197 insertions(+), 6 deletions(-)