From patchwork Wed Nov 13 20:00:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Johannesmeyer X-Patchwork-Id: 13874255 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E5AA206E63; Wed, 13 Nov 2024 20:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731528029; cv=none; b=RLC8eq8J+SQUIebmJPfqDtu8wh9k2RPWsRYJ9j0Pv+dLPrlXLx+RAeguR09rvEjPcWZq94TqMFye+xAD//B4FnaZYj6gNHcSFDHCOS9ZOmitA2itZZWWVzk8MY3dXGCnv6mP9cETl+YHINglGanguErsbBOnZZwMzlYP63sKg6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731528029; c=relaxed/simple; bh=d5viJel+82ljzhWK9mCPXgCaDSTDjH/J2BX+NnimVOk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n8RHYLObh6kCVMKcapttUI8I546tgACI+SEBmBKzgejq7vL9LhnhmXxn6AkSQHShWCqAZfjjBEFF61jcZDhUKTs3+bszp4tZLbFNcufzRDjOm6dQ6fBFC51hFEQmuiEeN9TtKPMQ6f2efPrbuwrDEY1fA3tJQGZTLX7Pm0q5O8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BJ8OKL9r; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BJ8OKL9r" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a9f1c590ecdso669941966b.1; Wed, 13 Nov 2024 12:00:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731528024; x=1732132824; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uVlI2r8n+S0FhsHSJ6kkX4Tar+jyuTTpMFKnYbDwCvM=; b=BJ8OKL9rf2lmTgaRqkaXNhkO/kbHHn5kE34RzI20ggIEa/SxwPEBGCeUKb21cIuVSP OiM1YkE4jkhI5N9wd3EAhqqTeO3W7PhMUYWTQ1hOUdaLZL0I0tcimNEAQa4/0OdpwJ/J +ZaShcz7/FhZFxb6xOFC1848Vs9PCid9U4FtJr9kj2mtET1VXA1bYu057a8SSdAm05zh LfVv6ajwAJMyvJnlYTug2yrnPr/jzp66cJO/VTlfUMI/phmLbSykat9ji+UpfDbZg4vD XbJH8YIELzjKpk3znd7JTjHnvBz+MnZmNhQqT9ySqUA/og9TBQ1KXlatLLa9bjeBqCgF bNvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731528024; x=1732132824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uVlI2r8n+S0FhsHSJ6kkX4Tar+jyuTTpMFKnYbDwCvM=; b=wwit3aTh2hv6ImrlplkkmGCl1DjE2LNfWHXmxGDf7N6w//sVuJXG9pJYq+krnuqlMn rhwM9Kn3wU9QRwDGSqvl5wOmmuE8aG7bvOPmyraWKOMJ4E1V4er+wD8jtHzREa3ytnJq iMKbPiwz5zBpUytie/LLZptKIsYIZubW5AodPouBLk+YdWk7oHGEm5G4SVMbKtjrxtzI +5XdMtJ6osd4EXhgyW7WklmvbSkflqqEMi3Z5MZA3p8tWbFhSD9rlfOZyYotDimeFdz3 LvZIgNtO/8/E0YuBaLe+Wldd/q2WfuUL3EC4telGyC+MWw7SgcHjKKRw7PKVJrDEi0+G 8MPA== X-Forwarded-Encrypted: i=1; AJvYcCUyBCeJpt1VK9AhDYSXat5TZLRSupZCqX8ZZS+YARQi/KlwKtszLnWL8UEqCOPqJTESIRgvt6FA@vger.kernel.org, AJvYcCWAsdZjGHX/7aDHtkas1gBVYKugj7Td5hmHhiid5wtYIfODKrpL18b/OajdT35ZC4CwkJwTqHG9s0TE1Ks=@vger.kernel.org X-Gm-Message-State: AOJu0YygJMXzl671t4ycNPbyVt8u7ZlH9soQl3vaYB0X97Maf5gDNiLx dxuuqnCqnMYkXQauD2iIk3WdA0eMVMhqEpeP+7sueIuHPPiMarOo X-Google-Smtp-Source: AGHT+IGyAcftxKD33p1adczISEa+8uVQe/SrQh3kWlJBDNwqWiuUASq8P7YyCPSja4Og4uiuI9na2g== X-Received: by 2002:a17:907:5ca:b0:a9e:c947:d5e5 with SMTP id a640c23a62f3a-aa1f807701bmr351520466b.28.1731528024357; Wed, 13 Nov 2024 12:00:24 -0800 (PST) Received: from rex.hwlab.vusec.net (lab-4.lab.cs.vu.nl. [192.33.36.4]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9efd2fe9fdsm675016066b.132.2024.11.13.12.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 12:00:24 -0800 (PST) From: Brian Johannesmeyer To: Ronak Doshi , Broadcom internal kernel review list , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andy King , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Brian Johannesmeyer , Raphael Isemann Subject: [PATCH 1/2] vmxnet3: Fix inconsistent DMA accesses in vmxnet3_probe_device() Date: Wed, 13 Nov 2024 21:00:00 +0100 Message-Id: <20241113200001.3567479-2-bjohannesmeyer@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113200001.3567479-1-bjohannesmeyer@gmail.com> References: <20241113200001.3567479-1-bjohannesmeyer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org After mapping `adapter` to streaming DMA, but before accessing it, synchronize it to the CPU. Then, before returning, synchronize it back to the device. This mitigates any inconsistent accesses to it from vmxnet3_probe_device(). Co-developed-by: Raphael Isemann Signed-off-by: Raphael Isemann Signed-off-by: Brian Johannesmeyer --- drivers/net/vmxnet3/vmxnet3_drv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index 7fa74b8b2100..cc76134c7db4 100644 --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c @@ -3623,6 +3623,8 @@ vmxnet3_probe_device(struct pci_dev *pdev, int num_rx_queues; int queues; unsigned long flags; + struct device *dev; + dma_addr_t adapter_pa; if (!pci_msi_enabled()) enable_mq = 0; @@ -3662,14 +3664,19 @@ vmxnet3_probe_device(struct pci_dev *pdev, } spin_lock_init(&adapter->cmd_lock); - adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter, + dev = &adapter->pdev->dev; + adapter_pa = dma_map_single(dev, adapter, sizeof(struct vmxnet3_adapter), DMA_TO_DEVICE); - if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) { + if (dma_mapping_error(dev, adapter_pa)) { dev_err(&pdev->dev, "Failed to map dma\n"); err = -EFAULT; goto err_set_mask; } + dma_sync_single_for_cpu(dev, adapter_pa, + sizeof(struct vmxnet3_adapter), DMA_TO_DEVICE); + adapter->adapter_pa = adapter_pa; + adapter->shared = dma_alloc_coherent( &adapter->pdev->dev, sizeof(struct Vmxnet3_DriverShared), @@ -3928,6 +3935,8 @@ vmxnet3_probe_device(struct pci_dev *pdev, } vmxnet3_check_link(adapter, false); + dma_sync_single_for_device(dev, adapter_pa, + sizeof(struct vmxnet3_adapter), DMA_TO_DEVICE); return 0; err_register: From patchwork Wed Nov 13 20:00:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Johannesmeyer X-Patchwork-Id: 13874256 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5721A2071EF; Wed, 13 Nov 2024 20:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731528030; cv=none; b=pZlG0d+u2720Z+SHnTVOXWiCGdLDBCaZeaL4jeiQetS2mS/qM3H5pWuTpT8swhZb3HYPqyh+g7LWn0EEluSw1iNS25PBbzq2hXJn1wlIgijqpiUguM7JlxS7d0mvjpPKlYkB7cpTEU/WCOUH321ckua4vel1J6BQkfnUP6Bc7SQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731528030; c=relaxed/simple; bh=bxvXj0rYTEUIuTo+oE6Fsv17g+bx+ZviM+T2flCinDA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=SF6lnOW9NluuB1VbtZSkoxgtjvwlwos1zz78lTSIyhOUBwPayXnxv8Jv1gc4rMWV3u/EN1b7/kom41r16fF3mtJ1DxSZz9cjeJnmNQd3wMP/0QXOiVnw/kAiDK0gr1/ggmYkHGnQabTJiTWmaWzVbMCiomC1wr099u1lyDNDMjk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QUHJD+Iq; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QUHJD+Iq" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2fb5fa911aaso101683161fa.2; Wed, 13 Nov 2024 12:00:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731528026; x=1732132826; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yNoagPAPa8LF4vkYrXReGe3nCeerUu69H6SQLVJho/s=; b=QUHJD+IqjSd2ReFj7y1VdgZujw1PvtGmB7bEn+M6Na75tTFDzyAj/uA+NZgqfkPlle htF9QKfNoaWvD2tL7zNr+X7DNpSENQkeraDjo1x2PFPNvRdPtFFN3Sd7wnzQ41JPsBIw iEhFzKVUfa0uDQmXM1O0c1kzQgbHrFTndP0DCC2WUhjd5a02aobuOX/F+UH5pfkGRmEg BQaHOMeaFoC4voZlMR9U5jTrJkVaKP/T169fhI/6drjmnCxTo+rilLiwwTXILzgPJZM6 Hxj0IeSLPHx2F8JuuF/dBYwkZgsLwtqlqCbEAcRwgXTn1veYkQbSeWzOX1SSQMwM7zAP tWUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731528026; x=1732132826; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yNoagPAPa8LF4vkYrXReGe3nCeerUu69H6SQLVJho/s=; b=gVu2SPtEhraIn8vAb4ar1bG+bW6dOIEVN1SfSnM3JHBP82DuB/125GZN7LSv0aQYVo yZ8HmjRku0Axz3LWSXO94odk9oE/kp6UBk8qTy/JkNus6KPHVTeIFyhn7AC4ZRIkasFI cBedFJQncQI/38NIwt3tQ4GQ7iwya5UML+96Z1up5gRkFix36MmBixdufeQs0yboVLHJ AA68a9cJS9mnhcvsA6BZJFYaHdj8ZVOQMqu+mLNF8BCnqHMZ1v5zU0+Sy7Aeqx6Yg5so wjKivKL6GbmcrTYi1YIOXLOarhRPQbfy7pWBYXAs2EfwZ7cpujHaZBsT2tXJOdzuLsAx SdWA== X-Forwarded-Encrypted: i=1; AJvYcCW3YYl/VWkcZwXcJJ758FrACkLZfrw6kFeF6933aUkYeZZTlCNzU0TzLl4FbV4MH4yWg5M7Big5vk4oOsM=@vger.kernel.org, AJvYcCW5iYil2C1Txa485SrujCfs+OedfVJcTjmpz6H3YZLLZupgRa8d/cmHCtHZPYisdLr9plkFHGbJ@vger.kernel.org X-Gm-Message-State: AOJu0Yy35qjuPt1/8LKVLLxC5/tD6XXLTrKKPeK1WNOaXm2dYxcJkp8O u1vG6SzL7ItIYrxYvkTabhe/Ktx/McCIce7hX1AdCx4iOOQYBtUC X-Google-Smtp-Source: AGHT+IHZ2iTOwACBsmAVacJwB6oQq4aacfYJnaFDukytp6B0W/wrdrWtkSP4TAASrmzLdcFTHZgr4g== X-Received: by 2002:a2e:a9a4:0:b0:2fb:63b5:c0bc with SMTP id 38308e7fff4ca-2ff20162837mr146723531fa.3.1731528026079; Wed, 13 Nov 2024 12:00:26 -0800 (PST) Received: from rex.hwlab.vusec.net (lab-4.lab.cs.vu.nl. [192.33.36.4]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9efd2fe9fdsm675016066b.132.2024.11.13.12.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 12:00:25 -0800 (PST) From: Brian Johannesmeyer To: Ronak Doshi , Broadcom internal kernel review list , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andy King , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Brian Johannesmeyer , Raphael Isemann Subject: [PATCH 2/2] vmxnet3: Remove adapter from DMA region Date: Wed, 13 Nov 2024 21:00:01 +0100 Message-Id: <20241113200001.3567479-3-bjohannesmeyer@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241113200001.3567479-1-bjohannesmeyer@gmail.com> References: <20241113200001.3567479-1-bjohannesmeyer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Revert parts of [0] that map `adapter` into a streaming DMA region. Also revert any other DMA-related uses of `adapter`. Doing so mitigates all inconsistent accesses to it. [0] commit b0eb57cb97e7837ebb746404c2c58c6f536f23fa ("VMXNET3: Add support for virtual IOMMU") Co-developed-by: Raphael Isemann Signed-off-by: Raphael Isemann Signed-off-by: Brian Johannesmeyer --- drivers/net/vmxnet3/vmxnet3_drv.c | 26 ++------------------------ drivers/net/vmxnet3/vmxnet3_int.h | 1 - 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index cc76134c7db4..5219992f6a63 100644 --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c @@ -2605,7 +2605,7 @@ vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter) devRead->misc.driverInfo.vmxnet3RevSpt = cpu_to_le32(1); devRead->misc.driverInfo.uptVerSpt = cpu_to_le32(1); - devRead->misc.ddPA = cpu_to_le64(adapter->adapter_pa); + devRead->misc.ddPA = cpu_to_le64(virt_to_phys(adapter)); devRead->misc.ddLen = cpu_to_le32(sizeof(struct vmxnet3_adapter)); /* set up feature flags */ @@ -3623,8 +3623,6 @@ vmxnet3_probe_device(struct pci_dev *pdev, int num_rx_queues; int queues; unsigned long flags; - struct device *dev; - dma_addr_t adapter_pa; if (!pci_msi_enabled()) enable_mq = 0; @@ -3664,19 +3662,6 @@ vmxnet3_probe_device(struct pci_dev *pdev, } spin_lock_init(&adapter->cmd_lock); - dev = &adapter->pdev->dev; - adapter_pa = dma_map_single(dev, adapter, - sizeof(struct vmxnet3_adapter), - DMA_TO_DEVICE); - if (dma_mapping_error(dev, adapter_pa)) { - dev_err(&pdev->dev, "Failed to map dma\n"); - err = -EFAULT; - goto err_set_mask; - } - dma_sync_single_for_cpu(dev, adapter_pa, - sizeof(struct vmxnet3_adapter), DMA_TO_DEVICE); - adapter->adapter_pa = adapter_pa; - adapter->shared = dma_alloc_coherent( &adapter->pdev->dev, sizeof(struct Vmxnet3_DriverShared), @@ -3684,7 +3669,7 @@ vmxnet3_probe_device(struct pci_dev *pdev, if (!adapter->shared) { dev_err(&pdev->dev, "Failed to allocate memory\n"); err = -ENOMEM; - goto err_alloc_shared; + goto err_set_mask; } err = vmxnet3_alloc_pci_resources(adapter); @@ -3935,8 +3920,6 @@ vmxnet3_probe_device(struct pci_dev *pdev, } vmxnet3_check_link(adapter, false); - dma_sync_single_for_device(dev, adapter_pa, - sizeof(struct vmxnet3_adapter), DMA_TO_DEVICE); return 0; err_register: @@ -3963,9 +3946,6 @@ vmxnet3_probe_device(struct pci_dev *pdev, dma_free_coherent(&adapter->pdev->dev, 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), DMA_TO_DEVICE); err_set_mask: free_netdev(netdev); return err; @@ -4032,8 +4012,6 @@ vmxnet3_remove_device(struct pci_dev *pdev) dma_free_coherent(&adapter->pdev->dev, sizeof(struct Vmxnet3_DriverShared), adapter->shared, adapter->shared_pa); - dma_unmap_single(&adapter->pdev->dev, adapter->adapter_pa, - sizeof(struct vmxnet3_adapter), DMA_TO_DEVICE); free_netdev(netdev); } diff --git a/drivers/net/vmxnet3/vmxnet3_int.h b/drivers/net/vmxnet3/vmxnet3_int.h index 3367db23aa13..b45ed1045ca3 100644 --- a/drivers/net/vmxnet3/vmxnet3_int.h +++ b/drivers/net/vmxnet3/vmxnet3_int.h @@ -404,7 +404,6 @@ struct vmxnet3_adapter { struct Vmxnet3_CoalesceScheme *coal_conf; bool default_coal_mode; - dma_addr_t adapter_pa; dma_addr_t pm_conf_pa; dma_addr_t rss_conf_pa; bool queuesExtEnabled;