Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'stm-for-greg-20160420' of git://git.kernel.org/pub/scm/linux/kernel/git/ash/stm into char-misc-next

Alexander writes:

stm class/intel_th: Updates for 4.7

These are:
* Intel TH/MSU: improved resource handling and releasing
* Intel TH/MSU: rehashed locking around buffer accesses
* Intel TH/outputs: better sysfs group handling
* Intel TH, STM: various bugfixes and smaller improvements
* Intel TH: added a PCI ID for Broxton-M SOC

+134 -89
+1
MAINTAINERS
··· 9754 9754 SYSTEM TRACE MODULE CLASS 9755 9755 M: Alexander Shishkin <alexander.shishkin@linux.intel.com> 9756 9756 S: Maintained 9757 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/ash/stm.git 9757 9758 F: Documentation/trace/stm.txt 9758 9759 F: drivers/hwtracing/stm/ 9759 9760 F: include/linux/stm.h
+27 -2
drivers/hwtracing/intel_th/core.c
··· 71 71 if (ret) 72 72 return ret; 73 73 74 + if (thdrv->attr_group) { 75 + ret = sysfs_create_group(&thdev->dev.kobj, thdrv->attr_group); 76 + if (ret) { 77 + thdrv->remove(thdev); 78 + 79 + return ret; 80 + } 81 + } 82 + 74 83 if (thdev->type == INTEL_TH_OUTPUT && 75 84 !intel_th_output_assigned(thdev)) 76 85 ret = hubdrv->assign(hub, thdev); ··· 99 90 if (err) 100 91 return err; 101 92 } 93 + 94 + if (thdrv->attr_group) 95 + sysfs_remove_group(&thdev->dev.kobj, thdrv->attr_group); 102 96 103 97 thdrv->remove(thdev); 104 98 ··· 183 171 184 172 static int intel_th_output_activate(struct intel_th_device *thdev) 185 173 { 186 - struct intel_th_driver *thdrv = to_intel_th_driver(thdev->dev.driver); 174 + struct intel_th_driver *thdrv = 175 + to_intel_th_driver_or_null(thdev->dev.driver); 176 + 177 + if (!thdrv) 178 + return -ENODEV; 179 + 180 + if (!try_module_get(thdrv->driver.owner)) 181 + return -ENODEV; 187 182 188 183 if (thdrv->activate) 189 184 return thdrv->activate(thdev); ··· 202 183 203 184 static void intel_th_output_deactivate(struct intel_th_device *thdev) 204 185 { 205 - struct intel_th_driver *thdrv = to_intel_th_driver(thdev->dev.driver); 186 + struct intel_th_driver *thdrv = 187 + to_intel_th_driver_or_null(thdev->dev.driver); 188 + 189 + if (!thdrv) 190 + return; 206 191 207 192 if (thdrv->deactivate) 208 193 thdrv->deactivate(thdev); 209 194 else 210 195 intel_th_trace_disable(thdev); 196 + 197 + module_put(thdrv->driver.owner); 211 198 } 212 199 213 200 static ssize_t active_show(struct device *dev, struct device_attribute *attr,
+6
drivers/hwtracing/intel_th/intel_th.h
··· 115 115 * @enable: enable tracing for a given output device 116 116 * @disable: disable tracing for a given output device 117 117 * @fops: file operations for device nodes 118 + * @attr_group: attributes provided by the driver 118 119 * 119 120 * Callbacks @probe and @remove are required for all device types. 120 121 * Switch device driver needs to fill in @assign, @enable and @disable ··· 140 139 void (*deactivate)(struct intel_th_device *thdev); 141 140 /* file_operations for those who want a device node */ 142 141 const struct file_operations *fops; 142 + /* optional attributes */ 143 + struct attribute_group *attr_group; 143 144 144 145 /* source ops */ 145 146 int (*set_output)(struct intel_th_device *thdev, ··· 150 147 151 148 #define to_intel_th_driver(_d) \ 152 149 container_of((_d), struct intel_th_driver, driver) 150 + 151 + #define to_intel_th_driver_or_null(_d) \ 152 + ((_d) ? to_intel_th_driver(_d) : NULL) 153 153 154 154 static inline struct intel_th_device * 155 155 to_intel_th_hub(struct intel_th_device *thdev)
+68 -48
drivers/hwtracing/intel_th/msu.c
··· 122 122 atomic_t mmap_count; 123 123 struct mutex buf_mutex; 124 124 125 - struct mutex iter_mutex; 126 125 struct list_head iter_list; 127 126 128 127 /* config */ ··· 256 257 257 258 iter = kzalloc(sizeof(*iter), GFP_KERNEL); 258 259 if (!iter) 259 - return NULL; 260 + return ERR_PTR(-ENOMEM); 261 + 262 + mutex_lock(&msc->buf_mutex); 263 + 264 + /* 265 + * Reading and tracing are mutually exclusive; if msc is 266 + * enabled, open() will fail; otherwise existing readers 267 + * will prevent enabling the msc and the rest of fops don't 268 + * need to worry about it. 269 + */ 270 + if (msc->enabled) { 271 + kfree(iter); 272 + iter = ERR_PTR(-EBUSY); 273 + goto unlock; 274 + } 260 275 261 276 msc_iter_init(iter); 262 277 iter->msc = msc; 263 278 264 - mutex_lock(&msc->iter_mutex); 265 279 list_add_tail(&iter->entry, &msc->iter_list); 266 - mutex_unlock(&msc->iter_mutex); 280 + unlock: 281 + mutex_unlock(&msc->buf_mutex); 267 282 268 283 return iter; 269 284 } 270 285 271 286 static void msc_iter_remove(struct msc_iter *iter, struct msc *msc) 272 287 { 273 - mutex_lock(&msc->iter_mutex); 288 + mutex_lock(&msc->buf_mutex); 274 289 list_del(&iter->entry); 275 - mutex_unlock(&msc->iter_mutex); 290 + mutex_unlock(&msc->buf_mutex); 276 291 277 292 kfree(iter); 278 293 } ··· 467 454 { 468 455 struct msc_window *win; 469 456 470 - mutex_lock(&msc->buf_mutex); 471 457 list_for_each_entry(win, &msc->win_list, entry) { 472 458 unsigned int blk; 473 459 size_t hw_sz = sizeof(struct msc_block_desc) - ··· 478 466 memset(&bdesc->hw_tag, 0, hw_sz); 479 467 } 480 468 } 481 - mutex_unlock(&msc->buf_mutex); 482 469 } 483 470 484 471 /** ··· 485 474 * @msc: the MSC device to configure 486 475 * 487 476 * Program storage mode, wrapping, burst length and trace buffer address 488 - * into a given MSC. If msc::enabled is set, enable the trace, too. 477 + * into a given MSC. Then, enable tracing and set msc::enabled. 478 + * The latter is serialized on msc::buf_mutex, so make sure to hold it. 489 479 */ 490 480 static int msc_configure(struct msc *msc) 491 481 { 492 482 u32 reg; 483 + 484 + lockdep_assert_held(&msc->buf_mutex); 493 485 494 486 if (msc->mode > MSC_MODE_MULTI) 495 487 return -ENOTSUPP; ··· 511 497 reg = ioread32(msc->reg_base + REG_MSU_MSC0CTL); 512 498 reg &= ~(MSC_MODE | MSC_WRAPEN | MSC_EN | MSC_RD_HDR_OVRD); 513 499 500 + reg |= MSC_EN; 514 501 reg |= msc->mode << __ffs(MSC_MODE); 515 502 reg |= msc->burst_len << __ffs(MSC_LEN); 516 - /*if (msc->mode == MSC_MODE_MULTI) 517 - reg |= MSC_RD_HDR_OVRD; */ 503 + 518 504 if (msc->wrap) 519 505 reg |= MSC_WRAPEN; 520 - if (msc->enabled) 521 - reg |= MSC_EN; 522 506 523 507 iowrite32(reg, msc->reg_base + REG_MSU_MSC0CTL); 524 508 525 - if (msc->enabled) { 526 - msc->thdev->output.multiblock = msc->mode == MSC_MODE_MULTI; 527 - intel_th_trace_enable(msc->thdev); 528 - } 509 + msc->thdev->output.multiblock = msc->mode == MSC_MODE_MULTI; 510 + intel_th_trace_enable(msc->thdev); 511 + msc->enabled = 1; 512 + 529 513 530 514 return 0; 531 515 } ··· 533 521 * @msc: MSC device to disable 534 522 * 535 523 * If @msc is enabled, disable tracing on the switch and then disable MSC 536 - * storage. 524 + * storage. Caller must hold msc::buf_mutex. 537 525 */ 538 526 static void msc_disable(struct msc *msc) 539 527 { 540 528 unsigned long count; 541 529 u32 reg; 542 530 543 - if (!msc->enabled) 544 - return; 531 + lockdep_assert_held(&msc->buf_mutex); 545 532 546 533 intel_th_trace_disable(msc->thdev); 547 534 ··· 580 569 static int intel_th_msc_activate(struct intel_th_device *thdev) 581 570 { 582 571 struct msc *msc = dev_get_drvdata(&thdev->dev); 583 - int ret = 0; 572 + int ret = -EBUSY; 584 573 585 574 if (!atomic_inc_unless_negative(&msc->user_count)) 586 575 return -ENODEV; 587 576 588 - mutex_lock(&msc->iter_mutex); 589 - if (!list_empty(&msc->iter_list)) 590 - ret = -EBUSY; 591 - mutex_unlock(&msc->iter_mutex); 577 + mutex_lock(&msc->buf_mutex); 592 578 593 - if (ret) { 579 + /* if there are readers, refuse */ 580 + if (list_empty(&msc->iter_list)) 581 + ret = msc_configure(msc); 582 + 583 + mutex_unlock(&msc->buf_mutex); 584 + 585 + if (ret) 594 586 atomic_dec(&msc->user_count); 595 - return ret; 596 - } 597 587 598 - msc->enabled = 1; 599 - 600 - return msc_configure(msc); 588 + return ret; 601 589 } 602 590 603 591 static void intel_th_msc_deactivate(struct intel_th_device *thdev) 604 592 { 605 593 struct msc *msc = dev_get_drvdata(&thdev->dev); 606 594 607 - msc_disable(msc); 608 - 609 - atomic_dec(&msc->user_count); 595 + mutex_lock(&msc->buf_mutex); 596 + if (msc->enabled) { 597 + msc_disable(msc); 598 + atomic_dec(&msc->user_count); 599 + } 600 + mutex_unlock(&msc->buf_mutex); 610 601 } 611 602 612 603 /** ··· 1048 1035 return -EPERM; 1049 1036 1050 1037 iter = msc_iter_install(msc); 1051 - if (!iter) 1052 - return -ENOMEM; 1038 + if (IS_ERR(iter)) 1039 + return PTR_ERR(iter); 1053 1040 1054 1041 file->private_data = iter; 1055 1042 ··· 1113 1100 1114 1101 if (!atomic_inc_unless_negative(&msc->user_count)) 1115 1102 return 0; 1116 - 1117 - if (msc->enabled) { 1118 - ret = -EBUSY; 1119 - goto put_count; 1120 - } 1121 1103 1122 1104 if (msc->mode == MSC_MODE_SINGLE && !msc->single_wrap) 1123 1105 size = msc->single_sz; ··· 1253 1245 .read = intel_th_msc_read, 1254 1246 .mmap = intel_th_msc_mmap, 1255 1247 .llseek = no_llseek, 1248 + .owner = THIS_MODULE, 1256 1249 }; 1257 1250 1258 1251 static int intel_th_msc_init(struct msc *msc) ··· 1263 1254 msc->mode = MSC_MODE_MULTI; 1264 1255 mutex_init(&msc->buf_mutex); 1265 1256 INIT_LIST_HEAD(&msc->win_list); 1266 - 1267 - mutex_init(&msc->iter_mutex); 1268 1257 INIT_LIST_HEAD(&msc->iter_list); 1269 1258 1270 1259 msc->burst_len = ··· 1400 1393 do { 1401 1394 end = memchr(p, ',', len); 1402 1395 s = kstrndup(p, end ? end - p : len, GFP_KERNEL); 1396 + if (!s) { 1397 + ret = -ENOMEM; 1398 + goto free_win; 1399 + } 1400 + 1403 1401 ret = kstrtoul(s, 10, &val); 1404 1402 kfree(s); 1405 1403 ··· 1485 1473 if (err) 1486 1474 return err; 1487 1475 1488 - err = sysfs_create_group(&dev->kobj, &msc_output_group); 1489 - if (err) 1490 - return err; 1491 - 1492 1476 dev_set_drvdata(dev, msc); 1493 1477 1494 1478 return 0; ··· 1492 1484 1493 1485 static void intel_th_msc_remove(struct intel_th_device *thdev) 1494 1486 { 1495 - sysfs_remove_group(&thdev->dev.kobj, &msc_output_group); 1487 + struct msc *msc = dev_get_drvdata(&thdev->dev); 1488 + int ret; 1489 + 1490 + intel_th_msc_deactivate(thdev); 1491 + 1492 + /* 1493 + * Buffers should not be used at this point except if the 1494 + * output character device is still open and the parent 1495 + * device gets detached from its bus, which is a FIXME. 1496 + */ 1497 + ret = msc_buffer_free_unless_used(msc); 1498 + WARN_ON_ONCE(ret); 1496 1499 } 1497 1500 1498 1501 static struct intel_th_driver intel_th_msc_driver = { ··· 1512 1493 .activate = intel_th_msc_activate, 1513 1494 .deactivate = intel_th_msc_deactivate, 1514 1495 .fops = &intel_th_msc_fops, 1496 + .attr_group = &msc_output_group, 1515 1497 .driver = { 1516 1498 .name = "msc", 1517 1499 .owner = THIS_MODULE,
+5
drivers/hwtracing/intel_th/pci.c
··· 75 75 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0a80), 76 76 .driver_data = (kernel_ulong_t)0, 77 77 }, 78 + { 79 + /* Broxton B-step */ 80 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1a8e), 81 + .driver_data = (kernel_ulong_t)0, 82 + }, 78 83 { 0 }, 79 84 }; 80 85
+1 -5
drivers/hwtracing/intel_th/pti.c
··· 200 200 struct resource *res; 201 201 struct pti_device *pti; 202 202 void __iomem *base; 203 - int ret; 204 203 205 204 res = intel_th_device_get_resource(thdev, IORESOURCE_MEM, 0); 206 205 if (!res) ··· 218 219 219 220 read_hw_config(pti); 220 221 221 - ret = sysfs_create_group(&dev->kobj, &pti_output_group); 222 - if (ret) 223 - return ret; 224 - 225 222 dev_set_drvdata(dev, pti); 226 223 227 224 return 0; ··· 232 237 .remove = intel_th_pti_remove, 233 238 .activate = intel_th_pti_activate, 234 239 .deactivate = intel_th_pti_deactivate, 240 + .attr_group = &pti_output_group, 235 241 .driver = { 236 242 .name = "pti", 237 243 .owner = THIS_MODULE,
+14 -13
drivers/hwtracing/stm/core.c
··· 546 546 if (ret) 547 547 goto err_free; 548 548 549 - ret = 0; 550 - 551 549 if (stm->data->link) 552 550 ret = stm->data->link(stm->data, stmf->output.master, 553 551 stmf->output.channel); ··· 666 668 stm->dev.parent = parent; 667 669 stm->dev.release = stm_device_release; 668 670 671 + mutex_init(&stm->link_mutex); 672 + spin_lock_init(&stm->link_lock); 673 + INIT_LIST_HEAD(&stm->link_list); 674 + 675 + /* initialize the object before it is accessible via sysfs */ 676 + spin_lock_init(&stm->mc_lock); 677 + mutex_init(&stm->policy_mutex); 678 + stm->sw_nmasters = nmasters; 679 + stm->owner = owner; 680 + stm->data = stm_data; 681 + stm_data->stm = stm; 682 + 669 683 err = kobject_set_name(&stm->dev.kobj, "%s", stm_data->name); 670 684 if (err) 671 685 goto err_device; ··· 686 676 if (err) 687 677 goto err_device; 688 678 689 - mutex_init(&stm->link_mutex); 690 - spin_lock_init(&stm->link_lock); 691 - INIT_LIST_HEAD(&stm->link_list); 692 - 693 - spin_lock_init(&stm->mc_lock); 694 - mutex_init(&stm->policy_mutex); 695 - stm->sw_nmasters = nmasters; 696 - stm->owner = owner; 697 - stm->data = stm_data; 698 - stm_data->stm = stm; 699 - 700 679 return 0; 701 680 702 681 err_device: 682 + unregister_chrdev(stm->major, stm_data->name); 683 + 703 684 /* matches device_initialize() above */ 704 685 put_device(&stm->dev); 705 686 err_free:
+5 -9
drivers/hwtracing/stm/dummy_stm.c
··· 46 46 47 47 static int nr_dummies = 4; 48 48 49 - module_param(nr_dummies, int, 0600); 50 - 51 - static unsigned int dummy_stm_nr; 49 + module_param(nr_dummies, int, 0400); 52 50 53 51 static unsigned int fail_mode; 54 52 ··· 63 65 64 66 static int dummy_stm_init(void) 65 67 { 66 - int i, ret = -ENOMEM, __nr_dummies = ACCESS_ONCE(nr_dummies); 68 + int i, ret = -ENOMEM; 67 69 68 - if (__nr_dummies < 0 || __nr_dummies > DUMMY_STM_MAX) 70 + if (nr_dummies < 0 || nr_dummies > DUMMY_STM_MAX) 69 71 return -EINVAL; 70 72 71 - for (i = 0; i < __nr_dummies; i++) { 73 + for (i = 0; i < nr_dummies; i++) { 72 74 dummy_stm[i].name = kasprintf(GFP_KERNEL, "dummy_stm.%d", i); 73 75 if (!dummy_stm[i].name) 74 76 goto fail_unregister; ··· 83 85 if (ret) 84 86 goto fail_free; 85 87 } 86 - 87 - dummy_stm_nr = __nr_dummies; 88 88 89 89 return 0; 90 90 ··· 101 105 { 102 106 int i; 103 107 104 - for (i = 0; i < dummy_stm_nr; i++) { 108 + for (i = 0; i < nr_dummies; i++) { 105 109 stm_unregister_device(&dummy_stm[i]); 106 110 kfree(dummy_stm[i].name); 107 111 }
+5 -9
drivers/hwtracing/stm/heartbeat.c
··· 26 26 static int nr_devs = 4; 27 27 static int interval_ms = 10; 28 28 29 - module_param(nr_devs, int, 0600); 29 + module_param(nr_devs, int, 0400); 30 30 module_param(interval_ms, int, 0600); 31 31 32 32 static struct stm_heartbeat { ··· 34 34 struct hrtimer hrtimer; 35 35 unsigned int active; 36 36 } stm_heartbeat[STM_HEARTBEAT_MAX]; 37 - 38 - static unsigned int nr_instances; 39 37 40 38 static const char str[] = "heartbeat stm source driver is here to serve you"; 41 39 ··· 72 74 73 75 static int stm_heartbeat_init(void) 74 76 { 75 - int i, ret = -ENOMEM, __nr_instances = ACCESS_ONCE(nr_devs); 77 + int i, ret = -ENOMEM; 76 78 77 - if (__nr_instances < 0 || __nr_instances > STM_HEARTBEAT_MAX) 79 + if (nr_devs < 0 || nr_devs > STM_HEARTBEAT_MAX) 78 80 return -EINVAL; 79 81 80 - for (i = 0; i < __nr_instances; i++) { 82 + for (i = 0; i < nr_devs; i++) { 81 83 stm_heartbeat[i].data.name = 82 84 kasprintf(GFP_KERNEL, "heartbeat.%d", i); 83 85 if (!stm_heartbeat[i].data.name) ··· 96 98 goto fail_free; 97 99 } 98 100 99 - nr_instances = __nr_instances; 100 - 101 101 return 0; 102 102 103 103 fail_unregister: ··· 112 116 { 113 117 int i; 114 118 115 - for (i = 0; i < nr_instances; i++) { 119 + for (i = 0; i < nr_devs; i++) { 116 120 stm_source_unregister_device(&stm_heartbeat[i].data); 117 121 kfree(stm_heartbeat[i].data.name); 118 122 }
+2 -3
drivers/hwtracing/stm/policy.c
··· 107 107 goto unlock; 108 108 109 109 /* must be within [sw_start..sw_end], which is an inclusive range */ 110 - if (first > INT_MAX || last > INT_MAX || first > last || 111 - first < stm->data->sw_start || 110 + if (first > last || first < stm->data->sw_start || 112 111 last > stm->data->sw_end) { 113 112 ret = -ERANGE; 114 113 goto unlock; ··· 341 342 return ERR_PTR(-EINVAL); 342 343 } 343 344 344 - *p++ = '\0'; 345 + *p = '\0'; 345 346 346 347 stm = stm_find_device(devname); 347 348 kfree(devname);