From patchwork Wed Sep 11 06:45:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 13799744 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 2F579EE0212 for ; Wed, 11 Sep 2024 06:45:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F52F8D00E2; Wed, 11 Sep 2024 02:45:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A4346B0384; Wed, 11 Sep 2024 02:45:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 745028D00E2; Wed, 11 Sep 2024 02:45:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 50BF86B0383 for ; Wed, 11 Sep 2024 02:45:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8567DA9F05 for ; Wed, 11 Sep 2024 06:45:46 +0000 (UTC) X-FDA: 82551521892.26.16E7314 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by imf29.hostedemail.com (Postfix) with ESMTP id 89330120008 for ; Wed, 11 Sep 2024 06:45:43 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FgKnDlte; spf=pass (imf29.hostedemail.com: domain of feng.tang@intel.com designates 198.175.65.12 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726037092; 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=ygW2h7ODlwmBx5yTCoi5Gmf0Sb0T4upnchiSqJUdeTg=; b=J75J1Dg+R+7aSBE1Fv+WLgRrEtdA47J19MVXv2QbEq4ddFNqO39LPFv84mK/ciqt/IgXte KMpRK3oodC+rd0UAU0/V3+ba2zt85bgAOBaES247NW5mM74N8FG82zvM7sZB8GAFUFAyLn fiYI1BlhXw46LfRdMj4kPsLw+3kVdng= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FgKnDlte; spf=pass (imf29.hostedemail.com: domain of feng.tang@intel.com designates 198.175.65.12 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=1726037092; a=rsa-sha256; cv=none; b=wccwBQaQp414yDw6elIltw+xqFmFMRGsq2r86UJlQvVNmkxPK4Emo4N53OJXRO/okEeq82 3nyZsXqNgdKp3CT4oZMeJMAwZK+81occaDy2CntOrzyz3GP7S2C9Zq1Z1XWGYoMZwBlB0B c/K1SvcHwEBXWR/x6z6894P/W63h13I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726037143; x=1757573143; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Q3lqKoiLjbmmga3F3S8RdhTiuakRNQeqwNeOT2Bp6GA=; b=FgKnDltenY3/g7dBgily3xDJKs9VJre5yLtXersxUaBlmZONebJofdbW Vtyq6sZz7MlzNuVyeXPqFCDGZELJ1zWpVhJDQs9eoNk6nIeszZSSOGtAs N3MyxdOGiZ2Jszw58B/aOF+OBrFH62gUyFaHwT0miEiATDgsZCec/zPVJ ZdZBXKmciLaJXQ5UQ1CPz5W2ccLj3osOHYqyQ7Z6AuP0hVaFO7oQUJQA/ Ighr4U0Ng3SMZ6zqT3Ley4Cw5bHYNn1zhwVgwyhnNU/vzAaDgkrp+c18s 0MrkMs8kCYRqC7+SWgS5LOZglQDJfAsMjsZd9UVIUPtX0Hp0aNZhidPJK A==; X-CSE-ConnectionGUID: PESIOldpRzi0tKtZLgDwHA== X-CSE-MsgGUID: MZihRpOtRdSDpYlSUSYthw== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="36172959" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="36172959" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 23:45:40 -0700 X-CSE-ConnectionGUID: 7FRSoTDrQNOS2pFrzeWgDA== X-CSE-MsgGUID: dO/k+wvZRJCKQ0Bk9A0CJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67771470" Received: from feng-clx.sh.intel.com ([10.239.159.50]) by orviesa007.jf.intel.com with ESMTP; 10 Sep 2024 23:45:36 -0700 From: Feng Tang To: Vlastimil Babka , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Konovalov , Marco Elver , Shuah Khan , David Gow , Danilo Krummrich , Alexander Potapenko , Andrey Ryabinin , Dmitry Vyukov , Vincenzo Frascino Cc: linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Feng Tang Subject: [PATCH v2 0/5] mm/slub: Improve data handling of krealloc() when orig_size is enabled Date: Wed, 11 Sep 2024 14:45:30 +0800 Message-Id: <20240911064535.557650-1-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 89330120008 X-Stat-Signature: t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plE7xEesgf0ZI6OkuOUY4CxIoeBx5bi2JdH67LjrUmWnmjID3czPd7E65zvN64Hqb5mLZXJOycm3Gby5H7c02ZANXbAYwysSfCilm8ClHvPA/1ot7bwUXEePvWLv1n1UucBDhn+Z3apdSh28SuvOgeAbXfNfZ8GqwpInmhY6YWEtTBCjpAhTVwpbOxLkLctwTrEU+EcY47SYUzf1Lm7zG567JoSRP3+JaXKpimYIZkwtZXee5/mH9fodVlZUyLT3Tx9eJKevu6z7TgSgaAaNrXf9dMsf6TnhzvwQRapGC0kKFRSG90IcJccNZXb2jcp+dze8A== 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: List-Subscribe: List-Unsubscribe: Danilo Krummrich's patch [1] raised one problem about krealloc() that its caller doesn't pass the old request size, say the object is 64 bytes kmalloc one, but caller originally only requested 48 bytes. Then when krealloc() shrinks or grows in the same object, or allocate a new bigger object, it lacks this 'original size' information to do accurate data preserving or zeroing (when __GFP_ZERO is set). Thus with slub debug redzone and object tracking enabled, parts of the object after krealloc() might contain redzone data instead of zeroes, which is violating the __GFP_ZERO guarantees. Good thing is in this case, kmalloc caches do have this 'orig_size' feature, which could be used to improve the situation here. To make the 'orig_size' accurate, we adjust some kasan/slub meta data handling. Also add a slub kunit test case for krealloc(). This patchset has dependency over patches in both -mm tree and -slab trees, so it is written based on linux-next tree '20240910' version. [1]. https://lore.kernel.org/lkml/20240812223707.32049-1-dakr@kernel.org/ Thanks, Feng Changelog: Since v1: * Drop the patch changing generic kunit code from this patchset, and will send it separately. * Separate the krealloc moving form slab_common.c to slub.c to a new patch for better review (Danilo/Vlastimil) * Improve commit log and comments (Vlastimil/Danilo) * Rework the kunit test case to remove its dependency over slub_debug (which is incomplete in v1) (Vlastimil) * Add ack and review tag from developers. Feng Tang (5): mm/kasan: Don't store metadata inside kmalloc object when slub_debug_orig_size is on mm/slub: Consider kfence case for get_orig_size() mm/slub: Move krealloc() and related code to slub.c mm/slub: Improve redzone check and zeroing for krealloc() mm/slub, kunit: Add testcase for krealloc redzone and zeroing lib/slub_kunit.c | 42 +++++++++++++++ mm/kasan/generic.c | 7 ++- mm/slab.h | 6 +++ mm/slab_common.c | 84 ------------------------------ mm/slub.c | 125 ++++++++++++++++++++++++++++++++++++++------- 5 files changed, 160 insertions(+), 104 deletions(-)