Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1961001imm; Thu, 24 May 2018 03:38:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqRrWHm8gXYXQLbcE5binXWEMCXBQQfGDNisNjrWJFeDpbumTxFk6ZD6rWXYYnG1EziiCKA X-Received: by 2002:a63:2b46:: with SMTP id r67-v6mr5296736pgr.89.1527158322240; Thu, 24 May 2018 03:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158322; cv=none; d=google.com; s=arc-20160816; b=IzKpDtx+/RDA0zTPBSbRogRUHWkwoFMqWETOaoVagkJ3sQ39BuRVFpEtsF971/fbfq q3AOTwgEsWcFnUiS8roFaGJ7EIHhvD1i48+kPJFkufmOzPYrFeqldswD3gVnDcUebR6f Ecqm7WSnzpB9wrFdVO56HK95yI2Jd/dX1YmE3m1dj+td6pFrNkvDJvkBxxbn2CtJcC76 2dOAfBjubJArvHBG98wGQx4N5dCWf2P+KrsmEXu3bGKf/kIpzosVbBIFfT3/uMCa35D+ 0UnP/5weP77EE/44iC00RdbLvxZDcpeoWw+h9Y9qPRZYF2gabIHV3UjbVXYYnxfEyQGq WgxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=bjEqpNhxap4Hv+q/Nbfrs7WbvFtd8VQiKqdgwkQNW4w=; b=PlVYJMJCImP8vbhfRmYVa7TvgUDlrUpW0hluUZCx+5Hm9WE2i9fq4KCniAUx3k9MDq f/vL30N7erUGZODy43Kkr6cbFPpZ83fnXoOWXF4Hs6A5ddPZA4+3ZYuOvnxyrja0V57V GulOmypgd/Y+Wc6FMQTBl7jHFspsDcDKWC/QfcOaCy/tQI5i1m23kqe+2FVCsHLDNqhq aF1jbN7n1rnVyYC7zGpTVRHBwGMne/LFJ/TT/vCk9MNWcVZrJZWhklQ//aw6rTw+DYpC bZJ+1aDSaqCIamq0cTcJE9rXsfpC7Tnfq4h7wjFA2YjXDo2orbuEs9jCHPzigRDeJ3qj wvhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZOBJO+M9; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5-v6si16593620pgp.379.2018.05.24.03.38.27; Thu, 24 May 2018 03:38:42 -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=@kernel.org header.s=default header.b=ZOBJO+M9; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030811AbeEXJ7p (ORCPT + 99 others); Thu, 24 May 2018 05:59:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:40792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030798AbeEXJ7k (ORCPT ); Thu, 24 May 2018 05:59:40 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DA32D20870; Thu, 24 May 2018 09:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155979; bh=7h+L3DNxytcf7mllwov4DzyhVRsPZ1FuZmM4D3b40rU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOBJO+M9GN1rb+WpRarMmAc+fv07T7Kyrw5pUE9saJ4PySg0OBnafeoF6wkHePp1W vd+C4hE3RD5/SJtTbqdhw11nRovFKGZdQj6ugciJMjy4hBx9aTp37lEXOS5gQcKVYk 2tnb/U0uuz6Be84FH63LPQtVI1q4+WztVPV0Z5DU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Regis Duchesne , Ronak Doshi , "David S. Miller" Subject: [PATCH 4.16 020/161] vmxnet3: set the DMA mask before the first DMA map operation Date: Thu, 24 May 2018 11:37:25 +0200 Message-Id: <20180524093020.751820220@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: "hpreg@vmware.com" [ Upstream commit 61aeecea40afb2b89933e27cd4adb10fc2e75cfd ] The DMA mask must be set before, not after, the first DMA map operation, or the first DMA map operation could in theory fail on some systems. Fixes: b0eb57cb97e78 ("VMXNET3: Add support for virtual IOMMU") Signed-off-by: Regis Duchesne Acked-by: Ronak Doshi Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/vmxnet3/vmxnet3_drv.c | 50 +++++++++++++++++++------------------- drivers/net/vmxnet3/vmxnet3_int.h | 8 +++--- 2 files changed, 30 insertions(+), 28 deletions(-) --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c @@ -2688,7 +2688,7 @@ vmxnet3_set_mac_addr(struct net_device * /* ==================== initialization and cleanup routines ============ */ static int -vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter, bool *dma64) +vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter) { int err; unsigned long mmio_start, mmio_len; @@ -2700,30 +2700,12 @@ vmxnet3_alloc_pci_resources(struct vmxne return err; } - if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) { - if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { - dev_err(&pdev->dev, - "pci_set_consistent_dma_mask failed\n"); - err = -EIO; - goto err_set_mask; - } - *dma64 = true; - } else { - if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { - dev_err(&pdev->dev, - "pci_set_dma_mask failed\n"); - err = -EIO; - goto err_set_mask; - } - *dma64 = false; - } - err = pci_request_selected_regions(pdev, (1 << 2) - 1, vmxnet3_driver_name); if (err) { dev_err(&pdev->dev, "Failed to request region for adapter: error %d\n", err); - goto err_set_mask; + goto err_enable_device; } pci_set_master(pdev); @@ -2751,7 +2733,7 @@ err_bar1: iounmap(adapter->hw_addr0); err_ioremap: pci_release_selected_regions(pdev, (1 << 2) - 1); -err_set_mask: +err_enable_device: pci_disable_device(pdev); return err; } @@ -3254,7 +3236,7 @@ vmxnet3_probe_device(struct pci_dev *pde #endif }; int err; - bool dma64 = false; /* stupid gcc */ + bool dma64; u32 ver; struct net_device *netdev; struct vmxnet3_adapter *adapter; @@ -3300,6 +3282,24 @@ vmxnet3_probe_device(struct pci_dev *pde adapter->rx_ring_size = VMXNET3_DEF_RX_RING_SIZE; adapter->rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE; + if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) { + if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { + dev_err(&pdev->dev, + "pci_set_consistent_dma_mask failed\n"); + err = -EIO; + goto err_set_mask; + } + dma64 = true; + } else { + if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { + dev_err(&pdev->dev, + "pci_set_dma_mask failed\n"); + err = -EIO; + goto err_set_mask; + } + dma64 = false; + } + spin_lock_init(&adapter->cmd_lock); adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter, sizeof(struct vmxnet3_adapter), @@ -3307,7 +3307,7 @@ vmxnet3_probe_device(struct pci_dev *pde if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) { dev_err(&pdev->dev, "Failed to map dma\n"); err = -EFAULT; - goto err_dma_map; + goto err_set_mask; } adapter->shared = dma_alloc_coherent( &adapter->pdev->dev, @@ -3358,7 +3358,7 @@ vmxnet3_probe_device(struct pci_dev *pde } #endif /* VMXNET3_RSS */ - err = vmxnet3_alloc_pci_resources(adapter, &dma64); + err = vmxnet3_alloc_pci_resources(adapter); if (err < 0) goto err_alloc_pci; @@ -3504,7 +3504,7 @@ err_alloc_queue_desc: err_alloc_shared: dma_unmap_single(&adapter->pdev->dev, adapter->adapter_pa, sizeof(struct vmxnet3_adapter), PCI_DMA_TODEVICE); -err_dma_map: +err_set_mask: free_netdev(netdev); return err; } --- a/drivers/net/vmxnet3/vmxnet3_int.h +++ b/drivers/net/vmxnet3/vmxnet3_int.h @@ -69,10 +69,12 @@ /* * Version numbers */ -#define VMXNET3_DRIVER_VERSION_STRING "1.4.14.0-k" +#define VMXNET3_DRIVER_VERSION_STRING "1.4.15.0-k" -/* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */ -#define VMXNET3_DRIVER_VERSION_NUM 0x01040e00 +/* Each byte of this 32-bit integer encodes a version number in + * VMXNET3_DRIVER_VERSION_STRING. + */ +#define VMXNET3_DRIVER_VERSION_NUM 0x01040f00 #if defined(CONFIG_PCI_MSI) /* RSS only makes sense if MSI-X is supported. */