Received: by 10.223.176.5 with SMTP id f5csp26460wra; Thu, 1 Feb 2018 14:57:48 -0800 (PST) X-Google-Smtp-Source: AH8x227x6HhYHHJFM6u6AtuIwPhIAOaP8azskdwi0e9tPVY0FMX0oY+4IWqYXpVcU5XADJ5/MWmN X-Received: by 2002:a17:902:6881:: with SMTP id i1-v6mr33772859plk.323.1517525868360; Thu, 01 Feb 2018 14:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517525868; cv=none; d=google.com; s=arc-20160816; b=dwn2Uu9hR2aWnD/DOTwCnwFdTBiGY2M2jLWVWCK5OcHmnDRsfEIYiHLkmJ3bYDlpGZ HvdoO+HEYXhWKwSL7x6XsRLnNqa6r40qzv0FKhUBIx9zDyCeFEN7rel5jqO/w17drXuP eE+xP0wwV3L88d5v9erVo+fMQ1N1n9myjAe3iqyKiOg/OZOFX7XR00/yRdWtC6xcZJZE dxf+DofbRwsEnaCwL9o8iI/9vVGkJtUrn2ZBAJy0/4gHOMGZtKgRy5BMqOeW1wLujGm3 XU9vK/pzxxoLmCNpr2lkyicUqc5iLkSw+oyr8AIFnw6AY/2g5YY5EYVXCms1nH4cByOJ ChDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature:arc-authentication-results; bh=vwnAUmNmFJMjbBytu6MX5c/2VD7mZKwntf1F+FIYQqM=; b=qT0dQ2u9zSpEGgSRccGuMbrGe3S0s31qfDj72+Dd+UQ/c8svMfj4K4ToPZLf2rVvMY WeYYAtscx+BXvvWx7xhL8tW/fsS1pvc6iVerv53AXPVBUllZYIXbz214qN7TO2YtDu1a bxWE4jVEDlL9kCOiV7NYtprZyQZI10AuilAAqAgyeCzwBrvouo/7LrsNoxHIZv9Nprev n374tDh5SpVBqv/FGcMQyOn0eMsUDV9Pzh7ZcY9sCS+75tExQcYVEprs3tfqkkf1zRJa c/wqvpkg886/DpwuhAaN89Lk8t2lo8DI7MaIjWgn8KM7IF5vlnvoEsyN13CtYG0jOHKa m8ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=EsApmuvm; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=aUtR8/sm; 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=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h127si383346pgc.1.2018.02.01.14.57.20; Thu, 01 Feb 2018 14:57:48 -0800 (PST) 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=@fb.com header.s=facebook header.b=EsApmuvm; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=aUtR8/sm; 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=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752222AbeBAW4j (ORCPT + 99 others); Thu, 1 Feb 2018 17:56:39 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:55522 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751967AbeBAW4b (ORCPT ); Thu, 1 Feb 2018 17:56:31 -0500 Received: from pps.filterd (m0001255.ppops.net [127.0.0.1]) by mx0b-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w11Mq1Mk022188; Thu, 1 Feb 2018 14:56:07 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=facebook; bh=vwnAUmNmFJMjbBytu6MX5c/2VD7mZKwntf1F+FIYQqM=; b=EsApmuvm9rz43dMjWEqVhgz4fOujah1jI28H8RiG6ds5XISuVUA66Dprup3q2F3UcQlv RA5FcRU2BZ+hwwJ9k2GCC/26Olhi7r2pVnKb9CTdG4oa+us8qQDUjjBKLHK6x1YsPaK5 HZiRTEIDxrUQ1LCdoRaCNShhRNbOZnmv71A= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0b-00082601.pphosted.com with ESMTP id 2fv9arrqhv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 01 Feb 2018 14:56:07 -0800 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.21) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 1 Feb 2018 17:56:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vwnAUmNmFJMjbBytu6MX5c/2VD7mZKwntf1F+FIYQqM=; b=aUtR8/sm8Nrzot1cOTQZ4SpScptpyFjYtFhZUQ1b9C7+0UwdIypNlOJuLj6xNVkdnjlTSY9tuE6H5oZYrzX2ogORezsrM0KRAU984jERL1bfVncV2xTmGqP6bDBJRsvOTmor0wnKdkQLhIOHHYV2QYlzgTTVM9rsBH5hNps3jjg= Received: from castle (2620:10d:c092:180::1:8960) by DM3PR15MB1082.namprd15.prod.outlook.com (2603:10b6:0:12::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Thu, 1 Feb 2018 22:56:01 +0000 Date: Thu, 1 Feb 2018 22:55:50 +0000 From: Roman Gushchin To: Eric Dumazet CC: "David S. Miller" , netdev , LKML , kernel-team , Johannes Weiner , Tejun Heo Subject: Re: [PATCH net] net: memcontrol: charge allocated memory after mem_cgroup_sk_alloc() Message-ID: <20180201225542.GA13072@castle> References: <20180125001911.15597-1-guro@fb.com> <20180125.120302.1117695034222616751.davem@davemloft.net> <20180131215401.GA8956@castle> <20180201.101655.1316424669256047119.davem@davemloft.net> <20180201202158.GA11477@castle.DHCP.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-Originating-IP: [2620:10d:c092:180::1:8960] X-ClientProxiedBy: DB6PR07CA0186.eurprd07.prod.outlook.com (2603:10a6:6:42::16) To DM3PR15MB1082.namprd15.prod.outlook.com (2603:10b6:0:12::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f003849b-dfb2-4087-8ec0-08d569c6f7f1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:DM3PR15MB1082; X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1082;3:l5yBbjsIJ9eucs5jdSvzNprbgLOgUE1AiFb47mIbo9lCorJNPbOJ9ueTdJTnlmLS2SsP1RUlt9BYr5hgxYOolaZNJpX+TeDbTfumPlgJBQa5qxAVSsaQ5QxPPvlQrQ/qriIj2HfdQvoZ0Zl7HpZbeKdkcbiKg+YjPMMpMta+UWGYxqT1eQMBGTBWdy/O18fW5v/Ye0OMApwX5jUiUUKAwv0eR8JxTZd9scyKOhadzls5EaRBcpbzqkaAp/ZBAN59;25:a1Ibne4sla43oJm9JolarF9Ka1puu2KbLPfOtTRNg0vEfg06PNUmMsu4Jky1iqApg0/ZDbTHJkbbtHWElqe3SI0BaqnssWTDizdH50k23UZ5tjfNtq9O4npV1UFyNZn+87z54TufCaST0DrO+MJ0WmlMvKA3+biunuUIe4B/S7f23QqlY/RO5+87F+WkCZY3YHHe8nyKQzqk62c9/wwzTPq8LZg90MysEutA0/ZhQZJVsiAm0JmKE7Vu7Qy/osDxCDj9L4YMsJpGMG7/0qXYugI0mceECHc+HfpDvGmMlUFy2fy3nQtUt5xgX2AlulNqisRfs+qWGvKFPxpfAwRiiQ==;31:1RFhDj7AtZwvmd2xWYFUW0OwHTu7dkLuwfdqNPrGDHGrlQMx2CqUg0MQIdRkgvOthvEo9ttJJPq27/zmhHUi3A1QWJ14Zgue7ViTq01yGLMED4l9I6cUmgZZv8lT2tlgCvXbt86xxe64G/eiMzjb8aIbImYySxCQWQsVayguUwydoL5x3s311WufeaBCzK2hlODjnkJ9G4pEesjJaJ7WVH5ZB3GpnXelDKNhiFnN24A= X-MS-TrafficTypeDiagnostic: DM3PR15MB1082: X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1082;20:3YqbWbnbyYAb1WcsJe9LTzk80/EUjjP8acdqzyG8AsFFahARn+F7YderT/SUz7W70vEErMeyWTcTNiCfcfrNPWwCPEP8o3GQihSUziZMh145FjzvmhG5PTqyPzeNJBll2jGAMH6dXBdaev+RR1HdRnApbhMRvZgxiJVjXaJcAWyRf7v8NuxepkUScsluMt8rO/R/GLXLiOxptV+Cf9TVaGYe1+fMygGoPIpNcvqc+Qfyg4g5KEQUj3dBrqLyZgGS2kY5No8LvR4hTnJoZwj//gue1cnSzAGTEqTZQ57nI//xMXwUfz/LXfDUpsBJ6uAz1IR7y2HafB52MirvmzilPLAxCxcFuN4VsBinAQqS8uKS26CZfXqsUnAj36uJg1zzS8VwZxoZjO5W7VJg6H6tOVK7qd/IlYF5n5758nE27k/rCIumzS6p9+1icLLf7oG1moO81njUAE7IhkkGqwnau/1F2fh1yq6aQfSmFgIejteA/0hlGcNeN5+nimLHU6D8;4:/hyGLWb1WocSDpBnrVgKYEQYlnQVUebJBlNYFwjGj0l7PMJVjgfbA6l7Qa836T/Tx2G7rsSr1OHOsdZecwJzrh6V9Kcn9tO8+MK0kRPbvZ9UzLywQOze93VAT5oZ7yNueeE8CCpONjXO+kPiIlLKe3IbpXbdGVTRUAAt0QswKESD/XbzdLkKYuysQVOVffPP2Hq/gX+/XdUU9JutSysjl4Qy3hDZJxYidKki9cEVqGmkACTW2sEmYlve/KBQ511VoSKIizbjjFES1QALo5kzHtUUZux9z9bS5uc+TDw6drIblrDlm6THmbOHsN/P3aS7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(11241501184)(2400082)(944501161)(93006095)(93001095)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM3PR15MB1082;BCL:0;PCL:0;RULEID:;SRVR:DM3PR15MB1082; X-Forefront-PRVS: 0570F1F193 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(366004)(396003)(39860400002)(376002)(39380400002)(346002)(189003)(199004)(76104003)(6246003)(33896004)(6666003)(52396003)(7736002)(59450400001)(53936002)(33656002)(229853002)(6496006)(53546011)(52116002)(305945005)(5660300001)(83506002)(9686003)(386003)(6916009)(55016002)(76176011)(478600001)(2950100002)(4326008)(6116002)(106356001)(25786009)(86362001)(316002)(58126008)(54906003)(50466002)(23726003)(1076002)(81166006)(81156014)(97736004)(8676002)(47776003)(68736007)(186003)(16526019)(16586007)(93886005)(8936002)(2906002)(105586002)(33716001)(18370500001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM3PR15MB1082;H:castle;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;D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oYxmMZ5f7YIOo0+w7N9I9htyuaCDWdZLvBqZ+SpIkcao7A2UAlbx1Ltm9SweG8gGhy1kVBcZn2eSw=;24:dCLem60e0eC81Rly/TizL5p0Exk0zMIbgrCvybhJ+nhVz/y1BwmCu6Mj10wCPqCMwLxcIdyvdRCSqEDWkJJM5UYEY19BCSIOtt19Vy+TsiM=;7:qKmSSK5jSvGUU6aFgZ0IkctwdHbIUZpueaQiWuOAXoRM4taWDvHs9+qEbx47kkliPpw7QizLTWdgQRV5psisU6P2EoNVUv9onrBi+FN+zjoBHUb/WZcg/gUle0s3mDcAwD2i1h1KIxpNpOmakLM1f/EMHvshw7yiT9zAtCsPLFfXnOyxStI+GR78/zCJmzuFHByo9P8FwFytWzgbADwUvtmXRj9+NMLsm6iaIhC+4qyYuYOybqc/mEjpPyChTPkY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1082;20:kif8rYG0OjSw23rGVBmyr3xBO17gadXYB0bI28arOGXWaopd/DoWtPp3gn2QuQiAKWgpT4WMLivnTsGEj3BKxB2fstoO4uE5/osaD3ePXS4MuU3VPP8uWAXeHP6opP5vtNLLLMEEwkvJhlF7TIIHrAAmclmCswZbQ59pRl37zPs= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2018 22:56:01.4224 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f003849b-dfb2-4087-8ec0-08d569c6f7f1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR15MB1082 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-01_07:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 01, 2018 at 01:17:56PM -0800, Eric Dumazet wrote: > On Thu, Feb 1, 2018 at 12:22 PM, Roman Gushchin wrote: > > On Thu, Feb 01, 2018 at 10:16:55AM -0500, David Miller wrote: > >> From: Roman Gushchin > >> Date: Wed, 31 Jan 2018 21:54:08 +0000 > >> > >> > So I really start thinking that reverting 9f1c2674b328 > >> > ("net: memcontrol: defer call to mem_cgroup_sk_alloc()") > >> > and fixing the original issue differently might be easier > >> > and a proper way to go. Does it makes sense? > >> > >> You'll need to work that out with Eric Dumazet who added the > >> change in question which you think we should revert. > > > > Eric, > > > > can you, please, provide some details about the use-after-free problem > > that you've fixed with commit 9f1c2674b328 ("net: memcontrol: defer call > > to mem_cgroup_sk_alloc()" ? Do you know how to reproduce it? > > > > Deferring mem_cgroup_sk_alloc() breaks socket memory accounting > > and makes it much more fragile in general. So, I wonder, if there are > > solutions for the use-after-free problem. > > > > Thank you! > > > > Roman > > Unfortunately bug is not public (Google-Bug-Id 67556600 for Googlers > following this thread ) > > Our kernel has a debug feature on percpu_ref_get_many() which detects > the typical use-after-free problem of > doing atomic_long_add(nr, &ref->count); while ref->count is 0, or > memory already freed. > > Bug was serious because css_put() will release the css a second time. > > Stack trace looked like : > > Oct 8 00:23:14 lphh23 kernel: [27239.568098] > [] dump_stack+0x4d/0x6c > Oct 8 00:23:14 lphh23 kernel: [27239.568108] [] ? > cgroup_get+0x43/0x50 > Oct 8 00:23:14 lphh23 kernel: [27239.568114] [] > warn_slowpath_common+0xac/0xc8 > Oct 8 00:23:14 lphh23 kernel: [27239.568117] [] > warn_slowpath_null+0x1a/0x1c > Oct 8 00:23:14 lphh23 kernel: [27239.568120] [] > cgroup_get+0x43/0x50 > Oct 8 00:23:14 lphh23 kernel: [27239.568123] [] > cgroup_sk_alloc+0x64/0x90 Hm, that looks strange... It's cgroup_sk_alloc(), not mem_cgroup_sk_alloc(), which was removed by 9f1c2674b328. I thought, that it's css_get() in mem_cgroup_sk_alloc(), which you removed, but the stacktrace you've posted is different. void mem_cgroup_sk_alloc(struct sock *sk) { /* * Socket cloning can throw us here with sk_memcg already * filled. It won't however, necessarily happen from * process context. So the test for root memcg given * the current task's memcg won't help us in this case. * * Respecting the original socket's memcg is a better * decision in this case. */ if (sk->sk_memcg) { BUG_ON(mem_cgroup_is_root(sk->sk_memcg)); >>> css_get(&sk->sk_memcg->css); return; } Is it possible to reproduce the issue on an upstream kernel? Any ideas of what can trigger it? Btw, with the following patch applied (below) and cgroup v2 enabled, the issue, which I'm talking about, can be reproduced in seconds after reboot by doing almost any network activity. Just sshing to a machine is enough. The corresponding warning will be printed to dmesg. What is a proper way to fix the socket memory accounting in this case, what do you think? Thank you! Roman -- diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index c51c589..55fb890 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -276,6 +276,8 @@ struct mem_cgroup { struct list_head event_list; spinlock_t event_list_lock; + atomic_t tcpcnt; + struct mem_cgroup_per_node *nodeinfo[0]; /* WARNING: nodeinfo must be the last member here */ }; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 19eea69..c69ff04 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5623,6 +5623,8 @@ static int memory_stat_show(struct seq_file *m, void *v) seq_printf(m, "workingset_nodereclaim %lu\n", stat[WORKINGSET_NODERECLAIM]); + seq_printf(m, "tcpcnt %d\n", atomic_read(&memcg->tcpcnt)); + return 0; } @@ -6139,6 +6141,8 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) { gfp_t gfp_mask = GFP_KERNEL; + atomic_add(nr_pages, &memcg->tcpcnt); + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { struct page_counter *fail; @@ -6171,6 +6175,11 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) */ void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) { + int v = atomic_sub_return(nr_pages, &memcg->tcpcnt); + if (v < 0) { + pr_info("@@@ %p %d \n", memcg, v); + } + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { page_counter_uncharge(&memcg->tcpmem, nr_pages); return;