Skip to content

Commit

Permalink
x86_iommu/amd: remove V=1 check from amdvi_validate_dte()
Browse files Browse the repository at this point in the history
Currently, the amdvi_validate_dte() assumes that a valid DTE will
always have V=1. This is not true. The V=1 means that bit[127:1] are
valid. A valid DTE can have IV=1 and V=0 (i.e address translation
disabled and interrupt remapping enabled)

Remove the V=1 check from amdvi_validate_dte(), make the caller
responsible to check for V or IV bits.

This also fixes a bug in existing code that when error is
detected during the translation we'll fail the translation
instead of assuming a passthrough mode.

Signed-off-by: Brijesh Singh <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Tom Lendacky <[email protected]>
Cc: Suravee Suthikulpanit <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
codomania authored and mstsirkin committed Nov 5, 2018
1 parent 35c2450 commit 470506b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hw/i386/amd_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ static inline uint64_t amdvi_get_perms(uint64_t entry)
AMDVI_DEV_PERM_SHIFT;
}

/* a valid entry should have V = 1 and reserved bits honoured */
/* validate that reserved bits are honoured */
static bool amdvi_validate_dte(AMDVIState *s, uint16_t devid,
uint64_t *dte)
{
Expand All @@ -820,7 +820,7 @@ static bool amdvi_validate_dte(AMDVIState *s, uint16_t devid,
return false;
}

return dte[0] & AMDVI_DEV_VALID;
return true;
}

/* get a device table entry given the devid */
Expand Down Expand Up @@ -966,8 +966,12 @@ static void amdvi_do_translate(AMDVIAddressSpace *as, hwaddr addr,
return;
}

/* devices with V = 0 are not translated */
if (!amdvi_get_dte(s, devid, entry)) {
return;
}

/* devices with V = 0 are not translated */
if (!(entry[0] & AMDVI_DEV_VALID)) {
goto out;
}

Expand Down

0 comments on commit 470506b

Please sign in to comment.