RE: [Qemu-devel] KVM call agenfda for 2014-04-01

2014-04-10 Thread Stuart Yoder


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Thursday, April 10, 2014 10:57 AM
 To: Peter Maydell
 Cc: Juan Quintela; KVM devel mailing list; qemu list; Yoder Stuart-
 B08248; Alistair Francis; Peter Crosthwaite; Christoffer Dall
 Subject: Re: [Qemu-devel] KVM call agenfda for 2014-04-01
 
 
 On 10.04.2014, at 17:52, Peter Maydell peter.mayd...@linaro.org wrote:
 
  On 10 April 2014 16:49, Alexander Graf ag...@suse.de wrote:
  For the next call, I would propose to revive the platform bus
  (aka: how to create non-PCI devices with -device) discussions
  to make sure we're all on the same page.
 
  I rather suspect we are not :-)  Do you have a link to
  the current proposals for prior reading?
 
 The only thing I could find is the old thread about my platform bus
 approach (which Anthony disliked):
 
   https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg03614.html
 
 So from what I remember the plan moving forward was to have a special
 device type similar to my platform bus devices that you can just create
 using -device, no bus involved. The machine file would then loop through
 them, interpret the I sit at address x and I want interrupt number y
 fields to link them to whatever the machine model thinks is a good fit.
 
 The same way the machine model today has to have knowledge on each device
 tree node type it generates, it would do the same for these devices. So
 the machine has to have awareness of all the funky special options a
 device tree node receives - the same as for any other device. Just that
 in this case it wouldn't be able to hardcode them, but have to generate
 them on the fly when it sees a device in the object tree.

Another link that may help from a call we had back in Sept:
https://lists.cs.columbia.edu/pipermail/kvmarm/2013-September/005532.html

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH] PCI: Introduce new device binding path using pci_dev.driver_override

2014-04-10 Thread Stuart Yoder


 -Original Message-
 From: Alex Williamson [mailto:alex.william...@redhat.com]
 Sent: Friday, April 04, 2014 3:19 PM
 To: bhelg...@google.com; linux-...@vger.kernel.org
 Cc: ag...@suse.de; kvm@vger.kernel.org; konrad.w...@oracle.com;
 kim.phill...@linaro.org; gre...@linuxfoundation.org; Yoder Stuart-B08248;
 linux-ker...@vger.kernel.org; libvir-l...@redhat.com; iommu@lists.linux-
 foundation.org; t...@virtualopensystems.com;
 kvm...@lists.cs.columbia.edu; christoffer.d...@linaro.org
 Subject: [PATCH] PCI: Introduce new device binding path using
 pci_dev.driver_override
 
 The driver_override field allows us to specify the driver for a device
 rather than relying on the driver to provide a positive match of the
 device.  This shortcuts the existing process of looking up the vendor
 and device ID, adding them to the driver new_id, binding the device,
 then removing the ID, but it also provides a couple advantages.
 
 First, the above existing process allows the driver to bind to any
 device matching the new_id for the window where it's enabled.  This is
 often not desired, such as the case of trying to bind a single device
 to a meta driver like pci-stub or vfio-pci.  Using driver_override we
 can do this deterministically using:
 
 echo pci-stub  /sys/bus/pci/devices/:03:00.0/driver_override
 echo :03:00.0  /sys/bus/pci/devices/:03:00.0/driver/unbind
 echo :03:00.0  /sys/bus/pci/drivers_probe
 
 Previously we could not invoke drivers_probe after adding a device
 to new_id for a driver as we get non-deterministic behavior whether
 the driver we intend or the standard driver will claim the device.
 Now it becomes a deterministic process, only the driver matching
 driver_override will probe the device.
 
 To return the device to the standard driver, we simply clear the
 driver_override and reprobe the device:
 
 echo  /sys/bus/pci/devices/:03:00.0/preferred_driver
 echo :03:00.0  /sys/bus/pci/devices/:03:00.0/driver/unbind
 echo :03:00.0  /sys/bus/pci/drivers_probe
 
 Another advantage to this approach is that we can specify a driver
 override to force a specific binding or prevent any binding.  For
 instance when an IOMMU group is exposed to userspace through VFIO
 we require that all devices within that group are owned by VFIO.
 However, devices can be hot-added into an IOMMU group, in which case
 we want to prevent the device from binding to any driver (preferred
 driver = none) or perhaps have it automatically bind to vfio-pci.
 With driver_override it's a simple matter for this field to be set
 internally when the device is first discovered to prevent driver
 matches.
 
 Signed-off-by: Alex Williamson alex.william...@redhat.com
 ---

Reviewed-by: Stuart Yoder stuart.yo...@freescale.com


RE: [PATCH] driver core: platform: add device binding path 'driver_override'

2014-04-10 Thread Stuart Yoder


 -Original Message-
 From: Kim Phillips [mailto:kim.phill...@freescale.com]
 Sent: Tuesday, April 08, 2014 8:47 PM
 To: Alex Williamson; gre...@linuxfoundation.org
 Cc: bhelg...@google.com; linux-...@vger.kernel.org; kvm@vger.kernel.org;
 konrad.w...@oracle.com; Yoder Stuart-B08248; libvir-l...@redhat.com;
 io...@lists.linux-foundation.org; t...@virtualopensystems.com;
 kvm...@lists.cs.columbia.edu; linux-ker...@vger.kernel.org; Guenter
 Roeck; christoffer.d...@linaro.org
 Subject: [PATCH] driver core: platform: add device binding path
 'driver_override'
 
 Needed by platform device drivers, such as the vfio-platform driver [1],
 in order to bypass the existing OF, ACPI, id_table and name string
 matches,
 and successfully be able to be bound to any device, like so:
 
 echo vfio-platform 
 /sys/bus/platform/devices/fff51000.ethernet/driver_override
 echo fff51000.ethernet 
 /sys/bus/platform/devices/fff51000.ethernet/driver/unbind
 echo fff51000.ethernet  /sys/bus/platform/drivers_probe
 
 This mimics PCI: Introduce new device binding path using
 pci_dev.driver_override [2], which is an interface enhancement
 for more deterministic PCI device binding, e.g., when in the
 presence of hotplug.
 
 [1] http://lkml.iu.edu/hypermail/linux/kernel/1402.1/00177.html
 [2] http://lists-archives.com/linux-kernel/28030441-pci-introduce-new-
 device-binding-path-using-pci_dev-driver_override.html
 
 Suggested-by: Alex Williamson alex.william...@redhat.com
 Signed-off-by: Kim Phillips kim.phill...@freescale.com
 ---

Reviewed-by: Stuart Yoder stuart.yo...@freescale.com
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: mechanism to allow a driver to bind to any device

2014-03-31 Thread Stuart Yoder


 -Original Message-
 From: Alex Williamson [mailto:alex.william...@redhat.com]
 Sent: Wednesday, March 26, 2014 5:09 PM
 To: Alexander Graf
 Cc: kvm@vger.kernel.org; jan.kis...@siemens.com; will.dea...@arm.com;
 Yoder Stuart-B08248; a.r...@virtualopensystems.com; Michal Hocko; Wood
 Scott-B07421; Sethi Varun-B16395; kvm...@lists.cs.columbia.edu; Rafael J.
 Wysocki; Guenter Roeck; Dmitry Kasatkin; Tejun Heo; Bjorn Helgaas;
 Antonios Motakis; t...@virtualopensystems.com; Toshi Kani; Greg KH;
 linux-ker...@vger.kernel.org; io...@lists.linux-foundation.org; Joe
 Perches; christoffer.d...@linaro.org
 Subject: Re: mechanism to allow a driver to bind to any device
 
 On Wed, 2014-03-26 at 10:21 -0600, Alex Williamson wrote:
  On Wed, 2014-03-26 at 23:06 +0800, Alexander Graf wrote:
  
Am 26.03.2014 um 22:40 schrieb Konrad Rzeszutek Wilk
 konrad.w...@oracle.com:
   
On Wed, Mar 26, 2014 at 01:40:32AM +, Stuart Yoder wrote:
Hi Greg,
   
We (Linaro, Freescale, Virtual Open Systems) are trying get an
 issue
closed that has been perculating for a while around creating a
 mechanism
that will allow kernel drivers like vfio can bind to devices of
 any type.
   
This thread with you:
http://www.spinics.net/lists/kvm-arm/msg08370.html
...seems to have died out, so am trying to get your response
and will summarize again.  Vfio drivers in the kernel (regardless
 of
bus type) need to bind to devices of any type.  The driver's
 function
is to simply export hardware resources of any type to user space.
   
There are several approaches that have been proposed:
   
You seem to have missed the one I proposed.
   
  1.  new_id -- (current approach) the user explicitly registers
  each new device type with the vfio driver using the new_id
  mechanism.
   
  Problem: multiple drivers will be resident that handle the
  same device type...and there is nothing user space hotplug
  infrastructure can do to help.
   
  2.  any id -- the vfio driver could specify a wildcard match
  of some kind in its ID match table which would allow it to
  match and bind to any possible device id.  However,
  we don't want the vfio driver grabbing _all_ devices...just
 the ones we
  explicitly want to pass to user space.
   
  The proposed patch to support this was to create a new flag
  sysfs_bind_only in struct device_driver.  When this flag
  is set, the driver can only bind to devices via the sysfs
  bind file.  This would allow the wildcard match to work.
   
  Patch is here:
  https://lkml.org/lkml/2013/12/3/253
   
  3.  Driver initiated explicit bind -- with this approach the
  vfio driver would create a private 'bind' sysfs object
  and the user would echo the requested device into it:
   
  echo 0001:03:00.0  /sys/bus/pci/drivers/vfio-pci/vfio_bind
   
  In order to make that work, the driver would need to call
  driver_probe_device() and thus we need this patch:
  https://lkml.org/lkml/2014/2/8/175
   
4). Use the 'unbind' (from the original device) and 'bind' to vfio
 driver.
  
   This is approach 2, no?
  
   
Which I think is what is currently being done. Why is that not
 sufficient?
  
   How would 'bind to vfio driver' look like?
  
The only thing I see in the URL is  That works, but it is ugly.
There is some mention of race but I don't see how - if you do the
 'unbind'
on the original driver and then bind the BDF to the VFIO how would
 you get
a race?
  
   Typically on PCI, you do a
  
 - add wildcard (pci id) match to vfio driver
 - unbind driver
 - reprobe
 - device attaches to vfio driver because it is the least recent
 match
 - remove wildcard match from vfio driver
  
   If in between you hotplug add a card of the same type, it gets
 attached to vfio - even though the logical default driver would be the
 device specific driver.
 
  I've mentioned drivers_autoprobe in the past, but I'm not sure we're
  really factoring it into the discussion.  drivers_autoprobe allows us
 to
  toggle two points:
 
  a) When a new device is added whether we automatically give drivers a
  try at binding to it
 
  b) When a new driver is added whether it gets to try to bind to
 anything
  in the system
 
  So we do have a mechanism to avoid the race, but the problem is that it
  becomes the responsibility of userspace to:
 
  1) turn off drivers_autoprobe
  2) unbind/new_id/bind/remove_id
  3) turn on drivers_autoprobe
  4) call drivers_probe for anything added between 1)  3)
 
  Is the question about the ugliness of the current solution whether it's
  unreasonable to ask userspace to do this?
 
  What we seem to be asking for above is more like an autoprobe flag per
  driver where there's some way for this special driver to opt out of
 auto
  probing.  Option 2

RE: [REPOST][PATCH 1/2] driver core: Add new device_driver flag to allow binding via sysfs only

2013-12-19 Thread Stuart Yoder


 -Original Message-
 From: Greg Kroah-Hartman [mailto:gre...@linuxfoundation.org]
 Sent: Thursday, December 19, 2013 2:34 PM
 To: Wood Scott-B07421
 Cc: Kim Phillips; linux-ker...@vger.kernel.org; kvm@vger.kernel.org;
 Bhushan Bharat-R65777; Yoder Stuart-B08248; christoffer.d...@linaro.org;
 alex.william...@redhat.com; a.mota...@virtualopensystems.com;
 ag...@suse.de; Sethi Varun-B16395
 Subject: Re: [REPOST][PATCH 1/2] driver core: Add new device_driver flag
 to allow binding via sysfs only
 
 On Thu, Dec 19, 2013 at 02:22:11PM -0600, Scott Wood wrote:
  On Wed, 2013-12-18 at 17:07 -0800, Greg Kroah-Hartman wrote:
   On Tue, Dec 03, 2013 at 12:34:46PM +, Kim Phillips wrote:
VFIO supports pass-through of devices to user space - for sake
of illustration, say a PCI e1000 device:
   
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told via new_id that it now handles e1000
 devices
- the e1000 is explicitly bound to vfio-pci through sysfs
   
However, now we have two drivers in the system that both handle
 e1000
devices.  A hotplug event could then occur and it is ambiguous as
 to which
driver will claim the device.  The desired semantics is that vfio-
 pci is
only bound to devices by explicit request in sysfs.  This patch
 makes this
possible by introducing a sysfs_bind_only flag in struct
 device_driver.
  
   Why deal with this at all and not just deal with the bind sysfs
 file
   instead?  That way no driver core logic needs to be changed at all,
 and
   your userspace tools know _exactly_ which device is being bound to
 the
   new device.
  
   Don't mess with the new_id file for stuff like this, as you point
 out,
   it's tricky...
 
  As discussed before, bind does not bypass the ID checks, and thus it
  does not work without either new_id or a wildcard match.
 
 Ah, forgot about that.
 
  Or are you proposing changing bind so that it does bypass the ID
  checks?  Or perhaps a new force_bind file that does?
 
 No.  But you can use bind/unbind along with the existing new_id file to
 get what you want today.

Yes, but that only works for PCI.  There is no such concept for platform
drivers.

 If you just happen to bind a device to a wrong
 driver for a while, that's not really a problem, right?

It's annoying but not the end of the world.

 I don't like this patch as we are adding lots of special and odd logic
 to the core, for use by almost no one, which ensures that it will never
 get tested, and will probably get broken in some subtle way in the
 future.

It certainly will be used by users of vfio-platform.

Here is the problem-- the new platform device match_any_dev mechanism
in patch 2 of this series is not going to work without sysfs_bind_only.
A platform driver that just sets match_any_dev will grab any or all 
platform devices during normal bus probing.

 Heck, I can't even ensure that you got it right now, with this tiny
 patch, how do you know it works given that there are no users of this
 flag anywhere (hint, you never showed me any...)

It has been tested on both vfio-pci and vfio-platform in some limited
experiments as far as I know, but that code is not ready for upstream
yet.

Thanks,
Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [REPOST][PATCH 1/2] driver core: Add new device_driver flag to allow binding via sysfs only

2013-12-19 Thread Stuart Yoder


 -Original Message-
 From: Greg Kroah-Hartman [mailto:gre...@linuxfoundation.org]
 Sent: Thursday, December 19, 2013 4:32 PM
 To: Wood Scott-B07421
 Cc: Yoder Stuart-B08248; Kim Phillips; linux-ker...@vger.kernel.org;
 kvm@vger.kernel.org; Bhushan Bharat-R65777; christoffer.d...@linaro.org;
 alex.william...@redhat.com; a.mota...@virtualopensystems.com;
 ag...@suse.de; Sethi Varun-B16395
 Subject: Re: [REPOST][PATCH 1/2] driver core: Add new device_driver flag
 to allow binding via sysfs only
 
 On Thu, Dec 19, 2013 at 04:15:03PM -0600, Scott Wood wrote:
  On Thu, 2013-12-19 at 13:43 -0800, Greg Kroah-Hartman wrote:
   On Thu, Dec 19, 2013 at 09:06:21PM +, Stuart Yoder wrote:
   
   
 -Original Message-
 From: Greg Kroah-Hartman [mailto:gre...@linuxfoundation.org]
 Sent: Thursday, December 19, 2013 2:34 PM
 To: Wood Scott-B07421
 Cc: Kim Phillips; linux-ker...@vger.kernel.org;
 kvm@vger.kernel.org;
 Bhushan Bharat-R65777; Yoder Stuart-B08248;
 christoffer.d...@linaro.org;
 alex.william...@redhat.com; a.mota...@virtualopensystems.com;
 ag...@suse.de; Sethi Varun-B16395
 Subject: Re: [REPOST][PATCH 1/2] driver core: Add new
 device_driver flag
 to allow binding via sysfs only

 No.  But you can use bind/unbind along with the existing new_id
 file to
 get what you want today.
   
Yes, but that only works for PCI.
  
   No, not only PCI.
  
There is no such concept for platform drivers.
  
   Then fix that.
 
  We've already explained why that would be bad.
 
 No you haven't, or if you have, my squirrel-brain doesn't remember it...
 
   Or make your device not be a platform device, odds are that's the
 better
   solution in the end, right?
 
  How would that solve anything?  We'd just be talking about there not
  being such a mechanism for the device tree bus instead.
 
 Nope, you could add it there, like PCI and other busses have.
 
 I don't like this patch as we are adding lots of special and odd
 logic
 to the core, for use by almost no one, which ensures that it will
 never
 get tested, and will probably get broken in some subtle way in
 the
 future.
   
It certainly will be used by users of vfio-platform.
   
Here is the problem-- the new platform device match_any_dev
 mechanism
in patch 2 of this series is not going to work without
 sysfs_bind_only.
A platform driver that just sets match_any_dev will grab any or
 all
platform devices during normal bus probing.
  
   No it will not, it will fail in the probe function as it knows to not
   grab the device, just like any driver for other busses that say it
 can
   handle all Intel PCI devices and the like.
 
  How will it know not to grab the device?  The knowledge of whether
 the
  binding was explicitly requested or not does not get passed through to
  the probe function.
 
 Nor should it, as a driver should not know, nor care about this.
 
 It's up to the BUS to handle this if it really wants to, and I'm afraid
 that I really am not convinced that the driver core needs to handle it
 either.
 
 But again, as you don't have anything that could actually use this code
 that is mergable, it's a totally moot point, sorry.

Understand, but what assumption do we develop vfio-plaform with?  That
a driver core 'sysfs_bind_only' flag is not an option, period?  If that
is the case we need to go back to square one and invent some new mechanism
to bind devices to the vfio-platform driver.

I guess it would need to be the platform bus equivalent of new_id.

But, then we're left with the potential racy situation where multiple drivers
can potentially grab a device and it's ambiguous and non-deterministic at to 
which
driver binds to it.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] Return info for device and its memory regions and interrupts

2013-11-07 Thread Stuart Yoder
 I will look into this. However, can we rely to have access to all
 device resources through platform abstractions, for every type of
 platform device

 The only resources we care about in vfio are mappable regions
 and irqs.  So, yes I think we can rely on access to those
 resources.

 It seems to me that platform devices that are not
 backed by a specific description mechanism (such as device tree) may
 include a lot of hard coded values etc in their drivers.

 If the platform device struct does not have reg/irq resources described
 then we can't expose them to user space with vfio.

 Which is my concern actually. If the struct does not describe reg/irq
 resources, or even worse if it describes them partially, do we want to
 let the user shoot himself on the foot?

 Granted this might happen with device tree too, but I find it much
 more likely with generic platform devices.

 Maybe we should adopt a whitelist instead?

Just realize I never replied to this query...

If there are no IRQs in the platform device struct we should
just return 0x0 for number of interrupts.
If the information in the platform device struct is only partially
complete, we should just return an error to the caller of the
ioctl.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


driver core patches

2013-11-05 Thread Stuart Yoder
Hi Greg,

Any feedback on the driver core patches in Kim Phillips patch series
from mid-October?

The 3rd patch of the series has some open issues related to vfio-pci,
but the first two are driver core related and am wondering if they
are acceptable.

[PATCH 1/4] driver core: Add new device_driver flag to allow binding via sysfs 
only
http://www.spinics.net/lists/kvm/msg97198.html
[PATCH 2/4] driver core: platform: allow platform drivers to bind to any device
http://www.spinics.net/lists/kvm/msg97195.html

If you have any issues, we would like to get them addressed.

Thanks,
Stuart Yoder

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] armv7 initial device passthrough support

2013-06-24 Thread Stuart Yoder
On Mon, Jun 24, 2013 at 3:01 PM, Christoffer Dall
christoffer.d...@linaro.org wrote:
 On Mon, Jun 24, 2013 at 10:08:08AM +0200, Mario Smarduch wrote:


 On 6/15/2013 5:47 PM, Paolo Bonzini wrote:
  Il 13/06/2013 11:19, Mario Smarduch ha scritto:
  Updated Device Passthrough Patch.
  - optimized IRQ-CPU-vCPU binding, irq is installed once
  - added dynamic IRQ affinity on schedule in
  - added documentation and few other coding recommendations.
 
  Per earlier discussion VFIO is our target but we like
  something earlier to work with to tackle performance
  latency issue (some ARM related) for device passthrough
  while we migrate towards VFIO.
 
  I don't think this is acceptable upstream, unfortunately.  KVM device
  assignment is deprecated and we should not add more users.
 That's fine we'll work our way towards dev-tree VFIO reusing what we can
 working with the community.

 At this point we're more concerned with numbers and best practices as
 opposed to mechanism this part will be time consuming.
 VFIO will be more background for us.

 
  What are the latency issues you have?

 Our focus now is on IRQ latency and throughput. Right now it appears lowest 
 latency
 is 2x + exit/enter + IRQ injection overhead. We can't tolerate additional
 IPIs or deferred IRQ injection approaches. We're looking for numbers closer
 to what IBMs ELI managed. Also high res timers which ARM Virt. Ext supports
 very well. Exitless interrupts which ARM handles very well too. There are
 some future hw ARM interrupt enhancements coming up which may help a lot as 
 well.

 There are many other latency/perf. reqs for NFV related to RT,
 essentially Guest must run near native. In the end it may turn out this
 may need to be outside of main tree we'll see.

 It doesn't sound like this will be the end result.  Everything that you
 try to do in your patch set can be accomplished using VFIO and a more
 generic infrastructure for virtual IRQ integration with KVM and user
 space.

 We should avoid creating an environment with important functionality
 outside of the main tree, if at all possible.

Also, as we architect that generic infrastructure we need to keep in mind that
there are important use cases for doing I/O in user space that are not
KVM guests-- just normal applications that need direct device
access.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] bookehv: Handle debug exception on guest exit

2013-04-11 Thread Stuart Yoder
On Thu, Apr 11, 2013 at 1:33 PM, Kumar Gala ga...@kernel.crashing.org wrote:

 On Apr 5, 2013, at 2:53 AM, Bhushan Bharat-R65777 wrote:

 Hi Kumar/Benh,

 After further looking into the code I think that if we correct the vector 
 range below in DebugDebug handler then we do not need the change I provided 
 in this patch.

 Here is the snapshot for 32 bit (head_booke.h, same will be true for 64 bit):

 #define DEBUG_DEBUG_EXCEPTION
  \
START_EXCEPTION(DebugDebug);  
 \
DEBUG_EXCEPTION_PROLOG;   
 \
  
 \
/*
 \
 * If there is a single step or branch-taken exception in an  
 \
 * exception entry sequence, it was probably meant to apply to
 \
 * the code where the exception occurred (since exception entry   
 \
 * doesn't turn off DE automatically).  We simulate the effect
 \
 * of turning off DE on entry to an exception handler by turning  
 \
 * off DE in the DSRR1 value and clearing the debug status.   
 \
 */   
 \
mfspr   r10,SPRN_DBSR;  /* check single-step/branch taken */  
 \
andis.  r10,r10,(DBSR_IC|DBSR_BT)@h;  
 \
beq+2f;   
 \
  
 \
lis r10,KERNELBASE@h;   /* check if exception in vectors */   
 \
ori r10,r10,KERNELBASE@l; 
 \
cmplw   r12,r10;  
 \
blt+2f; /* addr below exception vectors */
 \
  
 \
lis r10,DebugDebug@h;\
ori r10,r10,DebugDebug@l; 
\

 
   Here we assume all exception vector ends at DebugDebug, which is not 
 correct.
   We probably should get proper end by using some start_vector and 
 end_vector lebels
   or at least use end at Ehvpriv (which is last defined in 
 head_fsl_booke.S for PowerPC. Is that correct?


cmplw   r12,r10;  
 \
bgt+2f; /* addr above exception vectors */
 \

 Thanks
 -Bharat

 I talked to Stuart and this general approach is good.  Just make sure to 
 update both head_44x.S and head_fsl_booke.S.  Plus do this for both 
 DEBUG_CRIT_EXCEPTION  DEBUG_DEBUG_EXCEPTION

Also, it looks like 64-bit already handles this properly with symbols
identifying the
start/end of the vectors (exceptions-64e.S).

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] bookehv: Handle debug exception on guest exit

2013-04-11 Thread Stuart Yoder
So the patch should look something like this (on a 3.8 kernel):

diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 5f051ee..92b675a 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -286,13 +286,13 @@ label:
andis.  r10,r10,(DBSR_IC|DBSR_BT)@h;  \
beq+2f;   \
  \
-   lis r10,KERNELBASE@h;   /* check if exception in vectors */   \
-   ori r10,r10,KERNELBASE@l; \
+   lis r10,interrupt_base@h;   /* check if exception in vectors */   \
+   ori r10,r10,interrupt_base@l;
cmplw   r12,r10;  \
blt+2f; /* addr below exception vectors */\
  \
-   lis r10,DebugDebug@h; \
-   ori r10,r10,DebugDebug@l; \
+   lis r10,interrupt_end@h;  \
+   ori r10,r10,interrupt_end@l;
cmplw   r12,r10;  \
bgt+2f; /* addr above exception vectors */\
  \
@@ -339,13 +339,13 @@ label:
andis.  r10,r10,(DBSR_IC|DBSR_BT)@h;  \
beq+2f;   \
  \
-   lis r10,KERNELBASE@h;   /* check if exception in vectors */   \
-   ori r10,r10,KERNELBASE@l; \
+   lis r10,interrupt_base@h;   /* check if exception in vectors */   \
+   ori r10,r10,interrupt_base@l;
cmplw   r12,r10;  \
blt+2f; /* addr below exception vectors */\
  \
-   lis r10,DebugCrit@h;  \
-   ori r10,r10,DebugCrit@l;  \
+   lis r10,interrupt_end@h;  \
+   ori r10,r10,interrupt_end@l;
cmplw   r12,r10;  \
bgt+2f; /* addr above exception vectors */\
  \


diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
index 7a2e5e4..97e2671 100644
--- a/arch/powerpc/kernel/head_44x.S
+++ b/arch/powerpc/kernel/head_44x.S
@@ -769,6 +769,8 @@ finish_tlb_load_47x:
 */
DEBUG_CRIT_EXCEPTION

+interrupt_end:
+
 /*
  * Global functions
  */


diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl
index 58925b6..2c3e31d 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -605,6 +605,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
/* Embedded Hypervisor Privilege */
EXCEPTION(0, HV_PRIV, Ehvpriv, unknown_exception, EXC_XFER_EE)

+interrupt_end:
+
 /*
  * Local functions
  */
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] bookehv: Handle debug exception on guest exit

2013-04-11 Thread Stuart Yoder
So the patch should look something like this (on a 3.8 kernel):

diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 5f051ee..92b675a 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -286,13 +286,13 @@ label:
andis.  r10,r10,(DBSR_IC|DBSR_BT)@h;  \
beq+2f;   \
  \
-   lis r10,KERNELBASE@h;   /* check if exception in vectors */   \
-   ori r10,r10,KERNELBASE@l; \
+   lis r10,interrupt_base@h;   /* check if exception in vectors */   \
+   ori r10,r10,interrupt_base@l;
cmplw   r12,r10;  \
blt+2f; /* addr below exception vectors */\
  \
-   lis r10,DebugDebug@h; \
-   ori r10,r10,DebugDebug@l; \
+   lis r10,interrupt_end@h;  \
+   ori r10,r10,interrupt_end@l;
cmplw   r12,r10;  \
bgt+2f; /* addr above exception vectors */\
  \
@@ -339,13 +339,13 @@ label:
andis.  r10,r10,(DBSR_IC|DBSR_BT)@h;  \
beq+2f;   \
  \
-   lis r10,KERNELBASE@h;   /* check if exception in vectors */   \
-   ori r10,r10,KERNELBASE@l; \
+   lis r10,interrupt_base@h;   /* check if exception in vectors */   \
+   ori r10,r10,interrupt_base@l;
cmplw   r12,r10;  \
blt+2f; /* addr below exception vectors */\
  \
-   lis r10,DebugCrit@h;  \
-   ori r10,r10,DebugCrit@l;  \
+   lis r10,interrupt_end@h;  \
+   ori r10,r10,interrupt_end@l;
cmplw   r12,r10;  \
bgt+2f; /* addr above exception vectors */\
  \


diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
index 7a2e5e4..97e2671 100644
--- a/arch/powerpc/kernel/head_44x.S
+++ b/arch/powerpc/kernel/head_44x.S
@@ -769,6 +769,8 @@ finish_tlb_load_47x:
 */
DEBUG_CRIT_EXCEPTION

+interrupt_end:
+
 /*
  * Global functions
  */


diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl
index 58925b6..2c3e31d 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -605,6 +605,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
/* Embedded Hypervisor Privilege */
EXCEPTION(0, HV_PRIV, Ehvpriv, unknown_exception, EXC_XFER_EE)

+interrupt_end:
+
 /*
  * Local functions
  */
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] KVM: PPC: emulate dcbst

2013-04-09 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
 arch/powerpc/kvm/emulate.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 7a73b6f..631a265 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -38,6 +38,7 @@
 
 #define OP_31_XOP_TRAP  4
 #define OP_31_XOP_LWZX  23
+#define OP_31_XOP_DCBST 54
 #define OP_31_XOP_TRAP_64   68
 #define OP_31_XOP_DCBF  86
 #define OP_31_XOP_LBZX  87
@@ -370,6 +371,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
emulated = kvmppc_emulate_mtspr(vcpu, sprn, rs);
break;
 
+   case OP_31_XOP_DCBST:
case OP_31_XOP_DCBF:
case OP_31_XOP_DCBI:
/* Do nothing. The guest is performing dcbi because
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] KVM: PPC: emulate dcbst

2013-04-09 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
 arch/powerpc/kvm/emulate.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 7a73b6f..631a265 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -38,6 +38,7 @@
 
 #define OP_31_XOP_TRAP  4
 #define OP_31_XOP_LWZX  23
+#define OP_31_XOP_DCBST 54
 #define OP_31_XOP_TRAP_64   68
 #define OP_31_XOP_DCBF  86
 #define OP_31_XOP_LBZX  87
@@ -370,6 +371,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
emulated = kvmppc_emulate_mtspr(vcpu, sprn, rs);
break;
 
+   case OP_31_XOP_DCBST:
case OP_31_XOP_DCBF:
case OP_31_XOP_DCBI:
/* Do nothing. The guest is performing dcbi because
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-03 Thread Stuart Yoder
   Type1 is arbitrary.  It might as well be named brown and this one
  can be
  blue.

 The difference is that type1 seems to refer to hardware that can do
 arbitrary 4K page mappings, possibly constrained by an aperture but
 nothing else.  More than one IOMMU can reasonably fit that.  The odds
 that another IOMMU would have exactly the same restrictions as PAMU
 seem smaller in comparison.

 In any case, if you had to deal with some Intel-only quirk, would it
 make sense to call it a type1 attribute?  I'm not advocating one way
 or the other on whether an abstraction is viable here (though Stuart
 seems to think it's highly unlikely anything but a PAMU will comply),
 just that if it is to be abstracted rather than a hardware-specific
 interface, we need to document what is and is not part of the
 abstraction.  Otherwise a non-PAMU-specific user won't know what they
 can rely on, and someone adding support for a new windowed IOMMU won't
 know if theirs is close enough, or they need to introduce a type3.

 So Alexey named the SPAPR IOMMU something related to spapr...
 surprisingly enough.  I'm fine with that.  If you think it's unique
 enough, name it something appropriately.  I haven't seen the code and
 don't know the architecture sufficiently to have an opinion.

The only reason I suggested type 2 is that I thought that was the
convention...we would enumerate different iommus.   I think that
calling it pamu is better and more clear.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-03 Thread Stuart Yoder
On Tue, Apr 2, 2013 at 5:50 PM, Scott Wood scottw...@freescale.com wrote:
 On 04/02/2013 04:38:45 PM, Alex Williamson wrote:

 On Tue, 2013-04-02 at 16:08 -0500, Stuart Yoder wrote:
  On Tue, Apr 2, 2013 at 3:57 PM, Scott Wood scottw...@freescale.com
  wrote:
   C.  Explicit mapping using normal DMA map.  The last idea is
that
   we would introduce a new ioctl to give user-space an fd to
   the MSI bank, which could be mmapped.  The flow would be
   something like this:
  -for each group user space calls new ioctl
VFIO_GROUP_GET_MSI_FD
  -user space mmaps the fd, getting a vaddr
  -user space does a normal DMA map for desired iova
   This approach makes everything explicit, but adds a new
ioctl
   applicable most likely only to the PAMU (type2 iommu).
  
   And the DMA_MAP of that mmap then allows userspace to select the
   window
   used?  This one seems like a lot of overhead, adding a new ioctl, new
   fd, mmap, special mapping path, etc.
  
  
   There's going to be special stuff no matter what.  This would keep it
   separated from the IOMMU map code.
  
   I'm not sure what you mean by overhead here... the runtime overhead
   of
   setting things up is not particularly relevant as long as it's
   reasonable.
   If you mean development and maintenance effort, keeping things well
   separated should help.
 
  We don't need to change DMA_MAP.  If we can simply add a new type 2
  ioctl that allows user space to set which windows are MSIs, it seems
  vastly
  less complex than an ioctl to supply a new fd, mmap of it, etc.
 
  So maybe 2 ioctls:
  VFIO_IOMMU_GET_MSI_COUNT


 Do you mean a count of actual MSIs or a count of MSI banks used by the whole
 VFIO group?

I meant # of MSI banks, so VFIO_IOMMU_GET_MSI_BANK_COUNT would be better.

  VFIO_IOMMU_MAP_MSI(iova, size)


 Not sure how you mean size to be used -- for MPIC it would be 4K per bank,
 and you can only map one bank at a time (which bank you're mapping should be
 a parameter, if only so that the kernel doesn't have to keep iteration state
 for you).

The intent was for user space to tell the kernel which windows to use
for MSI.   So I envisioned a total size of window-size * msi-bank-count.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-03 Thread Stuart Yoder
 Would is be possible for userspace to simply leave room for MSI bank
 mapping (how much room could be determined by something like
 VFIO_IOMMU_GET_MSI_BANK_COUNT) then document the API that userspace can
 DMA_MAP starting at the 0x0 address of the aperture, growing up, and
 VFIO will map banks on demand at the top of the aperture, growing down?
 Wouldn't that avoid a lot of issues with userspace needing to know
 anything about MSI banks (other than count) and coordinating irq numbers
 and enabling handlers?

This is basically option #A in the original proposals sent.   I like
this approach, in that it
is simpler and keeps user space mostly out of this...which is
consistent with how things are done
on x86.  User space just needs to know how many windows to leave at
the top of the aperture.
The kernel then has the flexibility to use those windows how it wants.

But one question, is when should the kernel actually map (and unmap)
the MSI banks.   One thing we need to do is enable the aperture...and current
thinking is that is done on the first DMA_MAP.   Similarly when the last mapping
is unmapped we could also umap the MSI banks.

Sequence would be something like:

VFIO_GROUP_SET_CONTAINER // add groups to the container

VFIO_SET_IOMMU(VFIO_FSL_PAMU)// set iommu model

cnt = VFIO_IOMMU_GET_MSI_BANK_COUNT// returns max # of MSI banks

VFIO_IOMMU_SET_ATTR(ATTR_GEOMETRY) // set overall aperture

VFIO_IOMMU_SET_ATTR(ATTR_WINDOWS) // set # of windows,
including MSI banks

VFIO_IOMMU_MAP_DMA// map the guest's memory
   --- kernel enables aperture and maps needed MSI banks here

VFIO_DEVICE_SET_IRQS
   --- kernel sets actual MSI addr/data in physical
device here (I think)


Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-03 Thread Stuart Yoder
On Wed, Apr 3, 2013 at 2:18 PM, Scott Wood scottw...@freescale.com wrote:
 On 04/03/2013 02:09:45 PM, Stuart Yoder wrote:

  Would is be possible for userspace to simply leave room for MSI bank
  mapping (how much room could be determined by something like
  VFIO_IOMMU_GET_MSI_BANK_COUNT) then document the API that userspace can
  DMA_MAP starting at the 0x0 address of the aperture, growing up, and
  VFIO will map banks on demand at the top of the aperture, growing down?
  Wouldn't that avoid a lot of issues with userspace needing to know
  anything about MSI banks (other than count) and coordinating irq numbers
  and enabling handlers?

 This is basically option #A in the original proposals sent.   I like
 this approach, in that it
 is simpler and keeps user space mostly out of this...which is
 consistent with how things are done
 on x86.  User space just needs to know how many windows to leave at
 the top of the aperture.
 The kernel then has the flexibility to use those windows how it wants.

 But one question, is when should the kernel actually map (and unmap)
 the MSI banks.


 I think userspace should explicitly request it.  Userspace still wouldn't
 need to know anything but the count:

 count = VFIO_IOMMU_GET_MSI_BANK_COUNT
 VFIO_IOMMU_SET_ATTR(ATTR_GEOMETRY)
 VFIO_IOMMU_SET_ATTR(ATTR_WINDOWS)
 // do other DMA maps now, or later, or not at all, doesn't matter
 for (i = 0; i  count; i++)
 VFIO_IOMMU_MAP_MSI_BANK(iova, i);
 // The kernel now knows where each bank has been mapped, and can update PCI
 config space appropriately.

And the overall aperture enable/disable would occur on the first
dma/msi map() and last dma/msi unmap()?

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-02 Thread Stuart Yoder
On Tue, Apr 2, 2013 at 2:39 PM, Scott Wood scottw...@freescale.com wrote:
 On 04/02/2013 12:32:00 PM, Yoder Stuart-B08248 wrote:

 Alex,

 We are in the process of implementing vfio-pci support for the Freescale
 IOMMU (PAMU).  It is an aperture/window-based IOMMU and is quite different
 than x86, and will involve creating a 'type 2' vfio implementation.

 For each device's DMA mappings, PAMU has an overall aperture and a number
 of windows.  All sizes and window counts must be power of 2.  To
 illustrate,
 below is a mapping for a 256MB guest, including guest memory (backed by
 64MB huge pages) and some windows for MSIs:

 Total aperture: 512MB
 # of windows: 8

 win gphys/
 #   iovaphys  size
 ---   
 0   0x  0xX_XX00  64MB
 1   0x0400  0xX_XX00  64MB
 2   0x0800  0xX_XX00  64MB
 3   0x0C00  0xX_XX00  64MB
 4   0x1000  0xf_fe044000  4KB// msi bank 1
 5   0x1400  0xf_fe045000  4KB// msi bank 2
 6   0x1800  0xf_fe046000  4KB// msi bank 3
 7- -  disabled

 There are a couple of updates needed to the vfio user-kernel interface
 that we would like your feedback on.

 1.  IOMMU geometry

The kernel IOMMU driver now has an interface (see domain_set_attr,
domain_get_attr) that lets us set the domain geometry using
attributes.

We want to expose that to user space, so envision needing a couple
of new ioctls to do this:
 VFIO_IOMMU_SET_ATTR
 VFIO_IOMMU_GET_ATTR


 Note that this means attributes need to be updated for user-API
 appropriateness, such as using fixed-size types.


 2.   MSI window mappings

The more problematic question is how to deal with MSIs.  We need to
create mappings for up to 3 MSI banks that a device may need to target
to generate interrupts.  The Linux MSI driver can allocate MSIs from
the 3 banks any way it wants, and currently user space has no way of
knowing which bank may be used for a given device.

There are 3 options we have discussed and would like your direction:

A.  Implicit mappings -- with this approach user space would not
explicitly map MSIs.  User space would be required to set the
geometry so that there are 3 unused windows (the last 3 windows)


 Where does userspace get the number 3 from?  E.g. on newer chips there are
 4 MSI banks.  Maybe future chips have even more.

Ok, then make the number 4.   The chance of more MSI banks in future chips
is nil, and if it ever happened user space could adjust.  Also,
practically speaking since memory is typically allocate in powers of
2 way you need to approximately double the window geometry anyway.

B.  Explicit mapping using DMA map flags.  The idea is that a new
flag to DMA map (VFIO_DMA_MAP_FLAG_MSI) would mean that
a mapping is to be created for the supplied iova.  No vaddr
is given though.  So in the above example there would be a
a dma map at 0x1000 for 24KB (and no vaddr).


 A single 24 KiB mapping wouldn't work (and why 24KB? What if only one MSI
 group is involved in this VFIO group?  What if four MSI groups are
 involved?).  You'd need to either have a naturally aligned, power-of-two
 sized mapping that covers exactly the pages you want to map and no more, or
 you'd need to create a separate mapping for each MSI bank, and due to PAMU
 subwindow alignment restrictions these mappings could not be contiguous in
 iova-space.

You're right, a single 24KB mapping wouldn't work--  in the case of 3 MSI banks
perhaps we could just do one 64MB*3 mapping to identify which windows
are used for MSIs.

If only one MSI bank was involved the kernel could get clever and only enable
the banks actually needed.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-02 Thread Stuart Yoder
On Tue, Apr 2, 2013 at 3:32 PM, Alex Williamson
alex.william...@redhat.com wrote:
 2.   MSI window mappings

The more problematic question is how to deal with MSIs.  We need to
create mappings for up to 3 MSI banks that a device may need to target
to generate interrupts.  The Linux MSI driver can allocate MSIs from
the 3 banks any way it wants, and currently user space has no way of
knowing which bank may be used for a given device.

There are 3 options we have discussed and would like your direction:

A.  Implicit mappings -- with this approach user space would not
explicitly map MSIs.  User space would be required to set the
geometry so that there are 3 unused windows (the last 3 windows)
for MSIs, and it would be up to the kernel to create the mappings.
This approach requires some specific semantics (leaving 3 windows)
and it potentially gets a little weird-- when should the kernel
actually create the MSI mappings?  When should they be unmapped?
Some convention would need to be established.

 VFIO would have control of SET/GET_ATTR, right?  So we could reduce the
 number exposed to userspace on GET and transparently add MSI entries on
 SET.

The number of windows is always power of 2 (and max is 256).  And to reduce
PAMU cache pressure you want to use the fewest number of windows
you can.So, I don't see practically how we could transparently
steal entries to
add the MSIs. Either user space knows to leave empty windows for
MSIs and by convention the kernel knows which windows those are (as
in option #A) or explicitly tell the kernel which windows (as in option #B).

 On x86 the interrupt remapper handles this transparently when MSI
 is enabled and userspace never gets direct access to the device MSI
 address/data registers.  What kind of restrictions do you have around
 adding and removing windows while the aperture is enabled?

The windows can be enabled/disabled event while the aperture is
enabled (pretty sure)...

B.  Explicit mapping using DMA map flags.  The idea is that a new
flag to DMA map (VFIO_DMA_MAP_FLAG_MSI) would mean that
a mapping is to be created for the supplied iova.  No vaddr
is given though.  So in the above example there would be a
a dma map at 0x1000 for 24KB (and no vaddr).   It's
up to the kernel to determine which bank gets mapped where.
So, this option puts user space in control of which windows
are used for MSIs and when MSIs are mapped/unmapped.   There
would need to be some semantics as to how this is used-- it
only makes sense

 This could also be done as another type2 ioctl extension.  What's the
 value to userspace in determining which windows are used by which banks?
 It sounds like the case that there are X banks and if userspace wants to
 use MSI it needs to leave X windows available for that.  Is this just
 buying userspace a few more windows to allow them the choice between MSI
 or RAM?

Yes, it would potentially give user space the flexibility some more windows.
It also makes more explicit when the MSI mappings are created.  In option
#A the MSI mappings would probably get created at the time of the first
normal DMA map.

So, you're saying with this approach you'd rather see a new type 2
ioctl instead of adding new flags to DMA map, right?

C.  Explicit mapping using normal DMA map.  The last idea is that
we would introduce a new ioctl to give user-space an fd to
the MSI bank, which could be mmapped.  The flow would be
something like this:
   -for each group user space calls new ioctl VFIO_GROUP_GET_MSI_FD
   -user space mmaps the fd, getting a vaddr
   -user space does a normal DMA map for desired iova
This approach makes everything explicit, but adds a new ioctl
applicable most likely only to the PAMU (type2 iommu).

 And the DMA_MAP of that mmap then allows userspace to select the window
 used?  This one seems like a lot of overhead, adding a new ioctl, new
 fd, mmap, special mapping path, etc.  It would be less overhead to just
 add an ioctl to enable MSI, maybe letting userspace pick which windows
 get used, but I'm still not sure what the value is to userspace in
 exposing it.  Thanks,

Thanks,
Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-02 Thread Stuart Yoder
On Tue, Apr 2, 2013 at 3:47 PM, Scott Wood scottw...@freescale.com wrote:
 On 04/02/2013 03:38:42 PM, Stuart Yoder wrote:

 On Tue, Apr 2, 2013 at 2:39 PM, Scott Wood scottw...@freescale.com
 wrote:
  On 04/02/2013 12:32:00 PM, Yoder Stuart-B08248 wrote:
 
  Alex,
 
  We are in the process of implementing vfio-pci support for the
  Freescale
  IOMMU (PAMU).  It is an aperture/window-based IOMMU and is quite
  different
  than x86, and will involve creating a 'type 2' vfio implementation.
 
  For each device's DMA mappings, PAMU has an overall aperture and a
  number
  of windows.  All sizes and window counts must be power of 2.  To
  illustrate,
  below is a mapping for a 256MB guest, including guest memory (backed by
  64MB huge pages) and some windows for MSIs:
 
  Total aperture: 512MB
  # of windows: 8
 
  win gphys/
  #   iovaphys  size
  ---   
  0   0x  0xX_XX00  64MB
  1   0x0400  0xX_XX00  64MB
  2   0x0800  0xX_XX00  64MB
  3   0x0C00  0xX_XX00  64MB
  4   0x1000  0xf_fe044000  4KB// msi bank 1
  5   0x1400  0xf_fe045000  4KB// msi bank 2
  6   0x1800  0xf_fe046000  4KB// msi bank 3
  7- -  disabled
 
  There are a couple of updates needed to the vfio user-kernel interface
  that we would like your feedback on.
 
  1.  IOMMU geometry
 
 The kernel IOMMU driver now has an interface (see domain_set_attr,
 domain_get_attr) that lets us set the domain geometry using
 attributes.
 
 We want to expose that to user space, so envision needing a couple
 of new ioctls to do this:
  VFIO_IOMMU_SET_ATTR
  VFIO_IOMMU_GET_ATTR
 
 
  Note that this means attributes need to be updated for user-API
  appropriateness, such as using fixed-size types.
 
 
  2.   MSI window mappings
 
 The more problematic question is how to deal with MSIs.  We need to
 create mappings for up to 3 MSI banks that a device may need to
  target
 to generate interrupts.  The Linux MSI driver can allocate MSIs from
 the 3 banks any way it wants, and currently user space has no way of
 knowing which bank may be used for a given device.
 
 There are 3 options we have discussed and would like your direction:
 
 A.  Implicit mappings -- with this approach user space would not
 explicitly map MSIs.  User space would be required to set the
 geometry so that there are 3 unused windows (the last 3 windows)
 
 
  Where does userspace get the number 3 from?  E.g. on newer chips there
  are
  4 MSI banks.  Maybe future chips have even more.

 Ok, then make the number 4.   The chance of more MSI banks in future chips
 is nil,


 What makes you so sure?  Especially since you seem to be presenting this as
 not specifically an MPIC API.


 and if it ever happened user space could adjust.


 What bit of API is going to tell it that it needs to adjust?

Haven't thought through that completely, but I guess we could add an API
to return the number of MSI banks for type 2 iommus.

 Also, practically speaking since memory is typically allocate in powers of
 2 way you need to approximately double the window geometry anyway.


 Only if your existing mapping needs fit exactly in a power of two.


 B.  Explicit mapping using DMA map flags.  The idea is that a new
 flag to DMA map (VFIO_DMA_MAP_FLAG_MSI) would mean that
 a mapping is to be created for the supplied iova.  No vaddr
 is given though.  So in the above example there would be a
 a dma map at 0x1000 for 24KB (and no vaddr).
 
 
  A single 24 KiB mapping wouldn't work (and why 24KB? What if only one
  MSI
  group is involved in this VFIO group?  What if four MSI groups are
  involved?).  You'd need to either have a naturally aligned, power-of-two
  sized mapping that covers exactly the pages you want to map and no more,
  or
  you'd need to create a separate mapping for each MSI bank, and due to
  PAMU
  subwindow alignment restrictions these mappings could not be contiguous
  in
  iova-space.

 You're right, a single 24KB mapping wouldn't work--  in the case of 3 MSI
 banks
 perhaps we could just do one 64MB*3 mapping to identify which windows
 are used for MSIs.


 Where did the assumption of a 64MiB subwindow size come from?

The example I was using.   User space would need to create a
mapping for window_size * msi_bank_count.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: RFC: vfio API changes needed for powerpc

2013-04-02 Thread Stuart Yoder
On Tue, Apr 2, 2013 at 3:57 PM, Scott Wood scottw...@freescale.com wrote:
 This could also be done as another type2 ioctl extension.


 Again, what is type2, specifically?  If someone else is adding their own
 IOMMU that is kind of, sort of like PAMU, how would they know if it's close
 enough?  What assumptions can a user make when they see that they're dealing
 with type2?

We will define that as part of the type2 implementation.   Highly unlikely
anything but a PAMU will comply.

 What's the value to userspace in determining which windows are used by
 which banks?


 That depends on who programs the MSI config space address.  What is
 important is userspace controlling which iovas will be dedicated to this, in
 case it wants to put something else there.


 It sounds like the case that there are X banks and if userspace wants to
 use MSI it needs to leave X windows available for that.  Is this just
 buying userspace a few more windows to allow them the choice between MSI
 or RAM?


 Well, there could be that.  But also, userspace will generally have a much
 better idea of the type of mappings it's creating, so it's easier to keep
 everything explicit at the kernel/user interface than require more
 complicated code in the kernel to figure things out automatically (not just
 for MSIs but in general).

 If the kernel automatically creates the MSI mappings, when does it assume
 that userspace is done creating its own?  What if userspace doesn't need any
 DMA other than the MSIs?  What if userspace wants to continue dynamically
 modifying its other mappings?


 C.  Explicit mapping using normal DMA map.  The last idea is that
 we would introduce a new ioctl to give user-space an fd to
 the MSI bank, which could be mmapped.  The flow would be
 something like this:
-for each group user space calls new ioctl
  VFIO_GROUP_GET_MSI_FD
-user space mmaps the fd, getting a vaddr
-user space does a normal DMA map for desired iova
 This approach makes everything explicit, but adds a new ioctl
 applicable most likely only to the PAMU (type2 iommu).

 And the DMA_MAP of that mmap then allows userspace to select the window
 used?  This one seems like a lot of overhead, adding a new ioctl, new
 fd, mmap, special mapping path, etc.


 There's going to be special stuff no matter what.  This would keep it
 separated from the IOMMU map code.

 I'm not sure what you mean by overhead here... the runtime overhead of
 setting things up is not particularly relevant as long as it's reasonable.
 If you mean development and maintenance effort, keeping things well
 separated should help.

We don't need to change DMA_MAP.  If we can simply add a new type 2
ioctl that allows user space to set which windows are MSIs, it seems vastly
less complex than an ioctl to supply a new fd, mmap of it, etc.

So maybe 2 ioctls:
VFIO_IOMMU_GET_MSI_COUNT
VFIO_IOMMU_MAP_MSI(iova, size)

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH][v4] PPC: add paravirt idle loop for 64-bit book E

2013-02-08 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-removed KVM prefix to patch subject, patch is not KVM specific

 arch/powerpc/kernel/epapr_hcalls.S |2 ++
 arch/powerpc/kernel/idle_book3e.S  |   32 ++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 62c0dc2..9f1ebf7 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -17,6 +17,7 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+#ifndef CONFIG_PPC64
 /* epapr_ev_idle() was derived from e500_idle() */
 _GLOBAL(epapr_ev_idle)
CURRENT_THREAD_INFO(r3, r1)
@@ -42,6 +43,7 @@ epapr_ev_idle_start:
 * _TLF_NAPPING.
 */
b   idle_loop
+#endif
 
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
diff --git a/arch/powerpc/kernel/idle_book3e.S 
b/arch/powerpc/kernel/idle_book3e.S
index 4c7cb400..bfb73cc 100644
--- a/arch/powerpc/kernel/idle_book3e.S
+++ b/arch/powerpc/kernel/idle_book3e.S
@@ -16,11 +16,13 @@
 #include asm/ppc-opcode.h
 #include asm/processor.h
 #include asm/thread_info.h
+#include asm/epapr_hcalls.h
 
 /* 64-bit version only for now */
 #ifdef CONFIG_PPC64
 
-_GLOBAL(book3e_idle)
+.macro BOOK3E_IDLE name loop
+_GLOBAL(\name)
/* Save LR for later */
mflrr0
std r0,16(r1)
@@ -67,7 +69,33 @@ _GLOBAL(book3e_idle)
 
/* We can now re-enable hard interrupts and go to sleep */
wrteei  1
-1: PPC_WAIT(0)
+   \loop
+
+.endm
+
+.macro BOOK3E_IDLE_LOOP
+1:
+   PPC_WAIT(0)
b   1b
+.endm
+
+/* epapr_ev_idle_start below is patched with the proper hcall
+   opcodes during kernel initialization */
+.macro EPAPR_EV_IDLE_LOOP
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   b   idle_loop
+.endm
+
+BOOK3E_IDLE epapr_ev_idle EPAPR_EV_IDLE_LOOP
+
+BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP
 
 #endif /* CONFIG_PPC64 */
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH][v4] PPC: add paravirt idle loop for 64-bit book E

2013-02-08 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-removed KVM prefix to patch subject, patch is not KVM specific

 arch/powerpc/kernel/epapr_hcalls.S |2 ++
 arch/powerpc/kernel/idle_book3e.S  |   32 ++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 62c0dc2..9f1ebf7 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -17,6 +17,7 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+#ifndef CONFIG_PPC64
 /* epapr_ev_idle() was derived from e500_idle() */
 _GLOBAL(epapr_ev_idle)
CURRENT_THREAD_INFO(r3, r1)
@@ -42,6 +43,7 @@ epapr_ev_idle_start:
 * _TLF_NAPPING.
 */
b   idle_loop
+#endif
 
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
diff --git a/arch/powerpc/kernel/idle_book3e.S 
b/arch/powerpc/kernel/idle_book3e.S
index 4c7cb400..bfb73cc 100644
--- a/arch/powerpc/kernel/idle_book3e.S
+++ b/arch/powerpc/kernel/idle_book3e.S
@@ -16,11 +16,13 @@
 #include asm/ppc-opcode.h
 #include asm/processor.h
 #include asm/thread_info.h
+#include asm/epapr_hcalls.h
 
 /* 64-bit version only for now */
 #ifdef CONFIG_PPC64
 
-_GLOBAL(book3e_idle)
+.macro BOOK3E_IDLE name loop
+_GLOBAL(\name)
/* Save LR for later */
mflrr0
std r0,16(r1)
@@ -67,7 +69,33 @@ _GLOBAL(book3e_idle)
 
/* We can now re-enable hard interrupts and go to sleep */
wrteei  1
-1: PPC_WAIT(0)
+   \loop
+
+.endm
+
+.macro BOOK3E_IDLE_LOOP
+1:
+   PPC_WAIT(0)
b   1b
+.endm
+
+/* epapr_ev_idle_start below is patched with the proper hcall
+   opcodes during kernel initialization */
+.macro EPAPR_EV_IDLE_LOOP
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   b   idle_loop
+.endm
+
+BOOK3E_IDLE epapr_ev_idle EPAPR_EV_IDLE_LOOP
+
+BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP
 
 #endif /* CONFIG_PPC64 */
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH][v3] KVM: PPC: add paravirt idle loop for 64-bit book E

2013-01-24 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v3
   -whitespace cleanup, deleted stray comma, added comment

 arch/powerpc/kernel/epapr_hcalls.S |2 ++
 arch/powerpc/kernel/idle_book3e.S  |   32 ++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 62c0dc2..9f1ebf7 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -17,6 +17,7 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+#ifndef CONFIG_PPC64
 /* epapr_ev_idle() was derived from e500_idle() */
 _GLOBAL(epapr_ev_idle)
CURRENT_THREAD_INFO(r3, r1)
@@ -42,6 +43,7 @@ epapr_ev_idle_start:
 * _TLF_NAPPING.
 */
b   idle_loop
+#endif
 
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
diff --git a/arch/powerpc/kernel/idle_book3e.S 
b/arch/powerpc/kernel/idle_book3e.S
index 4c7cb400..bfb73cc 100644
--- a/arch/powerpc/kernel/idle_book3e.S
+++ b/arch/powerpc/kernel/idle_book3e.S
@@ -16,11 +16,13 @@
 #include asm/ppc-opcode.h
 #include asm/processor.h
 #include asm/thread_info.h
+#include asm/epapr_hcalls.h
 
 /* 64-bit version only for now */
 #ifdef CONFIG_PPC64
 
-_GLOBAL(book3e_idle)
+.macro BOOK3E_IDLE name loop
+_GLOBAL(\name)
/* Save LR for later */
mflrr0
std r0,16(r1)
@@ -67,7 +69,33 @@ _GLOBAL(book3e_idle)
 
/* We can now re-enable hard interrupts and go to sleep */
wrteei  1
-1: PPC_WAIT(0)
+   \loop
+
+.endm
+
+.macro BOOK3E_IDLE_LOOP
+1:
+   PPC_WAIT(0)
b   1b
+.endm
+
+/* epapr_ev_idle_start below is patched with the proper hcall
+   opcodes during kernel initialization */
+.macro EPAPR_EV_IDLE_LOOP
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   b   idle_loop
+.endm
+
+BOOK3E_IDLE epapr_ev_idle EPAPR_EV_IDLE_LOOP
+
+BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP
 
 #endif /* CONFIG_PPC64 */
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH][v2] KVM: PPC: add paravirt idle loop for 64-bit book E

2013-01-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v2
   -macro'ized loop in idle_book3e.S to avoid code 
duplication, paravirt loop is now in idle_book3e.S

 arch/powerpc/kernel/epapr_hcalls.S |2 ++
 arch/powerpc/kernel/idle_book3e.S  |   30 --
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 62c0dc2..9f1ebf7 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -17,6 +17,7 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+#ifndef CONFIG_PPC64
 /* epapr_ev_idle() was derived from e500_idle() */
 _GLOBAL(epapr_ev_idle)
CURRENT_THREAD_INFO(r3, r1)
@@ -42,6 +43,7 @@ epapr_ev_idle_start:
 * _TLF_NAPPING.
 */
b   idle_loop
+#endif
 
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
diff --git a/arch/powerpc/kernel/idle_book3e.S 
b/arch/powerpc/kernel/idle_book3e.S
index 4c7cb400..e1c9acd 100644
--- a/arch/powerpc/kernel/idle_book3e.S
+++ b/arch/powerpc/kernel/idle_book3e.S
@@ -16,11 +16,13 @@
 #include asm/ppc-opcode.h
 #include asm/processor.h
 #include asm/thread_info.h
+#include asm/epapr_hcalls.h
 
 /* 64-bit version only for now */
 #ifdef CONFIG_PPC64
 
-_GLOBAL(book3e_idle)
+.macro BOOK3E_IDLE name loop
+_GLOBAL(\name)
/* Save LR for later */
mflrr0
std r0,16(r1)
@@ -67,7 +69,31 @@ _GLOBAL(book3e_idle)
 
/* We can now re-enable hard interrupts and go to sleep */
wrteei  1
-1: PPC_WAIT(0)
+   \loop
+
+.endm
+
+.macro BOOK3E_IDLE_LOOP
+1:
+   PPC_WAIT(0)
b   1b
+.endm
+
+.macro EPAPR_EV_IDLE_LOOP
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   b   idle_loop
+.endm
+
+BOOK3E_IDLE epapr_ev_idle, EPAPR_EV_IDLE_LOOP
+
+BOOK3E_IDLE book3e_idle BOOK3E_IDLE_LOOP
 
 #endif /* CONFIG_PPC64 */
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] KVM: PPC: add paravirt idle loop for 64-bit book E

2013-01-16 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

loop was derived from book3e_idle()

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
 arch/powerpc/kernel/epapr_hcalls.S |   63 
 1 file changed, 63 insertions(+)

diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 62c0dc2..6a46bfb 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -17,6 +17,68 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+#ifdef CONFIG_PPC64
+/* epapr_ev_idle() was derived from book3e_idle() */
+_GLOBAL(epapr_ev_idle)
+   /* Save LR for later */
+   mflrr0
+   std r0,16(r1)
+
+   /* Hard disable interrupts */
+   wrteei  0
+
+   /* Now check if an interrupt came in while we were soft disabled
+* since we may otherwise lose it (doorbells etc...).
+*/
+   lbz r3,PACAIRQHAPPENED(r13)
+   cmpwi   cr0,r3,0
+   bnelr
+
+   /* Now we are going to mark ourselves as soft and hard enabled in
+* order to be able to take interrupts while asleep. We inform lockdep
+* of that. We don't actually turn interrupts on just yet tho.
+*/
+#ifdef CONFIG_TRACE_IRQFLAGS
+   stdur1,-128(r1)
+   bl  .trace_hardirqs_on
+   addir1,r1,128
+#endif
+   li  r0,1
+   stb r0,PACASOFTIRQEN(r13)
+   
+   /* Interrupts will make use return to LR, so get something we want
+* in there
+*/
+   bl  1f
+
+   /* And return (interrupts are on) */
+   ld  r0,16(r1)
+   mtlrr0
+   blr
+
+1: /* Let's set the _TLF_NAPPING flag so interrupts make us return
+* to the right spot
+   */
+   CURRENT_THREAD_INFO(r11, r1)
+   ld  r10,TI_LOCAL_FLAGS(r11)
+   ori r10,r10,_TLF_NAPPING
+   std r10,TI_LOCAL_FLAGS(r11)
+
+   /* We can now re-enable hard interrupts and go to sleep */
+   wrteei  1
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   b   idle_loop
+
+#else /* CONFIG_PPC64 */
+
 /* epapr_ev_idle() was derived from e500_idle() */
 _GLOBAL(epapr_ev_idle)
CURRENT_THREAD_INFO(r3, r1)
@@ -42,6 +104,7 @@ epapr_ev_idle_start:
 * _TLF_NAPPING.
 */
b   idle_loop
+#endif
 
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] KVM: PPC: add paravirt idle loop for 64-bit book E

2013-01-16 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

loop was derived from book3e_idle()

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
 arch/powerpc/kernel/epapr_hcalls.S |   63 
 1 file changed, 63 insertions(+)

diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 62c0dc2..6a46bfb 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -17,6 +17,68 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+#ifdef CONFIG_PPC64
+/* epapr_ev_idle() was derived from book3e_idle() */
+_GLOBAL(epapr_ev_idle)
+   /* Save LR for later */
+   mflrr0
+   std r0,16(r1)
+
+   /* Hard disable interrupts */
+   wrteei  0
+
+   /* Now check if an interrupt came in while we were soft disabled
+* since we may otherwise lose it (doorbells etc...).
+*/
+   lbz r3,PACAIRQHAPPENED(r13)
+   cmpwi   cr0,r3,0
+   bnelr
+
+   /* Now we are going to mark ourselves as soft and hard enabled in
+* order to be able to take interrupts while asleep. We inform lockdep
+* of that. We don't actually turn interrupts on just yet tho.
+*/
+#ifdef CONFIG_TRACE_IRQFLAGS
+   stdur1,-128(r1)
+   bl  .trace_hardirqs_on
+   addir1,r1,128
+#endif
+   li  r0,1
+   stb r0,PACASOFTIRQEN(r13)
+   
+   /* Interrupts will make use return to LR, so get something we want
+* in there
+*/
+   bl  1f
+
+   /* And return (interrupts are on) */
+   ld  r0,16(r1)
+   mtlrr0
+   blr
+
+1: /* Let's set the _TLF_NAPPING flag so interrupts make us return
+* to the right spot
+   */
+   CURRENT_THREAD_INFO(r11, r1)
+   ld  r10,TI_LOCAL_FLAGS(r11)
+   ori r10,r10,_TLF_NAPPING
+   std r10,TI_LOCAL_FLAGS(r11)
+
+   /* We can now re-enable hard interrupts and go to sleep */
+   wrteei  1
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   b   idle_loop
+
+#else /* CONFIG_PPC64 */
+
 /* epapr_ev_idle() was derived from e500_idle() */
 _GLOBAL(epapr_ev_idle)
CURRENT_THREAD_INFO(r3, r1)
@@ -42,6 +104,7 @@ epapr_ev_idle_start:
 * _TLF_NAPPING.
 */
b   idle_loop
+#endif
 
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
-- 
1.7.9.7


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 7/8] powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

2012-07-03 Thread Stuart Yoder
From: Scott Wood scottw...@freescale.com

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/sysdev/fsl_msi.c |9 +++--
 arch/powerpc/sysdev/fsl_soc.c |2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index 6e097de..7e2b2f2 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -236,7 +236,6 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
u32 intr_index;
u32 have_shift = 0;
struct fsl_msi_cascade_data *cascade_data;
-   unsigned int ret;
 
cascade_data = irq_get_handler_data(irq);
msi_data = cascade_data-msi_data;
@@ -268,7 +267,9 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
case FSL_PIC_IP_IPIC:
msir_value = fsl_msi_read(msi_data-msi_regs, msir_index * 0x4);
break;
-   case FSL_PIC_IP_VMPIC:
+#ifdef CONFIG_EPAPR_PARAVIRT
+   case FSL_PIC_IP_VMPIC: {
+   unsigned int ret;
ret = fh_vmpic_get_msir(virq_to_hw(irq), msir_value);
if (ret) {
pr_err(fsl-msi: fh_vmpic_get_msir() failed for 
@@ -277,6 +278,8 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
}
break;
}
+#endif
+   }
 
while (msir_value) {
intr_index = ffs(msir_value) - 1;
@@ -508,10 +511,12 @@ static const struct of_device_id fsl_of_msi_ids[] = {
.compatible = fsl,ipic-msi,
.data = (void *)ipic_msi_feature,
},
+#ifdef CONFIG_EPAPR_PARAVIRT
{
.compatible = fsl,vmpic-msi,
.data = (void *)vmpic_msi_feature,
},
+#endif
{}
 };
 
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index c449dbd..97118dc 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -253,6 +253,7 @@ struct platform_diu_data_ops diu_ops;
 EXPORT_SYMBOL(diu_ops);
 #endif
 
+#ifdef CONFIG_EPAPR_PARAVIRT
 /*
  * Restart the current partition
  *
@@ -278,3 +279,4 @@ void fsl_hv_halt(void)
pr_info(hv exit\n);
fh_partition_stop(-1);
 }
+#endif
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 1/8] PPC: epapr: create define for return code value of success

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index bf2c06c..c0c7adc 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -88,7 +88,8 @@
 #define _EV_HCALL_TOKEN(id, num) (((id)  16) | (num))
 #define EV_HCALL_TOKEN(hcall_num) _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, 
hcall_num)
 
-/* epapr error codes */
+/* epapr return codes */
+#define EV_SUCCESS 0
 #define EV_EPERM   1   /* Operation not permitted */
 #define EV_ENOENT  2   /*  Entry Not Found */
 #define EV_EIO 3   /* I/O error occured */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 0/8] KVM: PPC: Add ePAPR idle hcall support

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

v12 has a couple of updates to address feedback 
   -use new CURRENT_THREAD_INFO macro in epapr_hcalls.S
   -use EV_HCALL_TOKEN to create epapr hcall token

A prerequisite to applying this patch is the patch:
  PPC: use CURRENT_THREAD_INFO instead of open coded assembly

Liu Yu-B13201 (3):
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Scott Wood (1):
  powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

Stuart Yoder (4):
  PPC: epapr: create define for return code value of success
  KVM: PPC: use definitions in epapr header for hcalls
  KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500
  PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

 Documentation/virtual/kvm/api.txt   |7 -
 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   36 --
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/include/asm/kvm_para.h |   21 +
 arch/powerpc/kernel/epapr_hcalls.S  |   28 
 arch/powerpc/kernel/epapr_paravirt.c|   11 -
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   30 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 arch/powerpc/sysdev/fsl_msi.c   |9 ++-
 arch/powerpc/sysdev/fsl_soc.c   |2 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 129 insertions(+), 59 deletions(-)

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 8/8] PPC: Don't use hardcoded opcode for ePAPR hcall invocation

2012-07-03 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 833ce2c..b8d9445 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -195,7 +195,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -224,7 +224,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -254,7 +254,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -279,7 +279,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -307,7 +307,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -346,7 +346,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -385,7 +385,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -423,7 +423,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -456,7 +456,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -480,7 +480,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -500,7 +500,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int 
handle,
r9 = (uint32_t)propvalue_addr;
r10 = *propvalue_len

[PATCH v12 5/8] KVM: PPC: ev_idle hcall support for e500 guests

2012-07-03 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[varun: 64-bit changes]
Signed-off-by: Varun Sethi varun.se...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: use new CURRENT_THREAD_INFO macro

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   28 
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index c0c7adc..833ce2c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -109,6 +105,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -506,5 +507,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..62c0dc2 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,41 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
 #include asm/thread_info.h
 #include asm/ppc_asm.h
+#include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+/* epapr_ev_idle() was derived from e500_idle() */
+_GLOBAL(epapr_ev_idle)
+   CURRENT_THREAD_INFO(r3, r1)
+   PPC_LL  r4, TI_LOCAL_FLAGS(r3)  /* set napping bit */
+   ori r4, r4,_TLF_NAPPING /* so when we take an exception */
+   PPC_STL r4, TI_LOCAL_FLAGS(r3)  /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 2/8] KVM: PPC: use definitions in epapr header for hcalls

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/include/asm/kvm_para.h |   21 +++--
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   10 +-
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index c18916b..a168ce3 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,10 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
-#define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+
+#define KVM_HCALL_TOKEN(num) _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
+
+#include asm/epapr_hcalls.h
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
@@ -121,7 +122,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
   unsigned long *out,
   unsigned long nr)
 {
-   return HC_EV_UNIMPLEMENTED;
+   return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +133,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, 
unsigned long *r2)
unsigned long out[8];
unsigned long r;
 
-   r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
*r2 = out[0];
 
return r;
@@ -143,7 +144,7 @@ static inline long kvm_hypercall0(unsigned int nr)
unsigned long in[8];
unsigned long out[8];
 
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +153,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned 
long p1)
unsigned long out[8];
 
in[0] = p1;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +164,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned 
long p1,
 
in[0] = p1;
in[1] = p2;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +176,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned 
long p1,
in[0] = p1;
in[1] = p2;
in[2] = p3;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +190,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned 
long p1,
in[1] = p2;
in[2] = p3;
in[3] = p4;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 1c13307..5fcc537 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
in[0] = KVM_MAGIC_PAGE;
in[1] = KVM_MAGIC_PAGE;
 
-   kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+   kvm_hypercall(in, out, KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE));
 
*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 87f4dc8..a98f7e0 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
 
switch (nr) {
-   case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+   case KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE):
{
vcpu-arch.magic_page_pa = param1;
vcpu-arch.magic_page_ea = param2;
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-   r = HC_EV_SUCCESS;
+   r = EV_SUCCESS;
break;
}
-   case HC_VENDOR_KVM | KVM_HC_FEATURES:
-   r = HC_EV_SUCCESS;
+   case KVM_HCALL_TOKEN(KVM_HC_FEATURES):
+   r = EV_SUCCESS;
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
/* Second return value is in r4 */
break;
default:
-   r = HC_EV_UNIMPLEMENTED;
+   r = EV_UNIMPLEMENTED;
break;
}
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org

[PATCH v12 4/8] KVM: PPC: Add support for ePAPR idle hcall in host kernel

2012-07-03 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: use EV_HCALL_TOKEN macro

 Documentation/virtual/kvm/api.txt |7 +--
 arch/powerpc/include/asm/Kbuild   |1 +
 arch/powerpc/kvm/powerpc.c|   10 --
 include/linux/kvm.h   |2 ++
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 310fe50..920c3c4 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1190,12 +1190,15 @@ struct kvm_ppc_pvinfo {
 This ioctl fetches PV specific information that need to be passed to the guest
 using the device tree or other means from vm context.
 
-For now the only implemented piece of information distributed here is an array
-of 4 instructions that make up a hypercall.
+The hcall array defines 4 instructions that make up a hypercall.
 
 If any additional field gets added to this structure later on, a bit for that
 additional piece of information will be set in the flags bitmap.
 
+The flags bitmap is defined as:
+
+   /* the host supports the ePAPR idle hcall
+   #define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
 
 4.48 KVM_ASSIGN_PCI_DEVICE
 
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 30cf01c..1a4db32 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   return !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   return !!(v-arch.pending_exceptions) ||
   v-requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
+   r = EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+   break;
default:
r = EV_UNIMPLEMENTED;
break;
@@ -767,6 +771,8 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[3] = inst_nop;
 #endif
 
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 2ce09aa..c03e59e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -473,6 +473,8 @@ struct kvm_ppc_smmu_info {
struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 3/8] KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[stuart: factored this out from idle hcall support in host patch]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/kvm/powerpc.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index a98f7e0..30cf01c 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -739,9 +739,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct 
vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -758,6 +765,7 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
 
return 0;
 }
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 6/8] PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/platforms/Kconfig |1 +
 drivers/tty/Kconfig|1 +
 drivers/virt/Kconfig   |1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index e7a896a..48a920d 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -90,6 +90,7 @@ config MPIC
 config PPC_EPAPR_HV_PIC
bool
default n
+   select EPAPR_PARAVIRT
 
 config MPIC_WEIRD
bool
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 830cd62..aa99cd2 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -358,6 +358,7 @@ config TRACE_SINK
 config PPC_EPAPR_HV_BYTECHAN
tristate ePAPR hypervisor byte channel driver
depends on PPC
+   select EPAPR_PARAVIRT
help
  This driver creates /dev entries for each ePAPR hypervisor byte
  channel, thereby allowing applications to communicate with byte
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index 2dcdbc9..99ebdde 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -15,6 +15,7 @@ if VIRT_DRIVERS
 config FSL_HV_MANAGER
tristate Freescale hypervisor management driver
depends on FSL_SOC
+   select EPAPR_PARAVIRT
help
   The Freescale hypervisor management driver provides several services
  to drivers and applications related to the Freescale hypervisor:
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 0/8] KVM: PPC: Add ePAPR idle hcall support

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

v12 has a couple of updates to address feedback 
   -use new CURRENT_THREAD_INFO macro in epapr_hcalls.S
   -use EV_HCALL_TOKEN to create epapr hcall token

A prerequisite to applying this patch is the patch:
  PPC: use CURRENT_THREAD_INFO instead of open coded assembly

Liu Yu-B13201 (3):
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Scott Wood (1):
  powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

Stuart Yoder (4):
  PPC: epapr: create define for return code value of success
  KVM: PPC: use definitions in epapr header for hcalls
  KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500
  PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

 Documentation/virtual/kvm/api.txt   |7 -
 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   36 --
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/include/asm/kvm_para.h |   21 +
 arch/powerpc/kernel/epapr_hcalls.S  |   28 
 arch/powerpc/kernel/epapr_paravirt.c|   11 -
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   30 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 arch/powerpc/sysdev/fsl_msi.c   |9 ++-
 arch/powerpc/sysdev/fsl_soc.c   |2 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 129 insertions(+), 59 deletions(-)

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 8/8] PPC: Don't use hardcoded opcode for ePAPR hcall invocation

2012-07-03 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 833ce2c..b8d9445 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -195,7 +195,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -224,7 +224,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -254,7 +254,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -279,7 +279,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -307,7 +307,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -346,7 +346,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -385,7 +385,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -423,7 +423,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -456,7 +456,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -480,7 +480,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -500,7 +500,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int 
handle,
r9 = (uint32_t)propvalue_addr;
r10 = *propvalue_len

[PATCH v12 5/8] KVM: PPC: ev_idle hcall support for e500 guests

2012-07-03 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[varun: 64-bit changes]
Signed-off-by: Varun Sethi varun.se...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: use new CURRENT_THREAD_INFO macro

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   28 
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index c0c7adc..833ce2c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -109,6 +105,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -506,5 +507,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..62c0dc2 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,41 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
 #include asm/thread_info.h
 #include asm/ppc_asm.h
+#include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+/* epapr_ev_idle() was derived from e500_idle() */
+_GLOBAL(epapr_ev_idle)
+   CURRENT_THREAD_INFO(r3, r1)
+   PPC_LL  r4, TI_LOCAL_FLAGS(r3)  /* set napping bit */
+   ori r4, r4,_TLF_NAPPING /* so when we take an exception */
+   PPC_STL r4, TI_LOCAL_FLAGS(r3)  /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 2/8] KVM: PPC: use definitions in epapr header for hcalls

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/include/asm/kvm_para.h |   21 +++--
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   10 +-
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index c18916b..a168ce3 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,10 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
-#define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+
+#define KVM_HCALL_TOKEN(num) _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
+
+#include asm/epapr_hcalls.h
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
@@ -121,7 +122,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
   unsigned long *out,
   unsigned long nr)
 {
-   return HC_EV_UNIMPLEMENTED;
+   return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +133,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, 
unsigned long *r2)
unsigned long out[8];
unsigned long r;
 
-   r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
*r2 = out[0];
 
return r;
@@ -143,7 +144,7 @@ static inline long kvm_hypercall0(unsigned int nr)
unsigned long in[8];
unsigned long out[8];
 
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +153,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned 
long p1)
unsigned long out[8];
 
in[0] = p1;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +164,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned 
long p1,
 
in[0] = p1;
in[1] = p2;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +176,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned 
long p1,
in[0] = p1;
in[1] = p2;
in[2] = p3;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +190,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned 
long p1,
in[1] = p2;
in[2] = p3;
in[3] = p4;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 1c13307..5fcc537 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
in[0] = KVM_MAGIC_PAGE;
in[1] = KVM_MAGIC_PAGE;
 
-   kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+   kvm_hypercall(in, out, KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE));
 
*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 87f4dc8..a98f7e0 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
 
switch (nr) {
-   case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+   case KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE):
{
vcpu-arch.magic_page_pa = param1;
vcpu-arch.magic_page_ea = param2;
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-   r = HC_EV_SUCCESS;
+   r = EV_SUCCESS;
break;
}
-   case HC_VENDOR_KVM | KVM_HC_FEATURES:
-   r = HC_EV_SUCCESS;
+   case KVM_HCALL_TOKEN(KVM_HC_FEATURES):
+   r = EV_SUCCESS;
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
/* Second return value is in r4 */
break;
default:
-   r = HC_EV_UNIMPLEMENTED;
+   r = EV_UNIMPLEMENTED;
break;
}
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http

[PATCH v12 4/8] KVM: PPC: Add support for ePAPR idle hcall in host kernel

2012-07-03 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: use EV_HCALL_TOKEN macro

 Documentation/virtual/kvm/api.txt |7 +--
 arch/powerpc/include/asm/Kbuild   |1 +
 arch/powerpc/kvm/powerpc.c|   10 --
 include/linux/kvm.h   |2 ++
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 310fe50..920c3c4 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1190,12 +1190,15 @@ struct kvm_ppc_pvinfo {
 This ioctl fetches PV specific information that need to be passed to the guest
 using the device tree or other means from vm context.
 
-For now the only implemented piece of information distributed here is an array
-of 4 instructions that make up a hypercall.
+The hcall array defines 4 instructions that make up a hypercall.
 
 If any additional field gets added to this structure later on, a bit for that
 additional piece of information will be set in the flags bitmap.
 
+The flags bitmap is defined as:
+
+   /* the host supports the ePAPR idle hcall
+   #define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
 
 4.48 KVM_ASSIGN_PCI_DEVICE
 
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 30cf01c..1a4db32 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   return !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   return !!(v-arch.pending_exceptions) ||
   v-requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
+   r = EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+   break;
default:
r = EV_UNIMPLEMENTED;
break;
@@ -767,6 +771,8 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[3] = inst_nop;
 #endif
 
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 2ce09aa..c03e59e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -473,6 +473,8 @@ struct kvm_ppc_smmu_info {
struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 3/8] KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[stuart: factored this out from idle hcall support in host patch]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/kvm/powerpc.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index a98f7e0..30cf01c 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -739,9 +739,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct 
vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -758,6 +765,7 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
 
return 0;
 }
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 6/8] PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

2012-07-03 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v12: no changes

 arch/powerpc/platforms/Kconfig |1 +
 drivers/tty/Kconfig|1 +
 drivers/virt/Kconfig   |1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index e7a896a..48a920d 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -90,6 +90,7 @@ config MPIC
 config PPC_EPAPR_HV_PIC
bool
default n
+   select EPAPR_PARAVIRT
 
 config MPIC_WEIRD
bool
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 830cd62..aa99cd2 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -358,6 +358,7 @@ config TRACE_SINK
 config PPC_EPAPR_HV_BYTECHAN
tristate ePAPR hypervisor byte channel driver
depends on PPC
+   select EPAPR_PARAVIRT
help
  This driver creates /dev entries for each ePAPR hypervisor byte
  channel, thereby allowing applications to communicate with byte
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index 2dcdbc9..99ebdde 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -15,6 +15,7 @@ if VIRT_DRIVERS
 config FSL_HV_MANAGER
tristate Freescale hypervisor management driver
depends on FSL_SOC
+   select EPAPR_PARAVIRT
help
   The Freescale hypervisor management driver provides several services
  to drivers and applications related to the Freescale hypervisor:
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 0/8] KVM: PPC: Add ePAPR idle hcall support

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

This is a reworked version of the v10 patchset I sent out back
in March, address the comments, plus adding some additional
fixes found in further testing.

Liu Yu-B13201 (3):
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Scott Wood (1):
  powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

Stuart Yoder (4):
  PPC: epapr: create define for return code value of success
  KVM: PPC: use definitions in epapr header for hcalls
  KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500
  PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

 Documentation/virtual/kvm/api.txt   |7 -
 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   36 --
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/include/asm/kvm_para.h |   21 +
 arch/powerpc/kernel/epapr_hcalls.S  |   32 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 -
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   30 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 arch/powerpc/sysdev/fsl_msi.c   |9 ++-
 arch/powerpc/sysdev/fsl_soc.c   |2 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 133 insertions(+), 59 deletions(-)

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 1/8] PPC: epapr: create define for return code value of success

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-this is a new patch in v11

 arch/powerpc/include/asm/epapr_hcalls.h |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index bf2c06c..c0c7adc 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -88,7 +88,8 @@
 #define _EV_HCALL_TOKEN(id, num) (((id)  16) | (num))
 #define EV_HCALL_TOKEN(hcall_num) _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, 
hcall_num)
 
-/* epapr error codes */
+/* epapr return codes */
+#define EV_SUCCESS 0
 #define EV_EPERM   1   /* Operation not permitted */
 #define EV_ENOENT  2   /*  Entry Not Found */
 #define EV_EIO 3   /* I/O error occured */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 2/8] KVM: PPC: use definitions in epapr header for hcalls

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11:
   -as per Alex's comments, created a KVM hcall macro to 
simplify code creating hcall tokens
   -used macro for success return code

 arch/powerpc/include/asm/kvm_para.h |   21 +++--
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   10 +-
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index c18916b..a168ce3 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,10 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
-#define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+
+#define KVM_HCALL_TOKEN(num) _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
+
+#include asm/epapr_hcalls.h
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
@@ -121,7 +122,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
   unsigned long *out,
   unsigned long nr)
 {
-   return HC_EV_UNIMPLEMENTED;
+   return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +133,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, 
unsigned long *r2)
unsigned long out[8];
unsigned long r;
 
-   r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
*r2 = out[0];
 
return r;
@@ -143,7 +144,7 @@ static inline long kvm_hypercall0(unsigned int nr)
unsigned long in[8];
unsigned long out[8];
 
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +153,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned 
long p1)
unsigned long out[8];
 
in[0] = p1;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +164,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned 
long p1,
 
in[0] = p1;
in[1] = p2;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +176,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned 
long p1,
in[0] = p1;
in[1] = p2;
in[2] = p3;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +190,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned 
long p1,
in[1] = p2;
in[2] = p3;
in[3] = p4;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 1c13307..5fcc537 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
in[0] = KVM_MAGIC_PAGE;
in[1] = KVM_MAGIC_PAGE;
 
-   kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+   kvm_hypercall(in, out, KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE));
 
*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 87f4dc8..a98f7e0 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
 
switch (nr) {
-   case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+   case KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE):
{
vcpu-arch.magic_page_pa = param1;
vcpu-arch.magic_page_ea = param2;
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-   r = HC_EV_SUCCESS;
+   r = EV_SUCCESS;
break;
}
-   case HC_VENDOR_KVM | KVM_HC_FEATURES:
-   r = HC_EV_SUCCESS;
+   case KVM_HCALL_TOKEN(KVM_HC_FEATURES):
+   r = EV_SUCCESS;
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
/* Second return value is in r4 */
break;
default:
-   r = HC_EV_UNIMPLEMENTED;
+   r = EV_UNIMPLEMENTED;
break;
}
 
-- 
1.7.3.4


--
To unsubscribe from this list: send

[PATCH v11 3/8] KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[stuart: factored this out from idle hcall support in host patch]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11
   -split this code out into a separate patch as per the review
comments

 arch/powerpc/kvm/powerpc.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index a98f7e0..30cf01c 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -739,9 +739,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct 
vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -758,6 +765,7 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
 
return 0;
 }
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 4/8] KVM: PPC: Add support for ePAPR idle hcall in host kernel

2012-06-22 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11:
   -added PV info flag definition in api.txt 

 Documentation/virtual/kvm/api.txt |7 +--
 arch/powerpc/include/asm/Kbuild   |1 +
 arch/powerpc/kvm/powerpc.c|   10 --
 include/linux/kvm.h   |2 ++
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 310fe50..920c3c4 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1190,12 +1190,15 @@ struct kvm_ppc_pvinfo {
 This ioctl fetches PV specific information that need to be passed to the guest
 using the device tree or other means from vm context.
 
-For now the only implemented piece of information distributed here is an array
-of 4 instructions that make up a hypercall.
+The hcall array defines 4 instructions that make up a hypercall.
 
 If any additional field gets added to this structure later on, a bit for that
 additional piece of information will be set in the flags bitmap.
 
+The flags bitmap is defined as:
+
+   /* the host supports the ePAPR idle hcall
+   #define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
 
 4.48 KVM_ASSIGN_PCI_DEVICE
 
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 30cf01c..53d4d45 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   return !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   return !!(v-arch.pending_exceptions) ||
   v-requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
+   r = EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+   break;
default:
r = EV_UNIMPLEMENTED;
break;
@@ -767,6 +771,8 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[3] = inst_nop;
 #endif
 
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 2ce09aa..c03e59e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -473,6 +473,8 @@ struct kvm_ppc_smmu_info {
struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 5/8] KVM: PPC: ev_idle hcall support for e500 guests

2012-06-22 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[varun: 64-bit changes]
Signed-off-by: Varun Sethi varun.se...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11:
   -added comment about origin of idle instruction sequence
   -update for 64-bit support found in testing

 arch/powerpc/include/asm/epapr_hcalls.h |   11 +
 arch/powerpc/kernel/epapr_hcalls.S  |   32 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 +-
 3 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index c0c7adc..833ce2c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -109,6 +105,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -506,5 +507,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..eb19377 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,45 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
 #include asm/thread_info.h
 #include asm/ppc_asm.h
+#include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+/* epapr_ev_idle() was derived from e500_idle() */
+_GLOBAL(epapr_ev_idle)
+#ifndef CONFIG_PPC64
+   rlwinm  r3, r1, 0, 0, 31-THREAD_SHIFT   /* current thread_info */
+#else
+   clrrdi  r3, r1, THREAD_SHIFT
+#endif
+   PPC_LL  r4, TI_LOCAL_FLAGS(r3)  /* set napping bit */
+   ori r4, r4,_TLF_NAPPING /* so when we take an exception */
+   PPC_STL r4, TI_LOCAL_FLAGS(r3)  /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 6/8] PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-new in v11-- this patch is needed so the dependencies are correct
 for all users of epapr hcalls, without it there will be build issues
 after hardcoded opcodes for hcalls are removed

 arch/powerpc/platforms/Kconfig |1 +
 drivers/tty/Kconfig|1 +
 drivers/virt/Kconfig   |1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index e7a896a..48a920d 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -90,6 +90,7 @@ config MPIC
 config PPC_EPAPR_HV_PIC
bool
default n
+   select EPAPR_PARAVIRT
 
 config MPIC_WEIRD
bool
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 830cd62..aa99cd2 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -358,6 +358,7 @@ config TRACE_SINK
 config PPC_EPAPR_HV_BYTECHAN
tristate ePAPR hypervisor byte channel driver
depends on PPC
+   select EPAPR_PARAVIRT
help
  This driver creates /dev entries for each ePAPR hypervisor byte
  channel, thereby allowing applications to communicate with byte
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index 2dcdbc9..99ebdde 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -15,6 +15,7 @@ if VIRT_DRIVERS
 config FSL_HV_MANAGER
tristate Freescale hypervisor management driver
depends on FSL_SOC
+   select EPAPR_PARAVIRT
help
   The Freescale hypervisor management driver provides several services
  to drivers and applications related to the Freescale hypervisor:
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 7/8] powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

2012-06-22 Thread Stuart Yoder
From: Scott Wood scottw...@freescale.com

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-new in v11-- this is derived from an internal patch from Scott,
 without it there will be build issues after hardcoded opcodes for
 hcalls are removed

 arch/powerpc/sysdev/fsl_msi.c |9 +++--
 arch/powerpc/sysdev/fsl_soc.c |2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index 6e097de..7e2b2f2 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -236,7 +236,6 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
u32 intr_index;
u32 have_shift = 0;
struct fsl_msi_cascade_data *cascade_data;
-   unsigned int ret;
 
cascade_data = irq_get_handler_data(irq);
msi_data = cascade_data-msi_data;
@@ -268,7 +267,9 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
case FSL_PIC_IP_IPIC:
msir_value = fsl_msi_read(msi_data-msi_regs, msir_index * 0x4);
break;
-   case FSL_PIC_IP_VMPIC:
+#ifdef CONFIG_EPAPR_PARAVIRT
+   case FSL_PIC_IP_VMPIC: {
+   unsigned int ret;
ret = fh_vmpic_get_msir(virq_to_hw(irq), msir_value);
if (ret) {
pr_err(fsl-msi: fh_vmpic_get_msir() failed for 
@@ -277,6 +278,8 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
}
break;
}
+#endif
+   }
 
while (msir_value) {
intr_index = ffs(msir_value) - 1;
@@ -508,10 +511,12 @@ static const struct of_device_id fsl_of_msi_ids[] = {
.compatible = fsl,ipic-msi,
.data = (void *)ipic_msi_feature,
},
+#ifdef CONFIG_EPAPR_PARAVIRT
{
.compatible = fsl,vmpic-msi,
.data = (void *)vmpic_msi_feature,
},
+#endif
{}
 };
 
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index c449dbd..97118dc 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -253,6 +253,7 @@ struct platform_diu_data_ops diu_ops;
 EXPORT_SYMBOL(diu_ops);
 #endif
 
+#ifdef CONFIG_EPAPR_PARAVIRT
 /*
  * Restart the current partition
  *
@@ -278,3 +279,4 @@ void fsl_hv_halt(void)
pr_info(hv exit\n);
fh_partition_stop(-1);
 }
+#endif
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 8/8] PPC: Don't use hardcoded opcode for ePAPR hcall invocation

2012-06-22 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 833ce2c..b8d9445 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -195,7 +195,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -224,7 +224,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -254,7 +254,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -279,7 +279,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -307,7 +307,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -346,7 +346,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -385,7 +385,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -423,7 +423,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -456,7 +456,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -480,7 +480,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -500,7 +500,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int 
handle,
r9 = (uint32_t)propvalue_addr;
r10

[PATCH v11 0/8] KVM: PPC: Add ePAPR idle hcall support

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

This is a reworked version of the v10 patchset I sent out back
in March, address the comments, plus adding some additional
fixes found in further testing.

Liu Yu-B13201 (3):
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Scott Wood (1):
  powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

Stuart Yoder (4):
  PPC: epapr: create define for return code value of success
  KVM: PPC: use definitions in epapr header for hcalls
  KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500
  PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

 Documentation/virtual/kvm/api.txt   |7 -
 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   36 --
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/include/asm/kvm_para.h |   21 +
 arch/powerpc/kernel/epapr_hcalls.S  |   32 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 -
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   30 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 arch/powerpc/sysdev/fsl_msi.c   |9 ++-
 arch/powerpc/sysdev/fsl_soc.c   |2 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 133 insertions(+), 59 deletions(-)

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 1/8] PPC: epapr: create define for return code value of success

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-this is a new patch in v11

 arch/powerpc/include/asm/epapr_hcalls.h |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index bf2c06c..c0c7adc 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -88,7 +88,8 @@
 #define _EV_HCALL_TOKEN(id, num) (((id)  16) | (num))
 #define EV_HCALL_TOKEN(hcall_num) _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, 
hcall_num)
 
-/* epapr error codes */
+/* epapr return codes */
+#define EV_SUCCESS 0
 #define EV_EPERM   1   /* Operation not permitted */
 #define EV_ENOENT  2   /*  Entry Not Found */
 #define EV_EIO 3   /* I/O error occured */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 2/8] KVM: PPC: use definitions in epapr header for hcalls

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11:
   -as per Alex's comments, created a KVM hcall macro to 
simplify code creating hcall tokens
   -used macro for success return code

 arch/powerpc/include/asm/kvm_para.h |   21 +++--
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   10 +-
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index c18916b..a168ce3 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,10 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
-#define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+
+#define KVM_HCALL_TOKEN(num) _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
+
+#include asm/epapr_hcalls.h
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
@@ -121,7 +122,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
   unsigned long *out,
   unsigned long nr)
 {
-   return HC_EV_UNIMPLEMENTED;
+   return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +133,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, 
unsigned long *r2)
unsigned long out[8];
unsigned long r;
 
-   r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
*r2 = out[0];
 
return r;
@@ -143,7 +144,7 @@ static inline long kvm_hypercall0(unsigned int nr)
unsigned long in[8];
unsigned long out[8];
 
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +153,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned 
long p1)
unsigned long out[8];
 
in[0] = p1;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +164,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned 
long p1,
 
in[0] = p1;
in[1] = p2;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +176,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned 
long p1,
in[0] = p1;
in[1] = p2;
in[2] = p3;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +190,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned 
long p1,
in[1] = p2;
in[2] = p3;
in[3] = p4;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 1c13307..5fcc537 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
in[0] = KVM_MAGIC_PAGE;
in[1] = KVM_MAGIC_PAGE;
 
-   kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+   kvm_hypercall(in, out, KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE));
 
*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 87f4dc8..a98f7e0 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
 
switch (nr) {
-   case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+   case KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE):
{
vcpu-arch.magic_page_pa = param1;
vcpu-arch.magic_page_ea = param2;
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-   r = HC_EV_SUCCESS;
+   r = EV_SUCCESS;
break;
}
-   case HC_VENDOR_KVM | KVM_HC_FEATURES:
-   r = HC_EV_SUCCESS;
+   case KVM_HCALL_TOKEN(KVM_HC_FEATURES):
+   r = EV_SUCCESS;
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
/* Second return value is in r4 */
break;
default:
-   r = HC_EV_UNIMPLEMENTED;
+   r = EV_UNIMPLEMENTED;
break;
}
 
-- 
1.7.3.4


--
To unsubscribe from this list: send

[PATCH v11 3/8] KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[stuart: factored this out from idle hcall support in host patch]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11
   -split this code out into a separate patch as per the review
comments

 arch/powerpc/kvm/powerpc.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index a98f7e0..30cf01c 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -739,9 +739,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct 
vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -758,6 +765,7 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
 
return 0;
 }
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 4/8] KVM: PPC: Add support for ePAPR idle hcall in host kernel

2012-06-22 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11:
   -added PV info flag definition in api.txt 

 Documentation/virtual/kvm/api.txt |7 +--
 arch/powerpc/include/asm/Kbuild   |1 +
 arch/powerpc/kvm/powerpc.c|   10 --
 include/linux/kvm.h   |2 ++
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 310fe50..920c3c4 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1190,12 +1190,15 @@ struct kvm_ppc_pvinfo {
 This ioctl fetches PV specific information that need to be passed to the guest
 using the device tree or other means from vm context.
 
-For now the only implemented piece of information distributed here is an array
-of 4 instructions that make up a hypercall.
+The hcall array defines 4 instructions that make up a hypercall.
 
 If any additional field gets added to this structure later on, a bit for that
 additional piece of information will be set in the flags bitmap.
 
+The flags bitmap is defined as:
+
+   /* the host supports the ePAPR idle hcall
+   #define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
 
 4.48 KVM_ASSIGN_PCI_DEVICE
 
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 30cf01c..53d4d45 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   return !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   return !!(v-arch.pending_exceptions) ||
   v-requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
+   r = EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+   break;
default:
r = EV_UNIMPLEMENTED;
break;
@@ -767,6 +771,8 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[3] = inst_nop;
 #endif
 
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 2ce09aa..c03e59e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -473,6 +473,8 @@ struct kvm_ppc_smmu_info {
struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 5/8] KVM: PPC: ev_idle hcall support for e500 guests

2012-06-22 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[varun: 64-bit changes]
Signed-off-by: Varun Sethi varun.se...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11:
   -added comment about origin of idle instruction sequence
   -update for 64-bit support found in testing

 arch/powerpc/include/asm/epapr_hcalls.h |   11 +
 arch/powerpc/kernel/epapr_hcalls.S  |   32 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 +-
 3 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index c0c7adc..833ce2c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -109,6 +105,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -506,5 +507,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..eb19377 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,45 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
 #include asm/thread_info.h
 #include asm/ppc_asm.h
+#include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+/* epapr_ev_idle() was derived from e500_idle() */
+_GLOBAL(epapr_ev_idle)
+#ifndef CONFIG_PPC64
+   rlwinm  r3, r1, 0, 0, 31-THREAD_SHIFT   /* current thread_info */
+#else
+   clrrdi  r3, r1, THREAD_SHIFT
+#endif
+   PPC_LL  r4, TI_LOCAL_FLAGS(r3)  /* set napping bit */
+   ori r4, r4,_TLF_NAPPING /* so when we take an exception */
+   PPC_STL r4, TI_LOCAL_FLAGS(r3)  /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 6/8] PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

2012-06-22 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-new in v11-- this patch is needed so the dependencies are correct
 for all users of epapr hcalls, without it there will be build issues
 after hardcoded opcodes for hcalls are removed

 arch/powerpc/platforms/Kconfig |1 +
 drivers/tty/Kconfig|1 +
 drivers/virt/Kconfig   |1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index e7a896a..48a920d 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -90,6 +90,7 @@ config MPIC
 config PPC_EPAPR_HV_PIC
bool
default n
+   select EPAPR_PARAVIRT
 
 config MPIC_WEIRD
bool
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 830cd62..aa99cd2 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -358,6 +358,7 @@ config TRACE_SINK
 config PPC_EPAPR_HV_BYTECHAN
tristate ePAPR hypervisor byte channel driver
depends on PPC
+   select EPAPR_PARAVIRT
help
  This driver creates /dev entries for each ePAPR hypervisor byte
  channel, thereby allowing applications to communicate with byte
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index 2dcdbc9..99ebdde 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -15,6 +15,7 @@ if VIRT_DRIVERS
 config FSL_HV_MANAGER
tristate Freescale hypervisor management driver
depends on FSL_SOC
+   select EPAPR_PARAVIRT
help
   The Freescale hypervisor management driver provides several services
  to drivers and applications related to the Freescale hypervisor:
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 7/8] powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

2012-06-22 Thread Stuart Yoder
From: Scott Wood scottw...@freescale.com

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-new in v11-- this is derived from an internal patch from Scott,
 without it there will be build issues after hardcoded opcodes for
 hcalls are removed

 arch/powerpc/sysdev/fsl_msi.c |9 +++--
 arch/powerpc/sysdev/fsl_soc.c |2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index 6e097de..7e2b2f2 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -236,7 +236,6 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
u32 intr_index;
u32 have_shift = 0;
struct fsl_msi_cascade_data *cascade_data;
-   unsigned int ret;
 
cascade_data = irq_get_handler_data(irq);
msi_data = cascade_data-msi_data;
@@ -268,7 +267,9 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
case FSL_PIC_IP_IPIC:
msir_value = fsl_msi_read(msi_data-msi_regs, msir_index * 0x4);
break;
-   case FSL_PIC_IP_VMPIC:
+#ifdef CONFIG_EPAPR_PARAVIRT
+   case FSL_PIC_IP_VMPIC: {
+   unsigned int ret;
ret = fh_vmpic_get_msir(virq_to_hw(irq), msir_value);
if (ret) {
pr_err(fsl-msi: fh_vmpic_get_msir() failed for 
@@ -277,6 +278,8 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
}
break;
}
+#endif
+   }
 
while (msir_value) {
intr_index = ffs(msir_value) - 1;
@@ -508,10 +511,12 @@ static const struct of_device_id fsl_of_msi_ids[] = {
.compatible = fsl,ipic-msi,
.data = (void *)ipic_msi_feature,
},
+#ifdef CONFIG_EPAPR_PARAVIRT
{
.compatible = fsl,vmpic-msi,
.data = (void *)vmpic_msi_feature,
},
+#endif
{}
 };
 
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index c449dbd..97118dc 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -253,6 +253,7 @@ struct platform_diu_data_ops diu_ops;
 EXPORT_SYMBOL(diu_ops);
 #endif
 
+#ifdef CONFIG_EPAPR_PARAVIRT
 /*
  * Restart the current partition
  *
@@ -278,3 +279,4 @@ void fsl_hv_halt(void)
pr_info(hv exit\n);
fh_partition_stop(-1);
 }
+#endif
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 8/8] PPC: Don't use hardcoded opcode for ePAPR hcall invocation

2012-06-22 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v11: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 833ce2c..b8d9445 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -195,7 +195,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -224,7 +224,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -254,7 +254,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -279,7 +279,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -307,7 +307,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -346,7 +346,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -385,7 +385,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -423,7 +423,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -456,7 +456,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -480,7 +480,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -500,7 +500,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int 
handle,
r9 = (uint32_t)propvalue_addr;
r10

Re: Question about host CPU usage/allocation by KVM

2012-04-18 Thread Stuart Yoder
On Tue, Apr 17, 2012 at 4:54 PM, Alexander Lyakas
alex.bols...@gmail.com wrote:
 Greetings everybody,

 Can anybody please point me to code/documentation regarding the
 following questions I have:

 - What does it actually mean using -smp N option, in terms of CPU
 sharing between the host and the guest?
 - How are guest CPUs mapped to host CPUs (if at all)?

Each guest CPU (vcpu) corresponds to a QEMU thread.
You can see the thread ids in QEMU with info cpus in the
QEMU monitor.

Since a vcpu is a thread you can apply standard Linux
mechanisms to managing those threads-- CPU affinity, etc.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: smp option of qemu-kvm

2012-04-06 Thread Stuart Yoder
On Thu, Apr 5, 2012 at 1:52 PM, Steven wangwangk...@gmail.com wrote:
 Hi, Daniel,
 Thanks for your quick response. However, the ps -eLf show 4 threads
 for the VM and I checked 4 threads have the same tgid.
 But the VM I created is with -smp 2 option. Could you explain this? Thanks.

info cpus in the QEMU monitor shell willshow you which thread ID
corresponds to each vpu.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-03-15 Thread Stuart Yoder
On Wed, Mar 7, 2012 at 5:27 PM, Alexander Graf ag...@suse.de wrote:
 #define KVM_SC_MAGIC_R0               0x4b564d21 /* KVM! */
 -#define HC_VENDOR_KVM                (42  16)
 +
 +#include asm/epapr_hcalls.h
 +
 +/* ePAPR Hypercall Vendor ID */
 +#define HC_VENDOR_EPAPR              (EV_EPAPR_VENDOR_ID  16)
 +#define HC_VENDOR_KVM                (EV_KVM_VENDOR_ID  16)
 +
 +/* ePAPR Hypercall Token */
 +#define HC_EV_IDLE           EV_IDLE
 +
 +/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS         0
 -#define HC_EV_UNIMPLEMENTED  12
 +#define HC_EV_UNIMPLEMENTED  EV_UNIMPLEMENTED

 Shouldn't all this rather be in an epapr header file?

Think I see a cleaner way of handling this, will address in next respin.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-03-15 Thread Stuart Yoder
 +early_initcall(epapr_paravirt_init);

 Just want to double-check. Are you 100% sure that this gets called before 
 kvm_guest_init()?

Yes, kvm_guest_init is a postcore_initcall, which comes after early.
 Some printks confirmed this.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support

2012-03-15 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

v10:
   -patchset is now 5 patches, using the epapr header 
definitions is split out into a separate patch
   -patch titles and descriptions are also updated
   -cleanup as per review comments addressed

Liu Yu-B13201 (4):
  KVM: PPC: Factor out guest epapr initialization
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Stuart Yoder (1):
  KVM: PPC: use definitions in epapr header for hcalls

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   35 ++
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +-
 arch/powerpc/include/asm/kvm_para.h |   19 +-
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   53 +++
 arch/powerpc/kernel/epapr_paravirt.c|   61 +++
 arch/powerpc/kernel/kvm.c   |   30 ++-
 arch/powerpc/kernel/kvm_emul.S  |   10 -
 arch/powerpc/kvm/powerpc.c  |   30 +++
 arch/powerpc/platforms/Kconfig  |   10 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 14 files changed, 202 insertions(+), 88 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

epapr paravirtualization support is now a Kconfig
selectable option

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: misc minor fixes, description update]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v10
   -update patch subject/description

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 +++
 arch/powerpc/kernel/epapr_paravirt.c|   52 +++
 arch/powerpc/kernel/kvm.c   |   28 ++---
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |9 +
 7 files changed, 92 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..2173d4c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_paravirt_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ee728e4..ba8fa43 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -136,6 +136,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..028aeae
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,52 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_paravirt_enabled;
+
+static int __init epapr_paravirt_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (!insts)
+   return -ENODEV;
+
+   if (len % 4 || len  (4 * 4))
+   return -ENODEV;
+
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_paravirt_enabled = true;
+
+   return 0;
+}
+
+early_initcall(epapr_paravirt_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 62bdf23..1c13307 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -31,6 +31,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 
 #define KVM_MAGIC_PAGE (-4096L)
 #define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared, x)
@@ -726,7 +727,7 @@ unsigned long

[PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v10:
   -ePAPR definitions now addressed in separate patch
   -move clearing of KVM_REQ_UNHALT after kvm_vcpu_block() call 

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/kvm/powerpc.c  |   20 +---
 include/linux/kvm.h |2 ++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index d738626..7c4e5cc 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   return !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   return !!(v-arch.pending_exceptions) ||
   v-requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
+   r = 0;  /* success */
+   kvm_vcpu_block(vcpu);
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+   break;
default:
r = EV_UNIMPLEMENTED;
break;
@@ -732,9 +736,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct 
vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -751,6 +762,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
+
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
 
return 0;
 }
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 7a9dd4b..640ec5a 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -449,6 +449,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 5/5] PPC: Don't use hardcoded opcode for ePAPR hcall invocation

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Also, select ePAPR kconfig option for all users of  ePAPR hcalls.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: kconfig fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v10: update patch subject/description

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 5 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 78460ac..b95758d 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -189,7 +189,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -218,7 +218,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -248,7 +248,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -273,7 +273,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -301,7 +301,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -340,7 +340,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -379,7 +379,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -417,7 +417,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -450,7 +450,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -474,7 +474,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -494,7 +494,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1

[PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[stuart: update patch description]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v10:
   -add spaces as per comments
   -use PPC_LL/PPC_STL for long accesses

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   28 
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 2173d4c..78460ac 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -108,6 +104,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..698e7d9 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,41 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
 #include asm/thread_info.h
 #include asm/ppc_asm.h
+#include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3, r1, 0, 0, 31-THREAD_SHIFT   /* current thread_info */
+   PPC_LL  r4, TI_LOCAL_FLAGS(r3)  /* set napping bit */
+   ori r4, r4,_TLF_NAPPING /* so when we take an exception */
+   PPC_STL r4, TI_LOCAL_FLAGS(r3)  /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls

2012-03-15 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
 arch/powerpc/include/asm/kvm_para.h |   19 +--
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   10 +-
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index c18916b..7d4a870 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,8 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
-#define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+
+#include asm/epapr_hcalls.h
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
@@ -121,7 +120,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
   unsigned long *out,
   unsigned long nr)
 {
-   return HC_EV_UNIMPLEMENTED;
+   return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +131,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, 
unsigned long *r2)
unsigned long out[8];
unsigned long r;
 
-   r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   r = kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
*r2 = out[0];
 
return r;
@@ -143,7 +142,7 @@ static inline long kvm_hypercall0(unsigned int nr)
unsigned long in[8];
unsigned long out[8];
 
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +151,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned 
long p1)
unsigned long out[8];
 
in[0] = p1;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +162,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned 
long p1,
 
in[0] = p1;
in[1] = p2;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +174,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned 
long p1,
in[0] = p1;
in[1] = p2;
in[2] = p3;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +188,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned 
long p1,
in[1] = p2;
in[2] = p3;
in[3] = p4;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 1c13307..b5ba561 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
in[0] = KVM_MAGIC_PAGE;
in[1] = KVM_MAGIC_PAGE;
 
-   kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+   kvm_hypercall(in, out, _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, 
KVM_HC_PPC_MAP_MAGIC_PAGE));
 
*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 58ad860..d738626 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
 
switch (nr) {
-   case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+   case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_PPC_MAP_MAGIC_PAGE):
{
vcpu-arch.magic_page_pa = param1;
vcpu-arch.magic_page_ea = param2;
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-   r = HC_EV_SUCCESS;
+   r = 0;  /* success */
break;
}
-   case HC_VENDOR_KVM | KVM_HC_FEATURES:
-   r = HC_EV_SUCCESS;
+   case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_FEATURES):
+   r = 0;  /* success */
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
/* Second return value is in r4 */
break;
default:
-   r = HC_EV_UNIMPLEMENTED;
+   r = EV_UNIMPLEMENTED;
break;
}
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo

Re: [PATCH v9 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-03-15 Thread Stuart Yoder
On Wed, Mar 7, 2012 at 5:27 PM, Alexander Graf ag...@suse.de wrote:
 #define KVM_SC_MAGIC_R0               0x4b564d21 /* KVM! */
 -#define HC_VENDOR_KVM                (42  16)
 +
 +#include asm/epapr_hcalls.h
 +
 +/* ePAPR Hypercall Vendor ID */
 +#define HC_VENDOR_EPAPR              (EV_EPAPR_VENDOR_ID  16)
 +#define HC_VENDOR_KVM                (EV_KVM_VENDOR_ID  16)
 +
 +/* ePAPR Hypercall Token */
 +#define HC_EV_IDLE           EV_IDLE
 +
 +/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS         0
 -#define HC_EV_UNIMPLEMENTED  12
 +#define HC_EV_UNIMPLEMENTED  EV_UNIMPLEMENTED

 Shouldn't all this rather be in an epapr header file?

Think I see a cleaner way of handling this, will address in next respin.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-03-15 Thread Stuart Yoder
 +early_initcall(epapr_paravirt_init);

 Just want to double-check. Are you 100% sure that this gets called before 
 kvm_guest_init()?

Yes, kvm_guest_init is a postcore_initcall, which comes after early.
 Some printks confirmed this.

Stuart
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support

2012-03-15 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

v10:
   -patchset is now 5 patches, using the epapr header 
definitions is split out into a separate patch
   -patch titles and descriptions are also updated
   -cleanup as per review comments addressed

Liu Yu-B13201 (4):
  KVM: PPC: Factor out guest epapr initialization
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Stuart Yoder (1):
  KVM: PPC: use definitions in epapr header for hcalls

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   35 ++
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +-
 arch/powerpc/include/asm/kvm_para.h |   19 +-
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   53 +++
 arch/powerpc/kernel/epapr_paravirt.c|   61 +++
 arch/powerpc/kernel/kvm.c   |   30 ++-
 arch/powerpc/kernel/kvm_emul.S  |   10 -
 arch/powerpc/kvm/powerpc.c  |   30 +++
 arch/powerpc/platforms/Kconfig  |   10 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 14 files changed, 202 insertions(+), 88 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

epapr paravirtualization support is now a Kconfig
selectable option

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: misc minor fixes, description update]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v10
   -update patch subject/description

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 +++
 arch/powerpc/kernel/epapr_paravirt.c|   52 +++
 arch/powerpc/kernel/kvm.c   |   28 ++---
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |9 +
 7 files changed, 92 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..2173d4c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_paravirt_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ee728e4..ba8fa43 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -136,6 +136,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..028aeae
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,52 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_paravirt_enabled;
+
+static int __init epapr_paravirt_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (!insts)
+   return -ENODEV;
+
+   if (len % 4 || len  (4 * 4))
+   return -ENODEV;
+
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_paravirt_enabled = true;
+
+   return 0;
+}
+
+early_initcall(epapr_paravirt_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 62bdf23..1c13307 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -31,6 +31,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 
 #define KVM_MAGIC_PAGE (-4096L)
 #define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared, x)
@@ -726,7 +727,7 @@ unsigned long

[PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v10:
   -ePAPR definitions now addressed in separate patch
   -move clearing of KVM_REQ_UNHALT after kvm_vcpu_block() call 

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/kvm/powerpc.c  |   20 +---
 include/linux/kvm.h |2 ++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index d738626..7c4e5cc 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   return !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   return !!(v-arch.pending_exceptions) ||
   v-requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
+   r = 0;  /* success */
+   kvm_vcpu_block(vcpu);
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+   break;
default:
r = EV_UNIMPLEMENTED;
break;
@@ -732,9 +736,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct 
vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -751,6 +762,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
+
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
 
return 0;
 }
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 7a9dd4b..640ec5a 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -449,6 +449,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 5/5] PPC: Don't use hardcoded opcode for ePAPR hcall invocation

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Also, select ePAPR kconfig option for all users of  ePAPR hcalls.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: kconfig fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v10: update patch subject/description

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 5 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 78460ac..b95758d 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -189,7 +189,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -218,7 +218,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -248,7 +248,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -273,7 +273,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -301,7 +301,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -340,7 +340,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -379,7 +379,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -417,7 +417,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -450,7 +450,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -474,7 +474,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -494,7 +494,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1

[PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests

2012-03-15 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[stuart: update patch description]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v10:
   -add spaces as per comments
   -use PPC_LL/PPC_STL for long accesses

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   28 
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 2173d4c..78460ac 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -108,6 +104,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..698e7d9 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,41 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
 #include asm/thread_info.h
 #include asm/ppc_asm.h
+#include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3, r1, 0, 0, 31-THREAD_SHIFT   /* current thread_info */
+   PPC_LL  r4, TI_LOCAL_FLAGS(r3)  /* set napping bit */
+   ori r4, r4,_TLF_NAPPING /* so when we take an exception */
+   PPC_STL r4, TI_LOCAL_FLAGS(r3)  /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls

2012-03-15 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
 arch/powerpc/include/asm/kvm_para.h |   19 +--
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   10 +-
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index c18916b..7d4a870 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,8 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
-#define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+
+#include asm/epapr_hcalls.h
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
@@ -121,7 +120,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
   unsigned long *out,
   unsigned long nr)
 {
-   return HC_EV_UNIMPLEMENTED;
+   return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +131,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, 
unsigned long *r2)
unsigned long out[8];
unsigned long r;
 
-   r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   r = kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
*r2 = out[0];
 
return r;
@@ -143,7 +142,7 @@ static inline long kvm_hypercall0(unsigned int nr)
unsigned long in[8];
unsigned long out[8];
 
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +151,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned 
long p1)
unsigned long out[8];
 
in[0] = p1;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +162,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned 
long p1,
 
in[0] = p1;
in[1] = p2;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +174,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned 
long p1,
in[0] = p1;
in[1] = p2;
in[2] = p3;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +188,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned 
long p1,
in[1] = p2;
in[2] = p3;
in[3] = p4;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 1c13307..b5ba561 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
in[0] = KVM_MAGIC_PAGE;
in[1] = KVM_MAGIC_PAGE;
 
-   kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+   kvm_hypercall(in, out, _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, 
KVM_HC_PPC_MAP_MAGIC_PAGE));
 
*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 58ad860..d738626 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
 
switch (nr) {
-   case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+   case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_PPC_MAP_MAGIC_PAGE):
{
vcpu-arch.magic_page_pa = param1;
vcpu-arch.magic_page_ea = param2;
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-   r = HC_EV_SUCCESS;
+   r = 0;  /* success */
break;
}
-   case HC_VENDOR_KVM | KVM_HC_FEATURES:
-   r = HC_EV_SUCCESS;
+   case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_FEATURES):
+   r = 0;  /* success */
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
/* Second return value is in r4 */
break;
default:
-   r = HC_EV_UNIMPLEMENTED;
+   r = EV_UNIMPLEMENTED;
break;
}
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo

[PATCH 4/4] KVM: PPC: epapr: Update other hypercall invoking

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Discard the old way that invoke hypercall,
instead, use epapr paravirt.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: kconfig fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v8: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 5 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 78460ac..b95758d 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -189,7 +189,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -218,7 +218,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -248,7 +248,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -273,7 +273,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -301,7 +301,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -340,7 +340,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -379,7 +379,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -417,7 +417,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -450,7 +450,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -474,7 +474,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -494,7 +494,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile

[PATCH v8 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v8: updated hcall instruction for e500mc to be sc 1

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/kvm_para.h |   14 --
 arch/powerpc/kvm/booke.c|6 ++
 arch/powerpc/kvm/powerpc.c  |   14 --
 include/linux/kvm.h |2 ++
 5 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index d51df17..b68cb1c 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,3 +34,4 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index b3b4667..5617c8c 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -90,9 +90,19 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index f0ef0be..9fde645 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -593,6 +593,12 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
unsigned int priority;
 
if (vcpu-requests) {
+   /* kvm_vcpu_block() sets KVM_REQ_UNHALT, but it is
+* not cleared elsewhere as on x86.  Clear it here
+* for now, otherwise we never go idle.
+*/
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+
if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
smp_mb();
update_timer_ints(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index ee489f4..84e215b 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -48,8 +48,7 @@ static unsigned int perfmon_refcount;
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   bool ret = !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   bool ret = !!(v-arch.pending_exceptions) ||
   v-requests;
 
 #ifdef CONFIG_BOOKE
@@ -100,6 +99,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -888,6 +891,10 @@ out:
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
u32 inst_nop = 0x6000;
@@ -907,6 +914,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
+
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
 
return 0;
 }
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 28ced78..32b8f54 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -438,6 +438,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /*
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

from the kvm guest paravirt init code.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: misc minor fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v8: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 +++
 arch/powerpc/kernel/epapr_paravirt.c|   52 +++
 arch/powerpc/kernel/kvm.c   |   28 ++---
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |9 +
 7 files changed, 92 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..2173d4c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_paravirt_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ce4f7f1..09011d6 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -134,6 +134,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..028aeae
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,52 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_paravirt_enabled;
+
+static int __init epapr_paravirt_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (!insts)
+   return -ENODEV;
+
+   if (len % 4 || len  (4 * 4))
+   return -ENODEV;
+
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_paravirt_enabled = true;
+
+   return 0;
+}
+
+early_initcall(epapr_paravirt_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 9b6682e..b8a77a1 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -30,6 +30,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 #include asm/machdep.h
 #include asm/mpic.h
 
@@ -739,7 +740,7 @@ unsigned long kvm_hypercall(unsigned long *in,
unsigned long register r11 asm(r11) = nr;
unsigned long register r12 asm(r12);
 
-   asm volatile

[PATCH 3/4] KVM: PPC: epapr: install ev_idle hcall for e500 guest

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---

-v8: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   27 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 2173d4c..78460ac 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -108,6 +104,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..bf643ed 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,6 +8,7 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
@@ -15,6 +16,32 @@
 #include asm/ppc_asm.h
 #include asm/asm-offsets.h
 
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+   lwz r4,TI_LOCAL_FLAGS(r3)   /* set napping bit */
+   ori r4,r4,_TLF_NAPPING  /* so when we take an exception */
+   stw r4,TI_LOCAL_FLAGS(r3)   /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 0/4] KVM: PPC: Add ePAPR idle hcall support

2012-03-07 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

-v8
-updates hcall instruction for e500mc

Liu Yu-B13201 (4):
  KVM: PPC: epapr: Factor out the epapr init
  KVM: PPC: epapr: Add idle hcall support for host
  KVM: PPC: epapr: install ev_idle hcall for e500 guest
  KVM: PPC: epapr: Update other hypercall invoking

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   35 ++
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +-
 arch/powerpc/include/asm/kvm_para.h |   14 ++-
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   52 ++
 arch/powerpc/kernel/epapr_paravirt.c|   61 +++
 arch/powerpc/kernel/kvm.c   |   28 ++-
 arch/powerpc/kernel/kvm_emul.S  |   10 -
 arch/powerpc/kvm/booke.c|6 +++
 arch/powerpc/kvm/powerpc.c  |   14 ++-
 arch/powerpc/platforms/Kconfig  |   10 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 199 insertions(+), 73 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

from the kvm guest paravirt init code.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: misc minor fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v9: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 +++
 arch/powerpc/kernel/epapr_paravirt.c|   52 +++
 arch/powerpc/kernel/kvm.c   |   28 ++---
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |9 +
 7 files changed, 92 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..2173d4c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_paravirt_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ce4f7f1..09011d6 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -134,6 +134,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..028aeae
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,52 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_paravirt_enabled;
+
+static int __init epapr_paravirt_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (!insts)
+   return -ENODEV;
+
+   if (len % 4 || len  (4 * 4))
+   return -ENODEV;
+
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_paravirt_enabled = true;
+
+   return 0;
+}
+
+early_initcall(epapr_paravirt_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 9b6682e..b8a77a1 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -30,6 +30,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 #include asm/machdep.h
 #include asm/mpic.h
 
@@ -739,7 +740,7 @@ unsigned long kvm_hypercall(unsigned long *in,
unsigned long register r11 asm(r11) = nr;
unsigned long register r12 asm(r12);
 
-   asm volatile

[PATCH v9 4/4] KVM: PPC: epapr: Update other hypercall invoking

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Discard the old way that invoke hypercall,
instead, use epapr paravirt.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: kconfig fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v9: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 5 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 78460ac..b95758d 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -189,7 +189,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -218,7 +218,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -248,7 +248,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -273,7 +273,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -301,7 +301,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -340,7 +340,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -379,7 +379,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -417,7 +417,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -450,7 +450,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -474,7 +474,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -494,7 +494,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(bl

[PATCH v9 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v9: pad hcall instruction array with nops

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/kvm_para.h |   14 --
 arch/powerpc/kvm/booke.c|6 ++
 arch/powerpc/kvm/powerpc.c  |   19 ---
 include/linux/kvm.h |2 ++
 5 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index d51df17..b68cb1c 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,3 +34,4 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index b3b4667..5617c8c 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -90,9 +90,19 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index f0ef0be..9fde645 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -593,6 +593,12 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
unsigned int priority;
 
if (vcpu-requests) {
+   /* kvm_vcpu_block() sets KVM_REQ_UNHALT, but it is
+* not cleared elsewhere as on x86.  Clear it here
+* for now, otherwise we never go idle.
+*/
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+
if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
smp_mb();
update_timer_ints(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index ee489f4..2595916 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -48,8 +48,7 @@ static unsigned int perfmon_refcount;
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   bool ret = !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   bool ret = !!(v-arch.pending_exceptions) ||
   v-requests;
 
 #ifdef CONFIG_BOOKE
@@ -100,6 +99,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -888,9 +891,16 @@ out:
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -907,6 +917,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
+
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
 
return 0;
 }
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 28ced78..32b8f54 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -438,6 +438,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /*
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 0/4] KVM: PPC: Add ePAPR idle hcall support

2012-03-07 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

-v9
   -pad hcall instruction array with nops

Liu Yu-B13201 (4):
  KVM: PPC: epapr: Factor out the epapr init
  KVM: PPC: epapr: Add idle hcall support for host
  KVM: PPC: epapr: install ev_idle hcall for e500 guest
  KVM: PPC: epapr: Update other hypercall invoking

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   35 ++
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +-
 arch/powerpc/include/asm/kvm_para.h |   14 ++-
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   52 ++
 arch/powerpc/kernel/epapr_paravirt.c|   61 +++
 arch/powerpc/kernel/kvm.c   |   28 ++-
 arch/powerpc/kernel/kvm_emul.S  |   10 -
 arch/powerpc/kvm/booke.c|6 +++
 arch/powerpc/kvm/powerpc.c  |   19 --
 arch/powerpc/platforms/Kconfig  |   10 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 203 insertions(+), 74 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 3/4] KVM: PPC: epapr: install ev_idle hcall for e500 guest

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---
v9: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   27 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 2173d4c..78460ac 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -108,6 +104,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..bf643ed 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,6 +8,7 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
@@ -15,6 +16,32 @@
 #include asm/ppc_asm.h
 #include asm/asm-offsets.h
 
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+   lwz r4,TI_LOCAL_FLAGS(r3)   /* set napping bit */
+   ori r4,r4,_TLF_NAPPING  /* so when we take an exception */
+   stw r4,TI_LOCAL_FLAGS(r3)   /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] KVM: PPC: epapr: Update other hypercall invoking

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Discard the old way that invoke hypercall,
instead, use epapr paravirt.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: kconfig fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v8: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 5 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 78460ac..b95758d 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -189,7 +189,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -218,7 +218,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -248,7 +248,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -273,7 +273,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -301,7 +301,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -340,7 +340,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -379,7 +379,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -417,7 +417,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -450,7 +450,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -474,7 +474,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -494,7 +494,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile

[PATCH v8 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v8: updated hcall instruction for e500mc to be sc 1

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/kvm_para.h |   14 --
 arch/powerpc/kvm/booke.c|6 ++
 arch/powerpc/kvm/powerpc.c  |   14 --
 include/linux/kvm.h |2 ++
 5 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index d51df17..b68cb1c 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,3 +34,4 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index b3b4667..5617c8c 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -90,9 +90,19 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index f0ef0be..9fde645 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -593,6 +593,12 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
unsigned int priority;
 
if (vcpu-requests) {
+   /* kvm_vcpu_block() sets KVM_REQ_UNHALT, but it is
+* not cleared elsewhere as on x86.  Clear it here
+* for now, otherwise we never go idle.
+*/
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+
if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
smp_mb();
update_timer_ints(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index ee489f4..84e215b 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -48,8 +48,7 @@ static unsigned int perfmon_refcount;
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   bool ret = !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   bool ret = !!(v-arch.pending_exceptions) ||
   v-requests;
 
 #ifdef CONFIG_BOOKE
@@ -100,6 +99,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -888,6 +891,10 @@ out:
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
u32 inst_nop = 0x6000;
@@ -907,6 +914,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
+
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
 
return 0;
 }
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 28ced78..32b8f54 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -438,6 +438,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /*
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

from the kvm guest paravirt init code.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: misc minor fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---

-v8: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 +++
 arch/powerpc/kernel/epapr_paravirt.c|   52 +++
 arch/powerpc/kernel/kvm.c   |   28 ++---
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |9 +
 7 files changed, 92 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..2173d4c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_paravirt_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ce4f7f1..09011d6 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -134,6 +134,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..028aeae
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,52 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_paravirt_enabled;
+
+static int __init epapr_paravirt_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (!insts)
+   return -ENODEV;
+
+   if (len % 4 || len  (4 * 4))
+   return -ENODEV;
+
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_paravirt_enabled = true;
+
+   return 0;
+}
+
+early_initcall(epapr_paravirt_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 9b6682e..b8a77a1 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -30,6 +30,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 #include asm/machdep.h
 #include asm/mpic.h
 
@@ -739,7 +740,7 @@ unsigned long kvm_hypercall(unsigned long *in,
unsigned long register r11 asm(r11) = nr;
unsigned long register r12 asm(r12);
 
-   asm volatile

[PATCH 3/4] KVM: PPC: epapr: install ev_idle hcall for e500 guest

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---

-v8: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   27 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 2173d4c..78460ac 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -108,6 +104,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..bf643ed 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,6 +8,7 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
@@ -15,6 +16,32 @@
 #include asm/ppc_asm.h
 #include asm/asm-offsets.h
 
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+   lwz r4,TI_LOCAL_FLAGS(r3)   /* set napping bit */
+   ori r4,r4,_TLF_NAPPING  /* so when we take an exception */
+   stw r4,TI_LOCAL_FLAGS(r3)   /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

from the kvm guest paravirt init code.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: misc minor fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v9: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 +++
 arch/powerpc/kernel/epapr_paravirt.c|   52 +++
 arch/powerpc/kernel/kvm.c   |   28 ++---
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |9 +
 7 files changed, 92 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..2173d4c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_paravirt_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ce4f7f1..09011d6 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -134,6 +134,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..028aeae
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,52 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_paravirt_enabled;
+
+static int __init epapr_paravirt_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (!insts)
+   return -ENODEV;
+
+   if (len % 4 || len  (4 * 4))
+   return -ENODEV;
+
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_paravirt_enabled = true;
+
+   return 0;
+}
+
+early_initcall(epapr_paravirt_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 9b6682e..b8a77a1 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -30,6 +30,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 #include asm/machdep.h
 #include asm/mpic.h
 
@@ -739,7 +740,7 @@ unsigned long kvm_hypercall(unsigned long *in,
unsigned long register r11 asm(r11) = nr;
unsigned long register r12 asm(r12);
 
-   asm volatile

[PATCH v9 4/4] KVM: PPC: epapr: Update other hypercall invoking

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

Discard the old way that invoke hypercall,
instead, use epapr paravirt.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: kconfig fixes]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
v9: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 arch/powerpc/platforms/Kconfig  |1 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 5 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 78460ac..b95758d 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -189,7 +189,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -218,7 +218,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -248,7 +248,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -273,7 +273,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -301,7 +301,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -340,7 +340,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -379,7 +379,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -417,7 +417,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -450,7 +450,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -474,7 +474,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -494,7 +494,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(bl

[PATCH v9 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v9: pad hcall instruction array with nops

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/kvm_para.h |   14 --
 arch/powerpc/kvm/booke.c|6 ++
 arch/powerpc/kvm/powerpc.c  |   19 ---
 include/linux/kvm.h |2 ++
 5 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index d51df17..b68cb1c 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,3 +34,4 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index b3b4667..5617c8c 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -90,9 +90,19 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index f0ef0be..9fde645 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -593,6 +593,12 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
unsigned int priority;
 
if (vcpu-requests) {
+   /* kvm_vcpu_block() sets KVM_REQ_UNHALT, but it is
+* not cleared elsewhere as on x86.  Clear it here
+* for now, otherwise we never go idle.
+*/
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+
if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
smp_mb();
update_timer_ints(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index ee489f4..2595916 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -48,8 +48,7 @@ static unsigned int perfmon_refcount;
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   bool ret = !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   bool ret = !!(v-arch.pending_exceptions) ||
   v-requests;
 
 #ifdef CONFIG_BOOKE
@@ -100,6 +99,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -888,9 +891,16 @@ out:
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -907,6 +917,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
+
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
 
return 0;
 }
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 28ced78..32b8f54 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -438,6 +438,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /*
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 0/4] KVM: PPC: Add ePAPR idle hcall support

2012-03-07 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

-v9
   -pad hcall instruction array with nops

Liu Yu-B13201 (4):
  KVM: PPC: epapr: Factor out the epapr init
  KVM: PPC: epapr: Add idle hcall support for host
  KVM: PPC: epapr: install ev_idle hcall for e500 guest
  KVM: PPC: epapr: Update other hypercall invoking

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   35 ++
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +-
 arch/powerpc/include/asm/kvm_para.h |   14 ++-
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   52 ++
 arch/powerpc/kernel/epapr_paravirt.c|   61 +++
 arch/powerpc/kernel/kvm.c   |   28 ++-
 arch/powerpc/kernel/kvm_emul.S  |   10 -
 arch/powerpc/kvm/booke.c|6 +++
 arch/powerpc/kvm/powerpc.c  |   19 --
 arch/powerpc/platforms/Kconfig  |   10 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 203 insertions(+), 74 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 3/4] KVM: PPC: epapr: install ev_idle hcall for e500 guest

2012-03-07 Thread Stuart Yoder
From: Liu Yu-B13201 yu@freescale.com

If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---
v9: no changes

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   27 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 2173d4c..78460ac 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -108,6 +104,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..bf643ed 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,6 +8,7 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
@@ -15,6 +16,32 @@
 #include asm/ppc_asm.h
 #include asm/asm-offsets.h
 
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+   lwz r4,TI_LOCAL_FLAGS(r3)   /* set napping bit */
+   ori r4,r4,_TLF_NAPPING  /* so when we take an exception */
+   stw r4,TI_LOCAL_FLAGS(r3)   /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/4 v7] KVM: PPC: Add ePAPR idle hcall support

2012-03-06 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

-version 7 of this patchset

-version 7 changes
  KVM: PPC: epapr: Factor out the epapr init
  -used ENODEV return code in epapr_paravirt_init
  -improved error checkign logic as per review comments
  -fixed spelling errors
  KVM: PPC: epapr: Add idle hcall support for host
  -removed WE check from check if vcpu is runnable
  -clear KVM_REQ_UNHALT, which prevented guest from
   going idle.  This bit was set in common code, but never
   cleared on PPC.
  KVM: PPC: epapr: Update other hypercall invoking
  -updated Kconfig for byte-channel and vmpic hcalls

Liu Yu-B13201 (4):
  KVM: PPC: epapr: Factor out the epapr init
  KVM: PPC: epapr: Add idle hcall support for host
  KVM: PPC: epapr: install ev_idle hcall for e500 guest
  KVM: PPC: epapr: Update other hypercall invoking

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   35 ++
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +-
 arch/powerpc/include/asm/kvm_para.h |   14 ++-
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   52 ++
 arch/powerpc/kernel/epapr_paravirt.c|   61 +++
 arch/powerpc/kernel/kvm.c   |   28 ++-
 arch/powerpc/kernel/kvm_emul.S  |   10 -
 arch/powerpc/kvm/booke.c|6 +++
 arch/powerpc/kvm/powerpc.c  |9 -
 arch/powerpc/platforms/Kconfig  |   10 +
 drivers/tty/Kconfig |1 +
 drivers/virt/Kconfig|1 +
 include/linux/kvm.h |2 +
 15 files changed, 194 insertions(+), 73 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

-- 
1.7.3.4


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   >