From patchwork Fri Oct 6 11:17:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Levin, Alexander \(Sasha Levin\)" X-Patchwork-Id: 115051 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1669150qgn; Fri, 6 Oct 2017 04:20:29 -0700 (PDT) X-Google-Smtp-Source: AOwi7QApBw99ka52zdJHDK+SdrCfI87Qp0zPFK7aOP46Ke6IDQ2NAkPal99GNlyPaatEEgP+3FUu X-Received: by 10.99.110.12 with SMTP id j12mr1746759pgc.163.1507288828957; Fri, 06 Oct 2017 04:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507288828; cv=none; d=google.com; s=arc-20160816; b=aztyKfZeDoGQ3dnbLKPFc2sTY6/Fd+FY0an65kjPXRUi7pJoSiPKpV33jynrGfG/UD UyR/YewdWV+cNKoFgFXwo28e7HXM5wtzuUnI4uld7w3KnkZt2m4FICbY6JNnYO8plQn9 wivfRwWS3iB4TPau7sWwOXGWxCPGS6kZNDvP8twUue37DvzhlyjvE3/KuaI0z19P4BCX V1T4BSd+wI/t2EDnq3YMFwHR1nyfL4USdzjFSRnx3OejFNcQwsDd+t2g5tPJ1Z3MAvmb W/XzkjKkfMBk75Ysrjtnhxvy9a3cAxLN/uQRxZuX/7Uq47ukz0u576qsb0MzzdkN1q48 /Nvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:to:dkim-signature :dkim-signature:cc:from:dkim-signature:arc-authentication-results; bh=UScr5jyks71fvNSlJ+at7pnMVutr8sbezHqzlBZh3HY=; b=bYCvs7NtJTvTFTJ39AXpBXHZ8lcQsn2bC+13z3nsD6QD4KeYCC/dCm83HI6A85VK3y jgMEHqWQjSHpf14ay2qDzjfs96HYQKldgcWh96dT9UnQjFaAl6v70redhNOrERoGZmVb VNdy4P4tgmDI9vnPRO1V2gXFEguj/k0o84sBBhf/6eGMfzKgd7stCEn1syxKirKgl6Dt f68glx4w77Fo4UEyDw1tmj+cjrUrYP6cuWpPlmvThcYlOR2a9hG0+ZalYmZidRiUkPOU EuDUwQsiPypq0OoLVV2wEswQKZ3nvd2o+9IKhc2Uq6evHlL84xt/3m+TRKGytyq48YFN xP2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verizon.com header.s=corp header.b=lyn7r7MC; dkim=fail header.i=@verizon.com header.s=corp header.b=hwtQl1bv; dkim=fail header.i=@verizon.com header.s=corp header.b=hwtQl1bv; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d13si954507pgu.126.2017.10.06.04.20.28; Fri, 06 Oct 2017 04:20:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@verizon.com header.s=corp header.b=lyn7r7MC; dkim=fail header.i=@verizon.com header.s=corp header.b=hwtQl1bv; dkim=fail header.i=@verizon.com header.s=corp header.b=hwtQl1bv; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752051AbdJFLUZ (ORCPT + 8 others); Fri, 6 Oct 2017 07:20:25 -0400 Received: from omzsmtpe03.verizonbusiness.com ([199.249.25.208]:9317 "EHLO omzsmtpe03.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752124AbdJFLUW (ORCPT ); Fri, 6 Oct 2017 07:20:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1507288822; x=1538824822; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=r7rUxDa1zACUbinRAewwwYN6b9zuANeh/CqqTPdjvBU=; b=lyn7r7MC/+1jQTAC1AFBmdIVXv4qaO/OceX+S3qTxUt7I6teYFHIQFOI lz+W6FjHZgBVkN2mw9GBKUUc8IsuD4UaWB1/mJ0Qwr8kg5DGuG/flt18s ezL8FD02p+bNWkIU45EmirOxc8KpnZVgNBYks5eYMYsbJo5Z4cRR9A2CD I=; Received: from unknown (HELO fldsmtpi02.verizon.com) ([166.68.71.144]) by omzsmtpe03.verizonbusiness.com with ESMTP; 06 Oct 2017 11:20:20 +0000 From: "Levin, Alexander (Sasha Levin)" Cc: Arnd Bergmann , Greg Kroah-Hartman , "Levin, Alexander (Sasha Levin)" Received: from rogue-10-255-192-101.rogue.vzwcorp.com (HELO atlantis.verizonwireless.com) ([10.255.192.101]) by fldsmtpi02.verizon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Oct 2017 11:19:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1507288792; x=1538824792; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=r7rUxDa1zACUbinRAewwwYN6b9zuANeh/CqqTPdjvBU=; b=hwtQl1bvENg0fZwgV0QGemRegpKLxR7ZkyZSdUhgaGcgx9c5Stzjc4wg 3RplGjOSHRvpxZhpDAiDc2utKChrI8HxAGvTcjhJDnAy/hxnCv0XKXz2P pm3IyiWlfbo5gXQMmyR6Xk3i6LWLu/kfZWb372tVgZEhixuLTHwOkSzkB o=; Received: from mariner.tdc.vzwcorp.com (HELO eris.verizonwireless.com) ([10.254.88.84]) by atlantis.verizonwireless.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Oct 2017 07:19:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1507288792; x=1538824792; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=r7rUxDa1zACUbinRAewwwYN6b9zuANeh/CqqTPdjvBU=; b=hwtQl1bvENg0fZwgV0QGemRegpKLxR7ZkyZSdUhgaGcgx9c5Stzjc4wg 3RplGjOSHRvpxZhpDAiDc2utKChrI8HxAGvTcjhJDnAy/hxnCv0XKXz2P pm3IyiWlfbo5gXQMmyR6Xk3i6LWLu/kfZWb372tVgZEhixuLTHwOkSzkB o=; X-Host: mariner.tdc.vzwcorp.com Received: from ohtwi1exh002.uswin.ad.vzwcorp.com ([10.144.218.44]) by eris.verizonwireless.com with ESMTP/TLS/AES128-SHA256; 06 Oct 2017 11:19:52 +0000 Received: from tbwexch06apd.uswin.ad.vzwcorp.com (153.114.162.30) by OHTWI1EXH002.uswin.ad.vzwcorp.com (10.144.218.44) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 6 Oct 2017 07:19:52 -0400 Received: from OMZP1LUMXCA16.uswin.ad.vzwcorp.com (144.8.22.194) by tbwexch06apd.uswin.ad.vzwcorp.com (153.114.162.30) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Fri, 6 Oct 2017 07:19:51 -0400 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by OMZP1LUMXCA16.uswin.ad.vzwcorp.com (144.8.22.194) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Fri, 6 Oct 2017 06:19:51 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) by OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) with mapi id 15.00.1263.000; Fri, 6 Oct 2017 06:19:51 -0500 To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" Subject: [added to the v4.1 stable tree] tty: improve tty_insert_flip_char() fast path Thread-Topic: [added to the v4.1 stable tree] tty: improve tty_insert_flip_char() fast path Thread-Index: AQHTPpS75r+gbnqiU02SYqd6hQCmiQ== Date: Fri, 6 Oct 2017 11:17:44 +0000 Message-ID: <20171006111704.25872-98-alexander.levin@verizon.com> References: <20171006111704.25872-1-alexander.levin@verizon.com> In-Reply-To: <20171006111704.25872-1-alexander.levin@verizon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.144.60.250] MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Arnd Bergmann This patch has been added to the v4.1 stable tree. If you have any objections, please let us know. -- 2.11.0 =============== [ Upstream commit 979990c6284814617d8f2179d197f72ff62b5d85 ] kernelci.org reports a crazy stack usage for the VT code when CONFIG_KASAN is enabled: drivers/tty/vt/keyboard.c: In function 'kbd_keycode': drivers/tty/vt/keyboard.c:1452:1: error: the frame size of 2240 bytes is larger than 2048 bytes [-Werror=frame-larger-than=] The problem is that tty_insert_flip_char() gets inlined many times into kbd_keycode(), and also into other functions, and each copy requires 128 bytes for stack redzone to check for a possible out-of-bounds access on the 'ch' and 'flags' arguments that are passed into tty_insert_flip_string_flags as a variable-length string. This introduces a new __tty_insert_flip_char() function for the slow path, which receives the two arguments by value. This completely avoids the problem and the stack usage goes back down to around 100 bytes. Without KASAN, this is also slightly better, as we don't have to spill the arguments to the stack but can simply pass 'ch' and 'flag' in registers, saving a few bytes in .text for each call site. This should be backported to linux-4.0 or later, which first introduced the stack sanitizer in the kernel. Cc: stable@vger.kernel.org Fixes: c420f167db8c ("kasan: enable stack instrumentation") Signed-off-by: Arnd Bergmann Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/tty_buffer.c | 24 ++++++++++++++++++++++++ include/linux/tty_flip.h | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index aa9fad4f35b9..2843c2d4936d 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -356,6 +356,30 @@ int tty_insert_flip_string_flags(struct tty_port *port, EXPORT_SYMBOL(tty_insert_flip_string_flags); /** + * __tty_insert_flip_char - Add one character to the tty buffer + * @port: tty port + * @ch: character + * @flag: flag byte + * + * Queue a single byte to the tty buffering, with an optional flag. + * This is the slow path of tty_insert_flip_char. + */ +int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag) +{ + struct tty_buffer *tb = port->buf.tail; + int flags = (flag == TTY_NORMAL) ? TTYB_NORMAL : 0; + + if (!tty_buffer_request_room(port, 1)) + return 0; + + *flag_buf_ptr(tb, tb->used) = flag; + *char_buf_ptr(tb, tb->used++) = ch; + + return 1; +} +EXPORT_SYMBOL(__tty_insert_flip_char); + +/** * tty_schedule_flip - push characters to ldisc * @port: tty port to push from * diff --git a/include/linux/tty_flip.h b/include/linux/tty_flip.h index c28dd523f96e..d43837f2ce3a 100644 --- a/include/linux/tty_flip.h +++ b/include/linux/tty_flip.h @@ -12,6 +12,7 @@ extern int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars, size_t size); extern void tty_flip_buffer_push(struct tty_port *port); void tty_schedule_flip(struct tty_port *port); +int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag); static inline int tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag) @@ -26,7 +27,7 @@ static inline int tty_insert_flip_char(struct tty_port *port, *char_buf_ptr(tb, tb->used++) = ch; return 1; } - return tty_insert_flip_string_flags(port, &ch, &flag, 1); + return __tty_insert_flip_char(port, ch, flag); } static inline int tty_insert_flip_string(struct tty_port *port,