From patchwork Wed Mar 15 19:21:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Desnes Nunes X-Patchwork-Id: 663955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A874C6FD1D for ; Wed, 15 Mar 2023 19:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232017AbjCOTXI (ORCPT ); Wed, 15 Mar 2023 15:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232885AbjCOTW4 (ORCPT ); Wed, 15 Mar 2023 15:22:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE0965CC22 for ; Wed, 15 Mar 2023 12:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678908128; 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=sjZeOywou5LlsR82ghKWrKmDeccS5hy5Eq4jX+ackx4=; b=f+hCkX0agd0KwFFOB5OsAYLMPdPXRZ6eI5ueXFn8wQPCcrK4ilFKpaJH5MslC2lvoK88Eh 8Qk3P68jpzkDL3+KGg0YNtGA5U2QQd40GPIxQPHCPNHMf9ZVSh751+2Ixv4DO6pJjomUn4 1aS7YsgxEEQdrYGyKyJtGHarHf8ic/Q= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-8Xixh3fnNt647TNZ_7BuCQ-1; Wed, 15 Mar 2023 15:22:05 -0400 X-MC-Unique: 8Xixh3fnNt647TNZ_7BuCQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C17481C06EDB; Wed, 15 Mar 2023 19:22:04 +0000 (UTC) Received: from desnesn.remote.csb (ovpn-116-3.gru2.redhat.com [10.97.116.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28C4740C6E67; Wed, 15 Mar 2023 19:22:01 +0000 (UTC) From: Desnes Nunes To: iommu@lists.linux.dev, linux-scsi@vger.kernel.org, storagedev@microchip.com, linux-kernel@vger.kernel.org Cc: hch@lst.de, martin.petersen@oracle.com, don.brace@microchip.com, m.szyprowski@samsung.com, robin.murphy@arm.com, jejb@linux.ibm.com, jsnitsel@redhat.com, Desnes Nunes Subject: [PATCH 1/3] dma-debug: small dma_debug_entry's comment and variable name updates Date: Wed, 15 Mar 2023 16:21:28 -0300 Message-Id: <20230315192130.970021-2-desnesn@redhat.com> In-Reply-To: <20230315192130.970021-1-desnesn@redhat.com> References: <20230315192130.970021-1-desnesn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Small update on dma_debug_entry's struct commentary and also standardize the usage of 'dma_addr' variable name from debug_dma_map_page() on debug_dma_unmap_page(), and similarly on debug_dma_free_coherent() Signed-off-by: Desnes Nunes --- kernel/dma/debug.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c index 18c93c2276ca..e0ad8db1ec25 100644 --- a/kernel/dma/debug.c +++ b/kernel/dma/debug.c @@ -52,7 +52,8 @@ enum map_err_types { /** * struct dma_debug_entry - track a dma_map* or dma_alloc_coherent mapping * @list: node on pre-allocated free_entries list - * @dev: 'dev' argument to dma_map_{page|single|sg} or dma_alloc_coherent + * @dev: pointer to the device driver + * @dev_addr: 'dev' argument to dma_map_{page|single|sg} or dma_alloc_coherent * @size: length of the mapping * @type: single, page, sg, coherent * @direction: enum dma_data_direction @@ -1262,13 +1263,13 @@ void debug_dma_mapping_error(struct device *dev, dma_addr_t dma_addr) } EXPORT_SYMBOL(debug_dma_mapping_error); -void debug_dma_unmap_page(struct device *dev, dma_addr_t addr, +void debug_dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size, int direction) { struct dma_debug_entry ref = { .type = dma_debug_single, .dev = dev, - .dev_addr = addr, + .dev_addr = dma_addr, .size = size, .direction = direction, }; @@ -1403,13 +1404,13 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size, } void debug_dma_free_coherent(struct device *dev, size_t size, - void *virt, dma_addr_t addr) + void *virt, dma_addr_t dma_addr) { struct dma_debug_entry ref = { .type = dma_debug_coherent, .dev = dev, .offset = offset_in_page(virt), - .dev_addr = addr, + .dev_addr = dma_addr, .size = size, .direction = DMA_BIDIRECTIONAL, }; From patchwork Wed Mar 15 19:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Desnes Nunes X-Patchwork-Id: 664457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DAD9C7618D for ; Wed, 15 Mar 2023 19:23:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230489AbjCOTX3 (ORCPT ); Wed, 15 Mar 2023 15:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbjCOTXE (ORCPT ); Wed, 15 Mar 2023 15:23:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED7218B060 for ; Wed, 15 Mar 2023 12:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678908133; 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=GCtPtzpuFMR8qAF/d/etYJgL7eXxb5y6E1pj/qDFqRA=; b=RcVMlVJfc1KI03jrVWwlpq6fzCdGe5Bfstlhwmo9o4KhXR5e1+R2N+5j0oIawp9Zs23GkN 9uaT/ZkdSHOqTdZNVtOBlNUrnz+vs05ePXMaGXXB/nbJ34fMb/028S3TUBxcHiN9OTYieP EEM04eDjnC09kQu5kJ8WH5a4DvhAD54= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-270-UOU3zLJiPda4pg9KfIMnlg-1; Wed, 15 Mar 2023 15:22:08 -0400 X-MC-Unique: UOU3zLJiPda4pg9KfIMnlg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 785AB1C06EE2; Wed, 15 Mar 2023 19:22:07 +0000 (UTC) Received: from desnesn.remote.csb (ovpn-116-3.gru2.redhat.com [10.97.116.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A6C840C6E67; Wed, 15 Mar 2023 19:22:05 +0000 (UTC) From: Desnes Nunes To: iommu@lists.linux.dev, linux-scsi@vger.kernel.org, storagedev@microchip.com, linux-kernel@vger.kernel.org Cc: hch@lst.de, martin.petersen@oracle.com, don.brace@microchip.com, m.szyprowski@samsung.com, robin.murphy@arm.com, jejb@linux.ibm.com, jsnitsel@redhat.com, Desnes Nunes Subject: [PATCH 2/3] dma-debug: add cacheline to user/kernel space dump messages Date: Wed, 15 Mar 2023 16:21:29 -0300 Message-Id: <20230315192130.970021-3-desnesn@redhat.com> In-Reply-To: <20230315192130.970021-1-desnesn@redhat.com> References: <20230315192130.970021-1-desnesn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Having the cacheline also printed on the debug_dma_dump_mappings() and dump_show() is useful for debugging. Furthermore, this also standardizes the messages shown on both dump functions. Signed-off-by: Desnes Nunes --- kernel/dma/debug.c | 122 ++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c index e0ad8db1ec25..19cc59829ffd 100644 --- a/kernel/dma/debug.c +++ b/kernel/dma/debug.c @@ -396,37 +396,6 @@ static unsigned long long phys_addr(struct dma_debug_entry *entry) return page_to_phys(pfn_to_page(entry->pfn)) + entry->offset; } -/* - * Dump mapping entries for debugging purposes - */ -void debug_dma_dump_mappings(struct device *dev) -{ - int idx; - - for (idx = 0; idx < HASH_SIZE; idx++) { - struct hash_bucket *bucket = &dma_entry_hash[idx]; - struct dma_debug_entry *entry; - unsigned long flags; - - spin_lock_irqsave(&bucket->lock, flags); - - list_for_each_entry(entry, &bucket->list, list) { - if (!dev || dev == entry->dev) { - dev_info(entry->dev, - "%s idx %d P=%Lx N=%lx D=%Lx L=%Lx %s %s\n", - type2name[entry->type], idx, - phys_addr(entry), entry->pfn, - entry->dev_addr, entry->size, - dir2name[entry->direction], - maperr2str[entry->map_err_type]); - } - } - - spin_unlock_irqrestore(&bucket->lock, flags); - cond_resched(); - } -} - /* * For each mapping (initial cacheline in the case of * dma_alloc_coherent/dma_map_page, initial cacheline in each page of a @@ -547,6 +516,70 @@ static void active_cacheline_remove(struct dma_debug_entry *entry) spin_unlock_irqrestore(&radix_lock, flags); } +/* + * Dump mappings entries on kernel space for debugging purposes + */ +void debug_dma_dump_mappings(struct device *dev) +{ + int idx; + phys_addr_t cln; + + for (idx = 0; idx < HASH_SIZE; idx++) { + struct hash_bucket *bucket = &dma_entry_hash[idx]; + struct dma_debug_entry *entry; + unsigned long flags; + + spin_lock_irqsave(&bucket->lock, flags); + list_for_each_entry(entry, &bucket->list, list) { + if (!dev || dev == entry->dev) { + cln = to_cacheline_number(entry); + dev_info(entry->dev, + "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n", + type2name[entry->type], idx, + phys_addr(entry), entry->pfn, + entry->dev_addr, entry->size, + cln, dir2name[entry->direction], + maperr2str[entry->map_err_type]); + } + } + spin_unlock_irqrestore(&bucket->lock, flags); + + cond_resched(); + } +} + +/* + * Dump mappings entries on user space via debugfs + */ +static int dump_show(struct seq_file *seq, void *v) +{ + int idx; + phys_addr_t cln; + + for (idx = 0; idx < HASH_SIZE; idx++) { + struct hash_bucket *bucket = &dma_entry_hash[idx]; + struct dma_debug_entry *entry; + unsigned long flags; + + spin_lock_irqsave(&bucket->lock, flags); + list_for_each_entry(entry, &bucket->list, list) { + cln = to_cacheline_number(entry); + seq_printf(seq, + "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n", + dev_driver_string(entry->dev), + dev_name(entry->dev), + type2name[entry->type], idx, + phys_addr(entry), entry->pfn, + entry->dev_addr, entry->size, + cln, dir2name[entry->direction], + maperr2str[entry->map_err_type]); + } + spin_unlock_irqrestore(&bucket->lock, flags); + } + return 0; +} +DEFINE_SHOW_ATTRIBUTE(dump); + /* * Wrapper function for adding an entry to the hash. * This function takes care of locking itself. @@ -765,33 +798,6 @@ static const struct file_operations filter_fops = { .llseek = default_llseek, }; -static int dump_show(struct seq_file *seq, void *v) -{ - int idx; - - for (idx = 0; idx < HASH_SIZE; idx++) { - struct hash_bucket *bucket = &dma_entry_hash[idx]; - struct dma_debug_entry *entry; - unsigned long flags; - - spin_lock_irqsave(&bucket->lock, flags); - list_for_each_entry(entry, &bucket->list, list) { - seq_printf(seq, - "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx %s %s\n", - dev_name(entry->dev), - dev_driver_string(entry->dev), - type2name[entry->type], idx, - phys_addr(entry), entry->pfn, - entry->dev_addr, entry->size, - dir2name[entry->direction], - maperr2str[entry->map_err_type]); - } - spin_unlock_irqrestore(&bucket->lock, flags); - } - return 0; -} -DEFINE_SHOW_ATTRIBUTE(dump); - static int __init dma_debug_fs_init(void) { struct dentry *dentry = debugfs_create_dir("dma-api", NULL); From patchwork Wed Mar 15 19:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Desnes Nunes X-Patchwork-Id: 663954 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E5F5C6FD1D for ; Wed, 15 Mar 2023 19:24:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232856AbjCOTXa (ORCPT ); Wed, 15 Mar 2023 15:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232869AbjCOTXD (ORCPT ); Wed, 15 Mar 2023 15:23:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60B2D96C06 for ; Wed, 15 Mar 2023 12:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678908134; 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=i+mGYYulQUCelnuxj3PjgHCArB8Ei0mGxcOTGUHa8as=; b=Teh+yOeUCVohYlRW+7d5ZrpB0TJhUfc0LhundYpe4w4RnZR2noWJ+jLmkuPxXsfqRj+eFt ez144sB7cikViECiHd5oBlztn/R9vbRkoFzWGhMyyaSq5YeUdEN/NhdVhChk4YfXuvl4Vy Hrk0hJaEPWM3fY3H+yguir4h5oDM3NM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-MIUoPsYsPhadvaVkGwszxA-1; Wed, 15 Mar 2023 15:22:11 -0400 X-MC-Unique: MIUoPsYsPhadvaVkGwszxA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45D673801F4E; Wed, 15 Mar 2023 19:22:10 +0000 (UTC) Received: from desnesn.remote.csb (ovpn-116-3.gru2.redhat.com [10.97.116.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB1E340C6E69; Wed, 15 Mar 2023 19:22:07 +0000 (UTC) From: Desnes Nunes To: iommu@lists.linux.dev, linux-scsi@vger.kernel.org, storagedev@microchip.com, linux-kernel@vger.kernel.org Cc: hch@lst.de, martin.petersen@oracle.com, don.brace@microchip.com, m.szyprowski@samsung.com, robin.murphy@arm.com, jejb@linux.ibm.com, jsnitsel@redhat.com, Desnes Nunes Subject: [PATCH 3/3] scsi: smartpqi: fix DMA overlapping mappings asymmetry Date: Wed, 15 Mar 2023 16:21:30 -0300 Message-Id: <20230315192130.970021-4-desnesn@redhat.com> In-Reply-To: <20230315192130.970021-1-desnesn@redhat.com> References: <20230315192130.970021-1-desnesn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Currently, pqi_keep_device_offline() calls pqi_build_raid_path_request() (i.e., a wrapper to pqi_map_single()), but there isn't a pqi_pci_unmap() call in pqi_keep_device_offline(). Hence, this is flaged as an API viola- tion due to the overlapping mapping of the physical address. This patch fixes following warning: DMA-API: smartpqi 0000:43:00.0: cacheline tracking EEXIST, overlapping mappings aren't supported WARNING: CPU: 0 PID: 15 at kernel/dma/debug.c:570 add_dma_entry+0x1f6/0x2f0 CPU: 0 PID: 15 Comm: kworker/0:1 Not tainted 6.3.0-rc1-linux #1 Call Trace: dma_map_page_attrs+0x6f/0xa0 pqi_map_single+0xaa/0x160 [smartpqi] pqi_keep_device_offline+0xaf/0x160 [smartpqi] ? dma_unmap_page_attrs+0x1a1/0x1e0 ? pqi_identify_physical_device.constprop.0+0xd3/0xe0 [smartpqi] pqi_update_scsi_devices+0x284/0x7e0 [smartpqi] pqi_scan_scsi_devices+0x87/0xe0 [smartpqi] pqi_ctrl_init+0x725/0xa60 [smartpqi] pqi_pci_probe+0xa7/0x130 [smartpqi] local_pci_probe+0x46/0xa0 work_for_cpu_fn+0x16/0x20 process_one_work+0x2bf/0x670 ? __pfx_worker_thread+0x10/0x10 worker_thread+0x1d1/0x3b0 ? __pfx_worker_thread+0x10/0x10 kthread+0xf3/0x120 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x2c/0x50 Fixes: be76f90668d8 ("scsi: smartpqi: Add TEST UNIT READY check for SANITIZE operation") Signed-off-by: Desnes Nunes --- drivers/scsi/smartpqi/smartpqi_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c index 49a8f91810b6..6fca497ca605 100644 --- a/drivers/scsi/smartpqi/smartpqi_init.c +++ b/drivers/scsi/smartpqi/smartpqi_init.c @@ -1726,6 +1726,8 @@ static bool pqi_keep_device_offline(struct pqi_ctrl_info *ctrl_info, rc = pqi_submit_raid_request_synchronous(ctrl_info, &request.header, 0, &error_info); + pqi_pci_unmap(ctrl_info->pci_dev, request.sg_descriptors, 1, dir); + if (rc) goto out; /* Assume not offline */