2007-07-18 09:37:06 +08:00
|
|
|
/******************************************************************************
|
|
|
|
* Talks to Xen Store to figure out what devices we have.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Rusty Russell, IBM Corporation
|
|
|
|
* Copyright (C) 2005 Mike Wray, Hewlett-Packard
|
|
|
|
* Copyright (C) 2005, 2006 XenSource Ltd
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation; or, when distributed
|
|
|
|
* separately from the Linux kernel or incorporated into other
|
|
|
|
* software packages, subject to the following license:
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this source file (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy, modify,
|
|
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2013-06-28 18:21:41 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
2020-05-28 01:43:26 +08:00
|
|
|
#define dev_fmt pr_fmt
|
2013-06-28 18:21:41 +08:00
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
#define DPRINTK(fmt, args...) \
|
|
|
|
pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \
|
|
|
|
__func__, __LINE__, ##args)
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/mm.h>
|
2009-01-08 10:07:11 +08:00
|
|
|
#include <linux/proc_fs.h>
|
2007-07-18 09:37:06 +08:00
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/io.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-07-04 04:20:57 +08:00
|
|
|
#include <linux/module.h>
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/xen/hypervisor.h>
|
2009-10-07 06:11:14 +08:00
|
|
|
|
|
|
|
#include <xen/xen.h>
|
2007-07-18 09:37:06 +08:00
|
|
|
#include <xen/xenbus.h>
|
|
|
|
#include <xen/events.h>
|
2015-04-30 05:10:13 +08:00
|
|
|
#include <xen/xen-ops.h>
|
2007-07-18 09:37:06 +08:00
|
|
|
#include <xen/page.h>
|
|
|
|
|
2010-05-14 19:39:33 +08:00
|
|
|
#include <xen/hvm.h>
|
|
|
|
|
2017-02-09 21:39:56 +08:00
|
|
|
#include "xenbus.h"
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2009-01-08 10:07:11 +08:00
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
int xen_store_evtchn;
|
2009-03-22 14:51:26 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xen_store_evtchn);
|
2009-01-08 10:07:11 +08:00
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
struct xenstore_domain_interface *xen_store_interface;
|
2009-03-22 14:51:26 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xen_store_interface);
|
|
|
|
|
2013-05-29 01:09:55 +08:00
|
|
|
enum xenstore_init xen_store_domain_type;
|
|
|
|
EXPORT_SYMBOL_GPL(xen_store_domain_type);
|
|
|
|
|
2015-08-08 00:34:42 +08:00
|
|
|
static unsigned long xen_store_gfn;
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
static BLOCKING_NOTIFIER_HEAD(xenstore_chain);
|
|
|
|
|
|
|
|
/* If something in array of ids matches this device, return it. */
|
|
|
|
static const struct xenbus_device_id *
|
|
|
|
match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev)
|
|
|
|
{
|
|
|
|
for (; *arr->devicetype != '\0'; arr++) {
|
|
|
|
if (!strcmp(arr->devicetype, dev->devicetype))
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xenbus_match(struct device *_dev, struct device_driver *_drv)
|
|
|
|
{
|
|
|
|
struct xenbus_driver *drv = to_xenbus_driver(_drv);
|
|
|
|
|
|
|
|
if (!drv->ids)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return match_device(drv->ids, to_xenbus_device(_dev)) != NULL;
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_match);
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
static void free_otherend_details(struct xenbus_device *dev)
|
|
|
|
{
|
|
|
|
kfree(dev->otherend);
|
|
|
|
dev->otherend = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void free_otherend_watch(struct xenbus_device *dev)
|
|
|
|
{
|
|
|
|
if (dev->otherend_watch.node) {
|
|
|
|
unregister_xenbus_watch(&dev->otherend_watch);
|
|
|
|
kfree(dev->otherend_watch.node);
|
|
|
|
dev->otherend_watch.node = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-10 04:05:51 +08:00
|
|
|
static int talk_to_otherend(struct xenbus_device *dev)
|
|
|
|
{
|
|
|
|
struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver);
|
|
|
|
|
|
|
|
free_otherend_watch(dev);
|
|
|
|
free_otherend_details(dev);
|
|
|
|
|
|
|
|
return drv->read_otherend_details(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int watch_otherend(struct xenbus_device *dev)
|
|
|
|
{
|
2010-12-10 22:39:15 +08:00
|
|
|
struct xen_bus_type *bus =
|
|
|
|
container_of(dev->dev.bus, struct xen_bus_type, bus);
|
2009-02-10 04:05:51 +08:00
|
|
|
|
2010-12-10 22:39:15 +08:00
|
|
|
return xenbus_watch_pathfmt(dev, &dev->otherend_watch,
|
2020-12-14 17:05:47 +08:00
|
|
|
bus->otherend_will_handle,
|
|
|
|
bus->otherend_changed,
|
2009-02-10 04:05:51 +08:00
|
|
|
"%s/%s", dev->otherend, "state");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int xenbus_read_otherend_details(struct xenbus_device *xendev,
|
2007-07-18 09:37:06 +08:00
|
|
|
char *id_node, char *path_node)
|
|
|
|
{
|
|
|
|
int err = xenbus_gather(XBT_NIL, xendev->nodename,
|
|
|
|
id_node, "%i", &xendev->otherend_id,
|
|
|
|
path_node, NULL, &xendev->otherend,
|
|
|
|
NULL);
|
|
|
|
if (err) {
|
|
|
|
xenbus_dev_fatal(xendev, err,
|
|
|
|
"reading other end details from %s",
|
|
|
|
xendev->nodename);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (strlen(xendev->otherend) == 0 ||
|
|
|
|
!xenbus_exists(XBT_NIL, xendev->otherend, "")) {
|
|
|
|
xenbus_dev_fatal(xendev, -ENOENT,
|
|
|
|
"unable to read other end from %s. "
|
|
|
|
"missing or inaccessible.",
|
|
|
|
xendev->nodename);
|
|
|
|
free_otherend_details(xendev);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_read_otherend_details);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2009-02-10 04:05:51 +08:00
|
|
|
void xenbus_otherend_changed(struct xenbus_watch *watch,
|
2017-02-09 21:39:57 +08:00
|
|
|
const char *path, const char *token,
|
2009-02-10 04:05:51 +08:00
|
|
|
int ignore_on_shutdown)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
|
|
|
struct xenbus_device *dev =
|
|
|
|
container_of(watch, struct xenbus_device, otherend_watch);
|
|
|
|
struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver);
|
|
|
|
enum xenbus_state state;
|
|
|
|
|
|
|
|
/* Protect us against watches firing on old details when the otherend
|
|
|
|
details change, say immediately after a resume. */
|
|
|
|
if (!dev->otherend ||
|
2017-02-09 21:39:57 +08:00
|
|
|
strncmp(dev->otherend, path, strlen(dev->otherend))) {
|
|
|
|
dev_dbg(&dev->dev, "Ignoring watch at %s\n", path);
|
2007-07-18 09:37:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = xenbus_read_driver_state(dev->otherend);
|
|
|
|
|
2007-10-18 18:06:30 +08:00
|
|
|
dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n",
|
2017-02-09 21:39:57 +08:00
|
|
|
state, xenbus_strstate(state), dev->otherend_watch.node, path);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore xenbus transitions during shutdown. This prevents us doing
|
|
|
|
* work that can fail e.g., when the rootfs is gone.
|
|
|
|
*/
|
|
|
|
if (system_state > SYSTEM_RUNNING) {
|
2009-02-10 04:05:51 +08:00
|
|
|
if (ignore_on_shutdown && (state == XenbusStateClosing))
|
2007-07-18 09:37:06 +08:00
|
|
|
xenbus_frontend_closed(dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drv->otherend_changed)
|
|
|
|
drv->otherend_changed(dev, state);
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_otherend_changed);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2021-02-19 23:40:28 +08:00
|
|
|
#define XENBUS_SHOW_STAT(name) \
|
|
|
|
static ssize_t show_##name(struct device *_dev, \
|
|
|
|
struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
|
|
|
{ \
|
|
|
|
struct xenbus_device *dev = to_xenbus_device(_dev); \
|
|
|
|
\
|
|
|
|
return sprintf(buf, "%d\n", atomic_read(&dev->name)); \
|
|
|
|
} \
|
|
|
|
static DEVICE_ATTR(name, 0444, show_##name, NULL)
|
|
|
|
|
|
|
|
XENBUS_SHOW_STAT(event_channels);
|
|
|
|
XENBUS_SHOW_STAT(events);
|
|
|
|
XENBUS_SHOW_STAT(spurious_events);
|
|
|
|
XENBUS_SHOW_STAT(jiffies_eoi_delayed);
|
|
|
|
|
|
|
|
static ssize_t show_spurious_threshold(struct device *_dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct xenbus_device *dev = to_xenbus_device(_dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", dev->spurious_threshold);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t set_spurious_threshold(struct device *_dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct xenbus_device *dev = to_xenbus_device(_dev);
|
|
|
|
unsigned int val;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = kstrtouint(buf, 0, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
dev->spurious_threshold = val;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(spurious_threshold, 0644, show_spurious_threshold,
|
|
|
|
set_spurious_threshold);
|
|
|
|
|
|
|
|
static struct attribute *xenbus_attrs[] = {
|
|
|
|
&dev_attr_event_channels.attr,
|
|
|
|
&dev_attr_events.attr,
|
|
|
|
&dev_attr_spurious_events.attr,
|
|
|
|
&dev_attr_jiffies_eoi_delayed.attr,
|
|
|
|
&dev_attr_spurious_threshold.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group xenbus_group = {
|
|
|
|
.name = "xenbus",
|
|
|
|
.attrs = xenbus_attrs,
|
|
|
|
};
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
int xenbus_dev_probe(struct device *_dev)
|
|
|
|
{
|
|
|
|
struct xenbus_device *dev = to_xenbus_device(_dev);
|
|
|
|
struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
|
|
|
|
const struct xenbus_device_id *id;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
DPRINTK("%s", dev->nodename);
|
|
|
|
|
|
|
|
if (!drv->probe) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = match_device(drv->ids, dev);
|
|
|
|
if (!id) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = talk_to_otherend(dev);
|
|
|
|
if (err) {
|
|
|
|
dev_warn(&dev->dev, "talk_to_otherend on %s failed.\n",
|
|
|
|
dev->nodename);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-12-02 19:41:16 +08:00
|
|
|
if (!try_module_get(drv->driver.owner)) {
|
|
|
|
dev_warn(&dev->dev, "failed to acquire module reference on '%s'\n",
|
|
|
|
drv->driver.name);
|
|
|
|
err = -ESRCH;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-03-05 18:03:23 +08:00
|
|
|
down(&dev->reclaim_sem);
|
2007-07-18 09:37:06 +08:00
|
|
|
err = drv->probe(dev, id);
|
2020-03-05 18:03:23 +08:00
|
|
|
up(&dev->reclaim_sem);
|
2007-07-18 09:37:06 +08:00
|
|
|
if (err)
|
2019-12-02 19:41:16 +08:00
|
|
|
goto fail_put;
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
err = watch_otherend(dev);
|
|
|
|
if (err) {
|
|
|
|
dev_warn(&dev->dev, "watch_otherend on %s failed.\n",
|
|
|
|
dev->nodename);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:40:28 +08:00
|
|
|
dev->spurious_threshold = 1;
|
|
|
|
if (sysfs_create_group(&dev->dev.kobj, &xenbus_group))
|
|
|
|
dev_warn(&dev->dev, "sysfs_create_group on %s failed.\n",
|
|
|
|
dev->nodename);
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
return 0;
|
2019-12-02 19:41:16 +08:00
|
|
|
fail_put:
|
|
|
|
module_put(drv->driver.owner);
|
2007-07-18 09:37:06 +08:00
|
|
|
fail:
|
|
|
|
xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
|
2009-10-30 05:19:42 +08:00
|
|
|
return err;
|
2007-07-18 09:37:06 +08:00
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_dev_probe);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
int xenbus_dev_remove(struct device *_dev)
|
|
|
|
{
|
|
|
|
struct xenbus_device *dev = to_xenbus_device(_dev);
|
|
|
|
struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
|
|
|
|
|
|
|
|
DPRINTK("%s", dev->nodename);
|
|
|
|
|
2021-02-19 23:40:28 +08:00
|
|
|
sysfs_remove_group(&dev->dev.kobj, &xenbus_group);
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
free_otherend_watch(dev);
|
|
|
|
|
2020-01-27 16:18:09 +08:00
|
|
|
if (drv->remove) {
|
2020-03-05 18:03:23 +08:00
|
|
|
down(&dev->reclaim_sem);
|
2007-07-18 09:37:06 +08:00
|
|
|
drv->remove(dev);
|
2020-03-05 18:03:23 +08:00
|
|
|
up(&dev->reclaim_sem);
|
2020-01-27 16:18:09 +08:00
|
|
|
}
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2019-12-02 19:41:16 +08:00
|
|
|
module_put(drv->driver.owner);
|
|
|
|
|
2012-03-06 01:11:31 +08:00
|
|
|
free_otherend_details(dev);
|
|
|
|
|
2019-12-11 23:29:54 +08:00
|
|
|
/*
|
|
|
|
* If the toolstack has forced the device state to closing then set
|
|
|
|
* the state to closed now to allow it to be cleaned up.
|
|
|
|
* Similarly, if the driver does not support re-bind, set the
|
|
|
|
* closed.
|
|
|
|
*/
|
|
|
|
if (!drv->allow_rebind ||
|
|
|
|
xenbus_read_driver_state(dev->nodename) == XenbusStateClosing)
|
|
|
|
xenbus_switch_state(dev, XenbusStateClosed);
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_dev_remove);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
int xenbus_register_driver_common(struct xenbus_driver *drv,
|
2014-09-09 00:30:41 +08:00
|
|
|
struct xen_bus_type *bus,
|
|
|
|
struct module *owner, const char *mod_name)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
2014-09-09 00:30:41 +08:00
|
|
|
drv->driver.name = drv->name ? drv->name : drv->ids[0].devicetype;
|
2007-07-18 09:37:06 +08:00
|
|
|
drv->driver.bus = &bus->bus;
|
2014-09-09 00:30:41 +08:00
|
|
|
drv->driver.owner = owner;
|
|
|
|
drv->driver.mod_name = mod_name;
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
return driver_register(&drv->driver);
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_register_driver_common);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
void xenbus_unregister_driver(struct xenbus_driver *drv)
|
|
|
|
{
|
|
|
|
driver_unregister(&drv->driver);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xenbus_unregister_driver);
|
|
|
|
|
2011-07-26 19:17:23 +08:00
|
|
|
struct xb_find_info {
|
2007-07-18 09:37:06 +08:00
|
|
|
struct xenbus_device *dev;
|
|
|
|
const char *nodename;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cmp_dev(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct xenbus_device *xendev = to_xenbus_device(dev);
|
|
|
|
struct xb_find_info *info = data;
|
|
|
|
|
|
|
|
if (!strcmp(xendev->nodename, info->nodename)) {
|
|
|
|
info->dev = xendev;
|
|
|
|
get_device(dev);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 02:49:34 +08:00
|
|
|
static struct xenbus_device *xenbus_device_find(const char *nodename,
|
|
|
|
struct bus_type *bus)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
|
|
|
struct xb_find_info info = { .dev = NULL, .nodename = nodename };
|
|
|
|
|
|
|
|
bus_for_each_dev(bus, NULL, &info, cmp_dev);
|
|
|
|
return info.dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cleanup_dev(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct xenbus_device *xendev = to_xenbus_device(dev);
|
|
|
|
struct xb_find_info *info = data;
|
|
|
|
int len = strlen(info->nodename);
|
|
|
|
|
|
|
|
DPRINTK("%s", info->nodename);
|
|
|
|
|
|
|
|
/* Match the info->nodename path, or any subdirectory of that path. */
|
|
|
|
if (strncmp(xendev->nodename, info->nodename, len))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If the node name is longer, ensure it really is a subdirectory. */
|
|
|
|
if ((strlen(xendev->nodename) > len) && (xendev->nodename[len] != '/'))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
info->dev = xendev;
|
|
|
|
get_device(dev);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xenbus_cleanup_devices(const char *path, struct bus_type *bus)
|
|
|
|
{
|
|
|
|
struct xb_find_info info = { .nodename = path };
|
|
|
|
|
|
|
|
do {
|
|
|
|
info.dev = NULL;
|
|
|
|
bus_for_each_dev(bus, NULL, &info, cleanup_dev);
|
|
|
|
if (info.dev) {
|
|
|
|
device_unregister(&info.dev->dev);
|
|
|
|
put_device(&info.dev->dev);
|
|
|
|
}
|
|
|
|
} while (info.dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xenbus_dev_release(struct device *dev)
|
|
|
|
{
|
|
|
|
if (dev)
|
|
|
|
kfree(to_xenbus_device(dev));
|
|
|
|
}
|
|
|
|
|
2011-06-29 20:39:26 +08:00
|
|
|
static ssize_t nodename_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename);
|
|
|
|
}
|
2013-10-07 14:55:49 +08:00
|
|
|
static DEVICE_ATTR_RO(nodename);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2011-06-29 20:39:26 +08:00
|
|
|
static ssize_t devtype_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype);
|
|
|
|
}
|
2013-10-07 14:55:49 +08:00
|
|
|
static DEVICE_ATTR_RO(devtype);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2011-06-29 20:39:26 +08:00
|
|
|
static ssize_t modalias_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2008-04-03 01:54:05 +08:00
|
|
|
{
|
2011-06-29 20:40:08 +08:00
|
|
|
return sprintf(buf, "%s:%s\n", dev->bus->name,
|
|
|
|
to_xenbus_device(dev)->devicetype);
|
2008-04-03 01:54:05 +08:00
|
|
|
}
|
2013-10-07 14:55:49 +08:00
|
|
|
static DEVICE_ATTR_RO(modalias);
|
2011-06-29 20:39:26 +08:00
|
|
|
|
2018-08-28 22:56:08 +08:00
|
|
|
static ssize_t state_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%s\n",
|
|
|
|
xenbus_strstate(to_xenbus_device(dev)->state));
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(state);
|
|
|
|
|
2013-10-07 14:55:49 +08:00
|
|
|
static struct attribute *xenbus_dev_attrs[] = {
|
|
|
|
&dev_attr_nodename.attr,
|
|
|
|
&dev_attr_devtype.attr,
|
|
|
|
&dev_attr_modalias.attr,
|
2018-08-28 22:56:08 +08:00
|
|
|
&dev_attr_state.attr,
|
2013-10-07 14:55:49 +08:00
|
|
|
NULL,
|
2011-06-29 20:39:26 +08:00
|
|
|
};
|
2013-10-07 14:55:49 +08:00
|
|
|
|
|
|
|
static const struct attribute_group xenbus_dev_group = {
|
|
|
|
.attrs = xenbus_dev_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct attribute_group *xenbus_dev_groups[] = {
|
|
|
|
&xenbus_dev_group,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(xenbus_dev_groups);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
int xenbus_probe_node(struct xen_bus_type *bus,
|
|
|
|
const char *type,
|
|
|
|
const char *nodename)
|
|
|
|
{
|
2009-01-07 02:44:34 +08:00
|
|
|
char devname[XEN_BUS_ID_SIZE];
|
2007-07-18 09:37:06 +08:00
|
|
|
int err;
|
|
|
|
struct xenbus_device *xendev;
|
|
|
|
size_t stringlen;
|
|
|
|
char *tmpstring;
|
|
|
|
|
|
|
|
enum xenbus_state state = xenbus_read_driver_state(nodename);
|
|
|
|
|
|
|
|
if (state != XenbusStateInitialising) {
|
|
|
|
/* Device is not new, so ignore it. This can happen if a
|
|
|
|
device is going away after switching to Closed. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
stringlen = strlen(nodename) + 1 + strlen(type) + 1;
|
|
|
|
xendev = kzalloc(sizeof(*xendev) + stringlen, GFP_KERNEL);
|
|
|
|
if (!xendev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
xendev->state = XenbusStateInitialising;
|
|
|
|
|
|
|
|
/* Copy the strings into the extra space. */
|
|
|
|
|
|
|
|
tmpstring = (char *)(xendev + 1);
|
|
|
|
strcpy(tmpstring, nodename);
|
|
|
|
xendev->nodename = tmpstring;
|
|
|
|
|
|
|
|
tmpstring += strlen(tmpstring) + 1;
|
|
|
|
strcpy(tmpstring, type);
|
|
|
|
xendev->devicetype = tmpstring;
|
|
|
|
init_completion(&xendev->down);
|
|
|
|
|
|
|
|
xendev->dev.bus = &bus->bus;
|
|
|
|
xendev->dev.release = xenbus_dev_release;
|
|
|
|
|
2009-01-07 02:44:34 +08:00
|
|
|
err = bus->get_bus_id(devname, xendev->nodename);
|
2007-07-18 09:37:06 +08:00
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
2013-07-04 06:04:56 +08:00
|
|
|
dev_set_name(&xendev->dev, "%s", devname);
|
2020-03-05 18:03:23 +08:00
|
|
|
sema_init(&xendev->reclaim_sem, 1);
|
2009-01-07 02:44:34 +08:00
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
/* Register with generic device framework. */
|
|
|
|
err = device_register(&xendev->dev);
|
2018-03-06 18:10:37 +08:00
|
|
|
if (err) {
|
|
|
|
put_device(&xendev->dev);
|
|
|
|
xendev = NULL;
|
2007-07-18 09:37:06 +08:00
|
|
|
goto fail;
|
2018-03-06 18:10:37 +08:00
|
|
|
}
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
kfree(xendev);
|
|
|
|
return err;
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_probe_node);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
char **dir;
|
|
|
|
unsigned int dir_n = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dir = xenbus_directory(XBT_NIL, bus->root, type, &dir_n);
|
2010-03-30 05:38:12 +08:00
|
|
|
if (IS_ERR(dir))
|
2007-07-18 09:37:06 +08:00
|
|
|
return PTR_ERR(dir);
|
|
|
|
|
|
|
|
for (i = 0; i < dir_n; i++) {
|
2009-02-10 04:05:51 +08:00
|
|
|
err = bus->probe(bus, type, dir[i]);
|
2010-03-30 05:38:12 +08:00
|
|
|
if (err)
|
2007-07-18 09:37:06 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-03-30 05:38:12 +08:00
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
kfree(dir);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xenbus_probe_devices(struct xen_bus_type *bus)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
char **dir;
|
|
|
|
unsigned int i, dir_n;
|
|
|
|
|
|
|
|
dir = xenbus_directory(XBT_NIL, bus->root, "", &dir_n);
|
2010-03-30 05:38:12 +08:00
|
|
|
if (IS_ERR(dir))
|
2007-07-18 09:37:06 +08:00
|
|
|
return PTR_ERR(dir);
|
|
|
|
|
|
|
|
for (i = 0; i < dir_n; i++) {
|
|
|
|
err = xenbus_probe_device_type(bus, dir[i]);
|
2010-03-30 05:38:12 +08:00
|
|
|
if (err)
|
2007-07-18 09:37:06 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-03-30 05:38:12 +08:00
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
kfree(dir);
|
|
|
|
return err;
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_probe_devices);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
static unsigned int char_count(const char *str, char c)
|
|
|
|
{
|
|
|
|
unsigned int i, ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; str[i]; i++)
|
|
|
|
if (str[i] == c)
|
|
|
|
ret++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int strsep_len(const char *str, char c, unsigned int len)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; str[i]; i++)
|
|
|
|
if (str[i] == c) {
|
|
|
|
if (len == 0)
|
|
|
|
return i;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
return (len == 0) ? i : -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xenbus_dev_changed(const char *node, struct xen_bus_type *bus)
|
|
|
|
{
|
|
|
|
int exists, rootlen;
|
|
|
|
struct xenbus_device *dev;
|
2009-01-07 02:44:34 +08:00
|
|
|
char type[XEN_BUS_ID_SIZE];
|
2007-07-18 09:37:06 +08:00
|
|
|
const char *p, *root;
|
|
|
|
|
|
|
|
if (char_count(node, '/') < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
exists = xenbus_exists(XBT_NIL, node, "");
|
|
|
|
if (!exists) {
|
|
|
|
xenbus_cleanup_devices(node, &bus->bus);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* backend/<type>/... or device/<type>/... */
|
|
|
|
p = strchr(node, '/') + 1;
|
2009-01-07 02:44:34 +08:00
|
|
|
snprintf(type, XEN_BUS_ID_SIZE, "%.*s", (int)strcspn(p, "/"), p);
|
|
|
|
type[XEN_BUS_ID_SIZE-1] = '\0';
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
rootlen = strsep_len(node, '/', bus->levels);
|
|
|
|
if (rootlen < 0)
|
|
|
|
return;
|
|
|
|
root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node);
|
|
|
|
if (!root)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dev = xenbus_device_find(root, &bus->bus);
|
|
|
|
if (!dev)
|
|
|
|
xenbus_probe_node(bus, type, root);
|
|
|
|
else
|
|
|
|
put_device(&dev->dev);
|
|
|
|
|
|
|
|
kfree(root);
|
|
|
|
}
|
2009-02-10 04:05:53 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_dev_changed);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2011-02-19 06:43:07 +08:00
|
|
|
int xenbus_dev_suspend(struct device *dev)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct xenbus_driver *drv;
|
2010-12-10 22:39:15 +08:00
|
|
|
struct xenbus_device *xdev
|
|
|
|
= container_of(dev, struct xenbus_device, dev);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2009-02-10 04:05:51 +08:00
|
|
|
DPRINTK("%s", xdev->nodename);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
if (dev->driver == NULL)
|
|
|
|
return 0;
|
|
|
|
drv = to_xenbus_driver(dev->driver);
|
|
|
|
if (drv->suspend)
|
2011-02-19 06:43:07 +08:00
|
|
|
err = drv->suspend(xdev);
|
2007-07-18 09:37:06 +08:00
|
|
|
if (err)
|
2020-05-28 01:43:26 +08:00
|
|
|
dev_warn(dev, "suspend failed: %i\n", err);
|
2007-07-18 09:37:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_dev_suspend);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2009-02-10 04:05:51 +08:00
|
|
|
int xenbus_dev_resume(struct device *dev)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct xenbus_driver *drv;
|
2010-12-10 22:39:15 +08:00
|
|
|
struct xenbus_device *xdev
|
|
|
|
= container_of(dev, struct xenbus_device, dev);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2009-02-10 04:05:51 +08:00
|
|
|
DPRINTK("%s", xdev->nodename);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
if (dev->driver == NULL)
|
|
|
|
return 0;
|
|
|
|
drv = to_xenbus_driver(dev->driver);
|
|
|
|
err = talk_to_otherend(xdev);
|
|
|
|
if (err) {
|
2020-05-28 01:43:26 +08:00
|
|
|
dev_warn(dev, "resume (talk_to_otherend) failed: %i\n", err);
|
2007-07-18 09:37:06 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
xdev->state = XenbusStateInitialising;
|
|
|
|
|
|
|
|
if (drv->resume) {
|
|
|
|
err = drv->resume(xdev);
|
|
|
|
if (err) {
|
2020-05-28 01:43:26 +08:00
|
|
|
dev_warn(dev, "resume failed: %i\n", err);
|
2007-07-18 09:37:06 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = watch_otherend(xdev);
|
|
|
|
if (err) {
|
2020-05-28 01:43:26 +08:00
|
|
|
dev_warn(dev, "resume (watch_otherend) failed: %d\n", err);
|
2007-07-18 09:37:06 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-02-10 04:05:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(xenbus_dev_resume);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2011-02-19 06:43:07 +08:00
|
|
|
int xenbus_dev_cancel(struct device *dev)
|
|
|
|
{
|
|
|
|
/* Do nothing */
|
|
|
|
DPRINTK("cancel");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xenbus_dev_cancel);
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
/* A flag to determine if xenstored is 'ready' (i.e. has started) */
|
2011-07-26 19:17:23 +08:00
|
|
|
int xenstored_ready;
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
int register_xenstore_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-10-04 23:10:06 +08:00
|
|
|
if (xenstored_ready > 0)
|
|
|
|
ret = nb->notifier_call(nb, 0, NULL);
|
|
|
|
else
|
|
|
|
blocking_notifier_chain_register(&xenstore_chain, nb);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(register_xenstore_notifier);
|
|
|
|
|
|
|
|
void unregister_xenstore_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
blocking_notifier_chain_unregister(&xenstore_chain, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(unregister_xenstore_notifier);
|
|
|
|
|
2021-02-11 01:06:54 +08:00
|
|
|
static void xenbus_probe(void)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
2010-10-04 23:10:06 +08:00
|
|
|
xenstored_ready = 1;
|
2007-07-18 09:37:06 +08:00
|
|
|
|
xen: Fix event channel callback via INTX/GSI
For a while, event channel notification via the PCI platform device
has been broken, because we attempt to communicate with xenstore before
we even have notifications working, with the xs_reset_watches() call
in xs_init().
We tend to get away with this on Xen versions below 4.0 because we avoid
calling xs_reset_watches() anyway, because xenstore might not cope with
reading a non-existent key. And newer Xen *does* have the vector
callback support, so we rarely fall back to INTX/GSI delivery.
To fix it, clean up a bit of the mess of xs_init() and xenbus_probe()
startup. Call xs_init() directly from xenbus_init() only in the !XS_HVM
case, deferring it to be called from xenbus_probe() in the XS_HVM case
instead.
Then fix up the invocation of xenbus_probe() to happen either from its
device_initcall if the callback is available early enough, or when the
callback is finally set up. This means that the hack of calling
xenbus_probe() from a workqueue after the first interrupt, or directly
from the PCI platform device setup, is no longer needed.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/20210113132606.422794-2-dwmw2@infradead.org
Signed-off-by: Juergen Gross <jgross@suse.com>
2021-01-13 21:26:02 +08:00
|
|
|
/*
|
|
|
|
* In the HVM case, xenbus_init() deferred its call to
|
|
|
|
* xs_init() in case callbacks were not operational yet.
|
|
|
|
* So do it now.
|
|
|
|
*/
|
|
|
|
if (xen_store_domain_type == XS_HVM)
|
|
|
|
xs_init();
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
/* Notify others that xenstore is up */
|
|
|
|
blocking_notifier_call_chain(&xenstore_chain, 0, NULL);
|
|
|
|
}
|
|
|
|
|
xen: Fix event channel callback via INTX/GSI
For a while, event channel notification via the PCI platform device
has been broken, because we attempt to communicate with xenstore before
we even have notifications working, with the xs_reset_watches() call
in xs_init().
We tend to get away with this on Xen versions below 4.0 because we avoid
calling xs_reset_watches() anyway, because xenstore might not cope with
reading a non-existent key. And newer Xen *does* have the vector
callback support, so we rarely fall back to INTX/GSI delivery.
To fix it, clean up a bit of the mess of xs_init() and xenbus_probe()
startup. Call xs_init() directly from xenbus_init() only in the !XS_HVM
case, deferring it to be called from xenbus_probe() in the XS_HVM case
instead.
Then fix up the invocation of xenbus_probe() to happen either from its
device_initcall if the callback is available early enough, or when the
callback is finally set up. This means that the hack of calling
xenbus_probe() from a workqueue after the first interrupt, or directly
from the PCI platform device setup, is no longer needed.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/20210113132606.422794-2-dwmw2@infradead.org
Signed-off-by: Juergen Gross <jgross@suse.com>
2021-01-13 21:26:02 +08:00
|
|
|
/*
|
|
|
|
* Returns true when XenStore init must be deferred in order to
|
|
|
|
* allow the PCI platform device to be initialised, before we
|
|
|
|
* can actually have event channel interrupts working.
|
|
|
|
*/
|
|
|
|
static bool xs_hvm_defer_init_for_callback(void)
|
2010-05-18 00:08:21 +08:00
|
|
|
{
|
xen: Fix event channel callback via INTX/GSI
For a while, event channel notification via the PCI platform device
has been broken, because we attempt to communicate with xenstore before
we even have notifications working, with the xs_reset_watches() call
in xs_init().
We tend to get away with this on Xen versions below 4.0 because we avoid
calling xs_reset_watches() anyway, because xenstore might not cope with
reading a non-existent key. And newer Xen *does* have the vector
callback support, so we rarely fall back to INTX/GSI delivery.
To fix it, clean up a bit of the mess of xs_init() and xenbus_probe()
startup. Call xs_init() directly from xenbus_init() only in the !XS_HVM
case, deferring it to be called from xenbus_probe() in the XS_HVM case
instead.
Then fix up the invocation of xenbus_probe() to happen either from its
device_initcall if the callback is available early enough, or when the
callback is finally set up. This means that the hack of calling
xenbus_probe() from a workqueue after the first interrupt, or directly
from the PCI platform device setup, is no longer needed.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/20210113132606.422794-2-dwmw2@infradead.org
Signed-off-by: Juergen Gross <jgross@suse.com>
2021-01-13 21:26:02 +08:00
|
|
|
#ifdef CONFIG_XEN_PVHVM
|
|
|
|
return xen_store_domain_type == XS_HVM &&
|
|
|
|
!xen_have_vector_callback;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2010-05-18 00:08:21 +08:00
|
|
|
|
2021-01-27 01:01:49 +08:00
|
|
|
static int xenbus_probe_thread(void *unused)
|
|
|
|
{
|
|
|
|
DEFINE_WAIT(w);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We actually just want to wait for *any* trigger of xb_waitq,
|
|
|
|
* and run xenbus_probe() the moment it occurs.
|
|
|
|
*/
|
|
|
|
prepare_to_wait(&xb_waitq, &w, TASK_INTERRUPTIBLE);
|
|
|
|
schedule();
|
|
|
|
finish_wait(&xb_waitq, &w);
|
|
|
|
|
|
|
|
DPRINTK("probing");
|
|
|
|
xenbus_probe();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
xen: Fix event channel callback via INTX/GSI
For a while, event channel notification via the PCI platform device
has been broken, because we attempt to communicate with xenstore before
we even have notifications working, with the xs_reset_watches() call
in xs_init().
We tend to get away with this on Xen versions below 4.0 because we avoid
calling xs_reset_watches() anyway, because xenstore might not cope with
reading a non-existent key. And newer Xen *does* have the vector
callback support, so we rarely fall back to INTX/GSI delivery.
To fix it, clean up a bit of the mess of xs_init() and xenbus_probe()
startup. Call xs_init() directly from xenbus_init() only in the !XS_HVM
case, deferring it to be called from xenbus_probe() in the XS_HVM case
instead.
Then fix up the invocation of xenbus_probe() to happen either from its
device_initcall if the callback is available early enough, or when the
callback is finally set up. This means that the hack of calling
xenbus_probe() from a workqueue after the first interrupt, or directly
from the PCI platform device setup, is no longer needed.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/20210113132606.422794-2-dwmw2@infradead.org
Signed-off-by: Juergen Gross <jgross@suse.com>
2021-01-13 21:26:02 +08:00
|
|
|
static int __init xenbus_probe_initcall(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Probe XenBus here in the XS_PV case, and also XS_HVM unless we
|
|
|
|
* need to wait for the platform PCI device to come up.
|
|
|
|
*/
|
|
|
|
if (xen_store_domain_type == XS_PV ||
|
|
|
|
(xen_store_domain_type == XS_HVM &&
|
|
|
|
!xs_hvm_defer_init_for_callback()))
|
|
|
|
xenbus_probe();
|
2010-05-18 00:08:21 +08:00
|
|
|
|
2021-01-27 01:01:49 +08:00
|
|
|
/*
|
|
|
|
* For XS_LOCAL, spawn a thread which will wait for xenstored
|
|
|
|
* or a xenstore-stubdom to be started, then probe. It will be
|
|
|
|
* triggered when communication starts happening, by waiting
|
|
|
|
* on xb_waitq.
|
|
|
|
*/
|
|
|
|
if (xen_store_domain_type == XS_LOCAL) {
|
|
|
|
struct task_struct *probe_task;
|
|
|
|
|
|
|
|
probe_task = kthread_run(xenbus_probe_thread, NULL,
|
|
|
|
"xenbus_probe");
|
|
|
|
if (IS_ERR(probe_task))
|
|
|
|
return PTR_ERR(probe_task);
|
|
|
|
}
|
2010-05-18 00:08:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
device_initcall(xenbus_probe_initcall);
|
|
|
|
|
xen: Fix event channel callback via INTX/GSI
For a while, event channel notification via the PCI platform device
has been broken, because we attempt to communicate with xenstore before
we even have notifications working, with the xs_reset_watches() call
in xs_init().
We tend to get away with this on Xen versions below 4.0 because we avoid
calling xs_reset_watches() anyway, because xenstore might not cope with
reading a non-existent key. And newer Xen *does* have the vector
callback support, so we rarely fall back to INTX/GSI delivery.
To fix it, clean up a bit of the mess of xs_init() and xenbus_probe()
startup. Call xs_init() directly from xenbus_init() only in the !XS_HVM
case, deferring it to be called from xenbus_probe() in the XS_HVM case
instead.
Then fix up the invocation of xenbus_probe() to happen either from its
device_initcall if the callback is available early enough, or when the
callback is finally set up. This means that the hack of calling
xenbus_probe() from a workqueue after the first interrupt, or directly
from the PCI platform device setup, is no longer needed.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/20210113132606.422794-2-dwmw2@infradead.org
Signed-off-by: Juergen Gross <jgross@suse.com>
2021-01-13 21:26:02 +08:00
|
|
|
int xen_set_callback_via(uint64_t via)
|
|
|
|
{
|
|
|
|
struct xen_hvm_param a;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
a.domid = DOMID_SELF;
|
|
|
|
a.index = HVM_PARAM_CALLBACK_IRQ;
|
|
|
|
a.value = via;
|
|
|
|
|
|
|
|
ret = HYPERVISOR_hvm_op(HVMOP_set_param, &a);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If xenbus_probe_initcall() deferred the xenbus_probe()
|
|
|
|
* due to the callback not functioning yet, we can do it now.
|
|
|
|
*/
|
|
|
|
if (!xenstored_ready && xs_hvm_defer_init_for_callback())
|
|
|
|
xenbus_probe();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xen_set_callback_via);
|
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
/* Set up event channel for xenstored which is run as a local process
|
|
|
|
* (this is normally used only in dom0)
|
|
|
|
*/
|
|
|
|
static int __init xenstored_local_init(void)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
2016-12-05 16:22:22 +08:00
|
|
|
int err = -ENOMEM;
|
2010-09-02 21:53:56 +08:00
|
|
|
unsigned long page = 0;
|
2011-10-14 04:07:08 +08:00
|
|
|
struct evtchn_alloc_unbound alloc_unbound;
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
/* Allocate Xenstore page */
|
|
|
|
page = get_zeroed_page(GFP_KERNEL);
|
|
|
|
if (!page)
|
|
|
|
goto out_err;
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2018-05-09 18:21:28 +08:00
|
|
|
xen_store_gfn = virt_to_gfn((void *)page);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
/* Next allocate a local port which xenstored can bind to */
|
|
|
|
alloc_unbound.dom = DOMID_SELF;
|
|
|
|
alloc_unbound.remote_dom = DOMID_SELF;
|
2010-09-02 21:53:56 +08:00
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
|
|
|
|
&alloc_unbound);
|
|
|
|
if (err == -ENOSYS)
|
|
|
|
goto out_err;
|
2010-09-02 21:53:56 +08:00
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
BUG_ON(err);
|
2018-05-09 18:21:28 +08:00
|
|
|
xen_store_evtchn = alloc_unbound.port;
|
2010-09-02 21:53:56 +08:00
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
return 0;
|
2010-09-02 21:53:56 +08:00
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
out_err:
|
|
|
|
if (page != 0)
|
|
|
|
free_page(page);
|
|
|
|
return err;
|
|
|
|
}
|
2010-09-02 21:53:56 +08:00
|
|
|
|
2015-04-30 05:10:13 +08:00
|
|
|
static int xenbus_resume_cb(struct notifier_block *nb,
|
|
|
|
unsigned long action, void *data)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (xen_hvm_domain()) {
|
2015-05-28 16:26:37 +08:00
|
|
|
uint64_t v = 0;
|
2015-04-30 05:10:13 +08:00
|
|
|
|
|
|
|
err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
|
|
|
|
if (!err && v)
|
|
|
|
xen_store_evtchn = v;
|
|
|
|
else
|
|
|
|
pr_warn("Cannot update xenstore event channel: %d\n",
|
|
|
|
err);
|
|
|
|
} else
|
|
|
|
xen_store_evtchn = xen_start_info->store_evtchn;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block xenbus_resume_nb = {
|
|
|
|
.notifier_call = xenbus_resume_cb,
|
|
|
|
};
|
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
static int __init xenbus_init(void)
|
|
|
|
{
|
|
|
|
int err = 0;
|
2012-09-14 19:13:12 +08:00
|
|
|
uint64_t v = 0;
|
2013-05-29 01:09:55 +08:00
|
|
|
xen_store_domain_type = XS_UNKNOWN;
|
2010-09-02 21:53:56 +08:00
|
|
|
|
2011-10-14 04:07:08 +08:00
|
|
|
if (!xen_domain())
|
|
|
|
return -ENODEV;
|
|
|
|
|
2011-12-20 03:55:14 +08:00
|
|
|
xenbus_ring_ops_init();
|
|
|
|
|
2012-09-14 19:13:12 +08:00
|
|
|
if (xen_pv_domain())
|
2013-05-29 01:09:55 +08:00
|
|
|
xen_store_domain_type = XS_PV;
|
2012-09-14 19:13:12 +08:00
|
|
|
if (xen_hvm_domain())
|
2013-05-29 01:09:55 +08:00
|
|
|
xen_store_domain_type = XS_HVM;
|
2012-09-14 19:13:12 +08:00
|
|
|
if (xen_hvm_domain() && xen_initial_domain())
|
2013-05-29 01:09:55 +08:00
|
|
|
xen_store_domain_type = XS_LOCAL;
|
2012-09-14 19:13:12 +08:00
|
|
|
if (xen_pv_domain() && !xen_start_info->store_evtchn)
|
2013-05-29 01:09:55 +08:00
|
|
|
xen_store_domain_type = XS_LOCAL;
|
2012-09-14 19:13:12 +08:00
|
|
|
if (xen_pv_domain() && xen_start_info->store_evtchn)
|
|
|
|
xenstored_ready = 1;
|
|
|
|
|
2013-05-29 01:09:55 +08:00
|
|
|
switch (xen_store_domain_type) {
|
|
|
|
case XS_LOCAL:
|
2012-09-14 19:13:12 +08:00
|
|
|
err = xenstored_local_init();
|
|
|
|
if (err)
|
|
|
|
goto out_error;
|
2015-08-08 00:34:42 +08:00
|
|
|
xen_store_interface = gfn_to_virt(xen_store_gfn);
|
2012-09-14 19:13:12 +08:00
|
|
|
break;
|
2013-05-29 01:09:55 +08:00
|
|
|
case XS_PV:
|
2012-09-14 19:13:12 +08:00
|
|
|
xen_store_evtchn = xen_start_info->store_evtchn;
|
2015-08-08 00:34:42 +08:00
|
|
|
xen_store_gfn = xen_start_info->store_mfn;
|
|
|
|
xen_store_interface = gfn_to_virt(xen_store_gfn);
|
2012-09-14 19:13:12 +08:00
|
|
|
break;
|
2013-05-29 01:09:55 +08:00
|
|
|
case XS_HVM:
|
2011-10-14 04:07:08 +08:00
|
|
|
err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
|
|
|
|
if (err)
|
|
|
|
goto out_error;
|
|
|
|
xen_store_evtchn = (int)v;
|
|
|
|
err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
|
|
|
|
if (err)
|
|
|
|
goto out_error;
|
2015-08-08 00:34:42 +08:00
|
|
|
xen_store_gfn = (unsigned long)v;
|
2012-09-14 19:13:12 +08:00
|
|
|
xen_store_interface =
|
2015-05-05 23:38:27 +08:00
|
|
|
xen_remap(xen_store_gfn << XEN_PAGE_SHIFT,
|
|
|
|
XEN_PAGE_SIZE);
|
2012-09-14 19:13:12 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_warn("Xenstore state unknown\n");
|
|
|
|
break;
|
2007-07-18 09:37:06 +08:00
|
|
|
}
|
|
|
|
|
xen: Fix event channel callback via INTX/GSI
For a while, event channel notification via the PCI platform device
has been broken, because we attempt to communicate with xenstore before
we even have notifications working, with the xs_reset_watches() call
in xs_init().
We tend to get away with this on Xen versions below 4.0 because we avoid
calling xs_reset_watches() anyway, because xenstore might not cope with
reading a non-existent key. And newer Xen *does* have the vector
callback support, so we rarely fall back to INTX/GSI delivery.
To fix it, clean up a bit of the mess of xs_init() and xenbus_probe()
startup. Call xs_init() directly from xenbus_init() only in the !XS_HVM
case, deferring it to be called from xenbus_probe() in the XS_HVM case
instead.
Then fix up the invocation of xenbus_probe() to happen either from its
device_initcall if the callback is available early enough, or when the
callback is finally set up. This means that the hack of calling
xenbus_probe() from a workqueue after the first interrupt, or directly
from the PCI platform device setup, is no longer needed.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/20210113132606.422794-2-dwmw2@infradead.org
Signed-off-by: Juergen Gross <jgross@suse.com>
2021-01-13 21:26:02 +08:00
|
|
|
/*
|
|
|
|
* HVM domains may not have a functional callback yet. In that
|
|
|
|
* case let xs_init() be called from xenbus_probe(), which will
|
|
|
|
* get invoked at an appropriate time.
|
|
|
|
*/
|
|
|
|
if (xen_store_domain_type != XS_HVM) {
|
|
|
|
err = xs_init();
|
|
|
|
if (err) {
|
|
|
|
pr_warn("Error initializing xenstore comms: %i\n", err);
|
|
|
|
goto out_error;
|
|
|
|
}
|
2007-07-18 09:37:06 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 05:10:13 +08:00
|
|
|
if ((xen_store_domain_type != XS_LOCAL) &&
|
|
|
|
(xen_store_domain_type != XS_UNKNOWN))
|
|
|
|
xen_resume_notifier_register(&xenbus_resume_nb);
|
|
|
|
|
2009-01-08 10:07:11 +08:00
|
|
|
#ifdef CONFIG_XEN_COMPAT_XENFS
|
|
|
|
/*
|
|
|
|
* Create xenfs mountpoint in /proc for compatibility with
|
|
|
|
* utilities that expect to find "xenbus" under "/proc/xen".
|
|
|
|
*/
|
2016-11-14 19:12:56 +08:00
|
|
|
proc_create_mount_point("xen");
|
2009-01-08 10:07:11 +08:00
|
|
|
#endif
|
|
|
|
|
2011-07-26 19:17:23 +08:00
|
|
|
out_error:
|
2007-07-18 09:37:06 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-05-18 00:08:21 +08:00
|
|
|
postcore_initcall(xenbus_init);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|