@@ -796,8 +796,8 @@ static int _set_status_v2(const grant_entry_header_t *shah,
(scombo.domid != ldomid) ||
(!readonly && (scombo.flags & GTF_readonly)) )
{
- gnttab_clear_flag(rd, _GTF_writing, status);
- gnttab_clear_flag(rd, _GTF_reading, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_reading, status);
PIN_FAIL(done, GNTST_general_error,
"Unstable flags (%x) or dom (%d); expected d%d (r/w: %d)\n",
scombo.flags, scombo.domid, ldomid, !readonly);
@@ -807,7 +807,7 @@ static int _set_status_v2(const grant_entry_header_t *shah,
{
if ( unlikely(scombo.flags & GTF_readonly) )
{
- gnttab_clear_flag(rd, _GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
PIN_FAIL(done, GNTST_general_error,
"Unstable grant readonly flag\n");
}
@@ -1220,10 +1220,10 @@ map_grant_ref(
unlock_out_clear:
if ( !(op->flags & GNTMAP_readonly) &&
!(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
- gnttab_clear_flag(rd, _GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
if ( !act->pin )
- gnttab_clear_flag(rd, _GTF_reading, status);
+ gnttab_clear_flags(rd, GTF_reading, status);
act_release_out:
active_entry_release(act);
@@ -1493,10 +1493,10 @@ unmap_common_complete(struct gnttab_unmap_common *op)
if ( ((act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) == 0) &&
!(op->done & GNTMAP_readonly) )
- gnttab_clear_flag(rd, _GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
if ( act->pin == 0 )
- gnttab_clear_flag(rd, _GTF_reading, status);
+ gnttab_clear_flags(rd, GTF_reading, status);
active_entry_release(act);
grant_read_unlock(rgt);
@@ -2354,11 +2354,11 @@ release_grant_for_copy(
act->pin -= GNTPIN_hstw_inc;
if ( !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) )
- gnttab_clear_flag(rd, _GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
}
if ( !act->pin )
- gnttab_clear_flag(rd, _GTF_reading, status);
+ gnttab_clear_flags(rd, GTF_reading, status);
active_entry_release(act);
grant_read_unlock(rgt);
@@ -2385,10 +2385,10 @@ static void fixup_status_for_copy_pin(struct domain *rd,
uint16_t *status)
{
if ( !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) )
- gnttab_clear_flag(rd, _GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
if ( !act->pin )
- gnttab_clear_flag(rd, _GTF_reading, status);
+ gnttab_clear_flags(rd, GTF_reading, status);
}
/*
@@ -2639,10 +2639,10 @@ acquire_grant_for_copy(
unlock_out_clear:
if ( !(readonly) &&
!(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) )
- gnttab_clear_flag(rd, _GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
if ( !act->pin )
- gnttab_clear_flag(rd, _GTF_reading, status);
+ gnttab_clear_flags(rd, GTF_reading, status);
unlock_out:
active_entry_release(act);
@@ -3677,11 +3677,11 @@ gnttab_release_mappings(
}
if ( (act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) == 0 )
- gnttab_clear_flag(rd, _GTF_writing, status);
+ gnttab_clear_flags(rd, GTF_writing, status);
}
if ( act->pin == 0 )
- gnttab_clear_flag(rd, _GTF_reading, status);
+ gnttab_clear_flags(rd, GTF_reading, status);
active_entry_release(act);
grant_read_unlock(rgt);
@@ -16,10 +16,10 @@ struct grant_table_arch {
gfn_t *status_gfn;
};
-static inline void gnttab_clear_flag(struct domain *d,
- unsigned long nr, uint16_t *addr)
+static inline void gnttab_clear_flags(struct domain *d,
+ uint16_t mask, uint16_t *addr)
{
- guest_clear_mask16(d, BIT(nr, UL), addr);
+ guest_clear_mask16(d, mask, addr);
}
static inline void gnttab_mark_dirty(struct domain *d, mfn_t mfn)
@@ -60,14 +60,11 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
#define gnttab_mark_dirty(d, f) paging_mark_dirty(d, f)
-static inline void gnttab_clear_flag(struct domain *d, unsigned int nr,
- uint16_t *st)
+static inline void gnttab_clear_flags(struct domain *d,
+ uint16_t mask, uint16_t *addr)
{
- /*
- * Note that this cannot be clear_bit(), as the access must be
- * confined to the specified 2 bytes.
- */
- asm volatile ("lock btrw %w1,%0" : "+m" (*st) : "Ir" (nr));
+ /* Access must be confined to the specified 2 bytes. */
+ asm volatile ("lock andw %w1,%0" : "+m" (*addr) : "Ir" (~mask));
}
/* Foreign mappings of HVM-guest pages do not modify the type count. */
To allow for further improvements, it is useful to be able to clear more than a single flag at once. Rework gnttab_clear_flag() into gnttab_clear_flags() which takes a bitmask rather than a bit number. No practical change yet. Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> --- CC: Jan Beulich <JBeulich@suse.com> CC: Wei Liu <wl@xen.org> CC: Roger Pau Monné <roger.pau@citrix.com> CC: Stefano Stabellini <sstabellini@kernel.org> CC: Julien Grall <julien.grall@arm.com> CC: George Dunlap <george.dunlap@eu.citrix.com> --- xen/common/grant_table.c | 30 +++++++++++++++--------------- xen/include/asm-arm/grant_table.h | 6 +++--- xen/include/asm-x86/grant_table.h | 11 ++++------- 3 files changed, 22 insertions(+), 25 deletions(-)