Skip to content

Commit

Permalink
catfish: Add bluetooth_6lowpan
Browse files Browse the repository at this point in the history
This is intended to be a first step to implementing a generic data
transfer profile over Bluetooth as described here:
AsteroidOS/asteroid-btsyncd#22

Signed-off-by: Ed Beroset <beroset@ieee.org>
  • Loading branch information
beroset committed Oct 9, 2023
1 parent ab78cea commit 73eb7e6
Show file tree
Hide file tree
Showing 9 changed files with 618 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From 3ef5cd9eece497e5af800a66a6a2beb2e45c1f15 Mon Sep 17 00:00:00 2001
From: Ed Beroset <beroset@ieee.org>
Date: Fri, 6 Oct 2023 11:59:35 -0400
Subject: [PATCH] Add missing BT_6LOWPAN option to bluetooth Kconfig

This adds the BT_6LOWPAN option back in. It may have been deleted by
accident.

Signed-off-by: Ed Beroset <beroset@ieee.org>
---
net/bluetooth/Kconfig | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig
index 81f837f6d934..b8c794b87523 100644
--- a/net/bluetooth/Kconfig
+++ b/net/bluetooth/Kconfig
@@ -58,6 +58,12 @@ config BT_LE
depends on BT
default y

+config BT_6LOWPAN
+ tristate "Bluetooth 6LoWPAN support"
+ depends on BT_LE && 6LOWPAN
+ help
+ IPv6 compression over Bluetooth Low Energy.
+
config BT_SELFTEST
bool "Bluetooth self testing support"
depends on BT && DEBUG_KERNEL
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 34215ae8e5e5edbaed72b120b167b2b6f120cd2b Mon Sep 17 00:00:00 2001
From: Ed Beroset <beroset@ieee.org>
Date: Fri, 6 Oct 2023 12:08:29 -0400
Subject: [PATCH] Restore bluetooth_6lowpan to Makefile

I'm not sure why or how this was removed, but it's required for using
6lowpan over Bluetooth.

Signed-off-by: Ed Beroset <beroset@ieee.org>
---
net/bluetooth/Makefile | 3 +++
1 file changed, 3 insertions(+)

diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile
index c85a6afc6fe1..9a8ea232d28f 100644
--- a/net/bluetooth/Makefile
+++ b/net/bluetooth/Makefile
@@ -7,6 +7,9 @@ obj-$(CONFIG_BT_RFCOMM) += rfcomm/
obj-$(CONFIG_BT_BNEP) += bnep/
obj-$(CONFIG_BT_CMTP) += cmtp/
obj-$(CONFIG_BT_HIDP) += hidp/
+obj-$(CONFIG_BT_6LOWPAN) += bluetooth_6lowpan.o
+
+bluetooth_6lowpan-y := 6lowpan.o

bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \
hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o sco.o lib.o \
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 36893966a1b412a67fcd50cb4979d1ca5ed23bdc Mon Sep 17 00:00:00 2001
From: Ed Beroset <beroset@ieee.org>
Date: Fri, 6 Oct 2023 21:04:29 -0400
Subject: [PATCH] Move const to the right location

This fixes a small bug in the code in which a duplicate const
declaration was apparently intended to be a const pointer to a const
location.

Signed-off-by: Ed Beroset <beroset@ieee.org>
---
include/linux/msm_mhi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/msm_mhi.h b/include/linux/msm_mhi.h
index 08dc3a23abfa..a5ffa23a32d0 100644
--- a/include/linux/msm_mhi.h
+++ b/include/linux/msm_mhi.h
@@ -107,7 +107,7 @@ struct mhi_cb_info {

struct mhi_client_info_t {
enum MHI_CLIENT_CHANNEL chan;
- const struct device const *dev;
+ const struct device * const dev;
const char *node_name;
void (*mhi_client_cb)(struct mhi_cb_info *);
bool pre_allocate;
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
From f9981ae000018596f86f6c4ecbda34aef0253e2d Mon Sep 17 00:00:00 2001
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Date: Wed, 6 Feb 2019 18:56:27 +0100
Subject: [PATCH] include/linux/module.h: copy __init/__exit attrs to
init/cleanup_module

The upcoming GCC 9 release extends the -Wmissing-attributes warnings
(enabled by -Wall) to C and aliases: it warns when particular function
attributes are missing in the aliases but not in their target.

In particular, it triggers for all the init/cleanup_module
aliases in the kernel (defined by the module_init/exit macros),
ending up being very noisy.

These aliases point to the __init/__exit functions of a module,
which are defined as __cold (among other attributes). However,
the aliases themselves do not have the __cold attribute.

Since the compiler behaves differently when compiling a __cold
function as well as when compiling paths leading to calls
to __cold functions, the warning is trying to point out
the possibly-forgotten attribute in the alias.

In order to keep the warning enabled, we decided to silence
this case. Ideally, we would mark the aliases directly
as __init/__exit. However, there are currently around 132 modules
in the kernel which are missing __init/__exit in their init/cleanup
functions (either because they are missing, or for other reasons,
e.g. the functions being called from somewhere else); and
a section mismatch is a hard error.

A conservative alternative was to mark the aliases as __cold only.
However, since we would like to eventually enforce __init/__exit
to be always marked, we chose to use the new __copy function
attribute (introduced by GCC 9 as well to deal with this).
With it, we copy the attributes used by the target functions
into the aliases. This way, functions that were not marked
as __init/__exit won't have their aliases marked either,
and therefore there won't be a section mismatch.

Note that the warning would go away marking either the extern
declaration, the definition, or both. However, we only mark
the definition of the alias, since we do not want callers
(which only see the declaration) to be compiled as if the function
was __cold (and therefore the paths leading to those calls
would be assumed to be unlikely).

Link: https://lore.kernel.org/lkml/20190123173707.GA16603@gmail.com/
Link: https://lore.kernel.org/lkml/20190206175627.GA20399@gmail.com/
Suggested-by: Martin Sebor <msebor@gcc.gnu.org>
Acked-by: Jessica Yu <jeyu@kernel.org>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>

Signed-off-by: Ed Beroset <beroset@ieee.org>
---
include/linux/init.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 28ec4d128413..d68791117bd9 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -331,13 +331,13 @@ void __init parse_early_options(char *cmdline);
#define module_init(initfn) \
static inline initcall_t __inittest(void) \
{ return initfn; } \
- int init_module(void) __attribute__((alias(#initfn)));
+ int init_module(void) __copy(initfn) __attribute__((alias(#initfn)));

/* This is only required if you want to be unloadable. */
#define module_exit(exitfn) \
static inline exitcall_t __exittest(void) \
{ return exitfn; } \
- void cleanup_module(void) __attribute__((alias(#exitfn)));
+ void cleanup_module(void) __copy(exitfn) __attribute__((alias(#exitfn)));

#define __setup_param(str, unique_id, fn) /* nothing */
#define __setup(str, func) /* nothing */
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
From b97a52261d797f2731178416dafbad4d26dd0bf5 Mon Sep 17 00:00:00 2001
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Date: Fri, 6 Oct 2023 22:27:17 -0400
Subject: [PATCH] Compiler Attributes: add support for __copy (gcc >= 9)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

From the GCC manual:

copy
copy(function)

The copy attribute applies the set of attributes with which function
has been declared to the declaration of the function to which
the attribute is applied. The attribute is designed for libraries
that define aliases or function resolvers that are expected
to specify the same set of attributes as their targets. The copy
attribute can be used with functions, variables, or types. However,
the kind of symbol to which the attribute is applied (either
function or variable) must match the kind of symbol to which
the argument refers. The copy attribute copies only syntactic and
semantic attributes but not attributes that affect a symbol’s
linkage or visibility such as alias, visibility, or weak.
The deprecated attribute is also not copied.

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

The upcoming GCC 9 release extends the -Wmissing-attributes warnings
(enabled by -Wall) to C and aliases: it warns when particular function
attributes are missing in the aliases but not in their target, e.g.:

void __cold f(void) {}
void __alias("f") g(void);

diagnoses:

warning: 'g' specifies less restrictive attribute than
its target 'f': 'cold' [-Wmissing-attributes]

Using __copy(f) we can copy the __cold attribute from f to g:

void __cold f(void) {}
void __copy(f) __alias("f") g(void);

This attribute is most useful to deal with situations where an alias
is declared but we don't know the exact attributes the target has.

For instance, in the kernel, the widely used module_init/exit macros
define the init/cleanup_module aliases, but those cannot be marked
always as __init/__exit since some modules do not have their
functions marked as such.

Suggested-by: Martin Sebor <msebor@gcc.gnu.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>

Link: https://github.com/torvalds/linux/commit/c0d9782f5b6d7157635ae2fd782a4b27d55a6013
Link: https://github.com/ojeda/linux/commit/8803fd49f7f86efa39b60957c74ccf98690ae2ab

Signed-off-by: Ed Beroset <beroset@ieee.org>
---
include/linux/compiler.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 4c981adac770..682e8c0a95e5 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -50,6 +50,29 @@ extern void __chk_io_ptr(const volatile void __iomem *);

#ifdef __KERNEL__

+/*
+ * Minimal backport of compiler_attributes.h to add support for __copy
+ * to v4.9.y so that we can use it in init/exit_module to avoid
+ * -Werror=missing-attributes errors on GCC 9.
+ */
+#ifndef __has_attribute
+# define __has_attribute(x) __GCC4_has_attribute_##x
+# define __GCC4_has_attribute___copy__ 0
+#endif
+
+/*
+ * Optional: only supported since gcc >= 9
+ * Optional: not supported by clang
+ * Optional: not supported by icc
+ *
+ * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-copy-function-attribute
+ */
+#if __has_attribute(__copy__)
+# define __copy(symbol) __attribute__((__copy__(symbol)))
+#else
+# define __copy(symbol)
+#endif
+
#ifdef __GNUC__
#include <linux/compiler-gcc.h>
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
From 639c2a5098e96b510f7330e3084137bec0613985 Mon Sep 17 00:00:00 2001
From: Ed Beroset <beroset@ieee.org>
Date: Sat, 7 Oct 2023 11:42:34 -0400
Subject: [PATCH] Fix alignment of struct members

With newer versions (>9) of gcc, the compiler correctly warns that
"taking address of packed member of 'struct diag_mempool_t' may result
in an unaligned pointer value [-Waddress-of-packed-member]."

A similar warning comes up for dci_pkt_req_entry_t.

This removes the __packed attribute from both structs to address that
problem.

Signed-off-by: Ed Beroset <beroset@ieee.org>
---
drivers/char/diag/diag_dci.h | 4 ++--
drivers/char/diag/diagmem.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/char/diag/diag_dci.h b/drivers/char/diag/diag_dci.h
index a9e2d35cc50a..bf988c5fff23 100644
--- a/drivers/char/diag/diag_dci.h
+++ b/drivers/char/diag/diag_dci.h
@@ -95,7 +95,7 @@ struct dci_pkt_req_entry_t {
int uid;
int tag;
struct list_head track;
-} __packed;
+};

struct diag_dci_reg_tbl_t {
int client_id;
@@ -164,7 +164,7 @@ struct diag_dci_health_stats_proc {
int client_id;
struct diag_dci_health_stats health;
int proc;
-} __packed;
+};

struct diag_dci_peripherals_t {
int proc;
diff --git a/drivers/char/diag/diagmem.h b/drivers/char/diag/diagmem.h
index d097a3799e9a..77ef3003559e 100644
--- a/drivers/char/diag/diagmem.h
+++ b/drivers/char/diag/diagmem.h
@@ -50,7 +50,7 @@ struct diag_mempool_t {
unsigned int poolsize;
int count;
spinlock_t lock;
-} __packed;
+};

extern struct diag_mempool_t diag_mempools[NUM_MEMORY_POOLS];

Loading

0 comments on commit 73eb7e6

Please sign in to comment.