Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6458717rdb; Thu, 14 Dec 2023 21:26:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqvobL9iR+iaKUHFTgGkHDcLgJWDcrxO5Q3R58tOBAkOUN5o+u21rnMi1H5HfM848yArw3 X-Received: by 2002:a05:6a20:5656:b0:187:7761:6155 with SMTP id is22-20020a056a20565600b0018777616155mr12848561pzc.55.1702618009483; Thu, 14 Dec 2023 21:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702618009; cv=none; d=google.com; s=arc-20160816; b=e3gWMvQVcqHoU691jRdbS3Czin6u4+DzOq+hBb7KDi6FSyl5V6i3Vul2pbh6L9DRZf 8ho8Ur9wYDH3BXOZGHl8ao0IXy57C/kG5iCOK5vnggralHKsraMgNwwTZrlU6tQip84e zvS3DbJr18s6RuSiMWsK9kYE+oSlWoZtizayrhQjci9/0FHMW9zYoznhdf3fBAO47t/q WneLoz3hd5rJ0mPpe/3bpo6jHmUywewdtRRq/HEs3GQqmO0pJJd36C6yyBu2ndOBqefY yEeo7UVkUHKlm1RO7jt1lZnQHHeA+SDHRdJfJNCxoZaclAdVb/i1hTADzlzDkeIMN+5z R96Q== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-447-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id kq8-20020a056a004b0800b006cb6e6a740fsi12162700pfb.74.2023.12.14.21.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 21:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-447-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-447-linux.lists.archive=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 A5508B223E7 for ; Fri, 15 Dec 2023 05:26:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA9EA101C4; Fri, 15 Dec 2023 05:25:43 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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 | 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'." -- 2.41.0