Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH] wireless/p54: Remove duplicated net2280 header
From: John W. Linville @ 2014-12-01 19:59 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado
  Cc: Christian Lamparter, LKML, linux-wireless, netdev, David Miller
In-Reply-To: <CAPybu_1LBqp5JKBUr85HWfkcSJH5vy2zY9Z13Xvw7W1xyjKOzg@mail.gmail.com>

Did you check the wireless-next tree's git logs?

commit a831f20b6d6460640b83644d1c1df6e7e8ca9f68
Author: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Date:   Mon Nov 24 11:19:51 2014 +0100

    wireless/p54: Remove duplicated net2280 header
    
    The usb gadget driver net2280 has exported a header file with the
    register definition of the net2280 chip.
    
    Remove the custom/duplicated header file in favor of that header file
    in include/linux
    
    Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
    Signed-off-by: John W. Linville <linville@tuxdriver.com>

On Mon, Dec 01, 2014 at 11:46:43AM +0100, Ricardo Ribalda Delgado wrote:
> David Miller has marked the patch as "Awaiting Upstream", which I
> think means that it should be merged through the wireless tree.
> 
> Any comment from there?
> 
> On Mon, Nov 24, 2014 at 11:19 AM, Ricardo Ribalda Delgado
> <ricardo.ribalda@gmail.com> wrote:
> > The usb gadget driver net2280 has exported a header file with the
> > register definition of the net2280 chip.
> >
> > Remove the custom/duplicated header file in favor of that header file
> > in include/linux
> >
> > Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> > ---
> >  drivers/net/wireless/p54/net2280.h | 451 -------------------------------------
> >  drivers/net/wireless/p54/p54usb.h  |  13 +-
> >  2 files changed, 12 insertions(+), 452 deletions(-)
> >  delete mode 100644 drivers/net/wireless/p54/net2280.h
> >
> > diff --git a/drivers/net/wireless/p54/net2280.h b/drivers/net/wireless/p54/net2280.h
> > deleted file mode 100644
> > index aedfaf2..0000000
> > --- a/drivers/net/wireless/p54/net2280.h
> > +++ /dev/null
> > @@ -1,451 +0,0 @@
> > -#ifndef NET2280_H
> > -#define NET2280_H
> > -/*
> > - * NetChip 2280 high/full speed USB device controller.
> > - * Unlike many such controllers, this one talks PCI.
> > - */
> > -
> > -/*
> > - * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
> > - * Copyright (C) 2003 David Brownell
> > - *
> > - * 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; either version 2 of the License, or
> > - * (at your option) any later version.
> > - *
> > - * 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.
> > - *
> > - * You should have received a copy of the GNU General Public License
> > - * along with this program; if not, see <http://www.gnu.org/licenses/>.
> > - */
> > -
> > -/*-------------------------------------------------------------------------*/
> > -
> > -/* NET2280 MEMORY MAPPED REGISTERS
> > - *
> > - * The register layout came from the chip documentation, and the bit
> > - * number definitions were extracted from chip specification.
> > - *
> > - * Use the shift operator ('<<') to build bit masks, with readl/writel
> > - * to access the registers through PCI.
> > - */
> > -
> > -/* main registers, BAR0 + 0x0000 */
> > -struct net2280_regs {
> > -       /* offset 0x0000 */
> > -       __le32                  devinit;
> > -#define LOCAL_CLOCK_FREQUENCY                                  8
> > -#define FORCE_PCI_RESET                                                7
> > -#define PCI_ID                                                 6
> > -#define PCI_ENABLE                                             5
> > -#define FIFO_SOFT_RESET                                                4
> > -#define CFG_SOFT_RESET                                         3
> > -#define PCI_SOFT_RESET                                         2
> > -#define USB_SOFT_RESET                                         1
> > -#define M8051_RESET                                            0
> > -       __le32                  eectl;
> > -#define EEPROM_ADDRESS_WIDTH                                   23
> > -#define EEPROM_CHIP_SELECT_ACTIVE                              22
> > -#define EEPROM_PRESENT                                         21
> > -#define EEPROM_VALID                                           20
> > -#define EEPROM_BUSY                                            19
> > -#define EEPROM_CHIP_SELECT_ENABLE                              18
> > -#define EEPROM_BYTE_READ_START                                 17
> > -#define EEPROM_BYTE_WRITE_START                                        16
> > -#define EEPROM_READ_DATA                                       8
> > -#define EEPROM_WRITE_DATA                                      0
> > -       __le32                  eeclkfreq;
> > -       u32                     _unused0;
> > -       /* offset 0x0010 */
> > -
> > -       __le32                  pciirqenb0;     /* interrupt PCI master ... */
> > -#define SETUP_PACKET_INTERRUPT_ENABLE                          7
> > -#define ENDPOINT_F_INTERRUPT_ENABLE                            6
> > -#define ENDPOINT_E_INTERRUPT_ENABLE                            5
> > -#define ENDPOINT_D_INTERRUPT_ENABLE                            4
> > -#define ENDPOINT_C_INTERRUPT_ENABLE                            3
> > -#define ENDPOINT_B_INTERRUPT_ENABLE                            2
> > -#define ENDPOINT_A_INTERRUPT_ENABLE                            1
> > -#define ENDPOINT_0_INTERRUPT_ENABLE                            0
> > -       __le32                  pciirqenb1;
> > -#define PCI_INTERRUPT_ENABLE                                   31
> > -#define POWER_STATE_CHANGE_INTERRUPT_ENABLE                    27
> > -#define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE                   26
> > -#define PCI_PARITY_ERROR_INTERRUPT_ENABLE                      25
> > -#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE             20
> > -#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE             19
> > -#define PCI_TARGET_ABORT_ASSERTED_INTERRUPT_ENABLE             18
> > -#define PCI_RETRY_ABORT_INTERRUPT_ENABLE                       17
> > -#define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE                 16
> > -#define GPIO_INTERRUPT_ENABLE                                  13
> > -#define DMA_D_INTERRUPT_ENABLE                                 12
> > -#define DMA_C_INTERRUPT_ENABLE                                 11
> > -#define DMA_B_INTERRUPT_ENABLE                                 10
> > -#define DMA_A_INTERRUPT_ENABLE                                 9
> > -#define EEPROM_DONE_INTERRUPT_ENABLE                           8
> > -#define VBUS_INTERRUPT_ENABLE                                  7
> > -#define CONTROL_STATUS_INTERRUPT_ENABLE                                6
> > -#define ROOT_PORT_RESET_INTERRUPT_ENABLE                       4
> > -#define SUSPEND_REQUEST_INTERRUPT_ENABLE                       3
> > -#define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE                        2
> > -#define RESUME_INTERRUPT_ENABLE                                        1
> > -#define SOF_INTERRUPT_ENABLE                                   0
> > -       __le32                  cpu_irqenb0;    /* ... or onboard 8051 */
> > -#define SETUP_PACKET_INTERRUPT_ENABLE                          7
> > -#define ENDPOINT_F_INTERRUPT_ENABLE                            6
> > -#define ENDPOINT_E_INTERRUPT_ENABLE                            5
> > -#define ENDPOINT_D_INTERRUPT_ENABLE                            4
> > -#define ENDPOINT_C_INTERRUPT_ENABLE                            3
> > -#define ENDPOINT_B_INTERRUPT_ENABLE                            2
> > -#define ENDPOINT_A_INTERRUPT_ENABLE                            1
> > -#define ENDPOINT_0_INTERRUPT_ENABLE                            0
> > -       __le32                  cpu_irqenb1;
> > -#define CPU_INTERRUPT_ENABLE                                   31
> > -#define POWER_STATE_CHANGE_INTERRUPT_ENABLE                    27
> > -#define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE                   26
> > -#define PCI_PARITY_ERROR_INTERRUPT_ENABLE                      25
> > -#define PCI_INTA_INTERRUPT_ENABLE                              24
> > -#define PCI_PME_INTERRUPT_ENABLE                               23
> > -#define PCI_SERR_INTERRUPT_ENABLE                              22
> > -#define PCI_PERR_INTERRUPT_ENABLE                              21
> > -#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE             20
> > -#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE             19
> > -#define PCI_RETRY_ABORT_INTERRUPT_ENABLE                       17
> > -#define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE                 16
> > -#define GPIO_INTERRUPT_ENABLE                                  13
> > -#define DMA_D_INTERRUPT_ENABLE                                 12
> > -#define DMA_C_INTERRUPT_ENABLE                                 11
> > -#define DMA_B_INTERRUPT_ENABLE                                 10
> > -#define DMA_A_INTERRUPT_ENABLE                                 9
> > -#define EEPROM_DONE_INTERRUPT_ENABLE                           8
> > -#define VBUS_INTERRUPT_ENABLE                                  7
> > -#define CONTROL_STATUS_INTERRUPT_ENABLE                                6
> > -#define ROOT_PORT_RESET_INTERRUPT_ENABLE                       4
> > -#define SUSPEND_REQUEST_INTERRUPT_ENABLE                       3
> > -#define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE                        2
> > -#define RESUME_INTERRUPT_ENABLE                                        1
> > -#define SOF_INTERRUPT_ENABLE                                   0
> > -
> > -       /* offset 0x0020 */
> > -       u32                     _unused1;
> > -       __le32                  usbirqenb1;
> > -#define USB_INTERRUPT_ENABLE                                   31
> > -#define POWER_STATE_CHANGE_INTERRUPT_ENABLE                    27
> > -#define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE                   26
> > -#define PCI_PARITY_ERROR_INTERRUPT_ENABLE                      25
> > -#define PCI_INTA_INTERRUPT_ENABLE                              24
> > -#define PCI_PME_INTERRUPT_ENABLE                               23
> > -#define PCI_SERR_INTERRUPT_ENABLE                              22
> > -#define PCI_PERR_INTERRUPT_ENABLE                              21
> > -#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE             20
> > -#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE             19
> > -#define PCI_RETRY_ABORT_INTERRUPT_ENABLE                       17
> > -#define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE                 16
> > -#define GPIO_INTERRUPT_ENABLE                                  13
> > -#define DMA_D_INTERRUPT_ENABLE                                 12
> > -#define DMA_C_INTERRUPT_ENABLE                                 11
> > -#define DMA_B_INTERRUPT_ENABLE                                 10
> > -#define DMA_A_INTERRUPT_ENABLE                                 9
> > -#define EEPROM_DONE_INTERRUPT_ENABLE                           8
> > -#define VBUS_INTERRUPT_ENABLE                                  7
> > -#define CONTROL_STATUS_INTERRUPT_ENABLE                                6
> > -#define ROOT_PORT_RESET_INTERRUPT_ENABLE                       4
> > -#define SUSPEND_REQUEST_INTERRUPT_ENABLE                       3
> > -#define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE                        2
> > -#define RESUME_INTERRUPT_ENABLE                                        1
> > -#define SOF_INTERRUPT_ENABLE                                   0
> > -       __le32                  irqstat0;
> > -#define INTA_ASSERTED                                          12
> > -#define SETUP_PACKET_INTERRUPT                                 7
> > -#define ENDPOINT_F_INTERRUPT                                   6
> > -#define ENDPOINT_E_INTERRUPT                                   5
> > -#define ENDPOINT_D_INTERRUPT                                   4
> > -#define ENDPOINT_C_INTERRUPT                                   3
> > -#define ENDPOINT_B_INTERRUPT                                   2
> > -#define ENDPOINT_A_INTERRUPT                                   1
> > -#define ENDPOINT_0_INTERRUPT                                   0
> > -       __le32                  irqstat1;
> > -#define POWER_STATE_CHANGE_INTERRUPT                           27
> > -#define PCI_ARBITER_TIMEOUT_INTERRUPT                          26
> > -#define PCI_PARITY_ERROR_INTERRUPT                             25
> > -#define PCI_INTA_INTERRUPT                                     24
> > -#define PCI_PME_INTERRUPT                                      23
> > -#define PCI_SERR_INTERRUPT                                     22
> > -#define PCI_PERR_INTERRUPT                                     21
> > -#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT                    20
> > -#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT                    19
> > -#define PCI_RETRY_ABORT_INTERRUPT                              17
> > -#define PCI_MASTER_CYCLE_DONE_INTERRUPT                                16
> > -#define GPIO_INTERRUPT                                         13
> > -#define DMA_D_INTERRUPT                                                12
> > -#define DMA_C_INTERRUPT                                                11
> > -#define DMA_B_INTERRUPT                                                10
> > -#define DMA_A_INTERRUPT                                                9
> > -#define EEPROM_DONE_INTERRUPT                                  8
> > -#define VBUS_INTERRUPT                                         7
> > -#define CONTROL_STATUS_INTERRUPT                               6
> > -#define ROOT_PORT_RESET_INTERRUPT                              4
> > -#define SUSPEND_REQUEST_INTERRUPT                              3
> > -#define SUSPEND_REQUEST_CHANGE_INTERRUPT                       2
> > -#define RESUME_INTERRUPT                                       1
> > -#define SOF_INTERRUPT                                          0
> > -       /* offset 0x0030 */
> > -       __le32                  idxaddr;
> > -       __le32                  idxdata;
> > -       __le32                  fifoctl;
> > -#define PCI_BASE2_RANGE                                                16
> > -#define IGNORE_FIFO_AVAILABILITY                               3
> > -#define PCI_BASE2_SELECT                                       2
> > -#define FIFO_CONFIGURATION_SELECT                              0
> > -       u32                     _unused2;
> > -       /* offset 0x0040 */
> > -       __le32                  memaddr;
> > -#define START                                                  28
> > -#define DIRECTION                                              27
> > -#define FIFO_DIAGNOSTIC_SELECT                                 24
> > -#define MEMORY_ADDRESS                                         0
> > -       __le32                  memdata0;
> > -       __le32                  memdata1;
> > -       u32                     _unused3;
> > -       /* offset 0x0050 */
> > -       __le32                  gpioctl;
> > -#define GPIO3_LED_SELECT                                       12
> > -#define GPIO3_INTERRUPT_ENABLE                                 11
> > -#define GPIO2_INTERRUPT_ENABLE                                 10
> > -#define GPIO1_INTERRUPT_ENABLE                                 9
> > -#define GPIO0_INTERRUPT_ENABLE                                 8
> > -#define GPIO3_OUTPUT_ENABLE                                    7
> > -#define GPIO2_OUTPUT_ENABLE                                    6
> > -#define GPIO1_OUTPUT_ENABLE                                    5
> > -#define GPIO0_OUTPUT_ENABLE                                    4
> > -#define GPIO3_DATA                                             3
> > -#define GPIO2_DATA                                             2
> > -#define GPIO1_DATA                                             1
> > -#define GPIO0_DATA                                             0
> > -       __le32                  gpiostat;
> > -#define GPIO3_INTERRUPT                                                3
> > -#define GPIO2_INTERRUPT                                                2
> > -#define GPIO1_INTERRUPT                                                1
> > -#define GPIO0_INTERRUPT                                                0
> > -} __packed;
> > -
> > -/* usb control, BAR0 + 0x0080 */
> > -struct net2280_usb_regs {
> > -       /* offset 0x0080 */
> > -       __le32                  stdrsp;
> > -#define STALL_UNSUPPORTED_REQUESTS                             31
> > -#define SET_TEST_MODE                                          16
> > -#define GET_OTHER_SPEED_CONFIGURATION                          15
> > -#define GET_DEVICE_QUALIFIER                                   14
> > -#define SET_ADDRESS                                            13
> > -#define ENDPOINT_SET_CLEAR_HALT                                        12
> > -#define DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP                  11
> > -#define GET_STRING_DESCRIPTOR_2                                        10
> > -#define GET_STRING_DESCRIPTOR_1                                        9
> > -#define GET_STRING_DESCRIPTOR_0                                        8
> > -#define GET_SET_INTERFACE                                      6
> > -#define GET_SET_CONFIGURATION                                  5
> > -#define GET_CONFIGURATION_DESCRIPTOR                           4
> > -#define GET_DEVICE_DESCRIPTOR                                  3
> > -#define GET_ENDPOINT_STATUS                                    2
> > -#define GET_INTERFACE_STATUS                                   1
> > -#define GET_DEVICE_STATUS                                      0
> > -       __le32                  prodvendid;
> > -#define     PRODUCT_ID                                         16
> > -#define     VENDOR_ID                                          0
> > -       __le32                  relnum;
> > -       __le32                  usbctl;
> > -#define SERIAL_NUMBER_INDEX                                    16
> > -#define PRODUCT_ID_STRING_ENABLE                               13
> > -#define VENDOR_ID_STRING_ENABLE                                        12
> > -#define USB_ROOT_PORT_WAKEUP_ENABLE                            11
> > -#define VBUS_PIN                                               10
> > -#define TIMED_DISCONNECT                                       9
> > -#define SUSPEND_IMMEDIATELY                                    7
> > -#define SELF_POWERED_USB_DEVICE                                        6
> > -#define REMOTE_WAKEUP_SUPPORT                                  5
> > -#define PME_POLARITY                                           4
> > -#define USB_DETECT_ENABLE                                      3
> > -#define PME_WAKEUP_ENABLE                                      2
> > -#define DEVICE_REMOTE_WAKEUP_ENABLE                            1
> > -#define SELF_POWERED_STATUS                                    0
> > -       /* offset 0x0090 */
> > -       __le32                  usbstat;
> > -#define HIGH_SPEED                                             7
> > -#define FULL_SPEED                                             6
> > -#define GENERATE_RESUME                                                5
> > -#define GENERATE_DEVICE_REMOTE_WAKEUP                          4
> > -       __le32                  xcvrdiag;
> > -#define FORCE_HIGH_SPEED_MODE                                  31
> > -#define FORCE_FULL_SPEED_MODE                                  30
> > -#define USB_TEST_MODE                                          24
> > -#define LINE_STATE                                             16
> > -#define TRANSCEIVER_OPERATION_MODE                             2
> > -#define TRANSCEIVER_SELECT                                     1
> > -#define TERMINATION_SELECT                                     0
> > -       __le32                  setup0123;
> > -       __le32                  setup4567;
> > -       /* offset 0x0090 */
> > -       u32                     _unused0;
> > -       __le32                  ouraddr;
> > -#define FORCE_IMMEDIATE                                                7
> > -#define OUR_USB_ADDRESS                                                0
> > -       __le32                  ourconfig;
> > -} __packed;
> > -
> > -/* pci control, BAR0 + 0x0100 */
> > -struct net2280_pci_regs {
> > -       /* offset 0x0100 */
> > -       __le32                  pcimstctl;
> > -#define PCI_ARBITER_PARK_SELECT                                        13
> > -#define PCI_MULTI LEVEL_ARBITER                                        12
> > -#define PCI_RETRY_ABORT_ENABLE                                 11
> > -#define DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE                 10
> > -#define DMA_READ_MULTIPLE_ENABLE                               9
> > -#define DMA_READ_LINE_ENABLE                                   8
> > -#define PCI_MASTER_COMMAND_SELECT                              6
> > -#define                MEM_READ_OR_WRITE                               0
> > -#define                IO_READ_OR_WRITE                                1
> > -#define                CFG_READ_OR_WRITE                               2
> > -#define PCI_MASTER_START                                       5
> > -#define PCI_MASTER_READ_WRITE                                  4
> > -#define                PCI_MASTER_WRITE                                0
> > -#define                PCI_MASTER_READ                                 1
> > -#define PCI_MASTER_BYTE_WRITE_ENABLES                          0
> > -       __le32                  pcimstaddr;
> > -       __le32                  pcimstdata;
> > -       __le32                  pcimststat;
> > -#define PCI_ARBITER_CLEAR                                      2
> > -#define PCI_EXTERNAL_ARBITER                                   1
> > -#define PCI_HOST_MODE                                          0
> > -} __packed;
> > -
> > -/* dma control, BAR0 + 0x0180 ... array of four structs like this,
> > - * for channels 0..3.  see also struct net2280_dma:  descriptor
> > - * that can be loaded into some of these registers.
> > - */
> > -struct net2280_dma_regs {      /* [11.7] */
> > -       /* offset 0x0180, 0x01a0, 0x01c0, 0x01e0, */
> > -       __le32                  dmactl;
> > -#define DMA_SCATTER_GATHER_DONE_INTERRUPT_ENABLE               25
> > -#define DMA_CLEAR_COUNT_ENABLE                                 21
> > -#define DESCRIPTOR_POLLING_RATE                                        19
> > -#define                POLL_CONTINUOUS                                 0
> > -#define                POLL_1_USEC                                     1
> > -#define                POLL_100_USEC                                   2
> > -#define                POLL_1_MSEC                                     3
> > -#define DMA_VALID_BIT_POLLING_ENABLE                           18
> > -#define DMA_VALID_BIT_ENABLE                                   17
> > -#define DMA_SCATTER_GATHER_ENABLE                              16
> > -#define DMA_OUT_AUTO_START_ENABLE                              4
> > -#define DMA_PREEMPT_ENABLE                                     3
> > -#define DMA_FIFO_VALIDATE                                      2
> > -#define DMA_ENABLE                                             1
> > -#define DMA_ADDRESS_HOLD                                       0
> > -       __le32                  dmastat;
> > -#define DMA_SCATTER_GATHER_DONE_INTERRUPT                      25
> > -#define DMA_TRANSACTION_DONE_INTERRUPT                         24
> > -#define DMA_ABORT                                              1
> > -#define DMA_START                                              0
> > -       u32                     _unused0[2];
> > -       /* offset 0x0190, 0x01b0, 0x01d0, 0x01f0, */
> > -       __le32                  dmacount;
> > -#define VALID_BIT                                              31
> > -#define DMA_DIRECTION                                          30
> > -#define DMA_DONE_INTERRUPT_ENABLE                              29
> > -#define END_OF_CHAIN                                           28
> > -#define DMA_BYTE_COUNT_MASK                                    ((1<<24)-1)
> > -#define DMA_BYTE_COUNT                                         0
> > -       __le32                  dmaaddr;
> > -       __le32                  dmadesc;
> > -       u32                     _unused1;
> > -} __packed;
> > -
> > -/* dedicated endpoint registers, BAR0 + 0x0200 */
> > -
> > -struct net2280_dep_regs {      /* [11.8] */
> > -       /* offset 0x0200, 0x0210, 0x220, 0x230, 0x240 */
> > -       __le32                  dep_cfg;
> > -       /* offset 0x0204, 0x0214, 0x224, 0x234, 0x244 */
> > -       __le32                  dep_rsp;
> > -       u32                     _unused[2];
> > -} __packed;
> > -
> > -/* configurable endpoint registers, BAR0 + 0x0300 ... array of seven structs
> > - * like this, for ep0 then the configurable endpoints A..F
> > - * ep0 reserved for control; E and F have only 64 bytes of fifo
> > - */
> > -struct net2280_ep_regs {       /* [11.9] */
> > -       /* offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0 */
> > -       __le32                  ep_cfg;
> > -#define ENDPOINT_BYTE_COUNT                                    16
> > -#define ENDPOINT_ENABLE                                                10
> > -#define ENDPOINT_TYPE                                          8
> > -#define ENDPOINT_DIRECTION                                     7
> > -#define ENDPOINT_NUMBER                                                0
> > -       __le32                  ep_rsp;
> > -#define SET_NAK_OUT_PACKETS                                    15
> > -#define SET_EP_HIDE_STATUS_PHASE                               14
> > -#define SET_EP_FORCE_CRC_ERROR                                 13
> > -#define SET_INTERRUPT_MODE                                     12
> > -#define SET_CONTROL_STATUS_PHASE_HANDSHAKE                     11
> > -#define SET_NAK_OUT_PACKETS_MODE                               10
> > -#define SET_ENDPOINT_TOGGLE                                    9
> > -#define SET_ENDPOINT_HALT                                      8
> > -#define CLEAR_NAK_OUT_PACKETS                                  7
> > -#define CLEAR_EP_HIDE_STATUS_PHASE                             6
> > -#define CLEAR_EP_FORCE_CRC_ERROR                               5
> > -#define CLEAR_INTERRUPT_MODE                                   4
> > -#define CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE                   3
> > -#define CLEAR_NAK_OUT_PACKETS_MODE                             2
> > -#define CLEAR_ENDPOINT_TOGGLE                                  1
> > -#define CLEAR_ENDPOINT_HALT                                    0
> > -       __le32                  ep_irqenb;
> > -#define SHORT_PACKET_OUT_DONE_INTERRUPT_ENABLE                 6
> > -#define SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE              5
> > -#define DATA_PACKET_RECEIVED_INTERRUPT_ENABLE                  3
> > -#define DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE               2
> > -#define DATA_OUT_PING_TOKEN_INTERRUPT_ENABLE                   1
> > -#define DATA_IN_TOKEN_INTERRUPT_ENABLE                         0
> > -       __le32                  ep_stat;
> > -#define FIFO_VALID_COUNT                                       24
> > -#define HIGH_BANDWIDTH_OUT_TRANSACTION_PID                     22
> > -#define TIMEOUT                                                        21
> > -#define USB_STALL_SENT                                         20
> > -#define USB_IN_NAK_SENT                                                19
> > -#define USB_IN_ACK_RCVD                                                18
> > -#define USB_OUT_PING_NAK_SENT                                  17
> > -#define USB_OUT_ACK_SENT                                       16
> > -#define FIFO_OVERFLOW                                          13
> > -#define FIFO_UNDERFLOW                                         12
> > -#define FIFO_FULL                                              11
> > -#define FIFO_EMPTY                                             10
> > -#define FIFO_FLUSH                                             9
> > -#define SHORT_PACKET_OUT_DONE_INTERRUPT                                6
> > -#define SHORT_PACKET_TRANSFERRED_INTERRUPT                     5
> > -#define NAK_OUT_PACKETS                                                4
> > -#define DATA_PACKET_RECEIVED_INTERRUPT                         3
> > -#define DATA_PACKET_TRANSMITTED_INTERRUPT                      2
> > -#define DATA_OUT_PING_TOKEN_INTERRUPT                          1
> > -#define DATA_IN_TOKEN_INTERRUPT                                        0
> > -       /* offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0 */
> > -       __le32                  ep_avail;
> > -       __le32                  ep_data;
> > -       u32                     _unused0[2];
> > -} __packed;
> > -
> > -struct net2280_reg_write {
> > -       __le16 port;
> > -       __le32 addr;
> > -       __le32 val;
> > -} __packed;
> > -
> > -struct net2280_reg_read {
> > -       __le16 port;
> > -       __le32 addr;
> > -} __packed;
> > -#endif /* NET2280_H */
> > diff --git a/drivers/net/wireless/p54/p54usb.h b/drivers/net/wireless/p54/p54usb.h
> > index d273be7..a5f5f0f 100644
> > --- a/drivers/net/wireless/p54/p54usb.h
> > +++ b/drivers/net/wireless/p54/p54usb.h
> > @@ -16,7 +16,7 @@
> >
> >  /* for isl3886 register definitions used on ver 1 devices */
> >  #include "p54pci.h"
> > -#include "net2280.h"
> > +#include <linux/usb/net2280.h>
> >
> >  /* pci */
> >  #define NET2280_BASE           0x10000000
> > @@ -93,6 +93,17 @@ enum net2280_op_type {
> >         NET2280_DEV_CFG_U16     = 0x0883
> >  };
> >
> > +struct net2280_reg_write {
> > +       __le16 port;
> > +       __le32 addr;
> > +       __le32 val;
> > +} __packed;
> > +
> > +struct net2280_reg_read {
> > +       __le16 port;
> > +       __le32 addr;
> > +} __packed;
> > +
> >  #define P54U_FW_BLOCK 2048
> >
> >  #define X2_SIGNATURE "x2  "
> > --
> > 2.1.3
> >
> 
> 
> 
> -- 
> Ricardo Ribalda
> 

-- 
John W. Linville		Someday the world will need a hero, and you
linville@tuxdriver.com			might be all we have.  Be ready.

^ permalink raw reply

* RE: [PATCH v2] Add support of Cavium Liquidio ethernet adapters
From: Vatsavayi, Raghu @ 2014-12-01 19:57 UTC (permalink / raw)
  To: David Miller, f.fainelli@gmail.com
  Cc: netdev@vger.kernel.org, Chickles, Derek, Burla, Satananda,
	Manlunas, Felix
In-Reply-To: <20141124.160837.1008717214755094566.davem@davemloft.net>


> -----Original Message-----
> From: David Miller [mailto:davem@davemloft.net]
> Sent: Monday, November 24, 2014 1:09 PM
> To: f.fainelli@gmail.com
> Cc: Vatsavayi, Raghu; netdev@vger.kernel.org; Chickles, Derek; Burla,
> Satananda; Manlunas, Felix; Vatsavayi, Raghu
> Subject: Re: [PATCH v2] Add support of Cavium Liquidio ethernet adapters
> 
> From: Florian Fainelli <f.fainelli@gmail.com>
> Date: Mon, 24 Nov 2014 13:01:06 -0800
> 
> > On 11/23/2014 07:19 PM, Raghu Vatsavayi wrote:
> >> +if LIQUIDIO
> >> +
> >> +config LIQUIDIO_NAPI
> >> +	bool "Enable NAPI for LiquidIO"
> >> +	default y
> >> +	---help---
> >> +	  NAPI is a new driver API designed to reduce CPU and interrupt load
> >> +	  when the driver is receiving lots of packets from the card. You
> >> +	  would only disable this feature in very specific instances, like
> >> +	  an application that very rapidly sets up and tears down connections.
> >> +
> >> +	  If in doubt, say Y.
> >
> > You probably do not want to offer a non-NAPI variant, pretty much all
> > drivers have NAPI built-in now.
> 
> +1.
> 
> >> +config LIQUIDIO_DEBUG
> >> +	int "Debug level for LiquidIO"
> >> +	range 0 4
> >> +	default 0
> >
> > This should be moved to dynamic_debug/ethtools' msglvl control knob.
> 
> +1

Thanks for the comments. We are in the process of removing Kconfig based non-NAPI
selection and enabling NAPI by default. We are also removing  separate debug section
and integrating it with ethtool based msglvl debug infrastructure. Additionally we are
planning to clean up non-kerneldoc style comments.

Regards
Raghu

^ permalink raw reply

* RE: [linux-nics] [PATCH] e1000: remove unused variables
From: Fujinaka, Todd @ 2014-12-01 18:56 UTC (permalink / raw)
  To: Sudip Mukherjee, Ben Hutchings
  Cc: Linux NICS, e1000-devel@lists.sourceforge.net, Hisashi T Fujinaka,
	Vick, Matthew, Greg@isotope.jf.intel.com, Kirsher, Jeffrey T,
	netdev@vger.kernel.org, Wyborny, Carolyn,
	John@isotope.jf.intel.com, linux-kernel@vger.kernel.org
In-Reply-To: <20141201045446.GA3277@sudip-PC>

After discussing this locally, I'd like to NAK it because this could cause regressions to parts that are still in use but we don't have access to. Also, the assignment was necessary in the past for some versions of gcc and since this may be used in embedded systems using older compilers, we should leave it be.

Thanks.

Todd Fujinaka
Software Application Engineer
Networking Division (ND)
Intel Corporation
todd.fujinaka@intel.com
(503) 712-4565

-----Original Message-----
From: linux-nics-bounces@isotope.jf.intel.com [mailto:linux-nics-bounces@isotope.jf.intel.com] On Behalf Of Sudip Mukherjee
Sent: Sunday, November 30, 2014 8:55 PM
To: Ben Hutchings
Cc: Linux NICS; e1000-devel@lists.sourceforge.net; Hisashi T Fujinaka; Vick, Matthew; Greg@isotope.jf.intel.com; Kirsher, Jeffrey T; netdev@vger.kernel.org; Wyborny, Carolyn; John@isotope.jf.intel.com; linux-kernel@vger.kernel.org
Subject: Re: [linux-nics] [PATCH] e1000: remove unused variables

On Sun, Nov 30, 2014 at 01:45:13AM +0000, Ben Hutchings wrote:
> On Wed, 2014-11-26 at 21:59 -0800, Hisashi T Fujinaka wrote:
> > I'm pretty sure those double reads are there for a reason, so most 
> > of this I'm going to have to check on Monday. We have a long holiday 
> > weekend here in the US.
> [...]
> 
> If there were double register reads being replaced with single 
> register reads, I'd agree this was likely to introduce a regression.  
> But all I see is var = er32(REG) being changed to er32(REG).

no, double register reads are not modified. only the unused variables are removed.

thanks
sudip

> 
> Ben.
> 
> --
> Ben Hutchings
> The world is coming to an end.	Please log off.


_______________________________________________
Linux-nics mailing list
Linux-nics@intel.com

^ permalink raw reply

* Re: [PATCH net-next] test: bpf: expand DIV_KX to DIV_MOD_KX
From: Alexei Starovoitov @ 2014-12-01 17:44 UTC (permalink / raw)
  To: Denis Kirjanov, Daniel Borkmann; +Cc: Network Development

On Mon, Dec 1, 2014 at 2:12 AM, Denis Kirjanov <kda@linux-powerpc.org> wrote:
> Expand DIV_KX to use BPF_MOD operation in the
> DIV_KX bpf 'classic' test.
>
> CC: Alexei Starovoitov <ast@plumgrid.com>
> Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>

Increases test coverage. Makes sense. Thanks
Acked-by: Alexei Starovoitov <ast@plumgrid.com>

> ---
>  lib/test_bpf.c |   10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index 3f167d2..80d78c5 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -124,7 +124,7 @@ static struct bpf_test tests[] = {
>                 { { 0, 0xfffffffd } }
>         },
>         {
> -               "DIV_KX",
> +               "DIV_MOD_KX",
>                 .u.insns = {
>                         BPF_STMT(BPF_LD | BPF_IMM, 8),
>                         BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
> @@ -134,12 +134,18 @@ static struct bpf_test tests[] = {
>                         BPF_STMT(BPF_MISC | BPF_TAX, 0),
>                         BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
>                         BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
> +                       BPF_STMT(BPF_MISC | BPF_TAX, 0),
> +                       BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
> +                       BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
> +                       BPF_STMT(BPF_MISC | BPF_TAX, 0),
> +                       BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
> +                       BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
>                         BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
>                         BPF_STMT(BPF_RET | BPF_A, 0)
>                 },
>                 CLASSIC | FLAG_NO_DATA,
>                 { },
> -               { { 0, 0x40000001 } }
> +               { { 0, 0x20000000 } }
>         },
>         {
>                 "AND_OR_LSH_K",
> --
> 1.7.10.4
>

^ permalink raw reply

* Re: [PATCH 1/3] net-PPP: Deletion of unnecessary checks before the function call "kfree"
From: Sergei Shtylyov @ 2014-12-01 17:11 UTC (permalink / raw)
  To: SF Markus Elfring, Paul Mackerras, linux-ppp, netdev
  Cc: LKML, kernel-janitors, Julia Lawall
In-Reply-To: <547C82A6.2030808@users.sourceforge.net>

On 12/01/2014 06:00 PM, SF Markus Elfring wrote:

>>> diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
>>> index 911b216..7e44212 100644
>>> --- a/drivers/net/ppp/ppp_mppe.c
>>> +++ b/drivers/net/ppp/ppp_mppe.c
>>> @@ -238,8 +238,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
>>>        return (void *)state;
>>>
>>>        out_free:
>>> -        if (state->sha1_digest)
>>> -        kfree(state->sha1_digest);
>>> +    kfree(state->sha1_digest);

>>     Please keep this line aligned to the others.

> Can it be that the previous source code contained unwanted space
> characters at this place?

    Yes, it seems so.

> Do you want indentation fixes as a separate update step?

    Yes, that would be better to keep it separate.

> Regards,
> Markus

WBR, Sergei

^ permalink raw reply

* Re: Is this 32-bit NCM?
From: Enrico Mioso @ 2014-12-01 16:54 UTC (permalink / raw)
  To: Kevin Zhu
  Cc: Alex Strizhevsky, Bjørn Mork, Midge Shaojun Tan,
	youtux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Eli Britstein
In-Reply-To: <54783F18.1070709-6C2+4RG2qWF0ubjbjo6WXg@public.gmane.org>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2181 bytes --]

Evne to thank you for giving me a test device / shell, I am now modifying 
thedriver to be extra debug-ful. I don't know where exactly this will lead if 
anywhere, and really have no clue of whatto do next, since all seems normal. 
But at least I'll have a clue of what happens.


On Fri, 28 Nov 2014, Kevin Zhu wrote:

==Date: Fri, 28 Nov 2014 10:23:43
==From: Kevin Zhu <Mingying.Zhu-6C2+4RG2qWF0ubjbjo6WXg@public.gmane.org>
==To: Enrico Mioso <mrkiko.rs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
==Cc: Alex Strizhevsky <alexxst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>, Bjørn Mork <bjorn-yOkvZcmFvRU@public.gmane.org>,
==    Midge Shaojun  Tan <ShaojunMidge.Tan-6C2+4RG2qWF0ubjbjo6WXg@public.gmane.org>,
==    "youtux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <youtux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
==    "linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" <linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
==    "netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" <netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
==    Eli Britstein <Eli.Britstein-6C2+4RG2qWF0ubjbjo6WXg@public.gmane.org>
==Subject: Re: Is this 32-bit NCM?
==
==Yes. The MACs are right. When I started Wireshark, promisc mode was set.
==
==Regards,
==Kevin
==
==On 11/28/2014 05:17 PM, Enrico Mioso wrote:
==> Sorry - resending message to all.
==> Is the MAC right? In my case it was, but ... you never know.
==> And - have you tried the promisc mode, just in case... don't know if this might
==> even be implementedi n the driver, think not, but...
==> I don't know what to think anymore.
==> this ARP packet seems the same as with windows... but might be it's only my
==> impression.
==This email and any files transmitted with it are confidential material. They are intended solely for the use of the designated individual or entity to whom they are addressed. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, use, distribution or copying of this communication is strictly prohibited and may be unlawful.
==
==If you have received this email in error please immediately notify the sender and delete or destroy any copy of this message
==

^ permalink raw reply

* Re: [bisected] xfrm: TCP connection initiating PMTU discovery stalls on v3.12+
From: Wolfgang Walter @ 2014-12-01 16:41 UTC (permalink / raw)
  To: Thomas Jarosch; +Cc: netdev, Eric Dumazet
In-Reply-To: <2335530.7OPnEQXbmV@h2o.as.studentenwerk.mhn.de>

Am Montag, 1. Dezember 2014, 14:17:28 schrieb Wolfgang Walter:
> Am Samstag, 29. November 2014, 12:44:07 schrieb Thomas Jarosch:
> > Hello,
> > 
> > we're in the process of updating production level machines
> > from kernel 3.4.101 to kernel 3.14.25. On one mail server
> > we noticed that emails destined for an IPSec tunnel sometimes
> > get stuck in the mail queue with TCP timeouts.
> > 
> > To make a long story short: When the VPN connection is initially
> > set up or re-newed, the path MTU for the xfrm tunnel is undetermined.
> > 
> > As soon as a TCP client starts to send large packets,
> > it triggers path MTU detection. Some middlebox on the
> > way to the final server has a lower MTU and sends back
> > an "ICMP fragmentation needed" packet as normal.
> > 
> > With the old kernel, the packet size for the TCP connection inside
> > the xfrm tunnel gets adjusted and all is fine. With kernel v3.12+,
> > the connection stalls completely. Same thing with kernel v3.18-rc6.
> 
> We see something similar with real nic (RTL8139). In our case only the first
> tcp-connection which triggers PMTU stalls. Later tcp-connections then work
> fine.
> 
> I will revert that patch and see if that fixes the problem.


Reverting the commit fixes the problem here, too.


> 
> > We wrote a small tool to mimic postfix's TCP behavior (see attached file).
> > In the end it's a normal TCP client sending large packets.
> > The server side is just "socat - tcp4-listen:667".
> > 
> > If you run "socket_client" a second time, the path MTU
> > for the xfrm tunnel is already known and packets flow normal, too.
> > 
> > 
> > The "evil" commit in question is this one:
> > ---------------------------------------------------------------------
> > commit 8f26fb1c1ed81c33f5d87c5936f4d9d1b4118918
> > Author: Eric Dumazet <edumazet@google.com>
> > Date:   Tue Oct 15 12:24:54 2013 -0700
> > 
> >     tcp: remove the sk_can_gso() check from tcp_set_skb_tso_segs()
> >     
> >     sk_can_gso() should only be used as a hint in tcp_sendmsg() to build
> >     GSO
> > 
> > packets in the first place. (As a performance hint)
> > 
> >     Once we have GSO packets in write queue, we can not decide they are no
> >     longer GSO only because flow now uses a route which doesn't handle
> >     TSO/GSO.
> >     
> >     Core networking stack handles the case very well for us, all we need
> >     is keeping track of packet counts in MSS terms, regardless of
> >     segmentation done later (in GSO or hardware)
> >     
> >     Right now, if  tcp_fragment() splits a GSO packet in two parts,
> >     @left and @right, and route changed through a non GSO device,
> >     both @left and @right have pcount set to 1, which is wrong,
> >     and leads to incorrect packet_count tracking.
> >     
> >     This problem was added in commit d5ac99a648 ("[TCP]: skb pcount with
> >     MTU
> > 
> > discovery")
> > 
> >     Signed-off-by: Eric Dumazet <edumazet@google.com>
> >     Signed-off-by: Neal Cardwell <ncardwell@google.com>
> >     Signed-off-by: Yuchung Cheng <ycheng@google.com>
> >     Reported-by: Maciej Żenczykowski <maze@google.com>
> >     Signed-off-by: David S. Miller <davem@davemloft.net>
> > 
> > diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> > index 8fad1c1..d46f214 100644
> > --- a/net/ipv4/tcp_output.c
> > +++ b/net/ipv4/tcp_output.c
> > @@ -989,8 +989,7 @@ static void tcp_set_skb_tso_segs(const struct sock
> > *sk,
> > struct sk_buff *skb, /* Make sure we own this skb before messing
> > gso_size/gso_segs */ WARN_ON_ONCE(skb_cloned(skb));
> > 
> > -       if (skb->len <= mss_now || !sk_can_gso(sk) ||
> > -           skb->ip_summed == CHECKSUM_NONE) {
> > +       if (skb->len <= mss_now || skb->ip_summed == CHECKSUM_NONE) {
> > 
> >                 /* Avoid the costly divide in the normal
> >                 
> >                  * non-TSO case.
> >                  */
> > 
> > ---------------------------------------------------------------------
> > 
> > When I revert it, even kernel v3.18-rc6 starts working.
> > But I doubt this is the root problem, may be just hiding another issue.
> > 
> > --- Sample output of socket_client using vanilla v3.12 kernel ---
> > [1417258063 SEND result: 4096, strerror: Success]
> > tcp max seg: res: 0, max_seg: 1370
> > [1417258063 SEND result: 4096, strerror: Success]
> > tcp max seg: res: 0, max_seg: 1370
> > [1417258063 SEND result: 4096, strerror: Success]
> > tcp max seg: res: 0, max_seg: 1370
> > [1417258063 SEND result: 4096, strerror: Success]
> > tcp max seg: res: 0, max_seg: 1370
> > [1417258063 SEND result: 4096, strerror: Success]
> > tcp max seg: res: 0, max_seg: 1338
> > [1417258063 SEND result: 4096, strerror: Success]
> > tcp max seg: res: 0, max_seg: 1338
> > *STUCK*
> > --------------------------------------------------------
> > 
> > The "machine" is running on KVM and using "virtio_net" as NIC driver.
> > I've played with the ethtool offload settings:
> > 
> > *** eth1 defaults ***
> > Offload parameters for eth1:
> > rx-checksumming: on
> > tx-checksumming: on
> > scatter-gather: on
> > tcp-segmentation-offload: on
> > udp-fragmentation-offload: on
> > generic-segmentation-offload: on
> > generic-receive-offload: on
> > large-receive-offload: off
> > 
> > *** eth1 working (no stalls) using vanilla kernel ***
> > Offload parameters for eth1:
> > rx-checksumming: on
> > tx-checksumming: off  <-- the magic switch
> > scatter-gather: off
> > tcp-segmentation-offload: off
> > udp-fragmentation-offload: off
> > generic-segmentation-offload: off
> > generic-receive-offload: off
> > large-receive-offload: off
> > 
> > When I turn "tx-checksumming" back on, it fails again.
> > Though that is probably also just a side effect.
> > 
> > I can provide tcpdumps if needed but they are no real help
> > since you can just see the kernel stops sending TCP packets.
> > (and the outgoing TCP packets are encrypted in ESP packets)
> > 
> > 
> > Any vague idea what might be the root cause?
> > 
> > I also tried reverting commit 4d53eff48b5f03ce67f4f301d6acca1d2145cb7a
> > ("xfrm: Don't queue retransmitted packets if the original is still on the
> > host") but that didn't change the situation. In fact it wasn't even
> > triggered.
> > 
> > Please CC: comments. Thanks.
> > 
> > Best regards,
> > Thomas
> 
> Regards,

Regards,
-- 
Wolfgang Walter
Studentenwerk München
Anstalt des öffentlichen Rechts

^ permalink raw reply

* Re: [PATCH v2 02/19] kbuild: kselftest_install - add a new make target to install selftests
From: Shuah Khan @ 2014-12-01 16:39 UTC (permalink / raw)
  To: Michal Marek, gregkh, akpm, davem, keescook, tranmanphong,
	dh.herrmann, hughd, bobby.prani, ebiederm, serge.hallyn
  Cc: linux-kbuild, linux-kernel, linux-api, netdev,
	masami.hiramatsu.pt@hitachi.com >> Masami Hiramatsu,
	Shuah Khan
In-Reply-To: <547C8D81.1030605@suse.cz>

On 12/01/2014 08:47 AM, Michal Marek wrote:
> On 2014-11-11 21:27, Shuah Khan wrote:
>> Add a new make target to install to install kernel selftests.
>> This new target will build and install selftests. kselftest
>> target now depends on kselftest_install and runs the generated
>> kselftest script to reduce duplicate work and for common look
>> and feel when running tests.
>>
>> Approach:
>>
>> make kselftest_target:
>> -- exports kselftest INSTALL_KSFT_PATH
>>    default $(INSTALL_MOD_PATH)/lib/kselftest/$(KERNELRELEASE)
>> -- exports path for ksefltest.sh
>> -- runs selftests make install target:
>>
>> selftests make install target
>> -- creates kselftest.sh script in install install dir
>> -- runs install targets for all INSTALL_TARGETS
>>    (Note: ftrace and powerpc aren't included in INSTALL_TARGETS,
>>           to not add more content to patch v1 series. This work
>>           will happen soon. In this series these two targets are
>>           run after running the generated kselftest script, without
>>           any regression in the way these tests are run with
>>           "make kselftest" prior to this work.)
>> -- install target can be run only from top level source dir.
>>
>> Individual test make install targets:
>> -- install test programs and/or scripts in install dir
>> -- append to the ksefltest.sh file to add commands to run test
>> -- install target can be run only from top level source dir.
>>
>> Adds the following new ways to initiate selftests:
>> -- Installing and running kselftest from install directory
>>    by running  "make kselftest"
>> -- Running kselftest script from install directory
>>
>> Maintains the following ways to run tests:
>> -- make -C tools/testing/selftests run_tests
>> -- make -C tools/testing/selftests TARGETS=target run_tests
>>    Ability specify targets: e.g TARGETS=net
>> -- make run_tests from tools/testing/selftests
>> -- make run_tests from individual test directories:
>>    e.g: make run_tests in tools/testing/selftests/breakpoints
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  Makefile | 21 +++++++++++++++++++--
>>  1 file changed, 19 insertions(+), 2 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 05d67af..ccbd2e1 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -1071,12 +1071,26 @@ headers_check: headers_install
>>  	$(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/uapi/asm $(hdr-dst) HDRCHECK=1
>>  
>>  # ---------------------------------------------------------------------------
>> -# Kernel selftest
>> +# Kernel selftest targets
>> +
>> +PHONY += __kselftest_configure
>> +INSTALL_KSFT_PATH=$(INSTALL_MOD_PATH)/lib/kselftest/$(KERNELRELEASE)
>> +export INSTALL_KSFT_PATH
>> +KSELFTEST=$(INSTALL_KSFT_PATH)/kselftest.sh
>> +export KSELFTEST
> 
> Can this be moved to tools/testing/selftests/Makefile? It's only used in
> this part of the tree.

I looked into doing that. KERNELRELEASE will have to be exported for
tools/testing/selftests/Makefile to use it? Does that sound okay?

> 
> 
>>  PHONY += kselftest
>> -kselftest:
>> +kselftest: kselftest_install
>>  	$(Q)$(MAKE) -C tools/testing/selftests run_tests
>>  
>> +# Kernel selftest install
>> +
>> +PHONY += kselftest_install
>> +kselftest_install: __kselftest_configure
>> +	@rm -rf $(INSTALL_KSFT_PATH)
>> +	@mkdir -p $(INSTALL_KSFT_PATH)
> 
> Please use $(Q) insteaf od hardcoding the @.

I can do that.

> 
> 
>> +	$(Q)$(MAKE) -C tools/testing/selftests install
> 
> The install target is only added by the next patch, which in turn
> depends on changes done by later patches. The order (in the current
> numbering) should be 01/19, 04/19, ... 19/19, 03/19 and 02/19.
> 

Right. I can re-order the patches in my next version and make other
changes you recommended.

Also, it might be easier to get this series in, if you can Ack the main
Makefile patch (when we are ready i.e), so I can take it through
kselftest tree.

thanks,
-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply

* Re: [PATCH v2 02/19] kbuild: kselftest_install - add a new make target to install selftests
From: Shuah Khan @ 2014-12-01 16:27 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: gregkh, akpm, mmarek, davem, keescook, tranmanphong, dh.herrmann,
	hughd, bobby.prani, ebiederm, serge.hallyn, linux-kbuild,
	linux-kernel, linux-api, netdev, Shuah Khan
In-Reply-To: <5476B763.1030701@hitachi.com>

On 11/26/2014 10:32 PM, Masami Hiramatsu wrote:
> (2014/11/12 5:27), Shuah Khan wrote:
>> Add a new make target to install to install kernel selftests.
>> This new target will build and install selftests. kselftest
>> target now depends on kselftest_install and runs the generated
>> kselftest script to reduce duplicate work and for common look
>> and feel when running tests.
>>
>> Approach:
>>
>> make kselftest_target:
> 
> kselftest_install?

Thanks for catching this. Will fix it.

> 
>> -- exports kselftest INSTALL_KSFT_PATH
>>    default $(INSTALL_MOD_PATH)/lib/kselftest/$(KERNELRELEASE)
>> -- exports path for ksefltest.sh
>> -- runs selftests make install target:
> 
> This direction is OK to me.
> 
> BTW, I've found another path to make selftest in Makefile,
> Actually you can do
> 
> make -C tools/ selftest
> 
> And there are selftest_install and selftest_clean targets (but
> currently it has a bug and doesn't work, anyway)

Thanks for pointing this out. I didn't know this existed. kind of
hidden.

> 
> I think we'd better do subdir make instead of adding these targets.
> This means that "make kselftest*" should be an alias of "make -C tools/ selftest*"
> 

Yes that would be a good way to go and helps leverage these options
at tools/Makefile level.

> Also, I'd like to request passing some options like as O=$(objtree)
> so that we can make test kmodules in selftests.

Sounds good. I will look into it.

thanks,
-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply

* Re: [PATCH v2 03/19] selftests: add install target to enable installing selftests
From: Shuah Khan @ 2014-12-01 16:16 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: gregkh, akpm, mmarek, davem, keescook, tranmanphong, dh.herrmann,
	hughd, bobby.prani, ebiederm, serge.hallyn, linux-kbuild,
	linux-kernel, linux-api, netdev, yrl.pp-manager.tt@hitachi.com,
	Shuah Khan
In-Reply-To: <5476BA67.6020305@hitachi.com>

On 11/26/2014 10:45 PM, Masami Hiramatsu wrote:
> (2014/11/12 5:27), Shuah Khan wrote:
>> Add a new make target to enable installing selftests. This
>> new target will call install targets for the tests that are
>> specified in INSTALL_TARGETS. During install, a script is
>> generated to run tests that are installed. This script will
>> be installed in the selftest install directory. Individual
>> test Makefiles are changed to add to the script. This will
>> allow new tests to add install and run test commands to the
>> generated kselftest script. run_tests target runs the
>> generated kselftest script to run tests when it is initiated
>> from from "make kselftest" from top level source directory.
>>
>> Approach:
>>
>> make kselftest_target:
>> -- exports kselftest INSTALL_KSFT_PATH
>>    default $(INSTALL_MOD_PATH)/lib/kselftest/$(KERNELRELEASE)
>> -- exports path for ksefltest.sh
>> -- runs selftests make install target:
>>
>> selftests make install target
>> -- creates kselftest.sh script in install install dir
>> -- runs install targets for all INSTALL_TARGETS
>>    (Note: ftrace and powerpc aren't included in INSTALL_TARGETS,
>>           to not add more content to patch v1 series. This work
>>           will happen soon. In this series these two targets are
>>           run after running the generated kselftest script, without
>>           any regression in the way these tests are run with
>>           "make kselftest" prior to this work.)
>> -- install target can be run only from top level source dir.
>>
>> Individual test make install targets:
>> -- install test programs and/or scripts in install dir
>> -- append to the ksefltest.sh file to add commands to run test
>> -- install target can be run only from top level source dir.
>>
>> Adds the following new ways to initiate selftests:
>> -- Installing and running kselftest from install directory
>>    by running  "make kselftest"
>> -- Running kselftest script from install directory
>>
>> Maintains the following ways to run tests:
>> -- make -C tools/testing/selftests run_tests
>> -- make -C tools/testing/selftests TARGETS=target run_tests
>>    Ability specify targets: e.g TARGETS=net
>> -- make run_tests from tools/testing/selftests
>> -- make run_tests from individual test directories:
>>    e.g: make run_tests in tools/testing/selftests/breakpoints
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  tools/testing/selftests/Makefile | 31 ++++++++++++++++++++++++++++++-
>>  1 file changed, 30 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>> index 45f145c..b9bdc1d 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -16,6 +16,10 @@ TARGETS += sysctl
>>  TARGETS += firmware
>>  TARGETS += ftrace
>>  
>> +INSTALL_TARGETS = breakpoints cpu-hotplug efivarfs firmware ipc
>> +INSTALL_TARGETS += kcmp memfd memory-hotplug mqueue mount net
>> +INSTALL_TARGETS += ptrace sysctl timers user vm
>> +
>>  TARGETS_HOTPLUG = cpu-hotplug
>>  TARGETS_HOTPLUG += memory-hotplug
>>  
> 
> I think KSELFTEST itself should be defined here, since that is not
> a parameter.

I can do that.

> 
>> @@ -24,10 +28,35 @@ all:
>>  		make -C $$TARGET; \
>>  	done;
>>  
>> -run_tests: all
>> +install:
>> +ifdef INSTALL_KSFT_PATH
>> +	make all
>> +	@echo #!/bin/sh\n# Kselftest Run Tests .... >> $(KSELFTEST)
>> +	@echo # This file is generated during kselftest_install >> $(KSELFTEST)
>> +	@echo # Please don't change it !!\n  >> $(KSELFTEST)
>> +	@echo echo ============================== >> $(KSELFTEST)
>> +	for TARGET in $(INSTALL_TARGETS); do \
>> +		echo Installing $$TARGET; \
>> +		make -C $$TARGET install; \
> 
> Please pass O= option and others here.

I will change that.

> 
>> +	done;
>> +	chmod +x $(KSELFTEST)
>> +else
>> +	@echo Run make kselftest_install in top level source directory
>> +endif
>> +
>> +run_tests:
>> +ifdef INSTALL_KSFT_PATH
>> +	@cd $(INSTALL_KSFT_PATH); ./kselftest.sh; cd -
> 
> We'd better use some macro instead of ./kselftest.sh?
> 

I can play with this and see if there is a better way.

thanks,
-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply

* Re: [PATCH v2 11/19] selftests/memory-hotplug: add install target to enable installing test
From: Shuah Khan @ 2014-12-01 16:12 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: gregkh, akpm, mmarek, davem, keescook, tranmanphong, dh.herrmann,
	hughd, bobby.prani, ebiederm, serge.hallyn, linux-kbuild,
	linux-kernel, linux-api, netdev, yrl.pp-manager.tt@hitachi.com,
	Shuah Khan
In-Reply-To: <5476BB87.6010808@hitachi.com>

On 11/26/2014 10:49 PM, Masami Hiramatsu wrote:
> (2014/11/12 5:27), Shuah Khan wrote:
>> Add a new make target to enable installing test. This target
>> installs test in the kselftest install location and add to the
>> kselftest script to run the test. Install target can be run
>> only from top level source dir.
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  tools/testing/selftests/memory-hotplug/Makefile    |  17 +-
>>  .../selftests/memory-hotplug/mem-on-off-test.sh    | 238 +++++++++++++++++++++
>>  .../selftests/memory-hotplug/on-off-test.sh        | 238 ---------------------
>>  3 files changed, 253 insertions(+), 240 deletions(-)
>>  create mode 100644 tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
>>  delete mode 100644 tools/testing/selftests/memory-hotplug/on-off-test.sh
>>
>> diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile
>> index d46b8d4..8921631 100644
>> --- a/tools/testing/selftests/memory-hotplug/Makefile
>> +++ b/tools/testing/selftests/memory-hotplug/Makefile
>> @@ -1,9 +1,22 @@
>> +TEST_STR=/bin/bash ./mem-on-off-test.sh -r 2 || echo memory-hotplug selftests: [FAIL]
>> +
>>  all:
>>  
>> +install:
>> +ifdef INSTALL_KSFT_PATH
>> +	install ./mem-on-off-test.sh $(INSTALL_KSFT_PATH)/mem-on-off-test.sh
>> +	@echo echo Start memory hotplug test .... >> $(KSELFTEST)
>> +	@echo "$(TEST_STR)" >> $(KSELFTEST) >> $(KSELFTEST)
>> +	@echo echo End memory hotplug test .... >> $(KSELFTEST)
>> +	@echo echo ============================== >> $(KSELFTEST)
>> +else
>> +	@echo Run make kselftest_install in top level source directory
>> +endif
> 
> I saw this pattern repeated many times in this series.
> Can we make it a macro and include it instead of repeating this code?
> 

I might be able to move this to the selftest Makfile and use target as the
string. I will play with it and see if I can reduce the duplication further.

thanks,
-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply

* Re: Is this 32-bit NCM?
From: Enrico Mioso @ 2014-12-01 16:11 UTC (permalink / raw)
  To: Kevin Zhu
  Cc: Alex Strizhevsky, Eli Britstein, linux-usb@vger.kernel.org,
	youtux@gmail.com, Midge Shaojun Tan, netdev@vger.kernel.org,
	Bjørn Mork
In-Reply-To: <547C01DF.8030001@audiocodes.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 7775 bytes --]

thank you.
The interesting thing is that, by the way, I am not even able to use the dongle 
via PPP - it is not relevant, but curious.
Ok - at the moment I don't have other ideas.
I am sorry.

On Mon, 1 Dec 2014, Kevin Zhu wrote:

==Date: Mon, 1 Dec 2014 06:51:31
==From: Kevin Zhu <Mingying.Zhu@audiocodes.com>
==To: Enrico Mioso <mrkiko.rs@gmail.com>
==Cc: Alex Strizhevsky <alexxst@gmail.com>,
==    Eli Britstein <Eli.Britstein@audiocodes.com>,
==    "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
==    "youtux@gmail.com" <youtux@gmail.com>,
==    Midge Shaojun  Tan <ShaojunMidge.Tan@audiocodes.com>,
==    "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
==    Bjørn Mork <bjorn@mork.no>
==Subject: Re: Is this 32-bit NCM?
==
==I'm sorry.
==
==According to the wireshark capture, those packets without NCM signature
==are probably some periodical status checking interrupts. And some other
==packets in the same capture do show the NCM signature. Those packets are
==ping packets.
==
==Regarding the offset and alignment definition, the specification says as
==below:
==
==Alignment requirements are met by controlling the location of the
==payload (the data following the Ether-
==net header in each datagram). This alignment is specified by indicating
==a constraint as a divisor and a
==remainder. The agent formatting a given NTB aligns the payload of each
==datagram by inserting padding,
==such that the offset of each datagram satisfies the constraint:
==
==Offset % wNdpInDivisor == wNdpInPayloadRemainder (for IN datagrams)
==Or
==Offset % wNdpOutDivisor == wNdpOutPayloadRemainder (for OUT datagrams)
==
==
==Regards,
==Kevin
==
==On 12/01/2014 01:28 PM, Enrico Mioso wrote:
==> Sorry.
==> I am a visually impaired person - and use a braille display to read your
==> messages; can't have access to files that don't contain ascii-based content.
==> Sorry Kevin.
==>
==> And thank you for everything. Don't worry about the lateness.
==> It was sunday.
==>
==>
==> On Mon, 1 Dec 2014, Kevin Zhu wrote:
==>
==> ==Date: Mon, 1 Dec 2014 04:14:10
==> ==From: Kevin Zhu <Mingying.Zhu@audiocodes.com>
==> ==To: Enrico Mioso <mrkiko.rs@gmail.com>, Alex Strizhevsky <alexxst@gmail.com>
==> ==Cc: Eli Britstein <Eli.Britstein@audiocodes.com>,
==> ==    "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
==> ==    "youtux@gmail.com" <youtux@gmail.com>,
==> ==    Midge Shaojun  Tan <ShaojunMidge.Tan@audiocodes.com>,
==> ==    "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
==> ==    Bjørn Mork <bjorn@mork.no>
==> ==Subject: Re: Is this 32-bit NCM?
==> ==
==> ==Hi Enrico,
==> ==
==> ==I think those packets are some interrupt status. Please check my capture by
==> ==wireshark.
==> ==
==> ==[IMAGE]
==> ==
==> ==And this is a ping packet from window, which indicates it's an NCM packet.
==> ==
==> ==[IMAGE]
==> ==
==> ==Regards,
==> ==Kevin
==> ==On 11/30/2014 06:39 PM, Enrico Mioso wrote:
==> ==
==> ==My impression guys is that this is not cdc_ncm protocol.
==> ==Look how many short packets you can see in there.
==> ==Without any ncm signature.
==> ==right?
==> ==
==> ==
==> ==On Sun, 30 Nov 2014, Alex Strizhevsky wrote:
==> ==
==> ====Date: Sun, 30 Nov 2014 05:22:20
==> ====From: Alex Strizhevsky <alexxst@gmail.com>
==> ====To: Mrkiko Rs <mrkiko.rs@gmail.com>
==> ====Cc: Eli Britstein <Eli.Britstein@audiocodes.com>, linux-usb@vger.kernel.or
==> ==g,
==> ====    "youtux@gmail.com" <youtux@gmail.com>,
==> ====    Midge Shaojun Tan <ShaojunMidge.Tan@audiocodes.com>,
==> ====    "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
==> ====    Kevin Zhu <Mingying.Zhu@audiocodes.com>, Bjørn Mork <bjorn@mork.no>
==> ====Subject: Re: Is this 32-bit NCM?
==> ====
==> ====
==> ====Hi Enrico,
==> ====
==> ====Actually I have two dongles with different firmwares (23.128.00.00.00 &
==> ====21.286.03.01.209).
==> ====Probably have sent to you the USB  capture with the first one.
==> ====
==> ====In fact we have to make work the second one, this dongle has relevant SW.
==> ====
==> ====On Nov 30, 2014 3:13 AM, "Enrico Mioso" <mrkiko.rs@gmail.com> wrote:
==> ====      Hi guys.
==> ====      Sorry for the late our but ... I was trying to figure out
==> ====      something new about
==> ====      this dongle.
==> ====      I also searched for it in my city shops without finding it
==> ====      actually.
==> ====      But then I came back and ... tried to look at some things.
==> ====
==> ====      Alex, Kevin: in the Windows USB captures you sent me (and that I
==> ====      sent on the
==> ====      List), I can notiche something very strange.
==> ====      with a shell on a computer connected to a test device I can see
==> ====      the following:
==> ====      at+gmr
==> ====      21.286.03.01.209
==> ====      OK
==> ====      and so why in the Windows sniff the dongle answers to the same
==> ====      question
==> ====      something like
==> ====      23.128.00.00.00
==> ====      ?
==> ====      Alex - was it the same dongle?
==> ====      Kevin or anyone: can you use putty to interact with the dongle
==> ====      under Windows
==> ====      and type some commands, like:
==> ====      at+gmr
==> ====      and other similar commands?
==> ====      If the dongle reports different firmware versions under Linux
==> ====      and Windows, then
==> ====      guys... we need to figure out the Windows switch message.
==> ====      Overmore - in the device installation sh*t, you can see there is
==> ====      a firmware
==> ====      updater... Why?
==> ====
==> ====      Alex: I used the
==> ====      at^reset
==> ====      command to get the modem back to normal state once; and so it
==> ====      restored the
==> ====      nvram to default or something.
==> ====      If you reconnect it to windows ... i hope it gets re-setup as
==> ====      before.
==> ====      But - nothing harmful to the device, only to it's settings,
==> ====      sorry.
==> ====      I restored the relevant settings and it connects again, but no
==> ====      dhcp. But - be
==> ====      peaceful: other modems out there seems to not get dhcp anyway.
==> ====      this is the state the modem arrives when you buy it, so windows
==> ====      should know
==> ====      Wwhat To Say To The Modem (TM).
==> ====      Another thing - note that:
==> ====      [14170.048693] cdc_ncm 1-2:1.2: GET_MAX_DATAGRAM_SIZE failed
==> ====
==> ====      Any ideas, comments, suggestions are highly appreciated guys.
==> ====      Of any type.
==> ====
==> ====      Bjorn - unfortunately it seems this problem is related to E3727
==> ====      and E3276
==> ====      sticks; they can get IP from DHCP but not go ahead.
==> ====
==> ====
==> ====
==> ==
==> ==
==> ==This email and any files transmitted with it are confidential material. They
==> ==are intended solely for the use of the designated individual or entity to
==> ==whom they are addressed. If the reader of this message is not the intended
==> ==recipient, you are hereby notified that any dissemination, use, distribution
==> ==or copying of this communication is strictly prohibited and may be unlawful.
==> ==
==> ==If you have received this email in error please immediately notify the
==> ==sender and delete or destroy any copy of this message
==> ==
==This email and any files transmitted with it are confidential material. They are intended solely for the use of the designated individual or entity to whom they are addressed. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, use, distribution or copying of this communication is strictly prohibited and may be unlawful.
==
==If you have received this email in error please immediately notify the sender and delete or destroy any copy of this message
==

^ permalink raw reply

* [PATCH v8 50/50] virtio: drop VIRTIO_F_VERSION_1 from drivers
From: Michael S. Tsirkin @ 2014-12-01 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	Rusty Russell, Amit Shah, Arnd Bergmann, Greg Kroah-Hartman,
	James E.J. Bottomley, virtualization, netdev, linux-scsi
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Core activates this bit automatically now,
drop it from drivers that set it explicitly.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/block/virtio_blk.c    | 1 -
 drivers/char/virtio_console.c | 1 -
 drivers/net/virtio_net.c      | 1 -
 drivers/scsi/virtio_scsi.c    | 1 -
 4 files changed, 4 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 1f8b111..1fb9e09 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -836,7 +836,6 @@ static unsigned int features[] = {
 	VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
 	VIRTIO_BLK_F_TOPOLOGY,
 	VIRTIO_BLK_F_MQ,
-	VIRTIO_F_VERSION_1,
 };
 
 static struct virtio_driver virtio_blk = {
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 775c898..6cc832b 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -2130,7 +2130,6 @@ static struct virtio_device_id id_table[] = {
 static unsigned int features[] = {
 	VIRTIO_CONSOLE_F_SIZE,
 	VIRTIO_CONSOLE_F_MULTIPORT,
-	VIRTIO_F_VERSION_1,
 };
 
 static struct virtio_device_id rproc_serial_id_table[] = {
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 9ab3c50..b8bd719 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2004,7 +2004,6 @@ static unsigned int features[] = {
 	VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ,
 	VIRTIO_NET_F_CTRL_MAC_ADDR,
 	VIRTIO_F_ANY_LAYOUT,
-	VIRTIO_F_VERSION_1,
 };
 
 static struct virtio_driver virtio_net_driver = {
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index d9ec806..2308278 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -1085,7 +1085,6 @@ static unsigned int features[] = {
 	VIRTIO_SCSI_F_HOTPLUG,
 	VIRTIO_SCSI_F_CHANGE,
 	VIRTIO_SCSI_F_T10_PI,
-	VIRTIO_F_VERSION_1,
 };
 
 static struct virtio_driver virtio_scsi_driver = {
-- 
MST

^ permalink raw reply related

* [PATCH v8 46/50] af_packet: virtio 1.0 stubs
From: Michael S. Tsirkin @ 2014-12-01 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	Daniel Borkmann, Hannes Frederic Sowa, Eric Dumazet,
	Atzm Watanabe, Tom Herbert, Willem de Bruijn, netdev
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

This merely fixes sparse warnings, without actually
adding support for the new APIs.

Still working out the best way to enable the new
functionality.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 net/packet/af_packet.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 87d20f4..d4a877e 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2444,13 +2444,15 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 			goto out_unlock;
 
 		if ((vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
-		    (vnet_hdr.csum_start + vnet_hdr.csum_offset + 2 >
-		      vnet_hdr.hdr_len))
-			vnet_hdr.hdr_len = vnet_hdr.csum_start +
-						 vnet_hdr.csum_offset + 2;
+		    (__virtio16_to_cpu(false, vnet_hdr.csum_start) +
+		     __virtio16_to_cpu(false, vnet_hdr.csum_offset) + 2 >
+		      __virtio16_to_cpu(false, vnet_hdr.hdr_len)))
+			vnet_hdr.hdr_len = __cpu_to_virtio16(false,
+				 __virtio16_to_cpu(false, vnet_hdr.csum_start) +
+				__virtio16_to_cpu(false, vnet_hdr.csum_offset) + 2);
 
 		err = -EINVAL;
-		if (vnet_hdr.hdr_len > len)
+		if (__virtio16_to_cpu(false, vnet_hdr.hdr_len) > len)
 			goto out_unlock;
 
 		if (vnet_hdr.gso_type != VIRTIO_NET_HDR_GSO_NONE) {
@@ -2492,7 +2494,8 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	err = -ENOBUFS;
 	hlen = LL_RESERVED_SPACE(dev);
 	tlen = dev->needed_tailroom;
-	skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, vnet_hdr.hdr_len,
+	skb = packet_alloc_skb(sk, hlen + tlen, hlen, len,
+			       __virtio16_to_cpu(false, vnet_hdr.hdr_len),
 			       msg->msg_flags & MSG_DONTWAIT, &err);
 	if (skb == NULL)
 		goto out_unlock;
@@ -2534,14 +2537,16 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 
 	if (po->has_vnet_hdr) {
 		if (vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-			if (!skb_partial_csum_set(skb, vnet_hdr.csum_start,
-						  vnet_hdr.csum_offset)) {
+			u16 s = __virtio16_to_cpu(false, vnet_hdr.csum_start);
+			u16 o = __virtio16_to_cpu(false, vnet_hdr.csum_offset);
+			if (!skb_partial_csum_set(skb, s, o)) {
 				err = -EINVAL;
 				goto out_free;
 			}
 		}
 
-		skb_shinfo(skb)->gso_size = vnet_hdr.gso_size;
+		skb_shinfo(skb)->gso_size =
+			__virtio16_to_cpu(false, vnet_hdr.gso_size);
 		skb_shinfo(skb)->gso_type = gso_type;
 
 		/* Header must be checked, and gso_segs computed. */
@@ -2912,8 +2917,10 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
 			struct skb_shared_info *sinfo = skb_shinfo(skb);
 
 			/* This is a hint as to how much should be linear. */
-			vnet_hdr.hdr_len = skb_headlen(skb);
-			vnet_hdr.gso_size = sinfo->gso_size;
+			vnet_hdr.hdr_len =
+				__cpu_to_virtio16(false, skb_headlen(skb));
+			vnet_hdr.gso_size =
+				__cpu_to_virtio16(false, sinfo->gso_size);
 			if (sinfo->gso_type & SKB_GSO_TCPV4)
 				vnet_hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
 			else if (sinfo->gso_type & SKB_GSO_TCPV6)
@@ -2931,8 +2938,10 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
 
 		if (skb->ip_summed == CHECKSUM_PARTIAL) {
 			vnet_hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-			vnet_hdr.csum_start = skb_checksum_start_offset(skb);
-			vnet_hdr.csum_offset = skb->csum_offset;
+			vnet_hdr.csum_start = __cpu_to_virtio16(false,
+					  skb_checksum_start_offset(skb));
+			vnet_hdr.csum_offset = __cpu_to_virtio16(false,
+							 skb->csum_offset);
 		} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
 			vnet_hdr.flags = VIRTIO_NET_HDR_F_DATA_VALID;
 		} /* else everything is zero */
-- 
MST

^ permalink raw reply related

* [PATCH v8 45/50] vhost/scsi: partial virtio 1.0 support
From: Michael S. Tsirkin @ 2014-12-01 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	kvm, virtualization, netdev
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Include all endian conversions as required by virtio 1.0.
Don't set virtio 1.0 yet, since that requires ANY_LAYOUT
which we don't yet support.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
---
 drivers/vhost/scsi.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index a17f118..01c01cb 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -168,6 +168,7 @@ enum {
 	VHOST_SCSI_VQ_IO = 2,
 };
 
+/* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. */
 enum {
 	VHOST_SCSI_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG) |
 					       (1ULL << VIRTIO_SCSI_F_T10_PI)
@@ -577,8 +578,8 @@ tcm_vhost_allocate_evt(struct vhost_scsi *vs,
 		return NULL;
 	}
 
-	evt->event.event = event;
-	evt->event.reason = reason;
+	evt->event.event = cpu_to_vhost32(vq, event);
+	evt->event.reason = cpu_to_vhost32(vq, reason);
 	vs->vs_events_nr++;
 
 	return evt;
@@ -636,7 +637,7 @@ again:
 	}
 
 	if (vs->vs_events_missed) {
-		event->event |= VIRTIO_SCSI_T_EVENTS_MISSED;
+		event->event |= cpu_to_vhost32(vq, VIRTIO_SCSI_T_EVENTS_MISSED);
 		vs->vs_events_missed = false;
 	}
 
@@ -695,12 +696,13 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
 			cmd, se_cmd->residual_count, se_cmd->scsi_status);
 
 		memset(&v_rsp, 0, sizeof(v_rsp));
-		v_rsp.resid = se_cmd->residual_count;
+		v_rsp.resid = cpu_to_vhost32(cmd->tvc_vq, se_cmd->residual_count);
 		/* TODO is status_qualifier field needed? */
 		v_rsp.status = se_cmd->scsi_status;
-		v_rsp.sense_len = se_cmd->scsi_sense_length;
+		v_rsp.sense_len = cpu_to_vhost32(cmd->tvc_vq,
+						 se_cmd->scsi_sense_length);
 		memcpy(v_rsp.sense, cmd->tvc_sense_buf,
-		       v_rsp.sense_len);
+		       se_cmd->scsi_sense_length);
 		ret = copy_to_user(cmd->tvc_resp, &v_rsp, sizeof(v_rsp));
 		if (likely(ret == 0)) {
 			struct vhost_scsi_virtqueue *q;
@@ -1095,14 +1097,14 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
 						", but wrong data_direction\n");
 					goto err_cmd;
 				}
-				prot_bytes = v_req_pi.pi_bytesout;
+				prot_bytes = vhost32_to_cpu(vq, v_req_pi.pi_bytesout);
 			} else if (v_req_pi.pi_bytesin) {
 				if (data_direction != DMA_FROM_DEVICE) {
 					vq_err(vq, "Received non zero di_pi_niov"
 						", but wrong data_direction\n");
 					goto err_cmd;
 				}
-				prot_bytes = v_req_pi.pi_bytesin;
+				prot_bytes = vhost32_to_cpu(vq, v_req_pi.pi_bytesin);
 			}
 			if (prot_bytes) {
 				int tmp = 0;
@@ -1117,12 +1119,12 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
 				data_first += prot_niov;
 				data_niov = data_num - prot_niov;
 			}
-			tag = v_req_pi.tag;
+			tag = vhost64_to_cpu(vq, v_req_pi.tag);
 			task_attr = v_req_pi.task_attr;
 			cdb = &v_req_pi.cdb[0];
 			lun = ((v_req_pi.lun[2] << 8) | v_req_pi.lun[3]) & 0x3FFF;
 		} else {
-			tag = v_req.tag;
+			tag = vhost64_to_cpu(vq, v_req.tag);
 			task_attr = v_req.task_attr;
 			cdb = &v_req.cdb[0];
 			lun = ((v_req.lun[2] << 8) | v_req.lun[3]) & 0x3FFF;
-- 
MST

^ permalink raw reply related

* [PATCH v8 41/50] macvtap: TUN_VNET_LE support
From: Michael S. Tsirkin @ 2014-12-01 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	Jason Wang, Vlad Yasevich, Zhi Yong Wu, Tom Herbert,
	Ben Hutchings, netdev
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
---
 drivers/net/macvtap.c | 68 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 25 deletions(-)

diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 880cc09..af90ab5 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -45,6 +45,18 @@ struct macvtap_queue {
 	struct list_head next;
 };
 
+#define MACVTAP_FEATURES (IFF_VNET_HDR | IFF_VNET_LE | IFF_MULTI_QUEUE)
+
+static inline u16 macvtap16_to_cpu(struct macvtap_queue *q, __virtio16 val)
+{
+	return __virtio16_to_cpu(q->flags & IFF_VNET_LE, val);
+}
+
+static inline __virtio16 cpu_to_macvtap16(struct macvtap_queue *q, u16 val)
+{
+	return __cpu_to_virtio16(q->flags & IFF_VNET_LE, val);
+}
+
 static struct proto macvtap_proto = {
 	.name = "macvtap",
 	.owner = THIS_MODULE,
@@ -557,7 +569,8 @@ static inline struct sk_buff *macvtap_alloc_skb(struct sock *sk, size_t prepad,
  * macvtap_skb_from_vnet_hdr and macvtap_skb_to_vnet_hdr should
  * be shared with the tun/tap driver.
  */
-static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb,
+static int macvtap_skb_from_vnet_hdr(struct macvtap_queue *q,
+				     struct sk_buff *skb,
 				     struct virtio_net_hdr *vnet_hdr)
 {
 	unsigned short gso_type = 0;
@@ -588,13 +601,13 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb,
 	}
 
 	if (vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-		if (!skb_partial_csum_set(skb, vnet_hdr->csum_start,
-					  vnet_hdr->csum_offset))
+		if (!skb_partial_csum_set(skb, macvtap16_to_cpu(q, vnet_hdr->csum_start),
+					  macvtap16_to_cpu(q, vnet_hdr->csum_offset)))
 			return -EINVAL;
 	}
 
 	if (vnet_hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
-		skb_shinfo(skb)->gso_size = vnet_hdr->gso_size;
+		skb_shinfo(skb)->gso_size = macvtap16_to_cpu(q, vnet_hdr->gso_size);
 		skb_shinfo(skb)->gso_type = gso_type;
 
 		/* Header must be checked, and gso_segs computed. */
@@ -604,8 +617,9 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb,
 	return 0;
 }
 
-static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
-				   struct virtio_net_hdr *vnet_hdr)
+static void macvtap_skb_to_vnet_hdr(struct macvtap_queue *q,
+				    const struct sk_buff *skb,
+				    struct virtio_net_hdr *vnet_hdr)
 {
 	memset(vnet_hdr, 0, sizeof(*vnet_hdr));
 
@@ -613,8 +627,8 @@ static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
 		struct skb_shared_info *sinfo = skb_shinfo(skb);
 
 		/* This is a hint as to how much should be linear. */
-		vnet_hdr->hdr_len = skb_headlen(skb);
-		vnet_hdr->gso_size = sinfo->gso_size;
+		vnet_hdr->hdr_len = cpu_to_macvtap16(q, skb_headlen(skb));
+		vnet_hdr->gso_size = cpu_to_macvtap16(q, sinfo->gso_size);
 		if (sinfo->gso_type & SKB_GSO_TCPV4)
 			vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
 		else if (sinfo->gso_type & SKB_GSO_TCPV6)
@@ -628,10 +642,13 @@ static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
 		vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-		vnet_hdr->csum_start = skb_checksum_start_offset(skb);
 		if (vlan_tx_tag_present(skb))
-			vnet_hdr->csum_start += VLAN_HLEN;
-		vnet_hdr->csum_offset = skb->csum_offset;
+			vnet_hdr->csum_start = cpu_to_macvtap16(q,
+				skb_checksum_start_offset(skb) + VLAN_HLEN);
+		else
+			vnet_hdr->csum_start = cpu_to_macvtap16(q,
+				skb_checksum_start_offset(skb));
+		vnet_hdr->csum_offset = cpu_to_macvtap16(q, skb->csum_offset);
 	} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
 		vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
 	} /* else everything is zero */
@@ -666,12 +683,14 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 		if (err < 0)
 			goto err;
 		if ((vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
-		     vnet_hdr.csum_start + vnet_hdr.csum_offset + 2 >
-							vnet_hdr.hdr_len)
-			vnet_hdr.hdr_len = vnet_hdr.csum_start +
-						vnet_hdr.csum_offset + 2;
+		     macvtap16_to_cpu(q, vnet_hdr.csum_start) +
+		     macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2 >
+			     macvtap16_to_cpu(q, vnet_hdr.hdr_len))
+			vnet_hdr.hdr_len = cpu_to_macvtap16(q,
+				 macvtap16_to_cpu(q, vnet_hdr.csum_start) +
+				 macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2);
 		err = -EINVAL;
-		if (vnet_hdr.hdr_len > len)
+		if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > len)
 			goto err;
 	}
 
@@ -684,7 +703,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 		goto err;
 
 	if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
-		copylen = vnet_hdr.hdr_len ? vnet_hdr.hdr_len : GOODCOPY_LEN;
+		copylen = vnet_hdr.hdr_len ?
+			macvtap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN;
 		if (copylen > good_linear)
 			copylen = good_linear;
 		linear = copylen;
@@ -695,10 +715,10 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 
 	if (!zerocopy) {
 		copylen = len;
-		if (vnet_hdr.hdr_len > good_linear)
+		if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > good_linear)
 			linear = good_linear;
 		else
-			linear = vnet_hdr.hdr_len;
+			linear = macvtap16_to_cpu(q, vnet_hdr.hdr_len);
 	}
 
 	skb = macvtap_alloc_skb(&q->sk, NET_IP_ALIGN, copylen,
@@ -725,7 +745,7 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 	skb->protocol = eth_hdr(skb)->h_proto;
 
 	if (vnet_hdr_len) {
-		err = macvtap_skb_from_vnet_hdr(skb, &vnet_hdr);
+		err = macvtap_skb_from_vnet_hdr(q, skb, &vnet_hdr);
 		if (err)
 			goto err_kfree;
 	}
@@ -791,7 +811,7 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
 		if ((len -= vnet_hdr_len) < 0)
 			return -EINVAL;
 
-		macvtap_skb_to_vnet_hdr(skb, &vnet_hdr);
+		macvtap_skb_to_vnet_hdr(q, skb, &vnet_hdr);
 
 		if (memcpy_toiovecend(iv, (void *)&vnet_hdr, 0, sizeof(vnet_hdr)))
 			return -EFAULT;
@@ -1003,8 +1023,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
 			return -EFAULT;
 
 		ret = 0;
-		if ((u & ~(IFF_VNET_HDR | IFF_MULTI_QUEUE)) !=
-		    (IFF_NO_PI | IFF_TAP))
+		if ((u & ~MACVTAP_FEATURES) != (IFF_NO_PI | IFF_TAP))
 			ret = -EINVAL;
 		else
 			q->flags = u;
@@ -1036,8 +1055,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
 		return ret;
 
 	case TUNGETFEATURES:
-		if (put_user(IFF_TAP | IFF_NO_PI | IFF_VNET_HDR |
-			     IFF_MULTI_QUEUE, up))
+		if (put_user(IFF_TAP | IFF_NO_PI | MACVTAP_FEATURES, up))
 			return -EFAULT;
 		return 0;
 
-- 
MST

^ permalink raw reply related

* [PATCH v8 40/50] tun: TUN_VNET_LE support, fix sparse warnings for virtio headers
From: Michael S. Tsirkin @ 2014-12-01 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	Jason Wang, Zhi Yong Wu, Tom Herbert, Herbert Xu, Masatake YAMATO,
	Ben Hutchings, Xi Wang, netdev
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Pretty straight-forward: convert all fields to/from
virtio endian-ness.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
---
 drivers/net/tun.c | 48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 36be4fd..c052bd6b 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -111,7 +111,7 @@ do {								\
 #define TUN_FASYNC	IFF_ATTACH_QUEUE
 
 #define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \
-		      IFF_MULTI_QUEUE)
+		      IFF_VNET_LE | IFF_MULTI_QUEUE)
 #define GOODCOPY_LEN 128
 
 #define FLT_EXACT_COUNT 8
@@ -205,6 +205,16 @@ struct tun_struct {
 	u32 flow_count;
 };
 
+static inline u16 tun16_to_cpu(struct tun_struct *tun, __virtio16 val)
+{
+	return __virtio16_to_cpu(tun->flags & IFF_VNET_LE, val);
+}
+
+static inline __virtio16 cpu_to_tun16(struct tun_struct *tun, u16 val)
+{
+	return __cpu_to_virtio16(tun->flags & IFF_VNET_LE, val);
+}
+
 static inline u32 tun_hashfn(u32 rxhash)
 {
 	return rxhash & 0x3ff;
@@ -1053,10 +1063,10 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 			return -EFAULT;
 
 		if ((gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
-		    gso.csum_start + gso.csum_offset + 2 > gso.hdr_len)
-			gso.hdr_len = gso.csum_start + gso.csum_offset + 2;
+		    tun16_to_cpu(tun, gso.csum_start) + tun16_to_cpu(tun, gso.csum_offset) + 2 > tun16_to_cpu(tun, gso.hdr_len))
+			gso.hdr_len = cpu_to_tun16(tun, tun16_to_cpu(tun, gso.csum_start) + tun16_to_cpu(tun, gso.csum_offset) + 2);
 
-		if (gso.hdr_len > len)
+		if (tun16_to_cpu(tun, gso.hdr_len) > len)
 			return -EINVAL;
 		offset += tun->vnet_hdr_sz;
 	}
@@ -1064,7 +1074,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 	if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) {
 		align += NET_IP_ALIGN;
 		if (unlikely(len < ETH_HLEN ||
-			     (gso.hdr_len && gso.hdr_len < ETH_HLEN)))
+			     (gso.hdr_len && tun16_to_cpu(tun, gso.hdr_len) < ETH_HLEN)))
 			return -EINVAL;
 	}
 
@@ -1075,7 +1085,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		 * enough room for skb expand head in case it is used.
 		 * The rest of the buffer is mapped from userspace.
 		 */
-		copylen = gso.hdr_len ? gso.hdr_len : GOODCOPY_LEN;
+		copylen = gso.hdr_len ? tun16_to_cpu(tun, gso.hdr_len) : GOODCOPY_LEN;
 		if (copylen > good_linear)
 			copylen = good_linear;
 		linear = copylen;
@@ -1085,10 +1095,10 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 
 	if (!zerocopy) {
 		copylen = len;
-		if (gso.hdr_len > good_linear)
+		if (tun16_to_cpu(tun, gso.hdr_len) > good_linear)
 			linear = good_linear;
 		else
-			linear = gso.hdr_len;
+			linear = tun16_to_cpu(tun, gso.hdr_len);
 	}
 
 	skb = tun_alloc_skb(tfile, align, copylen, linear, noblock);
@@ -1115,8 +1125,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 	}
 
 	if (gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-		if (!skb_partial_csum_set(skb, gso.csum_start,
-					  gso.csum_offset)) {
+		if (!skb_partial_csum_set(skb, tun16_to_cpu(tun, gso.csum_start),
+					  tun16_to_cpu(tun, gso.csum_offset))) {
 			tun->dev->stats.rx_frame_errors++;
 			kfree_skb(skb);
 			return -EINVAL;
@@ -1184,7 +1194,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		if (gso.gso_type & VIRTIO_NET_HDR_GSO_ECN)
 			skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
 
-		skb_shinfo(skb)->gso_size = gso.gso_size;
+		skb_shinfo(skb)->gso_size = tun16_to_cpu(tun, gso.gso_size);
 		if (skb_shinfo(skb)->gso_size == 0) {
 			tun->dev->stats.rx_frame_errors++;
 			kfree_skb(skb);
@@ -1276,8 +1286,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
 			struct skb_shared_info *sinfo = skb_shinfo(skb);
 
 			/* This is a hint as to how much should be linear. */
-			gso.hdr_len = skb_headlen(skb);
-			gso.gso_size = sinfo->gso_size;
+			gso.hdr_len = cpu_to_tun16(tun, skb_headlen(skb));
+			gso.gso_size = cpu_to_tun16(tun, sinfo->gso_size);
 			if (sinfo->gso_type & SKB_GSO_TCPV4)
 				gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
 			else if (sinfo->gso_type & SKB_GSO_TCPV6)
@@ -1285,12 +1295,12 @@ static ssize_t tun_put_user(struct tun_struct *tun,
 			else {
 				pr_err("unexpected GSO type: "
 				       "0x%x, gso_size %d, hdr_len %d\n",
-				       sinfo->gso_type, gso.gso_size,
-				       gso.hdr_len);
+				       sinfo->gso_type, tun16_to_cpu(tun, gso.gso_size),
+				       tun16_to_cpu(tun, gso.hdr_len));
 				print_hex_dump(KERN_ERR, "tun: ",
 					       DUMP_PREFIX_NONE,
 					       16, 1, skb->head,
-					       min((int)gso.hdr_len, 64), true);
+					       min((int)tun16_to_cpu(tun, gso.hdr_len), 64), true);
 				WARN_ON_ONCE(1);
 				return -EINVAL;
 			}
@@ -1301,9 +1311,9 @@ static ssize_t tun_put_user(struct tun_struct *tun,
 
 		if (skb->ip_summed == CHECKSUM_PARTIAL) {
 			gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-			gso.csum_start = skb_checksum_start_offset(skb) +
-					 vlan_hlen;
-			gso.csum_offset = skb->csum_offset;
+			gso.csum_start = cpu_to_tun16(tun, skb_checksum_start_offset(skb) +
+						      vlan_hlen);
+			gso.csum_offset = cpu_to_tun16(tun, skb->csum_offset);
 		} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
 			gso.flags = VIRTIO_NET_HDR_F_DATA_VALID;
 		} /* else everything is zero */
-- 
MST

^ permalink raw reply related

* [PATCH v8 39/50] tun: add VNET_LE flag
From: Michael S. Tsirkin @ 2014-12-01 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	netdev, linux-api
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

virtio 1.0 modified virtio net header format,
making all fields little endian.

Users can tweak header format before submitting it to tun,
but this means more data copies where none were necessary.
And if the iovec is in RO memory, this means we might
need to split iovec also means we might in theory overflow
iovec max size.

This patch adds a simpler way for applications to handle this,
using new "little endian" flag in tun.
As a result, tun simply byte-swaps header fields as appropriate.
This is a NOP on LE architectures.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/uapi/linux/if_tun.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h
index 277a260..18b2403 100644
--- a/include/uapi/linux/if_tun.h
+++ b/include/uapi/linux/if_tun.h
@@ -57,6 +57,7 @@
 #define IFF_ONE_QUEUE	0x2000
 #define IFF_VNET_HDR	0x4000
 #define IFF_TUN_EXCL	0x8000
+#define IFF_VNET_LE	0x10000
 #define IFF_MULTI_QUEUE 0x0100
 #define IFF_ATTACH_QUEUE 0x0200
 #define IFF_DETACH_QUEUE 0x0400
-- 
MST

^ permalink raw reply related

* [PATCH v8 38/50] tun: drop most type defines
From: Michael S. Tsirkin @ 2014-12-01 16:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	Jason Wang, Zhi Yong Wu, Herbert Xu, Ben Hutchings, Tom Herbert,
	Masatake YAMATO, Xi Wang, netdev
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

It's just as easy to use IFF_ flags directly,
there's no point in adding our own defines.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/tun.c | 62 +++++++++++++++++++++++++------------------------------
 1 file changed, 28 insertions(+), 34 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index b4e4ca0..36be4fd 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -109,12 +109,6 @@ do {								\
  * overload it to mean fasync when stored there.
  */
 #define TUN_FASYNC	IFF_ATTACH_QUEUE
-#define TUN_NO_PI	IFF_NO_PI
-/* This flag has no real effect */
-#define TUN_ONE_QUEUE	IFF_ONE_QUEUE
-#define TUN_PERSIST 	IFF_PERSIST
-#define TUN_VNET_HDR 	IFF_VNET_HDR
-#define TUN_TAP_MQ      IFF_MULTI_QUEUE
 
 #define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \
 		      IFF_MULTI_QUEUE)
@@ -487,7 +481,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
 		if (tun && tun->numqueues == 0 && tun->numdisabled == 0) {
 			netif_carrier_off(tun->dev);
 
-			if (!(tun->flags & TUN_PERSIST) &&
+			if (!(tun->flags & IFF_PERSIST) &&
 			    tun->dev->reg_state == NETREG_REGISTERED)
 				unregister_netdevice(tun->dev);
 		}
@@ -538,7 +532,7 @@ static void tun_detach_all(struct net_device *dev)
 	}
 	BUG_ON(tun->numdisabled != 0);
 
-	if (tun->flags & TUN_PERSIST)
+	if (tun->flags & IFF_PERSIST)
 		module_put(THIS_MODULE);
 }
 
@@ -556,7 +550,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filte
 		goto out;
 
 	err = -EBUSY;
-	if (!(tun->flags & TUN_TAP_MQ) && tun->numqueues == 1)
+	if (!(tun->flags & IFF_MULTI_QUEUE) && tun->numqueues == 1)
 		goto out;
 
 	err = -E2BIG;
@@ -935,7 +929,7 @@ static void tun_net_init(struct net_device *dev)
 	struct tun_struct *tun = netdev_priv(dev);
 
 	switch (tun->flags & TUN_TYPE_MASK) {
-	case TUN_TUN_DEV:
+	case IFF_TUN:
 		dev->netdev_ops = &tun_netdev_ops;
 
 		/* Point-to-Point TUN Device */
@@ -949,7 +943,7 @@ static void tun_net_init(struct net_device *dev)
 		dev->tx_queue_len = TUN_READQ_SIZE;  /* We prefer our own queue length */
 		break;
 
-	case TUN_TAP_DEV:
+	case IFF_TAP:
 		dev->netdev_ops = &tap_netdev_ops;
 		/* Ethernet TAP Device */
 		ether_setup(dev);
@@ -1040,7 +1034,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 	int err;
 	u32 rxhash;
 
-	if (!(tun->flags & TUN_NO_PI)) {
+	if (!(tun->flags & IFF_NO_PI)) {
 		if (len < sizeof(pi))
 			return -EINVAL;
 		len -= sizeof(pi);
@@ -1050,7 +1044,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		offset += sizeof(pi);
 	}
 
-	if (tun->flags & TUN_VNET_HDR) {
+	if (tun->flags & IFF_VNET_HDR) {
 		if (len < tun->vnet_hdr_sz)
 			return -EINVAL;
 		len -= tun->vnet_hdr_sz;
@@ -1067,7 +1061,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		offset += tun->vnet_hdr_sz;
 	}
 
-	if ((tun->flags & TUN_TYPE_MASK) == TUN_TAP_DEV) {
+	if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) {
 		align += NET_IP_ALIGN;
 		if (unlikely(len < ETH_HLEN ||
 			     (gso.hdr_len && gso.hdr_len < ETH_HLEN)))
@@ -1130,8 +1124,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 	}
 
 	switch (tun->flags & TUN_TYPE_MASK) {
-	case TUN_TUN_DEV:
-		if (tun->flags & TUN_NO_PI) {
+	case IFF_TUN:
+		if (tun->flags & IFF_NO_PI) {
 			switch (skb->data[0] & 0xf0) {
 			case 0x40:
 				pi.proto = htons(ETH_P_IP);
@@ -1150,7 +1144,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		skb->protocol = pi.proto;
 		skb->dev = tun->dev;
 		break;
-	case TUN_TAP_DEV:
+	case IFF_TAP:
 		skb->protocol = eth_type_trans(skb, tun->dev);
 		break;
 	}
@@ -1256,10 +1250,10 @@ static ssize_t tun_put_user(struct tun_struct *tun,
 	if (vlan_tx_tag_present(skb))
 		vlan_hlen = VLAN_HLEN;
 
-	if (tun->flags & TUN_VNET_HDR)
+	if (tun->flags & IFF_VNET_HDR)
 		vnet_hdr_sz = tun->vnet_hdr_sz;
 
-	if (!(tun->flags & TUN_NO_PI)) {
+	if (!(tun->flags & IFF_NO_PI)) {
 		if ((len -= sizeof(pi)) < 0)
 			return -EINVAL;
 
@@ -1592,7 +1586,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 			return -EINVAL;
 
 		if (!!(ifr->ifr_flags & IFF_MULTI_QUEUE) !=
-		    !!(tun->flags & TUN_TAP_MQ))
+		    !!(tun->flags & IFF_MULTI_QUEUE))
 			return -EINVAL;
 
 		if (tun_not_capable(tun))
@@ -1605,7 +1599,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 		if (err < 0)
 			return err;
 
-		if (tun->flags & TUN_TAP_MQ &&
+		if (tun->flags & IFF_MULTI_QUEUE &&
 		    (tun->numqueues + tun->numdisabled > 1)) {
 			/* One or more queue has already been attached, no need
 			 * to initialize the device again.
@@ -1628,11 +1622,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 		/* Set dev type */
 		if (ifr->ifr_flags & IFF_TUN) {
 			/* TUN device */
-			flags |= TUN_TUN_DEV;
+			flags |= IFF_TUN;
 			name = "tun%d";
 		} else if (ifr->ifr_flags & IFF_TAP) {
 			/* TAP device */
-			flags |= TUN_TAP_DEV;
+			flags |= IFF_TAP;
 			name = "tap%d";
 		} else
 			return -EINVAL;
@@ -1825,7 +1819,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
 		ret = tun_attach(tun, file, false);
 	} else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {
 		tun = rtnl_dereference(tfile->tun);
-		if (!tun || !(tun->flags & TUN_TAP_MQ) || tfile->detached)
+		if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached)
 			ret = -EINVAL;
 		else
 			__tun_detach(tfile, false);
@@ -1929,12 +1923,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 		/* Disable/Enable persist mode. Keep an extra reference to the
 		 * module to prevent the module being unprobed.
 		 */
-		if (arg && !(tun->flags & TUN_PERSIST)) {
-			tun->flags |= TUN_PERSIST;
+		if (arg && !(tun->flags & IFF_PERSIST)) {
+			tun->flags |= IFF_PERSIST;
 			__module_get(THIS_MODULE);
 		}
-		if (!arg && (tun->flags & TUN_PERSIST)) {
-			tun->flags &= ~TUN_PERSIST;
+		if (!arg && (tun->flags & IFF_PERSIST)) {
+			tun->flags &= ~IFF_PERSIST;
 			module_put(THIS_MODULE);
 		}
 
@@ -1992,7 +1986,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 	case TUNSETTXFILTER:
 		/* Can be set only for TAPs */
 		ret = -EINVAL;
-		if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV)
+		if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
 			break;
 		ret = update_filter(&tun->txflt, (void __user *)arg);
 		break;
@@ -2051,7 +2045,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 	case TUNATTACHFILTER:
 		/* Can be set only for TAPs */
 		ret = -EINVAL;
-		if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV)
+		if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
 			break;
 		ret = -EFAULT;
 		if (copy_from_user(&tun->fprog, argp, sizeof(tun->fprog)))
@@ -2063,7 +2057,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 	case TUNDETACHFILTER:
 		/* Can be set only for TAPs */
 		ret = -EINVAL;
-		if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV)
+		if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
 			break;
 		ret = 0;
 		tun_detach_filter(tun, tun->numqueues);
@@ -2071,7 +2065,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 
 	case TUNGETFILTER:
 		ret = -EINVAL;
-		if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV)
+		if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
 			break;
 		ret = -EFAULT;
 		if (copy_to_user(argp, &tun->fprog, sizeof(tun->fprog)))
@@ -2264,10 +2258,10 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
 	strlcpy(info->version, DRV_VERSION, sizeof(info->version));
 
 	switch (tun->flags & TUN_TYPE_MASK) {
-	case TUN_TUN_DEV:
+	case IFF_TUN:
 		strlcpy(info->bus_info, "tun", sizeof(info->bus_info));
 		break;
-	case TUN_TAP_DEV:
+	case IFF_TAP:
 		strlcpy(info->bus_info, "tap", sizeof(info->bus_info));
 		break;
 	}
-- 
MST

^ permalink raw reply related

* [PATCH v8 37/50] tun: move internal flag defines out of uapi
From: Michael S. Tsirkin @ 2014-12-01 16:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	Jason Wang, Zhi Yong Wu, Tom Herbert, Herbert Xu, Masatake YAMATO,
	Xi Wang, netdev, linux-api
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

TUN_ flags are internal and never exposed
to userspace. Any application using it is almost
certainly buggy.

Move them out to tun.c.

Note: we remove these completely in follow-up patches,
this code movement is split out for ease of review.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/uapi/linux/if_tun.h | 16 ++--------
 drivers/net/tun.c           | 72 +++++++++++++--------------------------------
 2 files changed, 24 insertions(+), 64 deletions(-)

diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h
index e9502dd..277a260 100644
--- a/include/uapi/linux/if_tun.h
+++ b/include/uapi/linux/if_tun.h
@@ -22,21 +22,11 @@
 
 /* Read queue size */
 #define TUN_READQ_SIZE	500
-
-/* TUN device flags */
-#define TUN_TUN_DEV 	0x0001	
-#define TUN_TAP_DEV	0x0002
+/* TUN device type flags: deprecated. Use IFF_TUN/IFF_TAP instead. */
+#define TUN_TUN_DEV 	IFF_TUN
+#define TUN_TAP_DEV	IFF_TAP
 #define TUN_TYPE_MASK   0x000f
 
-#define TUN_FASYNC	0x0010
-#define TUN_NOCHECKSUM	0x0020
-#define TUN_NO_PI	0x0040
-/* This flag has no real effect */
-#define TUN_ONE_QUEUE	0x0080
-#define TUN_PERSIST 	0x0100	
-#define TUN_VNET_HDR 	0x0200
-#define TUN_TAP_MQ      0x0400
-
 /* Ioctl defines */
 #define TUNSETNOCSUM  _IOW('T', 200, int) 
 #define TUNSETDEBUG   _IOW('T', 201, int) 
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 9dd3746..b4e4ca0 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -103,6 +103,21 @@ do {								\
 } while (0)
 #endif
 
+/* TUN device flags */
+
+/* IFF_ATTACH_QUEUE is never stored in device flags,
+ * overload it to mean fasync when stored there.
+ */
+#define TUN_FASYNC	IFF_ATTACH_QUEUE
+#define TUN_NO_PI	IFF_NO_PI
+/* This flag has no real effect */
+#define TUN_ONE_QUEUE	IFF_ONE_QUEUE
+#define TUN_PERSIST 	IFF_PERSIST
+#define TUN_VNET_HDR 	IFF_VNET_HDR
+#define TUN_TAP_MQ      IFF_MULTI_QUEUE
+
+#define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \
+		      IFF_MULTI_QUEUE)
 #define GOODCOPY_LEN 128
 
 #define FLT_EXACT_COUNT 8
@@ -1521,32 +1536,7 @@ static struct proto tun_proto = {
 
 static int tun_flags(struct tun_struct *tun)
 {
-	int flags = 0;
-
-	if (tun->flags & TUN_TUN_DEV)
-		flags |= IFF_TUN;
-	else
-		flags |= IFF_TAP;
-
-	if (tun->flags & TUN_NO_PI)
-		flags |= IFF_NO_PI;
-
-	/* This flag has no real effect.  We track the value for backwards
-	 * compatibility.
-	 */
-	if (tun->flags & TUN_ONE_QUEUE)
-		flags |= IFF_ONE_QUEUE;
-
-	if (tun->flags & TUN_VNET_HDR)
-		flags |= IFF_VNET_HDR;
-
-	if (tun->flags & TUN_TAP_MQ)
-		flags |= IFF_MULTI_QUEUE;
-
-	if (tun->flags & TUN_PERSIST)
-		flags |= IFF_PERSIST;
-
-	return flags;
+	return tun->flags & (TUN_FEATURES | IFF_PERSIST | IFF_TUN | IFF_TAP);
 }
 
 static ssize_t tun_show_flags(struct device *dev, struct device_attribute *attr,
@@ -1706,28 +1696,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 
 	tun_debug(KERN_INFO, tun, "tun_set_iff\n");
 
-	if (ifr->ifr_flags & IFF_NO_PI)
-		tun->flags |= TUN_NO_PI;
-	else
-		tun->flags &= ~TUN_NO_PI;
-
-	/* This flag has no real effect.  We track the value for backwards
-	 * compatibility.
-	 */
-	if (ifr->ifr_flags & IFF_ONE_QUEUE)
-		tun->flags |= TUN_ONE_QUEUE;
-	else
-		tun->flags &= ~TUN_ONE_QUEUE;
-
-	if (ifr->ifr_flags & IFF_VNET_HDR)
-		tun->flags |= TUN_VNET_HDR;
-	else
-		tun->flags &= ~TUN_VNET_HDR;
-
-	if (ifr->ifr_flags & IFF_MULTI_QUEUE)
-		tun->flags |= TUN_TAP_MQ;
-	else
-		tun->flags &= ~TUN_TAP_MQ;
+	tun->flags = (tun->flags & ~TUN_FEATURES) |
+		(ifr->ifr_flags & TUN_FEATURES);
 
 	/* Make sure persistent devices do not get stuck in
 	 * xoff state.
@@ -1890,9 +1860,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 	if (cmd == TUNGETFEATURES) {
 		/* Currently this just means: "what IFF flags are valid?".
 		 * This is needed because we never checked for invalid flags on
-		 * TUNSETIFF. */
-		return put_user(IFF_TUN | IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE |
-				IFF_VNET_HDR | IFF_MULTI_QUEUE,
+		 * TUNSETIFF.
+		 */
+		return put_user(IFF_TUN | IFF_TAP | TUN_FEATURES,
 				(unsigned int __user*)argp);
 	} else if (cmd == TUNSETQUEUE)
 		return tun_set_queue(file, &ifr);
-- 
MST

^ permalink raw reply related

* [PATCH v8 36/50] vhost/net: enable virtio 1.0
From: Michael S. Tsirkin @ 2014-12-01 16:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: thuth, kvm, rusty, netdev, virtualization, dahi, pbonzini,
	David Miller
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 8ff4a6d..a935c25 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -61,7 +61,8 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
 enum {
 	VHOST_NET_FEATURES = VHOST_FEATURES |
 			 (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
-			 (1ULL << VIRTIO_NET_F_MRG_RXBUF),
+			 (1ULL << VIRTIO_NET_F_MRG_RXBUF) |
+			 (1ULL << VIRTIO_F_VERSION_1),
 };
 
 enum {
-- 
MST

^ permalink raw reply related

* [PATCH v8 35/50] vhost/net: larger header for virtio 1.0
From: Michael S. Tsirkin @ 2014-12-01 16:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: thuth, kvm, rusty, netdev, virtualization, dahi, pbonzini,
	David Miller
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 drivers/vhost/net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index c218188..8ff4a6d 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -1030,7 +1030,8 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features)
 	size_t vhost_hlen, sock_hlen, hdr_len;
 	int i;
 
-	hdr_len = (features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ?
+	hdr_len = (features & ((1ULL << VIRTIO_NET_F_MRG_RXBUF) |
+			       (1ULL << VIRTIO_F_VERSION_1))) ?
 			sizeof(struct virtio_net_hdr_mrg_rxbuf) :
 			sizeof(struct virtio_net_hdr);
 	if (features & (1 << VHOST_NET_F_VIRTIO_NET_HDR)) {
-- 
MST

^ permalink raw reply related

* [PATCH v8 34/50] vhost/net: virtio 1.0 byte swap
From: Michael S. Tsirkin @ 2014-12-01 16:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: thuth, kvm, rusty, netdev, virtualization, dahi, pbonzini,
	David Miller
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

I had to add an explicit tag to suppress compiler warning:
gcc isn't smart enough to notice that
len is always initialized since function is called with size > 0.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 drivers/vhost/net.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index dce5c58..c218188 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -416,7 +416,7 @@ static void handle_tx(struct vhost_net *net)
 			struct ubuf_info *ubuf;
 			ubuf = nvq->ubuf_info + nvq->upend_idx;
 
-			vq->heads[nvq->upend_idx].id = head;
+			vq->heads[nvq->upend_idx].id = cpu_to_vhost32(vq, head);
 			vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS;
 			ubuf->callback = vhost_zerocopy_callback;
 			ubuf->ctx = nvq->ubufs;
@@ -500,6 +500,10 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 	int headcount = 0;
 	unsigned d;
 	int r, nlogs = 0;
+	/* len is always initialized before use since we are always called with
+	 * datalen > 0.
+	 */
+	u32 uninitialized_var(len);
 
 	while (datalen > 0 && headcount < quota) {
 		if (unlikely(seg >= UIO_MAXIOV)) {
@@ -527,13 +531,14 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 			nlogs += *log_num;
 			log += *log_num;
 		}
-		heads[headcount].id = d;
-		heads[headcount].len = iov_length(vq->iov + seg, in);
-		datalen -= heads[headcount].len;
+		heads[headcount].id = cpu_to_vhost32(vq, d);
+		len = iov_length(vq->iov + seg, in);
+		heads[headcount].len = cpu_to_vhost32(vq, len);
+		datalen -= len;
 		++headcount;
 		seg += in;
 	}
-	heads[headcount - 1].len += datalen;
+	heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);
 	*iovcount = seg;
 	if (unlikely(log))
 		*log_num = nlogs;
-- 
MST

^ permalink raw reply related

* [PATCH v8 33/50] vhost: virtio 1.0 endian-ness support
From: Michael S. Tsirkin @ 2014-12-01 16:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: thuth, kvm, rusty, netdev, virtualization, dahi, pbonzini,
	David Miller
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/vhost.c | 86 +++++++++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 37 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 6a40837..ed71b53 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -33,8 +33,8 @@ enum {
 	VHOST_MEMORY_F_LOG = 0x1,
 };
 
-#define vhost_used_event(vq) ((u16 __user *)&vq->avail->ring[vq->num])
-#define vhost_avail_event(vq) ((u16 __user *)&vq->used->ring[vq->num])
+#define vhost_used_event(vq) ((__virtio16 __user *)&vq->avail->ring[vq->num])
+#define vhost_avail_event(vq) ((__virtio16 __user *)&vq->used->ring[vq->num])
 
 static void vhost_poll_func(struct file *file, wait_queue_head_t *wqh,
 			    poll_table *pt)
@@ -1001,7 +1001,7 @@ EXPORT_SYMBOL_GPL(vhost_log_write);
 static int vhost_update_used_flags(struct vhost_virtqueue *vq)
 {
 	void __user *used;
-	if (__put_user(vq->used_flags, &vq->used->flags) < 0)
+	if (__put_user(cpu_to_vhost16(vq, vq->used_flags), &vq->used->flags) < 0)
 		return -EFAULT;
 	if (unlikely(vq->log_used)) {
 		/* Make sure the flag is seen before log. */
@@ -1019,7 +1019,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq)
 
 static int vhost_update_avail_event(struct vhost_virtqueue *vq, u16 avail_event)
 {
-	if (__put_user(vq->avail_idx, vhost_avail_event(vq)))
+	if (__put_user(cpu_to_vhost16(vq, vq->avail_idx), vhost_avail_event(vq)))
 		return -EFAULT;
 	if (unlikely(vq->log_used)) {
 		void __user *used;
@@ -1038,7 +1038,7 @@ static int vhost_update_avail_event(struct vhost_virtqueue *vq, u16 avail_event)
 
 int vhost_init_used(struct vhost_virtqueue *vq)
 {
-	u16 last_used_idx;
+	__virtio16 last_used_idx;
 	int r;
 	if (!vq->private_data)
 		return 0;
@@ -1052,7 +1052,7 @@ int vhost_init_used(struct vhost_virtqueue *vq)
 	r = __get_user(last_used_idx, &vq->used->idx);
 	if (r)
 		return r;
-	vq->last_used_idx = last_used_idx;
+	vq->last_used_idx = vhost16_to_cpu(vq, last_used_idx);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(vhost_init_used);
@@ -1094,16 +1094,16 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 /* Each buffer in the virtqueues is actually a chain of descriptors.  This
  * function returns the next descriptor in the chain,
  * or -1U if we're at the end. */
-static unsigned next_desc(struct vring_desc *desc)
+static unsigned next_desc(struct vhost_virtqueue *vq, struct vring_desc *desc)
 {
 	unsigned int next;
 
 	/* If this descriptor says it doesn't chain, we're done. */
-	if (!(desc->flags & VRING_DESC_F_NEXT))
+	if (!(desc->flags & cpu_to_vhost16(vq, VRING_DESC_F_NEXT)))
 		return -1U;
 
 	/* Check they're not leading us off end of descriptors. */
-	next = desc->next;
+	next = vhost16_to_cpu(vq, desc->next);
 	/* Make sure compiler knows to grab that: we don't want it changing! */
 	/* We will use the result as an index in an array, so most
 	 * architectures only need a compiler barrier here. */
@@ -1120,18 +1120,19 @@ static int get_indirect(struct vhost_virtqueue *vq,
 {
 	struct vring_desc desc;
 	unsigned int i = 0, count, found = 0;
+	u32 len = vhost32_to_cpu(vq, indirect->len);
 	int ret;
 
 	/* Sanity check */
-	if (unlikely(indirect->len % sizeof desc)) {
+	if (unlikely(len % sizeof desc)) {
 		vq_err(vq, "Invalid length in indirect descriptor: "
 		       "len 0x%llx not multiple of 0x%zx\n",
-		       (unsigned long long)indirect->len,
+		       (unsigned long long)len,
 		       sizeof desc);
 		return -EINVAL;
 	}
 
-	ret = translate_desc(vq, indirect->addr, indirect->len, vq->indirect,
+	ret = translate_desc(vq, vhost64_to_cpu(vq, indirect->addr), len, vq->indirect,
 			     UIO_MAXIOV);
 	if (unlikely(ret < 0)) {
 		vq_err(vq, "Translation failure %d in indirect.\n", ret);
@@ -1142,7 +1143,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
 	 * architectures only need a compiler barrier here. */
 	read_barrier_depends();
 
-	count = indirect->len / sizeof desc;
+	count = len / sizeof desc;
 	/* Buffers are chained via a 16 bit next field, so
 	 * we can have at most 2^16 of these. */
 	if (unlikely(count > USHRT_MAX + 1)) {
@@ -1162,16 +1163,17 @@ static int get_indirect(struct vhost_virtqueue *vq,
 		if (unlikely(memcpy_fromiovec((unsigned char *)&desc,
 					      vq->indirect, sizeof desc))) {
 			vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n",
-			       i, (size_t)indirect->addr + i * sizeof desc);
+			       i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof desc);
 			return -EINVAL;
 		}
-		if (unlikely(desc.flags & VRING_DESC_F_INDIRECT)) {
+		if (unlikely(desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_INDIRECT))) {
 			vq_err(vq, "Nested indirect descriptor: idx %d, %zx\n",
-			       i, (size_t)indirect->addr + i * sizeof desc);
+			       i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof desc);
 			return -EINVAL;
 		}
 
-		ret = translate_desc(vq, desc.addr, desc.len, iov + iov_count,
+		ret = translate_desc(vq, vhost64_to_cpu(vq, desc.addr),
+				     vhost32_to_cpu(vq, desc.len), iov + iov_count,
 				     iov_size - iov_count);
 		if (unlikely(ret < 0)) {
 			vq_err(vq, "Translation failure %d indirect idx %d\n",
@@ -1179,11 +1181,11 @@ static int get_indirect(struct vhost_virtqueue *vq,
 			return ret;
 		}
 		/* If this is an input descriptor, increment that count. */
-		if (desc.flags & VRING_DESC_F_WRITE) {
+		if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) {
 			*in_num += ret;
 			if (unlikely(log)) {
-				log[*log_num].addr = desc.addr;
-				log[*log_num].len = desc.len;
+				log[*log_num].addr = vhost64_to_cpu(vq, desc.addr);
+				log[*log_num].len = vhost32_to_cpu(vq, desc.len);
 				++*log_num;
 			}
 		} else {
@@ -1196,7 +1198,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
 			}
 			*out_num += ret;
 		}
-	} while ((i = next_desc(&desc)) != -1);
+	} while ((i = next_desc(vq, &desc)) != -1);
 	return 0;
 }
 
@@ -1216,15 +1218,18 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 	struct vring_desc desc;
 	unsigned int i, head, found = 0;
 	u16 last_avail_idx;
+	__virtio16 avail_idx;
+	__virtio16 ring_head;
 	int ret;
 
 	/* Check it isn't doing very strange things with descriptor numbers. */
 	last_avail_idx = vq->last_avail_idx;
-	if (unlikely(__get_user(vq->avail_idx, &vq->avail->idx))) {
+	if (unlikely(__get_user(avail_idx, &vq->avail->idx))) {
 		vq_err(vq, "Failed to access avail idx at %p\n",
 		       &vq->avail->idx);
 		return -EFAULT;
 	}
+	vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
 
 	if (unlikely((u16)(vq->avail_idx - last_avail_idx) > vq->num)) {
 		vq_err(vq, "Guest moved used index from %u to %u",
@@ -1241,7 +1246,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 
 	/* Grab the next descriptor number they're advertising, and increment
 	 * the index we've seen. */
-	if (unlikely(__get_user(head,
+	if (unlikely(__get_user(ring_head,
 				&vq->avail->ring[last_avail_idx % vq->num]))) {
 		vq_err(vq, "Failed to read head: idx %d address %p\n",
 		       last_avail_idx,
@@ -1249,6 +1254,8 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 		return -EFAULT;
 	}
 
+	head = vhost16_to_cpu(vq, ring_head);
+
 	/* If their number is silly, that's an error. */
 	if (unlikely(head >= vq->num)) {
 		vq_err(vq, "Guest says index %u > %u is available",
@@ -1281,7 +1288,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 			       i, vq->desc + i);
 			return -EFAULT;
 		}
-		if (desc.flags & VRING_DESC_F_INDIRECT) {
+		if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_INDIRECT)) {
 			ret = get_indirect(vq, iov, iov_size,
 					   out_num, in_num,
 					   log, log_num, &desc);
@@ -1293,20 +1300,21 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 			continue;
 		}
 
-		ret = translate_desc(vq, desc.addr, desc.len, iov + iov_count,
+		ret = translate_desc(vq, vhost64_to_cpu(vq, desc.addr),
+				     vhost32_to_cpu(vq, desc.len), iov + iov_count,
 				     iov_size - iov_count);
 		if (unlikely(ret < 0)) {
 			vq_err(vq, "Translation failure %d descriptor idx %d\n",
 			       ret, i);
 			return ret;
 		}
-		if (desc.flags & VRING_DESC_F_WRITE) {
+		if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) {
 			/* If this is an input descriptor,
 			 * increment that count. */
 			*in_num += ret;
 			if (unlikely(log)) {
-				log[*log_num].addr = desc.addr;
-				log[*log_num].len = desc.len;
+				log[*log_num].addr = vhost64_to_cpu(vq, desc.addr);
+				log[*log_num].len = vhost32_to_cpu(vq, desc.len);
 				++*log_num;
 			}
 		} else {
@@ -1319,7 +1327,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 			}
 			*out_num += ret;
 		}
-	} while ((i = next_desc(&desc)) != -1);
+	} while ((i = next_desc(vq, &desc)) != -1);
 
 	/* On success, increment avail index. */
 	vq->last_avail_idx++;
@@ -1342,7 +1350,10 @@ EXPORT_SYMBOL_GPL(vhost_discard_vq_desc);
  * want to notify the guest, using eventfd. */
 int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len)
 {
-	struct vring_used_elem heads = { head, len };
+	struct vring_used_elem heads = {
+		cpu_to_vhost32(vq, head),
+		cpu_to_vhost32(vq, len)
+	};
 
 	return vhost_add_used_n(vq, &heads, 1);
 }
@@ -1411,7 +1422,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
 
 	/* Make sure buffer is written before we update index. */
 	smp_wmb();
-	if (__put_user(vq->last_used_idx, &vq->used->idx)) {
+	if (__put_user(cpu_to_vhost16(vq, vq->last_used_idx), &vq->used->idx)) {
 		vq_err(vq, "Failed to increment used idx");
 		return -EFAULT;
 	}
@@ -1429,7 +1440,8 @@ EXPORT_SYMBOL_GPL(vhost_add_used_n);
 
 static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
 {
-	__u16 old, new, event;
+	__u16 old, new;
+	__virtio16 event;
 	bool v;
 	/* Flush out used index updates. This is paired
 	 * with the barrier that the Guest executes when enabling
@@ -1441,12 +1453,12 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
 		return true;
 
 	if (!vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX)) {
-		__u16 flags;
+		__virtio16 flags;
 		if (__get_user(flags, &vq->avail->flags)) {
 			vq_err(vq, "Failed to get flags");
 			return true;
 		}
-		return !(flags & VRING_AVAIL_F_NO_INTERRUPT);
+		return !(flags & cpu_to_vhost16(vq, VRING_AVAIL_F_NO_INTERRUPT));
 	}
 	old = vq->signalled_used;
 	v = vq->signalled_used_valid;
@@ -1460,7 +1472,7 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
 		vq_err(vq, "Failed to get used event idx");
 		return true;
 	}
-	return vring_need_event(event, new, old);
+	return vring_need_event(vhost16_to_cpu(vq, event), new, old);
 }
 
 /* This actually signals the guest, using eventfd. */
@@ -1495,7 +1507,7 @@ EXPORT_SYMBOL_GPL(vhost_add_used_and_signal_n);
 /* OK, now we need to know about added descriptors. */
 bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
 {
-	u16 avail_idx;
+	__virtio16 avail_idx;
 	int r;
 
 	if (!(vq->used_flags & VRING_USED_F_NO_NOTIFY))
@@ -1526,7 +1538,7 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
 		return false;
 	}
 
-	return avail_idx != vq->avail_idx;
+	return vhost16_to_cpu(vq, avail_idx) != vq->avail_idx;
 }
 EXPORT_SYMBOL_GPL(vhost_enable_notify);
 
-- 
MST

^ permalink raw reply related

* [PATCH v8 32/50] vhost: switch to __get/__put_user exclusively
From: Michael S. Tsirkin @ 2014-12-01 16:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Miller, cornelia.huck, rusty, nab, pbonzini, thuth, dahi,
	kvm, virtualization, netdev
In-Reply-To: <1417449619-24896-1-git-send-email-mst@redhat.com>

Most places in vhost can use __get/__put_user rather than
get/put_user since addresses are pre-validated.
This should be good for performance, but this also
will help make code sparse-clean: get/put_user macros
don't play well with __virtioXX bitwise tags.
Switch to get/put_user to __ variants everywhere in vhost.
There's one exception - for consistency switch that
as well, and add an explicit access_ok check.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/vhost.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index c90f437..6a40837 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1038,6 +1038,7 @@ static int vhost_update_avail_event(struct vhost_virtqueue *vq, u16 avail_event)
 
 int vhost_init_used(struct vhost_virtqueue *vq)
 {
+	u16 last_used_idx;
 	int r;
 	if (!vq->private_data)
 		return 0;
@@ -1046,7 +1047,13 @@ int vhost_init_used(struct vhost_virtqueue *vq)
 	if (r)
 		return r;
 	vq->signalled_used_valid = false;
-	return get_user(vq->last_used_idx, &vq->used->idx);
+	if (!access_ok(VERIFY_READ, &vq->used->idx, sizeof vq->used->idx))
+		return -EFAULT;
+	r = __get_user(last_used_idx, &vq->used->idx);
+	if (r)
+		return r;
+	vq->last_used_idx = last_used_idx;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(vhost_init_used);
 
@@ -1404,7 +1411,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
 
 	/* Make sure buffer is written before we update index. */
 	smp_wmb();
-	if (put_user(vq->last_used_idx, &vq->used->idx)) {
+	if (__put_user(vq->last_used_idx, &vq->used->idx)) {
 		vq_err(vq, "Failed to increment used idx");
 		return -EFAULT;
 	}
@@ -1449,7 +1456,7 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
 	if (unlikely(!v))
 		return true;
 
-	if (get_user(event, vhost_used_event(vq))) {
+	if (__get_user(event, vhost_used_event(vq))) {
 		vq_err(vq, "Failed to get used event idx");
 		return true;
 	}
-- 
MST

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox