From nobody Mon May 6 19:53:30 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB527C433FE for ; Mon, 23 May 2022 14:29:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237114AbiEWO3E (ORCPT ); Mon, 23 May 2022 10:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237020AbiEWO3D (ORCPT ); Mon, 23 May 2022 10:29:03 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC37820F74 for ; Mon, 23 May 2022 07:29:01 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id q21so9018189ejm.1 for ; Mon, 23 May 2022 07:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=malat-biz.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gGEKaRL/00sKBHtj1hUxzGszVFwNUoCR3h2OByy1v5w=; b=PgJUjLKHURCjSmk42QVyCWSoJV+H0m1LxJrjAUL0xPQDH4TJf0WL0ZA3QxF5I/uF0k nycCZr7WbpmWu/RMHE8ogPHz1IyBBlBVJU/aLemja4FM8ucSIyoyFM7n08Z53rvsXisC jms5AJ+DvW/Qu8ar+YJ5rrsUllkOU4rD5K/pIakn+NRqFwrVBSxdXuIA+wRfE5qwgq/M dFUt3IdchFnQkqhWPCA5pwjyKdHOhi1Ez+9VgX3sxzHm+6imr9osUJx44mNaFjQG9hl9 /xQNbjvxc329bSIOyqI1tsE0zOoiZd7dV5XNpMbJ9zsZy+F+KAxIwVzRH8h62UIxF1HF ARaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gGEKaRL/00sKBHtj1hUxzGszVFwNUoCR3h2OByy1v5w=; b=Q//rc/K4NEN5y5jkSelIkfzNcO9op4OxG8msP4hzCzkfZfo8J+gQEUY9kLIDXsj1ex QX09Ze376NjzeRC4174KfUlZKc/SLDYjf1lU09c2Maz1mkS/n8YSGelTL6nzc7tfcGTN fqGjJoR43ffmu+qwk+o7WcInp3p1iZCi4yTzfXIuOCM76Wi2cSjfYhfxJi6T1zQukhWG xITetlCIDXOfYne4xGEYD4rdUhg4TWMyYgD6zJfjJJ53JxOr6dTxC9q9vBDc11Mra5oB WCk1w5J3YHmSboW1TTIyzbGPvfwa7Kj232+5vnS+nNv9wd61Rn+ccxv4A91no5Bk19Or Yqeg== X-Gm-Message-State: AOAM530dtyIsp2LaJB9gmqsNH+kctRCXwzNNOaJqS4nhUKRPznVo0XEo DmmBJo38eRmgv/Sw7sfA5Y1nr/ly99QuaQ== X-Google-Smtp-Source: ABdhPJxlgmV9DSbvu2Zh5aV26tUxOqNApPjJGp419HhV0pXpmzudNbsAML6QDeYwa8iixqwMPHQt8A== X-Received: by 2002:a17:907:7ea2:b0:6fe:d945:7fe with SMTP id qb34-20020a1709077ea200b006fed94507femr1026528ejc.228.1653316140469; Mon, 23 May 2022 07:29:00 -0700 (PDT) Received: from ntb.petris.klfree.czf ([2a02:8070:d483:ed00:4bcc:154f:5c11:5870]) by smtp.googlemail.com with ESMTPSA id i2-20020aa7c702000000b0042617ba6380sm8252640edq.10.2022.05.23.07.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 07:28:59 -0700 (PDT) From: Petr Malat To: linux-mtd@lists.infradead.org Cc: Joern Engel , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Petr Malat Subject: [PATCH] mtd: phram: Map RAM using memremap instead of ioremap Date: Mon, 23 May 2022 16:28:25 +0200 Message-Id: <20220523142825.3144904-1-oss@malat.biz> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" One can't use memcpy on memory obtained by ioremap, because IO memory may have different alignment and size access restriction than the system memory. Use memremap as phram driver operates on RAM. This fixes an unaligned access on ARM64, which could be triggered with e.g. dd if=3D/dev/phram/by-name/testdev bs=3D8190 count=3D1 Unable to handle kernel paging request at virtual address ffffffc01208bf= bf Mem abort info: ESR =3D 0x96000021 EC =3D 0x25: DABT (current EL), IL =3D 32 bits SET =3D 0, FnV =3D 0 EA =3D 0, S1PTW =3D 0 Data abort info: ISV =3D 0, ISS =3D 0x00000021 CM =3D 0, WnR =3D 0 swapper pgtable: 4k pages, 39-bit VAs, pgdp=3D0000000000cd5000 [ffffffc01208bfbf] pgd=3D00000002fffff003, p4d=3D00000002fffff003, pud= =3D00000002fffff003, pmd=3D0000000100b43003, pte=3D0068000022221717 Internal error: Oops: 96000021 [#1] PREEMPT SMP CPU: 2 PID: 14768 Comm: dd Tainted: G O 5.10.116-f13ddced= 70 #1 Hardware name: AXM56xx Victoria (DT) pstate: 80000005 (Nzcv daif -PAN -UAO -TCO BTYPE=3D--) pc : __memcpy+0x168/0x230 lr : phram_read+0x68/0xb0 [phram] sp : ffffffc0138f3bd0 x29: ffffffc0138f3bd0 x28: 0000000034a50090 x27: 0000000000000000 x26: ffffff81176ce000 x25: 0000000000000000 x24: 0000000000000000 x23: ffffffc0138f3cb8 x22: ffffff8109475000 x21: 0000000000000000 x20: ffffff81176ce000 x19: 0000000000001fff x18: 0000000000000020 x17: 0000000000000000 x16: 0000000000000000 x15: ffffff8125861410 x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000 x5 : ffffff81176cffff x4 : ffffffc01208bfff x3 : ffffff81176cff80 x2 : ffffffffffffffef x1 : ffffffc01208bfc0 x0 : ffffff81176ce000 Call trace: __memcpy+0x168/0x230 mtd_read_oob_std+0x80/0x90 mtd_read_oob+0x8c/0x150 mtd_read+0x54/0x80 mtdchar_read+0xdc/0x2c0 vfs_read+0xb8/0x1e4 ksys_read+0x78/0x10c __arm64_sys_read+0x28/0x34 do_el0_svc+0x94/0x1f0 el0_svc+0x20/0x30 el0_sync_handler+0x1a4/0x1c0 el0_sync+0x180/0x1c0 Code: a984346c a9c4342c f1010042 54fffee8 (a97c3c8e) ---[ end trace 5707221d643416b6 ]--- Signed-off-by: Petr Malat --- drivers/mtd/devices/phram.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index d503821a3e60..25d3674b4e51 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -83,7 +83,7 @@ static void unregister_devices(void) =20 list_for_each_entry_safe(this, safe, &phram_list, list) { mtd_device_unregister(&this->mtd); - iounmap(this->mtd.priv); + memunmap(this->mtd.priv); kfree(this->mtd.name); kfree(this); } @@ -99,9 +99,9 @@ static int register_device(char *name, phys_addr_t start,= size_t len, uint32_t e goto out0; =20 ret =3D -EIO; - new->mtd.priv =3D ioremap(start, len); + new->mtd.priv =3D memremap(start, len, MEMREMAP_WB); if (!new->mtd.priv) { - pr_err("ioremap failed\n"); + pr_err("memremap failed\n"); goto out1; } =20 @@ -129,7 +129,7 @@ static int register_device(char *name, phys_addr_t star= t, size_t len, uint32_t e return 0; =20 out2: - iounmap(new->mtd.priv); + memunmap(new->mtd.priv); out1: kfree(new); out0: --=20 2.30.2