mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
To: Peng Hongchi <hongchi.peng@siengine.com>,
	Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: dwc2: gadget: Don't write invalid mapped sg entries into dma_desc with iommu enabled
Date: Thu, 6 Jun 2024 07:12:08 +0000	[thread overview]
Message-ID: <2ee9afe4-4efd-6f07-7e61-37fec8dc50d5@synopsys.com> (raw)
In-Reply-To: <20240523100315.7226-1-hongchi.peng@siengine.com>



On 5/23/24 14:03, Peng Hongchi wrote:
> When using dma_map_sg() to map the scatterlist with iommu enabled,
> the entries in the scatterlist can be mergerd into less but longer
> entries in the function __finalise_sg(). So that the number of
> valid mapped entries is actually smaller than ureq->num_reqs,and
> there are still some invalid entries in the scatterlist with
> dma_addr=0xffffffff and len=0. Writing these invalid sg entries
> into the dma_desc can cause a data transmission error.
> 
> The function dma_map_sg() returns the number of valid map entries
> and the return value is assigned to usb_request::num_mapped_sgs in
> function usb_gadget_map_request_by_dev(). So that just write valid
> mapped entries into dma_desc according to the usb_request::num_mapped_sgs,
> and set the IOC bit if it's the last valid mapped entry.
> 
> This patch poses no risk to no-iommu situation, cause
> ureq->num_mapped_sgs equals ureq->num_sgs while using dma_direct_map_sg()
> to map the scatterlist whith iommu disabled.
> 
> Signed-off-by: Peng Hongchi <hongchi.peng@siengine.com>

Acked-by: Minas Harutyunyan <hminas@synopsys.com>

> ---
>   drivers/usb/dwc2/gadget.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index 74ac79abd8f3..e7bf9cc635be 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -885,10 +885,10 @@ static void dwc2_gadget_config_nonisoc_xfer_ddma(struct dwc2_hsotg_ep *hs_ep,
>   	}
>   
>   	/* DMA sg buffer */
> -	for_each_sg(ureq->sg, sg, ureq->num_sgs, i) {
> +	for_each_sg(ureq->sg, sg, ureq->num_mapped_sgs, i) {
>   		dwc2_gadget_fill_nonisoc_xfer_ddma_one(hs_ep, &desc,
>   			sg_dma_address(sg) + sg->offset, sg_dma_len(sg),
> -			sg_is_last(sg));
> +			(i == (ureq->num_mapped_sgs - 1)));
>   		desc_count += hs_ep->desc_count;
>   	}
>   

      reply	other threads:[~2024-06-06  7:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23 10:03 Peng Hongchi
2024-06-06  7:12 ` Minas Harutyunyan [this message]

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=2ee9afe4-4efd-6f07-7e61-37fec8dc50d5@synopsys.com \
    --to=minas.harutyunyan@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hongchi.peng@siengine.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®