Skip to content

Commit 3571afc

Browse files
junjiemao1lijinxia
authored andcommitted
HV: hypercall: revisit types in structure parameters
While fixing the MISRA C violations related to integral types, we have unified the type of the following data: uint8_t: phys_pin, virt_pin, vpic_pin, ioapic_pin, vioapic_pin uint16_t: vm_id, pcpu_id, vcpu_id, vpid uint32_t: vector, irq This patch revisits the types of the fields in vhm_request as well as the structures used as parameters in the hypercalls, and make them aligned with the types the hypervisor uses for such data. Reserved fields are added to keep the size and layout of the structures. Implicit paddings are also made explicit as reserved fields. Signed-off-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent f691cab commit 3571afc

File tree

3 files changed

+92
-39
lines changed

3 files changed

+92
-39
lines changed

devicemodel/include/public/acrn_common.h

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@
5050
#define REQ_STATE_PROCESSING 2
5151
#define REQ_STATE_FAILED -1
5252

53-
#define REQ_PORTIO 0
54-
#define REQ_MMIO 1
55-
#define REQ_PCICFG 2
56-
#define REQ_WP 3
53+
#define REQ_PORTIO 0U
54+
#define REQ_MMIO 1U
55+
#define REQ_PCICFG 2U
56+
#define REQ_WP 3U
5757

5858
#define REQUEST_READ 0U
5959
#define REQUEST_WRITE 1U
6060

6161
/* IOAPIC device model info */
62-
#define VIOAPIC_RTE_NUM 48 /* vioapic pins */
62+
#define VIOAPIC_RTE_NUM 48U /* vioapic pins */
6363

6464
#if VIOAPIC_RTE_NUM < 24
6565
#error "VIOAPIC_RTE_NUM must be larger than 23"
@@ -78,17 +78,17 @@
7878
struct mmio_request {
7979
uint32_t direction;
8080
uint32_t reserved;
81-
int64_t address;
82-
int64_t size;
83-
int64_t value;
81+
uint64_t address;
82+
uint64_t size;
83+
uint64_t value;
8484
} __aligned(8);
8585

8686
struct pio_request {
8787
uint32_t direction;
8888
uint32_t reserved;
89-
int64_t address;
90-
int64_t size;
91-
int32_t value;
89+
uint64_t address;
90+
uint64_t size;
91+
uint32_t value;
9292
} __aligned(8);
9393

9494
struct pci_request {
@@ -105,10 +105,9 @@ struct pci_request {
105105
/* vhm_request are 256Bytes aligned */
106106
struct vhm_request {
107107
/* offset: 0bytes - 63bytes */
108-
union {
109-
uint32_t type;
110-
int32_t reserved0[16];
111-
};
108+
uint32_t type;
109+
int32_t reserved0[15];
110+
112111
/* offset: 64bytes-127bytes */
113112
union {
114113
struct pio_request pio_request;
@@ -143,10 +142,16 @@ union vhm_request_buffer {
143142
*/
144143
struct acrn_create_vm {
145144
/** created vmid return to VHM. Keep it first field */
146-
int16_t vmid;
145+
uint16_t vmid;
146+
147+
/** Reserved */
148+
uint16_t reserved0;
147149

148150
/** VCPU numbers this VM want to create */
149-
uint32_t vcpu_num;
151+
uint16_t vcpu_num;
152+
153+
/** Reserved */
154+
uint16_t reserved1;
150155

151156
/** the GUID of this VM */
152157
uint8_t GUID[16];
@@ -157,7 +162,7 @@ struct acrn_create_vm {
157162
uint64_t vm_flag;
158163

159164
/** Reserved for future use*/
160-
uint8_t reserved[24];
165+
uint8_t reserved2[24];
161166
} __aligned(8);
162167

163168
/**
@@ -203,12 +208,18 @@ struct acrn_irqline {
203208
uint32_t reserved;
204209

205210
/** pic IRQ for ISA type */
206-
uint64_t pic_irq;
211+
uint32_t pic_irq;
212+
213+
/** Reserved */
214+
uint32_t reserved0;
207215

208216
/** ioapic IRQ for IOAPIC & ISA TYPE,
209-
* if ~0UL then this IRQ will not be injected
217+
* if ~0U then this IRQ will not be injected
210218
*/
211-
uint64_t ioapic_irq;
219+
uint32_t ioapic_irq;
220+
221+
/** Reserved */
222+
uint32_t reserved1;
212223
} __aligned(8);
213224

214225
/**
@@ -229,7 +240,13 @@ struct acrn_msi_entry {
229240
*/
230241
struct acrn_nmi_entry {
231242
/** virtual CPU ID to inject */
232-
int64_t vcpu_id;
243+
uint16_t vcpu_id;
244+
245+
/** Reserved */
246+
uint16_t reserved0;
247+
248+
/** Reserved */
249+
uint32_t reserved1;
233250
} __aligned(8);
234251

235252
/**

hypervisor/include/public/acrn_common.h

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@
5959
struct mmio_request {
6060
uint32_t direction;
6161
uint32_t reserved;
62-
int64_t address;
63-
int64_t size;
64-
int64_t value;
62+
uint64_t address;
63+
uint64_t size;
64+
uint64_t value;
6565
} __aligned(8);
6666

6767
struct pio_request {
6868
uint32_t direction;
6969
uint32_t reserved;
70-
int64_t address;
71-
int64_t size;
72-
int32_t value;
70+
uint64_t address;
71+
uint64_t size;
72+
uint32_t value;
7373
} __aligned(8);
7474

7575
struct pci_request {
@@ -123,10 +123,16 @@ union vhm_request_buffer {
123123
*/
124124
struct acrn_create_vm {
125125
/** created vmid return to VHM. Keep it first field */
126-
int16_t vmid;
126+
uint16_t vmid;
127+
128+
/** Reserved */
129+
uint16_t reserved0;
127130

128131
/** VCPU numbers this VM want to create */
129-
uint32_t vcpu_num;
132+
uint16_t vcpu_num;
133+
134+
/** Reserved */
135+
uint16_t reserved1;
130136

131137
/** the GUID of this VM */
132138
uint8_t GUID[16];
@@ -137,7 +143,7 @@ struct acrn_create_vm {
137143
uint64_t vm_flag;
138144

139145
/** Reserved for future use*/
140-
uint8_t reserved[24];
146+
uint8_t reserved2[24];
141147
} __aligned(8);
142148

143149
/**
@@ -183,12 +189,18 @@ struct acrn_irqline {
183189
uint32_t reserved;
184190

185191
/** pic IRQ for ISA type */
186-
uint64_t pic_irq;
192+
uint32_t pic_irq;
193+
194+
/** Reserved */
195+
uint32_t reserved0;
187196

188197
/** ioapic IRQ for IOAPIC & ISA TYPE,
189-
* if ~0UL then this IRQ will not be injected
198+
* if ~0U then this IRQ will not be injected
190199
*/
191-
uint64_t ioapic_irq;
200+
uint32_t ioapic_irq;
201+
202+
/** Reserved */
203+
uint32_t reserved1;
192204
} __aligned(8);
193205

194206
/**
@@ -209,7 +221,13 @@ struct acrn_msi_entry {
209221
*/
210222
struct acrn_nmi_entry {
211223
/** virtual CPU ID to inject */
212-
int64_t vcpu_id;
224+
uint16_t vcpu_id;
225+
226+
/** Reserved */
227+
uint16_t reserved0;
228+
229+
/** Reserved */
230+
uint32_t reserved1;
213231
} __aligned(8);
214232

215233
/**

hypervisor/include/public/acrn_hv_defs.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ struct memory_map {
152152
*/
153153
struct set_memmaps {
154154
/** vmid for this hypercall */
155-
uint64_t vmid;
155+
uint16_t vmid;
156+
157+
/** Reserved */
158+
uint16_t reserved0;
159+
160+
/** Reserved */
161+
uint32_t reserved1;
156162

157163
/** multi memmaps numbers */
158164
uint32_t memmaps_num;
@@ -171,6 +177,9 @@ struct sbuf_setup_param {
171177
/** sbuf physical cpu id */
172178
uint16_t pcpu_id;
173179

180+
/** Reserved */
181+
uint16_t reserved;
182+
174183
/** sbuf id */
175184
uint32_t sbuf_id;
176185

@@ -210,13 +219,22 @@ struct hc_ptdev_irq {
210219
/** INTX remapping info */
211220
struct {
212221
/** virtual IOAPIC/PIC pin */
213-
uint32_t virt_pin;
222+
uint8_t virt_pin;
223+
224+
/** Reserved */
225+
uint32_t reserved0:24;
214226

215227
/** physical IOAPIC pin */
216-
uint32_t phys_pin;
228+
uint8_t phys_pin;
229+
230+
/** Reserved */
231+
uint32_t reserved1:24;
217232

218233
/** is virtual pin from PIC */
219-
uint32_t pic_pin;
234+
bool pic_pin;
235+
236+
/** Reserved */
237+
uint32_t reserved2:24;
220238
} intx;
221239

222240
/** MSIx remapping info */

0 commit comments

Comments
 (0)