mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 03:10:12 +00:00
![Taehee Yoo](/assets/img/avatar_default.png)
vfnum buffer size and binary_len buffer size is received by user-space. So, this buffer size could be too large. If so, kmalloc will internally print a warning message. This warning message is actually not necessary for the netdevsim module. So, this patch adds __GFP_NOWARN. Test commands: modprobe netdevsim echo 1 > /sys/bus/netdevsim/new_device echo 1000000000 > /sys/devices/netdevsim1/sriov_numvfs Splat looks like: [ 357.847266][ T1000] WARNING: CPU: 0 PID: 1000 at mm/page_alloc.c:4738 __alloc_pages_nodemask+0x2f3/0x740 [ 357.850273][ T1000] Modules linked in: netdevsim veth openvswitch nsh nf_conncount nf_nat nf_conntrack nf_defrx [ 357.852989][ T1000] CPU: 0 PID: 1000 Comm: bash Tainted: G B 5.5.0-rc5+ #270 [ 357.854334][ T1000] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 357.855703][ T1000] RIP: 0010:__alloc_pages_nodemask+0x2f3/0x740 [ 357.856669][ T1000] Code: 64 fe ff ff 65 48 8b 04 25 c0 0f 02 00 48 05 f0 12 00 00 41 be 01 00 00 00 49 89 47 0 [ 357.860272][ T1000] RSP: 0018:ffff8880b7f47bd8 EFLAGS: 00010246 [ 357.861009][ T1000] RAX: ffffed1016fe8f80 RBX: 1ffff11016fe8fae RCX: 0000000000000000 [ 357.861843][ T1000] RDX: 0000000000000000 RSI: 0000000000000017 RDI: 0000000000000000 [ 357.862661][ T1000] RBP: 0000000000040dc0 R08: 1ffff11016fe8f67 R09: dffffc0000000000 [ 357.863509][ T1000] R10: ffff8880b7f47d68 R11: fffffbfff2798180 R12: 1ffff11016fe8f80 [ 357.864355][ T1000] R13: 0000000000000017 R14: 0000000000000017 R15: ffff8880c2038d68 [ 357.865178][ T1000] FS: 00007fd9a5b8c740(0000) GS:ffff8880d9c00000(0000) knlGS:0000000000000000 [ 357.866248][ T1000] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 357.867531][ T1000] CR2: 000055ce01ba8100 CR3: 00000000b7dbe005 CR4: 00000000000606f0 [ 357.868972][ T1000] Call Trace: [ 357.869423][ T1000] ? lock_contended+0xcd0/0xcd0 [ 357.870001][ T1000] ? __alloc_pages_slowpath+0x21d0/0x21d0 [ 357.870673][ T1000] ? _kstrtoull+0x76/0x160 [ 357.871148][ T1000] ? alloc_pages_current+0xc1/0x1a0 [ 357.871704][ T1000] kmalloc_order+0x22/0x80 [ 357.872184][ T1000] kmalloc_order_trace+0x1d/0x140 [ 357.872733][ T1000] __kmalloc+0x302/0x3a0 [ 357.873204][ T1000] nsim_bus_dev_numvfs_store+0x1ab/0x260 [netdevsim] [ 357.873919][ T1000] ? kernfs_get_active+0x12c/0x180 [ 357.874459][ T1000] ? new_device_store+0x450/0x450 [netdevsim] [ 357.875111][ T1000] ? kernfs_get_parent+0x70/0x70 [ 357.875632][ T1000] ? sysfs_file_ops+0x160/0x160 [ 357.876152][ T1000] kernfs_fop_write+0x276/0x410 [ 357.876680][ T1000] ? __sb_start_write+0x1ba/0x2e0 [ 357.877225][ T1000] vfs_write+0x197/0x4a0 [ 357.877671][ T1000] ksys_write+0x141/0x1d0 [ ... ] Reviewed-by: Jakub Kicinski <kuba@kernel.org> Fixes:7957922056
("netdevsim: add SR-IOV functionality") Fixes:82c93a87bf
("netdevsim: implement couple of testing devlink health reporters") Signed-off-by: Taehee Yoo <ap420073@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
319 lines
7.9 KiB
C
319 lines
7.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
|
|
|
|
#include <linux/debugfs.h>
|
|
#include <linux/err.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include "netdevsim.h"
|
|
|
|
static int
|
|
nsim_dev_empty_reporter_dump(struct devlink_health_reporter *reporter,
|
|
struct devlink_fmsg *fmsg, void *priv_ctx,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
nsim_dev_empty_reporter_diagnose(struct devlink_health_reporter *reporter,
|
|
struct devlink_fmsg *fmsg,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static const
|
|
struct devlink_health_reporter_ops nsim_dev_empty_reporter_ops = {
|
|
.name = "empty",
|
|
.dump = nsim_dev_empty_reporter_dump,
|
|
.diagnose = nsim_dev_empty_reporter_diagnose,
|
|
};
|
|
|
|
struct nsim_dev_dummy_reporter_ctx {
|
|
char *break_msg;
|
|
};
|
|
|
|
static int
|
|
nsim_dev_dummy_reporter_recover(struct devlink_health_reporter *reporter,
|
|
void *priv_ctx,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
|
|
struct nsim_dev_dummy_reporter_ctx *ctx = priv_ctx;
|
|
|
|
if (health->fail_recover) {
|
|
/* For testing purposes, user set debugfs fail_recover
|
|
* value to true. Fail right away.
|
|
*/
|
|
NL_SET_ERR_MSG_MOD(extack, "User setup the recover to fail for testing purposes");
|
|
return -EINVAL;
|
|
}
|
|
if (ctx) {
|
|
kfree(health->recovered_break_msg);
|
|
health->recovered_break_msg = kstrdup(ctx->break_msg,
|
|
GFP_KERNEL);
|
|
if (!health->recovered_break_msg)
|
|
return -ENOMEM;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int nsim_dev_dummy_fmsg_put(struct devlink_fmsg *fmsg, u32 binary_len)
|
|
{
|
|
char *binary;
|
|
int err;
|
|
int i;
|
|
|
|
err = devlink_fmsg_bool_pair_put(fmsg, "test_bool", true);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_u8_pair_put(fmsg, "test_u8", 1);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_u32_pair_put(fmsg, "test_u32", 3);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_u64_pair_put(fmsg, "test_u64", 4);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_string_pair_put(fmsg, "test_string", "somestring");
|
|
if (err)
|
|
return err;
|
|
|
|
binary = kmalloc(binary_len, GFP_KERNEL | __GFP_NOWARN);
|
|
if (!binary)
|
|
return -ENOMEM;
|
|
get_random_bytes(binary, binary_len);
|
|
err = devlink_fmsg_binary_pair_put(fmsg, "test_binary", binary, binary_len);
|
|
kfree(binary);
|
|
if (err)
|
|
return err;
|
|
|
|
err = devlink_fmsg_pair_nest_start(fmsg, "test_nest");
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_obj_nest_start(fmsg);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_bool_pair_put(fmsg, "nested_test_bool", false);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_u8_pair_put(fmsg, "nested_test_u8", false);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_obj_nest_end(fmsg);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_pair_nest_end(fmsg);
|
|
if (err)
|
|
return err;
|
|
|
|
err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_bool_array");
|
|
if (err)
|
|
return err;
|
|
for (i = 0; i < 10; i++) {
|
|
err = devlink_fmsg_bool_put(fmsg, true);
|
|
if (err)
|
|
return err;
|
|
}
|
|
err = devlink_fmsg_arr_pair_nest_end(fmsg);
|
|
if (err)
|
|
return err;
|
|
|
|
err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_u8_array");
|
|
if (err)
|
|
return err;
|
|
for (i = 0; i < 10; i++) {
|
|
err = devlink_fmsg_u8_put(fmsg, i);
|
|
if (err)
|
|
return err;
|
|
}
|
|
err = devlink_fmsg_arr_pair_nest_end(fmsg);
|
|
if (err)
|
|
return err;
|
|
|
|
err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_u32_array");
|
|
if (err)
|
|
return err;
|
|
for (i = 0; i < 10; i++) {
|
|
err = devlink_fmsg_u32_put(fmsg, i);
|
|
if (err)
|
|
return err;
|
|
}
|
|
err = devlink_fmsg_arr_pair_nest_end(fmsg);
|
|
if (err)
|
|
return err;
|
|
|
|
err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_u64_array");
|
|
if (err)
|
|
return err;
|
|
for (i = 0; i < 10; i++) {
|
|
err = devlink_fmsg_u64_put(fmsg, i);
|
|
if (err)
|
|
return err;
|
|
}
|
|
err = devlink_fmsg_arr_pair_nest_end(fmsg);
|
|
if (err)
|
|
return err;
|
|
|
|
err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_array_of_objects");
|
|
if (err)
|
|
return err;
|
|
for (i = 0; i < 10; i++) {
|
|
err = devlink_fmsg_obj_nest_start(fmsg);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_bool_pair_put(fmsg,
|
|
"in_array_nested_test_bool",
|
|
false);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_u8_pair_put(fmsg,
|
|
"in_array_nested_test_u8",
|
|
i);
|
|
if (err)
|
|
return err;
|
|
err = devlink_fmsg_obj_nest_end(fmsg);
|
|
if (err)
|
|
return err;
|
|
}
|
|
return devlink_fmsg_arr_pair_nest_end(fmsg);
|
|
}
|
|
|
|
static int
|
|
nsim_dev_dummy_reporter_dump(struct devlink_health_reporter *reporter,
|
|
struct devlink_fmsg *fmsg, void *priv_ctx,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
|
|
struct nsim_dev_dummy_reporter_ctx *ctx = priv_ctx;
|
|
int err;
|
|
|
|
if (ctx) {
|
|
err = devlink_fmsg_string_pair_put(fmsg, "break_message",
|
|
ctx->break_msg);
|
|
if (err)
|
|
return err;
|
|
}
|
|
return nsim_dev_dummy_fmsg_put(fmsg, health->binary_len);
|
|
}
|
|
|
|
static int
|
|
nsim_dev_dummy_reporter_diagnose(struct devlink_health_reporter *reporter,
|
|
struct devlink_fmsg *fmsg,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
|
|
int err;
|
|
|
|
if (health->recovered_break_msg) {
|
|
err = devlink_fmsg_string_pair_put(fmsg,
|
|
"recovered_break_message",
|
|
health->recovered_break_msg);
|
|
if (err)
|
|
return err;
|
|
}
|
|
return nsim_dev_dummy_fmsg_put(fmsg, health->binary_len);
|
|
}
|
|
|
|
static const
|
|
struct devlink_health_reporter_ops nsim_dev_dummy_reporter_ops = {
|
|
.name = "dummy",
|
|
.recover = nsim_dev_dummy_reporter_recover,
|
|
.dump = nsim_dev_dummy_reporter_dump,
|
|
.diagnose = nsim_dev_dummy_reporter_diagnose,
|
|
};
|
|
|
|
static ssize_t nsim_dev_health_break_write(struct file *file,
|
|
const char __user *data,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct nsim_dev_health *health = file->private_data;
|
|
struct nsim_dev_dummy_reporter_ctx ctx;
|
|
char *break_msg;
|
|
int err;
|
|
|
|
break_msg = kmalloc(count + 1, GFP_KERNEL);
|
|
if (!break_msg)
|
|
return -ENOMEM;
|
|
|
|
if (copy_from_user(break_msg, data, count)) {
|
|
err = -EFAULT;
|
|
goto out;
|
|
}
|
|
break_msg[count] = '\0';
|
|
if (break_msg[count - 1] == '\n')
|
|
break_msg[count - 1] = '\0';
|
|
|
|
ctx.break_msg = break_msg;
|
|
err = devlink_health_report(health->dummy_reporter, break_msg, &ctx);
|
|
if (err)
|
|
goto out;
|
|
|
|
out:
|
|
kfree(break_msg);
|
|
return err ?: count;
|
|
}
|
|
|
|
static const struct file_operations nsim_dev_health_break_fops = {
|
|
.open = simple_open,
|
|
.write = nsim_dev_health_break_write,
|
|
.llseek = generic_file_llseek,
|
|
};
|
|
|
|
int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink)
|
|
{
|
|
struct nsim_dev_health *health = &nsim_dev->health;
|
|
int err;
|
|
|
|
health->empty_reporter =
|
|
devlink_health_reporter_create(devlink,
|
|
&nsim_dev_empty_reporter_ops,
|
|
0, false, health);
|
|
if (IS_ERR(health->empty_reporter))
|
|
return PTR_ERR(health->empty_reporter);
|
|
|
|
health->dummy_reporter =
|
|
devlink_health_reporter_create(devlink,
|
|
&nsim_dev_dummy_reporter_ops,
|
|
0, false, health);
|
|
if (IS_ERR(health->dummy_reporter)) {
|
|
err = PTR_ERR(health->dummy_reporter);
|
|
goto err_empty_reporter_destroy;
|
|
}
|
|
|
|
health->ddir = debugfs_create_dir("health", nsim_dev->ddir);
|
|
if (IS_ERR(health->ddir)) {
|
|
err = PTR_ERR(health->ddir);
|
|
goto err_dummy_reporter_destroy;
|
|
}
|
|
|
|
health->recovered_break_msg = NULL;
|
|
debugfs_create_file("break_health", 0200, health->ddir, health,
|
|
&nsim_dev_health_break_fops);
|
|
health->binary_len = 16;
|
|
debugfs_create_u32("binary_len", 0600, health->ddir,
|
|
&health->binary_len);
|
|
health->fail_recover = false;
|
|
debugfs_create_bool("fail_recover", 0600, health->ddir,
|
|
&health->fail_recover);
|
|
return 0;
|
|
|
|
err_dummy_reporter_destroy:
|
|
devlink_health_reporter_destroy(health->dummy_reporter);
|
|
err_empty_reporter_destroy:
|
|
devlink_health_reporter_destroy(health->empty_reporter);
|
|
return err;
|
|
}
|
|
|
|
void nsim_dev_health_exit(struct nsim_dev *nsim_dev)
|
|
{
|
|
struct nsim_dev_health *health = &nsim_dev->health;
|
|
|
|
debugfs_remove_recursive(health->ddir);
|
|
kfree(health->recovered_break_msg);
|
|
devlink_health_reporter_destroy(health->dummy_reporter);
|
|
devlink_health_reporter_destroy(health->empty_reporter);
|
|
}
|