Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6459101ybi; Wed, 5 Jun 2019 01:05:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7kG6Ee0/jCU54yfynaLEl9+EtzB101BU/eFNdb0yPYUh4ciOuumnt/O1AF0lbv9+TBIOg X-Received: by 2002:a17:90a:ad05:: with SMTP id r5mr231125pjq.41.1559721927946; Wed, 05 Jun 2019 01:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559721927; cv=none; d=google.com; s=arc-20160816; b=yfMW+4wlO3ye/VsfLt5pUeAEYrHeBZVCNWMoyD+cEE/QytbE4Enulde38iuVmAur/H XKP9m6Sv6zPg5k8vOaf1w6wI6S3hDIgqBocNz27Dde+Zbwiue9C5dX8ffdx76swZmqqt eXr/oT+TvFAN40nBtwCcmGTDfg5F+X4xEL5d+gkQZCTIt42hVXtkj/JoCIrkY/V1KcOz yM6J7m62ywQiQFajOUZSpgJS3CvSVkm+mmkQ2qxgUoBkcF/g1qQ7+1XKQ4c9wQCsaUbE tzB+1sW7LQkH/m887koTI+SOGl1k1wjBabq9K+7kCLDghMJc6jGGKuSBVPe3YPAc6W0/ IG0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=KcRmtsAtploni+VGphkqFG1QVSm+Kg9tB5cFcUiwHPA=; b=axZaRwXS6G0FSv9aeauu7AHq6Ubl1bLcD1stqoEnPQWEz7bIvb5UR2XSDoLAt63J0D 9Cqt61WyCG0o+/Tuvf8ZA0hKpRYl0ykt6o5XbJ5dZ0lfgoyVdLdc2z0UBThA7GvD4Nby KcOdWKFjkcMNz4lJbHj6Uv9TewHDdR9Tnk/v+IBN8qZuWUlnq2R4KV+8AAs8kFK6EJK5 N9FBx6rK1AOvhZKXMRw6xaM6AcRg57ePoTnShbn2Jki15kLHFPwlIpupxYLhdDqI2HdR XN/vJtGF4NqPLoT6Ev5vidB0AQYlZ1bIIvUe6gJ80g9jmZmC/QRnBCqTN/Ym1QeMJDig jXPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si1892389plb.20.2019.06.05.01.05.10; Wed, 05 Jun 2019 01:05:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726794AbfFEIDs (ORCPT + 99 others); Wed, 5 Jun 2019 04:03:48 -0400 Received: from mga11.intel.com ([192.55.52.93]:56934 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726263AbfFEIDs (ORCPT ); Wed, 5 Jun 2019 04:03:48 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jun 2019 01:03:47 -0700 X-ExtLoop1: 1 Received: from pipin.fi.intel.com (HELO pipin) ([10.237.72.175]) by fmsmga006.fm.intel.com with ESMTP; 05 Jun 2019 01:03:46 -0700 From: Felipe Balbi To: Anurag Kumar Vulisha , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, v.anuragkumar@gmail.com, Anurag Kumar Vulisha Subject: Re: [PATCH] usb: dwc3: gadget: Correct the logic for finding last SG entry In-Reply-To: <1559141985-17104-1-git-send-email-anurag.kumar.vulisha@xilinx.com> References: <1559141985-17104-1-git-send-email-anurag.kumar.vulisha@xilinx.com> Date: Wed, 05 Jun 2019 11:03:42 +0300 Message-ID: <87y32gcvc1.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Anurag Kumar Vulisha writes: > As a process of preparing TRBs usb_gadget_map_request_by_dev() is > called from dwc3_prepare_trbs() for mapping the request. This will > call dma_map_sg() if req->num_sgs are greater than 0. dma_map_sg() > will map the sg entries in sglist and return the number of mapped SGs. > As a part of mapping, some sg entries having contigous memory may be > merged together into a single sg (when IOMMU used). So, the number of > mapped sg entries may not be equal to the number of orginal sg entries > in the request (req->num_sgs). > > As a part of preparing the TRBs, dwc3_prepare_one_trb_sg() iterates over > the sg entries present in the sglist and calls sg_is_last() to identify > whether the sg entry is last and set IOC bit for the last sg entry. The > sg_is_last() determines last sg if SG_END is set in sg->page_link. When > IOMMU used, dma_map_sg() merges 2 or more sgs into a single sg and it > doesn't retain the page_link properties. Because of this reason the > sg_is_last() may not find SG_END and thus resulting in IOC bit never > getting set. > > For example: > > Consider a request having 8 sg entries with each entry having a length of > 4096 bytes. Assume that sg1 & sg2, sg3 & sg4, sg5 & sg6, sg7 & sg8 are > having contigous memory regions. > > Before calling dma_map_sg(): > sg1-->sg2-->sg3-->sg4-->sg6-->sg7-->sg8 > dma_length: 4K 4K 4K 4K 4K 4K 4K > SG_END: False False False False False False True > num_sgs =3D 8 > num_mapped_sgs =3D 0 > > The dma_map_sg() merges sg1 & sg2 memory regions into sg1->dma_address. > Similarly sg3 & sg4 into sg2->dma_address, sg5 & sg6 into the > sg3->dma_address and sg6 & sg8 into sg4->dma_address. Here the memory > regions are merged but the page_link properties like SG_END are not > retained into the merged sgs. isn't this a bug in the scatterlist mapping code? Why doesn't it keep SG_END? =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEElLzh7wn96CXwjh2IzL64meEamQYFAlz3d14ACgkQzL64meEa mQbIKA/+Ii2ChJ8pGwu2ghUPIQnqcxUB7blHV78JMz1exJzlZJ1nJa+LicAky5rJ k2h0k2Ieaxqj/BExNkC6Q/NtDLSOKPIf7BHjZrjE60JnXexPFUuZiaupVVzVK356 5Y+VDvWVYW8q3DH4g4x7v3Z+ceY6cZiNYLnpKShdnsSyBJTrveTgMR375eYmgMZP vSc9eqDtN4goT2uqx3uBF6ZvT1r5Cwx1snmqSQiWGg+iDkVJbBC52IxS7mS5S85G cLQuIrMrJTwk/QS0xlrQjk5uJCZekruiRD5GsktWx+iUb0J2WAbaD3QYU/Hba/xQ qOdGkj/VPDfo4a0y2nVQIJd5ck6KEV1iOaAN0jx78PR0459nhQeZY19yGdkvTU9L wW2q7idyaiEDiZUMpaDyq6M+lfBCQUcYjJ5bCUluQEXwJy7srsuQlIh4s+XCCAVM puN3zV6f8FD+xJLCqQ0alw2JjbjZn53mW0W8eMTD2CSTFSl9GcCAdfblgmhciDBZ Yqrk8a7s0wDd7fA+/hGYUbJt5efLWHiPYY5Rqeh3GbOVEOP1LTN9/Ipsi6hM+Dxd FIkH2BjBD99TpIUQlrE+U6iaIUiy8b9pBPiORyjPcHGfdNK/7ITxQ7WWRZJznZRS MuQ0WAC2u60k8xwzouNwbXL/jcoUP6974/MDeOF5iK4di2YLogg= =uzJL -----END PGP SIGNATURE----- --=-=-=--