From nobody Sat May 4 14:00:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1599661445; cv=none; d=zohomail.com; s=zohoarc; b=l2O+qDynS1qmZ5W0s05ismnVYPLt2fFxhWMy9BIPf9KSITT9j1pOs0vhEL0pjJKFTjH+6w5w5fh7V1QdSLGb5Iz4I8qibCI0Zl3imr9BtCNVniG9nxZVBqS+Y7OTi4+so9GAG46c7y8bc5K4VE9gPTzdRD+cls6Eh7coQw29DaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599661445; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XveAq6dKRegNYH6qGpDAxuD8T7S7WZA4o4LfFGLZC+A=; b=WifzsWZmnY7bX6HRuFkIz6CE849QwMsSCQQDNwRGBjqRFoeV4D3hZMTHh2Pev1zkA/YyXlws4MeaCFSwH0kYGHQd7qHZ3ex9TchA8dkVZB7rdZ6yvAg7YIpJ3CNrGtgpQRENmezqU/dJfKbSY1nHZOiov0dAQtGVKwrs0ktY+fw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599661445892468.9300226363405; Wed, 9 Sep 2020 07:24:05 -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-151-B23BMuvmPJC97RTFesIQyQ-1; Wed, 09 Sep 2020 10:24:02 -0400 Received: by mail-wr1-f71.google.com with SMTP id n15so1015242wrv.23 for ; Wed, 09 Sep 2020 07:24:02 -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 p3sm3996274wmm.40.2020.09.09.07.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 07:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599661444; 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=XveAq6dKRegNYH6qGpDAxuD8T7S7WZA4o4LfFGLZC+A=; b=be7m1XTXMEzPPYeSsw57j0+kMW03DKDJMokshxWM22gXP6+lYaEk/NA6i7SbrVzWS3ii3B ULVV6K1ZrlQzTgWI7jwIboI66unsBbi6EKzKifQphmPOG/mz5MrxDsizDidWDZx1SvEqNf aNg92a1N9tuiEKfRZzefUiOutIL26Mg= X-MC-Unique: B23BMuvmPJC97RTFesIQyQ-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=XveAq6dKRegNYH6qGpDAxuD8T7S7WZA4o4LfFGLZC+A=; b=DPaKriMrjYg0+TYANcaiF6bw0+Fh8HKnCRpZ/qh+AEGS77vs5zwypuSwqLNw+XKOyj yKOo4mB1N+qUsmzw2+tMzOkRe0KrlyCSeJ1b/tVOOzSwwI3aigrrqziC2AaTmNcPjvOU uTB0B5ucBrcX4TwnwnDKQxWScuBMG5xkVW1/p5IY7r/+uDwTmC4mhUVBCuuF9UhxpAfb t6bwZJGmumwCI/reCI58pa5cn8ZZAHS7lU7u1OimP9w70PK3SfjEsd7cm7al27DRZb2a +evRVcgnKz3r/ow1O066MgDO54e8mSxzBMd7v/vjCiUy4Jv/H8FVJQ46hw83XHXrI3Co tAAw== X-Gm-Message-State: AOAM532hppXiSLiHIpweqQ4Ro6ly9i3zDdaYAIcjUWZ1a6FTq+wkB43t M2OitMuUEajH9kUvKhWnsJ51UmB4FHy/mD9H7gML+hPTy7/RXbK+h4sSQ+ox0LLIXQ8mUIjnKzb WqIk4W+aMk/ZLbw== X-Received: by 2002:a5d:6551:: with SMTP id z17mr4291185wrv.200.1599661441667; Wed, 09 Sep 2020 07:24:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3FEHScspgccwbCDzV4fWJUTuSOhYcB6BMl1A1rL9E6LZXgx+zpH5y2bLOShSE7qqnxgzSzg== X-Received: by 2002:a5d:6551:: with SMTP id z17mr4291165wrv.200.1599661441449; Wed, 09 Sep 2020 07:24:01 -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 1/4] util/vfio-helpers: Improve reporting unsupported IOMMU type Date: Wed, 9 Sep 2020 16:23:51 +0200 Message-Id: <20200909142354.334859-2-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) Change the confuse "VFIO IOMMU check failed" error message by the explicit "VFIO IOMMU Type1 is not supported" once. Example on POWER: $ qemu-system-ppc64 -drive if=3Dnone,id=3Dnvme0,file=3Dnvme://0001:01:00.0= /1,format=3Draw qemu-system-ppc64: -drive if=3Dnone,id=3Dnvme0,file=3Dnvme://0001:01:00.0/= 1,format=3Draw: VFIO IOMMU Type1 is not supported Suggested-by: Alex Williamson Reviewed-by: Fam Zheng Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- util/vfio-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 583bdfb36fc..55b4107ce69 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -261,7 +261,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const c= har *device, } =20 if (!ioctl(s->container, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) { - error_setg_errno(errp, errno, "VFIO IOMMU check failed"); + error_setg_errno(errp, errno, "VFIO IOMMU Type1 is not supported"); ret =3D -EINVAL; goto fail_container; } --=20 2.26.2 From nobody Sat May 4 14:00:26 2024 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 From nobody Sat May 4 14:00:26 2024 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=1599661455; cv=none; d=zohomail.com; s=zohoarc; b=kyEQ8i+wwPZPwdgHSzESoGS1QWe1q8iBBR6Y8mEyiA5xYMJmyrv0JjWSS1qsMpBmvv0CrUg7WnF6kwYh/slL6XeV6Wyva6XcgCHyUeaxaRHWUJVbVFxYe/RnzLcZLvbBpaxzPRNa4aUNVW8tH3zbtYpag98KGjTpUSBHxlL6EBk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599661455; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=PSnNVE3NZlz5gegrFx1Hb/kijSce9zFnCVUjF03h6sQ=; b=I4rg8npmnPPtZkay6c35gKTqNeGbrPr14wUrdMnHse9o4PUaOmzdDF6oFa3EcERX/zqgXxxy+V9GaiQo7eVey08oJR0WERebdejivIXD25xTJophgLQRjdt/p//YMQ8krZts7koynfwLF2rCb7JMhHskabKsAxabCqKVRSWfDT8= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599661455641394.057195903639; Wed, 9 Sep 2020 07:24:15 -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-111-rWjKstrJPdykbSE2lLvOdw-1; Wed, 09 Sep 2020 10:24:12 -0400 Received: by mail-wr1-f71.google.com with SMTP id l9so1016520wrq.20 for ; Wed, 09 Sep 2020 07:24:12 -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 a85sm4404267wmd.26.2020.09.09.07.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 07:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599661454; 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=PSnNVE3NZlz5gegrFx1Hb/kijSce9zFnCVUjF03h6sQ=; b=LWaN4ZSMmSxnj6CBWkNHsBxSg+zmAGGlVdqU76LPG9w1JU/9WMdW5O4wcrE4NahVN4ec5s mkYRcYlrn1qx6I95IpIhEUbZ8Cq2M2dmTJCFRfjHFyG2/S5mZP5shV15vN9BmlokrmOi70 hhZhsEXc6BT3yc6735Ve+JL0fCLIxhM= X-MC-Unique: rWjKstrJPdykbSE2lLvOdw-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=PSnNVE3NZlz5gegrFx1Hb/kijSce9zFnCVUjF03h6sQ=; b=SV4uR6s7KzI6Na5ii4Fx1UUDb7MMxRyUFcxPD0l8rDSrjo+cku+VEs2DI4vdEimxJf c1+pajsbmsheVIjsnYwA7YPEf8CFihqKf2715GU9qAu03MND7dxUNULNbPGLa0wo0fZ5 C0LenUg1jmn/uCe+2KCKRfAcsnOAG+Gy9pw0ojI9RNHU6rEHv/WT/d2YiHmFveFjT8Xi aAGSWUVtREyfQ9Xiq7A8Y+ytl7yxJbPR03DiY8nX6aCk9ExCH1stgdRL3bvxu99YLjsv IAWASeHn+iwN3pcsCtN0AL0OixgW5vvZXpPlEi3CXAHeHuDQ9ck6byQDRztQS02Xb+k1 +/cA== X-Gm-Message-State: AOAM531ZCK3xmONqMOEhcvOX67GM5Ilrhfu5e1ITSconn6YzXyEeqJMy 5oqrrdSpn0uecq9eud3ZxpFPAMfsw2cOhyMHOU6ghWTu86ChuOUKuCCkr3X30XUICYNBaoE5mL5 WTp6vHglUSMqX8A== X-Received: by 2002:a1c:2d85:: with SMTP id t127mr3838704wmt.22.1599661451560; Wed, 09 Sep 2020 07:24:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKp0ifME2A9FwhcPA5Sliz011v1Vm6kGX+4Y22yWYAqMvtENk9OK3lhqZ+Thfd3z0oar9OSg== X-Received: by 2002:a1c:2d85:: with SMTP id t127mr3838681wmt.22.1599661451303; Wed, 09 Sep 2020 07:24:11 -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 3/4] util/vfio-helpers: Introduce qemu_vfio_pci_init_msix_irqs() Date: Wed, 9 Sep 2020 16:23:53 +0200 Message-Id: <20200909142354.334859-4-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.003 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) qemu_vfio_pci_init_irq() allows us to initialize any type of IRQ, but only one. Introduce qemu_vfio_pci_init_msix_irqs() which is specific to MSIX IRQ type, and allow us to use multiple IRQs (thus passing multiple eventfd notifiers). Reviewed-by: Fam Zheng Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/vfio-helpers.h | 6 +++- util/vfio-helpers.c | 65 ++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h index 1f057c2b9e4..092b7b243f9 100644 --- a/include/qemu/vfio-helpers.h +++ b/include/qemu/vfio-helpers.h @@ -1,11 +1,13 @@ /* * QEMU VFIO helpers * - * Copyright 2016 - 2018 Red Hat, Inc. + * Copyright 2016 - 2020 Red Hat, Inc. * * Authors: * Fam Zheng + * Philippe Mathieu-Daud=C3=A9 * + * SPDX-License-Identifier: GPL-2.0-or-later * This work is licensed under the terms of the GNU GPL, version 2 or late= r. * See the COPYING file in the top-level directory. */ @@ -28,5 +30,7 @@ void qemu_vfio_pci_unmap_bar(QEMUVFIOState *s, int index,= void *bar, uint64_t offset, uint64_t size); int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotifier *e, int irq_type, Error **errp); +int qemu_vfio_pci_init_msix_irqs(QEMUVFIOState *s, EventNotifier *e, + unsigned *irq_count, Error **errp); =20 #endif diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 4cc5697dcb2..3b1b81caf8b 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -1,11 +1,13 @@ /* * VFIO utility * - * Copyright 2016 - 2018 Red Hat, Inc. + * Copyright 2016 - 2020 Red Hat, Inc. * * Authors: * Fam Zheng + * Philippe Mathieu-Daud=C3=A9 * + * SPDX-License-Identifier: GPL-2.0-or-later * This work is licensed under the terms of the GNU GPL, version 2 or late= r. * See the COPYING file in the top-level directory. */ @@ -216,6 +218,67 @@ int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNoti= fier *e, return 0; } =20 +/** + * Initialize device MSIX IRQs and register event notifiers. + * @irq_count: pointer to number of MSIX IRQs to initialize + * @notifier: Array of @irq_count notifiers (each corresponding to a MSIX = IRQ) + + * If the number of IRQs requested exceeds the available on the device, + * store the number of available IRQs in @irq_count and return -EOVERFLOW. + */ +int qemu_vfio_pci_init_msix_irqs(QEMUVFIOState *s, EventNotifier *notifier, + unsigned *irq_count, Error **errp) +{ + int r; + size_t irq_set_size; + struct vfio_irq_set *irq_set; + struct vfio_irq_info irq_info =3D { + .argsz =3D sizeof(irq_info), + .index =3D VFIO_PCI_MSIX_IRQ_INDEX + }; + + if (ioctl(s->device, VFIO_DEVICE_GET_IRQ_INFO, &irq_info)) { + error_setg_errno(errp, errno, "Failed to get device interrupt info= "); + return -errno; + } + if (irq_info.count < *irq_count) { + error_setg(errp, "Not enough device interrupts available"); + *irq_count =3D irq_info.count; + return -EOVERFLOW; + } + if (!(irq_info.flags & VFIO_IRQ_INFO_EVENTFD)) { + error_setg(errp, "Device interrupt doesn't support eventfd"); + return -EINVAL; + } + + irq_set_size =3D sizeof(*irq_set) + *irq_count * sizeof(int32_t); + irq_set =3D g_malloc0(irq_set_size); + + /* Get to a known IRQ state */ + *irq_set =3D (struct vfio_irq_set) { + .argsz =3D irq_set_size, + .flags =3D VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER, + .index =3D irq_info.index, + .start =3D 0, + .count =3D *irq_count, + }; + + for (unsigned i =3D 0; i < *irq_count; i++) { + ((int32_t *)&irq_set->data)[i] =3D event_notifier_get_fd(¬ifier= [i]); + } + r =3D ioctl(s->device, VFIO_DEVICE_SET_IRQS, irq_set); + g_free(irq_set); + if (r <=3D 0) { + error_setg_errno(errp, errno, "Failed to setup device interrupts"); + return -errno; + } else if (r < *irq_count) { + error_setg(errp, "Not enough device interrupts available"); + *irq_count =3D r; + return -EOVERFLOW; + } + return 0; +} + static int qemu_vfio_pci_read_config(QEMUVFIOState *s, void *buf, int size, int ofs) { --=20 2.26.2 From nobody Sat May 4 14:00:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1599661462; cv=none; d=zohomail.com; s=zohoarc; b=XTVsAmWahtZxWZEK4+HBDEXbXfL6egYF4ddrpKUpXGHuRQcVdMjBih66GSDVhin6Us3m1GH6e5NVR60Jo9WPgq4Po2VtokYJrxx7ozphoxCe6gPlWoY1aT6OIdDK6/o5/an0W3D4UsIMwxkJswoHnVdOeFsT7k1SCRsVmemNQOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599661462; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=hl24NRJ8Rt13BsX1usyBfMcCTpzjZpiQVXtc8EueBIg=; b=i1Gj1aos1P7u7fYUUPZ8W/ERJvhELaYWIjMxAh2dX9YiTNj65isjQ3Hl5PggnWcYshShBSAe5EJLxtH4sFhP7aJt71Gzrpw7N2O3EOy8XqxhYuOkmPq/LeUt6U5q8N0U4i+rokN7norO84ZBIu1gfAGBhzr9IvzaW7+yb14EZmk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1599661462883612.7761102160484; Wed, 9 Sep 2020 07:24:22 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-412-ZnBjMyGaNgiP8b33fK7TEw-1; Wed, 09 Sep 2020 10:24:19 -0400 Received: by mail-wm1-f71.google.com with SMTP id m125so838582wmm.7 for ; Wed, 09 Sep 2020 07:24:17 -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 b187sm4172577wmb.8.2020.09.09.07.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 07:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599661461; 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=hl24NRJ8Rt13BsX1usyBfMcCTpzjZpiQVXtc8EueBIg=; b=BOjkyjv69vCNneqBQo99Xa9EskUdqVNUMLVPet8JyLwMjmfM1SILeqMJpyXRg1pWBno8yE Lt0nrkVTs5rjcqG0TDgMsHAz1k+/fB0RS9xhXPmgnSvNgL4ctEMivS267sW3x8n08KAFsi mBscPxgOs1UOsRa2L7hty+85oPUiuW4= X-MC-Unique: ZnBjMyGaNgiP8b33fK7TEw-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=hl24NRJ8Rt13BsX1usyBfMcCTpzjZpiQVXtc8EueBIg=; b=JvBaY1b80sHhh0WxGqT+mSfF4+wZSUzUHfv9+le+Pq2dkKeNRp9o4JCgPYGzNJJrMv vs87906+JOD8QHTdaF/UUM0VrssZcVUZXT19KuRuarTB8Zu9A/SJkfayZGy+k7kKTHcR 3Hy6P+PT+5nKlSrdQRf6YypY+y9kooXnxhqgDEFy2zSFBlcZAwe5qy31GnBoa2UIIY6m nX67ejvVQiN5OEy/wpXEttYONG+3CZzCT2dMrMvIWPnRN6cZSLTkEl5k0fauz8VETocZ 7sw76Bx1QhCAUZL0m6j5mVufVl3/xQFsWc4m/mgB5NTREYFHtclfTj1q10wcURNbrW5s X95A== X-Gm-Message-State: AOAM533muni0QmIsyAtDn5yo9sZh26HUAiEzxhLgOMGc1mVbjHvrIiBb 9ZZbmip19sPC1kEVhdAM68GFQGK6uu2FwBqdwDqg32528Oosy4LYzqZI4gH5fb0zrx20WvN1w1M EFD1kdmWEF1xNcg== X-Received: by 2002:a1c:6341:: with SMTP id x62mr3814937wmb.70.1599661456336; Wed, 09 Sep 2020 07:24:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2AuS7XclxQglsXhutPrkRcK+UtTdydKLuczpxR70nsEyCL2jF0vcml4H9rgqTzZrK7nihWw== X-Received: by 2002:a1c:6341:: with SMTP id x62mr3814920wmb.70.1599661456134; Wed, 09 Sep 2020 07:24:16 -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 4/4] block/nvme: Use qemu_vfio_pci_init_msix_irqs() to initialize our IRQ Date: Wed, 9 Sep 2020 16:23:54 +0200 Message-Id: <20200909142354.334859-5-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) Instead of initializing one MSIX IRQ with the generic qemu_vfio_pci_init_irq() function, use the MSIX specific one which will allow us to use multiple IRQs. For now we provide an array of a single IRQ. Reviewed-by: Fam Zheng Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index f4f27b6da7d..e6dac027f72 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -694,6 +694,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, uint64_t timeout_ms; uint64_t deadline, now; Error *local_err =3D NULL; + unsigned irq_count =3D MSIX_IRQ_COUNT; =20 qemu_co_mutex_init(&s->dma_map_lock); qemu_co_queue_init(&s->dma_flush_queue); @@ -779,9 +780,13 @@ static int nvme_init(BlockDriverState *bs, const char = *device, int namespace, } } =20 - ret =3D qemu_vfio_pci_init_irq(s->vfio, s->irq_notifier, - VFIO_PCI_MSIX_IRQ_INDEX, errp); + ret =3D qemu_vfio_pci_init_msix_irqs(s->vfio, s->irq_notifier, + &irq_count, errp); if (ret) { + if (ret =3D=3D -EOVERFLOW) { + error_append_hint(errp, "%u IRQs requested but only %u availab= le\n", + MSIX_IRQ_COUNT, irq_count); + } goto out; } aio_set_event_notifier(bdrv_get_aio_context(bs), --=20 2.26.2