From patchwork Fri Dec 15 05:25:26 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: 13493998 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 4A45CC10F13 for ; Fri, 15 Dec 2023 05:25:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB4EA8D0113; Fri, 15 Dec 2023 00:25:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3E278D0103; Fri, 15 Dec 2023 00:25:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B69AD6B00BE; Fri, 15 Dec 2023 00:25:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9901F8D0103 for ; Fri, 15 Dec 2023 00:25:42 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 769B71C161D for ; Fri, 15 Dec 2023 05:25:42 +0000 (UTC) X-FDA: 81567915324.29.FB4672A Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf15.hostedemail.com (Postfix) with ESMTP id 51955A0008 for ; Fri, 15 Dec 2023 05:25:40 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=khx1FmTY; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702617940; a=rsa-sha256; cv=none; b=mryNVKW6UIfUjAjD89JGwvkkg8MlZQaCUTunEyfpsvk2+dYJ92Zx8K29vzJzm2YyvLrw9f 6aZ9y6B17HbxKR00OvC7UAutoMBOXV0PmVtY/U+ZTgboRZrqNppwdm135b8OR5AWH8otZC 9NNNbSXVWt1F4uNShLBLBEt+QKvYh5w= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=khx1FmTY; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 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=1702617940; 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:in-reply-to:references:references:dkim-signature; bh=akSvxKH89lALLTdkFCxz3zg9y9c/WbifuO3VvS8K3bg=; b=TLzUvAV4j9FAhcXyhDkLOLhWLa0O3DiE3FI/6fsDGHsQWTMkuKREyO77iUlqD/fWq+j1zv 82uP2hKJSSUiM91IQ21dm6Khao6OKHg0TyRf3uEgDlQgnKC1oWt70K8DSoCqla+CjlL57n 6flNuPCkYBr7kGllKbI2fLhbqxi04PI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702617940; x=1734153940; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=s2pn4yZl0XYTp65Nn5lvuI7n/QI1GItpUEXHrwpjM9A=; b=khx1FmTYZ9dpb9hoBdNnu3iIZwjRSYKozaeaZ3VWwqCmPsohI9Jsiuy6 iuFwucEMnoYxZTSNGJreABZuknUBMjR0tqnvuwQU/j55G8jqvj/V0/9WB Xc9u0pIbaI9hngEoLRycwysfFlxDn6/KG+7c9c0o8kQXWBBTChdpiCzhM QlHB4icGwaizyGcnyQDHAY5jlkYQOVF8KkctjpLOPuxw4X4HSGz9YDbEX JpOS50Jkrbk/V3Ri0MEmBKi82Env1xVobIUdK7F9X/xDh9nrHsgPmg7Ae bAmPxTN6dW2/YAZIPHDxWz2aUn4I5NNXJ6vqGCxmN1NEYfi9/fzOaSZYx g==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="461695020" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="461695020" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="808847933" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="808847933" Received: from mmtakalk-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.109.101]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:37 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 22:25:26 -0700 Subject: [PATCH v6 1/4] Documentatiion/ABI: Add ABI documentation for sys-bus-dax MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v6-1-ad900d698438@intel.com> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> In-Reply-To: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Oscar Salvador Cc: linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, David Hildenbrand , Dave Hansen , Huang Ying , Greg Kroah-Hartman , linux-mm@kvack.org X-Mailer: b4 0.13-dev-433a8 X-Developer-Signature: v=1; a=openpgp-sha256; l=5934; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=s2pn4yZl0XYTp65Nn5lvuI7n/QI1GItpUEXHrwpjM9A=; b=owGbwMvMwCXGf25diOft7jLG02pJDKnVj/0r9Ttm7/2+yP7HJW9hJf/0P4+efS1lffUjJ6Pgg 9WZDomFHaUsDGJcDLJiiix/93xkPCa3PZ8nMMERZg4rE8gQBi5OAZhIRDQjwxbWjft2Rj4KrVI6 9EGhPeCulr7/NHHe8/q6zTfk/Hx4Ghn+KcSHRwasT3++S+N9wN7MdKFvWmf5J5rMl49/ZXFIy1u eEwA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 51955A0008 X-Stat-Signature: 55ex5qyfasrb41r6g9kf3bd3s6gozwmg X-HE-Tag: 1702617940-94013 X-HE-Meta: U2FsdGVkX1/akVINijIGzLQIA9yNHHGCoML/566tg5M2pDb6Dn5V0eCP4kt8WaIfg2O6pR6QkjwVqojEmqbvx7sNyjR7mIUULFY3FvbhR9msRIXsTYAxYnebE9rxIR9riJbDpxQI2RWhLi6gSU6TqfC8HiQvgCkT3a/JYUAOK9inuzz1i7u/kyLY9f1Lu0jxxWfVW8jBanoKCQamubEy+US4JRLE5v/J/LeDM1hzTCCVWfG/VvDM8q/0lqLSeiSjiaZRPCdOteKQbAZ5Si5wbdTBwuy7J0s2hrX9syZhqCeyrd7Zu2X7C8KyPsoy4JbeeVw/0KU2bZUnPfU1T2c7/6CDUugQy53GPJx0RDUGdlWkIzK5Q5RT++4xxLfCm0huQQ8qkfpfD3Hbb2LdV+HEkR0Cd2ObH6jZW2N80hU3t66S4+bsdrIsFrJxw1CNm7kkGA7c95+wch15HNLMPNiCf186oQu5TSJxeFe3CtFri7Bi0ria2Et3EdwOFMrAbdAKcxiS/YJ0ljjURfG5Ed7boiMzKBoRX0EBy5dU+FKYZoMWrQNcZB7Bu1UfiyQ1pafdjAU8/Y+idUlV4BOMOv4Mj7IyZoQ5cQ+C6ickLFgIrOD01jKl5Twuto+XaxbZ6RewAxoHJah4aPO4QJM9TfAqk3oOB5QJKYcev+AyhYevvNyQaX+HFBqBBh83LWoGPD5dJ1gonOx4a+o90p9QyGnmlH73viyFtBYs6d1atRfPs6hdZRw9ykDjsEnM96S0WE5DdzfwBBplrY1VvCfzQKJNxs3dp9Dwpx0/x09fiFVtjJOjigclli1ImXq6xTY0rkmf/7NciX+ucXPAQo2Z+LFmZ1GqnKOCtUH442EigHn/48RjRqvrwaF1D8iV6EteYAuyGbQUVlst61pQFDoHkSeJBAYVcs9chJPWWcdj3Yc2auOZ0n0P8ydPOcKyCTEy+Eq7tneNTwd/fnBqPrJ3DtL WZqDlVAm 0ROtldKgXRDCHZOvWHZVh7lr6h+rT412ORA7RMjERzOlTzmYjVG0ZY+yogEyep9ND9DS5tketB+x7zwXsC5VvewWakwd9j9jUZluN4GYURhodRVRVNv2NCAc1uRQLyMT2qPGwEfDObIgaDg/c0OJt+t70FY8j/A2poPnnnWGjcb451PqWyWjJQ1An0UMG87qSOmvN 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: Add the missing sysfs ABI documentation for the device DAX subsystem. Various ABI attributes under this have been present since v5.1, and more have been added over time. In preparation for adding a new attribute, add this file with the historical details. Cc: Dan Williams Signed-off-by: Vishal Verma --- Documentation/ABI/testing/sysfs-bus-dax | 136 ++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-dax b/Documentation/ABI/testing/sysfs-bus-dax new file mode 100644 index 000000000000..6359f7bc9bf4 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-dax @@ -0,0 +1,136 @@ +What: /sys/bus/dax/devices/daxX.Y/align +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (RW) Provides a way to specify an alignment for a dax device. + Values allowed are constrained by the physical address ranges + that back the dax device, and also by arch requirements. + +What: /sys/bus/dax/devices/daxX.Y/mapping +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (WO) Provides a way to allocate a mapping range under a dax + device. Specified in the format -. + +What: /sys/bus/dax/devices/daxX.Y/mapping[0..N]/start +What: /sys/bus/dax/devices/daxX.Y/mapping[0..N]/end +What: /sys/bus/dax/devices/daxX.Y/mapping[0..N]/page_offset +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (RO) A dax device may have multiple constituent discontiguous + address ranges. These are represented by the different + 'mappingX' subdirectories. The 'start' attribute indicates the + start physical address for the given range. The 'end' attribute + indicates the end physical address for the given range. The + 'page_offset' attribute indicates the offset of the current + range in the dax device. + +What: /sys/bus/dax/devices/daxX.Y/resource +Date: June, 2019 +KernelVersion: v5.3 +Contact: nvdimm@lists.linux.dev +Description: + (RO) The resource attribute indicates the starting physical + address of a dax device. In case of a device with multiple + constituent ranges, it indicates the starting address of the + first range. + +What: /sys/bus/dax/devices/daxX.Y/size +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (RW) The size attribute indicates the total size of a dax + device. For creating subdivided dax devices, or for resizing + an existing device, the new size can be written to this as + part of the reconfiguration process. + +What: /sys/bus/dax/devices/daxX.Y/numa_node +Date: November, 2019 +KernelVersion: v5.5 +Contact: nvdimm@lists.linux.dev +Description: + (RO) If NUMA is enabled and the platform has affinitized the + backing device for this dax device, emit the CPU node + affinity for this device. + +What: /sys/bus/dax/devices/daxX.Y/target_node +Date: February, 2019 +KernelVersion: v5.1 +Contact: nvdimm@lists.linux.dev +Description: + (RO) The target-node attribute is the Linux numa-node that a + device-dax instance may create when it is online. Prior to + being online the device's 'numa_node' property reflects the + closest online cpu node which is the typical expectation of a + device 'numa_node'. Once it is online it becomes its own + distinct numa node. + +What: $(readlink -f /sys/bus/dax/devices/daxX.Y)/../dax_region/available_size +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (RO) The available_size attribute tracks available dax region + capacity. This only applies to volatile hmem devices, not pmem + devices, since pmem devices are defined by nvdimm namespace + boundaries. + +What: $(readlink -f /sys/bus/dax/devices/daxX.Y)/../dax_region/size +Date: July, 2017 +KernelVersion: v5.1 +Contact: nvdimm@lists.linux.dev +Description: + (RO) The size attribute indicates the size of a given dax region + in bytes. + +What: $(readlink -f /sys/bus/dax/devices/daxX.Y)/../dax_region/align +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (RO) The align attribute indicates alignment of the dax region. + Changes on align may not always be valid, when say certain + mappings were created with 2M and then we switch to 1G. This + validates all ranges against the new value being attempted, post + resizing. + +What: $(readlink -f /sys/bus/dax/devices/daxX.Y)/../dax_region/seed +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (RO) The seed device is a concept for dynamic dax regions to be + able to split the region amongst multiple sub-instances. The + seed device, similar to libnvdimm seed devices, is a device + that starts with zero capacity allocated and unbound to a + driver. + +What: $(readlink -f /sys/bus/dax/devices/daxX.Y)/../dax_region/create +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (RW) The create interface to the dax region provides a way to + create a new unconfigured dax device under the given region, which + can then be configured (with a size etc.) and then probed. + +What: $(readlink -f /sys/bus/dax/devices/daxX.Y)/../dax_region/delete +Date: October, 2020 +KernelVersion: v5.10 +Contact: nvdimm@lists.linux.dev +Description: + (WO) The delete interface for a dax region provides for deletion + of any 0-sized and idle dax devices. + +What: $(readlink -f /sys/bus/dax/devices/daxX.Y)/../dax_region/id +Date: July, 2017 +KernelVersion: v5.1 +Contact: nvdimm@lists.linux.dev +Description: + (RO) The id attribute indicates the region id of a dax region. From patchwork Fri Dec 15 05:25:27 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: 13493999 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 A27A0C4332F for ; Fri, 15 Dec 2023 05:25:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EC0D8D0114; Fri, 15 Dec 2023 00:25:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59C218D0103; Fri, 15 Dec 2023 00:25:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43CEA8D0114; Fri, 15 Dec 2023 00:25:44 -0500 (EST) 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 321638D0103 for ; Fri, 15 Dec 2023 00:25:44 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 00DE740BAA for ; Fri, 15 Dec 2023 05:25:43 +0000 (UTC) X-FDA: 81567915366.17.5042E0E Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf04.hostedemail.com (Postfix) with ESMTP id EBB6D40004 for ; Fri, 15 Dec 2023 05:25:41 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=JG4N7r1Y; spf=pass (imf04.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 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=1702617942; 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:in-reply-to:references:references:dkim-signature; bh=5J+gIfvXGnhCDLBK5rZw2WLoOAKtg347Jw8tbqyeHBk=; b=SFE81RVIBefb8ndeDPk21+d5GyAt9g3Z1geS6hDUsqctkZeMQH9YJAAR7m8pnKh729rZG+ lRqEOieojkKi+u8dl0XXjaVHGWz+Pe/DBqEMVRpWP+DUVeGGmMh2qhmk8mrzms+h0LRxTW G2c2fkGrYl5rt9mpswTkw/f1QrF5QGo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702617942; a=rsa-sha256; cv=none; b=dIsTUFYRZhDk+72pbLjEgg7tFOCAjU3E6O78HCk/S6OnV04KBTieuVCGp8OdGS5KUe+PhZ mfkalJ9qO/bDSQgxrTJhxo0rUIXhQ6G//Wy2W6pp1vaoTJvpl+7P9mq9X02pSbhLBPINUK vPhGlSouiZyA+dOab5z+905gT844NnU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=JG4N7r1Y; spf=pass (imf04.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 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=1702617941; x=1734153941; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=g9l8RslOMp5ad/gXCRHw+j360xuk1nb3+acdwFrlL50=; b=JG4N7r1Y0DjNUSwWXgGVWBPpHMKJr/HBIoHFBE4cKWjbrKo7SnzYxNnk gzagxomHBmrgFXkKLGUUKlE5K1IGgJYmTOKk1nvSlTNlToRSKrbwRMe+d tdxxHQFnyPO/4xsM83G/EIOiN5ryI4RtbHxz3dfOA7X5onokiquMvup+E GQ/MIX2ic65AEqnWsEg3Kkibj7QA1zXQB83s22VmGB2Xkr5Ty5eruSCnW DYvNJHiujRS0MPPXmgAUqr75Bo5lfa/96Sc35L3tnI0R64aZrlAZibAce ncyTW/WHthOF8A7kDNDBKO7FxTiQzHmEnKmwJrYEA1sDkQHgx0KDGCiSY Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="461695028" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="461695028" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="808847937" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="808847937" Received: from mmtakalk-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.109.101]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:38 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 22:25:27 -0700 Subject: [PATCH v6 2/4] dax/bus: Use guard(device) in sysfs attribute helpers MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v6-2-ad900d698438@intel.com> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> In-Reply-To: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Oscar Salvador Cc: linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, David Hildenbrand , Dave Hansen , Huang Ying , Greg Kroah-Hartman , linux-mm@kvack.org, Joao Martins X-Mailer: b4 0.13-dev-433a8 X-Developer-Signature: v=1; a=openpgp-sha256; l=7001; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=g9l8RslOMp5ad/gXCRHw+j360xuk1nb3+acdwFrlL50=; b=owGbwMvMwCXGf25diOft7jLG02pJDKnVj/23PV4Tsi/68R5Hl9unM3Y0djytWdHAbcGkJ6wik Xx6GsP5jlIWBjEuBlkxRZa/ez4yHpPbns8TmOAIM4eVCWQIAxenAEykr57hf0DG/93heXPCGta+ VdH15phpYq+zb1lQoDBvzzV7Xmm3bEaG70EflVMniO1OexLerz/H53mywgcvmXW6Pzq2vT/JGvK bGQA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: EBB6D40004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: a4zmncfm6fhhrqq85fj7x1rwxypm3fcx X-HE-Tag: 1702617941-208846 X-HE-Meta: U2FsdGVkX1+kH54ILAJeJsmSXMITOLpy0RjkyAVDKZ0yObsMHyQkSnOVLYFtjbwFRYH06H+sa3sN+LaNo4sQrspErv6aKFfSBqkuBCv3C+vG9mdtoFpmvEUePfWe4XkxWbyvMJpeVTtRIb/oRiPev2g3lW9iCOiw5gboNd/qalaN6Px8NRLvazKqFegb0bPi8OHOFdj12XPcYgXMpomG28rLEpnpln3w2VN1cxp6jXgGJmtkkk0DmKYWoTP1GdUTkXHQ1beYYoqry6mI2YYi7oAOmB+iJDePE2b42GiSpegEefrNcnMEt2LCzhVVhniL3OPiqV7eJojoi7w5T2BH1yoH8UxQDYdtOMqBI/S8qTeC+tkSfckYcheej6UxZUrCrpq6WJxx0P0ZJrdJkr3UZj/icKe0U0H7XKgLYmdHk/Q+3mQ5acJgUjk1rKg5yE4ZNneD5uwEt4m8i4VW8G6px9J9t9vfN8kyPLfg+skDjV73eHrmwWdly7qpudheEaBztgLEHQ2w4AHwYiyBOQaa1jARu3vGQbhG0T9z/97zK6P+Ty2+Po2evKX9cVpHbEAwKiGuWEawxvS04H/qv3WXp4EuRDFCcZe6s7qmAA61OqicrCJ6qQcYN2WcCALcGCLspof+6YotfQndYSHWFvkNiUY18qy29UuOz0dsZKKS5yq+kC60FI5czgihbBKqj1aov/JuNf8JCBW4jbu5bH+hBXYfQLC/EZnZufUDcx+2vcwdChCxt4zqmy+xCQxTiVNURqAqzWQv8JNAVIYBz/XlUQhJyT/ifwOTvnWUynNJe4VzbJsFMlwe9OOjwQf/q4WQtmzfxL+b1oNVRZJGl0dfZwbBUOva9/X4OF2+mnAer+0Nia1S31+oDGhgddKIxP4M+77AzG4htM/UjzhkafsqOmU5KORjsfiyk37vnoNPiErmCG2yc3QO7v3kZzPtSlbSpkdvKCKWpKGYy8IsAlF cXMF7ABu 4/DAqLUryO+TiOve1ynM6Vk+pfzY1Ica4C9Q6HBfl1b4SSnYCiukoFBs4DcOa8IWfz6UrZvYUsu88FmXt6yn+sqHbfowSwVlHkQJGyNPYaMk9UkkXehEVrP3SxmOEVq9i7lWdoX6jAJLQUplLRdaeZe3BLZSFmlO+tsqBzxH9aDOYwH3NEASJNC2FSDkabToK8IVN 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: Use the guard(device) macro to lock a 'struct device', and unlock it automatically when going out of scope using Scope Based Resource Management semantics. A lot of the sysfs attribute writes in drivers/dax/bus.c benefit from a cleanup using these, so change these where applicable. Cc: Joao Martins Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Jonathan Cameron --- drivers/dax/bus.c | 143 ++++++++++++++++++++++-------------------------------- 1 file changed, 59 insertions(+), 84 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 1ff1ab5fa105..6226de131d17 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -294,13 +294,10 @@ static ssize_t available_size_show(struct device *dev, struct device_attribute *attr, char *buf) { struct dax_region *dax_region = dev_get_drvdata(dev); - unsigned long long size; - device_lock(dev); - size = dax_region_avail_size(dax_region); - device_unlock(dev); + guard(device)(dev); - return sprintf(buf, "%llu\n", size); + return sprintf(buf, "%llu\n", dax_region_avail_size(dax_region)); } static DEVICE_ATTR_RO(available_size); @@ -309,17 +306,14 @@ static ssize_t seed_show(struct device *dev, { struct dax_region *dax_region = dev_get_drvdata(dev); struct device *seed; - ssize_t rc; if (is_static(dax_region)) return -EINVAL; - device_lock(dev); + guard(device)(dev); seed = dax_region->seed; - rc = sprintf(buf, "%s\n", seed ? dev_name(seed) : ""); - device_unlock(dev); - return rc; + return sprintf(buf, "%s\n", seed ? dev_name(seed) : ""); } static DEVICE_ATTR_RO(seed); @@ -328,24 +322,28 @@ static ssize_t create_show(struct device *dev, { struct dax_region *dax_region = dev_get_drvdata(dev); struct device *youngest; - ssize_t rc; if (is_static(dax_region)) return -EINVAL; - device_lock(dev); + guard(device)(dev); youngest = dax_region->youngest; - rc = sprintf(buf, "%s\n", youngest ? dev_name(youngest) : ""); - device_unlock(dev); - return rc; + return sprintf(buf, "%s\n", youngest ? dev_name(youngest) : ""); } static ssize_t create_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct dax_region *dax_region = dev_get_drvdata(dev); + struct dev_dax_data data = { + .dax_region = dax_region, + .size = 0, + .id = -1, + .memmap_on_memory = false, + }; unsigned long long avail; + struct dev_dax *dev_dax; ssize_t rc; int val; @@ -358,38 +356,25 @@ static ssize_t create_store(struct device *dev, struct device_attribute *attr, if (val != 1) return -EINVAL; - device_lock(dev); + guard(device)(dev); avail = dax_region_avail_size(dax_region); if (avail == 0) - rc = -ENOSPC; - else { - struct dev_dax_data data = { - .dax_region = dax_region, - .size = 0, - .id = -1, - .memmap_on_memory = false, - }; - struct dev_dax *dev_dax = devm_create_dev_dax(&data); + return -ENOSPC; - if (IS_ERR(dev_dax)) - rc = PTR_ERR(dev_dax); - else { - /* - * In support of crafting multiple new devices - * simultaneously multiple seeds can be created, - * but only the first one that has not been - * successfully bound is tracked as the region - * seed. - */ - if (!dax_region->seed) - dax_region->seed = &dev_dax->dev; - dax_region->youngest = &dev_dax->dev; - rc = len; - } - } - device_unlock(dev); + dev_dax = devm_create_dev_dax(&data); + if (IS_ERR(dev_dax)) + return PTR_ERR(dev_dax); - return rc; + /* + * In support of crafting multiple new devices simultaneously multiple + * seeds can be created, but only the first one that has not been + * successfully bound is tracked as the region seed. + */ + if (!dax_region->seed) + dax_region->seed = &dev_dax->dev; + dax_region->youngest = &dev_dax->dev; + + return len; } static DEVICE_ATTR_RW(create); @@ -481,12 +466,9 @@ static int __free_dev_dax_id(struct dev_dax *dev_dax) static int free_dev_dax_id(struct dev_dax *dev_dax) { struct device *dev = &dev_dax->dev; - int rc; - device_lock(dev); - rc = __free_dev_dax_id(dev_dax); - device_unlock(dev); - return rc; + guard(device)(dev); + return __free_dev_dax_id(dev_dax); } static int alloc_dev_dax_id(struct dev_dax *dev_dax) @@ -908,9 +890,8 @@ static ssize_t size_show(struct device *dev, struct dev_dax *dev_dax = to_dev_dax(dev); unsigned long long size; - device_lock(dev); + guard(device)(dev); size = dev_dax_size(dev_dax); - device_unlock(dev); return sprintf(buf, "%llu\n", size); } @@ -1080,17 +1061,16 @@ static ssize_t size_store(struct device *dev, struct device_attribute *attr, return -EINVAL; } - device_lock(dax_region->dev); - if (!dax_region->dev->driver) { - device_unlock(dax_region->dev); + guard(device)(dax_region->dev); + if (!dax_region->dev->driver) return -ENXIO; - } - device_lock(dev); + + guard(device)(dev); rc = dev_dax_resize(dax_region, dev_dax, val); - device_unlock(dev); - device_unlock(dax_region->dev); + if (rc) + return rc; - return rc == 0 ? len : rc; + return len; } static DEVICE_ATTR_RW(size); @@ -1137,21 +1117,20 @@ static ssize_t mapping_store(struct device *dev, struct device_attribute *attr, if (rc) return rc; - rc = -ENXIO; - device_lock(dax_region->dev); - if (!dax_region->dev->driver) { - device_unlock(dax_region->dev); - return rc; - } - device_lock(dev); + guard(device)(dax_region->dev); + if (!dax_region->dev->driver) + return -ENXIO; + guard(device)(dev); to_alloc = range_len(&r); - if (alloc_is_aligned(dev_dax, to_alloc)) - rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc); - device_unlock(dev); - device_unlock(dax_region->dev); + if (!alloc_is_aligned(dev_dax, to_alloc)) + return -ENXIO; - return rc == 0 ? len : rc; + rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc); + if (rc) + return rc; + + return len; } static DEVICE_ATTR_WO(mapping); @@ -1196,27 +1175,23 @@ static ssize_t align_store(struct device *dev, struct device_attribute *attr, if (!dax_align_valid(val)) return -EINVAL; - device_lock(dax_region->dev); - if (!dax_region->dev->driver) { - device_unlock(dax_region->dev); + guard(device)(dax_region->dev); + if (!dax_region->dev->driver) return -ENXIO; - } - device_lock(dev); - if (dev->driver) { - rc = -EBUSY; - goto out_unlock; - } + guard(device)(dev); + if (dev->driver) + return -EBUSY; align_save = dev_dax->align; dev_dax->align = val; rc = dev_dax_validate_align(dev_dax); - if (rc) + if (rc) { dev_dax->align = align_save; -out_unlock: - device_unlock(dev); - device_unlock(dax_region->dev); - return rc == 0 ? len : rc; + return rc; + } + + return len; } static DEVICE_ATTR_RW(align); From patchwork Fri Dec 15 05:25:28 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: 13494000 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 78402C4332F for ; Fri, 15 Dec 2023 05:25:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA1748D0115; Fri, 15 Dec 2023 00:25:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4E478D0103; Fri, 15 Dec 2023 00:25:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEEAC8D0115; Fri, 15 Dec 2023 00:25:44 -0500 (EST) 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 BD28B8D0103 for ; Fri, 15 Dec 2023 00:25:44 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 97463A0C20 for ; Fri, 15 Dec 2023 05:25:44 +0000 (UTC) X-FDA: 81567915408.13.DF44F5D Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf28.hostedemail.com (Postfix) with ESMTP id 674C7C0009 for ; Fri, 15 Dec 2023 05:25:42 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=HC+RvvLo; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 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=1702617942; 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:in-reply-to:references:references:dkim-signature; bh=ICpmLRSWxW4h+Ok4MRUPEjX88+GqQOKKr/nSwj8Jvt8=; b=mredXxpw8UW4AJoCRR01dLKmk1rJRhapox6+bB5YTmWrslZ50pvSFPlzFG946+Y9O9o89F R/O34ViWF0/A2oV/7QyQNHREJ8uRjyvIf9JbnvRb/QKnD8hgk7yeNU75m5CIP8iwW71Y+G AcREbllEhst6lzR2urp8fY3JMhxP4Ug= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=HC+RvvLo; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702617942; a=rsa-sha256; cv=none; b=vYi/phWZWeqqa0SC6foMMaSCSGM32vS7Nx9S0+CjgAVrQkI2aNBz+kCqEyEHSs6/z1eUyr B35G1neZE8mCe8t4JnLKPno70FMp2pn9GUby6WQ1rqxqklP5djtt0zDfMOf4CHjUhvTnoe /HQjHFVThkGAgV/4EHTPN9annx43lDk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702617942; x=1734153942; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=sNbGEdgrAJp/XDJyFdtJon3rtI5vNIQSMJsEoh64H1k=; b=HC+RvvLoupajt1PW5TfUC8wkv368KE09WgrsqSO9taS+YXfVy16DnjVk OaIoTEF0m38iQykZltxRBh0k7WtXWEupM/HVl7ExIvqaHiH1TGgJ+IGhj hALauW8hCQuN5phQcIH3B2i8fO7Dp9BqvAnl8DzLWEuP68+6K+a5qAfEn GoVfAZEyd05aXYL963eoXaxsYZt3L5an4uQnNDpXMPNOXwYlmOV9f+SLV JafpY9y9S89BY+tyljOg1wchyly9tSafbMjvZ0yW75+ulrqbCamKDu1Xy WUA7tY5m3MIuw21r7CQzwu6EW2DacpW61dXYnwD0L6ls3K6l6fP3tthlL A==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="461695036" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="461695036" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="808847946" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="808847946" Received: from mmtakalk-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.109.101]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:39 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 22:25:28 -0700 Subject: [PATCH v6 3/4] mm/memory_hotplug: export mhp_supports_memmap_on_memory() MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v6-3-ad900d698438@intel.com> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> In-Reply-To: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Oscar Salvador Cc: linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, David Hildenbrand , Dave Hansen , Huang Ying , Greg Kroah-Hartman , linux-mm@kvack.org, Michal Hocko X-Mailer: b4 0.13-dev-433a8 X-Developer-Signature: v=1; a=openpgp-sha256; l=4673; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=sNbGEdgrAJp/XDJyFdtJon3rtI5vNIQSMJsEoh64H1k=; b=owGbwMvMwCXGf25diOft7jLG02pJDKnVj/270n4d1C7Pn6OllvEj6eOC3R8OBFpMDgs02furb V3h077XHaUsDGJcDLJiiix/93xkPCa3PZ8nMMERZg4rE8gQBi5OAZjIaUVGhqvHbgn7n1PPSKt8 aNv1aHOVz+W7sd8qQ4V6SpzvsupvfMzwV6rjV/PTnz9mp3x8tmXRRvvOFYsvNPeVZ3jKPWjX1Zr qzQgA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: 674C7C0009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: sdwirps1hd158j31mbn5chg8am5ws767 X-HE-Tag: 1702617942-27128 X-HE-Meta: U2FsdGVkX19oM2rdXLmNUeZ+zSjnOl0Qu+i7zMB3ffZ3S9dXzdnzcAC6qLDPfh/ZqaD9J+UfCgY4MUS1QXLzWJ/A0etwma3T9U8JKEnfFpppXJ0X3fkCdAe/MAEGmhVVzeETUQ3J2rY8xpo+Slml+0bB6SJy2aI8eMvuEGWa6hUCgunGvVEFZ1LYW6PYVt02mQc188Y/vT5oOzCM1NvWmwTZWVwFn2txs8AIMhxwGACR3bc5Y6vAuIw9xYkNAgRGPkFwiUMi0u7GeREwrQ4ji+F9psnxt1oHFEqt3Jjo1pWgG2+QuLF7XKXD6dALjb4PsTuf60mG65qkHW3qJW7r/k/0rslqdbojc1UfZ3th8rN00LaWPN4JfY89dmZbES4CwK+SadinU/lCGp6f9o8RWXWo2qEnqrJPliHCZiTqcrrHWgyiXAeOjD+je2cHdCsG3JC3pialqsFQRjGAZ+GOF9jWg4Bb2se/4UjUZlK9U0hdtoVfhq9HkZxTWqlYegxvYAMr4YZ/qVFNwYgPUxraVwm40ylVohbFWC7t8tGOer2GiS4tNQfcKI+KatyEmdFY/brsjv7hFq7uN1DUQf9l6iLuvBHhdVlPzLQ1jSAC2Fm8vtbt2mjVSSim7G5LDwIxOE8mDFowJle+VFMw+yZmqJ8b0kAZ3G4jfJqB4wkmAU4ZTHC6z5d8g98jJbCmc9xwYPK+P4biIXbhhkGmLh8ysIre6WUwsjPXSWJ62VHtFSwqHCsHXIuQBBAlDpDGtQ7oTXjV/oepA8EcfykbNEndgGPv9d9a4TerwmhE/+b7Zy31dkbufX2HPHmZDXHakbNyQyLMOdsyzTbK/tkdyFN3UUmiaD2eD6KeBTyA5KbMT6/mIEg5IXKh5m/c+3OxlGF4AA9V03iDph0yOK0rmf5Mb6Ss5AdGOjPFwhXXIRps6vLdl85CZrzYkSS0O4IOu9FNY7ddCnYPVyQ32nUQwxd wvHzhBGG 9nEoueXC+ON+v3GzlOxSR/tZ1zOyfdfiVaUm2Ew3RP/fGWEKN/JQ0urYV03j++2ivTrA/7g55mwxHx6Dh+DzUx7fUAbKp/H4qJaEtGj9UZmSG0OPMLLfuz1itDxO0lUs1X6JuD/AQ8AE4tLMUQsiF/sY6iBMQ260dkqdukAHK0QFEdgDPknXSPtiOV3gUJ6t9NYPEIaU/F0H2SfkSCK69QvQm91RXruLpT+QQPV+rK0akYgHz+Xc3bQTTpwFcLlxSNfDUNjV/pWJprn4MvZ3NNMSx9gts7u5BYqWOghHtRYrBDCL9nzwg4gKDQjxleHgL0jr7Iv6RKSpqu1Mu3cgI+xPFqYT0QzrXSDIQyEl9t9YGFio= 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: In preparation for adding sysfs ABI to toggle memmap_on_memory semantics for drivers adding memory, export the mhp_supports_memmap_on_memory() helper. This allows drivers to check if memmap_on_memory support is available before trying to request it, and display an appropriate message if it isn't available. As part of this, remove the size argument to this - with recent updates to allow memmap_on_memory for larger ranges, and the internal splitting of altmaps into respective memory blocks, the size argument is meaningless. Cc: Andrew Morton Cc: David Hildenbrand Cc: Michal Hocko Cc: Oscar Salvador Cc: Dan Williams Cc: Dave Jiang Cc: Dave Hansen Cc: Huang Ying Suggested-by: David Hildenbrand Acked-by: David Hildenbrand Signed-off-by: Vishal Verma --- include/linux/memory_hotplug.h | 6 ++++++ mm/memory_hotplug.c | 17 ++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 7d2076583494..ebc9d528f00c 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -121,6 +121,7 @@ struct mhp_params { bool mhp_range_allowed(u64 start, u64 size, bool need_mapping); struct range mhp_get_pluggable_range(bool need_mapping); +bool mhp_supports_memmap_on_memory(void); /* * Zone resizing functions @@ -262,6 +263,11 @@ static inline bool movable_node_is_enabled(void) return false; } +static bool mhp_supports_memmap_on_memory(void) +{ + return false; +} + static inline void pgdat_kswapd_lock(pg_data_t *pgdat) {} static inline void pgdat_kswapd_unlock(pg_data_t *pgdat) {} static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {} diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 926e1cfb10e9..751664c519f7 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1325,7 +1325,7 @@ static inline bool arch_supports_memmap_on_memory(unsigned long vmemmap_size) } #endif -static bool mhp_supports_memmap_on_memory(unsigned long size) +bool mhp_supports_memmap_on_memory(void) { unsigned long vmemmap_size = memory_block_memmap_size(); unsigned long memmap_pages = memory_block_memmap_on_memory_pages(); @@ -1334,17 +1334,11 @@ static bool mhp_supports_memmap_on_memory(unsigned long size) * Besides having arch support and the feature enabled at runtime, we * need a few more assumptions to hold true: * - * a) We span a single memory block: memory onlining/offlinin;g happens - * in memory block granularity. We don't want the vmemmap of online - * memory blocks to reside on offline memory blocks. In the future, - * we might want to support variable-sized memory blocks to make the - * feature more versatile. - * - * b) The vmemmap pages span complete PMDs: We don't want vmemmap code + * a) The vmemmap pages span complete PMDs: We don't want vmemmap code * to populate memory from the altmap for unrelated parts (i.e., * other memory blocks) * - * c) The vmemmap pages (and thereby the pages that will be exposed to + * b) The vmemmap pages (and thereby the pages that will be exposed to * the buddy) have to cover full pageblocks: memory onlining/offlining * code requires applicable ranges to be page-aligned, for example, to * set the migratetypes properly. @@ -1356,7 +1350,7 @@ static bool mhp_supports_memmap_on_memory(unsigned long size) * altmap as an alternative source of memory, and we do not exactly * populate a single PMD. */ - if (!mhp_memmap_on_memory() || size != memory_block_size_bytes()) + if (!mhp_memmap_on_memory()) return false; /* @@ -1379,6 +1373,7 @@ static bool mhp_supports_memmap_on_memory(unsigned long size) return arch_supports_memmap_on_memory(vmemmap_size); } +EXPORT_SYMBOL_GPL(mhp_supports_memmap_on_memory); static void __ref remove_memory_blocks_and_altmaps(u64 start, u64 size) { @@ -1512,7 +1507,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) * Self hosted memmap array */ if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) && - mhp_supports_memmap_on_memory(memory_block_size_bytes())) { + mhp_supports_memmap_on_memory()) { ret = create_altmaps_and_memory_blocks(nid, group, start, size); if (ret) goto error; From patchwork Fri Dec 15 05:25:29 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: 13494001 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 61D7EC4167D for ; Fri, 15 Dec 2023 05:25:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D1E98D0116; Fri, 15 Dec 2023 00:25:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 882DE8D0103; Fri, 15 Dec 2023 00:25:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FC7E8D0116; Fri, 15 Dec 2023 00:25:45 -0500 (EST) 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 5C2838D0103 for ; Fri, 15 Dec 2023 00:25:45 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2ECF4120C5E for ; Fri, 15 Dec 2023 05:25:45 +0000 (UTC) X-FDA: 81567915450.11.C609ED0 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf15.hostedemail.com (Postfix) with ESMTP id 8F3F7A0008 for ; Fri, 15 Dec 2023 05:25:42 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SYHz9Jah; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702617943; a=rsa-sha256; cv=none; b=1HLjDdyfaQLP3nqs6t2RYqHtqMVi+xIWtDRFyRNqbhSNIZWL1T9Fb6vO1XOE3qTmLS5pw1 SQMQKkNiD1106Zd3LXZrtz5UB3t/z1m89Z8RN1NgpWqFQ6QIwtuvUrQVcWvXa58JhCxi7T bxqfHxi0SJzQXiSYWtxSZ4BWYcFW7i4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SYHz9Jah; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 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=1702617943; 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:in-reply-to:references:references:dkim-signature; bh=ypOKwW1hPaXDtU75GzRcGaliD9n4629vuU0d5YGt1I4=; b=GAdwNcopyNZsEOVpRX5s90PjscthCOUX2n9VUIc8BZvTodVnCSsElZCQaJzlcKrr/k3olV wu8eNHVEL4m/qh2K0MIGsaITkNtdo7vdNoPkp+jCkZU4VvMKe28eOAu18o5OFmo98oZUrV smPej2RZV4HV1T0+Jt4svqLRSa3eq+U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702617943; x=1734153943; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=8AydkZIRYE6htCOriMTQ/LIKTv23UzbFF+2Jgw5CRZ8=; b=SYHz9JahnQbB+Y2xvLYuvG8mMuIqyLWYiL/SHKpSZp37Tb4QcMNggx16 ukk6+U/OzZkA8Q9D5gGEI+Oome3mD1qPZZNGlUmUMYkb00x069jyeovP8 w2Re+drG2keD2PZfGdPD4lNmIQ1rrATft9PJ6UtHbEKMo2GpZDeXBZxvD cTyFiIh1UTRdcKrUyAuXdCLdzW8lZL5X4Tt5RhqrMKI7L+Q5Xqt4IgeP7 3rgV5ftLHJy7iZ46qJpRIvR0fcHG1Szl+2pkTmp9vqTuHQnzRKn1D1zbQ kCvppaw3pp94+Xn6OrAp91k8ZKOnAl02pa9b3MXqyhbhlzguwkUtDesND w==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="461695047" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="461695047" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="808847952" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="808847952" Received: from mmtakalk-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.109.101]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:39 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 22:25:29 -0700 Subject: [PATCH v6 4/4] dax: add a sysfs knob to control memmap_on_memory behavior MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v6-4-ad900d698438@intel.com> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> In-Reply-To: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Oscar Salvador Cc: linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, David Hildenbrand , Dave Hansen , Huang Ying , Greg Kroah-Hartman , linux-mm@kvack.org, Li Zhijian , Jonathan Cameron X-Mailer: b4 0.13-dev-433a8 X-Developer-Signature: v=1; a=openpgp-sha256; l=3850; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=8AydkZIRYE6htCOriMTQ/LIKTv23UzbFF+2Jgw5CRZ8=; b=owGbwMvMwCXGf25diOft7jLG02pJDKnVjwPMrpyut8x1v9xyeMKEi/HFHefXVb0r+zd5yfV7o h28Z3iUO0pZGMS4GGTFFFn+7vnIeExuez5PYIIjzBxWJpAhDFycAjARkWpGhjNf+ITlduxj1Trv ej864P87z0kCPQrNscmyYadszWv/rWP47z0rq7qGh41zMU9LWP5txanfJ8q82v08OECBd+ldtwf VHAA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8F3F7A0008 X-Stat-Signature: rmsg83qp1zaijxib64kxf17wbik3894i X-HE-Tag: 1702617942-334064 X-HE-Meta: U2FsdGVkX1/j1a/cgBX0m8hk8JS4VtyGtCzn7pkGFU4SdmhGgig5+GEp6e3EmyPgzq8Jq2C+he8vDbvjFBRQjqtm/IlXYGDAi8ys9c+3/EZOQFX53MhcvjBuyXdS9whb3fyxqBWQ+oivvwXaWYFqRQ5BxlOMKyS7EnMaciQ4UAFeODaj4B/kgxPRPkGvkLsYFWIx/0mtOE4oTY+2iGISe4Mk101R/rkOPDyc88GZLctiCCU/Q9U+Xurf4LIKNLEsOWGY6kLfFgthy1jyrD/UF6HojJsRKNEEcLrBnE4f5+F9IW5tHHKMqh+TLzlL6iUkhjKil7GKpuAk9zm8Pha1wd/nl9vmkUE84/70OKLJuM0IOnGwj+NbJTnXZ/t+uKepSPxZFzsE4jDF4GFb1A/KL96Pvgqd/qcHeNJoWawBuIkDcNqfS9BqOCMuIh/QkTnwVLbM5sIAMlIy4gBHP05vSnWJXt0EKz2eg9KcecKEbOReux72aXVr/NQePy7XWN1UekJcAYw29/HkRy8LLHclWB35c89fG+BjUZ1nae9Uf2ang3R8lFikl5v/2GftVlfpjQAgq18BpO3fBWsx4tKKyucTIpnrI/l+Chp4hAu1Kp+6KdawAYspWELYu8HrKwKztqDHVo187YqAfe594/Vtwz2TOdtdWzDDU6+7XwTzuHAN+tmt53xcMuwZgKH6CAzYAPlqbgQVE+L5fNpNOC+k6KQ4UJogQBWRYuBt4PL/s/9ExrQxiGP5NR58KdfYD9MsHNS3RBzgOLKbFqfEJUAI8zfmSygZL/Zc84okGWxlnJy+rWneY1kR70Vw+XA9BV3Q/NGwDHEC+R6xfDvKPSbwQ12n8Jn/ImjxoDYGtom8njZMkUy3x9ywT8eMzksoDnXCkAdgQQZ17mH5qpR9DOfizndmctFdAH8kdWwjmEfjONMaBNnoHQZcVfU0EsHpNbAlM0vwwPrP1nEUXS1DqTG U4G6F1Eb n1uzFnjCNUH/6/izpn2bmykbwYwbsejYQkFJcB1Mn19y0uWAwdwWpE+fJPfQuV7dnm2bzw+iIHG0c9qo7rqCax+4P6kKIHien1I0PFR3qRnuw3LV8ChqA8k02RT2D1+XAGILnlxkTU/8+HM49bvTb3w+4/QR2rt0kM5s8u6dnxsj4pkWJw1yG4FuOe8OMC1SgpHB6NtKPmdKaPtvWhurns4P6keQ7owv1J9sim6y8UmYQzTUrWvFWgCuDql5Mtc+q0oteQBB9ZX+kiO7LA3lhkPFjiPflLVUnU2MWe13DAZyvDPco0q5c+ZCfGUCb8pNLIlMg 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: Add a sysfs knob for dax devices to control the memmap_on_memory setting if the dax device were to be hotplugged as system memory. The default memmap_on_memory setting for dax devices originating via pmem or hmem is set to 'false' - i.e. no memmap_on_memory semantics, to preserve legacy behavior. For dax devices via CXL, the default is on. The sysfs control allows the administrator to override the above defaults if needed. Cc: David Hildenbrand Cc: Dan Williams Cc: Dave Jiang Cc: Dave Hansen Cc: Huang Ying Tested-by: Li Zhijian Reviewed-by: Jonathan Cameron Reviewed-by: David Hildenbrand Signed-off-by: Vishal Verma Reviewed-by: "Huang, Ying" --- drivers/dax/bus.c | 36 +++++++++++++++++++++++++++++++++ Documentation/ABI/testing/sysfs-bus-dax | 17 ++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6226de131d17..3622b3d1c0de 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1245,6 +1245,41 @@ static ssize_t numa_node_show(struct device *dev, } static DEVICE_ATTR_RO(numa_node); +static ssize_t memmap_on_memory_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct dev_dax *dev_dax = to_dev_dax(dev); + + return sysfs_emit(buf, "%d\n", dev_dax->memmap_on_memory); +} + +static ssize_t memmap_on_memory_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct dev_dax *dev_dax = to_dev_dax(dev); + ssize_t rc; + bool val; + + rc = kstrtobool(buf, &val); + if (rc) + return rc; + + if (val == true && !mhp_supports_memmap_on_memory()) { + dev_dbg(dev, "memmap_on_memory is not available\n"); + return -EOPNOTSUPP; + } + + guard(device)(dev); + if (dev_dax->memmap_on_memory != val && dev->driver && + to_dax_drv(dev->driver)->type == DAXDRV_KMEM_TYPE) + return -EBUSY; + dev_dax->memmap_on_memory = val; + + return len; +} +static DEVICE_ATTR_RW(memmap_on_memory); + static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n) { struct device *dev = container_of(kobj, struct device, kobj); @@ -1271,6 +1306,7 @@ static struct attribute *dev_dax_attributes[] = { &dev_attr_align.attr, &dev_attr_resource.attr, &dev_attr_numa_node.attr, + &dev_attr_memmap_on_memory.attr, NULL, }; diff --git a/Documentation/ABI/testing/sysfs-bus-dax b/Documentation/ABI/testing/sysfs-bus-dax index 6359f7bc9bf4..b34266bfae49 100644 --- a/Documentation/ABI/testing/sysfs-bus-dax +++ b/Documentation/ABI/testing/sysfs-bus-dax @@ -134,3 +134,20 @@ KernelVersion: v5.1 Contact: nvdimm@lists.linux.dev Description: (RO) The id attribute indicates the region id of a dax region. + +What: /sys/bus/dax/devices/daxX.Y/memmap_on_memory +Date: January, 2024 +KernelVersion: v6.8 +Contact: nvdimm@lists.linux.dev +Description: + (RW) Control the memmap_on_memory setting if the dax device + were to be hotplugged as system memory. This determines whether + the 'altmap' for the hotplugged memory will be placed on the + device being hotplugged (memmap_on_memory=1) or if it will be + placed on regular memory (memmap_on_memory=0). This attribute + must be set before the device is handed over to the 'kmem' + driver (i.e. hotplugged into system-ram). Additionally, this + depends on CONFIG_MHP_MEMMAP_ON_MEMORY, and a globally enabled + memmap_on_memory parameter for memory_hotplug. This is + typically set on the kernel command line - + memory_hotplug.memmap_on_memory set to 'true' or 'force'."