Received: by 10.213.65.16 with SMTP id m16csp268728imf; Mon, 12 Mar 2018 03:13:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELs75Tu35L3uJw6EzSBSvlWr2DLZb8PxEWS2gTb9ICvYV4M8umlUlGgSKcTgBWZFA0y6ijHH X-Received: by 2002:a17:902:ab8c:: with SMTP id f12-v6mr7466224plr.171.1520849638473; Mon, 12 Mar 2018 03:13:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520849638; cv=none; d=google.com; s=arc-20160816; b=ueQhe6rGprLFGzee8Xf5NRK+bXPxvivTOCzyiEknuMwYwKOoWwPzHy9pqFRAKDw2+A qMvZyy8/6dxD0Ln/W6KuwQPUn3/3nE7EOPe+YI6kDE1vUVcRQdrJZxQ6z9TV64P8b7vi /7XEArcS9pxaMH4SAOIIVuMfXDL0BbP7SasQ+78GsThUJwELrGYuRLgzxEfgfEbJwPW/ 7a6Z0t1t1C8K+u1WhfNLr+Fac7U3/6sA29X+RLZ3DTLBYtlGumCO5A4G1o3DvoiAapZZ nVsqpeCJibumHxbryCZyoZpj8sT+043sFyifJgqC2rWTjfJdbGvzdUyksOYGu6MQDbTq 45oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=kuOynbi+Zn8wyAPGneNLjGjjo5vuHA1sBOSU+sBwZ9Q=; b=yXg3wWL3ulFJ+/lCHT6+e7Bx615R6za5uwR+m1e9ps6LSlInqfs+onwApW6YskeGYz K/0FCy7DJPpQQKBy3l79paVZqq/i+bTpN8cRFAVoJ3GaKRRgTP3TRG5EZMGhOlFmy8bs nPjLF10rwfkE1qp01CcTswXhgmXjJxsmk6sfoPGOWk241fV2Iv48G+NhIeN7p2i/FuFS h4AO7x5uA2S2h8Qa+ClkX9qRgrapQsky3kaiUAPW7plZMH45FZCWkHwXbu21FdrHHe2d AxJChJanYuulMZPaZfDPj1iv8tdtw1SE3B4a99V52gZ8WlwCbtqzd/1pwRpT7Mk1GtUW gyGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Tmuk+JvM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q67si5589371pfj.146.2018.03.12.03.13.44; Mon, 12 Mar 2018 03:13:58 -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=@gmail.com header.s=20161025 header.b=Tmuk+JvM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752758AbeCLKLk (ORCPT + 99 others); Mon, 12 Mar 2018 06:11:40 -0400 Received: from mail-ua0-f194.google.com ([209.85.217.194]:36906 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751229AbeCLKLg (ORCPT ); Mon, 12 Mar 2018 06:11:36 -0400 Received: by mail-ua0-f194.google.com with SMTP id q12so6390817uae.4; Mon, 12 Mar 2018 03:11:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=kuOynbi+Zn8wyAPGneNLjGjjo5vuHA1sBOSU+sBwZ9Q=; b=Tmuk+JvMSj4JPt5MpjRSozcY13jf2TR/K32E+8CtS4Oz7bPRxXG5vWFUuWl1HFhDFD Wdc3NWGnYgahSSqE4dhRoaz357b6FbCdQLiDv3SStsT2C4q8ar9GplYY7CRdsNHjPzyr nOyjdeGaHkCLWRLnculi0RlMRW5M89NDQWYubzdG6foaCJ543FqhLqZ/gXUXwdk4z5in qIL1FWJJ1cBPW66bluQ+U4MhGIeRvRWChjoJZDWyPSW2f8kw5sUhtoh1wqr037/RSd+M bwjGSNoGdYTJ83IUqwl9d+Gd4f1kVUGfeS/1UZBoY/H/lvP0wjxuLo+v1nTMBUnA9HOE GFSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=kuOynbi+Zn8wyAPGneNLjGjjo5vuHA1sBOSU+sBwZ9Q=; b=e/l6LSb2p7ula3XezrqpLeSbhCLvFnDB/+Zd2cHGgE+emoJeZDhZZANxkxwj2DSXKw Cwh1mvNDYkpm7Ou2AnCe1ADbw/J+tgV/PbzUt7EHFw6BGF1XDrFgqrPmFwzQJo4DrsxD wrE/PIIEf4lxC2f72Yt72x1YesQ7mH5CMVogMyQhi/opZCNWWBfFzMi0vwlJa4ceREa4 dMh3xwEEKBrLBYWaJkmMOe3ixM/xs2cvBv15/xZNq6MwI5Ms81JogdaXELoxQI3v9ABm b1KfDWPjicEKySiWt6xeRHgyNtj1sGptf6R7VdLcn7eTtcx7/XsZwbNoBVxksQAhFzTV 3yBg== X-Gm-Message-State: AElRT7EafVX0B6Ekl5QF8Y4Jw29WpheRkd/D+RAReqVceHIC7QnpC6dB i8GBABuQzi+R9DXfNBSknfQblx35ow8ajKyRBB0= X-Received: by 10.176.72.72 with SMTP id c8mr5303697uad.150.1520849495356; Mon, 12 Mar 2018 03:11:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.170.7 with HTTP; Mon, 12 Mar 2018 03:11:15 -0700 (PDT) In-Reply-To: <20180312030834.GC8631@eros> References: <1520802418-17284-1-git-send-email-s.mesoraca16@gmail.com> <20180312030834.GC8631@eros> From: Salvatore Mesoraca Date: Mon, 12 Mar 2018 11:11:15 +0100 Message-ID: Subject: Re: [PATCH] scsi: eata: drop VLA in reorder() To: "Tobin C. Harding" Cc: linux-kernel@vger.kernel.org, Kernel Hardening , linux-scsi@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , Dario Ballabio , Kees Cook , Linus Torvalds , kernelnewbies@kernelnewbies.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-03-12 4:08 GMT+01:00 Tobin C. Harding : > 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.) Yes, I think you are right. I'll change it in v2. Thank you very much, Salvatore