From patchwork Tue Nov 7 07:22:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13448004 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 C76DDC4167D for ; Tue, 7 Nov 2023 07:23:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 321936B020D; Tue, 7 Nov 2023 02:23:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D1C46B025E; Tue, 7 Nov 2023 02:23:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 199266B025F; Tue, 7 Nov 2023 02:23:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0ABC26B020D for ; Tue, 7 Nov 2023 02:23:21 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D5F6616099A for ; Tue, 7 Nov 2023 07:23:20 +0000 (UTC) X-FDA: 81430317360.06.B978AB0 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by imf12.hostedemail.com (Postfix) with ESMTP id 3B28040003 for ; Tue, 7 Nov 2023 07:23:17 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iv+oH1lz; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699341798; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=NLFBGRhcvz2z7jxP7UjqLRH0FQImev5KWegwFz9r+uI=; b=RIrA0BoMdoRWk+LD293R3JxA3+4N355A+g5305JN5Slj4Seuz06WSutwncoioK1WZJAG20 wJ9Bczu4+LQzIzGNhVR80cH5iUVvIeNhBGGPI7OvGGkeHooszNOPTbU7Zx2je/P3S5BLcc BJ/e2g4Omz0CMHxLQJqgUWAVHhXawOc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iv+oH1lz; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699341798; a=rsa-sha256; cv=none; b=W22Fyi7kGBi01pniPlsKZzYEIu5Vt+9bTT0Y6BjjHB3urPFnmVi5KhY1QEB4EA241bcEzR HAP/CqETETU0j48vGjoDtfbOP0ffb58aYV+FCWpqAFq3qgBfujo8PjF/ZbE8XFr/wc22tN OXLsXEtivrnYv9MA1oLZ+oCaGY/Zy/U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699341798; x=1730877798; h=from:subject:date:message-id:mime-version: content-transfer-encoding:to:cc; bh=zxih+4WMqEN6PqGG1MzxNGemsJnW9/vzuClucSb0Eao=; b=iv+oH1lzHfpSW3zn42Godogj15S2o7TRh90JYMmVa0+uMDo0yEv9Mha8 wrLJ6fGmIN9ZLNR3P4RJ/tZ88wbxZKqtUfDmfx7+1nCbT/AHIJypzFNsL tdoXrJ5MzZOeS/bPjcUj7+zC7fsKHzAwffVV/LjowJNIT8X/KeLRN2dkE hrz3+NionEDISx1BoBkpcBANWD8TGRbEr3pOVHPW094UzYRbCm4WJqDP7 zJmaeaMvqrwIE2UiIhlfsceMjfk5ViMErdGOzICZ7aQNMuE0PtRz0fQA9 t0FEqG4Rm6s+JrPi7O6JWo8OSICl3KQMh4SRAexWVU38p5vSPfeIBxTG1 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="475689617" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="475689617" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 23:23:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="712477201" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="712477201" Received: from pengmich-mobl1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.96.119]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 23:23:14 -0800 From: Vishal Verma Subject: [PATCH v10 0/3] mm: use memmap_on_memory semantics for dax/kmem Date: Tue, 07 Nov 2023 00:22:40 -0700 Message-Id: <20231107-vv-kmem_memmap-v10-0-1253ec050ed0@intel.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAMDlSWUC/3XQzU7DMAwH8FeZciYoifPh7MR7IITcfLCItZvaU YGmvTvZDnQ0cMjBf+lnxz6zKY0lTWy7ObMxzWUqh6EWUjxsWNjR8JZ4iTVgSigQVgKfZ/7ep/6 1vp6O3GiEgFFo5TyrqKMp8W6kIewqGz72+xoex5TL523M80utd2U6Hcav29RZXtN/+8+SC55tT D5YyirYpzKc0v4xHHp2bTWrhTslGq4qR+wiUQfae1hzWDgK2XCoXAubPFE2Fv2a64V7hQ3Xldu cHeQUjPS05uaHSyFMw03lZHSUHmUW1Hze3nFpG24rFw6ziBAEOLnm7o6rdrq77k7ORmeNitmsO S5c/nE6rNwkTQgAEhDX3N9z1XBfuXcQbQeEWf463eVy+QbJXVTSugIAAA== To: Andrew Morton , David Hildenbrand , Oscar Salvador , Dan Williams , Dave Jiang Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Huang Ying , Dave Hansen , "Aneesh Kumar K.V" , Michal Hocko , Jonathan Cameron , Jeff Moyer , Vishal Verma , Fan Ni , Jonathan Cameron X-Mailer: b4 0.13-dev-26615 X-Developer-Signature: v=1; a=openpgp-sha256; l=6235; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=zxih+4WMqEN6PqGG1MzxNGemsJnW9/vzuClucSb0Eao=; b=owGbwMvMwCXGf25diOft7jLG02pJDKmeT+8lqLYqtqmsDr58Ui/2IUt13unTWaqnk5oNgluMl 0RPKH3XUcrCIMbFICumyPJ3z0fGY3Lb83kCExxh5rAygQxh4OIUgIk0rmZkmPcy0yS6s6VQ7Min vef3v0wzk7Fesb/n3qdnd/2FG6tYJzAyvIw8+0r8ueoH447pXOpli1/+SOlb/fHw74RT3VOOBDL 3sAEA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3B28040003 X-Stat-Signature: 6gko98esuehso7wjfcthubio1zi8jgxe X-Rspam-User: X-HE-Tag: 1699341797-461315 X-HE-Meta: U2FsdGVkX1+q++amJbLa75jmv6wnDGjxFHUhnRrFpnM4tCLIF6qfsp0oheEM4zl/Um2lQsglaw7QAzits/osijDje61WxR3SS9s285wkYWKQOjCVfC9YBzrBgPjX0PJkx8BMbUZTvKVDyWxdV1saGwU0J6GIPkHix8Mln9JEWTVsPcrvla6HwX0Nlb9gn8Jch9Xw8yxlxa9W9frmoXethh+PL4qgivQOcKs95pQYViqt/9J5GrY664+1tgU734niNiXlvVC1xQLbiD0Y2HcmgnXXZjx8Dl3JjzYGq+TDc4KLxjDlZejxiIXOBcjVk227wNxmPjiuWS1KXQ9McC70eLe/JUCMaXMAV2cLQHv0t86oyf4bm4blxG7IyGaCtA0tizkoLC4IZStCF5aAE9zCYPivXCVzZtDW9UXkRJEqGoTypPPjIYoLPjoZTGjCGR0fFO317INfppvWcv1a4f3ittekIW66SjHJg9vqw2E7ys9BIYukbf22LVKtPPGKj/Co+wbneoMK9bbkXm2aoqyflE1HC2vhy2wvFH94giajrF0wiIl9+5VFw3+X3O7eRnDwEo3ntfa1sX8lPJGot/gzLiPZ9Jdu11TuiZQ5IsnzgYXwx5AFngbxZYsj11m1NwgPvZZbImAqmYH8P8LK8s72QfkQLS5qckjilbHtzIWfXkEr8Doj0iN214JO2XSoYH09NATqwvLXH2HDnJuIK1/NPOJmS3EstHLRCd7I9esfCs/y+monKdbfH6VOf3AVSuXUQSBjgOvcHBXzJe8KT/Jp6y0s3+LcCpkuZIJNe2+Ics4VpVKBcGW7NmqkJO+vOYVp2Ghae4DQ3TKl9Mpxs/QxTwt280o8b+ql1e6sDog/jhSK6WyBlOToqI79rM74Jo7ec2L9S1pexDBLtWSpEZUqEWBj8jKPC0JFW4KmRWC6Wy15YGd9f9Yf+ztxw7z7RAEARCuhdDENpHlao6dkJIy zk96BhrN ga39MyewkTB26uKe67xI5QqaTzTV9qPGr6P2ILY09ZKZL3rLkofgP0SU1GwscAbMTKfNIbROB2YoYkGeJ/GQx0mPCddJtwhjs0O2iSD86tbzO+h0A/GDRz1EbQZ2bRhgtFJQVto/Z84xxNYJjwgr4cD2AiTJbHb19rRo3xKSqRIvl/06gFj+Xf7ivcHUlqTXLq1lyDodV7IZVD4bH754YXGzOFpXhvvRC2VnT+WbNgwk5SXs+tI5rk4L+hRXrqk4LJj+JzwcG6gcDCBsZQAnM5dhsxL9HZU1wPOJETXBLUQNKucY= 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: The dax/kmem driver can potentially hot-add large amounts of memory originating from CXL memory expanders, or NVDIMMs, or other 'device memories'. There is a chance there isn't enough regular system memory available to fit the memmap for this new memory. It's therefore desirable, if all other conditions are met, for the kmem managed memory to place its memmap on the newly added memory itself. The main hurdle for accomplishing this for kmem is that memmap_on_memory can only be done if the memory being added is equal to the size of one memblock. To overcome this, allow the hotplug code to split an add_memory() request into memblock-sized chunks, and try_remove_memory() to also expect and handle such a scenario. Patch 1 replaces an open-coded kmemdup() Patch 2 teaches the memory_hotplug code to allow for splitting add_memory() and remove_memory() requests over memblock sized chunks. Patch 3 allows the dax region drivers to request memmap_on_memory semantics. CXL dax regions default this to 'on', all others default to off to keep existing behavior unchanged. Signed-off-by: Vishal Verma --- Changes in v10: - Rebase on current mainline (Andrew Morton) - Pick up Reviewed-by (Fan Ni) - Link to v9: https://lore.kernel.org/r/20231102-vv-kmem_memmap-v9-0-973d6b3a8f1a@intel.com Changes in v9: - Fix error unwinding for the ENOMEM case in remove_memory_blocks_and_altmaps() (Ying, David) - Misc readability and style cleanups (David) - Link to v8: https://lore.kernel.org/r/20231101-vv-kmem_memmap-v8-0-5e4a83331388@intel.com Changes in v8: - Fix unwinding in create_altmaps_and_memory_blocks() to remove partially added blocks and altmaps. (David, Ying) - Simplify remove_memory_blocks_and_altmaps() since an altmap is assured. (David) - Since we remove per memory-block altmaps, the walk through memory blocks for a larger range isn't needed. Instead we can lookup the memory block directly from the pfn, allowing the test_has_altmap_cb() callback to be dropped and removed. (David) - Link to v7: https://lore.kernel.org/r/20231025-vv-kmem_memmap-v7-0-4a76d7652df5@intel.com Changes in v7: - Make the add_memory_resource() flow symmetrical w.r.t. try_remove_memory() in terms of how the altmap path is taken (David Hildenbrand) - Move a comment, clean up usage of 'memblock' vs. 'memory_block' (David Hildenbrand) - Don't use the altmap path for the mhp_supports_memmap_on_memory(memblock_size) == false case (Huang Ying) - Link to v6: https://lore.kernel.org/r/20231016-vv-kmem_memmap-v6-0-078f0d3c0371@intel.com Changes in v6: - Add a prep patch to replace an open coded kmemdup in add_memory_resource() (Dan Williams) - Fix ordering of firmware_map_remove w.r.t taking the hotplug lock (David Hildenbrand) - Remove unused 'nid' variable, and a stray whitespace (David Hildenbrand) - Clean up and simplify the altmap vs non-altmap paths for try_remove_memory (David Hildenbrand) - Add a note to the changelog in patch 1 linking to the PUD mappings proposal (David Hildenbrand) - Remove the new sysfs ABI from the kmem/dax drivers until ABI documentation for /sys/bus/dax can be established (will split this out into a separate patchset) (Dan Williams) - Link to v5: https://lore.kernel.org/r/20231005-vv-kmem_memmap-v5-0-a54d1981f0a3@intel.com Changes in v5: - Separate out per-memblock operations from per memory block operations in try_remove_memory(), and rename the inner function appropriately. This does expand the scope of the memory hotplug lock to include remove_memory_block_devices(), but the alternative was to drop the lock in the inner function separately for each iteration, and then re-acquire it in try_remove_memory() creating a small window where the lock isn't held. (David Hildenbrand) - Remove unnecessary rc check from the memmap_on_memory_store sysfs helper in patch 2 (Dan Carpenter) - Link to v4: https://lore.kernel.org/r/20230928-vv-kmem_memmap-v4-0-6ff73fec519a@intel.com Changes in v4: - Rebase to Aneesh's PPC64 memmap_on_memory series v8 [2]. - Tweak a goto / error path in add_memory_create_devices() (Jonathan) - Retain the old behavior for dax devices, only default to memmap_on_memory for CXL (Jonathan) - Link to v3: https://lore.kernel.org/r/20230801-vv-kmem_memmap-v3-0-406e9aaf5689@intel.com [2]: https://lore.kernel.org/linux-mm/20230808091501.287660-1-aneesh.kumar@linux.ibm.com Changes in v3: - Rebase on Aneesh's patches [1] - Drop Patch 1 - it is not needed since [1] allows for dynamic setting of the memmap_on_memory param (David) - Link to v2: https://lore.kernel.org/r/20230720-vv-kmem_memmap-v2-0-88bdaab34993@intel.com [1]: https://lore.kernel.org/r/20230801044116.10674-1-aneesh.kumar@linux.ibm.com Changes in v2: - Drop the patch to create an override path for the memmap_on_memory module param (David) - Move the chunking into memory_hotplug.c so that any caller of add_memory() can request this behavior. (David) - Handle remove_memory() too. (David, Ying) - Add a sysfs control in the kmem driver for memmap_on_memory semantics (David, Jonathan) - Add a #else case to define mhp_supports_memmap_on_memory() if CONFIG_MEMORY_HOTPLUG is unset. (0day report) - Link to v1: https://lore.kernel.org/r/20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com --- Vishal Verma (3): mm/memory_hotplug: replace an open-coded kmemdup() in add_memory_resource() mm/memory_hotplug: split memmap_on_memory requests across memblocks dax/kmem: allow kmem to add memory with memmap_on_memory drivers/dax/bus.h | 1 + drivers/dax/dax-private.h | 1 + drivers/dax/bus.c | 3 + drivers/dax/cxl.c | 1 + drivers/dax/hmem/hmem.c | 1 + drivers/dax/kmem.c | 8 +- drivers/dax/pmem.c | 1 + mm/memory_hotplug.c | 210 +++++++++++++++++++++++++++++----------------- 8 files changed, 150 insertions(+), 76 deletions(-) --- base-commit: d2f51b3516dade79269ff45eae2a7668ae711b25 change-id: 20230613-vv-kmem_memmap-5483c8d04279 Best regards,