Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1859875yba; Fri, 17 May 2019 06:39:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzphSySTfXyAbZwNZEciQlatcIxj7t1al6lN0KDpCMpdKAnk7C4834aNy5dv1xmNIPy5bx X-Received: by 2002:a17:902:5066:: with SMTP id f35mr9121409plh.54.1558100367372; Fri, 17 May 2019 06:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558100367; cv=none; d=google.com; s=arc-20160816; b=RLK7PFlmTmGNBxfeWCPvrMjcfQKKAm4YG8KvX/3xYlV6oaMHBoxdARtiMbFrB2mCa+ zO0dr/46koQQ0VdQJ/0XtoHgj+KkLw4DgWhcB0c3K+4PSaOBMvsO+GLWQPfIJQVb8tku CC8i8nCLZUM35rjxfbmOVsYlOj6YifDZLaKz3UpNHwWd008lKsQ4e0yeLfAgEqwxnYDD toXO/idyyKcupchMQN7XNWIjRRU8nYz2egVejruTU2ouwJe5hShweikOJR2x4ce78nZa 695sKFDzVKUyOZjrnsoU9gWUyzOibOGEMD7WEY17NHj2+c7mfVDrxwuUTNcDXQi41RdV yDgA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=hH3xJ0v8TexP7Quso2VUeFr2IlO7q7v9By4caLNd5PI=; b=hBt5d7vmop2ZhaF9HqqXsFriQ3sMZo8MDFD42Q4d/XW8YP0rHKJv0D8DQaKJlWnMey VBQS/tPzq3zK560fDr3qQMEKMgDLHOsBg5+W4rXHPbXc6YsRdHBeJLtfYuNHZrdhO0q6 VCAcGtgVV/Tld/fjt8SjtmPbWyJ3VnVwKdW7mhxDlwqC8HmyQDGL+rXEOROWxCqDQ+jp ikpY0iVnn7ZbjA7cOI62ZX0NcPHijiAlwKFj0bhmnXFGdWBnUouc56mW4bhS5djnO6WZ seMPM1NdCBjLxaxCLqcAB2xBEbAEvp6loOqgCIrdAcCShmR7d3MOliWDfrBfZH7J8GGK 926g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=JOcqkXq0; 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 e7si7933899pge.593.2019.05.17.06.39.11; Fri, 17 May 2019 06:39:27 -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=@st.com header.s=STMicroelectronics header.b=JOcqkXq0; 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 S1728756AbfEQNVk (ORCPT + 99 others); Fri, 17 May 2019 09:21:40 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:56929 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728100AbfEQNVk (ORCPT ); Fri, 17 May 2019 09:21:40 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4HDGMHk016693; Fri, 17 May 2019 15:21:26 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=STMicroelectronics; bh=hH3xJ0v8TexP7Quso2VUeFr2IlO7q7v9By4caLNd5PI=; b=JOcqkXq0EBNhGrX7hROB2vknY1XsUCJtByolPM9Kh/2aYDrlR2CoqOqXhqknavpWgxyg Qs2sSjbMmTi3r1CCEm5Zy/LNBhMAzFa1F2YEmSwyjHaIw0RNz7SRlNF5gusKygKOAoq4 17DjbSGesVRm5I3Lx4B9lg2S40RaAlDqMYFsBGpuw9r6YiLQ54O6pqV3ymCsodYoOaig G6tsSEbBg1VSf5UYn3s4wRxqhI7jcr3meGdnyj5lwrwvMJIIwAc+J2x/44LyZs1stLb/ 1M6bHFJUQ3TEKwp2NjSBrkTyLcW7xBLTgMBtyt3++mwKqgss4d/9DJCjeOkCgn69/O31 tg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2sg0ankx6c-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 17 May 2019 15:21:26 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EBEA431; Fri, 17 May 2019 13:21:25 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C00FD2B3A; Fri, 17 May 2019 13:21:25 +0000 (GMT) Received: from [10.48.0.131] (10.75.127.48) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 17 May 2019 15:21:25 +0200 Subject: Re: [PATCH v2 2/2] tty: add rpmsg driver To: Alan Cox CC: Ohad Ben-Cohen , Bjorn Andersson , Greg Kroah-Hartman , Jiri Slaby , xiang xiao , , , Fabien DESSENNE References: <1557500577-22366-1-git-send-email-arnaud.pouliquen@st.com> <1557500577-22366-3-git-send-email-arnaud.pouliquen@st.com> <20190516182058.2a565748@alans-desktop> From: Arnaud Pouliquen Openpgp: preference=signencrypt Autocrypt: addr=arnaud.pouliquen@st.com; prefer-encrypt=mutual; keydata= xsFNBFZu+HIBEAC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zoy8sWbnp/LD BSH5iRCwq6Q0hJiEzrVTnO3bBp0WXfgowjXqR+YR86JPrzw2zjgr1e2zCZ1gHBTOyJZiDwAR AQABwsFlBBgBAgAPBQJWbvhyAhsMBQkJZgGAAAoJEP0ZQ+DAfqbfs5AQAJKIr2+j+U3JaMs3 px9bbxcuxRLtVP5gR3FiPR0onalO0QEOLKkXb1DeJaeHHxDdJnVV7rCJX/Fz5CzkymUJ7GIO gpUGstSpJETi2sxvYvxfmTvE78D76rM5duvnGy8lob6wR2W3IqIRwmd4X0Cy1Gtgo+i2plh2 ttVOM3OoigkCPY3AGD0ts+FbTn1LBVeivaOorezSGpKXy3cTKrEY9H5PC+DRJ1j3nbodC3o6 peWAlfCXVtErSQ17QzNydFDOysL1GIVn0+XY7X4Bq+KpVmhQOloEX5/At4FlhOpsv9AQ30rZ 3F5lo6FG1EqLIvg4FnMJldDmszZRv0bR0RM9Ag71J9bgwHEn8uS2vafuL1hOazZ0eAo7Oyup 2VNRC7Inbc+irY1qXSjmq3ZrD3SSZVa+LhYfijFYuEgKjs4s+Dvk/xVL0JYWbKkpGWRz5M82 Pj7co6u8pTEReGBYSVUBHx7GF1e3L/IMZZMquggEsixD8CYMOzahCEZ7UUwD5LKxRfmBWBgK 36tfTyducLyZtGB3mbJYfWeI7aiFgYsd5ehov6OIBlOz5iOshd97+wbbmziYEp6jWMIMX+Em zqSvS5ETZydayO5JBbw7fFBd1nGVYk1WL6Ll72g+iEnqgIckMtxey1TgfT7GhPkR7hl54ZAe 8mOik8I/F6EW8XyQAA2P Message-ID: <28d67a7b-4b75-f2fc-3058-776b37d90622@st.com> Date: Fri, 17 May 2019 15:21:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190516182058.2a565748@alans-desktop> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG7NODE2.st.com (10.75.127.20) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-17_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Alan, On 5/16/19 7:20 PM, Alan Cox wrote: > >> +static int rpmsg_tty_data_handler(struct rpmsg_device *rpdev, void *data, >> + int len, void *priv, u32 src) >> +{ >> + struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev); >> + u8 *cbuf; >> + int space; >> + >> + dev_dbg(&rpdev->dev, "msg(<- src 0x%x) len %d\n", src, len); >> + >> + if (!len) >> + return 0; >> + >> + dev_dbg(&rpdev->dev, "space available: %d\n", >> + tty_buffer_space_avail(&cport->port)); >> + >> + space = tty_prepare_flip_string(&cport->port, &cbuf, len); >> + if (space <= 0) { >> + dev_err(&rpdev->dev, "No memory for tty_prepare_flip_string\n"); >> + return -ENOMEM; >> + } > > Really bad idea. > > 1. It's not an 'error'. It's normal that in the case the consumer is > blocked you can run out of processing space > > 2. You will trigger this when being hit by a very large fast flow of data > so responding by burning CPU spewing messages (possibly even out of this > tty) is bad. > > It's not a bug - just keep statistics and throw it away. If anyone cares > they will do flow control. Indeed,and there is a similar issue in the rpmsg_tty_write_control (on rpmsg_trysend failure), i will change message level to debug. Furthermore there is a nonsense to return error to rpmsg framework as rpmsg reception is ok... > > >> + >> +static int rpmsg_tty_write_control(struct tty_struct *tty, u8 ctrl, u8 *values, >> + unsigned int n_value) >> +{ >> + struct rpmsg_tty_port *cport = idr_find(&tty_idr, tty->index); >> + struct rpmsg_tty_payload *msg; >> + struct rpmsg_tty_ctrl *m_ctrl; >> + struct rpmsg_device *rpdev; >> + unsigned int msg_size; >> + int ret; >> + >> + if (!cport) { >> + dev_err(tty->dev, "cannot get cport\n"); >> + return -ENODEV; >> + } >> + >> + rpdev = cport->rpdev; >> + >> + msg_size = sizeof(*msg) + sizeof(*m_ctrl) + n_value; >> + msg = kzalloc(msg_size, GFP_KERNEL); > > > Out of memory check ? > >> +static int rpmsg_tty_write(struct tty_struct *tty, const u8 *buf, int len) >> +{ >> + struct rpmsg_tty_port *cport = idr_find(&tty_idr, tty->index); >> + struct rpmsg_device *rpdev; >> + int msg_size, msg_max_size, ret = 0; >> + int cmd_sz = sizeof(struct rpmsg_tty_payload); >> + u8 *tmpbuf; >> + >> + if (!cport) { >> + dev_err(tty->dev, "cannot get cport\n"); >> + return -ENODEV; >> + } >> + >> + /* If cts not set, the message is not sent*/ >> + if (!cport->cts) >> + return 0; >> + >> + rpdev = cport->rpdev; >> + >> + dev_dbg(&rpdev->dev, "%s: send msg from tty->index = %d, len = %d\n", >> + __func__, tty->index, len); >> + if (!buf) { >> + dev_err(&rpdev->dev, "buf shouldn't be null.\n"); >> + return -ENOMEM; >> + } >> + >> + msg_max_size = rpmsg_get_buf_payload_size(rpdev->ept); >> + if (msg_max_size < 0) >> + return msg_max_size; >> + >> + msg_size = min(len + cmd_sz, msg_max_size); >> + tmpbuf = kzalloc(msg_size, GFP_KERNEL); > > Allocation failure check ? > Thanks for your comments, i will fix in a v3. Regards Arnaud