Skip to content

Commit ac40916

Browse files
lrq-maxkuba-moo
authored andcommitted
rtnetlink: introduce nlmsg_new_large and use it in rtnl_getlink
if a PF has 256 or more VFs, ip link command will allocate an order 3 memory or more, and maybe trigger OOM due to memory fragment, the VFs needed memory size is computed in rtnl_vfinfo_size. so introduce nlmsg_new_large which calls netlink_alloc_large_skb in which vmalloc is used for large memory, to avoid the failure of allocating memory ip invoked oom-killer: gfp_mask=0xc2cc0(GFP_KERNEL|__GFP_NOWARN|\ __GFP_COMP|__GFP_NOMEMALLOC), order=3, oom_score_adj=0 CPU: 74 PID: 204414 Comm: ip Kdump: loaded Tainted: P OE Call Trace: dump_stack+0x57/0x6a dump_header+0x4a/0x210 oom_kill_process+0xe4/0x140 out_of_memory+0x3e8/0x790 __alloc_pages_slowpath.constprop.116+0x953/0xc50 __alloc_pages_nodemask+0x2af/0x310 kmalloc_large_node+0x38/0xf0 __kmalloc_node_track_caller+0x417/0x4d0 __kmalloc_reserve.isra.61+0x2e/0x80 __alloc_skb+0x82/0x1c0 rtnl_getlink+0x24f/0x370 rtnetlink_rcv_msg+0x12c/0x350 netlink_rcv_skb+0x50/0x100 netlink_unicast+0x1b2/0x280 netlink_sendmsg+0x355/0x4a0 sock_sendmsg+0x5b/0x60 ____sys_sendmsg+0x1ea/0x250 ___sys_sendmsg+0x88/0xd0 __sys_sendmsg+0x5e/0xa0 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f95a65a5b70 Cc: Yunsheng Lin <linyunsheng@huawei.com> Signed-off-by: Li RongQing <lirongqing@baidu.com> Link: https://lore.kernel.org/r/20231115120108.3711-1-lirongqing@baidu.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 459a70b commit ac40916

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

include/linux/netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,6 @@ bool netlink_ns_capable(const struct sk_buff *skb,
351351
struct user_namespace *ns, int cap);
352352
bool netlink_capable(const struct sk_buff *skb, int cap);
353353
bool netlink_net_capable(const struct sk_buff *skb, int cap);
354+
struct sk_buff *netlink_alloc_large_skb(unsigned int size, int broadcast);
354355

355356
#endif /* __LINUX_NETLINK_H */

include/net/netlink.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,20 @@ static inline struct sk_buff *nlmsg_new(size_t payload, gfp_t flags)
10101010
return alloc_skb(nlmsg_total_size(payload), flags);
10111011
}
10121012

1013+
/**
1014+
* nlmsg_new_large - Allocate a new netlink message with non-contiguous
1015+
* physical memory
1016+
* @payload: size of the message payload
1017+
*
1018+
* The allocated skb is unable to have frag page for shinfo->frags*,
1019+
* as the NULL setting for skb->head in netlink_skb_destructor() will
1020+
* bypass most of the handling in skb_release_data()
1021+
*/
1022+
static inline struct sk_buff *nlmsg_new_large(size_t payload)
1023+
{
1024+
return netlink_alloc_large_skb(nlmsg_total_size(payload), 0);
1025+
}
1026+
10131027
/**
10141028
* nlmsg_end - Finalize a netlink message
10151029
* @skb: socket buffer the message is stored in

net/core/rtnetlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3849,7 +3849,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
38493849
goto out;
38503850

38513851
err = -ENOBUFS;
3852-
nskb = nlmsg_new(if_nlmsg_size(dev, ext_filter_mask), GFP_KERNEL);
3852+
nskb = nlmsg_new_large(if_nlmsg_size(dev, ext_filter_mask));
38533853
if (nskb == NULL)
38543854
goto out;
38553855

net/netlink/af_netlink.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,7 @@ struct sock *netlink_getsockbyfilp(struct file *filp)
12041204
return sock;
12051205
}
12061206

1207-
static struct sk_buff *netlink_alloc_large_skb(unsigned int size,
1208-
int broadcast)
1207+
struct sk_buff *netlink_alloc_large_skb(unsigned int size, int broadcast)
12091208
{
12101209
struct sk_buff *skb;
12111210
void *data;

0 commit comments

Comments
 (0)