2020-06-11 13:29:24

by Alain Michaud

[permalink] [raw]
Subject: [PATCH v5] sco:Add support for BT_PKT_STATUS CMSG data

This change adds support for reporting the BT_PKT_STATUS to the socket
CMSG data to allow the implementation of a packet loss correction on
erronous data received on the SCO socket.

The patch was partially developed by Marcel Holtmann and validated by
Hsin-yu Chao.

Signed-off-by: Alain Michaud <[email protected]>

---

Changes in v5:
- reducing cmsg_mask to 8 bit
- clarifying the public symbol usage versus internal CMSG flags.

Changes in v4:
- Addressing feedback from Marcel

include/net/bluetooth/bluetooth.h | 10 ++++++++++
include/net/bluetooth/sco.h | 2 ++
net/bluetooth/af_bluetooth.c | 3 +++
net/bluetooth/hci_core.c | 1 +
net/bluetooth/sco.c | 33 +++++++++++++++++++++++++++++++
5 files changed, 49 insertions(+)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 3fa7b1e3c5d9..4044c6a1ffd0 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -147,6 +147,10 @@ struct bt_voice {
#define BT_MODE_LE_FLOWCTL 0x03
#define BT_MODE_EXT_FLOWCTL 0x04

+#define BT_PKT_STATUS 16
+
+#define BT_SCM_PKT_STATUS 0x03
+
__printf(1, 2)
void bt_info(const char *fmt, ...);
__printf(1, 2)
@@ -275,6 +279,7 @@ struct bt_sock {
struct sock *parent;
unsigned long flags;
void (*skb_msg_name)(struct sk_buff *, void *, int *);
+ void (*skb_put_cmsg)(struct sk_buff *, struct msghdr *, struct sock *);
};

enum {
@@ -324,6 +329,10 @@ struct l2cap_ctrl {
struct l2cap_chan *chan;
};

+struct sco_ctrl {
+ u8 pkt_status;
+};
+
struct hci_dev;

typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode);
@@ -350,6 +359,7 @@ struct bt_skb_cb {
u8 incoming:1;
union {
struct l2cap_ctrl l2cap;
+ struct sco_ctrl sco;
struct hci_ctrl hci;
};
};
diff --git a/include/net/bluetooth/sco.h b/include/net/bluetooth/sco.h
index f40ddb4264fc..1aa2e14b6c94 100644
--- a/include/net/bluetooth/sco.h
+++ b/include/net/bluetooth/sco.h
@@ -46,4 +46,6 @@ struct sco_conninfo {
__u8 dev_class[3];
};

+#define SCO_CMSG_PKT_STATUS 0x01
+
#endif /* __SCO_H */
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 3fd124927d4d..d0abea8d08cc 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -286,6 +286,9 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (msg->msg_name && bt_sk(sk)->skb_msg_name)
bt_sk(sk)->skb_msg_name(skb, msg->msg_name,
&msg->msg_namelen);
+
+ if (bt_sk(sk)->skb_put_cmsg)
+ bt_sk(sk)->skb_put_cmsg(skb, msg, sk);
}

skb_free_datagram(sk, skb);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 51d399273276..7b5e46198d99 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -4549,6 +4549,7 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)

if (conn) {
/* Send to upper protocol */
+ bt_cb(skb)->sco.pkt_status = flags & 0x03;
sco_recv_scodata(conn, skb);
return;
} else {
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c8c3d38cdc7b..012a1579c260 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -66,6 +66,7 @@ struct sco_pinfo {
bdaddr_t dst;
__u32 flags;
__u16 setting;
+ __u8 cmsg_mask;
struct sco_conn *conn;
};

@@ -449,6 +450,15 @@ static void sco_sock_close(struct sock *sk)
sco_sock_kill(sk);
}

+static void sco_skb_put_cmsg(struct sk_buff *skb, struct msghdr *msg,
+ struct sock *sk)
+{
+ if (test_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask))
+ put_cmsg(msg, SOL_BLUETOOTH, BT_SCM_PKT_STATUS,
+ sizeof(bt_cb(skb)->sco.pkt_status),
+ &bt_cb(skb)->sco.pkt_status);
+}
+
static void sco_sock_init(struct sock *sk, struct sock *parent)
{
BT_DBG("sk %p", sk);
@@ -457,6 +467,8 @@ static void sco_sock_init(struct sock *sk, struct sock *parent)
sk->sk_type = parent->sk_type;
bt_sk(sk)->flags = bt_sk(parent)->flags;
security_sk_clone(parent, sk);
+ } else {
+ bt_sk(sk)->skb_put_cmsg = sco_skb_put_cmsg;
}
}

@@ -846,6 +858,18 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
sco_pi(sk)->setting = voice.setting;
break;

+ case BT_PKT_STATUS:
+ if (get_user(opt, (u32 __user *)optval)) {
+ err = -EFAULT;
+ break;
+ }
+
+ if (opt)
+ set_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
+ else
+ clear_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
+ break;
+
default:
err = -ENOPROTOOPT;
break;
@@ -923,6 +947,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname,
int len, err = 0;
struct bt_voice voice;
u32 phys;
+ int pkt_status;

BT_DBG("sk %p", sk);

@@ -969,6 +994,14 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname,
err = -EFAULT;
break;

+ case BT_PKT_STATUS:
+ pkt_status = test_bit(SCO_CMSG_PKT_STATUS,
+ &(sco_pi(sk)->cmsg_mask));
+
+ if (put_user(pkt_status, (int __user *)optval))
+ err = -EFAULT;
+ break;
+
default:
err = -ENOPROTOOPT;
break;
--
2.27.0.290.gba653c62da-goog


2020-06-11 15:44:51

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v5] sco:Add support for BT_PKT_STATUS CMSG data

Hi Alain,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on next-20200611]
[cannot apply to v5.7]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Alain-Michaud/sco-Add-support-for-BT_PKT_STATUS-CMSG-data/20200611-212907
base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: x86_64-randconfig-s022-20200611 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-250-g42323db3-dirty
# save the attached .config to linux build tree
make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>, old ones prefixed by <<):

net/bluetooth/sco.c: In function 'sco_skb_put_cmsg':
>> net/bluetooth/sco.c:456:36: error: passing argument 2 of 'test_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
456 | if (test_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask))
| ^~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
In file included from arch/x86/include/asm/bitops.h:392,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/bluetooth/sco.c:27:
include/asm-generic/bitops/instrumented-non-atomic.h:108:68: note: expected 'const volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
108 | static inline bool test_bit(long nr, const volatile unsigned long *addr)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
net/bluetooth/sco.c: In function 'sco_sock_setsockopt':
>> net/bluetooth/sco.c:868:33: error: passing argument 2 of 'set_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
868 | set_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
| ^~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
In file included from arch/x86/include/asm/bitops.h:391,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/bluetooth/sco.c:27:
include/asm-generic/bitops/instrumented-atomic.h:26:61: note: expected 'volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
26 | static inline void set_bit(long nr, volatile unsigned long *addr)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
>> net/bluetooth/sco.c:870:35: error: passing argument 2 of 'clear_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
870 | clear_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
| ^~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
In file included from arch/x86/include/asm/bitops.h:391,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/bluetooth/sco.c:27:
include/asm-generic/bitops/instrumented-atomic.h:39:63: note: expected 'volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
39 | static inline void clear_bit(long nr, volatile unsigned long *addr)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
net/bluetooth/sco.c: In function 'sco_sock_getsockopt':
net/bluetooth/sco.c:999:11: error: passing argument 2 of 'test_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
999 | &(sco_pi(sk)->cmsg_mask));
| ^~~~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
In file included from arch/x86/include/asm/bitops.h:392,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/bluetooth/sco.c:27:
include/asm-generic/bitops/instrumented-non-atomic.h:108:68: note: expected 'const volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
108 | static inline bool test_bit(long nr, const volatile unsigned long *addr)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
cc1: some warnings being treated as errors

sparse warnings: (new ones prefixed by >>)

>> net/bluetooth/sco.c:456:44: sparse: sparse: incorrect type in argument 2 (different type sizes) @@ expected unsigned long const volatile *addr @@ got unsigned char * @@
>> net/bluetooth/sco.c:456:44: sparse: expected unsigned long const volatile *addr
>> net/bluetooth/sco.c:456:44: sparse: got unsigned char *
>> net/bluetooth/sco.c:868:55: sparse: sparse: incorrect type in argument 2 (different type sizes) @@ expected unsigned long volatile *addr @@ got unsigned char * @@
>> net/bluetooth/sco.c:868:55: sparse: expected unsigned long volatile *addr
net/bluetooth/sco.c:868:55: sparse: got unsigned char *
net/bluetooth/sco.c:870:57: sparse: sparse: incorrect type in argument 2 (different type sizes) @@ expected unsigned long volatile *addr @@ got unsigned char * @@
net/bluetooth/sco.c:870:57: sparse: expected unsigned long volatile *addr
net/bluetooth/sco.c:870:57: sparse: got unsigned char *
net/bluetooth/sco.c:999:41: sparse: sparse: incorrect type in argument 2 (different type sizes) @@ expected unsigned long const volatile *addr @@ got unsigned char * @@
net/bluetooth/sco.c:999:41: sparse: expected unsigned long const volatile *addr
net/bluetooth/sco.c:999:41: sparse: got unsigned char *

vim +/test_bit +456 net/bluetooth/sco.c

452
453 static void sco_skb_put_cmsg(struct sk_buff *skb, struct msghdr *msg,
454 struct sock *sk)
455 {
> 456 if (test_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask))
457 put_cmsg(msg, SOL_BLUETOOTH, BT_SCM_PKT_STATUS,
458 sizeof(bt_cb(skb)->sco.pkt_status),
459 &bt_cb(skb)->sco.pkt_status);
460 }
461

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (6.61 kB)
.config.gz (29.90 kB)
Download all attachments

2020-06-11 16:03:07

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v5] sco:Add support for BT_PKT_STATUS CMSG data

Hi Alain,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on next-20200611]
[cannot apply to v5.7]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Alain-Michaud/sco-Add-support-for-BT_PKT_STATUS-CMSG-data/20200611-212907
base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: arm-defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All error/warnings (new ones prefixed by >>, old ones prefixed by <<):

net/bluetooth/sco.c: In function 'sco_skb_put_cmsg':
net/bluetooth/sco.c:456:36: error: passing argument 2 of 'test_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
456 | if (test_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask))
| ^~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
In file included from arch/arm/include/asm/bitops.h:123,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/bluetooth/sco.c:27:
include/asm-generic/bitops/non-atomic.h:104:66: note: expected 'const volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
104 | static inline int test_bit(int nr, const volatile unsigned long *addr)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/bluetooth/sco.c:27:
net/bluetooth/sco.c: In function 'sco_sock_setsockopt':
>> net/bluetooth/sco.c:868:33: error: passing argument 2 of '_set_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
868 | set_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
| ^~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
arch/arm/include/asm/bitops.h:183:45: note: in definition of macro 'ATOMIC_BITOP'
183 | #define ATOMIC_BITOP(name,nr,p) _##name(nr,p)
| ^
>> net/bluetooth/sco.c:868:4: note: in expansion of macro 'set_bit'
868 | set_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
| ^~~~~~~
arch/arm/include/asm/bitops.h:153:55: note: expected 'volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
153 | extern void _set_bit(int nr, volatile unsigned long * p);
| ~~~~~~~~~~~~~~~~~~~~~~~~~^
>> net/bluetooth/sco.c:870:35: error: passing argument 2 of '_clear_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
870 | clear_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
| ^~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
arch/arm/include/asm/bitops.h:183:45: note: in definition of macro 'ATOMIC_BITOP'
183 | #define ATOMIC_BITOP(name,nr,p) _##name(nr,p)
| ^
>> net/bluetooth/sco.c:870:4: note: in expansion of macro 'clear_bit'
870 | clear_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
| ^~~~~~~~~
arch/arm/include/asm/bitops.h:154:57: note: expected 'volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
154 | extern void _clear_bit(int nr, volatile unsigned long * p);
| ~~~~~~~~~~~~~~~~~~~~~~~~~^
net/bluetooth/sco.c: In function 'sco_sock_getsockopt':
net/bluetooth/sco.c:999:11: error: passing argument 2 of 'test_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
999 | &(sco_pi(sk)->cmsg_mask));
| ^~~~~~~~~~~~~~~~~~~~~~~~
| |
| __u8 * {aka unsigned char *}
In file included from arch/arm/include/asm/bitops.h:123,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/module.h:12,
from net/bluetooth/sco.c:27:
include/asm-generic/bitops/non-atomic.h:104:66: note: expected 'const volatile long unsigned int *' but argument is of type '__u8 *' {aka 'unsigned char *'}
104 | static inline int test_bit(int nr, const volatile unsigned long *addr)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
cc1: some warnings being treated as errors

vim +/_set_bit +868 net/bluetooth/sco.c

804
805 static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
806 char __user *optval, unsigned int optlen)
807 {
808 struct sock *sk = sock->sk;
809 int len, err = 0;
810 struct bt_voice voice;
811 u32 opt;
812
813 BT_DBG("sk %p", sk);
814
815 lock_sock(sk);
816
817 switch (optname) {
818
819 case BT_DEFER_SETUP:
820 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
821 err = -EINVAL;
822 break;
823 }
824
825 if (get_user(opt, (u32 __user *) optval)) {
826 err = -EFAULT;
827 break;
828 }
829
830 if (opt)
831 set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
832 else
833 clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
834 break;
835
836 case BT_VOICE:
837 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
838 sk->sk_state != BT_CONNECT2) {
839 err = -EINVAL;
840 break;
841 }
842
843 voice.setting = sco_pi(sk)->setting;
844
845 len = min_t(unsigned int, sizeof(voice), optlen);
846 if (copy_from_user((char *)&voice, optval, len)) {
847 err = -EFAULT;
848 break;
849 }
850
851 /* Explicitly check for these values */
852 if (voice.setting != BT_VOICE_TRANSPARENT &&
853 voice.setting != BT_VOICE_CVSD_16BIT) {
854 err = -EINVAL;
855 break;
856 }
857
858 sco_pi(sk)->setting = voice.setting;
859 break;
860
861 case BT_PKT_STATUS:
862 if (get_user(opt, (u32 __user *)optval)) {
863 err = -EFAULT;
864 break;
865 }
866
867 if (opt)
> 868 set_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
869 else
> 870 clear_bit(SCO_CMSG_PKT_STATUS, &sco_pi(sk)->cmsg_mask);
871 break;
872
873 default:
874 err = -ENOPROTOOPT;
875 break;
876 }
877
878 release_sock(sk);
879 return err;
880 }
881

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (7.35 kB)
.config.gz (50.66 kB)
Download all attachments