common/gnttab: Fixes and cleanup.
cover common/gnttab: Fixes and cleanup.
Misc fixes and cleanup collected during the XSA-226 investigation.
Andrew Cooper (6):
common/gnttab: Correct error handling for gnttab_setup_table() common/gnttab: Correct __acquire_grant_for_copy() fastpath for transitive grants common/gnttab: General cleanup
common/gnttab: gnttab_setup_table() cleanup
common/gnttab: gnttab_query_size() cleanup
common/gnttab: simplify gnttab_copy_lock_domain()
xen/common/grant_table.c | 205 +++++++++++++++++++------------------- xen/include/asm-x86/grant_table.h | 2 +- xen/include/xen/grant_table.h | 10 +- 3 files changed, 107 insertions(+), 110 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/6 common/gnttab: Correct error handling for gnttab_setup_table()
Simplify the error labels to just "unlock" and "out". This fixes an erroneous path where a failure of rcu_lock_domain_by_any_id() still results in rcu_unlock_domain() being called.
This is only not an XSA by luck. rcu_unlock_domain() is a nop other than decrementing the preempt count, and nothing reads the preempt count outside of a debug build.
--- xen/common/grant_table.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
xen/common/grant_table.c +10 -9
@@ -1645,7 +1645,7 @@ gnttab_setup_table( XEN_GUEST_HANDLE_PARAM(gnttab_setup_table_t) uop, unsigned int count) {struct gnttab_setup_table op; -struct domain *d; +struct domain *d =NULL ;struct grant_table *gt;int i;xen_pfn_t gmfn;
@@ -1665,7 +1665,7 @@ gnttab_setup_table(" per domain.\n" , max_grant_frames); op.status = GNTST_general_error; - goto out1; + goto out; }if ( !guest_handle_okay (op.frame_list, op.nr_frames) )
@@ -1676,13 +1676,13 @@ gnttab_setup_table( {gdprintk (XENLOG_INFO ,"Bad domid %d.\n" , op.dom); op.status = GNTST_bad_domain; - goto out2; + goto out; }if (xsm_grant_setup (XSM_TARGET , current->domain, d) ) { op.status = GNTST_permission_denied; - goto out2; + goto out; } gt = d->grant_table;
@@ -1700,7 +1700,7 @@ gnttab_setup_table("Expand grant table to %u failed. Current: %u Max: %u\n" , op.nr_frames, nr_grant_frames(gt), max_grant_frames); op.status = GNTST_general_error; - goto out3; + goto unlock; } op.status = GNTST_okay;
@@ -1713,11 +1713,12 @@ gnttab_setup_table( op.status = GNTST_bad_virt_addr; } - out3: + unlock:grant_write_unlock (gt); - out2: -rcu_unlock_domain (d); - out1: + out: +if ( d ) +rcu_unlock_domain (d); +if (unlikely (__copy_field_to_guest (uop, &op, status)) )return -EFAULT ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/6 common/gnttab: Correct __acquire_grant_for_copy() fastpath for transitive grants
In reply to Andrew CooperAn RCU reference is always dropped for the transitive grant in __release_grant_for_copy(). The __acquire fastpath needs to match the slowpath in terms of number of references taken.
This is only not an XSA by luck. rcu_unlock_domain() is a nop other than decrementing the preempt count, and nothing reads the preempt count outside of a debug build.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
Whether to take this patch or not depends on which version of the transitive refcounting fix gets taken.
--- xen/common/grant_table.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/common/grant_table.c +6 -0
@@ -2345,6 +2345,12 @@ __acquire_grant_for_copy(* non-zero refcount and hence a valid owner. */ ASSERT (td); + +if ( td != rd ) + { +ASSERT (td == act->trans_domain); +rcu_lock_domain (td); + } } act->pin += readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/6] common/gnttab: Correct __acquire_grant_for_copy() fastpath for transitive grants
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.08.17 at 14:30, <[email protected]> wrote:
xen/common/grant_table.c +0
-0@@ -2345,6 +2345,12 @@ __acquire_grant_for_copy(* non-zero refcount and hence a valid owner. */
xen/common/grant_table.c __acquire_grant_for_copy( · line 2356
Quoted 10 lines
xen/common/grant_table.c +6
-0ASSERT (td); + +if ( td != rd ) + { +ASSERT (td == act->trans_domain); +rcu_lock_domain (td); + } } act->pin += readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc;
I think this is superseded by patch 2 of the XSA-226 series just sent.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 3/6 common/gnttab: General cleanup
In reply to Andrew Cooper * Drop trailing whitespace
* Style corrections
No functional change.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/common/grant_table.c | 118 ++++++++++++++++++++------------------ xen/include/asm-x86/grant_table.h | 2 +- xen/include/xen/grant_table.h | 10 ++-- 3 files changed, 68 insertions(+), 62 deletions(-)
xen/common/grant_table.c +62 -56
@@ -1,24 +1,24 @@/****************************************************************************** * common/grant_table.c -* +* * Mechanism for granting foreign access to page frames, and receiving * page-ownership transfers. -* +* * Copyright (c) 2005-2006 Christopher Clark * Copyright (c) 2004 K A Fraser * Copyright (c) 2005 Andrew Warfield * Modifications by Geoffrey Lefebvre are (c) Intel Research Cambridge -* +* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program; If not, see <http://www.gnu.org/licenses/>. */
@@ -40,7 +40,7 @@#include <xsm/xsm.h> #include <asm/flushtlb.h> -/* +/* * This option is deprecated, use gnttab_max_frames and * gnttab_max_maptrack_frames instead. */
@@ -186,7 +186,7 @@ static grant_entry_header_t * shared_entry_header(struct grant_table *t, grant_ref_t ref) {ASSERT (t->gt_version !=0 ); -if (t->gt_version ==1 ) +if ( t->gt_version ==1 )return (grant_entry_header_t *)&shared_entry_v1 (t, ref);else return &shared_entry_v2 (t, ref).hdr;
@@ -265,7 +265,7 @@ static inline void active_entry_release(struct active_grant_entry *act)spin_unlock (&act->lock); } -/* Check if the page has been paged out, or needs unsharing. +/* Check if the page has been paged out, or needs unsharing. If rc == GNTST_okay, *page contains the page struct with a ref taken. Caller must do put_page(*page). If any error, *page = NULL, *frame = INVALID_MFN, no ref taken. */
@@ -276,7 +276,7 @@ static int __get_paged_frame(unsigned long gfn, unsigned long *frame, struct pag#if defined(P2M_PAGED_TYPES ) || defined(P2M_SHARED_TYPES )p2m_type_t p2mt; - *page =get_page_from_gfn (rd, gfn, &p2mt, + *page =get_page_from_gfn (rd, gfn, &p2mt, (readonly) ?P2M_ALLOC :P2M_UNSHARE );if ( !(*page) ) {
@@ -529,7 +529,7 @@ static unsigned int nr_grant_entries(struct grant_table *gt)static int _set_status_v1 (domid_t domid,int readonly,int mapflag, -grant_entry_header_t *shah, +grant_entry_header_t *shah,struct active_grant_entry *act) {int rc = GNTST_okay;
@@ -548,7 +548,7 @@ static int _set_status_v1(domid_t domid,/* if this is a grant mapping operation we should ensure GTF_sub_page is not set */ -if (mapflag) +if ( mapflag ) mask |= GTF_sub_page; scombo.word = *(u32 *)shah;
@@ -556,7 +556,7 @@ static int _set_status_v1(domid_t domid,/* * This loop attempts to set the access (reading/writing) flags * in the grant table entry. It tries a cmpxchg on the field -* up to five times, and then fails under the assumption that +* up to five times, and then fails under the assumption that * the guest is misbehaving. */ for ( ; ; )
@@ -601,7 +601,7 @@ static int _set_status_v1(domid_t domid,static int _set_status_v2 (domid_t domid,int readonly,int mapflag, -grant_entry_header_t *shah, +grant_entry_header_t *shah,struct active_grant_entry *act,grant_status_t *status) {
@@ -622,7 +622,7 @@ static int _set_status_v2(domid_t domid,/* if this is a grant mapping operation we should ensure GTF_sub_page is not set */ -if (mapflag) +if ( mapflag ) mask |= GTF_sub_page;/* If not already pinned, check the grant domid and type. */
@@ -694,7 +694,7 @@ static int _set_status(unsigned gt_version, grant_status_t *status) { -if (gt_version ==1 ) +if ( gt_version ==1 )return _set_status_v1 (domid, readonly, mapflag, shah, act);else return _set_status_v2 (domid, readonly, mapflag, shah, act, status);
@@ -706,7 +706,7 @@ static int grant_map_exists(const struct domain *ld, unsigned int *ref_count) {unsigned int ref, max_iter; - +/* * The remote grant table should be locked but the percpu rwlock * cannot be checked for read lock without race conditions or high
@@ -782,7 +782,7 @@ static unsigned int mapkind(/* * Returns 0 if TLB flush / invalidate required by caller. * va will indicate the address to be invalidated. -* +* * addr is _either_ a host virtual address, or the address of the pte to * update, as indicated by the GNTMAP_contains_pte flag. */
@@ -885,7 +885,7 @@ __gnttab_map_grant_ref( shared_entry_v1(rgt, op->ref).frame :shared_entry_v2 (rgt, op->ref).full_page.frame; - rc =__get_paged_frame (gfn, &frame, &pg, + rc =__get_paged_frame (gfn, &frame, &pg, !!(op->flags & GNTMAP_readonly), rd);if ( rc != GNTST_okay ) goto unlock_out_clear;
@@ -948,7 +948,7 @@ __gnttab_map_grant_ref(if ( !iomem_access_permitted (rd, frame, frame) ) {gdprintk (XENLOG_WARNING , -"Iomem mapping not permitted %lx (domain %d)\n" , +"Iomem mapping not permitted %lx (domain %d)\n" , frame, rd->domain_id); rc = GNTST_general_error; goto undo_out;
@@ -1093,7 +1093,7 @@ __gnttab_map_grant_ref(if ( op->flags & GNTMAP_host_map ) act->pin -= (op->flags & GNTMAP_readonly) ? GNTPIN_hstr_inc : GNTPIN_hstw_inc; - + unlock_out_clear:if ( !(op->flags & GNTMAP_readonly) && !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
@@ -1121,11 +1121,14 @@ gnttab_map_grant_ref(for ( i =0 ; i < count; i++ ) { -if (i &&hypercall_preempt_check ()) +if ( i &&hypercall_preempt_check () )return i; +if (unlikely (__copy_from_guest_offset (&op, uop, i,1 )) )return -EFAULT ; +__gnttab_map_grant_ref (&op); +if (unlikely (__copy_to_guest_offset (uop, i, &op,1 )) )return -EFAULT ; }
@@ -1258,7 +1261,7 @@ __gnttab_unmap_common(if ( op->host_addr && (flags & GNTMAP_host_map) ) {if ( (rc =replace_grant_host_mapping (op->host_addr, - op->frame, op->new_addr, + op->frame, op->new_addr, flags)) <0 ) goto act_release_out;
@@ -1324,7 +1327,7 @@ __gnttab_unmap_common_complete(struct gnttab_unmap_common *op)uint16_t *status;if ( !op->done ) - { + {/* __gntab_unmap_common() didn't do anything - nothing to complete. */ return ; }
@@ -1445,10 +1448,10 @@ gnttab_unmap_grant_ref( count -= c; done += c; -if (count &&hypercall_preempt_check ()) +if ( count &&hypercall_preempt_check () )return done; } - +return 0 ; fault:
@@ -1467,7 +1470,7 @@ __gnttab_unmap_and_replace( common->host_addr = op->host_addr; common->new_addr = op->new_addr; common->handle = op->handle; - +/* Intialise these in case common contains old state */ common->done =0 ; common->dev_bus_addr =0 ;
@@ -1490,7 +1493,7 @@ gnttab_unmap_and_replace( { c =min (count, (unsigned int )GNTTAB_UNMAP_BATCH_SIZE ); partial_done =0 ; - +for ( i =0 ; i < c; i++ ) {if (unlikely (__copy_from_guest (&op, uop,1 )) )
@@ -1501,16 +1504,16 @@ gnttab_unmap_and_replace( goto fault;guest_handle_add_offset (uop,1 ); } - +gnttab_flush_tlb (current->domain); - +for ( i =0 ; i < partial_done; i++ )__gnttab_unmap_common_complete (&(common[i])); count -= c; done += c; -if (count &&hypercall_preempt_check ()) +if ( count &&hypercall_preempt_check () )return done; }
@@ -1521,7 +1524,7 @@ gnttab_unmap_and_replace(for ( i =0 ; i < partial_done; i++ )__gnttab_unmap_common_complete (&(common[i])); -return -EFAULT ; +return -EFAULT ; } static int
@@ -1610,7 +1613,7 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) }/* Status pages - version 2 */ -if (gt->gt_version >1 ) +if ( gt->gt_version >1 ) {if (gnttab_populate_status_frames (d, gt, req_nr_frames) ) goto shared_alloc_failed;
@@ -1640,7 +1643,7 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames)return 0 ; } -static long +static long gnttab_setup_table (XEN_GUEST_HANDLE_PARAM (gnttab_setup_table_t) uop,unsigned int count) {
@@ -1702,7 +1705,7 @@ gnttab_setup_table( op.status = GNTST_general_error; goto unlock; } - + op.status = GNTST_okay;for ( i =0 ; i < op.nr_frames; i++ ) {
@@ -1725,7 +1728,7 @@ gnttab_setup_table(return 0 ; } -static long +static long gnttab_query_size (XEN_GUEST_HANDLE_PARAM (gnttab_query_size_t) uop,unsigned int count) {
@@ -1765,7 +1768,7 @@ gnttab_query_size(grant_read_unlock (d->grant_table); - + query_out_unlock:rcu_unlock_domain (d);
@@ -1780,7 +1783,7 @@ gnttab_query_size(* Check that the given grant reference (rd,ref) allows 'ld' to transfer * ownership of a page frame. If so, lock down the grant entry. */ -static int +static int gnttab_prepare_for_transfer (struct domain *rd,struct domain *ld,grant_ref_t ref) {
@@ -1800,7 +1803,7 @@ gnttab_prepare_for_transfer( } sha =shared_entry_header (rgt, ref); - + scombo.word = *(u32 *)&sha->flags;for ( ; ; )
@@ -1858,7 +1861,7 @@ gnttab_transfer(bool_t okay;int rc; -if (i &&hypercall_preempt_check ()) +if ( i &&hypercall_preempt_check () )return i;/* Read from caller address space. */
@@ -1882,7 +1885,7 @@ gnttab_transfer(/* Check the passed page frame for basic validity. */ if (unlikely (!mfn_valid (_mfn (mfn))) ) - { + {put_gfn (d, gop.mfn);gdprintk (XENLOG_INFO ,"gnttab_transfer: out-of-range %lx\n" , (unsigned long )gop.mfn);
@@ -2085,7 +2088,7 @@ __release_grant_for_copy( sha =shared_entry_header (rgt, gref); r_frame = act->frame; -if (rgt->gt_version ==1 ) +if ( rgt->gt_version ==1 ) { status = &sha->flags; td = rd;
@@ -2152,13 +2155,13 @@ static void __fixup_status_for_copy_pin(const struct active_grant_entry *act, }/* Grab a frame number from a grant entry and update the flags and pin -count as appropriate. If rc == GNTST_okay, note that this *does* +count as appropriate. If rc == GNTST_okay, note that this *does* take one ref count on the target page, stored in *page. If there is any error, *page = NULL, no ref taken. */ static int __acquire_grant_for_copy (struct domain *rd,unsigned long gref,domid_t ldom,int readonly, -unsigned long *frame,struct page_info **page, +unsigned long *frame,struct page_info **page,uint16_t *page_off,uint16_t *length,unsigned allow_transitive) {struct grant_table *rgt = rd->grant_table;
@@ -2273,7 +2276,8 @@ __acquire_grant_for_copy(grant_read_lock (rgt); act =active_entry_acquire (rgt, gref); -if ( rc != GNTST_okay ) { +if ( rc != GNTST_okay ) + {__fixup_status_for_copy_pin (act, status);rcu_unlock_domain (td);active_entry_release (act);
@@ -2362,7 +2366,7 @@ __acquire_grant_for_copy(active_entry_release (act);grant_read_unlock (rgt);return rc; - + unlock_out_clear:if ( !(readonly) && !(act->pin & GNTPIN_hstw_mask) )
@@ -2843,14 +2847,16 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop, goto out1; } rc =xsm_grant_setup (XSM_TARGET , current->domain, d); -if ( rc ) { +if ( rc ) + { op.status = GNTST_permission_denied; goto out2; } gt = d->grant_table; -if (unlikely (op.nr_frames >nr_status_frames (gt)) ) { +if (unlikely (op.nr_frames >nr_status_frames (gt)) ) + {gdprintk (XENLOG_INFO ,"Guest requested addresses for %d grant status " "frames, but only %d are available.\n" , op.nr_frames,nr_status_frames (gt));
@@ -2865,7 +2871,7 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop,for ( i =0 ; i < op.nr_frames; i++ ) { gmfn =gnttab_status_gmfn (d, gt, i); -if (copy_to_guest_offset (op.frame_list, i, &gmfn,1 )) +if (copy_to_guest_offset (op.frame_list, i, &gmfn,1 ) ) op.status = GNTST_bad_virt_addr; }
@@ -3107,13 +3113,13 @@ do_grant_table_op( {long rc;unsigned int opaque_in = cmd &GNTTABOP_ARG_MASK , opaque_out =0 ; - +if ( (int )count <0 )return -EINVAL ;if ( (cmd &=GNTTABOP_CMD_MASK ) != GNTTABOP_cache_flush && opaque_in )return -EINVAL ; - + rc = -EFAULT ;switch ( cmd ) {
@@ -3257,7 +3263,7 @@ do_grant_table_op( rc = -ENOSYS ;break ; } - + out:if ( rc >0 || opaque_out !=0 ) {
@@ -3266,7 +3272,7 @@ do_grant_table_op( rc =hypercall_create_continuation (__HYPERVISOR_grant_table_op,"ihi" , opaque_out | cmd, uop, count - rc); } - +return rc; }
@@ -3274,7 +3280,7 @@ do_grant_table_op(#include "compat/grant_table.c" #endif -int +int grant_table_create (struct domain *d) {
@@ -3317,7 +3323,7 @@ grant_table_create( goto no_mem_4;clear_page (t->shared_raw[i]); } - +/* Status pages for grant table - for version 2 */ t->status = xzalloc_array(grant_status_t *,grant_to_status_frames (max_grant_frames));
@@ -3390,7 +3396,7 @@ gnttab_release_mappings( act =active_entry_acquire (rgt, ref); sha =shared_entry_header (rgt, ref); -if (rgt->gt_version ==1 ) +if ( rgt->gt_version ==1 ) status = &sha->flags;else status = &status_entry (rgt, ref);
@@ -3502,7 +3508,7 @@ grant_table_destroy(if ( t ==NULL )return ; - +for ( i =0 ; i <nr_grant_frames (t); i++ )free_xenheap_page (t->shared_raw[i]);xfree (t->shared_raw);
xen/include/asm-x86/grant_table.h +1 -1
@@ -1,6 +1,6 @@/****************************************************************************** * include/asm-x86/grant_table.h -* +* * Copyright (c) 2004-2005 K A Fraser */
xen/include/xen/grant_table.h +5 -5
@@ -1,21 +1,21 @@/****************************************************************************** * include/xen/grant_table.h -* +* * Mechanism for granting foreign access to page frames, and receiving * page-ownership transfers. -* +* * Copyright (c) 2004-2005 K A Fraser -* +* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program; If not, see <http://www.gnu.org/licenses/>. */
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 3/6] common/gnttab: General cleanup
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.08.17 at 14:30, <[email protected]> wrote:
* Drop trailing whitespace
* Style correctionsNo functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 4/6 common/gnttab: gnttab_setup_table() cleanup
In reply to Andrew CooperDrop pointless debugging messages, and reduce variable scope.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/common/grant_table.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
xen/common/grant_table.c +7 -9
@@ -1647,20 +1647,17 @@ static longgnttab_setup_table ( XEN_GUEST_HANDLE_PARAM(gnttab_setup_table_t) uop, unsigned int count) { + struct vcpu *curr = current;struct gnttab_setup_table op;struct domain *d =NULL ;struct grant_table *gt; -int i; -xen_pfn_t gmfn; +unsigned int i;if ( count !=1 )return -EINVAL ; -if (unlikely (copy_from_guest (&op, uop,1 ) !=0 ) ) - { -gdprintk (XENLOG_INFO ,"Fault while reading gnttab_setup_table_t.\n" ); +if (unlikely (copy_from_guest (&op, uop,1 )) )return -EFAULT ; - }if (unlikely (op.nr_frames > max_grant_frames) ) {
@@ -1677,12 +1674,11 @@ gnttab_setup_table( d =rcu_lock_domain_by_any_id (op.dom);if ( d ==NULL ) { -gdprintk (XENLOG_INFO ,"Bad domid %d.\n" , op.dom); op.status = GNTST_bad_domain; goto out; } -if (xsm_grant_setup (XSM_TARGET , current->domain, d) ) +if (xsm_grant_setup (XSM_TARGET , curr->domain, d) ) { op.status = GNTST_permission_denied; goto out;
@@ -1709,9 +1705,11 @@ gnttab_setup_table( op.status = GNTST_okay;for ( i =0 ; i < op.nr_frames; i++ ) { - gmfn =gnttab_shared_gmfn (d, gt, i); +xen_pfn_t gmfn =gnttab_shared_gmfn (d, gt, i); +/* Grant tables cannot be shared */ BUG_ON (SHARED_M2P (gmfn)); +if (__copy_to_guest_offset (op.frame_list, i, &gmfn,1 ) ) op.status = GNTST_bad_virt_addr; }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 4/6] common/gnttab: gnttab_setup_table() cleanup
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 15.08.17 at 14:30, <[email protected]> wrote:
Drop pointless debugging messages, and reduce variable scope.
... and correct the type of an induction variable.
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 5/6 common/gnttab: gnttab_query_size() cleanup
In reply to Andrew CooperDrop pointless debugging messages, and reduce variable scope.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/common/grant_table.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
xen/common/grant_table.c +8 -15
@@ -1731,31 +1731,25 @@ gnttab_query_size( XEN_GUEST_HANDLE_PARAM(gnttab_query_size_t) uop, unsigned int count) {struct gnttab_query_size op; -struct domain *d; -int rc; +struct domain *d =NULL ;if ( count !=1 )return -EINVAL ; -if (unlikely (copy_from_guest (&op, uop,1 ) !=0 ) ) - { -gdprintk (XENLOG_INFO ,"Fault while reading gnttab_query_size_t.\n" ); +if (unlikely (copy_from_guest (&op, uop,1 )) )return -EFAULT ; - } d =rcu_lock_domain_by_any_id (op.dom);if ( d ==NULL ) { -gdprintk (XENLOG_INFO ,"Bad domid %d.\n" , op.dom); op.status = GNTST_bad_domain; - goto query_out; + goto out; } - rc =xsm_grant_query_size (XSM_TARGET , current->domain, d); -if ( rc ) +if (xsm_grant_query_size (XSM_TARGET , current->domain, d) ) { op.status = GNTST_permission_denied; - goto query_out_unlock; + goto out; }grant_read_lock (d->grant_table);
@@ -1766,11 +1760,10 @@ gnttab_query_size(grant_read_unlock (d->grant_table); + out: +if ( d ) +rcu_unlock_domain (d); - query_out_unlock: -rcu_unlock_domain (d); - - query_out:if (unlikely (__copy_to_guest (uop, &op,1 )) )return -EFAULT ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 5/6] common/gnttab: gnttab_query_size() cleanup
xen/common/grant_table.c gnttab_query_size( · line 1734
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 15.08.17 at 14:30, <[email protected]> wrote:
xen/common/grant_table.c +1
-2@@ -1731,31 +1731,25 @@ gnttab_query_size( XEN_GUEST_HANDLE_PARAM(gnttab_query_size_t) uop, unsigned int count) {struct gnttab_query_size op; -struct domain *d; -int rc; +struct domain *d =NULL ;
There's no need to add an initializer here afaict. Other than that
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/6] common/gnttab: gnttab_query_size() cleanup
Quoted 11 lines · Jan Beulich
xen/common/grant_table.c gnttab_query_size( · line 1734
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 15.08.17 at 14:30, <[email protected]> wrote:
xen/common/grant_table.c +1
-2@@ -1731,31 +1731,25 @@ gnttab_query_size( XEN_GUEST_HANDLE_PARAM(gnttab_query_size_t) uop, unsigned int count) {struct gnttab_query_size op; -struct domain *d; -int rc; +struct domain *d =NULL ;There's no need to add an initializer here afaict.
Oh yes - so there isn't.
Quoted 2 lines
Other than that
Reviewed-by Jan Beulich <[email protected]>
Thanks.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 6/6 common/gnttab: simplify gnttab_copy_lock_domain()
In reply to Andrew CooperRemove the opencoded rcu_lock_domain_by_any_id(). Drop the PIN_FAIL()s and return GNTST_* values directly.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/common/grant_table.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
xen/common/grant_table.c +9 -16
@@ -2390,28 +2390,21 @@ struct gnttab_copy_buf {bool_t have_type; }; -static int gnttab_copy_lock_domain (domid_t domid,unsigned int gref_flag, +static int gnttab_copy_lock_domain (domid_t domid,bool is_gref,struct gnttab_copy_buf *buf) { -int rc; +/* Only DOMID_SELF may reference via frame. */ +if ( domid !=DOMID_SELF && !is_gref ) +return GNTST_permission_denied; -if ( domid !=DOMID_SELF && !gref_flag ) -PIN_FAIL (out, GNTST_permission_denied, -"only allow copy-by-mfn for DOMID_SELF.\n" ); + buf->domain =rcu_lock_domain_by_any_id (domid); -if ( domid ==DOMID_SELF ) - buf->domain =rcu_lock_current_domain (); -else - { - buf->domain =rcu_lock_domain_by_id (domid); -if ( buf->domain ==NULL ) -PIN_FAIL (out, GNTST_bad_domain,"couldn't find %d\n" , domid); - } +if ( buf->domain ==NULL ) +return GNTST_bad_domain; buf->ptr.domid = domid; - rc = GNTST_okay; - out: -return rc; + +return GNTST_okay; } static void gnttab_copy_unlock_domains(struct gnttab_copy_buf *src,
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 6/6] common/gnttab: simplify gnttab_copy_lock_domain()
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 15.08.17 at 14:30, <[email protected]> wrote:
Remove the opencoded
rcu_lock_domain_by_any_id(). Drop the PIN_FAIL()s and return GNTST_* values directly.Signed-off-by Andrew Cooper <[email protected]>
with one optional extra request:
Quoted 19 lines
xen/common/grant_table.c +5
-5@@ -2390,28 +2390,21 @@ struct gnttab_copy_buf {bool_t have_type; }; -static int gnttab_copy_lock_domain (domid_t domid,unsigned int gref_flag, +static int gnttab_copy_lock_domain (domid_t domid,bool is_gref,struct gnttab_copy_buf *buf) { -int rc; +/* Only DOMID_SELF may reference via frame. */ +if ( domid !=DOMID_SELF && !is_gref ) +return GNTST_permission_denied; -if ( domid !=DOMID_SELF && !gref_flag ) -PIN_FAIL (out, GNTST_permission_denied, -"only allow copy-by-mfn for DOMID_SELF.\n" ); + buf->domain =rcu_lock_domain_by_any_id (domid);
xen/common/grant_table.c struct gnttab_copy_buf { · line 2402
Quoted 10 lines
xen/common/grant_table.c +1
-8-if ( domid ==DOMID_SELF ) - buf->domain =rcu_lock_current_domain (); -else - { - buf->domain =rcu_lock_domain_by_id (domid); -if ( buf->domain ==NULL ) -PIN_FAIL (out, GNTST_bad_domain,"couldn't find %d\n" , domid); - } +if ( buf->domain ==NULL )
Use ! here?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel