Skip to content
  1. Jan 09, 2023
  2. Jan 07, 2023
  3. Jan 06, 2023
    • David S. Miller's avatar
      Merge branch 'devlink-unregister' · 6bd4755c
      David S. Miller authored
      
      
      Jakub Kicinski says:
      
      ====================
      devlink: remove the wait-for-references on unregister
      
      Move the registration and unregistration of the devlink instances
      under their instance locks. Don't perform the netdev-style wait
      for all references when unregistering the instance.
      
      Instead the devlink instance refcount will only ensure that
      the memory of the instance is not freed. All places which acquire
      access to devlink instances via a reference must check that the
      instance is still registered under the instance lock.
      
      This fixes the problem of the netdev code accessing devlink
      instances before they are registered.
      
      RFC: https://lore.kernel.org/all/20221217011953.152487-1-kuba@kernel.org/
       - rewrite the cover letter
       - rewrite the commit message for patch 1
       - un-export and rename devl_is_alive
       - squash the netdevsim patches
      ====================
      
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      6bd4755c
    • Jakub Kicinski's avatar
      netdevsim: move devlink registration under the instance lock · 82a3aef2
      Jakub Kicinski authored
      
      
      To prevent races with netdev code accessing free devlink instances
      move the registration under the devlink instance lock.
      Core now waits for the instance to be registered before accessing it.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      82a3aef2
    • Jakub Kicinski's avatar
      netdevsim: rename a label · 5c5ea1d0
      Jakub Kicinski authored
      
      
      err_dl_unregister should unregister the devlink instance.
      Looks like renaming it was missed in one of the reshufflings.
      
      Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      5c5ea1d0
    • Jakub Kicinski's avatar
      devlink: allow registering parameters after the instance · 1d18bb1a
      Jakub Kicinski authored
      
      
      It's most natural to register the instance first and then its
      subobjects. Now that we can use the instance lock to protect
      the atomicity of all init - it should also be safe.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1d18bb1a
    • Jakub Kicinski's avatar
      devlink: don't require setting features before registration · 6ef8f7da
      Jakub Kicinski authored
      
      
      Requiring devlink_set_features() to be run before devlink is
      registered is overzealous. devlink_set_features() itself is
      a leftover from old workarounds which were trying to prevent
      initiating reload before probe was complete.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      6ef8f7da
    • Jakub Kicinski's avatar
      devlink: remove the registration guarantee of references · 9053637e
      Jakub Kicinski authored
      
      
      The objective of exposing the devlink instance locks to
      drivers was to let them use these locks to prevent user space
      from accessing the device before it's fully initialized.
      This is difficult because devlink_unregister() waits for all
      references to be released, meaning that devlink_unregister()
      can't itself be called under the instance lock.
      
      To avoid this issue devlink_register() was moved after subobject
      registration a while ago. Unfortunately the netdev paths get
      a hold of the devlink instances _before_ they are registered.
      Ideally netdev should wait for devlink init to finish (synchronizing
      on the instance lock). This can't work because we don't know if the
      instance will _ever_ be registered (in case of failures it may not).
      The other option of returning an error until devlink_register()
      is called is unappealing (user space would get a notification
      netdev exist but would have to wait arbitrary amount of time
      before accessing some of its attributes).
      
      Weaken the guarantees of the devlink references.
      
      Holding a reference will now only guarantee that the memory
      of the object is around. Another way of looking at it is that
      the reference now protects the object not its "registered" status.
      Use devlink instance lock to synchronize unregistration.
      
      This implies that releasing of the "main" reference of the devlink
      instance moves from devlink_unregister() to devlink_free().
      
      Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      9053637e
    • Jakub Kicinski's avatar
      devlink: always check if the devlink instance is registered · ed539ba6
      Jakub Kicinski authored
      
      
      Always check under the instance lock whether the devlink instance
      is still / already registered.
      
      This is a no-op for the most part, as the unregistration path currently
      waits for all references. On the init path, however, we may temporarily
      open up a race with netdev code, if netdevs are registered before the
      devlink instance. This is temporary, the next change fixes it, and this
      commit has been split out for the ease of review.
      
      Note that in case of iterating over sub-objects which have their
      own lock (regions and line cards) we assume an implicit dependency
      between those objects existing and devlink unregistration.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ed539ba6
    • Jakub Kicinski's avatar
      devlink: protect devlink->dev by the instance lock · 870c7ad4
      Jakub Kicinski authored
      
      
      devlink->dev is assumed to be always valid as long as any
      outstanding reference to the devlink instance exists.
      
      In prep for weakening of the references take the instance lock.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      870c7ad4
    • Jakub Kicinski's avatar
      devlink: update the code in netns move to latest helpers · 7a54a519
      Jakub Kicinski authored
      
      
      devlink_pernet_pre_exit() is the only obvious place which takes
      the instance lock without using the devl_ helpers. Update the code
      and move the error print after releasing the reference
      (having unlock and put together feels slightly idiomatic).
      
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      7a54a519
    • Jakub Kicinski's avatar
      devlink: bump the instance index directly when iterating · d7727819
      Jakub Kicinski authored
      
      
      xa_find_after() is designed to handle multi-index entries correctly.
      If a xarray has two entries one which spans indexes 0-3 and one at
      index 4 xa_find_after(0) will return the entry at index 4.
      
      Having to juggle the two callbacks, however, is unnecessary in case
      of the devlink xarray, as there is 1:1 relationship with indexes.
      
      Always use xa_find() and increment the index manually.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      d7727819
    • Mahesh Bandewar's avatar
      sysctl: expose all net/core sysctls inside netns · 6b754d7b
      Mahesh Bandewar authored
      All were not visible to the non-priv users inside netns. However,
      with 4ecb9009
      
       ("sysctl: allow override of /proc/sys/net with
      CAP_NET_ADMIN"), these vars are protected from getting modified.
      A proc with capable(CAP_NET_ADMIN) can change the values so
      not having them visible inside netns is just causing nuisance to
      process that check certain values (e.g. net.core.somaxconn) and
      see different behavior in root-netns vs. other-netns
      
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Cc: Soheil Hassas Yeganeh <soheil@google.com>
      Signed-off-by: default avatarMahesh Bandewar <maheshb@google.com>
      Acked-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      6b754d7b
    • Jakub Kicinski's avatar
      Merge branch 'devlink-code-split-and-structured-instance-walk' · 3d759e9e
      Jakub Kicinski authored
      
      
      Jakub Kicinski says:
      
      ====================
      devlink: code split and structured instance walk
      
      Split devlink.c into a handful of files, trying to keep the "core"
      code away from all the command-specific implementations.
      The core code has been quite scattered until now. Going forward we can
      consider using a source file per-subobject, I think that it's quite
      beneficial to newcomers (based on relative ease with which folks
      contribute to ethtool vs devlink). But this series doesn't split
      everything out, yet - partially due to backporting concerns,
      but mostly due to lack of time. Bulk of the netlink command
      handling is left in a leftover.c file.
      
      Introduce a context structure for dumps, and use it to store
      the devlink instance ID of the last dumped devlink instance.
      This means we don't have to restart the walk from 0 each time.
      
      Finally - introduce a "structured walk". A centralized dump handler
      in devlink/netlink.c which walks the devlink instances, deals with
      refcounting/locking, simplifying the per-object implementations quite
      a bit. Inspired by the ethtool code.
      
      v1: https://lore.kernel.org/all/20230104041636.226398-1-kuba@kernel.org/
      RFC: https://lore.kernel.org/all/20221215020155.1619839-1-kuba@kernel.org/
      ====================
      
      Link: https://lore.kernel.org/r/20230105040531.353563-1-kuba@kernel.org
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      3d759e9e