compat code lacks support for __attribute__
I would like to share code between the hypervisor and xenalyze, so that every definition comes from a single place and is not duplicated in xen and xenalyze. This works as long as simple constructs like struct x {}; are used. Depending on the data to be stored into the trace buffer, having support for __packed may reduce the amount of data that need to be copied.
The tooling currently converts ___attribute__ into compat___attribute__. Was support for __attribute__ intentionally left out, or was there just no usecase for it?
Olaf
+++ b/xen/include/public/trace.h
@@ -80,6 +80,14 @@
#define TRC_LOST_RECORDS (TRC_GEN + 1)
#define TRC_TRACE_WRAP_BUFFER (TRC_GEN + 2)
#define TRC_TRACE_CPU_CHANGE (TRC_GEN + 3)
+#define TRC_a (TRC_GEN + 123)
+struct __attribute__((__packed__)) trc_a {
+ unsigned a;
+};
+#define TRC_b (TRC_GEN + 321)
+typedef struct __attribute__((__packed__)) trc_b {
+ unsigned b;
+} trc_b_t;
#define TRC_SCHED_RUNSTATE_CHANGE (TRC_SCHED_MIN + 1)
#define TRC_SCHED_CONTINUE_RUNNING (TRC_SCHED_MIN + 2)
Quoted 9 lines · Olaf Hering
I would like to share code between the hypervisor and xenalyze, so that every definition comes from a single place and is not duplicated in xen and xenalyze. This works as long as simple constructs like struct x {}; are used. Depending on the data to be stored into the trace buffer, having support for
__packedmay reduce the amount of data that need to be copied.The tooling currently converts
___attribute__intocompat___attribute__. Was support for__attribute__intentionally left out, or was there just no usecase for it?
It was intentionally left out, as the public headers that are subject to compat translation are supposed to not use any compiler extensions. See also our checking that these headers build in plain ANSI C mode (which of course doesn't catch all possible cases, as macros would need actually using in order to spot issues).
However, if you're after adding packed attributes, and if you're meaning to only communicate between Xen and the tool stack, then the requirement above doesn't exist. Yet then I would also wonder whether you need any compat translation in the first place. Those packed structures would better be arch-/bitness-agnostic, wouldn't they? So perhaps we could arrange for your additions to be excluded from the compat translation machinery?
Another option to consider might be to use #pragma pack instead of packed attributes. (I can't say off the top of my head whether such #pragma-s would survive the translation.)
Jan
Wed, 14 Jun 2023 11:49:35 +0200 Jan Beulich <[email protected]>:
Quoted 2 lines
So perhaps we could arrange for your additions to be excluded from the compat translation machinery?
Is there maybe a place for headers which are not public, but which are visible for tools/ and xen/? I think the trace functionality would be a candidate for such local shared headers.
Olaf
Quoted 8 lines · Olaf Hering
Wed, 14 Jun 2023 11:49:35 +0200 Jan Beulich <[email protected]>:
Quoted 2 lines
So perhaps we could arrange for your additions to be excluded from the compat translation machinery?
Is there maybe a place for headers which are not public, but which are visible for
tools/and xen/? I think the trace functionality would be a candidate for such local shared headers.
I'm not sure I understand what you're after. The "public" here means the externally visible interface of the hypervisor. Aiui the header your thinking of still falls in this category. In how far checking and translation need to be done for any particular header under public/ is controlled by xen/include/Makefile. So if you were to introduce a new header for your specific purpose, all would depend on what, if anything, you add to that makefile. I don't think we currently have any header which is entirely unmentioned there, but with the right justification I don't see why this couldn't change (or perhaps such a header might simply be added to headers-n, so it's clear that it wasn't just an oversight that it's not listed anywhere [else]).
Jan
Wed, 14 Jun 2023 11:49:35 +0200 Jan Beulich <[email protected]>:
Quoted 7 lines
However, if you're after adding packed attributes, and if you're meaning to only communicate between Xen and the tool stack, then the requirement above doesn't exist. Yet then I would also wonder whether you need any compat translation in the first place. Those packed structures would better be arch-/bitness-agnostic, wouldn't they? So perhaps we could arrange for your additions to be excluded from the compat translation machinery?
The change below works for me. I wonder if any special compat handling for t_buf and t_rec is required. To me it looks like only uint32_t is used, which will most likely cause no unexpected alignment issues.
Olaf
xen/common/trace.c +0 -9
@@ -34,15 +34,6 @@#include <asm/atomic.h> #include <public/sysctl.h> -#ifdef CONFIG_COMPAT -#include <compat/trace.h> -#define xen_t_buf t_buf -CHECK_t_buf; -#undef xen_t_buf -#else -#define compat_t_rec t_rec -#endif -/* opt_tbuf_size: trace buffer size (in pages) for each cpu */ static unsigned int opt_tbuf_size;static unsigned int opt_tevt_mask;
xen/include/Makefile +1 -1
@@ -30,7 +30,7 @@ headers-$(CONFIG_HVM) += compat/hvm/hvm_op.h headers-$(CONFIG_HVM) += compat/hvm/hvm_vcpu.h headers-$(CONFIG_HYPFS) += compat/hypfs.h headers-$(CONFIG_KEXEC) += compat/kexec.h -headers-$(CONFIG_TRACEBUFFER) += compat/trace.h +headers-n += compat/trace.h headers-$(CONFIG_XENOPROF) += compat/xenoprof.h headers-$(CONFIG_XSM_FLASK) += compat/xsm/flask_op.h
xen/include/public/trace.h +9 -0
@@ -81,6 +81,15 @@#define TRC_TRACE_WRAP_BUFFER (TRC_GEN + 2)#define TRC_TRACE_CPU_CHANGE (TRC_GEN + 3) +#define TRC_a (TRC_GEN + 123) +struct __attribute__((__packed__ ))trc_a { +unsigned a; +}; +#define TRC_b (TRC_GEN + 321) +typedef struct __attribute__((__packed__ ))trc_b { +unsigned b; +}trc_b_t ; +#define TRC_SCHED_RUNSTATE_CHANGE (TRC_SCHED_MIN + 1)#define TRC_SCHED_CONTINUE_RUNNING (TRC_SCHED_MIN + 2)#define TRC_SCHED_DOM_ADD (TRC_SCHED_VERBOSE + 1)
Quoted 10 lines · Olaf Hering
Wed, 14 Jun 2023 11:49:35 +0200 Jan Beulich <[email protected]>:
Quoted 7 lines
However, if you're after adding packed attributes, and if you're meaning to only communicate between Xen and the tool stack, then the requirement above doesn't exist. Yet then I would also wonder whether you need any compat translation in the first place. Those packed structures would better be arch-/bitness-agnostic, wouldn't they? So perhaps we could arrange for your additions to be excluded from the compat translation machinery?
Quoted 3 lines
The change below works for me. I wonder if any special compat handling for
t_bufandt_recis required. To me it looks like onlyuint32_tis used, which will most likely cause no unexpected alignment issues.
No special handling is needed, indeed, but ...
xen/common/trace.c line 40
Quoted 10 lines
xen/common/trace.c +0
-4@@ -34,15 +34,6 @@#include <asm/atomic.h> #include <public/sysctl.h> -#ifdef CONFIG_COMPAT -#include <compat/trace.h> -#define xen_t_buf t_buf -CHECK_t_buf;
... you're removing the line that's actually verifying this is the case.
Jan
Fri, 16 Jun 2023 12:07:20 +0200 Jan Beulich <[email protected]>:
Quoted 1 line
... you're removing the line that's actually verifying this is the case.
Yeah, because it disappeared. I think the other approach is to teach the python tool about __attribute__(()).
Let me know which way is preferred.
Olaf
Quoted 8 lines · Olaf Hering
Fri, 16 Jun 2023 12:07:20 +0200 Jan Beulich <[email protected]>:
Quoted 1 line
... you're removing the line that's actually verifying this is the case.
Yeah, because it disappeared. I think the other approach is to teach the python tool about __attribute__(()).
Let me know which way is preferred.
For the moment neither, I'm afraid. I don't know about other maintainers, but I at least would first like to see the gain. And if there is agreement that that's worth it, we could then try to determine what price we're willing to pay.
Jan