Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3311247imm; Tue, 17 Jul 2018 02:37:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcZMxMsTZ0CJ4HFSk7vANTsOpQ+Lmh6RGgRAv7HZlKRdSviYi1HVBEFjRmbo5Q1ZRo6OWNy X-Received: by 2002:a17:902:ba97:: with SMTP id k23-v6mr889508pls.259.1531820261345; Tue, 17 Jul 2018 02:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531820261; cv=none; d=google.com; s=arc-20160816; b=IVVAPJPDY0v4ixqcCPddw3tkPUjCKZ8sgQli4LtyMEG3Fm4vAXOaNSpZpvLimK2RGi eJaZlhWG/PmDSOy7TAprnBUffvqZ5Mk5Z1OTwnnqCZBf+mRN5jGKo1Oxa+/NW1FLx0Ms KGovwjrg2B2LPmgZWgUGDaXBkGNkaDzOGOeNkb6VzSLknIOd4/kPvnPXk3ah9OnMgY8k 79m7QC8jAha37o36D/1wzyclgmwgnFxW2pv5R/GXZ2RURI5Kj8evFGkfeWx6Osm5RAZ1 HKIQCTchgP12ixThe6VhneirnuvOxRGkxllAdh5CXE2Z0UAagMafxDsejsyhtirL/qe8 badA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=7cQ3M0V4QHLxKve//jt8Oj7BlOMJrkWMtFolfGE0fK8=; b=tEyu834CwaJnjxWYmLU0y6QM/hM3EMSiYMcVV2D6aeUmHhIssedYkdgph7yxEF9MIc 6fyPqOckkirq+eHpM499C0xEcuwnVtF/5QwOXCzXr5vVUBrxMQb/Lr+wR5ecaUxUAUHH dOxcttq+ie0N1XxaUOdg1T8KwrdcmjkLVkoBRkchuFCRi1K8IuihovT1aIRZZkkBT3GK peWy/w+p7lj9odl1FlGi/mM9aIpq6LwCNSQmbucH96eAzQfWVfrGS49Kk1EngRrv4Egt MO5/OiSEdfVPoq82aBqgtcSDetGoe/G62In/Co960OiT/fLr6ajGHvbWR2aFsi7IQcdn Xytw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=K0ccWrCG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8-v6si478397pfl.87.2018.07.17.02.37.26; Tue, 17 Jul 2018 02:37:41 -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; dkim=pass header.i=@synopsys.com header.s=mail header.b=K0ccWrCG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730252AbeGQKHv (ORCPT + 99 others); Tue, 17 Jul 2018 06:07:51 -0400 Received: from smtprelay2.synopsys.com ([198.182.60.111]:39139 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728835AbeGQKHv (ORCPT ); Tue, 17 Jul 2018 06:07:51 -0400 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id 6B0A310C134F; Tue, 17 Jul 2018 02:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1531820168; bh=1O/r2aDYKcGdEXAYb1vdl90YJL9gPljVDVaYHM9y6N0=; h=Subject:To:CC:References:From:Date:In-Reply-To:From; b=K0ccWrCG3mscUjLxB55Zuep7yOaXhjLKt9wNBQlgeFgJJeXxuwN/lC2c8AercZgzx TjFgqv3/bXMGaInqjT/CIj8kGV7DCR6p83tkVsyZZ9uiipOnmhXz8j5DUM3FOGOX+I S4s0E8385b8MiXimgdHadNEcfaQmsXPPL9j47d2mqrrFx1qq472gfSDL9Z+1HCLUg8 o1cwlKy/zbyAzPOwmv76/k6pRMP3Glj28d4mX2if5RTsmEk0T8MPMfCDlKkv+J6xRP DvmtP74B0vD9cBHbXQWYMNXKj/JayP9fIEYjmGuaILqH2MY+VnAzf8SHMlGqMB9bjz wRO5aliN++2aQ== Received: from US01WXQAHTC1.internal.synopsys.com (us01wxqahtc1.internal.synopsys.com [10.12.238.230]) by mailhost.synopsys.com (Postfix) with ESMTP id 45E8A3C49; Tue, 17 Jul 2018 02:36:08 -0700 (PDT) Received: from DE02WEHTCA.internal.synopsys.com (10.225.19.92) by US01WXQAHTC1.internal.synopsys.com (10.12.238.230) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 17 Jul 2018 02:36:07 -0700 Received: from DE02WEHTCB.internal.synopsys.com (10.225.19.94) by DE02WEHTCA.internal.synopsys.com (10.225.19.92) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 17 Jul 2018 11:36:06 +0200 Received: from [10.107.25.102] (10.107.25.102) by DE02WEHTCB.internal.synopsys.com (10.225.19.80) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 17 Jul 2018 11:36:05 +0200 Subject: Re: [PATCH v11 10/12] pci_endpoint_test: Add 2 ioctl commands To: Kishon Vijay Abraham I , Gustavo Pimentel , "bhelgaas@google.com" , "lorenzo.pieralisi@arm.com" , "joao.pinto@synopsys.com" , "jingoohan1@gmail.com" , "adouglas@cadence.com" , "jesper.nilsson@axis.com" , "shawn.lin@rock-chips.com" CC: "linux-pci@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <0dc487515e28a6cd790888cb98f84fb7ea3a412e.1531751641.git.gustavo.pimentel@synopsys.com> From: Gustavo Pimentel Message-ID: Date: Tue, 17 Jul 2018 10:33:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.107.25.102] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Kishon, On 17/07/2018 03:43, Kishon Vijay Abraham I wrote: > Hi Gustavo, > > On Monday 16 July 2018 08:22 PM, Gustavo Pimentel wrote: >> Add MSI-X support and update driver documentation accordingly. >> >> Add 2 new IOCTL commands: >> - Allow to reconfigure driver IRQ type in runtime. >> - Allow to retrieve current driver IRQ type configured. >> >> Add IRQ type validation before executing the READ/WRITE/COPY tests. >> >> Signed-off-by: Gustavo Pimentel >> --- >> Change v2->v3: >> - New patch file created base on the previous patch >> "misc: pci_endpoint_test: Add MSI-X support" patch file following >> Kishon's suggestion. >> Change v3->v4: >> - Rebased to Lorenzo's master branch v4.18-rc1. >> Change v4->v5: >> - Nothing changed, just to follow the patch set version. >> Change v5->v6: >> - Moved PCITEST_SET_IRQTYPE and PCITEST_GET_IRQTYPE ioctl entries >> from patch #10 to here. >> - Increased ioctl parameters range associated to >> drivers/misc/pci_endpoint_test.c driver. >> Change v6->v7: >> - irq_type variable update just before returning the function. >> Change v7->v8: >> - Re-sending the patch series. >> Change v8->v9: >> - Added a extra parameter to pci_endpoint_test_alloc_irq_vectors, >> that specifies which irq type should be allocated. >> Change v9->v10: >> - Fixed bug, report available: https://urldefense.proofpoint.com/v2/url?u=https-3A__lkml.org_lkml_2018_7_16_11&d=DwIC-g&c=DPL6_X_6JkXFx7AXWqB0tg&r=bkWxpLoW-f-E3EdiDCCa0_h0PicsViasSlvIpzZvPxs&m=kfPim9EoIsdNO2BRH1BV6fsKhqV4Qy_JAofUZ2bPmpg&s=sz6k8lKVuC2tpzwc3T-OwE9ShzNwtALcrS_fuJGfiK0&e= >> - Added IRQ type validation before executing the READ/WRITE/COPY >> tests. >> >> Documentation/ioctl/ioctl-number.txt | 2 +- >> Documentation/misc-devices/pci-endpoint-test.txt | 3 + >> drivers/misc/pci_endpoint_test.c | 192 +++++++++++++++++------ >> include/uapi/linux/pcitest.h | 2 + >> 4 files changed, 152 insertions(+), 47 deletions(-) >> >> diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt >> index 65259d4..c15c4f3 100644 >> --- a/Documentation/ioctl/ioctl-number.txt >> +++ b/Documentation/ioctl/ioctl-number.txt >> @@ -166,7 +166,7 @@ Code Seq#(hex) Include File Comments >> 'P' all linux/soundcard.h conflict! >> 'P' 60-6F sound/sscape_ioctl.h conflict! >> 'P' 00-0F drivers/usb/class/usblp.c conflict! >> -'P' 01-07 drivers/misc/pci_endpoint_test.c conflict! >> +'P' 01-09 drivers/misc/pci_endpoint_test.c conflict! >> 'Q' all linux/soundcard.h >> 'R' 00-1F linux/random.h conflict! >> 'R' 01 linux/rfkill.h conflict! >> diff --git a/Documentation/misc-devices/pci-endpoint-test.txt b/Documentation/misc-devices/pci-endpoint-test.txt >> index fdfa0f6..58ccca4 100644 >> --- a/Documentation/misc-devices/pci-endpoint-test.txt >> +++ b/Documentation/misc-devices/pci-endpoint-test.txt >> @@ -28,6 +28,9 @@ ioctl >> to be tested should be passed as argument. >> PCITEST_MSIX: Tests message signalled interrupts. The MSI-X number >> to be tested should be passed as argument. >> + PCITEST_SET_IRQTYPE: Changes driver IRQ type configuration. The IRQ type >> + should be passed as argument (0: Legacy, 1:MSI, 2:MSI-X). >> + PCITEST_GET_IRQTYPE: Gets driver IRQ type configuration. >> PCITEST_WRITE: Perform write tests. The size of the buffer should be passed >> as argument. >> PCITEST_READ: Perform read tests. The size of the buffer should be passed >> diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c >> index f4fef10..d909ca5 100644 >> --- a/drivers/misc/pci_endpoint_test.c >> +++ b/drivers/misc/pci_endpoint_test.c >> @@ -37,6 +37,7 @@ >> >> #define DRV_MODULE_NAME "pci-endpoint-test" >> >> +#define IRQ_TYPE_UNDEFINED -1 >> #define IRQ_TYPE_LEGACY 0 >> #define IRQ_TYPE_MSI 1 >> #define IRQ_TYPE_MSIX 2 >> @@ -157,6 +158,88 @@ static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id) >> return IRQ_HANDLED; >> } >> >> +static void pci_endpoint_test_free_irq_vectors(struct pci_endpoint_test *test) >> +{ >> + int i; >> + struct pci_dev *pdev = test->pdev; >> + struct device *dev = &pdev->dev; >> + >> + for (i = 0; i < test->num_irqs; i++) >> + devm_free_irq(dev, pci_irq_vector(pdev, i), test); >> + >> + test->num_irqs = 0; >> +} >> + >> +static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test, >> + int type) >> +{ >> + int irq = -1; >> + struct pci_dev *pdev = test->pdev; >> + struct device *dev = &pdev->dev; >> + bool res = true; >> + >> + switch (type) { >> + case IRQ_TYPE_LEGACY: >> + irq = 0; >> + break; >> + case IRQ_TYPE_MSI: >> + irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI); >> + if (irq < 0) >> + dev_err(dev, "Failed to get MSI interrupts\n"); >> + break; >> + case IRQ_TYPE_MSIX: >> + irq = pci_alloc_irq_vectors(pdev, 1, 2048, PCI_IRQ_MSIX); >> + if (irq < 0) >> + dev_err(dev, "Failed to get MSI-X interrupts\n"); >> + break; >> + default: >> + dev_err(dev, "Invalid IRQ type selected\n"); >> + } >> + >> + if (irq < 0) { >> + irq = 0; >> + res = false; >> + } >> + test->num_irqs = irq; >> + >> + return res; >> +} >> + >> +static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test) >> +{ >> + struct pci_dev *pdev = test->pdev; >> + >> + pci_disable_msi(pdev); >> + pci_disable_msix(pdev); >> +} >> + >> +static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test) >> +{ >> + int i; >> + int err; >> + struct pci_dev *pdev = test->pdev; >> + struct device *dev = &pdev->dev; >> + >> + err = devm_request_irq(dev, pdev->irq, pci_endpoint_test_irqhandler, >> + IRQF_SHARED, DRV_MODULE_NAME, test); >> + if (err) { >> + dev_err(dev, "Failed to request IRQ %d\n", pdev->irq); >> + return false; >> + } >> + >> + for (i = 1; i < test->num_irqs; i++) { >> + err = devm_request_irq(dev, pci_irq_vector(pdev, i), >> + pci_endpoint_test_irqhandler, >> + IRQF_SHARED, DRV_MODULE_NAME, test); >> + if (err) >> + dev_err(dev, "Failed to request IRQ %d for MSI%s %d\n", >> + pci_irq_vector(pdev, i), >> + irq_type == IRQ_TYPE_MSIX ? "-X" : "", i + 1); >> + } >> + >> + return true; >> +} >> + >> static bool pci_endpoint_test_bar(struct pci_endpoint_test *test, >> enum pci_barno barno) >> { >> @@ -247,6 +330,11 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size) >> if (size > SIZE_MAX - alignment) >> goto err; >> >> + if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { >> + dev_err(dev, "Invalid IRQ type option\n"); >> + goto err; >> + } >> + >> orig_src_addr = dma_alloc_coherent(dev, size + alignment, >> &orig_src_phys_addr, GFP_KERNEL); >> if (!orig_src_addr) { >> @@ -337,6 +425,11 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size) >> if (size > SIZE_MAX - alignment) >> goto err; >> >> + if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { >> + dev_err(dev, "Invalid IRQ type option\n"); >> + goto err; >> + } >> + >> orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, >> GFP_KERNEL); >> if (!orig_addr) { >> @@ -400,6 +493,11 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size) >> if (size > SIZE_MAX - alignment) >> goto err; >> >> + if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { >> + dev_err(dev, "Invalid IRQ type option\n"); >> + goto err; >> + } >> + >> orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, >> GFP_KERNEL); >> if (!orig_addr) { >> @@ -440,6 +538,38 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size) >> return ret; >> } >> >> +static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, >> + int req_irq_type) >> +{ >> + struct pci_dev *pdev = test->pdev; >> + struct device *dev = &pdev->dev; >> + >> + if (req_irq_type < IRQ_TYPE_LEGACY || req_irq_type > IRQ_TYPE_MSIX) { >> + dev_err(dev, "Invalid IRQ type option\n"); >> + return false; >> + } >> + >> + if (irq_type == req_irq_type) >> + return true; >> + >> + pci_endpoint_test_free_irq_vectors(test); >> + pci_endpoint_test_release_irq(test); >> + >> + if (!pci_endpoint_test_alloc_irq_vectors(test, req_irq_type)) >> + goto err; >> + >> + if (!pci_endpoint_test_request_irq(test)) >> + goto err; >> + >> + irq_type = req_irq_type; >> + return true; >> + >> +err: >> + pci_endpoint_test_release_irq(test); > > sorry for not noticing this earlier.. > > pci_endpoint_test_alloc_irq_vectors enables MSI.. I'd have expected > pci_endpoint_test_free_irq_vectors to disable MSI. Similarly > pci_endpoint_test_request_irq requests irq. Ideally > pci_endpoint_test_release_irq should have freed irq. I feel the contents of > pci_endpoint_test_release_irq() and pci_endpoint_test_free_irq_vectors are swapped. > > For the patch itself, I have tested it now and the issue I reported earlier is > not seen in this series. I just sent the patch series V12 with that swapped. Please give the Acked for the missing patches #4, #7 and #10 (if you agree) to close this patch series. > > Thanks > Kishon > Regards, Gustavo