From nobody Sat Feb 7 06:21:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603214695; cv=none; d=zohomail.com; s=zohoarc; b=iYyvZ4guQL3v7EjXQGJmE7OIW06M9wYidTmw5NyzX7f4EzPKTeUcO8ES21BJf8LRaonf//y/8AvbNiIewoKjErAV0mZNLqQp9SO06iMpKFxMHIi32GK48+wxv8V2SUopT4FZ2RK99FDPhz2ObJ9SUJfA6cUmDt1qkhsBmJKRsKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603214695; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=5tWL17xtY4KbK/NCVI9WhU1DjcEuaI56sUEhUSi0l/w=; b=WWl4j6pDCEzBC4ahZEO7x1bRVgOZ5bHN1tSAqR/0oLE8AjOFSHydzaC1rNG63usLKL1L1vVWT8KQNMxtA96dfRmgUL6kk+jxPrtpC0QqfQjVB1ccxDX21kITIzZRth1vV5ZNyCpWjTeq/kIRuJJgka/jEdc/koPFy2wLpl2ZEEE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603214695074747.0986728869351; Tue, 20 Oct 2020 10:24:55 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-3cVD_lriMZqMZv1VFbpXTA-1; Tue, 20 Oct 2020 13:24:52 -0400 Received: by mail-wr1-f70.google.com with SMTP id p6so1060729wrm.23 for ; Tue, 20 Oct 2020 10:24:52 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id m14sm4058942wro.43.2020.10.20.10.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 10:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603214694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5tWL17xtY4KbK/NCVI9WhU1DjcEuaI56sUEhUSi0l/w=; b=TM6uwLGgfqAWtejAChftcW5omGrXfUZJoFRvQhfhzF1AAcwAlfAZUKFqMV9MmY5K+4Z4E0 txBOWO9Y0G2EUClap5/A8OdKEm2ga6C2+wjbaji5TkEbsiEsw5aEA9vVA/MUCo3wRdheG7 jRAcxLoV81VBa93gAnT4hlm88QJBaJE= X-MC-Unique: 3cVD_lriMZqMZv1VFbpXTA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5tWL17xtY4KbK/NCVI9WhU1DjcEuaI56sUEhUSi0l/w=; b=uSqEwFY7uSYTWM2l8WcG/3r2v59NukyyuueUOd3ydsbAtvGzbBppR0PsLHTvaL2xND d9CC2gvzgJw7NAsEayjfXYWrI9iTbrH4pfLTidjGEZMeYFIc6T8z+C5z7F/UdPKrEfU8 1S8QuhI1opkJR6aK0jMZH5KxJ8CdqeuIMuvJ6RQoy12qG8AGsudLkIkf+UEXRB8pPjbb 5VzxuEVFOKHFacGWvmI63EW7R2ioDdIEwjpqhfXPiANfbEVQWMUuyL9XIqGZvBv8CXSW BDbLCp7pP+Q6OGiO4oj+LfhHfO/4btCxo3EaaMQLTU+58muoNF/fIiVYlm4C5A1HJKai tCgg== X-Gm-Message-State: AOAM533uFirtREEg5e5gh3UhFV652C+XaQA5qhqs4t0lxKN0seVONyh3 ZogXq6W5wVmasH4NYObk8CHDX8cVK+E+8IRdz3qk9u8jCQdsAeZ84SoaMdnwGhmg6+wfWBrgRyh VGixR6km5knDqPA== X-Received: by 2002:a5d:5387:: with SMTP id d7mr4648724wrv.224.1603214691182; Tue, 20 Oct 2020 10:24:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkr2NnhtZ8sFt+k39xD3IYZ6ad+P3a32ER6vfyb6CzWdVkw0gV8yUx+9GGe9yOoaqE3Eabfg== X-Received: by 2002:a5d:5387:: with SMTP id d7mr4648699wrv.224.1603214690988; Tue, 20 Oct 2020 10:24:50 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Alex Williamson , Stefan Hajnoczi , Max Reitz , Fam Zheng , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 04/16] util/vfio-helpers: Report error when IOMMU page size is not supported Date: Tue, 20 Oct 2020 19:24:16 +0200 Message-Id: <20201020172428.2220726-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201020172428.2220726-1-philmd@redhat.com> References: <20201020172428.2220726-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) This driver uses the host page size to align its memory regions, but this size is not always compatible with the IOMMU. Add a check if the size matches, and bails out providing a hint what is the minimum page size the driver should use. Suggested-by: Alex Williamson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- util/vfio-helpers.c | 28 ++++++++++++++++++++++++++-- util/trace-events | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index a2b084c69c1..bce2cdb2f3c 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -11,6 +11,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" #include #include #include "qapi/error.h" @@ -273,7 +274,7 @@ static void collect_usable_iova_ranges(QEMUVFIOState *s= , void *buf) } =20 static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device, - Error **errp) + size_t *requested_page_size, Error **errp) { int ret; int i; @@ -284,6 +285,8 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const c= har *device, struct vfio_device_info device_info =3D { .argsz =3D sizeof(device_inf= o) }; char *group_file =3D NULL; =20 + assert(requested_page_size && is_power_of_2(*requested_page_size)); + s->usable_iova_ranges =3D NULL; =20 /* Create a new container */ @@ -358,6 +361,27 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const = char *device, ret =3D -errno; goto fail; } + if (!(iommu_info->flags & VFIO_IOMMU_INFO_PGSIZES)) { + error_setg(errp, "Failed to get IOMMU page size info"); + ret =3D -EINVAL; + goto fail; + } + trace_qemu_vfio_iommu_iova_pgsizes(iommu_info->iova_pgsizes); + if (!(iommu_info->iova_pgsizes & *requested_page_size)) { + g_autofree char *req_page_size_str =3D size_to_str(*requested_page= _size); + g_autofree char *min_page_size_str =3D NULL; + uint64_t pgsizes_masked; + + pgsizes_masked =3D MAKE_64BIT_MASK(0, ctz64(*requested_page_size)); + *requested_page_size =3D 1U << ctz64(iommu_info->iova_pgsizes + & ~pgsizes_masked); + min_page_size_str =3D size_to_str(*requested_page_size); + error_setg(errp, "Unsupported IOMMU page size: %s", req_page_size_= str); + error_append_hint(errp, "Minimum IOMMU page size: %s\n", + min_page_size_str); + ret =3D -EINVAL; + goto fail; + } =20 /* * if the kernel does not report usable IOVA regions, choose @@ -500,7 +524,7 @@ QEMUVFIOState *qemu_vfio_open_pci(const char *device, s= ize_t *min_page_size, int r; QEMUVFIOState *s =3D g_new0(QEMUVFIOState, 1); =20 - r =3D qemu_vfio_init_pci(s, device, errp); + r =3D qemu_vfio_init_pci(s, device, min_page_size, errp); if (r) { g_free(s); return NULL; diff --git a/util/trace-events b/util/trace-events index 24c31803b01..19f03f14a33 100644 --- a/util/trace-events +++ b/util/trace-events @@ -85,3 +85,4 @@ qemu_vfio_new_mapping(void *s, void *host, size_t size, i= nt index, uint64_t iova qemu_vfio_do_mapping(void *s, void *host, size_t size, uint64_t iova) "s %= p host %p size 0x%zx iova 0x%"PRIx64 qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64= _t *iova) "s %p host %p size 0x%zx temporary %d iova %p" qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p" +qemu_vfio_iommu_iova_pgsizes(uint64_t iova_pgsizes) "iommu page size bitma= sk: 0x%08"PRIx64 --=20 2.26.2