diff mbox

dm-crypt: fix warning in shutdown path

Message ID 20180602174504.1847-1-kent.overstreet@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Kent Overstreet June 2, 2018, 5:45 p.m. UTC
The counter for the number of allocated pages includes pages in the
mempool's reserve, so checking that the number of allocated pages is 0
needs to happen after we exit the mempool.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
---
 drivers/md/dm-crypt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Krzysztof Kozlowski June 4, 2018, 9:31 a.m. UTC | #1
On Sat, Jun 2, 2018 at 10:10 PM, Jens Axboe <axboe@kernel.dk> wrote:
> On 6/2/18 2:07 PM, Mike Snitzer wrote:
>> On Sat, Jun 02 2018 at  4:03pm -0400,
>> Jens Axboe <axboe@kernel.dk> wrote:
>>
>>> On 6/2/18 11:45 AM, Kent Overstreet wrote:
>>>> The counter for the number of allocated pages includes pages in the
>>>> mempool's reserve, so checking that the number of allocated pages is 0
>>>> needs to happen after we exit the mempool.
>>>
>>> Looks good, but needs a fixes line. I'll add one.
>>
>> Also needs the subject and header updated to reflect that it fixes the
>> crash (Krzysztof please verify):
>>
>> Reported-by: Krzysztof Kozlowski <krzk@kernel.org>
>> Acked-by: Mike Snitzer <snitzer@redhat.com>
>
> Indeed, I have added that. Thanks Mike.

Thanks for adding tags!

This fixes reported issue:
Tested-by: Krzysztof Kozlowski <krzk@kernel.org>

Best regards,
Krzysztof

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index eaf6b279ac..9a000aa955 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -2221,14 +2221,14 @@  static void crypt_dtr(struct dm_target *ti)
 
 	bioset_exit(&cc->bs);
 
-	if (mempool_initialized(&cc->page_pool))
-		WARN_ON(percpu_counter_sum(&cc->n_allocated_pages) != 0);
-	percpu_counter_destroy(&cc->n_allocated_pages);
-
 	mempool_exit(&cc->page_pool);
 	mempool_exit(&cc->req_pool);
 	mempool_exit(&cc->tag_pool);
 
+	if (cc->n_allocated_pages.counters)
+		WARN_ON(percpu_counter_sum(&cc->n_allocated_pages) != 0);
+	percpu_counter_destroy(&cc->n_allocated_pages);
+
 	if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
 		cc->iv_gen_ops->dtr(cc);