xen: arm: correct return value of raw_copy_{to/from}_guest_*, raw_clear_guest

This is a generic interface which is supposed to return the number of bytes
which were not copied. Make it so.

Update the incorrect callers prepare_dtb, decode_thumb{2} and
xenmem_add_to_physmap_range.

In the xenmem_add_to_physmap_range case, observe that we are not propagating
errors from xenmem_add_to_physmap_one and do so.

In the decode_thumb case and an emacs magic block to decode.c

Make the flush_dcache parameter to the helper an int while at it.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
This commit is contained in:
Ian Campbell committed 2013-12-09 15:31:39 +00:00
1 parent 2c7a21dd65
commit d96392361c
4 files changed
+42 -31

No files matched your search

+14 -8
View File
@@ -36,12 +36,10 @@ static void update_dabt(struct hsr_dabt *dabt, int reg,
static int decode_thumb2(register_t pc, struct hsr_dabt *dabt, uint16_t hw1)
{
uint16_t hw2;
int rc;
uint16_t rt;
rc = raw_copy_from_guest(&hw2, (void *__user)(pc + 2), sizeof (hw2));
if ( rc )
return rc;
if ( raw_copy_from_guest(&hw2, (void *__user)(pc + 2), sizeof (hw2)) )
return -EFAULT;
rt = (hw2 >> 12) & 0x7;
@@ -88,11 +86,9 @@ bad_thumb2:
static int decode_thumb(register_t pc, struct hsr_dabt *dabt)
{
uint16_t instr;
int rc;
rc = raw_copy_from_guest(&instr, (void * __user)pc, sizeof (instr));
if ( rc )
return rc;
if ( raw_copy_from_guest(&instr, (void * __user)pc, sizeof (instr)) )
return -EFAULT;
switch ( instr >> 12 )
{
@@ -163,3 +159,13 @@ int decode_instruction(const struct cpu_user_regs *regs, struct hsr_dabt *dabt)
return 1;
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
+4 -4
View File
@@ -907,15 +907,15 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
static void dtb_load(struct kernel_info *kinfo)
{
void * __user dtb_virt = (void * __user)(register_t)kinfo->dtb_paddr;
unsigned long rc;
unsigned long left;
printk("Loading dom0 DTB to 0x%"PRIpaddr"-0x%"PRIpaddr"\n",
kinfo->dtb_paddr, kinfo->dtb_paddr + fdt_totalsize(kinfo->fdt));
rc = raw_copy_to_guest_flush_dcache(dtb_virt, kinfo->fdt,
left = raw_copy_to_guest_flush_dcache(dtb_virt, kinfo->fdt,
fdt_totalsize(kinfo->fdt));
if ( rc != 0 )
panic("Unable to copy the DTB to dom0 memory (rc = %lu)", rc);
if ( left != 0 )
panic("Unable to copy the DTB to dom0 memory (left = %lu bytes)", left);
xfree(kinfo->fdt);
}
+7 -13
View File
@@ -6,21 +6,19 @@
#include <asm/guest_access.h>
static unsigned long raw_copy_to_guest_helper(void *to, const void *from,
unsigned len, unsigned flush_dcache)
unsigned len, int flush_dcache)
{
/* XXX needs to handle faults */
unsigned offset = (vaddr_t)to & ~PAGE_MASK;
while ( len )
{
int rc;
paddr_t g;
void *p;
unsigned size = min(len, (unsigned)PAGE_SIZE - offset);
rc = gvirt_to_maddr((vaddr_t) to, &g);
if ( rc )
return rc;
if ( gvirt_to_maddr((vaddr_t) to, &g) )
return len;
p = map_domain_page(g>>PAGE_SHIFT);
p += offset;
@@ -56,14 +54,12 @@ unsigned long raw_clear_guest(void *to, unsigned len)
while ( len )
{
int rc;
paddr_t g;
void *p;
unsigned size = min(len, (unsigned)PAGE_SIZE - offset);
rc = gvirt_to_maddr((vaddr_t) to, &g);
if ( rc )
return rc;
if ( gvirt_to_maddr((vaddr_t) to, &g) )
return len;
p = map_domain_page(g>>PAGE_SHIFT);
p += offset;
@@ -84,14 +80,12 @@ unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned le
while ( len )
{
int rc;
paddr_t g;
void *p;
unsigned size = min(len, (unsigned)(PAGE_SIZE - offset));
rc = gvirt_to_maddr((vaddr_t) from & PAGE_MASK, &g);
if ( rc )
return rc;
if ( gvirt_to_maddr((vaddr_t) from & PAGE_MASK, &g) )
return len;
p = map_domain_page(g>>PAGE_SHIFT);
p += ((vaddr_t)from & (~PAGE_MASK));
+17 -6
View File
@@ -1067,22 +1067,33 @@ static int xenmem_add_to_physmap_range(struct domain *d,
xen_ulong_t idx;
xen_pfn_t gpfn;
rc = copy_from_guest_offset(&idx, xatpr->idxs, xatpr->size-1, 1);
if ( rc < 0 )
if ( unlikely(copy_from_guest_offset(&idx, xatpr->idxs,
xatpr->size-1, 1)) )
{
rc = -EFAULT;
goto out;
}
rc = copy_from_guest_offset(&gpfn, xatpr->gpfns, xatpr->size-1, 1);
if ( rc < 0 )
if ( unlikely(copy_from_guest_offset(&gpfn, xatpr->gpfns,
xatpr->size-1, 1)) )
{
rc = -EFAULT;
goto out;
}
rc = xenmem_add_to_physmap_one(d, xatpr->space,
xatpr->foreign_domid,
idx, gpfn);
rc = copy_to_guest_offset(xatpr->errs, xatpr->size-1, &rc, 1);
if ( rc < 0 )
goto out;
if ( unlikely(copy_to_guest_offset(xatpr->errs,
xatpr->size-1, &rc, 1)) );
{
rc = -EFAULT;
goto out;
}
xatpr->size--;
/* Check for continuation if it's not the last interation */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.