04 Nov, 2020

1 commit

  • All user space generated SKBs are owned by a socket (unless injected into the
    key via AF_PACKET). If a socket is closed, all associated skbs will be cleaned
    up.

    This leads to a problem when a CAN driver calls can_put_echo_skb() on a
    unshared SKB. If the socket is closed prior to the TX complete handler,
    can_get_echo_skb() and the subsequent delivering of the echo SKB to all
    registered callbacks, a SKB with a refcount of 0 is delivered.

    To avoid the problem, in can_get_echo_skb() the original SKB is now always
    cloned, regardless of shared SKB or not. If the process exists it can now
    safely discard its SKBs, without disturbing the delivery of the echo SKB.

    The problem shows up in the j1939 stack, when it clones the incoming skb, which
    detects the already 0 refcount.

    We can easily reproduce this with following example:

    testj1939 -B -r can0: &
    cansend can0 1823ff40#0123

    WARNING: CPU: 0 PID: 293 at lib/refcount.c:25 refcount_warn_saturate+0x108/0x174
    refcount_t: addition on 0; use-after-free.
    Modules linked in: coda_vpu imx_vdoa videobuf2_vmalloc dw_hdmi_ahb_audio vcan
    CPU: 0 PID: 293 Comm: cansend Not tainted 5.5.0-rc6-00376-g9e20dcb7040d #1
    Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
    Backtrace:
    [] (dump_backtrace) from [] (show_stack+0x20/0x24)
    [] (show_stack) from [] (dump_stack+0x8c/0xa0)
    [] (dump_stack) from [] (__warn+0xe0/0x108)
    [] (__warn) from [] (warn_slowpath_fmt+0xa8/0xcc)
    [] (warn_slowpath_fmt) from [] (refcount_warn_saturate+0x108/0x174)
    [] (refcount_warn_saturate) from [] (j1939_can_recv+0x20c/0x210)
    [] (j1939_can_recv) from [] (can_rcv_filter+0xb4/0x268)
    [] (can_rcv_filter) from [] (can_receive+0xb0/0xe4)
    [] (can_receive) from [] (can_rcv+0x48/0x98)
    [] (can_rcv) from [] (__netif_receive_skb_one_core+0x64/0x88)
    [] (__netif_receive_skb_one_core) from [] (__netif_receive_skb+0x38/0x94)
    [] (__netif_receive_skb) from [] (netif_receive_skb_internal+0x64/0xf8)
    [] (netif_receive_skb_internal) from [] (netif_receive_skb+0x34/0x19c)
    [] (netif_receive_skb) from [] (can_rx_offload_napi_poll+0x58/0xb4)

    Fixes: 0ae89beb283a ("can: add destructor for self generated skbs")
    Signed-off-by: Oleksij Rempel
    Link: http://lore.kernel.org/r/20200124132656.22156-1-o.rempel@pengutronix.de
    Acked-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oleksij Rempel
     

12 Oct, 2020

1 commit

  • As pointed out by Jakub Kicinski here:
    http://lore.kernel.org/r/20201009175751.5c54097f@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com
    this patch removes the obsolete version information of the different
    CAN protocols and the AF_CAN core module.

    Signed-off-by: Oliver Hartkopp
    Link: https://lore.kernel.org/r/20201012074354.25839-2-socketcan@hartkopp.net
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

08 Oct, 2020

1 commit

  • Rename macro CAN_CALC_SYNC_SEG to CAN_SYNC_SEG and make it available
    through include/linux/can/dev.h

    Add an helper function can_bit_time() which returns the duration (in
    time quanta) of one CAN bit.

    Rationale for this patch: the sync segment and the bit time are two
    concepts which are defined in the CAN ISO standard. Device drivers for
    CAN might need those.

    Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for
    additional information.

    Signed-off-by: Vincent Mailhol
    Link: https://lore.kernel.org/r/20201002154219.4887-6-mailhol.vincent@wanadoo.fr
    [mkl: Let can_bit_time() return an unsinged int, make argument const]
    Signed-off-by: Marc Kleine-Budde

    Vincent Mailhol
     

07 Oct, 2020

1 commit


21 Sep, 2020

3 commits


16 Jun, 2020

1 commit

  • There is a regular need in the kernel to provide a way to declare having a
    dynamically sized set of trailing elements in a structure. Kernel code should
    always use “flexible array members”[1] for these cases. The older style of
    one-element or zero-length arrays should no longer be used[2].

    [1] https://en.wikipedia.org/wiki/Flexible_array_member
    [2] https://github.com/KSPP/linux/issues/21

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

19 Apr, 2020

1 commit

  • The current codebase makes use of the zero-length array language
    extension to the C90 standard, but the preferred mechanism to declare
    variable-length types such as these ones is a flexible array member[1][2],
    introduced in C99:

    struct foo {
    int stuff;
    struct boo array[];
    };

    By making use of the mechanism above, we will get a compiler warning
    in case the flexible array does not occur last in the structure, which
    will help us prevent some kind of undefined behavior bugs from being
    inadvertently introduced[3] to the codebase from now on.

    Also, notice that, dynamic memory allocations won't be affected by
    this change:

    "Flexible array members have incomplete type, and so the sizeof operator
    may not be applied. As a quirk of the original implementation of
    zero-length arrays, sizeof evaluates to zero."[1]

    This issue was found with the help of Coccinelle.

    [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
    [2] https://github.com/KSPP/linux/issues/21
    [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

02 Jan, 2020

1 commit

  • KMSAN sysbot detected a read access to an untinitialized value in the
    headroom of an outgoing CAN related sk_buff. When using CAN sockets this
    area is filled appropriately - but when using a packet socket this
    initialization is missing.

    The problematic read access occurs in the CAN receive path which can
    only be triggered when the sk_buff is sent through a (virtual) CAN
    interface. So we check in the sending path whether we need to perform
    the missing initializations.

    Fixes: d3b58c47d330d ("can: replace timestamp as unique skb attribute")
    Reported-by: syzbot+b02ff0707a97e4e79ebb@syzkaller.appspotmail.com
    Signed-off-by: Oliver Hartkopp
    Tested-by: Oliver Hartkopp
    Cc: linux-stable # >= v4.1
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

17 Nov, 2019

1 commit


13 Nov, 2019

1 commit


12 Nov, 2019

3 commits

  • The skbs for classic CAN and CAN FD frames are allocated with seperate
    functions: alloc_can_skb() and alloc_canfd_skb().

    In order to support CAN FD frames via the rx-offload helper, the driver
    itself has to allocate the skb (depending whether it received a classic
    CAN or CAN FD frame), as the rx-offload helper cannot know which kind of
    CAN frame the driver has received.

    This patch moves the allocation of the skb into the struct
    can_rx_offload::mailbox_read callbacks of the the flexcan and ti_hecc
    driver and adjusts the rx-offload helper accordingly.

    Signed-off-by: Joakim Zhang
    Signed-off-by: Marc Kleine-Budde

    Joakim Zhang
     
  • This patch removes the function can_rx_offload_reset(), as it does
    nothing. If we ever need this function, add it back again.

    Signed-off-by: Marc Kleine-Budde

    Marc Kleine-Budde
     
  • Instead of using legacy platform data, switch to use device properties.
    For clock frequency we are using well established clock-frequency property.

    Users, two for now, are also converted here.

    Cc: Daniel Mack
    Cc: Haojian Zhuang
    Cc: Robert Jarzmik
    Cc: Russell King
    Signed-off-by: Andy Shevchenko
    Signed-off-by: Marc Kleine-Budde

    Andy Shevchenko
     

05 Sep, 2019

1 commit

  • …x/kernel/git/mkl/linux-can-next

    Marc Kleine-Budde says:

    ====================
    pull-request: can-next 2019-09-04 j1939

    this is a pull request for net-next/master consisting of 21 patches.

    the first 12 patches are by me and target the CAN core infrastructure.
    They clean up the names of variables , structs and struct members,
    convert can_rx_register() to use max() instead of open coding it and
    remove unneeded code from the can_pernet_exit() callback.

    The next three patches are also by me and they introduce and make use of
    the CAN midlayer private structure. It is used to hold protocol specific
    per device data structures.

    The next patch is by Oleksij Rempel, switches the
    &net->can.rcvlists_lock from a spin_lock() to a spin_lock_bh(), so that
    it can be used from NAPI (soft IRQ) context.

    The next 4 patches are by Kurt Van Dijck, he first updates his email
    address via mailmap and then extends sockaddr_can to include j1939
    members.

    The final patch is the collective effort of many entities (The j1939
    authors: Oliver Hartkopp, Bastian Stender, Elenita Hinds, kbuild test
    robot, Kurt Van Dijck, Maxime Jayat, Robin van der Gracht, Oleksij
    Rempel, Marc Kleine-Budde). It adds support of SAE J1939 protocol to the
    CAN networking stack.

    SAE J1939 is the vehicle bus recommended practice used for communication
    and diagnostics among vehicle components. Originating in the car and
    heavy-duty truck industry in the United States, it is now widely used in
    other parts of the world.

    P.S.: This pull request doesn't invalidate my last pull request:
    "pull-request: can-next 2019-09-03".
    ====================

    Signed-off-by: David S. Miller <davem@davemloft.net>

    David S. Miller
     

04 Sep, 2019

4 commits

  • SAE J1939 is the vehicle bus recommended practice used for communication
    and diagnostics among vehicle components. Originating in the car and
    heavy-duty truck industry in the United States, it is now widely used in
    other parts of the world.

    J1939, ISO 11783 and NMEA 2000 all share the same high level protocol.
    SAE J1939 can be considered the replacement for the older SAE J1708 and
    SAE J1587 specifications.

    Acked-by: Oliver Hartkopp
    Signed-off-by: Bastian Stender
    Signed-off-by: Elenita Hinds
    Signed-off-by: kbuild test robot
    Signed-off-by: Kurt Van Dijck
    Signed-off-by: Maxime Jayat
    Signed-off-by: Robin van der Gracht
    Signed-off-by: Oleksij Rempel
    Signed-off-by: Marc Kleine-Budde

    The j1939 authors
     
  • The size of this structure will be increased with J1939 support. To stay
    binary compatible, the CAN_REQUIRED_SIZE macro is introduced for
    existing CAN protocols.

    Signed-off-by: Kurt Van Dijck
    Signed-off-by: Oleksij Rempel
    Acked-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Kurt Van Dijck
     
  • This patch removes the old method of allocating the per device protocol
    specific memory via a netdevice_notifier. This had the drawback, that
    the allocation can fail, leading to a lot of null pointer checks in the
    code. This also makes the live cycle management of this memory quite
    complicated.

    This patch switches from the allocating the struct can_dev_rcv_lists in
    a NETDEV_REGISTER call to using the dev->ml_priv, which is allocated by
    the driver since the previous patch.

    Signed-off-by: Oleksij Rempel
    Acked-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Marc Kleine-Budde
     
  • This patch introduces the CAN midlayer private structure ("struct
    can_ml_priv") which should be used to hold protocol specific per device
    data structures. For now it's only member is "struct can_dev_rcv_lists".

    The CAN midlayer private is allocated via alloc_netdev()'s private and
    assigned to "struct net_device::ml_priv" during device creation. This is
    done transparently for CAN drivers using alloc_candev(). The slcan, vcan
    and vxcan drivers which are not using alloc_candev() have been adopted
    manually. The memory layout of the netdev_priv allocated via
    alloc_candev() will looke like this:

    +-------------------------+
    | driver's priv |
    +-------------------------+
    | struct can_ml_priv |
    +-------------------------+
    | array of struct sk_buff |
    +-------------------------+

    Signed-off-by: Oleksij Rempel
    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Marc Kleine-Budde
     

03 Sep, 2019

1 commit


20 Aug, 2019

1 commit

  • All R-Car platforms use DT for describing CAN controllers. R-Car CAN
    platform data support was never used in any upstream kernel.

    Move the Clock Select Register settings enum into the driver, and remove
    platform data support and the corresponding header file.

    Signed-off-by: Geert Uytterhoeven
    Reviewed-by: Wolfram Sang
    Signed-off-by: Marc Kleine-Budde

    Geert Uytterhoeven
     

24 Jul, 2019

2 commits


19 Jun, 2019

2 commits

  • Based on 2 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation #

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 4122 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Enrico Weigelt
    Reviewed-by: Kate Stewart
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     
  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the version 2 of the gnu general public
    license as published by the free software foundation this program is
    distributed in the hope that it will be useful but without any
    warranty without even the implied warranty of merchantability or
    fitness for a particular purpose see the gnu general public license
    for more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 10 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Enrico Weigelt
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190604081206.259525894@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

05 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation version 2 of the license this program
    is distributed in the hope that it will be useful but without any
    warranty without even the implied warranty of merchantability or
    fitness for a particular purpose see the gnu general public license
    for more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 100 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Alexios Zavras
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190529141900.918357685@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

10 Nov, 2018

3 commits


27 Jul, 2018

1 commit

  • The existing SocketCAN implementation provides alloc_candev() to
    allocate a CAN device using a single Tx and Rx queue. This can lead to
    priority inversion in case the single Tx queue is already full with low
    priority messages and a high priority message needs to be sent while the
    bus is fully loaded with medium priority messages.

    This problem can be solved by using the existing multi-queue support of
    the network subsytem. The commit makes it possible to use multi-queue in
    the CAN subsystem in the same way it is used in the Ethernet subsystem
    by adding an alloc_candev_mqs() call and accompanying macros. With this
    support a CAN device can use multi-queue qdisc (e.g. mqprio) to avoid
    the aforementioned priority inversion.

    The exisiting functionality of alloc_candev() is the same as before.

    CAN devices need to have prioritized multiple hardware queues or are
    able to abort waiting for arbitration to make sensible use of
    multi-queues.

    Signed-off-by: Zhu Yi
    Signed-off-by: Mark Jonas
    Reviewed-by: Heiko Schocher
    Signed-off-by: Marc Kleine-Budde

    Zhu Yi
     

16 Jan, 2018

1 commit

  • Various CAN or CAN-FD IP may be able to run at a faster rate than
    what the transceiver the CAN node is connected to. This can lead to
    unexpected errors. However, CAN transceivers typically have fixed
    limitations and provide no means to discover these limitations at
    runtime. Therefore, add support for a can-transceiver node that
    can be reused by other CAN peripheral drivers to determine for both
    CAN and CAN-FD what the max bitrate that can be used. If the user
    tries to configure CAN to pass these maximum bitrates it will throw
    an error.

    Also add support for reading bitrate_max via the netlink interface.

    Reviewed-by: Suman Anna
    Signed-off-by: Franklin S Cooper Jr
    [nsekhar@ti.com: fix build error with !CONFIG_OF]
    Signed-off-by: Sekhar Nori
    Signed-off-by: Faiz Abbas
    Signed-off-by: Marc Kleine-Budde

    Franklin S Cooper Jr
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

25 Apr, 2017

3 commits

  • The statistics and its proc output was not implemented as per-net in the
    initial network namespace support by Mario Kicherer (8e8cda6d737d).
    This patch adds the missing per-net statistics for the CAN subsystem.

    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     
  • This patch adds the support of the PCAN-PCI Express FD boards made
    by PEAK-System, for computers using the PCI Express slot.

    The PCAN-PCI Express FD has one or two CAN FD channels, depending
    on the model. A galvanic isolation of the CAN ports protects
    the electronics of the card and the respective computer against
    disturbances of up to 500 Volts. The PCAN-PCI Express FD can be operated
    with ambient temperatures in a range of -40 to +85 °C.

    Such boards run an extented version of the CAN-FD IP running into USB
    CAN-FD interfaces from PEAK-System, so this patch adds several new commands
    and their corresponding data types to the PEAK CAN-FD common definitions
    header file too.

    Signed-off-by: Stephane Grosjean
    Signed-off-by: Marc Kleine-Budde

    Stephane Grosjean
     
  • The CAN-FD IP from PEAK-System runs into several kinds of PC CAN-FD
    interfaces. Up to now, only the USB CAN-FD adapters were supported by
    the Kernel. In order to prepare the adding of some new non-USB CAN-FD
    interfaces, this patch moves - and rename - the IP definitions file
    from its private (usb) sub-directory into a - newly created - CAN specific
    one.

    Signed-off-by: Stephane Grosjean
    Signed-off-by: Marc Kleine-Budde

    Stephane Grosjean
     

04 Apr, 2017

2 commits

  • This patch adds initial support for network namespaces. The changes only
    enable support in the CAN raw, proc and af_can code. GW and BCM still
    have their checks that ensure that they are used only from the main
    namespace.

    The patch boils down to moving the global structures, i.e. the global
    filter list and their /proc stats, into a per-namespace structure and passing
    around the corresponding "struct net" in a lot of different places.

    Changes since v1:
    - rebased on current HEAD (2bfe01e)
    - fixed overlong line

    Signed-off-by: Mario Kicherer
    Signed-off-by: Marc Kleine-Budde

    Mario Kicherer
     
  • This patch converts TI HECC driver to DT only driver. This results in
    removing ti_hecc.h containing now obsolete platform data.

    Former transceiver_switch callback function will be now modelled via
    regulator API.

    Signed-off-by: Anton Glukhov
    Signed-off-by: Yegor Yefremov
    Signed-off-by: Marc Kleine-Budde

    Yegor Yefremov
     

06 Feb, 2017

2 commits

  • Some CAN controllers don't implement a FIFO in hardware, but fill their
    mailboxes in a particular order (from lowest to highest or highest to lowest).
    This makes problems to read the frames in the correct order from the hardware,
    as new frames might be filled into just read (low) mailboxes. This gets worse,
    when following new frames are received into not read (higher) mailboxes.

    On the bright side some these CAN controllers put a timestamp on each received
    CAN frame. This patch adds support to offload CAN frames in interrupt context,
    order them by timestamp and then transmitted in a NAPI context.

    Signed-off-by: Marc Kleine-Budde

    Marc Kleine-Budde
     
  • Some CAN controllers have a usable FIFO already but can still benefit
    from off-loading the CAN controller FIFO. The CAN frames of the FIFO are
    read and put into a skb queue during interrupt and then transmitted in a
    NAPI context.

    Signed-off-by: David Jander
    Signed-off-by: Marc Kleine-Budde

    David Jander