Skip to content

Commit

Permalink
Merge tag 'uml-for-linus-6.3-rc1' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/kernel/git/uml/linux

Pull UML updates from Richard Weinberger:

 - Add support for rust (yay!)

 - Add support for LTO

 - Add platform bus support to virtio-pci

 - Various virtio fixes

 - Coding style, spelling cleanups

* tag 'uml-for-linus-6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/uml/linux: (27 commits)
  Documentation: rust: Fix arch support table
  uml: vector: Remove unused definitions VECTOR_{WRITE,HEADERS}
  um: virt-pci: properly remove PCI device from bus
  um: virtio_uml: move device breaking into workqueue
  um: virtio_uml: mark device as unregistered when breaking it
  um: virtio_uml: free command if adding to virtqueue failed
  UML: define RUNTIME_DISCARD_EXIT
  virt-pci: add platform bus support
  um-virt-pci: Make max delay configurable
  um: virt-pci: implement pcibios_get_phb_of_node()
  um: Support LTO
  um: put power options in a menu
  um: Use CFLAGS_vmlinux
  um: Prevent building modules incompatible with MODVERSIONS
  um: Avoid pcap multiple definition errors
  um: Make the definition of cpu_data more compatible
  x86: um: vdso: Add '%rcx' and '%r11' to the syscall clobber list
  rust: arch/um: Add support for CONFIG_RUST under x86_64 UML
  rust: arch/um: Disable FP/SIMD instruction to match x86
  rust: arch/um: Use 'pie' relocation mode under UML
  ...
  • Loading branch information
torvalds committed Mar 1, 2023
2 parents e31b283 + 04df97e commit 64e8516
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 111 deletions.
2 changes: 2 additions & 0 deletions Documentation/rust/arch-support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
Architecture Level of support Constraints
============ ================ ==============================================
``x86`` Maintained ``x86_64`` only.
``um`` Maintained ``x86_64`` only.
============ ================ ==============================================

7 changes: 7 additions & 0 deletions arch/um/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ config UML
select GENERIC_IRQ_SHOW
select GENERIC_CPU_DEVICES
select HAVE_GCC_PLUGINS
select ARCH_SUPPORTS_LTO_CLANG
select ARCH_SUPPORTS_LTO_CLANG_THIN
select TRACE_IRQFLAGS_SUPPORT
select TTY # Needed for line.c
select HAVE_ARCH_VMAP_STACK
select HAVE_RUST if X86_64

config MMU
bool
Expand Down Expand Up @@ -242,4 +245,8 @@ source "arch/um/drivers/Kconfig"
config ARCH_SUSPEND_POSSIBLE
def_bool y

menu "Power management options"

source "kernel/power/Kconfig"

endmenu
7 changes: 4 additions & 3 deletions arch/um/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
-Din6addr_loopback=kernel_in6addr_loopback \
-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr

KBUILD_RUSTFLAGS += -Crelocation-model=pie

KBUILD_AFLAGS += $(ARCH_INCLUDE)

USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
Expand Down Expand Up @@ -139,11 +141,10 @@ ifeq ($(CONFIG_LD_IS_BFD),y)
LDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments)
endif

LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt))
LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS) $(LDFLAGS_EXECSTACK),-Wl,$(opt))

# Used by link-vmlinux.sh which has special support for um link
export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
export LDFLAGS_vmlinux := $(LDFLAGS_EXECSTACK)
export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) $(CC_FLAGS_LTO)

# When cleaning we don't include .config, so we don't include
# TT or skas makefiles and don't clean skas_ptregs.h.
Expand Down
2 changes: 2 additions & 0 deletions arch/um/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ config UML_NET_VECTOR
config UML_NET_VDE
bool "VDE transport (obsolete)"
depends on UML_NET
depends on !MODVERSIONS
select MAY_HAVE_RUNTIME_DEPS
help
This User-Mode Linux network transport allows one or more running
Expand Down Expand Up @@ -309,6 +310,7 @@ config UML_NET_MCAST
config UML_NET_PCAP
bool "pcap transport (obsolete)"
depends on UML_NET
depends on !MODVERSIONS
select MAY_HAVE_RUNTIME_DEPS
help
The pcap transport makes a pcap packet stream on the host look
Expand Down
4 changes: 2 additions & 2 deletions arch/um/drivers/pcap_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct pcap_init {
char *filter;
};

void pcap_init(struct net_device *dev, void *data)
void pcap_init_kern(struct net_device *dev, void *data)
{
struct uml_net_private *pri;
struct pcap_data *ppri;
Expand Down Expand Up @@ -44,7 +44,7 @@ static int pcap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
}

static const struct net_kern_info pcap_kern_info = {
.init = pcap_init,
.init = pcap_init_kern,
.protocol = eth_protocol,
.read = pcap_read,
.write = pcap_write,
Expand Down
1 change: 1 addition & 0 deletions arch/um/drivers/vector_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ static int vector_config(char *str, char **error_out)

if (parsed == NULL) {
*error_out = "vector_config failed to parse parameters";
kfree(params);
return -EINVAL;
}

Expand Down
2 changes: 0 additions & 2 deletions arch/um/drivers/vector_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ struct vector_fds {
};

#define VECTOR_READ 1
#define VECTOR_WRITE (1 < 1)
#define VECTOR_HEADERS (1 < 2)

extern struct arglist *uml_parse_vector_ifspec(char *arg);

Expand Down
139 changes: 132 additions & 7 deletions arch/um/drivers/virt-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/virtio.h>
#include <linux/virtio_config.h>
#include <linux/logic_iomem.h>
#include <linux/of_platform.h>
#include <linux/irqdomain.h>
#include <linux/virtio_pcidev.h>
#include <linux/virtio-uml.h>
Expand Down Expand Up @@ -39,6 +40,8 @@ struct um_pci_device {
unsigned long status;

int irq;

bool platform;
};

struct um_pci_device_reg {
Expand All @@ -48,13 +51,15 @@ struct um_pci_device_reg {

static struct pci_host_bridge *bridge;
static DEFINE_MUTEX(um_pci_mtx);
static struct um_pci_device *um_pci_platform_device;
static struct um_pci_device_reg um_pci_devices[MAX_DEVICES];
static struct fwnode_handle *um_pci_fwnode;
static struct irq_domain *um_pci_inner_domain;
static struct irq_domain *um_pci_msi_domain;
static unsigned long um_pci_msi_used[BITS_TO_LONGS(MAX_MSI_VECTORS)];

#define UM_VIRT_PCI_MAXDELAY 40000
static unsigned int um_pci_max_delay_us = 40000;
module_param_named(max_delay_us, um_pci_max_delay_us, uint, 0644);

struct um_pci_message_buffer {
struct virtio_pcidev_msg hdr;
Expand Down Expand Up @@ -132,8 +137,11 @@ static int um_pci_send_cmd(struct um_pci_device *dev,
out ? 1 : 0,
posted ? cmd : HANDLE_NO_FREE(cmd),
GFP_ATOMIC);
if (ret)
if (ret) {
if (posted)
kfree(cmd);
goto out;
}

if (posted) {
virtqueue_kick(dev->cmd_vq);
Expand All @@ -155,7 +163,7 @@ static int um_pci_send_cmd(struct um_pci_device *dev,
kfree(completed);

if (WARN_ONCE(virtqueue_is_broken(dev->cmd_vq) ||
++delay_count > UM_VIRT_PCI_MAXDELAY,
++delay_count > um_pci_max_delay_us,
"um virt-pci delay: %d", delay_count)) {
ret = -EIO;
break;
Expand Down Expand Up @@ -480,6 +488,9 @@ static void um_pci_handle_irq_message(struct virtqueue *vq,
struct virtio_device *vdev = vq->vdev;
struct um_pci_device *dev = vdev->priv;

if (!dev->irq)
return;

/* we should properly chain interrupts, but on ARCH=um we don't care */

switch (msg->op) {
Expand Down Expand Up @@ -533,6 +544,25 @@ static void um_pci_irq_vq_cb(struct virtqueue *vq)
}
}

/* Copied from arch/x86/kernel/devicetree.c */
struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
{
struct device_node *np;

for_each_node_by_type(np, "pci") {
const void *prop;
unsigned int bus_min;

prop = of_get_property(np, "bus-range", NULL);
if (!prop)
continue;
bus_min = be32_to_cpup(prop);
if (bus->number == bus_min)
return np;
}
return NULL;
}

static int um_pci_init_vqs(struct um_pci_device *dev)
{
struct virtqueue *vqs[2];
Expand Down Expand Up @@ -561,6 +591,55 @@ static int um_pci_init_vqs(struct um_pci_device *dev)
return 0;
}

static void __um_pci_virtio_platform_remove(struct virtio_device *vdev,
struct um_pci_device *dev)
{
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);

mutex_lock(&um_pci_mtx);
um_pci_platform_device = NULL;
mutex_unlock(&um_pci_mtx);

kfree(dev);
}

static int um_pci_virtio_platform_probe(struct virtio_device *vdev,
struct um_pci_device *dev)
{
int ret;

dev->platform = true;

mutex_lock(&um_pci_mtx);

if (um_pci_platform_device) {
mutex_unlock(&um_pci_mtx);
ret = -EBUSY;
goto out_free;
}

ret = um_pci_init_vqs(dev);
if (ret) {
mutex_unlock(&um_pci_mtx);
goto out_free;
}

um_pci_platform_device = dev;

mutex_unlock(&um_pci_mtx);

ret = of_platform_default_populate(vdev->dev.of_node, NULL, &vdev->dev);
if (ret)
__um_pci_virtio_platform_remove(vdev, dev);

return ret;

out_free:
kfree(dev);
return ret;
}

static int um_pci_virtio_probe(struct virtio_device *vdev)
{
struct um_pci_device *dev;
Expand All @@ -574,6 +653,9 @@ static int um_pci_virtio_probe(struct virtio_device *vdev)
dev->vdev = vdev;
vdev->priv = dev;

if (of_device_is_compatible(vdev->dev.of_node, "simple-bus"))
return um_pci_virtio_platform_probe(vdev, dev);

mutex_lock(&um_pci_mtx);
for (i = 0; i < MAX_DEVICES; i++) {
if (um_pci_devices[i].dev)
Expand Down Expand Up @@ -623,22 +705,39 @@ static void um_pci_virtio_remove(struct virtio_device *vdev)
struct um_pci_device *dev = vdev->priv;
int i;

/* Stop all virtqueues */
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);
if (dev->platform) {
of_platform_depopulate(&vdev->dev);
__um_pci_virtio_platform_remove(vdev, dev);
return;
}

device_set_wakeup_enable(&vdev->dev, false);

mutex_lock(&um_pci_mtx);
for (i = 0; i < MAX_DEVICES; i++) {
if (um_pci_devices[i].dev != dev)
continue;

um_pci_devices[i].dev = NULL;
irq_free_desc(dev->irq);

break;
}
mutex_unlock(&um_pci_mtx);

um_pci_rescan();
if (i < MAX_DEVICES) {
struct pci_dev *pci_dev;

pci_dev = pci_get_slot(bridge->bus, i);
if (pci_dev)
pci_stop_and_remove_bus_device_locked(pci_dev);
}

/* Stop all virtqueues */
virtio_reset_device(vdev);
dev->cmd_vq = NULL;
dev->irq_vq = NULL;
vdev->config->del_vqs(vdev);

kfree(dev);
}
Expand Down Expand Up @@ -860,6 +959,30 @@ void *pci_root_bus_fwnode(struct pci_bus *bus)
return um_pci_fwnode;
}

static long um_pci_map_platform(unsigned long offset, size_t size,
const struct logic_iomem_ops **ops,
void **priv)
{
if (!um_pci_platform_device)
return -ENOENT;

*ops = &um_pci_device_bar_ops;
*priv = &um_pci_platform_device->resptr[0];

return 0;
}

static const struct logic_iomem_region_ops um_pci_platform_ops = {
.map = um_pci_map_platform,
};

static struct resource virt_platform_resource = {
.name = "platform",
.start = 0x10000000,
.end = 0x1fffffff,
.flags = IORESOURCE_MEM,
};

static int __init um_pci_init(void)
{
int err, i;
Expand All @@ -868,6 +991,8 @@ static int __init um_pci_init(void)
&um_pci_cfgspace_ops));
WARN_ON(logic_iomem_add_region(&virt_iomem_resource,
&um_pci_iomem_ops));
WARN_ON(logic_iomem_add_region(&virt_platform_resource,
&um_pci_platform_ops));

if (WARN(CONFIG_UML_PCI_OVER_VIRTIO_DEVICE_ID < 0,
"No virtio device ID configured for PCI - no PCI support\n"))
Expand Down
20 changes: 18 additions & 2 deletions arch/um/drivers/virtio_uml.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ static void vhost_user_check_reset(struct virtio_uml_device *vu_dev,
if (!vu_dev->registered)
return;

virtio_break_device(&vu_dev->vdev);
vu_dev->registered = 0;

schedule_work(&pdata->conn_broken_wk);
}

Expand Down Expand Up @@ -412,7 +413,7 @@ static irqreturn_t vu_req_read_message(struct virtio_uml_device *vu_dev,
if (msg.msg.header.flags & VHOST_USER_FLAG_NEED_REPLY)
vhost_user_reply(vu_dev, &msg.msg, response);
irq_rc = IRQ_HANDLED;
};
}
/* mask EAGAIN as we try non-blocking read until socket is empty */
vu_dev->recv_rc = (rc == -EAGAIN) ? 0 : rc;
return irq_rc;
Expand Down Expand Up @@ -1136,6 +1137,15 @@ void virtio_uml_set_no_vq_suspend(struct virtio_device *vdev,

static void vu_of_conn_broken(struct work_struct *wk)
{
struct virtio_uml_platform_data *pdata;
struct virtio_uml_device *vu_dev;

pdata = container_of(wk, struct virtio_uml_platform_data, conn_broken_wk);

vu_dev = platform_get_drvdata(pdata->pdev);

virtio_break_device(&vu_dev->vdev);

/*
* We can't remove the device from the devicetree so the only thing we
* can do is warn.
Expand Down Expand Up @@ -1266,8 +1276,14 @@ static int vu_unregister_cmdline_device(struct device *dev, void *data)
static void vu_conn_broken(struct work_struct *wk)
{
struct virtio_uml_platform_data *pdata;
struct virtio_uml_device *vu_dev;

pdata = container_of(wk, struct virtio_uml_platform_data, conn_broken_wk);

vu_dev = platform_get_drvdata(pdata->pdev);

virtio_break_device(&vu_dev->vdev);

vu_unregister_cmdline_device(&pdata->pdev->dev, NULL);
}

Expand Down
Loading

0 comments on commit 64e8516

Please sign in to comment.