Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2090964rdb; Thu, 7 Dec 2023 19:16:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEth83zDlYWNfOdw5DkkIcLkSFUx6XRgqKv3LWNB++eb3rGyIkpCWCnAQXOMLYUM78ssxWN X-Received: by 2002:a17:903:2342:b0:1d0:700b:3f78 with SMTP id c2-20020a170903234200b001d0700b3f78mr337095plh.50.1702005399393; Thu, 07 Dec 2023 19:16:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702005399; cv=none; d=google.com; s=arc-20160816; b=DX8fb4dv0Qnm+W/jf5MLkTaCmm38MlRwjcpBW4XlRTdREgbD53D0ZWYk0xar5fzTzB 97n/E5G+PaZHhRW6xCwyQgLJUVpUUVIEw0rx2ZMn4uQ/lsEED8gNQT3KVDgzHB6s9cTY VLZcdR6KkkZ+4xbK5sXI32xQftub1wTNxWuu4UPTKkdnZkTYwBjZyrBAg6phjhoMD61r 39ZNa4qt2hAzriJMafua7VA5WDDxeRUgv6uMsBfrTqaIhm/OzczyItuwMpvF8hX4oAQd idBSWCHAIrB03Yj2EA9VgTfzxEEgU+FOy5LqVkDe/wcub4WcLMuCKJ+923d4drEFIx9c vZJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=LimBJgMg9ZVqRaXI/dlfvREg1CK5/039MXlYJJPmPOo=; fh=TuqThuxbPuUMcEZZSYJfb9K/mB9qstfci0OljHGx95c=; b=XfkM/6e8COuOe7YSD/ofA+U1LAIEWkuDCxgsqzwk0/l6nQ9IoTuYjEOZRapt0h3CYN XLBOPP8Vzybgq4B0qE+E0nJlZDe6yDgkenuolC+gOtOmlSkMtmJ+yPcbbPUm61y7sSVe hK4yuwZmxo51hEJy6uUf3r8SICuJUJ/6CM/pqZ3/4LeY8MOhx+BSZzWjvHEIskGuAX7k rvyxFyTWLfncheQtOvn37KXq1Q4QxF/kSdLfre0B65pI/wkKQ92oanDflF3yUa+5Pt+u w4vBr9E8eJj0GhI2O+09aDZ68jz74+v8Qkm0n19I62w9c9I3hCNiC13R+Ns+uG1QPzPn 7wyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VKEB1lY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id p9-20020a1709027ec900b001d00ed1187fsi795276plb.116.2023.12.07.19.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 19:16:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VKEB1lY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1678F803B724; Thu, 7 Dec 2023 19:15:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbjLHDPb (ORCPT + 99 others); Thu, 7 Dec 2023 22:15:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573050AbjLHDP3 (ORCPT ); Thu, 7 Dec 2023 22:15:29 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E53D10CA; Thu, 7 Dec 2023 19:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702005335; x=1733541335; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=E1JJBuiYZ1Cuzr0elmDVx0oyEbdNnlyFecjP6yNQEvM=; b=VKEB1lY4i5jj6OlktfLpMWpLT9i86NSNM5K6Flenf0UIxM+zdIkP9NN2 h4rxis4OOO4MO5DNoklo1fgf4ann81L2elcRHr8/xQnTYkSYZ70mv6ZAc XvJaXY5/k/PyPfiA+MYyToJmZgVriluNm2WGtgDKSnbv6E5XlILMdL4Mv 5oP2y7/CTE34PfF5S9NnZ9R2REvbjtFbPOLtPm/0ePda7T8q/IrVh+HdO P06TuzIsgTYZeBbwy1CDBWk7eNwhGkSQpRH2DzEHCxgdDNitGadTtGVf8 oqtIAXDqs9TVCZnmwG0kFhy8xw9L9F8g25lvueGqHPo16SDkAxsbC8y/G Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="15902082" X-IronPort-AV: E=Sophos;i="6.04,259,1695711600"; d="scan'208";a="15902082" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 19:15:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="721725249" X-IronPort-AV: E=Sophos;i="6.04,259,1695711600"; d="scan'208";a="721725249" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 19:15:32 -0800 From: "Huang, Ying" To: Vishal Verma Cc: Dave Jiang , Dan Williams , , , , David Hildenbrand , Dave Hansen , "Jonathan Cameron" Subject: Re: [PATCH v2 2/2] dax: add a sysfs knob to control memmap_on_memory behavior In-Reply-To: <20231206-vv-dax_abi-v2-2-f4f4f2336d08@intel.com> (Vishal Verma's message of "Wed, 6 Dec 2023 21:36:15 -0700") References: <20231206-vv-dax_abi-v2-0-f4f4f2336d08@intel.com> <20231206-vv-dax_abi-v2-2-f4f4f2336d08@intel.com> Date: Fri, 08 Dec 2023 11:13:32 +0800 Message-ID: <8734wd1j4z.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 07 Dec 2023 19:15:50 -0800 (PST) Vishal Verma writes: > 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 > Reviewed-by: Jonathan Cameron > Reviewed-by: David Hildenbrand > Signed-off-by: Vishal Verma > --- > drivers/dax/bus.c | 40 +++++++++++++++++++++++++++++++++ > Documentation/ABI/testing/sysfs-bus-dax | 13 +++++++++++ > 2 files changed, 53 insertions(+) > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > index 1ff1ab5fa105..11abb57cc031 100644 > --- a/drivers/dax/bus.c > +++ b/drivers/dax/bus.c > @@ -1270,6 +1270,45 @@ 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_region *dax_region = dev_dax->region; > + ssize_t rc; > + bool val; > + > + rc = kstrtobool(buf, &val); > + if (rc) > + return rc; > + > + if (dev_dax->memmap_on_memory == val) > + return len; > + > + device_lock(dax_region->dev); > + if (!dax_region->dev->driver) { This still doesn't look right. Can we check whether the current driver is kmem? And only allow change if it's not kmem? -- Best Regards, Huang, Ying > + device_unlock(dax_region->dev); > + return -ENXIO; > + } > + > + device_lock(dev); > + dev_dax->memmap_on_memory = val; > + device_unlock(dev); > + > + device_unlock(dax_region->dev); > + return rc == 0 ? len : rc; > +} > +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); > @@ -1296,6 +1335,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 a61a7b186017..bb063a004e41 100644 > --- a/Documentation/ABI/testing/sysfs-bus-dax > +++ b/Documentation/ABI/testing/sysfs-bus-dax > @@ -149,3 +149,16 @@ 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).