As described in commit 02117b8ae9c0 ("f2fs: Set GF_NOFS in read_cache_page_gfp while doing f2fs_quota_read"), we must not enter filesystem reclaim while holding the dq_lock. Prevent this more generally by using memalloc_nofs_save() while holding the lock.
Unified · Split
| @@ -79,6 +79,7 @@ · 78 unmodified lines | ||
| 79 | 79 | #include <linux/capability.h> |
| 80 | 80 | #include <linux/quotaops.h> |
| 81 | 81 | #include <linux/blkdev.h> |
| 82 | +#include <linux/sched/mm.h> | |
| 82 | 83 | #include "../internal.h" /* ugh */ |
| 83 | 84 | |
| 84 | 85 | #include <linux/uaccess.h> |
| @@ -425,9 +426,11 @@ EXPORT_SYMBOL(mark_info_dirty); · 340 unmodified lines | ||
| 425 | 426 | int dquot_acquire(struct dquot *dquot) |
| 426 | 427 | { |
| 427 | 428 | int ret = 0, ret2 = 0; |
| 429 | + unsigned int memalloc; | |
| 428 | 430 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
| 429 | 431 | |
| 430 | 432 | mutex_lock(&dquot->dq_lock); |
| 433 | + memalloc = memalloc_nofs_save(); | |
| 431 | 434 | if (!test_bit(DQ_READ_B, &dquot->dq_flags)) { |
| 432 | 435 | ret = dqopt->ops[dquot->dq_id.type]->read_dqblk(dquot); |
| 433 | 436 | if (ret < 0) |
| @@ -458,6 +461,7 @@ int dquot_acquire(struct dquot *dquot) · 24 unmodified lines | ||
| 458 | 461 | smp_mb__before_atomic(); |
| 459 | 462 | set_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
| 460 | 463 | out_iolock: |
| 464 | + memalloc_nofs_restore(memalloc); | |
| 461 | 465 | mutex_unlock(&dquot->dq_lock); |
| 462 | 466 | return ret; |
| 463 | 467 | } |
| @@ -469,9 +473,11 @@ EXPORT_SYMBOL(dquot_acquire); · 5 unmodified lines | ||
| 469 | 473 | int dquot_commit(struct dquot *dquot) |
| 470 | 474 | { |
| 471 | 475 | int ret = 0; |
| 476 | + unsigned int memalloc; | |
| 472 | 477 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
| 473 | 478 | |
| 474 | 479 | mutex_lock(&dquot->dq_lock); |
| 480 | + memalloc = memalloc_nofs_save(); | |
| 475 | 481 | if (!clear_dquot_dirty(dquot)) |
| 476 | 482 | goto out_lock; |
| 477 | 483 | /* Inactive dquot can be only if there was error during read/init |
| @@ -481,6 +487,7 @@ int dquot_commit(struct dquot *dquot) · 3 unmodified lines | ||
| 481 | 487 | else |
| 482 | 488 | ret = -EIO; |
| 483 | 489 | out_lock: |
| 490 | + memalloc_nofs_restore(memalloc); | |
| 484 | 491 | mutex_unlock(&dquot->dq_lock); |
| 485 | 492 | return ret; |
| 486 | 493 | } |
| @@ -492,9 +499,11 @@ EXPORT_SYMBOL(dquot_commit); · 5 unmodified lines | ||
| 492 | 499 | int dquot_release(struct dquot *dquot) |
| 493 | 500 | { |
| 494 | 501 | int ret = 0, ret2 = 0; |
| 502 | + unsigned int memalloc; | |
| 495 | 503 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
| 496 | 504 | |
| 497 | 505 | mutex_lock(&dquot->dq_lock); |
| 506 | + memalloc = memalloc_nofs_save(); | |
| 498 | 507 | /* Check whether we are not racing with some other dqget() */ |
| 499 | 508 | if (dquot_is_busy(dquot)) |
| 500 | 509 | goto out_dqlock; |
| @@ -510,6 +519,7 @@ int dquot_release(struct dquot *dquot) · 9 unmodified lines | ||
| 510 | 519 | } |
| 511 | 520 | clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
| 512 | 521 | out_dqlock: |
| 522 | + memalloc_nofs_restore(memalloc); | |
| 513 | 523 | mutex_unlock(&dquot->dq_lock); |
| 514 | 524 | return ret; |
| 515 | 525 | } |