From patchwork Tue Nov 19 22:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Johannesmeyer X-Patchwork-Id: 13880587 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 C3D0B1D5CDB; Tue, 19 Nov 2024 22:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054443; cv=none; b=dTmhn0gaqzEt6Uw69sImGukQr21V4/U3CV7UuebT6GC/v56j+aijFP67dNPgl/bpk28ZoCdyejS14d5mFuJE2+zZd8biu6Kc65QgdcJGU8TQM6nLFaMoasizY+WHrr/SpKm8oeCCqni/WnImhqRFpWoXBNuR2/f2THl6YOuVV58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054443; c=relaxed/simple; bh=lzP7Gvkcx/FmhvwQSpENog9t68uKeMkJZy5qk0I1338=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oKgL2QjJA58FLcsTW/n5e/plVKBr/jv43yjD0D6i8JnX4sGC2a1wq/evHYX/vpaRsMO/Isoxye8vgOVJDz7REXQywvNUwSmiMxn2S31uVRumP2OsnpA+Nq2N77R8IB6i1Oiw1PtdYRsStx/t1QP+1QgRw6Qr5IC0uhsbWuNACII= 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=eNxHbz+G; arc=none smtp.client-ip=209.85.208.41 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="eNxHbz+G" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5c9c28c1ecbso2085105a12.0; Tue, 19 Nov 2024 14:14:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732054440; x=1732659240; 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=jLg3Zgz+FEDEY+dTOsaG0ncu4gz3SWEdaD0wc9B4rSY=; b=eNxHbz+Gq/W1hz5k+I/CsiJCAZXmQkeRp9OtcZAK3hW2pM2WXICWsfbE9eMOmOy4U3 qWKTmcOYyZDK25p2EzUM0IZykgwmcbgKz6Qfm69lfuJ6BbK2zIzrHy+DpfPeILGBNuIY bTCi0NNiO/GcwswP460LYFrD8bbTxDrEH3JdLv7fMxqBRKiYzkxzSfx1dEh7c73rB9OQ 5UnmeZv+oV4HpIi0JfSFwSSvZ0F0ynmi8MP2UZUHbxPXJh6i3k/Gp3dSeUCh/eHa9ocW YXfMyAQE809VGsLKCE/qZxuj+V+D1xT5C2fQdNQFD8hsE1xkJs6V++KVzyzxIs3QbPzO h2dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732054440; x=1732659240; 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=jLg3Zgz+FEDEY+dTOsaG0ncu4gz3SWEdaD0wc9B4rSY=; b=GOcInnjg49R0RMaAXbM+H6gPcwLyZQBvT3BxzE5UZFJtk1pZS/UGypGxyypvfQMada EH17lvx4YB2muTVdmzd5shE72L7qEKrjqaHOwbGVKJbD2/8sqg5xDacBEEPHyO3/xGhM 5N5C11A6EuYkd3amHp+EmB/dUvbcAi9Dj2L+YhN8pwcS6tre8wRrep42HlFYFzFslSMn m04+hOXuhabIPUmbpA+dvza2WsMpd2O24If+wqdFII13ta2R0JYcsuLjxRayqT3Op1Kq XqflkJ0/PgAtfjkEEptxi4Z3GQNU1LKfOaY+pUdz7Zi+2J310YhtS7t6PyodpvM1+xSN gSIw== X-Forwarded-Encrypted: i=1; AJvYcCUoXt2kfm63qVdQEAWoy3J/7ZjdmH27/1K7QPExlXhOdl/JaK36Zpb81DBBiMz6liuoYfcN7J5zcPDPsrg=@vger.kernel.org, AJvYcCWlz/6fJeqi8BzNV3sFk3ou4uUhUN2EKAggDSJtipvynl6XaQBgE4SsUZEC+iLzP/4N1TcfxmWG@vger.kernel.org X-Gm-Message-State: AOJu0YzmFqG6MDKPLO67zri9VD5LLQdFVo6TGJPLBcKfVJ8DsxVYAHWb bBO1+KtLv8blFbYMBwNLaRAJJCNz3hkCEq/wke2TbPn7dq8COAQZ X-Google-Smtp-Source: AGHT+IF/SBX+B2+021nCX1tdeI9ozu3Mfn3ca5/E2iXbH7GqBvRnxzsFafGMnb4PILGaYjVb+4BGLw== X-Received: by 2002:a05:6402:524a:b0:5cf:e218:a4ae with SMTP id 4fb4d7f45d1cf-5cff4cdd75dmr163238a12.31.1732054439744; Tue, 19 Nov 2024 14:13:59 -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 4fb4d7f45d1cf-5cff45504fcsm133484a12.89.2024.11.19.14.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 14:13:59 -0800 (PST) From: Brian Johannesmeyer To: Ronak Doshi , Broadcom internal kernel review list , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Brian Johannesmeyer , Raphael Isemann , Cristiano Giuffrida , Herbert Bos Subject: [RFC v2 1/2] vmxnet3: Fix inconsistent DMA accesses in vmxnet3_probe_device() Date: Tue, 19 Nov 2024 23:13:53 +0100 Message-Id: <20241119221353.3912257-3-bjohannesmeyer@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241119221353.3912257-1-bjohannesmeyer@gmail.com> References: <20241119221353.3912257-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 X-Patchwork-State: RFC 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 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index 7fa74b8b2100..032d3cd34be1 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, - sizeof(struct vmxnet3_adapter), - DMA_TO_DEVICE); - if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) { + 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), @@ -3928,6 +3935,9 @@ 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 Tue Nov 19 22:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Johannesmeyer X-Patchwork-Id: 13880586 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 499901D2F64; Tue, 19 Nov 2024 22:14:00 +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=1732054442; cv=none; b=HaP3FiIiHiJ0FLDRFpxiR+mGnORX5VlxXJQbocVofV+EsDcl0h0bR4bwTquzVcuUQxF+9RW7RzxkXHL0U2HeDBz5gQRIFYny59VNE4Ss5YHY5x+uugzMyHCgC8TmAFdni2A+igf7kYq3fSAbw7UeOkvw+/u+wI0k+BJWs4EL+0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054442; c=relaxed/simple; bh=20DSJPorGLDBUaY58IT/e03JwEmC8787005QWBAWWMk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MFrAtk9hT+KPaWMk0uvWDkD0URJb0X7B1AB+OpYnD8oIdie/ER0l5zlhOb3JSCjOb9bObRxuiBeGvgWQ3ldk5cNSHYlOJNO8WLRP3uyp1qG4zFXaDWzfU+HScF4+6ZNwrH5AyytVUyjve9L/dEQA2Q+fM8zX1dopuZ6H1iJdt4I= 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=No8YYIBE; 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="No8YYIBE" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2fb388e64b0so58979381fa.0; Tue, 19 Nov 2024 14:14:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732054438; x=1732659238; 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=yF+XhgMq2qb2Fhx8mba/c1UDE5pPRHsVLVN7iX8+ig4=; b=No8YYIBEUZtbOa3DDNczpSIHwYVSEqkVl6/BfLplHtKjHhYStCV5u9rHNrvLDWyyoh p5XbmMfMKEWT7ZaVohKseNs3XOmMejLOswWUnDdKTeFLUvxhGP2+cEmufsI1x8RN2CZK p5lkz+0+xZ6df6WrHZH8BVrTwbQGYTGZjRhyngk9mN0tdHfgc3UgOUHtXtaRQ5pR/H+B kQHPuvE6ADP/NAqHmmAYmtbxFUwNptEykvjWRw/sPIQgOWWL16pJg99s4fnOgnteAqdd a74Let7Y7xxVCWE26gNJlAw3AkXjZU8nNssPqE8prqzMQy76PXxOmBLLHE9ZXB2Izc+J lvmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732054438; x=1732659238; 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=yF+XhgMq2qb2Fhx8mba/c1UDE5pPRHsVLVN7iX8+ig4=; b=l5c7wsrRUrL7AClGVgOIou4FxbWOycsR0M+u2nBowPgQc2xHgFjGNNw3xTLvmWO0BN Bi3xC7Is+qTCBuIB+kjaPdD1xWf87vER26VM/IjESgTy43bnDl8e6rdORiQNuMfPgbpW 8bZEPb8nx9PaSBMWdpcIqk8LEb/hcN0Gzzatsz7AxTWnfe+QRw9fcq2tmixqxUVRh+cH n/jziyR4ooezojW4vq2E2JcylRhvS0ZgGg2Hyybm5CasraIL7PRmF6ovC4f7NV0H7Caj G8bLlfL6nMOGhO8+BSwKsVSUcIKbdpWgf/v8OnWl03ZvJKbkpY0I0OaKMmK/ZH/r5SeL DUrA== X-Forwarded-Encrypted: i=1; AJvYcCUk4P9utex/l3dVSUHBa3DpsC86vi2W8QgeqjoralEm6ntd86uh9+FLZRjbbg59DIrOcJeYOhNK@vger.kernel.org, AJvYcCWw2Q/1pnIgqTOVER8/kl+Kxo/r79qRaPXWSHBdLt/3NZL75cdc47EuNoyNKURfMQB0RNnYHTtT7KE+QtE=@vger.kernel.org X-Gm-Message-State: AOJu0YzwoCrhYmof2gCnh+4BSpVIFPaUWdCw+4A7XQZ6sx7apE6Izo+q eXEegQ1r4Qsj0wx9xeoa/r09YAD0HET7nf3jjaMUZ9Yhy1DNFThf X-Google-Smtp-Source: AGHT+IGwviVTzfFewQBiJN59FgjgGN1Q2YqXT6ceUhaJ8bzaBn5hts1h0p/jcAXeMOQpddMmOWph1A== X-Received: by 2002:a05:651c:b14:b0:2fb:51e0:93f with SMTP id 38308e7fff4ca-2ff8dcf7836mr3185801fa.35.1732054438248; Tue, 19 Nov 2024 14:13:58 -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 4fb4d7f45d1cf-5cff45504fcsm133484a12.89.2024.11.19.14.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 14:13:57 -0800 (PST) From: Brian Johannesmeyer To: Ronak Doshi , Broadcom internal kernel review list , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Brian Johannesmeyer , Raphael Isemann , Cristiano Giuffrida , Herbert Bos Subject: [RFC v2 2/2] vmxnet3: Remove adapter from DMA region Date: Tue, 19 Nov 2024 23:13:52 +0100 Message-Id: <20241119221353.3912257-2-bjohannesmeyer@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241119221353.3912257-1-bjohannesmeyer@gmail.com> References: <20241119221353.3912257-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 X-Patchwork-State: RFC 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 | 17 ++--------------- drivers/net/vmxnet3/vmxnet3_int.h | 1 - 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index 7fa74b8b2100..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 */ @@ -3662,14 +3662,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), - DMA_TO_DEVICE); - 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), @@ -3677,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); @@ -3954,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; @@ -4023,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;