From patchwork Wed Jul 27 07:10:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 12930192 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A58F6C04A68 for ; Wed, 27 Jul 2022 07:10:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E44B76B0083; Wed, 27 Jul 2022 03:10:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF7056B0085; Wed, 27 Jul 2022 03:10:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE4FC6B0087; Wed, 27 Jul 2022 03:10:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C19746B0083 for ; Wed, 27 Jul 2022 03:10:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A2DF3C0AC8 for ; Wed, 27 Jul 2022 07:10:42 +0000 (UTC) X-FDA: 79732007124.05.8F3671E Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf05.hostedemail.com (Postfix) with ESMTP id 05B7A100093 for ; Wed, 27 Jul 2022 07:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658905841; x=1690441841; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=pgzWF10gM+nk0heJ6laSiJKJPMsfPIgqqxGgbJXgLcM=; b=CPuvezvURKDY2CuacRxi69V5A6QoOeFN/hqvc8y7Zpka0x9A+56FD3mV Nah6eubovG2OkapS2YvaIU+TIUH1i63LzpeaID+PA52zcDNlMqdfl9Yt/ DlOvTKPNt+FFtG0LkKOk97D7i295KzDUqAu7rYgk4bgOzrLG7giTiBhNm t8BtVR972Kx6ro1ZKLDig7ZyUijGTYZQR1tbDNLij9GwYIbESm+N0qMHu 0JNwOmdUkJHWhV3QY2WgdbRf97ZJLe8omBerBZTWOubCQz6H4ZIWQFtFV ZirxxLCybXf/zFmQ82pNKUI8OVWqV7tNRfx+8mYc+odq8dr7hW/UUJy8H g==; X-IronPort-AV: E=McAfee;i="6400,9594,10420"; a="275038557" X-IronPort-AV: E=Sophos;i="5.93,195,1654585200"; d="scan'208";a="275038557" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2022 00:10:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,195,1654585200"; d="scan'208";a="550737896" Received: from shbuild999.sh.intel.com ([10.239.146.138]) by orsmga003.jf.intel.com with ESMTP; 27 Jul 2022 00:10:35 -0700 From: Feng Tang To: Andrew Morton , Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Robin Murphy , John Garry , Kefeng Wang , Feng Tang Subject: [PATCH v3 0/3] mm/slub: some debug enhancements Date: Wed, 27 Jul 2022 15:10:39 +0800 Message-Id: <20220727071042.8796-1-feng.tang@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=CPuvezvU; spf=pass (imf05.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658905842; a=rsa-sha256; cv=none; b=czMkmG50TWUxzjSe4LklHj9p52iVtFHyKevaJaz7zMDYqn4j8vBsjjYnpJ1AsQWVwTxMyj 8ac6mLcG5EfG8+NZWFVaJ+OrFEmcY2unGnZKztT4INPDqxfJB+W+oUx3wbBSykkPwU94AD JWVPE2Mq7K9clluT0NwGQJp4/mMoMWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658905842; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=YTDWY8sfGFDj/yoBCLx91LnwKa9dTnWXIz0kV3xoXwM=; b=2WhrZq/FSiY/MbjIK8kFQAHJRsOq3rLFA+5Y4pNFdU29AoG/I2N6m8nkyEc0RF9p0lmTXg VWafs+TDImCiAg0nE5zJYQismVYH3xTKxHBu9Ij1VqLbQBpP1j/fyEdY1drAcW+GZwCR47 /q+XQlXZLemWkbNBMIGVwAo9eMyAr2w= Authentication-Results: imf05.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=CPuvezvU; spf=pass (imf05.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 05B7A100093 X-Stat-Signature: b7ygijtpi9smxbtzc4px57zxrp8nabf8 X-HE-Tag: 1658905840-895244 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: kmalloc's API family is critical for mm, and one of its nature is that it will round up the request size to a fixed one (mostly power of 2). When user requests memory for '2^n + 1' bytes, actually 2^(n+1) bytes could be allocated, so in worst case, there is around 50% memory space waste. The wastage is not a big issue for requests that get allocated/freed quickly, but may cause problems with objects that have longer life time, and there were some OOM cases in some extrem cases. This patchset tries to : * Add a debug method to track each kmalloced object's wastage info, and show the call stack of original allocation * Extend the redzone sanity check to the extra kmalloced buffer than requested, to better detect un-legitimate access to it. Please help to review, thanks! - Feng --- Changelogs: since v2: * rebased against slab tree's 'for-next' branch * fix pointer handling (Kefeng Wang) * move kzalloc zeroing handling change to a separate patch (Vlastimil Babka) * make 'orig_size' only depend on KMALLOC & STORE_USER flag bits (Vlastimil Babka) since v1: * limit the 'orig_size' to kmalloc objects only, and save it after track in metadata (Vlastimil Babka) * fix a offset calculation problem in print_trailer since RFC: * fix problems in kmem_cache_alloc_bulk() and records sorting, improve the print format (Hyeonggon Yoo) * fix a compiling issue found by 0Day bot * update the commit log based info from iova developers Feng Tang (3): mm/slub: enable debugging memory wasting of kmalloc mm/slub: only zero the requested size of buffer for kzalloc mm/slub: extend redzone check to cover extra allocated kmalloc space than requested include/linux/slab.h | 2 + mm/slab.c | 8 +-- mm/slab.h | 9 ++- mm/slub.c | 157 ++++++++++++++++++++++++++++++++++++------- 4 files changed, 146 insertions(+), 30 deletions(-)