qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Liu Ping Fan <kernelfans@gmail.com>
Cc: aliguori@us.ibm.com, kvm@vger.kernel.org, qemu-devel@nongnu.org,
	linux-kernel@vger.kernel.org, ryanh@us.ibm.com,
	jan.kiszka@web.de, avi@redhat.com
Subject: Re: [Qemu-devel] [PATCH] virtio: add a pci driver to notify host the CPU_DEAD event
Date: Sun, 27 Nov 2011 13:10:58 +0200	[thread overview]
Message-ID: <20111127111058.GN2557@redhat.com> (raw)
In-Reply-To: <1322362063-22569-1-git-send-email-kernelfans@gmail.com>

On Sun, Nov 27, 2011 at 10:47:43AM +0800, Liu Ping Fan wrote:
> From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> 
> A driver for qemu device "cpustate". This driver catch the guest
> CPU_DEAD event, and notify host.
> 
And if you do eject properly via ACPI this driver is replaced by 3 lines
of ACPI code and works with older guests too.

> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> ---
>  drivers/virtio/Kconfig         |    6 ++
>  drivers/virtio/Makefile        |    1 +
>  drivers/virtio/cpustate_stub.c |  154 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 161 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/virtio/cpustate_stub.c
> 
> diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
> index 816ed08..96ad253 100644
> --- a/drivers/virtio/Kconfig
> +++ b/drivers/virtio/Kconfig
> @@ -46,4 +46,10 @@ config VIRTIO_BALLOON
>  
>   	 If unsure, say N.
>  
> + config VIRTIO_CPUSTATE
> + 	tristate "Driver to notify host the cpu dead event (EXPERIMENTAL)"
> + 	depends on EXPERIMENTAL
> + 	---help---
> + 	 This drivers provides support to notify host the cpu dead event.
> +
>  endmenu
> diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
> index 5a4c63c..06a5ecf 100644
> --- a/drivers/virtio/Makefile
> +++ b/drivers/virtio/Makefile
> @@ -3,3 +3,4 @@ obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o
>  obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
>  obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
>  obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
> +obj-$(VIRTIO_CPUSTATE) += cpustate_stub.o
> diff --git a/drivers/virtio/cpustate_stub.c b/drivers/virtio/cpustate_stub.c
> new file mode 100644
> index 0000000..614da9d
> --- /dev/null
> +++ b/drivers/virtio/cpustate_stub.c
> @@ -0,0 +1,154 @@
> +/*
> + * PCI driver for qemu cpustate device. It notifies host the CPU_DEAD event
> + * in guest.
> + *
> + * Copyright IBM Corp. 2011
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +#include <linux/module.h>
> +#include <linux/list.h>
> +#include <linux/cpu.h>
> +#include <linux/pci.h>
> +#include <linux/slab.h>
> +#include <linux/interrupt.h>
> +#include <linux/spinlock.h>
> +
> +#define PCI_DEVICE_ID_CPUSTATE 0x1010
> +
> +struct cpustate_stub_regs {
> +	unsigned int cpu_phyid;
> +	unsigned int event;
> +};
> +
> +struct cpustate_stub {
> +	struct work_struct work;
> +
> +	unsigned int cpu_phyid;
> +	unsigned int event;
> +
> +	struct cpustate_stub_regs __iomem *regs;
> +};
> +
> +static struct cpustate_stub *agent;
> +
> +static void cpustate_work(struct work_struct *work)
> +{
> +	struct cpustate_stub *stub = container_of(work,
> +					struct cpustate_stub, work);
> +	printk(KERN_INFO "%s,cpu_phyid=0x%x, event=0x%x\n",
> +		__func__, stub->cpu_phyid, stub->event);
> +	stub->regs->cpu_phyid = stub->cpu_phyid;
> +	stub->regs->event = stub->event;
> +	barrier();
> +}
> +
> +static int cpu_dead_callback(struct notifier_block *b, unsigned long action,
> +				 void *data)
> +{
> +	unsigned long cpu = (unsigned long)data;
> +	int cpu_phyid;
> +	switch (action) {
> +	case CPU_DEAD:{
> +		cpu_phyid = per_cpu(x86_cpu_to_apicid, cpu);
> +		agent->cpu_phyid = cpu_phyid;
> +		agent->event = CPU_DEAD;
> +		schedule_work(&agent->work);
> +		break;
> +	}
> +	default:
> +		break;
> +	}
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block __cpuinitdata cpu_dead_notifier = {
> +	.notifier_call	= cpu_dead_callback,
> +	.priority	= 10,
> +};
> +
> +static int __devinit cpustate_probe(struct pci_dev *pci_dev,
> +	const struct pci_device_id *id)
> +{
> +	int ret = 0;
> +	agent = kzalloc(sizeof(struct cpustate_stub), GFP_KERNEL);
> +	if (agent == NULL) {
> +		ret = -1;
> +		goto fail;
> +	}
> +	/* enable the device */
> +	ret = pci_enable_device(pci_dev);
> +	if (ret) {
> +		printk(KERN_WARNING "%s, pci_enable_device fail,ret=0x%x\n",
> +			__func__, ret);
> +		goto fail;
> +	}
> +
> +	ret = pci_request_regions(pci_dev, "cpustate");
> +	if (ret) {
> +		printk(KERN_WARNING "%s, pci_request_regions fail,ret=0x%x\n",
> +			__func__, ret);
> +		goto out_enable_device;
> +	}
> +
> +	agent->regs = ioremap(pci_dev->resource[0].start,
> +			pci_dev->resource[0].end - pci_dev->resource[0].start);
> +	if (agent->regs == NULL) {
> +		printk(KERN_WARNING "%s, ioremap fail\n", __func__);
> +		goto out_req_regions;
> +	}
> +
> +	INIT_WORK(&agent->work, cpustate_work);
> +	register_cpu_notifier(&cpu_dead_notifier);
> +	printk(KERN_INFO "%s, success\n", __func__);
> +	return 0;
> +
> +out_req_regions:
> +	pci_release_regions(pci_dev);
> +out_enable_device:
> +	pci_disable_device(pci_dev);
> +	kfree(agent);
> +	agent = NULL;
> +fail:
> +	printk(KERN_WARNING "%s fail\n", __func__);
> +	return ret;
> +}
> +
> +static void __devexit cpustate_remove(struct pci_dev *pci_dev)
> +{
> +	unregister_cpu_notifier(&cpu_dead_notifier);
> +}
> +
> +/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */
> +static DEFINE_PCI_DEVICE_TABLE(pci_cpustate_id_table) = {
> +	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_CPUSTATE,
> +		PCI_ANY_ID, PCI_ANY_ID,
> +		PCI_CLASS_SYSTEM_OTHER, 0,
> +		0 },
> +	{ 0 },
> +};
> +MODULE_DEVICE_TABLE(pci, pci_cpustate_id_table);
> +
> +static struct pci_driver pci_cpustate_driver = {
> +	.name		= "cpustate",
> +	.id_table	= pci_cpustate_id_table,
> +	.probe		= cpustate_probe,
> +	.remove		= __devexit_p(cpustate_remove),
> +};
> +
> +static int __init pci_cpustate_init(void)
> +{
> +	return pci_register_driver(&pci_cpustate_driver);
> +}
> +module_init(pci_cpustate_init);
> +
> +static void __exit pci_cpustate_exit(void)
> +{
> +	pci_unregister_driver(&pci_cpustate_driver);
> +}
> +module_exit(pci_cpustate_exit);
> +MODULE_DESCRIPTION("cpustate");
> +MODULE_LICENSE("GPL");
> +MODULE_VERSION("1");
> -- 
> 1.7.4.4
> 

--
			Gleb.

      reply	other threads:[~2011-11-27 11:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-25  2:35 [Qemu-devel] [PATCH 0] A series patches for kvm&qemu to enable vcpu destruction in kvm Liu Ping Fan
2011-11-25  2:35 ` [Qemu-devel] [PATCH 1/2] kvm: make vcpu life cycle separated from kvm instance Liu Ping Fan
2011-11-27 10:36   ` Avi Kivity
2011-11-25 17:54 ` [Qemu-devel] [PATCH 0] A series patches for kvm&qemu to enable vcpu destruction in kvm Jan Kiszka
2011-11-27  3:07   ` Liu ping fan
2011-11-27  2:42 ` [Qemu-devel] [PATCH 2/2] kvm: exit to userspace with reason KVM_EXIT_VCPU_DEAD Liu Ping Fan
2011-11-27 10:36   ` Avi Kivity
2011-11-27 10:50     ` Gleb Natapov
2011-11-28  7:16       ` Liu ping fan
2011-11-28  8:46         ` Gleb Natapov
2011-11-27  2:45 ` [Qemu-devel] [PATCH 1/5] QEMU Add cpu_phyid_to_cpu() to map cpu phyid to CPUState Liu Ping Fan
2011-11-27  2:45 ` [Qemu-devel] [PATCH 2/5] QEMU Add cpu_free() to support arch related CPUState release Liu Ping Fan
2011-11-27  2:45 ` [Qemu-devel] [PATCH 3/5] QEMU Introduce a pci device "cpustate" to get CPU_DEAD event in guest Liu Ping Fan
2011-11-27 10:56   ` Gleb Natapov
2011-11-27  2:45 ` [Qemu-devel] [PATCH 4/5] QEMU Release vcpu and finally exit vcpu thread safely Liu Ping Fan
2011-11-29  5:37   ` ShaoHe Feng
2011-11-27  2:45 ` [Qemu-devel] [PATCH 5/5] QEMU tmp patches for linux-header files Liu Ping Fan
2011-11-27  2:47 ` [Qemu-devel] [PATCH] virtio: add a pci driver to notify host the CPU_DEAD event Liu Ping Fan
2011-11-27 11:10   ` Gleb Natapov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111127111058.GN2557@redhat.com \
    --to=gleb@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=jan.kiszka@web.de \
    --cc=kernelfans@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ryanh@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).