Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1393226pxa; Sun, 2 Aug 2020 06:14:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/1HUi0XPlZJzCv++8HQhgB6i8F/Xt5e4GbLfMpKolJRhwPVpHi9PwIpVraIfVfaQQEShF X-Received: by 2002:a17:906:5346:: with SMTP id j6mr11856080ejo.311.1596374077727; Sun, 02 Aug 2020 06:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596374077; cv=none; d=google.com; s=arc-20160816; b=DVDXOigZfcAnV+0F4oRLFxPY2agqB4Evo+v/eRZJo1OHos9ibPtZIAZb0VyYuSWuYH fO6Lv1nJ1snrZPm+uKnLsYr3hl2lATH04DkXxEyPBw1Rifu+IV2CfCjGtzaxDQWqrm+y n8SeNI5VHG2sstWFnxSzCPNcnixK1YgLyW4Qhd90axDtmpB9bI01fh0/bZS87La7VtPL FQdOA7TzyiS7BG1SZ7H8v+JJp6vf8jseYJC9ok7dGmhedMEL0Jad18GdriQeN8tq4Wal KgOn+7+EJQoH7gFfX886OLLlN9pOa4kiWIeFfoU5J5TtcFv9GDhrXo6UDLRRrk2WGYI3 Osyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=ttQmdovSolBaWp4bXI+wy4+3dsK6c38Kpr6GgBTc58g=; b=Ge4c9OMSvRx+2iZrxyBTCSXEHPRh/olOFYXM7NzVBfMRIMSGyLxM6dntDbe8IFMq2L ZUGZUHMmQLw7wGrotlO8a7Kwsr5N7E4nFP6jdXIzyJVYieGW6znXWr2zwuo9Fk9N9mHX WH/O2A2pIH70lDi2UYdnF6XG6Uki8+VLVHB6d4s7gKr64GnpJPTm2pRl9NX2eEwUkrNl Zw6tCiSJQiWk75R5r+H4+PknWp0xljXlxGFXJTMBZBz9FH2lQRKcU8yB+vcs3XG+o8cd pR3Dp1eD+n4SwQDTxubDW7JXp3wmXHbm/YIIpWOsF/jrrvF1TSY3cfy8mkmwutclgdPz 1nEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si3858375edp.162.2020.08.02.06.13.52; Sun, 02 Aug 2020 06:14:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728279AbgHBNLc (ORCPT + 99 others); Sun, 2 Aug 2020 09:11:32 -0400 Received: from zg8tmja5ljk3lje4mi4ymjia.icoremail.net ([209.97.182.222]:45614 "HELO zg8tmja5ljk3lje4mi4ymjia.icoremail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726578AbgHBNLc (ORCPT ); Sun, 2 Aug 2020 09:11:32 -0400 Received: from oslab.tsinghua.edu.cn (unknown [166.111.139.112]) by app-5 (Coremail) with SMTP id EwQGZQCnrnJtuyZfHMLtAw--.12483S2; Sun, 02 Aug 2020 21:11:14 +0800 (CST) From: Jia-Ju Bai To: doshir@vmware.com, pv-drivers@vmware.com, davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] net: vmxnet3: avoid accessing the data mapped to streaming DMA Date: Sun, 2 Aug 2020 21:11:07 +0800 Message-Id: <20200802131107.15857-1-baijiaju@tsinghua.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: EwQGZQCnrnJtuyZfHMLtAw--.12483S2 X-Co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dovvfxof0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In vmxnet3_probe_device(), "adapter" is mapped to streaming DMA: adapter->adapter_pa = dma_map_single(..., adapter, ...); Then "adapter" is accessed at many places in this function. Theses accesses may cause data inconsistency between CPU cache and hardware. To fix this problem, dma_map_single() is called after these accesses. Signed-off-by: Jia-Ju Bai --- drivers/net/vmxnet3/vmxnet3_drv.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index ca395f9679d0..96a4c28ba429 100644 --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c @@ -3445,14 +3445,6 @@ vmxnet3_probe_device(struct pci_dev *pdev, } spin_lock_init(&adapter->cmd_lock); - adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter, - sizeof(struct vmxnet3_adapter), - PCI_DMA_TODEVICE); - if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) { - dev_err(&pdev->dev, "Failed to map dma\n"); - err = -EFAULT; - goto err_set_mask; - } adapter->shared = dma_alloc_coherent( &adapter->pdev->dev, sizeof(struct Vmxnet3_DriverShared), @@ -3628,6 +3620,16 @@ vmxnet3_probe_device(struct pci_dev *pdev, } vmxnet3_check_link(adapter, false); + + adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter, + sizeof(struct vmxnet3_adapter), + PCI_DMA_TODEVICE); + if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) { + dev_err(&pdev->dev, "Failed to map dma\n"); + err = -EFAULT; + goto err_register; + } + return 0; err_register: @@ -3655,8 +3657,6 @@ vmxnet3_probe_device(struct pci_dev *pdev, sizeof(struct Vmxnet3_DriverShared), adapter->shared, adapter->shared_pa); err_alloc_shared: - dma_unmap_single(&adapter->pdev->dev, adapter->adapter_pa, - sizeof(struct vmxnet3_adapter), PCI_DMA_TODEVICE); err_set_mask: free_netdev(netdev); return err; -- 2.17.1