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: 179037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9055949dys; Thu, 14 Dec 2023 21:27:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEhnFm/n5LuGm0UrKWClDMLEEyh3EIBGsYXEui7wg7DMz9OEtDEngqJpUnzkKhH46wUVZ+ X-Received: by 2002:a17:902:6f16:b0:1d3:66ba:454d with SMTP id w22-20020a1709026f1600b001d366ba454dmr2317275plk.4.1702618036520; Thu, 14 Dec 2023 21:27:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702618036; cv=none; d=google.com; s=arc-20160816; b=fv1tt9t4wMSydd51toeW7hK6MdjaOHy7kGLnJdasYjQCfSMQz5+gtibK60kgtrdwMg cRF/plHgjuhiwbNBk+Fo2wX8+3jwtdovks7RnW83Dcbe+Y7w4z3n5Oy/vrykrZcE3AM5 cdAJ9UtELDDKbPa5j8bR6F1bOJHmu56iICMjmdnSdW+u2b3mr6o4JpFuUHY1QvBtAvas 3zTY/JDZ0Km8kIpn0/akdfNC+n/gi+XKmAjW6Wr3yMaYPYC/R4J/F/r5LsVXEg3uTPCZ kOQBJYgBYE79kK1LHuwl+sb6eABibVU06VEJD7EGPQBRcBndKjtp20FTgTbA/5id4+eq q6WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=ypOKwW1hPaXDtU75GzRcGaliD9n4629vuU0d5YGt1I4=; fh=W5PgHD4oq/kXUq62l3dls1PwFvusEGE3FnZhfx8GmxI=; b=u25V6XtLqj7pelSSTGxt6y+cVY7/kMWu44KKskwzhEPscNQYVnX1zzkVWynuwNByan e3PUSvAZUJJgMPJV21Aqz3o6kFh3etfTdEByXmMJix0T+F8RnmrYBDmMmcqqzhGDWXvd 9vT0gWHeRIkgnBaL++F2OIAoa/WlbqtIF3M7ZAD/m6vMcB6vwkJG5zE/TLQotFm0u6R/ PMsVSdonjYQz+PYfSGeLsmdXwHSm3/b87aZDehhQvhlwuPdFkJNxOaYzJm2n+e97rTyp tFj4BDN2MM2XFYSaHejZJsDxXdrYgJ4V9C+lkOfqb2rAmajYI7dZMl035UUEw1vE6UXl Wn9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O15cn6OX; spf=pass (google.com: domain of linux-kernel+bounces-447-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-447-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c9-20020a170902d48900b001d3766085a1si1496511plg.564.2023.12.14.21.27.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 21:27:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-447-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O15cn6OX; spf=pass (google.com: domain of linux-kernel+bounces-447-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-447-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 64B75B223B9 for ; Fri, 15 Dec 2023 05:27:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C17B610A16; Fri, 15 Dec 2023 05:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="O15cn6OX" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D1056FC6; Fri, 15 Dec 2023 05:25:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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=8AydkZIRYE6htCOriMTQ/LIKTv23UzbFF+2Jgw5CRZ8=; b=O15cn6OXNfftlH1/lrTND8psms4TDZQ6AZEHIMHNypaQESwqeDHK5PZk BSFQlBBWN2I1gSpftccfLAuAUw5wBqtXx6rXIAkPJRqQdscsrGhoqgc00 t1ycealMa8uf2QYkHq7/w5LdhLjdB9uDnnpBmnUTc1RdOktfnlAy9csSz /vbsHLmp3JX7XErycPdGdDhpoflGIy2xaIiPk+erDsNVNzX539ml4o7Nc sjaI1KV5kUpSftkR0vsaCnj4yiqqb2gTdSvAvdE16CGkg/kDI/NtN7PDu 3KVxkLuNn5lG/ruj4KuQUAnUOWqIgWcM4jlppeUK+Z4ZxBYmuvnxXgbq1 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="461695041" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="461695041" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785324410228966606 X-GMAIL-MSGID: 1785324410228966606 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'."