Skip to contentSkip to conversation

drm/nouveau: enable interrupts on cards with 32 intr lines

PATCH In review Adam Borowski 2 participants 2 messages Apr 2, 2017 – Apr 6, 2017 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau: enable interrupts on cards with 32 intr lines

The code attempts to enable them, but hits an undefined behaviour by shifting by the entire register's width:

    int lines = 32;
    u32 mask = (1 << lines) - 1;    // 00000000 on x86
    u32 mask = (1 << lines) - 1;    // ffffffff on arm (32)
    u32 mask = (1 << lines) - 1;    // 00000000 on arm64
    u32 mask = (1ULL << lines) - 1; // ffffffff everywhere

---
To be honest, I can't tell the difference other than UBSAN stopping its complaints, but the current code is obviously wrong.

 drivers/gpu/drm/nouveau/nvkm/subdev/gpio/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/subdev/gpio/base.c +1 -1
index 77c649723ad7..4a57defc99b3 100644
@@ -164,7 +164,7 @@ static int
 nvkm_gpio_fini(struct nvkm_subdev *subdev, bool suspend)
 {
 	struct nvkm_gpio *gpio = nvkm_gpio(subdev);
-	u32 mask = (1 << gpio->func->lines) - 1;
+	u32 mask = (1ULL << gpio->func->lines) - 1;
 
 	gpio->func->intr_mask(gpio, NVKM_GPIO_TOGGLED, mask, 0);
 	gpio->func->intr_stat(gpio, &mask, &mask);
Signature · 6 lines
2.11.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 20170402050328.9511-1-kilobyte-b9QjgO8OEXPVItvQsEIGlw@public.gmane.org

#2 lore raw
Quoted 2 lines · Adam Borowski

The code attempts to enable them, but hits an undefined behaviour by shifting by the entire register's width:

Good catch!

I've merged the patch, clarifying the commit title though to make it clear that it's *gpio* interrupts, and not interrupts in general.

Thanks,
Ben.

Quoted 21 lines
    int lines = 32;
    u32 mask = (1 << lines) - 1;    // 00000000 on x86
    u32 mask = (1 << lines) - 1;    // ffffffff on arm (32)
    u32 mask = (1 << lines) - 1;    // 00000000 on arm64
    u32 mask = (1ULL << lines) - 1; // ffffffff everywhere

---
To be honest, I can't tell the difference other than UBSAN stopping its complaints, but the current code is obviously wrong.

 drivers/gpu/drm/nouveau/nvkm/subdev/gpio/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/subdev/gpio/base.c +0 -0
index 77c649723ad7..4a57defc99b3 100644

drivers/gpu/drm/nouveau/nvkm/subdev/gpio/base.c static int · line 170

Quoted 8 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gpio/base.c +1 -1
@@ -164,7 +164,7 @@ static int
 nvkm_gpio_fini(struct nvkm_subdev *subdev, bool suspend)
 {
 	struct nvkm_gpio *gpio = nvkm_gpio(subdev);
-	u32 mask = (1 << gpio->func->lines) - 1;
+	u32 mask = (1ULL << gpio->func->lines) - 1;
 
 	gpio->func->intr_mask(gpio, NVKM_GPIO_TOGGLED, mask, 0);
 	gpio->func->intr_stat(gpio, &mask, &mask);

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau