2007-07-18 09:37:06 +08:00
|
|
|
/******************************************************************************
|
|
|
|
* xenbus.h
|
|
|
|
*
|
|
|
|
* Talks to Xen Store to figure out what devices we have.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Rusty Russell, IBM Corporation
|
|
|
|
* Copyright (C) 2005 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _XEN_XENBUS_H
|
|
|
|
#define _XEN_XENBUS_H
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/mutex.h>
|
2011-07-11 01:22:07 +08:00
|
|
|
#include <linux/export.h>
|
2017-02-09 21:39:56 +08:00
|
|
|
#include <linux/fs.h>
|
2007-07-18 09:37:06 +08:00
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/init.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>
|
2020-03-05 18:03:23 +08:00
|
|
|
#include <linux/semaphore.h>
|
2007-07-18 09:37:06 +08:00
|
|
|
#include <xen/interface/xen.h>
|
|
|
|
#include <xen/interface/grant_table.h>
|
|
|
|
#include <xen/interface/io/xenbus.h>
|
|
|
|
#include <xen/interface/io/xs_wire.h>
|
2020-03-24 00:15:11 +08:00
|
|
|
#include <xen/interface/event_channel.h>
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2015-10-14 00:50:11 +08:00
|
|
|
#define XENBUS_MAX_RING_GRANT_ORDER 4
|
|
|
|
#define XENBUS_MAX_RING_GRANTS (1U << XENBUS_MAX_RING_GRANT_ORDER)
|
2015-04-03 14:44:59 +08:00
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
/* Register callback to watch this node. */
|
|
|
|
struct xenbus_watch
|
|
|
|
{
|
|
|
|
struct list_head list;
|
|
|
|
|
|
|
|
/* Path being watched. */
|
|
|
|
const char *node;
|
|
|
|
|
2020-12-14 17:07:13 +08:00
|
|
|
unsigned int nr_pending;
|
|
|
|
|
xen/xenbus: Allow watches discard events before queueing
If handling logics of watch events are slower than the events enqueue
logic and the events can be created from the guests, the guests could
trigger memory pressure by intensively inducing the events, because it
will create a huge number of pending events that exhausting the memory.
Fortunately, some watch events could be ignored, depending on its
handler callback. For example, if the callback has interest in only one
single path, the watch wouldn't want multiple pending events. Or, some
watches could ignore events to same path.
To let such watches to volutarily help avoiding the memory pressure
situation, this commit introduces new watch callback, 'will_handle'. If
it is not NULL, it will be called for each new event just before
enqueuing it. Then, if the callback returns false, the event will be
discarded. No watch is using the callback for now, though.
This is part of XSA-349
Cc: stable@vger.kernel.org
Signed-off-by: SeongJae Park <sjpark@amazon.de>
Reported-by: Michael Kurth <mku@amazon.de>
Reported-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
2020-12-14 17:02:45 +08:00
|
|
|
/*
|
|
|
|
* Called just before enqueing new event while a spinlock is held.
|
|
|
|
* The event will be discarded if this callback returns false.
|
|
|
|
*/
|
|
|
|
bool (*will_handle)(struct xenbus_watch *,
|
|
|
|
const char *path, const char *token);
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
/* Callback (executed in a process context with no locks held). */
|
|
|
|
void (*callback)(struct xenbus_watch *,
|
2017-02-09 21:39:57 +08:00
|
|
|
const char *path, const char *token);
|
2007-07-18 09:37:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* A xenbus device. */
|
|
|
|
struct xenbus_device {
|
|
|
|
const char *devicetype;
|
|
|
|
const char *nodename;
|
|
|
|
const char *otherend;
|
|
|
|
int otherend_id;
|
|
|
|
struct xenbus_watch otherend_watch;
|
|
|
|
struct device dev;
|
|
|
|
enum xenbus_state state;
|
|
|
|
struct completion down;
|
2013-05-29 01:09:56 +08:00
|
|
|
struct work_struct work;
|
2020-03-05 18:03:23 +08:00
|
|
|
struct semaphore reclaim_sem;
|
2021-02-19 23:40:28 +08:00
|
|
|
|
|
|
|
/* Event channel based statistics and settings. */
|
|
|
|
atomic_t event_channels;
|
|
|
|
atomic_t events;
|
|
|
|
atomic_t spurious_events;
|
|
|
|
atomic_t jiffies_eoi_delayed;
|
|
|
|
unsigned int spurious_threshold;
|
2007-07-18 09:37:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct xenbus_device *to_xenbus_device(struct device *dev)
|
|
|
|
{
|
|
|
|
return container_of(dev, struct xenbus_device, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct xenbus_device_id
|
|
|
|
{
|
|
|
|
/* .../device/<device_type>/<identifier> */
|
|
|
|
char devicetype[32]; /* General class of device. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A xenbus driver. */
|
|
|
|
struct xenbus_driver {
|
2014-09-09 00:30:41 +08:00
|
|
|
const char *name; /* defaults to ids[0].devicetype */
|
2007-07-18 09:37:06 +08:00
|
|
|
const struct xenbus_device_id *ids;
|
2019-12-11 23:29:54 +08:00
|
|
|
bool allow_rebind; /* avoid setting xenstore closed during remove */
|
2007-07-18 09:37:06 +08:00
|
|
|
int (*probe)(struct xenbus_device *dev,
|
|
|
|
const struct xenbus_device_id *id);
|
|
|
|
void (*otherend_changed)(struct xenbus_device *dev,
|
|
|
|
enum xenbus_state backend_state);
|
|
|
|
int (*remove)(struct xenbus_device *dev);
|
2011-02-19 06:43:07 +08:00
|
|
|
int (*suspend)(struct xenbus_device *dev);
|
2007-07-18 09:37:06 +08:00
|
|
|
int (*resume)(struct xenbus_device *dev);
|
2009-02-10 04:05:51 +08:00
|
|
|
int (*uevent)(struct xenbus_device *, struct kobj_uevent_env *);
|
2007-07-18 09:37:06 +08:00
|
|
|
struct device_driver driver;
|
|
|
|
int (*read_otherend_details)(struct xenbus_device *dev);
|
2008-04-03 01:54:04 +08:00
|
|
|
int (*is_ready)(struct xenbus_device *dev);
|
2020-01-27 16:18:08 +08:00
|
|
|
void (*reclaim_memory)(struct xenbus_device *dev);
|
2007-07-18 09:37:06 +08:00
|
|
|
};
|
|
|
|
|
2011-12-22 17:08:13 +08:00
|
|
|
static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
|
2007-07-18 09:37:06 +08:00
|
|
|
{
|
2011-12-22 17:08:13 +08:00
|
|
|
return container_of(drv, struct xenbus_driver, driver);
|
2007-07-18 09:37:06 +08:00
|
|
|
}
|
|
|
|
|
2014-09-09 00:30:41 +08:00
|
|
|
int __must_check __xenbus_register_frontend(struct xenbus_driver *drv,
|
|
|
|
struct module *owner,
|
|
|
|
const char *mod_name);
|
|
|
|
int __must_check __xenbus_register_backend(struct xenbus_driver *drv,
|
|
|
|
struct module *owner,
|
|
|
|
const char *mod_name);
|
|
|
|
|
|
|
|
#define xenbus_register_frontend(drv) \
|
2015-03-01 18:57:38 +08:00
|
|
|
__xenbus_register_frontend(drv, THIS_MODULE, KBUILD_MODNAME)
|
2014-09-09 00:30:41 +08:00
|
|
|
#define xenbus_register_backend(drv) \
|
2015-03-01 18:57:38 +08:00
|
|
|
__xenbus_register_backend(drv, THIS_MODULE, KBUILD_MODNAME)
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
void xenbus_unregister_driver(struct xenbus_driver *drv);
|
|
|
|
|
|
|
|
struct xenbus_transaction
|
|
|
|
{
|
|
|
|
u32 id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Nil transaction ID. */
|
|
|
|
#define XBT_NIL ((struct xenbus_transaction) { 0 })
|
|
|
|
|
|
|
|
char **xenbus_directory(struct xenbus_transaction t,
|
|
|
|
const char *dir, const char *node, unsigned int *num);
|
|
|
|
void *xenbus_read(struct xenbus_transaction t,
|
|
|
|
const char *dir, const char *node, unsigned int *len);
|
|
|
|
int xenbus_write(struct xenbus_transaction t,
|
|
|
|
const char *dir, const char *node, const char *string);
|
|
|
|
int xenbus_mkdir(struct xenbus_transaction t,
|
|
|
|
const char *dir, const char *node);
|
|
|
|
int xenbus_exists(struct xenbus_transaction t,
|
|
|
|
const char *dir, const char *node);
|
|
|
|
int xenbus_rm(struct xenbus_transaction t, const char *dir, const char *node);
|
|
|
|
int xenbus_transaction_start(struct xenbus_transaction *t);
|
|
|
|
int xenbus_transaction_end(struct xenbus_transaction t, int abort);
|
|
|
|
|
|
|
|
/* Single read and scanf: returns -errno or num scanned if > 0. */
|
2012-03-24 06:02:16 +08:00
|
|
|
__scanf(4, 5)
|
2007-07-18 09:37:06 +08:00
|
|
|
int xenbus_scanf(struct xenbus_transaction t,
|
2012-03-24 06:02:16 +08:00
|
|
|
const char *dir, const char *node, const char *fmt, ...);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
2016-10-31 21:58:40 +08:00
|
|
|
/* Read an (optional) unsigned value. */
|
|
|
|
unsigned int xenbus_read_unsigned(const char *dir, const char *node,
|
|
|
|
unsigned int default_val);
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
/* Single printf and write: returns -errno or 0. */
|
2011-11-01 08:11:33 +08:00
|
|
|
__printf(4, 5)
|
2007-07-18 09:37:06 +08:00
|
|
|
int xenbus_printf(struct xenbus_transaction t,
|
2011-11-01 08:11:33 +08:00
|
|
|
const char *dir, const char *node, const char *fmt, ...);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
/* Generic read function: NULL-terminated triples of name,
|
|
|
|
* sprintf-style type string, and pointer. Returns 0 or errno.*/
|
|
|
|
int xenbus_gather(struct xenbus_transaction t, const char *dir, ...);
|
|
|
|
|
|
|
|
/* notifer routines for when the xenstore comes up */
|
|
|
|
extern int xenstored_ready;
|
|
|
|
int register_xenstore_notifier(struct notifier_block *nb);
|
|
|
|
void unregister_xenstore_notifier(struct notifier_block *nb);
|
|
|
|
|
|
|
|
int register_xenbus_watch(struct xenbus_watch *watch);
|
|
|
|
void unregister_xenbus_watch(struct xenbus_watch *watch);
|
|
|
|
void xs_suspend(void);
|
|
|
|
void xs_resume(void);
|
|
|
|
void xs_suspend_cancel(void);
|
|
|
|
|
|
|
|
struct work_struct;
|
|
|
|
|
|
|
|
#define XENBUS_IS_ERR_READ(str) ({ \
|
|
|
|
if (!IS_ERR(str) && strlen(str) == 0) { \
|
|
|
|
kfree(str); \
|
|
|
|
str = ERR_PTR(-ERANGE); \
|
|
|
|
} \
|
|
|
|
IS_ERR(str); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define XENBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
|
|
|
|
|
|
|
|
int xenbus_watch_path(struct xenbus_device *dev, const char *path,
|
|
|
|
struct xenbus_watch *watch,
|
2020-12-14 17:04:18 +08:00
|
|
|
bool (*will_handle)(struct xenbus_watch *,
|
|
|
|
const char *, const char *),
|
2007-07-18 09:37:06 +08:00
|
|
|
void (*callback)(struct xenbus_watch *,
|
2017-02-09 21:39:57 +08:00
|
|
|
const char *, const char *));
|
2020-12-14 17:04:18 +08:00
|
|
|
__printf(5, 6)
|
2007-07-18 09:37:06 +08:00
|
|
|
int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
|
2020-12-14 17:04:18 +08:00
|
|
|
bool (*will_handle)(struct xenbus_watch *,
|
|
|
|
const char *, const char *),
|
2007-07-18 09:37:06 +08:00
|
|
|
void (*callback)(struct xenbus_watch *,
|
2017-02-09 21:39:57 +08:00
|
|
|
const char *, const char *),
|
2011-11-01 08:11:33 +08:00
|
|
|
const char *pathfmt, ...);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
|
2015-04-03 14:44:59 +08:00
|
|
|
int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
|
|
|
|
unsigned int nr_pages, grant_ref_t *grefs);
|
|
|
|
int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
|
|
|
|
unsigned int nr_grefs, void **vaddr);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
|
|
|
|
|
2020-03-24 00:15:11 +08:00
|
|
|
int xenbus_alloc_evtchn(struct xenbus_device *dev, evtchn_port_t *port);
|
|
|
|
int xenbus_free_evtchn(struct xenbus_device *dev, evtchn_port_t port);
|
2007-07-18 09:37:06 +08:00
|
|
|
|
|
|
|
enum xenbus_state xenbus_read_driver_state(const char *path);
|
|
|
|
|
2011-11-01 08:11:33 +08:00
|
|
|
__printf(3, 4)
|
2007-07-18 09:37:06 +08:00
|
|
|
void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
|
2011-11-01 08:11:33 +08:00
|
|
|
__printf(3, 4)
|
2007-07-18 09:37:06 +08:00
|
|
|
void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt, ...);
|
|
|
|
|
|
|
|
const char *xenbus_strstate(enum xenbus_state state);
|
|
|
|
int xenbus_dev_is_online(struct xenbus_device *dev);
|
|
|
|
int xenbus_frontend_closed(struct xenbus_device *dev);
|
|
|
|
|
2017-02-09 21:39:56 +08:00
|
|
|
extern const struct file_operations xen_xenbus_fops;
|
|
|
|
extern struct xenstore_domain_interface *xen_store_interface;
|
|
|
|
extern int xen_store_evtchn;
|
|
|
|
|
2007-07-18 09:37:06 +08:00
|
|
|
#endif /* _XEN_XENBUS_H */
|