Coverage Report

Created: 2017-10-25 09:10

/root/src/xen/xen/arch/x86/hvm/grant_table.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 * arch/x86/hvm/grant_table.c
3
 *
4
 * Grant table interfaces for HVM guests
5
 *
6
 * Copyright (C) 2017 Wei Liu <wei.liu2@citrix.com>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include <xen/types.h>
23
24
#include <public/grant_table.h>
25
26
#include <asm/p2m.h>
27
28
int create_grant_p2m_mapping(uint64_t addr, unsigned long frame,
29
                             unsigned int flags,
30
                             unsigned int cache_flags)
31
0
{
32
0
    p2m_type_t p2mt;
33
0
    int rc;
34
0
35
0
    if ( cache_flags || (flags & ~GNTMAP_readonly) != GNTMAP_host_map )
36
0
        return GNTST_general_error;
37
0
38
0
    if ( flags & GNTMAP_readonly )
39
0
        p2mt = p2m_grant_map_ro;
40
0
    else
41
0
        p2mt = p2m_grant_map_rw;
42
0
    rc = guest_physmap_add_entry(current->domain,
43
0
                                 _gfn(addr >> PAGE_SHIFT),
44
0
                                 _mfn(frame), PAGE_ORDER_4K, p2mt);
45
0
    if ( rc )
46
0
        return GNTST_general_error;
47
0
    else
48
0
        return GNTST_okay;
49
0
}
50
51
int replace_grant_p2m_mapping(uint64_t addr, unsigned long frame,
52
                              uint64_t new_addr, unsigned int flags)
53
0
{
54
0
    unsigned long gfn = (unsigned long)(addr >> PAGE_SHIFT);
55
0
    p2m_type_t type;
56
0
    mfn_t old_mfn;
57
0
    struct domain *d = current->domain;
58
0
59
0
    if ( new_addr != 0 || (flags & GNTMAP_contains_pte) )
60
0
        return GNTST_general_error;
61
0
62
0
    old_mfn = get_gfn(d, gfn, &type);
63
0
    if ( !p2m_is_grant(type) || mfn_x(old_mfn) != frame )
64
0
    {
65
0
        put_gfn(d, gfn);
66
0
        gdprintk(XENLOG_WARNING,
67
0
                 "old mapping invalid (type %d, mfn %" PRI_mfn ", frame %lx)\n",
68
0
                 type, mfn_x(old_mfn), frame);
69
0
        return GNTST_general_error;
70
0
    }
71
0
    if ( guest_physmap_remove_page(d, _gfn(gfn), _mfn(frame), PAGE_ORDER_4K) )
72
0
    {
73
0
        put_gfn(d, gfn);
74
0
        return GNTST_general_error;
75
0
    }
76
0
77
0
    put_gfn(d, gfn);
78
0
    return GNTST_okay;
79
0
}
80
81
/*
82
 * Local variables:
83
 * mode: C
84
 * c-file-style: "BSD"
85
 * c-basic-offset: 4
86
 * tab-width: 4
87
 * indent-tabs-mode: nil
88
 * End:
89
 */