All of lore.kernel.org
 help / color / mirror / Atom feed
* PC Engines APU/APU2 led driver
@ 2017-09-11  5:35 Alan Mizrahi
  2017-09-11  6:15 ` Pavel Machek
  2017-09-11 20:46 ` Jacek Anaszewski
  0 siblings, 2 replies; 7+ messages in thread
From: Alan Mizrahi @ 2017-09-11  5:35 UTC (permalink / raw)
  To: linux-leds

[-- Attachment #1: Type: text/plain, Size: 3797 bytes --]

Hello,

I am writing a driver for the leds in PC Engines APU and APU2 boards
(see the attachment).

There was an attempt at this before (see
https://www.spinics.net/lists/linux-leds/msg07904.html), but it was not
accepted due to several issues.
So I tried to rewrite it completely, using leds-mlxpld.c as a base, and
it seems to be working.

But I'm getting this oops when trying to rmmod the module:

[52615.090143] BUG: unable to handle kernel paging request at
ffffc900000c5618
[52615.097435] IP: [<ffffffff811dd099>] ioread32+0x29/0x30
[52615.102835] PGD 11a00e067
[52615.105461] PUD 11a00f067
[52615.108251] PMD 11a014067
[52615.109543] PTE 0

[52615.113072] Oops: 0000 [#1] PREEMPT SMP
[52615.117150] Modules linked in: ledtrig_heartbeat arc4 ath10k_pci
ath10k_core ath mac80211 crct10dif_pclmul crc32_pclmul crc32c_intel
ghash_clmulni_intel aesni_
intel leds_apu(-) aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd
ccp sdhci_pci sdhci cfg80211 mmc_core led_class sha256_generic
sha1_generic rng_core
[52615.146823] CPU: 1 PID: 892 Comm: rmmod Not tainted 4.9.47 #37
[52615.152864] Hardware name: PC Engines APU2/APU2, BIOS 4.0.7 02/28/2017
[52615.159656] task: ffff880118538b40 task.stack: ffffc90001480000
[52615.165917] RIP: 0010:[<ffffffff811dd099>]  [<ffffffff811dd099>]
ioread32+0x29/0x30
[52615.173967] RSP: 0018:ffffc90001483dd0  EFLAGS: 00010292
[52615.179479] RAX: 0000000000000000 RBX: ffff8801185292c8 RCX:
000000018080007d
[52615.186933] RDX: 0000000000000001 RSI: 0000000000000000 RDI:
ffffc900000c5618
[52615.194342] RBP: 0000000000000000 R08: 0000000000000001 R09:
ffff88011ec0e8c0
[52615.201709] R10: ffff88011a004460 R11: ffff88011a001c00 R12:
0000000000000008
[52615.209057] R13: ffff88011a004440 R14: ffff88011a0042c0 R15:
00000000024ae010
[52615.216527] FS:  00007f665d212700(0000) GS:ffff88011ec80000(0000)
knlGS:0000000000000000
[52615.224873] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[52615.230828] CR2: ffffc900000c5618 CR3: 00000001180bc000 CR4:
00000000000406e0
[52615.238273] Stack:
[52615.240306]  ffffffffa0101023 ffff8801185292c8 ffff8801185293a0
ffffffffa0010076
[52615.248041]  ffffc90001483e08 ffff8801185f8010 ffffffff812923c0
ffff88011a312f00
[52615.255846]  ffff88011a004460 ffff8801185f8010 ffffffffa01011e8
ffffffff816370e0
[52615.263610] Call Trace:
[52615.266136]  [<ffffffffa0101023>] ? apu2_led_brightness_set+0x23/0x58
[leds_apu]
[52615.273805]  [<ffffffffa0010076>] ? led_classdev_unregister+0x46/0xa0
[led_class]
[52615.281594]  [<ffffffff812923c0>] ? release_nodes+0xf0/0x1b8
[52615.287483]  [<ffffffff8128f615>] ? __device_release_driver+0x9d/0x140
[52615.294381]  [<ffffffff8128fe41>] ? device_release_driver+0x19/0x28
[52615.300799]  [<ffffffff8128eabb>] ? bus_remove_device+0xeb/0x130
[52615.307016]  [<ffffffff8128bb79>] ? device_del+0x121/0x258
[52615.312729]  [<ffffffff8129158e>] ? platform_device_del+0x1e/0x70
[52615.319110]  [<ffffffff812915e9>] ? platform_device_unregister+0x9/0x20
[52615.325925]  [<ffffffffa01010b1>] ? apu_led_exit+0xf/0x1b [leds_apu]
[52615.332471]  [<ffffffff810919dc>] ? SyS_delete_module+0x18c/0x1d0
[52615.338761]  [<ffffffff810010b6>] ? exit_to_usermode_loop+0x66/0x70
[52615.345245]  [<ffffffff813fb560>] ? entry_SYSCALL_64_fastpath+0x13/0x94
[52615.352092] Code: 40 00 48 81 ff ff ff 03 00 77 20 48 81 ff 00 00 01
00 76 05 0f b7 d7 ed c3 48 c7 c6 fc df 4d 81 e8 35 ff ff ff b8 ff ff ff
ff c3 <8b> 07 c3 0f 1f 40 00 48 81 fe ff ff 03 00 48 89 f2 77 1f 48 81
[52615.373340] RIP  [<ffffffff811dd099>] ioread32+0x29/0x30
[52615.378891]  RSP <ffffc90001483dd0>
[52615.382547] CR2: ffffc900000c5618
[52615.385932] ---[ end trace 88328a1715960e7c ]---
[52615.390731] note: rmmod[892] exited with preempt_count 1


Any ideas and recommendations would be greatly appreciated.

Best regards,

Alan


[-- Attachment #2: leds-apu.c --]
[-- Type: text/plain, Size: 8390 bytes --]

/*
 * drivers/leds/leds-apu.c
 * Copyright (C) 2017 Alan Mizrahi, alan at mizrahi dot com dot ve
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the names of the copyright holders nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <linux/dmi.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/platform_device.h>

#define APU1_FCH_ACPI_MMIO_BASE 0xFED80000
#define APU1_FCH_GPIO_BASE      (APU1_FCH_ACPI_MMIO_BASE + 0x1BD)
#define APU1_LEDON              0x08
#define APU1_LEDOFF             0xC8
#define APU1_NUM_GPIO           3
#define APU1_IOSIZE             sizeof(u8)

#define APU2_FCH_ACPI_MMIO_BASE 0xFED80000
#define APU2_FCH_GPIO_BASE      (APU2_FCH_ACPI_MMIO_BASE + 0x1500)
#define APU2_GPIO_BIT_WRITE     22
#define APU2_APU2_NUM_GPIO      4
#define APU2_IOSIZE             sizeof(u32)

/* LED access parameters */
struct apu_param {
	void __iomem *addr; /* for ioread/iowrite */
};

/* LED private data */
struct apu_led_priv {
	struct led_classdev cdev;
	struct apu_param param;
};
#define cdev_to_priv(c) container_of(c, struct apu_led_priv, cdev)

/* LED profile */
struct apu_led_profile {
	const char *name;
	enum led_brightness brightness;
	unsigned long offset; /* for devm_ioremap */
};

/* Supported platform types */
enum apu_led_platform_types {
	LED_PLATFORM_APU1,
	LED_PLATFORM_APU2,
};

struct apu_led_pdata {
	struct platform_device *pdev;
	struct apu_led_priv *pled;
	struct apu_led_profile *profile;
	enum apu_led_platform_types platform;
	int num_led_instances;
	int iosize; /* for devm_ioremap() */
	spinlock_t lock;
};

static struct apu_led_pdata *apu_led;

static struct apu_led_profile apu1_led_profile[] = {
	{ "apu:1", 1,       APU1_FCH_GPIO_BASE + 0 * APU1_IOSIZE },
	{ "apu:2", LED_OFF, APU1_FCH_GPIO_BASE + 1 * APU1_IOSIZE },
	{ "apu:3", LED_OFF, APU1_FCH_GPIO_BASE + 2 * APU1_IOSIZE },
};

static struct apu_led_profile apu2_led_profile[] = {
	{ "apu2:1", 1,       APU2_FCH_GPIO_BASE + 68 * APU2_IOSIZE },
	{ "apu2:2", LED_OFF, APU2_FCH_GPIO_BASE + 69 * APU2_IOSIZE },
	{ "apu2:3", LED_OFF, APU2_FCH_GPIO_BASE + 70 * APU2_IOSIZE },
};

static struct dmi_system_id apu_led_dmi_table[] __initdata = {
	{
		.ident = "apu",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"),
			DMI_MATCH(DMI_PRODUCT_NAME, "APU")
		}
	},
	{
		.ident = "apu2",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"),
			DMI_MATCH(DMI_BOARD_NAME, "APU2")
		}
	},
	{}
};
MODULE_DEVICE_TABLE(dmi, apu_led_dmi_table);

static void apu1_led_brightness_set(struct led_classdev *led, enum led_brightness value)
{
	struct apu_led_priv *pled = cdev_to_priv(led);

	spin_lock(&apu_led->lock);
	iowrite8(value ? APU1_LEDON : APU1_LEDOFF, pled->param.addr);
	spin_unlock(&apu_led->lock);

	return;
}

static void apu2_led_brightness_set(struct led_classdev *led, enum led_brightness value)
{
	struct apu_led_priv *pled = cdev_to_priv(led);
	u32 value_new;

	spin_lock(&apu_led->lock);

	value_new = ioread32(pled->param.addr);

	if (value)
		value_new &= ~BIT(APU2_GPIO_BIT_WRITE);
	else
		value_new |= BIT(APU2_GPIO_BIT_WRITE);

	iowrite32(value_new, pled->param.addr);

	spin_unlock(&apu_led->lock);
	return;
}

/*
 * Does the hardware support this?
 *
static int apu1_led_blink_set(struct led_classdev *led, unsigned long *delay_on, unsigned long *delay_off)
{
	struct apu_led_priv *pled = cdev_to_priv(led);
	return 0;
}
static int apu2_led_blink_set(struct led_classdev *led, unsigned long *delay_on, unsigned long *delay_off)
{
	struct apu_led_priv *pled = cdev_to_priv(led);
	return 0;
}
*/

static int apu_led_config(struct device *dev, struct apu_led_pdata *apuld)
{
	int i;
	int err;

	apu_led->pled = devm_kzalloc(dev, sizeof(struct apu_led_priv) * apu_led->num_led_instances, GFP_KERNEL);

	if (!apu_led->pled)
		return -ENOMEM;

	for (i = 0; i < apu_led->num_led_instances; i++) {
		apu_led->pled[i].cdev.name = apu_led->profile[i].name;
		apu_led->pled[i].cdev.brightness = apu_led->profile[i].brightness;
		apu_led->pled[i].cdev.max_brightness = 1;
		if (apu_led->platform == LED_PLATFORM_APU1) {
			apu_led->pled[i].cdev.brightness_set = apu1_led_brightness_set;
			/* apu_led->pled[i].cdev.blink_set   = apu1_led_blink_set; */
		} else if (apu_led->platform == LED_PLATFORM_APU2) {
			apu_led->pled[i].cdev.brightness_set = apu2_led_brightness_set;
			/* apu_led->pled[i].cdev.blink_set   = apu2_led_blink_set; */
		}
		apu_led->pled[i].cdev.flags = LED_CORE_SUSPENDRESUME;

		err = devm_led_classdev_register(dev, &apu_led->pled[i].cdev);
		if (err)
			return err;

		apu_led->pled[i].param.addr = devm_ioremap(dev, apu_led->profile[i].offset, apu_led->iosize);
		if (!apu_led->pled[i].param.addr)
			return -ENOMEM;

		if (apu_led->profile[i].brightness)
			apu_led->pled[i].cdev.brightness_set(&apu_led->pled[i].cdev, apu_led->profile[i].brightness);
	}

	return 0;
}

static int __init apu_led_probe(struct platform_device *pdev)
{
	apu_led = devm_kzalloc(&pdev->dev, sizeof(*apu_led), GFP_KERNEL);

	if (!apu_led)
		return -ENOMEM;

	apu_led->pdev = pdev;

	if (dmi_match(DMI_BOARD_NAME, "APU")) {
		apu_led->profile = apu1_led_profile;
		apu_led->platform = LED_PLATFORM_APU1;
		apu_led->num_led_instances = ARRAY_SIZE(apu1_led_profile);
		apu_led->iosize = APU1_IOSIZE;
	} else if (dmi_match(DMI_BOARD_NAME, "APU2")) {
		apu_led->profile = apu2_led_profile;
		apu_led->platform = LED_PLATFORM_APU2;
		apu_led->num_led_instances = ARRAY_SIZE(apu2_led_profile);
		apu_led->iosize = APU2_IOSIZE;
	}

	spin_lock_init(&apu_led->lock);
	return apu_led_config(&pdev->dev, apu_led);
}

static struct platform_driver apu_led_driver = {
	.driver = {
		.name = KBUILD_MODNAME,
	},
};

static int __init apu_led_init(void)
{
	struct platform_device *pdev;
	int err;

	if (!dmi_match(DMI_SYS_VENDOR, "PC Engines")) {
		pr_err("No PC Engines board detected\n");
		return -ENODEV;
	}
	if (!(dmi_match(DMI_PRODUCT_NAME, "APU") || dmi_match(DMI_PRODUCT_NAME, "APU2"))) {
		printk(KERN_ERR "Unknown PC Engines board: %s\n", dmi_get_system_info(DMI_PRODUCT_NAME));
		return -ENODEV;
	}

	pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
	if (IS_ERR(pdev)) {
		pr_err("Device allocation failed\n");
		return PTR_ERR(pdev);
	}

	err = platform_driver_probe(&apu_led_driver, apu_led_probe);
	if (err) {
		pr_err("Probe platform driver failed\n");
		platform_device_unregister(pdev);
	}

	return err;
}

static void __exit apu_led_exit(void)
{
	platform_device_unregister(apu_led->pdev);
	platform_driver_unregister(&apu_led_driver);
}

module_init(apu_led_init);
module_exit(apu_led_exit);

MODULE_AUTHOR("Alan Mizrahi, alan at mizrahi dot com dot ve");
MODULE_DESCRIPTION("PC Engines APU family LED driver");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:leds_apu");

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PC Engines APU/APU2 led driver
  2017-09-11  5:35 PC Engines APU/APU2 led driver Alan Mizrahi
@ 2017-09-11  6:15 ` Pavel Machek
  2017-09-11  9:45   ` Alan Mizrahi
  2017-09-11 20:46 ` Jacek Anaszewski
  1 sibling, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2017-09-11  6:15 UTC (permalink / raw)
  To: Alan Mizrahi; +Cc: linux-leds

[-- Attachment #1: Type: text/plain, Size: 1226 bytes --]

Hi!

> static int __init apu_led_init(void)
> {
> 	struct platform_device *pdev;
> 	int err;
> 
> 	if (!dmi_match(DMI_SYS_VENDOR, "PC Engines")) {
> 		pr_err("No PC Engines board detected\n");
> 		return -ENODEV;
> 	}
> 	if (!(dmi_match(DMI_PRODUCT_NAME, "APU") || dmi_match(DMI_PRODUCT_NAME, "APU2"))) {
> 		printk(KERN_ERR "Unknown PC Engines board: %s\n", dmi_get_system_info(DMI_PRODUCT_NAME));
> 		return -ENODEV;
> 	}
> 
> 	pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
> 	if (IS_ERR(pdev)) {
> 		pr_err("Device allocation failed\n");
> 		return PTR_ERR(pdev);
> 	}
> 
> 	err = platform_driver_probe(&apu_led_driver, apu_led_probe);
> 	if (err) {
> 		pr_err("Probe platform driver failed\n");
> 		platform_device_unregister(pdev);
> 	}
> 
> 	return err;
> }
> 
> static void __exit apu_led_exit(void)
> {
> 	platform_device_unregister(apu_led->pdev);
> 	platform_driver_unregister(&apu_led_driver);
> }

Normally, I'd expect _exit() to be 'reverse' of _init(). That is I'd
expect reverese order there.
								Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PC Engines APU/APU2 led driver
  2017-09-11  6:15 ` Pavel Machek
@ 2017-09-11  9:45   ` Alan Mizrahi
  2017-09-16 13:52     ` Pavel Machek
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Mizrahi @ 2017-09-11  9:45 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-leds

>> static int __init apu_led_init(void)
>> {
>> 	struct platform_device *pdev;
>> 	int err;
>>
>> 	if (!dmi_match(DMI_SYS_VENDOR, "PC Engines")) {
>> 		pr_err("No PC Engines board detected\n");
>> 		return -ENODEV;
>> 	}
>> 	if (!(dmi_match(DMI_PRODUCT_NAME, "APU") || dmi_match(DMI_PRODUCT_NAME, "APU2"))) {
>> 		printk(KERN_ERR "Unknown PC Engines board: %s\n", dmi_get_system_info(DMI_PRODUCT_NAME));
>> 		return -ENODEV;
>> 	}
>>
>> 	pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
>> 	if (IS_ERR(pdev)) {
>> 		pr_err("Device allocation failed\n");
>> 		return PTR_ERR(pdev);
>> 	}
>>
>> 	err = platform_driver_probe(&apu_led_driver, apu_led_probe);
>> 	if (err) {
>> 		pr_err("Probe platform driver failed\n");
>> 		platform_device_unregister(pdev);
>> 	}
>>
>> 	return err;
>> }
>>
>> static void __exit apu_led_exit(void)
>> {
>> 	platform_device_unregister(apu_led->pdev);
>> 	platform_driver_unregister(&apu_led_driver);
>> }
> 
> Normally, I'd expect _exit() to be 'reverse' of _init(). That is I'd
> expect reverese order there.

That looked promising, but after inverting the order of the calls in
apu_led_exit(), the problem is still there but with a slightly different
backtrace:

[   11.320368] BUG: unable to handle kernel paging request at
ffffc900000b5618
[   11.327702] IP: [<ffffffff811dd099>] ioread32+0x29/0x30
[   11.333108] PGD 11a00e067 [   11.335708] PUD 11a00f067
PMD 11a014067 [   11.339807] PTE 0
[   11.341783]
[   11.343364] Oops: 0000 [#1] PREEMPT SMP
[   11.347305] Modules linked in: arc4 ath10k_pci ath10k_core ath
mac80211 crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intele
[   11.375310] CPU: 2 PID: 286 Comm: rmmod Not tainted 4.9.47 #37
[   11.381342] Hardware name: PC Engines APU2/APU2, BIOS 4.0.7 02/28/2017
[   11.388091] task: ffff880119af6540 task.stack: ffffc90000184000
[   11.394168] RIP: 0010:[<ffffffff811dd099>]  [<ffffffff811dd099>]
ioread32+0x29/0x30
[   11.402044] RSP: 0018:ffffc90000187e40  EFLAGS: 00010292
[   11.407567] RAX: 0000000000000000 RBX: ffff88011a1e4ac8 RCX:
0000000000001a22
[   11.414966] RDX: 0000000000000001 RSI: 0000000000000000 RDI:
ffffc900000b5618
[   11.422416] RBP: 0000000000000000 R08: 00000000000195a0 R09:
ffff88011ed0e8c0
[   11.429785] R10: ffffea0004686b80 R11: ffff88011a001c00 R12:
0000000000000008
[   11.437184] R13: ffff88011a1ae480 R14: ffff88011a1ae460 R15:
00000000007c5010
[   11.444535] FS:  00007f12f96ec700(0000) GS:ffff88011ed00000(0000)
knlGS:0000000000000000
[   11.452906] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   11.458842] CR2: ffffc900000b5618 CR3: 0000000115dee000 CR4:
00000000000406e0
[   11.466308] Stack:
[   11.468434]  ffffffffa00d1023 ffff88011a1e4ac8 ffff88011a1e4ba0
ffffffffa005e076
[   11.476255]  ffffc90000187e78 ffff8801196ab810 ffffffff812923c0
ffff880119528dc0
[   11.484073]  ffff88011a1ae4a0 ffff8801196ab810 ffffffffa00d11e8
ffff8801196ab870
[   11.491852] Call Trace:
[   11.494427]  [<ffffffffa00d1023>] ? apu2_led_brightness_set+0x23/0x58
[leds_apu]
[   11.502178]  [<ffffffffa005e076>] ? led_classdev_unregister+0x46/0xa0
[led_class]
[   11.509957]  [<ffffffff812923c0>] ? release_nodes+0xf0/0x1b8
[   11.515889]  [<ffffffff8128f615>] ? __device_release_driver+0x9d/0x140
[   11.522725]  [<ffffffff8128fef4>] ? driver_detach+0xa4/0xb0
[   11.528507]  [<ffffffff8128ed53>] ? bus_remove_driver+0x43/0x98
[   11.534615]  [<ffffffffa00d10a7>] ? apu_led_exit+0xc/0x1b [leds_apu]
[   11.541267]  [<ffffffff810919dc>] ? SyS_delete_module+0x18c/0x1d0
[   11.547653]  [<ffffffff810010b6>] ? exit_to_usermode_loop+0x66/0x70
[   11.554152]  [<ffffffff813fb560>] ? entry_SYSCALL_64_fastpath+0x13/0x94
[   11.560940] Code: 40 00 48 81 ff ff ff 03 00 77 20 48 81 ff 00 00 01
00 76 05 0f b7 d7 ed c3 48 c7 c6 fc df 4d 81 e8 35 ff ff ff b8 ff
[   11.582458] RIP [   11.582797] ath10k_pci 0000:04:00.0: no channel
configured; ignoring frame(s)!
[   11.591649]  [<ffffffff811dd099>] ioread32+0x29/0x30
 RSP <ffffc90000187e40>
[   11.599071] CR2: ffffc900000b5618
[   11.602472] ---[ end trace 138442b63d5d23b3 ]---


Any other ideas?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PC Engines APU/APU2 led driver
  2017-09-11  5:35 PC Engines APU/APU2 led driver Alan Mizrahi
  2017-09-11  6:15 ` Pavel Machek
@ 2017-09-11 20:46 ` Jacek Anaszewski
  1 sibling, 0 replies; 7+ messages in thread
From: Jacek Anaszewski @ 2017-09-11 20:46 UTC (permalink / raw)
  To: Alan Mizrahi, linux-leds

Hi Alan,

On 09/11/2017 07:35 AM, Alan Mizrahi wrote:
> Hello,
> 
> I am writing a driver for the leds in PC Engines APU and APU2 boards
> (see the attachment).
> 
> There was an attempt at this before (see
> https://www.spinics.net/lists/linux-leds/msg07904.html), but it was not
> accepted due to several issues.
> So I tried to rewrite it completely, using leds-mlxpld.c as a base, and
> it seems to be working.
> 
> But I'm getting this oops when trying to rmmod the module:
> 
> [52615.090143] BUG: unable to handle kernel paging request at
> ffffc900000c5618
> [52615.097435] IP: [<ffffffff811dd099>] ioread32+0x29/0x30
> [52615.102835] PGD 11a00e067
> [52615.105461] PUD 11a00f067
> [52615.108251] PMD 11a014067
> [52615.109543] PTE 0
> 
> [52615.113072] Oops: 0000 [#1] PREEMPT SMP
> [52615.117150] Modules linked in: ledtrig_heartbeat arc4 ath10k_pci

It seems that you have LED registered on heartbeat trigger events.
In theory releasing LED class driver with active heartbeat trigger
should be safe, but there could be some specific path when removing
a module.

You could try to chase it down with that diagnosis in mind.

Best regards,
Jacek Anaszewski

> ath10k_core ath mac80211 crct10dif_pclmul crc32_pclmul crc32c_intel
> ghash_clmulni_intel aesni_
> intel leds_apu(-) aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd
> ccp sdhci_pci sdhci cfg80211 mmc_core led_class sha256_generic
> sha1_generic rng_core
> [52615.146823] CPU: 1 PID: 892 Comm: rmmod Not tainted 4.9.47 #37
> [52615.152864] Hardware name: PC Engines APU2/APU2, BIOS 4.0.7 02/28/2017
> [52615.159656] task: ffff880118538b40 task.stack: ffffc90001480000
> [52615.165917] RIP: 0010:[<ffffffff811dd099>]  [<ffffffff811dd099>]
> ioread32+0x29/0x30
> [52615.173967] RSP: 0018:ffffc90001483dd0  EFLAGS: 00010292
> [52615.179479] RAX: 0000000000000000 RBX: ffff8801185292c8 RCX:
> 000000018080007d
> [52615.186933] RDX: 0000000000000001 RSI: 0000000000000000 RDI:
> ffffc900000c5618
> [52615.194342] RBP: 0000000000000000 R08: 0000000000000001 R09:
> ffff88011ec0e8c0
> [52615.201709] R10: ffff88011a004460 R11: ffff88011a001c00 R12:
> 0000000000000008
> [52615.209057] R13: ffff88011a004440 R14: ffff88011a0042c0 R15:
> 00000000024ae010
> [52615.216527] FS:  00007f665d212700(0000) GS:ffff88011ec80000(0000)
> knlGS:0000000000000000
> [52615.224873] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [52615.230828] CR2: ffffc900000c5618 CR3: 00000001180bc000 CR4:
> 00000000000406e0
> [52615.238273] Stack:
> [52615.240306]  ffffffffa0101023 ffff8801185292c8 ffff8801185293a0
> ffffffffa0010076
> [52615.248041]  ffffc90001483e08 ffff8801185f8010 ffffffff812923c0
> ffff88011a312f00
> [52615.255846]  ffff88011a004460 ffff8801185f8010 ffffffffa01011e8
> ffffffff816370e0
> [52615.263610] Call Trace:
> [52615.266136]  [<ffffffffa0101023>] ? apu2_led_brightness_set+0x23/0x58
> [leds_apu]
> [52615.273805]  [<ffffffffa0010076>] ? led_classdev_unregister+0x46/0xa0
> [led_class]
> [52615.281594]  [<ffffffff812923c0>] ? release_nodes+0xf0/0x1b8
> [52615.287483]  [<ffffffff8128f615>] ? __device_release_driver+0x9d/0x140
> [52615.294381]  [<ffffffff8128fe41>] ? device_release_driver+0x19/0x28
> [52615.300799]  [<ffffffff8128eabb>] ? bus_remove_device+0xeb/0x130
> [52615.307016]  [<ffffffff8128bb79>] ? device_del+0x121/0x258
> [52615.312729]  [<ffffffff8129158e>] ? platform_device_del+0x1e/0x70
> [52615.319110]  [<ffffffff812915e9>] ? platform_device_unregister+0x9/0x20
> [52615.325925]  [<ffffffffa01010b1>] ? apu_led_exit+0xf/0x1b [leds_apu]
> [52615.332471]  [<ffffffff810919dc>] ? SyS_delete_module+0x18c/0x1d0
> [52615.338761]  [<ffffffff810010b6>] ? exit_to_usermode_loop+0x66/0x70
> [52615.345245]  [<ffffffff813fb560>] ? entry_SYSCALL_64_fastpath+0x13/0x94
> [52615.352092] Code: 40 00 48 81 ff ff ff 03 00 77 20 48 81 ff 00 00 01
> 00 76 05 0f b7 d7 ed c3 48 c7 c6 fc df 4d 81 e8 35 ff ff ff b8 ff ff ff
> ff c3 <8b> 07 c3 0f 1f 40 00 48 81 fe ff ff 03 00 48 89 f2 77 1f 48 81
> [52615.373340] RIP  [<ffffffff811dd099>] ioread32+0x29/0x30
> [52615.378891]  RSP <ffffc90001483dd0>
> [52615.382547] CR2: ffffc900000c5618
> [52615.385932] ---[ end trace 88328a1715960e7c ]---
> [52615.390731] note: rmmod[892] exited with preempt_count 1
> 
> 
> Any ideas and recommendations would be greatly appreciated.
> 
> Best regards,
> 
> Alan
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PC Engines APU/APU2 led driver
  2017-09-11  9:45   ` Alan Mizrahi
@ 2017-09-16 13:52     ` Pavel Machek
  2017-09-16 13:57       ` Alan Mizrahi
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2017-09-16 13:52 UTC (permalink / raw)
  To: Alan Mizrahi; +Cc: linux-leds

[-- Attachment #1: Type: text/plain, Size: 2753 bytes --]

Hi!

> >> static void __exit apu_led_exit(void)
> >> {
> >> 	platform_device_unregister(apu_led->pdev);
> >> 	platform_driver_unregister(&apu_led_driver);
> >> }
> > 
> > Normally, I'd expect _exit() to be 'reverse' of _init(). That is I'd
> > expect reverese order there.
> 
> That looked promising, but after inverting the order of the calls in
> apu_led_exit(), the problem is still there but with a slightly different
> backtrace:
> 
> [   11.320368] BUG: unable to handle kernel paging request at
> ffffc900000b5618
> [   11.327702] IP: [<ffffffff811dd099>] ioread32+0x29/0x30
> [   11.333108] PGD 11a00e067 [   11.335708] PUD 11a00f067
> PMD 11a014067 [   11.339807] PTE 0
> [   11.341783]
> [   11.343364] Oops: 0000 [#1] PREEMPT SMP
> [   11.347305] Modules linked in: arc4 ath10k_pci ath10k_core ath
> mac80211 crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intele
> [   11.375310] CPU: 2 PID: 286 Comm: rmmod Not tainted 4.9.47 #37
> [   11.381342] Hardware name: PC Engines APU2/APU2, BIOS 4.0.7 02/28/2017
> [   11.388091] task: ffff880119af6540 task.stack: ffffc90000184000
> [   11.394168] RIP: 0010:[<ffffffff811dd099>]  [<ffffffff811dd099>]
> ioread32+0x29/0x30
> [   11.402044] RSP: 0018:ffffc90000187e40  EFLAGS: 00010292
> [   11.407567] RAX: 0000000000000000 RBX: ffff88011a1e4ac8 RCX:
> 0000000000001a22
> [   11.414966] RDX: 0000000000000001 RSI: 0000000000000000 RDI:
> ffffc900000b5618
> [   11.422416] RBP: 0000000000000000 R08: 00000000000195a0 R09:
> ffff88011ed0e8c0
> [   11.429785] R10: ffffea0004686b80 R11: ffff88011a001c00 R12:
> 0000000000000008
> [   11.437184] R13: ffff88011a1ae480 R14: ffff88011a1ae460 R15:
> 00000000007c5010
> [   11.444535] FS:  00007f12f96ec700(0000) GS:ffff88011ed00000(0000)
> knlGS:0000000000000000
> [   11.452906] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [   11.458842] CR2: ffffc900000b5618 CR3: 0000000115dee000 CR4:
> 00000000000406e0
> [   11.466308] Stack:
> [   11.468434]  ffffffffa00d1023 ffff88011a1e4ac8 ffff88011a1e4ba0
> ffffffffa005e076
> [   11.476255]  ffffc90000187e78 ffff8801196ab810 ffffffff812923c0
> ffff880119528dc0
> [   11.484073]  ffff88011a1ae4a0 ffff8801196ab810 ffffffffa00d11e8
> ffff8801196ab870
> [   11.491852] Call Trace:
> [   11.494427]  [<ffffffffa00d1023>] ? apu2_led_brightness_set+0x23/0x58
> [leds_apu]
> [   11.502178]  [<ffffffffa005e076>] ? led_classdev_unregister+0x46/0xa0
> [led_class]

Hmm. can you put debug prints where in brightness_set() it fails?

Is devm_() compatible with unregistering by hand?

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PC Engines APU/APU2 led driver
  2017-09-16 13:52     ` Pavel Machek
@ 2017-09-16 13:57       ` Alan Mizrahi
  2017-09-16 15:27         ` Jacek Anaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Mizrahi @ 2017-09-16 13:57 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-leds


On 2017-09-16 22:52, Pavel Machek wrote:
> Hi!
> 
>>>> static void __exit apu_led_exit(void)
>>>> {
>>>> 	platform_device_unregister(apu_led->pdev);
>>>> 	platform_driver_unregister(&apu_led_driver);
>>>> }
>>>
>>> Normally, I'd expect _exit() to be 'reverse' of _init(). That is I'd
>>> expect reverese order there.
>>
>> That looked promising, but after inverting the order of the calls in
>> apu_led_exit(), the problem is still there but with a slightly different
>> backtrace:
>>
>> [   11.320368] BUG: unable to handle kernel paging request at
>> ffffc900000b5618
>> [   11.327702] IP: [<ffffffff811dd099>] ioread32+0x29/0x30
>> [   11.333108] PGD 11a00e067 [   11.335708] PUD 11a00f067
>> PMD 11a014067 [   11.339807] PTE 0
>> [   11.341783]
>> [   11.343364] Oops: 0000 [#1] PREEMPT SMP
>> [   11.347305] Modules linked in: arc4 ath10k_pci ath10k_core ath
>> mac80211 crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intele
>> [   11.375310] CPU: 2 PID: 286 Comm: rmmod Not tainted 4.9.47 #37
>> [   11.381342] Hardware name: PC Engines APU2/APU2, BIOS 4.0.7 02/28/2017
>> [   11.388091] task: ffff880119af6540 task.stack: ffffc90000184000
>> [   11.394168] RIP: 0010:[<ffffffff811dd099>]  [<ffffffff811dd099>]
>> ioread32+0x29/0x30
>> [   11.402044] RSP: 0018:ffffc90000187e40  EFLAGS: 00010292
>> [   11.407567] RAX: 0000000000000000 RBX: ffff88011a1e4ac8 RCX:
>> 0000000000001a22
>> [   11.414966] RDX: 0000000000000001 RSI: 0000000000000000 RDI:
>> ffffc900000b5618
>> [   11.422416] RBP: 0000000000000000 R08: 00000000000195a0 R09:
>> ffff88011ed0e8c0
>> [   11.429785] R10: ffffea0004686b80 R11: ffff88011a001c00 R12:
>> 0000000000000008
>> [   11.437184] R13: ffff88011a1ae480 R14: ffff88011a1ae460 R15:
>> 00000000007c5010
>> [   11.444535] FS:  00007f12f96ec700(0000) GS:ffff88011ed00000(0000)
>> knlGS:0000000000000000
>> [   11.452906] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>> [   11.458842] CR2: ffffc900000b5618 CR3: 0000000115dee000 CR4:
>> 00000000000406e0
>> [   11.466308] Stack:
>> [   11.468434]  ffffffffa00d1023 ffff88011a1e4ac8 ffff88011a1e4ba0
>> ffffffffa005e076
>> [   11.476255]  ffffc90000187e78 ffff8801196ab810 ffffffff812923c0
>> ffff880119528dc0
>> [   11.484073]  ffff88011a1ae4a0 ffff8801196ab810 ffffffffa00d11e8
>> ffff8801196ab870
>> [   11.491852] Call Trace:
>> [   11.494427]  [<ffffffffa00d1023>] ? apu2_led_brightness_set+0x23/0x58
>> [leds_apu]
>> [   11.502178]  [<ffffffffa005e076>] ? led_classdev_unregister+0x46/0xa0
>> [led_class]
> 
> Hmm. can you put debug prints where in brightness_set() it fails?

That would be in ioread32().

> Is devm_() compatible with unregistering by hand?

I have no idea, but I based it on leds-mlxpld.c, and I assume it works
there.

Alan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PC Engines APU/APU2 led driver
  2017-09-16 13:57       ` Alan Mizrahi
@ 2017-09-16 15:27         ` Jacek Anaszewski
  0 siblings, 0 replies; 7+ messages in thread
From: Jacek Anaszewski @ 2017-09-16 15:27 UTC (permalink / raw)
  To: Alan Mizrahi, Pavel Machek; +Cc: linux-leds

Hi Alan,

On 09/16/2017 03:57 PM, Alan Mizrahi wrote:
> 
> On 2017-09-16 22:52, Pavel Machek wrote:
>> Hi!
>>
>>>>> static void __exit apu_led_exit(void)
>>>>> {
>>>>> 	platform_device_unregister(apu_led->pdev);
>>>>> 	platform_driver_unregister(&apu_led_driver);
>>>>> }
>>>>
>>>> Normally, I'd expect _exit() to be 'reverse' of _init(). That is I'd
>>>> expect reverese order there.
>>>
>>> That looked promising, but after inverting the order of the calls in
>>> apu_led_exit(), the problem is still there but with a slightly different
>>> backtrace:
>>>
>>> [   11.320368] BUG: unable to handle kernel paging request at
>>> ffffc900000b5618
>>> [   11.327702] IP: [<ffffffff811dd099>] ioread32+0x29/0x30
>>> [   11.333108] PGD 11a00e067 [   11.335708] PUD 11a00f067
>>> PMD 11a014067 [   11.339807] PTE 0
>>> [   11.341783]
>>> [   11.343364] Oops: 0000 [#1] PREEMPT SMP
>>> [   11.347305] Modules linked in: arc4 ath10k_pci ath10k_core ath
>>> mac80211 crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intele
>>> [   11.375310] CPU: 2 PID: 286 Comm: rmmod Not tainted 4.9.47 #37
>>> [   11.381342] Hardware name: PC Engines APU2/APU2, BIOS 4.0.7 02/28/2017
>>> [   11.388091] task: ffff880119af6540 task.stack: ffffc90000184000
>>> [   11.394168] RIP: 0010:[<ffffffff811dd099>]  [<ffffffff811dd099>]
>>> ioread32+0x29/0x30
>>> [   11.402044] RSP: 0018:ffffc90000187e40  EFLAGS: 00010292
>>> [   11.407567] RAX: 0000000000000000 RBX: ffff88011a1e4ac8 RCX:
>>> 0000000000001a22
>>> [   11.414966] RDX: 0000000000000001 RSI: 0000000000000000 RDI:
>>> ffffc900000b5618
>>> [   11.422416] RBP: 0000000000000000 R08: 00000000000195a0 R09:
>>> ffff88011ed0e8c0
>>> [   11.429785] R10: ffffea0004686b80 R11: ffff88011a001c00 R12:
>>> 0000000000000008
>>> [   11.437184] R13: ffff88011a1ae480 R14: ffff88011a1ae460 R15:
>>> 00000000007c5010
>>> [   11.444535] FS:  00007f12f96ec700(0000) GS:ffff88011ed00000(0000)
>>> knlGS:0000000000000000
>>> [   11.452906] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>>> [   11.458842] CR2: ffffc900000b5618 CR3: 0000000115dee000 CR4:
>>> 00000000000406e0
>>> [   11.466308] Stack:
>>> [   11.468434]  ffffffffa00d1023 ffff88011a1e4ac8 ffff88011a1e4ba0
>>> ffffffffa005e076
>>> [   11.476255]  ffffc90000187e78 ffff8801196ab810 ffffffff812923c0
>>> ffff880119528dc0
>>> [   11.484073]  ffff88011a1ae4a0 ffff8801196ab810 ffffffffa00d11e8
>>> ffff8801196ab870
>>> [   11.491852] Call Trace:
>>> [   11.494427]  [<ffffffffa00d1023>] ? apu2_led_brightness_set+0x23/0x58
>>> [leds_apu]
>>> [   11.502178]  [<ffffffffa005e076>] ? led_classdev_unregister+0x46/0xa0
>>> [led_class]
>>
>> Hmm. can you put debug prints where in brightness_set() it fails?
> 
> That would be in ioread32().
> 
>> Is devm_() compatible with unregistering by hand?
> 
> I have no idea, but I based it on leds-mlxpld.c, and I assume it works
> there.

Maybe this use case wasn't tested at all.

Could you try to switch to using
led_classdev_register()/led_classdev_unregister().

You should call led_classdev_unregister() from "remove" op that
should be added to your struct platform_driver apu_led_driver
initialization list.

-- 
Best regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-16 15:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-11  5:35 PC Engines APU/APU2 led driver Alan Mizrahi
2017-09-11  6:15 ` Pavel Machek
2017-09-11  9:45   ` Alan Mizrahi
2017-09-16 13:52     ` Pavel Machek
2017-09-16 13:57       ` Alan Mizrahi
2017-09-16 15:27         ` Jacek Anaszewski
2017-09-11 20:46 ` Jacek Anaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.