From patchwork Wed Sep 9 14:23:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCF87C433E2 for ; Wed, 9 Sep 2020 14:25:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5057422248 for ; Wed, 9 Sep 2020 14:25:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="be7m1XTX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5057422248 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kG12G-0001JX-CL for qemu-devel@archiver.kernel.org; Wed, 09 Sep 2020 10:25:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG115-0007QS-5W for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:07 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40844 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kG113-0004Hb-BA for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:06 -0400 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= 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-509-WZKOu_JxPVySybSAQBb8Hw-1; Wed, 09 Sep 2020 10:24:03 -0400 X-MC-Unique: WZKOu_JxPVySybSAQBb8Hw-1 Received: by mail-wr1-f71.google.com with SMTP id x15so1021712wrm.7 for ; Wed, 09 Sep 2020 07:24:02 -0700 (PDT) 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=SsHXtJAV3sMb849SSp+RdLXsdojRdN+DEPBLHibrbbwkfV+GVjytBse2aByW0s6rQH sc29vYXAdKDvkaMKpxcaU62CL8QVJpNteVhnrO6RAOs1ge5tPgamFSTyQN8E1qG2HACh AAJJ7Wnl63aPFW4WxgOQ6CRRYW6TnJaelKd//ueB4QWDvCa8jnEY5nsZjJUn79Dwnbcx xMITTFnjpyu913vcYk97tZG/gIjkl3EjH4lNWk8pO3L7ivbLp9gjbNXtDSs7H9/L9CU9 ll0RuU4HEb0ugPW8JJQokQmwRAAs7xP1FDe7kK0gq2h/reWH+uT/cJxI6R9Ir/cULoyv LuRQ== X-Gm-Message-State: AOAM530qPwVjAEeMeYRMS4OuhU1b3XUiLbHpJxEZlvK1L5ygNTMe849v 4/QcCEYiHgsWZs13oijHQx/t8I55QkQurfiDI2Jewzr2x7T4OJaQyaBXKsd5sooCQWGPG/G2tdn u3b2laGa1TO1JVqU= X-Received: by 2002:a5d:6551:: with SMTP id z17mr4291191wrv.200.1599661441704; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/09 03:05:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Alex Williamson , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?b?ZMOp?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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=none,id=nvme0,file=nvme://0001:01:00.0/1,format=raw qemu-system-ppc64: -drive if=none,id=nvme0,file=nvme://0001:01:00.0/1,format=raw: VFIO IOMMU Type1 is not supported Suggested-by: Alex Williamson Reviewed-by: Fam Zheng Signed-off-by: Philippe Mathieu-Daudé 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 char *device, } 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 = -EINVAL; goto fail_container; } From patchwork Wed Sep 9 14:23:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24D36C43461 for ; Wed, 9 Sep 2020 14:25:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A4F3D22248 for ; Wed, 9 Sep 2020 14:24:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Fi/IPpAi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4F3D22248 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kG11u-0000en-C7 for qemu-devel@archiver.kernel.org; Wed, 09 Sep 2020 10:24:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG11A-0007cv-0b for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:12 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:31217 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kG118-0004KS-9G for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599661449; 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=Fi/IPpAizPt1X/tVtTtBMx4KDIkMO10jIr310ijfY69sdkqUX8jTYYZMf8rDdoE/bhgW7U LZlYa0DZJVkbLJXuGjHIYPYtnwK82TEHePISV2emY6/0IRIhG0Q269eDxs6PPQbhRSXTuL +4KWeGzmTOmcES41khFmB6hWfDzuNRY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-401-AsEodwYQPPytSIeoFa0AUA-1; Wed, 09 Sep 2020 10:24:08 -0400 X-MC-Unique: AsEodwYQPPytSIeoFa0AUA-1 Received: by mail-wm1-f72.google.com with SMTP id c72so892763wme.4 for ; Wed, 09 Sep 2020 07:24:07 -0700 (PDT) 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=e4mkIxt5LTvX4GuebAJEGf8FKXFEiGcvldna/nyfo2EF5FsrgdLl2+rJd3dze5h0y2 MoLdd5dt0s7SWXU3wBPdQcbQqh2Dl8NlrlibHiksQywoXHlsSPiF8F5qZqP3J8Imkpy2 q2y2XioFZPRR+jKCCzvNfY6QmL+AF9MYXrzpcPtFa+GOWRzkhKIO7DJrOBhvWr6PCC5t s+FOOBycd42luIWlCIt65tbjBXhlsCxlRmguzVW1loG1c8QgTgFvE371+cBojzplnWHG ndfWav/3sOuWGm6rNYvnMDbwnr8ScUd2cLvr7eeT5hzjCgJP7MVmRZS95+v1CzcCXZNh iorQ== X-Gm-Message-State: AOAM532mcKdS6Cgc1gdlntq8AuTm1vIpapKq0U2ms0dOV14lhU4Qswp5 NPPRJ1GoFxPfg4TeHIPntoqJt1iJFXgsUq9JdPf+llDosHIrudbsVrhX6h7J5FxwnUsgBxeC2go nHRH+Ocz7R3C5h8M= X-Received: by 2002:adf:ec87:: with SMTP id z7mr4474432wrn.57.1599661446654; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/09 02:43:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Alex Williamson , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?b?ZMOp?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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=none,id=nvme0,file=nvme://0006:90:00.0/1,format=raw qemu-system-aarch64: -drive if=none,id=nvme0,file=nvme://0006:90:00.0/1,format=raw: 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é --- 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 @@ */ #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 = -errno; goto fail; } + if (!(iommu_info.flags & VFIO_IOMMU_INFO_PGSIZES)) { + error_setg(errp, "Failed to get IOMMU page size info"); + ret = -EINVAL; + goto fail; + } + if (!extract64(iommu_info.iova_pgsizes, + ctz64(qemu_real_host_page_size), 1)) { + g_autofree char *host_page_size = size_to_str(qemu_real_host_page_size); + error_setg(errp, "Unsupported IOMMU page size: %s", host_page_size); + error_append_hint(errp, "Available page size:\n"); + for (int i = 0; i < 64; i++) { + if (extract64(iommu_info.iova_pgsizes, i, 1)) { + g_autofree char *iova_pgsizes = size_to_str(1UL << i); + error_append_hint(errp, " %s\n", iova_pgsizes); + } + } + ret = -EINVAL; + goto fail; + } s->device = ioctl(s->group, VFIO_GROUP_GET_DEVICE_FD, device); From patchwork Wed Sep 9 14:23:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56ECBC43461 for ; Wed, 9 Sep 2020 14:27:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9B19215A4 for ; Wed, 9 Sep 2020 14:27:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f4Fadyzq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9B19215A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kG142-0004IV-1s for qemu-devel@archiver.kernel.org; Wed, 09 Sep 2020 10:27:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG11H-0007zd-Vv for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27757) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kG11G-0004PM-4O for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599661457; 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=f4FadyzqbuLcqAqC1V4MS93ACSsWasNqCtzAOW2dwvcoqDckBI4+N40CFAlmTQGMFoiyPt REhaVp8TdM7DLYlqM0P+WLy8fKvD188I6teivZVZE8+pAjoLBYaWtVkaAAnxP11m2cu7GK +OgP2HWjf7sKVOzA1RaXUnvI7DW09N4= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121--bfcyVR6MmGTORQFC2yEWA-1; Wed, 09 Sep 2020 10:24:13 -0400 X-MC-Unique: -bfcyVR6MmGTORQFC2yEWA-1 Received: by mail-wm1-f70.google.com with SMTP id 189so893146wme.5 for ; Wed, 09 Sep 2020 07:24:12 -0700 (PDT) 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=EJFgrYsUuMO+xdHZCDXv9hlPzo/uftpXUjQEhO9wD+DbeOg23t/hwUGuBBzG09YrCs Xzu1Kprtf1Z5eVR3gO8oSir/OiiOS/lnBbL9vDmOFZPikiMgkcAkub8IBArHLBECnMA6 JXXHBhCMh/A7xfNnAfhLHecFT2U+A1QBY7pJPk8YQ9+7u91SE4KNSibIsxIF6mxh5uAw T5eMjpBvAAR1Su6jPZGWAwkyXQYnaAds/pULrPLyGU62VZPpkhPpQ+PL9nk+W/9rZFpr 4SKoXjRXw7gQyFecUTDbGtoPUCKa0da+Fpn4eJLrZB38ChHHjc01bnV5fbsduHwX8t4A /39A== X-Gm-Message-State: AOAM532TAkJPnGF5KEz2ZxQC4USCKrMtk3wM2UBxknfPIc80IvBc3tIb dn6XoeliwC6UicGd+GQ3u6gfXfUkzxGoz3VuOAem48GHbHCtPVCTyHH4OcACxoNAtc8pxj9MCcc X40j0IVdc63Y6PtI= X-Received: by 2002:a1c:2d85:: with SMTP id t127mr3838697wmt.22.1599661451559; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/09 07:20:24 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Alex Williamson , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?b?ZMOp?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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é * + * SPDX-License-Identifier: GPL-2.0-or-later * This work is licensed under the terms of the GNU GPL, version 2 or later. * 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); #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é * + * SPDX-License-Identifier: GPL-2.0-or-later * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ @@ -216,6 +218,67 @@ int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotifier *e, return 0; } +/** + * 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 = { + .argsz = sizeof(irq_info), + .index = 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 = 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 = sizeof(*irq_set) + *irq_count * sizeof(int32_t); + irq_set = g_malloc0(irq_set_size); + + /* Get to a known IRQ state */ + *irq_set = (struct vfio_irq_set) { + .argsz = irq_set_size, + .flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER, + .index = irq_info.index, + .start = 0, + .count = *irq_count, + }; + + for (unsigned i = 0; i < *irq_count; i++) { + ((int32_t *)&irq_set->data)[i] = event_notifier_get_fd(¬ifier[i]); + } + r = ioctl(s->device, VFIO_DEVICE_SET_IRQS, irq_set); + g_free(irq_set); + if (r <= 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 = r; + return -EOVERFLOW; + } + return 0; +} + static int qemu_vfio_pci_read_config(QEMUVFIOState *s, void *buf, int size, int ofs) { From patchwork Wed Sep 9 14:23:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37692C433E2 for ; Wed, 9 Sep 2020 14:26:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98FAA215A4 for ; Wed, 9 Sep 2020 14:26:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AJ1OF0TY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98FAA215A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kG13c-0003d7-O8 for qemu-devel@archiver.kernel.org; Wed, 09 Sep 2020 10:26:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG11K-00087J-L4 for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kG11I-0004Qn-UQ for qemu-devel@nongnu.org; Wed, 09 Sep 2020 10:24:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599661460; 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=AJ1OF0TYGzo2vwRmFJANqrtrvQjrtcXGXBAt9AIbzBgE8Dr1YqZTGH+NnexamYDVN0tNBf Kp4WG3Xk4QvbGibR5GVXypv3YOnd/aDSYuRx82vQArc2oj0a4KlH1w6/t9ZiT6UJqhRZ3M /MifBle//pdkSXTRmf4RDcMU69+MRq4= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-cYC8fy7nOlOjoaABe1dcBA-1; Wed, 09 Sep 2020 10:24:19 -0400 X-MC-Unique: cYC8fy7nOlOjoaABe1dcBA-1 Received: by mail-wr1-f72.google.com with SMTP id v12so1031576wrm.9 for ; Wed, 09 Sep 2020 07:24:17 -0700 (PDT) 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=rDc63UiJic2ikm9xg4CPF7gBjUaIWh7UWsin8Z/nxSCFQKOgMlFFQ7tnWmMIvjglKt b37Q6cCsWpetWavck47q/QGyIDgwGp10qzs4SUNyCsyl7BzRVrb0lyLQifu24M9Xklp2 o86KflcNFm+53QWvYlx2FjLumhR6vaKLYvocfcON/qUJhCcB/c0Te4F3AFG/H3Ej1sdh J0HoXC2KmN9Fr9/xTOTeUwte/TfA8azz/6CHw+IWeiXZ5u6vyJAqe/Nf06SNQy+KNJ8E Jj+QB5rLa/iXZhGHINyPQf/N0i3y2/voxmJBxGrfTXFGbjRVezyklbskZ3K9q78/HK6m xXCA== X-Gm-Message-State: AOAM530VH3AX1kSFtz7eZiUdiVFW3CBIET9w6MVZBeki5XRI6kVxCO9E mRC/u1Gg4NMLxneyAGT6N5RGrvUfs3Rs/Dfslo/HkvfTjHIbOc0/7/hgfDKzgla056xi7KtTB9J A7iIMEr2dlKas5tk= X-Received: by 2002:a1c:6341:: with SMTP id x62mr3814942wmb.70.1599661456337; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/09 07:20:24 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Alex Williamson , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?b?ZMOp?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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 = NULL; + unsigned irq_count = MSIX_IRQ_COUNT; 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, } } - ret = qemu_vfio_pci_init_irq(s->vfio, s->irq_notifier, - VFIO_PCI_MSIX_IRQ_INDEX, errp); + ret = qemu_vfio_pci_init_msix_irqs(s->vfio, s->irq_notifier, + &irq_count, errp); if (ret) { + if (ret == -EOVERFLOW) { + error_append_hint(errp, "%u IRQs requested but only %u available\n", + MSIX_IRQ_COUNT, irq_count); + } goto out; } aio_set_event_notifier(bdrv_get_aio_context(bs),