x86: drop unneeded __packed attributes
PATCH 1/1 x86: drop unneeded __packed attributes
There where a couple of unneeded packed attributes in several x86-specific structures, that are obviously aligned. The only non-trivial one is vmcb_struct, which has been checked to have the same layout with and without the packed attribute using pahole. In that case add a build-time size check to be on the safe side.
No functional change is expected as a result of this commit.
---
Cc: Boris Ostrovsky <[email protected]>
Cc: Suravee Suthikulpanit <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
This supersedes patch #1 in my clang 4.0 series. Patch #2 is still needed.
--- xen/arch/x86/hvm/svm/vmcb.c | 3 +++ xen/arch/x86/x86_emulate/x86_emulate.h | 4 ++-- xen/include/asm-x86/hvm/svm/vmcb.h | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-)
xen/arch/x86/hvm/svm/vmcb.c +3 -0
@@ -71,6 +71,9 @@ static int construct_vmcb(struct vcpu *v)struct arch_svm_struct *arch_svm = &v->arch.hvm_svm;struct vmcb_struct *vmcb = arch_svm->vmcb; +/* Build-time check of the size of VMCB AMD structure. */ +BUILD_BUG_ON (sizeof (*vmcb) !=4096 ); + vmcb->_general1_intercepts =GENERAL1_INTERCEPT_INTR |GENERAL1_INTERCEPT_NMI | GENERAL1_INTERCEPT_SMI | GENERAL1_INTERCEPT_INIT |
xen/arch/x86/x86_emulate/x86_emulate.h +2 -2
@@ -108,7 +108,7 @@ struct x86_event {* Attribute for segment selector. This is a copy of bit 40:47 & 52:55 of the * segment descriptor. It happens to match the format of an AMD SVM VMCB. */ -typedef union __attribute__((__packed__)) segment_attributes { +typedef union segment_attributes { uint16_t bytes; struct {
@@ -128,7 +128,7 @@ typedef union __attribute__((__packed__)) segment_attributes {* Full state of a segment register (visible and hidden portions). * Again, this happens to match the format of an AMD SVM VMCB. */ -struct __attribute__((__packed__ ))segment_register { +struct segment_register {uint16_t sel;segment_attributes_t attr;uint32_t limit;
xen/include/asm-x86/hvm/svm/vmcb.h +6 -6
@@ -307,7 +307,7 @@ enum VMEXIT_EXITCODE/* Definition of segment state is borrowed by the generic HVM code. */ typedef struct segment_register svm_segment_register_t ; -typedef union __packed +typedef union { u64 bytes; struct
@@ -321,7 +321,7 @@ typedef union __packed } fields; } eventinj_t; -typedef union __packed +typedef union { u64 bytes; struct
@@ -339,7 +339,7 @@ typedef union __packed } fields; } vintr_t; -typedef union __packed +typedef union { u64 bytes; struct
@@ -356,7 +356,7 @@ typedef union __packed } fields; } ioio_info_t; -typedef union __packed +typedef union { u64 bytes; struct
@@ -365,7 +365,7 @@ typedef union __packed } fields; } lbrctrl_t; -typedef union __packed +typedef union { uint32_t bytes; struct
@@ -400,7 +400,7 @@ typedef union __packed#define IOPM_SIZE (12 * 1024)#define MSRPM_SIZE (8 * 1024) -struct __packed vmcb_struct { +struct vmcb_struct {u32 _cr_intercepts;/* offset 0x00 - cleanbit 0 */ u32 _dr_intercepts;/* offset 0x04 - cleanbit 0 */ u32 _exception_intercepts;/* offset 0x08 - cleanbit 0 */
Signature · 7 lines
2.10.1 (Apple Git-78) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.03.17 at 17:42, <[email protected]> wrote:
There where a couple of unneeded packed attributes in several x86-specific structures, that are obviously aligned. The only non-trivial one is
vmcb_struct, which has been checked to have the same layout with and without the packed attribute using pahole. In that case add a build-time size check to be on the safe side.No functional change is expected as a result of this commit.
Signed-off-by Roger Pau Monné <[email protected]>
albeit ...
xen/arch/x86/hvm/svm/vmcb.c static int construct_vmcb(struct vcpu *v) · line 75
Quoted 8 lines
xen/arch/x86/hvm/svm/vmcb.c +2
-0@@ -71,6 +71,9 @@ static int construct_vmcb(struct vcpu *v)struct arch_svm_struct *arch_svm = &v->arch.hvm_svm;struct vmcb_struct *vmcb = arch_svm->vmcb; +/* Build-time check of the size of VMCB AMD structure. */ +BUILD_BUG_ON (sizeof (*vmcb) !=4096 );
... I wonder whether this wouldn't better be PAGE_SIZE.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 20 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.03.17 at 17:42, <[email protected]> wrote:
There where a couple of unneeded packed attributes in several x86-specific structures, that are obviously aligned. The only non-trivial one is
vmcb_struct, which has been checked to have the same layout with and without the packed attribute using pahole. In that case add a build-time size check to be on the safe side.No functional change is expected as a result of this commit.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit ...
Quoted 6 lines
xen/arch/x86/hvm/svm/vmcb.c +0
-0@@ -71,6 +71,9 @@ static int construct_vmcb(struct vcpu *v)struct arch_svm_struct *arch_svm = &v->arch.hvm_svm;struct vmcb_struct *vmcb = arch_svm->vmcb;
Quoted 4 lines
xen/arch/x86/hvm/svm/vmcb.c static int construct_vmcb(struct vcpu *v) · line 75
Quoted 2 lines
xen/arch/x86/hvm/svm/vmcb.c +2
-0+/* Build-time check of the size of VMCB AMD structure. */ +BUILD_BUG_ON (sizeof (*vmcb) !=4096 );... I wonder whether this wouldn't better be
PAGE_SIZE.
I wondered the same, but then if we ever bump PAGE_SIZE to something else (which is not likely to happen), this still needs to be 4096. Feel free to change this to PAGE_SIZE if you prefer.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 06.03.17 at 18:15, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.03.17 at 17:42, <[email protected]> wrote:
There where a couple of unneeded packed attributes in several x86-specific structures, that are obviously aligned. The only non-trivial one is
vmcb_struct, which has been checked to have the same layout with andwithout
Quoted 1 line
Quoted 1 line
the packed attribute using pahole. In that case add a build-time size check
to
Quoted 15 lines
Quoted 5 lines
be on the safe side.
No functional change is expected as a result of this commit.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit ...
Quoted 6 lines
xen/arch/x86/hvm/svm/vmcb.c +0
-0@@ -71,6 +71,9 @@ static int construct_vmcb(struct vcpu *v)struct arch_svm_struct *arch_svm = &v->arch.hvm_svm;struct vmcb_struct *vmcb = arch_svm->vmcb;
Quoted 7 lines
Quoted 4 lines
xen/arch/x86/hvm/svm/vmcb.c static int construct_vmcb(struct vcpu *v) · line 75
Quoted 2 lines
xen/arch/x86/hvm/svm/vmcb.c +2
-0+/* Build-time check of the size of VMCB AMD structure. */ +BUILD_BUG_ON (sizeof (*vmcb) !=4096 );... I wonder whether this wouldn't better be
PAGE_SIZE.I wondered the same, but then if we ever bump
PAGE_SIZEto something else (which is not likely to happen), this still needs to be 4096.
Well, that depends on what meaning we assign to PAGE_SIZE: To me this is a constant dictated by the architecture. If we meant to invent a software page covering multiple hardware pages, I think we should introduce a distinct constant. But this is close to impossible to do, as discussed on a hackathon a while ago - the page size is baked into the public interface.
Quoted 1 line
Feel free to change this to
PAGE_SIZEif you prefer.
Indeed I may.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines · Roger Pau Monne
There where a couple of unneeded packed attributes in several x86-specific structures, that are obviously aligned. The only non-trivial one is
vmcb_struct, which has been checked to have the same layout with and without the packed attribute using pahole. In that case add a build-time size check to be on the safe side.No functional change is expected as a result of this commit.
Signed-off-by Roger Pau Monné <[email protected]>---
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel