Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5753226imm; Mon, 23 Jul 2018 05:36:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcf+fliarF1VMYITFUDbfe74c4XK8scBS3dIeHCItfp9GglesOmGHhvCAGEV+pfG/zwIWg8 X-Received: by 2002:a62:9f85:: with SMTP id v5-v6mr13094237pfk.27.1532349372747; Mon, 23 Jul 2018 05:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532349372; cv=none; d=google.com; s=arc-20160816; b=G/X9ePHLKYsONRxyl9QI6vjP/j1l8+gb5VsqSd50wZkH7d41T1FZkitGHN/bJwj+nw RqR3zmqRE4Nn4sCab0Cdh0p72MM+mNXl1hLFz9L7+iJBdCu/8XRWc9kcyxtvCGv3LE/r duE7pd9u6PiB013FHa5R3OfOJGIKQlKfKVTWmzZ2y2/jopOP+7FNSdYTrjmn2TiQM6/k SsbwF70EU56SYQo+ZZ2HQNtpiwFVcixbeR31kfdv2qwv/HjjBWJ0HwmUgRNkPCdcPsBP DUvPfu0cr7vb3hz1HhwpnfLLMl957niiUZywJEiVPvSq2rzMIBYLIFcc2MCFcgrkU1bS CrFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=z776lm0w39zY7xCEe96PNaj4EBCIua7DdREz0dSspxw=; b=PPp7S6AlqZT3m9k6PRQ/eoQ9saI2LN3x1uY8Q1vN+2OvJ0Ee+lXmE7Q+0gyxFRi0Jj ASBIBJy8lgWu+QF5caaueUYb8Cc6vCYIv2JWPaEy1LAPRHPW0zZkdNvMUNhZygAfLAe2 7DrXgjbdHnAFcHUieghq9QyEyMH5L9EQAvUnVOr2mZiA4XPw7jRjePcGLbbTXasYOAjp dgDh/Ui3L4QRdsfFX7QZuAuLvr1kP6F35Ax9doTJ3bl9pBQfcAK3FMH8+gzYkn0Qr6ZK E9c0tyhYyntjnWGsrcTPvd3J3q8hrVIdykPVBKSuBNhTQA8Y2gRZEOQP5UcFLAtmVQ2w RKhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g67-v6si8154154plb.73.2018.07.23.05.35.58; Mon, 23 Jul 2018 05:36:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389390AbeGWNb5 (ORCPT + 99 others); Mon, 23 Jul 2018 09:31:57 -0400 Received: from einhorn-mail.in-berlin.de ([217.197.80.20]:45291 "EHLO einhorn-mail.in-berlin.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388578AbeGWNb4 (ORCPT ); Mon, 23 Jul 2018 09:31:56 -0400 X-Greylist: delayed 367 seconds by postgrey-1.27 at vger.kernel.org; Mon, 23 Jul 2018 09:31:55 EDT X-Envelope-From: stefanr@s5r6.in-berlin.de Received: from authenticated.user (localhost [127.0.0.1]) by einhorn.in-berlin.de with ESMTP id w6NCOI4F004999 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Jul 2018 14:24:21 +0200 Date: Mon, 23 Jul 2018 14:24:18 +0200 From: Stefan Richter To: Jia-Ju Bai Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: Re: [PATCH] firewire: sbp2: Replace GFP_ATOMIC with GFP_KERNEL in sbp2_scsi_queuecommand() Message-ID: <20180723142418.4aef4910@kant> In-Reply-To: <20180723085801.6711-1-baijiaju1990@gmail.com> References: <20180723085801.6711-1-baijiaju1990@gmail.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding Cc: LSML On Jul 23 Jia-Ju Bai wrote: > sbp2_scsi_queuecommand() is only set to .queuecommand of > "struct scsi_host_template", and this function pointer is never called > in atomic context. As far as I remember, scsi_host_template::queuecommand() can be invoked from either process context or tasklet context, predominantly the latter. I haven't followed recent developments of the block and scsi stack, hence don't know if this has changed fundamentally. But even if it is purely process context now and no spinlocks held, the memory allocation must be done so that the kernel does not go into memory reclaim. Otherwise this could deadlock. > sbp2_scsi_queuecommand() calls kzalloc() with GFP_ATOMIC, > which is not necessary. > GFP_ATOMIC can be replaced with GFP_KERNEL. > > This is found by a static analysis tool named DCNS written by myself. I doubt that static analysis, even if very sophisticated, can detect deadlock scenarios such as I noted. > I also manually check the kernel code before reporting it. What does it mean? Did you run-time test it, for which actual SBP-2 hardware is required? (Such a test could detect GFP-KERNEL use in atomic context, but would not reliably detect memory reclaim related deadlocks.) > Signed-off-by: Jia-Ju Bai > --- > drivers/firewire/sbp2.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c > index 6bac03999fd4..a7cd9d87eb02 100644 > --- a/drivers/firewire/sbp2.c > +++ b/drivers/firewire/sbp2.c > @@ -1463,7 +1463,7 @@ static int sbp2_scsi_queuecommand(struct Scsi_Host *shost, > struct sbp2_command_orb *orb; > int generation, retval = SCSI_MLQUEUE_HOST_BUSY; > > - orb = kzalloc(sizeof(*orb), GFP_ATOMIC); > + orb = kzalloc(sizeof(*orb), GFP_KERNEL); > if (orb == NULL) > return SCSI_MLQUEUE_HOST_BUSY; > NACK for GFP_KERNEL, but I am curious whether a weaker GFP set than ATOMIC is possible in scsi_host_template::queuecommand. -- Stefan Richter -======---=- -=== =-=== http://arcgraph.de/sr/