kvm.vger.kernel.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: [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:10 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-25  2:35 [PATCH 0] A series patches for kvm&qemu to enable vcpu destruction in kvm Liu Ping Fan
2011-11-25  2:35 ` [PATCH 1/2] kvm: make vcpu life cycle separated from kvm instance Liu Ping Fan
2011-11-27 10:36   ` Avi Kivity
2011-12-02  6:26     ` [PATCH] " Liu Ping Fan
2011-12-02 18:26       ` Jan Kiszka
2011-12-04 11:53         ` Liu ping fan
2011-12-04 12:10           ` Gleb Natapov
2011-12-05  5:39             ` Liu ping fan
2011-12-05  8:41               ` Gleb Natapov
2011-12-06  6:54                 ` Liu ping fan
2011-12-06  8:14                   ` Gleb Natapov
2011-12-04 10:23       ` Avi Kivity
2011-12-05  5:29         ` Liu ping fan
2011-12-05  9:30           ` Avi Kivity
2011-12-05  9:42             ` Gleb Natapov
2011-12-05  9:58               ` Avi Kivity
2011-12-05 10:18                 ` Gleb Natapov
2011-12-05 10:22                   ` Avi Kivity
2011-12-05 10:40                     ` Gleb Natapov
2011-12-09  5:23       ` [PATCH V2] " Liu Ping Fan
2011-12-09 14:23         ` Gleb Natapov
2011-12-12  2:41           ` [PATCH v3] " Liu Ping Fan
2011-12-12 12:54             ` Gleb Natapov
2011-12-13  9:29               ` Liu ping fan
2011-12-13  9:47                 ` Gleb Natapov
2011-12-13 11:36             ` Marcelo Tosatti
2011-12-13 11:54               ` Gleb Natapov
2011-12-15  3:21               ` Liu ping fan
2011-12-15  4:28                 ` [PATCH v4] " Liu Ping Fan
2011-12-15  5:33                   ` Xiao Guangrong
2011-12-15  6:53                     ` Liu ping fan
2011-12-15  8:25                       ` Xiao Guangrong
2011-12-15  8:57                         ` Xiao Guangrong
2011-12-15  6:48                   ` Takuya Yoshikawa
2011-12-16  9:38                     ` Marcelo Tosatti
2011-12-17  3:57                     ` Liu ping fan
2011-12-19  1:16                       ` Takuya Yoshikawa
2011-12-15  9:10                   ` Gleb Natapov
2011-12-16  7:50                     ` Liu ping fan
2011-12-15  8:33                 ` [PATCH v3] " Gleb Natapov
2011-12-15  9:06                   ` Liu ping fan
2011-12-15  9:08                     ` Gleb Natapov
2011-12-17  3:19             ` [PATCH v5] " Liu Ping Fan
2011-12-26 11:09               ` Gleb Natapov
2011-12-26 11:17                 ` Avi Kivity
2011-12-26 11:21                   ` Gleb Natapov
2011-12-27  7:53                 ` Liu ping fan
2011-12-27  8:38               ` [PATCH v6] " Liu Ping Fan
2011-12-27 11:22                 ` Takuya Yoshikawa
2011-12-28  6:54                   ` Liu ping fan
2011-12-28  9:53                     ` Avi Kivity
2011-12-29 14:03                       ` Liu ping fan
2011-12-29 14:31                         ` Avi Kivity
2012-01-05  9:35                           ` Liu ping fan
2011-12-28 10:29                     ` Takuya Yoshikawa
2011-12-28  9:53                 ` Avi Kivity
2011-12-28  9:54                   ` Avi Kivity
2011-12-28 10:19                     ` Takuya Yoshikawa
2011-12-28 10:28                       ` Avi Kivity
2012-01-07  2:55               ` [PATCH v7] " Liu Ping Fan
2012-01-12 12:37                 ` Avi Kivity
2012-01-15 13:17                   ` Liu ping fan
2012-01-15 13:37                     ` Avi Kivity
2011-11-25 17:54 ` [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 ` [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       ` [Qemu-devel] " Liu ping fan
2011-11-28  8:46         ` Gleb Natapov
2011-11-27  2:45 ` [PATCH 1/5] QEMU Add cpu_phyid_to_cpu() to map cpu phyid to CPUState Liu Ping Fan
2011-11-27  2:45 ` [PATCH 2/5] QEMU Add cpu_free() to support arch related CPUState release Liu Ping Fan
2011-11-27  2:45 ` [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 ` [PATCH 4/5] QEMU Release vcpu and finally exit vcpu thread safely Liu Ping Fan
2011-11-27  2:45 ` [PATCH 5/5] QEMU tmp patches for linux-header files Liu Ping Fan
2011-11-27  2:47 ` [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).