Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1139044pxb; Wed, 10 Feb 2021 00:37:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvgMDDF5BrT9zxReCghHTsEUR3fVRqwNPIUlFwmOQi8RT7rbdzNlXbH3MsKRLbmVHH1RcY X-Received: by 2002:a50:ec8f:: with SMTP id e15mr2126103edr.79.1612946260137; Wed, 10 Feb 2021 00:37:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612946260; cv=none; d=google.com; s=arc-20160816; b=n4TUPEBq8GgU7PCwQ+AXBJj48OJnHQxmtPC/g295mTIx7uqA2CQOWLk8wYJgH516oL ayzLuGVBMvkTid/2mFu+agz/MwFGkZAaaaYxa9x5kGXFdx5UXvFfiVgVLTod7m6qxLw6 /srxzefoKtf/kMXbqt719fzA1Q58F1bgoAJ11+wfW0HFRBMSZPaDM0PoK/JvlMtAcfC4 WNbpFCneuCXO9bzVHMKnx9cCArG9UqAZGDfD8fBLlP5pcD7/xwGytXDyLdoaa5W8BPex p8DS66Iio95Z+8+QHrYGtjk+XI3ufoBRg1apGz2Ifg9z/zajd9gRo7Ph/ILGAm88RoI7 GiVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=BIlfa2cy/5+Yjvxzsa3tehqtwaQL36b2B1AzhanU16c=; b=g8oSztN9Y6ydW85F+tLfiomIUsr1G+/hT/RjZ6IFERWy6QVSjc98rap1UYWDRlJ2Ki v7NSpf8FNB5Y2QP1o4YKbaFwRxJZaIU63AakkO4SRJHD1PErLPvJQmz8+3ZwQQpc61zi ow9mBJ3CdAKKeShVa+Jw8++CAsijSsGFBahYMlCVtiAV+eTzCE8vt1tcENgSAB+vmhW8 dYdoGJowQ6CUVUHiQbIYE1HkvHyi7VsIXp91E1QLstf+Cc3WWwCO+sYJ9x1o6ByFTZXi 6W8nrj9iQWc+Iy3swJnVGewjff98FOjF6sO1XeeRWk03iRnRgsHFxDbzwnWQckeYhPMD C9EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=T4f2DKPg; 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 kl4si868381ejc.341.2021.02.10.00.37.16; Wed, 10 Feb 2021 00:37:40 -0800 (PST) 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=@mg.codeaurora.org header.s=smtp header.b=T4f2DKPg; 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 S231254AbhBJFdS (ORCPT + 99 others); Wed, 10 Feb 2021 00:33:18 -0500 Received: from mail29.static.mailgun.info ([104.130.122.29]:18668 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231245AbhBJFdQ (ORCPT ); Wed, 10 Feb 2021 00:33:16 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1612935172; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=BIlfa2cy/5+Yjvxzsa3tehqtwaQL36b2B1AzhanU16c=; b=T4f2DKPgqCbkRPFd+GDpyX9m600fol2D04T/hqBE4pvk41o6w4Xnk5rpMw+luFZY4BJGo+a1 pXWE7fX/3Vc5kwyVpIDx5zqry8NYYtVnRI+jp0qBA5rhVfqePsPovm3lnForJaxgY2ptFBXa hNBhUylFj6XS0Yxey6/YnTwq6wA= X-Mailgun-Sending-Ip: 104.130.122.29 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-west-2.postgun.com with SMTP id 60236fe34bd23a05ae12ef52 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 10 Feb 2021 05:32:19 GMT Sender: cang=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id DA41CC433ED; Wed, 10 Feb 2021 05:32:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id A0779C433CA; Wed, 10 Feb 2021 05:32:17 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 10 Feb 2021 13:32:17 +0800 From: Can Guo To: Bean Huo Cc: Avri Altman , daejun7.park@samsung.com, Greg KH , jejb@linux.ibm.com, martin.petersen@oracle.com, asutoshd@codeaurora.org, stanley.chu@mediatek.com, bvanassche@acm.org, ALIM AKHTAR , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Sung-Jun Park , yongmyung lee , Jinyoung CHOI , BoRam Shin , SEUNGUK SHIN Subject: Re: [PATCH v19 3/3] scsi: ufs: Prepare HPB read for cached sub-region In-Reply-To: <4355a1ebffea1da290389c57eb2b42df75990c6e.camel@gmail.com> References: <20210129052848epcms2p6e5797efd94e6282b76ad9ae6c99e3ab5@epcms2p6> <20210129053042epcms2p538e7fa396c3c2104594c44e48be53eb8@epcms2p5> <7f25ccb1d857131baa1c0424c4542e33@codeaurora.org> <4355a1ebffea1da290389c57eb2b42df75990c6e.camel@gmail.com> Message-ID: X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-02-09 22:21, Bean Huo wrote: > On Tue, 2021-02-09 at 13:25 +0000, Avri Altman wrote: >> > >> > >> > > > > + put_unaligned_be64(ppn, &cdb[6]); >> > > > >> > > > You are assuming the HPB entries read out by "HPB Read Buffer" >> > > > cmd >> > > > are >> > > > in Little >> > > > Endian, which is why you are using put_unaligned_be64 here. >> > > > However, >> > > > this assumption >> > > > is not right for all the other flash vendors - HPB entries read >> > > > out >> > > > by >> > > > "HPB Read Buffer" >> > > > cmd may come in Big Endian, if so, their random read >> > > > performance are >> > > > screwed. >> > > >> > > For this question, it is very hard to make a correct format since >> > > the >> > > Spec doesn't give a clear definition. Should we have a default >> > > format, >> > > if there is conflict, and then add quirk or add a vendor-specific >> > > table? >> > > >> > > Hi Avri >> > > Do you have a good idea? >> > >> > I don't know. Better let Daejun answer this. >> > This was working for me for both Galaxy S20 (Exynos) as well as >> > Xiaomi Mi10 >> > (8250). >> >> As for the endianity issue - >> I don't think that any fix is needed in the hpb driver. >> It is readily seen that the ppn from get_ppn, and the one in the upiu >> cdb (upiu trace) are identical. >> Therefore, if an issue exist, it is IMHO a device issue. >> >> kworker/u16:10-315 [001] d..2 62.283264: ufshpb_get_ppn: Avri >> ppn 480d2f8244c21abd >> kworker/u16:10-315 [001] d..2 62.283336: ufshcd_upiu: v:1.10 >> send: T:62283314922, HDR:014000000000000000000000, >> CDB:8800002ddaac480d2f8244c21abd0100, D: >> >> Again, verified on both gs20 (exynos) and mi10 (8250). >> Thanks, >> Avri > > > Hi Avri, > Your testing method is no problem, the current problem is in function > ufshpb_get_ppn(). > > > +static u64 ufshpb_get_ppn(struct ufshpb_lu *hpb, > + struct ufshpb_map_ctx *mctx, int pos, int > *error) > +{ > + u64 *ppn_table; > + struct page *page; > + int index, offset; > + > + index = pos / (PAGE_SIZE / HPB_ENTRY_SIZE); > + offset = pos % (PAGE_SIZE / HPB_ENTRY_SIZE); > + > + page = mctx->m_page[index]; > + if (unlikely(!page)) { > + *error = -ENOMEM; > + dev_err(&hpb->sdev_ufs_lu->sdev_dev, > + "error. cannot find page in mctx\n"); > + return 0; > + } > + > + ppn_table = page_address(page); > + if (unlikely(!ppn_table)) { > + *error = -ENOMEM; > + dev_err(&hpb->sdev_ufs_lu->sdev_dev, > + "error. cannot get ppn_table\n"); > + return 0; > + } > + > + return ppn_table[offset]; > +} > > > Say, the UFS device outputs the L2P entry in big-endian, which means > the most significant byte of an L2P entry will be output firstly, then > the less significant byte..., let's take an example of one L2P entry: > > 0x 12 34 56 78 90 12 34 56 > > 0x12 is the most significant byte, will be store in the lowest address > in the L2P cache. > > eg, > > F0000008: 1234 5678 9012 3456 > > In the ARM based system, If we use "return ppn_table[offset]", > the original L2P entry 0x1234 5678 9012 3456, will be converted to > 0x5634 1290 7856 3412. then use put_unaligned_be64(), UFS receive > unexpected L2P entry(L2P entry miss). > > If the UFS output L2P entry in the big-endian, this is a problem. > > > For the UFS outputs L2P entry in little-endian, no problem, > > Because of the L2P entry in the memory: > > F0000008: 5634 1290 7856 3412 > > After return ppn_table[offset], L2P entry will be correct L2P entry: > > 0x1234567890123456. then use put_unaligned_be64(), UFS can receive > expected L2P etnry(L2P entry hit). > > > we need to figure out which way is the JEDEC recommended L2P entry > output endianness. otherwise, two methods co-exist in HPB driver, there > will confuse customer. > If you have a look at the JEDEC HPB 2.0, seems the big-endian is > correct way. This need you and Daejun to double check inside your > company. > Bean is right, finally you know what I was saying... We need to fix it before move on - all the UFS3.1 HPB parts which I tested over the last few weeks are screwed due to this... I don't care where/how you want to get it fixed in next version. In my case, which may not be a valid fix, I simply hack the code as below and it works for me. - put_unaligned_be64(ppn, &cdb[6]); + memcpy(&cdb[6], &ppn, sizeof(u64)); Thanks, Can Guo. > thanks, > Bean