2021-09-15 23:38:19

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v4 1/4] Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF

From: Luiz Augusto von Dentz <[email protected]>

This adds support for BT_{SND,RCV}BUF so userspace can set MTU based on
the channel usage.

Fixes: https://github.com/bluez/bluez/issues/201

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
---
net/bluetooth/hci_sock.c | 105 +++++++++++++++++++++++++++++++++++----
1 file changed, 94 insertions(+), 11 deletions(-)

diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 55b0d177375b..e481eee8e61e 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -57,6 +57,7 @@ struct hci_pinfo {
unsigned long flags;
__u32 cookie;
char comm[TASK_COMM_LEN];
+ unsigned int mtu;
};

static struct hci_dev *hci_hdev_from_sock(struct sock *sk)
@@ -1374,6 +1375,10 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
break;
}

+ /* Default MTU to HCI_MAX_FRAME_SIZE if not set */
+ if (!hci_pi(sk)->mtu)
+ hci_pi(sk)->mtu = HCI_MAX_FRAME_SIZE;
+
sk->sk_state = BT_BOUND;

done:
@@ -1719,7 +1724,7 @@ static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg,
if (flags & ~(MSG_DONTWAIT | MSG_NOSIGNAL | MSG_ERRQUEUE | MSG_CMSG_COMPAT))
return -EINVAL;

- if (len < 4 || len > HCI_MAX_FRAME_SIZE)
+ if (len < 4 || len > hci_pi(sk)->mtu)
return -EINVAL;

buf = kmalloc(len, GFP_KERNEL);
@@ -1849,8 +1854,8 @@ static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg,
goto done;
}

-static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
- sockptr_t optval, unsigned int len)
+static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,
+ sockptr_t optval, unsigned int len)
{
struct hci_ufilter uf = { .opcode = 0 };
struct sock *sk = sock->sk;
@@ -1858,9 +1863,6 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,

BT_DBG("sk %p, opt %d", sk, optname);

- if (level != SOL_HCI)
- return -ENOPROTOOPT;
-
lock_sock(sk);

if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) {
@@ -1935,18 +1937,63 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
return err;
}

-static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
- char __user *optval, int __user *optlen)
+static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
+ sockptr_t optval, unsigned int len)
{
- struct hci_ufilter uf;
struct sock *sk = sock->sk;
- int len, opt, err = 0;
+ int err = 0, opt = 0;

BT_DBG("sk %p, opt %d", sk, optname);

- if (level != SOL_HCI)
+ if (level == SOL_HCI)
+ return hci_sock_setsockopt_old(sock, level, optname, optval,
+ len);
+
+ if (level != SOL_BLUETOOTH)
return -ENOPROTOOPT;

+ lock_sock(sk);
+
+ switch (optname) {
+ case BT_SNDMTU:
+ case BT_RCVMTU:
+ switch (hci_pi(sk)->channel) {
+ /* Don't allow changing MTU for channels that are meant for HCI
+ * traffic only.
+ */
+ case HCI_CHANNEL_RAW:
+ case HCI_CHANNEL_USER:
+ err = -ENOPROTOOPT;
+ goto done;
+ }
+
+ if (copy_from_sockptr(&opt, optval, sizeof(u16))) {
+ err = -EFAULT;
+ break;
+ }
+
+ hci_pi(sk)->mtu = opt;
+ break;
+
+ default:
+ err = -ENOPROTOOPT;
+ break;
+ }
+
+done:
+ release_sock(sk);
+ return err;
+}
+
+static int hci_sock_getsockopt_old(struct socket *sock, int level, int optname,
+ char __user *optval, int __user *optlen)
+{
+ struct hci_ufilter uf;
+ struct sock *sk = sock->sk;
+ int len, opt, err = 0;
+
+ BT_DBG("sk %p, opt %d", sk, optname);
+
if (get_user(len, optlen))
return -EFAULT;

@@ -2004,6 +2051,42 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
return err;
}

+static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
+ char __user *optval, int __user *optlen)
+{
+ struct sock *sk = sock->sk;
+ int len, err = 0;
+
+ BT_DBG("sk %p, opt %d", sk, optname);
+
+ if (level == SOL_HCI)
+ return hci_sock_getsockopt_old(sock, level, optname, optval,
+ optlen);
+
+ if (level != SOL_BLUETOOTH)
+ return -ENOPROTOOPT;
+
+ if (get_user(len, optlen))
+ return -EFAULT;
+
+ lock_sock(sk);
+
+ switch (optname) {
+ case BT_SNDMTU:
+ case BT_RCVMTU:
+ if (put_user(hci_pi(sk)->mtu, (u32 __user *)optval))
+ err = -EFAULT;
+ break;
+
+ default:
+ err = -ENOPROTOOPT;
+ break;
+ }
+
+ release_sock(sk);
+ return err;
+}
+
static const struct proto_ops hci_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
--
2.31.1


2021-09-16 00:07:22

by Tedd Ho-Jeong An

[permalink] [raw]
Subject: Re: [PATCH v4 1/4] Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF

Hi Luiz,

On Wed, 2021-09-15 at 16:35 -0700, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This adds support for BT_{SND,RCV}BUF so userspace can set MTU based on
> the channel usage.
>
> Fixes: https://github.com/bluez/bluez/issues/201
>
> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
> ---
> net/bluetooth/hci_sock.c | 105 +++++++++++++++++++++++++++++++++++----
> 1 file changed, 94 insertions(+), 11 deletions(-)
>

Tested-by: Tedd Ho-Jeong An <[email protected]>

Regards,
Tedd

2021-09-16 00:07:23

by bluez.test.bot

[permalink] [raw]
Subject: RE: [v4,1/4] Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=547637

---Test result---

Test Summary:
CheckPatch FAIL 1.81 seconds
GitLint FAIL 0.50 seconds
BuildKernel PASS 622.33 seconds
TestRunner: Setup PASS 406.20 seconds
TestRunner: l2cap-tester PASS 3.03 seconds
TestRunner: bnep-tester PASS 2.15 seconds
TestRunner: mgmt-tester PASS 32.17 seconds
TestRunner: rfcomm-tester PASS 2.29 seconds
TestRunner: sco-tester PASS 2.31 seconds
TestRunner: smp-tester PASS 2.35 seconds
TestRunner: userchan-tester PASS 2.16 seconds

Details
##############################
Test: CheckPatch - FAIL - 1.81 seconds
Run checkpatch.pl script with rule in .checkpatch.conf
Bluetooth: Fix passing NULL to PTR_ERR
WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#7:
bt_skb_sendmsg does never return NULL it is safe to replace the instances of

total: 0 errors, 1 warnings, 0 checks, 24 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] Bluetooth: Fix passing NULL to PTR_ERR" has style problems, please review.

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - FAIL - 0.50 seconds
Run gitlint with rule in .gitlint
Bluetooth: SCO: Fix sco_send_frame returning skb->len
6: B1 Line exceeds max length (90>80): "Fixes: 0771cbb3b97d ("Bluetooth: SCO: Replace use of memcpy_from_msg with bt_skb_sendmsg")"


##############################
Test: BuildKernel - PASS - 622.33 seconds
Build Kernel with minimal configuration supports Bluetooth


##############################
Test: TestRunner: Setup - PASS - 406.20 seconds
Setup environment for running Test Runner


##############################
Test: TestRunner: l2cap-tester - PASS - 3.03 seconds
Run test-runner with l2cap-tester
Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: bnep-tester - PASS - 2.15 seconds
Run test-runner with bnep-tester
Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: mgmt-tester - PASS - 32.17 seconds
Run test-runner with mgmt-tester
Total: 452, Passed: 452 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: rfcomm-tester - PASS - 2.29 seconds
Run test-runner with rfcomm-tester
Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: sco-tester - PASS - 2.31 seconds
Run test-runner with sco-tester
Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: smp-tester - PASS - 2.35 seconds
Run test-runner with smp-tester
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: userchan-tester - PASS - 2.16 seconds
Run test-runner with userchan-tester
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0



---
Regards,
Linux Bluetooth


Attachments:
l2cap-tester.log (50.36 kB)
bnep-tester.log (3.84 kB)
mgmt-tester.log (612.15 kB)
rfcomm-tester.log (14.44 kB)
sco-tester.log (12.74 kB)
smp-tester.log (11.58 kB)
userchan-tester.log (6.36 kB)
Download all attachments

2021-09-16 04:22:06

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 1/4] Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF

Hi Luiz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on bluetooth/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-hci_sock-Add-support-for-BT_-SND-RCV-BUF/20210916-073730
base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 11.2.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
# https://github.com/0day-ci/linux/commit/8298fef36eee7525d4e8c7d2c8da9f9473342308
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Luiz-Augusto-von-Dentz/Bluetooth-hci_sock-Add-support-for-BT_-SND-RCV-BUF/20210916-073730
git checkout 8298fef36eee7525d4e8c7d2c8da9f9473342308
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=mips

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

All warnings (new ones prefixed by >>):

net/bluetooth/hci_sock.c: In function 'hci_sock_getsockopt':
>> net/bluetooth/hci_sock.c:2058:13: warning: variable 'len' set but not used [-Wunused-but-set-variable]
2058 | int len, err = 0;
| ^~~


vim +/len +2058 net/bluetooth/hci_sock.c

2053
2054 static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
2055 char __user *optval, int __user *optlen)
2056 {
2057 struct sock *sk = sock->sk;
> 2058 int len, err = 0;
2059
2060 BT_DBG("sk %p, opt %d", sk, optname);
2061
2062 if (level == SOL_HCI)
2063 return hci_sock_getsockopt_old(sock, level, optname, optval,
2064 optlen);
2065
2066 if (level != SOL_BLUETOOTH)
2067 return -ENOPROTOOPT;
2068
2069 if (get_user(len, optlen))
2070 return -EFAULT;
2071
2072 lock_sock(sk);
2073
2074 switch (optname) {
2075 case BT_SNDMTU:
2076 case BT_RCVMTU:
2077 if (put_user(hci_pi(sk)->mtu, (u32 __user *)optval))
2078 err = -EFAULT;
2079 break;
2080
2081 default:
2082 err = -ENOPROTOOPT;
2083 break;
2084 }
2085
2086 release_sock(sk);
2087 return err;
2088 }
2089

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


Attachments:
(No filename) (2.80 kB)
.config.gz (69.37 kB)
Download all attachments