dm integrity: use init_completion instead of COMPLETION_INITIALIZER_ONSTACK

The new lockdep support for completions causeed the stack usage
in dm-integrity to explode, in case of write_journal from 504 bytes
to 1120 (using arm gcc-7.1.1):

drivers/md/dm-integrity.c: In function 'write_journal':
drivers/md/dm-integrity.c:827:1: error: the frame size of 1120 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]

The problem is that not only the size of 'struct completion' grows
significantly, but we end up having multiple copies of it on the stack
when we assign it from a local variable after the initial declaration.

COMPLETION_INITIALIZER_ONSTACK() is the right thing to use when we
want to declare and initialize a completion on the stack. However,
this driver doesn't do that and instead initializes the completion
just before it is used.

In this case, init_completion() does the same thing more efficiently,
and drops the stack usage for the function above down to 496 bytes.
While the other functions in this file are not bad enough to cause
a warning, they benefit equally from the change, so I do the change
across the entire file. In the one place where we reuse a completion,
I picked the cheaper reinit_completion() over init_completion().

Fixes: cd8084f91c02 ("locking/lockdep: Apply crossrelease to completions")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Arnd Bergmann and committed by
Mike Snitzer
b5e8ad92 7c373d66

+10 -10
+10 -10
drivers/md/dm-integrity.c
··· 773 773 unsigned i; 774 774 775 775 io_comp.ic = ic; 776 - io_comp.comp = COMPLETION_INITIALIZER_ONSTACK(io_comp.comp); 776 + init_completion(&io_comp.comp); 777 777 778 778 if (commit_start + commit_sections <= ic->journal_sections) { 779 779 io_comp.in_flight = (atomic_t)ATOMIC_INIT(1); 780 780 if (ic->journal_io) { 781 781 crypt_comp_1.ic = ic; 782 - crypt_comp_1.comp = COMPLETION_INITIALIZER_ONSTACK(crypt_comp_1.comp); 782 + init_completion(&crypt_comp_1.comp); 783 783 crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0); 784 784 encrypt_journal(ic, true, commit_start, commit_sections, &crypt_comp_1); 785 785 wait_for_completion_io(&crypt_comp_1.comp); ··· 795 795 to_end = ic->journal_sections - commit_start; 796 796 if (ic->journal_io) { 797 797 crypt_comp_1.ic = ic; 798 - crypt_comp_1.comp = COMPLETION_INITIALIZER_ONSTACK(crypt_comp_1.comp); 798 + init_completion(&crypt_comp_1.comp); 799 799 crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0); 800 800 encrypt_journal(ic, true, commit_start, to_end, &crypt_comp_1); 801 801 if (try_wait_for_completion(&crypt_comp_1.comp)) { 802 802 rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp); 803 - crypt_comp_1.comp = COMPLETION_INITIALIZER_ONSTACK(crypt_comp_1.comp); 803 + reinit_completion(&crypt_comp_1.comp); 804 804 crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0); 805 805 encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_1); 806 806 wait_for_completion_io(&crypt_comp_1.comp); 807 807 } else { 808 808 crypt_comp_2.ic = ic; 809 - crypt_comp_2.comp = COMPLETION_INITIALIZER_ONSTACK(crypt_comp_2.comp); 809 + init_completion(&crypt_comp_2.comp); 810 810 crypt_comp_2.in_flight = (atomic_t)ATOMIC_INIT(0); 811 811 encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_2); 812 812 wait_for_completion_io(&crypt_comp_1.comp); ··· 1679 1679 dio->in_flight = (atomic_t)ATOMIC_INIT(2); 1680 1680 1681 1681 if (need_sync_io) { 1682 - read_comp = COMPLETION_INITIALIZER_ONSTACK(read_comp); 1682 + init_completion(&read_comp); 1683 1683 dio->completion = &read_comp; 1684 1684 } else 1685 1685 dio->completion = NULL; ··· 1840 1840 1841 1841 comp.ic = ic; 1842 1842 comp.in_flight = (atomic_t)ATOMIC_INIT(1); 1843 - comp.comp = COMPLETION_INITIALIZER_ONSTACK(comp.comp); 1843 + init_completion(&comp.comp); 1844 1844 1845 1845 i = write_start; 1846 1846 for (n = 0; n < write_sections; n++, i++, wraparound_section(ic, &i)) { ··· 2067 2067 if (ic->journal_io) { 2068 2068 struct journal_completion crypt_comp; 2069 2069 crypt_comp.ic = ic; 2070 - crypt_comp.comp = COMPLETION_INITIALIZER_ONSTACK(crypt_comp.comp); 2070 + init_completion(&crypt_comp.comp); 2071 2071 crypt_comp.in_flight = (atomic_t)ATOMIC_INIT(0); 2072 2072 encrypt_journal(ic, false, 0, ic->journal_sections, &crypt_comp); 2073 2073 wait_for_completion(&crypt_comp.comp); ··· 2640 2640 memset(iv, 0x00, ivsize); 2641 2641 2642 2642 skcipher_request_set_crypt(req, sg, sg, PAGE_SIZE * ic->journal_pages + sizeof ic->commit_ids, iv); 2643 - comp.comp = COMPLETION_INITIALIZER_ONSTACK(comp.comp); 2643 + init_completion(&comp.comp); 2644 2644 comp.in_flight = (atomic_t)ATOMIC_INIT(1); 2645 2645 if (do_crypt(true, req, &comp)) 2646 2646 wait_for_completion(&comp.comp); ··· 2697 2697 2698 2698 sg_init_one(&sg, crypt_data, crypt_len); 2699 2699 skcipher_request_set_crypt(req, &sg, &sg, crypt_len, iv); 2700 - comp.comp = COMPLETION_INITIALIZER_ONSTACK(comp.comp); 2700 + init_completion(&comp.comp); 2701 2701 comp.in_flight = (atomic_t)ATOMIC_INIT(1); 2702 2702 if (do_crypt(true, req, &comp)) 2703 2703 wait_for_completion(&comp.comp);