Commit 1b7e0ca
bpf: Convert bpf_selem_unlink_map to failable
To prepare for changing bpf_local_storage_map_bucket::lock to rqspinlock,
convert bpf_selem_unlink_map() to failable. It still always succeeds and
returns 0 for now.
Since some operations updating local storage cannot fail in the middle,
open-code bpf_selem_unlink_map() to take the b->lock before the
operation. There are two such locations:
- bpf_local_storage_alloc()
The first selem will be unlinked from smap if cmpxchg owner_storage_ptr
fails, which should not fail. Therefore, hold b->lock when linking
until allocation complete. Helpers that assume b->lock is held by
callers are introduced: bpf_selem_link_map_nolock() and
bpf_selem_unlink_map_nolock().
- bpf_local_storage_update()
The three step update process: link_map(new_selem),
link_storage(new_selem), and unlink_map(old_selem) should not fail in
the middle.
In bpf_selem_unlink(), bpf_selem_unlink_map() and
bpf_selem_unlink_storage() should either all succeed or fail as a whole
instead of failing in the middle. So, return if unlink_map() failed.
Remove the selem_linked_to_map_lockless() check as an selem in the
common paths (not bpf_local_storage_map_free() or
bpf_local_storage_destroy()), will be unlinked under b->lock and
local_storage->lock and therefore no other threads can unlink the selem
from map at the same time.
In bpf_local_storage_destroy(), ignore the return of
bpf_selem_unlink_map() for now. A later patch will allow
bpf_local_storage_destroy() to unlink selems even when failing to
acquire locks.
Note that while this patch removes all callers of selem_linked_to_map(),
a later patch that introduces bpf_selem_unlink_nofail() will use it
again.
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20260205222916.1788211-3-ameryhung@gmail.com1 parent 0ccef70 commit 1b7e0ca
1 file changed
Lines changed: 39 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 64 | | |
70 | 65 | | |
71 | 66 | | |
| |||
347 | 342 | | |
348 | 343 | | |
349 | 344 | | |
350 | | - | |
| 345 | + | |
351 | 346 | | |
352 | 347 | | |
353 | 348 | | |
354 | 349 | | |
355 | 350 | | |
356 | 351 | | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | 352 | | |
362 | 353 | | |
363 | 354 | | |
364 | 355 | | |
365 | 356 | | |
366 | | - | |
367 | | - | |
| 357 | + | |
368 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
369 | 366 | | |
370 | 367 | | |
371 | 368 | | |
| |||
381 | 378 | | |
382 | 379 | | |
383 | 380 | | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
384 | 387 | | |
385 | 388 | | |
| 389 | + | |
| 390 | + | |
386 | 391 | | |
387 | 392 | | |
388 | 393 | | |
389 | 394 | | |
390 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
391 | 399 | | |
392 | 400 | | |
393 | 401 | | |
| |||
429 | 437 | | |
430 | 438 | | |
431 | 439 | | |
| 440 | + | |
| 441 | + | |
432 | 442 | | |
433 | 443 | | |
434 | 444 | | |
| |||
453 | 463 | | |
454 | 464 | | |
455 | 465 | | |
456 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
457 | 470 | | |
458 | 471 | | |
459 | 472 | | |
| |||
469 | 482 | | |
470 | 483 | | |
471 | 484 | | |
472 | | - | |
| 485 | + | |
| 486 | + | |
473 | 487 | | |
474 | 488 | | |
475 | 489 | | |
| 490 | + | |
476 | 491 | | |
477 | 492 | | |
478 | 493 | | |
| |||
494 | 509 | | |
495 | 510 | | |
496 | 511 | | |
| 512 | + | |
497 | 513 | | |
498 | | - | |
| 514 | + | |
499 | 515 | | |
500 | 516 | | |
501 | 517 | | |
| |||
579 | 595 | | |
580 | 596 | | |
581 | 597 | | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
582 | 602 | | |
583 | 603 | | |
584 | | - | |
| 604 | + | |
585 | 605 | | |
586 | 606 | | |
587 | 607 | | |
588 | 608 | | |
589 | 609 | | |
590 | 610 | | |
591 | | - | |
| 611 | + | |
592 | 612 | | |
593 | 613 | | |
594 | 614 | | |
595 | 615 | | |
| 616 | + | |
596 | 617 | | |
597 | 618 | | |
598 | 619 | | |
| |||
0 commit comments