Changes in 5.4.274 amdkfd: use calloc instead of kzalloc to avoid integer overflow Documentation/hw-vuln: Update spectre doc x86/cpu: Support AMD Automatic IBRS x86/bugs: Use sysfs_emit() timers: Update kernel-doc for various functions timers: Use del_timer_sync() even on UP timers: Rename del_timer_sync() to timer_delete_sync() wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach media: staging: ipu3-imgu: Set fields before media_entity_pads_init() clk: qcom: gcc-sdm845: Add soft dependency on rpmhpd smack: Set SMACK64TRANSMUTE only for dirs in smack_inode_setxattr() smack: Handle SMACK64TRANSMUTE in smack_inode_setsecurity() ARM: dts: mmp2-brownstone: Don't redeclare phandle references arm: dts: marvell: Fix maxium->maxim typo in brownstone dts serial: max310x: fix NULL pointer dereference in I2C instantiation media: xc4000: Fix atomicity violation in xc4000_get_frequency KVM: Always flush async #PF workqueue when vCPU is being destroyed sparc64: NMI watchdog: fix return value of __setup handler sparc: vDSO: fix return value of __setup handler crypto: qat - fix double free during reset crypto: qat - resolve race condition during AER recovery selftests/mqueue: Set timeout to 180 seconds ext4: correct best extent lstart adjustment logic fat: fix uninitialized field in nostale filehandles ubifs: Set page uptodate in the correct place ubi: Check for too small LEB size in VTBL code ubi: correct the calculation of fastmap size mtd: rawnand: meson: fix scrambling mode value in command macro parisc: Do not hardcode registers in checksum functions parisc: Fix ip_fast_csum parisc: Fix csum_ipv6_magic on 32-bit systems parisc: Fix csum_ipv6_magic on 64-bit systems parisc: Strip upper 32 bit of sum in csum_ipv6_magic for 64-bit builds PM: suspend: Set mem_sleep_current during kernel command line setup clk: qcom: gcc-ipq8074: fix terminating of frequency table arrays clk: qcom: mmcc-apq8084: fix terminating of frequency table arrays clk: qcom: mmcc-msm8974: fix terminating of frequency table arrays powerpc/fsl: Fix mfpmr build errors with newer binutils USB: serial: ftdi_sio: add support for GMC Z216C Adapter IR-USB USB: serial: add device ID for VeriFone adapter USB: serial: cp210x: add ID for MGP Instruments PDS100 USB: serial: option: add MeiG Smart SLM320 product USB: serial: cp210x: add pid/vid for TDK NC0110013M and MM0110113M PM: sleep: wakeirq: fix wake irq warning in system suspend mmc: tmio: avoid concurrent runs of mmc_request_done() fuse: don't unhash root btrfs: fix off-by-one chunk length calculation at contains_pending_extent() PCI: Drop pci_device_remove() test of pci_dev->driver PCI/PM: Drain runtime-idle callbacks before driver removal Revert "Revert "md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d"" dm-raid: fix lockdep waring in "pers->hot_add_disk" mmc: core: Fix switch on gp3 partition hwmon: (amc6821) add of_match table ext4: fix corruption during on-line resize firmware: meson_sm: Rework driver as a proper platform driver nvmem: meson-efuse: fix function pointer type mismatch slimbus: core: Remove usage of the deprecated ida_simple_xx() API speakup: Fix 8bit characters from direct synth kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 vfio/platform: Disable virqfds on cleanup ring-buffer: Fix resetting of shortest_full ring-buffer: Fix full_waiters_pending in poll soc: fsl: qbman: Always disable interrupts when taking cgr_lock soc: fsl: qbman: Add helper for sanity checking cgr ops soc: fsl: qbman: Add CGR update function soc: fsl: qbman: Use raw spinlock for cgr_lock s390/zcrypt: fix reference counting on zcrypt card objects drm/exynos: do not return negative values from .get_modes() drm/imx/ipuv3: do not return negative values from .get_modes() drm/vc4: hdmi: do not return negative values from .get_modes() memtest: use {READ,WRITE}_ONCE in memory scanning nilfs2: fix failure to detect DAT corruption in btree and direct mappings nilfs2: use a more common logging style nilfs2: prevent kernel bug at submit_bh_wbc() x86/CPU/AMD: Update the Zenbleed microcode revisions ahci: asm1064: correct count of reported ports ahci: asm1064: asm1166: don't limit reported ports dm snapshot: fix lockup in dm_exception_table_exit comedi: comedi_test: Prevent timers rescheduling during deletion netfilter: nf_tables: mark set as dead when unbinding anonymous set with timeout netfilter: nf_tables: disallow anonymous set with timeout flag netfilter: nf_tables: reject constant set with timeout xfrm: Avoid clang fortify warning in copy_to_user_tmpl() ALSA: hda/realtek - Fix headset Mic no show at resume back for Lenovo ALC897 platform USB: usb-storage: Prevent divide-by-0 error in isd200_ata_command usb: gadget: ncm: Fix handling of zero block length packets usb: port: Don't try to peer unused USB ports based on location tty: serial: fsl_lpuart: avoid idle preamble pending if CTS is enabled vt: fix unicode buffer corruption when deleting characters fs/aio: Check IOCB_AIO_RW before the struct aio_kiocb conversion objtool: is_fentry_call() crashes if call has no destination objtool: Add support for intra-function calls x86/speculation: Support intra-function call validation xen/events: close evtchn after mapping cleanup printk: Update @console_may_schedule in console_trylock_spinning() btrfs: allocate btrfs_ioctl_defrag_range_args on stack Revert "loop: Check for overflow while configuring loop" loop: Call loop_config_discard() only after new config is applied loop: Remove sector_t truncation checks loop: Factor out setting loop device size loop: Refactor loop_set_status() size calculation loop: Factor out configuring loop from status loop: Check for overflow while configuring loop loop: loop_set_status_from_info() check before assignment perf/core: Fix reentry problem in perf_output_read_group() efivarfs: Request at most 512 bytes for variable names powerpc: xor_vmx: Add '-mhard-float' to CFLAGS bounds: support non-power-of-two CONFIG_NR_CPUS vt: fix memory overlapping when deleting chars in the buffer mm/memory-failure: fix an incorrect use of tail pages mm/migrate: set swap entry values of THP tail pages properly. wifi: mac80211: check/clear fast rx for non-4addr sta VLAN changes exec: Fix NOMMU linux_binprm::exec in transfer_args_to_stack() mmc: core: Initialize mmc_blk_ioc_data mmc: core: Avoid negative index with array access usb: cdc-wdm: close race between read and workqueue ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs scsi: core: Fix unremoved procfs host directory regression usb: dwc2: host: Fix remote wakeup from hibernation usb: dwc2: host: Fix hibernation flow usb: dwc2: host: Fix ISOC flow in DDMA mode usb: dwc2: gadget: LPM flow fix usb: udc: remove warning when queue disabled ep scsi: qla2xxx: Fix command flush on cable pull x86/cpu: Enable STIBP on AMD if Automatic IBRS is enabled scsi: lpfc: Correct size for wqe for memset() USB: core: Fix deadlock in usb_deauthorize_interface() nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet ixgbe: avoid sleeping allocation in ixgbe_ipsec_vf_add_sa() tcp: properly terminate timers for kernel sockets dm integrity: fix out-of-range warning r8169: fix issue caused by buggy BIOS on certain boards with RTL8168d x86/cpufeatures: Add new word for scattered features Bluetooth: hci_event: set the conn encrypted before conn establishes Bluetooth: Fix TOCTOU in HCI debugfs implementation netfilter: nf_tables: disallow timeout for anonymous sets net/rds: fix possible cp null dereference vfio/pci: Disable auto-enable of exclusive INTx IRQ vfio/pci: Lock external INTx masking ops vfio: Introduce interface to flush virqfd inject workqueue vfio/pci: Create persistent INTx handler vfio/platform: Create persistent IRQ handlers Revert "x86/mm/ident_map: Use gbpages only where full GB page should be mapped." mm, vmscan: prevent infinite loop for costly GFP_NOIO | __GFP_RETRY_MAYFAIL allocations netfilter: nf_tables: flush pending destroy work before exit_net release netfilter: nf_tables: Fix potential data-race in __nft_flowtable_type_get() bpf, sockmap: Prevent lock inversion deadlock in map delete elem net/sched: act_skbmod: prevent kernel-infoleak net: stmmac: fix rx queue priority assignment selftests: reuseaddr_conflict: add missing new line at the end of the output ipv6: Fix infinite recursion in fib6_dump_done(). i40e: fix vf may be used uninitialized in this function warning staging: mmal-vchiq: Allocate and free components as required staging: mmal-vchiq: Fix client_component for 64 bit kernel staging: vc04_services: changen strncpy() to strscpy_pad() staging: vc04_services: fix information leak in create_component() fs: add a vfs_fchown helper fs: add a vfs_fchmod helper initramfs: switch initramfs unpacking to struct file based APIs init: open /initrd.image with O_LARGEFILE erspan: Add type I version 0 support. erspan: make sure erspan_base_hdr is present in skb->head net: ravb: Always process TX descriptor ring ASoC: ops: Fix wraparound for mask in snd_soc_get_volsw ata: sata_sx4: fix pdc20621_get_from_dimm() on 64-bit scsi: mylex: Fix sysfs buffer lengths ata: sata_mv: Fix PCI device ID table declaration compilation warning ALSA: hda/realtek: Update Panasonic CF-SZ6 quirk to support headset with microphone x86/mce: Make sure to grab mce_sysfs_mutex in set_bank() s390/entry: align system call table on 8 bytes wifi: ath9k: fix LNA selection in ath_ant_try_scan() VMCI: Fix memcpy() run-time warning in dg_dispatch_as_host() panic: Flush kernel log buffer at the end arm64: dts: rockchip: fix rk3328 hdmi ports node arm64: dts: rockchip: fix rk3399 hdmi ports node ionic: set adminq irq affinity tools/power x86_energy_perf_policy: Fix file leak in get_pkg_num() btrfs: handle chunk tree lookup error in btrfs_relocate_sys_chunks() btrfs: export: handle invalid inode or root reference in btrfs_get_parent() btrfs: send: handle path ref underflow in header iterate_inode_ref() Bluetooth: btintel: Fix null ptr deref in btintel_read_version Input: synaptics-rmi4 - fail probing if memory allocation for "phys" fails sysv: don't call sb_bread() with pointers_lock held scsi: lpfc: Fix possible memory leak in lpfc_rcv_padisc() isofs: handle CDs with bad root inode but good Joliet root directory media: sta2x11: fix irq handler cast drm/amd/display: Fix nanosec stat overflow SUNRPC: increase size of rpc_wait_queue.qlen from unsigned short to unsigned int Revert "ACPI: PM: Block ASUS B1400CEAE from suspend to idle by default" block: prevent division by zero in blk_rq_stat_sum() Input: allocate keycode for Display refresh rate toggle ktest: force $buildonly = 1 for 'make_warnings_file' test type tools: iio: replace seekdir() in iio_generic_buffer usb: typec: tcpci: add generic tcpci fallback compatible usb: sl811-hcd: only defined function checkdone if QUIRK2 is defined fbdev: viafb: fix typo in hw_bitblt_1 and hw_bitblt_2 fbmon: prevent division by zero in fb_videomode_from_videomode() netfilter: nf_tables: reject new basechain after table flag update netfilter: nf_tables: release batch on table validation from abort path netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path netfilter: nf_tables: discard table flag update with pending basechain deletion tty: n_gsm: require CAP_NET_ADMIN to attach N_GSM0710 ldisc drm/vkms: call drm_atomic_helper_shutdown before drm_dev_put() virtio: reenable config if freezing device failed x86/mm/pat: fix VM_PAT handling in COW mappings drm/i915/gt: Reset queue_priority_hint on parking x86/alternative: Don't call text_poke() in lazy TLB mode Bluetooth: btintel: Fixe build regression VMCI: Fix possible memcpy() run-time warning in vmci_datagram_invoke_guest_handler() erspan: Check IFLA_GRE_ERSPAN_VER is set. ip_gre: do not report erspan version on GRE interface firmware: meson_sm: fix to avoid potential NULL pointer dereference Linux 5.4.274 Change-Id: I759c99412f0d27d194308663aa08ab3682a1c43c Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
468 lines
11 KiB
C
468 lines
11 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#include <linux/virtio.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/virtio_config.h>
|
|
#include <linux/module.h>
|
|
#include <linux/idr.h>
|
|
#include <uapi/linux/virtio_ids.h>
|
|
|
|
/* Unique numbering for virtio devices. */
|
|
static DEFINE_IDA(virtio_index_ida);
|
|
|
|
static ssize_t device_show(struct device *_d,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct virtio_device *dev = dev_to_virtio(_d);
|
|
return sprintf(buf, "0x%04x\n", dev->id.device);
|
|
}
|
|
static DEVICE_ATTR_RO(device);
|
|
|
|
static ssize_t vendor_show(struct device *_d,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct virtio_device *dev = dev_to_virtio(_d);
|
|
return sprintf(buf, "0x%04x\n", dev->id.vendor);
|
|
}
|
|
static DEVICE_ATTR_RO(vendor);
|
|
|
|
static ssize_t status_show(struct device *_d,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct virtio_device *dev = dev_to_virtio(_d);
|
|
return sprintf(buf, "0x%08x\n", dev->config->get_status(dev));
|
|
}
|
|
static DEVICE_ATTR_RO(status);
|
|
|
|
static ssize_t modalias_show(struct device *_d,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct virtio_device *dev = dev_to_virtio(_d);
|
|
return sprintf(buf, "virtio:d%08Xv%08X\n",
|
|
dev->id.device, dev->id.vendor);
|
|
}
|
|
static DEVICE_ATTR_RO(modalias);
|
|
|
|
static ssize_t features_show(struct device *_d,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct virtio_device *dev = dev_to_virtio(_d);
|
|
unsigned int i;
|
|
ssize_t len = 0;
|
|
|
|
/* We actually represent this as a bitstring, as it could be
|
|
* arbitrary length in future. */
|
|
for (i = 0; i < sizeof(dev->features)*8; i++)
|
|
len += sprintf(buf+len, "%c",
|
|
__virtio_test_bit(dev, i) ? '1' : '0');
|
|
len += sprintf(buf+len, "\n");
|
|
return len;
|
|
}
|
|
static DEVICE_ATTR_RO(features);
|
|
|
|
static struct attribute *virtio_dev_attrs[] = {
|
|
&dev_attr_device.attr,
|
|
&dev_attr_vendor.attr,
|
|
&dev_attr_status.attr,
|
|
&dev_attr_modalias.attr,
|
|
&dev_attr_features.attr,
|
|
NULL,
|
|
};
|
|
ATTRIBUTE_GROUPS(virtio_dev);
|
|
|
|
static inline int virtio_id_match(const struct virtio_device *dev,
|
|
const struct virtio_device_id *id)
|
|
{
|
|
if (id->device != dev->id.device && id->device != VIRTIO_DEV_ANY_ID)
|
|
return 0;
|
|
|
|
return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor == dev->id.vendor;
|
|
}
|
|
|
|
/* This looks through all the IDs a driver claims to support. If any of them
|
|
* match, we return 1 and the kernel will call virtio_dev_probe(). */
|
|
static int virtio_dev_match(struct device *_dv, struct device_driver *_dr)
|
|
{
|
|
unsigned int i;
|
|
struct virtio_device *dev = dev_to_virtio(_dv);
|
|
const struct virtio_device_id *ids;
|
|
|
|
ids = drv_to_virtio(_dr)->id_table;
|
|
for (i = 0; ids[i].device; i++)
|
|
if (virtio_id_match(dev, &ids[i]))
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
static int virtio_uevent(struct device *_dv, struct kobj_uevent_env *env)
|
|
{
|
|
struct virtio_device *dev = dev_to_virtio(_dv);
|
|
|
|
return add_uevent_var(env, "MODALIAS=virtio:d%08Xv%08X",
|
|
dev->id.device, dev->id.vendor);
|
|
}
|
|
|
|
void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
|
|
unsigned int fbit)
|
|
{
|
|
unsigned int i;
|
|
struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver);
|
|
|
|
for (i = 0; i < drv->feature_table_size; i++)
|
|
if (drv->feature_table[i] == fbit)
|
|
return;
|
|
|
|
if (drv->feature_table_legacy) {
|
|
for (i = 0; i < drv->feature_table_size_legacy; i++)
|
|
if (drv->feature_table_legacy[i] == fbit)
|
|
return;
|
|
}
|
|
|
|
BUG();
|
|
}
|
|
EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature);
|
|
|
|
static void __virtio_config_changed(struct virtio_device *dev)
|
|
{
|
|
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
|
|
|
if (!dev->config_enabled)
|
|
dev->config_change_pending = true;
|
|
else if (drv && drv->config_changed)
|
|
drv->config_changed(dev);
|
|
}
|
|
|
|
void virtio_config_changed(struct virtio_device *dev)
|
|
{
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&dev->config_lock, flags);
|
|
__virtio_config_changed(dev);
|
|
spin_unlock_irqrestore(&dev->config_lock, flags);
|
|
}
|
|
EXPORT_SYMBOL_GPL(virtio_config_changed);
|
|
|
|
void virtio_config_disable(struct virtio_device *dev)
|
|
{
|
|
spin_lock_irq(&dev->config_lock);
|
|
dev->config_enabled = false;
|
|
spin_unlock_irq(&dev->config_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(virtio_config_disable);
|
|
|
|
void virtio_config_enable(struct virtio_device *dev)
|
|
{
|
|
spin_lock_irq(&dev->config_lock);
|
|
dev->config_enabled = true;
|
|
if (dev->config_change_pending)
|
|
__virtio_config_changed(dev);
|
|
dev->config_change_pending = false;
|
|
spin_unlock_irq(&dev->config_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(virtio_config_enable);
|
|
|
|
void virtio_add_status(struct virtio_device *dev, unsigned int status)
|
|
{
|
|
might_sleep();
|
|
dev->config->set_status(dev, dev->config->get_status(dev) | status);
|
|
}
|
|
EXPORT_SYMBOL_GPL(virtio_add_status);
|
|
|
|
/* Do some validation, then set FEATURES_OK */
|
|
static int virtio_features_ok(struct virtio_device *dev)
|
|
{
|
|
unsigned status;
|
|
|
|
might_sleep();
|
|
|
|
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
|
|
return 0;
|
|
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
|
|
status = dev->config->get_status(dev);
|
|
if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
|
|
dev_err(&dev->dev, "virtio: device refuses features: %x\n",
|
|
status);
|
|
return -ENODEV;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int virtio_dev_probe(struct device *_d)
|
|
{
|
|
int err, i;
|
|
struct virtio_device *dev = dev_to_virtio(_d);
|
|
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
|
u64 device_features;
|
|
u64 driver_features;
|
|
u64 driver_features_legacy;
|
|
|
|
/* We have a driver! */
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
|
|
|
|
/* Figure out what features the device supports. */
|
|
device_features = dev->config->get_features(dev);
|
|
|
|
/* Figure out what features the driver supports. */
|
|
driver_features = 0;
|
|
for (i = 0; i < drv->feature_table_size; i++) {
|
|
unsigned int f = drv->feature_table[i];
|
|
BUG_ON(f >= 64);
|
|
driver_features |= (1ULL << f);
|
|
}
|
|
|
|
/* Some drivers have a separate feature table for virtio v1.0 */
|
|
if (drv->feature_table_legacy) {
|
|
driver_features_legacy = 0;
|
|
for (i = 0; i < drv->feature_table_size_legacy; i++) {
|
|
unsigned int f = drv->feature_table_legacy[i];
|
|
BUG_ON(f >= 64);
|
|
driver_features_legacy |= (1ULL << f);
|
|
}
|
|
} else {
|
|
driver_features_legacy = driver_features;
|
|
}
|
|
|
|
if (device_features & (1ULL << VIRTIO_F_VERSION_1))
|
|
dev->features = driver_features & device_features;
|
|
else
|
|
dev->features = driver_features_legacy & device_features;
|
|
|
|
/* Transport features always preserved to pass to finalize_features. */
|
|
for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
|
|
if (device_features & (1ULL << i))
|
|
__virtio_set_bit(dev, i);
|
|
|
|
err = dev->config->finalize_features(dev);
|
|
if (err)
|
|
goto err;
|
|
|
|
if (drv->validate) {
|
|
u64 features = dev->features;
|
|
|
|
err = drv->validate(dev);
|
|
if (err)
|
|
goto err;
|
|
|
|
/* Did validation change any features? Then write them again. */
|
|
if (features != dev->features) {
|
|
err = dev->config->finalize_features(dev);
|
|
if (err)
|
|
goto err;
|
|
}
|
|
}
|
|
|
|
err = virtio_features_ok(dev);
|
|
if (err)
|
|
goto err;
|
|
|
|
err = drv->probe(dev);
|
|
if (err)
|
|
goto err;
|
|
|
|
/* If probe didn't do it, mark device DRIVER_OK ourselves. */
|
|
if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
|
|
virtio_device_ready(dev);
|
|
|
|
if (drv->scan)
|
|
drv->scan(dev);
|
|
|
|
virtio_config_enable(dev);
|
|
|
|
return 0;
|
|
err:
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
|
|
return err;
|
|
|
|
}
|
|
|
|
static int virtio_dev_remove(struct device *_d)
|
|
{
|
|
struct virtio_device *dev = dev_to_virtio(_d);
|
|
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
|
|
|
virtio_config_disable(dev);
|
|
|
|
drv->remove(dev);
|
|
|
|
/* Driver should have reset device. */
|
|
WARN_ON_ONCE(dev->config->get_status(dev));
|
|
|
|
/* Acknowledge the device's existence again. */
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
|
|
return 0;
|
|
}
|
|
|
|
static struct bus_type virtio_bus = {
|
|
.name = "virtio",
|
|
.match = virtio_dev_match,
|
|
.dev_groups = virtio_dev_groups,
|
|
.uevent = virtio_uevent,
|
|
.probe = virtio_dev_probe,
|
|
.remove = virtio_dev_remove,
|
|
};
|
|
|
|
int register_virtio_driver(struct virtio_driver *driver)
|
|
{
|
|
/* Catch this early. */
|
|
BUG_ON(driver->feature_table_size && !driver->feature_table);
|
|
driver->driver.bus = &virtio_bus;
|
|
return driver_register(&driver->driver);
|
|
}
|
|
EXPORT_SYMBOL_GPL(register_virtio_driver);
|
|
|
|
void unregister_virtio_driver(struct virtio_driver *driver)
|
|
{
|
|
driver_unregister(&driver->driver);
|
|
}
|
|
EXPORT_SYMBOL_GPL(unregister_virtio_driver);
|
|
|
|
/**
|
|
* register_virtio_device - register virtio device
|
|
* @dev : virtio device to be registered
|
|
*
|
|
* On error, the caller must call put_device on &@dev->dev (and not kfree),
|
|
* as another code path may have obtained a reference to @dev.
|
|
*
|
|
* Returns: 0 on suceess, -error on failure
|
|
*/
|
|
int register_virtio_device(struct virtio_device *dev)
|
|
{
|
|
int err;
|
|
|
|
dev->dev.bus = &virtio_bus;
|
|
device_initialize(&dev->dev);
|
|
|
|
/* Assign a unique device index and hence name. */
|
|
err = ida_simple_get(&virtio_index_ida, 0, 0, GFP_KERNEL);
|
|
if (err < 0)
|
|
goto out;
|
|
|
|
dev->index = err;
|
|
dev_set_name(&dev->dev, "virtio%u", dev->index);
|
|
|
|
spin_lock_init(&dev->config_lock);
|
|
dev->config_enabled = false;
|
|
dev->config_change_pending = false;
|
|
|
|
/* We always start by resetting the device, in case a previous
|
|
* driver messed it up. This also tests that code path a little. */
|
|
dev->config->reset(dev);
|
|
|
|
/* Acknowledge that we've seen the device. */
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
|
|
|
|
INIT_LIST_HEAD(&dev->vqs);
|
|
|
|
/*
|
|
* device_add() causes the bus infrastructure to look for a matching
|
|
* driver.
|
|
*/
|
|
err = device_add(&dev->dev);
|
|
if (err)
|
|
ida_simple_remove(&virtio_index_ida, dev->index);
|
|
out:
|
|
if (err)
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(register_virtio_device);
|
|
|
|
void unregister_virtio_device(struct virtio_device *dev)
|
|
{
|
|
int index = dev->index; /* save for after device release */
|
|
|
|
device_unregister(&dev->dev);
|
|
ida_simple_remove(&virtio_index_ida, index);
|
|
}
|
|
EXPORT_SYMBOL_GPL(unregister_virtio_device);
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
int virtio_device_freeze(struct virtio_device *dev)
|
|
{
|
|
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
|
int ret;
|
|
|
|
virtio_config_disable(dev);
|
|
|
|
dev->failed = dev->config->get_status(dev) & VIRTIO_CONFIG_S_FAILED;
|
|
|
|
if (drv && drv->freeze) {
|
|
ret = drv->freeze(dev);
|
|
if (ret) {
|
|
virtio_config_enable(dev);
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(virtio_device_freeze);
|
|
|
|
int virtio_device_restore(struct virtio_device *dev)
|
|
{
|
|
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
|
int ret;
|
|
|
|
/* We always start by resetting the device, in case a previous
|
|
* driver messed it up. */
|
|
dev->config->reset(dev);
|
|
|
|
/* Acknowledge that we've seen the device. */
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
|
|
|
|
/* Maybe driver failed before freeze.
|
|
* Restore the failed status, for debugging. */
|
|
if (dev->failed)
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
|
|
|
|
if (!drv)
|
|
return 0;
|
|
|
|
/* We have a driver! */
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
|
|
|
|
ret = dev->config->finalize_features(dev);
|
|
if (ret)
|
|
goto err;
|
|
|
|
ret = virtio_features_ok(dev);
|
|
if (ret)
|
|
goto err;
|
|
|
|
if (drv->restore) {
|
|
ret = drv->restore(dev);
|
|
if (ret)
|
|
goto err;
|
|
}
|
|
|
|
/* Finally, tell the device we're all set */
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
|
|
|
|
virtio_config_enable(dev);
|
|
|
|
return 0;
|
|
|
|
err:
|
|
virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(virtio_device_restore);
|
|
#endif
|
|
|
|
static int virtio_init(void)
|
|
{
|
|
if (bus_register(&virtio_bus) != 0)
|
|
panic("virtio bus registration failed");
|
|
return 0;
|
|
}
|
|
|
|
static void __exit virtio_exit(void)
|
|
{
|
|
bus_unregister(&virtio_bus);
|
|
ida_destroy(&virtio_index_ida);
|
|
}
|
|
core_initcall(virtio_init);
|
|
module_exit(virtio_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|