From patchwork Sat Nov 28 08:13:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Yufen X-Patchwork-Id: 549624 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B3BC71402C8 for ; Sat, 28 Nov 2015 19:14:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750847AbbK1INs (ORCPT ); Sat, 28 Nov 2015 03:13:48 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:45989 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750743AbbK1INq (ORCPT ); Sat, 28 Nov 2015 03:13:46 -0500 Received: from 172.24.1.47 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CZV03765; Sat, 28 Nov 2015 16:13:15 +0800 (CST) Received: from [127.0.0.1] (10.177.25.132) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Sat, 28 Nov 2015 16:13:09 +0800 Subject: Re: Issue with /proc/sys/net/ipv4/tcp_mem To: "Eric W. Biederman" , Eric Dumazet References: <561B7F98.1040809@huawei.com> <87io6coxg1.fsf@x220.int.ebiederm.org> <1444700679.21657.11.camel@edumazet-glaptop2.roam.corp.google.com> <87twpvmk57.fsf@x220.int.ebiederm.org> CC: , Hanjun Guo , Dingtianhong , Dianfang Zhang , Xinwei Hu From: wangyufen Message-ID: <56596214.5050003@huawei.com> Date: Sat, 28 Nov 2015 16:13:08 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <87twpvmk57.fsf@x220.int.ebiederm.org> X-Originating-IP: [10.177.25.132] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.5659621C.0042, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 2f20798d7b43373d717dbe42897812c4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2015/10/13 13:07, Eric W. Biederman wrote: > Eric Dumazet writes: > >> On Mon, 2015-10-12 at 11:37 -0500, Eric W. Biederman wrote: >>> wangyufen writes: >>> >>>> Hi, >>>> >>>> I tried on linux-4.1: >>>> linux:~# cat /proc/sys/net/ipv4/tcp_mem >>>> 8388608 12582912 16777216 >>>> linux:~# echo 1234 >/proc/sys/net/ipv4/tcp_mem >>>> -bash: echo: write error: Invalid argument >>>> linux:~# cat /proc/sys/net/ipv4/tcp_mem >>>> 1234 12582912 16777216 >>>> >>>> the echo operation got error, but value already written to tcp_mem. >>>> >>>> I checked, patch f594d63199688ad568fb caused the issue. >>> >>> >>> If your problem is that you can not write a single value and instead >>> have to write all three values I don't know what to tell you. I don't >>> see how that could have ever worked. >>> >>> Certainly the commit you pointed at did not change that behavior. >> >> I would not be so sure. >> Above commit added a regression for partial writes. >> If a write() returns an error like EINVAL, we expect no change occurred. >> >> Prior code was calling proc_doulongvec_minmax() using a temporary array, >> and updated tcp_mem[0 .. 2] only of proc_doulongvec_minmax() returned 0 >> >> ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos); >> if (ret) >> return ret; >> #ifdef CONFIG_MEMCG_KMEM >> // deleted for clarity >> #endif >> >> net->ipv4.sysctl_tcp_mem[0] = vec[0]; >> net->ipv4.sysctl_tcp_mem[1] = vec[1]; >> net->ipv4.sysctl_tcp_mem[2] = vec[2]; >> >> return 0; >> >> We could argue it is a bug in proc_doulongvec_minmax(). >> This helper probably should allocate a temp buffer, >> as we have the same issue with udp_mem[]. > > Point. We do store the value on partial writes when before we did not. > > That is weird. Clearly someone noticed. I agree this is a confusing > corner case in proc_doulongvec_minmax that it may be worth addressing. > I think maybe we can fix the confusing corner with that patch: --- kernel/sysctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index c3eee4c..e3ee4be 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2318,6 +2318,8 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int bool neg; left -= proc_skip_spaces(&kbuf); + if (!left) + break; err = proc_get_long(&kbuf, &left, &val, &neg, proc_wspace_sep,