* [PATCH] PCI/MSI: fix msi_mask()
@ 2009-02-05 2:47 Hidetoshi Seto
2009-02-08 11:26 ` Matthew Wilcox
0 siblings, 1 reply; 7+ messages in thread
From: Hidetoshi Seto @ 2009-02-05 2:47 UTC (permalink / raw)
To: linux-pci, linux-kernel; +Cc: Matthew Wilcox, Jesse Barnes
The commit bffac3c593eba1f9da3efd0199e49ea6558a40ce does:
- temp = (1 << multi_msi_capable(control));
- temp = ((temp - 1) & ~temp);
+ temp = msi_mask((control & PCI_MSI_FLAGS_QMASK) >> 1);
and provides msi_mask() to avoid undefined shift by 32.
According to PCI Local Bus Spec 3.0 "6.8.1.3 Message Control for MSI",
relations between the encoded bits in control register, the number of
vectors and the proper maskbits should be as following table:
control[3::1] | vectors | maskbits
--------------+----------+-----------
000b | 1 | 0x1
001b | 2 | 0x3
010b | 4 | 0xf
011b | 8 | 0xff
100b | 16 | 0xffff
101b | 32 | 0xffffffff
110b | Reserved | n/a
111b | Reserved | n/a
This patch fix the wrong array in the msi_mask().
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
---
drivers/pci/msi.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 44f15ff..1c88958 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -109,7 +109,7 @@ static void msix_set_enable(struct pci_dev *dev, int enable)
*/
static inline __attribute_const__ u32 msi_mask(unsigned x)
{
- static const u32 mask[] = { 1, 2, 4, 0xf, 0xff, 0xffff, 0xffffffff };
+ static const u32 mask[] = { 1, 3, 0xf, 0xff, 0xffff, 0xffffffff };
return mask[x];
}
--
1.6.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] PCI/MSI: fix msi_mask()
2009-02-05 2:47 [PATCH] PCI/MSI: fix msi_mask() Hidetoshi Seto
@ 2009-02-08 11:26 ` Matthew Wilcox
2009-02-09 1:38 ` Hidetoshi Seto
2009-02-09 1:40 ` [PATCH] PCI/MSI: fix msi_mask() (rev. 2) Hidetoshi Seto
0 siblings, 2 replies; 7+ messages in thread
From: Matthew Wilcox @ 2009-02-08 11:26 UTC (permalink / raw)
To: Hidetoshi Seto; +Cc: linux-pci, linux-kernel, Matthew Wilcox, Jesse Barnes
On Thu, Feb 05, 2009 at 11:47:36AM +0900, Hidetoshi Seto wrote:
> The commit bffac3c593eba1f9da3efd0199e49ea6558a40ce does:
>
> - temp = (1 << multi_msi_capable(control));
> - temp = ((temp - 1) & ~temp);
> + temp = msi_mask((control & PCI_MSI_FLAGS_QMASK) >> 1);
>
> and provides msi_mask() to avoid undefined shift by 32.
[...]
> This patch fix the wrong array in the msi_mask().
Quite correct. While disconnected for a couple of weeks, I also
considered this possible fix:
static inline __attribute_const__ u32 msi_mask(unsigned x)
{
/* Don't shift by >= width of type */
if (x >= 5)
return 0xffffffff;
return (1 << (1 << x)) - 1;
}
which has the added bonus of not running off the end of the array if
some device has a bogus value in its config space.
What do you think?
--
Matthew Wilcox Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] PCI/MSI: fix msi_mask()
2009-02-08 11:26 ` Matthew Wilcox
@ 2009-02-09 1:38 ` Hidetoshi Seto
2009-02-09 1:40 ` [PATCH] PCI/MSI: fix msi_mask() (rev. 2) Hidetoshi Seto
1 sibling, 0 replies; 7+ messages in thread
From: Hidetoshi Seto @ 2009-02-09 1:38 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-pci, linux-kernel, Matthew Wilcox, Jesse Barnes
Matthew Wilcox wrote:
> On Thu, Feb 05, 2009 at 11:47:36AM +0900, Hidetoshi Seto wrote:
>> This patch fix the wrong array in the msi_mask().
>
> Quite correct. While disconnected for a couple of weeks, I also
> considered this possible fix:
>
> static inline __attribute_const__ u32 msi_mask(unsigned x)
> {
> /* Don't shift by >= width of type */
> if (x >= 5)
> return 0xffffffff;
> return (1 << (1 << x)) - 1;
> }
>
> which has the added bonus of not running off the end of the array if
> some device has a bogus value in its config space.
>
> What do you think?
Yeah, I think it's better one.
I'm going to post a revised patch hiring this style.
Thanks,
H.Seto
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH] PCI/MSI: fix msi_mask() (rev. 2)
2009-02-08 11:26 ` Matthew Wilcox
2009-02-09 1:38 ` Hidetoshi Seto
@ 2009-02-09 1:40 ` Hidetoshi Seto
2009-02-09 3:27 ` Matthew Wilcox
1 sibling, 1 reply; 7+ messages in thread
From: Hidetoshi Seto @ 2009-02-09 1:40 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-pci, linux-kernel, Matthew Wilcox, Jesse Barnes
The commit bffac3c593eba1f9da3efd0199e49ea6558a40ce ("PCI MSI: Fix
undefined shift by 32") does:
- temp = (1 << multi_msi_capable(control));
- temp = ((temp - 1) & ~temp);
+ temp = msi_mask((control & PCI_MSI_FLAGS_QMASK) >> 1);
and provides msi_mask() to avoid undefined shift by 32.
According to PCI Local Bus Spec 3.0 "6.8.1.3 Message Control for MSI",
relations between the encoded bits in control register, the number of
vectors and the proper maskbits should be as the following table:
control[3::1] | vectors | maskbits
--------------+----------+-----------
000b | 1 | 0x1
001b | 2 | 0x3
010b | 4 | 0xf
011b | 8 | 0xff
100b | 16 | 0xffff
101b | 32 | 0xffffffff
110b | Reserved | n/a
111b | Reserved | n/a
This patch removes the wrong array in the msi_mask(), and adds a bonus of
not running off the end of the array if some device has a bogus value in
its config space.
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
---
drivers/pci/msi.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 44f15ff..7b8a51e 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -109,8 +109,10 @@ static void msix_set_enable(struct pci_dev *dev, int enable)
*/
static inline __attribute_const__ u32 msi_mask(unsigned x)
{
- static const u32 mask[] = { 1, 2, 4, 0xf, 0xff, 0xffff, 0xffffffff };
- return mask[x];
+ /* Don't shift by >= width of type */
+ if (x >= 5)
+ return 0xffffffff;
+ return (1 << (1 << x)) - 1;
}
static void msix_flush_writes(struct irq_desc *desc)
--
1.6.0.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] PCI/MSI: fix msi_mask() (rev. 2)
2009-02-09 1:40 ` [PATCH] PCI/MSI: fix msi_mask() (rev. 2) Hidetoshi Seto
@ 2009-02-09 3:27 ` Matthew Wilcox
2009-02-09 4:31 ` Hidetoshi Seto
2009-02-09 17:23 ` Jesse Barnes
0 siblings, 2 replies; 7+ messages in thread
From: Matthew Wilcox @ 2009-02-09 3:27 UTC (permalink / raw)
To: Hidetoshi Seto; +Cc: linux-pci, linux-kernel, Matthew Wilcox, Jesse Barnes
On Mon, Feb 09, 2009 at 10:40:55AM +0900, Hidetoshi Seto wrote:
> The commit bffac3c593eba1f9da3efd0199e49ea6558a40ce ("PCI MSI: Fix
> undefined shift by 32") does:
I think the commit message could be worded somewhat better, and I think
I should be credited as the author of the patch. How about this?
----
From: Matthew Wilcox <willy@linux.intel.com>
Hidetoshi Seto points out that commit
bffac3c593eba1f9da3efd0199e49ea6558a40ce has wrong values in the
array. Rather than correct the array, we can just use a bounds check
and perform the calculation specified in the comment. As a bonus, this
will not run off the end of the array if the device specifies an illegal
value in the MSI capcbility.
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
----
drivers/pci/msi.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 44f15ff..baba2eb 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -103,14 +103,12 @@ static void msix_set_enable(struct pci_dev *dev, int enable)
}
}
-/*
- * Essentially, this is ((1 << (1 << x)) - 1), but without the
- * undefinedness of a << 32.
- */
static inline __attribute_const__ u32 msi_mask(unsigned x)
{
- static const u32 mask[] = { 1, 2, 4, 0xf, 0xff, 0xffff, 0xffffffff };
- return mask[x];
+ /* Don't shift by >= width of type */
+ if (x >= 5)
+ return 0xffffffff;
+ return (1 << (1 << x)) - 1;
}
static void msix_flush_writes(struct irq_desc *desc)
--
Matthew Wilcox Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] PCI/MSI: fix msi_mask() (rev. 2)
2009-02-09 3:27 ` Matthew Wilcox
@ 2009-02-09 4:31 ` Hidetoshi Seto
2009-02-09 17:23 ` Jesse Barnes
1 sibling, 0 replies; 7+ messages in thread
From: Hidetoshi Seto @ 2009-02-09 4:31 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-pci, linux-kernel, Matthew Wilcox, Jesse Barnes
Matthew Wilcox wrote:
> On Mon, Feb 09, 2009 at 10:40:55AM +0900, Hidetoshi Seto wrote:
>> The commit bffac3c593eba1f9da3efd0199e49ea6558a40ce ("PCI MSI: Fix
>> undefined shift by 32") does:
>
> I think the commit message could be worded somewhat better, and I think
> I should be credited as the author of the patch. How about this?
>
> ----
>
> From: Matthew Wilcox <willy@linux.intel.com>
>
> Hidetoshi Seto points out that commit
> bffac3c593eba1f9da3efd0199e49ea6558a40ce has wrong values in the
> array. Rather than correct the array, we can just use a bounds check
> and perform the calculation specified in the comment. As a bonus, this
> will not run off the end of the array if the device specifies an illegal
> value in the MSI capcbility.
^^^^^^^^^^ capability
>
> Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
It looks good for me other than the typo above.
Thanks,
H.Seto
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] PCI/MSI: fix msi_mask() (rev. 2)
2009-02-09 3:27 ` Matthew Wilcox
2009-02-09 4:31 ` Hidetoshi Seto
@ 2009-02-09 17:23 ` Jesse Barnes
1 sibling, 0 replies; 7+ messages in thread
From: Jesse Barnes @ 2009-02-09 17:23 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Hidetoshi Seto, linux-pci, linux-kernel, Matthew Wilcox
On Sunday, February 8, 2009 7:27 pm Matthew Wilcox wrote:
> On Mon, Feb 09, 2009 at 10:40:55AM +0900, Hidetoshi Seto wrote:
> > The commit bffac3c593eba1f9da3efd0199e49ea6558a40ce ("PCI MSI: Fix
> > undefined shift by 32") does:
>
> I think the commit message could be worded somewhat better, and I think
> I should be credited as the author of the patch. How about this?
>
> ----
>
> From: Matthew Wilcox <willy@linux.intel.com>
>
> Hidetoshi Seto points out that commit
> bffac3c593eba1f9da3efd0199e49ea6558a40ce has wrong values in the
> array. Rather than correct the array, we can just use a bounds check
> and perform the calculation specified in the comment. As a bonus, this
> will not run off the end of the array if the device specifies an illegal
> value in the MSI capcbility.
>
> Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Applied to my for-linus branch, thanks guys.
--
Jesse Barnes, Intel Open Source Technology Center
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-02-09 17:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-05 2:47 [PATCH] PCI/MSI: fix msi_mask() Hidetoshi Seto
2009-02-08 11:26 ` Matthew Wilcox
2009-02-09 1:38 ` Hidetoshi Seto
2009-02-09 1:40 ` [PATCH] PCI/MSI: fix msi_mask() (rev. 2) Hidetoshi Seto
2009-02-09 3:27 ` Matthew Wilcox
2009-02-09 4:31 ` Hidetoshi Seto
2009-02-09 17:23 ` Jesse Barnes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox