Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp843584pxb; Thu, 17 Feb 2022 16:22:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXjIq42n1D8bksC46VdwBH3x9MBAUI8YZ7+qirgMEZ9UYUCD1Czn8gyjbUDf1Ora4D54f1 X-Received: by 2002:a63:dc58:0:b0:373:a20a:29c2 with SMTP id f24-20020a63dc58000000b00373a20a29c2mr4323708pgj.212.1645143734905; Thu, 17 Feb 2022 16:22:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645143734; cv=none; d=google.com; s=arc-20160816; b=NngSJ9+5hnsJ1cNIR+VARkzuscw3qikfTheczU+wenmRCq/WCTzWqftMdhhj+QP0Jv rxv2ToNIF01PAvEspswOuhOZMx00NnR8iis55x+2uISpqvNYTwvYtJQqAPkEqkFGxYu/ 8H0fC7YD3m8VwHxqKuww1Lb/gH44FSXwO8zbQ1QoX7wH63ixChLSrt6Gg0nQaL7pRkcB sX2pQMQWR0sUr6P0sKyC6RJbmlQJI0K0Xb6hWyzVtqAUwRmd/3jas3ZVa4Vu7V1hU4hS 9uvPrcptmPKjsUKGqKCv0dLgOx7Z5AdqT+JxqwvfgdYMumoQpv0cVbmO7G53G/lYRn9k I8ew== 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=cD4DY/iuVWWWEU+B7lYuOW47EogbL76oMXy+TtExHBA=; b=Um7zUcjrvu9AY5Zhin4BzbhkOuvH5fDYnzetGtfCTrQ6To9rtGWheBOpBgq1SEMeL4 KjArsEVjEteWmtusUdgTl2JNdznU/IbTPTLl+xoGUU0GQyDWQNCEXBJbFcPTwnK0ZTU/ t5VsegUDaxk6fsZoNWmT37F9UQVy55csW2R9N4wRVb3XrFyMyopqqyanLWV2x02Cc6Rp 5SFi10bs8KGGGDWPf1HJf4VSCict3mr2X4J6sfRRrCk6wy61Ad3Erbka/r41FpaU3b0m MOS7h2X3AOAB7A6r4mTevYsdntOGd0fu/IXg3R1lM2E9T0nK9uthO2eovpgLJ/POXp7i gnyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Cs0D46Hd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x6si9732600pgh.95.2022.02.17.16.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:22:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Cs0D46Hd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4673B370334; Thu, 17 Feb 2022 15:45:27 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233839AbiBQE3P (ORCPT + 99 others); Wed, 16 Feb 2022 23:29:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233814AbiBQE3O (ORCPT ); Wed, 16 Feb 2022 23:29:14 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73E6425DA44; Wed, 16 Feb 2022 20:29:00 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id d17so3996017pfl.0; Wed, 16 Feb 2022 20:29:00 -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; bh=cD4DY/iuVWWWEU+B7lYuOW47EogbL76oMXy+TtExHBA=; b=Cs0D46Hd+lQrpa2kOOAiTZYdV7O7dnetV0EpOnsEfabfZv/Xdfa93fYpnS4lxs9090 UoVQEgLnYOA+fHRdDx8MTztD/w10a54FSnCdXbEZS9MdkL60Sk00iEbg5HndEVWWuxW1 MnMSIxhkf5iFbl8udXXVRv5QKi66qDmTM9hKCUMdoLUjg3mcT+7lq2ekV2MlAxKm8ZhH J9GmOi+SYcdcwKk5md0nGM+0WXUZCs9zE2O4KfRVE8qk2ScVlp2Yc0lsGssP7Fz6VStJ 7FJW2Ttw+ydwJEY/v+3w6kcwyDvrG0iDMvk4BM6wM+Ex0G9SYb4LEuvx091QQHhjXcY+ qIiw== 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=cD4DY/iuVWWWEU+B7lYuOW47EogbL76oMXy+TtExHBA=; b=5d3s7rbR3ui/N2kniWDTL1MNg2CnK02I7p+WAnH/0wbMnW6vslDdpxf9UzcpXe4LMs YzP8dMHwq4797N+9D3zL6M5y4TWp4F5GpDfq0iS3MsV+bAPDyyG1ML2ROafe1rBnjEkO z5IXAZmP2oQFw6zx9esuCZgSe+BXybeo8/oZCKptttqlBE7vNX0ybsXMeYe8lNyZw62S 6aMc6zdrPntnUf2pwJvfPVQBHGUm39iwcx/sJVP4HyNeSu4QnT1HGFSi1bzhfmIfqiQe lUbUEcMzFAaIAxJIMSLeOugOvf1r9mZXHlwmfa9Ea9ir5/aKw27cstOaYlG6Lsi4VXB7 PmJg== X-Gm-Message-State: AOAM530tzpaXlZis5kY46TY7oR7lsyKayKFpk5Hx1K+6zTgjoz8FFscD 6C1UJbMJSq3vJ+P1qX6cDs/xjLjgr/KHSDvR8uM= X-Received: by 2002:a63:ce54:0:b0:364:f310:6e0c with SMTP id r20-20020a63ce54000000b00364f3106e0cmr1029941pgi.456.1645072139872; Wed, 16 Feb 2022 20:28:59 -0800 (PST) MIME-Version: 1.0 References: <20220216160500.2341255-1-alvin@pqrs.dk> <87k0dusmar.fsf@bang-olufsen.dk> In-Reply-To: <87k0dusmar.fsf@bang-olufsen.dk> From: Luiz Angelo Daros de Luca Date: Thu, 17 Feb 2022 01:28:48 -0300 Message-ID: Subject: Re: [PATCH net-next 0/2] net: dsa: realtek: fix PHY register read corruption To: =?UTF-8?Q?Alvin_=C5=A0ipraga?= Cc: =?UTF-8?Q?Alvin_=C5=A0ipraga?= , Linus Walleij , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Michael Rasmussen , =?UTF-8?B?QXLEsW7DpyDDnE5BTA==?= , "open list:NETWORKING DRIVERS" , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 > > I still feel like we are trying to go around a regmap limitation > > instead of fixing it there. If we control regmap lock (we can define a > > custom lock/unlock) and create new regmap_{read,write}_nolock > > variants, we'll just need to lock the regmap, do whatever you need, > > and unlock it. > > Can you show me what those regmap_{read,write}_nolock variants would > look like in your example? And what about the other regmap_ APIs we use, > like regmap_read_poll_timeout, regmap_update_bits, etc. - do you propose > to reimplement all of these? The option of having two regmaps is a nice way to have "_nolock" variants for free. It is much cleaner than any solutions I imagined! Ayway, I don't believe the regmap API expects to have an evil non-locked clone. It looks like it is being abused. What regmap API misses is a way to create a "transaction". Mdio, for example, expects the user to lock the bus before doing a series of accesses while regmap api assumes a single atomic access is enough. However, Realtek indirect register access shows that it is not enough. We could reimplement a mutex for every case where two calls might share the same register (or indirectly affect others like we saw with Realtek) but I believe a shared solution would be better, even if it costs a couple more wrap functions. It would be even nicer if we have a regmap "manual lock" mode that will expose the lock/unlock functions but it will never call them by itself. It would work if it could check if the caller is actually the same thread/context that locked it. However I doubt there is a clean solution in a kernel code that can check if the lock was acquired by the same context that is calling the read. > > BTW, I believe that, for realtek-mdio, a regmap custom lock mechanism > > could simply use mdio lock while realtek-smi already has priv->lock. > > Hmm OK. Actually I'm a bit confused about the mdio_lock: can you explain > what it's guarding against, for someone unfamiliar with MDIO? Currently > realtek-mdio's regmap has an additional lock around it (disable_locking > is 0), so with these patches applied the number of locks remains the > same. Today we already have to redundants locks (mdio and regmap). Your patch is just replacing the regmap lock. regmap_read is something like this: regmap_read lock regmap realtek_mdio_read() lock mdio ... unlock mdio unlock regmap If you are implementing a custom lock, simply use mdio lock directly. And the map_nolock you created does not mean "access without locks" but "you must lock it yourself before using anything here". If that lock is actually mdio_lock, it would be ok to remove the lock inside realtek_mdio_{read,write}. You just need a reference to those lock/unlock functions in realtek_priv. > priv->lock is a spinlock which is inappropriate here. I'm not really > sure what the point of it is, besides to handle unlocked calls to the > _noack function. It might be removable altogether but I would prefer not > to touch it for this series. If spinlock is inappropriate, it can be easily converted to a mutex. Everything else from realtek-mdio might apply. > Kind regards, > Alvin