From nobody Mon Feb 9 21:38:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1599661451; cv=none; d=zohomail.com; s=zohoarc; b=WfOpRmat1gWVwkIICn55cLQFhAw+v2kgE6J2HVV6BsaCr06PqW52eLzoPSvcRKyld+gYk+fLhM71QA4g3P+Hr3oKBqFXOspw44Qfs12VzU72gxjXOc12a//P2cKmj4z9KdLEEaSIJUdKTy9e8MP+tf+ICEClbOumJIcQJahQph4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599661451; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=raP/5IjyHL4k0lzw1JuIvnOdpYCQNl82Msw0GzdIoBQ=; b=iPjE3xUg+ANtjnVIBg3GRlBX6jX9VjY/R3X2ULX+fBf4hy1VMN3WxtVR1OceH3dH8nm0Gw1jS3Qj2wrJwAqzwPJKJn9m4K/Zpv+cTThsq1ojXrhfuH4Ge9u92iQMi7lDVEg6DCwF24DzO9ovP6nlJuedFnyk49NtxuFQ3wn6eRE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599661451638337.1178896046905; Wed, 9 Sep 2020 07:24:11 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-6rpiZyOUNuOSuXtX1IcyhA-1; Wed, 09 Sep 2020 10:24:07 -0400 Received: by mail-wr1-f71.google.com with SMTP id a10so1012672wrw.22 for ; Wed, 09 Sep 2020 07:24:07 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id k8sm4388721wma.16.2020.09.09.07.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 07:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599661450; 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=raP/5IjyHL4k0lzw1JuIvnOdpYCQNl82Msw0GzdIoBQ=; b=XiKAMigUy6i4DC91dtNjiJI/9HZrWekmhbb8TZrv8RsHK4rE2YpjUULoxfQQqsAatWqnDN RkRDIPJPnpmrEvS+flBRlf6XLxK7POhfKf2oS4k6N98/o67LrN2RCaa+QTwRAAv0cdeNWD 3qhz6VpRD7QBR/bm/gV3IUMiRVOtoRU= X-MC-Unique: 6rpiZyOUNuOSuXtX1IcyhA-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=raP/5IjyHL4k0lzw1JuIvnOdpYCQNl82Msw0GzdIoBQ=; b=SDRBYp+e8NIyHsNgCuD17Y0TaSS6SCzot9O9ck9IMDoiou2fJLnsPaZXf3WayG6i8Y nlRKq4IsDrie5V/81PsOdZKkW9bhLsdJCc36Zf6irwHg4ufUotzT8JnB+fYbzzbaIdAb 7vI2SLLbwA5vQ+tRBGj6ihgO/g3o010JbIkeBMmbEaapJbLPu9Lxg0IGkLEEBHNv/kmS 1VHYccD2yAF/lRH9e4+M+Kqxt6qh9ptkGBqDIISQX9ZP158cRCOdDIOSgr1AM4fY8PdY y/E8pQaXHc/M+geHrhR2BE44Fd9ug9KTCf2TXUTPvXLOgLViTkvVahPCPc7XmQnWVn6m eLew== X-Gm-Message-State: AOAM5301eRQQK6tzcMisDYORDOrG9ZkFMMr6mhCfUTLB5DMEC818lfBx erH5ngPmasdFARiQsKcHuur5DXMdjvhwbiAfZdaf6UJSN8uaEg6x5mdU7LPwY+jHMAkoeuUkGVs A9p4BvdctSAXDCA== X-Received: by 2002:adf:ec87:: with SMTP id z7mr4474427wrn.57.1599661446653; Wed, 09 Sep 2020 07:24:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaNfNrnJUOLCzWyQWlZEF+O41lcTg3EHiH9WT43krXGSQu9NVvkkCw5phaI2FWTa4XDKaOxg== X-Received: by 2002:adf:ec87:: with SMTP id z7mr4474410wrn.57.1599661446463; Wed, 09 Sep 2020 07:24:06 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Max Reitz , qemu-block@nongnu.org, Kevin Wolf , Fam Zheng , Alex Williamson , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 2/4] util/vfio-helpers: Report error when IOMMU page size is not supported Date: Wed, 9 Sep 2020 16:23:52 +0200 Message-Id: <20200909142354.334859-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200909142354.334859-1-philmd@redhat.com> References: <20200909142354.334859-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.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; 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 with listing the sizes the IOMMU supports. Example on Aarch64: $ qemu-system-aarch64 -M virt -drive if=3Dnone,id=3Dnvme0,file=3Dnvme://00= 06:90:00.0/1,format=3Draw qemu-system-aarch64: -drive if=3Dnone,id=3Dnvme0,file=3Dnvme://0006:90:00.= 0/1,format=3Draw: Unsupported IOMMU page size: 4 KiB Available page size: 64 KiB 512 MiB Suggested-by: Alex Williamson Reviewed-by: Fam Zheng Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- util/vfio-helpers.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 55b4107ce69..4cc5697dcb2 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" @@ -316,6 +317,25 @@ 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; + } + if (!extract64(iommu_info.iova_pgsizes, + ctz64(qemu_real_host_page_size), 1)) { + g_autofree char *host_page_size =3D size_to_str(qemu_real_host_pag= e_size); + error_setg(errp, "Unsupported IOMMU page size: %s", host_page_size= ); + error_append_hint(errp, "Available page size:\n"); + for (int i =3D 0; i < 64; i++) { + if (extract64(iommu_info.iova_pgsizes, i, 1)) { + g_autofree char *iova_pgsizes =3D size_to_str(1UL << i); + error_append_hint(errp, " %s\n", iova_pgsizes); + } + } + ret =3D -EINVAL; + goto fail; + } =20 s->device =3D ioctl(s->group, VFIO_GROUP_GET_DEVICE_FD, device); =20 --=20 2.26.2