From patchwork Thu Nov 2 18:27:12 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: 13444117 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 724FEC4332F for ; Thu, 2 Nov 2023 18:28:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D94C78D00A2; Thu, 2 Nov 2023 14:28:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D446C8D000F; Thu, 2 Nov 2023 14:28:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0E4B8D00A2; Thu, 2 Nov 2023 14:28:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B24E38D000F for ; Thu, 2 Nov 2023 14:28:04 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8A1E516014A for ; Thu, 2 Nov 2023 18:28:04 +0000 (UTC) X-FDA: 81413848488.11.8F9CA19 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by imf01.hostedemail.com (Postfix) with ESMTP id 7A65140013 for ; Thu, 2 Nov 2023 18:28:01 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=kvGljxie; spf=pass (imf01.hostedemail.com: domain of vishal.l.verma@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=vishal.l.verma@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=1698949682; 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=ovZ0iHzTfHwdtHwJQSEEahU+7A/rQz7Q2A2N0MFxzAU=; b=u9HKW4HtHRHUIHww6WMeVQqHBFNIWJBMVfQDffY7zFCm0cAhZN/IXy69AFvOntbhLYhHV2 IlgVoOHL2v0opk7HnMAourvoHRgLp26h0ESKmKrIK1RixZMhrddgK6eAGExsISkJoddMoL 4BKwRMM16J2gw4uZTY26jSgGXPUWurI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698949682; a=rsa-sha256; cv=none; b=6F1ZqHXR3obg16M8VoBnjCeP5Yyx+gbmKs7hXEDWK7Ixm0OiRLltIsJ8PgQLksxP6nXLTS k+dH0/QxAqJlYd00AxAcpjACwaud7Lw0EV7ndvry1fEmLyNNiGCDeeCPM0YBWikVQ4B+dm 5SXac7W/tNuF4bpmUWowZyCHtAmg8UE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=kvGljxie; spf=pass (imf01.hostedemail.com: domain of vishal.l.verma@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698949681; x=1730485681; h=from:subject:date:message-id:mime-version: content-transfer-encoding:to:cc; bh=4qUOmcq7thBdlj5wGqR9iQ3jAeBk8UU8mGmQFkFS1rc=; b=kvGljxiewxZ2anrHemwLcCWmYLXqOkIzdoBvSzbU8DldX09iWFZxNqpa 9nAVrP6BQ21o6vEKZ9Py21t6HUzfQqx+Bm+UuwQxgdg9Vwh2dLd67bZM5 ipUz8kDFdFPVcGu8s+cOV86azLsbLR6fz2UAFaeFs4NsTsWQ2tr7t5Ax1 xAp1KTeFBHRa6qACJ0SxKl5ginwukdq4kIHSz8CBkt/ZcsQ+ydXqlvO50 F1CBhQnUwkPUXFxFgozpTVctRFxUydTQnjl2G4sqUO4B7j1CvnYQ4aJvw aOXG3SplskhkMWi57Tetqqu2TUJpsz8EYMMojNEGtwd7NZs1xjqttGTm/ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="7421156" X-IronPort-AV: E=Sophos;i="6.03,272,1694761200"; d="scan'208";a="7421156" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2023 11:28:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="761359758" X-IronPort-AV: E=Sophos;i="6.03,272,1694761200"; d="scan'208";a="761359758" Received: from fmahinh-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.91.244]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2023 11:27:58 -0700 From: Vishal Verma Subject: [PATCH v9 0/3] mm: use memmap_on_memory semantics for dax/kmem Date: Thu, 02 Nov 2023 12:27:12 -0600 Message-Id: <20231102-vv-kmem_memmap-v9-0-973d6b3a8f1a@intel.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAADqQ2UC/3XQy07DMBAF0F+pvMbI9vgxZsV/IIQmflCLJqmSE oGq/jtuF6SKYeHFHenMtX1mc5pKmtnT7symtJS5jEMN/mHHwp6G98RLrJkpoUBYCXxZ+Eef+rd 6ejpyoxECRqGV86yijubEu4mGsK9s+Dwc6vA4pVy+bi0vrzXvy3wap+9b6SKv03/3L5ILnm1MP ljKKtjnMpzS4TGMPbuuWtTKnRINV5UjdpGoA+09bDmsHIVsOFSuhU2eKBuLfsv1yr3ChuvKbc4 OcgpGetpy88ulEKbhpnIyOkqPMgtqLm/vuLQNt5ULh1lECAKc3HJ3x1Xb7q5vJ2ejs0bFbLYcV y7/+Dqs3CRNCAASEO/55XL5AT91It96AgAA 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 , Jonathan Cameron X-Mailer: b4 0.13-dev-26615 X-Developer-Signature: v=1; a=openpgp-sha256; l=6045; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=4qUOmcq7thBdlj5wGqR9iQ3jAeBk8UU8mGmQFkFS1rc=; b=owGbwMvMwCXGf25diOft7jLG02pJDKnOr7Ruu+5unaW+c9n1k2yHeddveWFjXSUV32mxKEb0G EObn7tXRykLgxgXg6yYIsvfPR8Zj8ltz+cJTHCEmcPKBDKEgYtTACZSK8fIcDFw7cWiD6+8b/VM Fbz/632OUdFMVqX0i09EZ+1mmZn7ZgIjw7l87feuPO6+x/j6TWcznwqcwublGHg5cPbXn8q9pXG 8bAA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: 7A65140013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 1mxpa5e77odop5krrr8nomepozbm4a3g X-HE-Tag: 1698949681-557574 X-HE-Meta: U2FsdGVkX19g5TTKUUQL6kodUy9GBRIlyqONBdi4Um2DcrYSz0pMQzvgW+3eRuz9dmdvytAmHfiV1a8ZGc2pp9a9QUpvmSgo5wMD5MsMMLEdinbyfjTjye6zCmRbY0AUyw2lKAvJvht1lPVK9Auvnqf4WDxcjijbC2N3swv+Vy5lyXJDJQELZj7VNRkCASuYLp41+ENKNsKvmOpUgQ36Tl6sP6iH7MetgfmBmKSLJ9pbTTB7DuFHm/k2NUqEp9luJG3GYdXC57fup0g62C9fYOgL1OTAlvyQcG6LCUp2AljwqoD8PfA3cNyPepv/7jA6w3zQRkmNpvXmFUTByv/U5gg8LIX3ZEHfzhckEm3u19RMscA3f9XJsEJ7jPJYSKM31kHXoBLRf5i9IKzDPkSpEwim0a5un+MMFkt1+ERJzx/VJ1PSe4J45JpZxAM/LCtV1gQxQGWmPZUdYyuyp8ugVXOIKXrk2m3j+YjYKJBgK0xN1Txw84V0n2tMScR542daBOeFi5GU5Hn3xFbuPd3gGgP6bjREVlFgCTpdREp9KpTECRtJpXHN2vR/ytqkm75SfqOLavumL+CiD89OqpwWfB94L5EGedB3CDM1vR5vwJmJRMoYq73XXmd27ABKQBOioX/yjPjf5dpaayusva/6xZ4Zcc+P7zzsrDTk7aStxLvONG4qPU/IeeIKTXTvMF82uUk5iRDbS9Y6JK59TyEcYOLqDWJQ4ytHH5FQZjQObYYhtRrRTxkw5eyJOaPGIdDIVWVnMva3AFbFBGOD4on+/e4SbMa/DSXuV/1SPtqeYIMsI7I0ps91mA+bAfCnCmbkPs67IqbMIyYXSz815vB9exXuP7iorO/RWUxP0uxiA3cF/2uoaUh2Oyrvs7yhircdGcIzBg5Kxglk5yUGggzfjPRzCcVK7O138zEuAyMuMamV9v0S/FjaXnasDfIGiCZonX8+SE91Mhvu1GWEIMz n57Lw2zc Avu8YeOFG13F25L/uwO1sXwf3FexXlKXNUMjbKaky8HlHvtTduPQQwaqVVzE01Wd4cThXe70FEPtzYWyhkN0IgvLzMHjjKyF/X19Nnjx3Du2gIR06VDNpGJqSDhQhyArhWG/V/VsPOjKjoZN43e2Ln1dEhJhorDLKCuUB/NXCa/9vGY5y3HrytkYa7UCSopk80BL0KDlHEDB6PmOC8RuCDzCzijCygAr42wQWL2UcrmfDJMScHr+pRMmlwie7XLUm/PFVSnxQQ/IsxR3gSFjhZDFq10A8zEKoNY3UIEw2DCfBXJY= 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 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 | 208 ++++++++++++++++++++++++++++++---------------- 8 files changed, 150 insertions(+), 74 deletions(-) --- base-commit: 25b5b1a0646c3d39e1d885e27c10be1c9e202bf2 change-id: 20230613-vv-kmem_memmap-5483c8d04279 Best regards,