From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F307C48BDF for ; Tue, 15 Jun 2021 08:53:28 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8EC1060FEA for ; Tue, 15 Jun 2021 08:53:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8EC1060FEA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7D04881CA8; Tue, 15 Jun 2021 10:53:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=protonmail.com header.i=@protonmail.com header.b="DFtVZF12"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9F1AF81D48; Tue, 15 Jun 2021 10:53:22 +0200 (CEST) Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B82D78164D for ; Tue, 15 Jun 2021 10:53:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=litchi.pi@protonmail.com Date: Tue, 15 Jun 2021 08:53:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1623747197; bh=x4vVRDIF9sj2M49HbnA3wXSow4e87sxt2YarO5nxjVw=; h=Date:To:From:Cc:Reply-To:Subject:From; b=DFtVZF12WD2tR33tcrrNBfuhEPFyMk5BsKEFZ4NlOQ6/eJlTIL2ze6FcGV5MY3dWK l7BII5DHCzbc1DLJFRihQcvFbM7KisIs8Pi2lINuAeOJ3Nzrx7jy52yzykuw4XLnXd EowJqddQw38EUsy7Qop0FbQopJxkLXdhKinwk7YU= To: u-boot@lists.denx.de From: =?utf-8?Q?Timoth=C3=A9e_Cercueil?= Cc: Peng Fan , Jens Wiklander , litchipi , =?utf-8?Q?Timoth=C3=A9e_Cercueil?= Subject: [PATCH] mmc: rpmb: Fix driver routing memory alignment with tmp buffer Message-ID: <20210615085255.24899-1-litchi.pi@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: =?utf-8?Q?Timoth=C3=A9e_Cercueil?= Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: litchipi Fix mmc_rpmb_route_frames() implementation to comply with most MMC drivers that expect some alignment of MMC data frames in memory. When called from drivers/tee/optee/rpmb.c, the address passed is not aligned properly. OP-TEE OS inserts a 6-byte header before a raw RPMB frame which makes RPMB data buffer not 32bit aligned. To prevent breaking ABI with OPTEE-OS RPC memrefs, allocate a temporary buffer to copy the data into an aligned memory. Many RPMB drivers implicitly expect 32bit alignment of the eMMC frame including arm_pl180_mmci.c, sandbox_mmc.c and stm32_sdmmc2.c Signed-off-by: Timoth=C3=A9e Cercueil Signed-off-by: Timoth=C3=A9e Cercueil --- drivers/mmc/rpmb.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) Changes since v1: =09- Fixed the Signed-off-by errors from previous patch. =09- This patch follows the subject discussed at: https://lists.denx.de/pip= ermail/u-boot/2021-June/451687.html =09- Changed the commit log 1st line diff --git a/drivers/mmc/rpmb.c b/drivers/mmc/rpmb.c index ea7e506666..b68d98573c 100644 --- a/drivers/mmc/rpmb.c +++ b/drivers/mmc/rpmb.c @@ -480,10 +480,24 @@ int mmc_rpmb_route_frames(struct mmc *mmc, void *req,= unsigned long reqlen, =09 * and possibly just delay an eventual error which will be harder =09 * to track down. =09 */ +=09void *rpmb_data =3D NULL; +=09int ret; =09if (reqlen % sizeof(struct s_rpmb) || rsplen % sizeof(struct s_rpmb)) =09=09return -EINVAL; -=09return rpmb_route_frames(mmc, req, reqlen / sizeof(struct s_rpmb), -=09=09=09=09 rsp, rsplen / sizeof(struct s_rpmb)); +=09if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) { +=09=09/* Memory alignment is required by MMC driver */ +=09=09rpmb_data =3D malloc(reqlen); +=09=09if (!rpmb_data) +=09=09=09return -ENOMEM; + +=09=09memcpy(rpmb_data, req, reqlen); +=09=09req =3D rpmb_data; +=09} + +=09ret =3D rpmb_route_frames(mmc, req, reqlen / sizeof(struct s_rpmb), +=09=09=09=09rsp, rsplen / sizeof(struct s_rpmb)); +=09free(rpmb_data); +=09return ret; } -- 2.17.1