linux/drivers
Yann Droneaud f21519b23c IB/core: extended command: an improved infrastructure for uverbs commands
Commit 400dbc9658 ("IB/core: Infrastructure for extensible uverbs
commands") added an infrastructure for extensible uverbs commands
while later commit 436f2ad05a ("IB/core: Export ib_create/destroy_flow
through uverbs") exported ib_create_flow()/ib_destroy_flow() functions
using this new infrastructure.

According to the commit 400dbc9658, the purpose of this
infrastructure is to support passing around provider (eg. hardware)
specific buffers when userspace issue commands to the kernel, so that
it would be possible to extend uverbs (eg. core) buffers independently
from the provider buffers.

But the new kernel command function prototypes were not modified to
take advantage of this extension. This issue was exposed by Roland
Dreier in a previous review[1].

So the following patch is an attempt to a revised extensible command
infrastructure.

This improved extensible command infrastructure distinguish between
core (eg. legacy)'s command/response buffers from provider
(eg. hardware)'s command/response buffers: each extended command
implementing function is given a struct ib_udata to hold core
(eg. uverbs) input and output buffers, and another struct ib_udata to
hold the hw (eg. provider) input and output buffers.

Having those buffers identified separately make it easier to increase
one buffer to support extension without having to add some code to
guess the exact size of each command/response parts: This should make
the extended functions more reliable.

Additionally, instead of relying on command identifier being greater
than IB_USER_VERBS_CMD_THRESHOLD, the proposed infrastructure rely on
unused bits in command field: on the 32 bits provided by command
field, only 6 bits are really needed to encode the identifier of
commands currently supported by the kernel. (Even using only 6 bits
leaves room for about 23 new commands).

So this patch makes use of some high order bits in command field to
store flags, leaving enough room for more command identifiers than one
will ever need (eg. 256).

The new flags are used to specify if the command should be processed
as an extended one or a legacy one. While designing the new command
format, care was taken to make usage of flags itself extensible.

Using high order bits of the commands field ensure that newer
libibverbs on older kernel will properly fail when trying to call
extended commands. On the other hand, older libibverbs on newer kernel
will never be able to issue calls to extended commands.

The extended command header includes the optional response pointer so
that output buffer length and output buffer pointer are located
together in the command, allowing proper parameters checking. This
should make implementing functions easier and safer.

Additionally the extended header ensure 64bits alignment, while making
all sizes multiple of 8 bytes, extending the maximum buffer size:

                             legacy      extended

   Maximum command buffer:  256KBytes   1024KBytes (512KBytes + 512KBytes)
  Maximum response buffer:  256KBytes   1024KBytes (512KBytes + 512KBytes)

For the purpose of doing proper buffer size accounting, the headers
size are no more taken in account in "in_words".

One of the odds of the current extensible infrastructure, reading
twice the "legacy" command header, is fixed by removing the "legacy"
command header from the extended command header: they are processed as
two different parts of the command: memory is read once and
information are not duplicated: it's making clear that's an extended
command scheme and not a different command scheme.

The proposed scheme will format input (command) and output (response)
buffers this way:

- command:

  legacy header +
  extended header +
  command data (core + hw):

    +----------------------------------------+
    | flags     |   00      00    |  command |
    |        in_words    |   out_words       |
    +----------------------------------------+
    |                 response               |
    |                 response               |
    | provider_in_words | provider_out_words |
    |                 padding                |
    +----------------------------------------+
    |                                        |
    .              <uverbs input>            .
    .              (in_words * 8)            .
    |                                        |
    +----------------------------------------+
    |                                        |
    .             <provider input>           .
    .          (provider_in_words * 8)       .
    |                                        |
    +----------------------------------------+

- response, if present:

    +----------------------------------------+
    |                                        |
    .          <uverbs output space>         .
    .             (out_words * 8)            .
    |                                        |
    +----------------------------------------+
    |                                        |
    .         <provider output space>        .
    .         (provider_out_words * 8)       .
    |                                        |
    +----------------------------------------+

The overall design is to ensure that the extensible infrastructure is
itself extensible while begin more reliable with more input and bound
checking.

Note:

The unused field in the extended header would be perfect candidate to
hold the command "comp_mask" (eg. bit field used to handle
compatibility).  This was suggested by Roland Dreier in a previous
review[2].  But "comp_mask" field is likely to be present in the uverb
input and/or provider input, likewise for the response, as noted by
Matan Barak[3], so it doesn't make sense to put "comp_mask" in the
header.

[1]:
http://marc.info/?i=CAL1RGDWxmM17W2o_era24A-TTDeKyoL6u3NRu_=t_dhV_ZA9MA@mail.gmail.com

[2]:
http://marc.info/?i=CAL1RGDXJtrc849M6_XNZT5xO1+ybKtLWGq6yg6LhoSsKpsmkYA@mail.gmail.com

[3]:
http://marc.info/?i=525C1149.6000701@mellanox.com

Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Link: http://marc.info/?i=cover.1383773832.git.ydroneaud@opteya.com

[ Convert "ret ? ret : 0" to the equivalent "ret".  - Roland ]

Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-11-17 08:22:09 -08:00
..
accessibility
acpi ACPI / PM: Drop two functions that are not used any more 2013-10-17 15:44:48 +02:00
amba
ata Merge branch 'for-3.12-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata 2013-10-22 08:21:34 +01:00
atm atm: nicstar: fix regression made by previous patch 2013-09-15 22:18:55 -04:00
auxdisplay
base driver core: Release device_hotplug_lock when store_mem_state returns EINVAL 2013-10-16 18:42:41 -07:00
bcma bcma: make bcma_core_pci_{up,down}() callable from atomic context 2013-09-26 14:02:33 -04:00
block cciss: fix info leak in cciss_ioctl32_passthru() 2013-09-24 17:00:26 -07:00
bluetooth Bluetooth: btusb: Add support for Belkin F8065bf 2013-09-23 17:44:25 -03:00
bus bus: mvebu-mbus: Fix optional pcie-mem/io-aperture properties 2013-10-01 17:04:17 +00:00
cdrom
char A small fix for Xen on x86_32 and a build fix for xen-tpmfront on arm64. 2013-10-15 16:22:11 -07:00
clk The common clk framework changes for 3.12 are dominated by clock driver 2013-09-09 15:49:04 -07:00
clocksource clocksource: em_sti: Set cpu_possible_mask to fix SMP broadcast 2013-09-26 02:31:04 +02:00
connector connector: use 'size' everywhere in cn_netlink_send() 2013-10-02 16:03:50 -04:00
cpufreq acpi-cpufreq: Fail initialization if driver cannot be registered 2013-10-25 16:22:47 +02:00
cpuidle ACPI and power management fixes for 3.12-rc1 2013-09-12 11:22:45 -07:00
crypto Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux 2013-09-07 12:53:35 +10:00
dca
devfreq
dio
dma dmaengine: edma: fix another memory leak 2013-10-24 22:17:50 +05:30
edac Merge git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile 2013-09-06 11:14:33 -07:00
eisa
extcon Driver core patches for 3.12-rc1 2013-09-03 11:37:15 -07:00
firewire firewire: ohci: Fix deadlock at bus reset 2013-08-29 22:35:05 +02:00
firmware firmware/dmi_scan: drop OOM messages 2013-09-11 15:58:51 -07:00
fmc
gpio gpiolib: let gpiod_request() return -EPROBE_DEFER 2013-10-11 16:31:54 +02:00
gpu Merge branch 'drm-fixes-3.12' of git://people.freedesktop.org/~agd5f/linux into drm-fixes 2013-10-22 07:35:17 +01:00
hid HID: wiimote: add LEGO-wiimote VID 2013-10-21 13:39:37 +02:00
hsi
hv Revert "Drivers: hv: vmbus: Fix a bug in channel rescind code" 2013-10-17 09:30:10 -07:00
hwmon hwmon: (applesmc) Always read until end of data 2013-10-09 09:48:55 -07:00
hwspinlock
i2c i2c: i2c-mux-pinctrl: use deferred probe when adapter not found 2013-10-10 10:22:35 +02:00
ide ide: sgiioc4: Staticize ioc4_ide_attach_one() 2013-09-05 15:21:30 -04:00
idle
iio iio:buffer: Free active scan mask in iio_disable_all_buffers() 2013-10-15 19:26:43 +01:00
infiniband IB/core: extended command: an improved infrastructure for uverbs commands 2013-11-17 08:22:09 -08:00
input Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2013-09-15 07:13:39 -04:00
iommu x86, build, pci: Fix PCI_MSI build on !SMP 2013-10-04 10:43:34 -07:00
ipack
irqchip ARM: SoC late changes for v3.12 2013-09-09 16:35:29 -07:00
isdn isdn: hfcpci_softirq: get func return to suppress compiler warning 2013-09-15 22:27:04 -04:00
leds Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds 2013-09-12 11:35:33 -07:00
lguest lguest: fix guest kernel stack overflow when TF bit set. 2013-09-06 08:09:27 +09:30
macintosh
mailbox mailbox: remove unnecessary platform_set_drvdata() 2013-09-18 12:02:00 -07:00
md raid5: avoid finding "discard" stripe 2013-10-24 13:00:24 +11:00
media [media] saa7134: Fix crash when device is closed before streamoff 2013-10-14 06:37:00 -03:00
memory ARM: SoC platform changes for 3.12 2013-09-06 13:30:06 -07:00
memstick memstick: add support for legacy memorysticks 2013-09-11 15:59:35 -07:00
message
mfd Remove GENERIC_HARDIRQ config option 2013-09-13 15:09:52 +02:00
misc mei: cancel stall timers in mei_reset 2013-09-26 13:56:53 -07:00
mmc ARM: shmobile: update SDHI DT compatibility string to the <unit>-<soc> format 2013-09-21 09:55:32 -07:00
mtd mtd: gpmi: fix ECC regression 2013-10-25 10:09:43 -07:00
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2013-10-23 07:47:42 +01:00
nfc
ntb ntb: clean up unnecessary MSI/MSI-X capability find 2013-09-05 11:08:01 -07:00
nubus
of Revert "drivers: of: add initialization code for dma reserved memory" 2013-10-15 09:26:07 +01:00
oprofile oprofile: get rid of pointless forward declarations of struct super_block 2013-09-03 22:52:48 -04:00
parisc PCI changes for the v3.12 merge window: 2013-09-03 16:24:35 -07:00
parport drivers: parport: Kconfig: exclude h8300 for PARPORT_PC 2013-08-30 12:08:04 -07:00
pci ACPI / hotplug / PCI: Drop WARN_ON() from acpiphp_enumerate_slots() 2013-10-12 01:49:48 +02:00
pcmcia
pinctrl pinctrl: palmas: do not abort pin configuration for BIAS_DEFAULT 2013-09-27 16:22:43 +02:00
platform platform/x86: fix asus-wmi build error 2013-10-23 07:57:57 +01:00
pnp pnp: change pnp bus pm_ops to invoke pnp driver dev_pm_ops if specified 2013-09-11 15:58:15 -07:00
power Remove GENERIC_HARDIRQ config option 2013-09-13 15:09:52 +02:00
pps Remove GENERIC_HARDIRQ config option 2013-09-13 15:09:52 +02:00
ps3
ptp
pwm ARM: SoC cleanups for 3.12 2013-09-06 13:21:16 -07:00
rapidio
regulator Merge remote-tracking branch 'regulator/fix/wm8350' into regulator-linus 2013-09-30 12:04:33 +01:00
remoteproc
reset
rpmsg
rtc rtc: simplify devm_request_mem_region/devm_ioremap 2013-09-11 15:58:59 -07:00
s390 s390/time: correct use of store clock fast 2013-10-22 09:16:40 +02:00
sbus
scsi [SCSI] sd: call blk_pm_runtime_init before add_disk 2013-10-23 14:09:18 +01:00
sfi
sh
sn
spi Merge remote-tracking branch 'spi/fix/s3c64xx' into spi-linus 2013-10-07 14:51:59 +01:00
ssb
staging Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2013-10-23 07:52:36 +01:00
target target/pscsi: fix return value check 2013-10-25 10:42:09 -07:00
tc
thermal Merge branch 'x86_pkg_temp' of .git into for-rc 2013-10-21 11:26:45 +08:00
tty serial: vt8500: add missing braces 2013-10-16 13:22:16 -07:00
uio Driver core patches for 3.12-rc1 2013-09-03 11:37:15 -07:00
usb usb: misc: usb3503: Fix compile error due to incorrect regmap depedency 2013-10-16 13:52:16 -07:00
uwb
vfio VFIO: vfio_iommu_type1: fix bug caused by break in nested loop 2013-10-11 10:40:46 -06:00
vhost vhost/scsi: Fix incorrect usage of get_user_pages_fast write parameter 2013-10-25 11:03:34 -07:00
video video: mxsfb: Add missing break 2013-09-26 15:33:23 +03:00
virt
virtio virtio_pci: pm: Use CONFIG_PM_SLEEP instead of CONFIG_PM 2013-09-09 10:02:53 +09:30
vlynq
vme vme: vme_ca91cx42.c: fix to pass correct device identity to free_irq() 2013-08-27 21:49:26 -07:00
w1 w1 - call request_module with w1 master mutex unlocked 2013-10-07 00:12:14 -07:00
watchdog watchdog: sunxi: Fix section mismatch 2013-10-13 20:02:03 +02:00
xen Bug-fixes: 2013-09-25 15:50:53 -07:00
zorro
Kconfig
Makefile