2008-03-26 00:47:20 +07:00
|
|
|
/*
|
2012-07-20 16:15:04 +07:00
|
|
|
* access guest memory
|
2008-03-26 00:47:20 +07:00
|
|
|
*
|
2012-07-20 16:15:04 +07:00
|
|
|
* Copyright IBM Corp. 2008, 2009
|
2008-03-26 00:47:20 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License (version 2 only)
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Author(s): Carsten Otte <cotte@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __KVM_S390_GACCESS_H
|
|
|
|
#define __KVM_S390_GACCESS_H
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/kvm_host.h>
|
|
|
|
#include <asm/uaccess.h>
|
2009-05-25 18:40:51 +07:00
|
|
|
#include "kvm-s390.h"
|
2008-03-26 00:47:20 +07:00
|
|
|
|
2013-03-05 19:14:45 +07:00
|
|
|
static inline void *__gptr_to_uptr(struct kvm_vcpu *vcpu, void *gptr,
|
|
|
|
int prefixing)
|
2008-03-26 00:47:20 +07:00
|
|
|
{
|
2008-07-25 20:51:00 +07:00
|
|
|
unsigned long prefix = vcpu->arch.sie_block->prefix;
|
2013-03-05 19:14:44 +07:00
|
|
|
unsigned long gaddr = (unsigned long) gptr;
|
|
|
|
unsigned long uaddr;
|
|
|
|
|
2013-03-05 19:14:45 +07:00
|
|
|
if (prefixing) {
|
|
|
|
if (gaddr < 2 * PAGE_SIZE)
|
|
|
|
gaddr += prefix;
|
|
|
|
else if ((gaddr >= prefix) && (gaddr < prefix + 2 * PAGE_SIZE))
|
|
|
|
gaddr -= prefix;
|
|
|
|
}
|
2013-03-05 19:14:44 +07:00
|
|
|
uaddr = gmap_fault(gaddr, vcpu->arch.gmap);
|
|
|
|
if (IS_ERR_VALUE(uaddr))
|
|
|
|
uaddr = -EFAULT;
|
|
|
|
return (void *)uaddr;
|
2008-03-26 00:47:20 +07:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:14:44 +07:00
|
|
|
#define get_guest(vcpu, x, gptr) \
|
|
|
|
({ \
|
2013-03-05 19:14:45 +07:00
|
|
|
__typeof__(gptr) __uptr = __gptr_to_uptr(vcpu, gptr, 1);\
|
2013-03-05 19:14:44 +07:00
|
|
|
int __mask = sizeof(__typeof__(*(gptr))) - 1; \
|
|
|
|
int __ret = PTR_RET(__uptr); \
|
|
|
|
\
|
|
|
|
if (!__ret) { \
|
|
|
|
BUG_ON((unsigned long)__uptr & __mask); \
|
|
|
|
__ret = get_user(x, __uptr); \
|
|
|
|
} \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define put_guest(vcpu, x, gptr) \
|
|
|
|
({ \
|
2013-03-05 19:14:45 +07:00
|
|
|
__typeof__(gptr) __uptr = __gptr_to_uptr(vcpu, gptr, 1);\
|
2013-03-05 19:14:44 +07:00
|
|
|
int __mask = sizeof(__typeof__(*(gptr))) - 1; \
|
|
|
|
int __ret = PTR_RET(__uptr); \
|
|
|
|
\
|
|
|
|
if (!__ret) { \
|
|
|
|
BUG_ON((unsigned long)__uptr & __mask); \
|
|
|
|
__ret = put_user(x, __uptr); \
|
|
|
|
} \
|
|
|
|
__ret; \
|
|
|
|
})
|
2008-03-26 00:47:20 +07:00
|
|
|
|
2013-03-05 19:14:45 +07:00
|
|
|
static inline int __copy_guest(struct kvm_vcpu *vcpu, unsigned long to,
|
|
|
|
unsigned long from, unsigned long len,
|
|
|
|
int to_guest, int prefixing)
|
2008-03-26 00:47:20 +07:00
|
|
|
{
|
2013-03-05 19:14:45 +07:00
|
|
|
unsigned long _len, rc;
|
|
|
|
void *uptr;
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
uptr = to_guest ? (void *)to : (void *)from;
|
|
|
|
uptr = __gptr_to_uptr(vcpu, uptr, prefixing);
|
|
|
|
if (IS_ERR(uptr))
|
|
|
|
return -EFAULT;
|
|
|
|
_len = PAGE_SIZE - ((unsigned long)uptr & (PAGE_SIZE - 1));
|
|
|
|
_len = min(_len, len);
|
|
|
|
if (to_guest)
|
|
|
|
rc = copy_to_user(uptr, (void *)from, _len);
|
|
|
|
else
|
|
|
|
rc = copy_from_user((void *)to, uptr, _len);
|
|
|
|
if (rc)
|
|
|
|
return -EFAULT;
|
|
|
|
len -= _len;
|
|
|
|
from += _len;
|
|
|
|
to += _len;
|
2008-03-26 00:47:20 +07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-05 19:14:45 +07:00
|
|
|
#define copy_to_guest(vcpu, to, from, size) \
|
|
|
|
__copy_guest(vcpu, to, (unsigned long)from, size, 1, 1)
|
|
|
|
#define copy_from_guest(vcpu, to, from, size) \
|
|
|
|
__copy_guest(vcpu, (unsigned long)to, from, size, 0, 1)
|
|
|
|
#define copy_to_guest_absolute(vcpu, to, from, size) \
|
|
|
|
__copy_guest(vcpu, to, (unsigned long)from, size, 1, 0)
|
|
|
|
#define copy_from_guest_absolute(vcpu, to, from, size) \
|
|
|
|
__copy_guest(vcpu, (unsigned long)to, from, size, 0, 0)
|
2011-07-24 15:48:22 +07:00
|
|
|
|
2013-03-05 19:14:45 +07:00
|
|
|
#endif /* __KVM_S390_GACCESS_H */
|