From patchwork Wed May 5 15:46:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12240267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B588EC433B4 for ; Wed, 5 May 2021 15:47:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 456A4613BF for ; Wed, 5 May 2021 15:47:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 456A4613BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C41206B006E; Wed, 5 May 2021 11:47:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDDEF6B0071; Wed, 5 May 2021 11:47:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A30FB6B0072; Wed, 5 May 2021 11:47:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 83C146B006E for ; Wed, 5 May 2021 11:47:29 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3E96B8158 for ; Wed, 5 May 2021 15:47:29 +0000 (UTC) X-FDA: 78107607018.39.8CD0778 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 8145B60006D3 for ; Wed, 5 May 2021 15:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620229648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=SaT7Ji+jTKOj/hsJa+VOoJunLiJdoYDfVfwJl9Tkuy8=; b=UyzNgP8IIPlSIOTXRkUFT/vpmKz5eOWKFLosw/92jtTG+LEhdx9NcSAhUQFwv5vLmNUV6X 5IqYwKyM1qkQ2CYD5KeA698HMVdJE0v6fgKQbdUP7esirxDCkSJzf2HbOFwWVVeUY2ForF 0iH8pSbvR/3mnFkx3A06DdCapeGyQwg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-ddH9diWKObGyhy1l2Jnn2A-1; Wed, 05 May 2021 11:47:25 -0400 X-MC-Unique: ddH9diWKObGyhy1l2Jnn2A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D853C835DE5; Wed, 5 May 2021 15:47:22 +0000 (UTC) Received: from llong.com (ovpn-117-4.rdu2.redhat.com [10.10.117.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E718F5D6AC; Wed, 5 May 2021 15:47:20 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Shakeel Butt Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Waiman Long Subject: [PATCH v3 0/2] mm: memcg/slab: Fix objcg pointer array handling problem Date: Wed, 5 May 2021 11:46:11 -0400 Message-Id: <20210505154613.17214-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UyzNgP8I; spf=none (imf09.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8145B60006D3 X-Stat-Signature: hfa4no99tyxhmg4cq4aduhzk4gur8jbj Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620229639-239754 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: v3: - Update patch 2 commit log and rework kmalloc_type() to make it easier to read. v2: - Take suggestion from Vlastimil to use a new set of kmalloc-cg-* to handle the objcg pointer array allocation and freeing problems. Since the merging of the new slab memory controller in v5.9, the page structure stores a pointer to objcg pointer array for slab pages. When the slab has no used objects, it can be freed in free_slab() which will call kfree() to free the objcg pointer array in memcg_alloc_page_obj_cgroups(). If it happens that the objcg pointer array is the last used object in its slab, that slab may then be freed which may caused kfree() to be called again. With the right workload, the slab cache may be set up in a way that allows the recursive kfree() calling loop to nest deep enough to cause a kernel stack overflow and panic the system. In fact, we have a reproducer that can cause kernel stack overflow on a s390 system involving kmalloc-rcl-256 and kmalloc-rcl-128 slabs with the following kfree() loop recursively called 74 times: [ 285.520739] [<000000000ec432fc>] kfree+0x4bc/0x560 [ 285.520740] [<000000000ec43466>] __free_slab+0xc6/0x228 [ 285.520741] [<000000000ec41fc2>] __slab_free+0x3c2/0x3e0 [ 285.520742] [<000000000ec432fc>] kfree+0x4bc/0x560 : While investigating this issue, I also found an issue on the allocation side. If the objcg pointer array happen to come from the same slab or a circular dependency linkage is formed with multiple slabs, those affected slabs can never be freed again. This patch series addresses these two issues by introducing a new set of kmalloc-cg- caches split from kmalloc- caches. The new set will only contain non-reclaimable and non-dma objects that are accounted in memory cgroups whereas the old set are now for unaccounted objects only. By making this split, all the objcg pointer arrays will come from the kmalloc- caches, but those caches will never hold any objcg pointer array. As a result, deeply nested kfree() call and the unfreeable slab problems are now gone. Waiman Long (2): mm: memcg/slab: Properly set up gfp flags for objcg pointer array mm: memcg/slab: Create a new set of kmalloc-cg- caches include/linux/slab.h | 42 ++++++++++++++++++++++++++++++++++-------- mm/memcontrol.c | 8 ++++++++ mm/slab.h | 1 - mm/slab_common.c | 23 +++++++++++++++-------- 4 files changed, 57 insertions(+), 17 deletions(-)