Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp283852pxb; Thu, 30 Sep 2021 06:06:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAzwzS7qcNZV2dXY6Rk+ndzjFvqO1ZmmlcXaV++MFb2f8KBbx59dfdgpCbVNsAy/7Ncw38 X-Received: by 2002:a63:4c0e:: with SMTP id z14mr4826802pga.427.1633007216485; Thu, 30 Sep 2021 06:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633007216; cv=none; d=google.com; s=arc-20160816; b=ito0+tztydO8wfMmljjCt1Q2mPOqGUklAglLS0SsUGqr3+USG194Pale2syKWonNs5 JXF0LRDjpecfZ/s2oTV4dHmS8B57L4AUrAF6i6X5V2yqmQPWmAZ6VrAiN6NbfFfC6Eqg /ZFX7av1q/u/CySGECTeO1CHdTKfdaAwg8HdxXZ6Wl2eyV/6wCTaJvs/Mrpxc1eAa/S9 YadXt6qfW+G14ZqDwlwktcXZoj1+2UK1xcqHc9x1C6xrAene8ZyNRu+Ydzy22p0034nC jx6+aXlncsBjHKPrBcTESup4hZTd0NIywC4V5NzZQH87yiduis0Y3xXYpcsYfXngGEZR P5jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Q8PvzGV7RQh9r19dv7sQTAnPOmVRl05fj0IURPoGTjE=; b=qk4CvfWqgpqSbMtijajy+ns/N2fI/GMzBTUX5v/hApWeO+v99PIampfHOGBSv4oKK2 AR1sUsryVPpK5avu2ShCRpp7uVaoRXErt4YdVAhQctVkfyghkYVyvDQ88Fu/s7JKXlLo aCl1ZbGBp7c7yqXmUKGT8jQLfpkeZ5TOf8ip6kjnMndugVJCKuGS8+IluqMBSrdKQ84p Eo2yqOGKCnCR7q7Z3MCqIwRzHChpSLWcjX1JNfjDR38l0pMOx9nmV6F7T26zWacKlIvk 58AuwEb3amKmB1txDUcVz9ParL+1y0YBCQw2yU2ZinFYZkNAOWt35lkk7jpYtX/U2ir5 jF8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RXfkA+78; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n5si4019574pfd.32.2021.09.30.06.06.41; Thu, 30 Sep 2021 06:06:56 -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=@linaro.org header.s=google header.b=RXfkA+78; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350435AbhI3L1M (ORCPT + 99 others); Thu, 30 Sep 2021 07:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350433AbhI3L1G (ORCPT ); Thu, 30 Sep 2021 07:27:06 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B48FC06176D for ; Thu, 30 Sep 2021 04:25:23 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id x27so23962877lfu.5 for ; Thu, 30 Sep 2021 04:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Q8PvzGV7RQh9r19dv7sQTAnPOmVRl05fj0IURPoGTjE=; b=RXfkA+78yN2AQYzVjgxXgCUGzZNUhbTFuc4ZS4gofT3I8tJ2l+/uKe+ri6q1WKsmtt JhkaOU7nWduEFt+meXYv3p6g3K2J6cecRxgrVhLl+L5SvKZR2o+stcNUAY0kyMJOyQ4k xbpku8hUtiZ2b5dvIXGlfgnvzCe1TpZLKQGU2mE9ZutxqPKDscNkDX8L+3N71xBVPElG 5jrqMpTc7TwMmBOZgaeDHoik6ZSWNSMkMNf76y1ISu5XjYJcs4FuVvl0KmRg8azGnWwc nyiR8sJHyPaxwHLA+DVVIBzxduHcE8yxJbTNKA8Ga3pLHglJngTOJl6TL13LWTdnVMJE UnYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Q8PvzGV7RQh9r19dv7sQTAnPOmVRl05fj0IURPoGTjE=; b=LDsTTNaj/zQ8n0pFMbSiAxcgvoHN170OWIxeNaVJiu/1VFOWlzvBiqN9Wx6IGeH2hv u4/kR39F8LAIRxbZFL3seujpVKZIerwmAPGSnlghxl4ZRzhvSBCn1k2EdkOaZ6DKURFX k1rdK6iDMf1V6QyFv1woKB8lILo2bj+2Z1EUnRShOQ8hWTLwoeZzG+CDuBzy8Coq/Wz5 ooXNVBXI0k7j1KrUUQlICB8BldQ1cUC7wW+0I/E7e+5ooOwnS8PQCgch1fqSyhDhwq1Y YpQuF/szBIgA7A5soRpmCCx5U5cZXxldwPbbpLJIBmBY/4sC8hPTV6Nvf+KUIXjj90/P mfWw== X-Gm-Message-State: AOAM530Y9+IMmqAvFNg6YRhmWlzjsbaeuIgAEDquTfOXFZXcUeaGt25B cpZko+8BlLoMp82qkiDF+ypL41aSacrAkU8Lrohs8g== X-Received: by 2002:a05:6512:3095:: with SMTP id z21mr169648lfd.167.1633001121852; Thu, 30 Sep 2021 04:25:21 -0700 (PDT) MIME-Version: 1.0 References: <20210928073652.434690-1-narmstrong@baylibre.com> In-Reply-To: <20210928073652.434690-1-narmstrong@baylibre.com> From: Ulf Hansson Date: Thu, 30 Sep 2021 13:24:45 +0200 Message-ID: Subject: Re: [PATCH v2] mmc: meson-gx: do not use memcpy_to/fromio for dram-access-quirk To: Neil Armstrong Cc: linux-mmc , Linux ARM , "open list:ARM/Amlogic Meson..." , Linux Kernel Mailing List , Christian Hewitt , Martin Blumenstingl Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 28 Sept 2021 at 09:37, Neil Armstrong wrote: > > The memory at the end of the controller only accepts 32bit read/write > accesses, but the arm64 memcpy_to/fromio implementation only uses 64bit > (which will be split into two 32bit access) and 8bit leading to incomplete > copies to/from this memory when the buffer is not multiple of 8bytes. > > Add a local copy using writel/readl accesses to make sure we use the right > memory access width. > > The switch to memcpy_to/fromio was done because of 285133040e6c > ("arm64: Import latest memcpy()/memmove() implementation"), but using memcpy > worked before since it mainly used 32bit memory acceses. > > Fixes: 103a5348c22c ("mmc: meson-gx: use memcpy_to/fromio for dram-access-quirk") > Reported-by: Christian Hewitt > Suggested-by: Martin Blumenstingl > Signed-off-by: Neil Armstrong > Tested-by: Martin Blumenstingl Applied for fixes and by adding a stable tag, thanks! Kind regards Uffe > --- > Changes since v1: > - added sg pre-validation at meson_mmc_request and dropped checks in meson_mmc_copy_buffer > > drivers/mmc/host/meson-gx-mmc.c | 73 ++++++++++++++++++++++++++------- > 1 file changed, 59 insertions(+), 14 deletions(-) > > diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c > index 3f28eb4d17fe..8f36536cb1b6 100644 > --- a/drivers/mmc/host/meson-gx-mmc.c > +++ b/drivers/mmc/host/meson-gx-mmc.c > @@ -746,7 +746,7 @@ static void meson_mmc_desc_chain_transfer(struct mmc_host *mmc, u32 cmd_cfg) > writel(start, host->regs + SD_EMMC_START); > } > > -/* local sg copy to buffer version with _to/fromio usage for dram_access_quirk */ > +/* local sg copy for dram_access_quirk */ > static void meson_mmc_copy_buffer(struct meson_host *host, struct mmc_data *data, > size_t buflen, bool to_buffer) > { > @@ -764,21 +764,27 @@ static void meson_mmc_copy_buffer(struct meson_host *host, struct mmc_data *data > sg_miter_start(&miter, sgl, nents, sg_flags); > > while ((offset < buflen) && sg_miter_next(&miter)) { > - unsigned int len; > + unsigned int buf_offset = 0; > + unsigned int len, left; > + u32 *buf = miter.addr; > > len = min(miter.length, buflen - offset); > + left = len; > > - /* When dram_access_quirk, the bounce buffer is a iomem mapping */ > - if (host->dram_access_quirk) { > - if (to_buffer) > - memcpy_toio(host->bounce_iomem_buf + offset, miter.addr, len); > - else > - memcpy_fromio(miter.addr, host->bounce_iomem_buf + offset, len); > + if (to_buffer) { > + do { > + writel(*buf++, host->bounce_iomem_buf + offset + buf_offset); > + > + buf_offset += 4; > + left -= 4; > + } while (left); > } else { > - if (to_buffer) > - memcpy(host->bounce_buf + offset, miter.addr, len); > - else > - memcpy(miter.addr, host->bounce_buf + offset, len); > + do { > + *buf++ = readl(host->bounce_iomem_buf + offset + buf_offset); > + > + buf_offset += 4; > + left -= 4; > + } while (left); > } > > offset += len; > @@ -830,7 +836,11 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) > if (data->flags & MMC_DATA_WRITE) { > cmd_cfg |= CMD_CFG_DATA_WR; > WARN_ON(xfer_bytes > host->bounce_buf_size); > - meson_mmc_copy_buffer(host, data, xfer_bytes, true); > + if (host->dram_access_quirk) > + meson_mmc_copy_buffer(host, data, xfer_bytes, true); > + else > + sg_copy_to_buffer(data->sg, data->sg_len, > + host->bounce_buf, xfer_bytes); > dma_wmb(); > } > > @@ -849,12 +859,43 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) > writel(cmd->arg, host->regs + SD_EMMC_CMD_ARG); > } > > +static int meson_mmc_validate_dram_access(struct mmc_host *mmc, struct mmc_data *data) > +{ > + struct scatterlist *sg; > + int i; > + > + /* Reject request if any element offset or size is not 32bit aligned */ > + for_each_sg(data->sg, sg, data->sg_len, i) { > + if (!IS_ALIGNED(sg->offset, sizeof(u32)) || > + !IS_ALIGNED(sg->length, sizeof(u32))) { > + dev_err(mmc_dev(mmc), "unaligned sg offset %u len %u\n", > + data->sg->offset, data->sg->length); > + return -EINVAL; > + } > + } > + > + return 0; > +} > + > static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq) > { > struct meson_host *host = mmc_priv(mmc); > bool needs_pre_post_req = mrq->data && > !(mrq->data->host_cookie & SD_EMMC_PRE_REQ_DONE); > > + /* > + * The memory at the end of the controller used as bounce buffer for > + * the dram_access_quirk only accepts 32bit read/write access, > + * check the aligment and length of the data before starting the request. > + */ > + if (host->dram_access_quirk && mrq->data) { > + mrq->cmd->error = meson_mmc_validate_dram_access(mmc, mrq->data); > + if (mrq->cmd->error) { > + mmc_request_done(mmc, mrq); > + return; > + } > + } > + > if (needs_pre_post_req) { > meson_mmc_get_transfer_mode(mmc, mrq); > if (!meson_mmc_desc_chain_mode(mrq->data)) > @@ -999,7 +1040,11 @@ static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id) > if (meson_mmc_bounce_buf_read(data)) { > xfer_bytes = data->blksz * data->blocks; > WARN_ON(xfer_bytes > host->bounce_buf_size); > - meson_mmc_copy_buffer(host, data, xfer_bytes, false); > + if (host->dram_access_quirk) > + meson_mmc_copy_buffer(host, data, xfer_bytes, false); > + else > + sg_copy_from_buffer(data->sg, data->sg_len, > + host->bounce_buf, xfer_bytes); > } > > next_cmd = meson_mmc_get_next_command(cmd); > -- > 2.25.1 >