Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp231840pxb; Thu, 17 Feb 2022 02:54:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDpzl2TJBZDdSth6sWK2vAauI6Gn5c1OO88tQrFvH/9xgnT8qz+Anj/UsTG3NHzGVvCNXM X-Received: by 2002:a17:906:3803:b0:6aa:a5a0:1a54 with SMTP id v3-20020a170906380300b006aaa5a01a54mr1842910ejc.162.1645095254900; Thu, 17 Feb 2022 02:54:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645095254; cv=none; d=google.com; s=arc-20160816; b=DgxPDO4MaJanKLmWam/bNnKX54npBOTU1ZmclpQhcC/PHDkmjHDLjfCGQ7/y+/xum/ X6v1Zv4NUXjFFAdAm8LcQBMpovm5TnMViAOhzXkULZx8yWXZypUjomYuMiBXo0z1ckNB 4k/TZVcpL7bQK6gUACOyxzQo6hToF0zrVVE3QvWCJQm6eEKMJPnV0KWc9aVt5dpmi2w3 tOd6Gbze41FeIppk/LP9ae0+lV7EASDFTKHLPCUa2R9DDlsVwak45Nn9QG7psMbIiDMv vS28pE5bhW/NwIU77h1JziI7aR16AKgD3GHN3pxhmmE2oVX9QOVlFMJur2ppJIJMfU78 afAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9TATMg5XNmyHj9/wum7kE/N0AnlYkACa1RnuF2XMN4M=; b=yJMUDROXagd4EFh8k04/Oq/Htzw0kquH+TvJ4mJL6dyeGyG3dn9uUGfCm4hdClMeB4 hXMiyULdXmCzq+085OUgm5jplT5kbxcuOBLWMPxsyTYrH6YIkxQqd9b3tmfP8mvDjpk+ xWb/SJtHo7azQ8K8wc5bkyHYZw/PFJ581sE5TAxApEuWvLOk/Nnsuf1ntAikjaw32De6 3/D3bbtq7m1y/zxPYSyhkonqL72SLK3cCkuoKezIYLPsaRIws+EzoigyuPPUvUxRnpqT sWzvp8h5p4ZYuuj0dYl44XBWn8XhxeqIAQOaomygwMHefb5jw5yc8yUjckCH3KhXdEGg DxWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kEqcEz+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gu23si1502086ejb.271.2022.02.17.02.53.52; Thu, 17 Feb 2022 02:54:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kEqcEz+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbiBQDCL (ORCPT + 99 others); Wed, 16 Feb 2022 22:02:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232212AbiBQDCL (ORCPT ); Wed, 16 Feb 2022 22:02:11 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 988B6ECB08; Wed, 16 Feb 2022 19:01:57 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id g1so3829667pfv.1; Wed, 16 Feb 2022 19:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=9TATMg5XNmyHj9/wum7kE/N0AnlYkACa1RnuF2XMN4M=; b=kEqcEz+MUy7+urrkcE2qCxwNWkajGExK8R2BRi5V9jWLLnWy+oEDn6XXMGVI3QCuPd cUJvxOnNGy4ohBvk+euFQLBbY1aXq+2PdsXcP84IjpnimIUlARhtGMXmFywGP3LRdY7F LElpR7I97USrY3Qkz4V8EXzwYAFamJYlOcX1Q5eLkNZuMyqItK7ZGsLhgMxfy66C4cDF G7FOqD3hP+AsP5TmL5KyrYjRAQY5qh4sic/EXM5emC6Fn70sC9CdM6h46myzlm2MoFAK sH3xNzq7mQWOWsLRKijzXYXhTjwpz3eELUCYN22RtxK0sX2/4oGPoo+PygpxOZV6bSo1 R8xA== 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:content-transfer-encoding; bh=9TATMg5XNmyHj9/wum7kE/N0AnlYkACa1RnuF2XMN4M=; b=CQtcX7tSTzxd+rNQZ/GiAJnVEx5zGBpmRpnbfD6kWagbfd7XoChmOX/9jecTPf80io PSUv4AKzoE6JZLUhVZbgg9f+M8GIY/qFoutQjpBLncoCCHhhSpl0wP5HKt8vXOLQu0hH +kSsxVM9lTmp/gE0OVDy3aStPtLJ8XqDUWHIltHJi1u/EHCvzqR3jaDDkXx6VwGAsLcL B+Fm4KtkJMrzgzcI2kD6wdJTxU431SqqVTG4jKBuVICOirR/9tSzwTC7+GVSH3QXV+Zf WZKs+h/carP89+TYWP8OLvg/hcq76wIbp6mSMvN/1uDfYZ02/68hRoLgj4zT/hPsOLCI w4aQ== X-Gm-Message-State: AOAM533OiJs6nZ8+mxZ4xOn42gbNOPIt6TIHtAxT1yS33sqt5zqW9iZq Ckky4JIoKYG6BgyZp0dkclV2MM3SQ5umFmp6MDI= X-Received: by 2002:a05:6a00:be5:b0:4e1:9050:1e16 with SMTP id x37-20020a056a000be500b004e190501e16mr892036pfu.78.1645066916960; Wed, 16 Feb 2022 19:01:56 -0800 (PST) MIME-Version: 1.0 References: <20220216160500.2341255-1-alvin@pqrs.dk> <20220216160500.2341255-3-alvin@pqrs.dk> <20220216233906.5dh67olhgfz7ji6o@skbuf> In-Reply-To: <20220216233906.5dh67olhgfz7ji6o@skbuf> From: Luiz Angelo Daros de Luca Date: Thu, 17 Feb 2022 00:01:45 -0300 Message-ID: Subject: Re: [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: serialize indirect PHY register access To: Vladimir Oltean Cc: =?UTF-8?Q?Alvin_=C5=A0ipraga?= , Linus Walleij , Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Jakub Kicinski , =?UTF-8?Q?Alvin_=C5=A0ipraga?= , =?UTF-8?B?QXLEsW7DpyDDnE5BTA==?= , Michael Rasmussen , "open list:NETWORKING DRIVERS" , open list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vladimir, > This implementation where the indirect PHY access blocks out every other > register read and write is only justified if you can prove that you can > stuff just about any unrelated register read or write before > RTL8365MB_INDIRECT_ACCESS_READ_DATA_REG, and this, in and of itself, > will poison what gets read back from RTL8365MB_INDIRECT_ACCESS_READ_DATA_= REG. I was the first one trying to fix this issue reported by Arin=C3=A7 with SMP devices. At first I thought it was caused by two parallel indirect access reads polling the interface (it was not using interrupts). With no lock, they will eventually collide and one reads the result of the other one. However, a simple lock over the indirect access didn't solve the issue. Alvin tested it much further to isolate that indirect register access is messed up by any other register read. The fails while polling the interface status or the other test Alvin created only manifests in a device with multiple cores and mine is single core. I do get something similar in a single core device by reading an unused register address but it is hard to blame Realtek when we are doing something we were not supposed to do. Anyway, that indicates that "reading a register" is not an atomic operation inside the switch asic. > rtl8365mb_mib_counter_read() doesn't seem like a particularly good > example to prove this, since it appears to be an indirect access > procedure as well. Single register reads or writes would be ideal, like > RTL8365MB_CPU_CTRL_REG, artificially inserted into strategic places. > Ideally you wouldn't even have a DSA or MDIO or PHY driver running. > Just a simple kernel module with access to the regmap, and try to read > something known, like the PHY ID of one of the internal PHYs, via an > open-coded function. Then add extra regmap accesses and see what > corrupts the indirect PHY access procedure. The MIB might be just another example where the issue happens. It was first noticed with a SMP device without interruptions configured. I believe it will always fail with that configuration. > Are Realtek aware of this and do they confirm the issue? Sounds like > erratum material to me, and a pretty severe one, at that. Alternatively, > we may simply not be understanding the hardware architecture, like for > example the fact that MIB indirect access and PHY indirect access may > share some common bus and must be sequential w.r.t. each other. The realtek "API/driver" does exactly how the driver was doing. They do have a lock/unlock placeholder, but only in the equivalent regmap_{read,write} functions. Indirect access does not use locks at all (in fact, there is no other mention of "lock" elsewhere), even being obvious that it is not thread-safe. It was just with a DSA driver that we started to exercise register access for real, specially without interruptions. And even in that case, we could only notice this issue in multicore devices. I believe that, if they know about this issue, they might not be worried because it has never affected a real device. It would be very interesting to hear from Realtek but I do not have the contacts. Regards, Luiz