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

TOMOYO Linux Cross Reference
Linux/arch/s390/kvm/gaccess.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/s390/kvm/gaccess.h (Version linux-6.11-rc3) and /arch/sparc/kvm/gaccess.h (Version linux-6.8.12)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 
  2 /*                                                
  3  * access guest memory                            
  4  *                                                
  5  * Copyright IBM Corp. 2008, 2014                 
  6  *                                                
  7  *    Author(s): Carsten Otte <cotte@de.ibm.co    
  8  */                                               
  9                                                   
 10 #ifndef __KVM_S390_GACCESS_H                      
 11 #define __KVM_S390_GACCESS_H                      
 12                                                   
 13 #include <linux/compiler.h>                       
 14 #include <linux/kvm_host.h>                       
 15 #include <linux/uaccess.h>                        
 16 #include <linux/ptrace.h>                         
 17 #include "kvm-s390.h"                             
 18                                                   
 19 /**                                               
 20  * kvm_s390_real_to_abs - convert guest real a    
 21  * @prefix - guest prefix                         
 22  * @gra - guest real address                      
 23  *                                                
 24  * Returns the guest absolute address that cor    
 25  * address @gra of by applying the given prefi    
 26  */                                               
 27 static inline unsigned long _kvm_s390_real_to_    
 28 {                                                 
 29         if (gra < 2 * PAGE_SIZE)                  
 30                 gra += prefix;                    
 31         else if (gra >= prefix && gra < prefix    
 32                 gra -= prefix;                    
 33         return gra;                               
 34 }                                                 
 35                                                   
 36 /**                                               
 37  * kvm_s390_real_to_abs - convert guest real a    
 38  * @vcpu - guest virtual cpu                      
 39  * @gra - guest real address                      
 40  *                                                
 41  * Returns the guest absolute address that cor    
 42  * address @gra of a virtual guest cpu by appl    
 43  */                                               
 44 static inline unsigned long kvm_s390_real_to_a    
 45                                                   
 46 {                                                 
 47         return _kvm_s390_real_to_abs(kvm_s390_    
 48 }                                                 
 49                                                   
 50 /**                                               
 51  * _kvm_s390_logical_to_effective - convert gu    
 52  * @psw: psw of the guest                         
 53  * @ga: guest logical address                     
 54  *                                                
 55  * Convert a guest logical address to an effec    
 56  * rules of the addressing mode defined by bit    
 57  * (extendended/basic addressing mode).           
 58  *                                                
 59  * Depending on the addressing mode, the upper    
 60  * mode), 33 bits (31 bit addressing mode) or     
 61  * mode) of @ga will be zeroed and the remaini    
 62  */                                               
 63 static inline unsigned long _kvm_s390_logical_    
 64                                                   
 65 {                                                 
 66         if (psw_bits(*psw).eaba == PSW_BITS_AM    
 67                 return ga;                        
 68         if (psw_bits(*psw).eaba == PSW_BITS_AM    
 69                 return ga & ((1UL << 31) - 1);    
 70         return ga & ((1UL << 24) - 1);            
 71 }                                                 
 72                                                   
 73 /**                                               
 74  * kvm_s390_logical_to_effective - convert gue    
 75  * @vcpu: guest virtual cpu                       
 76  * @ga: guest logical address                     
 77  *                                                
 78  * Convert a guest vcpu logical address to a g    
 79  * applying the rules of the vcpu's addressing    
 80  * and 32 (extendended/basic addressing mode).    
 81  *                                                
 82  * Depending on the vcpu's addressing mode the    
 83  * mode), 33 bits (31 bit addressing mode) or     
 84  * of @ga will be zeroed and the remaining bit    
 85  */                                               
 86 static inline unsigned long kvm_s390_logical_t    
 87                                                   
 88 {                                                 
 89         return _kvm_s390_logical_to_effective(    
 90 }                                                 
 91                                                   
 92 /*                                                
 93  * put_guest_lc, read_guest_lc and write_guest    
 94  * which shall only be used to access the lowc    
 95  * These functions should be used for e.g. int    
 96  * guest memory access protection facilities,     
 97  * protection, are applicable.                    
 98  * At a later point guest vcpu lowcore access     
 99  * prefix pages, so that these pages can be ac    
100  * kernel mapping. All of these *_lc functions    
101  */                                               
102                                                   
103 /**                                               
104  * put_guest_lc - write a simple variable to a    
105  * @vcpu: virtual cpu                             
106  * @x: value to copy to guest                     
107  * @gra: vcpu's destination guest real address    
108  *                                                
109  * Copies a simple value from kernel space to     
110  * The size of the variable may be 1, 2, 4 or     
111  * must be located in the vcpu's lowcore. Othe    
112  *                                                
113  * Returns zero on success or -EFAULT on error    
114  *                                                
115  * Note: an error indicates that either the ke    
116  *       the guest memory mapping is broken. I    
117  *       would be to terminate the guest.         
118  *       It is wrong to inject a guest excepti    
119  */                                               
120 #define put_guest_lc(vcpu, x, gra)                
121 ({                                                
122         struct kvm_vcpu *__vcpu = (vcpu);         
123         __typeof__(*(gra)) __x = (x);             
124         unsigned long __gpa;                      
125                                                   
126         __gpa = (unsigned long)(gra);             
127         __gpa += kvm_s390_get_prefix(__vcpu);     
128         kvm_write_guest(__vcpu->kvm, __gpa, &_    
129 })                                                
130                                                   
131 /**                                               
132  * write_guest_lc - copy data from kernel spac    
133  * @vcpu: virtual cpu                             
134  * @gra: vcpu's source guest real address         
135  * @data: source address in kernel space          
136  * @len: number of bytes to copy                  
137  *                                                
138  * Copy data from kernel space to guest vcpu's    
139  * be located within the vcpu's lowcore, other    
140  *                                                
141  * Returns zero on success or -EFAULT on error    
142  *                                                
143  * Note: an error indicates that either the ke    
144  *       the guest memory mapping is broken. I    
145  *       would be to terminate the guest.         
146  *       It is wrong to inject a guest excepti    
147  */                                               
148 static inline __must_check                        
149 int write_guest_lc(struct kvm_vcpu *vcpu, unsi    
150                    unsigned long len)             
151 {                                                 
152         unsigned long gpa = gra + kvm_s390_get    
153                                                   
154         return kvm_write_guest(vcpu->kvm, gpa,    
155 }                                                 
156                                                   
157 /**                                               
158  * read_guest_lc - copy data from guest vcpu's    
159  * @vcpu: virtual cpu                             
160  * @gra: vcpu's source guest real address         
161  * @data: destination address in kernel space     
162  * @len: number of bytes to copy                  
163  *                                                
164  * Copy data from guest vcpu's lowcore to kern    
165  * be located within the vcpu's lowcore, other    
166  *                                                
167  * Returns zero on success or -EFAULT on error    
168  *                                                
169  * Note: an error indicates that either the ke    
170  *       the guest memory mapping is broken. I    
171  *       would be to terminate the guest.         
172  *       It is wrong to inject a guest excepti    
173  */                                               
174 static inline __must_check                        
175 int read_guest_lc(struct kvm_vcpu *vcpu, unsig    
176                   unsigned long len)              
177 {                                                 
178         unsigned long gpa = gra + kvm_s390_get    
179                                                   
180         return kvm_read_guest(vcpu->kvm, gpa,     
181 }                                                 
182                                                   
183 enum gacc_mode {                                  
184         GACC_FETCH,                               
185         GACC_STORE,                               
186         GACC_IFETCH,                              
187 };                                                
188                                                   
189 int guest_translate_address_with_key(struct kv    
190                                      unsigned     
191                                      u8 access    
192                                                   
193 int check_gva_range(struct kvm_vcpu *vcpu, uns    
194                     unsigned long length, enum    
195                                                   
196 int check_gpa_range(struct kvm *kvm, unsigned     
197                     enum gacc_mode mode, u8 ac    
198                                                   
199 int access_guest_abs_with_key(struct kvm *kvm,    
200                               unsigned long le    
201                                                   
202 int access_guest_with_key(struct kvm_vcpu *vcp    
203                           void *data, unsigned    
204                           u8 access_key);         
205                                                   
206 int access_guest_real(struct kvm_vcpu *vcpu, u    
207                       void *data, unsigned lon    
208                                                   
209 int cmpxchg_guest_abs_with_key(struct kvm *kvm    
210                                __uint128_t new    
211                                                   
212 /**                                               
213  * write_guest_with_key - copy data from kerne    
214  * @vcpu: virtual cpu                             
215  * @ga: guest address                             
216  * @ar: access register                           
217  * @data: source address in kernel space          
218  * @len: number of bytes to copy                  
219  * @access_key: access key the storage key nee    
220  *                                                
221  * Copy @len bytes from @data (kernel space) t    
222  * In order to copy data to guest space the PS    
223  * If DAT is off data will be copied to guest     
224  * If DAT is on data will be copied to the add    
225  * the address space bits of the PSW:             
226  * Primary, secondary, home space or access re    
227  * The addressing mode of the PSW is also insp    
228  * around is taken into account for 24-, 31- a    
229  * if the to be copied data crosses page bound    
230  * In addition low address, DAT and key protec    
231  * copying any data.                              
232  *                                                
233  * This function modifies the 'struct kvm_s390    
234  * In case of an access exception (e.g. protec    
235  * all data necessary so that a subsequent cal    
236  * will inject a correct exception into the gu    
237  * If no access exception happened, the conten    
238  * this function returns.                         
239  *                                                
240  * Returns:  - zero on success                    
241  *           - a negative value if e.g. the gu    
242  *             case of out-of-memory. In this     
243  *             undefined. Also parts of @data     
244  *             space.                             
245  *           - a positive value if an access e    
246  *             the returned value is the progr    
247  *             contents of pgm may be used to     
248  *             guest. No data has been copied     
249  *                                                
250  * Note: in case an access exception is recogn    
251  *       guest space (this is also true, if th    
252  *       one or more page boundaries in guest     
253  *       Therefore this function may be used f    
254  *       instruction emulation.                   
255  *       It may also be used for terminating i    
256  *       if data has been changed in guest spa    
257  */                                               
258 static inline __must_check                        
259 int write_guest_with_key(struct kvm_vcpu *vcpu    
260                          void *data, unsigned     
261 {                                                 
262         return access_guest_with_key(vcpu, ga,    
263                                      access_ke    
264 }                                                 
265                                                   
266 /**                                               
267  * write_guest - copy data from kernel space t    
268  * @vcpu: virtual cpu                             
269  * @ga: guest address                             
270  * @ar: access register                           
271  * @data: source address in kernel space          
272  * @len: number of bytes to copy                  
273  *                                                
274  * The behaviour of write_guest is identical t    
275  * that the PSW access key is used instead of     
276  */                                               
277 static inline __must_check                        
278 int write_guest(struct kvm_vcpu *vcpu, unsigne    
279                 unsigned long len)                
280 {                                                 
281         u8 access_key = psw_bits(vcpu->arch.si    
282                                                   
283         return write_guest_with_key(vcpu, ga,     
284 }                                                 
285                                                   
286 /**                                               
287  * read_guest_with_key - copy data from guest     
288  * @vcpu: virtual cpu                             
289  * @ga: guest address                             
290  * @ar: access register                           
291  * @data: destination address in kernel space     
292  * @len: number of bytes to copy                  
293  * @access_key: access key the storage key nee    
294  *                                                
295  * Copy @len bytes from @ga (guest address) to    
296  *                                                
297  * The behaviour of read_guest_with_key is ide    
298  * except that data will be copied from guest     
299  */                                               
300 static inline __must_check                        
301 int read_guest_with_key(struct kvm_vcpu *vcpu,    
302                         void *data, unsigned l    
303 {                                                 
304         return access_guest_with_key(vcpu, ga,    
305                                      access_ke    
306 }                                                 
307                                                   
308 /**                                               
309  * read_guest - copy data from guest space to     
310  * @vcpu: virtual cpu                             
311  * @ga: guest address                             
312  * @ar: access register                           
313  * @data: destination address in kernel space     
314  * @len: number of bytes to copy                  
315  *                                                
316  * Copy @len bytes from @ga (guest address) to    
317  *                                                
318  * The behaviour of read_guest is identical to    
319  * that the PSW access key is used instead of     
320  */                                               
321 static inline __must_check                        
322 int read_guest(struct kvm_vcpu *vcpu, unsigned    
323                unsigned long len)                 
324 {                                                 
325         u8 access_key = psw_bits(vcpu->arch.si    
326                                                   
327         return read_guest_with_key(vcpu, ga, a    
328 }                                                 
329                                                   
330 /**                                               
331  * read_guest_instr - copy instruction data fr    
332  * @vcpu: virtual cpu                             
333  * @ga: guest address                             
334  * @data: destination address in kernel space     
335  * @len: number of bytes to copy                  
336  *                                                
337  * Copy @len bytes from the given address (gue    
338  * space).                                        
339  *                                                
340  * The behaviour of read_guest_instr is identi    
341  * instruction data will be read from primary     
342  * address-space mode.                            
343  */                                               
344 static inline __must_check                        
345 int read_guest_instr(struct kvm_vcpu *vcpu, un    
346                      unsigned long len)           
347 {                                                 
348         u8 access_key = psw_bits(vcpu->arch.si    
349                                                   
350         return access_guest_with_key(vcpu, ga,    
351                                      access_ke    
352 }                                                 
353                                                   
354 /**                                               
355  * write_guest_abs - copy data from kernel spa    
356  * @vcpu: virtual cpu                             
357  * @gpa: guest physical (absolute) address        
358  * @data: source address in kernel space          
359  * @len: number of bytes to copy                  
360  *                                                
361  * Copy @len bytes from @data (kernel space) t    
362  * It is up to the caller to ensure that the e    
363  * valid memory before calling this function.     
364  * Guest low address and key protection are no    
365  *                                                
366  * Returns zero on success or -EFAULT on error    
367  *                                                
368  * If an error occurs data may have been copie    
369  */                                               
370 static inline __must_check                        
371 int write_guest_abs(struct kvm_vcpu *vcpu, uns    
372                     unsigned long len)            
373 {                                                 
374         return kvm_write_guest(vcpu->kvm, gpa,    
375 }                                                 
376                                                   
377 /**                                               
378  * read_guest_abs - copy data from guest space    
379  * @vcpu: virtual cpu                             
380  * @gpa: guest physical (absolute) address        
381  * @data: destination address in kernel space     
382  * @len: number of bytes to copy                  
383  *                                                
384  * Copy @len bytes from @gpa (guest absolute a    
385  * It is up to the caller to ensure that the e    
386  * valid memory before calling this function.     
387  * Guest key protection is not checked.           
388  *                                                
389  * Returns zero on success or -EFAULT on error    
390  *                                                
391  * If an error occurs data may have been copie    
392  */                                               
393 static inline __must_check                        
394 int read_guest_abs(struct kvm_vcpu *vcpu, unsi    
395                    unsigned long len)             
396 {                                                 
397         return kvm_read_guest(vcpu->kvm, gpa,     
398 }                                                 
399                                                   
400 /**                                               
401  * write_guest_real - copy data from kernel sp    
402  * @vcpu: virtual cpu                             
403  * @gra: guest real address                       
404  * @data: source address in kernel space          
405  * @len: number of bytes to copy                  
406  *                                                
407  * Copy @len bytes from @data (kernel space) t    
408  * It is up to the caller to ensure that the e    
409  * valid memory before calling this function.     
410  * Guest low address and key protection are no    
411  *                                                
412  * Returns zero on success or -EFAULT on error    
413  *                                                
414  * If an error occurs data may have been copie    
415  */                                               
416 static inline __must_check                        
417 int write_guest_real(struct kvm_vcpu *vcpu, un    
418                      unsigned long len)           
419 {                                                 
420         return access_guest_real(vcpu, gra, da    
421 }                                                 
422                                                   
423 /**                                               
424  * read_guest_real - copy data from guest spac    
425  * @vcpu: virtual cpu                             
426  * @gra: guest real address                       
427  * @data: destination address in kernel space     
428  * @len: number of bytes to copy                  
429  *                                                
430  * Copy @len bytes from @gra (guest real addre    
431  * It is up to the caller to ensure that the e    
432  * valid memory before calling this function.     
433  * Guest key protection is not checked.           
434  *                                                
435  * Returns zero on success or -EFAULT on error    
436  *                                                
437  * If an error occurs data may have been copie    
438  */                                               
439 static inline __must_check                        
440 int read_guest_real(struct kvm_vcpu *vcpu, uns    
441                     unsigned long len)            
442 {                                                 
443         return access_guest_real(vcpu, gra, da    
444 }                                                 
445                                                   
446 void ipte_lock(struct kvm *kvm);                  
447 void ipte_unlock(struct kvm *kvm);                
448 int ipte_lock_held(struct kvm *kvm);              
449 int kvm_s390_check_low_addr_prot_real(struct k    
450                                                   
451 /* MVPG PEI indication bits */                    
452 #define PEI_DAT_PROT 2                            
453 #define PEI_NOT_PTE 4                             
454                                                   
455 int kvm_s390_shadow_fault(struct kvm_vcpu *vcp    
456                           unsigned long saddr,    
457                                                   
458 #endif /* __KVM_S390_GACCESS_H */                 
459                                                   

~ [ 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