2023-12-06 16:34:17

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH RFC 01/13] x86: Move posted interrupt descriptor out of vmx code

On Sat, Nov 11 2023 at 20:16, Jacob Pan wrote:
> +/* Posted-Interrupt Descriptor */
> +struct pi_desc {
> + u32 pir[8]; /* Posted interrupt requested */
> + union {
> + struct {
> + /* bit 256 - Outstanding Notification */
> + u16 on : 1,
> + /* bit 257 - Suppress Notification */
> + sn : 1,
> + /* bit 271:258 - Reserved */
> + rsvd_1 : 14;
> + /* bit 279:272 - Notification Vector */
> + u8 nv;
> + /* bit 287:280 - Reserved */
> + u8 rsvd_2;
> + /* bit 319:288 - Notification Destination */
> + u32 ndst;

This mixture of bitfields and types is weird and really not intuitive:

/* Posted-Interrupt Descriptor */
struct pi_desc {
/* Posted interrupt requested */
u32 pir[8];

union {
struct {
/* bit 256 - Outstanding Notification */
u64 on : 1,
/* bit 257 - Suppress Notification */
sn : 1,
/* bit 271:258 - Reserved */
: 14,
/* bit 279:272 - Notification Vector */
nv : 8,
/* bit 287:280 - Reserved */
: 8,
/* bit 319:288 - Notification Destination */
ndst : 32;
};
u64 control;
};
u32 rsvd[6];
} __aligned(64);

Hmm?

> +static inline bool pi_test_and_set_on(struct pi_desc *pi_desc)
> +{
> + return test_and_set_bit(POSTED_INTR_ON,
> + (unsigned long *)&pi_desc->control);

Please get rid of those line breaks.

Thanks,

tglx


2023-12-08 04:50:54

by Jacob Pan

[permalink] [raw]
Subject: Re: [PATCH RFC 01/13] x86: Move posted interrupt descriptor out of vmx code

Hi Thomas,

On Wed, 06 Dec 2023 17:33:28 +0100, Thomas Gleixner <[email protected]>
wrote:

> On Sat, Nov 11 2023 at 20:16, Jacob Pan wrote:
> > +/* Posted-Interrupt Descriptor */
> > +struct pi_desc {
> > + u32 pir[8]; /* Posted interrupt requested */
> > + union {
> > + struct {
> > + /* bit 256 - Outstanding Notification
> > */
> > + u16 on : 1,
> > + /* bit 257 - Suppress Notification */
> > + sn : 1,
> > + /* bit 271:258 - Reserved */
> > + rsvd_1 : 14;
> > + /* bit 279:272 - Notification Vector */
> > + u8 nv;
> > + /* bit 287:280 - Reserved */
> > + u8 rsvd_2;
> > + /* bit 319:288 - Notification
> > Destination */
> > + u32 ndst;
>
> This mixture of bitfields and types is weird and really not intuitive:
>
> /* Posted-Interrupt Descriptor */
> struct pi_desc {
> /* Posted interrupt requested */
> u32 pir[8];
>
> union {
> struct {
> /* bit 256 - Outstanding Notification */
> u64 on : 1,
> /* bit 257 - Suppress Notification */
> sn : 1,
> /* bit 271:258 - Reserved */
> : 14,
> /* bit 279:272 - Notification Vector */
> nv : 8,
> /* bit 287:280 - Reserved */
> : 8,
> /* bit 319:288 - Notification Destination
> */ ndst : 32;
> };
> u64 control;
> };
> u32 rsvd[6];
> } __aligned(64);
>
It seems bit-fields cannot pass type check. I got these compile error.

arch/x86/kernel/irq.c: In function ‘intel_posted_msi_init’:
./include/linux/percpu-defs.h:363:20: error: cannot take address of bit-field ‘nv’
363 | __verify_pcpu_ptr(&(variable)); \
| ^
./include/linux/percpu-defs.h:219:47: note: in definition of macro ‘__verify_pcpu_ptr’
219 | const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
| ^~~
./include/linux/percpu-defs.h:490:34: note: in expansion of macro ‘__pcpu_size_call’
490 | #define this_cpu_write(pcp, val) __pcpu_size_call(this_cpu_write_, pcp, val)
| ^~~~~~~~~~~~~~~~
arch/x86/kernel/irq.c:358:2: note: in expansion of macro ‘this_cpu_write’
358 | this_cpu_write(posted_interrupt_desc.nv, POSTED_MSI_NOTIFICATION_VECTOR);
| ^~~~~~~~~~~~~~
./include/linux/percpu-defs.h:364:15: error: ‘sizeof’ applied to a bit-field
364 | switch(sizeof(variable)) { \
>
> > +static inline bool pi_test_and_set_on(struct pi_desc *pi_desc)
> > +{
> > + return test_and_set_bit(POSTED_INTR_ON,
> > + (unsigned long *)&pi_desc->control);
>
> Please get rid of those line breaks.
will do.


Thanks,

Jacob

2023-12-08 09:31:50

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH RFC 01/13] x86: Move posted interrupt descriptor out of vmx code

On Thu, Dec 07 2023 at 20:54, Jacob Pan wrote:
> On Wed, 06 Dec 2023 17:33:28 +0100, Thomas Gleixner <[email protected]>
> wrote:
>> On Sat, Nov 11 2023 at 20:16, Jacob Pan wrote:
>> u32 rsvd[6];
>> } __aligned(64);
>>
> It seems bit-fields cannot pass type check. I got these compile error.

And why are you telling me that instead if simply fixing it?

2023-12-08 23:16:36

by Jacob Pan

[permalink] [raw]
Subject: Re: [PATCH RFC 01/13] x86: Move posted interrupt descriptor out of vmx code

Hi Thomas,

On Fri, 08 Dec 2023 10:31:20 +0100, Thomas Gleixner <[email protected]>
wrote:

> On Thu, Dec 07 2023 at 20:54, Jacob Pan wrote:
> > On Wed, 06 Dec 2023 17:33:28 +0100, Thomas Gleixner <[email protected]>
> > wrote:
> >> On Sat, Nov 11 2023 at 20:16, Jacob Pan wrote:
> >> u32 rsvd[6];
> >> } __aligned(64);
> >>
> > It seems bit-fields cannot pass type check. I got these compile error.
>
> And why are you telling me that instead if simply fixing it?
My point is that I am not sure this change is worthwhile unless I don't do
the per CPU pointer check.

gcc cannot take bit-field address afaik. So the problem is that with this
bit-field change we don't have individual members anymore to check pointers.

e.g.
./include/linux/percpu-defs.h:363:20: error: cannot take address of
bit-field ‘nv’ 363 | __verify_pcpu_ptr(&(variable));


Thanks,

Jacob

2023-12-09 00:23:58

by Jacob Pan

[permalink] [raw]
Subject: Re: [PATCH RFC 01/13] x86: Move posted interrupt descriptor out of vmx code

Hi Thomas,

On Fri, 08 Dec 2023 10:31:20 +0100, Thomas Gleixner <[email protected]>
wrote:

> On Thu, Dec 07 2023 at 20:54, Jacob Pan wrote:
> > On Wed, 06 Dec 2023 17:33:28 +0100, Thomas Gleixner <[email protected]>
> > wrote:
> >> On Sat, Nov 11 2023 at 20:16, Jacob Pan wrote:
> >> u32 rsvd[6];
> >> } __aligned(64);
> >>
> > It seems bit-fields cannot pass type check. I got these compile error.
>
> And why are you telling me that instead if simply fixing it?
I guess we can fix it like this to use the new bitfields:

void intel_posted_msi_init(void)
{
- this_cpu_write(posted_interrupt_desc.nv, POSTED_MSI_NOTIFICATION_VECTOR);
- this_cpu_write(posted_interrupt_desc.ndst, this_cpu_read(x86_cpu_to_apicid));
+ struct pi_desc *pid = this_cpu_ptr(&posted_interrupt_desc);
+
+ pid->nv = POSTED_MSI_NOTIFICATION_VECTOR;
+ pid->ndst = this_cpu_read(x86_cpu_to_apicid);

It is init time, no IOMMU posting yet. So no need for atomics.


Thanks,

Jacob