Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A439DC64EC4 for ; Tue, 7 Mar 2023 02:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbjCGCMQ (ORCPT ); Mon, 6 Mar 2023 21:12:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229922AbjCGCMO (ORCPT ); Mon, 6 Mar 2023 21:12:14 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1D063A846 for ; Mon, 6 Mar 2023 18:12:12 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4PVzTz68WSz4f3jYq for ; Tue, 7 Mar 2023 10:12:07 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP4 (Coremail) with SMTP id gCh0CgCHOa12nQZks2uNEw--.20984S2; Tue, 07 Mar 2023 10:12:09 +0800 (CST) Subject: Re: dm crypt: initialize tasklet in crypt_io_init() To: Mike Snitzer Cc: dm-devel@redhat.com, Alasdair Kergon , Ignat Korchagin , linux-kernel@vger.kernel.org, houtao1@huawei.com References: <20230306134930.2878660-1-houtao@huaweicloud.com> From: Hou Tao Message-ID: Date: Tue, 7 Mar 2023 10:12:06 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-CM-TRANSID: gCh0CgCHOa12nQZks2uNEw--.20984S2 X-Coremail-Antispam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ected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 3/7/2023 3:31 AM, Mike Snitzer wrote: > On Mon, Mar 06 2023 at 8:49P -0500, > Hou Tao wrote: > >> From: Hou Tao >> >> When neither no_read_workqueue nor no_write_workqueue are enabled, >> tasklet_trylock() in crypt_dec_pending() may still return false due to >> an uninitialized state, and dm-crypt will do io completion in io_queue >> instead of current context unnecessarily. > Have you actually experienced this? Yes. I had written a bpftrace script to check the completion context of blkdev_bio_end_io_simple() when doing direct io read on dm-crypt device. The expected context should be unbound workers of crypt_queue, but sometimes the context is the bound worker of io_queue. > >> Fix it by initializing io->tasklet in crypt_io_init(). > Really would rather avoid always calling tasklet_init(). But I can > optimize it away with a later patch. My first though was "io->tasklet.state = 0", but it may be fragile because it operated on the internal status of tasklet, so I switch to tasklet_init(). > > Mike