/* * Copyright (C) 2016 National Instruments Corp. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include #include #include #include #include #include #define NIWD_CONTROL 0x01 #define NIWD_COUNTER2 0x02 #define NIWD_COUNTER1 0x03 #define NIWD_COUNTER0 0x04 #define NIWD_SEED2 0x05 #define NIWD_SEED1 0x06 #define NIWD_SEED0 0x07 #define NIWD_IO_SIZE 0x08 #define NIWD_CONTROL_MODE 0x80 #define NIWD_CONTROL_PROC_RESET 0x20 #define NIWD_CONTROL_PET 0x10 #define NIWD_CONTROL_RUNNING 0x08 #define NIWD_CONTROL_CAPTURECOUNTER 0x04 #define NIWD_CONTROL_RESET 0x02 #define NIWD_CONTROL_ALARM 0x01 #define NIWD_PERIOD_NS 30720 #define NIWD_MIN_TIMEOUT 1 #define NIWD_MAX_TIMEOUT 515 #define NIWD_DEFAULT_TIMEOUT 60 #define NIWD_NAME "ni903x_wdt" struct ni903x_wdt { struct device *dev; u16 io_base; struct watchdog_device wdd; }; static unsigned int timeout; module_param(timeout, uint, 0); MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (default=" __MODULE_STRING(NIWD_DEFAULT_TIMEOUT) ")"); static int nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, int, S_IRUGO); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); static void ni903x_start(struct ni903x_wdt *wdt) { u8 control = inb(wdt->io_base + NIWD_CONTROL); outb(control | NIWD_CONTROL_RESET, wdt->io_base + NIWD_CONTROL); outb(control | NIWD_CONTROL_PET, wdt->io_base + NIWD_CONTROL); } static int ni903x_wdd_set_timeout(struct watchdog_device *wdd, unsigned int timeout) { struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd); u32 counter = timeout * (1000000000 / NIWD_PERIOD_NS); outb(((0x00FF0000 & counter) >> 16), wdt->io_base + NIWD_SEED2); outb(((0x0000FF00 & counter) >> 8), wdt->io_base + NIWD_SEED1); outb((0x000000FF & counter), wdt->io_base + NIWD_SEED0); wdd->timeout = timeout; return 0; } static unsigned int ni903x_wdd_get_timeleft(struct watchdog_device *wdd) { struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd); u8 control, counter0, counter1, counter2; u32 counter; control = inb(wdt->io_base + NIWD_CONTROL); control |= NIWD_CONTROL_CAPTURECOUNTER; outb(control, wdt->io_base + NIWD_CONTROL); counter2 = inb(wdt->io_base + NIWD_COUNTER2); counter1 = inb(wdt->io_base + NIWD_COUNTER1); counter0 = inb(wdt->io_base + NIWD_COUNTER0); counter = (counter2 << 16) | (counter1 << 8) | counter0; return counter / (1000000000 / NIWD_PERIOD_NS); } static int ni903x_wdd_ping(struct watchdog_device *wdd) { struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd); u8 control; control = inb(wdt->io_base + NIWD_CONTROL); outb(control | NIWD_CONTROL_PET, wdt->io_base + NIWD_CONTROL); return 0; } static int ni903x_wdd_start(struct watchdog_device *wdd) { struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd); outb(NIWD_CONTROL_RESET | NIWD_CONTROL_PROC_RESET, wdt->io_base + NIWD_CONTROL); ni903x_wdd_set_timeout(wdd, wdd->timeout); ni903x_start(wdt); return 0; } static int ni903x_wdd_stop(struct watchdog_device *wdd) { struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd); outb(NIWD_CONTROL_RESET, wdt->io_base + NIWD_CONTROL); return 0; } static acpi_status ni903x_resources(struct acpi_resource *res, void *data) { struct ni903x_wdt *wdt = data; u16 io_size; switch (res->type) { case ACPI_RESOURCE_TYPE_IO: if (wdt->io_base != 0) { dev_err(wdt->dev, "too many IO resources\n"); return AE_ERROR; } wdt->io_base = res->data.io.minimum; io_size = res->data.io.address_length; if (io_size < NIWD_IO_SIZE) { dev_err(wdt->dev, "memory region too small\n"); return AE_ERROR; } if (!devm_request_region(wdt->dev, wdt->io_base, io_size, NIWD_NAME)) { dev_err(wdt->dev, "failed to get memory region\n"); return AE_ERROR; } return AE_OK; case ACPI_RESOURCE_TYPE_END_TAG: default: /* Ignore unsupported resources, e.g. IRQ */ return AE_OK; } } static const struct watchdog_info ni903x_wdd_info = { .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, .identity = "NI Watchdog", }; static const struct watchdog_ops ni903x_wdd_ops = { .owner = THIS_MODULE, .start = ni903x_wdd_start, .stop = ni903x_wdd_stop, .ping = ni903x_wdd_ping, .set_timeout = ni903x_wdd_set_timeout, .get_timeleft = ni903x_wdd_get_timeleft, }; static int ni903x_acpi_add(struct acpi_device *device) { struct device *dev = &device->dev; struct watchdog_device *wdd; struct ni903x_wdt *wdt; acpi_status status; int ret; wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); if (!wdt) return -ENOMEM; device->driver_data = wdt; wdt->dev = dev; status = acpi_walk_resources(device->handle, METHOD_NAME__CRS, ni903x_resources, wdt); if (ACPI_FAILURE(status) || wdt->io_base == 0) { dev_err(dev, "failed to get resources\n"); return -ENODEV; } wdd = &wdt->wdd; wdd->info = &ni903x_wdd_info; wdd->ops = &ni903x_wdd_ops; wdd->min_timeout = NIWD_MIN_TIMEOUT; wdd->max_timeout = NIWD_MAX_TIMEOUT; wdd->timeout = NIWD_DEFAULT_TIMEOUT; wdd->parent = dev; watchdog_set_drvdata(wdd, wdt); watchdog_set_nowayout(wdd, nowayout); ret = watchdog_init_timeout(wdd, timeout, dev); if (ret) dev_err(dev, "unable to set timeout value, using default\n"); ret = watchdog_register_device(wdd); if (ret) { dev_err(dev, "failed to register watchdog\n"); return ret; } /* Switch from boot mode to user mode */ outb(NIWD_CONTROL_RESET | NIWD_CONTROL_MODE, wdt->io_base + NIWD_CONTROL); dev_dbg(dev, "io_base=0x%04X, timeout=%d, nowayout=%d\n", wdt->io_base, timeout, nowayout); return 0; } static int ni903x_acpi_remove(struct acpi_device *device) { struct ni903x_wdt *wdt = acpi_driver_data(device); ni903x_wdd_stop(&wdt->wdd); watchdog_unregister_device(&wdt->wdd); return 0; } static const struct acpi_device_id ni903x_device_ids[] = { {"NIC775C", 0}, {"", 0}, }; MODULE_DEVICE_TABLE(acpi, ni903x_device_ids); static struct acpi_driver ni903x_acpi_driver = { .name = NIWD_NAME, .ids = ni903x_device_ids, .ops = { .add = ni903x_acpi_add, .remove = ni903x_acpi_remove, }, }; module_acpi_driver(ni903x_acpi_driver); MODULE_DESCRIPTION("NI 903x Watchdog"); MODULE_AUTHOR("Jeff Westfahl "); MODULE_AUTHOR("Kyle Roeschley "); MODULE_LICENSE("GPL"); e event is freed in 2 places. Solve this by only freeing the event in the atomic ioctl when it allocated its own event. This has been broken twice. The first time when the code was introduced, but only in the corner case when an event is allocated, but more crtc's were included by atomic check and then failing. This can mostly happen when you do an atomic modeset in i915 and the display clock is changed, which forces all crtc's to be included to the state. This has been broken worse by adding in-fences support, which caused the double free to be done unconditionally. [IGT] kms_rotation_crc: starting subtest primary-rotation-180 ============================================================================= BUG kmalloc-128 (Tainted: G U ): Object already free ----------------------------------------------------------------------------- Disabling lock debugging due to kernel taint INFO: Allocated in drm_atomic_helper_setup_commit+0x285/0x2f0 [drm_kms_helper] age=0 cpu=3 pid=1529 ___slab_alloc+0x308/0x3b0 __slab_alloc+0xd/0x20 kmem_cache_alloc_trace+0x92/0x1c0 drm_atomic_helper_setup_commit+0x285/0x2f0 [drm_kms_helper] intel_atomic_commit+0x35/0x4f0 [i915] drm_atomic_commit+0x46/0x50 [drm] drm_mode_atomic_ioctl+0x7d4/0xab0 [drm] drm_ioctl+0x2b3/0x490 [drm] do_vfs_ioctl+0x69c/0x700 SyS_ioctl+0x4e/0x80 entry_SYSCALL_64_fastpath+0x13/0x94 INFO: Freed in drm_event_cancel_free+0xa3/0xb0 [drm] age=0 cpu=3 pid=1529 __slab_free+0x48/0x2e0 kfree+0x159/0x1a0 drm_event_cancel_free+0xa3/0xb0 [drm] drm_mode_atomic_ioctl+0x86d/0xab0 [drm] drm_ioctl+0x2b3/0x490 [drm] do_vfs_ioctl+0x69c/0x700 SyS_ioctl+0x4e/0x80 entry_SYSCALL_64_fastpath+0x13/0x94 INFO: Slab 0xffffde1f0997b080 objects=17 used=2 fp=0xffff92fb65ec2578 flags=0x200000000008101 INFO: Object 0xffff92fb65ec2578 @offset=1400 fp=0xffff92fb65ec2ae8 Redzone ffff92fb65ec2570: bb bb bb bb bb bb bb bb ........ Object ffff92fb65ec2578: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec2588: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec2598: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25a8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25b8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25c8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25d8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25e8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk. Redzone ffff92fb65ec25f8: bb bb bb bb bb bb bb bb ........ Padding ffff92fb65ec2738: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ CPU: 3 PID: 180 Comm: kworker/3:2 Tainted: G BU 4.10.0-rc6-patser+ #5039 Hardware name: /NUC5PPYB, BIOS PYBSWCEL.86A.0031.2015.0601.1712 06/01/2015 Workqueue: events intel_atomic_helper_free_state [i915] Call Trace: dump_stack+0x4d/0x6d print_trailer+0x20c/0x220 free_debug_processing+0x1c6/0x330 ? drm_atomic_state_default_clear+0xf7/0x1c0 [drm] __slab_free+0x48/0x2e0 ? drm_atomic_state_default_clear+0xf7/0x1c0 [drm] kfree+0x159/0x1a0 drm_atomic_state_default_clear+0xf7/0x1c0 [drm] ? drm_atomic_state_clear+0x30/0x30 [drm] intel_atomic_state_clear+0xd/0x20 [i915] drm_atomic_state_clear+0x1a/0x30 [drm] __drm_atomic_state_free+0x13/0x60 [drm] intel_atomic_helper_free_state+0x5d/0x70 [i915] process_one_work+0x260/0x4a0 worker_thread+0x2d1/0x4f0 kthread+0x127/0x130 ? process_one_work+0x4a0/0x4a0 ? kthread_stop+0x120/0x120 ret_from_fork+0x29/0x40 FIX kmalloc-128: Object at 0xffff92fb65ec2578 not freed Fixes: 3b24f7d67581 ("drm/atomic: Add struct drm_crtc_commit to track async updates") Fixes: 9626014258a5 ("drm/fence: add in-fences support") Cc: <stable@vger.kernel.org> # v4.8+ Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/1485854725-27640-1-git-send-email-maarten.lankhorst@linux.intel.com
Diffstat (limited to 'include/uapi/asm-generic/swab.h')