* [PATCH] VT-d: prune super-page related capability macros
@ 2021-11-12 9:51 Jan Beulich
2021-11-15 5:00 ` Tian, Kevin
0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2021-11-12 9:51 UTC (permalink / raw)
To: xen-devel; +Cc: Kevin Tian
cap_super_page_val() and cap_super_offset() are unused (apart from the
latter using the former). I don't see how cap_super_offset() can be
useful in its current shape: cap_super_page_val()'s result is not an
lvalue and hence can't have its address taken. Plus a user would have
to check the capability register field is non-zero, for
find_first_bit() (or find_first_set_bit(), if suitably corrected) to be
valid in the first place. Yet as per the spec when the field is non-zero
the low bit would always be set, so the result would be independent of
the actual value the field holds.
Further zap cap_sps_512gb() and cap_sps_1tb(). While earlier versions
of the spec had things spelled out that way, the current version marks
the two bits as reserved. And "48-bit offset to page frame" wasn't in
line with 1Tb pages anyway - clearly 256Tb pages would have been meant
here.
Finally properly parenthesize parameter uses in the remaining two
macros.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/drivers/passthrough/vtd/iommu.h
+++ b/xen/drivers/passthrough/vtd/iommu.h
@@ -68,13 +68,8 @@
#define cap_num_fault_regs(c) ((((c) >> 40) & 0xff) + 1)
#define cap_pgsel_inv(c) (((c) >> 39) & 1)
-#define cap_super_page_val(c) (((c) >> 34) & 0xf)
-#define cap_super_offset(c) (((find_first_bit(&cap_super_page_val(c), 4)) \
- * OFFSET_STRIDE) + 21)
-#define cap_sps_2mb(c) ((c >> 34) & 1)
-#define cap_sps_1gb(c) ((c >> 35) & 1)
-#define cap_sps_512gb(c) ((c >> 36) & 1)
-#define cap_sps_1tb(c) ((c >> 37) & 1)
+#define cap_sps_2mb(c) (((c) >> 34) & 1)
+#define cap_sps_1gb(c) (((c) >> 35) & 1)
#define cap_fault_reg_offset(c) ((((c) >> 24) & 0x3ff) * 16)
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [PATCH] VT-d: prune super-page related capability macros
2021-11-12 9:51 [PATCH] VT-d: prune super-page related capability macros Jan Beulich
@ 2021-11-15 5:00 ` Tian, Kevin
0 siblings, 0 replies; 2+ messages in thread
From: Tian, Kevin @ 2021-11-15 5:00 UTC (permalink / raw)
To: Jan Beulich, xen-devel
> From: Jan Beulich <jbeulich@suse.com>
> Sent: Friday, November 12, 2021 5:51 PM
>
> cap_super_page_val() and cap_super_offset() are unused (apart from the
> latter using the former). I don't see how cap_super_offset() can be
> useful in its current shape: cap_super_page_val()'s result is not an
> lvalue and hence can't have its address taken. Plus a user would have
> to check the capability register field is non-zero, for
> find_first_bit() (or find_first_set_bit(), if suitably corrected) to be
> valid in the first place. Yet as per the spec when the field is non-zero
> the low bit would always be set, so the result would be independent of
> the actual value the field holds.
>
> Further zap cap_sps_512gb() and cap_sps_1tb(). While earlier versions
> of the spec had things spelled out that way, the current version marks
> the two bits as reserved. And "48-bit offset to page frame" wasn't in
> line with 1Tb pages anyway - clearly 256Tb pages would have been meant
> here.
>
> Finally properly parenthesize parameter uses in the remaining two
> macros.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
>
> --- a/xen/drivers/passthrough/vtd/iommu.h
> +++ b/xen/drivers/passthrough/vtd/iommu.h
> @@ -68,13 +68,8 @@
> #define cap_num_fault_regs(c) ((((c) >> 40) & 0xff) + 1)
> #define cap_pgsel_inv(c) (((c) >> 39) & 1)
>
> -#define cap_super_page_val(c) (((c) >> 34) & 0xf)
> -#define cap_super_offset(c) (((find_first_bit(&cap_super_page_val(c), 4)) \
> - * OFFSET_STRIDE) + 21)
> -#define cap_sps_2mb(c) ((c >> 34) & 1)
> -#define cap_sps_1gb(c) ((c >> 35) & 1)
> -#define cap_sps_512gb(c) ((c >> 36) & 1)
> -#define cap_sps_1tb(c) ((c >> 37) & 1)
> +#define cap_sps_2mb(c) (((c) >> 34) & 1)
> +#define cap_sps_1gb(c) (((c) >> 35) & 1)
>
> #define cap_fault_reg_offset(c) ((((c) >> 24) & 0x3ff) * 16)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-15 5:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 9:51 [PATCH] VT-d: prune super-page related capability macros Jan Beulich
2021-11-15 5:00 ` Tian, Kevin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).