[PATCH net-next] nfc: netlink: use >w in nfc_genl_rcv_nl_event

2021-01-14 Thread Geliang Tang
Use the struct member w of the struct urelease_work directly instead of
casting it.

Signed-off-by: Geliang Tang 
---
 net/nfc/netlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 573b38ad2f8e..640906359c22 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -1819,9 +1819,9 @@ static int nfc_genl_rcv_nl_event(struct notifier_block 
*this,
 
w = kmalloc(sizeof(*w), GFP_ATOMIC);
if (w) {
-   INIT_WORK((struct work_struct *) w, nfc_urelease_event_work);
+   INIT_WORK(>w, nfc_urelease_event_work);
w->portid = n->portid;
-   schedule_work((struct work_struct *) w);
+   schedule_work(>w);
}
 
 out:
-- 
2.29.2



[MPTCP][PATCH net-next] mptcp: clear use_ack and use_map when dropping other suboptions

2020-12-15 Thread Geliang Tang
02
[   15.259822] FS:  7fae4a60a700() GS:88807c50() 
knlGS:
[   15.259826] CS:  0010 DS:  ES:  CR0: 80050033
[   15.260296] RDX:  RSI: 818e06c5 RDI: 88807f6dc700
[   15.262514] CR2: 0048 CR3: 0b89c000 CR4: 06e0
[   15.262515] Call Trace:
[   15.262519]  skb_release_all+0x28/0x30
[   15.262523]  __kfree_skb+0x11/0x20
[   15.263054] RBP: 88807f71a4c0 R08: 0001 R09: 0001
[   15.263680]  tcp_data_queue+0x270/0x1240
[   15.263843] R10: c900019c7c18 R11:  R12: 88807f71a4f0
[   15.264693]  ? tcp_urg+0x50/0x2a0
[   15.264856] R13:  R14: 88807f6dc700 R15: 0002
[   15.265720]  tcp_rcv_established+0x39a/0x890
[   15.266438] FS:  7f65d9b5f700() GS:88807c40() 
knlGS:
[   15.267283]  ? __schedule+0x3fa/0x880
[   15.267287]  tcp_v4_do_rcv+0xb9/0x270
[   15.267290]  __release_sock+0x8a/0x160
[   15.268049] CS:  0010 DS:  ES:  CR0: 80050033
[   15.268788]  release_sock+0x32/0xd0
[   15.268791]  __inet_stream_connect+0x1d2/0x400
[   15.268795]  ? do_wait_intr_irq+0x80/0x80
[   15.269593] CR2: 00223b10 CR3: 0b883000 CR4: 06f0
[   15.270246]  inet_stream_connect+0x36/0x50
[   15.270250]  mptcp_stream_connect+0x69/0x1b0
[   15.270253]  __sys_connect+0x122/0x140
[   15.271097] Kernel panic - not syncing: Fatal exception
[   15.271820]  ? syscall_enter_from_user_mode+0x17/0x50
[   15.283542]  ? lockdep_hardirqs_on_prepare+0xd4/0x170
[   15.284275]  __x64_sys_connect+0x1a/0x20
[   15.284853]  do_syscall_64+0x33/0x40
[   15.285369]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[   15.286105] RIP: 0033:0x7fae49f19469
[   15.286638] Code: 00 f3 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 
f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 
f0 ff ff 73 01 c3 48 8b 0d ff 49 2b 00 f7 d8 64 89 01 48
[   15.289295] RSP: 002b:7fae4a609da8 EFLAGS: 0246 ORIG_RAX: 
002a
[   15.290375] RAX: ffda RBX: 0049bf00 RCX: 7fae49f19469
[   15.291403] RDX: 0010 RSI: 20c0 RDI: 0005
[   15.292437] RBP: 0049bf00 R08:  R09: 
[   15.293456] R10:  R11: 0246 R12: 0049bf0c
[   15.294473] R13: 7fff0004b6bf R14: 7fae4a5ea000 R15: 0003
[   15.295492] Modules linked in:
[   15.295944] CR2: 0048
[   15.296567] Kernel Offset: disabled
[   15.296941] ---[ end Kernel panic - not syncing: Fatal exception ]---

Reported-by: Christoph Paasch 
Fixes: 84dfe3677a6f (mptcp: send out dedicated ADD_ADDR packet)
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 5e7d7755d1a6..f4047ace032d 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -606,6 +606,8 @@ static bool mptcp_established_options_add_addr(struct sock 
*sk, struct sk_buff *
skb && skb_is_tcp_pure_ack(skb)) {
pr_debug("drop other suboptions");
opts->suboptions = 0;
+   opts->ext_copy.use_ack = 0;
+   opts->ext_copy.use_map = 0;
remaining += opt_size;
drop_other_suboptions = true;
}
-- 
2.29.2



[PATCH] NFSv4.1: use BITS_PER_LONG macro in nfs4session.h

2020-12-07 Thread Geliang Tang
Use the existing BITS_PER_LONG macro instead of calculating the value.

Signed-off-by: Geliang Tang 
---
 fs/nfs/nfs4session.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfs/nfs4session.h b/fs/nfs/nfs4session.h
index b996ee23f1ba..3de425f59b3a 100644
--- a/fs/nfs/nfs4session.h
+++ b/fs/nfs/nfs4session.h
@@ -34,7 +34,7 @@ enum nfs4_slot_tbl_state {
NFS4_SLOT_TBL_DRAINING,
 };
 
-#define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, 8*sizeof(long))
+#define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, BITS_PER_LONG)
 struct nfs4_slot_table {
struct nfs4_session *session;   /* Parent session */
struct nfs4_slot *slots;/* seqid per slot */
-- 
2.26.2



Re: [MPTCP][PATCH net 1/2] mptcp: fix static checker warnings in mptcp_pm_add_timer

2020-11-11 Thread Geliang Tang
Hi Jakub, Matt,

Jakub Kicinski  于2020年11月10日周二 上午6:20写道:
>
> On Mon, 9 Nov 2020 21:23:33 + (UTC) Matthieu Baerts wrote:
> > 09 Nov 2020 21:57:05 Jakub Kicinski :
> > > On Mon, 9 Nov 2020 17:28:54 +0100 Matthieu Baerts wrote:
> > >> A small detail (I think): the Signed-off-by of the sender (Geliang)
> > >> should be the last one in the list if I am not mistaken.
> > >> But I guess this is not blocking.
> > >>
> > >> Reviewed-by: Matthieu Baerts 
> > >
> > > I take it you'd like me to apply patch 1 directly to net?
> >
> > Sorry, I didn't know it was OK to apply only one patch of the series.
> > Then yes, if you don't mind, please apply this patch :)
>
> Not really, I was just establishing ownership ;)
>
> Geliang Tang, please rebase on net and repost just the first patch.
> It does not apply to net as is.

v2 of this patch had been sent out.

http://patchwork.ozlabs.org/project/netdev/patch/078a2ef5bdc4e3b2c25ef852461692001f426495.1604976945.git.geliangt...@gmail.com/

This patch should be applied to net-next, not -net. Since commit "mptcp:
add a new sysctl add_addr_timeout" is not applied to -net yet.

-Geliang


[MPTCP][PATCH net 2/2] mptcp: cleanup for mptcp_pm_alloc_anno_list

2020-11-09 Thread Geliang Tang
This patch added NULL pointer check for mptcp_pm_alloc_anno_list, and
avoided similar static checker warnings in mptcp_pm_add_timer.

Signed-off-by: Geliang Tang 
Reviewed-by: Dan Carpenter 
---
 net/mptcp/pm_netlink.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 03f2c28f11f5..dfc1bed4a55f 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -266,7 +266,9 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
 {
struct mptcp_pm_add_entry *add_entry = NULL;
struct sock *sk = (struct sock *)msk;
-   struct net *net = sock_net(sk);
+
+   if (!msk)
+   return false;
 
if (lookup_anno_list_by_saddr(msk, >addr))
return false;
@@ -283,7 +285,7 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
 
timer_setup(_entry->add_timer, mptcp_pm_add_timer, 0);
sk_reset_timer(sk, _entry->add_timer,
-  jiffies + mptcp_get_add_addr_timeout(net));
+  jiffies + mptcp_get_add_addr_timeout(sock_net(sk)));
 
return true;
 }
-- 
2.26.2



[MPTCP][PATCH net 1/2] mptcp: fix static checker warnings in mptcp_pm_add_timer

2020-11-09 Thread Geliang Tang
Fix the following Smatch complaint:

 net/mptcp/pm_netlink.c:213 mptcp_pm_add_timer()
 warn: variable dereferenced before check 'msk' (see line 208)

 net/mptcp/pm_netlink.c
207  struct mptcp_sock *msk = entry->sock;
208  struct sock *sk = (struct sock *)msk;
209  struct net *net = sock_net(sk);
   ^^
 "msk" dereferenced here.

210
211  pr_debug("msk=%p", msk);
212
213  if (!msk)

 Too late.

214  return;
215

Fixes: 93f323b9 ("mptcp: add a new sysctl add_addr_timeout")
Reported-by: Dan Carpenter 
Signed-off-by: Geliang Tang 
Reviewed-by: Dan Carpenter 
---
 net/mptcp/pm_netlink.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 6180a8b39a3f..03f2c28f11f5 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -206,7 +206,6 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer);
struct mptcp_sock *msk = entry->sock;
struct sock *sk = (struct sock *)msk;
-   struct net *net = sock_net(sk);
 
pr_debug("msk=%p", msk);
 
@@ -235,7 +234,7 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
 
if (entry->retrans_times < ADD_ADDR_RETRANS_MAX)
sk_reset_timer(sk, timer,
-  jiffies + mptcp_get_add_addr_timeout(net));
+  jiffies + 
mptcp_get_add_addr_timeout(sock_net(sk)));
 
spin_unlock_bh(>pm.lock);
 
-- 
2.26.2



[MPTCP][PATCH net 0/2] fix static checker warnings in

2020-11-09 Thread Geliang Tang
This patchset fixed static checker warnings in mptcp_pm_add_timer and
mptcp_pm_alloc_anno_list.

Geliang Tang (2):
  mptcp: fix static checker warnings in mptcp_pm_add_timer
  mptcp: cleanup for mptcp_pm_alloc_anno_list

 net/mptcp/pm_netlink.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

-- 
2.26.2



Re: [MPTCP][PATCH net-next 0/2] init ahmac and port of mptcp_options_received

2020-10-20 Thread Geliang Tang
Hi Jakub,

Jakub Kicinski  于2020年10月21日周三 上午7:39写道:
>
> On Mon, 19 Oct 2020 18:23:14 +0800 Geliang Tang wrote:
> > This patchset deals with initializations of mptcp_options_received's two
> > fields, ahmac and port.
>
> Applied, but two extra comments:
>  - please make sure the commit messages are in imperative form
>e.g. "Initialize x..." rather than "This patches initializes x.."
>  - I dropped the Fixes tag from patch 2, and only queued patch 1 for
>stable - patch 2 is a minor clean up, right?

Yes, that's right. Thanks for applying and updating the patches.

-Geliang

>
> Thanks!


[MPTCP][PATCH net-next 2/2] mptcp: move mptcp_options_received's port initialization

2020-10-19 Thread Geliang Tang
This patch moved mptcp_options_received's port initialization from
mptcp_parse_option to mptcp_get_options, put it together with the other
fields initializations of mptcp_options_received.

Fixes: 3df523ab582c5 ("mptcp: Add ADD_ADDR handling")
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 1ff3469938b6..a044dd43411d 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -241,7 +241,6 @@ static void mptcp_parse_option(const struct sk_buff *skb,
}
 
mp_opt->add_addr = 1;
-   mp_opt->port = 0;
mp_opt->addr_id = *ptr++;
pr_debug("ADD_ADDR: id=%d, echo=%d", mp_opt->addr_id, 
mp_opt->echo);
if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
@@ -298,6 +297,7 @@ void mptcp_get_options(const struct sk_buff *skb,
mp_opt->mp_join = 0;
mp_opt->add_addr = 0;
mp_opt->ahmac = 0;
+   mp_opt->port = 0;
mp_opt->rm_addr = 0;
mp_opt->dss = 0;
 
-- 
2.26.2



[MPTCP][PATCH net-next 0/2] init ahmac and port of mptcp_options_received

2020-10-19 Thread Geliang Tang
This patchset deals with initializations of mptcp_options_received's two
fields, ahmac and port.

Geliang Tang (2):
  mptcp: initialize mptcp_options_received's ahmac
  mptcp: move mptcp_options_received's port initialization

 net/mptcp/options.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.26.2



[MPTCP][PATCH net-next 1/2] mptcp: initialize mptcp_options_received's ahmac

2020-10-19 Thread Geliang Tang
This patch initialize mptcp_options_received's ahmac to zero, otherwise it
will be a random number when receiving ADD_ADDR suboption with echo-flag=1.

Fixes: 3df523ab582c5 ("mptcp: Add ADD_ADDR handling")
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 092a2d48bfd3..1ff3469938b6 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -297,6 +297,7 @@ void mptcp_get_options(const struct sk_buff *skb,
mp_opt->mp_capable = 0;
mp_opt->mp_join = 0;
mp_opt->add_addr = 0;
+   mp_opt->ahmac = 0;
mp_opt->rm_addr = 0;
mp_opt->dss = 0;
 
-- 
2.26.2



[MPTCP][PATCH net-next 16/16] mptcp: retransmit ADD_ADDR when timeout

2020-09-23 Thread Geliang Tang
This patch implemented the retransmition of ADD_ADDR when no ADD_ADDR echo
is received. It added a timer with the announced address. When timeout
occurs, ADD_ADDR will be retransmitted.

Suggested-by: Mat Martineau 
Suggested-by: Paolo Abeni 
Acked-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c|   1 +
 net/mptcp/pm_netlink.c | 109 ++---
 net/mptcp/protocol.h   |   3 ++
 3 files changed, 96 insertions(+), 17 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 171039cbe9c4..14a290fae767 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -893,6 +893,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff 
*skb,
mptcp_pm_add_addr_received(msk, );
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
} else {
+   mptcp_pm_del_add_timer(msk, );
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
}
mp_opt.add_addr = 0;
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 701972b55a45..5a0e4d11bcc3 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -31,6 +31,9 @@ struct mptcp_pm_addr_entry {
 struct mptcp_pm_add_entry {
struct list_headlist;
struct mptcp_addr_info  addr;
+   struct timer_list   add_timer;
+   struct mptcp_sock   *sock;
+   u8  retrans_times;
 };
 
 struct pm_nl_pernet {
@@ -46,6 +49,7 @@ struct pm_nl_pernet {
 };
 
 #define MPTCP_PM_ADDR_MAX  8
+#define ADD_ADDR_RETRANS_MAX   3
 
 static bool addresses_equal(const struct mptcp_addr_info *a,
struct mptcp_addr_info *b, bool use_port)
@@ -183,23 +187,83 @@ static void check_work_pending(struct mptcp_sock *msk)
WRITE_ONCE(msk->pm.work_pending, false);
 }
 
-static bool lookup_anno_list_by_saddr(struct mptcp_sock *msk,
- struct mptcp_addr_info *addr)
+static struct mptcp_pm_add_entry *
+lookup_anno_list_by_saddr(struct mptcp_sock *msk,
+ struct mptcp_addr_info *addr)
 {
struct mptcp_pm_add_entry *entry;
 
list_for_each_entry(entry, >pm.anno_list, list) {
if (addresses_equal(>addr, addr, false))
-   return true;
+   return entry;
}
 
-   return false;
+   return NULL;
+}
+
+static void mptcp_pm_add_timer(struct timer_list *timer)
+{
+   struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer);
+   struct mptcp_sock *msk = entry->sock;
+   struct sock *sk = (struct sock *)msk;
+
+   pr_debug("msk=%p", msk);
+
+   if (!msk)
+   return;
+
+   if (inet_sk_state_load(sk) == TCP_CLOSE)
+   return;
+
+   if (!entry->addr.id)
+   return;
+
+   if (mptcp_pm_should_add_signal(msk)) {
+   sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX / 8);
+   goto out;
+   }
+
+   spin_lock_bh(>pm.lock);
+
+   if (!mptcp_pm_should_add_signal(msk)) {
+   pr_debug("retransmit ADD_ADDR id=%d", entry->addr.id);
+   mptcp_pm_announce_addr(msk, >addr, false);
+   entry->retrans_times++;
+   }
+
+   if (entry->retrans_times < ADD_ADDR_RETRANS_MAX)
+   sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX);
+
+   spin_unlock_bh(>pm.lock);
+
+out:
+   __sock_put(sk);
+}
+
+struct mptcp_pm_add_entry *
+mptcp_pm_del_add_timer(struct mptcp_sock *msk,
+  struct mptcp_addr_info *addr)
+{
+   struct mptcp_pm_add_entry *entry;
+   struct sock *sk = (struct sock *)msk;
+
+   spin_lock_bh(>pm.lock);
+   entry = lookup_anno_list_by_saddr(msk, addr);
+   if (entry)
+   entry->retrans_times = ADD_ADDR_RETRANS_MAX;
+   spin_unlock_bh(>pm.lock);
+
+   if (entry)
+   sk_stop_timer_sync(sk, >add_timer);
+
+   return entry;
 }
 
 static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
 struct mptcp_pm_addr_entry *entry)
 {
struct mptcp_pm_add_entry *add_entry = NULL;
+   struct sock *sk = (struct sock *)msk;
 
if (lookup_anno_list_by_saddr(msk, >addr))
return false;
@@ -210,21 +274,32 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock 
*msk,
 
list_add(_entry->list, >pm.anno_list);
 
+   add_entry->addr = entry->addr;
+   add_entry->sock = msk;
+   add_entry->retrans_times = 0;
+
+   timer_setup(_entry->add_timer, mptcp_pm_add_timer, 0);
+   sk_reset_timer(sk, _entry->add_timer, jiffies + TCP_RTO_MAX);
+
return true;
 }
 
 void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
 {
struct mptcp_pm_ad

[MPTCP][PATCH net-next 15/16] mptcp: add sk_stop_timer_sync helper

2020-09-23 Thread Geliang Tang
This patch added a new helper sk_stop_timer_sync, it deactivates a timer
like sk_stop_timer, but waits for the handler to finish.

Acked-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 include/net/sock.h | 2 ++
 net/core/sock.c| 7 +++
 2 files changed, 9 insertions(+)

diff --git a/include/net/sock.h b/include/net/sock.h
index eaa5cac5e836..a5c6ae78df77 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2195,6 +2195,8 @@ void sk_reset_timer(struct sock *sk, struct timer_list 
*timer,
 
 void sk_stop_timer(struct sock *sk, struct timer_list *timer);
 
+void sk_stop_timer_sync(struct sock *sk, struct timer_list *timer);
+
 int __sk_queue_drop_skb(struct sock *sk, struct sk_buff_head *sk_queue,
struct sk_buff *skb, unsigned int flags,
void (*destructor)(struct sock *sk,
diff --git a/net/core/sock.c b/net/core/sock.c
index ba9e7d91e2ef..d9a537e6876a 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2947,6 +2947,13 @@ void sk_stop_timer(struct sock *sk, struct timer_list* 
timer)
 }
 EXPORT_SYMBOL(sk_stop_timer);
 
+void sk_stop_timer_sync(struct sock *sk, struct timer_list *timer)
+{
+   if (del_timer_sync(timer))
+   __sock_put(sk);
+}
+EXPORT_SYMBOL(sk_stop_timer_sync);
+
 void sock_init_data(struct socket *sock, struct sock *sk)
 {
sk_init_common(sk);
-- 
2.17.1



[MPTCP][PATCH net-next 14/16] mptcp: add struct mptcp_pm_add_entry

2020-09-23 Thread Geliang Tang
Add a new struct mptcp_pm_add_entry to describe add_addr's entry.

Acked-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm_netlink.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index b33aebd85bd5..701972b55a45 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -28,6 +28,11 @@ struct mptcp_pm_addr_entry {
struct rcu_head rcu;
 };
 
+struct mptcp_pm_add_entry {
+   struct list_headlist;
+   struct mptcp_addr_info  addr;
+};
+
 struct pm_nl_pernet {
/* protects pernet updates */
spinlock_t  lock;
@@ -181,7 +186,7 @@ static void check_work_pending(struct mptcp_sock *msk)
 static bool lookup_anno_list_by_saddr(struct mptcp_sock *msk,
  struct mptcp_addr_info *addr)
 {
-   struct mptcp_pm_addr_entry *entry;
+   struct mptcp_pm_add_entry *entry;
 
list_for_each_entry(entry, >pm.anno_list, list) {
if (addresses_equal(>addr, addr, false))
@@ -194,23 +199,23 @@ static bool lookup_anno_list_by_saddr(struct mptcp_sock 
*msk,
 static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
 struct mptcp_pm_addr_entry *entry)
 {
-   struct mptcp_pm_addr_entry *clone = NULL;
+   struct mptcp_pm_add_entry *add_entry = NULL;
 
if (lookup_anno_list_by_saddr(msk, >addr))
return false;
 
-   clone = kmemdup(entry, sizeof(*entry), GFP_ATOMIC);
-   if (!clone)
+   add_entry = kmalloc(sizeof(*add_entry), GFP_ATOMIC);
+   if (!add_entry)
return false;
 
-   list_add(>list, >pm.anno_list);
+   list_add(_entry->list, >pm.anno_list);
 
return true;
 }
 
 void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
 {
-   struct mptcp_pm_addr_entry *entry, *tmp;
+   struct mptcp_pm_add_entry *entry, *tmp;
 
pr_debug("msk=%p", msk);
 
@@ -654,7 +659,7 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned 
int id)
 static bool remove_anno_list_by_saddr(struct mptcp_sock *msk,
  struct mptcp_addr_info *addr)
 {
-   struct mptcp_pm_addr_entry *entry, *tmp;
+   struct mptcp_pm_add_entry *entry, *tmp;
 
list_for_each_entry_safe(entry, tmp, >pm.anno_list, list) {
if (addresses_equal(>addr, addr, false)) {
-- 
2.17.1



[MPTCP][PATCH net-next 13/16] selftests: mptcp: add remove addr and subflow test cases

2020-09-23 Thread Geliang Tang
This patch added the remove addr and subflow test cases and two new
functions.

The first function run_remove_tests calls do_transfer with two new
arguments, rm_nr_ns1 and rm_nr_ns2, for the numbers of addresses should be
removed during the transfer process in namespace 1 and namespace 2.

If both these two arguments are 0, we do the join test cases with
"mptcp_connect -j" command. Otherwise, do the remove test cases with
"mptcp_connect -r" command.

The second function chk_rm_nr checks the RM_ADDR related mibs's counters.

The output of the test cases looks like this:

11 remove single subflow   syn[ ok ] - synack[ ok ] - ack[ ok ]
   rm [ ok ] - sf[ ok ]
12 remove multiple subflowssyn[ ok ] - synack[ ok ] - ack[ ok ]
   rm [ ok ] - sf[ ok ]
13 remove single address   syn[ ok ] - synack[ ok ] - ack[ ok ]
   add[ ok ] - echo  [ ok ]
   rm [ ok ] - sf[ ok ]
14 remove subflow and signal   syn[ ok ] - synack[ ok ] - ack[ ok ]
   add[ ok ] - echo  [ ok ]
   rm [ ok ] - sf[ ok ]
15 remove subflows and signal  syn[ ok ] - synack[ ok ] - ack[ ok ]
   add[ ok ] - echo  [ ok ]
   rm [ ok ] - sf[ ok ]

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Suggested-by: Mat Martineau 
Acked-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 145 +-
 1 file changed, 142 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh 
b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 9d64abdde146..08f53d86dedc 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -8,6 +8,7 @@ cin=""
 cout=""
 ksft_skip=4
 timeout=30
+mptcp_connect=""
 capture=0
 
 TEST_COUNT=0
@@ -132,6 +133,8 @@ do_transfer()
cl_proto="$3"
srv_proto="$4"
connect_addr="$5"
+   rm_nr_ns1="$6"
+   rm_nr_ns2="$7"
 
port=$((1+$TEST_COUNT))
TEST_COUNT=$((TEST_COUNT+1))
@@ -156,14 +159,44 @@ do_transfer()
sleep 1
fi
 
-   ip netns exec ${listener_ns} ./mptcp_connect -j -t $timeout -l -p $port 
-s ${srv_proto} 0.0.0.0 < "$sin" > "$sout" &
+   if [[ $rm_nr_ns1 -eq 0 && $rm_nr_ns2 -eq 0 ]]; then
+   mptcp_connect="./mptcp_connect -j"
+   else
+   mptcp_connect="./mptcp_connect -r"
+   fi
+
+   ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $port -s 
${srv_proto} 0.0.0.0 < "$sin" > "$sout" &
spid=$!
 
sleep 1
 
-   ip netns exec ${connector_ns} ./mptcp_connect -j -t $timeout -p $port 
-s ${cl_proto} $connect_addr < "$cin" > "$cout" &
+   ip netns exec ${connector_ns} $mptcp_connect -t $timeout -p $port -s 
${cl_proto} $connect_addr < "$cin" > "$cout" &
cpid=$!
 
+   if [ $rm_nr_ns1 -gt 0 ]; then
+   counter=1
+   sleep 1
+
+   while [ $counter -le $rm_nr_ns1 ]
+   do
+   ip netns exec ${listener_ns} ./pm_nl_ctl del $counter
+   sleep 1
+   let counter+=1
+   done
+   fi
+
+   if [ $rm_nr_ns2 -gt 0 ]; then
+   counter=1
+   sleep 1
+
+   while [ $counter -le $rm_nr_ns2 ]
+   do
+   ip netns exec ${connector_ns} ./pm_nl_ctl del $counter
+   sleep 1
+   let counter+=1
+   done
+   fi
+
wait $cpid
retc=$?
wait $spid
@@ -219,7 +252,24 @@ run_tests()
connect_addr="$3"
lret=0
 
-   do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
+   do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 
0 0
+   lret=$?
+   if [ $lret -ne 0 ]; then
+   ret=$lret
+   return
+   fi
+}
+
+run_remove_tests()
+{
+   listener_ns="$1"
+   connector_ns="$2"
+   connect_addr="$3"
+   rm_nr_ns1="$4"
+   rm_nr_ns2="$5"
+   lret=0
+
+   do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 
${rm_nr_ns1} ${rm_nr_ns2}
lret=$?
if [ $lret -ne 0 ]; then
ret=$lret
@@ -313,6 +363,43 @@ chk_add_nr()
fi
 }
 
+chk_rm_nr()
+{
+   local rm_addr_nr=$1
+   local rm_subflow_nr=$2
+   local count
+   local dump

[MPTCP][PATCH net-next 12/16] selftests: mptcp: add remove cfg in mptcp_connect

2020-09-23 Thread Geliang Tang
This patch added a new cfg, named cfg_remove in mptcp_connect. This new
cfg_remove is copied from cfg_join. The only difference between them is in
the do_rnd_write function. Here we slow down the transfer process of all
data to let the RM_ADDR suboption can be sent and received completely.
Otherwise the remove address and subflow test cases don't work.

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Suggested-by: Mat Martineau 
Acked-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 .../selftests/net/mptcp/mptcp_connect.c| 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c 
b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index a54966531a64..77bb62feb872 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -54,6 +54,7 @@ static int pf = AF_INET;
 static int cfg_sndbuf;
 static int cfg_rcvbuf;
 static bool cfg_join;
+static bool cfg_remove;
 static int cfg_wait;
 
 static void die_usage(void)
@@ -271,6 +272,9 @@ static size_t do_rnd_write(const int fd, char *buf, const 
size_t len)
if (cfg_join && first && do_w > 100)
do_w = 100;
 
+   if (cfg_remove && do_w > 50)
+   do_w = 50;
+
bw = write(fd, buf, do_w);
if (bw < 0)
perror("write");
@@ -281,6 +285,9 @@ static size_t do_rnd_write(const int fd, char *buf, const 
size_t len)
first = false;
}
 
+   if (cfg_remove)
+   usleep(20);
+
return bw;
 }
 
@@ -428,7 +435,7 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd)
}
 
/* leave some time for late join/announce */
-   if (cfg_join)
+   if (cfg_join || cfg_remove)
usleep(cfg_wait);
 
close(peerfd);
@@ -686,7 +693,7 @@ static void maybe_close(int fd)
 {
unsigned int r = rand();
 
-   if (!cfg_join && (r & 1))
+   if (!(cfg_join || cfg_remove) && (r & 1))
close(fd);
 }
 
@@ -822,13 +829,18 @@ static void parse_opts(int argc, char **argv)
 {
int c;
 
-   while ((c = getopt(argc, argv, "6jlp:s:hut:m:S:R:w:")) != -1) {
+   while ((c = getopt(argc, argv, "6jrlp:s:hut:m:S:R:w:")) != -1) {
switch (c) {
case 'j':
cfg_join = true;
cfg_mode = CFG_MODE_POLL;
cfg_wait = 40;
break;
+   case 'r':
+   cfg_remove = true;
+   cfg_mode = CFG_MODE_POLL;
+   cfg_wait = 40;
+   break;
case 'l':
listen_mode = true;
break;
-- 
2.17.1



[MPTCP][PATCH net-next 11/16] mptcp: add mptcp_destroy_common helper

2020-09-23 Thread Geliang Tang
This patch added a new helper named mptcp_destroy_common containing the
shared code between mptcp_destroy() and mptcp_sock_destruct().

Suggested-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/protocol.c | 11 ---
 net/mptcp/protocol.h |  1 +
 net/mptcp/subflow.c  |  4 +---
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b53e55826975..34c037731f35 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2128,16 +2128,21 @@ static struct sock *mptcp_accept(struct sock *sk, int 
flags, int *err,
return newsk;
 }
 
+void mptcp_destroy_common(struct mptcp_sock *msk)
+{
+   skb_rbtree_purge(>out_of_order_queue);
+   mptcp_token_destroy(msk);
+   mptcp_pm_free_anno_list(msk);
+}
+
 static void mptcp_destroy(struct sock *sk)
 {
struct mptcp_sock *msk = mptcp_sk(sk);
 
-   skb_rbtree_purge(>out_of_order_queue);
-   mptcp_token_destroy(msk);
if (msk->cached_ext)
__skb_ext_put(msk->cached_ext);
 
-   mptcp_pm_free_anno_list(msk);
+   mptcp_destroy_common(msk);
sk_sockets_allocated_dec(sk);
 }
 
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index df6cc94df1f7..db1e5de2fee7 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -408,6 +408,7 @@ bool mptcp_finish_join(struct sock *sk);
 void mptcp_data_acked(struct sock *sk);
 void mptcp_subflow_eof(struct sock *sk);
 bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq);
+void mptcp_destroy_common(struct mptcp_sock *msk);
 
 void __init mptcp_token_init(void);
 static inline void mptcp_token_init_request(struct request_sock *req)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index a1fefc965e17..ac2b19993f1a 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -435,9 +435,7 @@ static void mptcp_sock_destruct(struct sock *sk)
sock_orphan(sk);
}
 
-   skb_rbtree_purge(_sk(sk)->out_of_order_queue);
-   mptcp_token_destroy(mptcp_sk(sk));
-   mptcp_pm_free_anno_list(mptcp_sk(sk));
+   mptcp_destroy_common(mptcp_sk(sk));
inet_sock_destruct(sk);
 }
 
-- 
2.17.1



[MPTCP][PATCH net-next 10/16] mptcp: add RM_ADDR related mibs

2020-09-23 Thread Geliang Tang
This patch added two new mibs for RM_ADDR, named MPTCP_MIB_RMADDR and
MPTCP_MIB_RMSUBFLOW, when the RM_ADDR suboption is received, increase
the first mib counter, when the local subflow is removed, increase the
second mib counter.

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Suggested-by: Mat Martineau 
Acked-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/mib.c| 2 ++
 net/mptcp/mib.h| 2 ++
 net/mptcp/pm_netlink.c | 5 +
 3 files changed, 9 insertions(+)

diff --git a/net/mptcp/mib.c b/net/mptcp/mib.c
index a33bf719ce6f..84d119436b22 100644
--- a/net/mptcp/mib.c
+++ b/net/mptcp/mib.c
@@ -29,6 +29,8 @@ static const struct snmp_mib mptcp_snmp_list[] = {
SNMP_MIB_ITEM("DuplicateData", MPTCP_MIB_DUPDATA),
SNMP_MIB_ITEM("AddAddr", MPTCP_MIB_ADDADDR),
SNMP_MIB_ITEM("EchoAdd", MPTCP_MIB_ECHOADD),
+   SNMP_MIB_ITEM("RmAddr", MPTCP_MIB_RMADDR),
+   SNMP_MIB_ITEM("RmSubflow", MPTCP_MIB_RMSUBFLOW),
SNMP_MIB_SENTINEL
 };
 
diff --git a/net/mptcp/mib.h b/net/mptcp/mib.h
index cdeea3732ddf..47bcecce1106 100644
--- a/net/mptcp/mib.h
+++ b/net/mptcp/mib.h
@@ -22,6 +22,8 @@ enum linux_mptcp_mib_field {
MPTCP_MIB_DUPDATA,  /* Segments discarded due to duplicate 
DSS */
MPTCP_MIB_ADDADDR,  /* Received ADD_ADDR with echo-flag=0 */
MPTCP_MIB_ECHOADD,  /* Received ADD_ADDR with echo-flag=1 */
+   MPTCP_MIB_RMADDR,   /* Received RM_ADDR */
+   MPTCP_MIB_RMSUBFLOW,/* Remove a subflow */
__MPTCP_MIB_MAX
 };
 
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 9064c8098521..b33aebd85bd5 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -15,6 +15,7 @@
 #include 
 
 #include "protocol.h"
+#include "mib.h"
 
 /* forward declaration */
 static struct genl_family mptcp_genl_family;
@@ -346,6 +347,8 @@ void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
msk->pm.subflows--;
WRITE_ONCE(msk->pm.accept_addr, true);
 
+   __MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMADDR);
+
break;
}
 }
@@ -379,6 +382,8 @@ void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock 
*msk, u8 rm_id)
msk->pm.local_addr_used--;
msk->pm.subflows--;
 
+   __MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW);
+
break;
}
 }
-- 
2.17.1



[MPTCP][PATCH net-next 09/16] mptcp: implement mptcp_pm_remove_subflow

2020-09-23 Thread Geliang Tang
This patch implemented the local subflow removing function,
mptcp_pm_remove_subflow, it simply called mptcp_pm_nl_rm_subflow_received
under the PM spin lock.

We use mptcp_pm_remove_subflow to remove a local subflow, so change it's
argument from remote_id to local_id.

We check subflow->local_id in mptcp_pm_nl_rm_subflow_received to remove
a subflow.

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Suggested-by: Mat Martineau 
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm.c |  9 +++--
 net/mptcp/pm_netlink.c | 33 +
 net/mptcp/protocol.h   |  3 ++-
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index f450bf0d49aa..7e81f53d1e5d 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -33,9 +33,14 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
return 0;
 }
 
-int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id)
+int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id)
 {
-   return -ENOTSUPP;
+   pr_debug("msk=%p, local_id=%d", msk, local_id);
+
+   spin_lock_bh(>pm.lock);
+   mptcp_pm_nl_rm_subflow_received(msk, local_id);
+   spin_unlock_bh(>pm.lock);
+   return 0;
 }
 
 /* path manager event handlers */
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 97f9280f83fb..9064c8098521 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -350,6 +350,39 @@ void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
}
 }
 
+void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id)
+{
+   struct mptcp_subflow_context *subflow, *tmp;
+   struct sock *sk = (struct sock *)msk;
+
+   pr_debug("subflow rm_id %d", rm_id);
+
+   if (!rm_id)
+   return;
+
+   if (list_empty(>conn_list))
+   return;
+
+   list_for_each_entry_safe(subflow, tmp, >conn_list, node) {
+   struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+   int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
+   long timeout = 0;
+
+   if (rm_id != subflow->local_id)
+   continue;
+
+   spin_unlock_bh(>pm.lock);
+   mptcp_subflow_shutdown(sk, ssk, how);
+   __mptcp_close_ssk(sk, ssk, subflow, timeout);
+   spin_lock_bh(>pm.lock);
+
+   msk->pm.local_addr_used--;
+   msk->pm.subflows--;
+
+   break;
+   }
+}
+
 static bool address_use_port(struct mptcp_pm_addr_entry *entry)
 {
return (entry->addr.flags &
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index d1b1416797f8..df6cc94df1f7 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -448,7 +448,7 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
   const struct mptcp_addr_info *addr,
   bool echo);
 int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
-int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id);
+int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
 
 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
 {
@@ -479,6 +479,7 @@ void mptcp_pm_nl_fully_established(struct mptcp_sock *msk);
 void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk);
 void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk);
 void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk);
+void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id);
 int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
-- 
2.17.1



[MPTCP][PATCH net-next 08/16] mptcp: remove addr and subflow in PM netlink

2020-09-23 Thread Geliang Tang
This patch implements the remove announced addr and subflow logic in PM
netlink.

When the PM netlink removes an address, we traverse all the existing msk
sockets to find the relevant sockets.

We add a new list named anno_list in mptcp_pm_data, to record all the
announced addrs. In the traversing, we check if it has been recorded.
If it has been, we trigger the RM_ADDR signal.

We also check if this address is in conn_list. If it is, we remove the
subflow which using this local address.

Since we call mptcp_pm_free_anno_list in mptcp_destroy, we need to move
__mptcp_init_sock before the mptcp_is_enabled check in mptcp_init_sock.

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Suggested-by: Mat Martineau 
Acked-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm.c |   7 ++-
 net/mptcp/pm_netlink.c | 122 +++--
 net/mptcp/protocol.c   |   9 +--
 net/mptcp/protocol.h   |   2 +
 net/mptcp/subflow.c|   1 +
 5 files changed, 130 insertions(+), 11 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index be4157279e15..f450bf0d49aa 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -26,7 +26,11 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 
 int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
 {
-   return -ENOTSUPP;
+   pr_debug("msk=%p, local_id=%d", msk, local_id);
+
+   msk->pm.rm_id = local_id;
+   WRITE_ONCE(msk->pm.rm_addr_signal, true);
+   return 0;
 }
 
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id)
@@ -231,6 +235,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
msk->pm.status = 0;
 
spin_lock_init(>pm.lock);
+   INIT_LIST_HEAD(>pm.anno_list);
 
mptcp_pm_nl_data_init(msk);
 }
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index f6f96bc2046b..97f9280f83fb 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -177,6 +177,50 @@ static void check_work_pending(struct mptcp_sock *msk)
WRITE_ONCE(msk->pm.work_pending, false);
 }
 
+static bool lookup_anno_list_by_saddr(struct mptcp_sock *msk,
+ struct mptcp_addr_info *addr)
+{
+   struct mptcp_pm_addr_entry *entry;
+
+   list_for_each_entry(entry, >pm.anno_list, list) {
+   if (addresses_equal(>addr, addr, false))
+   return true;
+   }
+
+   return false;
+}
+
+static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
+struct mptcp_pm_addr_entry *entry)
+{
+   struct mptcp_pm_addr_entry *clone = NULL;
+
+   if (lookup_anno_list_by_saddr(msk, >addr))
+   return false;
+
+   clone = kmemdup(entry, sizeof(*entry), GFP_ATOMIC);
+   if (!clone)
+   return false;
+
+   list_add(>list, >pm.anno_list);
+
+   return true;
+}
+
+void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
+{
+   struct mptcp_pm_addr_entry *entry, *tmp;
+
+   pr_debug("msk=%p", msk);
+
+   spin_lock_bh(>pm.lock);
+   list_for_each_entry_safe(entry, tmp, >pm.anno_list, list) {
+   list_del(>list);
+   kfree(entry);
+   }
+   spin_unlock_bh(>pm.lock);
+}
+
 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 {
struct mptcp_addr_info remote = { 0 };
@@ -197,8 +241,10 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct 
mptcp_sock *msk)
  msk->pm.add_addr_signaled);
 
if (local) {
-   msk->pm.add_addr_signaled++;
-   mptcp_pm_announce_addr(msk, >addr, false);
+   if (mptcp_pm_alloc_anno_list(msk, local)) {
+   msk->pm.add_addr_signaled++;
+   mptcp_pm_announce_addr(msk, >addr, 
false);
+   }
} else {
/* pick failed, avoid fourther attempts later */
msk->pm.local_addr_used = msk->pm.add_addr_signal_max;
@@ -567,6 +613,68 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned 
int id)
return NULL;
 }
 
+static bool remove_anno_list_by_saddr(struct mptcp_sock *msk,
+ struct mptcp_addr_info *addr)
+{
+   struct mptcp_pm_addr_entry *entry, *tmp;
+
+   list_for_each_entry_safe(entry, tmp, >pm.anno_list, list) {
+   if (addresses_equal(>addr, addr, false)) {
+   list_del(>list);
+   kfree(entry);
+   return true;
+   }
+   }
+
+   return false;
+}
+
+static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
+ struct mptcp_addr_info *addr,
+ bool force)
+{
+ 

[MPTCP][PATCH net-next 07/16] mptcp: add accept_subflow re-check

2020-09-23 Thread Geliang Tang
The re-check of pm->accept_subflow with pm->lock held was missing, this
patch fixed it.

Suggested-by: Mat Martineau 
Reviewed-by: Mat Martineau 
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 39a76620d0a5..be4157279e15 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -48,7 +48,7 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, int 
server_side)
 bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
 {
struct mptcp_pm_data *pm = >pm;
-   int ret;
+   int ret = 0;
 
pr_debug("msk=%p subflows=%d max=%d allow=%d", msk, pm->subflows,
 pm->subflows_max, READ_ONCE(pm->accept_subflow));
@@ -58,9 +58,11 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
return false;
 
spin_lock_bh(>lock);
-   ret = pm->subflows < pm->subflows_max;
-   if (ret && ++pm->subflows == pm->subflows_max)
-   WRITE_ONCE(pm->accept_subflow, false);
+   if (READ_ONCE(pm->accept_subflow)) {
+   ret = pm->subflows < pm->subflows_max;
+   if (ret && ++pm->subflows == pm->subflows_max)
+   WRITE_ONCE(pm->accept_subflow, false);
+   }
spin_unlock_bh(>lock);
 
return ret;
-- 
2.17.1



[MPTCP][PATCH net-next 06/16] selftests: mptcp: add ADD_ADDR mibs check function

2020-09-23 Thread Geliang Tang
This patch added the ADD_ADDR related mibs counter check function
chk_add_nr(). This function check both ADD_ADDR and ADD_ADDR with
echo flag.

The output looks like this:

 07 unused signal address syn[ ok ] - synack[ ok ] - ack[ ok ]
  add[ ok ] - echo  [ ok ]
 08 signal addresssyn[ ok ] - synack[ ok ] - ack[ ok ]
  add[ ok ] - echo  [ ok ]
 09 subflow and signalsyn[ ok ] - synack[ ok ] - ack[ ok ]
  add[ ok ] - echo  [ ok ]
 10 multiple subflows and signal  syn[ ok ] - synack[ ok ] - ack[ ok ]
  add[ ok ] - echo  [ ok ]
 11 remove subflow and signal syn[ ok ] - synack[ ok ] - ack[ ok ]
  add[ ok ] - echo  [ ok ]

Reviewed-by: Mat Martineau 
Signed-off-by: Geliang Tang 
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 44 +++
 1 file changed, 44 insertions(+)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh 
b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index c2943e4dfcfe..9d64abdde146 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -276,6 +276,43 @@ chk_join_nr()
fi
 }
 
+chk_add_nr()
+{
+   local add_nr=$1
+   local echo_nr=$2
+   local count
+   local dump_stats
+
+   printf "%-39s %s" " " "add"
+   count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk 
'{print $2}'`
+   [ -z "$count" ] && count=0
+   if [ "$count" != "$add_nr" ]; then
+   echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
+   ret=1
+   dump_stats=1
+   else
+   echo -n "[ ok ]"
+   fi
+
+   echo -n " - echo  "
+   count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk 
'{print $2}'`
+   [ -z "$count" ] && count=0
+   if [ "$count" != "$echo_nr" ]; then
+   echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
+   ret=1
+   dump_stats=1
+   else
+   echo "[ ok ]"
+   fi
+
+   if [ "${dump_stats}" = 1 ]; then
+   echo Server ns stats
+   ip netns exec $ns1 nstat -as | grep MPTcp
+   echo Client ns stats
+   ip netns exec $ns2 nstat -as | grep MPTcp
+   fi
+}
+
 sin=$(mktemp)
 sout=$(mktemp)
 cin=$(mktemp)
@@ -332,6 +369,7 @@ reset
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "unused signal address" 0 0 0
+chk_add_nr 1 1
 
 # accept and use add_addr
 reset
@@ -340,6 +378,7 @@ ip netns exec $ns2 ./pm_nl_ctl limits 1 1
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "signal address" 1 1 1
+chk_add_nr 1 1
 
 # accept and use add_addr with an additional subflow
 # note: signal address in server ns and local addresses in client ns must
@@ -352,6 +391,7 @@ ip netns exec $ns2 ./pm_nl_ctl limits 1 2
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "subflow and signal" 2 2 2
+chk_add_nr 1 1
 
 # accept and use add_addr with additional subflows
 reset
@@ -362,6 +402,7 @@ ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "multiple subflows and signal" 3 3 3
+chk_add_nr 1 1
 
 # single subflow, syncookies
 reset_with_cookies
@@ -396,6 +437,7 @@ ip netns exec $ns2 ./pm_nl_ctl limits 1 1
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "signal address with syn cookies" 1 1 1
+chk_add_nr 1 1
 
 # test cookie with subflow and signal
 reset_with_cookies
@@ -405,6 +447,7 @@ ip netns exec $ns2 ./pm_nl_ctl limits 1 2
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "subflow and signal w cookies" 2 2 2
+chk_add_nr 1 1
 
 # accept and use add_addr with additional subflows
 reset_with_cookies
@@ -415,5 +458,6 @@ ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "subflows and signal w. cookies" 3 3 3
+chk_add_nr 1 1
 
 exit $ret
-- 
2.17.1



[MPTCP][PATCH net-next 05/16] mptcp: add ADD_ADDR related mibs

2020-09-23 Thread Geliang Tang
This patch added two mibs for ADD_ADDR, MPTCP_MIB_ADDADDR for receiving
of the ADD_ADDR suboption with echo-flag=0, and MPTCP_MIB_ECHOADD for
receiving the ADD_ADDR suboption with echo-flag=1.

Reviewed-by: Mat Martineau 
Co-developed-by: Paolo Abeni 
Signed-off-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/mib.c | 2 ++
 net/mptcp/mib.h | 2 ++
 net/mptcp/options.c | 7 ++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/mib.c b/net/mptcp/mib.c
index 056986c7a228..a33bf719ce6f 100644
--- a/net/mptcp/mib.c
+++ b/net/mptcp/mib.c
@@ -27,6 +27,8 @@ static const struct snmp_mib mptcp_snmp_list[] = {
SNMP_MIB_ITEM("OFOMerge", MPTCP_MIB_OFOMERGE),
SNMP_MIB_ITEM("NoDSSInWindow", MPTCP_MIB_NODSSWINDOW),
SNMP_MIB_ITEM("DuplicateData", MPTCP_MIB_DUPDATA),
+   SNMP_MIB_ITEM("AddAddr", MPTCP_MIB_ADDADDR),
+   SNMP_MIB_ITEM("EchoAdd", MPTCP_MIB_ECHOADD),
SNMP_MIB_SENTINEL
 };
 
diff --git a/net/mptcp/mib.h b/net/mptcp/mib.h
index 937a177729f1..cdeea3732ddf 100644
--- a/net/mptcp/mib.h
+++ b/net/mptcp/mib.h
@@ -20,6 +20,8 @@ enum linux_mptcp_mib_field {
MPTCP_MIB_OFOMERGE, /* Segments merged in OoO queue */
MPTCP_MIB_NODSSWINDOW,  /* Segments not in MPTCP windows */
MPTCP_MIB_DUPDATA,  /* Segments discarded due to duplicate 
DSS */
+   MPTCP_MIB_ADDADDR,  /* Received ADD_ADDR with echo-flag=0 */
+   MPTCP_MIB_ECHOADD,  /* Received ADD_ADDR with echo-flag=1 */
__MPTCP_MIB_MAX
 };
 
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index a41996e6c6d7..171039cbe9c4 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include "protocol.h"
+#include "mib.h"
 
 static bool mptcp_cap_flag_sha256(u8 flags)
 {
@@ -888,8 +889,12 @@ void mptcp_incoming_options(struct sock *sk, struct 
sk_buff *skb,
addr.addr6 = mp_opt.addr6;
}
 #endif
-   if (!mp_opt.echo)
+   if (!mp_opt.echo) {
mptcp_pm_add_addr_received(msk, );
+   MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
+   } else {
+   MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
+   }
mp_opt.add_addr = 0;
}
 
-- 
2.17.1



[MPTCP][PATCH net-next 04/16] mptcp: send out ADD_ADDR with echo flag

2020-09-23 Thread Geliang Tang
When the ADD_ADDR suboption has been received, we need to send out the same
ADD_ADDR suboption with echo-flag=1, and no HMAC.

Suggested-by: Mat Martineau 
Reviewed-by: Mat Martineau 
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c| 27 ---
 net/mptcp/pm.c | 18 +-
 net/mptcp/pm_netlink.c |  4 +++-
 net/mptcp/protocol.h   |  6 --
 4 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index a52a05effac9..a41996e6c6d7 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -242,7 +242,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
mp_opt->add_addr = 1;
mp_opt->port = 0;
mp_opt->addr_id = *ptr++;
-   pr_debug("ADD_ADDR: id=%d", mp_opt->addr_id);
+   pr_debug("ADD_ADDR: id=%d, echo=%d", mp_opt->addr_id, 
mp_opt->echo);
if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
memcpy((u8 *)_opt->addr.s_addr, (u8 *)ptr, 4);
ptr += 4;
@@ -579,10 +579,11 @@ static bool mptcp_established_options_add_addr(struct 
sock *sk,
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
struct mptcp_addr_info saddr;
+   bool echo;
int len;
 
if (!mptcp_pm_should_add_signal(msk) ||
-   !(mptcp_pm_add_addr_signal(msk, remaining, )))
+   !(mptcp_pm_add_addr_signal(msk, remaining, , )))
return false;
 
len = mptcp_add_addr_len(saddr.family);
@@ -594,22 +595,26 @@ static bool mptcp_established_options_add_addr(struct 
sock *sk,
if (saddr.family == AF_INET) {
opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
opts->addr = saddr.addr;
-   opts->ahmac = add_addr_generate_hmac(msk->local_key,
-msk->remote_key,
-opts->addr_id,
->addr);
+   if (!echo) {
+   opts->ahmac = add_addr_generate_hmac(msk->local_key,
+msk->remote_key,
+opts->addr_id,
+>addr);
+   }
}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
else if (saddr.family == AF_INET6) {
opts->suboptions |= OPTION_MPTCP_ADD_ADDR6;
opts->addr6 = saddr.addr6;
-   opts->ahmac = add_addr6_generate_hmac(msk->local_key,
- msk->remote_key,
- opts->addr_id,
- >addr6);
+   if (!echo) {
+   opts->ahmac = add_addr6_generate_hmac(msk->local_key,
+ msk->remote_key,
+ opts->addr_id,
+ >addr6);
+   }
}
 #endif
-   pr_debug("addr_id=%d, ahmac=%llu", opts->addr_id, opts->ahmac);
+   pr_debug("addr_id=%d, ahmac=%llu, echo=%d", opts->addr_id, opts->ahmac, 
echo);
 
return true;
 }
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 558462d87eb3..39a76620d0a5 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -13,11 +13,13 @@
 /* path manager command handlers */
 
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
-  const struct mptcp_addr_info *addr)
+  const struct mptcp_addr_info *addr,
+  bool echo)
 {
pr_debug("msk=%p, local_id=%d", msk, addr->id);
 
msk->pm.local = *addr;
+   WRITE_ONCE(msk->pm.add_addr_echo, echo);
WRITE_ONCE(msk->pm.add_addr_signal, true);
return 0;
 }
@@ -135,15 +137,11 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
pr_debug("msk=%p remote_id=%d accept=%d", msk, addr->id,
 READ_ONCE(pm->accept_addr));
 
-   /* avoid acquiring the lock if there is no room for fouther addresses */
-   if (!READ_ONCE(pm->accept_addr))
-   return;
-
spin_lock_bh(>lock);
 
-   /* be sure there is something to signal re-checking under PM lock */
-   if (READ_ONCE(pm->accept_addr) &&
-   mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED))
+   if (!READ_ONCE(pm->accept_addr))
+   mptcp_pm_announce_addr(msk, addr, true);
+   els

[MPTCP][PATCH net-next 03/16] mptcp: add the incoming RM_ADDR support

2020-09-23 Thread Geliang Tang
This patch added the RM_ADDR option parsing logic:

We parsed the incoming options to find if the rm_addr option is received,
and called mptcp_pm_rm_addr_received to schedule PM work to a new status,
named MPTCP_PM_RM_ADDR_RECEIVED.

PM work got this status, and called mptcp_pm_nl_rm_addr_received to handle
it.

In mptcp_pm_nl_rm_addr_received, we closed the subflow matching the rm_id,
and updated PM counter.

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Suggested-by: Mat Martineau 
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c|  5 +
 net/mptcp/pm.c | 12 
 net/mptcp/pm_netlink.c | 34 ++
 net/mptcp/protocol.c   | 12 
 net/mptcp/protocol.h   |  7 +++
 5 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index bbc124876417..a52a05effac9 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -888,6 +888,11 @@ void mptcp_incoming_options(struct sock *sk, struct 
sk_buff *skb,
mp_opt.add_addr = 0;
}
 
+   if (mp_opt.rm_addr) {
+   mptcp_pm_rm_addr_received(msk, mp_opt.rm_id);
+   mp_opt.rm_addr = 0;
+   }
+
if (!mp_opt.dss)
return;
 
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 81b07ae213b9..558462d87eb3 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -149,6 +149,18 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
spin_unlock_bh(>lock);
 }
 
+void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)
+{
+   struct mptcp_pm_data *pm = >pm;
+
+   pr_debug("msk=%p remote_id=%d", msk, rm_id);
+
+   spin_lock_bh(>lock);
+   mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED);
+   pm->rm_id = rm_id;
+   spin_unlock_bh(>lock);
+}
+
 /* path manager helpers */
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index b4a9624d7bf2..4124bc581308 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -268,6 +268,40 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
spin_lock_bh(>pm.lock);
 }
 
+void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
+{
+   struct mptcp_subflow_context *subflow, *tmp;
+   struct sock *sk = (struct sock *)msk;
+
+   pr_debug("address rm_id %d", msk->pm.rm_id);
+
+   if (!msk->pm.rm_id)
+   return;
+
+   if (list_empty(>conn_list))
+   return;
+
+   list_for_each_entry_safe(subflow, tmp, >conn_list, node) {
+   struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+   int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
+   long timeout = 0;
+
+   if (msk->pm.rm_id != subflow->remote_id)
+   continue;
+
+   spin_unlock_bh(>pm.lock);
+   mptcp_subflow_shutdown(sk, ssk, how);
+   __mptcp_close_ssk(sk, ssk, subflow, timeout);
+   spin_lock_bh(>pm.lock);
+
+   msk->pm.add_addr_accepted--;
+   msk->pm.subflows--;
+   WRITE_ONCE(msk->pm.accept_addr, true);
+
+   break;
+   }
+}
+
 static bool address_use_port(struct mptcp_pm_addr_entry *entry)
 {
return (entry->addr.flags &
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 386cd4e60250..26b9233f247c 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1652,9 +1652,9 @@ static struct sock *mptcp_subflow_get_retrans(const 
struct mptcp_sock *msk)
  * so we need to use tcp_close() after detaching them from the mptcp
  * parent socket.
  */
-static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
- struct mptcp_subflow_context *subflow,
- long timeout)
+void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
+  struct mptcp_subflow_context *subflow,
+  long timeout)
 {
struct socket *sock = READ_ONCE(ssk->sk_socket);
 
@@ -1685,6 +1685,10 @@ static void pm_work(struct mptcp_sock *msk)
pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_RECEIVED);
mptcp_pm_nl_add_addr_received(msk);
}
+   if (pm->status & BIT(MPTCP_PM_RM_ADDR_RECEIVED)) {
+   pm->status &= ~BIT(MPTCP_PM_RM_ADDR_RECEIVED);
+   mptcp_pm_nl_rm_addr_received(msk);
+   }
if (pm->status & BIT(MPTCP_PM_ESTABLISHED)) {
pm->status &= ~BIT(MPTCP_PM_ESTABLISHED);
mptcp_pm_nl_fully_established(msk);
@@ -1846,7 +1850,7 @@ static void mptcp_cancel_work(struct sock *sk)
sock_put(sk);
 }
 
-static void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
+void mptcp_subflow_shutdown(struct sock *sk, st

[MPTCP][PATCH net-next 02/16] mptcp: add the outgoing RM_ADDR support

2020-09-23 Thread Geliang Tang
This patch added a new signal named rm_addr_signal in PM. On outgoing path,
we called mptcp_pm_should_rm_signal to check if rm_addr_signal has been
set. If it has been, we sent out the RM_ADDR option.

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c  | 29 +
 net/mptcp/pm.c   | 25 +
 net/mptcp/protocol.h |  9 +
 3 files changed, 63 insertions(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index ee0cb0546324..bbc124876417 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -614,6 +614,31 @@ static bool mptcp_established_options_add_addr(struct sock 
*sk,
return true;
 }
 
+static bool mptcp_established_options_rm_addr(struct sock *sk,
+ unsigned int *size,
+ unsigned int remaining,
+ struct mptcp_out_options *opts)
+{
+   struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
+   struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+   u8 rm_id;
+
+   if (!mptcp_pm_should_rm_signal(msk) ||
+   !(mptcp_pm_rm_addr_signal(msk, remaining, _id)))
+   return false;
+
+   if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
+   return false;
+
+   *size = TCPOLEN_MPTCP_RM_ADDR_BASE;
+   opts->suboptions |= OPTION_MPTCP_RM_ADDR;
+   opts->rm_id = rm_id;
+
+   pr_debug("rm_id=%d", opts->rm_id);
+
+   return true;
+}
+
 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
   unsigned int *size, unsigned int remaining,
   struct mptcp_out_options *opts)
@@ -644,6 +669,10 @@ bool mptcp_established_options(struct sock *sk, struct 
sk_buff *skb,
*size += opt_size;
remaining -= opt_size;
ret = true;
+   } else if (mptcp_established_options_rm_addr(sk, _size, remaining, 
opts)) {
+   *size += opt_size;
+   remaining -= opt_size;
+   ret = true;
}
 
return ret;
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index ce12b8b26ad2..81b07ae213b9 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -174,6 +174,29 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, 
unsigned int remaining,
return ret;
 }
 
+bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
+u8 *rm_id)
+{
+   int ret = false;
+
+   spin_lock_bh(>pm.lock);
+
+   /* double check after the lock is acquired */
+   if (!mptcp_pm_should_rm_signal(msk))
+   goto out_unlock;
+
+   if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
+   goto out_unlock;
+
+   *rm_id = msk->pm.rm_id;
+   WRITE_ONCE(msk->pm.rm_addr_signal, false);
+   ret = true;
+
+out_unlock:
+   spin_unlock_bh(>pm.lock);
+   return ret;
+}
+
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 {
return mptcp_pm_nl_get_local_id(msk, skc);
@@ -185,8 +208,10 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
msk->pm.add_addr_accepted = 0;
msk->pm.local_addr_used = 0;
msk->pm.subflows = 0;
+   msk->pm.rm_id = 0;
WRITE_ONCE(msk->pm.work_pending, false);
WRITE_ONCE(msk->pm.add_addr_signal, false);
+   WRITE_ONCE(msk->pm.rm_addr_signal, false);
WRITE_ONCE(msk->pm.accept_addr, false);
WRITE_ONCE(msk->pm.accept_subflow, false);
msk->pm.status = 0;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 91adc9a19757..8929b0c7660a 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -163,6 +163,7 @@ struct mptcp_pm_data {
spinlock_t  lock;   /*protects the whole PM data */
 
booladd_addr_signal;
+   boolrm_addr_signal;
boolserver_side;
boolwork_pending;
boolaccept_addr;
@@ -176,6 +177,7 @@ struct mptcp_pm_data {
u8  local_addr_max;
u8  subflows_max;
u8  status;
+   u8  rm_id;
 };
 
 struct mptcp_data_frag {
@@ -443,6 +445,11 @@ static inline bool mptcp_pm_should_add_signal(struct 
mptcp_sock *msk)
return READ_ONCE(msk->pm.add_addr_signal);
 }
 
+static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
+{
+   return READ_ONCE(msk->pm.rm_addr_signal);
+}
+
 static inline unsigned int mptcp_add_addr_len(int family)
 {
if (family == AF_INET)
@@ -452,6 +459,8 @@ static inline unsigned int mptcp_add_addr_len(int family)
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
  struct mptcp_addr_info *saddr);

[MPTCP][PATCH net-next 01/16] mptcp: rename addr_signal and the related functions

2020-09-23 Thread Geliang Tang
This patch renamed addr_signal and the related functions with the explicit
word "add".

Suggested-by: Matthieu Baerts 
Suggested-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c  | 14 +++---
 net/mptcp/pm.c   | 12 ++--
 net/mptcp/protocol.h | 10 +-
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 7fa822b55c34..ee0cb0546324 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -571,18 +571,18 @@ static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 
addr_id,
 }
 #endif
 
-static bool mptcp_established_options_addr(struct sock *sk,
-  unsigned int *size,
-  unsigned int remaining,
-  struct mptcp_out_options *opts)
+static bool mptcp_established_options_add_addr(struct sock *sk,
+  unsigned int *size,
+  unsigned int remaining,
+  struct mptcp_out_options *opts)
 {
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
struct mptcp_addr_info saddr;
int len;
 
-   if (!mptcp_pm_should_signal(msk) ||
-   !(mptcp_pm_addr_signal(msk, remaining, )))
+   if (!mptcp_pm_should_add_signal(msk) ||
+   !(mptcp_pm_add_addr_signal(msk, remaining, )))
return false;
 
len = mptcp_add_addr_len(saddr.family);
@@ -640,7 +640,7 @@ bool mptcp_established_options(struct sock *sk, struct 
sk_buff *skb,
 
*size += opt_size;
remaining -= opt_size;
-   if (mptcp_established_options_addr(sk, _size, remaining, opts)) {
+   if (mptcp_established_options_add_addr(sk, _size, remaining, opts)) 
{
*size += opt_size;
remaining -= opt_size;
ret = true;
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index a8ad20559aaa..ce12b8b26ad2 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -18,7 +18,7 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
pr_debug("msk=%p, local_id=%d", msk, addr->id);
 
msk->pm.local = *addr;
-   WRITE_ONCE(msk->pm.addr_signal, true);
+   WRITE_ONCE(msk->pm.add_addr_signal, true);
return 0;
 }
 
@@ -151,22 +151,22 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 
 /* path manager helpers */
 
-bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
- struct mptcp_addr_info *saddr)
+bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
+ struct mptcp_addr_info *saddr)
 {
int ret = false;
 
spin_lock_bh(>pm.lock);
 
/* double check after the lock is acquired */
-   if (!mptcp_pm_should_signal(msk))
+   if (!mptcp_pm_should_add_signal(msk))
goto out_unlock;
 
if (remaining < mptcp_add_addr_len(msk->pm.local.family))
goto out_unlock;
 
*saddr = msk->pm.local;
-   WRITE_ONCE(msk->pm.addr_signal, false);
+   WRITE_ONCE(msk->pm.add_addr_signal, false);
ret = true;
 
 out_unlock:
@@ -186,7 +186,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
msk->pm.local_addr_used = 0;
msk->pm.subflows = 0;
WRITE_ONCE(msk->pm.work_pending, false);
-   WRITE_ONCE(msk->pm.addr_signal, false);
+   WRITE_ONCE(msk->pm.add_addr_signal, false);
WRITE_ONCE(msk->pm.accept_addr, false);
WRITE_ONCE(msk->pm.accept_subflow, false);
msk->pm.status = 0;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 493bd2c13bc6..91adc9a19757 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -162,7 +162,7 @@ struct mptcp_pm_data {
 
spinlock_t  lock;   /*protects the whole PM data */
 
-   booladdr_signal;
+   booladd_addr_signal;
boolserver_side;
boolwork_pending;
boolaccept_addr;
@@ -438,9 +438,9 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id);
 
-static inline bool mptcp_pm_should_signal(struct mptcp_sock *msk)
+static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
 {
-   return READ_ONCE(msk->pm.addr_signal);
+   return READ_ONCE(msk->pm.add_addr_signal);
 }
 
 static inline unsigned int mptcp_add_addr_len(int family)
@@ -450,8 +450,8 @@ static inline unsigned int mptcp_add_addr_len(int family)
return TCPOLEN_MPTCP_ADD_ADDR6;
 }
 
-bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-

[MPTCP][PATCH net-next 00/16] mptcp: RM_ADDR/ADD_ADDR enhancements

2020-09-23 Thread Geliang Tang
This series include two enhancements for the MPTCP path management,
namely RM_ADDR support and ADD_ADDR echo support, as specified by RFC
sections 3.4.1 and 3.4.2.

1 RM_ADDR support include 9 patches (1-3 and 8-13):

Patch 1 is the helper for patch 2, these two patches add the RM_ADDR
outgoing functions, which are derived from ADD_ADDR's corresponding
functions.

Patch 3 adds the RM_ADDR incoming logic, when RM_ADDR suboption is
received, close the subflow matching the rm_id, and update PM counter.

Patch 8 is the main remove routine. When the PM netlink removes an address,
we traverse all the existing msk sockets to find the relevant sockets. Then
trigger the RM_ADDR signal and remove the subflow which using this local
address, this subflow removing functions has been implemented in patch 9.

Finally, patches 10-13 are the self-tests for RM_ADDR.

2 ADD_ADDR echo support include 7 patches (4-7 and 14-16).

Patch 4 adds the ADD_ADDR echo logic, when the ADD_ADDR suboption has been
received, send out the same ADD_ADDR suboption with echo-flag, and no HMAC
included.

Patches 5 and 6 are the self-tests for ADD_ADDR echo. Patch 7 is a little
cleaning up.

Patch 14 and 15 are the helpers for patch 16. These three patches add
the ADD_ADDR retransmition when no ADD_ADDR echo is received.

Geliang Tang (16):
  mptcp: rename addr_signal and the related functions
  mptcp: add the outgoing RM_ADDR support
  mptcp: add the incoming RM_ADDR support
  mptcp: send out ADD_ADDR with echo flag
  mptcp: add ADD_ADDR related mibs
  selftests: mptcp: add ADD_ADDR mibs check function
  mptcp: add accept_subflow re-check
  mptcp: remove addr and subflow in PM netlink
  mptcp: implement mptcp_pm_remove_subflow
  mptcp: add RM_ADDR related mibs
  mptcp: add mptcp_destroy_common helper
  selftests: mptcp: add remove cfg in mptcp_connect
  selftests: mptcp: add remove addr and subflow test cases
  mptcp: add struct mptcp_pm_add_entry
  mptcp: add sk_stop_timer_sync helper
  mptcp: retransmit ADD_ADDR when timeout

 include/net/sock.h|   2 +
 net/core/sock.c   |   7 +
 net/mptcp/mib.c   |   4 +
 net/mptcp/mib.h   |   4 +
 net/mptcp/options.c   |  81 +++--
 net/mptcp/pm.c|  91 --
 net/mptcp/pm_netlink.c| 276 +-
 net/mptcp/protocol.c  |  30 +-
 net/mptcp/protocol.h  |  39 ++-
 net/mptcp/subflow.c   |   3 +-
 .../selftests/net/mptcp/mptcp_connect.c   |  18 +-
 .../testing/selftests/net/mptcp/mptcp_join.sh | 189 +++-
 12 files changed, 674 insertions(+), 70 deletions(-)

-- 
2.17.1



Re: [mptcp] db71a2f198: WARNING:inconsistent_lock_state

2020-09-09 Thread Geliang Tang
kernel test robot  于2020年9月10日周四 上午8:19写道:
>
> Greeting,
>
> FYI, we noticed the following commit (built with gcc-9):
>
> commit: db71a2f198fef53a9f710ad5ac475bbdb6aba840 ("[MPTCP][PATCH v2 net 1/2] 
> mptcp: fix subflow's local_id issues")
> url: 
> https://github.com/0day-ci/linux/commits/Geliang-Tang/mptcp-fix-subflow-s-local_id-remote_id-issues/20200908-105733
> base: https://git.kernel.org/cgit/linux/kernel/git/davem/net.git 
> e1f469cd5866499ac40bfdca87411e1c525a10c7
>
> in testcase: kernel-selftests
> version: kernel-selftests-x86_64-e8e8f16e-1_20200807
> with following parameters:
>
> group: kselftests-mptcp
>
> test-description: The kernel contains a set of "self tests" under the 
> tools/testing/selftests/ directory. These are intended to be small unit tests 
> to exercise individual code paths in the kernel.
> test-url: https://www.kernel.org/doc/Documentation/kselftest.txt
>
>
> on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 8G
>
> caused below changes (please refer to attached dmesg/kmsg for entire 
> log/backtrace):
>
>
> ++++
> |
> | e1f469cd58 | db71a2f198 |
> ++++
> | boot_successes 
> | 15 | 8  |
> | boot_failures  
> | 2  | 9  |
> | Kernel_panic-not_syncing:VFS:Unable_to_mount_root_fs_on_unknown-block(#,#) 
> | 2  ||
> | WARNING:inconsistent_lock_state
> | 0  | 9  |
> | inconsistent{SOFTIRQ-ON-W}->{IN-SOFTIRQ-W}usage
> | 0  | 9  |
> | calltrace:asm_call_on_stack
> | 0  | 9  |
> | BUG:sleeping_function_called_from_invalid_context_at_mm/slab.h 
> | 0  | 9  |
> ++++
>
>
> If you fix the issue, kindly add following tag
> Reported-by: kernel test robot 
>
>
> [  257.607162] WARNING: inconsistent lock state
> [  257.609399] 5.9.0-rc3-00371-gdb71a2f198fef #1 Not tainted
> [  257.611927] 
> [  257.614273] inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
> [  257.617486] kworker/1:2/101 [HC0[0]:SC1[3]:HE1:SE0] takes:
> [  257.620140] ae1aaa40 (fs_reclaim){+.?.}-{0:0}, at: 
> fs_reclaim_acquire+0x5/0x40
> [  257.623680] {SOFTIRQ-ON-W} state was registered at:
> [  257.626250]   lock_acquire+0xaf/0x380
> [  257.628516]   fs_reclaim_acquire+0x25/0x40
> [  257.631071]   __kmalloc_node+0x60/0x560
> [  257.633350]   alloc_cpumask_var_node+0x1b/0x40
> [  257.635850]   native_smp_prepare_cpus+0xad/0x292
> [  257.638255]   kernel_init_freeable+0x15a/0x2dd
> [  257.640847]   kernel_init+0xa/0x122
> [  257.643277]   ret_from_fork+0x22/0x30
> [  257.645510] irq event stamp: 89762
> [  257.647888] hardirqs last  enabled at (89762): [] 
> process_backlog+0x1b0/0x260
> [  257.651614] hardirqs last disabled at (89761): [] 
> process_backlog+0x235/0x260
> [  257.655368] softirqs last  enabled at (89756): [] 
> ip_finish_output2+0x258/0xa20
> [  257.659186] softirqs last disabled at (89757): [] 
> asm_call_on_stack+0x12/0x20
> [  257.663053]
> [  257.663053] other info that might help us debug this:
> [  257.667675]  Possible unsafe locking scenario:
> [  257.667675]
> [  257.672233]CPU0
> [  257.674229]
> [  257.676375]   lock(fs_reclaim);
> [  257.678563]   
> [  257.680618] lock(fs_reclaim);
> [  257.682673]
> [  257.682673]  *** DEADLOCK ***
> [  257.682673]
> [  257.687974] 8 locks held by kworker/1:2/101:
> [  257.690177]  #0: a060c7c56938 ((wq_completion)events){+.+.}-{0:0}, at: 
> process_one_work+0x1bc/0x5a0
> [  257.693771]  #1: c2fac0197e58 
> ((work_completion)(>work)){+.+.}-{0:0}, at: process_one_work+0x1bc/0x5a0
> [  257.697437]  #2: a060dd8258e0 (sk_lock-AF_INET){+.+.}-{0:0}, at: 
> mptcp_worker+0x5f/0xac0
> [  257.700972]  #3: a061247e2e20 (k-sk_lock-AF_INET){+.+.}-{0:0}, at: 
> inet_stream_connect+0x23/0x60
> [  257.704558]  #4: ae0c9a40 (rcu_read_lock){}-{1:2}, at: 
> __ip_queue_xmit+0x5/0x600
> [  257.707957]  #5: ae0c9a40 (rcu_read_lock){}-{1:2}, at: 
> process_backlog+0x75/0x260
&

[MPTCP][PATCH net] mptcp: fix kmalloc flag in mptcp_pm_nl_get_local_id

2020-09-08 Thread Geliang Tang
mptcp_pm_nl_get_local_id may be called in interrupt context, so we need to
use GFP_ATOMIC flag to allocate memory to avoid sleeping in atomic context.

[  280.209809] BUG: sleeping function called from invalid context at 
mm/slab.h:498
[  280.209812] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1680, 
name: kworker/1:3
[  280.209814] INFO: lockdep is turned off.
[  280.209816] CPU: 1 PID: 1680 Comm: kworker/1:3 Tainted: GW 
5.9.0-rc3-mptcp+ #146
[  280.209818] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS 
VirtualBox 12/01/2006
[  280.209820] Workqueue: events mptcp_worker
[  280.209822] Call Trace:
[  280.209824]  
[  280.209826]  dump_stack+0x77/0xa0
[  280.209829]  ___might_sleep.cold+0xa6/0xb6
[  280.209832]  kmem_cache_alloc_trace+0x1d1/0x290
[  280.209835]  mptcp_pm_nl_get_local_id+0x23c/0x410
[  280.209840]  subflow_init_req+0x1e9/0x2ea
[  280.209843]  ? inet_reqsk_alloc+0x1c/0x120
[  280.209845]  ? kmem_cache_alloc+0x264/0x290
[  280.209849]  tcp_conn_request+0x303/0xae0
[  280.209854]  ? printk+0x53/0x6a
[  280.209857]  ? tcp_rcv_state_process+0x28f/0x1374
[  280.209859]  tcp_rcv_state_process+0x28f/0x1374
[  280.209864]  ? tcp_v4_do_rcv+0xb3/0x1f0
[  280.209866]  tcp_v4_do_rcv+0xb3/0x1f0
[  280.209869]  tcp_v4_rcv+0xed6/0xfa0
[  280.209873]  ip_protocol_deliver_rcu+0x28/0x270
[  280.209875]  ip_local_deliver_finish+0x89/0x120
[  280.209877]  ip_local_deliver+0x180/0x220
[  280.209881]  ip_rcv+0x166/0x210
[  280.209885]  __netif_receive_skb_one_core+0x82/0x90
[  280.209888]  process_backlog+0xd6/0x230
[  280.209891]  net_rx_action+0x13a/0x410
[  280.209895]  __do_softirq+0xcf/0x468
[  280.209899]  asm_call_on_stack+0x12/0x20
[  280.209901]  
[  280.209903]  ? ip_finish_output2+0x240/0x9a0
[  280.209906]  do_softirq_own_stack+0x4d/0x60
[  280.209908]  do_softirq.part.0+0x2b/0x60
[  280.209911]  __local_bh_enable_ip+0x9a/0xa0
[  280.209913]  ip_finish_output2+0x264/0x9a0
[  280.209916]  ? rcu_read_lock_held+0x4d/0x60
[  280.209920]  ? ip_output+0x7a/0x250
[  280.209922]  ip_output+0x7a/0x250
[  280.209925]  ? __ip_finish_output+0x330/0x330
[  280.209928]  __ip_queue_xmit+0x1dc/0x5a0
[  280.209931]  __tcp_transmit_skb+0xa0f/0xc70
[  280.209937]  tcp_connect+0xb03/0xff0
[  280.209939]  ? lockdep_hardirqs_on_prepare+0xe7/0x190
[  280.209942]  ? ktime_get_with_offset+0x125/0x150
[  280.209944]  ? trace_hardirqs_on+0x1c/0xe0
[  280.209948]  tcp_v4_connect+0x449/0x550
[  280.209953]  __inet_stream_connect+0xbb/0x320
[  280.209955]  ? mark_held_locks+0x49/0x70
[  280.209958]  ? lockdep_hardirqs_on_prepare+0xe7/0x190
[  280.209960]  ? __local_bh_enable_ip+0x6b/0xa0
[  280.209963]  inet_stream_connect+0x32/0x50
[  280.209966]  __mptcp_subflow_connect+0x1fd/0x242
[  280.209972]  mptcp_pm_create_subflow_or_signal_addr+0x2db/0x600
[  280.209975]  mptcp_worker+0x543/0x7a0
[  280.209980]  process_one_work+0x26d/0x5b0
[  280.209984]  ? process_one_work+0x5b0/0x5b0
[  280.209987]  worker_thread+0x48/0x3d0
[  280.209990]  ? process_one_work+0x5b0/0x5b0
[  280.209993]  kthread+0x117/0x150
[  280.209996]  ? kthread_park+0x80/0x80
[  280.209998]  ret_from_fork+0x22/0x30

Fixes: 01cacb00b35cb ("mptcp: add netlink-based PM")
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index bd88e9c0bf71..1f6d029ccf40 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -354,7 +354,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct 
sock_common *skc)
return ret;
 
/* address not found, add to local list */
-   entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+   entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
if (!entry)
return -ENOMEM;
 
-- 
2.17.1



[MPTCP][PATCH v2 net 2/2] mptcp: fix subflow's remote_id issues

2020-09-07 Thread Geliang Tang
This patch set the init remote_id to zero, otherwise it will be a random
number.

Then it added the missing subflow's remote_id setting code both in
__mptcp_subflow_connect and in subflow_ulp_clone.

Fixes: 01cacb00b35cb ("mptcp: add netlink-based PM")
Fixes: ec3edaa7ca6ce ("mptcp: Add handling of outgoing MP_JOIN requests")
Fixes: f296234c98a8f ("mptcp: Add handling of incoming MP_JOIN requests")
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm_netlink.c | 2 +-
 net/mptcp/subflow.c| 7 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 3e70d848033d..bd88e9c0bf71 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -181,9 +181,9 @@ static void check_work_pending(struct mptcp_sock *msk)
 
 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 {
+   struct mptcp_addr_info remote = { 0 };
struct sock *sk = (struct sock *)msk;
struct mptcp_pm_addr_entry *local;
-   struct mptcp_addr_info remote;
struct pm_nl_pernet *pernet;
 
pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index e8cac2655c82..9ead43f79023 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1063,6 +1063,7 @@ int __mptcp_subflow_connect(struct sock *sk, int ifindex,
struct mptcp_sock *msk = mptcp_sk(sk);
struct mptcp_subflow_context *subflow;
struct sockaddr_storage addr;
+   int remote_id = remote->id;
int local_id = loc->id;
struct socket *sf;
struct sock *ssk;
@@ -1107,10 +1108,11 @@ int __mptcp_subflow_connect(struct sock *sk, int 
ifindex,
goto failed;
 
mptcp_crypto_key_sha(subflow->remote_key, _token, NULL);
-   pr_debug("msk=%p remote_token=%u local_id=%d", msk, remote_token,
-local_id);
+   pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
+remote_token, local_id, remote_id);
subflow->remote_token = remote_token;
subflow->local_id = local_id;
+   subflow->remote_id = remote_id;
subflow->request_join = 1;
subflow->request_bkup = 1;
mptcp_info2sockaddr(remote, );
@@ -1347,6 +1349,7 @@ static void subflow_ulp_clone(const struct request_sock 
*req,
new_ctx->fully_established = 1;
new_ctx->backup = subflow_req->backup;
new_ctx->local_id = subflow_req->local_id;
+   new_ctx->remote_id = subflow_req->remote_id;
new_ctx->token = subflow_req->token;
new_ctx->thmac = subflow_req->thmac;
}
-- 
2.17.1



[MPTCP][PATCH v2 net 1/2] mptcp: fix subflow's local_id issues

2020-09-07 Thread Geliang Tang
In mptcp_pm_nl_get_local_id, skc_local is the same as msk_local, so it
always return 0. Thus every subflow's local_id is 0. It's incorrect.

This patch fixed this issue.

Also, we need to ignore the zero address here, like 0.0.0.0 in IPv4. When
we use the zero address as a local address, it means that we can use any
one of the local addresses. The zero address is not a new address, we don't
need to add it to PM, so this patch added a new function address_zero to
check whether an address is the zero address, if it is, we ignore this
address.

Fixes: 01cacb00b35cb ("mptcp: add netlink-based PM")
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm_netlink.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 2c208d2e65cd..3e70d848033d 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -66,6 +66,16 @@ static bool addresses_equal(const struct mptcp_addr_info *a,
return a->port == b->port;
 }
 
+static bool address_zero(const struct mptcp_addr_info *addr)
+{
+   struct mptcp_addr_info zero;
+
+   memset(, 0, sizeof(zero));
+   zero.family = addr->family;
+
+   return addresses_equal(addr, , false);
+}
+
 static void local_address(const struct sock_common *skc,
  struct mptcp_addr_info *addr)
 {
@@ -323,10 +333,13 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, 
struct sock_common *skc)
 * addr
 */
local_address((struct sock_common *)msk, _local);
-   local_address((struct sock_common *)msk, _local);
+   local_address((struct sock_common *)skc, _local);
if (addresses_equal(_local, _local, false))
return 0;
 
+   if (address_zero(_local))
+   return 0;
+
pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
 
rcu_read_lock();
-- 
2.17.1



[MPTCP][PATCH v2 net 0/2] mptcp: fix subflow's local_id/remote_id issues

2020-09-07 Thread Geliang Tang
v2:
 - add Fixes tags;
 - simply with 'return addresses_equal';
 - use 'reversed Xmas tree' way.

Geliang Tang (2):
  mptcp: fix subflow's local_id issues
  mptcp: fix subflow's remote_id issues

 net/mptcp/pm_netlink.c | 17 +++--
 net/mptcp/subflow.c|  7 +--
 2 files changed, 20 insertions(+), 4 deletions(-)

-- 
2.17.1



[MPTCP][PATCH net 2/2] mptcp: fix subflow's remote_id issues

2020-09-07 Thread Geliang Tang
This patch set the init remote_id to zero, otherwise it will be a random
number.

Then it added the missing subflow's remote_id setting code both in
__mptcp_subflow_connect and in subflow_ulp_clone.

Reviewed-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm_netlink.c | 2 +-
 net/mptcp/subflow.c| 7 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index dc2c57860d2d..255695221309 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -186,7 +186,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct 
mptcp_sock *msk)
 {
struct sock *sk = (struct sock *)msk;
struct mptcp_pm_addr_entry *local;
-   struct mptcp_addr_info remote;
+   struct mptcp_addr_info remote = { 0 };
struct pm_nl_pernet *pernet;
 
pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index e8cac2655c82..9ead43f79023 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1063,6 +1063,7 @@ int __mptcp_subflow_connect(struct sock *sk, int ifindex,
struct mptcp_sock *msk = mptcp_sk(sk);
struct mptcp_subflow_context *subflow;
struct sockaddr_storage addr;
+   int remote_id = remote->id;
int local_id = loc->id;
struct socket *sf;
struct sock *ssk;
@@ -1107,10 +1108,11 @@ int __mptcp_subflow_connect(struct sock *sk, int 
ifindex,
goto failed;
 
mptcp_crypto_key_sha(subflow->remote_key, _token, NULL);
-   pr_debug("msk=%p remote_token=%u local_id=%d", msk, remote_token,
-local_id);
+   pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk,
+remote_token, local_id, remote_id);
subflow->remote_token = remote_token;
subflow->local_id = local_id;
+   subflow->remote_id = remote_id;
subflow->request_join = 1;
subflow->request_bkup = 1;
mptcp_info2sockaddr(remote, );
@@ -1347,6 +1349,7 @@ static void subflow_ulp_clone(const struct request_sock 
*req,
new_ctx->fully_established = 1;
new_ctx->backup = subflow_req->backup;
new_ctx->local_id = subflow_req->local_id;
+   new_ctx->remote_id = subflow_req->remote_id;
new_ctx->token = subflow_req->token;
new_ctx->thmac = subflow_req->thmac;
}
-- 
2.17.1



[MPTCP][PATCH net 1/2] mptcp: fix subflow's local_id issues

2020-09-07 Thread Geliang Tang
In mptcp_pm_nl_get_local_id, skc_local is the same as msk_local, so it
always return 0. Thus every subflow's local_id is 0. It's incorrect.

This patch fixed this issue.

Also, we need to ignore the zero address here, like 0.0.0.0 in IPv4. When
we use the zero address as a local address, it means that we can use any
one of the local addresses. The zero address is not a new address, we don't
need to add it to PM, so this patch added a new function address_zero to
check whether an address is the zero address, if it is, we ignore this
address.

Reviewed-by: Paolo Abeni 
Signed-off-by: Geliang Tang 
---
 net/mptcp/pm_netlink.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 2c208d2e65cd..dc2c57860d2d 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -66,6 +66,19 @@ static bool addresses_equal(const struct mptcp_addr_info *a,
return a->port == b->port;
 }
 
+static bool address_zero(const struct mptcp_addr_info *addr)
+{
+   struct mptcp_addr_info zero;
+
+   memset(, 0, sizeof(zero));
+   zero.family = addr->family;
+
+   if (addresses_equal(addr, , false))
+   return true;
+
+   return false;
+}
+
 static void local_address(const struct sock_common *skc,
  struct mptcp_addr_info *addr)
 {
@@ -323,10 +336,13 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, 
struct sock_common *skc)
 * addr
 */
local_address((struct sock_common *)msk, _local);
-   local_address((struct sock_common *)msk, _local);
+   local_address((struct sock_common *)skc, _local);
if (addresses_equal(_local, _local, false))
return 0;
 
+   if (address_zero(_local))
+   return 0;
+
pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
 
rcu_read_lock();
-- 
2.17.1



[PATCH net-next] mptcp: use mptcp_for_each_subflow in mptcp_stream_accept

2020-08-03 Thread Geliang Tang
Use mptcp_for_each_subflow in mptcp_stream_accept instead of
open-coding.

Signed-off-by: Geliang Tang 
---
 net/mptcp/protocol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d3fe7296e1c9..400824eabf73 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2249,7 +2249,7 @@ static int mptcp_stream_accept(struct socket *sock, 
struct socket *newsock,
 * This is needed so NOSPACE flag can be set from tcp stack.
 */
__mptcp_flush_join_list(msk);
-   list_for_each_entry(subflow, >conn_list, node) {
+   mptcp_for_each_subflow(msk, subflow) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 
if (!ssk->sk_socket)
-- 
2.17.1



[PATCH net-next] liquidio: use list_empty_careful in lio_list_delete_head

2020-06-28 Thread Geliang Tang
Use list_empty_careful() instead of open-coding.

Signed-off-by: Geliang Tang 
---
 drivers/net/ethernet/cavium/liquidio/octeon_network.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_network.h 
b/drivers/net/ethernet/cavium/liquidio/octeon_network.h
index 50201fc86dcf..ebe56bd8849b 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_network.h
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_network.h
@@ -612,7 +612,7 @@ static inline struct list_head *lio_list_delete_head(struct 
list_head *root)
 {
struct list_head *node;
 
-   if (root->prev == root && root->next == root)
+   if (list_empty_careful(root))
node = NULL;
else
node = root->next;
-- 
2.17.1



[PATCH net-next] sctp: use list_is_singular in sctp_list_single_entry

2020-06-28 Thread Geliang Tang
Use list_is_singular() instead of open-coding.

Signed-off-by: Geliang Tang 
---
 include/net/sctp/sctp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index f8bcb75bb044..e3bd198b00ae 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -412,7 +412,7 @@ static inline void sctp_skb_set_owner_r(struct sk_buff 
*skb, struct sock *sk)
 /* Tests if the list has one and only one entry. */
 static inline int sctp_list_single_entry(struct list_head *head)
 {
-   return (head->next != head) && (head->next == head->prev);
+   return list_is_singular(head);
 }
 
 static inline bool sctp_chunk_pending(const struct sctp_chunk *chunk)
-- 
2.17.1



[PATCH net v2] mptcp: drop sndr_key in mptcp_syn_options

2020-06-22 Thread Geliang Tang
In RFC 8684, we don't need to send sndr_key in SYN package anymore, so drop
it.

Fixes: cc7972ea1932 ("mptcp: parse and emit MP_CAPABLE option according to v1 
spec")
Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 490b92534afc..df9a51425c6f 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -336,9 +336,7 @@ bool mptcp_syn_options(struct sock *sk, const struct 
sk_buff *skb,
 */
subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
if (subflow->request_mptcp) {
-   pr_debug("local_key=%llu", subflow->local_key);
opts->suboptions = OPTION_MPTCP_MPC_SYN;
-   opts->sndr_key = subflow->local_key;
*size = TCPOLEN_MPTCP_MPC_SYN;
return true;
} else if (subflow->request_join) {
-- 
2.17.1



Re: [PATCH net-next 0/3] add MP_PRIO, MP_FAIL and MP_FASTCLOSE suboptions handling

2020-06-18 Thread Geliang Tang
On Tue, Jun 16, 2020 at 05:18:56PM +0200, Matthieu Baerts wrote:
> Hi Geliang
> 
> On 16/06/2020 08:47, Geliang Tang wrote:
> > Add handling for sending and receiving the MP_PRIO, MP_FAIL, and
> > MP_FASTCLOSE suboptions.
> 
> Thank you for the patches!
> 
> Unfortunately, I don't think it would be wise to accept them now: for the
> moment, these suboptions are ignored at the reception. If we accept them and
> change some variables like you did, we would need to make sure the kernel is
> still acting correctly. In other words, we would need tests:
> * For MP_PRIO, there are still quite some works to do regarding the
> scheduling of the packets between the different MPTCP subflows to do before
> supporting this.
> * For MP_FAIL, we should forward the info to the path manager.
> * For MP_FASTCLOSE, we should close connections and ACK this.
> 
> Also, net-next is closed for the moment:
> http://vger.kernel.org/~davem/net-next.html
> 
> I would suggest you to discuss about that on MPTCP mailing list. We also
> have meetings every Thursday. New devs are always welcome to contribute to
> new features and bug-fixes!
> 

Hi Matt,

Thanks for your reply. I will do these tests and improve my patches.

-Geliang

> Cheers,
> Matt
> -- 
> Tessares | Belgium | Hybrid Access Solutions
> www.tessares.net


[PATCH net-next 3/3] mptcp: add MP_FASTCLOSE suboption handling

2020-06-16 Thread Geliang Tang
Add handling for sending and receiving MP_FASTCLOSE suboption.

Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c  | 16 
 net/mptcp/protocol.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 82b3d7c566b4..a99b3989fec1 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -297,6 +297,15 @@ static void mptcp_parse_option(const struct sk_buff *skb,
pr_debug("MP_FAIL: data_seq=%lld", mp_opt->data_seq);
break;
 
+   case MPTCPOPT_MP_FASTCLOSE:
+   if (opsize != TCPOLEN_MPTCP_FASTCLOSE)
+   break;
+
+   ptr += 2;
+   mp_opt->rcvr_key = get_unaligned_be64(ptr);
+   pr_debug("MP_FASTCLOSE: rcvr_key=%lld", mp_opt->rcvr_key);
+   break;
+
default:
break;
}
@@ -993,6 +1002,13 @@ void mptcp_write_options(__be32 *ptr, struct 
mptcp_out_options *opts)
put_unaligned_be64(mpext->data_seq, ptr);
}
 
+   if (OPTION_MPTCP_FASTCLOSE & opts->suboptions) {
+   *ptr++ = mptcp_option(MPTCPOPT_MP_FASTCLOSE,
+ TCPOLEN_MPTCP_FASTCLOSE,
+ 0, 0);
+   put_unaligned_be64(opts->rcvr_key, ptr);
+   }
+
if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
  TCPOLEN_MPTCP_MPJ_SYN,
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index e6ae0a73716b..a8faab61e7af 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -25,6 +25,7 @@
 #define OPTION_MPTCP_RM_ADDR   BIT(8)
 #define OPTION_MPTCP_PRIO  BIT(9)
 #define OPTION_MPTCP_FAIL  BIT(10)
+#define OPTION_MPTCP_FASTCLOSE BIT(11)
 
 /* MPTCP option subtypes */
 #define MPTCPOPT_MP_CAPABLE0
@@ -62,6 +63,7 @@
 #define TCPOLEN_MPTCP_RM_ADDR_BASE 4
 #define TCPOLEN_MPTCP_PRIO 3
 #define TCPOLEN_MPTCP_FAIL 12
+#define TCPOLEN_MPTCP_FASTCLOSE12
 
 /* MPTCP MP_JOIN flags */
 #define MPTCPOPT_BACKUPBIT(0)
-- 
2.17.1



[PATCH net-next 2/3] mptcp: add MP_FAIL suboption handling

2020-06-16 Thread Geliang Tang
Add handling for sending and receiving MP_FAIL suboption.

Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c  | 18 ++
 net/mptcp/protocol.h |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index cc3039f0ac43..82b3d7c566b4 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -288,6 +288,15 @@ static void mptcp_parse_option(const struct sk_buff *skb,
pr_debug("MP_PRIO: backup=%d", mp_opt->backup);
break;
 
+   case MPTCPOPT_MP_FAIL:
+   if (opsize != TCPOLEN_MPTCP_FAIL)
+   break;
+
+   ptr += 2;
+   mp_opt->data_seq = get_unaligned_be64(ptr);
+   pr_debug("MP_FAIL: data_seq=%lld", mp_opt->data_seq);
+   break;
+
default:
break;
}
@@ -975,6 +984,15 @@ void mptcp_write_options(__be32 *ptr, struct 
mptcp_out_options *opts)
  opts->backup, 0);
}
 
+   if (OPTION_MPTCP_FAIL & opts->suboptions) {
+   struct mptcp_ext *mpext = >ext_copy;
+
+   *ptr++ = mptcp_option(MPTCPOPT_MP_FAIL,
+ TCPOLEN_MPTCP_FAIL,
+ 0, 0);
+   put_unaligned_be64(mpext->data_seq, ptr);
+   }
+
if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
  TCPOLEN_MPTCP_MPJ_SYN,
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 623c9a1c4343..e6ae0a73716b 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -24,6 +24,7 @@
 #define OPTION_MPTCP_ADD_ADDR6 BIT(7)
 #define OPTION_MPTCP_RM_ADDR   BIT(8)
 #define OPTION_MPTCP_PRIO  BIT(9)
+#define OPTION_MPTCP_FAIL  BIT(10)
 
 /* MPTCP option subtypes */
 #define MPTCPOPT_MP_CAPABLE0
@@ -60,6 +61,7 @@
 #define TCPOLEN_MPTCP_PORT_LEN 2
 #define TCPOLEN_MPTCP_RM_ADDR_BASE 4
 #define TCPOLEN_MPTCP_PRIO 3
+#define TCPOLEN_MPTCP_FAIL 12
 
 /* MPTCP MP_JOIN flags */
 #define MPTCPOPT_BACKUPBIT(0)
-- 
2.17.1



[PATCH net-next 1/3] mptcp: add MP_PRIO suboption handling

2020-06-16 Thread Geliang Tang
Add handling for sending and receiving MP_PRIO suboption.

Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c  | 14 ++
 net/mptcp/protocol.h |  5 +
 2 files changed, 19 insertions(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 490b92534afc..cc3039f0ac43 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -280,6 +280,14 @@ static void mptcp_parse_option(const struct sk_buff *skb,
pr_debug("RM_ADDR: id=%d", mp_opt->rm_id);
break;
 
+   case MPTCPOPT_MP_PRIO:
+   if (opsize != TCPOLEN_MPTCP_PRIO)
+   break;
+
+   mp_opt->backup = (*ptr++) & MPTCP_PRIO_BACKUP;
+   pr_debug("MP_PRIO: backup=%d", mp_opt->backup);
+   break;
+
default:
break;
}
@@ -961,6 +969,12 @@ void mptcp_write_options(__be32 *ptr, struct 
mptcp_out_options *opts)
  0, opts->rm_id);
}
 
+   if (OPTION_MPTCP_PRIO & opts->suboptions) {
+   *ptr++ = mptcp_option(MPTCPOPT_MP_PRIO,
+ TCPOLEN_MPTCP_PRIO,
+ opts->backup, 0);
+   }
+
if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
  TCPOLEN_MPTCP_MPJ_SYN,
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index db56535dfc29..623c9a1c4343 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -23,6 +23,7 @@
 #define OPTION_MPTCP_ADD_ADDR  BIT(6)
 #define OPTION_MPTCP_ADD_ADDR6 BIT(7)
 #define OPTION_MPTCP_RM_ADDR   BIT(8)
+#define OPTION_MPTCP_PRIO  BIT(9)
 
 /* MPTCP option subtypes */
 #define MPTCPOPT_MP_CAPABLE0
@@ -58,6 +59,7 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT  22
 #define TCPOLEN_MPTCP_PORT_LEN 2
 #define TCPOLEN_MPTCP_RM_ADDR_BASE 4
+#define TCPOLEN_MPTCP_PRIO 3
 
 /* MPTCP MP_JOIN flags */
 #define MPTCPOPT_BACKUPBIT(0)
@@ -84,6 +86,9 @@
 #define MPTCP_ADDR_IPVERSION_4 4
 #define MPTCP_ADDR_IPVERSION_6 6
 
+/* MPTCP MP_PRIO flags */
+#define MPTCP_PRIO_BACKUP  BIT(0)
+
 /* MPTCP socket flags */
 #define MPTCP_DATA_READY   0
 #define MPTCP_SEND_SPACE   1
-- 
2.17.1



[PATCH net-next 0/3] add MP_PRIO, MP_FAIL and MP_FASTCLOSE suboptions handling

2020-06-16 Thread Geliang Tang
Add handling for sending and receiving the MP_PRIO, MP_FAIL, and
MP_FASTCLOSE suboptions.

Geliang Tang (3):
  mptcp: add MP_PRIO suboption handling
  mptcp: add MP_FAIL suboption handling
  mptcp: add MP_FASTCLOSE suboption handling

 net/mptcp/options.c  | 48 
 net/mptcp/protocol.h |  9 +
 2 files changed, 57 insertions(+)

-- 
2.17.1



Re: [PATCH] mptcp: use list_first_entry_or_null

2020-06-15 Thread Geliang Tang
On Fri, Jun 12, 2020 at 11:22:31AM -0700, Mat Martineau wrote:
> 
> Hello Geliang,
> 
> On Fri, 12 Jun 2020, Geliang Tang wrote:
> 
> > Use list_first_entry_or_null to simplify the code.
> > 
> > Signed-off-by: Geliang Tang 
> > ---
> > net/mptcp/protocol.h | 5 +
> > 1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> > index 86d265500cf6..55c65abcad64 100644
> > --- a/net/mptcp/protocol.h
> > +++ b/net/mptcp/protocol.h
> > @@ -234,10 +234,7 @@ static inline struct mptcp_data_frag 
> > *mptcp_rtx_head(const struct sock *sk)
> > {
> > struct mptcp_sock *msk = mptcp_sk(sk);
> > 
> > -   if (list_empty(>rtx_queue))
> > -   return NULL;
> > -
> > -   return list_first_entry(>rtx_queue, struct mptcp_data_frag, list);
> > +   return list_first_entry_or_null(>rtx_queue, struct 
> > mptcp_data_frag, list);
> > }
> > 
> > struct mptcp_subflow_request_sock {
> > -- 
> > 2.17.1
> 
> As Matthieu mentioned on your earlier patch, please submit patches to netdev
> with either a [PATCH net] or [PATCH net-next] tag. In this case, these are
> non-critical bug fixes so they should be targeted at net-next.
> 
> Note that net-next branch is currently closed to submissions due to the v5.8
> merge window. Please resubmit both MPTCP patches for net-next when David
> announces that it is open again. The change does look ok but will not be
> merged now.
> 
> Thanks for your patch,
> 
> --
> Mat Martineau
> Intel

Hi Mat,

Thanks for your reply.
I have already resend patch v2 to you.

-Geliang


Re: [PATCH] mptcp: unify MPTCP_PM_MAX_ADDR and MPTCP_PM_ADDR_MAX

2020-06-15 Thread Geliang Tang
On Fri, Jun 12, 2020 at 07:33:11PM +0200, Matthieu Baerts wrote:
> Hi Geliang,
> 
> On 12/06/2020 07:27, Geliang Tang wrote:
> > Unify these two duplicate macros into 8.
> 
> Thank you for this new patch!
> 
> (...)
> 
> > diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> > index 809687d3f410..86d265500cf6 100644
> > --- a/net/mptcp/protocol.h
> > +++ b/net/mptcp/protocol.h
> > @@ -135,7 +135,7 @@ static inline __be32 mptcp_option(u8 subopt, u8 len, u8 
> > nib, u8 field)
> >  ((nib & 0xF) << 8) | field);
> >   }
> > -#define MPTCP_PM_MAX_ADDR  4
> > +#define MPTCP_PM_ADDR_MAX  8
> 
> I think it would be better to drop MPTCP_PM_MAX_ADDR and keep
> MPTCP_PM_ADDR_MAX in pm_netlink.c where it is used. Each PM can decide
> what's the maximum number of addresses it can support.
> 
> MPTCP_PM_MAX_ADDR seems to be a left over from a previous implementation of
> a PM that has not been upstreamed but replaced by the Netlink PM later.
> 
> Also, please always add "net" or "net-next" prefix in the subject of your
> email to help -net maintainers. Do not hesitate to look at the netdev FAQ
> for more details.
> 
> Here this patch looks like a fix so you should have [PATCH net] and a
> "Fixes" tag. I guess for this patch you can use:
> 
>   Fixes: 1b1c7a0ef7f3 ("mptcp: Add path manager interface")
> 
> That's where MPTCP_PM_MAX_ADDR has been introduced. It was already not used
> and never used later.
> 
> Cheers,
> Matt
> -- 
> Tessares | Belgium | Hybrid Access Solutions
> www.tessares.net

Hi Matt,

Thanks for your reply.
I have already resend patch v2 to you.

-Geliang


[PATCH net-next v2] mptcp: use list_first_entry_or_null

2020-06-15 Thread Geliang Tang
Use list_first_entry_or_null to simplify the code.

Signed-off-by: Geliang Tang 
---
 Changes in v2:
  - Add "net-next" tag in Subject.
---
 net/mptcp/protocol.h | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 70ed698bd206..db56535dfc29 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -232,10 +232,7 @@ static inline struct mptcp_data_frag *mptcp_rtx_head(const 
struct sock *sk)
 {
struct mptcp_sock *msk = mptcp_sk(sk);
 
-   if (list_empty(>rtx_queue))
-   return NULL;
-
-   return list_first_entry(>rtx_queue, struct mptcp_data_frag, list);
+   return list_first_entry_or_null(>rtx_queue, struct 
mptcp_data_frag, list);
 }
 
 struct mptcp_subflow_request_sock {
-- 
2.17.1



[PATCH net v2] mptcp: drop MPTCP_PM_MAX_ADDR

2020-06-15 Thread Geliang Tang
We have defined MPTCP_PM_ADDR_MAX in pm_netlink.c, so drop this duplicate macro.

Fixes: 1b1c7a0ef7f3 ("mptcp: Add path manager interface")
Signed-off-by: Geliang Tang 
---
 Changes in v2:
  - change Subject from "mptcp: unify MPTCP_PM_MAX_ADDR and MPTCP_PM_ADDR_MAX"
---
 net/mptcp/protocol.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 809687d3f410..70ed698bd206 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -135,8 +135,6 @@ static inline __be32 mptcp_option(u8 subopt, u8 len, u8 
nib, u8 field)
 ((nib & 0xF) << 8) | field);
 }
 
-#define MPTCP_PM_MAX_ADDR  4
-
 struct mptcp_addr_info {
sa_family_t family;
__be16  port;
-- 
2.17.1



[PATCH] mptcp: use list_first_entry_or_null

2020-06-12 Thread Geliang Tang
Use list_first_entry_or_null to simplify the code.

Signed-off-by: Geliang Tang 
---
 net/mptcp/protocol.h | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 86d265500cf6..55c65abcad64 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -234,10 +234,7 @@ static inline struct mptcp_data_frag *mptcp_rtx_head(const 
struct sock *sk)
 {
struct mptcp_sock *msk = mptcp_sk(sk);
 
-   if (list_empty(>rtx_queue))
-   return NULL;
-
-   return list_first_entry(>rtx_queue, struct mptcp_data_frag, list);
+   return list_first_entry_or_null(>rtx_queue, struct 
mptcp_data_frag, list);
 }
 
 struct mptcp_subflow_request_sock {
-- 
2.17.1



[PATCH] mptcp: unify MPTCP_PM_MAX_ADDR and MPTCP_PM_ADDR_MAX

2020-06-11 Thread Geliang Tang
Unify these two duplicate macros into 8.

Signed-off-by: Geliang Tang 
---
 net/mptcp/pm_netlink.c | 2 --
 net/mptcp/protocol.h   | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index b78edf237ba0..b694f13caba8 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -41,8 +41,6 @@ struct pm_nl_pernet {
unsigned intnext_id;
 };
 
-#define MPTCP_PM_ADDR_MAX  8
-
 static bool addresses_equal(const struct mptcp_addr_info *a,
struct mptcp_addr_info *b, bool use_port)
 {
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 809687d3f410..86d265500cf6 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -135,7 +135,7 @@ static inline __be32 mptcp_option(u8 subopt, u8 len, u8 
nib, u8 field)
 ((nib & 0xF) << 8) | field);
 }
 
-#define MPTCP_PM_MAX_ADDR  4
+#define MPTCP_PM_ADDR_MAX  8
 
 struct mptcp_addr_info {
sa_family_t family;
-- 
2.17.1



Re: [PATCH] mptcp: bugfix for RM_ADDR option parsing

2020-06-08 Thread Geliang Tang
On Mon, Jun 08, 2020 at 12:10:23PM +0200, Matthieu Baerts wrote:
> Hi Geliang,
> 
> On 08/06/2020 09:48, Geliang Tang wrote:
> > In MPTCPOPT_RM_ADDR option parsing, the pointer "ptr" pointed to the
> > "Subtype" octet, the pointer "ptr+1" pointed to the "Address ID" octet:
> > 
> >+---+---+---+
> >|Subtype|(resvd)|   Address ID  |
> >+---+---+---+
> >|   |
> >   ptrptr+1
> > 
> > We should set mp_opt->rm_id to the value of "ptr+1", not "ptr". This patch
> > will fix this bug.
> 
> Thank you for the patch, good catch!
> Indeed "ptr" should be incremented.
> 
> Because this is a bug-fix for net, may you clearly indicate that in the
> subject to help -net maintainers please? [PATCH net v2]
> 
> Also, may you add a "Fixes" tag as well as it is for -net ? I guess it
> should be:
> 
> Fixes: 3df523ab582c ("mptcp: Add ADD_ADDR handling")
> 
> The rest is good!
> 
> Cheers,
> Matt
> -- 
> Matthieu Baerts | R Engineer
> matthieu.bae...@tessares.net
> Tessares SA | Hybrid Access Solutions
> www.tessares.net
> 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium

Hi Matt,

Thanks for your reply.

I have already resend patch v2 to you.

-Geliang


[PATCH net v2] mptcp: bugfix for RM_ADDR option parsing

2020-06-08 Thread Geliang Tang
In MPTCPOPT_RM_ADDR option parsing, the pointer "ptr" pointed to the
"Subtype" octet, the pointer "ptr+1" pointed to the "Address ID" octet:

  +---+---+---+
  |Subtype|(resvd)|   Address ID  |
  +---+---+---+
  |   |
 ptrptr+1

We should set mp_opt->rm_id to the value of "ptr+1", not "ptr". This patch
will fix this bug.

Fixes: 3df523ab582c ("mptcp: Add ADD_ADDR handling")
Signed-off-by: Geliang Tang 
---
 Changes in v2:
  - Add "-net" subject and "Fixes" tag as Matt suggested.
---
 net/mptcp/options.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 01f1f4cf4902..490b92534afc 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -273,6 +273,8 @@ static void mptcp_parse_option(const struct sk_buff *skb,
if (opsize != TCPOLEN_MPTCP_RM_ADDR_BASE)
break;
 
+   ptr++;
+
mp_opt->rm_addr = 1;
mp_opt->rm_id = *ptr++;
pr_debug("RM_ADDR: id=%d", mp_opt->rm_id);
-- 
2.17.1



[PATCH] mptcp: bugfix for RM_ADDR option parsing

2020-06-08 Thread Geliang Tang
In MPTCPOPT_RM_ADDR option parsing, the pointer "ptr" pointed to the
"Subtype" octet, the pointer "ptr+1" pointed to the "Address ID" octet:

  +---+---+---+
  |Subtype|(resvd)|   Address ID  |
  +---+---+---+
  |   |
 ptrptr+1

We should set mp_opt->rm_id to the value of "ptr+1", not "ptr". This patch
will fix this bug.

Signed-off-by: Geliang Tang 
---
 net/mptcp/options.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 01f1f4cf4902..490b92534afc 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -273,6 +273,8 @@ static void mptcp_parse_option(const struct sk_buff *skb,
if (opsize != TCPOLEN_MPTCP_RM_ADDR_BASE)
break;
 
+   ptr++;
+
mp_opt->rm_addr = 1;
mp_opt->rm_id = *ptr++;
pr_debug("RM_ADDR: id=%d", mp_opt->rm_id);
-- 
2.17.1



Re: [PATCH] bcache: use kmemdup_nul for CACHED_LABEL buffer

2019-02-26 Thread Geliang Tang
On Wed, Feb 06, 2019 at 04:37:36PM +0800, Coly Li wrote:
> On 2019/1/30 5:29 下午, Geliang Tang wrote:
> > This patch uses kmemdup_nul to create a NUL-terminated string from
> > dc->sb.label. This is better than open coding it.
> > 
> > With this, we can move env[2] initialization into env[] array to make
> > code more elegant.
> > 
> > Signed-off-by: Geliang Tang 
> 
> Hi Geliang,
> 
> In general I am OK with your idea. But I feel there might be some
> regression with your change. I comment your patch in line, correct me if
> I am wrong.
> 
> 
> > ---
> >  drivers/md/bcache/super.c | 10 --
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> > index 4dee119c3664..84ab241c8516 100644
> > --- a/drivers/md/bcache/super.c
> > +++ b/drivers/md/bcache/super.c
> > @@ -906,21 +906,18 @@ static int cached_dev_status_update(void *arg)
> >  void bch_cached_dev_run(struct cached_dev *dc)
> >  {
> > struct bcache_device *d = >disk;
> > -   char buf[SB_LABEL_SIZE + 1];
> > +   char *buf = kmemdup_nul(dc->sb.label, SB_LABEL_SIZE, GFP_KERNEL);
> 
> If kdumdup_null() is failed, buf will be NULL.
> 
> > char *env[] = {
> > "DRIVER=bcache",
> > kasprintf(GFP_KERNEL, "CACHED_UUID=%pU", dc->sb.uuid),
> > -   NULL,
> > +   kasprintf(GFP_KERNEL, "CACHED_LABEL=%s", buf ? : ""),
> 
> If buf is NULL, env[2] here is pointed to "" which is allocated in
> read-only data segment, and not a dynamic memory.

Hi Coly,

Sorry for my late reply.

If buf is NULL, env[2] is kasprintf(GFP_KERNEL, "CACHED_LABEL=%s", "");
In this case, env[2] is also a dynamic memory, a string like this, 
"CACHED_LABEL=".
So we can use kfree() to free it. There is no problem.

And here is a test case:

$ cat test.c 
#include 
#include 
#include 

static int __init test_init(void)
{
char *env = kasprintf(GFP_KERNEL, "CACHED_LABEL=%s", "");
pr_info("env = [%s]\n", env);
kfree(env);
return 0;
}

static void __exit test_exit(void)
{
}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");

$ sudo insmod test.ko
$ dmesg
[ 3026.072298] env = [CACHED_LABEL=]
$ sudo rmmod test

Thanks.

-Geliang

> 
> > NULL,
> > };
> >  
> > -   memcpy(buf, dc->sb.label, SB_LABEL_SIZE);
> > -   buf[SB_LABEL_SIZE] = '\0';
> > -   env[2] = kasprintf(GFP_KERNEL, "CACHED_LABEL=%s", buf);
> > -
> > if (atomic_xchg(>running, 1)) {
> > kfree(env[1]);
> > kfree(env[2]);
> 
> Then kfree() here will try to release a read-only memory segment. I
> guess this is problematic.
> 
> > +   kfree(buf);
> > return;
> > }
> >  
> > @@ -944,6 +941,7 @@ void bch_cached_dev_run(struct cached_dev *dc)
> > kobject_uevent_env(_to_dev(d->disk)->kobj, KOBJ_CHANGE, env);
> > kfree(env[1]);
> > kfree(env[2]);
> 
> Same problem might happen here for env[2].
> 
> > +   kfree(buf);
> >  
> > if (sysfs_create_link(>kobj, _to_dev(d->disk)->kobj, "dev") ||
> > sysfs_create_link(_to_dev(d->disk)->kobj, >kobj, "bcache"))
> > 
> 
> 
> -- 
> 
> Coly Li



Re: [PATCH] security: keys: add NULL checking for key->type->instantiate

2019-02-26 Thread Geliang Tang
On Wed, Feb 06, 2019 at 10:26:53PM +, David Howells wrote:
> Geliang Tang  wrote:
> 
> > key->type->instantiate can be NULL, add NULL checking to prevent
> > NULL pointer dereference in __key_instantiate_and_link().
> 
> Do you have an oops report or test case for this?
> 
> David

Here is the test module code. Insmod it, we can get the oops.

#include 
#include 
#include 
#include 
#include 
#include 

static int test_instantiate(struct key *key, struct key_preparsed_payload *prep)
{
return 0;
}

static void test_describe(const struct key *key, struct seq_file *m)
{
seq_puts(m, key->description);
}

struct key_type test_key_type = {
.name   = "test",
//.instantiate  = test_instantiate,
.describe   = test_describe,
};

static int __init test_init(void)
{
const struct cred *cred = current_cred();
struct key *key;
int ret;

register_key_type(_key_type);

key = key_alloc(_key_type, "test",
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, cred,
KEY_POS_SEARCH, KEY_ALLOC_NOT_IN_QUOTA, NULL);
if (IS_ERR(key))
return -1;

pr_info("keyring allocated successfully.\n");

ret = key_instantiate_and_link(key,
   NULL,
   sizeof(int),
   current->cred->user->session_keyring,
   NULL);
if (ret < 0) {
key_revoke(key);
key_put(key);
return ret;
}

return 0;
}

static void __exit test_exit(void)
{
unregister_key_type(_key_type);
}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");


Re: [PATCH] security: keys: add NULL checking for key->type->instantiate

2019-02-26 Thread Geliang Tang
On Wed, Feb 06, 2019 at 10:26:53PM +, David Howells wrote:
> Geliang Tang  wrote:
> 
> > key->type->instantiate can be NULL, add NULL checking to prevent
> > NULL pointer dereference in __key_instantiate_and_link().
> 
> Do you have an oops report or test case for this?
> 
> David

Here is the test module code. Insmod it, we can get the oops.

#include 
#include 
#include 
#include 
#include 
#include 

static int test_instantiate(struct key *key, struct key_preparsed_payload *prep)
{
return 0;
}

static void test_describe(const struct key *key, struct seq_file *m)
{
seq_puts(m, key->description);
}

struct key_type test_key_type = {
.name   = "test",
//.instantiate  = test_instantiate,
.describe   = test_describe,
};

static int __init test_init(void)
{
const struct cred *cred = current_cred();
struct key *key;
int ret;

register_key_type(_key_type);

key = key_alloc(_key_type, "test",
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, cred,
KEY_POS_SEARCH, KEY_ALLOC_NOT_IN_QUOTA, NULL);
if (IS_ERR(key))
return -1;

pr_info("keyring allocated successfully.\n");

ret = key_instantiate_and_link(key,
   NULL,
   sizeof(int),
   current->cred->user->session_keyring,
   NULL);
if (ret < 0) {
key_revoke(key);
key_put(key);
return ret;
}

return 0;
}

static void __exit test_exit(void)
{
unregister_key_type(_key_type);
}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");


[PATCH] tcp: fix __tcp_transmit_skb's comment text

2019-02-26 Thread Geliang Tang
The function name tcp_do_sendmsg has been renamed. But it still
appears in __tcp_transmit_skb's comment text. This patch changes
it to tcp_sendmsg_locked.

Signed-off-by: Geliang Tang 
---
 net/ipv4/tcp_output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index e72aa0ff5785..67a43b966b8a 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1003,7 +1003,7 @@ static void tcp_update_skb_after_send(struct sock *sk, 
struct sk_buff *skb,
 }
 
 /* This routine actually transmits TCP packets queued in by
- * tcp_do_sendmsg().  This is used by both the initial
+ * tcp_sendmsg_locked().  This is used by both the initial
  * transmission and possible later retransmissions.
  * All SKB's seen here are completely headerless.  It is our
  * job to build the TCP header, and pass the packet down to
-- 
2.17.1



[PATCH] bcache: use kmemdup_nul for CACHED_LABEL buffer

2019-01-30 Thread Geliang Tang
This patch uses kmemdup_nul to create a NUL-terminated string from
dc->sb.label. This is better than open coding it.

With this, we can move env[2] initialization into env[] array to make
code more elegant.

Signed-off-by: Geliang Tang 
---
 drivers/md/bcache/super.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 4dee119c3664..84ab241c8516 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -906,21 +906,18 @@ static int cached_dev_status_update(void *arg)
 void bch_cached_dev_run(struct cached_dev *dc)
 {
struct bcache_device *d = >disk;
-   char buf[SB_LABEL_SIZE + 1];
+   char *buf = kmemdup_nul(dc->sb.label, SB_LABEL_SIZE, GFP_KERNEL);
char *env[] = {
"DRIVER=bcache",
kasprintf(GFP_KERNEL, "CACHED_UUID=%pU", dc->sb.uuid),
-   NULL,
+   kasprintf(GFP_KERNEL, "CACHED_LABEL=%s", buf ? : ""),
NULL,
};
 
-   memcpy(buf, dc->sb.label, SB_LABEL_SIZE);
-   buf[SB_LABEL_SIZE] = '\0';
-   env[2] = kasprintf(GFP_KERNEL, "CACHED_LABEL=%s", buf);
-
if (atomic_xchg(>running, 1)) {
kfree(env[1]);
kfree(env[2]);
+   kfree(buf);
return;
}
 
@@ -944,6 +941,7 @@ void bch_cached_dev_run(struct cached_dev *dc)
kobject_uevent_env(_to_dev(d->disk)->kobj, KOBJ_CHANGE, env);
kfree(env[1]);
kfree(env[2]);
+   kfree(buf);
 
if (sysfs_create_link(>kobj, _to_dev(d->disk)->kobj, "dev") ||
sysfs_create_link(_to_dev(d->disk)->kobj, >kobj, "bcache"))
-- 
2.17.1



[PATCH v5 2/2] squashfs-tools: Add posix acl support

2019-01-25 Thread Geliang Tang
This patch adds posix acl (Access Control Lists) support to squashfs-tools.

Signed-off-by: Geliang Tang 
---
 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..8ef8291 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -64,6 +64,8 @@ static long long xattr_table_start;
  */
 struct prefix prefix_table[] = {
{ "user.", SQUASHFS_XATTR_USER },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_ACCESS },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_DEFAULT },
{ "trusted.", SQUASHFS_XATTR_TRUSTED },
{ "security.", SQUASHFS_XATTR_SECURITY },
{ "", -1 }
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index afca918..040035c 100644
--- a/squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h
@@ -122,11 +122,13 @@
 #define SQUASHFS_LSOCKET_TYPE  14
 
 /* Xattr types */
-#define SQUASHFS_XATTR_USER0
-#define SQUASHFS_XATTR_TRUSTED 1
-#define SQUASHFS_XATTR_SECURITY2
-#define SQUASHFS_XATTR_VALUE_OOL   256
-#define SQUASHFS_XATTR_PREFIX_MASK 0xff
+#define SQUASHFS_XATTR_USER0
+#define SQUASHFS_XATTR_POSIX_ACL_ACCESS1
+#define SQUASHFS_XATTR_POSIX_ACL_DEFAULT   2
+#define SQUASHFS_XATTR_TRUSTED 3
+#define SQUASHFS_XATTR_SECURITY4
+#define SQUASHFS_XATTR_VALUE_OOL   256
+#define SQUASHFS_XATTR_PREFIX_MASK 0xff
 
 /* Flag whether block is compressed or uncompressed, bit is set if block is
  * uncompressed */
-- 
2.17.1



[PATCH v5 1/2] squashfs: Add posix acl support

2019-01-25 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs documentation.  This patch implements
a squashfs_get_acl function to read the file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang 
---
Changes in v5:
  - add SPDX lines.
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 +
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 56 ++
 fs/squashfs/acl.h  | 18 +
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++---
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +-
 fs/squashfs/xattr.h|  8 
 12 files changed, 145 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..f9719ed30dad
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2019
+ * Geliang Tang 
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int ret;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   ret = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (ret > 0) {
+   value = kmalloc(ret, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   ret = squashfs_xattr_get(inode, name_index, name, value, ret);
+   }
+   if (ret > 0)
+   acl = posix_acl_from_xattr(_user_ns, value, ret);
+   else if (ret == -ENODATA || ret == -ENOSYS)
+   acl = NULL;
+   else
+   acl = ERR_PTR(ret);
+
+   kfree(value);
+
+   return acl;
+}
diff --git a/fs/squashfs/acl.h b/fs/squashfs/acl.h
new file mode 100644
index ..e7806c5fbc44
--- /dev/null
+++ b/fs/squashfs/acl.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2019
+ * Geliang Tang 
+ *
+ * acl.h
+ */
+
+#include 
+#include 
+
+#ifdef CONFIG_SQUASHFS_POSIX_ACL
+extern struct posix_acl *squashfs_get_acl(struct inode *inode, int type);
+#else
+#define squashfs_get_acl   NULL
+#endi

[PATCH v5 0/2] squashfs/squashfs-tools: Add posix acl support

2019-01-25 Thread Geliang Tang
When we use mksquashfs tool to create a squashfs image from the files which
have POSIX ACLs(Access Control Lists), we get these errors:

Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_default

This patcheset adds posix acl support to squashfs to fix this problem. Patch
#1 for kerenl tree and patch #2 for squashfs-tools tree.

---

Testcase:

$ mkdir root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  group::r-x
  other::r-x
$ setfacl -m u:tgl:rw root
$ setfacl -m d:tgl:rw root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d root
  # file: root
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

$ mksquashfs root root.img
$ sudo mount root.img /mnt/squash/

$ cd /mnt
$ getfacl squash
  # file: squash
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d squash
  # file: squash
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

---

Geliang Tang (1):
  squashfs: Add posix acl support

 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 +
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 56 ++
 fs/squashfs/acl.h  | 18 +
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++---
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +-
 fs/squashfs/xattr.h|  8 
 12 files changed, 145 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

---

Geliang Tang (1):
  squashfs-tools: Add posix acl support

 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

-- 
2.17.1



[PATCH v4 1/2] squashfs: Add posix acl support

2019-01-25 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs documentation.  This patch implements
a squashfs_get_acl function to read the file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang 
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++--
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +++-
 fs/squashfs/xattr.h|  8 +++
 12 files changed, 171 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..0db28f5eacc6
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int ret;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   ret = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (ret > 0) {
+   value = kmalloc(ret, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   ret = squashfs_xattr_get(inode, name_index, name, value, ret);
+   }
+   if (ret > 0)
+   acl = posix_acl_from_xattr(_user_ns, value, ret);
+   else if (ret == -ENODATA || 

[PATCH v4 0/2] squashfs/squashfs-tools: Add posix acl support

2019-01-25 Thread Geliang Tang
When we use mksquashfs tool to create a squashfs image from the files which
have POSIX ACLs(Access Control Lists), we get these errors:

Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_default

This patcheset adds posix acl support to squashfs to fix this problem. Patch
#1 for kerenl tree and patch #2 for squashfs-tools tree.

---

Testcase:

$ mkdir root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  group::r-x
  other::r-x
$ setfacl -m u:tgl:rw root
$ setfacl -m d:tgl:rw root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d root
  # file: root
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

$ mksquashfs root root.img
$ sudo mount root.img /mnt/squash/

$ cd /mnt
$ getfacl squash
  # file: squash
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d squash
  # file: squash
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

---

Geliang Tang (1):
  squashfs: Add posix acl support

 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++--
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +++-
 fs/squashfs/xattr.h|  8 +++
 12 files changed, 171 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

---

Geliang Tang (1):
  squashfs-tools: Add posix acl support

 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

-- 
2.17.1



[PATCH v4 2/2] squashfs-tools: Add posix acl support

2019-01-25 Thread Geliang Tang
This patch adds posix acl (Access Control Lists) support to squashfs-tools.

Signed-off-by: Geliang Tang 
---
 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..8ef8291 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -64,6 +64,8 @@ static long long xattr_table_start;
  */
 struct prefix prefix_table[] = {
{ "user.", SQUASHFS_XATTR_USER },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_ACCESS },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_DEFAULT },
{ "trusted.", SQUASHFS_XATTR_TRUSTED },
{ "security.", SQUASHFS_XATTR_SECURITY },
{ "", -1 }
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index afca918..040035c 100644
--- a/squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h
@@ -122,11 +122,13 @@
 #define SQUASHFS_LSOCKET_TYPE  14
 
 /* Xattr types */
-#define SQUASHFS_XATTR_USER0
-#define SQUASHFS_XATTR_TRUSTED 1
-#define SQUASHFS_XATTR_SECURITY2
-#define SQUASHFS_XATTR_VALUE_OOL   256
-#define SQUASHFS_XATTR_PREFIX_MASK 0xff
+#define SQUASHFS_XATTR_USER0
+#define SQUASHFS_XATTR_POSIX_ACL_ACCESS1
+#define SQUASHFS_XATTR_POSIX_ACL_DEFAULT   2
+#define SQUASHFS_XATTR_TRUSTED 3
+#define SQUASHFS_XATTR_SECURITY4
+#define SQUASHFS_XATTR_VALUE_OOL   256
+#define SQUASHFS_XATTR_PREFIX_MASK 0xff
 
 /* Flag whether block is compressed or uncompressed, bit is set if block is
  * uncompressed */
-- 
2.17.1



[PATCH] f2fs: fix typos in code comments

2019-01-24 Thread Geliang Tang
lengh -> length

Signed-off-by: Geliang Tang 
---
 include/linux/f2fs_fs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index d7711048ef93..624b8a47d3c6 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -186,7 +186,7 @@ struct f2fs_orphan_block {
 struct f2fs_extent {
__le32 fofs;/* start file offset of the extent */
__le32 blk; /* start block address of the extent */
-   __le32 len; /* lengh of the extent */
+   __le32 len; /* length of the extent */
 } __packed;
 
 #define F2FS_NAME_LEN  255
@@ -511,7 +511,7 @@ typedef __le32  f2fs_hash_t;
 struct f2fs_dir_entry {
__le32 hash_code;   /* hash code of file name */
__le32 ino; /* inode number */
-   __le16 name_len;/* lengh of file name */
+   __le16 name_len;/* length of file name */
__u8 file_type; /* file type */
 } __packed;
 
-- 
2.17.1



[PATCH] security: keys: add NULL checking for key->type->instantiate

2019-01-24 Thread Geliang Tang
key->type->instantiate can be NULL, add NULL checking to prevent
NULL pointer dereference in __key_instantiate_and_link().

Signed-off-by: Geliang Tang 
---
 security/keys/key.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/security/keys/key.c b/security/keys/key.c
index 44a80d6741a1..ae3cc11be0d2 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -438,7 +438,8 @@ static int __key_instantiate_and_link(struct key *key,
/* can't instantiate twice */
if (key->state == KEY_IS_UNINSTANTIATED) {
/* instantiate the key */
-   ret = key->type->instantiate(key, prep);
+   if (key->type->instantiate)
+   ret = key->type->instantiate(key, prep);
 
if (ret == 0) {
/* mark the key as being instantiated */
-- 
2.17.1



[PATCH v3 2/2] squashfs-tools: Add posix acl support

2018-08-07 Thread Geliang Tang
This patch adds posix acl (Access Control Lists) support to squashfs-tools.

Signed-off-by: Geliang Tang 
---
 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..8ef8291 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -64,6 +64,8 @@ static long long xattr_table_start;
  */
 struct prefix prefix_table[] = {
{ "user.", SQUASHFS_XATTR_USER },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_ACCESS },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_DEFAULT },
{ "trusted.", SQUASHFS_XATTR_TRUSTED },
{ "security.", SQUASHFS_XATTR_SECURITY },
{ "", -1 }
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index afca918..040035c 100644
--- a/squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h
@@ -122,11 +122,13 @@
 #define SQUASHFS_LSOCKET_TYPE  14
 
 /* Xattr types */
-#define SQUASHFS_XATTR_USER0
-#define SQUASHFS_XATTR_TRUSTED 1
-#define SQUASHFS_XATTR_SECURITY2
-#define SQUASHFS_XATTR_VALUE_OOL   256
-#define SQUASHFS_XATTR_PREFIX_MASK 0xff
+#define SQUASHFS_XATTR_USER0
+#define SQUASHFS_XATTR_POSIX_ACL_ACCESS1
+#define SQUASHFS_XATTR_POSIX_ACL_DEFAULT   2
+#define SQUASHFS_XATTR_TRUSTED 3
+#define SQUASHFS_XATTR_SECURITY4
+#define SQUASHFS_XATTR_VALUE_OOL   256
+#define SQUASHFS_XATTR_PREFIX_MASK 0xff
 
 /* Flag whether block is compressed or uncompressed, bit is set if block is
  * uncompressed */
-- 
2.17.1



[PATCH v3 2/2] squashfs-tools: Add posix acl support

2018-08-07 Thread Geliang Tang
This patch adds posix acl (Access Control Lists) support to squashfs-tools.

Signed-off-by: Geliang Tang 
---
 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..8ef8291 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -64,6 +64,8 @@ static long long xattr_table_start;
  */
 struct prefix prefix_table[] = {
{ "user.", SQUASHFS_XATTR_USER },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_ACCESS },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_DEFAULT },
{ "trusted.", SQUASHFS_XATTR_TRUSTED },
{ "security.", SQUASHFS_XATTR_SECURITY },
{ "", -1 }
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index afca918..040035c 100644
--- a/squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h
@@ -122,11 +122,13 @@
 #define SQUASHFS_LSOCKET_TYPE  14
 
 /* Xattr types */
-#define SQUASHFS_XATTR_USER0
-#define SQUASHFS_XATTR_TRUSTED 1
-#define SQUASHFS_XATTR_SECURITY2
-#define SQUASHFS_XATTR_VALUE_OOL   256
-#define SQUASHFS_XATTR_PREFIX_MASK 0xff
+#define SQUASHFS_XATTR_USER0
+#define SQUASHFS_XATTR_POSIX_ACL_ACCESS1
+#define SQUASHFS_XATTR_POSIX_ACL_DEFAULT   2
+#define SQUASHFS_XATTR_TRUSTED 3
+#define SQUASHFS_XATTR_SECURITY4
+#define SQUASHFS_XATTR_VALUE_OOL   256
+#define SQUASHFS_XATTR_PREFIX_MASK 0xff
 
 /* Flag whether block is compressed or uncompressed, bit is set if block is
  * uncompressed */
-- 
2.17.1



[PATCH v3 1/2] squashfs: Add posix acl support

2018-08-07 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs documentation.  This patch implements
a squashfs_get_acl function to read the file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang 
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++--
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +++-
 fs/squashfs/xattr.h|  8 +++
 12 files changed, 171 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..1c9eb2d13c2b
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int retval;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   retval = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (retval > 0) {
+   value = kmalloc(retval, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   retval = squashfs_xattr_get(inode, name_index, name, value, 
retval);
+   }
+   if (retval > 0)
+   acl = posix_acl_from_xattr(_user_ns, value, retval);
+   else if (retv

[PATCH v3 0/2] squashfs/squashfs-tools: Add posix acl support

2018-08-07 Thread Geliang Tang
When we use mksquashfs tool to create a squashfs image from the files which
have POSIX ACLs(Access Control Lists), we get these errors:

Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_default

This patcheset adds posix acl support to squashfs to fix this problem. Patch
#1 for kerenl tree and patch #2 for squashfs-tools tree.

---

Testcase:

$ mkdir root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  group::r-x
  other::r-x
$ setfacl -m u:tgl:rw root
$ setfacl -m d:tgl:rw root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d root
  # file: root
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

$ mksquashfs root root.img
$ sudo mount root.img /mnt/squash/

$ cd /mnt
$ getfacl squash
  # file: squash
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d squash
  # file: squash
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

---

Geliang Tang (1):
  squashfs: Add posix acl support

 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++--
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +++-
 fs/squashfs/xattr.h|  8 +++
 12 files changed, 171 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

---

Geliang Tang (1):
  squashfs-tools: Add posix acl support

 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

-- 
2.17.1



[PATCH v3 1/2] squashfs: Add posix acl support

2018-08-07 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs documentation.  This patch implements
a squashfs_get_acl function to read the file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang 
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++--
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +++-
 fs/squashfs/xattr.h|  8 +++
 12 files changed, 171 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..1c9eb2d13c2b
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int retval;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   retval = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (retval > 0) {
+   value = kmalloc(retval, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   retval = squashfs_xattr_get(inode, name_index, name, value, 
retval);
+   }
+   if (retval > 0)
+   acl = posix_acl_from_xattr(_user_ns, value, retval);
+   else if (retv

[PATCH v3 0/2] squashfs/squashfs-tools: Add posix acl support

2018-08-07 Thread Geliang Tang
When we use mksquashfs tool to create a squashfs image from the files which
have POSIX ACLs(Access Control Lists), we get these errors:

Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_default

This patcheset adds posix acl support to squashfs to fix this problem. Patch
#1 for kerenl tree and patch #2 for squashfs-tools tree.

---

Testcase:

$ mkdir root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  group::r-x
  other::r-x
$ setfacl -m u:tgl:rw root
$ setfacl -m d:tgl:rw root
$ getfacl root
  # file: root
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d root
  # file: root
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

$ mksquashfs root root.img
$ sudo mount root.img /mnt/squash/

$ cd /mnt
$ getfacl squash
  # file: squash
  # owner: tgl
  # group: tgl
  user::rwx
  user:tgl:rw-
  group::r-x
  mask::rwx
  other::r-x
  default:user::rwx
  default:user:tgl:rw-
  default:group::r-x
  default:mask::rwx
  default:other::r-x
$ getfattr -m . -d squash
  # file: squash
  
system.posix_acl_access=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=
  
system.posix_acl_default=0sAgEABwD/AgAGAOgDAAAEAAUA/xAABwD/IAAFAP8=

---

Geliang Tang (1):
  squashfs: Add posix acl support

 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++--
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 31 +++-
 fs/squashfs/xattr.h|  8 +++
 12 files changed, 171 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

---

Geliang Tang (1):
  squashfs-tools: Add posix acl support

 squashfs-tools/read_xattrs.c |  2 ++
 squashfs-tools/squashfs_fs.h | 12 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

-- 
2.17.1



[PATCH] pstore: set PSTORE_ZSTD_COMPRESS to bool

2018-08-03 Thread Geliang Tang
Fix build error:

   fs/pstore/platform.o: In function `zbufsize_zstd':
>> platform.c:(.text+0x172): undefined reference to `ZSTD_compressBound'

Signed-off-by: Geliang Tang 
---
 fs/pstore/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 63cf4813559a..503086f7f7c1 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -51,7 +51,7 @@ config PSTORE_842_COMPRESS
  This option enables 842 compression algorithm support.
 
 config PSTORE_ZSTD_COMPRESS
-   tristate "zstd compression"
+   bool "zstd compression"
depends on PSTORE
select CRYPTO_ZSTD
help
-- 
2.17.1



[PATCH] pstore: set PSTORE_ZSTD_COMPRESS to bool

2018-08-03 Thread Geliang Tang
Fix build error:

   fs/pstore/platform.o: In function `zbufsize_zstd':
>> platform.c:(.text+0x172): undefined reference to `ZSTD_compressBound'

Signed-off-by: Geliang Tang 
---
 fs/pstore/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 63cf4813559a..503086f7f7c1 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -51,7 +51,7 @@ config PSTORE_842_COMPRESS
  This option enables 842 compression algorithm support.
 
 config PSTORE_ZSTD_COMPRESS
-   tristate "zstd compression"
+   bool "zstd compression"
depends on PSTORE
select CRYPTO_ZSTD
help
-- 
2.17.1



[PATCH] pstore: add zstd compression support

2018-08-01 Thread Geliang Tang
This patch added the 6th compression algorithm support for pstore: zstd.

Signed-off-by: Geliang Tang 
---
 fs/pstore/Kconfig| 17 ++---
 fs/pstore/platform.c | 16 
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..63cf4813559a 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
help
  This option enables 842 compression algorithm support.
 
+config PSTORE_ZSTD_COMPRESS
+   tristate "zstd compression"
+   depends on PSTORE
+   select CRYPTO_ZSTD
+   help
+ This option enables zstd compression algorithm support.
+
 config PSTORE_COMPRESS
def_bool y
depends on PSTORE
depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
   PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
-  PSTORE_842_COMPRESS
+  PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS
 
 choice
prompt "Default pstore compression algorithm"
@@ -65,8 +72,8 @@ choice
  This change be changed at boot with "pstore.compress=..." on
  the kernel command line.
 
- Currently, pstore has support for 5 compression algorithms:
- deflate, lzo, lz4, lz4hc and 842.
+ Currently, pstore has support for 6 compression algorithms:
+ deflate, lzo, lz4, lz4hc, 842 and zstd.
 
  The default compression algorithm is deflate.
 
@@ -85,6 +92,9 @@ choice
config PSTORE_842_COMPRESS_DEFAULT
bool "842" if PSTORE_842_COMPRESS
 
+   config PSTORE_ZSTD_COMPRESS_DEFAULT
+   bool "zstd" if PSTORE_ZSTD_COMPRESS
+
 endchoice
 
 config PSTORE_COMPRESS_DEFAULT
@@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
default "842" if PSTORE_842_COMPRESS_DEFAULT
+   default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
 
 config PSTORE_CONSOLE
bool "Log kernel console messages"
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index c238ab8ba31d..15e99d5a681d 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,6 +34,9 @@
 #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || 
IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+static int zbufsize_zstd(size_t size)
+{
+   return ZSTD_compressBound(size);
+}
+#endif
+
 static const struct pstore_zbackend *zbackend __ro_after_init;
 
 static const struct pstore_zbackend zbackends[] = {
@@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
.zbufsize   = zbufsize_842,
.name   = "842",
},
+#endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+   {
+   .zbufsize   = zbufsize_zstd,
+   .name   = "zstd",
+   },
 #endif
{ }
 };
-- 
2.17.1



[PATCH] pstore: add zstd compression support

2018-08-01 Thread Geliang Tang
This patch added the 6th compression algorithm support for pstore: zstd.

Signed-off-by: Geliang Tang 
---
 fs/pstore/Kconfig| 17 ++---
 fs/pstore/platform.c | 16 
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..63cf4813559a 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
help
  This option enables 842 compression algorithm support.
 
+config PSTORE_ZSTD_COMPRESS
+   tristate "zstd compression"
+   depends on PSTORE
+   select CRYPTO_ZSTD
+   help
+ This option enables zstd compression algorithm support.
+
 config PSTORE_COMPRESS
def_bool y
depends on PSTORE
depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
   PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
-  PSTORE_842_COMPRESS
+  PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS
 
 choice
prompt "Default pstore compression algorithm"
@@ -65,8 +72,8 @@ choice
  This change be changed at boot with "pstore.compress=..." on
  the kernel command line.
 
- Currently, pstore has support for 5 compression algorithms:
- deflate, lzo, lz4, lz4hc and 842.
+ Currently, pstore has support for 6 compression algorithms:
+ deflate, lzo, lz4, lz4hc, 842 and zstd.
 
  The default compression algorithm is deflate.
 
@@ -85,6 +92,9 @@ choice
config PSTORE_842_COMPRESS_DEFAULT
bool "842" if PSTORE_842_COMPRESS
 
+   config PSTORE_ZSTD_COMPRESS_DEFAULT
+   bool "zstd" if PSTORE_ZSTD_COMPRESS
+
 endchoice
 
 config PSTORE_COMPRESS_DEFAULT
@@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
default "842" if PSTORE_842_COMPRESS_DEFAULT
+   default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
 
 config PSTORE_CONSOLE
bool "Log kernel console messages"
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index c238ab8ba31d..15e99d5a681d 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,6 +34,9 @@
 #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || 
IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+static int zbufsize_zstd(size_t size)
+{
+   return ZSTD_compressBound(size);
+}
+#endif
+
 static const struct pstore_zbackend *zbackend __ro_after_init;
 
 static const struct pstore_zbackend zbackends[] = {
@@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
.zbufsize   = zbufsize_842,
.name   = "842",
},
+#endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+   {
+   .zbufsize   = zbufsize_zstd,
+   .name   = "zstd",
+   },
 #endif
{ }
 };
-- 
2.17.1



Re: [PATCH] pstore: add zstd compression support

2018-04-23 Thread Geliang Tang
On Wed, Mar 21, 2018 at 08:29:31PM +0800, Geliang Tang wrote:
> This patch added the 6th compression algorithm support for pstore: zstd.
> 
> Signed-off-by: Geliang Tang <geliangt...@gmail.com>
> ---
> Depend on 'crypto: Add zstd support' by Nick Terrell <terre...@fb.com>

Hi Kees,

The patch 'crypto: zstd - Add zstd support' has been applied to
linux-next tree, 20180423, already. So we can use zstd in pstore
compression now. Please reconsider if my patch can be applied.

Thanks.
-Geliang

> ---
>  fs/pstore/Kconfig| 17 ++---
>  fs/pstore/platform.c | 16 
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
> index 09c19ef91526..63cf4813559a 100644
> --- a/fs/pstore/Kconfig
> +++ b/fs/pstore/Kconfig
> @@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
>   help
> This option enables 842 compression algorithm support.
>  
> +config PSTORE_ZSTD_COMPRESS
> + tristate "zstd compression"
> + depends on PSTORE
> + select CRYPTO_ZSTD
> + help
> +   This option enables zstd compression algorithm support.
> +
>  config PSTORE_COMPRESS
>   def_bool y
>   depends on PSTORE
>   depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
>  PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
> -PSTORE_842_COMPRESS
> +PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS
>  
>  choice
>   prompt "Default pstore compression algorithm"
> @@ -65,8 +72,8 @@ choice
> This change be changed at boot with "pstore.compress=..." on
> the kernel command line.
>  
> -   Currently, pstore has support for 5 compression algorithms:
> -   deflate, lzo, lz4, lz4hc and 842.
> +   Currently, pstore has support for 6 compression algorithms:
> +   deflate, lzo, lz4, lz4hc, 842 and zstd.
>  
> The default compression algorithm is deflate.
>  
> @@ -85,6 +92,9 @@ choice
>   config PSTORE_842_COMPRESS_DEFAULT
>   bool "842" if PSTORE_842_COMPRESS
>  
> + config PSTORE_ZSTD_COMPRESS_DEFAULT
> + bool "zstd" if PSTORE_ZSTD_COMPRESS
> +
>  endchoice
>  
>  config PSTORE_COMPRESS_DEFAULT
> @@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
>   default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
>   default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
>   default "842" if PSTORE_842_COMPRESS_DEFAULT
> + default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
>  
>  config PSTORE_CONSOLE
>   bool "Log kernel console messages"
> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> index 1143ef351c58..9df8cdc378f5 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -34,6 +34,9 @@
>  #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || 
> IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
>  #include 
>  #endif
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> +#include 
> +#endif
>  #include 
>  #include 
>  #include 
> @@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
>  }
>  #endif
>  
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> +static int zbufsize_zstd(size_t size)
> +{
> + return ZSTD_compressBound(size);
> +}
> +#endif
> +
>  static const struct pstore_zbackend *zbackend __ro_after_init;
>  
>  static const struct pstore_zbackend zbackends[] = {
> @@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
>   .zbufsize   = zbufsize_842,
>   .name   = "842",
>   },
> +#endif
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> + {
> + .zbufsize   = zbufsize_zstd,
> + .name   = "zstd",
> + },
>  #endif
>   { }
>  };
> -- 
> 2.14.1


Re: [PATCH] pstore: add zstd compression support

2018-04-23 Thread Geliang Tang
On Wed, Mar 21, 2018 at 08:29:31PM +0800, Geliang Tang wrote:
> This patch added the 6th compression algorithm support for pstore: zstd.
> 
> Signed-off-by: Geliang Tang 
> ---
> Depend on 'crypto: Add zstd support' by Nick Terrell 

Hi Kees,

The patch 'crypto: zstd - Add zstd support' has been applied to
linux-next tree, 20180423, already. So we can use zstd in pstore
compression now. Please reconsider if my patch can be applied.

Thanks.
-Geliang

> ---
>  fs/pstore/Kconfig| 17 ++---
>  fs/pstore/platform.c | 16 
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
> index 09c19ef91526..63cf4813559a 100644
> --- a/fs/pstore/Kconfig
> +++ b/fs/pstore/Kconfig
> @@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
>   help
> This option enables 842 compression algorithm support.
>  
> +config PSTORE_ZSTD_COMPRESS
> + tristate "zstd compression"
> + depends on PSTORE
> + select CRYPTO_ZSTD
> + help
> +   This option enables zstd compression algorithm support.
> +
>  config PSTORE_COMPRESS
>   def_bool y
>   depends on PSTORE
>   depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
>  PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
> -PSTORE_842_COMPRESS
> +PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS
>  
>  choice
>   prompt "Default pstore compression algorithm"
> @@ -65,8 +72,8 @@ choice
> This change be changed at boot with "pstore.compress=..." on
> the kernel command line.
>  
> -   Currently, pstore has support for 5 compression algorithms:
> -   deflate, lzo, lz4, lz4hc and 842.
> +   Currently, pstore has support for 6 compression algorithms:
> +   deflate, lzo, lz4, lz4hc, 842 and zstd.
>  
> The default compression algorithm is deflate.
>  
> @@ -85,6 +92,9 @@ choice
>   config PSTORE_842_COMPRESS_DEFAULT
>   bool "842" if PSTORE_842_COMPRESS
>  
> + config PSTORE_ZSTD_COMPRESS_DEFAULT
> + bool "zstd" if PSTORE_ZSTD_COMPRESS
> +
>  endchoice
>  
>  config PSTORE_COMPRESS_DEFAULT
> @@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
>   default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
>   default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
>   default "842" if PSTORE_842_COMPRESS_DEFAULT
> + default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
>  
>  config PSTORE_CONSOLE
>   bool "Log kernel console messages"
> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> index 1143ef351c58..9df8cdc378f5 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -34,6 +34,9 @@
>  #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || 
> IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
>  #include 
>  #endif
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> +#include 
> +#endif
>  #include 
>  #include 
>  #include 
> @@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
>  }
>  #endif
>  
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> +static int zbufsize_zstd(size_t size)
> +{
> + return ZSTD_compressBound(size);
> +}
> +#endif
> +
>  static const struct pstore_zbackend *zbackend __ro_after_init;
>  
>  static const struct pstore_zbackend zbackends[] = {
> @@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
>   .zbufsize   = zbufsize_842,
>   .name   = "842",
>   },
> +#endif
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> + {
> + .zbufsize   = zbufsize_zstd,
> + .name   = "zstd",
> + },
>  #endif
>   { }
>  };
> -- 
> 2.14.1


[PATCH v2] squashfs: Add posix acl support

2018-04-09 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs' documentation.  This patch implements
the squashfs_get_acl function to read file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
Changes in v2:
 - fix build error, set squashfs_get_acl to NULL when CONFIG_SQUASHFS_POSIX_ACL 
is not selected.
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 ++
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 +++
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++---
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 13 ++-
 fs/squashfs/xattr.h|  8 
 12 files changed, 153 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..1c9eb2d13c2b
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher <phil...@squashfs.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int retval;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   retval = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (retval > 0) {
+   value = kmalloc(retval, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   re

[PATCH v2] squashfs: Add posix acl support

2018-04-09 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs' documentation.  This patch implements
the squashfs_get_acl function to read file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang 
---
Changes in v2:
 - fix build error, set squashfs_get_acl to NULL when CONFIG_SQUASHFS_POSIX_ACL 
is not selected.
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 ++
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 31 +++
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++---
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 13 ++-
 fs/squashfs/xattr.h|  8 
 12 files changed, 153 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..1c9eb2d13c2b
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int retval;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   retval = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (retval > 0) {
+   value = kmalloc(retval, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   retval = squashfs_xattr_get(inode, name_index, name, value, 
retval);

[PATCH] squashfs-tools: Add posix acl support

2018-04-09 Thread Geliang Tang
Add posix acl (Access Control Lists) support for mksquashfs and
unsquashfs tools.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
 squashfs-tools/read_xattrs.c  |  2 ++
 squashfs-tools/squashfs_fs.h  | 12 +++-
 squashfs-tools/unsquashfs_xattr.c |  4 +++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..8ef8291 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -64,6 +64,8 @@ static long long xattr_table_start;
  */
 struct prefix prefix_table[] = {
{ "user.", SQUASHFS_XATTR_USER },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_ACCESS },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_DEFAULT },
{ "trusted.", SQUASHFS_XATTR_TRUSTED },
{ "security.", SQUASHFS_XATTR_SECURITY },
{ "", -1 }
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index afca918..040035c 100644
--- a/squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h
@@ -122,11 +122,13 @@
 #define SQUASHFS_LSOCKET_TYPE  14
 
 /* Xattr types */
-#define SQUASHFS_XATTR_USER0
-#define SQUASHFS_XATTR_TRUSTED 1
-#define SQUASHFS_XATTR_SECURITY2
-#define SQUASHFS_XATTR_VALUE_OOL   256
-#define SQUASHFS_XATTR_PREFIX_MASK 0xff
+#define SQUASHFS_XATTR_USER0
+#define SQUASHFS_XATTR_POSIX_ACL_ACCESS1
+#define SQUASHFS_XATTR_POSIX_ACL_DEFAULT   2
+#define SQUASHFS_XATTR_TRUSTED 3
+#define SQUASHFS_XATTR_SECURITY4
+#define SQUASHFS_XATTR_VALUE_OOL   256
+#define SQUASHFS_XATTR_PREFIX_MASK 0xff
 
 /* Flag whether block is compressed or uncompressed, bit is set if block is
  * uncompressed */
diff --git a/squashfs-tools/unsquashfs_xattr.c 
b/squashfs-tools/unsquashfs_xattr.c
index 59f4aae..34aae84 100644
--- a/squashfs-tools/unsquashfs_xattr.c
+++ b/squashfs-tools/unsquashfs_xattr.c
@@ -57,7 +57,9 @@ void write_xattr(char *pathname, unsigned int xattr)
if(user_xattrs && prefix != SQUASHFS_XATTR_USER)
continue;
 
-   if(root_process || prefix == SQUASHFS_XATTR_USER) {
+   if(root_process || prefix == SQUASHFS_XATTR_USER
+   || prefix == SQUASHFS_XATTR_POSIX_ACL_ACCESS
+   || prefix == SQUASHFS_XATTR_POSIX_ACL_DEFAULT) {
int res = lsetxattr(pathname, xattr_list[i].full_name,
xattr_list[i].value, xattr_list[i].vsize, 0);
 
-- 
2.14.1



[PATCH] squashfs-tools: Add posix acl support

2018-04-09 Thread Geliang Tang
Add posix acl (Access Control Lists) support for mksquashfs and
unsquashfs tools.

Signed-off-by: Geliang Tang 
---
 squashfs-tools/read_xattrs.c  |  2 ++
 squashfs-tools/squashfs_fs.h  | 12 +++-
 squashfs-tools/unsquashfs_xattr.c |  4 +++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..8ef8291 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -64,6 +64,8 @@ static long long xattr_table_start;
  */
 struct prefix prefix_table[] = {
{ "user.", SQUASHFS_XATTR_USER },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_ACCESS },
+   { "system.", SQUASHFS_XATTR_POSIX_ACL_DEFAULT },
{ "trusted.", SQUASHFS_XATTR_TRUSTED },
{ "security.", SQUASHFS_XATTR_SECURITY },
{ "", -1 }
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index afca918..040035c 100644
--- a/squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h
@@ -122,11 +122,13 @@
 #define SQUASHFS_LSOCKET_TYPE  14
 
 /* Xattr types */
-#define SQUASHFS_XATTR_USER0
-#define SQUASHFS_XATTR_TRUSTED 1
-#define SQUASHFS_XATTR_SECURITY2
-#define SQUASHFS_XATTR_VALUE_OOL   256
-#define SQUASHFS_XATTR_PREFIX_MASK 0xff
+#define SQUASHFS_XATTR_USER0
+#define SQUASHFS_XATTR_POSIX_ACL_ACCESS1
+#define SQUASHFS_XATTR_POSIX_ACL_DEFAULT   2
+#define SQUASHFS_XATTR_TRUSTED 3
+#define SQUASHFS_XATTR_SECURITY4
+#define SQUASHFS_XATTR_VALUE_OOL   256
+#define SQUASHFS_XATTR_PREFIX_MASK 0xff
 
 /* Flag whether block is compressed or uncompressed, bit is set if block is
  * uncompressed */
diff --git a/squashfs-tools/unsquashfs_xattr.c 
b/squashfs-tools/unsquashfs_xattr.c
index 59f4aae..34aae84 100644
--- a/squashfs-tools/unsquashfs_xattr.c
+++ b/squashfs-tools/unsquashfs_xattr.c
@@ -57,7 +57,9 @@ void write_xattr(char *pathname, unsigned int xattr)
if(user_xattrs && prefix != SQUASHFS_XATTR_USER)
continue;
 
-   if(root_process || prefix == SQUASHFS_XATTR_USER) {
+   if(root_process || prefix == SQUASHFS_XATTR_USER
+   || prefix == SQUASHFS_XATTR_POSIX_ACL_ACCESS
+   || prefix == SQUASHFS_XATTR_POSIX_ACL_DEFAULT) {
int res = lsetxattr(pathname, xattr_list[i].full_name,
xattr_list[i].value, xattr_list[i].vsize, 0);
 
-- 
2.14.1



[PATCH] squashfs: Add posix acl support

2018-04-09 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs' documentation.  This patch implements
the squashfs_get_acl function to read file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 ++
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 27 +
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++---
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 13 ++-
 fs/squashfs/xattr.h|  8 
 12 files changed, 149 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..1c9eb2d13c2b
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher <phil...@squashfs.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int retval;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   retval = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (retval > 0) {
+   value = kmalloc(retval, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   retval = squashfs_xattr_get(inode, name_index, name, value, 
retval);
+   }
+   if (retval > 0)
+   acl = po

[PATCH] squashfs: Add posix acl support

2018-04-09 Thread Geliang Tang
Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs' documentation.  This patch implements
the squashfs_get_acl function to read file's acl information from its
xattr lists.

Signed-off-by: Geliang Tang 
---
 Documentation/filesystems/squashfs.txt |  2 -
 fs/squashfs/Kconfig| 11 ++
 fs/squashfs/Makefile   |  1 +
 fs/squashfs/acl.c  | 69 ++
 fs/squashfs/acl.h  | 27 +
 fs/squashfs/inode.c|  4 +-
 fs/squashfs/namei.c|  6 ++-
 fs/squashfs/squashfs_fs.h  | 12 +++---
 fs/squashfs/super.c|  3 ++
 fs/squashfs/symlink.c  |  6 ++-
 fs/squashfs/xattr.c| 13 ++-
 fs/squashfs/xattr.h|  8 
 12 files changed, 149 insertions(+), 13 deletions(-)
 create mode 100644 fs/squashfs/acl.c
 create mode 100644 fs/squashfs/acl.h

diff --git a/Documentation/filesystems/squashfs.txt 
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
 4.1 Todo list
 -
 
-Implement ACL support.
-
 4.2 Squashfs internal cache
 ---
 
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
 
  If unsure, say N.
 
+config SQUASHFS_POSIX_ACL
+   bool "Squashfs POSIX ACL support"
+   depends on SQUASHFS_XATTR
+   select FS_POSIX_ACL
+   help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
 config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) += 
decompressor_single.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
 squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
 squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
 squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
 squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..1c9eb2d13c2b
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include 
+#include 
+#include 
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+   int name_index;
+   char *name;
+   struct posix_acl *acl = NULL;
+   char *value = NULL;
+   int retval;
+
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+   name = XATTR_POSIX_ACL_ACCESS;
+   break;
+   case ACL_TYPE_DEFAULT:
+   name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+   name = XATTR_POSIX_ACL_DEFAULT;
+   break;
+   default:
+   BUG();
+   }
+
+   retval = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+   if (retval > 0) {
+   value = kmalloc(retval, GFP_KERNEL);
+   if (!value)
+   return ERR_PTR(-ENOMEM);
+   retval = squashfs_xattr_get(inode, name_index, name, value, 
retval);
+   }
+   if (retval > 0)
+   acl = posix_acl_from_xattr(_user_ns, value, retval);

[PATCH] pstore: set PSTORE_842_COMPRESS tristate

2018-03-21 Thread Geliang Tang
This patch sets PSTORE_842_COMPRESS 'tristate' like other pstore
compression algorithms in Kconfig.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
 fs/pstore/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..a80c9bc0fbfc 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -44,7 +44,7 @@ config PSTORE_LZ4HC_COMPRESS
  This option enables LZ4HC (high compression) mode algorithm.
 
 config PSTORE_842_COMPRESS
-   bool "842 compression"
+   tristate "842 compression"
depends on PSTORE
select CRYPTO_842
help
-- 
2.14.1



[PATCH] pstore: set PSTORE_842_COMPRESS tristate

2018-03-21 Thread Geliang Tang
This patch sets PSTORE_842_COMPRESS 'tristate' like other pstore
compression algorithms in Kconfig.

Signed-off-by: Geliang Tang 
---
 fs/pstore/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..a80c9bc0fbfc 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -44,7 +44,7 @@ config PSTORE_LZ4HC_COMPRESS
  This option enables LZ4HC (high compression) mode algorithm.
 
 config PSTORE_842_COMPRESS
-   bool "842 compression"
+   tristate "842 compression"
depends on PSTORE
select CRYPTO_842
help
-- 
2.14.1



[PATCH] pstore: rename two compression functions

2018-03-21 Thread Geliang Tang
We have following five functions which deal with pstore compression.
This patch renamed two functions to make the names of those functions
consistent:

allocate_buf_for_compression->  pstore_init_compression
free_buf_for_compression->  pstore_free_compression
pstore_choose_compression   pstore_choose_compression
pstore_compress pstore_compress
pstore_decompress   pstore_decompress

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
 fs/pstore/platform.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1143ef351c58..03d16b6ed5ec 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -256,7 +256,7 @@ static int pstore_decompress(void *in, void *out,
return outlen;
 }
 
-static void allocate_buf_for_compression(void)
+static void pstore_init_compression(void)
 {
if (!zbackend)
return;
@@ -285,7 +285,7 @@ static void allocate_buf_for_compression(void)
}
 }
 
-static void free_buf_for_compression(void)
+static void pstore_free_compression(void)
 {
if (!IS_ERR_OR_NULL(tfm))
crypto_free_comp(tfm);
@@ -560,7 +560,7 @@ int pstore_register(struct pstore_info *psi)
return -EINVAL;
}
 
-   allocate_buf_for_compression();
+   pstore_init_compression();
 
if (pstore_is_mounted())
pstore_get_records(0);
@@ -611,7 +611,7 @@ void pstore_unregister(struct pstore_info *psi)
if (psi->flags & PSTORE_FLAGS_DMESG)
pstore_unregister_kmsg();
 
-   free_buf_for_compression();
+   pstore_free_compression();
 
psinfo = NULL;
backend = NULL;
-- 
2.14.1



[PATCH] pstore: rename two compression functions

2018-03-21 Thread Geliang Tang
We have following five functions which deal with pstore compression.
This patch renamed two functions to make the names of those functions
consistent:

allocate_buf_for_compression->  pstore_init_compression
free_buf_for_compression->  pstore_free_compression
pstore_choose_compression   pstore_choose_compression
pstore_compress pstore_compress
pstore_decompress   pstore_decompress

Signed-off-by: Geliang Tang 
---
 fs/pstore/platform.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1143ef351c58..03d16b6ed5ec 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -256,7 +256,7 @@ static int pstore_decompress(void *in, void *out,
return outlen;
 }
 
-static void allocate_buf_for_compression(void)
+static void pstore_init_compression(void)
 {
if (!zbackend)
return;
@@ -285,7 +285,7 @@ static void allocate_buf_for_compression(void)
}
 }
 
-static void free_buf_for_compression(void)
+static void pstore_free_compression(void)
 {
if (!IS_ERR_OR_NULL(tfm))
crypto_free_comp(tfm);
@@ -560,7 +560,7 @@ int pstore_register(struct pstore_info *psi)
return -EINVAL;
}
 
-   allocate_buf_for_compression();
+   pstore_init_compression();
 
if (pstore_is_mounted())
pstore_get_records(0);
@@ -611,7 +611,7 @@ void pstore_unregister(struct pstore_info *psi)
if (psi->flags & PSTORE_FLAGS_DMESG)
pstore_unregister_kmsg();
 
-   free_buf_for_compression();
+   pstore_free_compression();
 
psinfo = NULL;
backend = NULL;
-- 
2.14.1



[PATCH] pstore: add zstd compression support

2018-03-21 Thread Geliang Tang
This patch added the 6th compression algorithm support for pstore: zstd.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
Depend on 'crypto: Add zstd support' by Nick Terrell <terre...@fb.com>
---
 fs/pstore/Kconfig| 17 ++---
 fs/pstore/platform.c | 16 
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..63cf4813559a 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
help
  This option enables 842 compression algorithm support.
 
+config PSTORE_ZSTD_COMPRESS
+   tristate "zstd compression"
+   depends on PSTORE
+   select CRYPTO_ZSTD
+   help
+ This option enables zstd compression algorithm support.
+
 config PSTORE_COMPRESS
def_bool y
depends on PSTORE
depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
   PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
-  PSTORE_842_COMPRESS
+  PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS
 
 choice
prompt "Default pstore compression algorithm"
@@ -65,8 +72,8 @@ choice
  This change be changed at boot with "pstore.compress=..." on
  the kernel command line.
 
- Currently, pstore has support for 5 compression algorithms:
- deflate, lzo, lz4, lz4hc and 842.
+ Currently, pstore has support for 6 compression algorithms:
+ deflate, lzo, lz4, lz4hc, 842 and zstd.
 
  The default compression algorithm is deflate.
 
@@ -85,6 +92,9 @@ choice
config PSTORE_842_COMPRESS_DEFAULT
bool "842" if PSTORE_842_COMPRESS
 
+   config PSTORE_ZSTD_COMPRESS_DEFAULT
+   bool "zstd" if PSTORE_ZSTD_COMPRESS
+
 endchoice
 
 config PSTORE_COMPRESS_DEFAULT
@@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
default "842" if PSTORE_842_COMPRESS_DEFAULT
+   default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
 
 config PSTORE_CONSOLE
bool "Log kernel console messages"
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1143ef351c58..9df8cdc378f5 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,6 +34,9 @@
 #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || 
IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+static int zbufsize_zstd(size_t size)
+{
+   return ZSTD_compressBound(size);
+}
+#endif
+
 static const struct pstore_zbackend *zbackend __ro_after_init;
 
 static const struct pstore_zbackend zbackends[] = {
@@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
.zbufsize   = zbufsize_842,
.name   = "842",
},
+#endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+   {
+   .zbufsize   = zbufsize_zstd,
+   .name   = "zstd",
+   },
 #endif
{ }
 };
-- 
2.14.1



[PATCH] pstore: add zstd compression support

2018-03-21 Thread Geliang Tang
This patch added the 6th compression algorithm support for pstore: zstd.

Signed-off-by: Geliang Tang 
---
Depend on 'crypto: Add zstd support' by Nick Terrell 
---
 fs/pstore/Kconfig| 17 ++---
 fs/pstore/platform.c | 16 
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..63cf4813559a 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
help
  This option enables 842 compression algorithm support.
 
+config PSTORE_ZSTD_COMPRESS
+   tristate "zstd compression"
+   depends on PSTORE
+   select CRYPTO_ZSTD
+   help
+ This option enables zstd compression algorithm support.
+
 config PSTORE_COMPRESS
def_bool y
depends on PSTORE
depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
   PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
-  PSTORE_842_COMPRESS
+  PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS
 
 choice
prompt "Default pstore compression algorithm"
@@ -65,8 +72,8 @@ choice
  This change be changed at boot with "pstore.compress=..." on
  the kernel command line.
 
- Currently, pstore has support for 5 compression algorithms:
- deflate, lzo, lz4, lz4hc and 842.
+ Currently, pstore has support for 6 compression algorithms:
+ deflate, lzo, lz4, lz4hc, 842 and zstd.
 
  The default compression algorithm is deflate.
 
@@ -85,6 +92,9 @@ choice
config PSTORE_842_COMPRESS_DEFAULT
bool "842" if PSTORE_842_COMPRESS
 
+   config PSTORE_ZSTD_COMPRESS_DEFAULT
+   bool "zstd" if PSTORE_ZSTD_COMPRESS
+
 endchoice
 
 config PSTORE_COMPRESS_DEFAULT
@@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
default "842" if PSTORE_842_COMPRESS_DEFAULT
+   default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
 
 config PSTORE_CONSOLE
bool "Log kernel console messages"
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1143ef351c58..9df8cdc378f5 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,6 +34,9 @@
 #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || 
IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+static int zbufsize_zstd(size_t size)
+{
+   return ZSTD_compressBound(size);
+}
+#endif
+
 static const struct pstore_zbackend *zbackend __ro_after_init;
 
 static const struct pstore_zbackend zbackends[] = {
@@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
.zbufsize   = zbufsize_842,
.name   = "842",
},
+#endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+   {
+   .zbufsize   = zbufsize_zstd,
+   .name   = "zstd",
+   },
 #endif
{ }
 };
-- 
2.14.1



[PATCH] pstore: use crypto compress API

2018-03-09 Thread Geliang Tang
In the pstore compression part, we use zlib/lzo/lz4/lz4hc/842
compression algorithm API to implement pstore compression backends. But
there are many repeat codes in these implementations. This patch uses
crypto compress API to simplify these codes.

1) rewrite allocate_buf_for_compression, free_buf_for_compression,
pstore_compress, pstore_decompress functions using crypto compress API.
2) drop compress, decompress, allocate, free functions in pstore_zbackend,
and add zbufsize function to get each different compress buffer size.
3) use late_initcall to call ramoops_init later, to make sure the crypto
subsystem has already initialized.
4) use 'unsigned int' type instead of 'size_t' in pstore_compress,
pstore_decompress functions' length arguments.
5) rename 'zlib' to 'deflate' to follow the crypto API's name
convention.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
 fs/pstore/Kconfig|  33 ++--
 fs/pstore/platform.c | 413 ---
 fs/pstore/ram.c  |   2 +-
 3 files changed, 80 insertions(+), 368 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index e4e22026c7a1..26f1c0fcada3 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -12,51 +12,46 @@ config PSTORE
   If you don't have a platform persistent store driver,
   say N.
 
-config PSTORE_ZLIB_COMPRESS
-   bool "ZLIB compression"
+config PSTORE_DEFLATE_COMPRESS
+   bool "DEFLATE compression"
default y
depends on PSTORE
-   select ZLIB_DEFLATE
-   select ZLIB_INFLATE
+   select CRYPTO_DEFLATE
help
- This option enables ZLIB compression algorithm support.
+ This option enables DEFLATE compression algorithm support.
 
 config PSTORE_LZO_COMPRESS
bool "LZO compression"
depends on PSTORE
-   select LZO_COMPRESS
-   select LZO_DECOMPRESS
+   select CRYPTO_LZO
help
  This option enables LZO compression algorithm support.
 
 config PSTORE_LZ4_COMPRESS
bool "LZ4 compression"
depends on PSTORE
-   select LZ4_COMPRESS
-   select LZ4_DECOMPRESS
+   select CRYPTO_LZ4
help
  This option enables LZ4 compression algorithm support.
 
 config PSTORE_LZ4HC_COMPRESS
bool "LZ4HC compression"
depends on PSTORE
-   select LZ4HC_COMPRESS
-   select LZ4_DECOMPRESS
+   select CRYPTO_LZ4HC
help
  This option enables LZ4HC (high compression) mode algorithm.
 
 config PSTORE_842_COMPRESS
bool "842 compression"
depends on PSTORE
-   select 842_COMPRESS
-   select 842_DECOMPRESS
+   select CRYPTO_842
help
  This option enables 842 compression algorithm support.
 
 config PSTORE_COMPRESS
def_bool y
depends on PSTORE
-   depends on PSTORE_ZLIB_COMPRESS || PSTORE_LZO_COMPRESS ||   \
+   depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
   PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
   PSTORE_842_COMPRESS
 
@@ -69,12 +64,12 @@ choice
  the kernel command line.
 
  Currently, pstore has support for 5 compression algorithms:
- zlib, lzo, lz4, lz4hc and 842.
+ deflate, lzo, lz4, lz4hc and 842.
 
- The default compression algorithm is zlib.
+ The default compression algorithm is deflate.
 
-   config PSTORE_ZLIB_COMPRESS_DEFAULT
-   bool "zlib" if PSTORE_ZLIB_COMPRESS=y
+   config PSTORE_DEFLATE_COMPRESS_DEFAULT
+   bool "deflate" if PSTORE_DEFLATE_COMPRESS=y
 
config PSTORE_LZO_COMPRESS_DEFAULT
bool "lzo" if PSTORE_LZO_COMPRESS=y
@@ -93,7 +88,7 @@ endchoice
 config PSTORE_COMPRESS_DEFAULT
string
depends on PSTORE_COMPRESS
-   default "zlib" if PSTORE_ZLIB_COMPRESS_DEFAULT
+   default "deflate" if PSTORE_DEFLATE_COMPRESS_DEFAULT
default "lzo" if PSTORE_LZO_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 06e3b280c3a5..1d40b4588d68 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -28,18 +28,13 @@
 #include 
 #include 
 #include 
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS
-#include 
-#endif
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
 #if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
-#ifdef CONFIG_PSTORE_842_COMPRESS
-#include 
-#endif
+#include 
 #include 
 #include 
 #include 
@@ -85,25 +80,10 @@ static char *compress =
 #endif
 
 /* Compression parameters */
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS
-#define COMPR_LEVEL 6
-#define WINDOW_BITS 12
-#define MEM_LEVEL 4
-static struct z_stream_s stream;

[PATCH] pstore: use crypto compress API

2018-03-09 Thread Geliang Tang
In the pstore compression part, we use zlib/lzo/lz4/lz4hc/842
compression algorithm API to implement pstore compression backends. But
there are many repeat codes in these implementations. This patch uses
crypto compress API to simplify these codes.

1) rewrite allocate_buf_for_compression, free_buf_for_compression,
pstore_compress, pstore_decompress functions using crypto compress API.
2) drop compress, decompress, allocate, free functions in pstore_zbackend,
and add zbufsize function to get each different compress buffer size.
3) use late_initcall to call ramoops_init later, to make sure the crypto
subsystem has already initialized.
4) use 'unsigned int' type instead of 'size_t' in pstore_compress,
pstore_decompress functions' length arguments.
5) rename 'zlib' to 'deflate' to follow the crypto API's name
convention.

Signed-off-by: Geliang Tang 
---
 fs/pstore/Kconfig|  33 ++--
 fs/pstore/platform.c | 413 ---
 fs/pstore/ram.c  |   2 +-
 3 files changed, 80 insertions(+), 368 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index e4e22026c7a1..26f1c0fcada3 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -12,51 +12,46 @@ config PSTORE
   If you don't have a platform persistent store driver,
   say N.
 
-config PSTORE_ZLIB_COMPRESS
-   bool "ZLIB compression"
+config PSTORE_DEFLATE_COMPRESS
+   bool "DEFLATE compression"
default y
depends on PSTORE
-   select ZLIB_DEFLATE
-   select ZLIB_INFLATE
+   select CRYPTO_DEFLATE
help
- This option enables ZLIB compression algorithm support.
+ This option enables DEFLATE compression algorithm support.
 
 config PSTORE_LZO_COMPRESS
bool "LZO compression"
depends on PSTORE
-   select LZO_COMPRESS
-   select LZO_DECOMPRESS
+   select CRYPTO_LZO
help
  This option enables LZO compression algorithm support.
 
 config PSTORE_LZ4_COMPRESS
bool "LZ4 compression"
depends on PSTORE
-   select LZ4_COMPRESS
-   select LZ4_DECOMPRESS
+   select CRYPTO_LZ4
help
  This option enables LZ4 compression algorithm support.
 
 config PSTORE_LZ4HC_COMPRESS
bool "LZ4HC compression"
depends on PSTORE
-   select LZ4HC_COMPRESS
-   select LZ4_DECOMPRESS
+   select CRYPTO_LZ4HC
help
  This option enables LZ4HC (high compression) mode algorithm.
 
 config PSTORE_842_COMPRESS
bool "842 compression"
depends on PSTORE
-   select 842_COMPRESS
-   select 842_DECOMPRESS
+   select CRYPTO_842
help
  This option enables 842 compression algorithm support.
 
 config PSTORE_COMPRESS
def_bool y
depends on PSTORE
-   depends on PSTORE_ZLIB_COMPRESS || PSTORE_LZO_COMPRESS ||   \
+   depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS ||\
   PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||  \
   PSTORE_842_COMPRESS
 
@@ -69,12 +64,12 @@ choice
  the kernel command line.
 
  Currently, pstore has support for 5 compression algorithms:
- zlib, lzo, lz4, lz4hc and 842.
+ deflate, lzo, lz4, lz4hc and 842.
 
- The default compression algorithm is zlib.
+ The default compression algorithm is deflate.
 
-   config PSTORE_ZLIB_COMPRESS_DEFAULT
-   bool "zlib" if PSTORE_ZLIB_COMPRESS=y
+   config PSTORE_DEFLATE_COMPRESS_DEFAULT
+   bool "deflate" if PSTORE_DEFLATE_COMPRESS=y
 
config PSTORE_LZO_COMPRESS_DEFAULT
bool "lzo" if PSTORE_LZO_COMPRESS=y
@@ -93,7 +88,7 @@ endchoice
 config PSTORE_COMPRESS_DEFAULT
string
depends on PSTORE_COMPRESS
-   default "zlib" if PSTORE_ZLIB_COMPRESS_DEFAULT
+   default "deflate" if PSTORE_DEFLATE_COMPRESS_DEFAULT
default "lzo" if PSTORE_LZO_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 06e3b280c3a5..1d40b4588d68 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -28,18 +28,13 @@
 #include 
 #include 
 #include 
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS
-#include 
-#endif
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
 #if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
-#ifdef CONFIG_PSTORE_842_COMPRESS
-#include 
-#endif
+#include 
 #include 
 #include 
 #include 
@@ -85,25 +80,10 @@ static char *compress =
 #endif
 
 /* Compression parameters */
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS
-#define COMPR_LEVEL 6
-#define WINDOW_BITS 12
-#define MEM_LEVEL 4
-static struct z_stream_s stream;
-#endif
-#if defined(CON

[PATCH v4] pstore: add lz4hc and 842 compression support

2018-02-12 Thread Geliang Tang
Currently, pstore has supported three compression algorithms: zlib,
lzo and lz4. This patch added two more compression algorithms: lz4hc
and 842.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
Changes in v4:
 -842 compress is not work in patch v3 since big_oops_buf_sz is too big.
  change big_oops_buf_sz from psinfo->bufsize * 2 to psinfo->bufsize.
Changes in v3:
 -fix outlen in 842
Changes in v2:
 -fix checkpatch.pl WARNING:
  please write a paragraph that describes the config symbol fully
---
 fs/pstore/Kconfig|  25 +
 fs/pstore/platform.c | 147 ---
 2 files changed, 154 insertions(+), 18 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index b42e5bd6d8ff..cf97a3ecdce0 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -39,6 +39,31 @@ config PSTORE_LZ4_COMPRESS
 select LZ4_DECOMPRESS
 help
   This option enables LZ4 compression algorithm support.
+
+config PSTORE_LZ4HC_COMPRESS
+   bool "LZ4HC"
+   select LZ4HC_COMPRESS
+   select LZ4_DECOMPRESS
+   help
+ This option enables LZ4 high compression mode algorithm.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
+config PSTORE_842_COMPRESS
+   bool "842"
+   select 842_COMPRESS
+   select 842_DECOMPRESS
+   help
+ This option enables 842 compression algorithm support.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
 endchoice
 
 config PSTORE_CONSOLE
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index c3129b131e4d..19aaefeb052f 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,9 +34,12 @@
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#ifdef CONFIG_PSTORE_842_COMPRESS
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -336,6 +339,33 @@ static const struct pstore_zbackend backend_lzo = {
 };
 #endif
 
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
+static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_decompress_safe(in, out, inlen, outlen);
+   if (ret < 0) {
+   /*
+* LZ4_decompress_safe will return an error code
+* (< 0) if decompression failed
+*/
+   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   return -EIO;
+   }
+
+   return ret;
+}
+
+static void free_lz4(void)
+{
+   kfree(workspace);
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   big_oops_buf_sz = 0;
+}
+#endif
+
 #ifdef CONFIG_PSTORE_LZ4_COMPRESS
 static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
 {
@@ -350,29 +380,54 @@ static int compress_lz4(const void *in, void *out, size_t 
inlen, size_t outlen)
return ret;
 }
 
-static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+static void allocate_lz4(void)
+{
+   big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize);
+   big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
+   if (big_oops_buf) {
+   workspace = kmalloc(LZ4_MEM_COMPRESS, GFP_KERNEL);
+   if (!workspace) {
+   pr_err("No memory for compression workspace; skipping 
compression\n");
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   }
+   } else {
+   pr_err("No memory for uncompressed data; skipping 
compression\n");
+   workspace = NULL;
+   }
+}
+
+static const struct pstore_zbackend backend_lz4 = {
+   .compress   = compress_lz4,
+   .decompress = decompress_lz4,
+   .allocate   = allocate_lz4,
+   .free   = free_lz4,
+   .name   = "lz4",
+};
+#endif
+
+#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
+static int compress_lz4hc(const void *in, void *out,
+ size_t inlen, size_t outlen)
 {
int ret;
 
-   ret = LZ4_decompress_safe(in, out, inlen, outlen);
-   if (ret < 0) {
-   /*
-* LZ4_decompress_safe will return an error code
-* (< 0) if decompression failed
-*/
-   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   ret = LZ4_compress_HC(in, out, inlen, outlen,
+ LZ4HC_DEFAULT_CLEVEL, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_HC error; compression failed!\n");
   

[PATCH v4] pstore: add lz4hc and 842 compression support

2018-02-12 Thread Geliang Tang
Currently, pstore has supported three compression algorithms: zlib,
lzo and lz4. This patch added two more compression algorithms: lz4hc
and 842.

Signed-off-by: Geliang Tang 
---
Changes in v4:
 -842 compress is not work in patch v3 since big_oops_buf_sz is too big.
  change big_oops_buf_sz from psinfo->bufsize * 2 to psinfo->bufsize.
Changes in v3:
 -fix outlen in 842
Changes in v2:
 -fix checkpatch.pl WARNING:
  please write a paragraph that describes the config symbol fully
---
 fs/pstore/Kconfig|  25 +
 fs/pstore/platform.c | 147 ---
 2 files changed, 154 insertions(+), 18 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index b42e5bd6d8ff..cf97a3ecdce0 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -39,6 +39,31 @@ config PSTORE_LZ4_COMPRESS
 select LZ4_DECOMPRESS
 help
   This option enables LZ4 compression algorithm support.
+
+config PSTORE_LZ4HC_COMPRESS
+   bool "LZ4HC"
+   select LZ4HC_COMPRESS
+   select LZ4_DECOMPRESS
+   help
+ This option enables LZ4 high compression mode algorithm.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
+config PSTORE_842_COMPRESS
+   bool "842"
+   select 842_COMPRESS
+   select 842_DECOMPRESS
+   help
+ This option enables 842 compression algorithm support.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
 endchoice
 
 config PSTORE_CONSOLE
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index c3129b131e4d..19aaefeb052f 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,9 +34,12 @@
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#ifdef CONFIG_PSTORE_842_COMPRESS
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -336,6 +339,33 @@ static const struct pstore_zbackend backend_lzo = {
 };
 #endif
 
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
+static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_decompress_safe(in, out, inlen, outlen);
+   if (ret < 0) {
+   /*
+* LZ4_decompress_safe will return an error code
+* (< 0) if decompression failed
+*/
+   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   return -EIO;
+   }
+
+   return ret;
+}
+
+static void free_lz4(void)
+{
+   kfree(workspace);
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   big_oops_buf_sz = 0;
+}
+#endif
+
 #ifdef CONFIG_PSTORE_LZ4_COMPRESS
 static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
 {
@@ -350,29 +380,54 @@ static int compress_lz4(const void *in, void *out, size_t 
inlen, size_t outlen)
return ret;
 }
 
-static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+static void allocate_lz4(void)
+{
+   big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize);
+   big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
+   if (big_oops_buf) {
+   workspace = kmalloc(LZ4_MEM_COMPRESS, GFP_KERNEL);
+   if (!workspace) {
+   pr_err("No memory for compression workspace; skipping 
compression\n");
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   }
+   } else {
+   pr_err("No memory for uncompressed data; skipping 
compression\n");
+   workspace = NULL;
+   }
+}
+
+static const struct pstore_zbackend backend_lz4 = {
+   .compress   = compress_lz4,
+   .decompress = decompress_lz4,
+   .allocate   = allocate_lz4,
+   .free   = free_lz4,
+   .name   = "lz4",
+};
+#endif
+
+#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
+static int compress_lz4hc(const void *in, void *out,
+ size_t inlen, size_t outlen)
 {
int ret;
 
-   ret = LZ4_decompress_safe(in, out, inlen, outlen);
-   if (ret < 0) {
-   /*
-* LZ4_decompress_safe will return an error code
-* (< 0) if decompression failed
-*/
-   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   ret = LZ4_compress_HC(in, out, inlen, outlen,
+ LZ4HC_DEFAULT_CLEVEL, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_HC error; compression failed!\n");
return -EIO;

[PATCH v3] pstore: add lz4hc and 842 compression support

2018-02-11 Thread Geliang Tang
Currently, pstore has supported three compression algorithms: zlib,
lzo and lz4. This patch added two more compression algorithms: lz4hc
and 842.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
Changes in v3:
 -fix outlen in 842
Changes in v2:
 -fix checkpatch.pl WARNING:
  please write a paragraph that describes the config symbol fully
---
 fs/pstore/Kconfig|  25 +
 fs/pstore/platform.c | 147 ---
 2 files changed, 154 insertions(+), 18 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index b42e5bd6d8ff..cf97a3ecdce0 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -39,6 +39,31 @@ config PSTORE_LZ4_COMPRESS
 select LZ4_DECOMPRESS
 help
   This option enables LZ4 compression algorithm support.
+
+config PSTORE_LZ4HC_COMPRESS
+   bool "LZ4HC"
+   select LZ4HC_COMPRESS
+   select LZ4_DECOMPRESS
+   help
+ This option enables LZ4 high compression mode algorithm.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
+config PSTORE_842_COMPRESS
+   bool "842"
+   select 842_COMPRESS
+   select 842_DECOMPRESS
+   help
+ This option enables 842 compression algorithm support.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
 endchoice
 
 config PSTORE_CONSOLE
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 2b21d180157c..a573708f74f8 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,9 +34,12 @@
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#ifdef CONFIG_PSTORE_842_COMPRESS
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -337,6 +340,33 @@ static const struct pstore_zbackend backend_lzo = {
 };
 #endif
 
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
+static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_decompress_safe(in, out, inlen, outlen);
+   if (ret < 0) {
+   /*
+* LZ4_decompress_safe will return an error code
+* (< 0) if decompression failed
+*/
+   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   return -EIO;
+   }
+
+   return ret;
+}
+
+static void free_lz4(void)
+{
+   kfree(workspace);
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   big_oops_buf_sz = 0;
+}
+#endif
+
 #ifdef CONFIG_PSTORE_LZ4_COMPRESS
 static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
 {
@@ -351,29 +381,54 @@ static int compress_lz4(const void *in, void *out, size_t 
inlen, size_t outlen)
return ret;
 }
 
-static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+static void allocate_lz4(void)
+{
+   big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize);
+   big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
+   if (big_oops_buf) {
+   workspace = kmalloc(LZ4_MEM_COMPRESS, GFP_KERNEL);
+   if (!workspace) {
+   pr_err("No memory for compression workspace; skipping 
compression\n");
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   }
+   } else {
+   pr_err("No memory for uncompressed data; skipping 
compression\n");
+   workspace = NULL;
+   }
+}
+
+static const struct pstore_zbackend backend_lz4 = {
+   .compress   = compress_lz4,
+   .decompress = decompress_lz4,
+   .allocate   = allocate_lz4,
+   .free   = free_lz4,
+   .name   = "lz4",
+};
+#endif
+
+#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
+static int compress_lz4hc(const void *in, void *out,
+ size_t inlen, size_t outlen)
 {
int ret;
 
-   ret = LZ4_decompress_safe(in, out, inlen, outlen);
-   if (ret < 0) {
-   /*
-* LZ4_decompress_safe will return an error code
-* (< 0) if decompression failed
-*/
-   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   ret = LZ4_compress_HC(in, out, inlen, outlen,
+ LZ4HC_DEFAULT_CLEVEL, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_HC error; compression failed!\n");
return -EIO;
}
 
return ret;
 }
 
-static void allocate_lz4(void)
+static void allocate_lz4hc(void)
 {
big_oops_bu

Re: [PATCH] pstore: add lz4hc and 842 compression support

2018-02-11 Thread Geliang Tang
On Tue, Nov 28, 2017 at 05:44:52PM -0800, Kees Cook wrote:
> > +
> > +   ret = LZ4_compress_default(in, out, inlen, outlen, workspace);
> > +   if (!ret) {
> > +   pr_err("LZ4_compress_default error; compression failed!\n");
> > +   return -EIO;
> > +   }
> > +
> > +   return ret;
> 
> Other compress/decompress return outlen, rather than ret. Is "ret" the
> outlen here?
> 

> > +
> > +   ret = LZ4_compress_HC(in, out, inlen, outlen,
> > + LZ4HC_DEFAULT_CLEVEL, workspace);
> > +   if (!ret) {
> > +   pr_err("LZ4_compress_HC error; compression failed!\n");
> > +   return -EIO;
> > +   }
> > +
> > +   return ret;
> 
> And here?
> 

Yes, ret is outlen in LZ4_compress_default and LZ4_compress_HC.

> > +
> > +   ret = sw842_compress(in, inlen, out, , workspace);
> > +   if (!ret) {
> > +   pr_err("sw842_compress error; compression failed!\n");
> > +   return -EIO;
> > +   }
> > +   outlen = len;
> 
> This has no effect. What was intended?
> 

> > +   ret = sw842_decompress(in, inlen, out, );
> > +   if (ret < 0) {
> > +   pr_err("sw842_decompress error, ret = %d!\n", ret);
> > +   return -EIO;
> > +   }
> > +   outlen = len;
> 
> Same.
> 

I fixed them in patch v3.

> 
> Otherwise this all looks good. Thanks!
> 
> -Kees
> 
> -- 
> Kees Cook
> Pixel Security

Geliang Tang (1):
  pstore: add lz4hc and 842 compression support

 fs/pstore/Kconfig|  25 +
 fs/pstore/platform.c | 147 ---
 2 files changed, 154 insertions(+), 18 deletions(-)

-- 
2.14.1



[PATCH v3] pstore: add lz4hc and 842 compression support

2018-02-11 Thread Geliang Tang
Currently, pstore has supported three compression algorithms: zlib,
lzo and lz4. This patch added two more compression algorithms: lz4hc
and 842.

Signed-off-by: Geliang Tang 
---
Changes in v3:
 -fix outlen in 842
Changes in v2:
 -fix checkpatch.pl WARNING:
  please write a paragraph that describes the config symbol fully
---
 fs/pstore/Kconfig|  25 +
 fs/pstore/platform.c | 147 ---
 2 files changed, 154 insertions(+), 18 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index b42e5bd6d8ff..cf97a3ecdce0 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -39,6 +39,31 @@ config PSTORE_LZ4_COMPRESS
 select LZ4_DECOMPRESS
 help
   This option enables LZ4 compression algorithm support.
+
+config PSTORE_LZ4HC_COMPRESS
+   bool "LZ4HC"
+   select LZ4HC_COMPRESS
+   select LZ4_DECOMPRESS
+   help
+ This option enables LZ4 high compression mode algorithm.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
+config PSTORE_842_COMPRESS
+   bool "842"
+   select 842_COMPRESS
+   select 842_DECOMPRESS
+   help
+ This option enables 842 compression algorithm support.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
 endchoice
 
 config PSTORE_CONSOLE
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 2b21d180157c..a573708f74f8 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,9 +34,12 @@
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#ifdef CONFIG_PSTORE_842_COMPRESS
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -337,6 +340,33 @@ static const struct pstore_zbackend backend_lzo = {
 };
 #endif
 
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
+static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_decompress_safe(in, out, inlen, outlen);
+   if (ret < 0) {
+   /*
+* LZ4_decompress_safe will return an error code
+* (< 0) if decompression failed
+*/
+   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   return -EIO;
+   }
+
+   return ret;
+}
+
+static void free_lz4(void)
+{
+   kfree(workspace);
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   big_oops_buf_sz = 0;
+}
+#endif
+
 #ifdef CONFIG_PSTORE_LZ4_COMPRESS
 static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
 {
@@ -351,29 +381,54 @@ static int compress_lz4(const void *in, void *out, size_t 
inlen, size_t outlen)
return ret;
 }
 
-static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
+static void allocate_lz4(void)
+{
+   big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize);
+   big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
+   if (big_oops_buf) {
+   workspace = kmalloc(LZ4_MEM_COMPRESS, GFP_KERNEL);
+   if (!workspace) {
+   pr_err("No memory for compression workspace; skipping 
compression\n");
+   kfree(big_oops_buf);
+   big_oops_buf = NULL;
+   }
+   } else {
+   pr_err("No memory for uncompressed data; skipping 
compression\n");
+   workspace = NULL;
+   }
+}
+
+static const struct pstore_zbackend backend_lz4 = {
+   .compress   = compress_lz4,
+   .decompress = decompress_lz4,
+   .allocate   = allocate_lz4,
+   .free   = free_lz4,
+   .name   = "lz4",
+};
+#endif
+
+#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
+static int compress_lz4hc(const void *in, void *out,
+ size_t inlen, size_t outlen)
 {
int ret;
 
-   ret = LZ4_decompress_safe(in, out, inlen, outlen);
-   if (ret < 0) {
-   /*
-* LZ4_decompress_safe will return an error code
-* (< 0) if decompression failed
-*/
-   pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
+   ret = LZ4_compress_HC(in, out, inlen, outlen,
+ LZ4HC_DEFAULT_CLEVEL, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_HC error; compression failed!\n");
return -EIO;
}
 
return ret;
 }
 
-static void allocate_lz4(void)
+static void allocate_lz4hc(void)
 {
big_oops_buf_sz = LZ4_compressBound(psinfo-&

Re: [PATCH] pstore: add lz4hc and 842 compression support

2018-02-11 Thread Geliang Tang
On Tue, Nov 28, 2017 at 05:44:52PM -0800, Kees Cook wrote:
> > +
> > +   ret = LZ4_compress_default(in, out, inlen, outlen, workspace);
> > +   if (!ret) {
> > +   pr_err("LZ4_compress_default error; compression failed!\n");
> > +   return -EIO;
> > +   }
> > +
> > +   return ret;
> 
> Other compress/decompress return outlen, rather than ret. Is "ret" the
> outlen here?
> 

> > +
> > +   ret = LZ4_compress_HC(in, out, inlen, outlen,
> > + LZ4HC_DEFAULT_CLEVEL, workspace);
> > +   if (!ret) {
> > +   pr_err("LZ4_compress_HC error; compression failed!\n");
> > +   return -EIO;
> > +   }
> > +
> > +   return ret;
> 
> And here?
> 

Yes, ret is outlen in LZ4_compress_default and LZ4_compress_HC.

> > +
> > +   ret = sw842_compress(in, inlen, out, , workspace);
> > +   if (!ret) {
> > +   pr_err("sw842_compress error; compression failed!\n");
> > +   return -EIO;
> > +   }
> > +   outlen = len;
> 
> This has no effect. What was intended?
> 

> > +   ret = sw842_decompress(in, inlen, out, );
> > +   if (ret < 0) {
> > +   pr_err("sw842_decompress error, ret = %d!\n", ret);
> > +   return -EIO;
> > +   }
> > +   outlen = len;
> 
> Same.
> 

I fixed them in patch v3.

> 
> Otherwise this all looks good. Thanks!
> 
> -Kees
> 
> -- 
> Kees Cook
> Pixel Security

Geliang Tang (1):
  pstore: add lz4hc and 842 compression support

 fs/pstore/Kconfig|  25 +
 fs/pstore/platform.c | 147 ---
 2 files changed, 154 insertions(+), 18 deletions(-)

-- 
2.14.1



[PATCH v2] pstore: add lz4hc and 842 compression support

2017-11-01 Thread Geliang Tang
From: Geliang Tang <geliangt...@gmail.com>

Currently, pstore has supported three compression algorithms: zlib,
lzo and lz4. This patch added two more compression algorithms: lz4hc
and 842.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
Changes in v2:
 fix checkpatch.pl WARNING:
 please write a paragraph that describes the config symbol fully
---
 fs/pstore/Kconfig|  25 ++
 fs/pstore/platform.c | 128 +--
 2 files changed, 138 insertions(+), 15 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index b42e5bd..cf97a3e 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -39,6 +39,31 @@ config PSTORE_LZ4_COMPRESS
 select LZ4_DECOMPRESS
 help
   This option enables LZ4 compression algorithm support.
+
+config PSTORE_LZ4HC_COMPRESS
+   bool "LZ4HC"
+   select LZ4HC_COMPRESS
+   select LZ4_DECOMPRESS
+   help
+ This option enables LZ4 high compression mode algorithm.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
+config PSTORE_842_COMPRESS
+   bool "842"
+   select 842_COMPRESS
+   select 842_DECOMPRESS
+   help
+ This option enables 842 compression algorithm support.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
 endchoice
 
 config PSTORE_CONSOLE
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index ec7199e..def0210 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,9 +34,12 @@
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#ifdef CONFIG_PSTORE_842_COMPRESS
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -337,20 +340,7 @@ static const struct pstore_zbackend backend_lzo = {
 };
 #endif
 
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
-static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
-{
-   int ret;
-
-   ret = LZ4_compress_default(in, out, inlen, outlen, workspace);
-   if (!ret) {
-   pr_err("LZ4_compress_default error; compression failed!\n");
-   return -EIO;
-   }
-
-   return ret;
-}
-
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
 {
int ret;
@@ -392,6 +382,21 @@ static void free_lz4(void)
big_oops_buf = NULL;
big_oops_buf_sz = 0;
 }
+#endif
+
+#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_compress_default(in, out, inlen, outlen, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_default error; compression failed!\n");
+   return -EIO;
+   }
+
+   return ret;
+}
 
 static const struct pstore_zbackend backend_lz4 = {
.compress   = compress_lz4,
@@ -402,6 +407,95 @@ static const struct pstore_zbackend backend_lz4 = {
 };
 #endif
 
+#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
+static int compress_lz4hc(const void *in, void *out,
+ size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_compress_HC(in, out, inlen, outlen,
+ LZ4HC_DEFAULT_CLEVEL, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_HC error; compression failed!\n");
+   return -EIO;
+   }
+
+   return ret;
+}
+
+static const struct pstore_zbackend backend_lz4hc = {
+   .compress   = compress_lz4hc,
+   .decompress = decompress_lz4,
+   .allocate   = allocate_lz4,
+   .free   = free_lz4,
+   .name   = "lz4hc",
+};
+#endif
+
+#ifdef CONFIG_PSTORE_842_COMPRESS
+static int compress_842(const void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+   unsigned int len;
+
+   ret = sw842_compress(in, inlen, out, , workspace);
+   if (!ret) {
+   pr_err("sw842_compress error; compression failed!\n");
+   return -EIO;
+   }
+   outlen = len;
+
+   return ret;
+}
+
+static int decompress_842(void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+   unsigned int len;
+
+   ret = sw842_decompress(in, inlen, out, );
+   if (ret < 0) {
+   pr_err("sw842_decompress error, ret = %d!\n", ret);
+   return -EIO;
+   }
+   outlen = len;
+
+   return ret;
+}
+
+static void allocate_842(void)
+{
+   big_oops_buf_sz = psinfo->bufsize * 2;
+   big_oops_buf = kma

[PATCH v2] pstore: add lz4hc and 842 compression support

2017-11-01 Thread Geliang Tang
From: Geliang Tang 

Currently, pstore has supported three compression algorithms: zlib,
lzo and lz4. This patch added two more compression algorithms: lz4hc
and 842.

Signed-off-by: Geliang Tang 
---
Changes in v2:
 fix checkpatch.pl WARNING:
 please write a paragraph that describes the config symbol fully
---
 fs/pstore/Kconfig|  25 ++
 fs/pstore/platform.c | 128 +--
 2 files changed, 138 insertions(+), 15 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index b42e5bd..cf97a3e 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -39,6 +39,31 @@ config PSTORE_LZ4_COMPRESS
 select LZ4_DECOMPRESS
 help
   This option enables LZ4 compression algorithm support.
+
+config PSTORE_LZ4HC_COMPRESS
+   bool "LZ4HC"
+   select LZ4HC_COMPRESS
+   select LZ4_DECOMPRESS
+   help
+ This option enables LZ4 high compression mode algorithm.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
+config PSTORE_842_COMPRESS
+   bool "842"
+   select 842_COMPRESS
+   select 842_DECOMPRESS
+   help
+ This option enables 842 compression algorithm support.
+
+ Currently, pstore has supported five compression algorithms:
+ zlib, lzo, lz4, lz4hc and 842.
+
+ The default compression algorithm is zlib.
+
 endchoice
 
 config PSTORE_CONSOLE
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index ec7199e..def0210 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,9 +34,12 @@
 #ifdef CONFIG_PSTORE_LZO_COMPRESS
 #include 
 #endif
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 #include 
 #endif
+#ifdef CONFIG_PSTORE_842_COMPRESS
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -337,20 +340,7 @@ static const struct pstore_zbackend backend_lzo = {
 };
 #endif
 
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS
-static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
-{
-   int ret;
-
-   ret = LZ4_compress_default(in, out, inlen, outlen, workspace);
-   if (!ret) {
-   pr_err("LZ4_compress_default error; compression failed!\n");
-   return -EIO;
-   }
-
-   return ret;
-}
-
+#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || 
defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
 static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)
 {
int ret;
@@ -392,6 +382,21 @@ static void free_lz4(void)
big_oops_buf = NULL;
big_oops_buf_sz = 0;
 }
+#endif
+
+#ifdef CONFIG_PSTORE_LZ4_COMPRESS
+static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_compress_default(in, out, inlen, outlen, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_default error; compression failed!\n");
+   return -EIO;
+   }
+
+   return ret;
+}
 
 static const struct pstore_zbackend backend_lz4 = {
.compress   = compress_lz4,
@@ -402,6 +407,95 @@ static const struct pstore_zbackend backend_lz4 = {
 };
 #endif
 
+#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
+static int compress_lz4hc(const void *in, void *out,
+ size_t inlen, size_t outlen)
+{
+   int ret;
+
+   ret = LZ4_compress_HC(in, out, inlen, outlen,
+ LZ4HC_DEFAULT_CLEVEL, workspace);
+   if (!ret) {
+   pr_err("LZ4_compress_HC error; compression failed!\n");
+   return -EIO;
+   }
+
+   return ret;
+}
+
+static const struct pstore_zbackend backend_lz4hc = {
+   .compress   = compress_lz4hc,
+   .decompress = decompress_lz4,
+   .allocate   = allocate_lz4,
+   .free   = free_lz4,
+   .name   = "lz4hc",
+};
+#endif
+
+#ifdef CONFIG_PSTORE_842_COMPRESS
+static int compress_842(const void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+   unsigned int len;
+
+   ret = sw842_compress(in, inlen, out, , workspace);
+   if (!ret) {
+   pr_err("sw842_compress error; compression failed!\n");
+   return -EIO;
+   }
+   outlen = len;
+
+   return ret;
+}
+
+static int decompress_842(void *in, void *out, size_t inlen, size_t outlen)
+{
+   int ret;
+   unsigned int len;
+
+   ret = sw842_decompress(in, inlen, out, );
+   if (ret < 0) {
+   pr_err("sw842_decompress error, ret = %d!\n", ret);
+   return -EIO;
+   }
+   outlen = len;
+
+   return ret;
+}
+
+static void allocate_842(void)
+{
+   big_oops_buf_sz = psinfo->bufsize * 2;
+   big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
+   

  1   2   3   4   5   6   7   8   9   10   >