Operators need a way to limit how much memory cgroups use. User events need to be included into that accounting. Fix this by using GFP_KERNEL_ACCOUNT for allocations generated by user programs for user_event tracing. Link: https://lkml.kernel.org/r/20230328235219.203-11-beaub@linux.microsoft.com
Unified · Split
| @@ -442,7 +442,7 @@ static bool user_event_enabler_dup(struct user_event_enabler *orig, · 441 unmodified lines | ||
| 442 | 442 | if (unlikely(test_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(orig)))) |
| 443 | 443 | return true; |
| 444 | 444 | |
| 445 | − enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT); | |
| 445 | + enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT | __GFP_ACCOUNT); | |
| 446 | 446 | |
| 447 | 447 | if (!enabler) |
| 448 | 448 | return false; |
| @@ -502,7 +502,7 @@ static struct user_event_mm *user_event_mm_create(struct task_struct *t) · 53 unmodified lines | ||
| 502 | 502 | struct user_event_mm *user_mm; |
| 503 | 503 | unsigned long flags; |
| 504 | 504 | |
| 505 | − user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL); | |
| 505 | + user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL_ACCOUNT); | |
| 506 | 506 | |
| 507 | 507 | if (!user_mm) |
| 508 | 508 | return NULL; |
| @@ -662,7 +662,7 @@ static struct user_event_enabler · 153 unmodified lines | ||
| 662 | 662 | if (!user_mm) |
| 663 | 663 | return NULL; |
| 664 | 664 | |
| 665 | − enabler = kzalloc(sizeof(*enabler), GFP_KERNEL); | |
| 665 | + enabler = kzalloc(sizeof(*enabler), GFP_KERNEL_ACCOUNT); | |
| 666 | 666 | |
| 667 | 667 | if (!enabler) |
| 668 | 668 | goto out; |
| @@ -870,7 +870,7 @@ static int user_event_add_field(struct user_event *user, const char *type, · 201 unmodified lines | ||
| 870 | 870 | struct ftrace_event_field *field; |
| 871 | 871 | int validator_flags = 0; |
| 872 | 872 | |
| 873 | − field = kmalloc(sizeof(*field), GFP_KERNEL); | |
| 873 | + field = kmalloc(sizeof(*field), GFP_KERNEL_ACCOUNT); | |
| 874 | 874 | |
| 875 | 875 | if (!field) |
| 876 | 876 | return -ENOMEM; |
| @@ -889,7 +889,7 @@ add_validator: · 12 unmodified lines | ||
| 889 | 889 | if (strstr(type, "char") != NULL) |
| 890 | 890 | validator_flags |= VALIDATOR_ENSURE_NULL; |
| 891 | 891 | |
| 892 | − validator = kmalloc(sizeof(*validator), GFP_KERNEL); | |
| 892 | + validator = kmalloc(sizeof(*validator), GFP_KERNEL_ACCOUNT); | |
| 893 | 893 | |
| 894 | 894 | if (!validator) { |
| 895 | 895 | kfree(field); |
| @@ -1175,7 +1175,7 @@ static int user_event_create_print_fmt(struct user_event *user) · 279 unmodified lines | ||
| 1175 | 1175 | |
| 1176 | 1176 | len = user_event_set_print_fmt(user, NULL, 0); |
| 1177 | 1177 | |
| 1178 | − print_fmt = kmalloc(len, GFP_KERNEL); | |
| 1178 | + print_fmt = kmalloc(len, GFP_KERNEL_ACCOUNT); | |
| 1179 | 1179 | |
| 1180 | 1180 | if (!print_fmt) |
| 1181 | 1181 | return -ENOMEM; |
| @@ -1508,7 +1508,7 @@ static int user_event_create(const char *raw_command) · 326 unmodified lines | ||
| 1508 | 1508 | raw_command += USER_EVENTS_PREFIX_LEN; |
| 1509 | 1509 | raw_command = skip_spaces(raw_command); |
| 1510 | 1510 | |
| 1511 | − name = kstrdup(raw_command, GFP_KERNEL); | |
| 1511 | + name = kstrdup(raw_command, GFP_KERNEL_ACCOUNT); | |
| 1512 | 1512 | |
| 1513 | 1513 | if (!name) |
| 1514 | 1514 | return -ENOMEM; |
| @@ -1704,7 +1704,7 @@ static int user_event_parse(struct user_event_group *group, char *name, · 189 unmodified lines | ||
| 1704 | 1704 | return 0; |
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | − user = kzalloc(sizeof(*user), GFP_KERNEL); | |
| 1707 | + user = kzalloc(sizeof(*user), GFP_KERNEL_ACCOUNT); | |
| 1708 | 1708 | |
| 1709 | 1709 | if (!user) |
| 1710 | 1710 | return -ENOMEM; |
| @@ -1874,7 +1874,7 @@ static int user_events_open(struct inode *node, struct file *file) · 163 unmodified lines | ||
| 1874 | 1874 | if (!group) |
| 1875 | 1875 | return -ENOENT; |
| 1876 | 1876 | |
| 1877 | − info = kzalloc(sizeof(*info), GFP_KERNEL); | |
| 1877 | + info = kzalloc(sizeof(*info), GFP_KERNEL_ACCOUNT); | |
| 1878 | 1878 | |
| 1879 | 1879 | if (!info) |
| 1880 | 1880 | return -ENOMEM; |
| @@ -1927,7 +1927,7 @@ static int user_events_ref_add(struct user_event_file_info *info, · 46 unmodified lines | ||
| 1927 | 1927 | |
| 1928 | 1928 | size = struct_size(refs, events, count + 1); |
| 1929 | 1929 | |
| 1930 | − new_refs = kzalloc(size, GFP_KERNEL); | |
| 1930 | + new_refs = kzalloc(size, GFP_KERNEL_ACCOUNT); | |
| 1931 | 1931 | |
| 1932 | 1932 | if (!new_refs) |
| 1933 | 1933 | return -ENOMEM; |