Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2920302pxb; Tue, 12 Oct 2021 16:39:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3EyerFyC+2Sd9sdYIdBSe9zDNofAa9WKhfxZvUM9EfKFkNN8Wbbn4I9VFp91j6+G9zU56 X-Received: by 2002:a63:7d59:: with SMTP id m25mr15152328pgn.46.1634081972930; Tue, 12 Oct 2021 16:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634081972; cv=none; d=google.com; s=arc-20160816; b=bKCmToeDt8YFWRKg26gOU+oN35+64dKTvGQf/iubwSBXMAsEza0IEtCH7R3X9qiN8n 8vmFeRmpZuYt7RduZu4krujGZmioXMSNZOtVv2vwEQ66mcHV7bBLGiCZNcbG9GAV0OwX V5HQLDreW8XZZj2DfAt9AXROlC4agW7VZobO8VEB1uPCTRzXUZMNLIt11wTWipPDT2Be wJnF+luQBNZ82iB0Td9K8KosQqQjB0ffH/pBACm0k5WRrqYGQMcjiYToWS4JMt1vrHpJ qg8R0ot3UgMoDQVI7fjbc3Q9ATftAnzEDj69rw1+gcSVEPzdhB5gWfCVqvT7aFj9qhpw qdwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=q117RSLv3RobY8UuO/vQ7wnIEv8TSbDfx48RDKhsmIM=; b=F3ega09gVNICpzndBCq7oBdtPAvpbrLQG+xq9BJhjqer4C0cN62nBZg0322olAjQ7G pk49dCiRv6/Ugx7iCEQpc5D/eM+jBiS6vOKchd0xzqisLk1pSL/YG/LiVTkPMmpGefwK AF+/u9gwDFBiE0i6BxSfKEVDKRTTabqns9BpsohbJBj6Xh2g3YRmnJREQMqre/yRMCyn 5mYwGvGkfxN7gv+xdbb7jMSxnHp+do9QDV+xgafmK2UdfhBlH/oODUrtzEuIAb4t710O mf76DAGee6PapPYOrkxWflvpP9Yg5NefA0Dt8lfiMWLdMt8hGD85Mgc8vtBiACncibs0 g01A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Epu0peO6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 127si3743024pfe.180.2021.10.12.16.39.20; Tue, 12 Oct 2021 16:39:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Epu0peO6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236249AbhJLXkH (ORCPT + 99 others); Tue, 12 Oct 2021 19:40:07 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:46697 "EHLO wout1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236054AbhJLXkG (ORCPT ); Tue, 12 Oct 2021 19:40:06 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 32C203200DA8; Tue, 12 Oct 2021 19:38:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 12 Oct 2021 19:38:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=q117RS Lv3RobY8UuO/vQ7wnIEv8TSbDfx48RDKhsmIM=; b=Epu0peO6s1ANPAo9FDqcT1 XCxAVvX8Xa1kCCaQ1JLq7xhEXCUv0YIGpgBo/pQE3oxY0Cw5pvoVbrcrdU6qxPWr pFhaxHhwkH+PmpfUQIli/lGkMQBCBEzKdioeR5RYtPvjXfubkb22fliufL3VyU+X +0gnHLDFlLUkUSdVlAIMcbIKoJOfRnEAoL5pvywPwyluIFNSwXODC0yfgd7quFgP Yc5hFMCWlKCyXPdj+9Bc6v8SgSUJRQnnXDVoHqZvrGQLN84Rabgn1tZYW1EUj/+h SYvfQx07gUcCwN+N/7idvCgwbSBfcB4flXvhbZua1/ik6osyEGlzwivuY3yJKzeA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddtledgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffujgfkfhggtgesthdtredttddtvdenucfhrhhomhephfhinhhnucfv hhgrihhnuceofhhthhgrihhnsehlihhnuhigqdhmieekkhdrohhrgheqnecuggftrfgrth htvghrnhepffduhfegfedvieetudfgleeugeehkeekfeevfffhieevteelvdfhtdevffet uedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepfh hthhgrihhnsehlihhnuhigqdhmieekkhdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Oct 2021 19:38:00 -0400 (EDT) Date: Wed, 13 Oct 2021 10:37:56 +1100 (AEDT) From: Finn Thain To: Cai Huoqing cc: hch@infradead.org, Michael Cyr , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] scsi: ibmvscsi_tgt: Use dma_alloc_noncoherent() instead of get_zeroed_page/dma_map_single() In-Reply-To: <20211012032110.2224-1-caihuoqing@baidu.com> Message-ID: References: <20211012032110.2224-1-caihuoqing@baidu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 Oct 2021, Cai Huoqing wrote: > Replacing get_zeroed_page/free_page/dma_map_single/dma_unmap_single() > with dma_alloc_noncoherent/dma_free_noncoherent() helps to reduce > code size, and simplify the code, and the hardware keep DMA coherent > itself. > > Signed-off-by: Cai Huoqing > --- > v1->v2: > *Change to dma_alloc/free_noncoherent from dma_alloc/free_coherent. > *Update changelog. > > drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 46 ++++++++---------------- > 1 file changed, 15 insertions(+), 31 deletions(-) > > diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c > index 61f06f6885a5..91199b969718 100644 > --- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c > +++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c > @@ -3007,20 +3007,13 @@ static long ibmvscsis_create_command_q(struct scsi_info *vscsi, int num_cmds) > > vscsi->cmd_q.size = pages; > > - vscsi->cmd_q.base_addr = > - (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL); > - if (!vscsi->cmd_q.base_addr) > - return -ENOMEM; > - > vscsi->cmd_q.mask = ((uint)pages * CRQ_PER_PAGE) - 1; > > - vscsi->cmd_q.crq_token = dma_map_single(&vdev->dev, > - vscsi->cmd_q.base_addr, > - PAGE_SIZE, DMA_BIDIRECTIONAL); > - if (dma_mapping_error(&vdev->dev, vscsi->cmd_q.crq_token)) { > - free_page((unsigned long)vscsi->cmd_q.base_addr); > + vscsi->cmd_q.base_addr = dma_alloc_noncoherent(&vdev->dev, PAGE_SIZE, > + &vscsi->cmd_q.crq_token, > + DMA_BIDIRECTIONAL, GFP_KERNEL); > + if (!vscsi->cmd_q.base_addr) > return -ENOMEM; > - } > > return 0; > } > @@ -3036,9 +3029,9 @@ static long ibmvscsis_create_command_q(struct scsi_info *vscsi, int num_cmds) > */ > static void ibmvscsis_destroy_command_q(struct scsi_info *vscsi) > { > - dma_unmap_single(&vscsi->dma_dev->dev, vscsi->cmd_q.crq_token, > - PAGE_SIZE, DMA_BIDIRECTIONAL); > - free_page((unsigned long)vscsi->cmd_q.base_addr); > + dma_free_noncoherent(&vscsi->dma_dev->dev, > + PAGE_SIZE, vscsi->cmd_q.base_addr, > + vscsi->cmd_q.crq_token, DMA_BIDIRECTIONAL); > vscsi->cmd_q.base_addr = NULL; > vscsi->state = NO_QUEUE; > } > @@ -3504,18 +3497,12 @@ static int ibmvscsis_probe(struct vio_dev *vdev, > goto free_timer; > } > > - vscsi->map_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); > + vscsi->map_buf = dma_alloc_noncoherent(&vdev->dev, > + PAGE_SIZE, &vscsi->map_ioba, > + DMA_BIDIRECTIONAL, GFP_KERNEL); > if (!vscsi->map_buf) { > rc = -ENOMEM; > dev_err(&vscsi->dev, "probe: allocating cmd buffer failed\n"); > - goto destroy_queue; > - } > - > - vscsi->map_ioba = dma_map_single(&vdev->dev, vscsi->map_buf, PAGE_SIZE, > - DMA_BIDIRECTIONAL); > - if (dma_mapping_error(&vdev->dev, vscsi->map_ioba)) { > - rc = -ENOMEM; > - dev_err(&vscsi->dev, "probe: error mapping command buffer\n"); > goto free_buf; Shouldn't that be goto destroy_queue? > } > > @@ -3544,7 +3531,7 @@ static int ibmvscsis_probe(struct vio_dev *vdev, > if (!vscsi->work_q) { > rc = -ENOMEM; > dev_err(&vscsi->dev, "create_workqueue failed\n"); > - goto unmap_buf; > + goto destroy_queue; And goto free_buf? > } > > rc = request_irq(vdev->irq, ibmvscsis_interrupt, 0, "ibmvscsis", vscsi); > @@ -3562,11 +3549,9 @@ static int ibmvscsis_probe(struct vio_dev *vdev, > > destroy_WQ: > destroy_workqueue(vscsi->work_q); > -unmap_buf: > - dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE, > - DMA_BIDIRECTIONAL); > free_buf: > - kfree(vscsi->map_buf); > + dma_free_noncoherent(&vdev->dev, PAGE_SIZE, vscsi->map_buf, > + vscsi->map_ioba, DMA_BIDIRECTIONAL); > destroy_queue: > tasklet_kill(&vscsi->work_task); > ibmvscsis_unregister_command_q(vscsi); > @@ -3602,9 +3587,8 @@ static void ibmvscsis_remove(struct vio_dev *vdev) > vio_disable_interrupts(vdev); > free_irq(vdev->irq, vscsi); > destroy_workqueue(vscsi->work_q); > - dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE, > - DMA_BIDIRECTIONAL); > - kfree(vscsi->map_buf); > + dma_free_noncoherent(&vdev->dev, PAGE_SIZE, vscsi->map_buf, > + vscsi->map_ioba, DMA_BIDIRECTIONAL); > tasklet_kill(&vscsi->work_task); > ibmvscsis_destroy_command_q(vscsi); > ibmvscsis_freetimer(vscsi); >