30 May, 2018

1 commit

  • [ Upstream commit 68d2059be660944152ba667e43c3b4ec225974bc ]

    Currently if map is null then a potential null pointer deference
    occurs when calling sock_release on map->sock. I believe the
    actual intention was to call sock_release on sock instead. Fix
    this.

    Fixes: 5db4d286a8ef ("xen/pvcalls: implement connect command")
    Signed-off-by: Colin Ian King
    Reviewed-by: Juergen Gross
    Signed-off-by: Juergen Gross
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Colin Ian King
     

31 Aug, 2017

17 commits

  • __WARN() is an internal helper that is only available on
    some architectures, but causes a build error e.g. on ARM64
    in some configurations:

    drivers/xen/pvcalls-back.c: In function 'set_backend_state':
    drivers/xen/pvcalls-back.c:1097:5: error: implicit declaration of function '__WARN' [-Werror=implicit-function-declaration]

    Unfortunately, there is no equivalent of BUG() that takes no
    arguments, but WARN_ON(1) is commonly used in other drivers
    and works on all configurations.

    Fixes: 7160378206b2 ("xen/pvcalls: xenbus state handling")
    Signed-off-by: Arnd Bergmann
    Reviewed-by: Stefano Stabellini
    Signed-off-by: Boris Ostrovsky

    Arnd Bergmann
     
  • When the other end notifies us that there is data to be written
    (pvcalls_back_conn_event), increment the io and write counters, and
    schedule the ioworker.

    Implement the write function called by ioworker by reading the data from
    the data ring, writing it to the socket by calling inet_sendmsg.

    Set out_error on error.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • When an active socket has data available, increment the io and read
    counters, and schedule the ioworker.

    Implement the read function by reading from the socket, writing the data
    to the data ring.

    Set in_error on error.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • We have one ioworker per socket. Each ioworker goes through the list of
    outstanding read/write requests. Once all requests have been dealt with,
    it returns.

    We use one atomic counter per socket for "read" operations and one
    for "write" operations to keep track of the reads/writes to do.

    We also use one atomic counter ("io") per ioworker to keep track of how
    many outstanding requests we have in total assigned to the ioworker. The
    ioworker finishes when there are none.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Boris Ostrovsky
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Implement backend_disconnect. Call pvcalls_back_release_active on active
    sockets and pvcalls_back_release_passive on passive sockets.

    Implement module_exit by calling backend_disconnect on frontend
    connections.

    [ boris: fixed long lines ]

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Release both active and passive sockets. For active sockets, make sure
    to avoid possible conflicts with the ioworker reading/writing to those
    sockets concurrently. Set map->release to let the ioworker know
    atomically that the socket will be released soon, then wait until the
    ioworker finishes (flush_work).

    Unmap indexes pages and data rings.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Implement poll on passive sockets by requesting a delayed response with
    mappass->reqcopy, and reply back when there is data on the passive
    socket.

    Poll on active socket is unimplemented as by the spec, as the frontend
    should just wait for events and check the indexes on the indexes page.

    Only support one outstanding poll (or accept) request for every passive
    socket at any given time.

    [ boris: fixed long lines ]

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Implement the accept command by calling inet_accept. To avoid blocking
    in the kernel, call inet_accept(O_NONBLOCK) from a workqueue, which get
    scheduled on sk_data_ready (for a passive socket, it means that there
    are connections to accept).

    Use the reqcopy field to store the request. Accept the new socket from
    the delayed work function, create a new sock_mapping for it, map
    the indexes page and data ring, and reply to the other end. Allocate an
    ioworker for the socket.

    Only support one outstanding blocking accept request for every socket at
    any time.

    Add a field to sock_mapping to remember the passive socket from which an
    active socket was created.

    [ boris: fixed whitespaces ]

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Call inet_listen to implement the listen command.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Boris Ostrovsky
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Allocate a socket. Track the allocated passive sockets with a new data
    structure named sockpass_mapping. It contains an unbound workqueue to
    schedule delayed work for the accept and poll commands. It also has a
    reqcopy field to be used to store a copy of a request for delayed work.
    Reads/writes to it are protected by a lock (the "copy_lock" spinlock).
    Initialize the workqueue in pvcalls_back_bind.

    Implement the bind command with inet_bind.

    The pass_sk_data_ready event handler will be added later.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Allocate a socket. Keep track of socket ring mappings with a new data
    structure, called sock_mapping. Implement the connect command by calling
    inet_stream_connect, and mapping the new indexes page and data ring.
    Allocate a workqueue and a work_struct, called ioworker, to perform
    reads and writes to the socket.

    When an active socket is closed (sk_state_change), set in_error to
    -ENOTCONN and notify the other end, as specified by the protocol.

    sk_data_ready and pvcalls_back_ioworker will be implemented later.

    [ boris: fixed whitespaces ]

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Just reply with success to the other end for now. Delay the allocation
    of the actual socket to bind and/or connect.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Boris Ostrovsky
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • When the other end notifies us that there are commands to be read
    (pvcalls_back_event), wake up the backend thread to parse the command.

    The command ring works like most other Xen rings, so use the usual
    ring macros to read and write to it. The functions implementing the
    commands are empty stubs for now.

    [ boris: fixed whitespaces ]

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Introduce a per-frontend data structure named pvcalls_fedata. It
    contains pointers to the command ring, its event channel, a list of
    active sockets and a tree of passive sockets (passing sockets need to be
    looked up from the id on listen, accept and poll commands, while active
    sockets only on release).

    It also has an unbound workqueue to schedule the work of parsing and
    executing commands on the command ring. socket_lock protects the two
    lists. In pvcalls_back_global, keep a list of connected frontends.

    [ boris: fixed whitespaces/long lines ]

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Boris Ostrovsky
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Introduce the code to handle xenbus state changes.

    Implement the probe function for the pvcalls backend. Write the
    supported versions, max-page-order and function-calls nodes to xenstore,
    as required by the protocol.

    Introduce stub functions for disconnecting/connecting to a frontend.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Boris Ostrovsky
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Keep a list of connected frontends. Use a semaphore to protect list
    accesses.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Boris Ostrovsky
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini
     
  • Introduce a xenbus backend for the pvcalls protocol, as defined by
    https://xenbits.xen.org/docs/unstable/misc/pvcalls.html.

    This patch only adds the stubs, the code will be added by the following
    patches.

    Signed-off-by: Stefano Stabellini
    Reviewed-by: Boris Ostrovsky
    Reviewed-by: Juergen Gross
    CC: boris.ostrovsky@oracle.com
    CC: jgross@suse.com
    Signed-off-by: Boris Ostrovsky

    Stefano Stabellini