From patchwork Thu Feb 1 23:33:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 195506 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp95078dyc; Thu, 1 Feb 2024 15:38:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHR+bbWEkztz8n3tNnomOH6xCyLHzUyQhOH5qSQZ4s26LKgK7fBmkcB1Pdn0bgAMt7h8XSk X-Received: by 2002:a05:6a21:998b:b0:19e:3373:d726 with SMTP id ve11-20020a056a21998b00b0019e3373d726mr863548pzb.2.1706830692735; Thu, 01 Feb 2024 15:38:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706830692; cv=pass; d=google.com; s=arc-20160816; b=xaipA4zXXbK6UC3wit7+HEQeBbsfa8qTDQq54wz6x5LN+bE4euZD33NTx1yqFcBHdG BT++P8VA+zgUUYPc2JiL5MbO8Fbbu/B6gKFGYzzJio2W4ZyX7FeNLJ4yglnAEZwMFcwi ZC2KB6UdqwPg2uTU36/0zRUdvyiez+mpgQh7lwe2AqhtSJxl1KkY+0dUeNVFS4xvkvXf ogdug/MwIiw2IWmDreBJdXFh7EddhpWSMrl67x0zGFkYfmiYcwJBJfJ+qzz8UntUwM7T Fd4qR45pgrKe6BU3Jwh/tFFqCTyjwadZWrh7zMQ2cbnGqCaDu/z8Db8kFbY109gob+Hz EWWA== 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=vSHqITouUlq7CCUtWN8V4a0IRIlAJ0GlTBNdFKzO/Ok=; fh=EerTSRD5bRyzLOCYam4q/rGb7jIcsNTwIOHK+P6z6+w=; b=ZX/S4XS+P2M435vA7RXpeVsyqWDyth7TAUNAvrQKoG2jaTm0VSAANGV/FtyNVulJhC gtktqoe/RaxntN7lUrPKfSYSdMtQsNls5ohTqe56XXmDY2F+B4XnLOp7a38RD5WKDvVS PuYHGl9RrBG/AtCtamdRfsHWnUQ73rb0mVYYKtbbz0VLWmLDfo/6iWngBROZGY21a67p mVSk1z/X2ZgO8TqrPSqPhI8+1QfHvHIJyBWrt5TMjU3EYciHjgpEeC3Ls7x7zuRf0Rbs kjcviw6pC8DQWSDKZRVU9LpMhxKgsU81brpS9qoDIxMoWo7bPw2GZlaezWOzyWxyo+D2 LWog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=db8nUKg+; 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-48998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48998-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCUof4HstvlDQONmvWtjXQhgGzukqlZktiQjDW8H0Hs4Hf7rsq4b0CeMdMCR6nRcZ9KQVmYseBRrnyAMlTCSVHyhmgqKBQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j21-20020a63cf15000000b005cee03a5355si490625pgg.518.2024.02.01.15.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 15:38:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48998-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=db8nUKg+; 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-48998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48998-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 AF118B25763 for ; Thu, 1 Feb 2024 23:35:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C557482E5; Thu, 1 Feb 2024 23:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="db8nUKg+" 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 9DF1F47F57 for ; Thu, 1 Feb 2024 23:34:22 +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=1706830464; cv=none; b=JHmar9SCbZLVzqldqwWaoBKobCVtwfIZ3f9rewOK4xJkugGS0UvoKLIAjuLwbOK2a+fFe7Wpi1DQluMSNPkJBpi/wtvPtDj3NtsJ3rssbsrVw7rEYVyBSE4RUPhLwb7UnP8R4pdnMMvGiE03jcA44IW4lH3CafSk6oFJi9s/Zwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706830464; c=relaxed/simple; bh=AVG0aFP8okb+tYmPodyeA6t8ACKIOa5mpXDxU39XVjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f5rXUYyLdcQ/NSzKvTkGHrpuUgZYh+BUHdQmtn9Jd9gYjvhaqN98VvPrTCUam5ghEsiYvhxdJ8vAnotozeYmvThCbh9ZGeywrLPR2f6+GTcLY/UBPyQscVHOpnn5MmxNxoKCYutfFX3acLgZzFp5HTJpBuZj3M1kjPh8cxFdFng= 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=db8nUKg+; 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=1706830461; 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=vSHqITouUlq7CCUtWN8V4a0IRIlAJ0GlTBNdFKzO/Ok=; b=db8nUKg+EHFZ25VAzBj0RxHSX6cQb0g6FKVy4PKW/v+EjlwZEYQslICqoPMWqv/51ER0Ku 86+cZm/H67+VuDaMwuzFQ85x/qB6Ud7WDjs0tkKYHk32Pkq34jq5tkRABKGnv4rPn9Hv2E NFB4hDSESPY3KycTKJATgl6WY90zjwo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-gY9EdXkqNSGdobHRO1yUfg-1; Thu, 01 Feb 2024 18:34:18 -0500 X-MC-Unique: gY9EdXkqNSGdobHRO1yUfg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 3F2A1837227; Thu, 1 Feb 2024 23:34:18 +0000 (UTC) Received: from rhel-developer-toolbox-latest.rmtusor.csb (unknown [10.2.16.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1296A1BDB1; Thu, 1 Feb 2024 23:34:16 +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 v5 1/4] uio: introduce UIO_MEM_DMA_COHERENT type Date: Thu, 1 Feb 2024 15:33:57 -0800 Message-ID: <20240201233400.3394996-2-cleech@redhat.com> In-Reply-To: <20240201233400.3394996-1-cleech@redhat.com> References: <20240201233400.3394996-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.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789741700348630564 X-GMAIL-MSGID: 1789741700348630564 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 will 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 | 47 ++++++++++++++++++++++++++++++++++++++ include/linux/uio_driver.h | 8 +++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 2d572f6c8ec83..bb77de6fa067e 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,49 @@ 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->addr & ~PAGE_MASK) + return -ENODEV; + if (mem->dma_addr & ~PAGE_MASK) + return -ENODEV; + if (!mem->dma_device) + return -ENODEV; + if (vma->vm_end - vma->vm_start > mem->size) + return -EINVAL; + + dev_warn(mem->dma_device, + "use of UIO_MEM_DMA_COHERENT is highly discouraged"); + + /* + * 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 +850,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..a7756f909dd01 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,12 @@ extern int __must_check #define UIO_MEM_LOGICAL 2 #define UIO_MEM_VIRTUAL 3 #define UIO_MEM_IOVA 4 +/* + * UIO_MEM_DMA_COHERENT exists for legacy drivers that had been getting by with + * improperly mapping DMA coherent allocations through the other modes. + * Do not use in new drivers. + */ +#define UIO_MEM_DMA_COHERENT 5 /* defines for uio_port->porttype */ #define UIO_PORT_NONE 0 From patchwork Thu Feb 1 23:33:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 195504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp94106dyc; Thu, 1 Feb 2024 15:35:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9DaDD3szYXJ/vsEEAGFNaqlkTayJ0igo3Qknb+z361jtFqctHtU7IUqT1b3oHPES9XdgT X-Received: by 2002:a05:622a:1c5:b0:42b:f408:4a02 with SMTP id t5-20020a05622a01c500b0042bf4084a02mr451566qtw.59.1706830541718; Thu, 01 Feb 2024 15:35:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706830541; cv=pass; d=google.com; s=arc-20160816; b=d1QIpujT0xhbECy4pvUM//ou5BuzlEQPr+ofFWE09ND/zyxK9uQetS24Y6+PZLHtHz 8GB12FPTxaLiKG/wxFAEi0r+n2kdgBu2a/yOaEnXMz3nbXlkXzoY8U3k8D8/Rovp37vj 99JNu6bkNGz6CQo2renmT3RxFVDzuWcQykNK159uiDiApbAgbrQlUxFfltxMt9SADLXr ODTOsZRxWTKqw8yw66yqqazszqf9ho9Bm6tzgogPLwEISc4UWTmnJgHdLR4CUUTKvtvE VjA40a/wD0tBKptwHpSCVNDi5mpAvnX47pYOok91kHL8wtir2aCzvfCRC4tbGTNWLops QGSQ== 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=vW15KnuWbJ1Fv8UDVL9jaY2/JqQeNoawE9G/00qiEXM=; fh=62L0ZswAHj4BEw/byxPB+9zctF/pUm18X1nUfNFfSzI=; b=VoPx2Z6C1/gTGLDgZfqpou+/bVjzeMu+9aiL0jMQLt0USQeTShgifeoo1eWWYMBSi9 CTEH8wdCZ0qBgo0soqX48DL1jI5RGZyiWGw7ykbUzJE5KINZaDpsHD752PICkkQU/jju sma+0lWYhnPAC8crcjcxQzyvTEHyGCs9terix1/F6MXmw5UXaOG/gawx0E7KT39Qec+O yc3bys51kNajIqvakf4060CRj5jCfnmBaQygQ9cAivPXqQP+0cNCa54FCXvS7NacKPF3 hL6SFCcAM+ui86rHMqKN1nBjMIbWtrEUts7Sk4Vth2xIGtoQxKMKgz6Ff215o2wmw3m0 Ktog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EGCrg3qD; 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-48999-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48999-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWipiwO+lItGHt9kNw12drfWoLfbItxgUPgvgS2EgWwCpUP6egm600wfPJ5Qbx8J0DUEkYWNsfXPa60/mP3W9c3+hsOSw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z13-20020ac87f8d000000b0042aacc878b9si646913qtj.655.2024.02.01.15.35.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 15:35:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48999-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EGCrg3qD; 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-48999-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48999-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 73DA71C23EA0 for ; Thu, 1 Feb 2024 23:35:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 684EA48789; Thu, 1 Feb 2024 23:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EGCrg3qD" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 3BB1947F67 for ; Thu, 1 Feb 2024 23:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706830465; cv=none; b=oiKpjeFjolYDurQZSqBD8iBkmY8GeBM110Wfls+D2A+FzAJtD0SaqHBVNSCmzSvyciSWK9ehub2xmzS65BH9gCwA8Y9JjnwYQkLfyEmfAXk+WH/AtRyTRjmtsxSgt5gkGkP2E/VaJXhQRSxK1WegyaHfCzpI8BdcUrMrUmomjXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706830465; c=relaxed/simple; bh=Ahlg3vRN5+qaUGPIvlQZECDJaIYDaGE+TjgxiiUe6oA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aBxQOp83u8TCpZ03MZkZFHL0dEpKTM/o7XWbyHv2ArC5CIZeMm7GHydHAFbYgKwxmGMgAze7N2iAoR248a6WG2LEbKIoX1P/IpPo9+dP1z9eOyTzu5g+VVoRY4lu1WOLG+bKCKrGZyzT2zsqnd4zTuP9uTiSKZAzivHnlxCdF2c= 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=EGCrg3qD; arc=none smtp.client-ip=170.10.133.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=1706830463; 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=vW15KnuWbJ1Fv8UDVL9jaY2/JqQeNoawE9G/00qiEXM=; b=EGCrg3qDTSutRt46ovfxRStPNuOm68dWHXjVfG+2dt4ByT8S6aFEhhwZN2ynIq4fYeakQl rFiToSlW5l1FFZNbAC9M4hsNFOfFS4Nx51/yVK7R8o0PJ1dJeg0Pf6wJgl9MecVUxQd+qV GhbXRFhqYyvrTqeNtaRUJCzIjs5rygo= 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-364-LKzkquViN8CR3NERUKdAZw-1; Thu, 01 Feb 2024 18:34:20 -0500 X-MC-Unique: LKzkquViN8CR3NERUKdAZw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 9576B3806622; Thu, 1 Feb 2024 23:34:19 +0000 (UTC) Received: from rhel-developer-toolbox-latest.rmtusor.csb (unknown [10.2.16.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 658D8111F9; Thu, 1 Feb 2024 23:34:18 +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 v5 2/4] cnic,bnx2,bnx2x: use UIO_MEM_DMA_COHERENT Date: Thu, 1 Feb 2024 15:33:58 -0800 Message-ID: <20240201233400.3394996-3-cleech@redhat.com> In-Reply-To: <20240201233400.3394996-1-cleech@redhat.com> References: <20240201233400.3394996-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.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789741542172056018 X-GMAIL-MSGID: 1789741542172056018 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. Signed-off-by: Nilesh Javali Signed-off-by: Chris Leech Acked-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnx2.c | 1 + .../net/ethernet/broadcom/bnx2x/bnx2x_main.c | 2 ++ drivers/net/ethernet/broadcom/cnic.c | 25 +++++++++++++------ drivers/net/ethernet/broadcom/cnic.h | 1 + drivers/net/ethernet/broadcom/cnic_if.h | 1 + 5 files changed, 22 insertions(+), 8 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..3d63177e7e52b 100644 --- a/drivers/net/ethernet/broadcom/cnic.c +++ b/drivers/net/ethernet/broadcom/cnic.c @@ -1107,10 +1107,11 @@ 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; + uinfo->mem[1].size = PAGE_ALIGN(BNX2_SBLK_MSIX_ALIGN_SIZE * 9); else - uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE; + uinfo->mem[1].size = PAGE_ALIGN(BNX2_SBLK_MSIX_ALIGN_SIZE); uinfo->name = "bnx2_cnic"; } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { @@ -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].size = sizeof(*cp->bnx2x_def_status_blk); + uinfo->mem[1].dma_addr = cp->status_blk_map; + uinfo->mem[1].size = PAGE_ALIGN(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].size = udev->l2_ring_size; - uinfo->mem[2].memtype = UIO_MEM_LOGICAL; + uinfo->mem[2].dma_addr = udev->l2_ring_map; + uinfo->mem[2].size = PAGE_ALIGN(udev->l2_ring_size); + 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].size = udev->l2_buf_size; - uinfo->mem[3].memtype = UIO_MEM_LOGICAL; + uinfo->mem[3].dma_addr = udev->l2_buf_map; + uinfo->mem[3].size = PAGE_ALIGN(udev->l2_buf_size); + 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; From patchwork Thu Feb 1 23:33:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 195505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp94633dyc; Thu, 1 Feb 2024 15:37:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3x5vie3PyuwWr/Py813y8nYKQtt8hjC2HF5/EnbMHt37Lyhu8nf3veWHt55svq2D3wcpj X-Received: by 2002:a17:907:1119:b0:a31:34a9:d742 with SMTP id qu25-20020a170907111900b00a3134a9d742mr344300ejb.3.1706830620148; Thu, 01 Feb 2024 15:37:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706830620; cv=pass; d=google.com; s=arc-20160816; b=vDgzxBxKDWZRcPvyx/LKv992qST/VO+LzE39PEWm+LsajsbuBLWMZq2M3Zahs9A3U0 Uii7hBe9r1WdDLo2EFmlNTRK99Xe9Jh8zKY+5o1ZFpiCMN13vZoZmPUcwbxp8RClIUzT 7ZA5nqUG4SAkMGarvcSpnS9a+OoALgRvpZHAE1QUpFpTnJnPLc5ac6AHo1lcLcnUsa/n /4uOo5H9PmZ3Ce4ZHt9Ifu4vdgir5TjSeznhJEMDuyKDjqNuzfTiZBgWXnxuc+8MOml/ TQ8EStmCvuU5n4Ug1zK1n7Hj+XoQ/CxrSFkcaUX5T6h7DAyS/EikrgcwhiuTXusbTgJh suVg== 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=Feaa7ltqMImVUAF90OIsH77NDPTc4xlAwHCDaWrW23I=; fh=hkuJQZZE1xa6ixxvZyUSEIaoUVGSkvpXv18YjPdR9jw=; b=h9XvXJA7xhXAQsWrli72QfGuzzTgOTZAsnkkPzP8O0WxQ2rx/L26zOVAP+9edPsLBz lWKAchJ/mTi3LbLWHcTSNxC1J9WNYlBh2hecTZ26zopla4i49ic7eFISdUUvpkDV2lPr XxAazharmYftnRlOqi5fpxhtMx9v0s26Xpxqw3DDAjKdYQVezMpGmS5AuJAkAzTo+v8/ WPyLa0pWsGYnXVsnRWz8B7rc1mOCLtanKhj15aPH7T2UfscinfkL5Mi8pxTmLpJD9lS5 cHIOAYOLgh71+mIqutDGaG/ZZoL5vWCf80vcQ57hlSnweE5ByeKpiAQnRlnjYypZZgGK IRYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TzmPpz9K; 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-49001-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49001-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCVz3yujXX/GuRUdO4SEEZ4EOurS9VxUek7RuUazWkwYyyunoK9iTGimh6QfLpWhDTyCDod+MGjkEXc5s20isGEUJnPlHA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v27-20020a17090606db00b00a3281fb08f4si250518ejb.824.2024.02.01.15.36.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 15:37:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49001-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TzmPpz9K; 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-49001-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49001-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 C85DE1F2542D for ; Thu, 1 Feb 2024 23:36:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76982495E0; Thu, 1 Feb 2024 23:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TzmPpz9K" 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 2ED81481AA for ; Thu, 1 Feb 2024 23:34:26 +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=1706830469; cv=none; b=CgHuwJvxndtUdlI4CjyHthwaIYiECqim/ZP9x3bEf1GocUpzdkWmsUUDUi4iMrXu9PusvKwWdyL53KgaUMWvoJfBYRbuf4g+/WMmhLg1KhtfYHOCtenMeFGgVKT55ZStn+NjZZHwbZWL0CMEorCqPYeri3tWMTQk10svO8cRCxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706830469; c=relaxed/simple; bh=3FokyUnI5P5cmAhKtt6pFHX6NyRCuaS0/kuNt9gir80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mt3SaeqoU6Lt4b3nOrgHro8TURjKKm6+xX+WyffRHf1aH8xIL4rgovgaY0pYx58ZKx0IxexGCOtSRAIT2W8xbyBEnjt6wzr0EBON06Fctq4qsI8Y3b+EYYUcs4/jYqpIpNFO9OQUGgY2/qGnZlcGUSzc1uH+xoNa4vUWcepVzcM= 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=TzmPpz9K; 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=1706830466; 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=Feaa7ltqMImVUAF90OIsH77NDPTc4xlAwHCDaWrW23I=; b=TzmPpz9KnoDnbxPGIwqhAhlNgZbOr0395I9f28uIFNnLQOEDj0EKpmybiYBwTeErGbcBa9 5ppoNN+r0uYJh1UwD4GJNOVcoz0ly6x4YaLEEPGj02MHhuAh2vS0/ASnKMor0FGvzC6JRE qap+drmMY4/2sO7NWk0DLltVXpEBbAI= 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-333-gWWzCNdgOoS9f3Qu8Af-FQ-1; Thu, 01 Feb 2024 18:34:21 -0500 X-MC-Unique: gWWzCNdgOoS9f3Qu8Af-FQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 E9CA829AC00A; Thu, 1 Feb 2024 23:34:20 +0000 (UTC) Received: from rhel-developer-toolbox-latest.rmtusor.csb (unknown [10.2.16.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB9661BDB1; Thu, 1 Feb 2024 23:34:19 +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 v5 3/4] uio_pruss: UIO_MEM_DMA_COHERENT conversion Date: Thu, 1 Feb 2024 15:33:59 -0800 Message-ID: <20240201233400.3394996-4-cleech@redhat.com> In-Reply-To: <20240201233400.3394996-1-cleech@redhat.com> References: <20240201233400.3394996-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.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789741623964004783 X-GMAIL-MSGID: 1789741623964004783 Conversion of this driver to use UIO_MEM_DMA_COHERENT for dma_alloc_coherent memory instead of UIO_MEM_PHYS. Signed-off-by: Chris Leech --- drivers/uio/uio_pruss.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c index 77e2dc4048855..72b33f7d4c40f 100644 --- a/drivers/uio/uio_pruss.c +++ b/drivers/uio/uio_pruss.c @@ -191,9 +191,11 @@ static int pruss_probe(struct platform_device *pdev) p->mem[1].size = sram_pool_sz; p->mem[1].memtype = UIO_MEM_PHYS; - p->mem[2].addr = gdev->ddr_paddr; + p->mem[2].addr = (phys_addr_t) gdev->ddr_vaddr; + p->mem[2].dma_addr = gdev->ddr_paddr; p->mem[2].size = extram_pool_sz; - p->mem[2].memtype = UIO_MEM_PHYS; + p->mem[2].memtype = UIO_MEM_DMA_COHERENT; + p->mem[2].dma_device = dev; p->name = devm_kasprintf(dev, GFP_KERNEL, "pruss_evt%d", cnt); p->version = DRV_VERSION; From patchwork Thu Feb 1 23:34:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 195507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp95417dyc; Thu, 1 Feb 2024 15:39:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcMiMwawtO8GmId8C1SXad5MCvyIXycOF/s0lZAqmtDtkMqwwujxoePU0JQNHE2eAWeZsC X-Received: by 2002:a05:6a20:e405:b0:19c:a16d:ca79 with SMTP id nh5-20020a056a20e40500b0019ca16dca79mr3468160pzb.15.1706830739851; Thu, 01 Feb 2024 15:38:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706830739; cv=pass; d=google.com; s=arc-20160816; b=KTHANvg+Hm/tS2GTfwQg9WbNXGzf1rooPKUMXaktoBbddszkoI/ZEUx+PbmRtcm9tm HfYwNBkX0YT9Vz3vf1WbOxWJBhuScy2xiNlb0+TqRQqNzqJxYuoXmptbLr+VBVrEUnxS DipoQSGXfqWhBvAdE9jv2Lg4SdberE/qPecDg/kCEt4sym/AkgO3p67cxP9GplYV2EoF i7WfMUy5sw/kIpvpU+RdcZjBh5M+Oa7pzhGOCAEv/utC/53gqnH96kgRaWno1OnNMAlW ZOab2d7xLpiythCCIa2JjuR7ODeedfvODIA5JZwkAONl1zJEi774Jx+8PO1oHb/q5C1s pVBA== 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=kviV4OEyGv0IXC67TnkXo6XXxah3+E8Y2hWZv9VjMFo=; fh=5luoPurCkgP0zFlctRJURpnomRK2Bb82YD1tByqnYvQ=; b=uqUXjFoWG8Qv9DcDoXNKhde5YOMxG6Udsr4do1bmIXYEIgIGahH6geZo1yI7lH91Lx LXvHk3RZNaop8ajSuPMwBbsLFfP413nON0Hk3ygfRcPNz/0Lm8N4Ms6INVMInOig85tY YJuKpLwhjP2/qUDYSEma7R6Daa9YCBNF6p49sdEXPY9bJjUQ+rjzZRfEVdHlQxuBntIx 3BBuu4xwUAeRqT9yA62b8DgIDN1eZ0vj25GGozfYXYc3Ec1YrkjdnqFSwOCXjTWDzqcg OlhXsV7Rxq+V93OtE6EwebVNbcUphAP5BZeKh/wPJXxV7hqZNrechZT/Xl5sW5LBE8bz OTWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dojqep+/"; 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-49000-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49000-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWHBjme9asMPd1/FbJDaoedCgzvvrrffHYvaW0dSQsqoKLWtkVBDg4TF1Ni8sOG4w0Ttfzw/LCDjBGwsE/0cX25jaM01g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a25-20020a634d19000000b00589fcc39ef1si515955pgb.365.2024.02.01.15.38.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 15:38:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49000-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="dojqep+/"; 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-49000-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49000-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 0D5BEB26081 for ; Thu, 1 Feb 2024 23:36:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65006495DC; Thu, 1 Feb 2024 23:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dojqep+/" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 61EBA482E3 for ; Thu, 1 Feb 2024 23:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706830469; cv=none; b=qPAD5VJnOkysQct3aDjhgcQ/0F7+m7s/A7PEDdjYgTRvVo9Q+szjsu/tRYPQvRtaLYiLU6/Pjj4bMpm4fyhwLP0CqOixfHkIpNrpUckY1KCdaaMEASqUgCl0PirxXucTK3Y/wnlky4rhDP2Eb/iZ8bb1ndnQ8lIm5v+mGi1x/TU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706830469; c=relaxed/simple; bh=J66uGdblJybSdIyISNAiXxVD4U/ZxuF3S6nfLo54RFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzDehh13/JlgovuI5r1vYP4K6j2BLzlxxoPNt/boAuJJDeguDEPY0kPIZ8y/fQP1Mbx95AreMKZGAEELET3EsZtmPg30pHjZu+T8sxsScRzlK5QSAtXO5lsimSkk75+SFU8VafYy/ShHe/uqlj89oNeuFX87dOSMEJybx/SF6WE= 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=dojqep+/; arc=none smtp.client-ip=170.10.133.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=1706830466; 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=kviV4OEyGv0IXC67TnkXo6XXxah3+E8Y2hWZv9VjMFo=; b=dojqep+/fbFDnxWRQVYaQDWK9R2eet3vXO0kyG3W+4ia2yoLdXskiXAlT4xqPe0cYYTROO fFVpEXFHb+d+72FgowKrrqKQdZK72JNMGEq/z1/rzCllQzxqqhSp040wu54jzce4e2Xw3w vsBHom8Imp6VkClF9NvRmJsJHoLvx9s= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-9it-QiwGMCWzk2Dtrm9xXw-1; Thu, 01 Feb 2024 18:34:23 -0500 X-MC-Unique: 9it-QiwGMCWzk2Dtrm9xXw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 8569E810BB0; Thu, 1 Feb 2024 23:34:22 +0000 (UTC) Received: from rhel-developer-toolbox-latest.rmtusor.csb (unknown [10.2.16.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 552AE111F9; Thu, 1 Feb 2024 23:34:21 +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 v5 4/4] uio_dmem_genirq: UIO_MEM_DMA_COHERENT conversion Date: Thu, 1 Feb 2024 15:34:00 -0800 Message-ID: <20240201233400.3394996-5-cleech@redhat.com> In-Reply-To: <20240201233400.3394996-1-cleech@redhat.com> References: <20240201233400.3394996-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.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789741749813876773 X-GMAIL-MSGID: 1789741749813876773 Conversion of this driver to use UIO_MEM_DMA_COHERENT for dma_alloc_coherent memory instead of UIO_MEM_PHYS. Signed-off-by: Chris Leech --- drivers/uio/uio_dmem_genirq.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/uio/uio_dmem_genirq.c b/drivers/uio/uio_dmem_genirq.c index 5313307c2754a..8634eba0ef2ab 100644 --- a/drivers/uio/uio_dmem_genirq.c +++ b/drivers/uio/uio_dmem_genirq.c @@ -36,7 +36,6 @@ struct uio_dmem_genirq_platdata { struct platform_device *pdev; unsigned int dmem_region_start; unsigned int num_dmem_regions; - void *dmem_region_vaddr[MAX_UIO_MAPS]; struct mutex alloc_lock; unsigned int refcnt; }; @@ -50,7 +49,6 @@ static int uio_dmem_genirq_open(struct uio_info *info, struct inode *inode) { struct uio_dmem_genirq_platdata *priv = info->priv; struct uio_mem *uiomem; - int dmem_region = priv->dmem_region_start; uiomem = &priv->uioinfo->mem[priv->dmem_region_start]; @@ -61,11 +59,8 @@ static int uio_dmem_genirq_open(struct uio_info *info, struct inode *inode) break; addr = dma_alloc_coherent(&priv->pdev->dev, uiomem->size, - (dma_addr_t *)&uiomem->addr, GFP_KERNEL); - if (!addr) { - uiomem->addr = DMEM_MAP_ERROR; - } - priv->dmem_region_vaddr[dmem_region++] = addr; + &uiomem->dma_addr, GFP_KERNEL); + uiomem->addr = addr ? (phys_addr_t) addr : DMEM_MAP_ERROR; ++uiomem; } priv->refcnt++; @@ -80,7 +75,6 @@ static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode) { struct uio_dmem_genirq_platdata *priv = info->priv; struct uio_mem *uiomem; - int dmem_region = priv->dmem_region_start; /* Tell the Runtime PM code that the device has become idle */ pm_runtime_put_sync(&priv->pdev->dev); @@ -93,13 +87,12 @@ static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode) while (!priv->refcnt && uiomem < &priv->uioinfo->mem[MAX_UIO_MAPS]) { if (!uiomem->size) break; - if (priv->dmem_region_vaddr[dmem_region]) { - dma_free_coherent(&priv->pdev->dev, uiomem->size, - priv->dmem_region_vaddr[dmem_region], - uiomem->addr); + if (uiomem->addr) { + dma_free_coherent(uiomem->dma_device, uiomem->size, + (void *) uiomem->addr, + uiomem->dma_addr); } uiomem->addr = DMEM_MAP_ERROR; - ++dmem_region; ++uiomem; } @@ -264,7 +257,8 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) " dynamic and fixed memory regions.\n"); break; } - uiomem->memtype = UIO_MEM_PHYS; + uiomem->memtype = UIO_MEM_DMA_COHERENT; + uiomem->dma_device = &pdev->dev, uiomem->addr = DMEM_MAP_ERROR; uiomem->size = pdata->dynamic_region_sizes[i]; ++uiomem;