From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: Thomas Huth <thuth@redhat.com>
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
Alexander Graf <agraf@suse.de>,
qemu-devel@nongnu.org,
Alex Williamson <alex.williamson@redhat.com>,
qemu-ppc@nongnu.org, Gavin Shan <gwshan@linux.vnet.ibm.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [PATCH qemu v6 07/15] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering)
Date: Fri, 24 Apr 2015 15:55:34 +1000 [thread overview]
Message-ID: <5539DAD6.4010504@ozlabs.ru> (raw)
In-Reply-To: <20150416120727.3a823a40@thh440s>
On 04/16/2015 08:07 PM, Thomas Huth wrote:
> Am Sat, 11 Apr 2015 01:24:36 +1000
> schrieb Alexey Kardashevskiy <aik@ozlabs.ru>:
>
>> This makes use of the new "memory registering" feature. The idea is
>> to provide the userspace ability to notify the host kernel about pages
>> which are going to be used for DMA. Having this information, the host
>> kernel can pin them all once per user process, do locked pages
>> accounting (once) and not spent time on doing that in real time with
>> possible failures which cannot be handled nicely in some cases.
>>
>> This adds a guest RAM memory listener which notifies a VFIO container
>> about memory which needs to be pinned/unpinned. VFIO MMIO regions
>> (i.e. "skip dump" regions) are skipped.
>>
>> The feature is only enabled for SPAPR IOMMU v2. The host kernel changes
>> are required. Since v2 does not need/support VFIO_IOMMU_ENABLE, this does
>> not call it when v2 is detected and enabled.
>>
>> This does not change the guest visible interface.
>>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> ---
>> Changes:
>> v6:
>> * fixed commit log (s/guest/userspace/), added note about no guest visible
>> change
>> * fixed error checking if ram registration failed
>> * added alignment check for section->offset_within_region
>>
>> v5:
>> * simplified the patch
>> * added trace points
>> * added round_up() for the size
>> * SPAPR IOMMU v2 used
>> ---
>> hw/vfio/common.c | 26 +++++++++----
>> hw/vfio/spapr.c | 88 ++++++++++++++++++++++++++++++++++++++++++-
>> include/hw/vfio/vfio-common.h | 5 ++-
>> trace-events | 1 +
>> 4 files changed, 109 insertions(+), 11 deletions(-)
> [...]
>> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
>> index 5f79194..31353f1 100644
>> --- a/hw/vfio/spapr.c
>> +++ b/hw/vfio/spapr.c
>> @@ -17,6 +17,9 @@
>> * along with this program; if not, see <http://www.gnu.org/licenses/>.
>> */
>>
>> +#include <sys/ioctl.h>
>> +#include <linux/vfio.h>
>> +
>> #include "hw/vfio/vfio-common.h"
>> #include "qemu/error-report.h"
>> #include "trace.h"
>> @@ -211,16 +214,97 @@ static const MemoryListener vfio_spapr_memory_listener = {
>> .region_del = vfio_spapr_listener_region_del,
>> };
>>
>> +static void vfio_ram_do_region(VFIOContainer *container,
>> + MemoryRegionSection *section, unsigned long req)
>> +{
>> + int ret;
>> + struct vfio_iommu_spapr_register_memory reg = { .argsz = sizeof(reg) };
>> +
>> + if (!memory_region_is_ram(section->mr) ||
>> + memory_region_is_skip_dump(section->mr)) {
>> + return;
>> + }
>> +
>> + if (unlikely((section->offset_within_region & (getpagesize() - 1)))) {
>> + error_report("%s received unaligned region", __func__);
>> + return;
>> + }
>> +
>> + reg.vaddr = (__u64) memory_region_get_ram_ptr(section->mr) +
>> + section->offset_within_region;
>> + reg.size = ROUND_UP(int128_get64(section->size), TARGET_PAGE_SIZE);
>> +
>> + ret = ioctl(container->fd, req, ®);
>> + trace_vfio_ram_register(_IOC_NR(req) - VFIO_BASE, reg.vaddr, reg.size,
>> + ret ? -errno : 0);
>> + if (!ret) {
>
> Since this function does not return an error code (maybe it should?),
It is called from listener callbacks which do not return codes.
> would it
> make sense to print out at least an error message here that something went wrong?
> (most people won't have the tracing enabled, so the error might go unnoticed otherwise)
!ret means ret==0 which means "good". The error case handling is few lines
below and it won't go unnoticed.
>
>> + return;
>> + }
>> +
>> + /*
>> + * On the initfn path, store the first error in the container so we
>> + * can gracefully fail. Runtime, there's not much we can do other
>> + * than throw a hardware error.
>> + */
>> + if (!container->iommu_data.spapr.ram_reg_initialized) {
>> + if (!container->iommu_data.spapr.ram_reg_error) {
>> + container->iommu_data.spapr.ram_reg_error = -errno;
>> + }
>> + } else {
>> + hw_error("vfio: RAM registering failed, unable to continue");
>> + }
>> +}
>
> Thomas
>
--
Alexey
next prev parent reply other threads:[~2015-04-24 5:56 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-10 15:24 [Qemu-devel] [PATCH qemu v6 00/15] spapr: vfio: Enable Dynamic DMA windows (DDW) Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 01/15] linux headers update for DDW on SPAPR Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 02/15] vmstate: Define VARRAY with VMS_ALLOC Alexey Kardashevskiy
2015-04-15 3:47 ` David Gibson
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 03/15] spapr_pci: Make find_phb()/find_dev() public Alexey Kardashevskiy
2015-04-21 20:44 ` Michael Roth
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 04/15] vfio: spapr: Move SPAPR-related code to a separate file Alexey Kardashevskiy
2015-04-16 7:50 ` Thomas Huth
2015-04-16 16:27 ` Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 05/15] spapr_pci_vfio: Enable multiple groups per container Alexey Kardashevskiy
2015-04-22 5:34 ` David Gibson
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 06/15] spapr_pci: Convert finish_realize() to dma_capabilities_update()+dma_init_window() Alexey Kardashevskiy
2015-04-22 5:39 ` David Gibson
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 07/15] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering) Alexey Kardashevskiy
2015-04-16 10:07 ` Thomas Huth
2015-04-24 5:55 ` Alexey Kardashevskiy [this message]
2015-04-22 5:53 ` David Gibson
2015-04-22 9:38 ` Alexey Kardashevskiy
2015-04-29 5:58 ` David Gibson
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 08/15] spapr_iommu: Introduce "enabled" state for TCE table Alexey Kardashevskiy
2015-04-16 10:59 ` Thomas Huth
2015-04-22 6:14 ` David Gibson
2015-04-22 9:10 ` Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 09/15] spapr_iommu: Add root memory region Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 10/15] spapr_pci_vfio: Remove unnecessary cast to sPAPRPHBVFIOState Alexey Kardashevskiy
2015-04-16 10:31 ` Thomas Huth
2015-04-17 1:55 ` Alexey Kardashevskiy
2015-04-22 6:33 ` David Gibson
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 11/15] spapr_pci: Do complete reset of DMA config when resetting PHB Alexey Kardashevskiy
2015-04-22 6:39 ` David Gibson
2015-04-22 9:17 ` Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 12/15] spapr_vfio_pci: Remove redundant spapr-pci-vfio-host-bridge Alexey Kardashevskiy
2015-04-22 6:47 ` David Gibson
2015-04-22 9:06 ` Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 13/15] spapr: Add pseries-2.4 machine Alexey Kardashevskiy
2015-04-22 6:48 ` David Gibson
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 14/15] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) Alexey Kardashevskiy
2015-04-10 15:24 ` [Qemu-devel] [PATCH qemu v6 15/15] vfio: Enable DDW ioctls to VFIO IOMMU driver Alexey Kardashevskiy
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=5539DAD6.4010504@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=agraf@suse.de \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=gwshan@linux.vnet.ibm.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).