mirror of
https://github.com/torvalds/linux.git
synced 2026-10-08 11:36:02 +02:00
There is no atomic mechanism to offline and remove an entire
multi-block DAX kmem device. This is presently done in two steps:
1. offline all
2. remove all
This creates a race condition where another entity operates directly on
the memory blocks and can cause hot-unplug to fail / unbind to deadlock.
Add a new 'state' sysfs attribute that enables an atomic whole-device
hotplug operation across its entire memory region.
daxX.Y/state mirrors the per-block memoryX/state ABI:
- [offline, online, online_kernel, online_movable]
- "unplugged" - is added specifically for dax0.0/state
The valid writable states include:
- "unplugged": memory blocks are not present
- "online": memory is online, zone chosen by the kernel
- "online_kernel": memory is online in ZONE_NORMAL
- "online_movable": memory is online in ZONE_MOVABLE
Valid transitions:
- unplugged -> online[_kernel|_movable]
- online[_kernel|_movable] -> unplugged
- offline -> unplugged
A device can only be onlined from "unplugged", so it must be returned
there before being onlined into a different state.
For backwards compatibility the memory blocks are always created at probe
- existing tools expect them to be present after kmem binds.
"offline" is therefore a reportable state but is not writable: it only
arises from the legacy auto_online_blocks=offline policy. Onlining such a
device through this attribute requires unplugging it first in an effort to
get drivers creating DAX devices to set a default.
Unplug is atomic across the whole device: dax_kmem_do_hotremove() collects
every added range and offlines/removes them in one operation. Either the
operation succeeds or is entirely rolled back.
Unbind Note:
An offline dax device memory is removed on unbind as before.
If online at unbind, the resources are leaked (as before), but now
we prevent deadlock if a memory region is impossible to hotremove.
Link: https://lore.kernel.org/20260712154505.3564379-10-gourry@gourry.net
Signed-off-by: Gregory Price <gourry@gourry.net>
Suggested-by: Hannes Reinecke <hare@suse.de>
Suggested-by: David Hildenbrand <david@kernel.org>
Reviewed-by: Dan Williams <djbw@kernel.org>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Pankaj Gupta <pankaj.gupta@amd.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
82 lines
2.1 KiB
C
82 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
|
|
#ifndef __DAX_BUS_H__
|
|
#define __DAX_BUS_H__
|
|
#include <linux/device.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/range.h>
|
|
#include <linux/workqueue.h>
|
|
|
|
struct dev_dax;
|
|
struct resource;
|
|
struct dax_device;
|
|
struct dax_region;
|
|
|
|
/* dax bus specific ioresource flags */
|
|
#define IORESOURCE_DAX_STATIC BIT(0)
|
|
#define IORESOURCE_DAX_KMEM BIT(1)
|
|
|
|
#define DAX_KMEM_UNPLUGGED (-1) /* Do not create memory blocks */
|
|
|
|
struct dax_region *alloc_dax_region(struct device *parent, int region_id,
|
|
struct range *range, int target_node, unsigned int align,
|
|
unsigned long flags);
|
|
|
|
struct dev_dax_data {
|
|
struct dax_region *dax_region;
|
|
struct dev_pagemap *pgmap;
|
|
resource_size_t size;
|
|
int id;
|
|
bool memmap_on_memory;
|
|
};
|
|
|
|
struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data);
|
|
|
|
enum dax_driver_type {
|
|
DAXDRV_KMEM_TYPE,
|
|
DAXDRV_DEVICE_TYPE,
|
|
DAXDRV_FSDEV_TYPE,
|
|
};
|
|
|
|
struct dax_device_driver {
|
|
struct device_driver drv;
|
|
struct list_head ids;
|
|
enum dax_driver_type type;
|
|
int (*probe)(struct dev_dax *dev);
|
|
void (*remove)(struct dev_dax *dev);
|
|
};
|
|
|
|
#define to_dax_drv(__drv) container_of_const(__drv, struct dax_device_driver, drv)
|
|
|
|
int __dax_driver_register(struct dax_device_driver *dax_drv,
|
|
struct module *module, const char *mod_name);
|
|
#define dax_driver_register(driver) \
|
|
__dax_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
|
|
void dax_driver_unregister(struct dax_device_driver *dax_drv);
|
|
void kill_dev_dax(struct dev_dax *dev_dax);
|
|
bool static_dev_dax(struct dev_dax *dev_dax);
|
|
|
|
struct hmem_platform_device {
|
|
struct platform_device pdev;
|
|
struct work_struct work;
|
|
bool did_probe;
|
|
};
|
|
|
|
static inline struct hmem_platform_device *
|
|
to_hmem_platform_device(struct platform_device *pdev)
|
|
{
|
|
return container_of(pdev, struct hmem_platform_device, pdev);
|
|
}
|
|
|
|
#if IS_ENABLED(CONFIG_DEV_DAX_HMEM)
|
|
void dax_hmem_flush_work(void);
|
|
#else
|
|
static inline void dax_hmem_flush_work(void) { }
|
|
#endif
|
|
|
|
#define MODULE_ALIAS_DAX_DEVICE(type) \
|
|
MODULE_ALIAS("dax:t" __stringify(type) "*")
|
|
#define DAX_DEVICE_MODALIAS_FMT "dax:t%d"
|
|
|
|
#endif /* __DAX_BUS_H__ */
|