Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp11893605pxu; Fri, 1 Jan 2021 02:30:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHAJJlpfyctTNUVkXodur5vvD2baHGcInABhpPzAfz5L51FIpHGLV6XnaaO6TcT5L3GKIX X-Received: by 2002:a17:906:3712:: with SMTP id d18mr58381001ejc.178.1609497034262; Fri, 01 Jan 2021 02:30:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609497034; cv=none; d=google.com; s=arc-20160816; b=QAvEx8HJ2b+Pn3Q40Sm3hxKHDj1gOWqbQnWxX/ygm7G1L4RC0Qyt9taIEnYyPdYuHI m18sPPTjKaUQxFttwtDqdkPULxtynntXS9BqQTjVrzHaasqX4bejPtcKXXobtjmDC+uw a06v1M8vb37belGhkKVYJAhNNwUml8P23q9fzAKr8bjOZVrKnSRlqpy+cWaYGcJgRWX8 bjZwQ1C8QBStGNOW4rDayO7YRm2VuKxh4X35ZieHdsg9shW7Ev0IXm7UTnI0f08u+qxE /9fWU3oVO+IosAzAqKFDd8TSX8uicrCIm+X/BwUQk2kWOn28SdywFZCtWtWOzsMQHDj+ eesw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=k2vQ6iqC4CndNBeiIFLrfo2PMRh+mcqERP0ZLSMI0UU=; b=B2inhM48lXoq2wBJCS3Hic00JoCyp00u0jd12jFDI+lJJNt4fhdfbndvi+GwrhAM2d DUdGboxy9TvyF3KDm4L8hZKcPIRjrYWuR8gSgpUAUIodjAK8FSlKf8+ytRfBS3FUjg5j 82L9NF/gj3f4FthcPfajCktCuM2BCpnjgwYRoZfALrH9x/Dq89WVOKPZ3aqzhjag1rmt x+EERymVpmxlcqxFshzKvITeJGW1PoGMsXOgHv+hfTV8xodJTD3KIzpOAOSPA5oPs/Jq APTQ3FwbsP60MZJX5R0EtJVr2xVjOrvQv3KuubhpiZ5ctTk4/w6D2qBq5f/rDEyYm5aK BBtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=S2e0UyON; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si23644930eja.133.2021.01.01.02.29.50; Fri, 01 Jan 2021 02:30:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=S2e0UyON; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726798AbhAAK1o (ORCPT + 99 others); Fri, 1 Jan 2021 05:27:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726462AbhAAK1n (ORCPT ); Fri, 1 Jan 2021 05:27:43 -0500 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EA83C061573 for ; Fri, 1 Jan 2021 02:26:58 -0800 (PST) Received: by mail-il1-x136.google.com with SMTP id x15so19162398ilq.1 for ; Fri, 01 Jan 2021 02:26:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=k2vQ6iqC4CndNBeiIFLrfo2PMRh+mcqERP0ZLSMI0UU=; b=S2e0UyON57vBfV4TYhF3yPrS2nbggdWhKASDKkJyyZhZZrjDkAVKHQZ26oCiBGwSFX UDzTX28rWXZcodt0np0keMnUqzYQ17/DQTLTwwfR+nqTnbOIeJKrun6JulieBxrFKNb6 sijYwADkpBgOOo7LwIp5zStNDZK3l0kIytvlw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=k2vQ6iqC4CndNBeiIFLrfo2PMRh+mcqERP0ZLSMI0UU=; b=OG5MCQeYUuNExCDIMDF+WajxC418VIrtCdgnwej2Q7wT2lyHBu0Q40/ZI668udkjsA nKv39a9w4cAvfD597u89YHi2ZZ/hLn/PRr9CSzYxxmYmCdtnNI3YJ8Y879ebuPnVOyzN vHypbHiiwvdm2WZ5lzfRUinbDmUmKzy+JlPhCagtByEN5fQaLC+ES92Gz1St3nBd5GMk m/KVV5ZllFGn/8eIZotYvdPB7CzbFP5crCIXnpeyHHywi/VU4mB/evh4+1J4/ojLFO67 E+AxNA8e1We1e0vh2bl2bZpRUvhS/7YFPxK3bN/vHTpUyM9P0VzIB0YzLaKmnSNtwW+d 1O3A== X-Gm-Message-State: AOAM532uzpHxXO1oHvlXbjzmXuDhzJYl038MM0ejffp6c9pOqMX9YhEC JqyHCm96Cwa7k3oyviPSs7Ah2U/quHMhQ/joGS8C9g== X-Received: by 2002:a92:c990:: with SMTP id y16mr60036119iln.35.1609496817666; Fri, 01 Jan 2021 02:26:57 -0800 (PST) MIME-Version: 1.0 References: <20201230214520.154793-1-ignat@cloudflare.com> <20201230214520.154793-2-ignat@cloudflare.com> In-Reply-To: From: Ignat Korchagin Date: Fri, 1 Jan 2021 10:26:46 +0000 Message-ID: Subject: Re: [PATCH v2 1/2] dm crypt: use GFP_ATOMIC when allocating crypto requests from softirq To: Mikulas Patocka Cc: Alasdair G Kergon , Mike Snitzer , device-mapper development , dm-crypt@saout.de, linux-kernel , Eric Biggers , Damien Le Moal , Herbert Xu , kernel-team , Nobuto Murata , Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, "Maciej S. Szmigiero" , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 1, 2021 at 10:00 AM Mikulas Patocka wrote: > > > > On Wed, 30 Dec 2020, Ignat Korchagin wrote: > > > diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c > > index 53791138d78b..e4fd690c70e1 100644 > > --- a/drivers/md/dm-crypt.c > > +++ b/drivers/md/dm-crypt.c > > @@ -1539,7 +1549,10 @@ static blk_status_t crypt_convert(struct crypt_config *cc, > > > > while (ctx->iter_in.bi_size && ctx->iter_out.bi_size) { > > > > - crypt_alloc_req(cc, ctx); > > + r = crypt_alloc_req(cc, ctx); > > + if (r) > > + return BLK_STS_RESOURCE; > > + > > atomic_inc(&ctx->cc_pending); > > > > if (crypt_integrity_aead(cc)) > > -- > > 2.20.1 > > I'm not quite convinced that returning BLK_STS_RESOURCE will help. The > block layer will convert this value back to -ENOMEM and return it to the > caller, resulting in an I/O error. > > Note that GFP_ATOMIC allocations may fail anytime and you must handle > allocation failure gracefully - i.e. process the request without any > error. > > An acceptable solution would be to punt the request to a workqueue and do > GFP_NOIO allocation from the workqueue. Or add the request to some list > and process the list when some other request completes. We can do the workqueue, if that's the desired behaviour. The second patch from this patchset already adds the code for the request to be retried from the workqueue if crypt_convert returns BLK_STS_DEV_RESOURCE, so all is needed is to change returning BLK_STS_RESOURCE to BLK_STS_DEV_RESOURCE here. Does that sound reasonable? > You should write a test that simulates allocation failure and verify that > the kernel handles it gracefully without any I/O error. I already have the test for the second patch in the set, but will adapt it to make sure the allocation failure codepath is covered as well. > Mikulas >