Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932932AbcCRRoY (ORCPT ); Fri, 18 Mar 2016 13:44:24 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:34251 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932869AbcCRRoW (ORCPT ); Fri, 18 Mar 2016 13:44:22 -0400 Date: Fri, 18 Mar 2016 10:44:19 -0700 From: Brian Norris To: Arnd Bergmann Cc: David Woodhouse , linux-arm-kernel@lists.infradead.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mtd: avoid stack overflow in MTD CFI code Message-ID: <20160318174419.GA70362@google.com> References: <1456748436-522413-1-git-send-email-arnd@arndb.de> <20160304212159.GA55664@google.com> <2259988.Lj3BC6sPv6@wuerfel> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2259988.Lj3BC6sPv6@wuerfel> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1971 Lines: 41 On Sat, Mar 05, 2016 at 12:25:24AM +0100, Arnd Bergmann wrote: > On Friday 04 March 2016 13:21:59 Brian Norris wrote: > > > > Looking a little closer at this... why do we need the changes to > > include/linux/mtd/map.h again? It should be fine to leave these > > definitions as-is, right? They don't contribute to the large stack > > usage, do they? > > > > Maybe I'm just missing something obvious, so please do enlighten > > > > It's been a while since I created the patch, and the originally > failing configuration currently doesn't produce this (probably > because something else changed). I remember that it was something > rather subtle, but don't exactly remember what happened. > > I've reverted the patch now, trying to reproduce it on my > randconfig setup, but I might not be able to get back to you > in the next week while I'm traveling. FWIW, I took a little look at this, and I can reproduce this myself. I can get a large frame size on at least 2 of the 3 functions you report. I think most of the gain you get with this patch is due to the Kconfig change (MTD_COMPLEX_MAPPINGS) because it forces an extra level of indirection. The other changes seem to give a modest decrease in size, though it's less clear why exactly. Anyway, I think the problem isn't primarily with anything you're touching here exactly, but with the fact that we're putting several copies of the 'map_word' typedef on the stack, and doing assignment to it as if it's a typical variable. But with MAP_WIDTH_32, this is a 32-byte object, and I assume that these (too) long functions are introducing enough complexity that the compiler has to have several copies of them. To properly fix all this, it seems like the code could use some more attention, and not just the superficial changes here. Anyway, I'm interested if you have any more thoughts on this. If you still think this is worthwhile, I can probably just take it. (It looks OK, despite the above comments.) Brian