From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3614AC433FE for ; Thu, 24 Nov 2022 13:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbiKXNTa (ORCPT ); Thu, 24 Nov 2022 08:19:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbiKXNT3 (ORCPT ); Thu, 24 Nov 2022 08:19:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EE0771F15 for ; Thu, 24 Nov 2022 05:19:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AE86EB827DC for ; Thu, 24 Nov 2022 13:19:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 602E6C433C1; Thu, 24 Nov 2022 13:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669295965; bh=uQNeHHIJvCN+jBJ5mWft+AyOT9YLaeb147kcTYwPQRg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=mjXZr1wH/Z/7SeYgnIG6+Tm/hPVJ8qHa+N+zJkcAXtPGRENFEnQz5Pa8O1JYjzYMp k0KWXAP88D28S37kKKgNvxaYVOJJ9tdfkZlWpbWgGXiMmdiKd3Nw87ddlD0/7+vWmh GT52U5L4XR3xkyxGgD0D3m1ZZGtjwOK8UOWfId4DQ3AZx76YA/o+m1/pu0sknVRvXF BFSJikos4wUh6LVKeFA8NMaqVeTDwIIo4ZMeNWmIN/De6z/5MlNAd3C3LLTx1XZQzZ 8YERJsh/k7kjGwB/Wd/eb8Yv88CmU+tk0KT75dcRW8cD1fCWyGGG+qzX6DkgffnK8S S8c5KgJXsWuTQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oyC8R-008Nfd-5t; Thu, 24 Nov 2022 13:19:23 +0000 Date: Thu, 24 Nov 2022 13:19:22 +0000 Message-ID: <861qpso5gl.wl-maz@kernel.org> From: Marc Zyngier To: Alex Williamson Cc: chenxiang , , , Subject: Re: [PATCH v2] vfio/pci: Verify each MSI vector to avoid invalid MSI vectors In-Reply-To: <20221123125514.5bf83fa8.alex.williamson@redhat.com> References: <1669167756-196788-1-git-send-email-chenxiang66@hisilicon.com> <86k03loouy.wl-maz@kernel.org> <20221123125514.5bf83fa8.alex.williamson@redhat.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: alex.williamson@redhat.com, chenxiang66@hisilicon.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, linuxarm@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, 23 Nov 2022 19:55:14 +0000, Alex Williamson wrote: > > On Wed, 23 Nov 2022 12:08:05 +0000 > Marc Zyngier wrote: > > > On Wed, 23 Nov 2022 01:42:36 +0000, > > chenxiang wrote: > > > > > > +static int vfio_pci_verify_msi_entry(struct vfio_pci_core_device *vdev, > > > + struct eventfd_ctx *trigger) > > > +{ > > > + struct kvm *kvm = vdev->vdev.kvm; > > > + struct kvm_kernel_irqfd *tmp; > > > + struct kvm_kernel_irq_routing_entry irq_entry; > > > + int ret = -ENODEV; > > > + > > > + spin_lock_irq(&kvm->irqfds.lock); > > > + list_for_each_entry(tmp, &kvm->irqfds.items, list) { > > > + if (trigger == tmp->eventfd) { > > > + ret = 0; > > > + break; > > > + } > > > + } > > > + spin_unlock_irq(&kvm->irqfds.lock); > > > + if (ret) > > > + return ret; > > > + irq_entry = tmp->irq_entry; > > > + return kvm_verify_msi(kvm, &irq_entry); > > > > How does this work on !arm64? Why do we need an on-stack version of > > tmp->irq_entry? > > Not only on !arm64, but in any scenario that doesn't involve KVM. > There cannot be a hard dependency between vfio and kvm. Thanks, Yup, good point. > > Alex > > PS - What driver/device actually cares about more than 1 MSI vector and > doesn't implement MSI-X? Unfortunately, there is a metric ton of crap that fits in that description: 01:00.0 Network controller: Broadcom Inc. and subsidiaries Device 4433 (rev 07) Subsystem: Apple Inc. Device 4387 Device tree node: /sys/firmware/devicetree/base/soc/pcie@690000000/pci@0,0/wifi@0,0 Flags: bus master, fast devsel, latency 0, IRQ 97, IOMMU group 4 Memory at 6c1400000 (64-bit, non-prefetchable) [size=64K] Memory at 6c0000000 (64-bit, non-prefetchable) [size=16M] Capabilities: [48] Power Management version 3 Capabilities: [58] MSI: Enable+ Count=1/32 Maskable- 64bit+ ... and no MSI-X in sight. Pass this to a VM, and you'll see exactly what is described here. And that's not old stuff either. This is brand new HW. Do we need to care? I don't think so. M. -- Without deviation from the norm, progress is not possible.