aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-12-15 21:13:41 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-15 21:13:41 -0500
commited3c5a0be38c180ab0899a0f52719e81f36b87a1 (patch)
tree684eb66d1e8513b4584c680e157f3887c04c58ba
parent66d466722c39f663b2bbeb44ba4f9419a548fa23 (diff)
parent6bdf1e0efb04a1716373646cb6f35b73addca492 (diff)
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: "virtio, vhost: new device, fixes, speedups This includes the new virtio crypto device, and fixes all over the place. In particular enabling endian-ness checks for sparse builds found some bugs which this fixes. And it appears that everyone is in agreement that disabling endian-ness sparse checks shouldn't be necessary any longer. So this enables them for everyone, and drops the __CHECK_ENDIAN__ and __bitwise__ APIs. IRQ handling in virtio has been refactored somewhat, the larger switch to IRQ_SHARED will have to wait as it proved too aggressive" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (34 commits) Makefile: drop -D__CHECK_ENDIAN__ from cflags fs/logfs: drop __CHECK_ENDIAN__ Documentation/sparse: drop __CHECK_ENDIAN__ linux: drop __bitwise__ everywhere checkpatch: replace __bitwise__ with __bitwise Documentation/sparse: drop __bitwise__ tools: enable endian checks for all sparse builds linux/types.h: enable endian checks for all sparse builds virtio_mmio: Set dev.release() to avoid warning vhost: remove unused feature bit virtio_ring: fix description of virtqueue_get_buf vhost/scsi: Remove unused but set variable tools/virtio: use {READ,WRITE}_ONCE() in uaccess.h vringh: kill off ACCESS_ONCE() tools/virtio: fix READ_ONCE() crypto: add virtio-crypto driver vhost: cache used event for better performance vsock: lookup and setup guest_cid inside vhost_vsock_lock virtio_pci: split vp_try_to_find_vqs into INTx and MSI-X variants virtio_pci: merge vp_free_vectors into vp_del_vqs ...
-rw-r--r--Documentation/dev-tools/sparse.rst14
-rw-r--r--Documentation/translations/zh_CN/sparse.txt7
-rw-r--r--MAINTAINERS9
-rw-r--r--arch/arm/plat-samsung/include/plat/gpio-cfg.h2
-rw-r--r--drivers/bluetooth/Makefile2
-rw-r--r--drivers/char/virtio_console.c14
-rw-r--r--drivers/crypto/Kconfig2
-rw-r--r--drivers/crypto/Makefile1
-rw-r--r--drivers/crypto/virtio/Kconfig10
-rw-r--r--drivers/crypto/virtio/Makefile5
-rw-r--r--drivers/crypto/virtio/virtio_crypto_algs.c540
-rw-r--r--drivers/crypto/virtio/virtio_crypto_common.h128
-rw-r--r--drivers/crypto/virtio/virtio_crypto_core.c476
-rw-r--r--drivers/crypto/virtio/virtio_crypto_mgr.c264
-rw-r--r--drivers/gpu/drm/virtio/virtgpu_plane.c4
-rw-r--r--drivers/gpu/drm/virtio/virtgpu_vq.c6
-rw-r--r--drivers/md/dm-cache-block-types.h6
-rw-r--r--drivers/net/can/Makefile1
-rw-r--r--drivers/net/ethernet/altera/Makefile1
-rw-r--r--drivers/net/ethernet/atheros/alx/Makefile1
-rw-r--r--drivers/net/ethernet/freescale/Makefile2
-rw-r--r--drivers/net/ethernet/sun/sunhme.h2
-rw-r--r--drivers/net/wireless/ath/Makefile2
-rw-r--r--drivers/net/wireless/ath/wil6210/Makefile2
-rw-r--r--drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile2
-rw-r--r--drivers/net/wireless/broadcom/brcm80211/brcmsmac/Makefile1
-rw-r--r--drivers/net/wireless/intel/iwlegacy/Makefile2
-rw-r--r--drivers/net/wireless/intel/iwlwifi/Makefile2
-rw-r--r--drivers/net/wireless/intel/iwlwifi/dvm/Makefile2
-rw-r--r--drivers/net/wireless/intel/iwlwifi/iwl-fw-file.h4
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/Makefile2
-rw-r--r--drivers/net/wireless/intersil/orinoco/Makefile3
-rw-r--r--drivers/net/wireless/mediatek/mt7601u/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8188ee/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192c/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192ce/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192cu/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192de/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192ee/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192se/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8723ae/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8723be/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8723com/Makefile2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8821ae/Makefile2
-rw-r--r--drivers/net/wireless/ti/wl1251/Makefile2
-rw-r--r--drivers/net/wireless/ti/wlcore/Makefile2
-rw-r--r--drivers/staging/rtl8188eu/Makefile2
-rw-r--r--drivers/staging/rtl8192e/Makefile2
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/Makefile2
-rw-r--r--drivers/vhost/scsi.c2
-rw-r--r--drivers/vhost/vhost.c40
-rw-r--r--drivers/vhost/vhost.h3
-rw-r--r--drivers/vhost/vringh.c5
-rw-r--r--drivers/vhost/vsock.c25
-rw-r--r--drivers/virtio/virtio_mmio.c2
-rw-r--r--drivers/virtio/virtio_pci_common.c201
-rw-r--r--drivers/virtio/virtio_pci_common.h1
-rw-r--r--drivers/virtio/virtio_pci_modern.c8
-rw-r--r--drivers/virtio/virtio_ring.c6
-rw-r--r--fs/logfs/logfs.h4
-rw-r--r--include/linux/mmzone.h2
-rw-r--r--include/linux/serial_core.h4
-rw-r--r--include/linux/types.h4
-rw-r--r--include/scsi/iscsi_proto.h2
-rw-r--r--include/target/target_core_base.h2
-rw-r--r--include/uapi/linux/Kbuild1
-rw-r--r--include/uapi/linux/types.h4
-rw-r--r--include/uapi/linux/vhost.h2
-rw-r--r--include/uapi/linux/virtio_crypto.h450
-rw-r--r--include/uapi/linux/virtio_ids.h1
-rw-r--r--include/uapi/linux/virtio_types.h6
-rw-r--r--net/bluetooth/Makefile2
-rw-r--r--net/ieee802154/6lowpan/6lowpan_i.h2
-rw-r--r--net/ieee802154/Makefile2
-rw-r--r--net/mac80211/Makefile2
-rw-r--r--net/mac80211/ieee80211_i.h4
-rw-r--r--net/mac802154/Makefile2
-rw-r--r--net/vmw_vsock/virtio_transport.c2
-rw-r--r--net/vmw_vsock/virtio_transport_common.c17
-rw-r--r--net/wireless/Makefile2
-rwxr-xr-xscripts/checkpatch.pl4
-rw-r--r--tools/include/linux/types.h4
-rw-r--r--tools/virtio/linux/compiler.h2
-rw-r--r--tools/virtio/linux/uaccess.h9
86 files changed, 2106 insertions, 280 deletions
diff --git a/Documentation/dev-tools/sparse.rst b/Documentation/dev-tools/sparse.rst
index 8c250e8a2105..78aa00a604a0 100644
--- a/Documentation/dev-tools/sparse.rst
+++ b/Documentation/dev-tools/sparse.rst
@@ -51,13 +51,6 @@ sure that bitwise types don't get mixed up (little-endian vs big-endian
51vs cpu-endian vs whatever), and there the constant "0" really _is_ 51vs cpu-endian vs whatever), and there the constant "0" really _is_
52special. 52special.
53 53
54__bitwise__ - to be used for relatively compact stuff (gfp_t, etc.) that
55is mostly warning-free and is supposed to stay that way. Warnings will
56be generated without __CHECK_ENDIAN__.
57
58__bitwise - noisy stuff; in particular, __le*/__be* are that. We really
59don't want to drown in noise unless we'd explicitly asked for it.
60
61Using sparse for lock checking 54Using sparse for lock checking
62------------------------------ 55------------------------------
63 56
@@ -109,9 +102,4 @@ be recompiled or not. The latter is a fast way to check the whole tree if you
109have already built it. 102have already built it.
110 103
111The optional make variable CF can be used to pass arguments to sparse. The 104The optional make variable CF can be used to pass arguments to sparse. The
112build system passes -Wbitwise to sparse automatically. To perform endianness 105build system passes -Wbitwise to sparse automatically.
113checks, you may define __CHECK_ENDIAN__::
114
115 make C=2 CF="-D__CHECK_ENDIAN__"
116
117These checks are disabled by default as they generate a host of warnings.
diff --git a/Documentation/translations/zh_CN/sparse.txt b/Documentation/translations/zh_CN/sparse.txt
index cc144e581515..e41dc940e162 100644
--- a/Documentation/translations/zh_CN/sparse.txt
+++ b/Documentation/translations/zh_CN/sparse.txt
@@ -92,9 +92,4 @@ DaveJ 把每小时自动生成的 git 源码树 tar 包放在以下地址:
92如果你已经编译了内核,用后一种方式可以很快地检查整个源码树。 92如果你已经编译了内核,用后一种方式可以很快地检查整个源码树。
93 93
94make 的可选变量 CHECKFLAGS 可以用来向 sparse 工具传递参数。编译系统会自 94make 的可选变量 CHECKFLAGS 可以用来向 sparse 工具传递参数。编译系统会自
95动向 sparse 工具传递 -Wbitwise 参数。你可以定义 __CHECK_ENDIAN__ 来进行 95动向 sparse 工具传递 -Wbitwise 参数。
96大小尾检查。
97
98 make C=2 CHECKFLAGS="-D__CHECK_ENDIAN__"
99
100这些检查默认都是被关闭的,因为他们通常会产生大量的警告。
diff --git a/MAINTAINERS b/MAINTAINERS
index 7dc766390b73..299ee500f8fd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13013,6 +13013,7 @@ F: drivers/net/virtio_net.c
13013F: drivers/block/virtio_blk.c 13013F: drivers/block/virtio_blk.c
13014F: include/linux/virtio_*.h 13014F: include/linux/virtio_*.h
13015F: include/uapi/linux/virtio_*.h 13015F: include/uapi/linux/virtio_*.h
13016F: drivers/crypto/virtio/
13016 13017
13017VIRTIO DRIVERS FOR S390 13018VIRTIO DRIVERS FOR S390
13018M: Christian Borntraeger <borntraeger@de.ibm.com> 13019M: Christian Borntraeger <borntraeger@de.ibm.com>
@@ -13049,6 +13050,14 @@ S: Maintained
13049F: drivers/virtio/virtio_input.c 13050F: drivers/virtio/virtio_input.c
13050F: include/uapi/linux/virtio_input.h 13051F: include/uapi/linux/virtio_input.h
13051 13052
13053VIRTIO CRYPTO DRIVER
13054M: Gonglei <arei.gonglei@huawei.com>
13055L: virtualization@lists.linux-foundation.org
13056L: linux-crypto@vger.kernel.org
13057S: Maintained
13058F: drivers/crypto/virtio/
13059F: include/uapi/linux/virtio_crypto.h
13060
13052VIA RHINE NETWORK DRIVER 13061VIA RHINE NETWORK DRIVER
13053S: Orphan 13062S: Orphan
13054F: drivers/net/ethernet/via/via-rhine.c 13063F: drivers/net/ethernet/via/via-rhine.c
diff --git a/arch/arm/plat-samsung/include/plat/gpio-cfg.h b/arch/arm/plat-samsung/include/plat/gpio-cfg.h
index 21391faab068..e55d1f597db8 100644
--- a/arch/arm/plat-samsung/include/plat/gpio-cfg.h
+++ b/arch/arm/plat-samsung/include/plat/gpio-cfg.h
@@ -26,7 +26,7 @@
26 26
27#include <linux/types.h> 27#include <linux/types.h>
28 28
29typedef unsigned int __bitwise__ samsung_gpio_pull_t; 29typedef unsigned int __bitwise samsung_gpio_pull_t;
30 30
31/* forward declaration if gpio-core.h hasn't been included */ 31/* forward declaration if gpio-core.h hasn't been included */
32struct samsung_gpio_chip; 32struct samsung_gpio_chip;
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index b1fc29a697b7..80627187c8b6 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -40,5 +40,3 @@ hci_uart-$(CONFIG_BT_HCIUART_QCA) += hci_qca.o
40hci_uart-$(CONFIG_BT_HCIUART_AG6XX) += hci_ag6xx.o 40hci_uart-$(CONFIG_BT_HCIUART_AG6XX) += hci_ag6xx.o
41hci_uart-$(CONFIG_BT_HCIUART_MRVL) += hci_mrvl.o 41hci_uart-$(CONFIG_BT_HCIUART_MRVL) += hci_mrvl.o
42hci_uart-objs := $(hci_uart-y) 42hci_uart-objs := $(hci_uart-y)
43
44ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 5649234b7316..8b00e79c2683 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -152,8 +152,8 @@ struct ports_device {
152 spinlock_t c_ivq_lock; 152 spinlock_t c_ivq_lock;
153 spinlock_t c_ovq_lock; 153 spinlock_t c_ovq_lock;
154 154
155 /* The current config space is stored here */ 155 /* max. number of ports this device can hold */
156 struct virtio_console_config config; 156 u32 max_nr_ports;
157 157
158 /* The virtio device we're associated with */ 158 /* The virtio device we're associated with */
159 struct virtio_device *vdev; 159 struct virtio_device *vdev;
@@ -1649,11 +1649,11 @@ static void handle_control_message(struct virtio_device *vdev,
1649 break; 1649 break;
1650 } 1650 }
1651 if (virtio32_to_cpu(vdev, cpkt->id) >= 1651 if (virtio32_to_cpu(vdev, cpkt->id) >=
1652 portdev->config.max_nr_ports) { 1652 portdev->max_nr_ports) {
1653 dev_warn(&portdev->vdev->dev, 1653 dev_warn(&portdev->vdev->dev,
1654 "Request for adding port with " 1654 "Request for adding port with "
1655 "out-of-bound id %u, max. supported id: %u\n", 1655 "out-of-bound id %u, max. supported id: %u\n",
1656 cpkt->id, portdev->config.max_nr_ports - 1); 1656 cpkt->id, portdev->max_nr_ports - 1);
1657 break; 1657 break;
1658 } 1658 }
1659 add_port(portdev, virtio32_to_cpu(vdev, cpkt->id)); 1659 add_port(portdev, virtio32_to_cpu(vdev, cpkt->id));
@@ -1894,7 +1894,7 @@ static int init_vqs(struct ports_device *portdev)
1894 u32 i, j, nr_ports, nr_queues; 1894 u32 i, j, nr_ports, nr_queues;
1895 int err; 1895 int err;
1896 1896
1897 nr_ports = portdev->config.max_nr_ports; 1897 nr_ports = portdev->max_nr_ports;
1898 nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2; 1898 nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
1899 1899
1900 vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL); 1900 vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
@@ -2047,13 +2047,13 @@ static int virtcons_probe(struct virtio_device *vdev)
2047 } 2047 }
2048 2048
2049 multiport = false; 2049 multiport = false;
2050 portdev->config.max_nr_ports = 1; 2050 portdev->max_nr_ports = 1;
2051 2051
2052 /* Don't test MULTIPORT at all if we're rproc: not a valid feature! */ 2052 /* Don't test MULTIPORT at all if we're rproc: not a valid feature! */
2053 if (!is_rproc_serial(vdev) && 2053 if (!is_rproc_serial(vdev) &&
2054 virtio_cread_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT, 2054 virtio_cread_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT,
2055 struct virtio_console_config, max_nr_ports, 2055 struct virtio_console_config, max_nr_ports,
2056 &portdev->config.max_nr_ports) == 0) { 2056 &portdev->max_nr_ports) == 0) {
2057 multiport = true; 2057 multiport = true;
2058 } 2058 }
2059 2059
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 4d2b81f2b223..79564785ae30 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -555,4 +555,6 @@ config CRYPTO_DEV_ROCKCHIP
555 555
556source "drivers/crypto/chelsio/Kconfig" 556source "drivers/crypto/chelsio/Kconfig"
557 557
558source "drivers/crypto/virtio/Kconfig"
559
558endif # CRYPTO_HW 560endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index ad7250fa1348..bc53cb833a06 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -32,3 +32,4 @@ obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
32obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sunxi-ss/ 32obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sunxi-ss/
33obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/ 33obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/
34obj-$(CONFIG_CRYPTO_DEV_CHELSIO) += chelsio/ 34obj-$(CONFIG_CRYPTO_DEV_CHELSIO) += chelsio/
35obj-$(CONFIG_CRYPTO_DEV_VIRTIO) += virtio/
diff --git a/drivers/crypto/virtio/Kconfig b/drivers/crypto/virtio/Kconfig
new file mode 100644
index 000000000000..d80f73366ae2
--- /dev/null
+++ b/drivers/crypto/virtio/Kconfig
@@ -0,0 +1,10 @@
1config CRYPTO_DEV_VIRTIO
2 tristate "VirtIO crypto driver"
3 depends on VIRTIO
4 select CRYPTO_AEAD
5 select CRYPTO_AUTHENC
6 select CRYPTO_BLKCIPHER
7 default m
8 help
9 This driver provides support for virtio crypto device. If you
10 choose 'M' here, this module will be called virtio_crypto.
diff --git a/drivers/crypto/virtio/Makefile b/drivers/crypto/virtio/Makefile
new file mode 100644
index 000000000000..dd342c947ff9
--- /dev/null
+++ b/drivers/crypto/virtio/Makefile
@@ -0,0 +1,5 @@
1obj-$(CONFIG_CRYPTO_DEV_VIRTIO) += virtio_crypto.o
2virtio_crypto-objs := \
3 virtio_crypto_algs.o \
4 virtio_crypto_mgr.o \
5 virtio_crypto_core.o
diff --git a/drivers/crypto/virtio/virtio_crypto_algs.c b/drivers/crypto/virtio/virtio_crypto_algs.c
new file mode 100644
index 000000000000..c2374df9abae
--- /dev/null
+++ b/drivers/crypto/virtio/virtio_crypto_algs.c
@@ -0,0 +1,540 @@
1 /* Algorithms supported by virtio crypto device
2 *
3 * Authors: Gonglei <arei.gonglei@huawei.com>
4 *
5 * Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/scatterlist.h>
22#include <crypto/algapi.h>
23#include <linux/err.h>
24#include <crypto/scatterwalk.h>
25#include <linux/atomic.h>
26
27#include <uapi/linux/virtio_crypto.h>
28#include "virtio_crypto_common.h"
29
30/*
31 * The algs_lock protects the below global virtio_crypto_active_devs
32 * and crypto algorithms registion.
33 */
34static DEFINE_MUTEX(algs_lock);
35static unsigned int virtio_crypto_active_devs;
36
37static u64 virtio_crypto_alg_sg_nents_length(struct scatterlist *sg)
38{
39 u64 total = 0;
40
41 for (total = 0; sg; sg = sg_next(sg))
42 total += sg->length;
43
44 return total;
45}
46
47static int
48virtio_crypto_alg_validate_key(int key_len, uint32_t *alg)
49{
50 switch (key_len) {
51 case AES_KEYSIZE_128:
52 case AES_KEYSIZE_192:
53 case AES_KEYSIZE_256:
54 *alg = VIRTIO_CRYPTO_CIPHER_AES_CBC;
55 break;
56 default:
57 pr_err("virtio_crypto: Unsupported key length: %d\n",
58 key_len);
59 return -EINVAL;
60 }
61 return 0;
62}
63
64static int virtio_crypto_alg_ablkcipher_init_session(
65 struct virtio_crypto_ablkcipher_ctx *ctx,
66 uint32_t alg, const uint8_t *key,
67 unsigned int keylen,
68 int encrypt)
69{
70 struct scatterlist outhdr, key_sg, inhdr, *sgs[3];
71 unsigned int tmp;
72 struct virtio_crypto *vcrypto = ctx->vcrypto;
73 int op = encrypt ? VIRTIO_CRYPTO_OP_ENCRYPT : VIRTIO_CRYPTO_OP_DECRYPT;
74 int err;
75 unsigned int num_out = 0, num_in = 0;
76
77 /*
78 * Avoid to do DMA from the stack, switch to using
79 * dynamically-allocated for the key
80 */
81 uint8_t *cipher_key = kmalloc(keylen, GFP_ATOMIC);
82
83 if (!cipher_key)
84 return -ENOMEM;
85
86 memcpy(cipher_key, key, keylen);
87
88 spin_lock(&vcrypto->ctrl_lock);
89 /* Pad ctrl header */
90 vcrypto->ctrl.header.opcode =
91 cpu_to_le32(VIRTIO_CRYPTO_CIPHER_CREATE_SESSION);
92 vcrypto->ctrl.header.algo = cpu_to_le32(alg);
93 /* Set the default dataqueue id to 0 */
94 vcrypto->ctrl.header.queue_id = 0;
95
96 vcrypto->input.status = cpu_to_le32(VIRTIO_CRYPTO_ERR);
97 /* Pad cipher's parameters */
98 vcrypto->ctrl.u.sym_create_session.op_type =
99 cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER);
100 vcrypto->ctrl.u.sym_create_session.u.cipher.para.algo =
101 vcrypto->ctrl.header.algo;
102 vcrypto->ctrl.u.sym_create_session.u.cipher.para.keylen =
103 cpu_to_le32(keylen);
104 vcrypto->ctrl.u.sym_create_session.u.cipher.para.op =
105 cpu_to_le32(op);
106
107 sg_init_one(&outhdr, &vcrypto->ctrl, sizeof(vcrypto->ctrl));
108 sgs[num_out++] = &outhdr;
109
110 /* Set key */
111 sg_init_one(&key_sg, cipher_key, keylen);
112 sgs[num_out++] = &key_sg;
113
114 /* Return status and session id back */
115 sg_init_one(&inhdr, &vcrypto->input, sizeof(vcrypto->input));
116 sgs[num_out + num_in++] = &inhdr;
117
118 err = virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out,
119 num_in, vcrypto, GFP_ATOMIC);
120 if (err < 0) {
121 spin_unlock(&vcrypto->ctrl_lock);
122 kzfree(cipher_key);
123 return err;
124 }
125 virtqueue_kick(vcrypto->ctrl_vq);
126
127 /*
128 * Trapping into the hypervisor, so the request should be
129 * handled immediately.
130 */
131 while (!virtqueue_get_buf(vcrypto->ctrl_vq, &tmp) &&
132 !virtqueue_is_broken(vcrypto->ctrl_vq))
133 cpu_relax();
134
135 if (le32_to_cpu(vcrypto->input.status) != VIRTIO_CRYPTO_OK) {
136 spin_unlock(&vcrypto->ctrl_lock);
137 pr_err("virtio_crypto: Create session failed status: %u\n",
138 le32_to_cpu(vcrypto->input.status));
139 kzfree(cipher_key);
140 return -EINVAL;
141 }
142
143 if (encrypt)
144 ctx->enc_sess_info.session_id =
145 le64_to_cpu(vcrypto->input.session_id);
146 else
147 ctx->dec_sess_info.session_id =
148 le64_to_cpu(vcrypto->input.session_id);
149
150 spin_unlock(&vcrypto->ctrl_lock);
151
152 kzfree(cipher_key);
153 return 0;
154}
155
156static int virtio_crypto_alg_ablkcipher_close_session(
157 struct virtio_crypto_ablkcipher_ctx *ctx,
158 int encrypt)
159{
160 struct scatterlist outhdr, status_sg, *sgs[2];
161 unsigned int tmp;
162 struct virtio_crypto_destroy_session_req *destroy_session;
163 struct virtio_crypto *vcrypto = ctx->vcrypto;
164 int err;
165 unsigned int num_out = 0, num_in = 0;
166
167 spin_lock(&vcrypto->ctrl_lock);
168 vcrypto->ctrl_status.status = VIRTIO_CRYPTO_ERR;
169 /* Pad ctrl header */
170 vcrypto->ctrl.header.opcode =
171 cpu_to_le32(VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION);
172 /* Set the default virtqueue id to 0 */
173 vcrypto->ctrl.header.queue_id = 0;
174
175 destroy_session = &vcrypto->ctrl.u.destroy_session;
176
177 if (encrypt)
178 destroy_session->session_id =
179 cpu_to_le64(ctx->enc_sess_info.session_id);
180 else
181 destroy_session->session_id =
182 cpu_to_le64(ctx->dec_sess_info.session_id);
183
184 sg_init_one(&outhdr, &vcrypto->ctrl, sizeof(vcrypto->ctrl));
185 sgs[num_out++] = &outhdr;
186
187 /* Return status and session id back */
188 sg_init_one(&status_sg, &vcrypto->ctrl_status.status,
189 sizeof(vcrypto->ctrl_status.status));
190 sgs[num_out + num_in++] = &status_sg;
191
192 err = virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out,
193 num_in, vcrypto, GFP_ATOMIC);
194 if (err < 0) {
195 spin_unlock(&vcrypto->ctrl_lock);
196 return err;
197 }
198 virtqueue_kick(vcrypto->ctrl_vq);
199
200 while (!virtqueue_get_buf(vcrypto->ctrl_vq, &tmp) &&
201 !virtqueue_is_broken(vcrypto->ctrl_vq))
202 cpu_relax();
203
204 if (vcrypto->ctrl_status.status != VIRTIO_CRYPTO_OK) {
205 spin_unlock(&vcrypto->ctrl_lock);
206 pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%llx\n",
207 vcrypto->ctrl_status.status,
208 destroy_session->session_id);
209
210 return -EINVAL;
211 }
212 spin_unlock(&vcrypto->ctrl_lock);
213
214 return 0;
215}
216
217static int virtio_crypto_alg_ablkcipher_init_sessions(
218 struct virtio_crypto_ablkcipher_ctx *ctx,
219 const uint8_t *key, unsigned int keylen)
220{
221 uint32_t alg;
222 int ret;
223 struct virtio_crypto *vcrypto = ctx->vcrypto;
224
225 if (keylen > vcrypto->max_cipher_key_len) {
226 pr_err("virtio_crypto: the key is too long\n");
227 goto bad_key;
228 }
229
230 if (virtio_crypto_alg_validate_key(keylen, &alg))
231 goto bad_key;
232
233 /* Create encryption session */
234 ret = virtio_crypto_alg_ablkcipher_init_session(ctx,
235 alg, key, keylen, 1);
236 if (ret)
237 return ret;
238 /* Create decryption session */
239 ret = virtio_crypto_alg_ablkcipher_init_session(ctx,
240 alg, key, keylen, 0);
241 if (ret) {
242 virtio_crypto_alg_ablkcipher_close_session(ctx, 1);
243 return ret;
244 }
245 return 0;
246
247bad_key:
248 crypto_tfm_set_flags(ctx->tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
249 return -EINVAL;
250}
251
252/* Note: kernel crypto API realization */
253static int virtio_crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
254 const uint8_t *key,
255 unsigned int keylen)
256{
257 struct virtio_crypto_ablkcipher_ctx *ctx = crypto_ablkcipher_ctx(tfm);
258 int ret;
259
260 if (!ctx->vcrypto) {
261 /* New key */
262 int node = virtio_crypto_get_current_node();
263 struct virtio_crypto *vcrypto =
264 virtcrypto_get_dev_node(node);
265 if (!vcrypto) {
266 pr_err("virtio_crypto: Could not find a virtio device in the system");
267 return -ENODEV;
268 }
269
270 ctx->vcrypto = vcrypto;
271 } else {
272 /* Rekeying, we should close the created sessions previously */
273 virtio_crypto_alg_ablkcipher_close_session(ctx, 1);
274 virtio_crypto_alg_ablkcipher_close_session(ctx, 0);
275 }
276
277 ret = virtio_crypto_alg_ablkcipher_init_sessions(ctx, key, keylen);
278 if (ret) {
279 virtcrypto_dev_put(ctx->vcrypto);
280 ctx->vcrypto = NULL;
281
282 return ret;
283 }
284
285 return 0;
286}
287
288static int
289__virtio_crypto_ablkcipher_do_req(struct virtio_crypto_request *vc_req,
290 struct ablkcipher_request *req,
291 struct data_queue *data_vq,
292 __u8 op)
293{
294 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
295 unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
296 struct virtio_crypto_ablkcipher_ctx *ctx = vc_req->ablkcipher_ctx;
297 struct virtio_crypto *vcrypto = ctx->vcrypto;
298 struct virtio_crypto_op_data_req *req_data;
299 int src_nents, dst_nents;
300 int err;
301 unsigned long flags;
302 struct scatterlist outhdr, iv_sg, status_sg, **sgs;
303 int i;
304 u64 dst_len;
305 unsigned int num_out = 0, num_in = 0;
306 int sg_total;
307 uint8_t *iv;
308
309 src_nents = sg_nents_for_len(req->src, req->nbytes);
310 dst_nents = sg_nents(req->dst);
311
312 pr_debug("virtio_crypto: Number of sgs (src_nents: %d, dst_nents: %d)\n",
313 src_nents, dst_nents);
314
315 /* Why 3? outhdr + iv + inhdr */
316 sg_total = src_nents + dst_nents + 3;
317 sgs = kzalloc_node(sg_total * sizeof(*sgs), GFP_ATOMIC,
318 dev_to_node(&vcrypto->vdev->dev));
319 if (!sgs)
320 return -ENOMEM;
321
322 req_data = kzalloc_node(sizeof(*req_data), GFP_ATOMIC,
323 dev_to_node(&vcrypto->vdev->dev));
324 if (!req_data) {
325 kfree(sgs);
326 return -ENOMEM;
327 }
328
329 vc_req->req_data = req_data;
330 vc_req->type = VIRTIO_CRYPTO_SYM_OP_CIPHER;
331 /* Head of operation */
332 if (op) {
333 req_data->header.session_id =
334 cpu_to_le64(ctx->enc_sess_info.session_id);
335 req_data->header.opcode =
336 cpu_to_le32(VIRTIO_CRYPTO_CIPHER_ENCRYPT);
337 } else {
338 req_data->header.session_id =
339 cpu_to_le64(ctx->dec_sess_info.session_id);
340 req_data->header.opcode =
341 cpu_to_le32(VIRTIO_CRYPTO_CIPHER_DECRYPT);
342 }
343 req_data->u.sym_req.op_type = cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER);
344 req_data->u.sym_req.u.cipher.para.iv_len = cpu_to_le32(ivsize);
345 req_data->u.sym_req.u.cipher.para.src_data_len =
346 cpu_to_le32(req->nbytes);
347
348 dst_len = virtio_crypto_alg_sg_nents_length(req->dst);
349 if (unlikely(dst_len > U32_MAX)) {
350 pr_err("virtio_crypto: The dst_len is beyond U32_MAX\n");
351 err = -EINVAL;
352 goto free;
353 }
354
355 pr_debug("virtio_crypto: src_len: %u, dst_len: %llu\n",
356 req->nbytes, dst_len);
357
358 if (unlikely(req->nbytes + dst_len + ivsize +
359 sizeof(vc_req->status) > vcrypto->max_size)) {
360 pr_err("virtio_crypto: The length is too big\n");
361 err = -EINVAL;
362 goto free;
363 }
364
365 req_data->u.sym_req.u.cipher.para.dst_data_len =
366 cpu_to_le32((uint32_t)dst_len);
367
368 /* Outhdr */
369 sg_init_one(&outhdr, req_data, sizeof(*req_data));
370 sgs[num_out++] = &outhdr;
371
372 /* IV */
373
374 /*
375 * Avoid to do DMA from the stack, switch to using
376 * dynamically-allocated for the IV
377 */
378 iv = kzalloc_node(ivsize, GFP_ATOMIC,
379 dev_to_node(&vcrypto->vdev->dev));
380 if (!iv) {
381 err = -ENOMEM;
382 goto free;
383 }
384 memcpy(iv, req->info, ivsize);
385 sg_init_one(&iv_sg, iv, ivsize);
386 sgs[num_out++] = &iv_sg;
387 vc_req->iv = iv;
388
389 /* Source data */
390 for (i = 0; i < src_nents; i++)
391 sgs[num_out++] = &req->src[i];
392
393 /* Destination data */
394 for (i = 0; i < dst_nents; i++)
395 sgs[num_out + num_in++] = &req->dst[i];
396
397 /* Status */
398 sg_init_one(&status_sg, &vc_req->status, sizeof(vc_req->status));
399 sgs[num_out + num_in++] = &status_sg;
400
401 vc_req->sgs = sgs;
402
403 spin_lock_irqsave(&data_vq->lock, flags);
404 err = virtqueue_add_sgs(data_vq->vq, sgs, num_out,
405 num_in, vc_req, GFP_ATOMIC);
406 virtqueue_kick(data_vq->vq);
407 spin_unlock_irqrestore(&data_vq->lock, flags);
408 if (unlikely(err < 0))
409 goto free_iv;
410
411 return 0;
412
413free_iv:
414 kzfree(iv);
415free:
416 kzfree(req_data);
417 kfree(sgs);
418 return err;
419}
420
421static int virtio_crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
422{
423 struct crypto_ablkcipher *atfm = crypto_ablkcipher_reqtfm(req);
424 struct virtio_crypto_ablkcipher_ctx *ctx = crypto_ablkcipher_ctx(atfm);
425 struct virtio_crypto_request *vc_req = ablkcipher_request_ctx(req);
426 struct virtio_crypto *vcrypto = ctx->vcrypto;
427 int ret;
428 /* Use the first data virtqueue as default */
429 struct data_queue *data_vq = &vcrypto->data_vq[0];
430
431 vc_req->ablkcipher_ctx = ctx;
432 vc_req->ablkcipher_req = req;
433 ret = __virtio_crypto_ablkcipher_do_req(vc_req, req, data_vq, 1);
434 if (ret < 0) {
435 pr_err("virtio_crypto: Encryption failed!\n");
436 return ret;
437 }
438
439 return -EINPROGRESS;
440}
441
442static int virtio_crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
443{
444 struct crypto_ablkcipher *atfm = crypto_ablkcipher_reqtfm(req);
445 struct virtio_crypto_ablkcipher_ctx *ctx = crypto_ablkcipher_ctx(atfm);
446 struct virtio_crypto_request *vc_req = ablkcipher_request_ctx(req);
447 struct virtio_crypto *vcrypto = ctx->vcrypto;
448 int ret;
449 /* Use the first data virtqueue as default */
450 struct data_queue *data_vq = &vcrypto->data_vq[0];
451
452 vc_req->ablkcipher_ctx = ctx;
453 vc_req->ablkcipher_req = req;
454
455 ret = __virtio_crypto_ablkcipher_do_req(vc_req, req, data_vq, 0);
456 if (ret < 0) {
457 pr_err("virtio_crypto: Decryption failed!\n");
458 return ret;
459 }
460
461 return -EINPROGRESS;
462}
463
464static int virtio_crypto_ablkcipher_init(struct crypto_tfm *tfm)
465{
466 struct virtio_crypto_ablkcipher_ctx *ctx = crypto_tfm_ctx(tfm);
467
468 tfm->crt_ablkcipher.reqsize = sizeof(struct virtio_crypto_request);
469 ctx->tfm = tfm;
470
471 return 0;
472}
473
474static void virtio_crypto_ablkcipher_exit(struct crypto_tfm *tfm)
475{
476 struct virtio_crypto_ablkcipher_ctx *ctx = crypto_tfm_ctx(tfm);
477
478 if (!ctx->vcrypto)
479 return;
480
481 virtio_crypto_alg_ablkcipher_close_session(ctx, 1);
482 virtio_crypto_alg_ablkcipher_close_session(ctx, 0);
483 virtcrypto_dev_put(ctx->vcrypto);
484 ctx->vcrypto = NULL;
485}
486
487static struct crypto_alg virtio_crypto_algs[] = { {
488 .cra_name = "cbc(aes)",
489 .cra_driver_name = "virtio_crypto_aes_cbc",
490 .cra_priority = 501,
491 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
492 .cra_blocksize = AES_BLOCK_SIZE,
493 .cra_ctxsize = sizeof(struct virtio_crypto_ablkcipher_ctx),
494 .cra_alignmask = 0,
495 .cra_module = THIS_MODULE,
496 .cra_type = &crypto_ablkcipher_type,
497 .cra_init = virtio_crypto_ablkcipher_init,
498 .cra_exit = virtio_crypto_ablkcipher_exit,
499 .cra_u = {
500 .ablkcipher = {
501 .setkey = virtio_crypto_ablkcipher_setkey,
502 .decrypt = virtio_crypto_ablkcipher_decrypt,
503 .encrypt = virtio_crypto_ablkcipher_encrypt,
504 .min_keysize = AES_MIN_KEY_SIZE,
505 .max_keysize = AES_MAX_KEY_SIZE,
506 .ivsize = AES_BLOCK_SIZE,
507 },
508 },
509} };
510
511int virtio_crypto_algs_register(void)
512{
513 int ret = 0;
514
515 mutex_lock(&algs_lock);
516 if (++virtio_crypto_active_devs != 1)
517 goto unlock;
518
519 ret = crypto_register_algs(virtio_crypto_algs,
520 ARRAY_SIZE(virtio_crypto_algs));
521 if (ret)
522 virtio_crypto_active_devs--;
523
524unlock:
525 mutex_unlock(&algs_lock);
526 return ret;
527}
528
529void virtio_crypto_algs_unregister(void)
530{
531 mutex_lock(&algs_lock);
532 if (--virtio_crypto_active_devs != 0)
533 goto unlock;
534
535 crypto_unregister_algs(virtio_crypto_algs,
536 ARRAY_SIZE(virtio_crypto_algs));
537
538unlock:
539 mutex_unlock(&algs_lock);
540}
diff --git a/drivers/crypto/virtio/virtio_crypto_common.h b/drivers/crypto/virtio/virtio_crypto_common.h
new file mode 100644
index 000000000000..3d6566b02876
--- /dev/null
+++ b/drivers/crypto/virtio/virtio_crypto_common.h
@@ -0,0 +1,128 @@
1/* Common header for Virtio crypto device.
2 *
3 * Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _VIRTIO_CRYPTO_COMMON_H
20#define _VIRTIO_CRYPTO_COMMON_H
21
22#include <linux/virtio.h>
23#include <linux/crypto.h>
24#include <linux/spinlock.h>
25#include <crypto/aead.h>
26#include <crypto/aes.h>
27#include <crypto/authenc.h>
28
29
30/* Internal representation of a data virtqueue */
31struct data_queue {
32 /* Virtqueue associated with this send _queue */
33 struct virtqueue *vq;
34
35 /* To protect the vq operations for the dataq */
36 spinlock_t lock;
37
38 /* Name of the tx queue: dataq.$index */
39 char name[32];
40};
41
42struct virtio_crypto {
43 struct virtio_device *vdev;
44 struct virtqueue *ctrl_vq;
45 struct data_queue *data_vq;
46
47 /* To protect the vq operations for the controlq */
48 spinlock_t ctrl_lock;
49
50 /* Maximum of data queues supported by the device */
51 u32 max_data_queues;
52
53 /* Number of queue currently used by the driver */
54 u32 curr_queue;
55
56 /* Maximum length of cipher key */
57 u32 max_cipher_key_len;
58 /* Maximum length of authenticated key */
59 u32 max_auth_key_len;
60 /* Maximum size of per request */
61 u64 max_size;
62
63 /* Control VQ buffers: protected by the ctrl_lock */
64 struct virtio_crypto_op_ctrl_req ctrl;
65 struct virtio_crypto_session_input input;
66 struct virtio_crypto_inhdr ctrl_status;
67
68 unsigned long status;
69 atomic_t ref_count;
70 struct list_head list;
71 struct module *owner;
72 uint8_t dev_id;
73
74 /* Does the affinity hint is set for virtqueues? */
75 bool affinity_hint_set;
76};
77
78struct virtio_crypto_sym_session_info {
79 /* Backend session id, which come from the host side */
80 __u64 session_id;
81};
82
83struct virtio_crypto_ablkcipher_ctx {
84 struct virtio_crypto *vcrypto;
85 struct crypto_tfm *tfm;
86
87 struct virtio_crypto_sym_session_info enc_sess_info;
88 struct virtio_crypto_sym_session_info dec_sess_info;
89};
90
91struct virtio_crypto_request {
92 /* Cipher or aead */
93 uint32_t type;
94 uint8_t status;
95 struct virtio_crypto_ablkcipher_ctx *ablkcipher_ctx;
96 struct ablkcipher_request *ablkcipher_req;
97 struct virtio_crypto_op_data_req *req_data;
98 struct scatterlist **sgs;
99 uint8_t *iv;
100};
101
102int virtcrypto_devmgr_add_dev(struct virtio_crypto *vcrypto_dev);
103struct list_head *virtcrypto_devmgr_get_head(void);
104void virtcrypto_devmgr_rm_dev(struct virtio_crypto *vcrypto_dev);
105struct virtio_crypto *virtcrypto_devmgr_get_first(void);
106int virtcrypto_dev_in_use(struct virtio_crypto *vcrypto_dev);
107int virtcrypto_dev_get(struct virtio_crypto *vcrypto_dev);
108void virtcrypto_dev_put(struct virtio_crypto *vcrypto_dev);
109int virtcrypto_dev_started(struct virtio_crypto *vcrypto_dev);
110struct virtio_crypto *virtcrypto_get_dev_node(int node);
111int virtcrypto_dev_start(struct virtio_crypto *vcrypto);
112void virtcrypto_dev_stop(struct virtio_crypto *vcrypto);
113
114static inline int virtio_crypto_get_current_node(void)
115{
116 int cpu, node;
117
118 cpu = get_cpu();
119 node = topology_physical_package_id(cpu);
120 put_cpu();
121
122 return node;
123}
124
125int virtio_crypto_algs_register(void);
126void virtio_crypto_algs_unregister(void);
127
128#endif /* _VIRTIO_CRYPTO_COMMON_H */
diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
new file mode 100644
index 000000000000..fe70ec823b27
--- /dev/null
+++ b/drivers/crypto/virtio/virtio_crypto_core.c
@@ -0,0 +1,476 @@
1 /* Driver for Virtio crypto device.
2 *
3 * Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/err.h>
20#include <linux/module.h>
21#include <linux/virtio_config.h>
22#include <linux/cpu.h>
23
24#include <uapi/linux/virtio_crypto.h>
25#include "virtio_crypto_common.h"
26
27
28static void
29virtcrypto_clear_request(struct virtio_crypto_request *vc_req)
30{
31 if (vc_req) {
32 kzfree(vc_req->iv);
33 kzfree(vc_req->req_data);
34 kfree(vc_req->sgs);
35 }
36}
37
38static void virtcrypto_dataq_callback(struct virtqueue *vq)
39{
40 struct virtio_crypto *vcrypto = vq->vdev->priv;
41 struct virtio_crypto_request *vc_req;
42 unsigned long flags;
43 unsigned int len;
44 struct ablkcipher_request *ablk_req;
45 int error;
46 unsigned int qid = vq->index;
47
48 spin_lock_irqsave(&vcrypto->data_vq[qid].lock, flags);
49 do {
50 virtqueue_disable_cb(vq);
51 while ((vc_req = virtqueue_get_buf(vq, &len)) != NULL) {
52 if (vc_req->type == VIRTIO_CRYPTO_SYM_OP_CIPHER) {
53 switch (vc_req->status) {
54 case VIRTIO_CRYPTO_OK:
55 error = 0;
56 break;
57 case VIRTIO_CRYPTO_INVSESS:
58 case VIRTIO_CRYPTO_ERR:
59 error = -EINVAL;
60 break;
61 case VIRTIO_CRYPTO_BADMSG:
62 error = -EBADMSG;
63 break;
64 default:
65 error = -EIO;
66 break;
67 }
68 ablk_req = vc_req->ablkcipher_req;
69 virtcrypto_clear_request(vc_req);
70
71 spin_unlock_irqrestore(
72 &vcrypto->data_vq[qid].lock, flags);
73 /* Finish the encrypt or decrypt process */
74 ablk_req->base.complete(&ablk_req->base, error);
75 spin_lock_irqsave(
76 &vcrypto->data_vq[qid].lock, flags);
77 }
78 }
79 } while (!virtqueue_enable_cb(vq));
80 spin_unlock_irqrestore(&vcrypto->data_vq[qid].lock, flags);
81}
82
83static int virtcrypto_find_vqs(struct virtio_crypto *vi)
84{
85 vq_callback_t **callbacks;
86 struct virtqueue **vqs;
87 int ret = -ENOMEM;
88 int i, total_vqs;
89 const char **names;
90
91 /*
92 * We expect 1 data virtqueue, followed by
93 * possible N-1 data queues used in multiqueue mode,
94 * followed by control vq.
95 */
96 total_vqs = vi->max_data_queues + 1;
97
98 /* Allocate space for find_vqs parameters */
99 vqs = kcalloc(total_vqs, sizeof(*vqs), GFP_KERNEL);
100 if (!vqs)
101 goto err_vq;
102 callbacks = kcalloc(total_vqs, sizeof(*callbacks), GFP_KERNEL);
103 if (!callbacks)
104 goto err_callback;
105 names = kcalloc(total_vqs, sizeof(*names), GFP_KERNEL);
106 if (!names)
107 goto err_names;
108
109 /* Parameters for control virtqueue */
110 callbacks[total_vqs - 1] = NULL;
111 names[total_vqs - 1] = "controlq";
112
113 /* Allocate/initialize parameters for data virtqueues */
114 for (i = 0; i < vi->max_data_queues; i++) {
115 callbacks[i] = virtcrypto_dataq_callback;
116 snprintf(vi->data_vq[i].name, sizeof(vi->data_vq[i].name),
117 "dataq.%d", i);
118 names[i] = vi->data_vq[i].name;
119 }
120
121 ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
122 names);
123 if (ret)
124 goto err_find;
125
126 vi->ctrl_vq = vqs[total_vqs - 1];
127
128 for (i = 0; i < vi->max_data_queues; i++) {
129 spin_lock_init(&vi->data_vq[i].lock);
130 vi->data_vq[i].vq = vqs[i];
131 }
132
133 kfree(names);
134 kfree(callbacks);
135 kfree(vqs);
136
137 return 0;
138
139err_find:
140 kfree(names);
141err_names:
142 kfree(callbacks);
143err_callback:
144 kfree(vqs);
145err_vq:
146 return ret;
147}
148
149static int virtcrypto_alloc_queues(struct virtio_crypto *vi)
150{
151 vi->data_vq = kcalloc(vi->max_data_queues, sizeof(*vi->data_vq),
152 GFP_KERNEL);
153 if (!vi->data_vq)
154 return -ENOMEM;
155
156 return 0;
157}
158
159static void virtcrypto_clean_affinity(struct virtio_crypto *vi, long hcpu)
160{
161 int i;
162
163 if (vi->affinity_hint_set) {
164 for (i = 0; i < vi->max_data_queues; i++)
165 virtqueue_set_affinity(vi->data_vq[i].vq, -1);
166
167 vi->affinity_hint_set = false;
168 }
169}
170
171static void virtcrypto_set_affinity(struct virtio_crypto *vcrypto)
172{
173 int i = 0;
174 int cpu;
175
176 /*
177 * In single queue mode, we don't set the cpu affinity.
178 */
179 if (vcrypto->curr_queue == 1 || vcrypto->max_data_queues == 1) {
180 virtcrypto_clean_affinity(vcrypto, -1);
181 return;
182 }
183
184 /*
185 * In multiqueue mode, we let the queue to be private to one cpu
186 * by setting the affinity hint to eliminate the contention.
187 *
188 * TODO: adds cpu hotplug support by register cpu notifier.
189 *
190 */
191 for_each_online_cpu(cpu) {
192 virtqueue_set_affinity(vcrypto->data_vq[i].vq, cpu);
193 if (++i >= vcrypto->max_data_queues)
194 break;
195 }
196
197 vcrypto->affinity_hint_set = true;
198}
199
200static void virtcrypto_free_queues(struct virtio_crypto *vi)
201{
202 kfree(vi->data_vq);
203}
204
205static int virtcrypto_init_vqs(struct virtio_crypto *vi)
206{
207 int ret;
208
209 /* Allocate send & receive queues */
210 ret = virtcrypto_alloc_queues(vi);
211 if (ret)
212 goto err;
213
214 ret = virtcrypto_find_vqs(vi);
215 if (ret)
216 goto err_free;
217
218 get_online_cpus();
219 virtcrypto_set_affinity(vi);
220 put_online_cpus();
221
222 return 0;
223
224err_free:
225 virtcrypto_free_queues(vi);
226err:
227 return ret;
228}
229
230static int virtcrypto_update_status(struct virtio_crypto *vcrypto)
231{
232 u32 status;
233 int err;
234
235 virtio_cread(vcrypto->vdev,
236 struct virtio_crypto_config, status, &status);
237
238 /*
239 * Unknown status bits would be a host error and the driver
240 * should consider the device to be broken.
241 */
242 if (status & (~VIRTIO_CRYPTO_S_HW_READY)) {
243 dev_warn(&vcrypto->vdev->dev,
244 "Unknown status bits: 0x%x\n", status);
245
246 virtio_break_device(vcrypto->vdev);
247 return -EPERM;
248 }
249
250 if (vcrypto->status == status)
251 return 0;
252
253 vcrypto->status = status;
254
255 if (vcrypto->status & VIRTIO_CRYPTO_S_HW_READY) {
256 err = virtcrypto_dev_start(vcrypto);
257 if (err) {
258 dev_err(&vcrypto->vdev->dev,
259 "Failed to start virtio crypto device.\n");
260
261 return -EPERM;
262 }
263 dev_info(&vcrypto->vdev->dev, "Accelerator is ready\n");
264 } else {
265 virtcrypto_dev_stop(vcrypto);
266 dev_info(&vcrypto->vdev->dev, "Accelerator is not ready\n");
267 }
268
269 return 0;
270}
271
272static void virtcrypto_del_vqs(struct virtio_crypto *vcrypto)
273{
274 struct virtio_device *vdev = vcrypto->vdev;
275
276 virtcrypto_clean_affinity(vcrypto, -1);
277
278 vdev->config->del_vqs(vdev);
279
280 virtcrypto_free_queues(vcrypto);
281}
282
283static int virtcrypto_probe(struct virtio_device *vdev)
284{
285 int err = -EFAULT;
286 struct virtio_crypto *vcrypto;
287 u32 max_data_queues = 0, max_cipher_key_len = 0;
288 u32 max_auth_key_len = 0;
289 u64 max_size = 0;
290
291 if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1))
292 return -ENODEV;
293
294 if (!vdev->config->get) {
295 dev_err(&vdev->dev, "%s failure: config access disabled\n",
296 __func__);
297 return -EINVAL;
298 }
299
300 if (num_possible_nodes() > 1 && dev_to_node(&vdev->dev) < 0) {
301 /*
302 * If the accelerator is connected to a node with no memory
303 * there is no point in using the accelerator since the remote
304 * memory transaction will be very slow.
305 */
306 dev_err(&vdev->dev, "Invalid NUMA configuration.\n");
307 return -EINVAL;
308 }
309
310 vcrypto = kzalloc_node(sizeof(*vcrypto), GFP_KERNEL,
311 dev_to_node(&vdev->dev));
312 if (!vcrypto)
313 return -ENOMEM;
314
315 virtio_cread(vdev, struct virtio_crypto_config,
316 max_dataqueues, &max_data_queues);
317 if (max_data_queues < 1)
318 max_data_queues = 1;
319
320 virtio_cread(vdev, struct virtio_crypto_config,
321 max_cipher_key_len, &max_cipher_key_len);
322 virtio_cread(vdev, struct virtio_crypto_config,
323 max_auth_key_len, &max_auth_key_len);
324 virtio_cread(vdev, struct virtio_crypto_config,
325 max_size, &max_size);
326
327 /* Add virtio crypto device to global table */
328 err = virtcrypto_devmgr_add_dev(vcrypto);
329 if (err) {
330 dev_err(&vdev->dev, "Failed to add new virtio crypto device.\n");
331 goto free;
332 }
333 vcrypto->owner = THIS_MODULE;
334 vcrypto = vdev->priv = vcrypto;
335 vcrypto->vdev = vdev;
336
337 spin_lock_init(&vcrypto->ctrl_lock);
338
339 /* Use single data queue as default */
340 vcrypto->curr_queue = 1;
341 vcrypto->max_data_queues = max_data_queues;
342 vcrypto->max_cipher_key_len = max_cipher_key_len;
343 vcrypto->max_auth_key_len = max_auth_key_len;
344 vcrypto->max_size = max_size;
345
346 dev_info(&vdev->dev,
347 "max_queues: %u, max_cipher_key_len: %u, max_auth_key_len: %u, max_size 0x%llx\n",
348 vcrypto->max_data_queues,
349 vcrypto->max_cipher_key_len,
350 vcrypto->max_auth_key_len,
351 vcrypto->max_size);
352
353 err = virtcrypto_init_vqs(vcrypto);
354 if (err) {
355 dev_err(&vdev->dev, "Failed to initialize vqs.\n");
356 goto free_dev;
357 }
358 virtio_device_ready(vdev);
359
360 err = virtcrypto_update_status(vcrypto);
361 if (err)
362 goto free_vqs;
363
364 return 0;
365
366free_vqs:
367 vcrypto->vdev->config->reset(vdev);
368 virtcrypto_del_vqs(vcrypto);
369free_dev:
370 virtcrypto_devmgr_rm_dev(vcrypto);
371free:
372 kfree(vcrypto);
373 return err;
374}
375
376static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
377{
378 struct virtio_crypto_request *vc_req;
379 int i;
380 struct virtqueue *vq;
381
382 for (i = 0; i < vcrypto->max_data_queues; i++) {
383 vq = vcrypto->data_vq[i].vq;
384 while ((vc_req = virtqueue_detach_unused_buf(vq)) != NULL) {
385 kfree(vc_req->req_data);
386 kfree(vc_req->sgs);
387 }
388 }
389}
390
391static void virtcrypto_remove(struct virtio_device *vdev)
392{
393 struct virtio_crypto *vcrypto = vdev->priv;
394
395 dev_info(&vdev->dev, "Start virtcrypto_remove.\n");
396
397 if (virtcrypto_dev_started(vcrypto))
398 virtcrypto_dev_stop(vcrypto);
399 vdev->config->reset(vdev);
400 virtcrypto_free_unused_reqs(vcrypto);
401 virtcrypto_del_vqs(vcrypto);
402 virtcrypto_devmgr_rm_dev(vcrypto);
403 kfree(vcrypto);
404}
405
406static void virtcrypto_config_changed(struct virtio_device *vdev)
407{
408 struct virtio_crypto *vcrypto = vdev->priv;
409
410 virtcrypto_update_status(vcrypto);
411}
412
413#ifdef CONFIG_PM_SLEEP
414static int virtcrypto_freeze(struct virtio_device *vdev)
415{
416 struct virtio_crypto *vcrypto = vdev->priv;
417
418 vdev->config->reset(vdev);
419 virtcrypto_free_unused_reqs(vcrypto);
420 if (virtcrypto_dev_started(vcrypto))
421 virtcrypto_dev_stop(vcrypto);
422
423 virtcrypto_del_vqs(vcrypto);
424 return 0;
425}
426
427static int virtcrypto_restore(struct virtio_device *vdev)
428{
429 struct virtio_crypto *vcrypto = vdev->priv;
430 int err;
431
432 err = virtcrypto_init_vqs(vcrypto);
433 if (err)
434 return err;
435
436 virtio_device_ready(vdev);
437 err = virtcrypto_dev_start(vcrypto);
438 if (err) {
439 dev_err(&vdev->dev, "Failed to start virtio crypto device.\n");
440 return -EFAULT;
441 }
442
443 return 0;
444}
445#endif
446
447static unsigned int features[] = {
448 /* none */
449};
450
451static struct virtio_device_id id_table[] = {
452 { VIRTIO_ID_CRYPTO, VIRTIO_DEV_ANY_ID },
453 { 0 },
454};
455
456static struct virtio_driver virtio_crypto_driver = {
457 .driver.name = KBUILD_MODNAME,
458 .driver.owner = THIS_MODULE,
459 .feature_table = features,
460 .feature_table_size = ARRAY_SIZE(features),
461 .id_table = id_table,
462 .probe = virtcrypto_probe,
463 .remove = virtcrypto_remove,
464 .config_changed = virtcrypto_config_changed,
465#ifdef CONFIG_PM_SLEEP
466 .freeze = virtcrypto_freeze,
467 .restore = virtcrypto_restore,
468#endif
469};
470
471module_virtio_driver(virtio_crypto_driver);
472
473MODULE_DEVICE_TABLE(virtio, id_table);
474MODULE_DESCRIPTION("virtio crypto device driver");
475MODULE_LICENSE("GPL");
476MODULE_AUTHOR("Gonglei <arei.gonglei@huawei.com>");
diff --git a/drivers/crypto/virtio/virtio_crypto_mgr.c b/drivers/crypto/virtio/virtio_crypto_mgr.c
new file mode 100644
index 000000000000..a69ff71de2c4
--- /dev/null
+++ b/drivers/crypto/virtio/virtio_crypto_mgr.c
@@ -0,0 +1,264 @@
1 /* Management for virtio crypto devices (refer to adf_dev_mgr.c)
2 *
3 * Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/mutex.h>
20#include <linux/list.h>
21#include <linux/module.h>
22
23#include <uapi/linux/virtio_crypto.h>
24#include "virtio_crypto_common.h"
25
26static LIST_HEAD(virtio_crypto_table);
27static uint32_t num_devices;
28
29/* The table_lock protects the above global list and num_devices */
30static DEFINE_MUTEX(table_lock);
31
32#define VIRTIO_CRYPTO_MAX_DEVICES 32
33
34
35/*
36 * virtcrypto_devmgr_add_dev() - Add vcrypto_dev to the acceleration
37 * framework.
38 * @vcrypto_dev: Pointer to virtio crypto device.
39 *
40 * Function adds virtio crypto device to the global list.
41 * To be used by virtio crypto device specific drivers.
42 *
43 * Return: 0 on success, error code othewise.
44 */
45int virtcrypto_devmgr_add_dev(struct virtio_crypto *vcrypto_dev)
46{
47 struct list_head *itr;
48
49 mutex_lock(&table_lock);
50 if (num_devices == VIRTIO_CRYPTO_MAX_DEVICES) {
51 pr_info("virtio_crypto: only support up to %d devices\n",
52 VIRTIO_CRYPTO_MAX_DEVICES);
53 mutex_unlock(&table_lock);
54 return -EFAULT;
55 }
56
57 list_for_each(itr, &virtio_crypto_table) {
58 struct virtio_crypto *ptr =
59 list_entry(itr, struct virtio_crypto, list);
60
61 if (ptr == vcrypto_dev) {
62 mutex_unlock(&table_lock);
63 return -EEXIST;
64 }
65 }
66 atomic_set(&vcrypto_dev->ref_count, 0);
67 list_add_tail(&vcrypto_dev->list, &virtio_crypto_table);
68 vcrypto_dev->dev_id = num_devices++;
69 mutex_unlock(&table_lock);
70 return 0;
71}
72
73struct list_head *virtcrypto_devmgr_get_head(void)
74{
75 return &virtio_crypto_table;
76}
77
78/*
79 * virtcrypto_devmgr_rm_dev() - Remove vcrypto_dev from the acceleration
80 * framework.
81 * @vcrypto_dev: Pointer to virtio crypto device.
82 *
83 * Function removes virtio crypto device from the acceleration framework.
84 * To be used by virtio crypto device specific drivers.
85 *
86 * Return: void
87 */
88void virtcrypto_devmgr_rm_dev(struct virtio_crypto *vcrypto_dev)
89{
90 mutex_lock(&table_lock);
91 list_del(&vcrypto_dev->list);
92 num_devices--;
93 mutex_unlock(&table_lock);
94}
95
96/*
97 * virtcrypto_devmgr_get_first()
98 *
99 * Function returns the first virtio crypto device from the acceleration
100 * framework.
101 *
102 * To be used by virtio crypto device specific drivers.
103 *
104 * Return: pointer to vcrypto_dev or NULL if not found.
105 */
106struct virtio_crypto *virtcrypto_devmgr_get_first(void)
107{
108 struct virtio_crypto *dev = NULL;
109
110 mutex_lock(&table_lock);
111 if (!list_empty(&virtio_crypto_table))
112 dev = list_first_entry(&virtio_crypto_table,
113 struct virtio_crypto,
114 list);
115 mutex_unlock(&table_lock);
116 return dev;
117}
118
119/*
120 * virtcrypto_dev_in_use() - Check whether vcrypto_dev is currently in use
121 * @vcrypto_dev: Pointer to virtio crypto device.
122 *
123 * To be used by virtio crypto device specific drivers.
124 *
125 * Return: 1 when device is in use, 0 otherwise.
126 */
127int virtcrypto_dev_in_use(struct virtio_crypto *vcrypto_dev)
128{
129 return atomic_read(&vcrypto_dev->ref_count) != 0;
130}
131
132/*
133 * virtcrypto_dev_get() - Increment vcrypto_dev reference count
134 * @vcrypto_dev: Pointer to virtio crypto device.
135 *
136 * Increment the vcrypto_dev refcount and if this is the first time
137 * incrementing it during this period the vcrypto_dev is in use,
138 * increment the module refcount too.
139 * To be used by virtio crypto device specific drivers.
140 *
141 * Return: 0 when successful, EFAULT when fail to bump module refcount
142 */
143int virtcrypto_dev_get(struct virtio_crypto *vcrypto_dev)
144{
145 if (atomic_add_return(1, &vcrypto_dev->ref_count) == 1)
146 if (!try_module_get(vcrypto_dev->owner))
147 return -EFAULT;
148 return 0;
149}
150
151/*
152 * virtcrypto_dev_put() - Decrement vcrypto_dev reference count
153 * @vcrypto_dev: Pointer to virtio crypto device.
154 *
155 * Decrement the vcrypto_dev refcount and if this is the last time
156 * decrementing it during this period the vcrypto_dev is in use,
157 * decrement the module refcount too.
158 * To be used by virtio crypto device specific drivers.
159 *
160 * Return: void
161 */
162void virtcrypto_dev_put(struct virtio_crypto *vcrypto_dev)
163{
164 if (atomic_sub_return(1, &vcrypto_dev->ref_count) == 0)
165 module_put(vcrypto_dev->owner);
166}
167
168/*
169 * virtcrypto_dev_started() - Check whether device has started
170 * @vcrypto_dev: Pointer to virtio crypto device.
171 *
172 * To be used by virtio crypto device specific drivers.
173 *
174 * Return: 1 when the device has started, 0 otherwise
175 */
176int virtcrypto_dev_started(struct virtio_crypto *vcrypto_dev)
177{
178 return (vcrypto_dev->status & VIRTIO_CRYPTO_S_HW_READY);
179}
180
181/*
182 * virtcrypto_get_dev_node() - Get vcrypto_dev on the node.
183 * @node: Node id the driver works.
184 *
185 * Function returns the virtio crypto device used fewest on the node.
186 *
187 * To be used by virtio crypto device specific drivers.
188 *
189 * Return: pointer to vcrypto_dev or NULL if not found.
190 */
191struct virtio_crypto *virtcrypto_get_dev_node(int node)
192{
193 struct virtio_crypto *vcrypto_dev = NULL, *tmp_dev;
194 unsigned long best = ~0;
195 unsigned long ctr;
196
197 mutex_lock(&table_lock);
198 list_for_each_entry(tmp_dev, virtcrypto_devmgr_get_head(), list) {
199
200 if ((node == dev_to_node(&tmp_dev->vdev->dev) ||
201 dev_to_node(&tmp_dev->vdev->dev) < 0) &&
202 virtcrypto_dev_started(tmp_dev)) {
203 ctr = atomic_read(&tmp_dev->ref_count);
204 if (best > ctr) {
205 vcrypto_dev = tmp_dev;
206 best = ctr;
207 }
208 }
209 }
210
211 if (!vcrypto_dev) {
212 pr_info("virtio_crypto: Could not find a device on node %d\n",
213 node);
214 /* Get any started device */
215 list_for_each_entry(tmp_dev,
216 virtcrypto_devmgr_get_head(), list) {
217 if (virtcrypto_dev_started(tmp_dev)) {
218 vcrypto_dev = tmp_dev;
219 break;
220 }
221 }
222 }
223 mutex_unlock(&table_lock);
224 if (!vcrypto_dev)
225 return NULL;
226
227 virtcrypto_dev_get(vcrypto_dev);
228 return vcrypto_dev;
229}
230
231/*
232 * virtcrypto_dev_start() - Start virtio crypto device
233 * @vcrypto: Pointer to virtio crypto device.
234 *
235 * Function notifies all the registered services that the virtio crypto device
236 * is ready to be used.
237 * To be used by virtio crypto device specific drivers.
238 *
239 * Return: 0 on success, EFAULT when fail to register algorithms
240 */
241int virtcrypto_dev_start(struct virtio_crypto *vcrypto)
242{
243 if (virtio_crypto_algs_register()) {
244 pr_err("virtio_crypto: Failed to register crypto algs\n");
245 return -EFAULT;
246 }
247
248 return 0;
249}
250
251/*
252 * virtcrypto_dev_stop() - Stop virtio crypto device
253 * @vcrypto: Pointer to virtio crypto device.
254 *
255 * Function notifies all the registered services that the virtio crypto device
256 * is ready to be used.
257 * To be used by virtio crypto device specific drivers.
258 *
259 * Return: void
260 */
261void virtcrypto_dev_stop(struct virtio_crypto *vcrypto)
262{
263 virtio_crypto_algs_unregister();
264}
diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c
index cb75f0663ba0..11288ffa4af6 100644
--- a/drivers/gpu/drm/virtio/virtgpu_plane.c
+++ b/drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -88,8 +88,8 @@ static void virtio_gpu_primary_plane_update(struct drm_plane *plane,
88 (vgdev, handle, 0, 88 (vgdev, handle, 0,
89 cpu_to_le32(plane->state->src_w >> 16), 89 cpu_to_le32(plane->state->src_w >> 16),
90 cpu_to_le32(plane->state->src_h >> 16), 90 cpu_to_le32(plane->state->src_h >> 16),
91 plane->state->src_x >> 16, 91 cpu_to_le32(plane->state->src_x >> 16),
92 plane->state->src_y >> 16, NULL); 92 cpu_to_le32(plane->state->src_y >> 16), NULL);
93 } 93 }
94 } else { 94 } else {
95 handle = 0; 95 handle = 0;
diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
index 974f9410474b..43ea0dc957d2 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -109,8 +109,10 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev)
109 109
110 spin_lock(&vgdev->free_vbufs_lock); 110 spin_lock(&vgdev->free_vbufs_lock);
111 for (i = 0; i < count; i++) { 111 for (i = 0; i < count; i++) {
112 if (WARN_ON(list_empty(&vgdev->free_vbufs))) 112 if (WARN_ON(list_empty(&vgdev->free_vbufs))) {
113 spin_unlock(&vgdev->free_vbufs_lock);
113 return; 114 return;
115 }
114 vbuf = list_first_entry(&vgdev->free_vbufs, 116 vbuf = list_first_entry(&vgdev->free_vbufs,
115 struct virtio_gpu_vbuffer, list); 117 struct virtio_gpu_vbuffer, list);
116 list_del(&vbuf->list); 118 list_del(&vbuf->list);
@@ -295,6 +297,8 @@ void virtio_gpu_dequeue_cursor_func(struct work_struct *work)
295 297
296static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev, 298static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
297 struct virtio_gpu_vbuffer *vbuf) 299 struct virtio_gpu_vbuffer *vbuf)
300 __releases(&vgdev->ctrlq.qlock)
301 __acquires(&vgdev->ctrlq.qlock)
298{ 302{
299 struct virtqueue *vq = vgdev->ctrlq.vq; 303 struct virtqueue *vq = vgdev->ctrlq.vq;
300 struct scatterlist *sgs[3], vcmd, vout, vresp; 304 struct scatterlist *sgs[3], vcmd, vout, vresp;
diff --git a/drivers/md/dm-cache-block-types.h b/drivers/md/dm-cache-block-types.h
index bed4ad4e1b7c..389c9e8ac785 100644
--- a/drivers/md/dm-cache-block-types.h
+++ b/drivers/md/dm-cache-block-types.h
@@ -17,9 +17,9 @@
17 * discard bitset. 17 * discard bitset.
18 */ 18 */
19 19
20typedef dm_block_t __bitwise__ dm_oblock_t; 20typedef dm_block_t __bitwise dm_oblock_t;
21typedef uint32_t __bitwise__ dm_cblock_t; 21typedef uint32_t __bitwise dm_cblock_t;
22typedef dm_block_t __bitwise__ dm_dblock_t; 22typedef dm_block_t __bitwise dm_dblock_t;
23 23
24static inline dm_oblock_t to_oblock(dm_block_t b) 24static inline dm_oblock_t to_oblock(dm_block_t b)
25{ 25{
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 26ba4b794a0b..7a85495dbb0c 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -31,5 +31,4 @@ obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o
31obj-$(CONFIG_CAN_XILINXCAN) += xilinx_can.o 31obj-$(CONFIG_CAN_XILINXCAN) += xilinx_can.o
32obj-$(CONFIG_PCH_CAN) += pch_can.o 32obj-$(CONFIG_PCH_CAN) += pch_can.o
33 33
34subdir-ccflags-y += -D__CHECK_ENDIAN__
35subdir-ccflags-$(CONFIG_CAN_DEBUG_DEVICES) += -DDEBUG 34subdir-ccflags-$(CONFIG_CAN_DEBUG_DEVICES) += -DDEBUG
diff --git a/drivers/net/ethernet/altera/Makefile b/drivers/net/ethernet/altera/Makefile
index 3eff2fd3997e..d4a187e45369 100644
--- a/drivers/net/ethernet/altera/Makefile
+++ b/drivers/net/ethernet/altera/Makefile
@@ -5,4 +5,3 @@
5obj-$(CONFIG_ALTERA_TSE) += altera_tse.o 5obj-$(CONFIG_ALTERA_TSE) += altera_tse.o
6altera_tse-objs := altera_tse_main.o altera_tse_ethtool.o \ 6altera_tse-objs := altera_tse_main.o altera_tse_ethtool.o \
7altera_msgdma.o altera_sgdma.o altera_utils.o 7altera_msgdma.o altera_sgdma.o altera_utils.o
8ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/ethernet/atheros/alx/Makefile b/drivers/net/ethernet/atheros/alx/Makefile
index 5901fa407d52..ed4a605874a3 100644
--- a/drivers/net/ethernet/atheros/alx/Makefile
+++ b/drivers/net/ethernet/atheros/alx/Makefile
@@ -1,3 +1,2 @@
1obj-$(CONFIG_ALX) += alx.o 1obj-$(CONFIG_ALX) += alx.o
2alx-objs := main.o ethtool.o hw.o 2alx-objs := main.o ethtool.o hw.o
3ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/ethernet/freescale/Makefile b/drivers/net/ethernet/freescale/Makefile
index 4a13115155c9..c46df5c82af5 100644
--- a/drivers/net/ethernet/freescale/Makefile
+++ b/drivers/net/ethernet/freescale/Makefile
@@ -4,8 +4,6 @@
4 4
5obj-$(CONFIG_FEC) += fec.o 5obj-$(CONFIG_FEC) += fec.o
6fec-objs :=fec_main.o fec_ptp.o 6fec-objs :=fec_main.o fec_ptp.o
7CFLAGS_fec_main.o := -D__CHECK_ENDIAN__
8CFLAGS_fec_ptp.o := -D__CHECK_ENDIAN__
9 7
10obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o 8obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o
11ifeq ($(CONFIG_FEC_MPC52xx_MDIO),y) 9ifeq ($(CONFIG_FEC_MPC52xx_MDIO),y)
diff --git a/drivers/net/ethernet/sun/sunhme.h b/drivers/net/ethernet/sun/sunhme.h
index f4307654e4ae..4a8d5b18dfd5 100644
--- a/drivers/net/ethernet/sun/sunhme.h
+++ b/drivers/net/ethernet/sun/sunhme.h
@@ -302,7 +302,7 @@
302 * Always write the address first before setting the ownership 302 * Always write the address first before setting the ownership
303 * bits to avoid races with the hardware scanning the ring. 303 * bits to avoid races with the hardware scanning the ring.
304 */ 304 */
305typedef u32 __bitwise__ hme32; 305typedef u32 __bitwise hme32;
306 306
307struct happy_meal_rxd { 307struct happy_meal_rxd {
308 hme32 rx_flags; 308 hme32 rx_flags;
diff --git a/drivers/net/wireless/ath/Makefile b/drivers/net/wireless/ath/Makefile
index 89f8d5979402..4cdebc7659dd 100644
--- a/drivers/net/wireless/ath/Makefile
+++ b/drivers/net/wireless/ath/Makefile
@@ -19,6 +19,4 @@ ath-objs := main.o \
19ath-$(CONFIG_ATH_DEBUG) += debug.o 19ath-$(CONFIG_ATH_DEBUG) += debug.o
20ath-$(CONFIG_ATH_TRACEPOINTS) += trace.o 20ath-$(CONFIG_ATH_TRACEPOINTS) += trace.o
21 21
22ccflags-y += -D__CHECK_ENDIAN__
23
24CFLAGS_trace.o := -I$(src) 22CFLAGS_trace.o := -I$(src)
diff --git a/drivers/net/wireless/ath/wil6210/Makefile b/drivers/net/wireless/ath/wil6210/Makefile
index 11b544b26c74..89bf2f9eca1d 100644
--- a/drivers/net/wireless/ath/wil6210/Makefile
+++ b/drivers/net/wireless/ath/wil6210/Makefile
@@ -22,5 +22,3 @@ wil6210-y += p2p.o
22 22
23# for tracing framework to find trace.h 23# for tracing framework to find trace.h
24CFLAGS_trace.o := -I$(src) 24CFLAGS_trace.o := -I$(src)
25
26subdir-ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
index d1568bed1ad1..0383ba559edc 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
@@ -19,8 +19,6 @@ ccflags-y += \
19 -Idrivers/net/wireless/broadcom/brcm80211/brcmfmac \ 19 -Idrivers/net/wireless/broadcom/brcm80211/brcmfmac \
20 -Idrivers/net/wireless/broadcom/brcm80211/include 20 -Idrivers/net/wireless/broadcom/brcm80211/include
21 21
22ccflags-y += -D__CHECK_ENDIAN__
23
24obj-$(CONFIG_BRCMFMAC) += brcmfmac.o 22obj-$(CONFIG_BRCMFMAC) += brcmfmac.o
25brcmfmac-objs += \ 23brcmfmac-objs += \
26 cfg80211.o \ 24 cfg80211.o \
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/Makefile b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/Makefile
index 960e6b86bbcb..ed83f33aceb7 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/Makefile
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/Makefile
@@ -16,7 +16,6 @@
16# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 17
18ccflags-y := \ 18ccflags-y := \
19 -D__CHECK_ENDIAN__ \
20 -Idrivers/net/wireless/broadcom/brcm80211/brcmsmac \ 19 -Idrivers/net/wireless/broadcom/brcm80211/brcmsmac \
21 -Idrivers/net/wireless/broadcom/brcm80211/brcmsmac/phy \ 20 -Idrivers/net/wireless/broadcom/brcm80211/brcmsmac/phy \
22 -Idrivers/net/wireless/broadcom/brcm80211/include 21 -Idrivers/net/wireless/broadcom/brcm80211/include
diff --git a/drivers/net/wireless/intel/iwlegacy/Makefile b/drivers/net/wireless/intel/iwlegacy/Makefile
index c985a01a0731..c826a6b985bb 100644
--- a/drivers/net/wireless/intel/iwlegacy/Makefile
+++ b/drivers/net/wireless/intel/iwlegacy/Makefile
@@ -13,5 +13,3 @@ iwl4965-$(CONFIG_IWLEGACY_DEBUGFS) += 4965-debug.o
13obj-$(CONFIG_IWL3945) += iwl3945.o 13obj-$(CONFIG_IWL3945) += iwl3945.o
14iwl3945-objs := 3945-mac.o 3945.o 3945-rs.o 14iwl3945-objs := 3945-mac.o 3945.o 3945-rs.o
15iwl3945-$(CONFIG_IWLEGACY_DEBUGFS) += 3945-debug.o 15iwl3945-$(CONFIG_IWLEGACY_DEBUGFS) += 3945-debug.o
16
17ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/intel/iwlwifi/Makefile b/drivers/net/wireless/intel/iwlwifi/Makefile
index 6e7ed908de0c..92e611841200 100644
--- a/drivers/net/wireless/intel/iwlwifi/Makefile
+++ b/drivers/net/wireless/intel/iwlwifi/Makefile
@@ -15,7 +15,7 @@ iwlwifi-objs += $(iwlwifi-m)
15 15
16iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TRACING) += iwl-devtrace.o 16iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TRACING) += iwl-devtrace.o
17 17
18ccflags-y += -D__CHECK_ENDIAN__ -I$(src) 18ccflags-y += -I$(src)
19 19
20obj-$(CONFIG_IWLDVM) += dvm/ 20obj-$(CONFIG_IWLDVM) += dvm/
21obj-$(CONFIG_IWLMVM) += mvm/ 21obj-$(CONFIG_IWLMVM) += mvm/
diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/Makefile b/drivers/net/wireless/intel/iwlwifi/dvm/Makefile
index 4d19685f31c3..b256a354953a 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/Makefile
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/Makefile
@@ -10,4 +10,4 @@ iwldvm-objs += rxon.o devices.o
10iwldvm-$(CONFIG_IWLWIFI_LEDS) += led.o 10iwldvm-$(CONFIG_IWLWIFI_LEDS) += led.o
11iwldvm-$(CONFIG_IWLWIFI_DEBUGFS) += debugfs.o 11iwldvm-$(CONFIG_IWLWIFI_DEBUGFS) += debugfs.o
12 12
13ccflags-y += -D__CHECK_ENDIAN__ -I$(src)/../ 13ccflags-y += -I$(src)/../
diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-fw-file.h b/drivers/net/wireless/intel/iwlwifi/iwl-fw-file.h
index 1ad0ec180d5d..84813b550ef1 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-fw-file.h
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-fw-file.h
@@ -228,7 +228,7 @@ enum iwl_ucode_tlv_flag {
228 IWL_UCODE_TLV_FLAGS_BCAST_FILTERING = BIT(29), 228 IWL_UCODE_TLV_FLAGS_BCAST_FILTERING = BIT(29),
229}; 229};
230 230
231typedef unsigned int __bitwise__ iwl_ucode_tlv_api_t; 231typedef unsigned int __bitwise iwl_ucode_tlv_api_t;
232 232
233/** 233/**
234 * enum iwl_ucode_tlv_api - ucode api 234 * enum iwl_ucode_tlv_api - ucode api
@@ -258,7 +258,7 @@ enum iwl_ucode_tlv_api {
258#endif 258#endif
259}; 259};
260 260
261typedef unsigned int __bitwise__ iwl_ucode_tlv_capa_t; 261typedef unsigned int __bitwise iwl_ucode_tlv_capa_t;
262 262
263/** 263/**
264 * enum iwl_ucode_tlv_capa - ucode capabilities 264 * enum iwl_ucode_tlv_capa - ucode capabilities
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/Makefile b/drivers/net/wireless/intel/iwlwifi/mvm/Makefile
index 2e06dfc1c477..83ac807e547d 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/Makefile
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/Makefile
@@ -9,4 +9,4 @@ iwlmvm-$(CONFIG_IWLWIFI_LEDS) += led.o
9iwlmvm-y += tof.o fw-dbg.o 9iwlmvm-y += tof.o fw-dbg.o
10iwlmvm-$(CONFIG_PM) += d3.o 10iwlmvm-$(CONFIG_PM) += d3.o
11 11
12ccflags-y += -D__CHECK_ENDIAN__ -I$(src)/../ 12ccflags-y += -I$(src)/../
diff --git a/drivers/net/wireless/intersil/orinoco/Makefile b/drivers/net/wireless/intersil/orinoco/Makefile
index bfdefb85abcd..b7ecef820f76 100644
--- a/drivers/net/wireless/intersil/orinoco/Makefile
+++ b/drivers/net/wireless/intersil/orinoco/Makefile
@@ -12,6 +12,3 @@ obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o
12obj-$(CONFIG_NORTEL_HERMES) += orinoco_nortel.o 12obj-$(CONFIG_NORTEL_HERMES) += orinoco_nortel.o
13obj-$(CONFIG_PCMCIA_SPECTRUM) += spectrum_cs.o 13obj-$(CONFIG_PCMCIA_SPECTRUM) += spectrum_cs.o
14obj-$(CONFIG_ORINOCO_USB) += orinoco_usb.o 14obj-$(CONFIG_ORINOCO_USB) += orinoco_usb.o
15
16# Orinoco should be endian clean.
17ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/mediatek/mt7601u/Makefile b/drivers/net/wireless/mediatek/mt7601u/Makefile
index ea9ed8a5db4d..08fc802ead4b 100644
--- a/drivers/net/wireless/mediatek/mt7601u/Makefile
+++ b/drivers/net/wireless/mediatek/mt7601u/Makefile
@@ -1,5 +1,3 @@
1ccflags-y += -D__CHECK_ENDIAN__
2
3obj-$(CONFIG_MT7601U) += mt7601u.o 1obj-$(CONFIG_MT7601U) += mt7601u.o
4 2
5mt7601u-objs = \ 3mt7601u-objs = \
diff --git a/drivers/net/wireless/realtek/rtlwifi/Makefile b/drivers/net/wireless/realtek/rtlwifi/Makefile
index ad6d3c52ec57..84c2e826fa1d 100644
--- a/drivers/net/wireless/realtek/rtlwifi/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/Makefile
@@ -30,5 +30,3 @@ obj-$(CONFIG_RTLBTCOEXIST) += btcoexist/
30obj-$(CONFIG_RTL8723_COMMON) += rtl8723com/ 30obj-$(CONFIG_RTL8723_COMMON) += rtl8723com/
31obj-$(CONFIG_RTL8821AE) += rtl8821ae/ 31obj-$(CONFIG_RTL8821AE) += rtl8821ae/
32obj-$(CONFIG_RTL8192EE) += rtl8192ee/ 32obj-$(CONFIG_RTL8192EE) += rtl8192ee/
33
34ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile b/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
index 47ceecfcb7dc..d1454d4f08a5 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
@@ -3,5 +3,3 @@ btcoexist-objs := halbtc8723b2ant.o \
3 rtl_btc.o 3 rtl_btc.o
4 4
5obj-$(CONFIG_RTLBTCOEXIST) += btcoexist.o 5obj-$(CONFIG_RTLBTCOEXIST) += btcoexist.o
6
7ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/Makefile
index 676e7de27f27..dae4f0f19cd3 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/Makefile
@@ -11,5 +11,3 @@ rtl8188ee-objs := \
11 trx.o 11 trx.o
12 12
13obj-$(CONFIG_RTL8188EE) += rtl8188ee.o 13obj-$(CONFIG_RTL8188EE) += rtl8188ee.o
14
15ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192c/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8192c/Makefile
index aee42d7ae8a2..0546b7556259 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192c/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192c/Makefile
@@ -5,5 +5,3 @@ rtl8192c-common-objs := \
5 phy_common.o 5 phy_common.o
6 6
7obj-$(CONFIG_RTL8192C_COMMON) += rtl8192c-common.o 7obj-$(CONFIG_RTL8192C_COMMON) += rtl8192c-common.o
8
9ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/Makefile
index c0cb0cfe7d37..577c7adbc322 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/Makefile
@@ -9,5 +9,3 @@ rtl8192ce-objs := \
9 trx.o 9 trx.o
10 10
11obj-$(CONFIG_RTL8192CE) += rtl8192ce.o 11obj-$(CONFIG_RTL8192CE) += rtl8192ce.o
12
13ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/Makefile
index ad2de6b839ef..97437dadc287 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/Makefile
@@ -10,5 +10,3 @@ rtl8192cu-objs := \
10 trx.o 10 trx.o
11 11
12obj-$(CONFIG_RTL8192CU) += rtl8192cu.o 12obj-$(CONFIG_RTL8192CU) += rtl8192cu.o
13
14ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/Makefile
index e3213c8264b6..d0703f20d30c 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/Makefile
@@ -10,5 +10,3 @@ rtl8192de-objs := \
10 trx.o 10 trx.o
11 11
12obj-$(CONFIG_RTL8192DE) += rtl8192de.o 12obj-$(CONFIG_RTL8192DE) += rtl8192de.o
13
14ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/Makefile
index 0315eeda9b60..f254b9f64326 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/Makefile
@@ -12,5 +12,3 @@ rtl8192ee-objs := \
12 12
13 13
14obj-$(CONFIG_RTL8192EE) += rtl8192ee.o 14obj-$(CONFIG_RTL8192EE) += rtl8192ee.o
15
16ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/Makefile
index b7eb13819cbc..dfa9dbbe2cdf 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/Makefile
@@ -11,5 +11,3 @@ rtl8192se-objs := \
11 11
12obj-$(CONFIG_RTL8192SE) += rtl8192se.o 12obj-$(CONFIG_RTL8192SE) += rtl8192se.o
13 13
14ccflags-y += -D__CHECK_ENDIAN__
15
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/Makefile
index 6220672a96f4..e7607d2cb2ef 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/Makefile
@@ -14,5 +14,3 @@ rtl8723ae-objs := \
14 14
15 15
16obj-$(CONFIG_RTL8723AE) += rtl8723ae.o 16obj-$(CONFIG_RTL8723AE) += rtl8723ae.o
17
18ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/Makefile
index a77c34102792..a841cbd55d8e 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/Makefile
@@ -12,5 +12,3 @@ rtl8723be-objs := \
12 12
13 13
14obj-$(CONFIG_RTL8723BE) += rtl8723be.o 14obj-$(CONFIG_RTL8723BE) += rtl8723be.o
15
16ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723com/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8723com/Makefile
index 345a68adcf38..73da75526e2a 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723com/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723com/Makefile
@@ -5,5 +5,3 @@ rtl8723-common-objs := \
5 phy_common.o 5 phy_common.o
6 6
7obj-$(CONFIG_RTL8723_COMMON) += rtl8723-common.o 7obj-$(CONFIG_RTL8723_COMMON) += rtl8723-common.o
8
9ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/Makefile b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/Makefile
index f7a26f71197e..8ca406b95f02 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/Makefile
@@ -12,5 +12,3 @@ rtl8821ae-objs := \
12 12
13 13
14obj-$(CONFIG_RTL8821AE) += rtl8821ae.o 14obj-$(CONFIG_RTL8821AE) += rtl8821ae.o
15
16ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/ti/wl1251/Makefile b/drivers/net/wireless/ti/wl1251/Makefile
index a5c6328b5f72..58b4f935a3f6 100644
--- a/drivers/net/wireless/ti/wl1251/Makefile
+++ b/drivers/net/wireless/ti/wl1251/Makefile
@@ -6,5 +6,3 @@ wl1251_sdio-objs += sdio.o
6obj-$(CONFIG_WL1251) += wl1251.o 6obj-$(CONFIG_WL1251) += wl1251.o
7obj-$(CONFIG_WL1251_SPI) += wl1251_spi.o 7obj-$(CONFIG_WL1251_SPI) += wl1251_spi.o
8obj-$(CONFIG_WL1251_SDIO) += wl1251_sdio.o 8obj-$(CONFIG_WL1251_SDIO) += wl1251_sdio.o
9
10ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/ti/wlcore/Makefile b/drivers/net/wireless/ti/wlcore/Makefile
index 0a69c1373643..e286713b3c18 100644
--- a/drivers/net/wireless/ti/wlcore/Makefile
+++ b/drivers/net/wireless/ti/wlcore/Makefile
@@ -8,5 +8,3 @@ wlcore-$(CONFIG_NL80211_TESTMODE) += testmode.o
8obj-$(CONFIG_WLCORE) += wlcore.o 8obj-$(CONFIG_WLCORE) += wlcore.o
9obj-$(CONFIG_WLCORE_SPI) += wlcore_spi.o 9obj-$(CONFIG_WLCORE_SPI) += wlcore_spi.o
10obj-$(CONFIG_WLCORE_SDIO) += wlcore_sdio.o 10obj-$(CONFIG_WLCORE_SDIO) += wlcore_sdio.o
11
12ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/staging/rtl8188eu/Makefile b/drivers/staging/rtl8188eu/Makefile
index 29b9834870fd..27af86e05098 100644
--- a/drivers/staging/rtl8188eu/Makefile
+++ b/drivers/staging/rtl8188eu/Makefile
@@ -53,4 +53,4 @@ r8188eu-y := \
53 53
54obj-$(CONFIG_R8188EU) := r8188eu.o 54obj-$(CONFIG_R8188EU) := r8188eu.o
55 55
56ccflags-y += -D__CHECK_ENDIAN__ -I$(srctree)/$(src)/include 56ccflags-y += -I$(srctree)/$(src)/include
diff --git a/drivers/staging/rtl8192e/Makefile b/drivers/staging/rtl8192e/Makefile
index cb18db74d78c..7101fcc8871b 100644
--- a/drivers/staging/rtl8192e/Makefile
+++ b/drivers/staging/rtl8192e/Makefile
@@ -17,5 +17,3 @@ obj-$(CONFIG_RTLLIB_CRYPTO_TKIP) += rtllib_crypt_tkip.o
17obj-$(CONFIG_RTLLIB_CRYPTO_WEP) += rtllib_crypt_wep.o 17obj-$(CONFIG_RTLLIB_CRYPTO_WEP) += rtllib_crypt_wep.o
18 18
19obj-$(CONFIG_RTL8192E) += rtl8192e/ 19obj-$(CONFIG_RTL8192E) += rtl8192e/
20
21ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/staging/rtl8192e/rtl8192e/Makefile b/drivers/staging/rtl8192e/rtl8192e/Makefile
index a2c4fb4ba1af..176a4a2b8b20 100644
--- a/drivers/staging/rtl8192e/rtl8192e/Makefile
+++ b/drivers/staging/rtl8192e/rtl8192e/Makefile
@@ -16,5 +16,3 @@ r8192e_pci-objs := \
16 rtl_wx.o \ 16 rtl_wx.o \
17 17
18obj-$(CONFIG_RTL8192E) += r8192e_pci.o 18obj-$(CONFIG_RTL8192E) += r8192e_pci.o
19
20ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 6e29d053843d..e2be447752c2 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1749,7 +1749,6 @@ out:
1749static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg, 1749static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
1750 const char *name) 1750 const char *name)
1751{ 1751{
1752 struct se_portal_group *se_tpg;
1753 struct vhost_scsi_nexus *tv_nexus; 1752 struct vhost_scsi_nexus *tv_nexus;
1754 1753
1755 mutex_lock(&tpg->tv_tpg_mutex); 1754 mutex_lock(&tpg->tv_tpg_mutex);
@@ -1758,7 +1757,6 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
1758 pr_debug("tpg->tpg_nexus already exists\n"); 1757 pr_debug("tpg->tpg_nexus already exists\n");
1759 return -EEXIST; 1758 return -EEXIST;
1760 } 1759 }
1761 se_tpg = &tpg->se_tpg;
1762 1760
1763 tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL); 1761 tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL);
1764 if (!tv_nexus) { 1762 if (!tv_nexus) {
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 266354390c8f..c0f81e8cb50c 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -49,7 +49,7 @@ enum {
49 49
50INTERVAL_TREE_DEFINE(struct vhost_umem_node, 50INTERVAL_TREE_DEFINE(struct vhost_umem_node,
51 rb, __u64, __subtree_last, 51 rb, __u64, __subtree_last,
52 START, LAST, , vhost_umem_interval_tree); 52 START, LAST, static inline, vhost_umem_interval_tree);
53 53
54#ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY 54#ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY
55static void vhost_disable_cross_endian(struct vhost_virtqueue *vq) 55static void vhost_disable_cross_endian(struct vhost_virtqueue *vq)
@@ -290,6 +290,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
290 vq->avail = NULL; 290 vq->avail = NULL;
291 vq->used = NULL; 291 vq->used = NULL;
292 vq->last_avail_idx = 0; 292 vq->last_avail_idx = 0;
293 vq->last_used_event = 0;
293 vq->avail_idx = 0; 294 vq->avail_idx = 0;
294 vq->last_used_idx = 0; 295 vq->last_used_idx = 0;
295 vq->signalled_used = 0; 296 vq->signalled_used = 0;
@@ -719,7 +720,7 @@ static int memory_access_ok(struct vhost_dev *d, struct vhost_umem *umem,
719static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len, 720static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
720 struct iovec iov[], int iov_size, int access); 721 struct iovec iov[], int iov_size, int access);
721 722
722static int vhost_copy_to_user(struct vhost_virtqueue *vq, void *to, 723static int vhost_copy_to_user(struct vhost_virtqueue *vq, void __user *to,
723 const void *from, unsigned size) 724 const void *from, unsigned size)
724{ 725{
725 int ret; 726 int ret;
@@ -749,7 +750,7 @@ out:
749} 750}
750 751
751static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to, 752static int vhost_copy_from_user(struct vhost_virtqueue *vq, void *to,
752 void *from, unsigned size) 753 void __user *from, unsigned size)
753{ 754{
754 int ret; 755 int ret;
755 756
@@ -783,7 +784,7 @@ out:
783} 784}
784 785
785static void __user *__vhost_get_user(struct vhost_virtqueue *vq, 786static void __user *__vhost_get_user(struct vhost_virtqueue *vq,
786 void *addr, unsigned size) 787 void __user *addr, unsigned size)
787{ 788{
788 int ret; 789 int ret;
789 790
@@ -934,8 +935,8 @@ static int umem_access_ok(u64 uaddr, u64 size, int access)
934 return 0; 935 return 0;
935} 936}
936 937
937int vhost_process_iotlb_msg(struct vhost_dev *dev, 938static int vhost_process_iotlb_msg(struct vhost_dev *dev,
938 struct vhost_iotlb_msg *msg) 939 struct vhost_iotlb_msg *msg)
939{ 940{
940 int ret = 0; 941 int ret = 0;
941 942
@@ -1324,7 +1325,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
1324 r = -EINVAL; 1325 r = -EINVAL;
1325 break; 1326 break;
1326 } 1327 }
1327 vq->last_avail_idx = s.num; 1328 vq->last_avail_idx = vq->last_used_event = s.num;
1328 /* Forget the cached index value. */ 1329 /* Forget the cached index value. */
1329 vq->avail_idx = vq->last_avail_idx; 1330 vq->avail_idx = vq->last_avail_idx;
1330 break; 1331 break;
@@ -2159,10 +2160,6 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
2159 __u16 old, new; 2160 __u16 old, new;
2160 __virtio16 event; 2161 __virtio16 event;
2161 bool v; 2162 bool v;
2162 /* Flush out used index updates. This is paired
2163 * with the barrier that the Guest executes when enabling
2164 * interrupts. */
2165 smp_mb();
2166 2163
2167 if (vhost_has_feature(vq, VIRTIO_F_NOTIFY_ON_EMPTY) && 2164 if (vhost_has_feature(vq, VIRTIO_F_NOTIFY_ON_EMPTY) &&
2168 unlikely(vq->avail_idx == vq->last_avail_idx)) 2165 unlikely(vq->avail_idx == vq->last_avail_idx))
@@ -2170,6 +2167,10 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
2170 2167
2171 if (!vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX)) { 2168 if (!vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX)) {
2172 __virtio16 flags; 2169 __virtio16 flags;
2170 /* Flush out used index updates. This is paired
2171 * with the barrier that the Guest executes when enabling
2172 * interrupts. */
2173 smp_mb();
2173 if (vhost_get_user(vq, flags, &vq->avail->flags)) { 2174 if (vhost_get_user(vq, flags, &vq->avail->flags)) {
2174 vq_err(vq, "Failed to get flags"); 2175 vq_err(vq, "Failed to get flags");
2175 return true; 2176 return true;
@@ -2184,11 +2185,26 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
2184 if (unlikely(!v)) 2185 if (unlikely(!v))
2185 return true; 2186 return true;
2186 2187
2188 /* We're sure if the following conditions are met, there's no
2189 * need to notify guest:
2190 * 1) cached used event is ahead of new
2191 * 2) old to new updating does not cross cached used event. */
2192 if (vring_need_event(vq->last_used_event, new + vq->num, new) &&
2193 !vring_need_event(vq->last_used_event, new, old))
2194 return false;
2195
2196 /* Flush out used index updates. This is paired
2197 * with the barrier that the Guest executes when enabling
2198 * interrupts. */
2199 smp_mb();
2200
2187 if (vhost_get_user(vq, event, vhost_used_event(vq))) { 2201 if (vhost_get_user(vq, event, vhost_used_event(vq))) {
2188 vq_err(vq, "Failed to get used event idx"); 2202 vq_err(vq, "Failed to get used event idx");
2189 return true; 2203 return true;
2190 } 2204 }
2191 return vring_need_event(vhost16_to_cpu(vq, event), new, old); 2205 vq->last_used_event = vhost16_to_cpu(vq, event);
2206
2207 return vring_need_event(vq->last_used_event, new, old);
2192} 2208}
2193 2209
2194/* This actually signals the guest, using eventfd. */ 2210/* This actually signals the guest, using eventfd. */
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 78f3c5fc02e4..a9cbbb148f46 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -107,6 +107,9 @@ struct vhost_virtqueue {
107 /* Last index we used. */ 107 /* Last index we used. */
108 u16 last_used_idx; 108 u16 last_used_idx;
109 109
110 /* Last used evet we've seen */
111 u16 last_used_event;
112
110 /* Used flags */ 113 /* Used flags */
111 u16 used_flags; 114 u16 used_flags;
112 115
diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 3bb02c60a2f5..bb8971f2a634 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Since these may be in userspace, we use (inline) accessors. 4 * Since these may be in userspace, we use (inline) accessors.
5 */ 5 */
6#include <linux/compiler.h>
6#include <linux/module.h> 7#include <linux/module.h>
7#include <linux/vringh.h> 8#include <linux/vringh.h>
8#include <linux/virtio_ring.h> 9#include <linux/virtio_ring.h>
@@ -820,13 +821,13 @@ EXPORT_SYMBOL(vringh_need_notify_user);
820static inline int getu16_kern(const struct vringh *vrh, 821static inline int getu16_kern(const struct vringh *vrh,
821 u16 *val, const __virtio16 *p) 822 u16 *val, const __virtio16 *p)
822{ 823{
823 *val = vringh16_to_cpu(vrh, ACCESS_ONCE(*p)); 824 *val = vringh16_to_cpu(vrh, READ_ONCE(*p));
824 return 0; 825 return 0;
825} 826}
826 827
827static inline int putu16_kern(const struct vringh *vrh, __virtio16 *p, u16 val) 828static inline int putu16_kern(const struct vringh *vrh, __virtio16 *p, u16 val)
828{ 829{
829 ACCESS_ONCE(*p) = cpu_to_vringh16(vrh, val); 830 WRITE_ONCE(*p, cpu_to_vringh16(vrh, val));
830 return 0; 831 return 0;
831} 832}
832 833
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index e6b70966c19d..bbbf588540ed 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -50,11 +50,10 @@ static u32 vhost_transport_get_local_cid(void)
50 return VHOST_VSOCK_DEFAULT_HOST_CID; 50 return VHOST_VSOCK_DEFAULT_HOST_CID;
51} 51}
52 52
53static struct vhost_vsock *vhost_vsock_get(u32 guest_cid) 53static struct vhost_vsock *__vhost_vsock_get(u32 guest_cid)
54{ 54{
55 struct vhost_vsock *vsock; 55 struct vhost_vsock *vsock;
56 56
57 spin_lock_bh(&vhost_vsock_lock);
58 list_for_each_entry(vsock, &vhost_vsock_list, list) { 57 list_for_each_entry(vsock, &vhost_vsock_list, list) {
59 u32 other_cid = vsock->guest_cid; 58 u32 other_cid = vsock->guest_cid;
60 59
@@ -63,15 +62,24 @@ static struct vhost_vsock *vhost_vsock_get(u32 guest_cid)
63 continue; 62 continue;
64 63
65 if (other_cid == guest_cid) { 64 if (other_cid == guest_cid) {
66 spin_unlock_bh(&vhost_vsock_lock);
67 return vsock; 65 return vsock;
68 } 66 }
69 } 67 }
70 spin_unlock_bh(&vhost_vsock_lock);
71 68
72 return NULL; 69 return NULL;
73} 70}
74 71
72static struct vhost_vsock *vhost_vsock_get(u32 guest_cid)
73{
74 struct vhost_vsock *vsock;
75
76 spin_lock_bh(&vhost_vsock_lock);
77 vsock = __vhost_vsock_get(guest_cid);
78 spin_unlock_bh(&vhost_vsock_lock);
79
80 return vsock;
81}
82
75static void 83static void
76vhost_transport_do_send_pkt(struct vhost_vsock *vsock, 84vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
77 struct vhost_virtqueue *vq) 85 struct vhost_virtqueue *vq)
@@ -559,11 +567,12 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid)
559 return -EINVAL; 567 return -EINVAL;
560 568
561 /* Refuse if CID is already in use */ 569 /* Refuse if CID is already in use */
562 other = vhost_vsock_get(guest_cid);
563 if (other && other != vsock)
564 return -EADDRINUSE;
565
566 spin_lock_bh(&vhost_vsock_lock); 570 spin_lock_bh(&vhost_vsock_lock);
571 other = __vhost_vsock_get(guest_cid);
572 if (other && other != vsock) {
573 spin_unlock_bh(&vhost_vsock_lock);
574 return -EADDRINUSE;
575 }
567 vsock->guest_cid = guest_cid; 576 vsock->guest_cid = guest_cid;
568 spin_unlock_bh(&vhost_vsock_lock); 577 spin_unlock_bh(&vhost_vsock_lock);
569 578
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 48bfea91dbca..d47a2fcef818 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -489,6 +489,7 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
489}; 489};
490 490
491 491
492static void virtio_mmio_release_dev_empty(struct device *_d) {}
492 493
493/* Platform device */ 494/* Platform device */
494 495
@@ -511,6 +512,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
511 return -ENOMEM; 512 return -ENOMEM;
512 513
513 vm_dev->vdev.dev.parent = &pdev->dev; 514 vm_dev->vdev.dev.parent = &pdev->dev;
515 vm_dev->vdev.dev.release = virtio_mmio_release_dev_empty;
514 vm_dev->vdev.config = &virtio_mmio_config_ops; 516 vm_dev->vdev.config = &virtio_mmio_config_ops;
515 vm_dev->pdev = pdev; 517 vm_dev->pdev = pdev;
516 INIT_LIST_HEAD(&vm_dev->virtqueues); 518 INIT_LIST_HEAD(&vm_dev->virtqueues);
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index d9a905827967..186cbab327b8 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -37,7 +37,7 @@ void vp_synchronize_vectors(struct virtio_device *vdev)
37 synchronize_irq(vp_dev->pci_dev->irq); 37 synchronize_irq(vp_dev->pci_dev->irq);
38 38
39 for (i = 0; i < vp_dev->msix_vectors; ++i) 39 for (i = 0; i < vp_dev->msix_vectors; ++i)
40 synchronize_irq(vp_dev->msix_entries[i].vector); 40 synchronize_irq(pci_irq_vector(vp_dev->pci_dev, i));
41} 41}
42 42
43/* the notify function used when creating a virt queue */ 43/* the notify function used when creating a virt queue */
@@ -102,41 +102,6 @@ static irqreturn_t vp_interrupt(int irq, void *opaque)
102 return vp_vring_interrupt(irq, opaque); 102 return vp_vring_interrupt(irq, opaque);
103} 103}
104 104
105static void vp_free_vectors(struct virtio_device *vdev)
106{
107 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
108 int i;
109
110 if (vp_dev->intx_enabled) {
111 free_irq(vp_dev->pci_dev->irq, vp_dev);
112 vp_dev->intx_enabled = 0;
113 }
114
115 for (i = 0; i < vp_dev->msix_used_vectors; ++i)
116 free_irq(vp_dev->msix_entries[i].vector, vp_dev);
117
118 for (i = 0; i < vp_dev->msix_vectors; i++)
119 if (vp_dev->msix_affinity_masks[i])
120 free_cpumask_var(vp_dev->msix_affinity_masks[i]);
121
122 if (vp_dev->msix_enabled) {
123 /* Disable the vector used for configuration */
124 vp_dev->config_vector(vp_dev, VIRTIO_MSI_NO_VECTOR);
125
126 pci_disable_msix(vp_dev->pci_dev);
127 vp_dev->msix_enabled = 0;
128 }
129
130 vp_dev->msix_vectors = 0;
131 vp_dev->msix_used_vectors = 0;
132 kfree(vp_dev->msix_names);
133 vp_dev->msix_names = NULL;
134 kfree(vp_dev->msix_entries);
135 vp_dev->msix_entries = NULL;
136 kfree(vp_dev->msix_affinity_masks);
137 vp_dev->msix_affinity_masks = NULL;
138}
139
140static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors, 105static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
141 bool per_vq_vectors) 106 bool per_vq_vectors)
142{ 107{
@@ -147,10 +112,6 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
147 112
148 vp_dev->msix_vectors = nvectors; 113 vp_dev->msix_vectors = nvectors;
149 114
150 vp_dev->msix_entries = kmalloc(nvectors * sizeof *vp_dev->msix_entries,
151 GFP_KERNEL);
152 if (!vp_dev->msix_entries)
153 goto error;
154 vp_dev->msix_names = kmalloc(nvectors * sizeof *vp_dev->msix_names, 115 vp_dev->msix_names = kmalloc(nvectors * sizeof *vp_dev->msix_names,
155 GFP_KERNEL); 116 GFP_KERNEL);
156 if (!vp_dev->msix_names) 117 if (!vp_dev->msix_names)
@@ -165,12 +126,9 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
165 GFP_KERNEL)) 126 GFP_KERNEL))
166 goto error; 127 goto error;
167 128
168 for (i = 0; i < nvectors; ++i) 129 err = pci_alloc_irq_vectors(vp_dev->pci_dev, nvectors, nvectors,
169 vp_dev->msix_entries[i].entry = i; 130 PCI_IRQ_MSIX);
170 131 if (err < 0)
171 err = pci_enable_msix_exact(vp_dev->pci_dev,
172 vp_dev->msix_entries, nvectors);
173 if (err)
174 goto error; 132 goto error;
175 vp_dev->msix_enabled = 1; 133 vp_dev->msix_enabled = 1;
176 134
@@ -178,7 +136,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
178 v = vp_dev->msix_used_vectors; 136 v = vp_dev->msix_used_vectors;
179 snprintf(vp_dev->msix_names[v], sizeof *vp_dev->msix_names, 137 snprintf(vp_dev->msix_names[v], sizeof *vp_dev->msix_names,
180 "%s-config", name); 138 "%s-config", name);
181 err = request_irq(vp_dev->msix_entries[v].vector, 139 err = request_irq(pci_irq_vector(vp_dev->pci_dev, v),
182 vp_config_changed, 0, vp_dev->msix_names[v], 140 vp_config_changed, 0, vp_dev->msix_names[v],
183 vp_dev); 141 vp_dev);
184 if (err) 142 if (err)
@@ -197,7 +155,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
197 v = vp_dev->msix_used_vectors; 155 v = vp_dev->msix_used_vectors;
198 snprintf(vp_dev->msix_names[v], sizeof *vp_dev->msix_names, 156 snprintf(vp_dev->msix_names[v], sizeof *vp_dev->msix_names,
199 "%s-virtqueues", name); 157 "%s-virtqueues", name);
200 err = request_irq(vp_dev->msix_entries[v].vector, 158 err = request_irq(pci_irq_vector(vp_dev->pci_dev, v),
201 vp_vring_interrupt, 0, vp_dev->msix_names[v], 159 vp_vring_interrupt, 0, vp_dev->msix_names[v],
202 vp_dev); 160 vp_dev);
203 if (err) 161 if (err)
@@ -206,19 +164,6 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
206 } 164 }
207 return 0; 165 return 0;
208error: 166error:
209 vp_free_vectors(vdev);
210 return err;
211}
212
213static int vp_request_intx(struct virtio_device *vdev)
214{
215 int err;
216 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
217
218 err = request_irq(vp_dev->pci_dev->irq, vp_interrupt,
219 IRQF_SHARED, dev_name(&vdev->dev), vp_dev);
220 if (!err)
221 vp_dev->intx_enabled = 1;
222 return err; 167 return err;
223} 168}
224 169
@@ -276,67 +221,88 @@ void vp_del_vqs(struct virtio_device *vdev)
276{ 221{
277 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 222 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
278 struct virtqueue *vq, *n; 223 struct virtqueue *vq, *n;
279 struct virtio_pci_vq_info *info; 224 int i;
280 225
281 list_for_each_entry_safe(vq, n, &vdev->vqs, list) { 226 list_for_each_entry_safe(vq, n, &vdev->vqs, list) {
282 info = vp_dev->vqs[vq->index]; 227 if (vp_dev->per_vq_vectors) {
283 if (vp_dev->per_vq_vectors && 228 int v = vp_dev->vqs[vq->index]->msix_vector;
284 info->msix_vector != VIRTIO_MSI_NO_VECTOR) 229
285 free_irq(vp_dev->msix_entries[info->msix_vector].vector, 230 if (v != VIRTIO_MSI_NO_VECTOR)
286 vq); 231 free_irq(pci_irq_vector(vp_dev->pci_dev, v),
232 vq);
233 }
287 vp_del_vq(vq); 234 vp_del_vq(vq);
288 } 235 }
289 vp_dev->per_vq_vectors = false; 236 vp_dev->per_vq_vectors = false;
290 237
291 vp_free_vectors(vdev); 238 if (vp_dev->intx_enabled) {
239 free_irq(vp_dev->pci_dev->irq, vp_dev);
240 vp_dev->intx_enabled = 0;
241 }
242
243 for (i = 0; i < vp_dev->msix_used_vectors; ++i)
244 free_irq(pci_irq_vector(vp_dev->pci_dev, i), vp_dev);
245
246 for (i = 0; i < vp_dev->msix_vectors; i++)
247 if (vp_dev->msix_affinity_masks[i])
248 free_cpumask_var(vp_dev->msix_affinity_masks[i]);
249
250 if (vp_dev->msix_enabled) {
251 /* Disable the vector used for configuration */
252 vp_dev->config_vector(vp_dev, VIRTIO_MSI_NO_VECTOR);
253
254 pci_free_irq_vectors(vp_dev->pci_dev);
255 vp_dev->msix_enabled = 0;
256 }
257
258 vp_dev->msix_vectors = 0;
259 vp_dev->msix_used_vectors = 0;
260 kfree(vp_dev->msix_names);
261 vp_dev->msix_names = NULL;
262 kfree(vp_dev->msix_affinity_masks);
263 vp_dev->msix_affinity_masks = NULL;
292 kfree(vp_dev->vqs); 264 kfree(vp_dev->vqs);
293 vp_dev->vqs = NULL; 265 vp_dev->vqs = NULL;
294} 266}
295 267
296static int vp_try_to_find_vqs(struct virtio_device *vdev, unsigned nvqs, 268static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
297 struct virtqueue *vqs[], 269 struct virtqueue *vqs[],
298 vq_callback_t *callbacks[], 270 vq_callback_t *callbacks[],
299 const char * const names[], 271 const char * const names[],
300 bool use_msix,
301 bool per_vq_vectors) 272 bool per_vq_vectors)
302{ 273{
303 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 274 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
304 u16 msix_vec; 275 u16 msix_vec;
305 int i, err, nvectors, allocated_vectors; 276 int i, err, nvectors, allocated_vectors;
306 277
307 vp_dev->vqs = kmalloc(nvqs * sizeof *vp_dev->vqs, GFP_KERNEL); 278 vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
308 if (!vp_dev->vqs) 279 if (!vp_dev->vqs)
309 return -ENOMEM; 280 return -ENOMEM;
310 281
311 if (!use_msix) { 282 if (per_vq_vectors) {
312 /* Old style: one normal interrupt for change and all vqs. */ 283 /* Best option: one for change interrupt, one per vq. */
313 err = vp_request_intx(vdev); 284 nvectors = 1;
314 if (err) 285 for (i = 0; i < nvqs; ++i)
315 goto error_find; 286 if (callbacks[i])
287 ++nvectors;
316 } else { 288 } else {
317 if (per_vq_vectors) { 289 /* Second best: one for change, shared for all vqs. */
318 /* Best option: one for change interrupt, one per vq. */ 290 nvectors = 2;
319 nvectors = 1;
320 for (i = 0; i < nvqs; ++i)
321 if (callbacks[i])
322 ++nvectors;
323 } else {
324 /* Second best: one for change, shared for all vqs. */
325 nvectors = 2;
326 }
327
328 err = vp_request_msix_vectors(vdev, nvectors, per_vq_vectors);
329 if (err)
330 goto error_find;
331 } 291 }
332 292
293 err = vp_request_msix_vectors(vdev, nvectors, per_vq_vectors);
294 if (err)
295 goto error_find;
296
333 vp_dev->per_vq_vectors = per_vq_vectors; 297 vp_dev->per_vq_vectors = per_vq_vectors;
334 allocated_vectors = vp_dev->msix_used_vectors; 298 allocated_vectors = vp_dev->msix_used_vectors;
335 for (i = 0; i < nvqs; ++i) { 299 for (i = 0; i < nvqs; ++i) {
336 if (!names[i]) { 300 if (!names[i]) {
337 vqs[i] = NULL; 301 vqs[i] = NULL;
338 continue; 302 continue;
339 } else if (!callbacks[i] || !vp_dev->msix_enabled) 303 }
304
305 if (!callbacks[i])
340 msix_vec = VIRTIO_MSI_NO_VECTOR; 306 msix_vec = VIRTIO_MSI_NO_VECTOR;
341 else if (vp_dev->per_vq_vectors) 307 else if (vp_dev->per_vq_vectors)
342 msix_vec = allocated_vectors++; 308 msix_vec = allocated_vectors++;
@@ -356,14 +322,12 @@ static int vp_try_to_find_vqs(struct virtio_device *vdev, unsigned nvqs,
356 sizeof *vp_dev->msix_names, 322 sizeof *vp_dev->msix_names,
357 "%s-%s", 323 "%s-%s",
358 dev_name(&vp_dev->vdev.dev), names[i]); 324 dev_name(&vp_dev->vdev.dev), names[i]);
359 err = request_irq(vp_dev->msix_entries[msix_vec].vector, 325 err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec),
360 vring_interrupt, 0, 326 vring_interrupt, 0,
361 vp_dev->msix_names[msix_vec], 327 vp_dev->msix_names[msix_vec],
362 vqs[i]); 328 vqs[i]);
363 if (err) { 329 if (err)
364 vp_del_vq(vqs[i]);
365 goto error_find; 330 goto error_find;
366 }
367 } 331 }
368 return 0; 332 return 0;
369 333
@@ -372,6 +336,43 @@ error_find:
372 return err; 336 return err;
373} 337}
374 338
339static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
340 struct virtqueue *vqs[], vq_callback_t *callbacks[],
341 const char * const names[])
342{
343 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
344 int i, err;
345
346 vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
347 if (!vp_dev->vqs)
348 return -ENOMEM;
349
350 err = request_irq(vp_dev->pci_dev->irq, vp_interrupt, IRQF_SHARED,
351 dev_name(&vdev->dev), vp_dev);
352 if (err)
353 goto out_del_vqs;
354
355 vp_dev->intx_enabled = 1;
356 vp_dev->per_vq_vectors = false;
357 for (i = 0; i < nvqs; ++i) {
358 if (!names[i]) {
359 vqs[i] = NULL;
360 continue;
361 }
362 vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i],
363 VIRTIO_MSI_NO_VECTOR);
364 if (IS_ERR(vqs[i])) {
365 err = PTR_ERR(vqs[i]);
366 goto out_del_vqs;
367 }
368 }
369
370 return 0;
371out_del_vqs:
372 vp_del_vqs(vdev);
373 return err;
374}
375
375/* the config->find_vqs() implementation */ 376/* the config->find_vqs() implementation */
376int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs, 377int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
377 struct virtqueue *vqs[], 378 struct virtqueue *vqs[],
@@ -381,17 +382,15 @@ int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
381 int err; 382 int err;
382 383
383 /* Try MSI-X with one vector per queue. */ 384 /* Try MSI-X with one vector per queue. */
384 err = vp_try_to_find_vqs(vdev, nvqs, vqs, callbacks, names, true, true); 385 err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, true);
385 if (!err) 386 if (!err)
386 return 0; 387 return 0;
387 /* Fallback: MSI-X with one vector for config, one shared for queues. */ 388 /* Fallback: MSI-X with one vector for config, one shared for queues. */
388 err = vp_try_to_find_vqs(vdev, nvqs, vqs, callbacks, names, 389 err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, false);
389 true, false);
390 if (!err) 390 if (!err)
391 return 0; 391 return 0;
392 /* Finally fall back to regular interrupts. */ 392 /* Finally fall back to regular interrupts. */
393 return vp_try_to_find_vqs(vdev, nvqs, vqs, callbacks, names, 393 return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names);
394 false, false);
395} 394}
396 395
397const char *vp_bus_name(struct virtio_device *vdev) 396const char *vp_bus_name(struct virtio_device *vdev)
@@ -419,7 +418,7 @@ int vp_set_vq_affinity(struct virtqueue *vq, int cpu)
419 418
420 if (vp_dev->msix_enabled) { 419 if (vp_dev->msix_enabled) {
421 mask = vp_dev->msix_affinity_masks[info->msix_vector]; 420 mask = vp_dev->msix_affinity_masks[info->msix_vector];
422 irq = vp_dev->msix_entries[info->msix_vector].vector; 421 irq = pci_irq_vector(vp_dev->pci_dev, info->msix_vector);
423 if (cpu == -1) 422 if (cpu == -1)
424 irq_set_affinity_hint(irq, NULL); 423 irq_set_affinity_hint(irq, NULL);
425 else { 424 else {
diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
index 28263200ed42..b2f666250ae0 100644
--- a/drivers/virtio/virtio_pci_common.h
+++ b/drivers/virtio/virtio_pci_common.h
@@ -85,7 +85,6 @@ struct virtio_pci_device {
85 /* MSI-X support */ 85 /* MSI-X support */
86 int msix_enabled; 86 int msix_enabled;
87 int intx_enabled; 87 int intx_enabled;
88 struct msix_entry *msix_entries;
89 cpumask_var_t *msix_affinity_masks; 88 cpumask_var_t *msix_affinity_masks;
90 /* Name strings for interrupts. This size should be enough, 89 /* Name strings for interrupts. This size should be enough,
91 * and I'm too lazy to allocate each name separately. */ 90 * and I'm too lazy to allocate each name separately. */
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index e76bd91a29da..4bf7ab375894 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -33,12 +33,12 @@ static inline u8 vp_ioread8(u8 __iomem *addr)
33{ 33{
34 return ioread8(addr); 34 return ioread8(addr);
35} 35}
36static inline u16 vp_ioread16 (u16 __iomem *addr) 36static inline u16 vp_ioread16 (__le16 __iomem *addr)
37{ 37{
38 return ioread16(addr); 38 return ioread16(addr);
39} 39}
40 40
41static inline u32 vp_ioread32(u32 __iomem *addr) 41static inline u32 vp_ioread32(__le32 __iomem *addr)
42{ 42{
43 return ioread32(addr); 43 return ioread32(addr);
44} 44}
@@ -48,12 +48,12 @@ static inline void vp_iowrite8(u8 value, u8 __iomem *addr)
48 iowrite8(value, addr); 48 iowrite8(value, addr);
49} 49}
50 50
51static inline void vp_iowrite16(u16 value, u16 __iomem *addr) 51static inline void vp_iowrite16(u16 value, __le16 __iomem *addr)
52{ 52{
53 iowrite16(value, addr); 53 iowrite16(value, addr);
54} 54}
55 55
56static inline void vp_iowrite32(u32 value, u32 __iomem *addr) 56static inline void vp_iowrite32(u32 value, __le32 __iomem *addr)
57{ 57{
58 iowrite32(value, addr); 58 iowrite32(value, addr);
59} 59}
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 489bfc61cf30..409aeaa49246 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -420,7 +420,7 @@ unmap_release:
420 if (i == err_idx) 420 if (i == err_idx)
421 break; 421 break;
422 vring_unmap_one(vq, &desc[i]); 422 vring_unmap_one(vq, &desc[i]);
423 i = vq->vring.desc[i].next; 423 i = virtio16_to_cpu(_vq->vdev, vq->vring.desc[i].next);
424 } 424 }
425 425
426 vq->vq.num_free += total_sg; 426 vq->vq.num_free += total_sg;
@@ -601,7 +601,7 @@ EXPORT_SYMBOL_GPL(virtqueue_kick);
601static void detach_buf(struct vring_virtqueue *vq, unsigned int head) 601static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
602{ 602{
603 unsigned int i, j; 603 unsigned int i, j;
604 u16 nextflag = cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT); 604 __virtio16 nextflag = cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT);
605 605
606 /* Clear data ptr. */ 606 /* Clear data ptr. */
607 vq->desc_state[head].data = NULL; 607 vq->desc_state[head].data = NULL;
@@ -649,7 +649,7 @@ static inline bool more_used(const struct vring_virtqueue *vq)
649 * @vq: the struct virtqueue we're talking about. 649 * @vq: the struct virtqueue we're talking about.
650 * @len: the length written into the buffer 650 * @len: the length written into the buffer
651 * 651 *
652 * If the driver wrote data into the buffer, @len will be set to the 652 * If the device wrote data into the buffer, @len will be set to the
653 * amount written. This means you don't need to clear the buffer 653 * amount written. This means you don't need to clear the buffer
654 * beforehand to ensure there's no data leakage in the case of short 654 * beforehand to ensure there's no data leakage in the case of short
655 * writes. 655 * writes.
diff --git a/fs/logfs/logfs.h b/fs/logfs/logfs.h
index 27d040e35faa..11209eefbe59 100644
--- a/fs/logfs/logfs.h
+++ b/fs/logfs/logfs.h
@@ -10,9 +10,7 @@
10#ifndef FS_LOGFS_LOGFS_H 10#ifndef FS_LOGFS_LOGFS_H
11#define FS_LOGFS_LOGFS_H 11#define FS_LOGFS_LOGFS_H
12 12
13#undef __CHECK_ENDIAN__ 13#include <linux/types.h>
14#define __CHECK_ENDIAN__
15
16#include <linux/btree.h> 14#include <linux/btree.h>
17#include <linux/crc32.h> 15#include <linux/crc32.h>
18#include <linux/fs.h> 16#include <linux/fs.h>
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 0f088f3a2fed..36d9896fbc1e 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -246,7 +246,7 @@ struct lruvec {
246#define ISOLATE_UNEVICTABLE ((__force isolate_mode_t)0x8) 246#define ISOLATE_UNEVICTABLE ((__force isolate_mode_t)0x8)
247 247
248/* LRU Isolation modes. */ 248/* LRU Isolation modes. */
249typedef unsigned __bitwise__ isolate_mode_t; 249typedef unsigned __bitwise isolate_mode_t;
250 250
251enum zone_watermarks { 251enum zone_watermarks {
252 WMARK_MIN, 252 WMARK_MIN,
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 5d494888a612..5def8e830fb0 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -111,8 +111,8 @@ struct uart_icount {
111 __u32 buf_overrun; 111 __u32 buf_overrun;
112}; 112};
113 113
114typedef unsigned int __bitwise__ upf_t; 114typedef unsigned int __bitwise upf_t;
115typedef unsigned int __bitwise__ upstat_t; 115typedef unsigned int __bitwise upstat_t;
116 116
117struct uart_port { 117struct uart_port {
118 spinlock_t lock; /* port lock */ 118 spinlock_t lock; /* port lock */
diff --git a/include/linux/types.h b/include/linux/types.h
index baf718324f4a..d501ad3ba247 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -154,8 +154,8 @@ typedef u64 dma_addr_t;
154typedef u32 dma_addr_t; 154typedef u32 dma_addr_t;
155#endif 155#endif
156 156
157typedef unsigned __bitwise__ gfp_t; 157typedef unsigned __bitwise gfp_t;
158typedef unsigned __bitwise__ fmode_t; 158typedef unsigned __bitwise fmode_t;
159 159
160#ifdef CONFIG_PHYS_ADDR_T_64BIT 160#ifdef CONFIG_PHYS_ADDR_T_64BIT
161typedef u64 phys_addr_t; 161typedef u64 phys_addr_t;
diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
index c1260d80ef30..df156f1d50b2 100644
--- a/include/scsi/iscsi_proto.h
+++ b/include/scsi/iscsi_proto.h
@@ -74,7 +74,7 @@ static inline int iscsi_sna_gte(u32 n1, u32 n2)
74#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;} 74#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
75 75
76/* initiator tags; opaque for target */ 76/* initiator tags; opaque for target */
77typedef uint32_t __bitwise__ itt_t; 77typedef uint32_t __bitwise itt_t;
78/* below makes sense only for initiator that created this tag */ 78/* below makes sense only for initiator that created this tag */
79#define build_itt(itt, age) ((__force itt_t)\ 79#define build_itt(itt, age) ((__force itt_t)\
80 ((itt) | ((age) << ISCSI_AGE_SHIFT))) 80 ((itt) | ((age) << ISCSI_AGE_SHIFT)))
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index c2119008990a..00558287936d 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -149,7 +149,7 @@ enum se_cmd_flags_table {
149 * Used by transport_send_check_condition_and_sense() 149 * Used by transport_send_check_condition_and_sense()
150 * to signal which ASC/ASCQ sense payload should be built. 150 * to signal which ASC/ASCQ sense payload should be built.
151 */ 151 */
152typedef unsigned __bitwise__ sense_reason_t; 152typedef unsigned __bitwise sense_reason_t;
153 153
154enum tcm_sense_reason_table { 154enum tcm_sense_reason_table {
155#define R(x) (__force sense_reason_t )(x) 155#define R(x) (__force sense_reason_t )(x)
diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
index bc2ef9fef7c8..a26c5c76ab62 100644
--- a/include/uapi/linux/Kbuild
+++ b/include/uapi/linux/Kbuild
@@ -462,6 +462,7 @@ header-y += virtio_rng.h
462header-y += virtio_scsi.h 462header-y += virtio_scsi.h
463header-y += virtio_types.h 463header-y += virtio_types.h
464header-y += virtio_vsock.h 464header-y += virtio_vsock.h
465header-y += virtio_crypto.h
465header-y += vm_sockets.h 466header-y += vm_sockets.h
466header-y += vt.h 467header-y += vt.h
467header-y += vtpm_proxy.h 468header-y += vtpm_proxy.h
diff --git a/include/uapi/linux/types.h b/include/uapi/linux/types.h
index acf0979b790a..41e5914f0a8e 100644
--- a/include/uapi/linux/types.h
+++ b/include/uapi/linux/types.h
@@ -23,11 +23,7 @@
23#else 23#else
24#define __bitwise__ 24#define __bitwise__
25#endif 25#endif
26#ifdef __CHECK_ENDIAN__
27#define __bitwise __bitwise__ 26#define __bitwise __bitwise__
28#else
29#define __bitwise
30#endif
31 27
32typedef __u16 __bitwise __le16; 28typedef __u16 __bitwise __le16;
33typedef __u16 __bitwise __be16; 29typedef __u16 __bitwise __be16;
diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
index 56b7ab584cc0..60180c0b5dc6 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -172,8 +172,6 @@ struct vhost_memory {
172#define VHOST_F_LOG_ALL 26 172#define VHOST_F_LOG_ALL 26
173/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */ 173/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
174#define VHOST_NET_F_VIRTIO_NET_HDR 27 174#define VHOST_NET_F_VIRTIO_NET_HDR 27
175/* Vhost have device IOTLB */
176#define VHOST_F_DEVICE_IOTLB 63
177 175
178/* VHOST_SCSI specific definitions */ 176/* VHOST_SCSI specific definitions */
179 177
diff --git a/include/uapi/linux/virtio_crypto.h b/include/uapi/linux/virtio_crypto.h
new file mode 100644
index 000000000000..50cdc8aebfcf
--- /dev/null
+++ b/include/uapi/linux/virtio_crypto.h
@@ -0,0 +1,450 @@
1#ifndef _VIRTIO_CRYPTO_H
2#define _VIRTIO_CRYPTO_H
3/* This header is BSD licensed so anyone can use the definitions to implement
4 * compatible drivers/servers.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of IBM nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30#include <linux/types.h>
31#include <linux/virtio_types.h>
32#include <linux/virtio_ids.h>
33#include <linux/virtio_config.h>
34
35
36#define VIRTIO_CRYPTO_SERVICE_CIPHER 0
37#define VIRTIO_CRYPTO_SERVICE_HASH 1
38#define VIRTIO_CRYPTO_SERVICE_MAC 2
39#define VIRTIO_CRYPTO_SERVICE_AEAD 3
40
41#define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op))
42
43struct virtio_crypto_ctrl_header {
44#define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \
45 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02)
46#define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \
47 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03)
48#define VIRTIO_CRYPTO_HASH_CREATE_SESSION \
49 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02)
50#define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \
51 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03)
52#define VIRTIO_CRYPTO_MAC_CREATE_SESSION \
53 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02)
54#define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \
55 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03)
56#define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \
57 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02)
58#define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \
59 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03)
60 __le32 opcode;
61 __le32 algo;
62 __le32 flag;
63 /* data virtqueue id */
64 __le32 queue_id;
65};
66
67struct virtio_crypto_cipher_session_para {
68#define VIRTIO_CRYPTO_NO_CIPHER 0
69#define VIRTIO_CRYPTO_CIPHER_ARC4 1
70#define VIRTIO_CRYPTO_CIPHER_AES_ECB 2
71#define VIRTIO_CRYPTO_CIPHER_AES_CBC 3
72#define VIRTIO_CRYPTO_CIPHER_AES_CTR 4
73#define VIRTIO_CRYPTO_CIPHER_DES_ECB 5
74#define VIRTIO_CRYPTO_CIPHER_DES_CBC 6
75#define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7
76#define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8
77#define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9
78#define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10
79#define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11
80#define VIRTIO_CRYPTO_CIPHER_AES_F8 12
81#define VIRTIO_CRYPTO_CIPHER_AES_XTS 13
82#define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14
83 __le32 algo;
84 /* length of key */
85 __le32 keylen;
86
87#define VIRTIO_CRYPTO_OP_ENCRYPT 1
88#define VIRTIO_CRYPTO_OP_DECRYPT 2
89 /* encrypt or decrypt */
90 __le32 op;
91 __le32 padding;
92};
93
94struct virtio_crypto_session_input {
95 /* Device-writable part */
96 __le64 session_id;
97 __le32 status;
98 __le32 padding;
99};
100
101struct virtio_crypto_cipher_session_req {
102 struct virtio_crypto_cipher_session_para para;
103 __u8 padding[32];
104};
105
106struct virtio_crypto_hash_session_para {
107#define VIRTIO_CRYPTO_NO_HASH 0
108#define VIRTIO_CRYPTO_HASH_MD5 1
109#define VIRTIO_CRYPTO_HASH_SHA1 2
110#define VIRTIO_CRYPTO_HASH_SHA_224 3
111#define VIRTIO_CRYPTO_HASH_SHA_256 4
112#define VIRTIO_CRYPTO_HASH_SHA_384 5
113#define VIRTIO_CRYPTO_HASH_SHA_512 6
114#define VIRTIO_CRYPTO_HASH_SHA3_224 7
115#define VIRTIO_CRYPTO_HASH_SHA3_256 8
116#define VIRTIO_CRYPTO_HASH_SHA3_384 9
117#define VIRTIO_CRYPTO_HASH_SHA3_512 10
118#define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11
119#define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12
120 __le32 algo;
121 /* hash result length */
122 __le32 hash_result_len;
123 __u8 padding[8];
124};
125
126struct virtio_crypto_hash_create_session_req {
127 struct virtio_crypto_hash_session_para para;
128 __u8 padding[40];
129};
130
131struct virtio_crypto_mac_session_para {
132#define VIRTIO_CRYPTO_NO_MAC 0
133#define VIRTIO_CRYPTO_MAC_HMAC_MD5 1
134#define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2
135#define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3
136#define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4
137#define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5
138#define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6
139#define VIRTIO_CRYPTO_MAC_CMAC_3DES 25
140#define VIRTIO_CRYPTO_MAC_CMAC_AES 26
141#define VIRTIO_CRYPTO_MAC_KASUMI_F9 27
142#define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28
143#define VIRTIO_CRYPTO_MAC_GMAC_AES 41
144#define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42
145#define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49
146#define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50
147#define VIRTIO_CRYPTO_MAC_XCBC_AES 53
148 __le32 algo;
149 /* hash result length */
150 __le32 hash_result_len;
151 /* length of authenticated key */
152 __le32 auth_key_len;
153 __le32 padding;
154};
155
156struct virtio_crypto_mac_create_session_req {
157 struct virtio_crypto_mac_session_para para;
158 __u8 padding[40];
159};
160
161struct virtio_crypto_aead_session_para {
162#define VIRTIO_CRYPTO_NO_AEAD 0
163#define VIRTIO_CRYPTO_AEAD_GCM 1
164#define VIRTIO_CRYPTO_AEAD_CCM 2
165#define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3
166 __le32 algo;
167 /* length of key */
168 __le32 key_len;
169 /* hash result length */
170 __le32 hash_result_len;
171 /* length of the additional authenticated data (AAD) in bytes */
172 __le32 aad_len;
173 /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */
174 __le32 op;
175 __le32 padding;
176};
177
178struct virtio_crypto_aead_create_session_req {
179 struct virtio_crypto_aead_session_para para;
180 __u8 padding[32];
181};
182
183struct virtio_crypto_alg_chain_session_para {
184#define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1
185#define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2
186 __le32 alg_chain_order;
187/* Plain hash */
188#define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1
189/* Authenticated hash (mac) */
190#define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2
191/* Nested hash */
192#define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3
193 __le32 hash_mode;
194 struct virtio_crypto_cipher_session_para cipher_param;
195 union {
196 struct virtio_crypto_hash_session_para hash_param;
197 struct virtio_crypto_mac_session_para mac_param;
198 __u8 padding[16];
199 } u;
200 /* length of the additional authenticated data (AAD) in bytes */
201 __le32 aad_len;
202 __le32 padding;
203};
204
205struct virtio_crypto_alg_chain_session_req {
206 struct virtio_crypto_alg_chain_session_para para;
207};
208
209struct virtio_crypto_sym_create_session_req {
210 union {
211 struct virtio_crypto_cipher_session_req cipher;
212 struct virtio_crypto_alg_chain_session_req chain;
213 __u8 padding[48];
214 } u;
215
216 /* Device-readable part */
217
218/* No operation */
219#define VIRTIO_CRYPTO_SYM_OP_NONE 0
220/* Cipher only operation on the data */
221#define VIRTIO_CRYPTO_SYM_OP_CIPHER 1
222/*
223 * Chain any cipher with any hash or mac operation. The order
224 * depends on the value of alg_chain_order param
225 */
226#define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2
227 __le32 op_type;
228 __le32 padding;
229};
230
231struct virtio_crypto_destroy_session_req {
232 /* Device-readable part */
233 __le64 session_id;
234 __u8 padding[48];
235};
236
237/* The request of the control virtqueue's packet */
238struct virtio_crypto_op_ctrl_req {
239 struct virtio_crypto_ctrl_header header;
240
241 union {
242 struct virtio_crypto_sym_create_session_req
243 sym_create_session;
244 struct virtio_crypto_hash_create_session_req
245 hash_create_session;
246 struct virtio_crypto_mac_create_session_req
247 mac_create_session;
248 struct virtio_crypto_aead_create_session_req
249 aead_create_session;
250 struct virtio_crypto_destroy_session_req
251 destroy_session;
252 __u8 padding[56];
253 } u;
254};
255
256struct virtio_crypto_op_header {
257#define VIRTIO_CRYPTO_CIPHER_ENCRYPT \
258 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00)
259#define VIRTIO_CRYPTO_CIPHER_DECRYPT \
260 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01)
261#define VIRTIO_CRYPTO_HASH \
262 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00)
263#define VIRTIO_CRYPTO_MAC \
264 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00)
265#define VIRTIO_CRYPTO_AEAD_ENCRYPT \
266 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00)
267#define VIRTIO_CRYPTO_AEAD_DECRYPT \
268 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01)
269 __le32 opcode;
270 /* algo should be service-specific algorithms */
271 __le32 algo;
272 /* session_id should be service-specific algorithms */
273 __le64 session_id;
274 /* control flag to control the request */
275 __le32 flag;
276 __le32 padding;
277};
278
279struct virtio_crypto_cipher_para {
280 /*
281 * Byte Length of valid IV/Counter
282 *
283 * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for
284 * SNOW3G in UEA2 mode, this is the length of the IV (which
285 * must be the same as the block length of the cipher).
286 * For block ciphers in CTR mode, this is the length of the counter
287 * (which must be the same as the block length of the cipher).
288 * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007.
289 *
290 * The IV/Counter will be updated after every partial cryptographic
291 * operation.
292 */
293 __le32 iv_len;
294 /* length of source data */
295 __le32 src_data_len;
296 /* length of dst data */
297 __le32 dst_data_len;
298 __le32 padding;
299};
300
301struct virtio_crypto_hash_para {
302 /* length of source data */
303 __le32 src_data_len;
304 /* hash result length */
305 __le32 hash_result_len;
306};
307
308struct virtio_crypto_mac_para {
309 struct virtio_crypto_hash_para hash;
310};
311
312struct virtio_crypto_aead_para {
313 /*
314 * Byte Length of valid IV data pointed to by the below iv_addr
315 * parameter.
316 *
317 * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which
318 * case iv_addr points to J0.
319 * For CCM mode, this is the length of the nonce, which can be in the
320 * range 7 to 13 inclusive.
321 */
322 __le32 iv_len;
323 /* length of additional auth data */
324 __le32 aad_len;
325 /* length of source data */
326 __le32 src_data_len;
327 /* length of dst data */
328 __le32 dst_data_len;
329};
330
331struct virtio_crypto_cipher_data_req {
332 /* Device-readable part */
333 struct virtio_crypto_cipher_para para;
334 __u8 padding[24];
335};
336
337struct virtio_crypto_hash_data_req {
338 /* Device-readable part */
339 struct virtio_crypto_hash_para para;
340 __u8 padding[40];
341};
342
343struct virtio_crypto_mac_data_req {
344 /* Device-readable part */
345 struct virtio_crypto_mac_para para;
346 __u8 padding[40];
347};
348
349struct virtio_crypto_alg_chain_data_para {
350 __le32 iv_len;
351 /* Length of source data */
352 __le32 src_data_len;
353 /* Length of destination data */
354 __le32 dst_data_len;
355 /* Starting point for cipher processing in source data */
356 __le32 cipher_start_src_offset;
357 /* Length of the source data that the cipher will be computed on */
358 __le32 len_to_cipher;
359 /* Starting point for hash processing in source data */
360 __le32 hash_start_src_offset;
361 /* Length of the source data that the hash will be computed on */
362 __le32 len_to_hash;
363 /* Length of the additional auth data */
364 __le32 aad_len;
365 /* Length of the hash result */
366 __le32 hash_result_len;
367 __le32 reserved;
368};
369
370struct virtio_crypto_alg_chain_data_req {
371 /* Device-readable part */
372 struct virtio_crypto_alg_chain_data_para para;
373};
374
375struct virtio_crypto_sym_data_req {
376 union {
377 struct virtio_crypto_cipher_data_req cipher;
378 struct virtio_crypto_alg_chain_data_req chain;
379 __u8 padding[40];
380 } u;
381
382 /* See above VIRTIO_CRYPTO_SYM_OP_* */
383 __le32 op_type;
384 __le32 padding;
385};
386
387struct virtio_crypto_aead_data_req {
388 /* Device-readable part */
389 struct virtio_crypto_aead_para para;
390 __u8 padding[32];
391};
392
393/* The request of the data virtqueue's packet */
394struct virtio_crypto_op_data_req {
395 struct virtio_crypto_op_header header;
396
397 union {
398 struct virtio_crypto_sym_data_req sym_req;
399 struct virtio_crypto_hash_data_req hash_req;
400 struct virtio_crypto_mac_data_req mac_req;
401 struct virtio_crypto_aead_data_req aead_req;
402 __u8 padding[48];
403 } u;
404};
405
406#define VIRTIO_CRYPTO_OK 0
407#define VIRTIO_CRYPTO_ERR 1
408#define VIRTIO_CRYPTO_BADMSG 2
409#define VIRTIO_CRYPTO_NOTSUPP 3
410#define VIRTIO_CRYPTO_INVSESS 4 /* Invalid session id */
411
412/* The accelerator hardware is ready */
413#define VIRTIO_CRYPTO_S_HW_READY (1 << 0)
414
415struct virtio_crypto_config {
416 /* See VIRTIO_CRYPTO_OP_* above */
417 __u32 status;
418
419 /*
420 * Maximum number of data queue
421 */
422 __u32 max_dataqueues;
423
424 /*
425 * Specifies the services mask which the device support,
426 * see VIRTIO_CRYPTO_SERVICE_* above
427 */
428 __u32 crypto_services;
429
430 /* Detailed algorithms mask */
431 __u32 cipher_algo_l;
432 __u32 cipher_algo_h;
433 __u32 hash_algo;
434 __u32 mac_algo_l;
435 __u32 mac_algo_h;
436 __u32 aead_algo;
437 /* Maximum length of cipher key */
438 __u32 max_cipher_key_len;
439 /* Maximum length of authenticated key */
440 __u32 max_auth_key_len;
441 __u32 reserve;
442 /* Maximum size of each crypto request's content */
443 __u64 max_size;
444};
445
446struct virtio_crypto_inhdr {
447 /* See VIRTIO_CRYPTO_* above */
448 __u8 status;
449};
450#endif
diff --git a/include/uapi/linux/virtio_ids.h b/include/uapi/linux/virtio_ids.h
index 3228d582234a..6d5c3b2d4f4d 100644
--- a/include/uapi/linux/virtio_ids.h
+++ b/include/uapi/linux/virtio_ids.h
@@ -42,5 +42,6 @@
42#define VIRTIO_ID_GPU 16 /* virtio GPU */ 42#define VIRTIO_ID_GPU 16 /* virtio GPU */
43#define VIRTIO_ID_INPUT 18 /* virtio input */ 43#define VIRTIO_ID_INPUT 18 /* virtio input */
44#define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ 44#define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */
45#define VIRTIO_ID_CRYPTO 20 /* virtio crypto */
45 46
46#endif /* _LINUX_VIRTIO_IDS_H */ 47#endif /* _LINUX_VIRTIO_IDS_H */
diff --git a/include/uapi/linux/virtio_types.h b/include/uapi/linux/virtio_types.h
index e845e8c4cbee..55c3b738722c 100644
--- a/include/uapi/linux/virtio_types.h
+++ b/include/uapi/linux/virtio_types.h
@@ -39,8 +39,8 @@
39 * - __le{16,32,64} for standard-compliant virtio devices 39 * - __le{16,32,64} for standard-compliant virtio devices
40 */ 40 */
41 41
42typedef __u16 __bitwise__ __virtio16; 42typedef __u16 __bitwise __virtio16;
43typedef __u32 __bitwise__ __virtio32; 43typedef __u32 __bitwise __virtio32;
44typedef __u64 __bitwise__ __virtio64; 44typedef __u64 __bitwise __virtio64;
45 45
46#endif /* _UAPI_LINUX_VIRTIO_TYPES_H */ 46#endif /* _UAPI_LINUX_VIRTIO_TYPES_H */
diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile
index b3ff12eb9b6d..4bfaa19a5573 100644
--- a/net/bluetooth/Makefile
+++ b/net/bluetooth/Makefile
@@ -20,5 +20,3 @@ bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o
20bluetooth-$(CONFIG_BT_LEDS) += leds.o 20bluetooth-$(CONFIG_BT_LEDS) += leds.o
21bluetooth-$(CONFIG_BT_DEBUGFS) += hci_debugfs.o 21bluetooth-$(CONFIG_BT_DEBUGFS) += hci_debugfs.o
22bluetooth-$(CONFIG_BT_SELFTEST) += selftest.o 22bluetooth-$(CONFIG_BT_SELFTEST) += selftest.o
23
24subdir-ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/ieee802154/6lowpan/6lowpan_i.h b/net/ieee802154/6lowpan/6lowpan_i.h
index 5ac778962e4e..ac7c96b73ad5 100644
--- a/net/ieee802154/6lowpan/6lowpan_i.h
+++ b/net/ieee802154/6lowpan/6lowpan_i.h
@@ -7,7 +7,7 @@
7#include <net/inet_frag.h> 7#include <net/inet_frag.h>
8#include <net/6lowpan.h> 8#include <net/6lowpan.h>
9 9
10typedef unsigned __bitwise__ lowpan_rx_result; 10typedef unsigned __bitwise lowpan_rx_result;
11#define RX_CONTINUE ((__force lowpan_rx_result) 0u) 11#define RX_CONTINUE ((__force lowpan_rx_result) 0u)
12#define RX_DROP_UNUSABLE ((__force lowpan_rx_result) 1u) 12#define RX_DROP_UNUSABLE ((__force lowpan_rx_result) 1u)
13#define RX_DROP ((__force lowpan_rx_result) 2u) 13#define RX_DROP ((__force lowpan_rx_result) 2u)
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index 4adfd4d5471b..9b92ade687a3 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -7,5 +7,3 @@ ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \
7ieee802154_socket-y := socket.o 7ieee802154_socket-y := socket.o
8 8
9CFLAGS_trace.o := -I$(src) 9CFLAGS_trace.o := -I$(src)
10
11ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 0b202b343fd4..282912245938 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -61,4 +61,4 @@ rc80211_minstrel_ht-$(CONFIG_MAC80211_DEBUGFS) += rc80211_minstrel_ht_debugfs.o
61mac80211-$(CONFIG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y) 61mac80211-$(CONFIG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
62mac80211-$(CONFIG_MAC80211_RC_MINSTREL_HT) += $(rc80211_minstrel_ht-y) 62mac80211-$(CONFIG_MAC80211_RC_MINSTREL_HT) += $(rc80211_minstrel_ht-y)
63 63
64ccflags-y += -D__CHECK_ENDIAN__ -DDEBUG 64ccflags-y += -DDEBUG
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index d37a577f63a1..b2069fbd60f9 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -159,7 +159,7 @@ enum ieee80211_bss_valid_data_flags {
159 IEEE80211_BSS_VALID_ERP = BIT(3) 159 IEEE80211_BSS_VALID_ERP = BIT(3)
160}; 160};
161 161
162typedef unsigned __bitwise__ ieee80211_tx_result; 162typedef unsigned __bitwise ieee80211_tx_result;
163#define TX_CONTINUE ((__force ieee80211_tx_result) 0u) 163#define TX_CONTINUE ((__force ieee80211_tx_result) 0u)
164#define TX_DROP ((__force ieee80211_tx_result) 1u) 164#define TX_DROP ((__force ieee80211_tx_result) 1u)
165#define TX_QUEUED ((__force ieee80211_tx_result) 2u) 165#define TX_QUEUED ((__force ieee80211_tx_result) 2u)
@@ -180,7 +180,7 @@ struct ieee80211_tx_data {
180}; 180};
181 181
182 182
183typedef unsigned __bitwise__ ieee80211_rx_result; 183typedef unsigned __bitwise ieee80211_rx_result;
184#define RX_CONTINUE ((__force ieee80211_rx_result) 0u) 184#define RX_CONTINUE ((__force ieee80211_rx_result) 0u)
185#define RX_DROP_UNUSABLE ((__force ieee80211_rx_result) 1u) 185#define RX_DROP_UNUSABLE ((__force ieee80211_rx_result) 1u)
186#define RX_DROP_MONITOR ((__force ieee80211_rx_result) 2u) 186#define RX_DROP_MONITOR ((__force ieee80211_rx_result) 2u)
diff --git a/net/mac802154/Makefile b/net/mac802154/Makefile
index 17a51e8389e2..5857bb1e1695 100644
--- a/net/mac802154/Makefile
+++ b/net/mac802154/Makefile
@@ -3,5 +3,3 @@ mac802154-objs := main.o rx.o tx.o mac_cmd.o mib.o \
3 iface.o llsec.o util.o cfg.o trace.o 3 iface.o llsec.o util.o cfg.o trace.o
4 4
5CFLAGS_trace.o := -I$(src) 5CFLAGS_trace.o := -I$(src)
6
7ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 2e47f9f06b96..6788264acc63 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -379,7 +379,7 @@ static void virtio_vsock_reset_sock(struct sock *sk)
379static void virtio_vsock_update_guest_cid(struct virtio_vsock *vsock) 379static void virtio_vsock_update_guest_cid(struct virtio_vsock *vsock)
380{ 380{
381 struct virtio_device *vdev = vsock->vdev; 381 struct virtio_device *vdev = vsock->vdev;
382 u64 guest_cid; 382 __le64 guest_cid;
383 383
384 vdev->config->get(vdev, offsetof(struct virtio_vsock_config, guest_cid), 384 vdev->config->get(vdev, offsetof(struct virtio_vsock_config, guest_cid),
385 &guest_cid, sizeof(guest_cid)); 385 &guest_cid, sizeof(guest_cid));
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 687e9fdb3d67..849c4ad0411e 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -32,7 +32,7 @@ static const struct virtio_transport *virtio_transport_get_ops(void)
32 return container_of(t, struct virtio_transport, transport); 32 return container_of(t, struct virtio_transport, transport);
33} 33}
34 34
35struct virtio_vsock_pkt * 35static struct virtio_vsock_pkt *
36virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info, 36virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
37 size_t len, 37 size_t len,
38 u32 src_cid, 38 u32 src_cid,
@@ -82,7 +82,6 @@ out_pkt:
82 kfree(pkt); 82 kfree(pkt);
83 return NULL; 83 return NULL;
84} 84}
85EXPORT_SYMBOL_GPL(virtio_transport_alloc_pkt);
86 85
87static int virtio_transport_send_pkt_info(struct vsock_sock *vsk, 86static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
88 struct virtio_vsock_pkt_info *info) 87 struct virtio_vsock_pkt_info *info)
@@ -606,9 +605,9 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)
606 return 0; 605 return 0;
607 606
608 pkt = virtio_transport_alloc_pkt(&info, 0, 607 pkt = virtio_transport_alloc_pkt(&info, 0,
609 le32_to_cpu(pkt->hdr.dst_cid), 608 le64_to_cpu(pkt->hdr.dst_cid),
610 le32_to_cpu(pkt->hdr.dst_port), 609 le32_to_cpu(pkt->hdr.dst_port),
611 le32_to_cpu(pkt->hdr.src_cid), 610 le64_to_cpu(pkt->hdr.src_cid),
612 le32_to_cpu(pkt->hdr.src_port)); 611 le32_to_cpu(pkt->hdr.src_port));
613 if (!pkt) 612 if (!pkt)
614 return -ENOMEM; 613 return -ENOMEM;
@@ -823,7 +822,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
823 struct virtio_vsock_pkt_info info = { 822 struct virtio_vsock_pkt_info info = {
824 .op = VIRTIO_VSOCK_OP_RESPONSE, 823 .op = VIRTIO_VSOCK_OP_RESPONSE,
825 .type = VIRTIO_VSOCK_TYPE_STREAM, 824 .type = VIRTIO_VSOCK_TYPE_STREAM,
826 .remote_cid = le32_to_cpu(pkt->hdr.src_cid), 825 .remote_cid = le64_to_cpu(pkt->hdr.src_cid),
827 .remote_port = le32_to_cpu(pkt->hdr.src_port), 826 .remote_port = le32_to_cpu(pkt->hdr.src_port),
828 .reply = true, 827 .reply = true,
829 }; 828 };
@@ -863,9 +862,9 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
863 child->sk_state = SS_CONNECTED; 862 child->sk_state = SS_CONNECTED;
864 863
865 vchild = vsock_sk(child); 864 vchild = vsock_sk(child);
866 vsock_addr_init(&vchild->local_addr, le32_to_cpu(pkt->hdr.dst_cid), 865 vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
867 le32_to_cpu(pkt->hdr.dst_port)); 866 le32_to_cpu(pkt->hdr.dst_port));
868 vsock_addr_init(&vchild->remote_addr, le32_to_cpu(pkt->hdr.src_cid), 867 vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid),
869 le32_to_cpu(pkt->hdr.src_port)); 868 le32_to_cpu(pkt->hdr.src_port));
870 869
871 vsock_insert_connected(vchild); 870 vsock_insert_connected(vchild);
@@ -904,9 +903,9 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
904 struct sock *sk; 903 struct sock *sk;
905 bool space_available; 904 bool space_available;
906 905
907 vsock_addr_init(&src, le32_to_cpu(pkt->hdr.src_cid), 906 vsock_addr_init(&src, le64_to_cpu(pkt->hdr.src_cid),
908 le32_to_cpu(pkt->hdr.src_port)); 907 le32_to_cpu(pkt->hdr.src_port));
909 vsock_addr_init(&dst, le32_to_cpu(pkt->hdr.dst_cid), 908 vsock_addr_init(&dst, le64_to_cpu(pkt->hdr.dst_cid),
910 le32_to_cpu(pkt->hdr.dst_port)); 909 le32_to_cpu(pkt->hdr.dst_port));
911 910
912 trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port, 911 trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index 4c9e39f04ef8..816c9331c8d2 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -17,8 +17,6 @@ cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o
17 17
18CFLAGS_trace.o := -I$(src) 18CFLAGS_trace.o := -I$(src)
19 19
20ccflags-y += -D__CHECK_ENDIAN__
21
22$(obj)/regdb.c: $(src)/db.txt $(src)/genregdb.awk 20$(obj)/regdb.c: $(src)/db.txt $(src)/genregdb.awk
23 @$(AWK) -f $(srctree)/$(src)/genregdb.awk < $< > $@ 21 @$(AWK) -f $(srctree)/$(src)/genregdb.awk < $< > $@
24 22
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index fd3556b2a5d1..982c52ca6473 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -335,7 +335,7 @@ our $Attribute = qr{
335 __percpu| 335 __percpu|
336 __nocast| 336 __nocast|
337 __safe| 337 __safe|
338 __bitwise__| 338 __bitwise|
339 __packed__| 339 __packed__|
340 __packed2__| 340 __packed2__|
341 __naked| 341 __naked|
@@ -3681,7 +3681,7 @@ sub process {
3681 $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && 3681 $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
3682 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && 3682 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
3683 $line !~ /\b$typeTypedefs\b/ && 3683 $line !~ /\b$typeTypedefs\b/ &&
3684 $line !~ /\b__bitwise(?:__|)\b/) { 3684 $line !~ /\b__bitwise\b/) {
3685 WARN("NEW_TYPEDEFS", 3685 WARN("NEW_TYPEDEFS",
3686 "do not add new typedefs\n" . $herecurr); 3686 "do not add new typedefs\n" . $herecurr);
3687 } 3687 }
diff --git a/tools/include/linux/types.h b/tools/include/linux/types.h
index 8ebf6278b2ef..c24b3e3ae296 100644
--- a/tools/include/linux/types.h
+++ b/tools/include/linux/types.h
@@ -42,11 +42,7 @@ typedef __s8 s8;
42#else 42#else
43#define __bitwise__ 43#define __bitwise__
44#endif 44#endif
45#ifdef __CHECK_ENDIAN__
46#define __bitwise __bitwise__ 45#define __bitwise __bitwise__
47#else
48#define __bitwise
49#endif
50 46
51#define __force 47#define __force
52#define __user 48#define __user
diff --git a/tools/virtio/linux/compiler.h b/tools/virtio/linux/compiler.h
index 845960e1cbf2..c9ccfd42ec13 100644
--- a/tools/virtio/linux/compiler.h
+++ b/tools/virtio/linux/compiler.h
@@ -4,6 +4,6 @@
4#define WRITE_ONCE(var, val) \ 4#define WRITE_ONCE(var, val) \
5 (*((volatile typeof(val) *)(&(var))) = (val)) 5 (*((volatile typeof(val) *)(&(var))) = (val))
6 6
7#define READ_ONCE(var) (*((volatile typeof(val) *)(&(var)))) 7#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
8 8
9#endif 9#endif
diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
index 0a578fe18653..fa05d01b2c90 100644
--- a/tools/virtio/linux/uaccess.h
+++ b/tools/virtio/linux/uaccess.h
@@ -1,8 +1,9 @@
1#ifndef UACCESS_H 1#ifndef UACCESS_H
2#define UACCESS_H 2#define UACCESS_H
3extern void *__user_addr_min, *__user_addr_max;
4 3
5#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) 4#include <linux/compiler.h>
5
6extern void *__user_addr_min, *__user_addr_max;
6 7
7static inline void __chk_user_ptr(const volatile void *p, size_t size) 8static inline void __chk_user_ptr(const volatile void *p, size_t size)
8{ 9{
@@ -13,7 +14,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
13({ \ 14({ \
14 typeof(ptr) __pu_ptr = (ptr); \ 15 typeof(ptr) __pu_ptr = (ptr); \
15 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \ 16 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
16 ACCESS_ONCE(*(__pu_ptr)) = x; \ 17 WRITE_ONCE(*(__pu_ptr), x); \
17 0; \ 18 0; \
18}) 19})
19 20
@@ -21,7 +22,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
21({ \ 22({ \
22 typeof(ptr) __pu_ptr = (ptr); \ 23 typeof(ptr) __pu_ptr = (ptr); \
23 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \ 24 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
24 x = ACCESS_ONCE(*(__pu_ptr)); \ 25 x = READ_ONCE(*(__pu_ptr)); \
25 0; \ 26 0; \
26}) 27})
27 28