From patchwork Wed Jan 31 19:17:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 194913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2109024dyb; Wed, 31 Jan 2024 11:18:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhp2KDtq8R/zzc9UnnKmc61ot6ybK1f8eTD2u6cbNQjNfyc7PuBYNsXjpqJb9Zf8KD0lcR X-Received: by 2002:aa7:c718:0:b0:55f:43e2:56c8 with SMTP id i24-20020aa7c718000000b0055f43e256c8mr85796edq.38.1706728723464; Wed, 31 Jan 2024 11:18:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706728723; cv=pass; d=google.com; s=arc-20160816; b=h5xcigjl/PWRszWmyD8KL7wmxmVkqQjn8VT1hXoo2N7dOW07dAPpKF11+1mKh3Wczm nY26d60FJ6SK8fkqY1i9rZFkotBf/P/poJYgPENp/Il0r1x3GS+8mi3+eF//C1a6DHeI Qxw8ICDXr7Xo3Tjj67Z+ochPo9TImrYBe+N0mZMfVmwzAXLG3NUpoBkJ8PAVmgi00hud wRiOqSaVeEPc5jMCfSKZPKixFXyZrZee8nQyEFUdPfz85nwgC3NJJvamITyNpkDbw3lY 8B7QB+VLAQF/IUbpArxnJ7OhXt+kCS42YiTKY9YxqLwQI69V/SJ80iH59t8AYU83UMZ1 AV+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lGf8V7YbO8S1JxykOgAqwJn9BdraNH1lFGF1LdAyQdg=; fh=dGpp3Q63UGOPxj0yZr53DqMWfPCuJwsvZyzwJoY6aPI=; b=PnWYdmSpO9jTbOBw/AhHVi6Frf48ugall/otETlvm/lL1PXIoUmlSWWGyjuo1PkgiF aLBca1cISVKd3ySQwQDtqcz5n5kOjmEu7Cj7jkMDZGpt2pdO2IeMZ785f7wQrzokRU4h aYF5mETqNY3tDiQy3BzJ3/XfoKao4XX00or5n8zKJMRmQTff9tsT/WRNfqAwRv8bYGmX KExdQtXHeMuxJnXw0s5kNnh4B8IrZBifugUQQflSX79yHR8BWH7cAyLmfuNcroM95uEC 1XF107WZdFOTNvPYn8zoYpzZ7umBu2fpf4KzOfROiKs8z/lBVdf01x42W14n+VSmoMnu Tafg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gnAQ8c7l; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47010-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47010-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCUZQYdMNqDCoO/2yBm4koTtMwQPHAxE7pbltHQnpbJIviWZXEcxa6mCDpeIRQfgvMeMm0ZViFAA8dDKUe/nrE/RRNIr+A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w14-20020a05640234ce00b00557392e2ed6si5893346edc.429.2024.01.31.11.18.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:18:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47010-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gnAQ8c7l; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47010-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47010-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1A3F71F25B65 for ; Wed, 31 Jan 2024 19:18:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A14E138F94; Wed, 31 Jan 2024 19:18:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gnAQ8c7l" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBA6338387 for ; Wed, 31 Jan 2024 19:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706728680; cv=none; b=p9W+Xf44pGPjBN3jL1bz8o63kvlzJiezz4bLeUIS6pQPxnSpdy5w4B+of9i6mRAB7K7lkksrwEOeT4vbUUTQDvyY2q0zd+aq/KpwrncnCwsofd84Z0r4RjxMV/2VyiEKAZthRFbHrIRqE5DjmmRaYNbFP5MsEGarfOSMnGVrZLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706728680; c=relaxed/simple; bh=2DnmIvdGmjURmShJtRCsEJMDdPmjxWUH1IKPlXRajfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IINaTiFGB3zegt8ok+tNINp+Rgmo6hAvXOOipWmlXeANjG5u62utGjY3uAErXn+ws5qzyTuYKC2hCUimntzJitMJcaP9XRgfODS678NCGUAjztJo98mt5jRViYq7CwGQQ42CjjINyrrNlWp+s3WB16F8tu6M6uRudgv2QPJpROs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gnAQ8c7l; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706728677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lGf8V7YbO8S1JxykOgAqwJn9BdraNH1lFGF1LdAyQdg=; b=gnAQ8c7l1RRHHn8MqZPNnBJLi/XfhK2fLwmhywPLS7gUhKGbFQLJascpSt90vAOAwF4CM5 NAujZv9JUZntxswwGFpAHgwq1SjSnhVWCzF4T26fAJU1BhLdZwRz5izHHrpRNy1DmBUJXD p3EoNAtqFHclvgVlhkT8rM9db74LJsM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-RcjBULaaPWGpQPubRupjSg-1; Wed, 31 Jan 2024 14:17:55 -0500 X-MC-Unique: RcjBULaaPWGpQPubRupjSg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5870329AC03F; Wed, 31 Jan 2024 19:17:54 +0000 (UTC) Received: from rhel-developer-toolbox-latest.rmtusor.csb (unknown [10.2.16.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C24840CD14B; Wed, 31 Jan 2024 19:17:53 +0000 (UTC) From: Chris Leech To: Greg Kroah-Hartman , Nilesh Javali Cc: Christoph Hellwig , John Meneghini , Lee Duncan , Mike Christie , Hannes Reinecke , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, GR-QLogic-Storage-Upstream@marvell.com Subject: [PATCH 1/2] uio: introduce UIO_MEM_DMA_COHERENT type Date: Wed, 31 Jan 2024 11:17:31 -0800 Message-ID: <20240131191732.3247996-2-cleech@redhat.com> In-Reply-To: <20240131191732.3247996-1-cleech@redhat.com> References: <20240131191732.3247996-1-cleech@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789634777429434699 X-GMAIL-MSGID: 1789634777429434699 Add a UIO memtype specifically for sharing dma_alloc_coherent memory with userspace, backed by dma_mmap_coherent. This is mainly for the bnx2/bnx2x/bnx2i "cnic" interface, although there are a few other uio drivers which map dma_alloc_coherent memory and could be converted to use dma_mmap_coherent as well. Signed-off-by: Nilesh Javali Signed-off-by: Chris Leech Reviewed-by: Christoph Hellwig --- drivers/uio/uio.c | 40 ++++++++++++++++++++++++++++++++++++++ include/linux/uio_driver.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 2d572f6c8ec83..dde3f49855233 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -24,6 +24,7 @@ #include #include #include +#include #define UIO_MAX_DEVICES (1U << MINORBITS) @@ -759,6 +760,42 @@ static int uio_mmap_physical(struct vm_area_struct *vma) vma->vm_page_prot); } +static int uio_mmap_dma_coherent(struct vm_area_struct *vma) +{ + struct uio_device *idev = vma->vm_private_data; + struct uio_mem *mem; + void *addr; + int ret = 0; + int mi; + + mi = uio_find_mem_index(vma); + if (mi < 0) + return -EINVAL; + + mem = idev->info->mem + mi; + + if (mem->dma_addr & ~PAGE_MASK) + return -ENODEV; + if (vma->vm_end - vma->vm_start > mem->size) + return -EINVAL; + + /* + * UIO uses offset to index into the maps for a device. + * We need to clear vm_pgoff for dma_mmap_coherent. + */ + vma->vm_pgoff = 0; + + addr = (void *)mem->addr; + ret = dma_mmap_coherent(mem->dma_device, + vma, + addr, + mem->dma_addr, + vma->vm_end - vma->vm_start); + vma->vm_pgoff = mi; + + return ret; +} + static int uio_mmap(struct file *filep, struct vm_area_struct *vma) { struct uio_listener *listener = filep->private_data; @@ -806,6 +843,9 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma) case UIO_MEM_VIRTUAL: ret = uio_mmap_logical(vma); break; + case UIO_MEM_DMA_COHERENT: + ret = uio_mmap_dma_coherent(vma); + break; default: ret = -EINVAL; } diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h index 47c5962b876b0..14d9dd2a07e85 100644 --- a/include/linux/uio_driver.h +++ b/include/linux/uio_driver.h @@ -37,10 +37,12 @@ struct uio_map; struct uio_mem { const char *name; phys_addr_t addr; + dma_addr_t dma_addr; unsigned long offs; resource_size_t size; int memtype; void __iomem *internal_addr; + struct device *dma_device; struct uio_map *map; }; @@ -158,6 +160,7 @@ extern int __must_check #define UIO_MEM_LOGICAL 2 #define UIO_MEM_VIRTUAL 3 #define UIO_MEM_IOVA 4 +#define UIO_MEM_DMA_COHERENT 5 /* defines for uio_port->porttype */ #define UIO_PORT_NONE 0 From patchwork Wed Jan 31 19:17:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 194915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2112858dyb; Wed, 31 Jan 2024 11:25:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRMqOnsJ1rRPCKY5fBQ3eloG90dw6uIHcSQtIG/RGnHaMkY9FDZvx5LlEnONgnE/7FfdKa X-Received: by 2002:a62:f24f:0:b0:6da:fc2b:5a88 with SMTP id y15-20020a62f24f000000b006dafc2b5a88mr2605870pfl.15.1706729147505; Wed, 31 Jan 2024 11:25:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706729147; cv=pass; d=google.com; s=arc-20160816; b=Tu2bzaVi2zwHLHunRbYoJIYa4gLK5iJv9ZbzQjire++l8sOvua0DvoFXrPmbxJThzK mozrFw21SujgJddM9VMEgnacxRmJOu5W+a/z8Y+ZjV6zwzmbprVsEn3GonzA92n1DAb7 5IlPLkDSqJhSVjwHv/7Br8bvJqWcJr6RD24fzUfni84CC3gdFDppcdxpWdrVg38UuEui UsznfBuplueaFxWekowDAu4soPptsHQJuqexBE3dR6LougQGmiVbqTt2ulBSCiCltMHm H6TGZa6qAgcrUP5PHNh3BfDg4sK2/Yam7nL0y6vRLPQfQW98FXcBkIlGrpGPcDxXb9Dh oqZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hSVKx6QtgMDEM8LnOwfuT1EuekagUrvnp40Yk/IOnn8=; fh=YWKkKva17/FNQ7PegfYRG+QN97WW66XS6yX8WWOXCTg=; b=sITBw/1rhoFzIrl1WM8Tfg/aRCdPgJuh3Q1uxUACPIQF32+/1uk7ptP4UK1ZSFYj0e 4D+4chj0j6p1OUQxYt7X131/S1jDsRYjpZ/wjDW2iZNifHq5rT2jOhDADmrukm3i4tbQ 1xzFpFN9dtiyMj8/qI2EAb7fQslTmeH5tZ6dg8AFGtbHzHDUh2tuCq+o7/Mnbh4Dclyh Oa2xyvBkjmUSkMwD9cVk3PUIxM++W3SnX7meRk8nz3N5Zm98EZ7YloPDWKhWFmAg31KF 5yqkgRU1aPbao0wBmJ7TClxdhduuKz2YVW7qSELddKUC/hKs63XgaRpJjDz/5eqOp8Nn csCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jUQD7eAo; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47011-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCU/65cGcAVH+x/E8nedg3hT+iLsPvdwaGGKcrdwE/i4Kq0eXM4GntK5vlISEH+OjjZSn3Dk6GuShLLpmV4AWc71eSgyGQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o9-20020a655209000000b005d8e22b5258si3918734pgp.879.2024.01.31.11.25.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:25:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jUQD7eAo; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47011-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id EA838B22838 for ; Wed, 31 Jan 2024 19:19:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D59B1405C1; Wed, 31 Jan 2024 19:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jUQD7eAo" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D157A3EA9B for ; Wed, 31 Jan 2024 19:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706728683; cv=none; b=c0YNqnJgyNe0lCS7qWh0GnkzZEhnMQ5abcLd4I/tFIMoGC1KeQ6U/ehq5LZK82B8MHitFUfN547OHwsJI0jYOF7WzLL8QbBL+D3diVYM5ghRVC3GQK5WLkP1M6ksXweAriNhzia5hdP2ts7Y9WPtwDGYaB15mBGdYSX4dbunfnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706728683; c=relaxed/simple; bh=JiU/Zj2jN5FGcTJs6+iPLUXDsDn+TM4A60WJFyv8XsA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YNbFEmgt++G7mhZBGhQn34VYCS+kRq1aHNx+NgR/L2sf1iSY33spAAIN9tVrNJAAYXbFftiHFM3SvKAm3TavSd/fAtsW0JDW6JUbka06oHeUc7si4tA5FjQpcqFOx116OD+gB/PVJ8WWCi/gQkheyEeEHi391L5hSROGM4H2ciU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jUQD7eAo; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706728681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hSVKx6QtgMDEM8LnOwfuT1EuekagUrvnp40Yk/IOnn8=; b=jUQD7eAoDdki/a8F4atU3qGOpPftdWlBNMUWOgreab1GNMjzHgaHKbaJWjNbBnKYW0/X11 Z1ouBRWdjXIhZloohi0mwoQOJTfN+Cat11KUGMrprSNmrvGYULIk/DvHJepNEGcfO99UgH ozgLXxvHAj4qE8fcS207asqgXemsfWg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-AUv43VFnM4KSGHJbSMaTyA-1; Wed, 31 Jan 2024 14:17:56 -0500 X-MC-Unique: AUv43VFnM4KSGHJbSMaTyA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD6E41C0BA49; Wed, 31 Jan 2024 19:17:55 +0000 (UTC) Received: from rhel-developer-toolbox-latest.rmtusor.csb (unknown [10.2.16.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E63A40C9444; Wed, 31 Jan 2024 19:17:54 +0000 (UTC) From: Chris Leech To: Greg Kroah-Hartman , Nilesh Javali Cc: Christoph Hellwig , John Meneghini , Lee Duncan , Mike Christie , Hannes Reinecke , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, GR-QLogic-Storage-Upstream@marvell.com Subject: [PATCH 2/2] cnic,bnx2,bnx2x: use UIO_MEM_DMA_COHERENT Date: Wed, 31 Jan 2024 11:17:32 -0800 Message-ID: <20240131191732.3247996-3-cleech@redhat.com> In-Reply-To: <20240131191732.3247996-1-cleech@redhat.com> References: <20240131191732.3247996-1-cleech@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789635222487578444 X-GMAIL-MSGID: 1789635222487578444 Use the UIO_MEM_DMA_COHERENT type to properly handle mmap for dma_alloc_coherent buffers. The cnic l2_ring and l2_buf mmaps have caused page refcount issues as the dma_alloc_coherent no longer provide __GFP_COMP allocation as per commit "dma-mapping: reject __GFP_COMP in dma_alloc_attrs". Fix this by having the uio device use dma_mmap_coherent. The bnx2 and bnx2x status block allocations are also dma_alloc_coherent, and should use dma_mmap_coherent. They don't allocate multiple pages, but this interface does not work correctly with an iommu enabled unless dma_mmap_coherent is used. Fixes: bb73955c0b1d ("cnic: don't pass bogus GFP_ flags to dma_alloc_coherent") Signed-off-by: Nilesh Javali Signed-off-by: Chris Leech --- drivers/net/ethernet/broadcom/bnx2.c | 1 + drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 2 ++ drivers/net/ethernet/broadcom/cnic.c | 15 ++++++++++++--- drivers/net/ethernet/broadcom/cnic.h | 1 + drivers/net/ethernet/broadcom/cnic_if.h | 1 + 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c index 0d917a9699c58..b65b8592ad759 100644 --- a/drivers/net/ethernet/broadcom/bnx2.c +++ b/drivers/net/ethernet/broadcom/bnx2.c @@ -367,6 +367,7 @@ static void bnx2_setup_cnic_irq_info(struct bnx2 *bp) cp->irq_arr[0].status_blk = (void *) ((unsigned long) bnapi->status_blk.msi + (BNX2_SBLK_MSIX_ALIGN_SIZE * sb_id)); + cp->irq_arr[0].status_blk_map = bp->status_blk_mapping; cp->irq_arr[0].status_blk_num = sb_id; cp->num_irq = 1; } diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c index 0d8e61c63c7c6..678829646cec3 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c @@ -14912,9 +14912,11 @@ void bnx2x_setup_cnic_irq_info(struct bnx2x *bp) else cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb; + cp->irq_arr[0].status_blk_map = bp->cnic_sb_mapping; cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp); cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp); cp->irq_arr[1].status_blk = bp->def_status_blk; + cp->irq_arr[1].status_blk_map = bp->def_status_blk_mapping; cp->irq_arr[1].status_blk_num = DEF_SB_ID; cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID; diff --git a/drivers/net/ethernet/broadcom/cnic.c b/drivers/net/ethernet/broadcom/cnic.c index 7926aaef8f0c5..cca1e94fc35dc 100644 --- a/drivers/net/ethernet/broadcom/cnic.c +++ b/drivers/net/ethernet/broadcom/cnic.c @@ -1107,6 +1107,7 @@ static int cnic_init_uio(struct cnic_dev *dev) TX_MAX_TSS_RINGS + 1); uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen & CNIC_PAGE_MASK; + uinfo->mem[1].dma_addr = cp->status_blk_map; if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9; else @@ -1118,20 +1119,26 @@ static int cnic_init_uio(struct cnic_dev *dev) uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk & CNIC_PAGE_MASK; + uinfo->mem[1].dma_addr = cp->status_blk_map; uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk); uinfo->name = "bnx2x_cnic"; } - uinfo->mem[1].memtype = UIO_MEM_LOGICAL; + uinfo->mem[1].dma_device = &dev->pcidev->dev; + uinfo->mem[1].memtype = UIO_MEM_DMA_COHERENT; uinfo->mem[2].addr = (unsigned long) udev->l2_ring; + uinfo->mem[2].dma_addr = udev->l2_ring_map; uinfo->mem[2].size = udev->l2_ring_size; - uinfo->mem[2].memtype = UIO_MEM_LOGICAL; + uinfo->mem[2].dma_device = &dev->pcidev->dev; + uinfo->mem[2].memtype = UIO_MEM_DMA_COHERENT; uinfo->mem[3].addr = (unsigned long) udev->l2_buf; + uinfo->mem[3].dma_addr = udev->l2_buf_map; uinfo->mem[3].size = udev->l2_buf_size; - uinfo->mem[3].memtype = UIO_MEM_LOGICAL; + uinfo->mem[3].dma_device = &dev->pcidev->dev; + uinfo->mem[3].memtype = UIO_MEM_DMA_COHERENT; uinfo->version = CNIC_MODULE_VERSION; uinfo->irq = UIO_IRQ_CUSTOM; @@ -1313,6 +1320,7 @@ static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev) return 0; cp->bnx2x_def_status_blk = cp->ethdev->irq_arr[1].status_blk; + cp->status_blk_map = cp->ethdev->irq_arr[1].status_blk_map; cp->l2_rx_ring_size = 15; @@ -5323,6 +5331,7 @@ static int cnic_start_hw(struct cnic_dev *dev) pci_dev_get(dev->pcidev); cp->func = PCI_FUNC(dev->pcidev->devfn); cp->status_blk.gen = ethdev->irq_arr[0].status_blk; + cp->status_blk_map = ethdev->irq_arr[0].status_blk_map; cp->status_blk_num = ethdev->irq_arr[0].status_blk_num; err = cp->alloc_resc(dev); diff --git a/drivers/net/ethernet/broadcom/cnic.h b/drivers/net/ethernet/broadcom/cnic.h index 4baea81bae7a3..fedc84ada937d 100644 --- a/drivers/net/ethernet/broadcom/cnic.h +++ b/drivers/net/ethernet/broadcom/cnic.h @@ -260,6 +260,7 @@ struct cnic_local { #define SM_RX_ID 0 #define SM_TX_ID 1 } status_blk; + dma_addr_t status_blk_map; struct host_sp_status_block *bnx2x_def_status_blk; diff --git a/drivers/net/ethernet/broadcom/cnic_if.h b/drivers/net/ethernet/broadcom/cnic_if.h index 789e5c7e93116..49a11ec80b364 100644 --- a/drivers/net/ethernet/broadcom/cnic_if.h +++ b/drivers/net/ethernet/broadcom/cnic_if.h @@ -190,6 +190,7 @@ struct cnic_ops { struct cnic_irq { unsigned int vector; void *status_blk; + dma_addr_t status_blk_map; u32 status_blk_num; u32 status_blk_num2; u32 irq_flags;