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 X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 8FBC7C282DD for ; Mon, 8 Apr 2019 01:27:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 59D0620883 for ; Mon, 8 Apr 2019 01:27:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="iuvLpJWr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726536AbfDHB1y (ORCPT ); Sun, 7 Apr 2019 21:27:54 -0400 Received: from mail-yb1-f193.google.com ([209.85.219.193]:39078 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbfDHB1y (ORCPT ); Sun, 7 Apr 2019 21:27:54 -0400 Received: by mail-yb1-f193.google.com with SMTP id b88so4548143ybi.6 for ; Sun, 07 Apr 2019 18:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IYBpeb1hM5WGzOAz6a5KnUsnQB8vYOsIsT8q10nvFg8=; b=iuvLpJWrwn8S1CnVss1ptsO+9Sh4wQT6s+ei8WPTWj9A8sAAudMxVsJS+qx119P+wY IYPo0FFhibgelLiNlTiHUOBnfdAyFnNutfb2hVbxTVA0h+ubxX3eNiMPtxuvvQGCHlDe J7ZgZfaroJrrqZQ2bPUeuEkHDwXHEaDdZneMlvYU2LeasXI2A1fJZn3UAc5qbZP3zWlu 1kxRRC1/h5ITcHKCuKY+oHmLNFrrCzW12D2ZpoiAeMfGTo+ihXqc9hjBwgD0mBmJr5ix iVxOVwM/O+1D6ANnhYAJooAxYGXCuVeXRPzjPtCnCfb9Z2/6b2bVYZCQKVyrpH3kVou5 FSlQ== 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; bh=IYBpeb1hM5WGzOAz6a5KnUsnQB8vYOsIsT8q10nvFg8=; b=kyNAedxVho2qNklflC94xNaoQHDilbR3F1f/u9CMlOA6S5qds/YIkL+kidBrS9ogRW DgoGnQ0bocFLLBbGK2A6orNefov6chhfEthNAxC+wik+5AgkUKThxsF71e+RlVDDuIin uEWM5YjuIVl7n966PTVVime++YMUQ/hyIWo9ZSCApwn1qfe01PQwv7iwLFu0hG8pnQRX SUASsjBxNmVoUIKYTKLoRMs1hPrir/1yJDJM+/j0EkGwLUMx/7PAFORBdJjbgitBzRUK orooHBMzpWNyUEBOIMRxAwDecJh33vCtXWwHqVDY196dWMFTYgHWpE5Zdl61iDo9Z9uP RADg== X-Gm-Message-State: APjAAAVgAZz5ZkxA0Dg/yFoScjhitVeBHUAEQU+KZarpP/rc3Xoquvks w8jrny5AsIo9CBMP6EraswiKXgKkiSC2oHv2 X-Google-Smtp-Source: APXvYqzEwyTO3bYhwpzPsceG2Jd4WA5VG9HW3aLeXM29ct2Vq7Fzlee2snV2YUgiCrAgqWIWU7gYig== X-Received: by 2002:a25:1e57:: with SMTP id e84mr22261328ybe.184.1554686872852; Sun, 07 Apr 2019 18:27:52 -0700 (PDT) Received: from localhost.localdomain (li931-65.members.linode.com. [45.56.113.65]) by smtp.gmail.com with ESMTPSA id 190sm10494919ywd.62.2019.04.07.18.27.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Apr 2019 18:27:52 -0700 (PDT) From: Leo Yan To: "kvm@vger.kernel.org" , "kvmarm@lists.cs.columbia.edu" , Will Deacon , Jean-Philippe Brucker , Marc Zyngier , Eric Auger , Robin Murphy Cc: Leo Yan Subject: [PATCH v4 2/3] vfio-pci: Add new function for INTx one-time initialisation Date: Mon, 8 Apr 2019 09:27:18 +0800 Message-Id: <20190408012719.16158-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190408012719.16158-1-leo.yan@linaro.org> References: <20190408012719.16158-1-leo.yan@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To support INTx enabling for multiple times, we need firstly to extract one-time initialisation and move the related code into a new function vfio_pci_init_intx(); if later disable and re-enable the INTx, we can skip these one-time operations. This patch move below three main operations for INTx one-time initialisation from function vfio_pci_enable_intx() into function vfio_pci_init_intx(): - Reserve 2 FDs for INTx; - Sanity check with ioctl VFIO_DEVICE_GET_IRQ_INFO; - Setup pdev->intx_gsi. Suggested-by: Jean-Philippe Brucker Signed-off-by: Leo Yan Reviewed-by: Jean-Philippe Brucker --- vfio/pci.c | 67 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/vfio/pci.c b/vfio/pci.c index 5224fee..3c39844 100644 --- a/vfio/pci.c +++ b/vfio/pci.c @@ -1018,30 +1018,7 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) struct vfio_irq_eventfd trigger; struct vfio_irq_eventfd unmask; struct vfio_pci_device *pdev = &vdev->pci; - int gsi = pdev->hdr.irq_line - KVM_IRQ_OFFSET; - - struct vfio_irq_info irq_info = { - .argsz = sizeof(irq_info), - .index = VFIO_PCI_INTX_IRQ_INDEX, - }; - - vfio_pci_reserve_irq_fds(2); - - ret = ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); - if (ret || irq_info.count == 0) { - vfio_dev_err(vdev, "no INTx reported by VFIO"); - return -ENODEV; - } - - if (!(irq_info.flags & VFIO_IRQ_INFO_EVENTFD)) { - vfio_dev_err(vdev, "interrupt not eventfd capable"); - return -EINVAL; - } - - if (!(irq_info.flags & VFIO_IRQ_INFO_AUTOMASKED)) { - vfio_dev_err(vdev, "INTx interrupt not AUTOMASKED"); - return -EINVAL; - } + int gsi = pdev->intx_gsi; /* * PCI IRQ is level-triggered, so we use two eventfds. trigger_fd @@ -1097,8 +1074,6 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) pdev->intx_fd = trigger_fd; pdev->unmask_fd = unmask_fd; - /* Guest is going to ovewrite our irq_line... */ - pdev->intx_gsi = gsi; return 0; @@ -1117,6 +1092,39 @@ err_close: return ret; } +static int vfio_pci_init_intx(struct kvm *kvm, struct vfio_device *vdev) +{ + int ret; + struct vfio_pci_device *pdev = &vdev->pci; + struct vfio_irq_info irq_info = { + .argsz = sizeof(irq_info), + .index = VFIO_PCI_INTX_IRQ_INDEX, + }; + + vfio_pci_reserve_irq_fds(2); + + ret = ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); + if (ret || irq_info.count == 0) { + vfio_dev_err(vdev, "no INTx reported by VFIO"); + return -ENODEV; + } + + if (!(irq_info.flags & VFIO_IRQ_INFO_EVENTFD)) { + vfio_dev_err(vdev, "interrupt not eventfd capable"); + return -EINVAL; + } + + if (!(irq_info.flags & VFIO_IRQ_INFO_AUTOMASKED)) { + vfio_dev_err(vdev, "INTx interrupt not AUTOMASKED"); + return -EINVAL; + } + + /* Guest is going to ovewrite our irq_line... */ + pdev->intx_gsi = pdev->hdr.irq_line - KVM_IRQ_OFFSET; + + return 0; +} + static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev) { int ret = 0; @@ -1142,8 +1150,13 @@ static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev return ret; } - if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) + if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) { + ret = vfio_pci_init_intx(kvm, vdev); + if (ret) + return ret; + ret = vfio_pci_enable_intx(kvm, vdev); + } return ret; } -- 2.19.1