Because liveupdate FLB objects will soon drop their persistent module references when registered, list traversals must be protected against concurrent module unloading. To provide this protection, utilize the global luo_register_rwlock. It protects the global registry of FLBs and the handler's specific list of FLB dependencies. Read locks are used during concurrent list traversals (e.g., during preservation and serialization). Write locks are taken during registration and unregistration.
Unified · Split
| @@ -12,6 +12,7 @@ · 11 unmodified lines | |||
| 12 | #include <linux/kho/abi/luo.h> | 12 | #include <linux/kho/abi/luo.h> |
| 13 | #include <linux/list.h> | 13 | #include <linux/list.h> |
| 14 | #include <linux/mutex.h> | 14 | #include <linux/mutex.h> |
| 15 | #include <linux/rwsem.h> | ||
| 15 | #include <linux/types.h> | 16 | #include <linux/types.h> |
| 16 | #include <uapi/linux/liveupdate.h> | 17 | #include <uapi/linux/liveupdate.h> |
| 17 | 18 | ||
| @@ -245,17 +245,20 @@ int luo_flb_file_preserve(struct liveupdate_file_handler *fh) · 244 unmodified lines | |||
| 245 | struct luo_flb_link *iter; | 245 | struct luo_flb_link *iter; |
| 246 | int err = 0; | 246 | int err = 0; |
| 247 | 247 | ||
| 248 | down_read(&luo_register_rwlock); | ||
| 248 | list_for_each_entry(iter, flb_list, list) { | 249 | list_for_each_entry(iter, flb_list, list) { |
| 249 | err = luo_flb_file_preserve_one(iter->flb); | 250 | err = luo_flb_file_preserve_one(iter->flb); |
| 250 | if (err) | 251 | if (err) |
| 251 | goto exit_err; | 252 | goto exit_err; |
| 252 | } | 253 | } |
| 254 | up_read(&luo_register_rwlock); | ||
| 253 | 255 | ||
| 254 | return 0; | 256 | return 0; |
| 255 | 257 | ||
| 256 | exit_err: | 258 | exit_err: |
| 257 | list_for_each_entry_continue_reverse(iter, flb_list, list) | 259 | list_for_each_entry_continue_reverse(iter, flb_list, list) |
| 258 | luo_flb_file_unpreserve_one(iter->flb); | 260 | luo_flb_file_unpreserve_one(iter->flb); |
| 261 | up_read(&luo_register_rwlock); | ||
| 259 | 262 | ||
| 260 | return err; | 263 | return err; |
| 261 | } | 264 | } |
| @@ -277,6 +280,7 @@ void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh) · 15 unmodified lines | |||
| 277 | struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); | 280 | struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); |
| 278 | struct luo_flb_link *iter; | 281 | struct luo_flb_link *iter; |
| 279 | 282 | ||
| 283 | guard(rwsem_read)(&luo_register_rwlock); | ||
| 280 | list_for_each_entry_reverse(iter, flb_list, list) | 284 | list_for_each_entry_reverse(iter, flb_list, list) |
| 281 | luo_flb_file_unpreserve_one(iter->flb); | 285 | luo_flb_file_unpreserve_one(iter->flb); |
| 282 | } | 286 | } |
| @@ -297,6 +301,7 @@ void luo_flb_file_finish(struct liveupdate_file_handler *fh) · 14 unmodified lines | |||
| 297 | struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); | 301 | struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); |
| 298 | struct luo_flb_link *iter; | 302 | struct luo_flb_link *iter; |
| 299 | 303 | ||
| 304 | guard(rwsem_read)(&luo_register_rwlock); | ||
| 300 | list_for_each_entry_reverse(iter, flb_list, list) | 305 | list_for_each_entry_reverse(iter, flb_list, list) |
| 301 | luo_flb_file_finish_one(iter->flb); | 306 | luo_flb_file_finish_one(iter->flb); |
| 302 | } | 307 | } |
| @@ -360,6 +365,8 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh, · 57 unmodified lines | |||
| 360 | if (!luo_session_quiesce()) | 365 | if (!luo_session_quiesce()) |
| 361 | return -EBUSY; | 366 | return -EBUSY; |
| 362 | 367 | ||
| 368 | down_write(&luo_register_rwlock); | ||
| 369 | |||
| 363 | /* Check that this FLB is not already linked to this file handler */ | 370 | /* Check that this FLB is not already linked to this file handler */ |
| 364 | err = -EEXIST; | 371 | err = -EEXIST; |
| 365 | list_for_each_entry(iter, flb_list, list) { | 372 | list_for_each_entry(iter, flb_list, list) { |
| @@ -401,11 +408,13 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh, · 35 unmodified lines | |||
| 401 | private->users++; | 408 | private->users++; |
| 402 | link->flb = flb; | 409 | link->flb = flb; |
| 403 | list_add_tail(&no_free_ptr(link)->list, flb_list); | 410 | list_add_tail(&no_free_ptr(link)->list, flb_list); |
| 411 | up_write(&luo_register_rwlock); | ||
| 404 | luo_session_resume(); | 412 | luo_session_resume(); |
| 405 | 413 | ||
| 406 | return 0; | 414 | return 0; |
| 407 | 415 | ||
| 408 | err_resume: | 416 | err_resume: |
| 417 | up_write(&luo_register_rwlock); | ||
| 409 | luo_session_resume(); | 418 | luo_session_resume(); |
| 410 | return err; | 419 | return err; |
| 411 | } | 420 | } |
| @@ -449,6 +458,8 @@ int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, · 37 unmodified lines | |||
| 449 | if (!luo_session_quiesce()) | 458 | if (!luo_session_quiesce()) |
| 450 | return -EBUSY; | 459 | return -EBUSY; |
| 451 | 460 | ||
| 461 | down_write(&luo_register_rwlock); | ||
| 462 | |||
| 452 | /* Find and remove the link from the file handler's list */ | 463 | /* Find and remove the link from the file handler's list */ |
| 453 | list_for_each_entry(iter, flb_list, list) { | 464 | list_for_each_entry(iter, flb_list, list) { |
| 454 | if (iter->flb == flb) { | 465 | if (iter->flb == flb) { |
| @@ -473,11 +484,13 @@ int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, · 18 unmodified lines | |||
| 473 | module_put(flb->ops->owner); | 484 | module_put(flb->ops->owner); |
| 474 | } | 485 | } |
| 475 | 486 | ||
| 487 | up_write(&luo_register_rwlock); | ||
| 476 | luo_session_resume(); | 488 | luo_session_resume(); |
| 477 | 489 | ||
| 478 | return 0; | 490 | return 0; |
| 479 | 491 | ||
| 480 | err_resume: | 492 | err_resume: |
| 493 | up_write(&luo_register_rwlock); | ||
| 481 | luo_session_resume(); | 494 | luo_session_resume(); |
| 482 | return err; | 495 | return err; |
| 483 | } | 496 | } |
| @@ -643,6 +656,7 @@ void luo_flb_serialize(void) · 159 unmodified lines | |||
| 643 | struct liveupdate_flb *gflb; | 656 | struct liveupdate_flb *gflb; |
| 644 | int i = 0; | 657 | int i = 0; |
| 645 | 658 | ||
| 659 | guard(rwsem_read)(&luo_register_rwlock); | ||
| 646 | list_private_for_each_entry(gflb, &luo_flb_global.list, private.list) { | 660 | list_private_for_each_entry(gflb, &luo_flb_global.list, private.list) { |
| 647 | struct luo_flb_private *private = luo_flb_get_private(gflb); | 661 | struct luo_flb_private *private = luo_flb_get_private(gflb); |
| 648 | 662 | ||