History

liveupdate: protect FLB lists with luo_register_rwlock

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.

Pasha Tatashin committed 7 months ago

Commit 6b2b22f1 parent 9e1e1852 files · +15 −0Browse files

Unified · Split

2 files
  1. include/linux/liveupdate.h +1 −0
  2. kernel/liveupdate/luo_flb.c +14 −0
include/linux/liveupdate.h+1−0
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <linux/kho/abi/luo.h>
1313 #include <linux/list.h>
1414 #include <linux/mutex.h>
15+#include <linux/rwsem.h>
1516 #include <linux/types.h>
1617 #include <uapi/linux/liveupdate.h>
1718
kernel/liveupdate/luo_flb.c+14−0
@@ -245,17 +245,20 @@ int luo_flb_file_preserve(struct liveupdate_file_handler *fh) · 244 unmodified lines
245245 struct luo_flb_link *iter;
246246 int err = 0;
247247
248+ down_read(&luo_register_rwlock);
248249 list_for_each_entry(iter, flb_list, list) {
249250 err = luo_flb_file_preserve_one(iter->flb);
250251 if (err)
251252 goto exit_err;
252253 }
254+ up_read(&luo_register_rwlock);
253255
254256 return 0;
255257
256258 exit_err:
257259 list_for_each_entry_continue_reverse(iter, flb_list, list)
258260 luo_flb_file_unpreserve_one(iter->flb);
261+ up_read(&luo_register_rwlock);
259262
260263 return err;
261264 }
@@ -277,6 +280,7 @@ void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh) · 15 unmodified lines
277280 struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list);
278281 struct luo_flb_link *iter;
279282
283+ guard(rwsem_read)(&luo_register_rwlock);
280284 list_for_each_entry_reverse(iter, flb_list, list)
281285 luo_flb_file_unpreserve_one(iter->flb);
282286 }
@@ -297,6 +301,7 @@ void luo_flb_file_finish(struct liveupdate_file_handler *fh) · 14 unmodified lines
297301 struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list);
298302 struct luo_flb_link *iter;
299303
304+ guard(rwsem_read)(&luo_register_rwlock);
300305 list_for_each_entry_reverse(iter, flb_list, list)
301306 luo_flb_file_finish_one(iter->flb);
302307 }
@@ -360,6 +365,8 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh, · 57 unmodified lines
360365 if (!luo_session_quiesce())
361366 return -EBUSY;
362367
368+ down_write(&luo_register_rwlock);
369+
363370 /* Check that this FLB is not already linked to this file handler */
364371 err = -EEXIST;
365372 list_for_each_entry(iter, flb_list, list) {
@@ -401,11 +408,13 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh, · 35 unmodified lines
401408 private->users++;
402409 link->flb = flb;
403410 list_add_tail(&no_free_ptr(link)->list, flb_list);
411+ up_write(&luo_register_rwlock);
404412 luo_session_resume();
405413
406414 return 0;
407415
408416 err_resume:
417+ up_write(&luo_register_rwlock);
409418 luo_session_resume();
410419 return err;
411420 }
@@ -449,6 +458,8 @@ int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, · 37 unmodified lines
449458 if (!luo_session_quiesce())
450459 return -EBUSY;
451460
461+ down_write(&luo_register_rwlock);
462+
452463 /* Find and remove the link from the file handler's list */
453464 list_for_each_entry(iter, flb_list, list) {
454465 if (iter->flb == flb) {
@@ -473,11 +484,13 @@ int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, · 18 unmodified lines
473484 module_put(flb->ops->owner);
474485 }
475486
487+ up_write(&luo_register_rwlock);
476488 luo_session_resume();
477489
478490 return 0;
479491
480492 err_resume:
493+ up_write(&luo_register_rwlock);
481494 luo_session_resume();
482495 return err;
483496 }
@@ -643,6 +656,7 @@ void luo_flb_serialize(void) · 159 unmodified lines
643656 struct liveupdate_flb *gflb;
644657 int i = 0;
645658
659+ guard(rwsem_read)(&luo_register_rwlock);
646660 list_private_for_each_entry(gflb, &luo_flb_global.list, private.list) {
647661 struct luo_flb_private *private = luo_flb_get_private(gflb);
648662

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t