From nobody Mon Sep 16 19:37:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1695030383; cv=none; d=zohomail.com; s=zohoarc; b=Zebnc8XI/76QtufFtuTUhmMjYdjVAK7NzfrgHhjeVS/9pKIqVsaaV6OlvKBLigE+hHDuU1ESLL08p3BbRr60IQ2nG2eZ0CLlH+kXaEBK/TcBp1GlqhenPJfZkwLZJRfFBscOEa7eQKOd/BEoeVdcONGVkUeFynGZfesidRE9m4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695030383; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GaA/M7P5Qe9ZK9zsjmSsZ5ZKGULYB42DUUlLcKeSipI=; b=PTFMAq7Zrsbg/Xd266V2ntJ+b6Yq77aKGwKmcWETcJRVQb2FKh7Y0KhcRkm3PIh4Gl/Rs3uKgECzxAjQ3hfrCZc+m23KARv5tTJGHxm2QWa0yjHuEDgcKcmz79dTQyTBk9FPnjVCh8W9SkkL+k1SFJ3TFAjdTCP6hnUEvVflztM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169503038307333.7778860367913; Mon, 18 Sep 2023 02:46:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiAou-0005p0-28; Mon, 18 Sep 2023 05:45:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiAos-0005oU-2P for qemu-devel@nongnu.org; Mon, 18 Sep 2023 05:45:30 -0400 Received: from mgamail.intel.com ([134.134.136.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiAop-0000zF-US for qemu-devel@nongnu.org; Mon, 18 Sep 2023 05:45:29 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 02:45:20 -0700 Received: from vmmteam.bj.intel.com ([10.240.193.84]) by FMSMGA003.fm.intel.com with ESMTP; 18 Sep 2023 02:45:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695030327; x=1726566327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KqrlI41bT36v2JNI8frGPTvfWv6nYWbfQq51fwpgcGI=; b=fIsb/RJplL8cSG9ePCTqpWGbjE4v/xvM15wwvA5U4uPjnJn0FS+YgmaH RYHrG6DwlNKgUtWo5VeHOQigONWK81vmG+exD03BPq44rMBbwTPASDi3L rZUXxdtzMan2WVJksYH+h1gvpAxx9IoO0kiwBKAFtiHod/ehEPoWTAt0P L3f6mNGCo4yD0mhr72ByhMJMd6nOrw4IpzFGTaqd+0vbgEvLhmU576kEv IKx+kli3RV8f8iirVsHz3+9S10iiomkOyjDIZqjcd9ckp0NgcpDDU/cPf H5XJItYHdATbr/Id1QJRZgFEblvRaINyiBSYa/2UZymj8OG3HOR5oKBF0 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10836"; a="446072281" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="446072281" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10836"; a="835955962" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="835955962" From: Jing Liu To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, pbonzini@redhat.com, kevin.tian@intel.com, reinette.chatre@intel.com, jing2.liu@intel.com, jing2.liu@linux.intel.com Subject: [PATCH v2 4/4] vfio/pci: enable MSI-X in interrupt restoring on dynamic allocation Date: Mon, 18 Sep 2023 05:45:07 -0400 Message-Id: <20230918094507.409050-5-jing2.liu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230918094507.409050-1-jing2.liu@intel.com> References: <20230918094507.409050-1-jing2.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.100; envelope-from=jing2.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1695030384019100001 Content-Type: text/plain; charset="utf-8" During migration restoring, vfio_enable_vectors() is called to restore enabling MSI-X interrupts for assigned devices. It sets the range from 0 to nr_vectors to kernel to enable MSI-X and the vectors unmasked in guest. During the MSI-X enabling, all the vectors within the range are allocated according to the VFIO_DEVICE_SET_IRQS ioctl. When dynamic MSI-X allocation is supported, we only want the guest unmasked vectors being allocated and enabled. Use vector 0 with an invalid fd to get MSI-X enabled, after that, all the vectors can be allocated in need. Signed-off-by: Jing Liu Reviewed-by: C=C3=A9dric Le Goater --- Changes since v1: - No change. Changes since RFC v1: - Revise the comments. (Alex) - Call the new helper function in previous patch to enable MSI-X. (Alex) --- hw/vfio/pci.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 0117f230e934..f5f891dc0792 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -402,6 +402,23 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bo= ol msix) int ret =3D 0, i, argsz; int32_t *fds; =20 + /* + * If dynamic MSI-X allocation is supported, the vectors to be allocat= ed + * and enabled can be scattered. Before kernel enabling MSI-X, setting + * nr_vectors causes all these vectors to be allocated on host. + * + * To keep allocation as needed, use vector 0 with an invalid fd to get + * MSI-X enabled first, then set vectors with a potentially sparse set= of + * eventfds to enable interrupts only when enabled in guest. + */ + if (msix && !vdev->msix->noresize) { + ret =3D vfio_enable_msix_no_vec(vdev); + + if (ret) { + return ret; + } + } + argsz =3D sizeof(*irq_set) + (vdev->nr_vectors * sizeof(*fds)); =20 irq_set =3D g_malloc0(argsz); --=20 2.27.0