From patchwork Mon Mar 5 06:45:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreekanth Reddy X-Patchwork-Id: 10258187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BC7E76037E for ; Mon, 5 Mar 2018 06:45:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7AE62654B for ; Mon, 5 Mar 2018 06:45:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C30B2886D; Mon, 5 Mar 2018 06:45:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E57162654B for ; Mon, 5 Mar 2018 06:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932959AbeCEGph (ORCPT ); Mon, 5 Mar 2018 01:45:37 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34281 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932832AbeCEGpf (ORCPT ); Mon, 5 Mar 2018 01:45:35 -0500 Received: by mail-pf0-f193.google.com with SMTP id j20so6827224pfi.1 for ; Sun, 04 Mar 2018 22:45:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:references:in-reply-to:mime-version:thread-index:date :message-id:subject:to:cc; bh=eIwFEZovmKxgIj8qks21opEYICbWn/1NQsV3soSS0as=; b=TCKwbuyy1uobWAusa9PRlHVKijLzREtxg1wPwp55QjtQwAgbRv07pGzWalDCN6xX1C dSDKHR2enGXUgewEdBar8Jfv7YfrgAeVwXHIyxg7A1FdvFVDJ1s8EEC4eoukml6nuCuB tWd80Spw001eMujtqvZ/stAO4afk+WfN3vWIg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc; bh=eIwFEZovmKxgIj8qks21opEYICbWn/1NQsV3soSS0as=; b=UmerYPQtRjbn+T4WqrdTohzws/xluZdz95XZpmXYtUjNc0OFAn43PxnsiOxEHWac7y x12pVfSRvRBzmS72FdIDyT0Du7FVZct+c2FZxQGxJ24y17bAZ5rPzMEmNOVQ7hb0jp0X qJ78S/GaTM55vbByL5tcyQQA4aItNhHYOPz08uvyyWZmDg22akZte57WXDC1a1njzLhW NULM70dyJrfZSImf8oyFLJx7iG4skwDIbnfa80X9TPtuEMPQMbzBViVJbc96Ho1qWAtC /YfKtkFuX/nZbkQQwV+gMBNxxCbpaGkehX2FEs+/xp6OeMm4ByGvtGnV73sXOmiD6VS/ idvQ== X-Gm-Message-State: APf1xPAN1063Afs518yf6GD14lHKLd9Jku5lEKu//FcZCX2CmsmJv4q2 CCZ2LAzeKThEvJWo7mxmV9/0st+Fg/TNwRCC8QTEDg== X-Google-Smtp-Source: AG47ELv7XtpOpFUhnnv4HNSicMansbiOkUXH5mBzhaS2cd+FODMSw9SGm+cFxDcuY3I+mRA4HBlokxFkt3IGqCJ6jpU= X-Received: by 10.98.18.70 with SMTP id a67mr14302032pfj.213.1520232334798; Sun, 04 Mar 2018 22:45:34 -0800 (PST) From: Sreekanth Reddy References: <20180301130729.3278022-1-arnd@arndb.de> In-Reply-To: <20180301130729.3278022-1-arnd@arndb.de> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQMtp/Bh4yYS/yIQvEtH+n2ZC8G49KENSwDw Date: Mon, 5 Mar 2018 12:15:32 +0530 Message-ID: Subject: RE: [PATCH] scsi: mpt3sas: clarify mmio pointer types To: Arnd Bergmann , Suganath Prabu Subramani , Sathya Prakash Veerichetty , Chaitra Basappa , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Hannes Reinecke , PDL-MPT-FUSIONLINUX , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP -----Original Message----- From: Arnd Bergmann [mailto:arnd@arndb.de] Sent: Thursday, March 1, 2018 6:37 PM To: Suganath Prabu S; Sathya Prakash; Chaitra P B; James E.J. Bottomley; Martin K. Petersen Cc: Arnd Bergmann; Hannes Reinecke; Sreekanth Reddy; MPT-FusionLinux.pdl@broadcom.com; linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org Subject: [PATCH] scsi: mpt3sas: clarify mmio pointer types The newly added code mixes up phys_addr_t/resource_size_t with dma_addr_t and void pointers, as seen from these compiler warning: drivers/scsi/mpt3sas/mpt3sas_base.c: In function '_base_get_chain_phys': drivers/scsi/mpt3sas/mpt3sas_base.c:235:21: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] base_chain_phys = (void *)ioc->chip_phys + MPI_FRAME_START_OFFSET + ^ drivers/scsi/mpt3sas/mpt3sas_base.c: In function '_clone_sg_entries': drivers/scsi/mpt3sas/mpt3sas_base.c:427:20: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] sgel->Address = (dma_addr_t)dst_addr_phys; ^ drivers/scsi/mpt3sas/mpt3sas_base.c:438:7: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] (dma_addr_t)buff_ptr_phys; ^ drivers/scsi/mpt3sas/mpt3sas_base.c:444:10: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] (dma_addr_t)buff_ptr_phys; Both dma_addr_t and phys_addr_t may be wider than a pointer, so we must avoid the conversion to pointer types. This also helps readability. A second problem is treating MMIO addresses from a 'struct resource' as addresses that can be used for DMA on that device. In almost all cases, those are the same, but on some of the more obscure architectures, PCI memory address 0 is mapped into the CPU address space at a nonzero offset. I don't have a good fix for that, so I'm adding a comment here, plus a WARN_ON() that triggers whenever the phys_addr_t number is outside of the low 32-bit address space and causes a straight overflow when assigned to the 32-bit sgel->Address. Fixes: 182ac784b41f ("scsi: mpt3sas: Introduce Base function for cloning.") Signed-off-by: Arnd Bergmann --- drivers/scsi/mpt3sas/mpt3sas_base.c | 42 ++++++++++++++++++++----------------- drivers/scsi/mpt3sas/mpt3sas_base.h | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) -- 2.9.0 Acked-by: Sreekanth Reddy Thanks, Sreekanth diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 9f2434e59b40..61f93a134956 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -225,14 +225,14 @@ _base_get_chain(struct MPT3SAS_ADAPTER *ioc, u16 smid, * * @Return - Physical chain address. */ -static inline void * +static inline phys_addr_t _base_get_chain_phys(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 sge_chain_count) { - void *base_chain_phys, *chain_phys; + phys_addr_t base_chain_phys, chain_phys; u16 cmd_credit = ioc->facts.RequestCredit + 1; - base_chain_phys = (void *)ioc->chip_phys + MPI_FRAME_START_OFFSET + + base_chain_phys = ioc->chip_phys + MPI_FRAME_START_OFFSET + (cmd_credit * ioc->request_sz) + REPLY_FREE_POOL_SIZE; chain_phys = base_chain_phys + (smid * ioc->facts.MaxChainDepth * @@ -272,11 +272,11 @@ _base_get_buffer_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) * * @Returns - Pointer to buffer location in BAR0. */ -static void * +static phys_addr_t _base_get_buffer_phys_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) { u16 cmd_credit = ioc->facts.RequestCredit + 1; - void *chain_end_phys = _base_get_chain_phys(ioc, + phys_addr_t chain_end_phys = _base_get_chain_phys(ioc, cmd_credit + 1, ioc->facts.MaxChainDepth); return chain_end_phys + (smid * 64 * 1024); @@ -330,11 +330,12 @@ static void _clone_sg_entries(struct MPT3SAS_ADAPTER *ioc, bool is_write = 0; u16 i = 0; void __iomem *buffer_iomem; - void *buffer_iomem_phys; + phys_addr_t buffer_iomem_phys; void __iomem *buff_ptr; - void *buff_ptr_phys; + phys_addr_t buff_ptr_phys; void __iomem *dst_chain_addr[MCPU_MAX_CHAINS_PER_IO]; - void *src_chain_addr[MCPU_MAX_CHAINS_PER_IO], *dst_addr_phys; + void *src_chain_addr[MCPU_MAX_CHAINS_PER_IO]; + phys_addr_t dst_addr_phys; MPI2RequestHeader_t *request_hdr; struct scsi_cmnd *scmd; struct scatterlist *sg_scmd = NULL; @@ -391,6 +392,7 @@ static void _clone_sg_entries(struct MPT3SAS_ADAPTER *ioc, buff_ptr = buffer_iomem; buff_ptr_phys = buffer_iomem_phys; + WARN_ON(buff_ptr_phys > U32_MAX); if (sgel->FlagsLength & (MPI2_SGE_FLAGS_HOST_TO_IOC << MPI2_SGE_FLAGS_SHIFT)) @@ -421,10 +423,10 @@ static void _clone_sg_entries(struct MPT3SAS_ADAPTER *ioc, smid, sge_chain_count); src_chain_addr[sge_chain_count] = (void *) sgel_next; - dst_addr_phys = - _base_get_chain_phys(ioc, + dst_addr_phys = _base_get_chain_phys(ioc, smid, sge_chain_count); - sgel->Address = (dma_addr_t)dst_addr_phys; + WARN_ON(dst_addr_phys > U32_MAX); + sgel->Address = (u32)dst_addr_phys; sgel = sgel_next; sge_chain_count++; break; @@ -434,14 +436,16 @@ static void _clone_sg_entries(struct MPT3SAS_ADAPTER *ioc, _base_clone_to_sys_mem(buff_ptr, sg_virt(sg_scmd), (sgel->FlagsLength & 0x00ffffff)); - sgel->Address = - (dma_addr_t)buff_ptr_phys; + /* + * FIXME: this relies on a a zero + * PCI mem_offset. + */ + sgel->Address = (u32)buff_ptr_phys; } else { _base_clone_to_sys_mem(buff_ptr, ioc->config_vaddr, (sgel->FlagsLength & 0x00ffffff)); - sgel->Address = - (dma_addr_t)buff_ptr_phys; + sgel->Address = (u32)buff_ptr_phys; } } buff_ptr += (sgel->FlagsLength & 0x00ffffff); @@ -2941,7 +2945,7 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) u32 pio_sz; int i, r = 0; u64 pio_chip = 0; - u64 chip_phys = 0; + phys_addr_t chip_phys = 0; struct adapter_reply_queue *reply_q; dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", @@ -2989,7 +2993,7 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) if (memap_sz) continue; ioc->chip_phys = pci_resource_start(pdev, i); - chip_phys = (u64)ioc->chip_phys; + chip_phys = ioc->chip_phys; memap_sz = pci_resource_len(pdev, i); ioc->chip = ioremap(ioc->chip_phys, memap_sz); } @@ -3064,8 +3068,8 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) "IO-APIC enabled"), pci_irq_vector(ioc->pdev, reply_q->msix_index)); - pr_info(MPT3SAS_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n", - ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz); + pr_info(MPT3SAS_FMT "iomem(%pap), mapped(0x%p), size(%d)\n", + ioc->name, &chip_phys, ioc->chip, memap_sz); pr_info(MPT3SAS_FMT "ioport(0x%016llx), size(%d)\n", ioc->name, (unsigned long long)pio_chip, pio_sz); diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index df8233c1e1c1..ae36d8fb2f2b 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -1103,7 +1103,7 @@ struct MPT3SAS_ADAPTER { char tmp_string[MPT_STRING_LENGTH]; struct pci_dev *pdev; Mpi2SystemInterfaceRegs_t __iomem *chip; - resource_size_t chip_phys; + phys_addr_t chip_phys; int logging_level; int fwfault_debug; u8 ir_firmware;