From patchwork Thu Jan 19 16:51:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9526477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6596A60113 for ; Thu, 19 Jan 2017 17:14:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57A5A2863A for ; Thu, 19 Jan 2017 17:14:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C31E28642; Thu, 19 Jan 2017 17:14:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 294A32863A for ; Thu, 19 Jan 2017 17:14:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753832AbdASRO2 (ORCPT ); Thu, 19 Jan 2017 12:14:28 -0500 Received: from mail-bn3nam01on0044.outbound.protection.outlook.com ([104.47.33.44]:38373 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753819AbdASRO0 (ORCPT ); Thu, 19 Jan 2017 12:14:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ZL0PNdPS9mOq6F1VD8WucrghMOpF4bYGJ4F5klHjpbw=; b=m/6IbZeaKVzq1A66QcNGx/VDCI9vhzlcCN3y360uxA1+8EMXxLu5oWyGMLIvyAY2NyN0XMyCuNoa+3nURPC/OKofS/Y5dRJA33wro54pHC4MvXkaXE6TeTyU/ZC+nUD+M9IrwowmIdmcB4d06Jfaj8zdHcDxuDdrFkdsMkdTmb4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aditr@vmware.com; Received: from gandalf.eng.vmware.com (208.91.1.34) by CO2PR0501MB837.namprd05.prod.outlook.com (10.141.244.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.860.6; Thu, 19 Jan 2017 16:56:18 +0000 From: Adit Ranadive To: , CC: Adit Ranadive , , Bryan Tan Subject: [PATCH rdma-core] vmw_pvrdma: Check vendor and device ID on driver init Date: Thu, 19 Jan 2017 08:51:36 -0800 Message-ID: <1484844696-11983-1-git-send-email-aditr@vmware.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: CY1PR01CA0014.prod.exchangelabs.com (10.163.94.24) To CO2PR0501MB837.namprd05.prod.outlook.com (10.141.244.147) X-MS-Office365-Filtering-Correlation-Id: 4a5bf5d8-b21d-48d6-1433-08d4408c16ee X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CO2PR0501MB837; X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 3:5Jnp1N/3glLsbMsO6yYBv/4NLNbUYHoBR0tP3ERHw8YgK2fzL7vDGFshP3q/XJGHmaLVGb2e6t8fUkNnCxt0Ne9EMLHxFjUfM+4Ax9wsME8UnsULuAXq9XbtCzWz2X/ggqTgvcbf08SMWd+NfrthNOwBXJsS/ugsB/+zEc8pjXM1m/4nUsIOQ9qyQl2AOAL/1h7ZedBy3r7fUO/x4oZrzGmACZNaztDwH0k0WpHaRpQbZCfbM098hk5p0A3BN2iY3jc3srllfOrH/sWWXU43yA== X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 25:utVZ7MifGoD6H9vtPoXGLfroAbw3tDQcYAsZHGmBFwGXkvOj500LPKIAGKHa56RvhCI0QEPqqlheonK5NToCK4Dgfp+JqZynw0SczNNz544CtgOKOTaMpODh/g6rPAOLm98FooY+0huuzk5g2S4czrxrDO+GYJ73wVp0DifFz9hc2p70fUwbFuD6WMEPJxMVbV8j5SDoFfV8+OkJc38F0w0te4ntqeRFiZpY+Yq6x5aEwXeXwHD6ZA1nQQXAJQmEu6BggprKwE4GeBtpyC0hH2acXCyNkTUaFwd7tvI0bw3R2goc4X/B1eaxHU2nE8G1r5TN37hAuNkgYkM/Qzjb5XoL+yoREc4ZlhKmBrUi7WDTJutAvoA6Fh2k9UZv0YaDEVt9lA1HYSp/+nc+xrQkvIDDTce30VILxOylt4M3wSH4g/QQxN1p2TkOq1cwStvpNIfaUN3Br3OyAcHWhvBpMdtKAJFg4i8mbTXiHpXwGijqY5s1wEGFaxphO71H9zs5jD9mz3oLSEDtEudTqAA95jI6e85YjW4cp/jobaSx+URcNr3m8sr/5JN6JowtRF89cvX0V247wZR8fhDC2RzQo2NPsDR3NMwcQCjkpXwCmdIMADsoMsdCtsU3hToviDsEFkzpSxgsuEO5IdHLxCawjHRQEYkTi6EHoyoG4llNMI5MbjaXtOBBDNc+C/vwSPUDH2znTbpnskLZQPLFFDPqSDF7SMTFKUFxmhj9tnoZwlhaXGcXVF6Zk227MIIKPYq5XdqydTCbkzzIlNVDK6oq+94DayBY9UK57bmvAmk+4sfTm0PUQ+kRSNDH2tOny0EC X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 31:dgcyGy7Z9bsUVU/VDVk+XcocAGaak25O2LAZWplOAO1Rfj05Kl0R5W7VdJKHK6adTEALteOuCKDgPzqIgJZq3AyTsjinyidueyCRaSF6EHJF617i5uXiVOBTkHqu2GU/EWfFuDI0gFF7IntJr/BgTYFH35SmtUdb9El6irS2GkZ1cNqbEYRlxc/H1h7Fsk3HV/m6DUFc56HYcQIGKX01EBHIk19VRvdB7442CJm55HJm3Nivv5EGKoCyHl108JnfvBAJUI6L60Beiay+mEywDA==; 20:rHfCQvpkzyDJEzoYmAmRZf+WsnwfFKx621UEQAE+7P7hNDQnU3103Ig2OuYiQS8hf7roYfqw6rXsE5PuKp+Ym6jbtogohKWd0f15nLj/8PsmuRZ9qgNvApeAnK8zI7kniqXYp5otafV7UKGUL/fGBfCretqarvuweAHmKJ7OZAELBrvEh+HU+fikSOyFUQVHtR4qH+puAwZiF8SGI9MuXe1AROwZxHpxnZiBQnoLby/3Tq+JTPHK2U0IY3K9n490x6P7DH04rEZpSGSgawzGebL5sP7K7Kq8/Gbni8nNNOGAvO+CXxclqlzLC4i2LdArhmc2nhWOqruMkHw1H6+ZRojv0KX2uHD4Lr4ksKnFt54MOYRIYEhLbSSUWrcXW4GSWYOBOgL3fszH7ogOhu0RDWa4EpcZUPh37bnda9BFtqXSJpu0NJMnYpQa1QFl1ve+FQxTY2plaIXliY02xS/MlMQOwjicg2SfYKMTtKTQpjNZz8H3o9g0+Ga6ithCY0O4 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123562025)(20161123555025)(20161123564025)(20161123560025)(6072148); SRVR:CO2PR0501MB837; BCL:0; PCL:0; RULEID:; SRVR:CO2PR0501MB837; X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 4:I9nHEbqebPDINCENnCCtmTu1I5Xs4qjC51prus0BAu0Ny16SvkdU2E412GqSc253p99VcR/a5JztKyBR0Oj0Xd/+nRzgHlq9POuiKSL4fgZ11b8wVpYhb96fvhSfqFF7URvXjnf7VTm9YvU3jX4ccUZcnO3I/ZRzb+o5VVb2gFwA7csQ36APFirUqCwQfoTSdAVYcBiy93UPTGBgIdviYo3B+GAohiI8HZwEXPVk0TLWqNdnKmtszbRZp29dTKycENn7+b6Y9fh2jM3S7tU4MVb+SfuO4a50x7SDmb3vIxWZkFfoUO3a6V1FWjWY85pl4xAsPNE6Oa3FxStUvyp6kF7IRiPfO5BeR2BUqbf29NinW3CBHdgptPEb5m+bjZeGEgnO50g03l7btxdPsFmYh6oBMdP1hpImymYz54JQpFMhCxGF9vo0Vd0+5bRe/VJ5M0fqdH0VaY1+/nogMZKKCw3Ij6f7hrppVqO3iIMNf6XAqWmZIJkR3anfwA0xcOzp0xltcvS21buYWVlWpVeX7IPpdWU0M2Dq0tYmFbYkYXnO6NStya1lQ4i79kODQJuwZJvF4fObmZXiK/pfR51iR/YTYKauj6W3elX1q+42MH2nsFQpNhknsDJa9XgM+iqO X-Forefront-PRVS: 0192E812EC X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(39450400003)(199003)(189002)(53936002)(7736002)(33646002)(105586002)(5890100001)(8676002)(81156014)(81166006)(106356001)(36756003)(4001430100002)(66066001)(92566002)(47776003)(305945005)(86362001)(50226002)(68736007)(25786008)(6666003)(4326007)(3846002)(6116002)(6486002)(189998001)(48376002)(50466002)(101416001)(42186005)(5003940100001)(97736004)(5001770100001)(5660300001)(54906002)(107886002)(38730400001)(2906002)(50986999)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR0501MB837; H:gandalf.eng.vmware.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR0501MB837; 23:w98yeprDT+sERc6ev4A7Rr65VE78EwlGmcI71snk?= =?us-ascii?Q?6L7/REM0Oq9hTXucW6x+gs0GAU5MI8mAMIFdYaS4gzpATsVbvr+lkDkK+7Vd?= =?us-ascii?Q?kINajUMbcCbsLG+n3lAVVRMeWZcn/M54IK4J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xiuk2veXw1QY8mFaKLrQaH6/o9tcfnQ4VW0VCI8IX8fDR5BRzEKQWWX5IkwndLFXzF+TJ0c2QsKpS9gY4aRFjPCFfQgYTL94QKP5GbVqn+k4et+RnW9vS414hWlHoYHCs1KWvbL2zGgUaAZIWL7aFy3ctXAj7SjRf6oiqeqSkYIJ5CF1EwOS0mo9+89iP6yVMW3KfL7XNHD+P8SWiu9NZ1t1UzwN1/1NQMTItXB6gTqrwWhrNRQF8klKzUtIOxViLrLY3ij38J2MdMksF6eCOEoHazXdvCdmWFblepSQweoFxTDKu25E11TyQ4apsxhACtaYusbcK9C5gEd/i6c2t2kKurBsc6p0AqKm5HsHDfm1Z24YJTFfmApXBw==; 20:/nvr2o/BfuJezn+3VLH11JnmDmKqssadx3cKzjKWZf9/LQvLvjvuJMGncycBUOJxjgpth+Ua1bAtO+cnFP/kGldQtPwpY3wGZe1kGM0HS+cy4ZY5zS+B3hOBPWePA18vVmmMWfk+3045AWj7viwxt3njzrDLG6fDEIGQTldi0jk= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2017 16:56:18.3487 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR0501MB837 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Whenever a new RDMA device appears, the RDMA stack tries to attach each driver to the new device to see which is the correct driver. We need to check the vendor ID and device ID to make sure we don't accidentally attach to another device. Reviewed-by: Aditya Sarwade Signed-off-by: Bryan Tan Signed-off-by: Adit Ranadive --- providers/vmw_pvrdma/pvrdma_main.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/providers/vmw_pvrdma/pvrdma_main.c b/providers/vmw_pvrdma/pvrdma_main.c index 9a7e07b..7190efa 100644 --- a/providers/vmw_pvrdma/pvrdma_main.c +++ b/providers/vmw_pvrdma/pvrdma_main.c @@ -45,6 +45,12 @@ #include "pvrdma.h" +/* + * VMware PVRDMA vendor id and PCI device id. + */ +#define PCI_VENDOR_ID_VMWARE 0x15AD +#define PCI_DEVICE_ID_VMWARE_PVRDMA 0x0820 + static struct ibv_context_ops pvrdma_ctx_ops = { .query_device = pvrdma_query_device, .query_port = pvrdma_query_port, @@ -166,7 +172,22 @@ static struct pvrdma_device *pvrdma_driver_init_shared( int abi_version) { struct pvrdma_device *dev; - char name[16]; + char value[8]; + unsigned int vendor_id, device_id; + + if (ibv_read_sysfs_file(uverbs_sys_path, "device/vendor", + value, sizeof(value)) < 0) + return NULL; + vendor_id = strtol(value, NULL, 16); + + if (ibv_read_sysfs_file(uverbs_sys_path, "device/device", + value, sizeof(value)) < 0) + return NULL; + device_id = strtol(value, NULL, 16); + + if (vendor_id != PCI_VENDOR_ID_VMWARE || + device_id != PCI_DEVICE_ID_VMWARE_PVRDMA) + return NULL; /* We support only a single ABI version for now. */ if (abi_version != PVRDMA_UVERBS_ABI_VERSION) { @@ -177,12 +198,6 @@ static struct pvrdma_device *pvrdma_driver_init_shared( return NULL; } - if (ibv_read_sysfs_file(uverbs_sys_path, - "ibdev", name, sizeof(name)) < 0) { - fprintf(stderr, PFX "not ib device\n"); - return NULL; - } - dev = malloc(sizeof(*dev)); if (!dev) { fprintf(stderr, PFX "couldn't allocate device for %s\n",