From patchwork Thu Dec 14 07:37:54 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: 13492508 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 E92AAC4332F for ; Thu, 14 Dec 2023 07:38:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF59A8D009F; Thu, 14 Dec 2023 02:38:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA4EF8D009C; Thu, 14 Dec 2023 02:38:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96D6E8D009F; Thu, 14 Dec 2023 02:38:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 876A88D009C for ; Thu, 14 Dec 2023 02:38:18 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4B205140C68 for ; Thu, 14 Dec 2023 07:38:18 +0000 (UTC) X-FDA: 81564620676.03.AF66FA9 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by imf13.hostedemail.com (Postfix) with ESMTP id BE89020011 for ; Thu, 14 Dec 2023 07:38:15 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GxR21Dzn; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf13.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=1702539496; 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=jQfUFx5CSM+iDeoQ8rWNyIQ8Un9bdk9ChlrOpSokRsv5rcZpNDS7RtHV2eAthlevyFK374 96b3Ggr8hEWbMddRQSKMCJ/mpOCvuShwGYx6fbFJivrXfWLstRT2njAmKQKpFEf4XAPkdU kyWWvd1mAyPAHU8fPUN3S+zGm5H1P6I= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GxR21Dzn; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf13.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=1702539496; a=rsa-sha256; cv=none; b=WCdA9Q99Vv6QJBHA8ey6dX1j3sYP5rIUtGp973TW8URt6VmDze/UUz0ejI6x6dyvtyhLAU X1XeKKd726pLhOZ4U6nCDTB3qZhzpPTQkGkQT0lYEXXJLeCHBg+zTUd4Aar0eWr9EaWqNm t7jw92VB2+A6qGSwYViTpI/dKCxYbzg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702539496; x=1734075496; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=s2pn4yZl0XYTp65Nn5lvuI7n/QI1GItpUEXHrwpjM9A=; b=GxR21DznRlBoXJ4Z+Ja1F583bzV5w42yC6ALIHFYcA0oiMau+CaGQrj8 uTnFhb1VIqu45/t5pSbyrROf4sAhAAxxxarXlV78KpxYfceR1zJwRbTbc nR7HD1pezsGFr0FCRzJfzgLe3zE98QygoCIigtC2O6+K8U++voyBZRcko LChRp0tlc+V5J6wWwoT61vJPlJ6WOdEhD5y1o8Y4jZXxuvC0Jcab4h3gr zLFiFWPc833zv4e02NBA15Xq+RJvuhynsfY1McL5o95+e3kYidZ+8kN7g BMWfNA6GG89se/ZTRVDUs+RNr9gzhvCuynipe1Cv9S8qrpKo/hVSko6/H A==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="481275514" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="481275514" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="723972059" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="723972059" Received: from llblake-mobl1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.213.191.124]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:11 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 00:37:54 -0700 Subject: [PATCH v5 1/4] Documentatiion/ABI: Add ABI documentation for sys-bus-dax MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v5-1-3f7b006960b4@intel.com> References: <20231214-vv-dax_abi-v5-0-3f7b006960b4@intel.com> In-Reply-To: <20231214-vv-dax_abi-v5-0-3f7b006960b4@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=owGbwMvMwCXGf25diOft7jLG02pJDKlVGx4VxXeVLzrzw/Rzevi5Y9KH3GbOf7RvZum9o3Ouq E1sv6TV21HKwiDGxSArpsjyd89HxmNy2/N5AhMcYeawMoEMYeDiFICJ2Isx/OHn+2U8ea3O/vwu Tesphzmq5lYYaJ1peJkQ9+FcOvPT7GhGhs2HTzq8qm+IF3kimLko9v/0y/bhllrfTy0IN5ZJ/lB 7hQsA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: BE89020011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 7mqfw5yspabx6d17r36fbir93fs35cs9 X-HE-Tag: 1702539495-136472 X-HE-Meta: U2FsdGVkX19+cm6liGzcFnx7QdWZdnjWKiiMvmEu5KZC1/OcRXaoY1A7gfxnwGj5+vCbLXbyCU2ryxiSQR3irzLJR6JFoxk26ddAZKJyqh6RmYcZ3kP/VbifepZt3gcbz31NC0st4ldzz/Nz4V+O1Wmo6WUCTpSYrO76MGgnhEu/Tkjpis9A/CFoHoITKyoT92TmsOl+JJ1f+uDlRwf3NPFri6EID97UunI72w7XbaUvSuj3JfJoCa0L/7AxLI+Ynqn7rJQEcXp1M2Ch8R1BpWj22zm+Pb5Y104qVRnb31APxYh4hLbUSj2Vs+s2utMWIdMQLQYtrq4eZvG81ya6xUPbFCRbC7DYPiAOIRGeKd2qxM6luqwPIZhAypGxOQwDTVgqaaUPT1Oqsp1Rw/OXCeFxb0Zvli6Px+4IfJwpqPICxA5xcSHgxPA4JpB8QBhahQvRDV7voEOevjGitCz8r/sMFeH9IPUm9tAhE1Ne1eucP/Psxdd346I5ANz1XOXPYmAyoGF66JftAEf19y+eGutDGUdhI9a+hurcr+GYXD2qCyuCfHxrrb9yZCZA2KERwiJW+wMavq6Y03JU8aOLtSZeGWbcI2tsfnHBrYAcpCdEMK75/uaILYCIyCT/N/oAC8AxmzFq+pNwYXJTyAkhHYDGku1fBZN0KGM7UPR/DLVmOwvWH1edxD4/mN6BYFHYIe/mXH9Pj9/x87qtaMIlub5uhclhDnGePsLN5neRypd6BZO+eXX+L7JvvAJZhvTdcKoCNYgSPou9END+f83Kauuw6gDsQ49gZsujuCMJgtYYu1sYp5UjWKJOxBVGs836qF/+KubKaLNbZMqIiz5xV9CudCrxnELS+wem+YP1Ztq07t88KuoP7QDr2CRbN5iONov0jSehuqw2fWGeVTXbGgqRjo0JHP4TNVXNrbO6WhaCGHBeuCstEwygqo0e4u+tGR58zEJBRZSF8WTGlW3 2JpbDhkL kYfLJcdlaES1UVDImLRh98N58bxwFzQGvG0WHI9kAyD/Ie7N7Hvm965blC/Sz4huGgXpxvAjUDsPSapnZQwAsxrFptvHwE7HccC7S3yY3gXte+ACG6p4KZYYq9Kj8BSQSMOB7TqYcwKmCWQzyGXJOMkZVMwR3r0aQwb4oX9myzp4w9q2TDtB/r8WuL8aHCyKlfgBf 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 Thu Dec 14 07:37:55 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: 13492509 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 6451FC4167B for ; Thu, 14 Dec 2023 07:38:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7C178D00A0; Thu, 14 Dec 2023 02:38:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C2B7E8D009C; Thu, 14 Dec 2023 02:38:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA5808D00A0; Thu, 14 Dec 2023 02:38:19 -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 986D48D009C for ; Thu, 14 Dec 2023 02:38:19 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 65F9F404CF for ; Thu, 14 Dec 2023 07:38:19 +0000 (UTC) X-FDA: 81564620718.29.7767878 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by imf28.hostedemail.com (Postfix) with ESMTP id 41014C0015 for ; Thu, 14 Dec 2023 07:38:17 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QPcGYiaA; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.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=1702539497; 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=z9mIUZljZOntghzSqdBJFEnWJfQqlfI3T2wdLpBzyBW2Tm7XsJEOZ2YQ2IXjj6IIN+xr1T WnJGIsgJesXvA9sypowKZtn0pKpDJcoRKGhaSOwPhVJ+57cGzPDtrL7fLjkT1a/DPbW7oF vv6EeREBhqC1GMGDzFaIoWWFxNY1oX4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QPcGYiaA; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.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=1702539497; a=rsa-sha256; cv=none; b=rw+VUIIi0NGpCGhMyEc9W6XTuHGpFnBMp+SFLppx+Ui8DvZ0le1yaE2D7FRFz9h0EAFMD9 HNZuaufYVMxflMLj3E7fjCBlvrRwUJ4FLo6qW8Yw395ypKPwI97BAGmTKalAy9SReqnLMV FrMVJVBNL4A+2UfG42heka+mAaplWb4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702539497; x=1734075497; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=g9l8RslOMp5ad/gXCRHw+j360xuk1nb3+acdwFrlL50=; b=QPcGYiaANOEb+k3o+l0av37H90eT1ABCPApchs1dnLeC/HCfcim+IZn7 LiostB7pyxnfCnhbSojujYTv1GghTCv3JJQ/Vws+gUyiSvtATHT14gm51 6yNWS6OFmr5Ble6RFvMTKL2jfpKGpWmdWi1aYPvR49HnU+iO+Yaj4cTpt w7v8VO2hZ5PO6WhKTntf31jS2ae2jHZmnxNYrwt4NSkDB0xx57wN0RXjP khVhuFnPvn2iU1HPm+hXYa/JKpgkMTqmdM5LW+nVOrApAqjWOAZ4aV8gU FkCfSbr1ZSQlTYoSRisxzvp1ITzJb3pipfiyFWinrvbZd0DyUlSFxpPdg Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="481275524" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="481275524" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="723972064" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="723972064" Received: from llblake-mobl1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.213.191.124]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:12 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 00:37:55 -0700 Subject: [PATCH v5 2/4] dax/bus: Use guard(device) in sysfs attribute helpers MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v5-2-3f7b006960b4@intel.com> References: <20231214-vv-dax_abi-v5-0-3f7b006960b4@intel.com> In-Reply-To: <20231214-vv-dax_abi-v5-0-3f7b006960b4@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=owGbwMvMwCXGf25diOft7jLG02pJDKlVGx4ZxJv18x/TfPRo6pLQrU05Fp3PElasO7C0qM1kr 5tHY3xlRykLgxgXg6yYIsvfPR8Zj8ltz+cJTHCEmcPKBDKEgYtTACZySoGRoZ9jz78FO0WOfBHN z7hkJdKzWZrxycoHdT8NjQSDuFZGHmZk+Kn/VmUD14viH/ymS1fZFjwx1PJr9J8nFCC9Yf3cLpa H7AA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspam-User: X-Stat-Signature: x1zqdfxt3qm4r8pdw7opar9rzhtkrsos X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 41014C0015 X-HE-Tag: 1702539497-930383 X-HE-Meta: U2FsdGVkX18uM2pGorDFAjOxRVfLzpqQBdprLFZ+gx0DCQ1XS/9P1ESix6mH7NDPmNJwZ7zTkP8wSwMWO1Vl+EHiWPWgdohLWBTpHegugWIqOi3jKwVRLh/iP6k9ntKqIfdxCPTxm1+eZbhEPKp+7MtC18c0XI2jpdHimwbPoX0AynHi90E/dW1ABzLFFPBEdlKMHTPSHjEZBU1EOZshDfBRVhq+4hI63hDI9gjPxmUM41yXESbpGKM3uakKGoNqaU7gXNYJKN3LKiU6gvho9ZzeUy0Ug+X5JwKIzsyuVjL/x4Su4yVbDpQuwEZ35+SjLUBZxyiIHxHvHriNF5B2sp7vXzIERCwkDoDMwOoC9YJYbcBKFNxkvvlRAzQdd2ObQnzlyTcdV9zAVv3r1pyw+H4rvrGGcsKJX4yszopK1sO2ML/LfHHxJT0ufKS95OY7mAbLcA53UPu7OdXafYhDfnUvdtHWQ0I4hJh0CskIdWUC1d1RfrYtdduvVGo43GtGl4C5sVg9ysAiUJbb11vPnd7NFBAIfYtGJ/RBv0gUlos3OsvzgRMukQoUS0ys/+fLG5/UL6xIiPcFq1WuFvpRyv2Ja+r6+W4thiCpkq9Da5JogXni0U/Y1orqbi7OS1vBetBE05OV2XOBjdsQFM5+zirH7PJLzYtYqL0QYtp7m4XC54L3bN7FL27i4mMICzQ+nH+KdoPrvbHDAEQuPthVYuK0zxBIFTkwD6JeEon5PLkCID/ZlFhcUM+nwsAgs6rfyENa1D44o5vsPTcZQwbLjgHLUMjcBqUS1lB+E7WA6t1pPSVjf/Sp6r/rvI64nP3ZtI3GfBFu/J+RkQEA+Nm9IBfSLHVIhusYhpm8GoIrlrYXGPkzx9cIJ2ahw3s5uU0moKV9rB6bAQoizjRrqPjg1prrbUvX3puYTjkucwZNFasiEtgPgJ1B5lqgZNsf59i2GJWyPLP9qf0fOvVCtQ2 275f//bO MbEIS3WUhkJCP3qWnl2mbx+iWYDPZTlX0YwrpYAAiiTpQwtSM/9mmjeg/o5xK8IpYXTnu/UiPMAZ3/hlIU03G6nd/yNJ4dS1bueMDRvIkenKNJx/vYqZ9twO4+D5yUBIHTNk3xd5E1tRiC221cccYd6wy31uJU60pu86gE72obi6Z/jxphTftLBPjDeLFPlWBEYY4 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 --- 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 Thu Dec 14 07:37:56 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: 13492511 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 3ECC6C4167B for ; Thu, 14 Dec 2023 07:38:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8ACFB8D009C; Thu, 14 Dec 2023 02:38:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85D5C8D00A2; Thu, 14 Dec 2023 02:38:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D5418D009C; Thu, 14 Dec 2023 02:38: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 480AA8D00A2 for ; Thu, 14 Dec 2023 02:38:21 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 162041C0BFC for ; Thu, 14 Dec 2023 07:38:21 +0000 (UTC) X-FDA: 81564620802.24.06EE2F2 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by imf22.hostedemail.com (Postfix) with ESMTP id C5F95C000F for ; Thu, 14 Dec 2023 07:38:17 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LGBGch3u; spf=pass (imf22.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.43 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=1702539498; 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=fh20T2gB/B6w0dTGtnuH7g/9myiyWlxtGzmDSKX8rWg=; b=ByTkcdKbV8dZC+ZkvsxsnoYLBpmANPBrsVF8mSN/OeioAoB6P/yPnnwFlDo6kLEwP8jegx m3AAlr0jmjqJR0obrZGIjq1jXHeviyZLF/4tbdgqboAwddULLoG3n4ADWUtxyrRjcdx79e Pmf17mtkNYAU5qGooxp2XdnxV/EAwSA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702539498; a=rsa-sha256; cv=none; b=eR2V00VjF9adS2Dmesa+qFuG2GLqeO2KxjINw+LDnGkhVTPfCcpx4WwXEHisAK8oUvpWEn QOgI55nDGTBD0HeAGCsB2TxtR9EjB09niFhSPYfvOnuJPbR4P5Ud0ca/JH+lcClsg4ZUzG zR5pBrEPXVadKyhbEWKagMnFVKwww7U= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LGBGch3u; spf=pass (imf22.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.43 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=1702539497; x=1734075497; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=VTyAcMOb3p9TMnLFpPQVGZqQ3IoF/IW/eEzVelz5aSE=; b=LGBGch3u/EkEEHUb2MISE+BMie8tv3gt0yzIiaTLxo2gywL1EDPERoEt 2ml1I1ev1M05jr8MQV+x2SaxA8qq5klEA66D8rW5yun0YPHsFTEJqCQA7 Sf4kdAEGGuxEFdJv5oaCUhREwrZvrEaFuJECAiEsGZbJ3YCs+Urbx7AVH xhCizd7yz17XAvzJFyv9enX0UcOWzPguAkeuLf5wDEx+wrE8QBNBG6r14 b/fT9toBaTICfQJ4ew6+m5Vk0ddrPyOpJk7MfUvaRZ69pfoBSLue2Udev W1OIStQQXhqRvkSDDrQRLdNn9KJCnpWBJcU6/C5eg+4Vs22oX7LVSEv8t A==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="481275532" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="481275532" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="723972068" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="723972068" Received: from llblake-mobl1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.213.191.124]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:13 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 00:37:56 -0700 Subject: [PATCH v5 3/4] mm/memory_hotplug: export mhp_supports_memmap_on_memory() MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v5-3-3f7b006960b4@intel.com> References: <20231214-vv-dax_abi-v5-0-3f7b006960b4@intel.com> In-Reply-To: <20231214-vv-dax_abi-v5-0-3f7b006960b4@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=4625; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=VTyAcMOb3p9TMnLFpPQVGZqQ3IoF/IW/eEzVelz5aSE=; b=owGbwMvMwCXGf25diOft7jLG02pJDKlVGx4pb98Uu1/qmbru9H/PH6bM1J0/7UV3iMK//UUCo ZtfqC/k7ihlYRDjYpAVU2T5u+cj4zG57fk8gQmOMHNYmUCGMHBxCsBEUiMYGVbuX/Wr9FcXs9aM oDlX6jRyr1fI/1s065G+YX6fQ+ehP6sYGV4/iDWrnHaq9Xa2THW3oGnTxgemL7ds3qmhVXMi5Nu BHB4A X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: C5F95C000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 4j6ojmkizfcmz9jm3ubkk9z5xdc5jjiq X-HE-Tag: 1702539497-821046 X-HE-Meta: U2FsdGVkX19ehw1Tdn+SlICZ9mvcW6na2hZF9KRTSefEq/pvXS7Us2Mw1Fi1QAKZes+9sik6q+YKk2igQNz0tUdwsuaMeqjE0vVVvgnzsZgFW79doT4TWJVurw+ZaErNJjvv9PqgdFmNc6r2vPjc7iBSxAYet1F8FpyWssVc4Ox3Y492WqwT3lMcyEs1ydFbcwjzPNIb4XbbkrMBbf0Dra/DIQNO+l/vYoMFTmgES9GBydARmuIdfGIfmFtz9wLOC4DamheDDTzd1g0l9/oCc2MtR4F8HgOzKYVldUvlAfOi2AEfdNNoPzb7McIIvVEfVDHQSRbw9p92Jv/MPqraDDM2iirNrWbptNQdKYFpOMzlddAAESwnr8kOhihEC875aQVGwF5UwD1H1MgcsUgbhi8U8HfMj+u4jOTMfFKtEevDhsfwdyv05OwkHFGoNsz0NNuX6X4cew1NeR1OfbUF9JxnR7JARrJcNhpqcCtssHtBiVm+A6+urr2nPN8ZY6eFK760dNgXUHagP2uxip1xi+8nyRfs56aXEqKjlM0DEnpFrWGGHh2yzGVyaL/rJDm1L9OUQQl6uWlrWMNazXCGrI5X1UX0C4kyX8ThCZkZqNk5f2GxE3OSqiFR2xdZ3RLtLN9jtk93TNAaEI9EUhKIkFgtqrbACfkvDtXI7ZV24Zj8y8VPgruZjXHf+/QLfgODm1HCJZMEy/bzwGwtRy00Z037oIduEm0Ulpjoayyy7MdrWoyeWNYPBg/I2wLRLtvFRfBGQVeOvsm8IQsbXoQoGoN9XL/y8RtXqqo+u2FdkYNCAGbHromd1l8hjiP4yRlakYzrbdpKjdA6iDv/rwKozo6Ak8e0aADUSG7RvdBdSiZBOWT2Z6IVoMGY2dhl3mz5dAbQdJUJfp6vTp8j7RQzPE7wNQC3/Ni6jXx0oJF7PKz51Mu9xikDT0oqShQWek24f2Kh69zaMMmFIijo1Fp E+jSLbX3 5Ic+1YIlNIX6Qm9mHZqek5vPlOEBDQBT+LOW5/g5XjSXWWG1accLE9Y9/OfC3QlwLnQcbyfSynjIVl2HNWPxLNWD5/lzlMbW4d/ObMV/5ZHaRLPBR+uDMXvGzc20M5N1Ppte7l1UYzXjY1Lu4l2RXv1didMdIgJfllELTng/aLUujLxPu1iqvDTvQiR6H/+ZF9Fo3d/nmkh7EoqutMv1wNKLQVDfPDTAhm79t/1IZpyjRcdyF92Z5kDH9upizOLcv2L3Q2TQs7JhglzRk/jAgmpDYcZI9N/KqprujRUPXRs55JMbz7p6pyZzn1sP/GI9iDwK8VecSAOYdqeRdjJSbptBrS3LV2/TcS8pH 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 Signed-off-by: Vishal Verma Acked-by: David Hildenbrand --- 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 Thu Dec 14 07:37:57 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: 13492510 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 1C3F7C4167D for ; Thu, 14 Dec 2023 07:38:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32E9D8D00A1; Thu, 14 Dec 2023 02:38:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B6D18D009C; Thu, 14 Dec 2023 02:38:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10ADC8D00A1; Thu, 14 Dec 2023 02:38:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ED5678D009C for ; Thu, 14 Dec 2023 02:38:20 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BBB1AC0BE2 for ; Thu, 14 Dec 2023 07:38:20 +0000 (UTC) X-FDA: 81564620760.19.B39562D Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by imf13.hostedemail.com (Postfix) with ESMTP id 8F6332000D for ; Thu, 14 Dec 2023 07:38:18 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FjsXBDTB; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf13.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=1702539498; 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=iZ2C1C0RLSlpkRpvJ4e2k5gM3EbrzqAt/DPxuK5hvD4=; b=RDjfjOdGtiQ09xafdYXYcwRkA11YSHfBF72webTEIJxG58RB++JrT//T2l8HdFW0Z3AGq3 qYs34XsPuoxayxiVaodRKMDZZtqsToD6cddTKvYVnMjmDoX23B+cLkZ0AHVpfhk6NRVMez BU6+Y/9JnCGSuOITN+MWJ7xU07tWeC0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FjsXBDTB; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf13.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=1702539498; a=rsa-sha256; cv=none; b=Z48vhdNHKyXdudAjwDyhxkWf0zH2wukKK2FaeDsxlrKyJsFSl5QBH+slmx2cdFo9rVPknx 9tg45ZHacs+dupLe7Q+VSM+fDrmoNCPs/9w4oUlh1JbFn8MyAmaoRFw4+4jz7wX1cPyRcg QjxxiqraARMjw5ttJLf0onUnX0sFsZM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702539498; x=1734075498; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=jYMqTdWolji6J2rYKSsSVwH7OXLij+oakPFuQznWwJY=; b=FjsXBDTBFLYZIHtD2tdahDN+ctzcZftAkBPbO6YC9HsN9n4BZJQf8z+i RRQJakWk2OkRESG2mBDRbLw01Ntk4MV4j7CU7rcNIX452rAxBWyROeDmB pd7Fd2pQnR3sfPN879mLXOBavp0lzzdVFJoBoxRc506P8fFlF7FQ08lIm NSKDCXcUZslpcg0Fhm6mgEUU28PtYyDDsZiwh6Vnt/oXptpNmyna505rJ BYhq3qROLmRoOvx1glJp/cEWExHv2MMA4EuxX0tJ/saOvSFALNvctSlKE tclMvgQiOqU1RwsfMs2yWnJ4CzkzJUVc9VK49YM7dlD0ormRlmbOxyGjS Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="481275543" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="481275543" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="723972075" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="723972075" Received: from llblake-mobl1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.213.191.124]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:14 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 00:37:57 -0700 Subject: [PATCH v5 4/4] dax: add a sysfs knob to control memmap_on_memory behavior MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v5-4-3f7b006960b4@intel.com> References: <20231214-vv-dax_abi-v5-0-3f7b006960b4@intel.com> In-Reply-To: <20231214-vv-dax_abi-v5-0-3f7b006960b4@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=3902; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=jYMqTdWolji6J2rYKSsSVwH7OXLij+oakPFuQznWwJY=; b=owGbwMvMwCXGf25diOft7jLG02pJDKlVGx4xGLwMeT8h+dTH8ILmoEoW649mq5eJfrI008iZd dHkQLRRRykLgxgXg6yYIsvfPR8Zj8ltz+cJTHCEmcPKBDaEi1MAJhKYxsgw/8ehpzXc1V8u7tt1 7WqTeHdgvEtK+ZM+7val85Qn6ao7MjLsucZTNdV7da/OS+73H804o1XEmnZ7n/p5accFhRezdDU 4AA== X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: 8F6332000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: p5kfg99szg4fnykt8tx5ntnowwpb8wdz X-HE-Tag: 1702539498-303859 X-HE-Meta: U2FsdGVkX18XgG06UX2mh3doeDRwN53zvM4/acWwDoPpzf3olwZpvcQxny5AnB5FndKdVaM16QNQHgGGpkYPuJnpMWWwsSQid00asJQBujz/ekdVPyN6E83rTHtIX8ej9tNMhMPcAsU1SmzDhK10l8vikudUP8xicrNI0t3tI8BRl7EdfH4w0QqSEz/urYNkX4unxXux02G/hPlsi3YYKH8T5yh6THZE4gR3EbGmQoEOG6V1SRatmwjGfzWX5G8a5j62XYX1S6E0YvdIIyixSj/eAhbq99j/IhyHeKo7IR2CiPkkG5j5vlTgdUNC2cTY3I6x1TyQdAOgef+gwbYwf8jLGsoMNF1lvyY2VMEnB+QsVGYHh5c7ktH+OFSc9b5ZwBv+5quWdyQ8+y3/QoWUAvbwbCUKGU1rfP952DuwKbkK5SKXRerTeSCrN2cEf+E1CssJ7Zz18afkINukBJd7DzQwNWWK7bj6QluqfIs61k7MoElxMJ4EknoeOzgElfK81ZXEIMvEfQ3RWoDrbBYL69ofxfdpEp/Amb6CBZfd7zC9xYAz5hedUvrtMKfMjigXAhsNSuk1J3wy/kjh6S1qxSWJovIwdJu0X/ZrYFmvKPp36FQKo51UidwY2sXA0fbyclT4CdR5SRL9Qrp+YVm4PPfTb4japryAQHBtj/b1DE9QZagtc3pDwkEXecD2BoZLGFGbtuAuIwfD38kgOYOPtRwvhTkMjB3kypIR712KTQqpwvmkoQBZD/uUPyRopPuCZ8FE8GLqx/Cuim/9N1wg9gaVim6UfC49iXxQr24gG4iFPMVxZmB/iEjz6s7Dc34pcUl59QI/NCcwLGqpSwcst/KfL5DTWEN9riCYmu5IHgQ5Tf7LQS2wRgqd144yzFmhBhN1WSdd2fuV5dKKNFWf974p/L3+vE9nwMrNC5vKwlIpXs0IgQy+ZaEVSm+bNrhBV/Nq96UNHXEccqDXsB/ DeRZHsAS lISJVeOljpROy0OXs3q5r01Oj0jlxscB3R6zByZ73VVFZI0YfFaDd+ftrQmq2ZrrdW3IHntyU3B9W2heennncGWaJGrLltPgJWLHhW0RC58p8d2QQEiIrLD1Cak84i6McZmxqhp+x6Q3Gb3aaR8aNMoeilmcyo6QryGnxD8Pt7tX8ED6P4pxEZRoQLa7neO9dXdLzJC4hu4gdFj/7RuUxv2bl31it6wMVkAvVvy8rDnXw5AMpO/y6BjNkRANbxAPzRTRsWipJctHJmm4mVYKS1mwh0XVmhlvXQFnQsxTc5b16o/bTQuXAC9Cz9g== 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 --- drivers/dax/bus.c | 38 +++++++++++++++++++++++++++++++++ Documentation/ABI/testing/sysfs-bus-dax | 17 +++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6226de131d17..f4d3beec507c 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1245,6 +1245,43 @@ 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 sprintf(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); + struct dax_device_driver *dax_drv; + 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); + dax_drv = to_dax_drv(dev->driver); + if (dax_drv && dev_dax->memmap_on_memory != val && + dax_drv->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 +1308,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..40d9965733b2 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: October, 2023 +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'."