~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm64/kvm/trng.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/arm64/kvm/trng.c (Architecture m68k) and /arch/ppc/kvm/trng.c (Architecture ppc)


  1 // SPDX-License-Identifier: GPL-2.0                 1 
  2 // Copyright (C) 2020 Arm Ltd.                    
  3                                                   
  4 #include <linux/arm-smccc.h>                      
  5 #include <linux/kvm_host.h>                       
  6                                                   
  7 #include <asm/kvm_emulate.h>                      
  8                                                   
  9 #include <kvm/arm_hypercalls.h>                   
 10                                                   
 11 #define ARM_SMCCC_TRNG_VERSION_1_0      0x1000    
 12                                                   
 13 /* Those values are deliberately separate from    
 14 #define TRNG_SUCCESS                    0UL       
 15 #define TRNG_NOT_SUPPORTED              ((unsi    
 16 #define TRNG_INVALID_PARAMETER          ((unsi    
 17 #define TRNG_NO_ENTROPY                 ((unsi    
 18                                                   
 19 #define TRNG_MAX_BITS64                 192       
 20                                                   
 21 static const uuid_t arm_smc_trng_uuid __aligne    
 22         0x0d21e000, 0x4384, 0x11eb, 0x80, 0x70    
 23                                                   
 24 static int kvm_trng_do_rnd(struct kvm_vcpu *vc    
 25 {                                                 
 26         DECLARE_BITMAP(bits, TRNG_MAX_BITS64);    
 27         u32 num_bits = smccc_get_arg1(vcpu);      
 28         int i;                                    
 29                                                   
 30         if (num_bits > 3 * size) {                
 31                 smccc_set_retval(vcpu, TRNG_IN    
 32                 return 1;                         
 33         }                                         
 34                                                   
 35         /* get as many bits as we need to fulf    
 36         for (i = 0; i < DIV_ROUND_UP(num_bits,    
 37                 bits[i] = get_random_long();      
 38                                                   
 39         bitmap_clear(bits, num_bits, TRNG_MAX_    
 40                                                   
 41         if (size == 32)                           
 42                 smccc_set_retval(vcpu, TRNG_SU    
 43                                  upper_32_bits    
 44         else                                      
 45                 smccc_set_retval(vcpu, TRNG_SU    
 46                                                   
 47         memzero_explicit(bits, sizeof(bits));     
 48         return 1;                                 
 49 }                                                 
 50                                                   
 51 int kvm_trng_call(struct kvm_vcpu *vcpu)          
 52 {                                                 
 53         const __le32 *u = (__le32 *)arm_smc_tr    
 54         u32 func_id = smccc_get_function(vcpu)    
 55         unsigned long val = TRNG_NOT_SUPPORTED    
 56         int size = 64;                            
 57                                                   
 58         switch (func_id) {                        
 59         case ARM_SMCCC_TRNG_VERSION:              
 60                 val = ARM_SMCCC_TRNG_VERSION_1    
 61                 break;                            
 62         case ARM_SMCCC_TRNG_FEATURES:             
 63                 switch (smccc_get_arg1(vcpu))     
 64                 case ARM_SMCCC_TRNG_VERSION:      
 65                 case ARM_SMCCC_TRNG_FEATURES:     
 66                 case ARM_SMCCC_TRNG_GET_UUID:     
 67                 case ARM_SMCCC_TRNG_RND32:        
 68                 case ARM_SMCCC_TRNG_RND64:        
 69                         val = TRNG_SUCCESS;       
 70                 }                                 
 71                 break;                            
 72         case ARM_SMCCC_TRNG_GET_UUID:             
 73                 smccc_set_retval(vcpu, le32_to    
 74                                  le32_to_cpu(u    
 75                 return 1;                         
 76         case ARM_SMCCC_TRNG_RND32:                
 77                 size = 32;                        
 78                 fallthrough;                      
 79         case ARM_SMCCC_TRNG_RND64:                
 80                 return kvm_trng_do_rnd(vcpu, s    
 81         }                                         
 82                                                   
 83         smccc_set_retval(vcpu, val, 0, 0, 0);     
 84         return 1;                                 
 85 }                                                 
 86                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php