Skip to content

Commit d1ea4a1

Browse files
aljimenezbMichael Tokarev
authored andcommitted
amd_iommu: Update bitmasks representing DTE reserved fields
The DTE validation method verifies that all bits in reserved DTE fields are unset. Update them according to the latest definition available in AMD I/O Virtualization Technology (IOMMU) Specification - Section 2.2.2.1 Device Table Entry Format. Remove the magic numbers and use a macro helper to generate bitmasks covering the specified ranges for better legibility. Note that some reserved fields specify that events are generated when they contain non-zero bits, or checks are skipped under certain configurations. This change only updates the reserved masks, checks for special conditions are not yet implemented. Cc: [email protected] Signed-off-by: Alejandro Jimenez <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> (cherry picked from commit ff3dcb3bf652912466dcc1cd10d3267f185c212e) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 1ca9d2e commit d1ea4a1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

hw/i386/amd_iommu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,10 @@ static inline uint64_t amdvi_get_perms(uint64_t entry)
848848
static bool amdvi_validate_dte(AMDVIState *s, uint16_t devid,
849849
uint64_t *dte)
850850
{
851-
if ((dte[0] & AMDVI_DTE_LOWER_QUAD_RESERVED)
852-
|| (dte[1] & AMDVI_DTE_MIDDLE_QUAD_RESERVED)
853-
|| (dte[2] & AMDVI_DTE_UPPER_QUAD_RESERVED) || dte[3]) {
851+
if ((dte[0] & AMDVI_DTE_QUAD0_RESERVED) ||
852+
(dte[1] & AMDVI_DTE_QUAD1_RESERVED) ||
853+
(dte[2] & AMDVI_DTE_QUAD2_RESERVED) ||
854+
(dte[3] & AMDVI_DTE_QUAD3_RESERVED)) {
854855
amdvi_log_illegaldevtab_error(s, devid,
855856
s->devtab +
856857
devid * AMDVI_DEVTAB_ENTRY_SIZE, 0);

hw/i386/amd_iommu.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "hw/i386/x86-iommu.h"
2626
#include "qom/object.h"
2727

28+
#define GENMASK64(h, l) (((~0ULL) >> (63 - (h) + (l))) << (l))
29+
2830
/* Capability registers */
2931
#define AMDVI_CAPAB_BAR_LOW 0x04
3032
#define AMDVI_CAPAB_BAR_HIGH 0x08
@@ -162,9 +164,10 @@
162164
#define AMDVI_FEATURE_PC (1ULL << 9) /* Perf counters */
163165

164166
/* reserved DTE bits */
165-
#define AMDVI_DTE_LOWER_QUAD_RESERVED 0x80300000000000fc
166-
#define AMDVI_DTE_MIDDLE_QUAD_RESERVED 0x0000000000000100
167-
#define AMDVI_DTE_UPPER_QUAD_RESERVED 0x08f0000000000000
167+
#define AMDVI_DTE_QUAD0_RESERVED (GENMASK64(6, 2) | GENMASK64(63, 63))
168+
#define AMDVI_DTE_QUAD1_RESERVED 0
169+
#define AMDVI_DTE_QUAD2_RESERVED GENMASK64(53, 52)
170+
#define AMDVI_DTE_QUAD3_RESERVED (GENMASK64(14, 0) | GENMASK64(53, 48))
168171

169172
/* AMDVI paging mode */
170173
#define AMDVI_GATS_MODE (2ULL << 12)

0 commit comments

Comments
 (0)