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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus-6.16-1' of https://github.com/cminyard/linux-ipmi

Pull IPMI updates from Corey Minyard:
"Restructure the IPMI driver.

This is a restructure of the IPMI driver, mostly to remove SRCU. The
locking had issues, and they were not going to be straightforward to
fix. Plus it used tons of memory and was generally a pain.

Most of this moves handling of messages out of bh and interrupt
context and runs it in thread context. Then getting rid of SRCU is
easy.

This also has a minor cleanup to remove a warning on newer GCCs and to
fix some documentation"

* tag 'for-linus-6.16-1' of https://github.com/cminyard/linux-ipmi: (26 commits)
docs: ipmi: fix spelling and grammar mistakes
ipmi:msghandler: Fix potential memory corruption in ipmi_create_user()
ipmi:watchdog: Use the new interface for panic messages
ipmi:msghandler: Export and fix panic messaging capability
Documentation:ipmi: Remove comments about interrupt level
ipmi:ssif: Fix a shutdown race
ipmi:msghandler: Don't deliver messages to deleted users
ipmi:si: Rework startup of IPMI devices
ipmi:msghandler: Add a error return from unhandle LAN cmds
ipmi:msghandler: Shut down lower layer first at unregister
ipmi:msghandler: Remove proc_fs.h
ipmi:msghandler: Don't check for shutdown when returning responses
ipmi:msghandler: Don't acquire a user refcount for queued messages
ipmi:msghandler: Fix locking around users and interfaces
ipmi:msghandler: Remove some user level processing in panic mode
ipmi: Add a note about the pretimeout callback
ipmi:watchdog: Change lock to mutex
ipmi:msghandler: Remove srcu for the ipmi_interfaces list
ipmi:msghandler: Remove srcu from the ipmi user structure
ipmi:msghandler: Use the system_wq, not system_bh_wq
...

+585 -525
+13 -16
Documentation/driver-api/ipmi.rst
··· 45 45 for direct I2C access to the IPMI management controller. Some boards 46 46 support this, but it is unknown if it will work on every board. For 47 47 this, choose 'IPMI SMBus handler', but be ready to try to do some 48 - figuring to see if it will work on your system if the SMBIOS/APCI 48 + figuring to see if it will work on your system if the SMBIOS/ACPI 49 49 information is wrong or not present. It is fairly safe to have both 50 50 these enabled and let the drivers auto-detect what is present. 51 51 ··· 63 63 IPMI defines a standard watchdog timer. You can enable this with the 64 64 'IPMI Watchdog Timer' config option. If you compile the driver into 65 65 the kernel, then via a kernel command-line option you can have the 66 - watchdog timer start as soon as it initializes. It also have a lot 66 + watchdog timer start as soon as it initializes. It also has a lot 67 67 of other options, see the 'Watchdog' section below for more details. 68 68 Note that you can also have the watchdog continue to run if it is 69 69 closed (by default it is disabled on close). Go into the 'Watchdog ··· 280 280 To use the message handler, you must first create a user using 281 281 ipmi_create_user. The interface number specifies which SMI you want 282 282 to connect to, and you must supply callback functions to be called 283 - when data comes in. The callback function can run at interrupt level, 284 - so be careful using the callbacks. This also allows to you pass in a 285 - piece of data, the handler_data, that will be passed back to you on 286 - all calls. 283 + when data comes in. This also allows to you pass in a piece of data, 284 + the handler_data, that will be passed back to you on all calls. 287 285 288 286 Once you are done, call ipmi_destroy_user() to get rid of the user. 289 287 ··· 301 303 302 304 Responses come back in the function pointed to by the ipmi_recv_hndl 303 305 field of the "handler" that you passed in to ipmi_create_user(). 304 - Remember again, these may be running at interrupt level. Remember to 305 - look at the receive type, too. 306 + Remember to look at the receive type, too. 306 307 307 308 From userland, you fill out an ipmi_req_t structure and use the 308 309 IPMICTL_SEND_COMMAND ioctl. For incoming stuff, you can use select() ··· 314 317 315 318 If the message cannot fit into the data you provide, you will get an 316 319 EMSGSIZE error and the driver will leave the data in the receive 317 - queue. If you want to get it and have it truncate the message, us 320 + queue. If you want to get it and have it truncate the message, use 318 321 the IPMICTL_RECEIVE_MSG_TRUNC ioctl. 319 322 320 323 When you send a command (which is defined by the lowest-order bit of 321 324 the netfn per the IPMI spec) on the IPMB bus, the driver will 322 325 automatically assign the sequence number to the command and save the 323 - command. If the response is not receive in the IPMI-specified 5 326 + command. If the response is not received in the IPMI-specified 5 324 327 seconds, it will generate a response automatically saying the command 325 328 timed out. If an unsolicited response comes in (if it was after 5 326 329 seconds, for instance), that response will be ignored. ··· 364 367 365 368 To respond to a received command, set the response bit in the returned 366 369 netfn, use the address from the received message, and use the same 367 - msgid that you got in the receive message. 370 + msgid that you got in the received message. 368 371 369 372 From userland, equivalent IOCTLs are provided to do these functions. 370 373 ··· 437 440 438 441 The regsizes parameter gives the size of a register, in bytes. The 439 442 data used by IPMI is 8-bits wide, but it may be inside a larger 440 - register. This parameter allows the read and write type to specified. 443 + register. This parameter allows the read and write type to be specified. 441 444 It may be 1, 2, 4, or 8. The default is 1. 442 445 443 446 Since the register size may be larger than 32 bits, the IPMI data may not ··· 478 481 SMIC interface, the IPMI driver will start a kernel thread for the 479 482 interface to help speed things up. This is a low-priority kernel 480 483 thread that constantly polls the IPMI driver while an IPMI operation 481 - is in progress. The force_kipmid module parameter will all the user to 482 - force this thread on or off. If you force it off and don't have 484 + is in progress. The force_kipmid module parameter will allow the user 485 + to force this thread on or off. If you force it off and don't have 483 486 interrupts, the driver will run VERY slowly. Don't blame me, 484 487 these interfaces suck. 485 488 ··· 580 583 These are the same options as on the module command line. 581 584 582 585 The I2C driver does not support non-blocking access or polling, so 583 - this driver cannod to IPMI panic events, extend the watchdog at panic 586 + this driver cannot do IPMI panic events, extend the watchdog at panic 584 587 time, or other panic-related IPMI functions without special kernel 585 588 patches and driver modifications. You can get those at the openipmi 586 589 web page. ··· 607 610 ipmi_ipmb.retry_time_ms=<Time between retries on IPMB> 608 611 ipmi_ipmb.max_retries=<Number of times to retry a message> 609 612 610 - Loading the module will not result in the driver automatcially 613 + Loading the module will not result in the driver automatically 611 614 starting unless there is device tree information setting it up. If 612 615 you want to instantiate one of these by hand, do:: 613 616
+402 -363
drivers/char/ipmi/ipmi_msghandler.c
··· 27 27 #include <linux/ipmi_smi.h> 28 28 #include <linux/notifier.h> 29 29 #include <linux/init.h> 30 - #include <linux/proc_fs.h> 31 30 #include <linux/rcupdate.h> 32 31 #include <linux/interrupt.h> 33 32 #include <linux/moduleparam.h> ··· 40 41 41 42 static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 42 43 static int ipmi_init_msghandler(void); 43 - static void smi_recv_work(struct work_struct *t); 44 + static void smi_work(struct work_struct *t); 44 45 static void handle_new_recv_msgs(struct ipmi_smi *intf); 45 46 static void need_waiter(struct ipmi_smi *intf); 46 47 static int handle_one_recv_msg(struct ipmi_smi *intf, 47 48 struct ipmi_smi_msg *msg); 49 + static void intf_free(struct kref *ref); 48 50 49 51 static bool initialized; 50 52 static bool drvregistered; ··· 180 180 struct ipmi_user { 181 181 struct list_head link; 182 182 183 - /* 184 - * Set to NULL when the user is destroyed, a pointer to myself 185 - * so srcu_dereference can be used on it. 186 - */ 187 - struct ipmi_user *self; 188 - struct srcu_struct release_barrier; 189 - 190 183 struct kref refcount; 184 + refcount_t destroyed; 191 185 192 186 /* The upper layer that handles receive messages. */ 193 187 const struct ipmi_user_hndl *handler; ··· 194 200 bool gets_events; 195 201 196 202 atomic_t nr_msgs; 197 - 198 - /* Free must run in process context for RCU cleanup. */ 199 - struct work_struct remove_work; 200 203 }; 201 - 202 - static struct workqueue_struct *remove_work_wq; 203 - 204 - static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user, int *index) 205 - __acquires(user->release_barrier) 206 - { 207 - struct ipmi_user *ruser; 208 - 209 - *index = srcu_read_lock(&user->release_barrier); 210 - ruser = srcu_dereference(user->self, &user->release_barrier); 211 - if (!ruser) 212 - srcu_read_unlock(&user->release_barrier, *index); 213 - return ruser; 214 - } 215 - 216 - static void release_ipmi_user(struct ipmi_user *user, int index) 217 - { 218 - srcu_read_unlock(&user->release_barrier, index); 219 - } 220 204 221 205 struct cmd_rcvr { 222 206 struct list_head link; ··· 298 326 unsigned char cc; /* completion code */ 299 327 }; 300 328 #define to_bmc_device(x) container_of((x), struct bmc_device, pdev.dev) 329 + 330 + static struct workqueue_struct *bmc_remove_work_wq; 301 331 302 332 static int bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc, 303 333 struct ipmi_device_id *id, ··· 425 451 struct list_head link; 426 452 427 453 /* 428 - * The list of upper layers that are using me. seq_lock write 429 - * protects this. Read protection is with srcu. 454 + * The list of upper layers that are using me. 430 455 */ 431 456 struct list_head users; 432 - struct srcu_struct users_srcu; 457 + struct mutex users_mutex; 433 458 atomic_t nr_users; 434 459 struct device_attribute nr_users_devattr; 435 460 struct device_attribute nr_msgs_devattr; ··· 469 496 int curr_seq; 470 497 471 498 /* 472 - * Messages queued for delivery. If delivery fails (out of memory 473 - * for instance), They will stay in here to be processed later in a 474 - * periodic timer interrupt. The workqueue is for handling received 475 - * messages directly from the handler. 499 + * Messages queued for deliver to the user. 500 + */ 501 + struct mutex user_msgs_mutex; 502 + struct list_head user_msgs; 503 + 504 + /* 505 + * Messages queued for processing. If processing fails (out 506 + * of memory for instance), They will stay in here to be 507 + * processed later in a periodic timer interrupt. The 508 + * workqueue is for handling received messages directly from 509 + * the handler. 476 510 */ 477 511 spinlock_t waiting_rcv_msgs_lock; 478 512 struct list_head waiting_rcv_msgs; 479 513 atomic_t watchdog_pretimeouts_to_deliver; 480 - struct work_struct recv_work; 514 + struct work_struct smi_work; 481 515 482 516 spinlock_t xmit_msgs_lock; 483 517 struct list_head xmit_msgs; ··· 502 522 * Events that were queues because no one was there to receive 503 523 * them. 504 524 */ 505 - spinlock_t events_lock; /* For dealing with event stuff. */ 525 + struct mutex events_mutex; /* For dealing with event stuff. */ 506 526 struct list_head waiting_events; 507 527 unsigned int waiting_events_count; /* How many events in queue? */ 508 - char delivering_events; 509 528 char event_msg_printed; 510 529 511 530 /* How many users are waiting for events? */ ··· 592 613 bool guid_set, guid_t *guid, int intf_num); 593 614 static int __scan_channels(struct ipmi_smi *intf, struct ipmi_device_id *id); 594 615 616 + static void free_ipmi_user(struct kref *ref) 617 + { 618 + struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount); 619 + struct module *owner; 620 + 621 + owner = user->intf->owner; 622 + kref_put(&user->intf->refcount, intf_free); 623 + module_put(owner); 624 + vfree(user); 625 + } 626 + 627 + static void release_ipmi_user(struct ipmi_user *user) 628 + { 629 + kref_put(&user->refcount, free_ipmi_user); 630 + } 631 + 632 + static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user) 633 + { 634 + if (!kref_get_unless_zero(&user->refcount)) 635 + return NULL; 636 + return user; 637 + } 595 638 596 639 /* 597 640 * The driver model view of the IPMI messaging driver. ··· 631 630 632 631 static LIST_HEAD(ipmi_interfaces); 633 632 static DEFINE_MUTEX(ipmi_interfaces_mutex); 634 - #define ipmi_interfaces_mutex_held() \ 635 - lockdep_is_held(&ipmi_interfaces_mutex) 636 - static struct srcu_struct ipmi_interfaces_srcu; 637 633 638 634 /* 639 635 * List of watchers that want to know when smi's are added and deleted. ··· 696 698 } 697 699 } 698 700 699 - static void clean_up_interface_data(struct ipmi_smi *intf) 701 + static void intf_free(struct kref *ref) 700 702 { 703 + struct ipmi_smi *intf = container_of(ref, struct ipmi_smi, refcount); 701 704 int i; 702 705 struct cmd_rcvr *rcvr, *rcvr2; 703 - struct list_head list; 704 - 705 - cancel_work_sync(&intf->recv_work); 706 706 707 707 free_smi_msg_list(&intf->waiting_rcv_msgs); 708 708 free_recv_msg_list(&intf->waiting_events); 709 709 710 710 /* 711 711 * Wholesale remove all the entries from the list in the 712 - * interface and wait for RCU to know that none are in use. 712 + * interface. No need for locks, this is single-threaded. 713 713 */ 714 - mutex_lock(&intf->cmd_rcvrs_mutex); 715 - INIT_LIST_HEAD(&list); 716 - list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu); 717 - mutex_unlock(&intf->cmd_rcvrs_mutex); 718 - 719 - list_for_each_entry_safe(rcvr, rcvr2, &list, link) 714 + list_for_each_entry_safe(rcvr, rcvr2, &intf->cmd_rcvrs, link) 720 715 kfree(rcvr); 721 716 722 717 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { ··· 717 726 && (intf->seq_table[i].recv_msg)) 718 727 ipmi_free_recv_msg(intf->seq_table[i].recv_msg); 719 728 } 720 - } 721 729 722 - static void intf_free(struct kref *ref) 723 - { 724 - struct ipmi_smi *intf = container_of(ref, struct ipmi_smi, refcount); 725 - 726 - clean_up_interface_data(intf); 727 730 kfree(intf); 728 731 } 729 732 730 733 int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher) 731 734 { 732 735 struct ipmi_smi *intf; 733 - int index, rv; 736 + unsigned int count = 0, i; 737 + int *interfaces = NULL; 738 + struct device **devices = NULL; 739 + int rv = 0; 734 740 735 741 /* 736 742 * Make sure the driver is actually initialized, this handles ··· 741 753 742 754 list_add(&watcher->link, &smi_watchers); 743 755 744 - index = srcu_read_lock(&ipmi_interfaces_srcu); 745 - list_for_each_entry_rcu(intf, &ipmi_interfaces, link, 746 - lockdep_is_held(&smi_watchers_mutex)) { 747 - int intf_num = READ_ONCE(intf->intf_num); 748 - 749 - if (intf_num == -1) 750 - continue; 751 - watcher->new_smi(intf_num, intf->si_dev); 756 + /* 757 + * Build an array of ipmi interfaces and fill it in, and 758 + * another array of the devices. We can't call the callback 759 + * with ipmi_interfaces_mutex held. smi_watchers_mutex will 760 + * keep things in order for the user. 761 + */ 762 + mutex_lock(&ipmi_interfaces_mutex); 763 + list_for_each_entry(intf, &ipmi_interfaces, link) 764 + count++; 765 + if (count > 0) { 766 + interfaces = kmalloc_array(count, sizeof(*interfaces), 767 + GFP_KERNEL); 768 + if (!interfaces) { 769 + rv = -ENOMEM; 770 + } else { 771 + devices = kmalloc_array(count, sizeof(*devices), 772 + GFP_KERNEL); 773 + if (!devices) { 774 + kfree(interfaces); 775 + interfaces = NULL; 776 + rv = -ENOMEM; 777 + } 778 + } 779 + count = 0; 752 780 } 753 - srcu_read_unlock(&ipmi_interfaces_srcu, index); 781 + if (interfaces) { 782 + list_for_each_entry(intf, &ipmi_interfaces, link) { 783 + int intf_num = READ_ONCE(intf->intf_num); 784 + 785 + if (intf_num == -1) 786 + continue; 787 + devices[count] = intf->si_dev; 788 + interfaces[count++] = intf_num; 789 + } 790 + } 791 + mutex_unlock(&ipmi_interfaces_mutex); 792 + 793 + if (interfaces) { 794 + for (i = 0; i < count; i++) 795 + watcher->new_smi(interfaces[i], devices[i]); 796 + kfree(interfaces); 797 + kfree(devices); 798 + } 754 799 755 800 mutex_unlock(&smi_watchers_mutex); 756 801 757 - return 0; 802 + return rv; 758 803 } 759 804 EXPORT_SYMBOL(ipmi_smi_watcher_register); 760 805 ··· 800 779 } 801 780 EXPORT_SYMBOL(ipmi_smi_watcher_unregister); 802 781 803 - /* 804 - * Must be called with smi_watchers_mutex held. 805 - */ 806 782 static void 807 783 call_smi_watchers(int i, struct device *dev) 808 784 { 809 785 struct ipmi_smi_watcher *w; 810 786 811 - mutex_lock(&smi_watchers_mutex); 812 787 list_for_each_entry(w, &smi_watchers, link) { 813 788 if (try_module_get(w->owner)) { 814 789 w->new_smi(i, dev); 815 790 module_put(w->owner); 816 791 } 817 792 } 818 - mutex_unlock(&smi_watchers_mutex); 819 793 } 820 794 821 795 static int ··· 957 941 ipmi_free_recv_msg(msg); 958 942 atomic_dec(&msg->user->nr_msgs); 959 943 } else { 960 - int index; 961 - struct ipmi_user *user = acquire_ipmi_user(msg->user, &index); 962 - 963 - if (user) { 964 - atomic_dec(&user->nr_msgs); 965 - user->handler->ipmi_recv_hndl(msg, user->handler_data); 966 - release_ipmi_user(user, index); 967 - } else { 968 - /* User went away, give up. */ 969 - ipmi_free_recv_msg(msg); 970 - rv = -EINVAL; 971 - } 944 + /* 945 + * Deliver it in smi_work. The message will hold a 946 + * refcount to the user. 947 + */ 948 + mutex_lock(&intf->user_msgs_mutex); 949 + list_add_tail(&msg->link, &intf->user_msgs); 950 + mutex_unlock(&intf->user_msgs_mutex); 951 + queue_work(system_wq, &intf->smi_work); 972 952 } 973 953 974 954 return rv; ··· 1204 1192 return rv; 1205 1193 } 1206 1194 1207 - static void free_user_work(struct work_struct *work) 1208 - { 1209 - struct ipmi_user *user = container_of(work, struct ipmi_user, 1210 - remove_work); 1211 - 1212 - cleanup_srcu_struct(&user->release_barrier); 1213 - vfree(user); 1214 - } 1215 - 1216 1195 int ipmi_create_user(unsigned int if_num, 1217 1196 const struct ipmi_user_hndl *handler, 1218 1197 void *handler_data, 1219 1198 struct ipmi_user **user) 1220 1199 { 1221 1200 unsigned long flags; 1222 - struct ipmi_user *new_user; 1223 - int rv, index; 1201 + struct ipmi_user *new_user = NULL; 1202 + int rv = 0; 1224 1203 struct ipmi_smi *intf; 1225 1204 1226 1205 /* ··· 1233 1230 if (rv) 1234 1231 return rv; 1235 1232 1236 - new_user = vzalloc(sizeof(*new_user)); 1237 - if (!new_user) 1238 - return -ENOMEM; 1239 - 1240 - index = srcu_read_lock(&ipmi_interfaces_srcu); 1241 - list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 1233 + mutex_lock(&ipmi_interfaces_mutex); 1234 + list_for_each_entry(intf, &ipmi_interfaces, link) { 1242 1235 if (intf->intf_num == if_num) 1243 1236 goto found; 1244 1237 } 1245 1238 /* Not found, return an error */ 1246 1239 rv = -EINVAL; 1247 - goto out_kfree; 1240 + goto out_unlock; 1248 1241 1249 1242 found: 1243 + if (intf->in_shutdown) { 1244 + rv = -ENODEV; 1245 + goto out_unlock; 1246 + } 1247 + 1250 1248 if (atomic_add_return(1, &intf->nr_users) > max_users) { 1251 1249 rv = -EBUSY; 1252 1250 goto out_kfree; 1253 1251 } 1254 1252 1255 - INIT_WORK(&new_user->remove_work, free_user_work); 1256 - 1257 - rv = init_srcu_struct(&new_user->release_barrier); 1258 - if (rv) 1253 + new_user = vzalloc(sizeof(*new_user)); 1254 + if (!new_user) { 1255 + rv = -ENOMEM; 1259 1256 goto out_kfree; 1257 + } 1260 1258 1261 1259 if (!try_module_get(intf->owner)) { 1262 1260 rv = -ENODEV; ··· 1269 1265 1270 1266 atomic_set(&new_user->nr_msgs, 0); 1271 1267 kref_init(&new_user->refcount); 1268 + refcount_set(&new_user->destroyed, 1); 1269 + kref_get(&new_user->refcount); /* Destroy owns a refcount. */ 1272 1270 new_user->handler = handler; 1273 1271 new_user->handler_data = handler_data; 1274 1272 new_user->intf = intf; 1275 1273 new_user->gets_events = false; 1276 1274 1277 - rcu_assign_pointer(new_user->self, new_user); 1275 + mutex_lock(&intf->users_mutex); 1278 1276 spin_lock_irqsave(&intf->seq_lock, flags); 1279 - list_add_rcu(&new_user->link, &intf->users); 1277 + list_add(&new_user->link, &intf->users); 1280 1278 spin_unlock_irqrestore(&intf->seq_lock, flags); 1279 + mutex_unlock(&intf->users_mutex); 1280 + 1281 1281 if (handler->ipmi_watchdog_pretimeout) 1282 1282 /* User wants pretimeouts, so make sure to watch for them. */ 1283 1283 smi_add_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG); 1284 - srcu_read_unlock(&ipmi_interfaces_srcu, index); 1285 - *user = new_user; 1286 - return 0; 1287 1284 1288 1285 out_kfree: 1289 - atomic_dec(&intf->nr_users); 1290 - srcu_read_unlock(&ipmi_interfaces_srcu, index); 1291 - vfree(new_user); 1286 + if (rv) { 1287 + atomic_dec(&intf->nr_users); 1288 + vfree(new_user); 1289 + } else { 1290 + *user = new_user; 1291 + } 1292 + out_unlock: 1293 + mutex_unlock(&ipmi_interfaces_mutex); 1292 1294 return rv; 1293 1295 } 1294 1296 EXPORT_SYMBOL(ipmi_create_user); 1295 1297 1296 1298 int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data) 1297 1299 { 1298 - int rv, index; 1300 + int rv = -EINVAL; 1299 1301 struct ipmi_smi *intf; 1300 1302 1301 - index = srcu_read_lock(&ipmi_interfaces_srcu); 1302 - list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 1303 - if (intf->intf_num == if_num) 1304 - goto found; 1303 + mutex_lock(&ipmi_interfaces_mutex); 1304 + list_for_each_entry(intf, &ipmi_interfaces, link) { 1305 + if (intf->intf_num == if_num) { 1306 + if (!intf->handlers->get_smi_info) 1307 + rv = -ENOTTY; 1308 + else 1309 + rv = intf->handlers->get_smi_info(intf->send_info, data); 1310 + break; 1311 + } 1305 1312 } 1306 - srcu_read_unlock(&ipmi_interfaces_srcu, index); 1307 - 1308 - /* Not found, return an error */ 1309 - return -EINVAL; 1310 - 1311 - found: 1312 - if (!intf->handlers->get_smi_info) 1313 - rv = -ENOTTY; 1314 - else 1315 - rv = intf->handlers->get_smi_info(intf->send_info, data); 1316 - srcu_read_unlock(&ipmi_interfaces_srcu, index); 1313 + mutex_unlock(&ipmi_interfaces_mutex); 1317 1314 1318 1315 return rv; 1319 1316 } 1320 1317 EXPORT_SYMBOL(ipmi_get_smi_info); 1321 1318 1322 - static void free_user(struct kref *ref) 1323 - { 1324 - struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount); 1325 - 1326 - /* SRCU cleanup must happen in workqueue context. */ 1327 - queue_work(remove_work_wq, &user->remove_work); 1328 - } 1329 - 1319 + /* Must be called with intf->users_mutex held. */ 1330 1320 static void _ipmi_destroy_user(struct ipmi_user *user) 1331 1321 { 1332 1322 struct ipmi_smi *intf = user->intf; ··· 1328 1330 unsigned long flags; 1329 1331 struct cmd_rcvr *rcvr; 1330 1332 struct cmd_rcvr *rcvrs = NULL; 1331 - struct module *owner; 1333 + struct ipmi_recv_msg *msg, *msg2; 1332 1334 1333 - if (!acquire_ipmi_user(user, &i)) { 1334 - /* 1335 - * The user has already been cleaned up, just make sure 1336 - * nothing is using it and return. 1337 - */ 1338 - synchronize_srcu(&user->release_barrier); 1335 + if (!refcount_dec_if_one(&user->destroyed)) 1339 1336 return; 1340 - } 1341 - 1342 - rcu_assign_pointer(user->self, NULL); 1343 - release_ipmi_user(user, i); 1344 - 1345 - synchronize_srcu(&user->release_barrier); 1346 1337 1347 1338 if (user->handler->shutdown) 1348 1339 user->handler->shutdown(user->handler_data); ··· 1342 1355 if (user->gets_events) 1343 1356 atomic_dec(&intf->event_waiters); 1344 1357 1345 - /* Remove the user from the interface's sequence table. */ 1346 - spin_lock_irqsave(&intf->seq_lock, flags); 1347 - list_del_rcu(&user->link); 1358 + /* Remove the user from the interface's list and sequence table. */ 1359 + list_del(&user->link); 1348 1360 atomic_dec(&intf->nr_users); 1349 1361 1362 + spin_lock_irqsave(&intf->seq_lock, flags); 1350 1363 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { 1351 1364 if (intf->seq_table[i].inuse 1352 1365 && (intf->seq_table[i].recv_msg->user == user)) { ··· 1361 1374 * Remove the user from the command receiver's table. First 1362 1375 * we build a list of everything (not using the standard link, 1363 1376 * since other things may be using it till we do 1364 - * synchronize_srcu()) then free everything in that list. 1377 + * synchronize_rcu()) then free everything in that list. 1365 1378 */ 1366 1379 mutex_lock(&intf->cmd_rcvrs_mutex); 1367 1380 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, ··· 1373 1386 } 1374 1387 } 1375 1388 mutex_unlock(&intf->cmd_rcvrs_mutex); 1376 - synchronize_rcu(); 1377 1389 while (rcvrs) { 1378 1390 rcvr = rcvrs; 1379 1391 rcvrs = rcvr->next; 1380 1392 kfree(rcvr); 1381 1393 } 1382 1394 1383 - owner = intf->owner; 1384 - kref_put(&intf->refcount, intf_free); 1385 - module_put(owner); 1395 + mutex_lock(&intf->user_msgs_mutex); 1396 + list_for_each_entry_safe(msg, msg2, &intf->user_msgs, link) { 1397 + if (msg->user != user) 1398 + continue; 1399 + list_del(&msg->link); 1400 + ipmi_free_recv_msg(msg); 1401 + } 1402 + mutex_unlock(&intf->user_msgs_mutex); 1403 + 1404 + release_ipmi_user(user); 1386 1405 } 1387 1406 1388 1407 void ipmi_destroy_user(struct ipmi_user *user) 1389 1408 { 1390 - _ipmi_destroy_user(user); 1409 + struct ipmi_smi *intf = user->intf; 1391 1410 1392 - kref_put(&user->refcount, free_user); 1411 + mutex_lock(&intf->users_mutex); 1412 + _ipmi_destroy_user(user); 1413 + mutex_unlock(&intf->users_mutex); 1414 + 1415 + kref_put(&user->refcount, free_ipmi_user); 1393 1416 } 1394 1417 EXPORT_SYMBOL(ipmi_destroy_user); 1395 1418 ··· 1408 1411 unsigned char *minor) 1409 1412 { 1410 1413 struct ipmi_device_id id; 1411 - int rv, index; 1414 + int rv; 1412 1415 1413 - user = acquire_ipmi_user(user, &index); 1416 + user = acquire_ipmi_user(user); 1414 1417 if (!user) 1415 1418 return -ENODEV; 1416 1419 ··· 1419 1422 *major = ipmi_version_major(&id); 1420 1423 *minor = ipmi_version_minor(&id); 1421 1424 } 1422 - release_ipmi_user(user, index); 1425 + release_ipmi_user(user); 1423 1426 1424 1427 return rv; 1425 1428 } ··· 1429 1432 unsigned int channel, 1430 1433 unsigned char address) 1431 1434 { 1432 - int index, rv = 0; 1435 + int rv = 0; 1433 1436 1434 - user = acquire_ipmi_user(user, &index); 1437 + user = acquire_ipmi_user(user); 1435 1438 if (!user) 1436 1439 return -ENODEV; 1437 1440 ··· 1441 1444 channel = array_index_nospec(channel, IPMI_MAX_CHANNELS); 1442 1445 user->intf->addrinfo[channel].address = address; 1443 1446 } 1444 - release_ipmi_user(user, index); 1447 + release_ipmi_user(user); 1445 1448 1446 1449 return rv; 1447 1450 } ··· 1451 1454 unsigned int channel, 1452 1455 unsigned char *address) 1453 1456 { 1454 - int index, rv = 0; 1457 + int rv = 0; 1455 1458 1456 - user = acquire_ipmi_user(user, &index); 1459 + user = acquire_ipmi_user(user); 1457 1460 if (!user) 1458 1461 return -ENODEV; 1459 1462 ··· 1463 1466 channel = array_index_nospec(channel, IPMI_MAX_CHANNELS); 1464 1467 *address = user->intf->addrinfo[channel].address; 1465 1468 } 1466 - release_ipmi_user(user, index); 1469 + release_ipmi_user(user); 1467 1470 1468 1471 return rv; 1469 1472 } ··· 1473 1476 unsigned int channel, 1474 1477 unsigned char LUN) 1475 1478 { 1476 - int index, rv = 0; 1479 + int rv = 0; 1477 1480 1478 - user = acquire_ipmi_user(user, &index); 1481 + user = acquire_ipmi_user(user); 1479 1482 if (!user) 1480 1483 return -ENODEV; 1481 1484 ··· 1485 1488 channel = array_index_nospec(channel, IPMI_MAX_CHANNELS); 1486 1489 user->intf->addrinfo[channel].lun = LUN & 0x3; 1487 1490 } 1488 - release_ipmi_user(user, index); 1491 + release_ipmi_user(user); 1489 1492 1490 1493 return rv; 1491 1494 } ··· 1495 1498 unsigned int channel, 1496 1499 unsigned char *address) 1497 1500 { 1498 - int index, rv = 0; 1501 + int rv = 0; 1499 1502 1500 - user = acquire_ipmi_user(user, &index); 1503 + user = acquire_ipmi_user(user); 1501 1504 if (!user) 1502 1505 return -ENODEV; 1503 1506 ··· 1507 1510 channel = array_index_nospec(channel, IPMI_MAX_CHANNELS); 1508 1511 *address = user->intf->addrinfo[channel].lun; 1509 1512 } 1510 - release_ipmi_user(user, index); 1513 + release_ipmi_user(user); 1511 1514 1512 1515 return rv; 1513 1516 } ··· 1515 1518 1516 1519 int ipmi_get_maintenance_mode(struct ipmi_user *user) 1517 1520 { 1518 - int mode, index; 1521 + int mode; 1519 1522 unsigned long flags; 1520 1523 1521 - user = acquire_ipmi_user(user, &index); 1524 + user = acquire_ipmi_user(user); 1522 1525 if (!user) 1523 1526 return -ENODEV; 1524 1527 1525 1528 spin_lock_irqsave(&user->intf->maintenance_mode_lock, flags); 1526 1529 mode = user->intf->maintenance_mode; 1527 1530 spin_unlock_irqrestore(&user->intf->maintenance_mode_lock, flags); 1528 - release_ipmi_user(user, index); 1531 + release_ipmi_user(user); 1529 1532 1530 1533 return mode; 1531 1534 } ··· 1540 1543 1541 1544 int ipmi_set_maintenance_mode(struct ipmi_user *user, int mode) 1542 1545 { 1543 - int rv = 0, index; 1546 + int rv = 0; 1544 1547 unsigned long flags; 1545 1548 struct ipmi_smi *intf = user->intf; 1546 1549 1547 - user = acquire_ipmi_user(user, &index); 1550 + user = acquire_ipmi_user(user); 1548 1551 if (!user) 1549 1552 return -ENODEV; 1550 1553 ··· 1574 1577 } 1575 1578 out_unlock: 1576 1579 spin_unlock_irqrestore(&intf->maintenance_mode_lock, flags); 1577 - release_ipmi_user(user, index); 1580 + release_ipmi_user(user); 1578 1581 1579 1582 return rv; 1580 1583 } ··· 1582 1585 1583 1586 int ipmi_set_gets_events(struct ipmi_user *user, bool val) 1584 1587 { 1585 - unsigned long flags; 1586 1588 struct ipmi_smi *intf = user->intf; 1587 1589 struct ipmi_recv_msg *msg, *msg2; 1588 1590 struct list_head msgs; 1589 - int index; 1590 1591 1591 - user = acquire_ipmi_user(user, &index); 1592 + user = acquire_ipmi_user(user); 1592 1593 if (!user) 1593 1594 return -ENODEV; 1594 1595 1595 1596 INIT_LIST_HEAD(&msgs); 1596 1597 1597 - spin_lock_irqsave(&intf->events_lock, flags); 1598 + mutex_lock(&intf->events_mutex); 1598 1599 if (user->gets_events == val) 1599 1600 goto out; 1600 1601 ··· 1605 1610 atomic_dec(&intf->event_waiters); 1606 1611 } 1607 1612 1608 - if (intf->delivering_events) 1609 - /* 1610 - * Another thread is delivering events for this, so 1611 - * let it handle any new events. 1612 - */ 1613 - goto out; 1614 - 1615 1613 /* Deliver any queued events. */ 1616 1614 while (user->gets_events && !list_empty(&intf->waiting_events)) { 1617 1615 list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) ··· 1615 1627 intf->event_msg_printed = 0; 1616 1628 } 1617 1629 1618 - intf->delivering_events = 1; 1619 - spin_unlock_irqrestore(&intf->events_lock, flags); 1620 - 1621 1630 list_for_each_entry_safe(msg, msg2, &msgs, link) { 1622 1631 msg->user = user; 1623 1632 kref_get(&user->refcount); 1624 1633 deliver_local_response(intf, msg); 1625 1634 } 1626 - 1627 - spin_lock_irqsave(&intf->events_lock, flags); 1628 - intf->delivering_events = 0; 1629 1635 } 1630 1636 1631 1637 out: 1632 - spin_unlock_irqrestore(&intf->events_lock, flags); 1633 - release_ipmi_user(user, index); 1638 + mutex_unlock(&intf->events_mutex); 1639 + release_ipmi_user(user); 1634 1640 1635 1641 return 0; 1636 1642 } ··· 1669 1687 { 1670 1688 struct ipmi_smi *intf = user->intf; 1671 1689 struct cmd_rcvr *rcvr; 1672 - int rv = 0, index; 1690 + int rv = 0; 1673 1691 1674 - user = acquire_ipmi_user(user, &index); 1692 + user = acquire_ipmi_user(user); 1675 1693 if (!user) 1676 1694 return -ENODEV; 1677 1695 ··· 1701 1719 if (rv) 1702 1720 kfree(rcvr); 1703 1721 out_release: 1704 - release_ipmi_user(user, index); 1722 + release_ipmi_user(user); 1705 1723 1706 1724 return rv; 1707 1725 } ··· 1715 1733 struct ipmi_smi *intf = user->intf; 1716 1734 struct cmd_rcvr *rcvr; 1717 1735 struct cmd_rcvr *rcvrs = NULL; 1718 - int i, rv = -ENOENT, index; 1736 + int i, rv = -ENOENT; 1719 1737 1720 - user = acquire_ipmi_user(user, &index); 1738 + user = acquire_ipmi_user(user); 1721 1739 if (!user) 1722 1740 return -ENODEV; 1723 1741 ··· 1740 1758 } 1741 1759 mutex_unlock(&intf->cmd_rcvrs_mutex); 1742 1760 synchronize_rcu(); 1743 - release_ipmi_user(user, index); 1761 + release_ipmi_user(user); 1744 1762 while (rcvrs) { 1745 1763 smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_COMMANDS); 1746 1764 rcvr = rcvrs; ··· 1864 1882 const struct ipmi_smi_handlers *handlers, 1865 1883 struct ipmi_smi_msg *smi_msg, int priority) 1866 1884 { 1867 - int run_to_completion = intf->run_to_completion; 1885 + int run_to_completion = READ_ONCE(intf->run_to_completion); 1868 1886 unsigned long flags = 0; 1869 1887 1870 1888 if (!run_to_completion) 1871 1889 spin_lock_irqsave(&intf->xmit_msgs_lock, flags); 1872 1890 smi_msg = smi_add_send_msg(intf, smi_msg, priority); 1873 - 1874 1891 if (!run_to_completion) 1875 1892 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags); 1876 1893 ··· 2285 2304 { 2286 2305 struct ipmi_smi_msg *smi_msg; 2287 2306 struct ipmi_recv_msg *recv_msg; 2307 + int run_to_completion = READ_ONCE(intf->run_to_completion); 2288 2308 int rv = 0; 2289 2309 2290 2310 if (user) { ··· 2319 2337 } 2320 2338 } 2321 2339 2322 - rcu_read_lock(); 2340 + if (!run_to_completion) 2341 + mutex_lock(&intf->users_mutex); 2323 2342 if (intf->in_shutdown) { 2324 2343 rv = -ENODEV; 2325 2344 goto out_err; ··· 2366 2383 2367 2384 smi_send(intf, intf->handlers, smi_msg, priority); 2368 2385 } 2369 - rcu_read_unlock(); 2386 + if (!run_to_completion) 2387 + mutex_unlock(&intf->users_mutex); 2370 2388 2371 2389 out: 2372 2390 if (rv && user) ··· 2398 2414 unsigned int retry_time_ms) 2399 2415 { 2400 2416 unsigned char saddr = 0, lun = 0; 2401 - int rv, index; 2417 + int rv; 2402 2418 2403 2419 if (!user) 2404 2420 return -EINVAL; 2405 2421 2406 - user = acquire_ipmi_user(user, &index); 2422 + user = acquire_ipmi_user(user); 2407 2423 if (!user) 2408 2424 return -ENODEV; 2409 2425 ··· 2422 2438 retries, 2423 2439 retry_time_ms); 2424 2440 2425 - release_ipmi_user(user, index); 2441 + release_ipmi_user(user); 2426 2442 return rv; 2427 2443 } 2428 2444 EXPORT_SYMBOL(ipmi_request_settime); ··· 2437 2453 int priority) 2438 2454 { 2439 2455 unsigned char saddr = 0, lun = 0; 2440 - int rv, index; 2456 + int rv; 2441 2457 2442 2458 if (!user) 2443 2459 return -EINVAL; 2444 2460 2445 - user = acquire_ipmi_user(user, &index); 2461 + user = acquire_ipmi_user(user); 2446 2462 if (!user) 2447 2463 return -ENODEV; 2448 2464 ··· 2461 2477 lun, 2462 2478 -1, 0); 2463 2479 2464 - release_ipmi_user(user, index); 2480 + release_ipmi_user(user); 2465 2481 return rv; 2466 2482 } 2467 2483 EXPORT_SYMBOL(ipmi_request_supply_msgs); ··· 3048 3064 * with removing the device attributes while reading a device 3049 3065 * attribute. 3050 3066 */ 3051 - queue_work(remove_work_wq, &bmc->remove_work); 3067 + queue_work(bmc_remove_work_wq, &bmc->remove_work); 3052 3068 } 3053 3069 3054 3070 /* ··· 3504 3520 char *buf) 3505 3521 { 3506 3522 struct ipmi_smi *intf = container_of(attr, 3507 - struct ipmi_smi, nr_msgs_devattr); 3523 + struct ipmi_smi, nr_msgs_devattr); 3508 3524 struct ipmi_user *user; 3509 - int index; 3510 3525 unsigned int count = 0; 3511 3526 3512 - index = srcu_read_lock(&intf->users_srcu); 3513 - list_for_each_entry_rcu(user, &intf->users, link) 3527 + mutex_lock(&intf->users_mutex); 3528 + list_for_each_entry(user, &intf->users, link) 3514 3529 count += atomic_read(&user->nr_msgs); 3515 - srcu_read_unlock(&intf->users_srcu, index); 3530 + mutex_unlock(&intf->users_mutex); 3516 3531 3517 3532 return sysfs_emit(buf, "%u\n", count); 3518 3533 } ··· 3552 3569 if (!intf) 3553 3570 return -ENOMEM; 3554 3571 3555 - rv = init_srcu_struct(&intf->users_srcu); 3556 - if (rv) { 3557 - kfree(intf); 3558 - return rv; 3559 - } 3560 - 3561 3572 intf->owner = owner; 3562 3573 intf->bmc = &intf->tmp_bmc; 3563 3574 INIT_LIST_HEAD(&intf->bmc->intfs); ··· 3568 3591 } 3569 3592 if (slave_addr != 0) 3570 3593 intf->addrinfo[0].address = slave_addr; 3594 + INIT_LIST_HEAD(&intf->user_msgs); 3595 + mutex_init(&intf->user_msgs_mutex); 3571 3596 INIT_LIST_HEAD(&intf->users); 3597 + mutex_init(&intf->users_mutex); 3572 3598 atomic_set(&intf->nr_users, 0); 3573 3599 intf->handlers = handlers; 3574 3600 intf->send_info = send_info; ··· 3583 3603 intf->curr_seq = 0; 3584 3604 spin_lock_init(&intf->waiting_rcv_msgs_lock); 3585 3605 INIT_LIST_HEAD(&intf->waiting_rcv_msgs); 3586 - INIT_WORK(&intf->recv_work, smi_recv_work); 3606 + INIT_WORK(&intf->smi_work, smi_work); 3587 3607 atomic_set(&intf->watchdog_pretimeouts_to_deliver, 0); 3588 3608 spin_lock_init(&intf->xmit_msgs_lock); 3589 3609 INIT_LIST_HEAD(&intf->xmit_msgs); 3590 3610 INIT_LIST_HEAD(&intf->hp_xmit_msgs); 3591 - spin_lock_init(&intf->events_lock); 3611 + mutex_init(&intf->events_mutex); 3592 3612 spin_lock_init(&intf->watch_lock); 3593 3613 atomic_set(&intf->event_waiters, 0); 3594 3614 intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME; ··· 3601 3621 for (i = 0; i < IPMI_NUM_STATS; i++) 3602 3622 atomic_set(&intf->stats[i], 0); 3603 3623 3624 + /* 3625 + * Grab the watchers mutex so we can deliver the new interface 3626 + * without races. 3627 + */ 3628 + mutex_lock(&smi_watchers_mutex); 3604 3629 mutex_lock(&ipmi_interfaces_mutex); 3605 3630 /* Look for a hole in the numbers. */ 3606 3631 i = 0; 3607 3632 link = &ipmi_interfaces; 3608 - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, 3609 - ipmi_interfaces_mutex_held()) { 3633 + list_for_each_entry(tintf, &ipmi_interfaces, link) { 3610 3634 if (tintf->intf_num != i) { 3611 3635 link = &tintf->link; 3612 3636 break; ··· 3619 3635 } 3620 3636 /* Add the new interface in numeric order. */ 3621 3637 if (i == 0) 3622 - list_add_rcu(&intf->link, &ipmi_interfaces); 3638 + list_add(&intf->link, &ipmi_interfaces); 3623 3639 else 3624 - list_add_tail_rcu(&intf->link, link); 3640 + list_add_tail(&intf->link, link); 3625 3641 3626 3642 rv = handlers->start_processing(send_info, intf); 3627 3643 if (rv) ··· 3653 3669 goto out_err_bmc_reg; 3654 3670 } 3655 3671 3656 - /* 3657 - * Keep memory order straight for RCU readers. Make 3658 - * sure everything else is committed to memory before 3659 - * setting intf_num to mark the interface valid. 3660 - */ 3661 - smp_wmb(); 3662 3672 intf->intf_num = i; 3663 3673 mutex_unlock(&ipmi_interfaces_mutex); 3664 3674 3665 3675 /* After this point the interface is legal to use. */ 3666 3676 call_smi_watchers(i, intf->si_dev); 3677 + 3678 + mutex_unlock(&smi_watchers_mutex); 3667 3679 3668 3680 return 0; 3669 3681 ··· 3669 3689 if (intf->handlers->shutdown) 3670 3690 intf->handlers->shutdown(intf->send_info); 3671 3691 out_err: 3672 - list_del_rcu(&intf->link); 3692 + list_del(&intf->link); 3673 3693 mutex_unlock(&ipmi_interfaces_mutex); 3674 - synchronize_srcu(&ipmi_interfaces_srcu); 3675 - cleanup_srcu_struct(&intf->users_srcu); 3694 + mutex_unlock(&smi_watchers_mutex); 3676 3695 kref_put(&intf->refcount, intf_free); 3677 3696 3678 3697 return rv; ··· 3737 3758 void ipmi_unregister_smi(struct ipmi_smi *intf) 3738 3759 { 3739 3760 struct ipmi_smi_watcher *w; 3740 - int intf_num, index; 3761 + int intf_num; 3741 3762 3742 3763 if (!intf) 3743 3764 return; 3765 + 3744 3766 intf_num = intf->intf_num; 3745 3767 mutex_lock(&ipmi_interfaces_mutex); 3768 + cancel_work_sync(&intf->smi_work); 3769 + /* smi_work() can no longer be in progress after this. */ 3770 + 3746 3771 intf->intf_num = -1; 3747 3772 intf->in_shutdown = true; 3748 - list_del_rcu(&intf->link); 3773 + list_del(&intf->link); 3749 3774 mutex_unlock(&ipmi_interfaces_mutex); 3750 - synchronize_srcu(&ipmi_interfaces_srcu); 3751 3775 3752 - /* At this point no users can be added to the interface. */ 3776 + /* 3777 + * At this point no users can be added to the interface and no 3778 + * new messages can be sent. 3779 + */ 3780 + 3781 + if (intf->handlers->shutdown) 3782 + intf->handlers->shutdown(intf->send_info); 3753 3783 3754 3784 device_remove_file(intf->si_dev, &intf->nr_msgs_devattr); 3755 3785 device_remove_file(intf->si_dev, &intf->nr_users_devattr); ··· 3772 3784 w->smi_gone(intf_num); 3773 3785 mutex_unlock(&smi_watchers_mutex); 3774 3786 3775 - index = srcu_read_lock(&intf->users_srcu); 3787 + mutex_lock(&intf->users_mutex); 3776 3788 while (!list_empty(&intf->users)) { 3777 - struct ipmi_user *user = 3778 - container_of(list_next_rcu(&intf->users), 3779 - struct ipmi_user, link); 3789 + struct ipmi_user *user = list_first_entry(&intf->users, 3790 + struct ipmi_user, link); 3780 3791 3781 3792 _ipmi_destroy_user(user); 3782 3793 } 3783 - srcu_read_unlock(&intf->users_srcu, index); 3784 - 3785 - if (intf->handlers->shutdown) 3786 - intf->handlers->shutdown(intf->send_info); 3794 + mutex_unlock(&intf->users_mutex); 3787 3795 3788 3796 cleanup_smi_msgs(intf); 3789 3797 3790 3798 ipmi_bmc_unregister(intf); 3791 3799 3792 - cleanup_srcu_struct(&intf->users_srcu); 3793 3800 kref_put(&intf->refcount, intf_free); 3794 3801 } 3795 3802 EXPORT_SYMBOL(ipmi_unregister_smi); ··· 3909 3926 dev_dbg(intf->si_dev, "Invalid command: %*ph\n", 3910 3927 msg->data_size, msg->data); 3911 3928 3912 - rcu_read_lock(); 3913 - if (!intf->in_shutdown) { 3914 - smi_send(intf, intf->handlers, msg, 0); 3915 - /* 3916 - * We used the message, so return the value 3917 - * that causes it to not be freed or 3918 - * queued. 3919 - */ 3920 - rv = -1; 3921 - } 3922 - rcu_read_unlock(); 3929 + smi_send(intf, intf->handlers, msg, 0); 3930 + /* 3931 + * We used the message, so return the value that 3932 + * causes it to not be freed or queued. 3933 + */ 3934 + rv = -1; 3923 3935 } else { 3924 3936 recv_msg = ipmi_alloc_recv_msg(); 3925 3937 if (!recv_msg) { ··· 3924 3946 * later. 3925 3947 */ 3926 3948 rv = 1; 3927 - kref_put(&user->refcount, free_user); 3949 + kref_put(&user->refcount, free_ipmi_user); 3928 3950 } else { 3929 3951 /* Extract the source address from the data. */ 3930 3952 ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr; ··· 3995 4017 msg->data[4] = IPMI_INVALID_CMD_COMPLETION_CODE; 3996 4018 msg->data_size = 5; 3997 4019 3998 - rcu_read_lock(); 3999 - if (!intf->in_shutdown) { 4000 - smi_send(intf, intf->handlers, msg, 0); 4001 - /* 4002 - * We used the message, so return the value 4003 - * that causes it to not be freed or 4004 - * queued. 4005 - */ 4006 - rv = -1; 4007 - } 4008 - rcu_read_unlock(); 4020 + smi_send(intf, intf->handlers, msg, 0); 4021 + /* 4022 + * We used the message, so return the value that 4023 + * causes it to not be freed or queued. 4024 + */ 4025 + rv = -1; 4009 4026 } else { 4010 4027 recv_msg = ipmi_alloc_recv_msg(); 4011 4028 if (!recv_msg) { ··· 4010 4037 * later. 4011 4038 */ 4012 4039 rv = 1; 4013 - kref_put(&user->refcount, free_user); 4040 + kref_put(&user->refcount, free_ipmi_user); 4014 4041 } else { 4015 4042 /* Extract the source address from the data. */ 4016 4043 daddr = (struct ipmi_ipmb_direct_addr *)&recv_msg->addr; ··· 4179 4206 rcu_read_unlock(); 4180 4207 4181 4208 if (user == NULL) { 4182 - /* We didn't find a user, just give up. */ 4209 + /* We didn't find a user, just give up and return an error. */ 4183 4210 ipmi_inc_stat(intf, unhandled_commands); 4184 4211 4212 + msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); 4213 + msg->data[1] = IPMI_SEND_MSG_CMD; 4214 + msg->data[2] = chan; 4215 + msg->data[3] = msg->rsp[4]; /* handle */ 4216 + msg->data[4] = msg->rsp[8]; /* rsSWID */ 4217 + msg->data[5] = ((netfn + 1) << 2) | (msg->rsp[9] & 0x3); 4218 + msg->data[6] = ipmb_checksum(&msg->data[3], 3); 4219 + msg->data[7] = msg->rsp[5]; /* rqSWID */ 4220 + /* rqseq/lun */ 4221 + msg->data[8] = (msg->rsp[9] & 0xfc) | (msg->rsp[6] & 0x3); 4222 + msg->data[9] = cmd; 4223 + msg->data[10] = IPMI_INVALID_CMD_COMPLETION_CODE; 4224 + msg->data[11] = ipmb_checksum(&msg->data[7], 4); 4225 + msg->data_size = 12; 4226 + 4227 + dev_dbg(intf->si_dev, "Invalid command: %*ph\n", 4228 + msg->data_size, msg->data); 4229 + 4230 + smi_send(intf, intf->handlers, msg, 0); 4185 4231 /* 4186 - * Don't do anything with these messages, just allow 4187 - * them to be freed. 4232 + * We used the message, so return the value that 4233 + * causes it to not be freed or queued. 4188 4234 */ 4189 - rv = 0; 4235 + rv = -1; 4190 4236 } else { 4191 4237 recv_msg = ipmi_alloc_recv_msg(); 4192 4238 if (!recv_msg) { ··· 4214 4222 * message, so requeue it for handling later. 4215 4223 */ 4216 4224 rv = 1; 4217 - kref_put(&user->refcount, free_user); 4225 + kref_put(&user->refcount, free_ipmi_user); 4218 4226 } else { 4219 4227 /* Extract the source address from the data. */ 4220 4228 lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr; ··· 4323 4331 * later. 4324 4332 */ 4325 4333 rv = 1; 4326 - kref_put(&user->refcount, free_user); 4334 + kref_put(&user->refcount, free_ipmi_user); 4327 4335 } else { 4328 4336 /* 4329 4337 * OEM Messages are expected to be delivered via ··· 4385 4393 struct ipmi_recv_msg *recv_msg, *recv_msg2; 4386 4394 struct list_head msgs; 4387 4395 struct ipmi_user *user; 4388 - int rv = 0, deliver_count = 0, index; 4389 - unsigned long flags; 4396 + int rv = 0, deliver_count = 0; 4390 4397 4391 4398 if (msg->rsp_size < 19) { 4392 4399 /* Message is too small to be an IPMB event. */ ··· 4400 4409 4401 4410 INIT_LIST_HEAD(&msgs); 4402 4411 4403 - spin_lock_irqsave(&intf->events_lock, flags); 4412 + mutex_lock(&intf->events_mutex); 4404 4413 4405 4414 ipmi_inc_stat(intf, events); 4406 4415 ··· 4408 4417 * Allocate and fill in one message for every user that is 4409 4418 * getting events. 4410 4419 */ 4411 - index = srcu_read_lock(&intf->users_srcu); 4412 - list_for_each_entry_rcu(user, &intf->users, link) { 4420 + mutex_lock(&intf->users_mutex); 4421 + list_for_each_entry(user, &intf->users, link) { 4413 4422 if (!user->gets_events) 4414 4423 continue; 4415 4424 4416 4425 recv_msg = ipmi_alloc_recv_msg(); 4417 4426 if (!recv_msg) { 4418 - rcu_read_unlock(); 4427 + mutex_unlock(&intf->users_mutex); 4419 4428 list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, 4420 4429 link) { 4430 + user = recv_msg->user; 4421 4431 list_del(&recv_msg->link); 4422 4432 ipmi_free_recv_msg(recv_msg); 4433 + kref_put(&user->refcount, free_ipmi_user); 4423 4434 } 4424 4435 /* 4425 4436 * We couldn't allocate memory for the ··· 4439 4446 kref_get(&user->refcount); 4440 4447 list_add_tail(&recv_msg->link, &msgs); 4441 4448 } 4442 - srcu_read_unlock(&intf->users_srcu, index); 4449 + mutex_unlock(&intf->users_mutex); 4443 4450 4444 4451 if (deliver_count) { 4445 4452 /* Now deliver all the messages. */ ··· 4477 4484 } 4478 4485 4479 4486 out: 4480 - spin_unlock_irqrestore(&intf->events_lock, flags); 4487 + mutex_unlock(&intf->events_mutex); 4481 4488 4482 4489 return rv; 4483 4490 } ··· 4563 4570 && (msg->data[1] == IPMI_SEND_MSG_CMD) 4564 4571 && (msg->user_data == NULL)) { 4565 4572 4566 - if (intf->in_shutdown) 4573 + if (intf->in_shutdown || intf->run_to_completion) 4567 4574 goto out; 4568 4575 4569 4576 /* ··· 4635 4642 */ 4636 4643 struct ipmi_recv_msg *recv_msg; 4637 4644 4645 + if (intf->run_to_completion) 4646 + goto out; 4647 + 4638 4648 chan = msg->data[2] & 0x0f; 4639 4649 if (chan >= IPMI_MAX_CHANNELS) 4640 4650 /* Invalid channel number */ ··· 4659 4663 } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) 4660 4664 && (msg->rsp[1] == IPMI_GET_MSG_CMD)) { 4661 4665 struct ipmi_channel *chans; 4666 + 4667 + if (intf->run_to_completion) 4668 + goto out; 4662 4669 4663 4670 /* It's from the receive queue. */ 4664 4671 chan = msg->rsp[3] & 0xf; ··· 4737 4738 } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) 4738 4739 && (msg->rsp[1] == IPMI_READ_EVENT_MSG_BUFFER_CMD)) { 4739 4740 /* It's an asynchronous event. */ 4741 + if (intf->run_to_completion) 4742 + goto out; 4743 + 4740 4744 requeue = handle_read_event_rsp(intf, msg); 4741 4745 } else { 4742 4746 /* It's a response from the local BMC. */ ··· 4755 4753 */ 4756 4754 static void handle_new_recv_msgs(struct ipmi_smi *intf) 4757 4755 { 4758 - struct ipmi_smi_msg *smi_msg; 4759 - unsigned long flags = 0; 4760 - int rv; 4761 - int run_to_completion = intf->run_to_completion; 4756 + struct ipmi_smi_msg *smi_msg; 4757 + unsigned long flags = 0; 4758 + int rv; 4759 + int run_to_completion = READ_ONCE(intf->run_to_completion); 4762 4760 4763 4761 /* See if any waiting messages need to be processed. */ 4764 4762 if (!run_to_completion) ··· 4792 4790 } 4793 4791 if (!run_to_completion) 4794 4792 spin_unlock_irqrestore(&intf->waiting_rcv_msgs_lock, flags); 4795 - 4796 - /* 4797 - * If the pretimout count is non-zero, decrement one from it and 4798 - * deliver pretimeouts to all the users. 4799 - */ 4800 - if (atomic_add_unless(&intf->watchdog_pretimeouts_to_deliver, -1, 0)) { 4801 - struct ipmi_user *user; 4802 - int index; 4803 - 4804 - index = srcu_read_lock(&intf->users_srcu); 4805 - list_for_each_entry_rcu(user, &intf->users, link) { 4806 - if (user->handler->ipmi_watchdog_pretimeout) 4807 - user->handler->ipmi_watchdog_pretimeout( 4808 - user->handler_data); 4809 - } 4810 - srcu_read_unlock(&intf->users_srcu, index); 4811 - } 4812 4793 } 4813 4794 4814 - static void smi_recv_work(struct work_struct *t) 4795 + static void smi_work(struct work_struct *t) 4815 4796 { 4816 4797 unsigned long flags = 0; /* keep us warning-free. */ 4817 - struct ipmi_smi *intf = from_work(intf, t, recv_work); 4818 - int run_to_completion = intf->run_to_completion; 4798 + struct ipmi_smi *intf = from_work(intf, t, smi_work); 4799 + int run_to_completion = READ_ONCE(intf->run_to_completion); 4819 4800 struct ipmi_smi_msg *newmsg = NULL; 4801 + struct ipmi_recv_msg *msg, *msg2; 4820 4802 4821 4803 /* 4822 4804 * Start the next message if available. ··· 4809 4823 * because the lower layer is allowed to hold locks while calling 4810 4824 * message delivery. 4811 4825 */ 4812 - 4813 - rcu_read_lock(); 4814 4826 4815 4827 if (!run_to_completion) 4816 4828 spin_lock_irqsave(&intf->xmit_msgs_lock, flags); ··· 4827 4843 intf->curr_msg = newmsg; 4828 4844 } 4829 4845 } 4830 - 4831 4846 if (!run_to_completion) 4832 4847 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags); 4848 + 4833 4849 if (newmsg) 4834 4850 intf->handlers->sender(intf->send_info, newmsg); 4835 4851 4836 - rcu_read_unlock(); 4837 - 4838 4852 handle_new_recv_msgs(intf); 4853 + 4854 + /* Nothing below applies during panic time. */ 4855 + if (run_to_completion) 4856 + return; 4857 + 4858 + /* 4859 + * If the pretimout count is non-zero, decrement one from it and 4860 + * deliver pretimeouts to all the users. 4861 + */ 4862 + if (atomic_add_unless(&intf->watchdog_pretimeouts_to_deliver, -1, 0)) { 4863 + struct ipmi_user *user; 4864 + 4865 + mutex_lock(&intf->users_mutex); 4866 + list_for_each_entry(user, &intf->users, link) { 4867 + if (user->handler->ipmi_watchdog_pretimeout) 4868 + user->handler->ipmi_watchdog_pretimeout( 4869 + user->handler_data); 4870 + } 4871 + mutex_unlock(&intf->users_mutex); 4872 + } 4873 + 4874 + /* 4875 + * Freeing the message can cause a user to be released, which 4876 + * can then cause the interface to be freed. Make sure that 4877 + * doesn't happen until we are ready. 4878 + */ 4879 + kref_get(&intf->refcount); 4880 + 4881 + mutex_lock(&intf->user_msgs_mutex); 4882 + list_for_each_entry_safe(msg, msg2, &intf->user_msgs, link) { 4883 + struct ipmi_user *user = msg->user; 4884 + 4885 + list_del(&msg->link); 4886 + 4887 + if (refcount_read(&user->destroyed) == 0) { 4888 + ipmi_free_recv_msg(msg); 4889 + } else { 4890 + atomic_dec(&user->nr_msgs); 4891 + user->handler->ipmi_recv_hndl(msg, user->handler_data); 4892 + } 4893 + } 4894 + mutex_unlock(&intf->user_msgs_mutex); 4895 + 4896 + kref_put(&intf->refcount, intf_free); 4839 4897 } 4840 4898 4841 4899 /* Handle a new message from the lower layer. */ ··· 4885 4859 struct ipmi_smi_msg *msg) 4886 4860 { 4887 4861 unsigned long flags = 0; /* keep us warning-free. */ 4888 - int run_to_completion = intf->run_to_completion; 4862 + int run_to_completion = READ_ONCE(intf->run_to_completion); 4889 4863 4890 4864 /* 4891 4865 * To preserve message order, we keep a queue and deliver from ··· 4910 4884 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags); 4911 4885 4912 4886 if (run_to_completion) 4913 - smi_recv_work(&intf->recv_work); 4887 + smi_work(&intf->smi_work); 4914 4888 else 4915 - queue_work(system_bh_wq, &intf->recv_work); 4889 + queue_work(system_wq, &intf->smi_work); 4916 4890 } 4917 4891 EXPORT_SYMBOL(ipmi_smi_msg_received); 4918 4892 ··· 4922 4896 return; 4923 4897 4924 4898 atomic_set(&intf->watchdog_pretimeouts_to_deliver, 1); 4925 - queue_work(system_bh_wq, &intf->recv_work); 4899 + queue_work(system_wq, &intf->smi_work); 4926 4900 } 4927 4901 EXPORT_SYMBOL(ipmi_smi_watchdog_pretimeout); 4928 4902 ··· 5091 5065 flags); 5092 5066 } 5093 5067 5094 - queue_work(system_bh_wq, &intf->recv_work); 5068 + queue_work(system_wq, &intf->smi_work); 5095 5069 5096 5070 return need_timer; 5097 5071 } ··· 5110 5084 5111 5085 static atomic_t stop_operation; 5112 5086 5113 - static void ipmi_timeout(struct timer_list *unused) 5087 + static void ipmi_timeout_work(struct work_struct *work) 5114 5088 { 5089 + if (atomic_read(&stop_operation)) 5090 + return; 5091 + 5115 5092 struct ipmi_smi *intf; 5116 5093 bool need_timer = false; 5117 - int index; 5118 5094 5119 5095 if (atomic_read(&stop_operation)) 5120 5096 return; 5121 5097 5122 - index = srcu_read_lock(&ipmi_interfaces_srcu); 5123 - list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 5098 + mutex_lock(&ipmi_interfaces_mutex); 5099 + list_for_each_entry(intf, &ipmi_interfaces, link) { 5124 5100 if (atomic_read(&intf->event_waiters)) { 5125 5101 intf->ticks_to_req_ev--; 5126 5102 if (intf->ticks_to_req_ev == 0) { ··· 5134 5106 5135 5107 need_timer |= ipmi_timeout_handler(intf, IPMI_TIMEOUT_TIME); 5136 5108 } 5137 - srcu_read_unlock(&ipmi_interfaces_srcu, index); 5109 + mutex_unlock(&ipmi_interfaces_mutex); 5138 5110 5139 5111 if (need_timer) 5140 5112 mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); 5113 + } 5114 + 5115 + static DECLARE_WORK(ipmi_timer_work, ipmi_timeout_work); 5116 + 5117 + static void ipmi_timeout(struct timer_list *unused) 5118 + { 5119 + if (atomic_read(&stop_operation)) 5120 + return; 5121 + 5122 + queue_work(system_wq, &ipmi_timer_work); 5141 5123 } 5142 5124 5143 5125 static void need_waiter(struct ipmi_smi *intf) ··· 5206 5168 void ipmi_free_recv_msg(struct ipmi_recv_msg *msg) 5207 5169 { 5208 5170 if (msg->user && !oops_in_progress) 5209 - kref_put(&msg->user->refcount, free_user); 5171 + kref_put(&msg->user->refcount, free_ipmi_user); 5210 5172 msg->done(msg); 5211 5173 } 5212 5174 EXPORT_SYMBOL(ipmi_free_recv_msg); ··· 5226 5188 /* 5227 5189 * Inside a panic, send a message and wait for a response. 5228 5190 */ 5229 - static void ipmi_panic_request_and_wait(struct ipmi_smi *intf, 5230 - struct ipmi_addr *addr, 5231 - struct kernel_ipmi_msg *msg) 5191 + static void _ipmi_panic_request_and_wait(struct ipmi_smi *intf, 5192 + struct ipmi_addr *addr, 5193 + struct kernel_ipmi_msg *msg) 5232 5194 { 5233 5195 struct ipmi_smi_msg smi_msg; 5234 5196 struct ipmi_recv_msg recv_msg; ··· 5257 5219 while (atomic_read(&panic_done_count) != 0) 5258 5220 ipmi_poll(intf); 5259 5221 } 5222 + 5223 + void ipmi_panic_request_and_wait(struct ipmi_user *user, 5224 + struct ipmi_addr *addr, 5225 + struct kernel_ipmi_msg *msg) 5226 + { 5227 + user->intf->run_to_completion = 1; 5228 + _ipmi_panic_request_and_wait(user->intf, addr, msg); 5229 + } 5230 + EXPORT_SYMBOL(ipmi_panic_request_and_wait); 5260 5231 5261 5232 static void event_receiver_fetcher(struct ipmi_smi *intf, 5262 5233 struct ipmi_recv_msg *msg) ··· 5335 5288 } 5336 5289 5337 5290 /* Send the event announcing the panic. */ 5338 - ipmi_panic_request_and_wait(intf, &addr, &msg); 5291 + _ipmi_panic_request_and_wait(intf, &addr, &msg); 5339 5292 5340 5293 /* 5341 5294 * On every interface, dump a bunch of OEM event holding the ··· 5371 5324 msg.data = NULL; 5372 5325 msg.data_len = 0; 5373 5326 intf->null_user_handler = device_id_fetcher; 5374 - ipmi_panic_request_and_wait(intf, &addr, &msg); 5327 + _ipmi_panic_request_and_wait(intf, &addr, &msg); 5375 5328 5376 5329 if (intf->local_event_generator) { 5377 5330 /* Request the event receiver from the local MC. */ ··· 5380 5333 msg.data = NULL; 5381 5334 msg.data_len = 0; 5382 5335 intf->null_user_handler = event_receiver_fetcher; 5383 - ipmi_panic_request_and_wait(intf, &addr, &msg); 5336 + _ipmi_panic_request_and_wait(intf, &addr, &msg); 5384 5337 } 5385 5338 intf->null_user_handler = NULL; 5386 5339 ··· 5432 5385 memcpy_and_pad(data+5, 11, p, size, '\0'); 5433 5386 p += size; 5434 5387 5435 - ipmi_panic_request_and_wait(intf, &addr, &msg); 5388 + _ipmi_panic_request_and_wait(intf, &addr, &msg); 5436 5389 } 5437 5390 } 5438 5391 ··· 5450 5403 has_panicked = 1; 5451 5404 5452 5405 /* For every registered interface, set it to run to completion. */ 5453 - list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 5406 + list_for_each_entry(intf, &ipmi_interfaces, link) { 5454 5407 if (!intf->handlers || intf->intf_num == -1) 5455 5408 /* Interface is not ready. */ 5456 5409 continue; ··· 5480 5433 intf->handlers->set_run_to_completion(intf->send_info, 5481 5434 1); 5482 5435 5483 - list_for_each_entry_rcu(user, &intf->users, link) { 5436 + list_for_each_entry(user, &intf->users, link) { 5484 5437 if (user->handler->ipmi_panic_handler) 5485 5438 user->handler->ipmi_panic_handler( 5486 5439 user->handler_data); ··· 5525 5478 if (initialized) 5526 5479 goto out; 5527 5480 5528 - rv = init_srcu_struct(&ipmi_interfaces_srcu); 5529 - if (rv) 5530 - goto out; 5531 - 5532 - remove_work_wq = create_singlethread_workqueue("ipmi-msghandler-remove-wq"); 5533 - if (!remove_work_wq) { 5481 + bmc_remove_work_wq = create_singlethread_workqueue("ipmi-msghandler-remove-wq"); 5482 + if (!bmc_remove_work_wq) { 5534 5483 pr_err("unable to create ipmi-msghandler-remove-wq workqueue"); 5535 5484 rv = -ENOMEM; 5536 - goto out_wq; 5485 + goto out; 5537 5486 } 5538 5487 5539 5488 timer_setup(&ipmi_timer, ipmi_timeout, 0); ··· 5539 5496 5540 5497 initialized = true; 5541 5498 5542 - out_wq: 5543 - if (rv) 5544 - cleanup_srcu_struct(&ipmi_interfaces_srcu); 5545 5499 out: 5546 5500 mutex_unlock(&ipmi_interfaces_mutex); 5547 5501 return rv; ··· 5562 5522 int count; 5563 5523 5564 5524 if (initialized) { 5565 - destroy_workqueue(remove_work_wq); 5525 + destroy_workqueue(bmc_remove_work_wq); 5566 5526 5567 5527 atomic_notifier_chain_unregister(&panic_notifier_list, 5568 5528 &panic_block); ··· 5579 5539 */ 5580 5540 atomic_set(&stop_operation, 1); 5581 5541 timer_delete_sync(&ipmi_timer); 5542 + cancel_work_sync(&ipmi_timer_work); 5582 5543 5583 5544 initialized = false; 5584 5545 ··· 5590 5549 count = atomic_read(&recv_msg_inuse_count); 5591 5550 if (count != 0) 5592 5551 pr_warn("recv message count %d at exit\n", count); 5593 - 5594 - cleanup_srcu_struct(&ipmi_interfaces_srcu); 5595 5552 } 5596 5553 if (drvregistered) 5597 5554 driver_unregister(&ipmidriver.driver);
+9 -1
drivers/char/ipmi/ipmi_si.h
··· 26 26 /* Array is defined in the ipmi_si_intf.c */ 27 27 extern const char *const si_to_str[]; 28 28 29 + struct ipmi_match_info { 30 + enum si_type type; 31 + }; 32 + 33 + extern const struct ipmi_match_info ipmi_kcs_si_info; 34 + extern const struct ipmi_match_info ipmi_smic_si_info; 35 + extern const struct ipmi_match_info ipmi_bt_si_info; 36 + 29 37 enum ipmi_addr_space { 30 38 IPMI_IO_ADDR_SPACE, IPMI_MEM_ADDR_SPACE 31 39 }; ··· 72 64 void (*irq_cleanup)(struct si_sm_io *io); 73 65 74 66 u8 slave_addr; 75 - enum si_type si_type; 67 + const struct ipmi_match_info *si_info; 76 68 struct device *dev; 77 69 }; 78 70
+82 -36
drivers/char/ipmi/ipmi_si_intf.c
··· 73 73 /* 'invalid' to allow a firmware-specified interface to be disabled */ 74 74 const char *const si_to_str[] = { "invalid", "kcs", "smic", "bt", NULL }; 75 75 76 + const struct ipmi_match_info ipmi_kcs_si_info = { .type = SI_KCS }; 77 + const struct ipmi_match_info ipmi_smic_si_info = { .type = SI_SMIC }; 78 + const struct ipmi_match_info ipmi_bt_si_info = { .type = SI_BT }; 79 + 76 80 static bool initialized; 77 81 78 82 /* ··· 696 692 break; 697 693 } 698 694 enables = current_global_enables(smi_info, 0, &irq_on); 699 - if (smi_info->io.si_type == SI_BT) 695 + if (smi_info->io.si_info->type == SI_BT) 700 696 /* BT has its own interrupt enable bit. */ 701 697 check_bt_irq(smi_info, irq_on); 702 698 if (enables != (msg[3] & GLOBAL_ENABLES_MASK)) { ··· 1123 1119 struct smi_info *smi_info = data; 1124 1120 unsigned long flags; 1125 1121 1126 - if (smi_info->io.si_type == SI_BT) 1122 + if (smi_info->io.si_info->type == SI_BT) 1127 1123 /* We need to clear the IRQ flag for the BT interface. */ 1128 1124 smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG, 1129 1125 IPMI_BT_INTMASK_CLEAR_IRQ_BIT ··· 1168 1164 * The BT interface is efficient enough to not need a thread, 1169 1165 * and there is no need for a thread if we have interrupts. 1170 1166 */ 1171 - else if ((new_smi->io.si_type != SI_BT) && (!new_smi->io.irq)) 1167 + else if (new_smi->io.si_info->type != SI_BT && !new_smi->io.irq) 1172 1168 enable = 1; 1173 1169 1174 1170 if (enable) { ··· 1239 1235 1240 1236 void ipmi_irq_finish_setup(struct si_sm_io *io) 1241 1237 { 1242 - if (io->si_type == SI_BT) 1238 + if (io->si_info->type == SI_BT) 1243 1239 /* Enable the interrupt in the BT interface. */ 1244 1240 io->outputb(io, IPMI_BT_INTMASK_REG, 1245 1241 IPMI_BT_INTMASK_ENABLE_IRQ_BIT); ··· 1247 1243 1248 1244 void ipmi_irq_start_cleanup(struct si_sm_io *io) 1249 1245 { 1250 - if (io->si_type == SI_BT) 1246 + if (io->si_info->type == SI_BT) 1251 1247 /* Disable the interrupt in the BT interface. */ 1252 1248 io->outputb(io, IPMI_BT_INTMASK_REG, 0); 1253 1249 } ··· 1618 1614 { 1619 1615 struct smi_info *smi_info = dev_get_drvdata(dev); 1620 1616 1621 - return sysfs_emit(buf, "%s\n", si_to_str[smi_info->io.si_type]); 1617 + return sysfs_emit(buf, "%s\n", si_to_str[smi_info->io.si_info->type]); 1622 1618 } 1623 1619 static DEVICE_ATTR_RO(type); 1624 1620 ··· 1653 1649 1654 1650 return sysfs_emit(buf, 1655 1651 "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n", 1656 - si_to_str[smi_info->io.si_type], 1652 + si_to_str[smi_info->io.si_info->type], 1657 1653 addr_space_to_str[smi_info->io.addr_space], 1658 1654 smi_info->io.addr_data, 1659 1655 smi_info->io.regspacing, ··· 1807 1803 { 1808 1804 struct ipmi_device_id *id = &smi_info->device_id; 1809 1805 if (id->manufacturer_id == DELL_IANA_MFR_ID && 1810 - smi_info->io.si_type == SI_BT) 1806 + smi_info->io.si_info->type == SI_BT) 1811 1807 register_xaction_notifier(&dell_poweredge_bt_xaction_notifier); 1812 1808 } 1813 1809 ··· 1911 1907 /* We prefer ACPI over SMBIOS. */ 1912 1908 dev_info(dup->io.dev, 1913 1909 "Removing SMBIOS-specified %s state machine in favor of ACPI\n", 1914 - si_to_str[new_smi->io.si_type]); 1910 + si_to_str[new_smi->io.si_info->type]); 1915 1911 cleanup_one_si(dup); 1916 1912 } else { 1917 1913 dev_info(new_smi->io.dev, 1918 1914 "%s-specified %s state machine: duplicate\n", 1919 1915 ipmi_addr_src_to_str(new_smi->io.addr_source), 1920 - si_to_str[new_smi->io.si_type]); 1916 + si_to_str[new_smi->io.si_info->type]); 1921 1917 rv = -EBUSY; 1922 1918 kfree(new_smi); 1923 1919 goto out_err; ··· 1926 1922 1927 1923 pr_info("Adding %s-specified %s state machine\n", 1928 1924 ipmi_addr_src_to_str(new_smi->io.addr_source), 1929 - si_to_str[new_smi->io.si_type]); 1925 + si_to_str[new_smi->io.si_info->type]); 1930 1926 1931 1927 list_add_tail(&new_smi->link, &smi_infos); 1932 1928 ··· 1949 1945 1950 1946 pr_info("Trying %s-specified %s state machine at %s address 0x%lx, slave address 0x%x, irq %d\n", 1951 1947 ipmi_addr_src_to_str(new_smi->io.addr_source), 1952 - si_to_str[new_smi->io.si_type], 1948 + si_to_str[new_smi->io.si_info->type], 1953 1949 addr_space_to_str[new_smi->io.addr_space], 1954 1950 new_smi->io.addr_data, 1955 1951 new_smi->io.slave_addr, new_smi->io.irq); 1956 1952 1957 - switch (new_smi->io.si_type) { 1953 + switch (new_smi->io.si_info->type) { 1958 1954 case SI_KCS: 1959 1955 new_smi->handlers = &kcs_smi_handlers; 1960 1956 break; ··· 2077 2073 smi_num++; 2078 2074 2079 2075 dev_info(new_smi->io.dev, "IPMI %s interface initialized\n", 2080 - si_to_str[new_smi->io.si_type]); 2076 + si_to_str[new_smi->io.si_info->type]); 2081 2077 2082 2078 WARN_ON(new_smi->io.dev->init_name != NULL); 2083 2079 ··· 2095 2091 return rv; 2096 2092 } 2097 2093 2094 + /* 2095 + * Devices in the same address space at the same address are the same. 2096 + */ 2097 + static bool __init ipmi_smi_info_same(struct smi_info *e1, struct smi_info *e2) 2098 + { 2099 + return (e1->io.addr_space == e2->io.addr_space && 2100 + e1->io.addr_data == e2->io.addr_data); 2101 + } 2102 + 2098 2103 static int __init init_ipmi_si(void) 2099 2104 { 2100 - struct smi_info *e; 2105 + struct smi_info *e, *e2; 2101 2106 enum ipmi_addr_src type = SI_INVALID; 2102 2107 2103 2108 if (initialized) ··· 2122 2109 2123 2110 ipmi_si_parisc_init(); 2124 2111 2125 - /* We prefer devices with interrupts, but in the case of a machine 2126 - with multiple BMCs we assume that there will be several instances 2127 - of a given type so if we succeed in registering a type then also 2128 - try to register everything else of the same type */ 2129 2112 mutex_lock(&smi_infos_lock); 2113 + 2114 + /* 2115 + * Scan through all the devices. We prefer devices with 2116 + * interrupts, so go through those first in case there are any 2117 + * duplicates that don't have the interrupt set. 2118 + */ 2130 2119 list_for_each_entry(e, &smi_infos, link) { 2131 - /* Try to register a device if it has an IRQ and we either 2132 - haven't successfully registered a device yet or this 2133 - device has the same type as one we successfully registered */ 2134 - if (e->io.irq && (!type || e->io.addr_source == type)) { 2135 - if (!try_smi_init(e)) { 2136 - type = e->io.addr_source; 2120 + bool dup = false; 2121 + 2122 + /* Register ones with interrupts first. */ 2123 + if (!e->io.irq) 2124 + continue; 2125 + 2126 + /* 2127 + * Go through the ones we have already seen to see if this 2128 + * is a dup. 2129 + */ 2130 + list_for_each_entry(e2, &smi_infos, link) { 2131 + if (e2 == e) 2132 + break; 2133 + if (e2->io.irq && ipmi_smi_info_same(e, e2)) { 2134 + dup = true; 2135 + break; 2137 2136 } 2138 2137 } 2138 + if (!dup) 2139 + try_smi_init(e); 2139 2140 } 2140 2141 2141 - /* type will only have been set if we successfully registered an si */ 2142 - if (type) 2143 - goto skip_fallback_noirq; 2144 - 2145 - /* Fall back to the preferred device */ 2146 - 2142 + /* 2143 + * Now try devices without interrupts. 2144 + */ 2147 2145 list_for_each_entry(e, &smi_infos, link) { 2148 - if (!e->io.irq && (!type || e->io.addr_source == type)) { 2149 - if (!try_smi_init(e)) { 2150 - type = e->io.addr_source; 2146 + bool dup = false; 2147 + 2148 + if (e->io.irq) 2149 + continue; 2150 + 2151 + /* 2152 + * Go through the ones we have already seen to see if 2153 + * this is a dup. We have already looked at the ones 2154 + * with interrupts. 2155 + */ 2156 + list_for_each_entry(e2, &smi_infos, link) { 2157 + if (!e2->io.irq) 2158 + continue; 2159 + if (ipmi_smi_info_same(e, e2)) { 2160 + dup = true; 2161 + break; 2151 2162 } 2152 2163 } 2164 + list_for_each_entry(e2, &smi_infos, link) { 2165 + if (e2 == e) 2166 + break; 2167 + if (ipmi_smi_info_same(e, e2)) { 2168 + dup = true; 2169 + break; 2170 + } 2171 + } 2172 + if (!dup) 2173 + try_smi_init(e); 2153 2174 } 2154 2175 2155 - skip_fallback_noirq: 2156 2176 initialized = true; 2157 2177 mutex_unlock(&smi_infos_lock); 2158 2178 ··· 2313 2267 list_for_each_entry_safe(e, tmp_e, &smi_infos, link) { 2314 2268 if (e->io.addr_space != addr_space) 2315 2269 continue; 2316 - if (e->io.si_type != si_type) 2270 + if (e->io.si_info->type != si_type) 2317 2271 continue; 2318 2272 if (e->io.addr_data == addr) { 2319 2273 dev = get_device(e->io.dev);
+1 -1
drivers/char/ipmi/ipmi_si_parisc.c
··· 13 13 14 14 memset(&io, 0, sizeof(io)); 15 15 16 - io.si_type = SI_KCS; 16 + io.si_info = &ipmi_kcs_si_info; 17 17 io.addr_source = SI_DEVICETREE; 18 18 io.addr_space = IPMI_MEM_ADDR_SPACE; 19 19 io.addr_data = dev->hpa.start;
+25 -23
drivers/char/ipmi/ipmi_si_pci.c
··· 23 23 24 24 static int ipmi_pci_probe_regspacing(struct si_sm_io *io) 25 25 { 26 - if (io->si_type == SI_KCS) { 27 - unsigned char status; 28 - int regspacing; 26 + unsigned char status; 27 + int regspacing; 29 28 30 - io->regsize = DEFAULT_REGSIZE; 31 - io->regshift = 0; 29 + if (io->si_info->type != SI_KCS) 30 + return DEFAULT_REGSPACING; 32 31 33 - /* detect 1, 4, 16byte spacing */ 34 - for (regspacing = DEFAULT_REGSPACING; regspacing <= 16;) { 35 - io->regspacing = regspacing; 36 - if (io->io_setup(io)) { 37 - dev_err(io->dev, "Could not setup I/O space\n"); 38 - return DEFAULT_REGSPACING; 39 - } 40 - /* write invalid cmd */ 41 - io->outputb(io, 1, 0x10); 42 - /* read status back */ 43 - status = io->inputb(io, 1); 44 - io->io_cleanup(io); 45 - if (status) 46 - return regspacing; 47 - regspacing *= 4; 32 + io->regsize = DEFAULT_REGSIZE; 33 + io->regshift = 0; 34 + 35 + /* detect 1, 4, 16byte spacing */ 36 + for (regspacing = DEFAULT_REGSPACING; regspacing <= 16;) { 37 + io->regspacing = regspacing; 38 + if (io->io_setup(io)) { 39 + dev_err(io->dev, "Could not setup I/O space\n"); 40 + return DEFAULT_REGSPACING; 48 41 } 42 + /* write invalid cmd */ 43 + io->outputb(io, 1, 0x10); 44 + /* read status back */ 45 + status = io->inputb(io, 1); 46 + io->io_cleanup(io); 47 + if (status) 48 + return regspacing; 49 + regspacing *= 4; 49 50 } 51 + 50 52 return DEFAULT_REGSPACING; 51 53 } 52 54 ··· 76 74 77 75 switch (pdev->class) { 78 76 case PCI_CLASS_SERIAL_IPMI_SMIC: 79 - io.si_type = SI_SMIC; 77 + io.si_info = &ipmi_smic_si_info; 80 78 break; 81 79 82 80 case PCI_CLASS_SERIAL_IPMI_KCS: 83 - io.si_type = SI_KCS; 81 + io.si_info = &ipmi_kcs_si_info; 84 82 break; 85 83 86 84 case PCI_CLASS_SERIAL_IPMI_BT: 87 - io.si_type = SI_BT; 85 + io.si_info = &ipmi_bt_si_info; 88 86 break; 89 87 90 88 default:
+14 -13
drivers/char/ipmi/ipmi_si_platform.c
··· 163 163 164 164 switch (type) { 165 165 case SI_KCS: 166 + io.si_info = &ipmi_kcs_si_info; 167 + break; 166 168 case SI_SMIC: 169 + io.si_info = &ipmi_smic_si_info; 170 + break; 167 171 case SI_BT: 168 - io.si_type = type; 172 + io.si_info = &ipmi_bt_si_info; 169 173 break; 170 174 case SI_TYPE_INVALID: /* User disabled this in hardcode. */ 171 175 return -ENODEV; ··· 217 213 218 214 #ifdef CONFIG_OF 219 215 static const struct of_device_id of_ipmi_match[] = { 220 - { .type = "ipmi", .compatible = "ipmi-kcs", 221 - .data = (void *)(unsigned long) SI_KCS }, 222 - { .type = "ipmi", .compatible = "ipmi-smic", 223 - .data = (void *)(unsigned long) SI_SMIC }, 224 - { .type = "ipmi", .compatible = "ipmi-bt", 225 - .data = (void *)(unsigned long) SI_BT }, 226 - {}, 216 + { .type = "ipmi", .compatible = "ipmi-kcs", .data = &ipmi_kcs_si_info }, 217 + { .type = "ipmi", .compatible = "ipmi-smic", .data = &ipmi_smic_si_info }, 218 + { .type = "ipmi", .compatible = "ipmi-bt", .data = &ipmi_bt_si_info }, 219 + {} 227 220 }; 228 221 MODULE_DEVICE_TABLE(of, of_ipmi_match); 229 222 ··· 266 265 } 267 266 268 267 memset(&io, 0, sizeof(io)); 269 - io.si_type = (enum si_type)device_get_match_data(&pdev->dev); 268 + io.si_info = device_get_match_data(&pdev->dev); 270 269 io.addr_source = SI_DEVICETREE; 271 270 io.irq_setup = ipmi_std_irq_setup; 272 271 ··· 297 296 { 298 297 #ifdef CONFIG_IPMI_DMI_DECODE 299 298 if (!slave_addr) 300 - slave_addr = ipmi_dmi_get_slave_addr(io->si_type, 299 + slave_addr = ipmi_dmi_get_slave_addr(io->si_info->type, 301 300 io->addr_space, 302 301 io->addr_data); 303 302 #endif ··· 336 335 337 336 switch (tmp) { 338 337 case 1: 339 - io.si_type = SI_KCS; 338 + io.si_info = &ipmi_kcs_si_info; 340 339 break; 341 340 case 2: 342 - io.si_type = SI_SMIC; 341 + io.si_info = &ipmi_smic_si_info; 343 342 break; 344 343 case 3: 345 - io.si_type = SI_BT; 344 + io.si_info = &ipmi_bt_si_info; 346 345 break; 347 346 case 4: /* SSIF, just ignore */ 348 347 return -ENODEV;
+1 -5
drivers/char/ipmi/ipmi_ssif.c
··· 481 481 /* Wait for something to do */ 482 482 result = wait_for_completion_interruptible( 483 483 &ssif_info->wake_thread); 484 - if (ssif_info->stopping) 485 - break; 486 484 if (result == -ERESTARTSYS) 487 485 continue; 488 486 init_completion(&ssif_info->wake_thread); ··· 1268 1270 ssif_info->stopping = true; 1269 1271 timer_delete_sync(&ssif_info->watch_timer); 1270 1272 timer_delete_sync(&ssif_info->retry_timer); 1271 - if (ssif_info->thread) { 1272 - complete(&ssif_info->wake_thread); 1273 + if (ssif_info->thread) 1273 1274 kthread_stop(ssif_info->thread); 1274 - } 1275 1275 } 1276 1276 1277 1277 static void ssif_remove(struct i2c_client *client)
+26 -66
drivers/char/ipmi/ipmi_watchdog.c
··· 150 150 static unsigned char preop_val = WDOG_PREOP_NONE; 151 151 152 152 static char preop[16] = "preop_none"; 153 - static DEFINE_SPINLOCK(ipmi_read_lock); 153 + static DEFINE_MUTEX(ipmi_read_mutex); 154 154 static char data_to_read; 155 155 static DECLARE_WAIT_QUEUE_HEAD(read_q); 156 156 static struct fasync_struct *fasync_q; ··· 363 363 { 364 364 struct kernel_ipmi_msg msg; 365 365 unsigned char data[6]; 366 - int rv; 366 + int rv = 0; 367 367 struct ipmi_system_interface_addr addr; 368 368 int hbnow = 0; 369 369 ··· 405 405 msg.cmd = IPMI_WDOG_SET_TIMER; 406 406 msg.data = data; 407 407 msg.data_len = sizeof(data); 408 - rv = ipmi_request_supply_msgs(watchdog_user, 409 - (struct ipmi_addr *) &addr, 410 - 0, 411 - &msg, 412 - NULL, 413 - smi_msg, 414 - recv_msg, 415 - 1); 408 + if (smi_msg) 409 + rv = ipmi_request_supply_msgs(watchdog_user, 410 + (struct ipmi_addr *) &addr, 411 + 0, 412 + &msg, 413 + NULL, 414 + smi_msg, 415 + recv_msg, 416 + 1); 417 + else 418 + ipmi_panic_request_and_wait(watchdog_user, 419 + (struct ipmi_addr *) &addr, &msg); 416 420 if (rv) 417 421 pr_warn("set timeout error: %d\n", rv); 418 422 else if (send_heartbeat_now) ··· 435 431 436 432 atomic_set(&msg_tofree, 2); 437 433 438 - rv = __ipmi_set_timeout(&smi_msg, 439 - &recv_msg, 440 - &send_heartbeat_now); 434 + rv = __ipmi_set_timeout(&smi_msg, &recv_msg, &send_heartbeat_now); 441 435 if (rv) { 442 436 atomic_set(&msg_tofree, 0); 443 437 return rv; ··· 462 460 return rv; 463 461 } 464 462 465 - static atomic_t panic_done_count = ATOMIC_INIT(0); 466 - 467 - static void panic_smi_free(struct ipmi_smi_msg *msg) 468 - { 469 - atomic_dec(&panic_done_count); 470 - } 471 - static void panic_recv_free(struct ipmi_recv_msg *msg) 472 - { 473 - atomic_dec(&panic_done_count); 474 - } 475 - 476 - static struct ipmi_smi_msg panic_halt_heartbeat_smi_msg = 477 - INIT_IPMI_SMI_MSG(panic_smi_free); 478 - static struct ipmi_recv_msg panic_halt_heartbeat_recv_msg = 479 - INIT_IPMI_RECV_MSG(panic_recv_free); 480 - 481 463 static void panic_halt_ipmi_heartbeat(void) 482 464 { 483 465 struct kernel_ipmi_msg msg; 484 466 struct ipmi_system_interface_addr addr; 485 - int rv; 486 467 487 468 /* 488 469 * Don't reset the timer if we have the timer turned off, that ··· 482 497 msg.cmd = IPMI_WDOG_RESET_TIMER; 483 498 msg.data = NULL; 484 499 msg.data_len = 0; 485 - atomic_add(2, &panic_done_count); 486 - rv = ipmi_request_supply_msgs(watchdog_user, 487 - (struct ipmi_addr *) &addr, 488 - 0, 489 - &msg, 490 - NULL, 491 - &panic_halt_heartbeat_smi_msg, 492 - &panic_halt_heartbeat_recv_msg, 493 - 1); 494 - if (rv) 495 - atomic_sub(2, &panic_done_count); 500 + ipmi_panic_request_and_wait(watchdog_user, (struct ipmi_addr *) &addr, 501 + &msg); 496 502 } 497 - 498 - static struct ipmi_smi_msg panic_halt_smi_msg = 499 - INIT_IPMI_SMI_MSG(panic_smi_free); 500 - static struct ipmi_recv_msg panic_halt_recv_msg = 501 - INIT_IPMI_RECV_MSG(panic_recv_free); 502 503 503 504 /* 504 505 * Special call, doesn't claim any locks. This is only to be called ··· 497 526 int send_heartbeat_now; 498 527 int rv; 499 528 500 - /* Wait for the messages to be free. */ 501 - while (atomic_read(&panic_done_count) != 0) 502 - ipmi_poll_interface(watchdog_user); 503 - atomic_add(2, &panic_done_count); 504 - rv = __ipmi_set_timeout(&panic_halt_smi_msg, 505 - &panic_halt_recv_msg, 506 - &send_heartbeat_now); 529 + rv = __ipmi_set_timeout(NULL, NULL, &send_heartbeat_now); 507 530 if (rv) { 508 - atomic_sub(2, &panic_done_count); 509 531 pr_warn("Unable to extend the watchdog timeout\n"); 510 532 } else { 511 533 if (send_heartbeat_now) 512 534 panic_halt_ipmi_heartbeat(); 513 535 } 514 - while (atomic_read(&panic_done_count) != 0) 515 - ipmi_poll_interface(watchdog_user); 516 536 } 517 537 518 538 static int __ipmi_heartbeat(void) ··· 755 793 * Reading returns if the pretimeout has gone off, and it only does 756 794 * it once per pretimeout. 757 795 */ 758 - spin_lock_irq(&ipmi_read_lock); 796 + mutex_lock(&ipmi_read_mutex); 759 797 if (!data_to_read) { 760 798 if (file->f_flags & O_NONBLOCK) { 761 799 rv = -EAGAIN; ··· 766 804 add_wait_queue(&read_q, &wait); 767 805 while (!data_to_read && !signal_pending(current)) { 768 806 set_current_state(TASK_INTERRUPTIBLE); 769 - spin_unlock_irq(&ipmi_read_lock); 807 + mutex_unlock(&ipmi_read_mutex); 770 808 schedule(); 771 - spin_lock_irq(&ipmi_read_lock); 809 + mutex_lock(&ipmi_read_mutex); 772 810 } 773 811 remove_wait_queue(&read_q, &wait); 774 812 ··· 780 818 data_to_read = 0; 781 819 782 820 out: 783 - spin_unlock_irq(&ipmi_read_lock); 821 + mutex_unlock(&ipmi_read_mutex); 784 822 785 823 if (rv == 0) { 786 824 if (copy_to_user(buf, &data_to_read, 1)) ··· 818 856 819 857 poll_wait(file, &read_q, wait); 820 858 821 - spin_lock_irq(&ipmi_read_lock); 859 + mutex_lock(&ipmi_read_mutex); 822 860 if (data_to_read) 823 861 mask |= (EPOLLIN | EPOLLRDNORM); 824 - spin_unlock_irq(&ipmi_read_lock); 862 + mutex_unlock(&ipmi_read_mutex); 825 863 826 864 return mask; 827 865 } ··· 894 932 if (atomic_inc_and_test(&preop_panic_excl)) 895 933 panic("Watchdog pre-timeout"); 896 934 } else if (preop_val == WDOG_PREOP_GIVE_DATA) { 897 - unsigned long flags; 898 - 899 - spin_lock_irqsave(&ipmi_read_lock, flags); 935 + mutex_lock(&ipmi_read_mutex); 900 936 data_to_read = 1; 901 937 wake_up_interruptible(&read_q); 902 938 kill_fasync(&fasync_q, SIGIO, POLL_IN); 903 - spin_unlock_irqrestore(&ipmi_read_lock, flags); 939 + mutex_unlock(&ipmi_read_mutex); 904 940 } 905 941 } 906 942
+12 -1
include/linux/ipmi.h
··· 93 93 94 94 /* 95 95 * Called when the interface detects a watchdog pre-timeout. If 96 - * this is NULL, it will be ignored for the user. 96 + * this is NULL, it will be ignored for the user. Note that you 97 + * can't do any IPMI calls from here, it's called with locks held. 97 98 */ 98 99 void (*ipmi_watchdog_pretimeout)(void *handler_data); 99 100 ··· 343 342 344 343 /* Helper function for computing the IPMB checksum of some data. */ 345 344 unsigned char ipmb_checksum(unsigned char *data, int size); 345 + 346 + /* 347 + * For things that must send messages at panic time, like the IPMI watchdog 348 + * driver that extends the reset time on a panic, use this to send messages 349 + * from panic context. Note that this puts the driver into a mode that 350 + * only works at panic time, so only use it then. 351 + */ 352 + void ipmi_panic_request_and_wait(struct ipmi_user *user, 353 + struct ipmi_addr *addr, 354 + struct kernel_ipmi_msg *msg); 346 355 347 356 #endif /* __LINUX_IPMI_H */