Skip to content

Commit 4e4e7dc

Browse files
Alex Williamsonairlied
authored andcommitted
vgaarb: We can own non-decoded resources
The VGA arbiter does not allow devices to "own" resources that it doesn't "decode". However, it does allow devices to "lock" resources that it doesn't decode. This gets us into trouble because locking the resource goes through the same bridge routing updates regardless of whether we decode the resource. This means that when a non-decoded resource is released, the bridge is left with VGA routing enabled and locking a different device won't clear it. This happens in the following scenario: VGA device 01:00.0 (VGA1) is owned by the radeon driver, which registers a set_vga_decode function which releases legacy VGA decodes. VGA device 02:00.0 (VGA2) is any VGA device. VGA1 user locks VGA resources triggering first_use callback of set_vga_decoded, clearing "decode" and "owns" of legacy resources on VGA1. VGA1 user unlocks VGA resources. VGA2 user locks VGA resources, which skips VGA1 as conflicting as it does not "own" legacy resources, although VGA routing is still enabled for the VGA1 bridge. VGA routing is enabled on VGA2 bridge. VGA2 may or may not receive VGA transactions depending on the bus priority of VGA1 vs VGA2 bridge. To resolve this, we need to allow devices to "own" resources that they do not "decode". This way we can track bus ownership of VGA. When a device decodes VGA, it only means that we must update the command bits in cases where the conflicting device is on the same bus. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: Dave Airlie <airlied@redhat.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent f71c5d9 commit 4e4e7dc

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

‎drivers/gpu/vga/vgaarb.c‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,10 @@ static struct vga_device *__vga_tryget(struct vga_device *vgadev,
237237
if (conflict->locks & lwants)
238238
return conflict;
239239

240-
/* Ok, now check if he owns the resource we want. We don't need
241-
* to check "decodes" since it should be impossible to own
242-
* own legacy resources you don't decode unless I have a bug
243-
* in this code...
240+
/* Ok, now check if it owns the resource we want. We can
241+
* lock resources that are not decoded, therefore a device
242+
* can own resources it doesn't decode.
244243
*/
245-
WARN_ON(conflict->owns & ~conflict->decodes);
246244
match = lwants & conflict->owns;
247245
if (!match)
248246
continue;
@@ -254,32 +252,39 @@ static struct vga_device *__vga_tryget(struct vga_device *vgadev,
254252
flags = 0;
255253
pci_bits = 0;
256254

255+
/* If we can't control legacy resources via the bridge, we
256+
* also need to disable normal decoding.
257+
*/
257258
if (!conflict->bridge_has_one_vga) {
258-
vga_irq_set_state(conflict, false);
259-
flags |= PCI_VGA_STATE_CHANGE_DECODES;
260-
if (match & (VGA_RSRC_LEGACY_MEM|VGA_RSRC_NORMAL_MEM))
259+
if ((match & conflict->decodes) & VGA_RSRC_LEGACY_MEM)
261260
pci_bits |= PCI_COMMAND_MEMORY;
262-
if (match & (VGA_RSRC_LEGACY_IO|VGA_RSRC_NORMAL_IO))
261+
if ((match & conflict->decodes) & VGA_RSRC_LEGACY_IO)
263262
pci_bits |= PCI_COMMAND_IO;
263+
264+
if (pci_bits) {
265+
vga_irq_set_state(conflict, false);
266+
flags |= PCI_VGA_STATE_CHANGE_DECODES;
267+
}
264268
}
265269

266270
if (change_bridge)
267271
flags |= PCI_VGA_STATE_CHANGE_BRIDGE;
268272

269273
pci_set_vga_state(conflict->pdev, false, pci_bits, flags);
270274
conflict->owns &= ~match;
271-
/* If he also owned non-legacy, that is no longer the case */
272-
if (match & VGA_RSRC_LEGACY_MEM)
275+
276+
/* If we disabled normal decoding, reflect it in owns */
277+
if (pci_bits & PCI_COMMAND_MEMORY)
273278
conflict->owns &= ~VGA_RSRC_NORMAL_MEM;
274-
if (match & VGA_RSRC_LEGACY_IO)
279+
if (pci_bits & PCI_COMMAND_IO)
275280
conflict->owns &= ~VGA_RSRC_NORMAL_IO;
276281
}
277282

278283
enable_them:
279284
/* ok dude, we got it, everybody conflicting has been disabled, let's
280-
* enable us. Make sure we don't mark a bit in "owns" that we don't
281-
* also have in "decodes". We can lock resources we don't decode but
282-
* not own them.
285+
* enable us. Mark any bits in "owns" regardless of whether we
286+
* decoded them. We can lock resources we don't decode, therefore
287+
* we must track them via "owns".
283288
*/
284289
flags = 0;
285290
pci_bits = 0;
@@ -291,15 +296,15 @@ static struct vga_device *__vga_tryget(struct vga_device *vgadev,
291296
if (wants & (VGA_RSRC_LEGACY_IO|VGA_RSRC_NORMAL_IO))
292297
pci_bits |= PCI_COMMAND_IO;
293298
}
294-
if (!!(wants & VGA_RSRC_LEGACY_MASK))
299+
if (wants & VGA_RSRC_LEGACY_MASK)
295300
flags |= PCI_VGA_STATE_CHANGE_BRIDGE;
296301

297302
pci_set_vga_state(vgadev->pdev, true, pci_bits, flags);
298303

299304
if (!vgadev->bridge_has_one_vga) {
300305
vga_irq_set_state(vgadev, true);
301306
}
302-
vgadev->owns |= (wants & vgadev->decodes);
307+
vgadev->owns |= wants;
303308
lock_them:
304309
vgadev->locks |= (rsrc & VGA_RSRC_LEGACY_MASK);
305310
if (rsrc & VGA_RSRC_LEGACY_IO)
@@ -649,7 +654,6 @@ static inline void vga_update_device_decodes(struct vga_device *vgadev,
649654
old_decodes = vgadev->decodes;
650655
decodes_removed = ~new_decodes & old_decodes;
651656
decodes_unlocked = vgadev->locks & decodes_removed;
652-
vgadev->owns &= ~decodes_removed;
653657
vgadev->decodes = new_decodes;
654658

655659
pr_info("vgaarb: device changed decodes: PCI:%s,olddecodes=%s,decodes=%s:owns=%s\n",

0 commit comments

Comments
 (0)