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