All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: arnd@arndb.de, hch@infradead.org, akpm@linux-foundation.org,
	sathya.prakash@broadcom.com, sreekanth.reddy@broadcom.com,
	suganath-prabu.subramani@broadcom.com
Cc: MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Subject: [PATCH 15/16] scsi: mptctl: Use dma_alloc_coherent()
Date: Thu,  6 Jan 2022 22:54:39 +0100	[thread overview]
Message-ID: <516375d6d06114484533baf03aae351306100246.1641500561.git.christophe.jaillet@wanadoo.fr> (raw)
In-Reply-To: <cover.1641500561.git.christophe.jaillet@wanadoo.fr>

In [1], Christoph Hellwig has proposed to remove the wrappers in
include/linux/pci-dma-compat.h.

Some reasons why this API should be removed have been given by Julia
Lawall in [2].


When memory is allocated in kbuf_alloc_2_sgl() GFP_KERNEL can be used
because this function already uses the GFP_USER flag for some memory
allocation and not spin_lock is taken in the between.

When memory is allocated in mptctl_do_mpt_command() GFP_KERNEL can be
used because this function already uses copy_from_user() and this
function can sleep.

When memory is allocated in mptctl_hp_hostinfo() GFP_KERNEL can be used
because this function already uses mpt_config() and this function has
an explicit might_sleep().

When memory is allocated in mptctl_hp_targetinfo() GFP_KERNEL can be used
because this function already uses mpt_config() and this function has
an explicit might_sleep().


[1]: https://lore.kernel.org/kernel-janitors/20200421081257.GA131897@infradead.org/
[2]: https://lore.kernel.org/kernel-janitors/alpine.DEB.2.22.394.2007120902170.2424@hadrien/

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
I'm a bit unsure about the use of GFP_KERNEL in kbuf_alloc_2_sgl().

In all conversion that I've done, GFP_USER was never used. I don't fully
understand the difference between GFP_USER and GFP_KERNEL.
---
 drivers/message/fusion/mptctl.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 0f447179e3f5..03c8fb1795c2 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -1041,7 +1041,8 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
 	 * copying the data in this array into the correct place in the
 	 * request and chain buffers.
 	 */
-	sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
+	sglbuf = dma_alloc_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES,
+				    sglbuf_dma, GFP_KERNEL);
 	if (sglbuf == NULL)
 		goto free_and_fail;
 
@@ -1062,9 +1063,9 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
 	while (bytes_allocd < bytes) {
 		this_alloc = min(alloc_sz, bytes-bytes_allocd);
 		buflist[buflist_ent].len = this_alloc;
-		buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
-								 this_alloc,
-								 &pa);
+		buflist[buflist_ent].kptr = dma_alloc_coherent(&ioc->pcidev->dev,
+							       this_alloc,
+							       &pa, GFP_KERNEL);
 		if (buflist[buflist_ent].kptr == NULL) {
 			alloc_sz = alloc_sz / 2;
 			if (alloc_sz == 0) {
@@ -2105,8 +2106,9 @@ mptctl_do_mpt_command (MPT_ADAPTER *ioc, struct mpt_ioctl_command karg, void __u
 			}
 			flagsLength |= karg.dataOutSize;
 			bufOut.len = karg.dataOutSize;
-			bufOut.kptr = pci_alloc_consistent(
-					ioc->pcidev, bufOut.len, &dma_addr_out);
+			bufOut.kptr = dma_alloc_coherent(&ioc->pcidev->dev,
+							 bufOut.len,
+							 &dma_addr_out, GFP_KERNEL);
 
 			if (bufOut.kptr == NULL) {
 				rc = -ENOMEM;
@@ -2139,8 +2141,9 @@ mptctl_do_mpt_command (MPT_ADAPTER *ioc, struct mpt_ioctl_command karg, void __u
 			flagsLength |= karg.dataInSize;
 
 			bufIn.len = karg.dataInSize;
-			bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
-					bufIn.len, &dma_addr_in);
+			bufIn.kptr = dma_alloc_coherent(&ioc->pcidev->dev,
+							bufIn.len,
+							&dma_addr_in, GFP_KERNEL);
 
 			if (bufIn.kptr == NULL) {
 				rc = -ENOMEM;
@@ -2400,7 +2403,9 @@ mptctl_hp_hostinfo(MPT_ADAPTER *ioc, unsigned long arg, unsigned int data_size)
 			/* Issue the second config page request */
 			cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
 
-			pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
+			pbuf = dma_alloc_coherent(&ioc->pcidev->dev,
+						  hdr.PageLength * 4,
+						  &buf_dma, GFP_KERNEL);
 			if (pbuf) {
 				cfg.physAddr = buf_dma;
 				if (mpt_config(ioc, &cfg) == 0) {
@@ -2477,7 +2482,7 @@ mptctl_hp_hostinfo(MPT_ADAPTER *ioc, unsigned long arg, unsigned int data_size)
 	else
 		IstwiRWRequest->DeviceAddr = 0xB0;
 
-	pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
+	pbuf = dma_alloc_coherent(&ioc->pcidev->dev, 4, &buf_dma, GFP_KERNEL);
 	if (!pbuf)
 		goto out;
 	ioc->add_sge((char *)&IstwiRWRequest->SGL,
@@ -2592,7 +2597,8 @@ mptctl_hp_targetinfo(MPT_ADAPTER *ioc, unsigned long arg)
        /* Get the data transfer speeds
         */
 	data_sz = ioc->spi_data.sdp0length * 4;
-	pg0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
+	pg0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz, &page_dma,
+				       GFP_KERNEL);
 	if (pg0_alloc) {
 		hdr.PageVersion = ioc->spi_data.sdp0version;
 		hdr.PageLength = data_sz;
@@ -2657,7 +2663,8 @@ mptctl_hp_targetinfo(MPT_ADAPTER *ioc, unsigned long arg)
 		/* Issue the second config page request */
 		cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
 		data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
-		pg3_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
+		pg3_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
+					       &page_dma, GFP_KERNEL);
 		if (pg3_alloc) {
 			cfg.physAddr = page_dma;
 			cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
-- 
2.32.0


  parent reply	other threads:[~2022-01-06 21:55 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 21:45 [PATCH 00/16] Remove usage of the deprecated "pci-dma-compat.h" API Christophe JAILLET
2022-01-06 21:45 ` Christophe JAILLET
2022-01-06 21:46 ` [PATCH 01/16] alpha: " Christophe JAILLET
2022-01-10  8:43   ` Christoph Hellwig
2022-01-06 21:47 ` [PATCH 02/16] floppy: " Christophe JAILLET
2022-01-06 21:47   ` Christophe JAILLET
2022-01-10  8:43   ` Christoph Hellwig
2022-01-10  8:43     ` Christoph Hellwig
2022-01-06 21:49 ` [PATCH 03/16] fpga: dfl: pci: " Christophe JAILLET
2022-01-06 23:06   ` Arnd Bergmann
2022-01-07  0:58     ` Arnd Bergmann
2022-01-07  6:34       ` Christophe JAILLET
2022-01-10  8:44   ` Christoph Hellwig
2022-01-06 21:50 ` [PATCH 04/16] media: " Christophe JAILLET
2022-01-07  0:51   ` Arnd Bergmann
2022-01-07  7:10     ` Mauro Carvalho Chehab
2022-02-18 13:11       ` Hans Verkuil
2022-01-10  8:44   ` Christoph Hellwig
2022-01-06 21:51 ` [PATCH 05/16] agp/intel: " Christophe JAILLET
2022-01-07  0:53   ` Arnd Bergmann
2022-01-10  8:45   ` Christoph Hellwig
2022-01-06 21:51 ` [PATCH 06/16] sparc: " Christophe JAILLET
2022-01-07  0:54   ` Arnd Bergmann
2022-01-07 11:04   ` David Miller
2022-01-10  8:45   ` Christoph Hellwig
2022-01-06 21:52 ` [PATCH 07/16] dmaengine: pch_dma: " Christophe JAILLET
2022-01-07  0:56   ` Arnd Bergmann
2022-01-08 16:47     ` Vinod Koul
2022-01-10  8:45   ` Christoph Hellwig
2022-01-06 21:52 ` [PATCH 08/16] rapidio/tsi721: " Christophe JAILLET
2022-01-07  1:00   ` Arnd Bergmann
2022-01-10  8:46   ` Christoph Hellwig
2022-01-06 21:53 ` [PATCH 09/16] media: v4l2-pci-skeleton: " Christophe JAILLET
2022-01-07  1:01   ` Arnd Bergmann
2022-01-10  8:46   ` Christoph Hellwig
2022-01-06 21:54 ` [PATCH 10/16] scsi: message: fusion: " Christophe JAILLET
2022-01-10  8:47   ` Christoph Hellwig
2022-01-06 21:54 ` [PATCH 11/16] scsi: mptbase: Use dma_alloc_coherent() in 'mpt_alloc_fw_memory()' Christophe JAILLET
2022-01-10  8:47   ` Christoph Hellwig
2022-01-06 21:54 ` [PATCH 12/16] scsi: mptbase: Use dma_alloc_coherent() Christophe JAILLET
2022-01-10  8:47   ` Christoph Hellwig
2022-01-06 21:54 ` [PATCH 13/16] scsi: mptsas: Use dma_alloc_coherent() in mptsas_exp_repmanufacture_info() Christophe JAILLET
2022-01-10  8:48   ` Christoph Hellwig
2022-01-06 21:54 ` [PATCH 14/16] scsi: mptsas: Use dma_alloc_coherent() Christophe JAILLET
2022-01-10  8:48   ` Christoph Hellwig
2022-01-06 21:54 ` Christophe JAILLET [this message]
2022-01-10  8:48   ` [PATCH 15/16] scsi: mptctl: " Christoph Hellwig
2022-01-06 21:55 ` [PATCH 16/16] PCI: Remove usage of the deprecated "pci-dma-compat.h" API Christophe JAILLET
2022-01-06 22:28   ` Bjorn Helgaas
2022-01-07  6:34     ` Christophe JAILLET
2022-01-07 17:23       ` Marion & Christophe JAILLET
2022-01-10  8:49         ` Christoph Hellwig
2022-01-07  9:20   ` kernel test robot
2022-01-07  9:41   ` kernel test robot
2022-01-10 15:35 ` [PATCH 00/16] " Martin K. Petersen
2022-01-10 15:35   ` Martin K. Petersen
2022-01-10 15:35   ` Martin K. Petersen
2022-01-19  4:06 ` Martin K. Petersen
2022-01-19  4:06   ` Martin K. Petersen
2022-01-25 19:28 ` Moritz Fischer
2022-01-25 19:28   ` Moritz Fischer
2022-01-25 19:28   ` Moritz Fischer
2022-02-23  7:46 ` Christoph Hellwig
2022-02-23  7:46   ` Christoph Hellwig
2022-02-23  7:46   ` Christoph Hellwig
2022-02-23 20:26   ` Christophe JAILLET
2022-02-23 20:26     ` Christophe JAILLET
2022-02-23 20:42     ` Arnd Bergmann
2022-02-23 20:42       ` Arnd Bergmann
2022-02-23 20:42       ` Arnd Bergmann
2022-02-24  6:25     ` Christoph Hellwig
2022-02-24  6:25       ` Christoph Hellwig
2022-02-24  6:25       ` Christoph Hellwig
2022-02-24  7:07       ` Arnd Bergmann
2022-02-24  7:07         ` Arnd Bergmann
2022-02-24  7:07         ` Arnd Bergmann
2022-02-24 18:15         ` Christophe JAILLET
2022-02-24 18:15           ` Christophe JAILLET
2022-02-24 18:15           ` Christophe JAILLET
2022-02-25 16:20 ` Christoph Hellwig
2022-02-25 16:20   ` Christoph Hellwig
2022-02-25 16:20   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=516375d6d06114484533baf03aae351306100246.1641500561.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=MPT-FusionLinux.pdl@broadcom.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=hch@infradead.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sathya.prakash@broadcom.com \
    --cc=sreekanth.reddy@broadcom.com \
    --cc=suganath-prabu.subramani@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.