Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4166858ybh; Tue, 6 Aug 2019 07:21:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqydu8t/Nrxa9nWFKlTXycPt0jyeFpePObr/2gde+Ah7Ew+psKq0QaAOnCdoIUly980EN7zK X-Received: by 2002:a65:5348:: with SMTP id w8mr3275955pgr.176.1565101282835; Tue, 06 Aug 2019 07:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565101282; cv=none; d=google.com; s=arc-20160816; b=eCPvoepYN6ftRqOvlljqAkQnFaFujyNdc+7QP2GD6EH3CskP/ShlzMoPmjZtHy70iV sEzYxp2IFjBzQjWSUvNtuw8w+hZg/mJWvmULhS93zXtfXNpq6l649sv64Jq/wT6smXcl mZNVPFdcn90kwRcJA1D+ztji5r7dFyAsX93JcndiazdXdILiPjaVJFJ3Crmmd1DorlZU UEQ9Q1kI5PXzyvSk+xXoAsPoKhAGA0fSoCTIpfhrpDTupG2cIsdcYPwC9seVzGW1MJ0O iASxrSfQbC2w2/P3ExzWb5m8Ott+WHBHfbDlKgtwKn0lT+ZbxUKmGxlDSBW/WDGkkmbP rdxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zV7Dw79Q7t8KLzDBQXP6RM7tymqqKT74Az8NkzoU2hY=; b=KMNHXacS7lGxBkn8t5yja4Qoxfv9YhNVcQYdZlyRLzrdFoUmTGhvZiOI4zkZFAKzsy rO+13G5w8f1AZSWbQMl+I64qgxeek/sKLGMvS46+dBnc4e/iECkXEwat80DzZ7+hUi0j TuSVD36479gkjj86hNQ52PCHVPsxL3yYpmtPdpFW50WofvHLwXJ2inDz3MQ4sKqbbhGA iHkV/A3fVGpPXW7XaEw732Ahe7fNKq7hKbtaYn0oGhO90A8xhpldjKx9ZGvwIZ+GDZQp jXuTEOmXXcdylUL1Ns+Pcuzdq8CILHLVpxVUoMmc/823HSCStCgUGeLMnHpc7w9xkiof 5mSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cj11si43395484plb.373.2019.08.06.07.21.06; Tue, 06 Aug 2019 07:21:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733031AbfHFOSr (ORCPT + 99 others); Tue, 6 Aug 2019 10:18:47 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:46734 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732997AbfHFOSq (ORCPT ); Tue, 6 Aug 2019 10:18:46 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from parav@mellanox.com) with ESMTPS (AES256-SHA encrypted); 6 Aug 2019 17:18:40 +0300 Received: from sw-mtx-036.mtx.labs.mlnx (sw-mtx-036.mtx.labs.mlnx [10.12.150.149]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x76EIa7i019368; Tue, 6 Aug 2019 17:18:38 +0300 From: Parav Pandit To: kvm@vger.kernel.org, wankhede@nvidia.com, linux-kernel@vger.kernel.org Cc: parav@mellanox.com, alex.williamson@redhat.com, cohuck@redhat.com, cjia@nvidia.com Subject: [PATCH v1 1/2] vfio-mdev/mtty: Simplify interrupt generation Date: Tue, 6 Aug 2019 09:18:25 -0500 Message-Id: <20190806141826.52712-2-parav@mellanox.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190806141826.52712-1-parav@mellanox.com> References: <20190802065905.45239-1-parav@mellanox.com> <20190806141826.52712-1-parav@mellanox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While generating interrupt, mdev_state is already available for which interrupt is generated. Instead of doing indirect way from state->device->uuid-> to searching state linearly in linked list on every interrupt generation, directly use the available state. Hence, simplify the code to use mdev_state and remove unused helper function with that. Reviewed-by: Cornelia Huck Signed-off-by: Parav Pandit --- samples/vfio-mdev/mtty.c | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 92e770a06ea2..ce84a300a4da 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -152,20 +152,9 @@ static const struct file_operations vd_fops = { /* function prototypes */ -static int mtty_trigger_interrupt(const guid_t *uuid); +static int mtty_trigger_interrupt(struct mdev_state *mdev_state); /* Helper functions */ -static struct mdev_state *find_mdev_state_by_uuid(const guid_t *uuid) -{ - struct mdev_state *mds; - - list_for_each_entry(mds, &mdev_devices_list, next) { - if (guid_equal(mdev_uuid(mds->mdev), uuid)) - return mds; - } - - return NULL; -} static void dump_buffer(u8 *buf, uint32_t count) { @@ -337,8 +326,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, pr_err("Serial port %d: Fifo level trigger\n", index); #endif - mtty_trigger_interrupt( - mdev_uuid(mdev_state->mdev)); + mtty_trigger_interrupt(mdev_state); } } else { #if defined(DEBUG_INTR) @@ -352,8 +340,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, */ if (mdev_state->s[index].uart_reg[UART_IER] & UART_IER_RLSI) - mtty_trigger_interrupt( - mdev_uuid(mdev_state->mdev)); + mtty_trigger_interrupt(mdev_state); } mutex_unlock(&mdev_state->rxtx_lock); break; @@ -372,8 +359,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, pr_err("Serial port %d: IER_THRI write\n", index); #endif - mtty_trigger_interrupt( - mdev_uuid(mdev_state->mdev)); + mtty_trigger_interrupt(mdev_state); } mutex_unlock(&mdev_state->rxtx_lock); @@ -444,7 +430,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, #if defined(DEBUG_INTR) pr_err("Serial port %d: MCR_OUT2 write\n", index); #endif - mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev)); + mtty_trigger_interrupt(mdev_state); } if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) && @@ -452,7 +438,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, #if defined(DEBUG_INTR) pr_err("Serial port %d: MCR RTS/DTR write\n", index); #endif - mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev)); + mtty_trigger_interrupt(mdev_state); } break; @@ -503,8 +489,7 @@ static void handle_bar_read(unsigned int index, struct mdev_state *mdev_state, #endif if (mdev_state->s[index].uart_reg[UART_IER] & UART_IER_THRI) - mtty_trigger_interrupt( - mdev_uuid(mdev_state->mdev)); + mtty_trigger_interrupt(mdev_state); } mutex_unlock(&mdev_state->rxtx_lock); @@ -1028,17 +1013,9 @@ static int mtty_set_irqs(struct mdev_device *mdev, uint32_t flags, return ret; } -static int mtty_trigger_interrupt(const guid_t *uuid) +static int mtty_trigger_interrupt(struct mdev_state *mdev_state) { int ret = -1; - struct mdev_state *mdev_state; - - mdev_state = find_mdev_state_by_uuid(uuid); - - if (!mdev_state) { - pr_info("%s: mdev not found\n", __func__); - return -EINVAL; - } if ((mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) && (!mdev_state->msi_evtfd)) -- 2.21.0.777.g83232e3864