Skip to content

Commit db34a36

Browse files
Jan Beulichjbarnes993
authored andcommitted
x86/PCI: config space accessor functions should not ignore the segment argument
Without this change, the majority of the raw PCI config space access functions silently ignore a non-zero segment argument, which is certainly wrong. Apart from pci_direct_conf1, all other non-MMCFG access methods get used only for non-extended accesses (i.e. assigned to raw_pci_ops only). Consequently, with the way raw_pci_{read,write}() work, it would be a coding error to call these functions with a non-zero segment (with the current call flow this cannot happen afaict). The access method 1 accessor, as it can be used for extended accesses (on AMD systems) instead gets checks added for the passed in segment to be zero. This would be the case when on such a system having multiple PCI segments (don't know whether any exist in practice) MMCFG for some reason is not usable, and method 1 gets selected for doing extended accesses. Rather than accessing the wrong device's config space, the function will now error out. v2: Convert BUG_ON() to WARN_ON(), and extend description as per Ingo's request. Signed-off-by: Jan Beulich <jbeulich@novell.com> Reviewed-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 688398b commit db34a36

5 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎arch/x86/pci/ce4100.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ static int ce4100_conf_read(unsigned int seg, unsigned int bus,
257257
{
258258
int i;
259259

260+
WARN_ON(seg);
260261
if (bus == 1) {
261262
for (i = 0; i < ARRAY_SIZE(bus1_fixups); i++) {
262263
if (bus1_fixups[i].dev_func == devfn &&
@@ -282,6 +283,7 @@ static int ce4100_conf_write(unsigned int seg, unsigned int bus,
282283
{
283284
int i;
284285

286+
WARN_ON(seg);
285287
if (bus == 1) {
286288
for (i = 0; i < ARRAY_SIZE(bus1_fixups); i++) {
287289
if (bus1_fixups[i].dev_func == devfn &&

‎arch/x86/pci/direct.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int pci_conf1_read(unsigned int seg, unsigned int bus,
2222
{
2323
unsigned long flags;
2424

25-
if ((bus > 255) || (devfn > 255) || (reg > 4095)) {
25+
if (seg || (bus > 255) || (devfn > 255) || (reg > 4095)) {
2626
*value = -1;
2727
return -EINVAL;
2828
}
@@ -53,7 +53,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
5353
{
5454
unsigned long flags;
5555

56-
if ((bus > 255) || (devfn > 255) || (reg > 4095))
56+
if (seg || (bus > 255) || (devfn > 255) || (reg > 4095))
5757
return -EINVAL;
5858

5959
raw_spin_lock_irqsave(&pci_config_lock, flags);
@@ -97,6 +97,7 @@ static int pci_conf2_read(unsigned int seg, unsigned int bus,
9797
unsigned long flags;
9898
int dev, fn;
9999

100+
WARN_ON(seg);
100101
if ((bus > 255) || (devfn > 255) || (reg > 255)) {
101102
*value = -1;
102103
return -EINVAL;
@@ -138,6 +139,7 @@ static int pci_conf2_write(unsigned int seg, unsigned int bus,
138139
unsigned long flags;
139140
int dev, fn;
140141

142+
WARN_ON(seg);
141143
if ((bus > 255) || (devfn > 255) || (reg > 255))
142144
return -EINVAL;
143145

‎arch/x86/pci/numaq_32.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static int pci_conf1_mq_read(unsigned int seg, unsigned int bus,
3434
unsigned long flags;
3535
void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
3636

37+
WARN_ON(seg);
3738
if (!value || (bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
3839
return -EINVAL;
3940

@@ -73,6 +74,7 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
7374
unsigned long flags;
7475
void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
7576

77+
WARN_ON(seg);
7678
if ((bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
7779
return -EINVAL;
7880

‎arch/x86/pci/olpc.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static int pci_olpc_read(unsigned int seg, unsigned int bus,
206206
{
207207
uint32_t *addr;
208208

209+
WARN_ON(seg);
210+
209211
/* Use the hardware mechanism for non-simulated devices */
210212
if (!is_simulated(bus, devfn))
211213
return pci_direct_conf1.read(seg, bus, devfn, reg, len, value);
@@ -264,6 +266,8 @@ static int pci_olpc_read(unsigned int seg, unsigned int bus,
264266
static int pci_olpc_write(unsigned int seg, unsigned int bus,
265267
unsigned int devfn, int reg, int len, uint32_t value)
266268
{
269+
WARN_ON(seg);
270+
267271
/* Use the hardware mechanism for non-simulated devices */
268272
if (!is_simulated(bus, devfn))
269273
return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);

‎arch/x86/pci/pcbios.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
181181
unsigned long flags;
182182
unsigned long bx = (bus << 8) | devfn;
183183

184+
WARN_ON(seg);
184185
if (!value || (bus > 255) || (devfn > 255) || (reg > 255))
185186
return -EINVAL;
186187

@@ -247,6 +248,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
247248
unsigned long flags;
248249
unsigned long bx = (bus << 8) | devfn;
249250

251+
WARN_ON(seg);
250252
if ((bus > 255) || (devfn > 255) || (reg > 255))
251253
return -EINVAL;
252254

0 commit comments

Comments
 (0)