Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1329033rdh; Fri, 27 Oct 2023 10:47:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzQ8ZF02KcJOowQxrjEM2aSAvgnNtEPK0TWQmYM14Y/wWex1ZDZvX28ggMzzzIBHaS8t5W X-Received: by 2002:a9d:624f:0:b0:6cc:cc02:6ea4 with SMTP id i15-20020a9d624f000000b006cccc026ea4mr3147519otk.38.1698428862604; Fri, 27 Oct 2023 10:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698428862; cv=none; d=google.com; s=arc-20160816; b=JgQoXzybW5SobUvA9J/1rYzwLLtux4IAFkq1dyUpQT4oaD89dsrCzhCIuvkVb/Stfq 4JrjG+lQo52Rb645tmg5s4qlUsnHXFVGWjdvL7Qh134zI/vpAOi4961oRWeWFEgv4Pj6 8iysiOY1Wwh1y87w8XAzQ9M5BIxg/istWlwQpajtI8MBbba0YqaGzmWXaOUt+IASWtYI BXdL12W7OWDVIPc5x7kE+yC1ih0ZM3koCDRnVIImc//g7Kv3G4NZPMKIePZM0ZPtTMhw Fx13uk0VukSvGdFA0YjZi0+Bp0l75sqpZtAkieBA8G49qycjLzGoMcKBv9AgxpNm75Nj RQDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AzMCYtHoI7SG+hrdCFiCqKFA4nKMelQAhb2DhwTgKRQ=; fh=CldmKAyD4vT9FhOXGn33jgfmm5TA/oUiaaWNA4EkR5Q=; b=vJWgenJ6FSyt8H2jMiRLIFwGpAQAk/1qNvvxw7t7yLAD/SUPrgvW6cL6AWwxE0qIEC 0LVrrJaBpqSnV3C6BuHFixDO1lmRy+lmW66TmiSDPsxqj/htETnLxUws1ohlli70Igzo U1NQLdhprCC5Me421fbIpJXxLAyXdbec+jG2UHJjMm2VdpFIjFuzjCmTR4IxcwlgAjjX PTOxGEAO07gQlNdxuE0Y1HfzgadRaKVAZC+7H4w0j3Odu2lu3j8vq6V4YGddTmOXIlea 1Ne1HZ2Ug2qnTjdpKqcm5HIcE1WseuJr4N1UBxYi7NfV5I1DKpiKaptZ1YtIoQFhSRQD gTJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ks2FCKwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id n190-20020a0dfdc7000000b005a87ec8f16bsi2834652ywf.545.2023.10.27.10.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 10:47:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ks2FCKwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0981280E0A5E; Fri, 27 Oct 2023 10:47:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346054AbjJ0RrS (ORCPT + 99 others); Fri, 27 Oct 2023 13:47:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231464AbjJ0RrS (ORCPT ); Fri, 27 Oct 2023 13:47:18 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60E56E3; Fri, 27 Oct 2023 10:47:14 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id F29E920004; Fri, 27 Oct 2023 17:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1698428832; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AzMCYtHoI7SG+hrdCFiCqKFA4nKMelQAhb2DhwTgKRQ=; b=ks2FCKwG+qUGKUKS+xSIydbNB4NGUY3mwlU/NgeDdlDTejLg2JambDcbwdSVHxjpDt6RUt SOU6wkVUqDvDPuNYREmWTw4y4l19+SkYR/efASy76gR27gfeiCCE7jeH4Z3jQUyM1WHzHy mPbVYC7t/7eCFUEPF2V1NPcbHqAafDEmZlQgUqUtr56luoeH2EYplww6oKLNY+/bJC3oBB w9FLaRfw30aAVWcE/AAfxziwv5+k6QSmrJlZZQAXHmLcr8t2gOYXO7q+ZcEt9i6JB7lV+n Y1868b/iAouRTioj4Z+j4Jr3mGg2R4itesLTyA8FLznzayFbfVBu98AV2TlnqQ== From: Miquel Raynal To: Linus Walleij , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Nicolas Pitre Subject: Re: [PATCH v4] mtd: cfi_cmdset_0001: Byte swap OTP info Date: Fri, 27 Oct 2023 19:47:11 +0200 Message-Id: <20231027174711.369946-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020-mtd-otp-byteswap-v4-1-0d132c06aa9d@linaro.org> References: MIME-Version: 1.0 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: b'565fe150624ee77dc63a735cc1b3bff5101f38a3' Content-Transfer-Encoding: 8bit X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 27 Oct 2023 10:47:40 -0700 (PDT) On Fri, 2023-10-20 at 20:30:29 UTC, Linus Walleij wrote: > Currently the offset into the device when looking for OTP > bits can go outside of the address of the MTD NOR devices, > and if that memory isn't readable, bad things happen > on the IXP4xx (added prints that illustrate the problem before > the crash): > > cfi_intelext_otp_walk walk OTP on chip 0 start at reg_prot_offset 0x00000100 > ixp4xx_copy_from copy from 0x00000100 to 0xc880dd78 > cfi_intelext_otp_walk walk OTP on chip 0 start at reg_prot_offset 0x12000000 > ixp4xx_copy_from copy from 0x12000000 to 0xc880dd78 > 8<--- cut here --- > Unable to handle kernel paging request at virtual address db000000 > [db000000] *pgd=00000000 > (...) > > This happens in this case because the IXP4xx is big endian and > the 32- and 16-bit fields in the struct cfi_intelext_otpinfo are not > properly byteswapped. Compare to how the code in read_pri_intelext() > byteswaps the fields in struct cfi_pri_intelext. > > Adding a small byte swapping loop for the OTP in read_pri_intelext() > and the crash goes away. > > The problem went unnoticed for many years until I enabled > CONFIG_MTD_OTP on the IXP4xx as well, triggering the bug. > > Cc: stable@vger.kernel.org > Reviewed-by: Nicolas Pitre > Signed-off-by: Linus Walleij Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks. Miquel