30 Dec, 2020

1 commit

  • [ Upstream commit e0da68994d16b46384cce7b86eb645f1ef7c51ef ]

    Fix incorrect type of max_entries in UVERBS_METHOD_QUERY_GID_TABLE -
    max_entries is of type size_t although it can take negative values.

    The following static check revealed it:

    drivers/infiniband/core/uverbs_std_types_device.c:338 ib_uverbs_handler_UVERBS_METHOD_QUERY_GID_TABLE() warn: 'max_entries' unsigned
    Signed-off-by: Avihai Horon
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Sasha Levin

    Avihai Horon
     

30 Jul, 2020

1 commit

  • The header files in RDMA subsystem are dual licensed and can be
    described by simple SPDX tag, so replace all of them at once
    together with making them use the same coding style for header
    guard defines.

    Link: https://lore.kernel.org/r/20200719072521.135260-1-leon@kernel.org
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe

    Leon Romanovsky
     

25 Jul, 2020

1 commit


30 May, 2020

1 commit


28 May, 2020

1 commit


22 May, 2020

1 commit

  • While creating a uobject every create reaches a point where the uobject is
    fully initialized. For ioctls that go on to copy_to_user this means they
    need to open code the destruction of a fully created uobject - ie the
    RDMA_REMOVE_DESTROY sort of flow.

    Open coding this creates bugs, eg the CQ does not properly flush the
    events list when it does its error unwind.

    Provide a uverbs_finalize_uobj_create() function which indicates that the
    uobject is fully initialized and that abort should call to destroy_hw to
    destroy the uobj->object and related.

    Methods can call this function if they go on to have error cases after
    setting uobj->object. Once done those error cases can simply do return,
    without an error unwind.

    Link: https://lore.kernel.org/r/20200519072711.257271-2-leon@kernel.org
    Signed-off-by: Yishai Hadas
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe

    Jason Gunthorpe
     

27 Mar, 2020

1 commit

  • Expose UAR object and its alloc/destroy commands to be used over the ioctl
    interface by user space applications.

    This API supports both BF & NC modes and enables a dynamic allocation of
    UARs once really needed.

    As the number of driver objects were limited by the core ones when the
    merged tree is prepared, had to decrease the number of core objects to
    enable the new UAR object usage.

    Link: https://lore.kernel.org/r/20200324060143.1569116-2-leon@kernel.org
    Signed-off-by: Yishai Hadas
    Reviewed-by: Michael Guralnik
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe

    Yishai Hadas
     

16 Feb, 2019

2 commits


21 Dec, 2018

1 commit

  • Add a helper to zero fill fields before copying data to
    UVERBS_ATTR_STRUCT.

    As UVERBS_ATTR_STRUCT can be used as an extensible struct, we want to make
    sure that if the user supplies us with a struct that has new fields that
    we are not aware of, we return them zeroed to the user.

    This helper should be used when using UVERBS_ATTR_STRUCT for an extendable
    data structure and there is a need to make sure that extended members of
    the struct, that the kernel doesn't handle, are returned zeroed to the
    user. This is needed due to the fact that UVERBS_ATTR_STRUCT allows
    non-zero values for members after 'last' member.

    Signed-off-by: Michael Guralnik
    Reviewed-by: Majd Dibbiny
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe

    Michael Guralnik
     

19 Dec, 2018

1 commit

  • When the parser of an ioctl command has the knowledge that a ptr attribute
    in a bundle represents an array of structures, it is useful for it to know
    the number of elements in the array. This is done by dividing the
    attribute length with the element size.

    Signed-off-by: Moni Shoua
    Reviewed-by: Guy Levi
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe

    Moni Shoua
     

12 Dec, 2018

2 commits


05 Dec, 2018

1 commit

  • Introduce the UVERBS_IDR_ANY_OBJECT type to match any IDR object.

    Once used, the infrastructure skips checking for the IDR type, it
    becomes the driver handler responsibility.

    This enables drivers to get in a given method an object from various of
    types.

    Signed-off-by: Yishai Hadas
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Doug Ledford

    Yishai Hadas
     

04 Dec, 2018

2 commits


27 Nov, 2018

6 commits


23 Nov, 2018

4 commits

  • Add annotations to the uverbs_api structure indicating which driver
    methods are called by the implementation. If the required method
    is NULL the write API will be not be callable.

    This effectively duplicates the cmd_mask system, however it does it by
    expressing invariants required by the core code, not by delegating
    decision making to the driver. This is another step toward eliminating
    cmd_mask.

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Leon Romanovsky

    Jason Gunthorpe
     
  • Bringing all uapi entry points into one place lets us deal with them
    consistently. For instance the write, write_ex and ioctl paths can be
    disabled when an API is not supported by the driver.

    This will replace the uverbs_cmd_table static arrays.

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Leon Romanovsky

    Jason Gunthorpe
     
  • We have many cases where parts of the uapi are not supported in a driver,
    needs a certain protocol, or whatever. It is best to reflect this directly
    into the struct uverbs_api when it is built so that everything is simply
    blocked off, and future introspection can report a proper supported list.

    This is done by adding some additional helpers to the definition list
    language that disable objects based on a 'supported' call back, and a
    helper that disables based on a NULL struct ib_device function pointer.

    Disablement is global. For instance, if a driver disables an object then
    everything connected to that object is removed, including core methods.

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Leon Romanovsky

    Jason Gunthorpe
     
  • The 'tree' data structure is very hard to build at compile time, and this
    makes it very limited. The new radix tree based compiler can handle a more
    complex input language that does not require the compiler to perfectly
    group everything into a neat tree structure.

    Instead use a simple list to describe to input, where the list elements
    can be of various different 'opcodes' instructing the radix compiler what
    to do. Start out with opcodes chaining to other definition lists and
    chaining to the existing 'tree' definition.

    Replace the very top level of the 'object tree' with this list type and
    get rid of struct uverbs_object_tree_def and DECLARE_UVERBS_OBJECT_TREE.

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Leon Romanovsky

    Jason Gunthorpe
     

11 Sep, 2018

1 commit

  • Methods sometimes need to get a flexible set of IDRs and not a strict set
    as can be achieved today by the conventional IDR attribute. Add a new
    IDRS_ARRAY attribute to the generic uverbs ioctl layer.

    IDRS_ARRAY points to array of idrs of the same object type and same access
    rights, only write and read are supported.

    Signed-off-by: Guy Levi
    Signed-off-by: Jason Gunthorpe ``
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe

    Guy Levi
     

06 Sep, 2018

1 commit

  • This makes it clear and safe to access constants passed in from user
    space. We define a consistent ABI of u64 for all constants, and verify
    that the data passed in can be represented by the type the user supplies.

    The expectation is this will always be used with an enum declaring the
    constant values, and the user will use the enum type as input to the
    accessor.

    To retrieve the attribute value we introduce two helper calls - one
    standard which may fail if attribute is not valid and one where caller can
    provide a default value which will be used in case the attribute is not
    valid (useful when attribute is optional).

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Ariel Levkovich
    Signed-off-by: Mark Bloch
    Signed-off-by: Leon Romanovsky

    Mark Bloch
     

13 Aug, 2018

3 commits

  • Everything now uses the uverbs_uapi data structure.

    Signed-off-by: Jason Gunthorpe

    Jason Gunthorpe
     
  • Convert the ioctl method syscall path to use the uverbs_api data
    structures. The new uapi structure includes all the same information, just
    in a different and more optimal way.

    - Use attr_bkey instead of 2 level radix trees for everything related to
    attributes. This includes the attribute storage, presence, and
    detection of missing mandatory attributes.
    - Avoid iterating over all attribute storage at finish, instead use
    find_first_bit with the attr_bkey to locate only those attrs that need
    cleanup.
    - Organize things to always run, and always rely on, cleanup. This
    avoids a bunch of tricky error unwind cases.
    - Locate the method using the radix tree, and locate the attributes
    using a very efficient incremental radix tree lookup
    - Use the precomputed destroy_bkey to handle uobject destruction
    - Use the precomputed allocation sizes and precomputed 'need_stack'
    to avoid maths in the fast path. This is optimal if userspace
    does not pass (many) unsupported attributes.

    Overall this results in much better codegen for the attribute accessors,
    everything is now stored in bitmaps or linear arrays indexed by attr_bkey.
    The compiler can compute attr_bkey values at compile time for all method
    attributes, meaning things like uverbs_attr_is_valid() now compile into
    single instruction bit tests.

    Signed-off-by: Jason Gunthorpe

    Jason Gunthorpe
     
  • This is similar in spirit to devm, it keeps track of any allocations
    linked to this method call and ensures they are all freed when the method
    exits. Further, if there is space in the internal/onstack buffer then the
    allocator will hand out that memory and avoid an expensive call to
    kalloc/kfree in the syscall path.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Leon Romanovsky

    Jason Gunthorpe
     

11 Aug, 2018

3 commits

  • Memory in the bundle is valuable, do not waste it holding an 8 byte
    pointer for the rare case of writing to a PTR_OUT. We can compute the
    pointer by storing a small 1 byte array offset and the base address of the
    uattr memory in the bundle private memory.

    This also means we can access the kernel's copy of the ib_uverbs_attr, so
    drop the copy of flags as well.

    Since the uattr base should be private bundle information this also
    de-inlines the already too big uverbs_copy_to inline and moves
    create_udata into uverbs_ioctl.c so they can see the private struct
    definition.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Leon Romanovsky

    Jason Gunthorpe
     
  • This already existed as the anonymous 'ctx' structure, but this was not
    really a useful form. Hoist this struct into bundle_priv and rework the
    internal things to use it instead.

    Move a bunch of the processing internal state into the priv and reduce the
    excessive use of function arguments.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Leon Romanovsky

    Jason Gunthorpe
     
  • This radix tree datastructure is intended to replace the 'hash' structure
    used today for parsing ioctl methods during system calls. This first
    commit introduces the structure and builds it from the existing .rodata
    descriptions.

    The so-called hash arrangement is actually a 5 level open coded radix tree.
    This new version uses a 3 level radix tree built using the radix tree
    library.

    Overall this is much less code and much easier to build as the radix tree
    API allows for dynamic modification during the building. There is a small
    memory penalty to pay for this, but since the radix tree is allocated on
    a per device basis, a few kb of RAM seems immaterial considering the
    gained simplicity.

    The radix tree is similar to the existing tree, but also has a 'attr_bkey'
    concept, which is a small value'd index for each method attribute. This is
    used to simplify and improve performance of everything in the next
    patches.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Leon Romanovsky
    Reviewed-by: Michael J. Ruhl

    Jason Gunthorpe
     

02 Aug, 2018

1 commit

  • This does the same as the patch before, except for ioctl. The rules are
    the same, but for the ioctl methods the core code handles setting up the
    uobject.

    - Retrieve the ib_dev from the uobject->context->device. This is
    safe under ioctl as the core has already done rdma_alloc_begin_uobject
    and so CREATE calls are entirely protected by the rwsem.
    - Retrieve the ib_dev from uobject->object
    - Call ib_uverbs_get_ucontext()

    Signed-off-by: Jason Gunthorpe

    Jason Gunthorpe
     

31 Jul, 2018

1 commit

  • This clearly indicates that the input is a bitwise combination of values
    in an enum, and identifies which enum contains the definition of the bits.

    Special accessors are provided that handle the mandatory validation of the
    allowed bits and enforce the correct type for bitwise flags.

    If we had introduced this at the start then the kabi would have uniformly
    used u64 data to pass flags, however today there is a mixture of u64 and
    u32 flags. All places are converted to accept both sizes and the accessor
    fixes it. This allows all existing flags to grow to u64 in future without
    any hassle.

    Finally all flags are, by definition, optional. If flags are not passed
    the accessor does not fail, but provides a value of zero.

    Signed-off-by: Jason Gunthorpe
    Reviewed-by: Leon Romanovsky

    Jason Gunthorpe
     

26 Jul, 2018

1 commit

  • We have a parallel unlocked reader and writer with ib_uverbs_get_context()
    vs everything else, and nothing guarantees this works properly.

    Audit and fix all of the places that access ucontext to use one of the
    following locking schemes:
    - Call ib_uverbs_get_ucontext() under SRCU and check for failure
    - Access the ucontext through an struct ib_uobject context member
    while holding a READ or WRITE lock on the uobject.
    This value cannot be NULL and has no race.
    - Hold the ucontext_lock and check for ufile->ucontext !NULL

    This also re-implements ib_uverbs_get_ucontext() in a way that is safe
    against concurrent ib_uverbs_get_context() and disassociation.

    As a side effect, every access to ucontext in the commands is via
    ib_uverbs_get_context() with an error check, or via the uobject, so there
    is no longer any need for the core code to check ucontext on every command
    call. These checks are also removed.

    Signed-off-by: Jason Gunthorpe

    Jason Gunthorpe
     

25 Jul, 2018

1 commit

  • Introduce flow steering matcher object and its create and destroy methods.

    This matcher object holds some mlx5 specific driver properties that
    matches the underlay device specification when an mlx5 flow steering group
    is created.

    It will be used in downstream patches to be part of mlx5 specific create
    flow method.

    Signed-off-by: Yishai Hadas
    Signed-off-by: Leon Romanovsky
    Signed-off-by: Jason Gunthorpe

    Yishai Hadas
     

05 Jul, 2018

2 commits

  • After all the rework is done it is now possible to include single flags in
    the type macros. Any user of UVERBS_ATTR_STRUCT needs to zero check data
    past the end of the known struct to be correct, so make this mandatory,
    and get rid of MIN_SZ_OR_ZERO as a user flag.

    This changes UVERBS_ATTR_TYPE to refer to a struct of exact size with not
    possibility of extension, convert the few users of UVERBS_ATTR_TYPE and
    MIN_SZ_OR_ZERO to use UVERBS_ATTR_STRUCT.

    The one user of UVERBS_ATTR_STRUCT without MIN_SZ_OR_ZERO is just
    confused. There is some padding at the end of that struct, but userspace
    always provides it with the padding. The construction doesn't test if the
    padding is zero, so it is pointless. Just use UVERBS_ATTR_TYPE.

    Finally, rename min_sz_or_zero to zero_trailing to better reflect what it
    does and hopefully avoid such mis-uses in the future.

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Leon Romanovsky

    Jason Gunthorpe
     
  • This newer macro allows specifying a lower bound on the accepted size, and
    has an 'unlimited' upper bound. Due to this it never checks for trailing
    zeroing so it doesn't make any sense to combine it with MIN_SZ_OR_ZERO, so
    drop MIN_SZ_OR_ZERO when they are used together

    There were a couple of places that open coded this pattern, switch them to
    use the clearer UVERBS_ATTR_MIN_SIZE for clarity.

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Leon Romanovsky

    Jason Gunthorpe