Received: by 10.213.65.16 with SMTP id m16csp137556imf; Sun, 11 Mar 2018 20:11:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELvaF+8ru3hrWpIhO3UTZJYtGkv4nTYnqkIpR1Rf30ONFHk4UFq2iHG2LQPEwUW10gXvsKFG X-Received: by 10.98.71.3 with SMTP id u3mr6488548pfa.219.1520824276909; Sun, 11 Mar 2018 20:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520824276; cv=none; d=google.com; s=arc-20160816; b=k1eLCvs/lteqceqV12zWhC5m87m7LJLqMpVmhDMbexrS6KAbt9frfnceK3iWRDaHX8 LTjONMUc7iP7Zc112dtqk2vC3IgOk85O5S2xuaw2P2RhDGyCjzrzYIA6ny70jjF66gXL yUgXIavQBCQgoe6zbbRjYbmnHH7X+A0JXBH30bh6RF1EVjrSxbI42tmoSHSMldh8gXgw aaLSl/14GjuTJVUmBuwZLIcPKh6EyYCXbBtlR/OsH9mdcMMr9dr97QFx4mXxDYSM7aeD PhmYMzww98fDR+AyD53G4TQ5gVGFKB1BNlqX/nL8S9Y0DFUZieAz8cbf+HNDoytnhXMw BS4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Pjmq0+bWnIEQMLIxO7FXq1efItrl9lo2aqebNKMK6Mo=; b=VkM8uxVjAgSFiZBUY9IQXsb6P4nDjx3DfN00rk2bztwakzY9EwY3h4MZw3pT7sZ3kz BWmsRBy2f2v9YzJEfd9XN37Xm11/huBUMoayGdHssLZ0VbJ+lSRjetFeUaSTSlua6h2S 3DZ64yDb17sRStiiDNk+aFTrwxtzv6WKafg47kBBSP9SRwvfXTcyvxr+gL9XXQA/kxo3 HDIW97O47VyE1ecITMOnQazx/JLdAJe6du5yQD48wpOSbvjl+n6SznipI8SKsKnHRQwk IWyBNt9RWQSIowtzC/afclE57P09bVvHJAljcQBdFjb+kPfDDpMKUjSK2AaQrTLeEHcB 7pWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jPeIl+4d; 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 l33-v6si5209072pld.187.2018.03.11.20.11.02; Sun, 11 Mar 2018 20:11:16 -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; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jPeIl+4d; 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 S932875AbeCLDIk (ORCPT + 99 others); Sun, 11 Mar 2018 23:08:40 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:34487 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932486AbeCLDIi (ORCPT ); Sun, 11 Mar 2018 23:08:38 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 3828A20CFA; Sun, 11 Mar 2018 23:08:38 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Sun, 11 Mar 2018 23:08:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=Pjmq0+bWnIEQMLIxO7FXq1efItrl9 lo2aqebNKMK6Mo=; b=jPeIl+4dbxe0df32xEZtduSjenfoUmQNZd++E2K5wJb3Z Nt4GyIkKxqzhLfqzJ+KSNIXsZO6pOouFfC2RqYO8+1n4gURzRjIbvz49Bt7giGDZ 86BMKCmf7XaSNmcOUtezp4hKgOOJi2Ynua2OHbmr2TPfj+WhITTJ5Iy94vq9qMEE iIGKP6Qu+AzuKSLBQuugQUDuPsFRlWa/01kc8KzF7z6VgAPeyd/2/L37b3tog8jN cJketdtAT4qhfZUnmkqn57XhrmzIBY8it7bH1oWj1is5hSTxAR/gAhf652ZxpMZZ vwxpCwm9P4R9vzCAQU2UnOcJd5aTUVNcZpKRiL2jQ== X-ME-Sender: Received: from localhost (124-170-217-156.dyn.iinet.net.au [124.170.217.156]) by mail.messagingengine.com (Postfix) with ESMTPA id 68ED5240CE; Sun, 11 Mar 2018 23:08:37 -0400 (EDT) Date: Mon, 12 Mar 2018 14:08:34 +1100 From: "Tobin C. Harding" To: Salvatore Mesoraca Cc: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-scsi@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , Dario Ballabio , Kees Cook , Linus Torvalds , kernelnewbies@kernelnewbies.org Subject: Re: [PATCH] scsi: eata: drop VLA in reorder() Message-ID: <20180312030834.GC8631@eros> References: <1520802418-17284-1-git-send-email-s.mesoraca16@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1520802418-17284-1-git-send-email-s.mesoraca16@gmail.com> X-Mailer: Mutt 1.5.24 (2015-08-30) User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding kernel newbies to CC because I pose a few noob questions :) Adding Linus to CC because I quoted him. On Sun, Mar 11, 2018 at 10:06:58PM +0100, Salvatore Mesoraca wrote: > n_ready will always be less than or equal to MAX_MAILBOXES. > So we avoid a VLA[1] and use fixed-length arrays instead. > > [1] https://lkml.org/lkml/2018/3/7/621 > > Signed-off-by: Salvatore Mesoraca > --- > drivers/scsi/eata.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c > index 6501c33..202cd17 100644 > --- a/drivers/scsi/eata.c > +++ b/drivers/scsi/eata.c > @@ -2096,7 +2096,7 @@ static int reorder(struct hostdata *ha, unsigned long cursec, > unsigned int k, n; > unsigned int rev = 0, s = 1, r = 1; > unsigned int input_only = 1, overlap = 0; > - unsigned long sl[n_ready], pl[n_ready], ll[n_ready]; > + unsigned long sl[MAX_MAILBOXES], pl[MAX_MAILBOXES], ll[MAX_MAILBOXES]; I think we are going to see a recurring theme here. MAX_MAILBOXES==64 so this patch adds 1536 bytes to the stack on a 64 bit machine or 768 bytes on a 32 bit machine. Linus already commented on another VLA removal patch that 768 was a lot of stack space. That comment did, however say 'deep in some transfer call chain'. I don't know what a 'transfer call chain' (the transfer bit) is but is there some heuristic we can use to know how deep is deep? Or more to the point, is there some heuristic we can use to know what is an acceptable amount of stack space to use? As far as this patch is concerned wouldn't a kmalloc (with GFP_ATOMIC) be ok? We are in an interrupt handler, can we assume that since IO has just occurred that the IO will be so slow comparatively that a memory allocation will be quick. (assuming IO since eata.c only requests a single irq line.) thanks, Tobin.