public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Wei Hu <wei.hoo@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: Correct way to enable BusMaster with VFIO?
Date: Wed, 08 Apr 2015 09:17:29 -0600	[thread overview]
Message-ID: <1428506249.5567.483.camel@redhat.com> (raw)
In-Reply-To: <CACzySHTbtUWzw1jjTgY0pUSrTL7HV5w=cfXFc88j2nQek0QEzw@mail.gmail.com>

Hi Wei,

On Tue, 2015-04-07 at 21:02 -0700, Wei Hu wrote:
> Hi Alex,
> 
> With your change "Release devices with BusMaster disabled", I've found
> that my VFIO device driver is no longer receiving MSI interrupts.
> After reviewing the code I think it makes sense. But I had two
> questions below while debugging my issue.
> 
> 1.  If I had set the bus master bit in the command register by hand
> before opening the vfio device, the kernel would actually leave
> BusMaster enabled. This seems to contradict the call to
> pci_clear_master() from vfio_pci_enable(). What's going on here, is
> something else enabling BusMaster?

I don't see this behavior.  If I use a test program that simply opens
the vfio group, configures the IOMMU container and gets a device file
descriptor, BusMaster is clear at that point regardless of whether the
device has it enabled or disabled beforehand.  Are you perhaps attaching
bridges to vfio-pci and the bridge is getting enabled as part of the
pci_enable_device() call of the endpoint?  Newer versions of vfio-pci
won't allow binding bridges, it was a bug that it was ever allowed.  Our
config space manipulation only knows about normal header types.

> 2. What's the recommended way to enable BusMaster with your change
> now? Should my driver map the config space region and set the
> BusMaster bit? Or should I have a separate command to enable the bit
> before opening the device?

VFIO is designed to be a complete interface to the device, why would you
write a driver that makes use of VFIO that has pre-conditions of
manipulating the device state outside of VFIO?  There's no additional
mapping of config space required, you already have access to it through
the device file descriptor.  It should simply be a matter of doing a
read-modify-write at the proper offset to toggle the command register.
QEMU uses pread(2) and pwrite(2) for this, but any equivalent tool
should work as well.  Thanks,

Alex


  reply	other threads:[~2015-04-08 15:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08  4:02 Correct way to enable BusMaster with VFIO? Wei Hu
2015-04-08 15:17 ` Alex Williamson [this message]
2015-04-08 16:45   ` Wei Hu
2015-04-08 17:31     ` Alex Williamson
2015-04-08 17:50       ` Wei Hu

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=1428506249.5567.483.camel@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=wei.hoo@gmail.com \
    /path/to/YOUR_REPLY

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

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