From 4747c75687073be0bf14f6665d72637d7176f9cf Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 2 Apr 2024 16:44:57 +0000 Subject: [PATCH 01/38] Reapply "ANDROID: null_blk: Support configuring the maximum segment size" This reverts commit 95d3e50fde4993d5631e83aa65414b98de24cb90. Bug: 308663717 Bug: 319125789 Cc: Bart Van Assche Cc: Juan Yescas Change-Id: Ib07f0e6c7fb3266ca7959aef6615f2daf5701665 Signed-off-by: Greg Kroah-Hartman --- drivers/block/null_blk/main.c | 19 ++++++++++++++++--- drivers/block/null_blk/null_blk.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 959952e8ede3..e245e8411e15 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -157,6 +157,10 @@ static int g_max_sectors; module_param_named(max_sectors, g_max_sectors, int, 0444); MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); +static unsigned int g_max_segment_size = BLK_MAX_SEGMENT_SIZE; +module_param_named(max_segment_size, g_max_segment_size, int, 0444); +MODULE_PARM_DESC(max_segment_size, "Maximum size of a segment in bytes"); + static unsigned int nr_devices = 1; module_param(nr_devices, uint, 0444); MODULE_PARM_DESC(nr_devices, "Number of devices to register"); @@ -409,6 +413,7 @@ NULLB_DEVICE_ATTR(home_node, uint, NULL); NULLB_DEVICE_ATTR(queue_mode, uint, NULL); NULLB_DEVICE_ATTR(blocksize, uint, NULL); NULLB_DEVICE_ATTR(max_sectors, uint, NULL); +NULLB_DEVICE_ATTR(max_segment_size, uint, NULL); NULLB_DEVICE_ATTR(irqmode, uint, NULL); NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL); NULLB_DEVICE_ATTR(index, uint, NULL); @@ -532,6 +537,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { &nullb_device_attr_queue_mode, &nullb_device_attr_blocksize, &nullb_device_attr_max_sectors, + &nullb_device_attr_max_segment_size, &nullb_device_attr_irqmode, &nullb_device_attr_hw_queue_depth, &nullb_device_attr_index, @@ -610,7 +616,8 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page) return snprintf(page, PAGE_SIZE, "badblocks,blocking,blocksize,cache_size," "completion_nsec,discard,home_node,hw_queue_depth," - "irqmode,max_sectors,mbps,memory_backed,no_sched," + "irqmode,max_sectors,max_segment_size,mbps," + "memory_backed,no_sched," "poll_queues,power,queue_mode,shared_tag_bitmap,size," "submit_queues,use_per_node_hctx,virt_boundary,zoned," "zone_capacity,zone_max_active,zone_max_open," @@ -673,6 +680,7 @@ static struct nullb_device *null_alloc_dev(void) dev->queue_mode = g_queue_mode; dev->blocksize = g_bs; dev->max_sectors = g_max_sectors; + dev->max_segment_size = g_max_segment_size; dev->irqmode = g_irqmode; dev->hw_queue_depth = g_hw_queue_depth; dev->blocking = g_blocking; @@ -1214,6 +1222,8 @@ static int null_transfer(struct nullb *nullb, struct page *page, unsigned int valid_len = len; int err = 0; + WARN_ONCE(len > dev->max_segment_size, "%u > %u\n", len, + dev->max_segment_size); if (!is_write) { if (dev->zoned) valid_len = null_zone_valid_read_len(nullb, @@ -1249,7 +1259,8 @@ static int null_handle_rq(struct nullb_cmd *cmd) spin_lock_irq(&nullb->lock); rq_for_each_segment(bvec, rq, iter) { - len = bvec.bv_len; + len = min(bvec.bv_len, nullb->dev->max_segment_size); + bvec.bv_len = len; err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, op_is_write(req_op(rq)), sector, rq->cmd_flags & REQ_FUA); @@ -1276,7 +1287,8 @@ static int null_handle_bio(struct nullb_cmd *cmd) spin_lock_irq(&nullb->lock); bio_for_each_segment(bvec, bio, iter) { - len = bvec.bv_len; + len = min(bvec.bv_len, nullb->dev->max_segment_size); + bvec.bv_len = len; err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, op_is_write(bio_op(bio)), sector, bio->bi_opf & REQ_FUA); @@ -2116,6 +2128,7 @@ static int null_add_dev(struct nullb_device *dev) blk_queue_physical_block_size(nullb->q, dev->blocksize); if (dev->max_sectors) blk_queue_max_hw_sectors(nullb->q, dev->max_sectors); + blk_queue_max_segment_size(nullb->q, dev->max_segment_size); if (dev->virt_boundary) blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1); diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 94ff68052b1e..6784ee9f5fda 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -102,6 +102,7 @@ struct nullb_device { unsigned int queue_mode; /* block interface */ unsigned int blocksize; /* block size */ unsigned int max_sectors; /* Max sectors per command */ + unsigned int max_segment_size; /* Max size of a single DMA segment. */ unsigned int irqmode; /* IRQ completion handler */ unsigned int hw_queue_depth; /* queue depth */ unsigned int index; /* index of the disk, only valid with a disk */ From baba019a000c8fb0182aea1ddb27cd57b6332e9d Mon Sep 17 00:00:00 2001 From: fengqi Date: Tue, 2 Apr 2024 18:43:13 +0800 Subject: [PATCH 02/38] ANDROID: GKI: update symbol list file for xiaomi 5 function symbol(s) added 'struct backlight_device* backlight_device_get_by_name(const char*)' 'void netdev_reset_tc(struct net_device*)' 'int netdev_set_num_tc(struct net_device*, u8)' 'int netdev_set_tc_queue(struct net_device*, u8, u16, u16)' 'int pci_sriov_set_totalvfs(struct pci_dev*, u16)' 1 variable symbol(s) added 'const struct udp_tunnel_nic_ops* udp_tunnel_nic_ops' Bug: 332479153 Change-Id: Ia8c886218eea2048df52bc3406ded44d4ed3ab66 Signed-off-by: fengqi --- android/abi_gki_aarch64.stg | 211 +++++++++++++++++++++++++++++++++ android/abi_gki_aarch64_xiaomi | 14 ++- 2 files changed, 224 insertions(+), 1 deletion(-) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index f9ec60375ec5..a8b38168e06a 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -5148,6 +5148,11 @@ pointer_reference { kind: POINTER pointee_type_id: 0x1c3eec85 } +pointer_reference { + id: 0x0d9fa351 + kind: POINTER + pointee_type_id: 0x1c3e6bd8 +} pointer_reference { id: 0x0da01896 kind: POINTER @@ -5458,6 +5463,16 @@ pointer_reference { kind: POINTER pointee_type_id: 0x1d33ca38 } +pointer_reference { + id: 0x0ddd9122 + kind: POINTER + pointee_type_id: 0x1d36a215 +} +pointer_reference { + id: 0x0dddbb92 + kind: POINTER + pointee_type_id: 0x1d3608d6 +} pointer_reference { id: 0x0dde65b8 kind: POINTER @@ -14183,6 +14198,11 @@ pointer_reference { kind: POINTER pointee_type_id: 0x9a8049e0 } +pointer_reference { + id: 0x2c302ca8 + kind: POINTER + pointee_type_id: 0x9a80543f +} pointer_reference { id: 0x2c312b62 kind: POINTER @@ -20043,6 +20063,11 @@ pointer_reference { kind: POINTER pointee_type_id: 0x903e851b } +pointer_reference { + id: 0x2e9fb2c1 + kind: POINTER + pointee_type_id: 0x903e2d98 +} pointer_reference { id: 0x2e9fe637 kind: POINTER @@ -24743,6 +24768,11 @@ pointer_reference { kind: POINTER pointee_type_id: 0xf9fcb2cf } +pointer_reference { + id: 0x34f747ff + kind: POINTER + pointee_type_id: 0xf99df961 +} pointer_reference { id: 0x3500e23a kind: POINTER @@ -35063,6 +35093,11 @@ qualified { qualifier: CONST qualified_type_id: 0x95a5decf } +qualified { + id: 0xf99df961 + qualifier: CONST + qualified_type_id: 0x9630530f +} qualified { id: 0xf9d1a7a0 qualifier: CONST @@ -44204,6 +44239,12 @@ member { type_id: 0x2c7e659b offset: 1152 } +member { + id: 0xfdc15727 + name: "add_port" + type_id: 0x0d9fa351 + offset: 128 +} member { id: 0x4dcf2c11 name: "add_producer" @@ -73090,6 +73131,12 @@ member { type_id: 0x0fa14b4c offset: 320 } +member { + id: 0x702151a1 + name: "del_port" + type_id: 0x0d9fa351 + offset: 192 +} member { id: 0x5e7ee5d3 name: "del_producer" @@ -80843,6 +80890,12 @@ member { type_id: 0x33756485 offset: 192 } +member { + id: 0xa072eefa + name: "dump_size" + type_id: 0x2c302ca8 + offset: 320 +} member { id: 0x031e119e name: "dump_stats" @@ -80867,6 +80920,12 @@ member { type_id: 0x0d21fdc9 offset: 1856 } +member { + id: 0x4cc2c45a + name: "dump_write" + type_id: 0x2e9fb2c1 + offset: 384 +} member { id: 0xfc3fad02 name: "dumper" @@ -96734,6 +96793,11 @@ member { type_id: 0x2ced7c4b offset: 1536 } +member { + id: 0x06a833a8 + name: "get_port" + type_id: 0x0ddd9122 +} member { id: 0xa9079cd6 name: "get_power_status" @@ -165802,6 +165866,12 @@ member { type_id: 0x629984b1 offset: 25984 } +member { + id: 0x7062211d + name: "reset_ntf" + type_id: 0x0d9c4ffe + offset: 256 +} member { id: 0x98c83941 name: "reset_pending" @@ -175535,6 +175605,12 @@ member { name: "set_port" type_id: 0x2e9bbd8d } +member { + id: 0x9a820b0d + name: "set_port_priv" + type_id: 0x0dddbb92 + offset: 64 +} member { id: 0x8086060a name: "set_power" @@ -262973,6 +263049,21 @@ struct_union { member_id: 0xb0bb615b } } +struct_union { + id: 0x9630530f + kind: STRUCT + name: "udp_tunnel_nic_ops" + definition { + bytesize: 56 + member_id: 0x06a833a8 + member_id: 0x9a820b0d + member_id: 0xfdc15727 + member_id: 0x702151a1 + member_id: 0x7062211d + member_id: 0xa072eefa + member_id: 0x4cc2c45a + } +} struct_union { id: 0xe832fb84 kind: STRUCT @@ -297707,6 +297798,12 @@ function { return_type_id: 0x48b5725f parameter_id: 0x32941b2b } +function { + id: 0x1c3e6bd8 + return_type_id: 0x48b5725f + parameter_id: 0x32a623d7 + parameter_id: 0x03ecaf94 +} function { id: 0x1c3eec85 return_type_id: 0x48b5725f @@ -298537,6 +298634,22 @@ function { parameter_id: 0x0258f96e parameter_id: 0x32bd639f } +function { + id: 0x1d3608d6 + return_type_id: 0x48b5725f + parameter_id: 0x32a623d7 + parameter_id: 0x4585663f + parameter_id: 0x4585663f + parameter_id: 0x295c7202 +} +function { + id: 0x1d36a215 + return_type_id: 0x48b5725f + parameter_id: 0x32a623d7 + parameter_id: 0x4585663f + parameter_id: 0x4585663f + parameter_id: 0x03ecaf94 +} function { id: 0x1d39707c return_type_id: 0x48b5725f @@ -305409,6 +305522,11 @@ function { parameter_id: 0x3a6574c9 parameter_id: 0x3bad809b } +function { + id: 0x733f53a5 + return_type_id: 0x309d6e18 + parameter_id: 0x3e10b518 +} function { id: 0x73531faf return_type_id: 0x92233392 @@ -307154,6 +307272,13 @@ function { parameter_id: 0x3411dbb1 parameter_id: 0x2e0f9112 } +function { + id: 0x903e2d98 + return_type_id: 0x6720d32f + parameter_id: 0x32a623d7 + parameter_id: 0x4585663f + parameter_id: 0x054f691a +} function { id: 0x903e8010 return_type_id: 0x6720d32f @@ -308694,6 +308819,12 @@ function { parameter_id: 0x32a623d7 parameter_id: 0x282d39ce } +function { + id: 0x918c1a12 + return_type_id: 0x6720d32f + parameter_id: 0x32a623d7 + parameter_id: 0x295c7202 +} function { id: 0x918cb258 return_type_id: 0x6720d32f @@ -308907,6 +309038,14 @@ function { parameter_id: 0x2a48f3d0 parameter_id: 0x4585663f } +function { + id: 0x91aa0c4b + return_type_id: 0x6720d32f + parameter_id: 0x32a623d7 + parameter_id: 0x295c7202 + parameter_id: 0x914dbfdc + parameter_id: 0x914dbfdc +} function { id: 0x91aa9fd5 return_type_id: 0x6720d32f @@ -318447,6 +318586,12 @@ function { parameter_id: 0x1d44326e parameter_id: 0x1469952b } +function { + id: 0x9a80543f + return_type_id: 0xf435685e + parameter_id: 0x32a623d7 + parameter_id: 0x4585663f +} function { id: 0x9a844b16 return_type_id: 0x6720d32f @@ -321887,6 +322032,12 @@ function { parameter_id: 0x11cffa09 parameter_id: 0x92233392 } +function { + id: 0x9bbc7443 + return_type_id: 0x6720d32f + parameter_id: 0x11e6864c + parameter_id: 0x914dbfdc +} function { id: 0x9bbcaaf0 return_type_id: 0x6720d32f @@ -347901,6 +348052,15 @@ elf_symbol { type_id: 0x1e18ac15 full_name: "avenrun" } +elf_symbol { + id: 0x0760f21e + name: "backlight_device_get_by_name" + is_defined: true + symbol_type: FUNCTION + crc: 0xbdffe5b8 + type_id: 0x733f53a5 + full_name: "backlight_device_get_by_name" +} elf_symbol { id: 0xb9c34cbd name: "backlight_device_get_by_type" @@ -376281,6 +376441,15 @@ elf_symbol { type_id: 0x1fdf0b41 full_name: "netdev_printk" } +elf_symbol { + id: 0x6c3e8f78 + name: "netdev_reset_tc" + is_defined: true + symbol_type: FUNCTION + crc: 0x13ed0551 + type_id: 0x1c31d966 + full_name: "netdev_reset_tc" +} elf_symbol { id: 0x22c60050 name: "netdev_rss_key_fill" @@ -376317,6 +376486,24 @@ elf_symbol { type_id: 0x1cd08481 full_name: "netdev_set_default_ethtool_ops" } +elf_symbol { + id: 0xd0f388bf + name: "netdev_set_num_tc" + is_defined: true + symbol_type: FUNCTION + crc: 0x1e03adf1 + type_id: 0x918c1a12 + full_name: "netdev_set_num_tc" +} +elf_symbol { + id: 0xc32be078 + name: "netdev_set_tc_queue" + is_defined: true + symbol_type: FUNCTION + crc: 0x4442f196 + type_id: 0x91aa0c4b + full_name: "netdev_set_tc_queue" +} elf_symbol { id: 0x13d32ab6 name: "netdev_state_change" @@ -380253,6 +380440,15 @@ elf_symbol { type_id: 0x998196f8 full_name: "pci_set_power_state" } +elf_symbol { + id: 0xab90cbbb + name: "pci_sriov_set_totalvfs" + is_defined: true + symbol_type: FUNCTION + crc: 0x32679a37 + type_id: 0x9bbc7443 + full_name: "pci_sriov_set_totalvfs" +} elf_symbol { id: 0xa321b388 name: "pci_stop_root_bus" @@ -396745,6 +396941,15 @@ elf_symbol { type_id: 0x99621666 full_name: "udp_tunnel6_xmit_skb" } +elf_symbol { + id: 0x7d720277 + name: "udp_tunnel_nic_ops" + is_defined: true + symbol_type: OBJECT + crc: 0x5f62b5af + type_id: 0x34f747ff + full_name: "udp_tunnel_nic_ops" +} elf_symbol { id: 0x7f7d27b4 name: "udp_tunnel_sock_release" @@ -405414,6 +405619,7 @@ interface { symbol_id: 0xd772fde3 symbol_id: 0x1abdc14f symbol_id: 0x3eb51b20 + symbol_id: 0x0760f21e symbol_id: 0xb9c34cbd symbol_id: 0x0bd7f049 symbol_id: 0xf54175ef @@ -408566,10 +408772,13 @@ interface { symbol_id: 0xd5ed1a09 symbol_id: 0xd78c295f symbol_id: 0xe42df14f + symbol_id: 0x6c3e8f78 symbol_id: 0x22c60050 symbol_id: 0x7a3d8713 symbol_id: 0xf7edefd1 symbol_id: 0xb78d7b09 + symbol_id: 0xd0f388bf + symbol_id: 0xc32be078 symbol_id: 0x13d32ab6 symbol_id: 0x88a6525c symbol_id: 0xa9b870ab @@ -409007,6 +409216,7 @@ interface { symbol_id: 0x9595d229 symbol_id: 0xfc86cde9 symbol_id: 0xe770d8d1 + symbol_id: 0xab90cbbb symbol_id: 0xa321b388 symbol_id: 0x958eb206 symbol_id: 0xd0c1e622 @@ -410840,6 +411050,7 @@ interface { symbol_id: 0x2259ac6a symbol_id: 0x3bea1d77 symbol_id: 0x83627eaa + symbol_id: 0x7d720277 symbol_id: 0x7f7d27b4 symbol_id: 0x674efb6f symbol_id: 0x3fa12248 diff --git a/android/abi_gki_aarch64_xiaomi b/android/abi_gki_aarch64_xiaomi index 60c623ce7db0..63104d8e367e 100644 --- a/android/abi_gki_aarch64_xiaomi +++ b/android/abi_gki_aarch64_xiaomi @@ -301,8 +301,9 @@ of_node_name_prefix bdi_unregister -#required by dispaly.ko +#required by msm_drm.ko mipi_dsi_dcs_set_display_off + backlight_device_get_by_name #required by debug_ext.ko of_find_all_nodes @@ -359,3 +360,14 @@ #required by speed_ui.ko __tracepoint_android_rvh_update_cpus_allowed __traceiter_android_rvh_update_cpus_allowed + +#required by brcm_xgbe.ko + cpumask_local_spread + udp_tunnel_nic_ops + netdev_reset_tc + netdev_set_num_tc + netdev_set_tc_queue + pci_select_bars + pci_sriov_set_totalvfs + pci_num_vf + From dcdec80d6bb8a786f5d5b24b4af51e0e15c534a9 Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Wed, 3 Apr 2024 19:26:59 +0000 Subject: [PATCH 03/38] ANDROID: Export cpu_busy_with_softirqs() This function used to be called task_may_not_preempt() in older versions and used by modules that have their extension to RT. Export it to allow users to continue to use it. Bug: 332629555 Signed-off-by: Qais Yousef Change-Id: I04affb8e9e6258f9fb36ebab4d7956a265e9e299 --- kernel/sched/rt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 2e1e83ff4c80..7d9fec642662 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1636,7 +1636,7 @@ static int find_lowest_rq(struct task_struct *task); * task is likely to block preemptions soon because it is a * ksoftirq thread that is handling softirqs. */ -static bool cpu_busy_with_softirqs(int cpu) +bool cpu_busy_with_softirqs(int cpu) { u32 softirqs = per_cpu(active_softirqs, cpu) | __cpu_softirq_pending(cpu); @@ -1644,11 +1644,12 @@ static bool cpu_busy_with_softirqs(int cpu) return softirqs & LONG_SOFTIRQ_MASK; } #else -static bool cpu_busy_with_softirqs(int cpu) +bool cpu_busy_with_softirqs(int cpu) { return false; } #endif /* CONFIG_RT_SOFTIRQ_AWARE_SCHED */ +EXPORT_SYMBOL_GPL(cpu_busy_with_softirqs); static bool rt_task_fits_cpu(struct task_struct *p, int cpu) { @@ -3168,3 +3169,5 @@ void print_rt_stats(struct seq_file *m, int cpu) rcu_read_unlock(); } #endif /* CONFIG_SCHED_DEBUG */ + +extern bool cpu_busy_with_softirqs(int cpu); From 9ce8f4d0bb5a939714402749be38d79bdc12e20e Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Wed, 3 Apr 2024 19:41:49 +0000 Subject: [PATCH 04/38] ANDROID: Update the ABI symbol list Adding the following symbols: - cpu_busy_with_softirqs - __traceiter_android_rvh_tick_entry - __tracepoint_android_rvh_tick_entry Bug: 332629555 Change-Id: I8ff85b6c13e39de35013dd742aaccf5db02e74b4 Signed-off-by: Qais Yousef --- android/abi_gki_aarch64.stg | 10 ++++++++++ android/abi_gki_aarch64_pixel | 3 +++ 2 files changed, 13 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index a8b38168e06a..2da59a0da5e7 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -352231,6 +352231,15 @@ elf_symbol { type_id: 0xd0d5f663 full_name: "cpu_bit_bitmap" } +elf_symbol { + id: 0xb8669175 + name: "cpu_busy_with_softirqs" + is_defined: true + symbol_type: FUNCTION + crc: 0x3c5aab9e + type_id: 0xe76c6fcf + full_name: "cpu_busy_with_softirqs" +} elf_symbol { id: 0x15e1667b name: "cpu_have_feature" @@ -406084,6 +406093,7 @@ interface { symbol_id: 0x9f1f7cee symbol_id: 0xd89255c2 symbol_id: 0x962b6a68 + symbol_id: 0xb8669175 symbol_id: 0x15e1667b symbol_id: 0x33bbeca6 symbol_id: 0x4e0ae383 diff --git a/android/abi_gki_aarch64_pixel b/android/abi_gki_aarch64_pixel index 9ef39dbbe259..66c2b850d31c 100644 --- a/android/abi_gki_aarch64_pixel +++ b/android/abi_gki_aarch64_pixel @@ -230,6 +230,7 @@ __cpu_active_mask cpu_all_bits cpu_bit_bitmap + cpu_busy_with_softirqs cpufreq_add_update_util_hook cpufreq_cpu_get cpufreq_cpu_get_raw @@ -2332,6 +2333,7 @@ __traceiter_android_rvh_set_task_cpu __traceiter_android_rvh_set_user_nice __traceiter_android_rvh_set_user_nice_locked + __traceiter_android_rvh_tick_entry __traceiter_android_rvh_typec_tcpci_get_vbus __traceiter_android_rvh_uclamp_eff_get __traceiter_android_rvh_ufs_complete_init @@ -2454,6 +2456,7 @@ __tracepoint_android_rvh_set_task_cpu __tracepoint_android_rvh_set_user_nice __tracepoint_android_rvh_set_user_nice_locked + __tracepoint_android_rvh_tick_entry __tracepoint_android_rvh_typec_tcpci_get_vbus __tracepoint_android_rvh_uclamp_eff_get __tracepoint_android_rvh_ufs_complete_init From 58699757f43def2dc642cf822d59ee5579cd0834 Mon Sep 17 00:00:00 2001 From: Charan Teja Kalla Date: Fri, 24 Nov 2023 16:35:52 +0530 Subject: [PATCH 05/38] UPSTREAM: mm: page_alloc: correct high atomic reserve calculations Patch series "mm: page_alloc: fixes for high atomic reserve caluculations", v3. The state of the system where the issue exposed shown in oom kill logs: [ 295.998653] Normal free:7728kB boost:0kB min:804kB low:1004kB high:1204kB reserved_highatomic:8192KB active_anon:4kB inactive_anon:0kB active_file:24kB inactive_file:24kB unevictable:1220kB writepending:0kB present:70732kB managed:49224kB mlocked:0kB bounce:0kB free_pcp:688kBlocal_pcp:492kB free_cma:0kB [ 295.998656] lowmem_reserve[]: 0 32 [ 295.998659] Normal: 508*4kB (UMEH) 241*8kB (UMEH) 143*16kB (UMEH) 33*32kB (UH) 7*64kB (UH) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 7752kB From the above, it is seen that ~16MB of memory reserved for high atomic reserves against the expectation of 1% reserves which is fixed in the 1st patch. Don't reserve the high atomic page blocks if 1% of zone memory size is below a pageblock size. This patch (of 2): reserve_highatomic_pageblock() aims to reserve the 1% of the managed pages of a zone, which is used for the high order atomic allocations. It uses the below calculation to reserve: static void reserve_highatomic_pageblock(struct page *page, ....) { ....... max_managed = (zone_managed_pages(zone) / 100) + pageblock_nr_pages; if (zone->nr_reserved_highatomic >= max_managed) goto out; zone->nr_reserved_highatomic += pageblock_nr_pages; set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC); move_freepages_block(zone, page, MIGRATE_HIGHATOMIC, NULL); out: .... } Since we are always appending the 1% of zone managed pages count to pageblock_nr_pages, the minimum it is turning into 2 pageblocks as the nr_reserved_highatomic is incremented/decremented in pageblock sizes. Encountered a system(actually a VM running on the Linux kernel) with the below zone configuration: Normal free:7728kB boost:0kB min:804kB low:1004kB high:1204kB reserved_highatomic:8192KB managed:49224kB The existing calculations making it to reserve the 8MB(with pageblock size of 4MB) i.e. 16% of the zone managed memory. Reserving such high amount of memory can easily exert memory pressure in the system thus may lead into unnecessary reclaims till unreserving of high atomic reserves. Since high atomic reserves are managed in pageblock size granules, as MIGRATE_HIGHATOMIC is set for such pageblock, fix the calculations for high atomic reserves as, minimum is pageblock size , maximum is approximately 1% of the zone managed pages. Bug: 332219324 Link: https://lkml.kernel.org/r/cover.1700821416.git.quic_charante@quicinc.com Link: https://lkml.kernel.org/r/1660034138397b82a0a8b6ae51cbe96bd583d89e.1700821416.git.quic_charante@quicinc.com Change-Id: Icc15fb88ef6166f691f5aa14311bc45bff972b99 (cherry picked from commit d68e39fc45f70e35eb74df2128d315c1d91e4dc4) Signed-off-by: Charan Teja Kalla Acked-by: Mel Gorman Acked-by: David Rientjes Cc: David Hildenbrand Cc: Johannes Weiner Cc: Michal Hocko Cc: Pavankumar Kondeti Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/page_alloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b88e6ad7eb08..48b32a573f10 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2919,10 +2919,11 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone, unsigned long max_managed, flags; /* - * Limit the number reserved to 1 pageblock or roughly 1% of a zone. + * The number reserved as: minimum is 1 pageblock, maximum is + * roughly 1% of a zone. * Check is race-prone but harmless. */ - max_managed = (zone_managed_pages(zone) / 100) + pageblock_nr_pages; + max_managed = ALIGN((zone_managed_pages(zone) / 100), pageblock_nr_pages); if (zone->nr_reserved_highatomic >= max_managed) return; From 6d3db504d1167da08247294326482e66444e89f5 Mon Sep 17 00:00:00 2001 From: Charan Teja Kalla Date: Fri, 24 Nov 2023 16:35:53 +0530 Subject: [PATCH 06/38] UPSTREAM: mm: page_alloc: enforce minimum zone size to do high atomic reserves Highatomic reserves are set to roughly 1% of zone for maximum and a pageblock size for minimum. Encountered a system with the below configuration: Normal free:7728kB boost:0kB min:804kB low:1004kB high:1204kB reserved_highatomic:8192KB managed:49224kB On such systems, even a single pageblock makes highatomic reserves are set to ~8% of the zone memory. This high value can easily exert pressure on the zone. Per discussion with Michal and Mel, it is not much useful to reserve the memory for highatomic allocations on such small systems[1]. Since the minimum size for high atomic reserves is always going to be a pageblock size and if 1% of zone managed pages is going to be below pageblock size, don't reserve memory for high atomic allocations. Thanks Michal for this suggestion[2]. Since no memory is being reserved for high atomic allocations and if respective allocation failures are seen, this patch can be reverted. [1] https://lore.kernel.org/linux-mm/20231117161956.d3yjdxhhm4rhl7h2@techsingularity.net/ [2] https://lore.kernel.org/linux-mm/ZVYRJMUitykepLRy@tiehlicka/ Bug: 332219324 Link: https://lkml.kernel.org/r/c3a2a48e2cfe08176a80eaf01c110deb9e918055.1700821416.git.quic_charante@quicinc.com Change-Id: Id059b63bd6ee68b3a2cd1c4b44613234a42d0a46 (cherry picked from commit 9cd20f3fe045af95a8fe7a12328b21bfd2f3b8bf) Signed-off-by: Charan Teja Kalla Acked-by: David Rientjes Cc: David Hildenbrand Cc: Johannes Weiner Cc: Mel Gorman Cc: Michal Hocko Cc: Pavankumar Kondeti Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/page_alloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 48b32a573f10..a9c10e284bbc 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2920,9 +2920,12 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone, /* * The number reserved as: minimum is 1 pageblock, maximum is - * roughly 1% of a zone. + * roughly 1% of a zone. But if 1% of a zone falls below a + * pageblock size, then don't reserve any pageblocks. * Check is race-prone but harmless. */ + if ((zone_managed_pages(zone) / 100) < pageblock_nr_pages) + return; max_managed = ALIGN((zone_managed_pages(zone) / 100), pageblock_nr_pages); if (zone->nr_reserved_highatomic >= max_managed) return; From 5dd0c4814fa5d61e0944fccd38547e6cb94635eb Mon Sep 17 00:00:00 2001 From: Charan Teja Kalla Date: Fri, 24 Nov 2023 16:27:25 +0530 Subject: [PATCH 07/38] UPSTREAM: mm: page_alloc: unreserve highatomic page blocks before oom __alloc_pages_direct_reclaim() is called from slowpath allocation where high atomic reserves can be unreserved after there is a progress in reclaim and yet no suitable page is found. Later should_reclaim_retry() gets called from slow path allocation to decide if the reclaim needs to be retried before OOM kill path is taken. should_reclaim_retry() checks the available(reclaimable + free pages) memory against the min wmark levels of a zone and returns: a) true, if it is above the min wmark so that slow path allocation will do the reclaim retries. b) false, thus slowpath allocation takes oom kill path. should_reclaim_retry() can also unreserves the high atomic reserves **but only after all the reclaim retries are exhausted.** In a case where there are almost none reclaimable memory and free pages contains mostly the high atomic reserves but allocation context can't use these high atomic reserves, makes the available memory below min wmark levels hence false is returned from should_reclaim_retry() leading the allocation request to take OOM kill path. This can turn into a early oom kill if high atomic reserves are holding lot of free memory and unreserving of them is not attempted. (early)OOM is encountered on a VM with the below state: [ 295.998653] Normal free:7728kB boost:0kB min:804kB low:1004kB high:1204kB reserved_highatomic:8192KB active_anon:4kB inactive_anon:0kB active_file:24kB inactive_file:24kB unevictable:1220kB writepending:0kB present:70732kB managed:49224kB mlocked:0kB bounce:0kB free_pcp:688kB local_pcp:492kB free_cma:0kB [ 295.998656] lowmem_reserve[]: 0 32 [ 295.998659] Normal: 508*4kB (UMEH) 241*8kB (UMEH) 143*16kB (UMEH) 33*32kB (UH) 7*64kB (UH) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 7752kB Per above log, the free memory of ~7MB exist in the high atomic reserves is not freed up before falling back to oom kill path. Fix it by trying to unreserve the high atomic reserves in should_reclaim_retry() before __alloc_pages_direct_reclaim() can fallback to oom kill path. Bug: 332219324 Link: https://lkml.kernel.org/r/1700823445-27531-1-git-send-email-quic_charante@quicinc.com Fixes: 0aaa29a56e4f ("mm, page_alloc: reserve pageblocks for high-order atomic allocations on demand") (cherry picked from commit ac3f3b0a55518056bc80ed32a41931c99e1f7d81) Change-Id: I432d4ac4864d401a4413f6b2ef902625766f8070 Signed-off-by: Charan Teja Kalla Reported-by: Chris Goldsworthy Suggested-by: Michal Hocko Acked-by: Michal Hocko Acked-by: David Rientjes Cc: Chris Goldsworthy Cc: David Hildenbrand Cc: Johannes Weiner Cc: Mel Gorman Cc: Pavankumar Kondeti Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/page_alloc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a9c10e284bbc..55e1b0d71b79 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5048,14 +5048,9 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, else (*no_progress_loops)++; - /* - * Make sure we converge to OOM if we cannot make any progress - * several times in the row. - */ - if (*no_progress_loops > MAX_RECLAIM_RETRIES) { - /* Before OOM, exhaust highatomic_reserve */ - return unreserve_highatomic_pageblock(ac, true); - } + if (*no_progress_loops > MAX_RECLAIM_RETRIES) + goto out; + /* * Keep reclaiming pages while there is a chance this will lead @@ -5098,6 +5093,11 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, schedule_timeout_uninterruptible(1); else cond_resched(); +out: + /* Before OOM, exhaust highatomic_reserve */ + if (!ret) + return unreserve_highatomic_pageblock(ac, true); + return ret; } From ebcdb9dc211f42a26523f6a4571304855de2643b Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Wed, 3 Apr 2024 23:38:02 +0000 Subject: [PATCH 08/38] ANDROID: Move cpu_busy_with_softirqs() into sched.h The extern declaration ended up at the end of rt.c instead of sched.h by mistake. Bug: 332629555 Fixes: dcdec80d6bb8 ("ANDROID: Export cpu_busy_with_softirqs()") Signed-off-by: Qais Yousef Change-Id: Id95a1c2261134c4d4f589ec51d350fc5eb2724f9 --- kernel/sched/rt.c | 2 -- kernel/sched/sched.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 7d9fec642662..c0fc24530643 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -3169,5 +3169,3 @@ void print_rt_stats(struct seq_file *m, int cpu) rcu_read_unlock(); } #endif /* CONFIG_SCHED_DEBUG */ - -extern bool cpu_busy_with_softirqs(int cpu); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 210032735650..f3ee288cc680 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -3278,4 +3278,5 @@ static inline void update_current_exec_runtime(struct task_struct *curr, cgroup_account_cputime(curr, delta_exec); } +extern bool cpu_busy_with_softirqs(int cpu); #endif /* _KERNEL_SCHED_SCHED_H */ From 0fd201845469d5bf39a807bb588608f02d2d12d1 Mon Sep 17 00:00:00 2001 From: Marcin Radomski Date: Wed, 31 Jan 2024 16:01:32 +0000 Subject: [PATCH 09/38] ANDROID: Update symbols list for virtio_snd.ko audio controls Added just symbols reported as required by: tools/bazel run //common-modules/virtual-device:virtual_device_aarch64_dist because the virtual_device_aarch64_abi_update_symbol_list tool introduces a ton of unrelated changes - not just trivial reordering, but also adds some extra symbols. Bug: 330891925 Test: Build dist packages on the entire commit chain: Test: tools/bazel run //common-modules/virtual-device:virtual_device_x86_64_dist Test: tools/bazel run //common-modules/virtual-device:virtual_device_aarch64_dist Change-Id: I26abf56b3cb9b3cc3f179647ce229aa85a3dd7c8 Signed-off-by: Marcin Radomski --- android/abi_gki_aarch64_virtual_device | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/abi_gki_aarch64_virtual_device b/android/abi_gki_aarch64_virtual_device index 7b5c972bff09..eacbf9364c9d 100644 --- a/android/abi_gki_aarch64_virtual_device +++ b/android/abi_gki_aarch64_virtual_device @@ -1349,6 +1349,9 @@ snd_card_free snd_card_new snd_card_register + snd_ctl_add + snd_ctl_new1 + snd_ctl_notify snd_jack_new snd_jack_report snd_pcm_add_chmap_ctls From e7f7d5547135d1a80f300611efbd1ded527c078e Mon Sep 17 00:00:00 2001 From: Anton Yakovlev Date: Mon, 15 Jan 2024 14:36:54 +0100 Subject: [PATCH 10/38] UPSTREAM: ALSA: virtio: add support for audio controls Implementation of support for audio controls in accordance with the extension of the virtio sound device specification [1] planned for virtio-v1.3-cs01. The device can announce the VIRTIO_SND_F_CTLS feature. If the feature is negotiated, then an additional field appears in the configuration space: struct virtio_snd_config { ... /* number of available control elements */ __le32 controls; }; The driver can send the following requests to manage audio controls: enum { ... /* control element request types */ VIRTIO_SND_R_CTL_INFO = 0x0300, VIRTIO_SND_R_CTL_ENUM_ITEMS, VIRTIO_SND_R_CTL_READ, VIRTIO_SND_R_CTL_WRITE, VIRTIO_SND_R_CTL_TLV_READ, VIRTIO_SND_R_CTL_TLV_WRITE, VIRTIO_SND_R_CTL_TLV_COMMAND, ... }; And the device can send the following audio control event notification: enum { ... /* control element event types */ VIRTIO_SND_EVT_CTL_NOTIFY = 0x1200, ... }; See additional details in [1]. [1] https://lists.oasis-open.org/archives/virtio-comment/202104/msg00013.html Signed-off-by: Anton Yakovlev Signed-off-by: Aiswarya Cyriac Link: https://lore.kernel.org/r/20240115133654.576068-2-aiswarya.cyriac@opensynergy.com Signed-off-by: Takashi Iwai Bug: 330891925 Change-Id: I4c70787a920bc4a7cf82b8115fc9f0a6c77b4859 (cherry picked from commit d6568e3de42dd971a1356f7ba581e6600d53f0a0) Signed-off-by: Marcin Radomski --- include/uapi/linux/virtio_snd.h | 154 +++++++++++ sound/virtio/Makefile | 1 + sound/virtio/virtio_card.c | 21 ++ sound/virtio/virtio_card.h | 22 ++ sound/virtio/virtio_kctl.c | 466 ++++++++++++++++++++++++++++++++ 5 files changed, 664 insertions(+) create mode 100644 sound/virtio/virtio_kctl.c diff --git a/include/uapi/linux/virtio_snd.h b/include/uapi/linux/virtio_snd.h index dfe49547a7b0..5f4100c2cf04 100644 --- a/include/uapi/linux/virtio_snd.h +++ b/include/uapi/linux/virtio_snd.h @@ -7,6 +7,14 @@ #include +/******************************************************************************* + * FEATURE BITS + */ +enum { + /* device supports control elements */ + VIRTIO_SND_F_CTLS = 0 +}; + /******************************************************************************* * CONFIGURATION SPACE */ @@ -17,6 +25,8 @@ struct virtio_snd_config { __le32 streams; /* # of available channel maps */ __le32 chmaps; + /* # of available control elements */ + __le32 controls; }; enum { @@ -55,6 +65,15 @@ enum { /* channel map control request types */ VIRTIO_SND_R_CHMAP_INFO = 0x0200, + /* control element request types */ + VIRTIO_SND_R_CTL_INFO = 0x0300, + VIRTIO_SND_R_CTL_ENUM_ITEMS, + VIRTIO_SND_R_CTL_READ, + VIRTIO_SND_R_CTL_WRITE, + VIRTIO_SND_R_CTL_TLV_READ, + VIRTIO_SND_R_CTL_TLV_WRITE, + VIRTIO_SND_R_CTL_TLV_COMMAND, + /* jack event types */ VIRTIO_SND_EVT_JACK_CONNECTED = 0x1000, VIRTIO_SND_EVT_JACK_DISCONNECTED, @@ -63,6 +82,9 @@ enum { VIRTIO_SND_EVT_PCM_PERIOD_ELAPSED = 0x1100, VIRTIO_SND_EVT_PCM_XRUN, + /* control element event types */ + VIRTIO_SND_EVT_CTL_NOTIFY = 0x1200, + /* common status codes */ VIRTIO_SND_S_OK = 0x8000, VIRTIO_SND_S_BAD_MSG, @@ -331,4 +353,136 @@ struct virtio_snd_chmap_info { __u8 positions[VIRTIO_SND_CHMAP_MAX_SIZE]; }; +/******************************************************************************* + * CONTROL ELEMENTS MESSAGES + */ +struct virtio_snd_ctl_hdr { + /* VIRTIO_SND_R_CTL_XXX */ + struct virtio_snd_hdr hdr; + /* 0 ... virtio_snd_config::controls - 1 */ + __le32 control_id; +}; + +/* supported roles for control elements */ +enum { + VIRTIO_SND_CTL_ROLE_UNDEFINED = 0, + VIRTIO_SND_CTL_ROLE_VOLUME, + VIRTIO_SND_CTL_ROLE_MUTE, + VIRTIO_SND_CTL_ROLE_GAIN +}; + +/* supported value types for control elements */ +enum { + VIRTIO_SND_CTL_TYPE_BOOLEAN = 0, + VIRTIO_SND_CTL_TYPE_INTEGER, + VIRTIO_SND_CTL_TYPE_INTEGER64, + VIRTIO_SND_CTL_TYPE_ENUMERATED, + VIRTIO_SND_CTL_TYPE_BYTES, + VIRTIO_SND_CTL_TYPE_IEC958 +}; + +/* supported access rights for control elements */ +enum { + VIRTIO_SND_CTL_ACCESS_READ = 0, + VIRTIO_SND_CTL_ACCESS_WRITE, + VIRTIO_SND_CTL_ACCESS_VOLATILE, + VIRTIO_SND_CTL_ACCESS_INACTIVE, + VIRTIO_SND_CTL_ACCESS_TLV_READ, + VIRTIO_SND_CTL_ACCESS_TLV_WRITE, + VIRTIO_SND_CTL_ACCESS_TLV_COMMAND +}; + +struct virtio_snd_ctl_info { + /* common header */ + struct virtio_snd_info hdr; + /* element role (VIRTIO_SND_CTL_ROLE_XXX) */ + __le32 role; + /* element value type (VIRTIO_SND_CTL_TYPE_XXX) */ + __le32 type; + /* element access right bit map (1 << VIRTIO_SND_CTL_ACCESS_XXX) */ + __le32 access; + /* # of members in the element value */ + __le32 count; + /* index for an element with a non-unique name */ + __le32 index; + /* name identifier string for the element */ + __u8 name[44]; + /* additional information about the element's value */ + union { + /* VIRTIO_SND_CTL_TYPE_INTEGER */ + struct { + /* minimum supported value */ + __le32 min; + /* maximum supported value */ + __le32 max; + /* fixed step size for value (0 = variable size) */ + __le32 step; + } integer; + /* VIRTIO_SND_CTL_TYPE_INTEGER64 */ + struct { + /* minimum supported value */ + __le64 min; + /* maximum supported value */ + __le64 max; + /* fixed step size for value (0 = variable size) */ + __le64 step; + } integer64; + /* VIRTIO_SND_CTL_TYPE_ENUMERATED */ + struct { + /* # of options supported for value */ + __le32 items; + } enumerated; + } value; +}; + +struct virtio_snd_ctl_enum_item { + /* option name */ + __u8 item[64]; +}; + +struct virtio_snd_ctl_iec958 { + /* AES/IEC958 channel status bits */ + __u8 status[24]; + /* AES/IEC958 subcode bits */ + __u8 subcode[147]; + /* nothing */ + __u8 pad; + /* AES/IEC958 subframe bits */ + __u8 dig_subframe[4]; +}; + +struct virtio_snd_ctl_value { + union { + /* VIRTIO_SND_CTL_TYPE_BOOLEAN|INTEGER value */ + __le32 integer[128]; + /* VIRTIO_SND_CTL_TYPE_INTEGER64 value */ + __le64 integer64[64]; + /* VIRTIO_SND_CTL_TYPE_ENUMERATED value (option indexes) */ + __le32 enumerated[128]; + /* VIRTIO_SND_CTL_TYPE_BYTES value */ + __u8 bytes[512]; + /* VIRTIO_SND_CTL_TYPE_IEC958 value */ + struct virtio_snd_ctl_iec958 iec958; + } value; +}; + +/* supported event reason types */ +enum { + /* element's value has changed */ + VIRTIO_SND_CTL_EVT_MASK_VALUE = 0, + /* element's information has changed */ + VIRTIO_SND_CTL_EVT_MASK_INFO, + /* element's metadata has changed */ + VIRTIO_SND_CTL_EVT_MASK_TLV +}; + +struct virtio_snd_ctl_event { + /* VIRTIO_SND_EVT_CTL_NOTIFY */ + struct virtio_snd_hdr hdr; + /* 0 ... virtio_snd_config::controls - 1 */ + __le16 control_id; + /* event reason bit map (1 << VIRTIO_SND_CTL_EVT_MASK_XXX) */ + __le16 mask; +}; + #endif /* VIRTIO_SND_IF_H */ diff --git a/sound/virtio/Makefile b/sound/virtio/Makefile index 2742bddb8874..a839f8c8b5e6 100644 --- a/sound/virtio/Makefile +++ b/sound/virtio/Makefile @@ -7,6 +7,7 @@ virtio_snd-objs := \ virtio_chmap.o \ virtio_ctl_msg.o \ virtio_jack.o \ + virtio_kctl.o \ virtio_pcm.o \ virtio_pcm_msg.o \ virtio_pcm_ops.o diff --git a/sound/virtio/virtio_card.c b/sound/virtio/virtio_card.c index e2847c040f75..61df3476cf70 100644 --- a/sound/virtio/virtio_card.c +++ b/sound/virtio/virtio_card.c @@ -64,6 +64,9 @@ static void virtsnd_event_dispatch(struct virtio_snd *snd, case VIRTIO_SND_EVT_PCM_XRUN: virtsnd_pcm_event(snd, event); break; + case VIRTIO_SND_EVT_CTL_NOTIFY: + virtsnd_kctl_event(snd, event); + break; } } @@ -235,6 +238,12 @@ static int virtsnd_build_devs(struct virtio_snd *snd) if (rc) return rc; + if (virtio_has_feature(vdev, VIRTIO_SND_F_CTLS)) { + rc = virtsnd_kctl_parse_cfg(snd); + if (rc) + return rc; + } + if (snd->njacks) { rc = virtsnd_jack_build_devs(snd); if (rc) @@ -253,6 +262,12 @@ static int virtsnd_build_devs(struct virtio_snd *snd) return rc; } + if (snd->nkctls) { + rc = virtsnd_kctl_build_devs(snd); + if (rc) + return rc; + } + return snd_card_register(snd->card); } @@ -419,10 +434,16 @@ static const struct virtio_device_id id_table[] = { { 0 }, }; +static unsigned int features[] = { + VIRTIO_SND_F_CTLS +}; + static struct virtio_driver virtsnd_driver = { .driver.name = KBUILD_MODNAME, .driver.owner = THIS_MODULE, .id_table = id_table, + .feature_table = features, + .feature_table_size = ARRAY_SIZE(features), .validate = virtsnd_validate, .probe = virtsnd_probe, .remove = virtsnd_remove, diff --git a/sound/virtio/virtio_card.h b/sound/virtio/virtio_card.h index 86ef3941895e..3ceee4e416fc 100644 --- a/sound/virtio/virtio_card.h +++ b/sound/virtio/virtio_card.h @@ -31,6 +31,16 @@ struct virtio_snd_queue { struct virtqueue *vqueue; }; +/** + * struct virtio_kctl - VirtIO control element. + * @kctl: ALSA control element. + * @items: Items for the ENUMERATED element type. + */ +struct virtio_kctl { + struct snd_kcontrol *kctl; + struct virtio_snd_ctl_enum_item *items; +}; + /** * struct virtio_snd - VirtIO sound card device. * @vdev: Underlying virtio device. @@ -45,6 +55,9 @@ struct virtio_snd_queue { * @nsubstreams: Number of PCM substreams. * @chmaps: VirtIO channel maps. * @nchmaps: Number of channel maps. + * @kctl_infos: VirtIO control element information. + * @kctls: VirtIO control elements. + * @nkctls: Number of control elements. */ struct virtio_snd { struct virtio_device *vdev; @@ -59,6 +72,9 @@ struct virtio_snd { u32 nsubstreams; struct virtio_snd_chmap_info *chmaps; u32 nchmaps; + struct virtio_snd_ctl_info *kctl_infos; + struct virtio_kctl *kctls; + u32 nkctls; }; /* Message completion timeout in milliseconds (module parameter). */ @@ -108,4 +124,10 @@ int virtsnd_chmap_parse_cfg(struct virtio_snd *snd); int virtsnd_chmap_build_devs(struct virtio_snd *snd); +int virtsnd_kctl_parse_cfg(struct virtio_snd *snd); + +int virtsnd_kctl_build_devs(struct virtio_snd *snd); + +void virtsnd_kctl_event(struct virtio_snd *snd, struct virtio_snd_event *event); + #endif /* VIRTIO_SND_CARD_H */ diff --git a/sound/virtio/virtio_kctl.c b/sound/virtio/virtio_kctl.c new file mode 100644 index 000000000000..0c6ac74aca1e --- /dev/null +++ b/sound/virtio/virtio_kctl.c @@ -0,0 +1,466 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * virtio-snd: Virtio sound device + * Copyright (C) 2022 OpenSynergy GmbH + */ +#include +#include + +#include "virtio_card.h" + +/* Map for converting VirtIO types to ALSA types. */ +static const snd_ctl_elem_type_t g_v2a_type_map[] = { + [VIRTIO_SND_CTL_TYPE_BOOLEAN] = SNDRV_CTL_ELEM_TYPE_BOOLEAN, + [VIRTIO_SND_CTL_TYPE_INTEGER] = SNDRV_CTL_ELEM_TYPE_INTEGER, + [VIRTIO_SND_CTL_TYPE_INTEGER64] = SNDRV_CTL_ELEM_TYPE_INTEGER64, + [VIRTIO_SND_CTL_TYPE_ENUMERATED] = SNDRV_CTL_ELEM_TYPE_ENUMERATED, + [VIRTIO_SND_CTL_TYPE_BYTES] = SNDRV_CTL_ELEM_TYPE_BYTES, + [VIRTIO_SND_CTL_TYPE_IEC958] = SNDRV_CTL_ELEM_TYPE_IEC958 +}; + +/* Map for converting VirtIO access rights to ALSA access rights. */ +static const unsigned int g_v2a_access_map[] = { + [VIRTIO_SND_CTL_ACCESS_READ] = SNDRV_CTL_ELEM_ACCESS_READ, + [VIRTIO_SND_CTL_ACCESS_WRITE] = SNDRV_CTL_ELEM_ACCESS_WRITE, + [VIRTIO_SND_CTL_ACCESS_VOLATILE] = SNDRV_CTL_ELEM_ACCESS_VOLATILE, + [VIRTIO_SND_CTL_ACCESS_INACTIVE] = SNDRV_CTL_ELEM_ACCESS_INACTIVE, + [VIRTIO_SND_CTL_ACCESS_TLV_READ] = SNDRV_CTL_ELEM_ACCESS_TLV_READ, + [VIRTIO_SND_CTL_ACCESS_TLV_WRITE] = SNDRV_CTL_ELEM_ACCESS_TLV_WRITE, + [VIRTIO_SND_CTL_ACCESS_TLV_COMMAND] = SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND +}; + +/* Map for converting VirtIO event masks to ALSA event masks. */ +static const unsigned int g_v2a_mask_map[] = { + [VIRTIO_SND_CTL_EVT_MASK_VALUE] = SNDRV_CTL_EVENT_MASK_VALUE, + [VIRTIO_SND_CTL_EVT_MASK_INFO] = SNDRV_CTL_EVENT_MASK_INFO, + [VIRTIO_SND_CTL_EVT_MASK_TLV] = SNDRV_CTL_EVENT_MASK_TLV +}; + +/** + * virtsnd_kctl_info() - Returns information about the control. + * @kcontrol: ALSA control element. + * @uinfo: Element information. + * + * Context: Process context. + * Return: 0 on success, -errno on failure. + */ +static int virtsnd_kctl_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct virtio_snd *snd = kcontrol->private_data; + struct virtio_kctl *kctl = &snd->kctls[kcontrol->private_value]; + struct virtio_snd_ctl_info *kinfo = + &snd->kctl_infos[kcontrol->private_value]; + unsigned int i; + + uinfo->type = g_v2a_type_map[le32_to_cpu(kinfo->type)]; + uinfo->count = le32_to_cpu(kinfo->count); + + switch (uinfo->type) { + case SNDRV_CTL_ELEM_TYPE_INTEGER: + uinfo->value.integer.min = + le32_to_cpu(kinfo->value.integer.min); + uinfo->value.integer.max = + le32_to_cpu(kinfo->value.integer.max); + uinfo->value.integer.step = + le32_to_cpu(kinfo->value.integer.step); + + break; + case SNDRV_CTL_ELEM_TYPE_INTEGER64: + uinfo->value.integer64.min = + le64_to_cpu(kinfo->value.integer64.min); + uinfo->value.integer64.max = + le64_to_cpu(kinfo->value.integer64.max); + uinfo->value.integer64.step = + le64_to_cpu(kinfo->value.integer64.step); + + break; + case SNDRV_CTL_ELEM_TYPE_ENUMERATED: + uinfo->value.enumerated.items = + le32_to_cpu(kinfo->value.enumerated.items); + i = uinfo->value.enumerated.item; + if (i >= uinfo->value.enumerated.items) + return -EINVAL; + + strscpy(uinfo->value.enumerated.name, kctl->items[i].item, + sizeof(uinfo->value.enumerated.name)); + + break; + } + + return 0; +} + +/** + * virtsnd_kctl_get() - Read the value from the control. + * @kcontrol: ALSA control element. + * @uvalue: Element value. + * + * Context: Process context. + * Return: 0 on success, -errno on failure. + */ +static int virtsnd_kctl_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *uvalue) +{ + struct virtio_snd *snd = kcontrol->private_data; + struct virtio_snd_ctl_info *kinfo = + &snd->kctl_infos[kcontrol->private_value]; + unsigned int type = le32_to_cpu(kinfo->type); + unsigned int count = le32_to_cpu(kinfo->count); + struct virtio_snd_msg *msg; + struct virtio_snd_ctl_hdr *hdr; + struct virtio_snd_ctl_value *kvalue; + size_t request_size = sizeof(*hdr); + size_t response_size = sizeof(struct virtio_snd_hdr) + sizeof(*kvalue); + unsigned int i; + int rc; + + msg = virtsnd_ctl_msg_alloc(request_size, response_size, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + virtsnd_ctl_msg_ref(msg); + + hdr = virtsnd_ctl_msg_request(msg); + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_READ); + hdr->control_id = cpu_to_le32(kcontrol->private_value); + + rc = virtsnd_ctl_msg_send_sync(snd, msg); + if (rc) + goto on_failure; + + kvalue = (void *)((u8 *)virtsnd_ctl_msg_response(msg) + + sizeof(struct virtio_snd_hdr)); + + switch (type) { + case VIRTIO_SND_CTL_TYPE_BOOLEAN: + case VIRTIO_SND_CTL_TYPE_INTEGER: + for (i = 0; i < count; ++i) + uvalue->value.integer.value[i] = + le32_to_cpu(kvalue->value.integer[i]); + break; + case VIRTIO_SND_CTL_TYPE_INTEGER64: + for (i = 0; i < count; ++i) + uvalue->value.integer64.value[i] = + le64_to_cpu(kvalue->value.integer64[i]); + break; + case VIRTIO_SND_CTL_TYPE_ENUMERATED: + for (i = 0; i < count; ++i) + uvalue->value.enumerated.item[i] = + le32_to_cpu(kvalue->value.enumerated[i]); + break; + case VIRTIO_SND_CTL_TYPE_BYTES: + memcpy(uvalue->value.bytes.data, kvalue->value.bytes, count); + break; + case VIRTIO_SND_CTL_TYPE_IEC958: + memcpy(&uvalue->value.iec958, &kvalue->value.iec958, + sizeof(uvalue->value.iec958)); + break; + } + +on_failure: + virtsnd_ctl_msg_unref(msg); + + return rc; +} + +/** + * virtsnd_kctl_put() - Write the value to the control. + * @kcontrol: ALSA control element. + * @uvalue: Element value. + * + * Context: Process context. + * Return: 0 on success, -errno on failure. + */ +static int virtsnd_kctl_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *uvalue) +{ + struct virtio_snd *snd = kcontrol->private_data; + struct virtio_snd_ctl_info *kinfo = + &snd->kctl_infos[kcontrol->private_value]; + unsigned int type = le32_to_cpu(kinfo->type); + unsigned int count = le32_to_cpu(kinfo->count); + struct virtio_snd_msg *msg; + struct virtio_snd_ctl_hdr *hdr; + struct virtio_snd_ctl_value *kvalue; + size_t request_size = sizeof(*hdr) + sizeof(*kvalue); + size_t response_size = sizeof(struct virtio_snd_hdr); + unsigned int i; + + msg = virtsnd_ctl_msg_alloc(request_size, response_size, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr = virtsnd_ctl_msg_request(msg); + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_WRITE); + hdr->control_id = cpu_to_le32(kcontrol->private_value); + + kvalue = (void *)((u8 *)hdr + sizeof(*hdr)); + + switch (type) { + case VIRTIO_SND_CTL_TYPE_BOOLEAN: + case VIRTIO_SND_CTL_TYPE_INTEGER: + for (i = 0; i < count; ++i) + kvalue->value.integer[i] = + cpu_to_le32(uvalue->value.integer.value[i]); + break; + case VIRTIO_SND_CTL_TYPE_INTEGER64: + for (i = 0; i < count; ++i) + kvalue->value.integer64[i] = + cpu_to_le64(uvalue->value.integer64.value[i]); + break; + case VIRTIO_SND_CTL_TYPE_ENUMERATED: + for (i = 0; i < count; ++i) + kvalue->value.enumerated[i] = + cpu_to_le32(uvalue->value.enumerated.item[i]); + break; + case VIRTIO_SND_CTL_TYPE_BYTES: + memcpy(kvalue->value.bytes, uvalue->value.bytes.data, count); + break; + case VIRTIO_SND_CTL_TYPE_IEC958: + memcpy(&kvalue->value.iec958, &uvalue->value.iec958, + sizeof(kvalue->value.iec958)); + break; + } + + return virtsnd_ctl_msg_send_sync(snd, msg); +} + +/** + * virtsnd_kctl_tlv_op() - Perform an operation on the control's metadata. + * @kcontrol: ALSA control element. + * @op_flag: Operation code (SNDRV_CTL_TLV_OP_XXX). + * @size: Size of the TLV data in bytes. + * @utlv: TLV data. + * + * Context: Process context. + * Return: 0 on success, -errno on failure. + */ +static int virtsnd_kctl_tlv_op(struct snd_kcontrol *kcontrol, int op_flag, + unsigned int size, unsigned int __user *utlv) +{ + struct virtio_snd *snd = kcontrol->private_data; + struct virtio_snd_msg *msg; + struct virtio_snd_ctl_hdr *hdr; + unsigned int *tlv; + struct scatterlist sg; + int rc; + + msg = virtsnd_ctl_msg_alloc(sizeof(*hdr), sizeof(struct virtio_snd_hdr), + GFP_KERNEL); + if (!msg) + return -ENOMEM; + + tlv = kzalloc(size, GFP_KERNEL); + if (!tlv) { + virtsnd_ctl_msg_unref(msg); + return -ENOMEM; + } + + sg_init_one(&sg, tlv, size); + + hdr = virtsnd_ctl_msg_request(msg); + hdr->control_id = cpu_to_le32(kcontrol->private_value); + + switch (op_flag) { + case SNDRV_CTL_TLV_OP_READ: + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_TLV_READ); + + rc = virtsnd_ctl_msg_send(snd, msg, NULL, &sg, false); + if (!rc) { + if (copy_to_user(utlv, tlv, size)) + rc = -EFAULT; + } + + break; + case SNDRV_CTL_TLV_OP_WRITE: + case SNDRV_CTL_TLV_OP_CMD: + if (op_flag == SNDRV_CTL_TLV_OP_WRITE) + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_TLV_WRITE); + else + hdr->hdr.code = + cpu_to_le32(VIRTIO_SND_R_CTL_TLV_COMMAND); + + if (copy_from_user(tlv, utlv, size)) + rc = -EFAULT; + else + rc = virtsnd_ctl_msg_send(snd, msg, &sg, NULL, false); + + break; + } + + kfree(tlv); + + return rc; +} + +/** + * virtsnd_kctl_get_enum_items() - Query items for the ENUMERATED element type. + * @snd: VirtIO sound device. + * @cid: Control element ID. + * + * This function is called during initial device initialization. + * + * Context: Any context that permits to sleep. + * Return: 0 on success, -errno on failure. + */ +static int virtsnd_kctl_get_enum_items(struct virtio_snd *snd, unsigned int cid) +{ + struct virtio_device *vdev = snd->vdev; + struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[cid]; + struct virtio_kctl *kctl = &snd->kctls[cid]; + struct virtio_snd_msg *msg; + struct virtio_snd_ctl_hdr *hdr; + unsigned int n = le32_to_cpu(kinfo->value.enumerated.items); + struct scatterlist sg; + + msg = virtsnd_ctl_msg_alloc(sizeof(*hdr), + sizeof(struct virtio_snd_hdr), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + kctl->items = devm_kcalloc(&vdev->dev, n, sizeof(*kctl->items), + GFP_KERNEL); + if (!kctl->items) { + virtsnd_ctl_msg_unref(msg); + return -ENOMEM; + } + + sg_init_one(&sg, kctl->items, n * sizeof(*kctl->items)); + + hdr = virtsnd_ctl_msg_request(msg); + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_ENUM_ITEMS); + hdr->control_id = cpu_to_le32(cid); + + return virtsnd_ctl_msg_send(snd, msg, NULL, &sg, false); +} + +/** + * virtsnd_kctl_parse_cfg() - Parse the control element configuration. + * @snd: VirtIO sound device. + * + * This function is called during initial device initialization. + * + * Context: Any context that permits to sleep. + * Return: 0 on success, -errno on failure. + */ +int virtsnd_kctl_parse_cfg(struct virtio_snd *snd) +{ + struct virtio_device *vdev = snd->vdev; + u32 i; + int rc; + + virtio_cread_le(vdev, struct virtio_snd_config, controls, + &snd->nkctls); + if (!snd->nkctls) + return 0; + + snd->kctl_infos = devm_kcalloc(&vdev->dev, snd->nkctls, + sizeof(*snd->kctl_infos), GFP_KERNEL); + if (!snd->kctl_infos) + return -ENOMEM; + + snd->kctls = devm_kcalloc(&vdev->dev, snd->nkctls, sizeof(*snd->kctls), + GFP_KERNEL); + if (!snd->kctls) + return -ENOMEM; + + rc = virtsnd_ctl_query_info(snd, VIRTIO_SND_R_CTL_INFO, 0, snd->nkctls, + sizeof(*snd->kctl_infos), snd->kctl_infos); + if (rc) + return rc; + + for (i = 0; i < snd->nkctls; ++i) { + struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[i]; + unsigned int type = le32_to_cpu(kinfo->type); + + if (type == VIRTIO_SND_CTL_TYPE_ENUMERATED) { + rc = virtsnd_kctl_get_enum_items(snd, i); + if (rc) + return rc; + } + } + + return 0; +} + +/** + * virtsnd_kctl_build_devs() - Build ALSA control elements. + * @snd: VirtIO sound device. + * + * Context: Any context that permits to sleep. + * Return: 0 on success, -errno on failure. + */ +int virtsnd_kctl_build_devs(struct virtio_snd *snd) +{ + unsigned int cid; + + for (cid = 0; cid < snd->nkctls; ++cid) { + struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[cid]; + struct virtio_kctl *kctl = &snd->kctls[cid]; + struct snd_kcontrol_new kctl_new; + unsigned int i; + int rc; + + memset(&kctl_new, 0, sizeof(kctl_new)); + + kctl_new.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + kctl_new.name = kinfo->name; + kctl_new.index = le32_to_cpu(kinfo->index); + + for (i = 0; i < ARRAY_SIZE(g_v2a_access_map); ++i) + if (le32_to_cpu(kinfo->access) & (1 << i)) + kctl_new.access |= g_v2a_access_map[i]; + + if (kctl_new.access & (SNDRV_CTL_ELEM_ACCESS_TLV_READ | + SNDRV_CTL_ELEM_ACCESS_TLV_WRITE | + SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND)) { + kctl_new.access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; + kctl_new.tlv.c = virtsnd_kctl_tlv_op; + } + + kctl_new.info = virtsnd_kctl_info; + kctl_new.get = virtsnd_kctl_get; + kctl_new.put = virtsnd_kctl_put; + kctl_new.private_value = cid; + + kctl->kctl = snd_ctl_new1(&kctl_new, snd); + if (!kctl->kctl) + return -ENOMEM; + + rc = snd_ctl_add(snd->card, kctl->kctl); + if (rc) + return rc; + } + + return 0; +} + +/** + * virtsnd_kctl_event() - Handle the control element event notification. + * @snd: VirtIO sound device. + * @event: VirtIO sound event. + * + * Context: Interrupt context. + */ +void virtsnd_kctl_event(struct virtio_snd *snd, struct virtio_snd_event *event) +{ + struct virtio_snd_ctl_event *kevent = + (struct virtio_snd_ctl_event *)event; + struct virtio_kctl *kctl; + unsigned int cid = le16_to_cpu(kevent->control_id); + unsigned int mask = 0; + unsigned int i; + + if (cid >= snd->nkctls) + return; + + for (i = 0; i < ARRAY_SIZE(g_v2a_mask_map); ++i) + if (le16_to_cpu(kevent->mask) & (1 << i)) + mask |= g_v2a_mask_map[i]; + + + kctl = &snd->kctls[cid]; + + snd_ctl_notify(snd->card, mask, &kctl->kctl->id); +} From 60534eef47392cc95ccb87f9f7466e90c7d6a666 Mon Sep 17 00:00:00 2001 From: Aiswarya Cyriac Date: Fri, 16 Feb 2024 11:06:43 +0100 Subject: [PATCH 11/38] UPSTREAM: ALSA: virtio: Fix "Coverity: virtsnd_kctl_tlv_op(): Uninitialized variables" warning. This commit fixes the following warning when building virtio_snd driver. " *** CID 1583619: Uninitialized variables (UNINIT) sound/virtio/virtio_kctl.c:294 in virtsnd_kctl_tlv_op() 288 289 break; 290 } 291 292 kfree(tlv); 293 vvv CID 1583619: Uninitialized variables (UNINIT) vvv Using uninitialized value "rc". 294 return rc; 295 } 296 297 /** 298 * virtsnd_kctl_get_enum_items() - Query items for the ENUMERATED element type. 299 * @snd: VirtIO sound device. " This warning is caused by the absence of the "default" branch in the switch-block, and is a false positive because the kernel calls virtsnd_kctl_tlv_op() only with values for op_flag processed in this block. Also, this commit unifies the cleanup path for all possible control paths in the callback function. Signed-off-by: Anton Yakovlev Signed-off-by: Aiswarya Cyriac Reported-by: coverity-bot Addresses-Coverity-ID: 1583619 ("Uninitialized variables") Fixes: d6568e3de42d ("ALSA: virtio: add support for audio controls") Acked-by: Michael S. Tsirkin Link: https://lore.kernel.org/r/20240216100643.688590-1-aiswarya.cyriac@opensynergy.com Signed-off-by: Takashi Iwai Bug: 330891925 Change-Id: I6fb999ed48457baddcde95a3539daf010d505296 (cherry picked from commit ba00e413fa1515e4d0890803c01ebc555f500f15) Signed-off-by: Marcin Radomski --- sound/virtio/virtio_kctl.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sound/virtio/virtio_kctl.c b/sound/virtio/virtio_kctl.c index 0c6ac74aca1e..7aa79c05b464 100644 --- a/sound/virtio/virtio_kctl.c +++ b/sound/virtio/virtio_kctl.c @@ -253,8 +253,8 @@ static int virtsnd_kctl_tlv_op(struct snd_kcontrol *kcontrol, int op_flag, tlv = kzalloc(size, GFP_KERNEL); if (!tlv) { - virtsnd_ctl_msg_unref(msg); - return -ENOMEM; + rc = -ENOMEM; + goto on_msg_unref; } sg_init_one(&sg, tlv, size); @@ -281,14 +281,25 @@ static int virtsnd_kctl_tlv_op(struct snd_kcontrol *kcontrol, int op_flag, hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_TLV_COMMAND); - if (copy_from_user(tlv, utlv, size)) + if (copy_from_user(tlv, utlv, size)) { rc = -EFAULT; - else + goto on_msg_unref; + } else { rc = virtsnd_ctl_msg_send(snd, msg, &sg, NULL, false); + } break; + default: + rc = -EINVAL; + /* We never get here - we listed all values for op_flag */ + WARN_ON(1); + goto on_msg_unref; } + kfree(tlv); + return rc; +on_msg_unref: + virtsnd_ctl_msg_unref(msg); kfree(tlv); return rc; From 56ba301cac0b42ba3af04087672f927340fd2d45 Mon Sep 17 00:00:00 2001 From: Giuliano Procida Date: Mon, 8 Apr 2024 12:04:26 +0100 Subject: [PATCH 12/38] ANDROID: drop redundant OWNERS_DrNo file This file should only exist in android-mainline. Bug: 333350072 Change-Id: I6350acb9d187f94a67c34c2e72b607a9599269b0 Signed-off-by: Giuliano Procida --- OWNERS_DrNo | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 OWNERS_DrNo diff --git a/OWNERS_DrNo b/OWNERS_DrNo deleted file mode 100644 index c4b8c0d5e270..000000000000 --- a/OWNERS_DrNo +++ /dev/null @@ -1,23 +0,0 @@ -# Authoritative list of Dr. No reviewers to approve changes on GKI release -# branches, such as android12-5.10. -# -# This file has no effect in this branch, but is referred to from release -# branches. So, please do not move or rename. -# -# See the GKI release documentation (go/gki-dr-no) for further details. - -# Main reviewers -adelva@google.com -maennich@google.com -saravanak@google.com -vmartensson@google.com -tkjos@google.com -willdeacon@google.com - -# GKI Release Team -howardsoc@google.com #{LAST_RESORT_SUGGESTION} -szuweilin@google.com #{LAST_RESORT_SUGGESTION} - -# Backup -sspatil@google.com #{LAST_RESORT_SUGGESTION} -malchev@google.com #{LAST_RESORT_SUGGESTION} From 27c443059cd233403353f94111f166988df1dd5d Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 1 Mar 2024 00:11:10 +0100 Subject: [PATCH 13/38] UPSTREAM: netfilter: nf_tables: disallow anonymous set with timeout flag commit 16603605b667b70da974bea8216c93e7db043bf1 upstream. Anonymous sets are never used with timeout from userspace, reject this. Exception to this rule is NFT_SET_EVAL to ensure legacy meters still work. Bug: 329055463 Cc: stable@vger.kernel.org Fixes: 761da2935d6e ("netfilter: nf_tables: add set timeout API support") Reported-by: lonial con Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 72c1efe3f247a581667b7d368fff3bd9a03cd57a) Signed-off-by: Lee Jones Change-Id: I8c1c818e3d155d5edefee0b741568104081efb38 --- net/netfilter/nf_tables_api.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 631668f9cdfd..1314e4035517 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -4704,6 +4704,9 @@ static int nf_tables_newset(struct sk_buff *skb, const struct nfnl_info *info, if ((flags & (NFT_SET_EVAL | NFT_SET_OBJECT)) == (NFT_SET_EVAL | NFT_SET_OBJECT)) return -EOPNOTSUPP; + if ((flags & (NFT_SET_ANONYMOUS | NFT_SET_TIMEOUT | NFT_SET_EVAL)) == + (NFT_SET_ANONYMOUS | NFT_SET_TIMEOUT)) + return -EOPNOTSUPP; } desc.dtype = 0; From 66193f866d1667fa8ee159725153bb149a1b9a93 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Sat, 6 Apr 2024 01:05:28 +0000 Subject: [PATCH 14/38] ANDROID: add reclaim tune parameter functions This patch adds two exported functions to set/get reclaim parameters. Bug: 323406883 Change-Id: I8c29073dba3e77cb5db7f45b640518deae04b8a9 Signed-off-by: Minchan Kim --- include/linux/gfp.h | 3 +++ mm/page_alloc.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index e652b9bbb262..9ec3b227e8f2 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -351,6 +351,9 @@ static inline bool pm_suspended_storage(void) } #endif /* CONFIG_PM_SLEEP */ +int set_reclaim_params(int wmark_scale_factor, int swappiness); +void get_reclaim_params(int *wmark_scale_factor, int *swappiness); + #ifdef CONFIG_CONTIG_ALLOC /* The below functions must be run on a range from a single zone. */ extern int alloc_contig_range(unsigned long start, unsigned long end, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 55e1b0d71b79..0c32100ecf9a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -536,6 +536,30 @@ static inline int pfn_to_bitidx(const struct page *page, unsigned long pfn) return (pfn >> pageblock_order) * NR_PAGEBLOCK_BITS; } +int set_reclaim_params(int wmark_scale_factor, int swappiness) +{ + if (wmark_scale_factor > 3000 || wmark_scale_factor < 1) + return -EINVAL; + + if (swappiness > 200 || swappiness < 0) + return -EINVAL; + + WRITE_ONCE(vm_swappiness, swappiness); + WRITE_ONCE(watermark_scale_factor, wmark_scale_factor); + + setup_per_zone_wmarks(); + + return 0; +} +EXPORT_SYMBOL_GPL(set_reclaim_params); + +void get_reclaim_params(int *wmark_scale_factor, int *swappiness) +{ + *wmark_scale_factor = watermark_scale_factor; + *swappiness = vm_swappiness; +} +EXPORT_SYMBOL_GPL(get_reclaim_params); + static __always_inline unsigned long __get_pfnblock_flags_mask(const struct page *page, unsigned long pfn, From babe7ef868457431b8fe1076cf303bfc4c75624d Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Sat, 6 Apr 2024 01:06:22 +0000 Subject: [PATCH 15/38] ANDROID: export two function to reclaim memory Export two functions to help memory reclaim. Bug: 323406883 Change-Id: I099d414c9b3648224ab077b9929c6622b2d4228a Signed-off-by: Minchan Kim --- include/linux/oom.h | 1 + kernel/signal.c | 1 + mm/oom_kill.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/oom.h b/include/linux/oom.h index f008e23d9b41..1f1aebf17001 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -109,6 +109,7 @@ extern int unregister_oom_notifier(struct notifier_block *nb); extern bool oom_killer_disable(signed long timeout); extern void oom_killer_enable(void); +extern bool __oom_reap_task_mm(struct mm_struct *mm); extern struct task_struct *find_lock_task_mm(struct task_struct *p); diff --git a/kernel/signal.c b/kernel/signal.c index a55cc27959e7..f7a4cfbe24ad 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1312,6 +1312,7 @@ int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p return ret; } +EXPORT_SYMBOL_GPL(do_send_sig_info); enum sig_handler { HANDLER_CURRENT, /* If reachable use the current handler */ diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 6bb096462170..7a9e1c7f636c 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -511,7 +511,7 @@ static DECLARE_WAIT_QUEUE_HEAD(oom_reaper_wait); static struct task_struct *oom_reaper_list; static DEFINE_SPINLOCK(oom_reaper_lock); -static bool __oom_reap_task_mm(struct mm_struct *mm) +bool __oom_reap_task_mm(struct mm_struct *mm) { struct vm_area_struct *vma; bool ret = true; @@ -560,6 +560,7 @@ static bool __oom_reap_task_mm(struct mm_struct *mm) return ret; } +EXPORT_SYMBOL_GPL(__oom_reap_task_mm); /* * Reaps the address space of the give task. From dfd2c809b9881653567f10f5df36e394a04bbfc9 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Fri, 5 Apr 2024 23:45:02 +0000 Subject: [PATCH 16/38] ANDROID: Update the ABI symbol list 4 function symbol(s) added 'bool __oom_reap_task_mm(struct mm_struct*)' 'int do_send_sig_info(int, struct kernel_siginfo*, struct task_struct*, enum pid_type)' 'void get_reclaim_params(int*, int*)' 'int set_reclaim_params(int, int)' Bug: 323406883 Change-Id: I07f578ef8ec675e4980f225611630c57ec9eaff3 Signed-off-by: Minchan Kim --- android/abi_gki_aarch64.stg | 59 +++++++++++++++++++++++++++++++++++ android/abi_gki_aarch64_pixel | 9 ++++++ 2 files changed, 68 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index 2da59a0da5e7..aaa41d10b09a 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -292776,6 +292776,12 @@ function { return_type_id: 0x48b5725f parameter_id: 0x126add1c } +function { + id: 0x140332fd + return_type_id: 0x48b5725f + parameter_id: 0x13580d6c + parameter_id: 0x13580d6c +} function { id: 0x140db9fc return_type_id: 0x48b5725f @@ -306310,6 +306316,14 @@ function { parameter_id: 0x6720d32f parameter_id: 0x390b641d } +function { + id: 0x84ad5b06 + return_type_id: 0x6720d32f + parameter_id: 0x6720d32f + parameter_id: 0x38264f07 + parameter_id: 0x1d19a9d5 + parameter_id: 0x94ed3026 +} function { id: 0x84af08b2 return_type_id: 0x6720d32f @@ -333955,6 +333969,11 @@ function { return_type_id: 0x1729da91 parameter_id: 0x1e9745d3 } +function { + id: 0xf869eaec + return_type_id: 0x6d7f5ff6 + parameter_id: 0x1b36c7a2 +} function { id: 0xf879ffed return_type_id: 0x0b59f310 @@ -337119,6 +337138,15 @@ elf_symbol { type_id: 0x026c1696 full_name: "__of_reset_control_get" } +elf_symbol { + id: 0x4b944f82 + name: "__oom_reap_task_mm" + is_defined: true + symbol_type: FUNCTION + crc: 0xefd8a66d + type_id: 0xf869eaec + full_name: "__oom_reap_task_mm" +} elf_symbol { id: 0x4d1e5aba name: "__page_file_index" @@ -358999,6 +359027,15 @@ elf_symbol { type_id: 0x1b27f18a full_name: "do_SAK" } +elf_symbol { + id: 0x9c1c9dfa + name: "do_send_sig_info" + is_defined: true + symbol_type: FUNCTION + crc: 0x4a95e76f + type_id: 0x84ad5b06 + full_name: "do_send_sig_info" +} elf_symbol { id: 0xb50c088c name: "do_trace_netlink_extack" @@ -366156,6 +366193,15 @@ elf_symbol { type_id: 0x534abe77 full_name: "get_random_u8" } +elf_symbol { + id: 0x7aac3cd4 + name: "get_reclaim_params" + is_defined: true + symbol_type: FUNCTION + crc: 0x14d5a025 + type_id: 0x140332fd + full_name: "get_reclaim_params" +} elf_symbol { id: 0x3a06dd48 name: "get_sg_io_hdr" @@ -389017,6 +389063,15 @@ elf_symbol { type_id: 0xff048ca3 full_name: "set_page_writeback" } +elf_symbol { + id: 0x62e16249 + name: "set_reclaim_params" + is_defined: true + symbol_type: FUNCTION + crc: 0x51ece615 + type_id: 0x85d454a8 + full_name: "set_reclaim_params" +} elf_symbol { id: 0xe19d98a9 name: "set_task_cpu" @@ -404413,6 +404468,7 @@ interface { symbol_id: 0x38c74e33 symbol_id: 0xcbeef20f symbol_id: 0x10e977be + symbol_id: 0x4b944f82 symbol_id: 0x4d1e5aba symbol_id: 0x057c7766 symbol_id: 0x8d43f7e0 @@ -406843,6 +406899,7 @@ interface { symbol_id: 0x400fac71 symbol_id: 0xdae2cdaf symbol_id: 0x6bebb14a + symbol_id: 0x9c1c9dfa symbol_id: 0xb50c088c symbol_id: 0xae435551 symbol_id: 0x718fec30 @@ -407638,6 +407695,7 @@ interface { symbol_id: 0x0447d62c symbol_id: 0xba2bc2c4 symbol_id: 0x3266d1f2 + symbol_id: 0x7aac3cd4 symbol_id: 0x3a06dd48 symbol_id: 0x75d8e345 symbol_id: 0xfa5debf3 @@ -410178,6 +410236,7 @@ interface { symbol_id: 0x455375fa symbol_id: 0xc1ea8aaa symbol_id: 0x500f328c + symbol_id: 0x62e16249 symbol_id: 0xe19d98a9 symbol_id: 0xdebcf3e9 symbol_id: 0x8f1deac6 diff --git a/android/abi_gki_aarch64_pixel b/android/abi_gki_aarch64_pixel index 66c2b850d31c..812a5ac0b34b 100644 --- a/android/abi_gki_aarch64_pixel +++ b/android/abi_gki_aarch64_pixel @@ -24,6 +24,7 @@ __alloc_skb alloc_skb_with_frags alloc_workqueue + all_vm_events alt_cb_patch_nops amba_bustype amba_driver_register @@ -611,6 +612,7 @@ dma_unmap_resource dma_unmap_sg_attrs do_SAK + do_send_sig_info do_trace_netlink_extack do_wait_intr_irq down @@ -980,6 +982,7 @@ get_random_u32 __get_random_u32_below get_random_u8 + get_reclaim_params get_sg_io_hdr __get_task_comm get_task_cred @@ -1552,6 +1555,7 @@ of_thermal_is_trip_valid of_translate_address of_usb_host_tpl_support + __oom_reap_task_mm page_endio page_frag_alloc_align __page_frag_cache_drain @@ -1563,6 +1567,7 @@ param_array_ops param_get_int param_get_string + param_get_uint param_ops_bool param_ops_byte param_ops_charp @@ -1573,6 +1578,7 @@ param_ops_ulong param_set_copystring param_set_int + param_set_uint pci_alloc_irq_vectors_affinity pci_assign_resource pci_clear_master @@ -1934,6 +1940,7 @@ sched_uclamp_used schedule schedule_timeout + schedule_timeout_idle schedule_timeout_interruptible scnprintf scsi_add_host_with_dma @@ -1984,6 +1991,7 @@ set_page_dirty set_page_dirty_lock __SetPageMovable + set_reclaim_params set_task_cpu set_user_nice sg_alloc_table @@ -2754,6 +2762,7 @@ vmap vmf_insert_pfn_prot vm_iomap_memory + vm_zone_stat vprintk vprintk_emit vring_del_virtqueue From 97808981edd8576fd35e96a471833f9f1bf417a0 Mon Sep 17 00:00:00 2001 From: Carlos Galo Date: Thu, 4 Apr 2024 23:39:13 +0000 Subject: [PATCH 17/38] Revert "FROMGIT: BACKPORT: mm: update mark_victim tracepoints fields" This reverts commit 6b4c816d17ba2c59dec517ed20d3f954d1027a8b. Reason for revert: b/331214192 Change-Id: I9f4f56de7d65cee19c7015b0cb1bda339d82a5f5 Signed-off-by: Carlos Galo --- include/trace/events/oom.h | 19 ++++--------------- mm/oom_kill.c | 7 +------ 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/include/trace/events/oom.h b/include/trace/events/oom.h index 3c5941da8075..26a11e4a2c36 100644 --- a/include/trace/events/oom.h +++ b/include/trace/events/oom.h @@ -72,30 +72,19 @@ TRACE_EVENT(reclaim_retry_zone, ); TRACE_EVENT(mark_victim, - TP_PROTO(struct task_struct *task, uid_t uid), + TP_PROTO(int pid), - TP_ARGS(task, uid), + TP_ARGS(pid), TP_STRUCT__entry( __field(int, pid) - __field(uid_t, uid) - __string(comm, task->comm) - __field(short, oom_score_adj) ), TP_fast_assign( - __entry->pid = task->pid; - __entry->uid = uid; - __assign_str(comm, task->comm); - __entry->oom_score_adj = task->signal->oom_score_adj; + __entry->pid = pid; ), - TP_printk("pid=%d uid=%u comm=%s oom_score_adj=%hd", - __entry->pid, - __entry->uid, - __get_str(comm), - __entry->oom_score_adj - ) + TP_printk("pid=%d", __entry->pid) ); TRACE_EVENT(wake_reaper, diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 7a9e1c7f636c..eb6a24072c3f 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -44,7 +44,6 @@ #include #include #include -#include #include #include "internal.h" @@ -773,8 +772,6 @@ static void __mark_oom_victim(struct task_struct *tsk) */ static void mark_oom_victim(struct task_struct *tsk) { - const struct cred *cred; - WARN_ON(oom_killer_disabled); /* OOM killer might race with memcg OOM */ if (test_and_set_tsk_thread_flag(tsk, TIF_MEMDIE)) @@ -791,9 +788,7 @@ static void mark_oom_victim(struct task_struct *tsk) */ __thaw_task(tsk); atomic_inc(&oom_victims); - cred = get_task_cred(tsk); - trace_mark_victim(tsk, cred->uid.val); - put_cred(cred); + trace_mark_victim(tsk->pid); } /** From 338203a817216e1cd81b7a19f734f58cf59ff658 Mon Sep 17 00:00:00 2001 From: Carlos Galo Date: Fri, 23 Feb 2024 17:32:49 +0000 Subject: [PATCH 18/38] BACKPORT: mm: update mark_victim tracepoints fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current implementation of the mark_victim tracepoint provides only the process ID (pid) of the victim process. This limitation poses challenges for userspace tools requiring real-time OOM analysis and intervention. Although this information is available from the kernel logs, it’s not the appropriate format to provide OOM notifications. In Android, BPF programs are used with the mark_victim trace events to notify userspace of an OOM kill. For consistency, update the trace event to include the same information about the OOMed victim as the kernel logs. - UID In Android each installed application has a unique UID. Including the `uid` assists in correlating OOM events with specific apps. - Process Name (comm) Enables identification of the affected process. - OOM Score Will allow userspace to get additional insight of the relative kill priority of the OOM victim. In Android, the oom_score_adj is used to categorize app state (foreground, background, etc.), which aids in analyzing user-perceptible impacts of OOM events [1]. - Total VM, RSS Stats, and pgtables Amount of memory used by the victim that will, potentially, be freed up by killing it. [1] https://cs.android.com/android/platform/superproject/main/+/246dc8fc95b6d93afcba5c6d6c133307abb3ac2e:frameworks/base/services/core/java/com/android/server/am/ProcessList.java;l=188-283 Signed-off-by: Carlos Galo Reviewed-by: Steven Rostedt Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: "Masami Hiramatsu (Google)" Cc: Mathieu Desnoyers Signed-off-by: Andrew Morton Bug: 331214192 (cherry picked from commit 72ba14deb40a9e9668ec5e66a341ed657e5215c2) [ carlosgalo: Manually added struct cred change in mark_oom_victim function ] Link: https://lore.kernel.org/all/20240223173258.174828-1-carlosgalo@google.com/ Change-Id: I24f503ceca04b83f8abf42fcd04a3409e17be6b5 --- include/trace/events/oom.h | 36 ++++++++++++++++++++++++++++++++---- mm/oom_kill.c | 7 ++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/include/trace/events/oom.h b/include/trace/events/oom.h index 26a11e4a2c36..b799f3bcba82 100644 --- a/include/trace/events/oom.h +++ b/include/trace/events/oom.h @@ -7,6 +7,8 @@ #include #include +#define PG_COUNT_TO_KB(x) ((x) << (PAGE_SHIFT - 10)) + TRACE_EVENT(oom_score_adj_update, TP_PROTO(struct task_struct *task), @@ -72,19 +74,45 @@ TRACE_EVENT(reclaim_retry_zone, ); TRACE_EVENT(mark_victim, - TP_PROTO(int pid), + TP_PROTO(struct task_struct *task, uid_t uid), - TP_ARGS(pid), + TP_ARGS(task, uid), TP_STRUCT__entry( __field(int, pid) + __string(comm, task->comm) + __field(unsigned long, total_vm) + __field(unsigned long, anon_rss) + __field(unsigned long, file_rss) + __field(unsigned long, shmem_rss) + __field(uid_t, uid) + __field(unsigned long, pgtables) + __field(short, oom_score_adj) ), TP_fast_assign( - __entry->pid = pid; + __entry->pid = task->pid; + __assign_str(comm, task->comm); + __entry->total_vm = PG_COUNT_TO_KB(task->mm->total_vm); + __entry->anon_rss = PG_COUNT_TO_KB(get_mm_counter(task->mm, MM_ANONPAGES)); + __entry->file_rss = PG_COUNT_TO_KB(get_mm_counter(task->mm, MM_FILEPAGES)); + __entry->shmem_rss = PG_COUNT_TO_KB(get_mm_counter(task->mm, MM_SHMEMPAGES)); + __entry->uid = uid; + __entry->pgtables = mm_pgtables_bytes(task->mm) >> 10; + __entry->oom_score_adj = task->signal->oom_score_adj; ), - TP_printk("pid=%d", __entry->pid) + TP_printk("pid=%d comm=%s total-vm=%lukB anon-rss=%lukB file-rss:%lukB shmem-rss:%lukB uid=%u pgtables=%lukB oom_score_adj=%hd", + __entry->pid, + __get_str(comm), + __entry->total_vm, + __entry->anon_rss, + __entry->file_rss, + __entry->shmem_rss, + __entry->uid, + __entry->pgtables, + __entry->oom_score_adj + ) ); TRACE_EVENT(wake_reaper, diff --git a/mm/oom_kill.c b/mm/oom_kill.c index eb6a24072c3f..7a9e1c7f636c 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include "internal.h" @@ -772,6 +773,8 @@ static void __mark_oom_victim(struct task_struct *tsk) */ static void mark_oom_victim(struct task_struct *tsk) { + const struct cred *cred; + WARN_ON(oom_killer_disabled); /* OOM killer might race with memcg OOM */ if (test_and_set_tsk_thread_flag(tsk, TIF_MEMDIE)) @@ -788,7 +791,9 @@ static void mark_oom_victim(struct task_struct *tsk) */ __thaw_task(tsk); atomic_inc(&oom_victims); - trace_mark_victim(tsk->pid); + cred = get_task_cred(tsk); + trace_mark_victim(tsk, cred->uid.val); + put_cred(cred); } /** From 5cb88480abe4c7bbdb5833c818fb6780082901b5 Mon Sep 17 00:00:00 2001 From: Sabrina Dubroca Date: Mon, 9 Oct 2023 22:50:46 +0200 Subject: [PATCH 19/38] UPSTREAM: tls: extract context alloc/initialization out of tls_set_sw_offload [ Upstream commit 615580cbc99af0da2d1c7226fab43a3d5003eb97 ] Simplify tls_set_sw_offload a bit. Bug: 326214245 Signed-off-by: Sabrina Dubroca Signed-off-by: David S. Miller Stable-dep-of: aec7961916f3 ("tls: fix race between async notify and socket close") Signed-off-by: Sasha Levin (cherry picked from commit d55eb0b495a9e4de1c61394087bb06f12d18b6bc) Signed-off-by: Lee Jones Change-Id: I97ae8c76bb91d49ca26ad9d92c7ce099a3f780ed --- net/tls/tls_sw.c | 86 ++++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index fb6337adef53..dbe8559d4bd8 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -2507,6 +2507,48 @@ void tls_update_rx_zc_capable(struct tls_context *tls_ctx) tls_ctx->prot_info.version != TLS_1_3_VERSION; } +static struct tls_sw_context_tx *init_ctx_tx(struct tls_context *ctx, struct sock *sk) +{ + struct tls_sw_context_tx *sw_ctx_tx; + + if (!ctx->priv_ctx_tx) { + sw_ctx_tx = kzalloc(sizeof(*sw_ctx_tx), GFP_KERNEL); + if (!sw_ctx_tx) + return NULL; + } else { + sw_ctx_tx = ctx->priv_ctx_tx; + } + + crypto_init_wait(&sw_ctx_tx->async_wait); + spin_lock_init(&sw_ctx_tx->encrypt_compl_lock); + INIT_LIST_HEAD(&sw_ctx_tx->tx_list); + INIT_DELAYED_WORK(&sw_ctx_tx->tx_work.work, tx_work_handler); + sw_ctx_tx->tx_work.sk = sk; + + return sw_ctx_tx; +} + +static struct tls_sw_context_rx *init_ctx_rx(struct tls_context *ctx) +{ + struct tls_sw_context_rx *sw_ctx_rx; + + if (!ctx->priv_ctx_rx) { + sw_ctx_rx = kzalloc(sizeof(*sw_ctx_rx), GFP_KERNEL); + if (!sw_ctx_rx) + return NULL; + } else { + sw_ctx_rx = ctx->priv_ctx_rx; + } + + crypto_init_wait(&sw_ctx_rx->async_wait); + spin_lock_init(&sw_ctx_rx->decrypt_compl_lock); + init_waitqueue_head(&sw_ctx_rx->wq); + skb_queue_head_init(&sw_ctx_rx->rx_list); + skb_queue_head_init(&sw_ctx_rx->async_hold); + + return sw_ctx_rx; +} + int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx) { struct tls_context *tls_ctx = tls_get_ctx(sk); @@ -2528,48 +2570,22 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx) } if (tx) { - if (!ctx->priv_ctx_tx) { - sw_ctx_tx = kzalloc(sizeof(*sw_ctx_tx), GFP_KERNEL); - if (!sw_ctx_tx) { - rc = -ENOMEM; - goto out; - } - ctx->priv_ctx_tx = sw_ctx_tx; - } else { - sw_ctx_tx = - (struct tls_sw_context_tx *)ctx->priv_ctx_tx; - } - } else { - if (!ctx->priv_ctx_rx) { - sw_ctx_rx = kzalloc(sizeof(*sw_ctx_rx), GFP_KERNEL); - if (!sw_ctx_rx) { - rc = -ENOMEM; - goto out; - } - ctx->priv_ctx_rx = sw_ctx_rx; - } else { - sw_ctx_rx = - (struct tls_sw_context_rx *)ctx->priv_ctx_rx; - } - } + ctx->priv_ctx_tx = init_ctx_tx(ctx, sk); + if (!ctx->priv_ctx_tx) + return -ENOMEM; - if (tx) { - crypto_init_wait(&sw_ctx_tx->async_wait); - spin_lock_init(&sw_ctx_tx->encrypt_compl_lock); + sw_ctx_tx = ctx->priv_ctx_tx; crypto_info = &ctx->crypto_send.info; cctx = &ctx->tx; aead = &sw_ctx_tx->aead_send; - INIT_LIST_HEAD(&sw_ctx_tx->tx_list); - INIT_DELAYED_WORK(&sw_ctx_tx->tx_work.work, tx_work_handler); - sw_ctx_tx->tx_work.sk = sk; } else { - crypto_init_wait(&sw_ctx_rx->async_wait); - spin_lock_init(&sw_ctx_rx->decrypt_compl_lock); - init_waitqueue_head(&sw_ctx_rx->wq); + ctx->priv_ctx_rx = init_ctx_rx(ctx); + if (!ctx->priv_ctx_rx) + return -ENOMEM; + + sw_ctx_rx = ctx->priv_ctx_rx; crypto_info = &ctx->crypto_recv.info; cctx = &ctx->rx; - skb_queue_head_init(&sw_ctx_rx->rx_list); - skb_queue_head_init(&sw_ctx_rx->async_hold); aead = &sw_ctx_rx->aead_recv; } From fd16669b182b380350effa5566f6739882da6f65 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 6 Feb 2024 17:18:18 -0800 Subject: [PATCH 20/38] UPSTREAM: net: tls: factor out tls_*crypt_async_wait() [ Upstream commit c57ca512f3b68ddcd62bda9cc24a8f5584ab01b1 ] Factor out waiting for async encrypt and decrypt to finish. There are already multiple copies and a subsequent fix will need more. No functional changes. Note that crypto_wait_req() returns wait->err Bug: 326214245 Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Reviewed-by: Sabrina Dubroca Signed-off-by: David S. Miller Stable-dep-of: aec7961916f3 ("tls: fix race between async notify and socket close") Signed-off-by: Sasha Levin (cherry picked from commit 2c6841c88201e13967583f0f8a9f9b54b9cde404) Signed-off-by: Lee Jones Change-Id: I7355c32d284623e08650c4d2b2a7d3be40f0cc0c --- net/tls/tls_sw.c | 78 +++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index dbe8559d4bd8..aae9f012a0a0 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -229,6 +229,20 @@ static void tls_decrypt_done(crypto_completion_data_t *data, int err) spin_unlock_bh(&ctx->decrypt_compl_lock); } +static int tls_decrypt_async_wait(struct tls_sw_context_rx *ctx) +{ + int pending; + + spin_lock_bh(&ctx->decrypt_compl_lock); + reinit_completion(&ctx->async_wait.completion); + pending = atomic_read(&ctx->decrypt_pending); + spin_unlock_bh(&ctx->decrypt_compl_lock); + if (pending) + crypto_wait_req(-EINPROGRESS, &ctx->async_wait); + + return ctx->async_wait.err; +} + static int tls_do_decryption(struct sock *sk, struct scatterlist *sgin, struct scatterlist *sgout, @@ -496,6 +510,28 @@ static void tls_encrypt_done(crypto_completion_data_t *data, int err) schedule_delayed_work(&ctx->tx_work.work, 1); } +static int tls_encrypt_async_wait(struct tls_sw_context_tx *ctx) +{ + int pending; + + spin_lock_bh(&ctx->encrypt_compl_lock); + ctx->async_notify = true; + + pending = atomic_read(&ctx->encrypt_pending); + spin_unlock_bh(&ctx->encrypt_compl_lock); + if (pending) + crypto_wait_req(-EINPROGRESS, &ctx->async_wait); + else + reinit_completion(&ctx->async_wait.completion); + + /* There can be no concurrent accesses, since we have no + * pending encrypt operations + */ + WRITE_ONCE(ctx->async_notify, false); + + return ctx->async_wait.err; +} + static int tls_do_encryption(struct sock *sk, struct tls_context *tls_ctx, struct tls_sw_context_tx *ctx, @@ -953,7 +989,6 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) int num_zc = 0; int orig_size; int ret = 0; - int pending; if (msg->msg_flags & ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_CMSG_COMPAT)) @@ -1122,24 +1157,12 @@ trim_sgl: if (!num_async) { goto send_end; } else if (num_zc) { + int err; + /* Wait for pending encryptions to get completed */ - spin_lock_bh(&ctx->encrypt_compl_lock); - ctx->async_notify = true; - - pending = atomic_read(&ctx->encrypt_pending); - spin_unlock_bh(&ctx->encrypt_compl_lock); - if (pending) - crypto_wait_req(-EINPROGRESS, &ctx->async_wait); - else - reinit_completion(&ctx->async_wait.completion); - - /* There can be no concurrent accesses, since we have no - * pending encrypt operations - */ - WRITE_ONCE(ctx->async_notify, false); - - if (ctx->async_wait.err) { - ret = ctx->async_wait.err; + err = tls_encrypt_async_wait(ctx); + if (err) { + ret = err; copied = 0; } } @@ -2117,16 +2140,10 @@ put_on_rx_list: recv_end: if (async) { - int ret, pending; + int ret; /* Wait for all previously submitted records to be decrypted */ - spin_lock_bh(&ctx->decrypt_compl_lock); - reinit_completion(&ctx->async_wait.completion); - pending = atomic_read(&ctx->decrypt_pending); - spin_unlock_bh(&ctx->decrypt_compl_lock); - ret = 0; - if (pending) - ret = crypto_wait_req(-EINPROGRESS, &ctx->async_wait); + ret = tls_decrypt_async_wait(ctx); __skb_queue_purge(&ctx->async_hold); if (ret) { @@ -2345,16 +2362,9 @@ void tls_sw_release_resources_tx(struct sock *sk) struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_sw_context_tx *ctx = tls_sw_ctx_tx(tls_ctx); struct tls_rec *rec, *tmp; - int pending; /* Wait for any pending async encryptions to complete */ - spin_lock_bh(&ctx->encrypt_compl_lock); - ctx->async_notify = true; - pending = atomic_read(&ctx->encrypt_pending); - spin_unlock_bh(&ctx->encrypt_compl_lock); - - if (pending) - crypto_wait_req(-EINPROGRESS, &ctx->async_wait); + tls_encrypt_async_wait(ctx); tls_tx_records(sk, -1); From 5b4439c0d77012b040ec1ad511f7daa443313e44 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 6 Feb 2024 17:18:19 -0800 Subject: [PATCH 21/38] UPSTREAM: tls: fix race between async notify and socket close [ Upstream commit aec7961916f3f9e88766e2688992da6980f11b8d ] The submitting thread (one which called recvmsg/sendmsg) may exit as soon as the async crypto handler calls complete() so any code past that point risks touching already freed data. Try to avoid the locking and extra flags altogether. Have the main thread hold an extra reference, this way we can depend solely on the atomic ref counter for synchronization. Don't futz with reiniting the completion, either, we are now tightly controlling when completion fires. Bug: 326214245 Reported-by: valis Fixes: 0cada33241d9 ("net/tls: fix race condition causing kernel panic") Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Reviewed-by: Eric Dumazet Reviewed-by: Sabrina Dubroca Signed-off-by: David S. Miller Signed-off-by: Sasha Levin (cherry picked from commit 7a3ca06d04d589deec81f56229a9a9d62352ce01) Signed-off-by: Lee Jones Change-Id: Idda32dd68ed26ae5c85c985305f52c3b2245e32c --- include/net/tls.h | 5 ----- net/tls/tls_sw.c | 43 ++++++++++--------------------------------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/include/net/tls.h b/include/net/tls.h index 1196d7202f85..8729dd02ec07 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -109,9 +109,6 @@ struct tls_sw_context_tx { struct tls_rec *open_rec; struct list_head tx_list; atomic_t encrypt_pending; - /* protect crypto_wait with encrypt_pending */ - spinlock_t encrypt_compl_lock; - int async_notify; u8 async_capable:1; #define BIT_TX_SCHEDULED 0 @@ -150,8 +147,6 @@ struct tls_sw_context_rx { struct tls_strparser strp; atomic_t decrypt_pending; - /* protect crypto_wait with decrypt_pending*/ - spinlock_t decrypt_compl_lock; struct sk_buff_head async_hold; struct wait_queue_head wq; diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index aae9f012a0a0..d135cac39f97 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -223,22 +223,15 @@ static void tls_decrypt_done(crypto_completion_data_t *data, int err) kfree(aead_req); - spin_lock_bh(&ctx->decrypt_compl_lock); - if (!atomic_dec_return(&ctx->decrypt_pending)) + if (atomic_dec_and_test(&ctx->decrypt_pending)) complete(&ctx->async_wait.completion); - spin_unlock_bh(&ctx->decrypt_compl_lock); } static int tls_decrypt_async_wait(struct tls_sw_context_rx *ctx) { - int pending; - - spin_lock_bh(&ctx->decrypt_compl_lock); - reinit_completion(&ctx->async_wait.completion); - pending = atomic_read(&ctx->decrypt_pending); - spin_unlock_bh(&ctx->decrypt_compl_lock); - if (pending) + if (!atomic_dec_and_test(&ctx->decrypt_pending)) crypto_wait_req(-EINPROGRESS, &ctx->async_wait); + atomic_inc(&ctx->decrypt_pending); return ctx->async_wait.err; } @@ -266,6 +259,7 @@ static int tls_do_decryption(struct sock *sk, aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_BACKLOG, tls_decrypt_done, aead_req); + DEBUG_NET_WARN_ON_ONCE(atomic_read(&ctx->decrypt_pending) < 1); atomic_inc(&ctx->decrypt_pending); } else { aead_request_set_callback(aead_req, @@ -455,7 +449,6 @@ static void tls_encrypt_done(crypto_completion_data_t *data, int err) struct tls_rec *rec; bool ready = false; struct sock *sk; - int pending; rec = container_of(aead_req, struct tls_rec, aead_req); msg_en = &rec->msg_encrypted; @@ -495,12 +488,8 @@ static void tls_encrypt_done(crypto_completion_data_t *data, int err) ready = true; } - spin_lock_bh(&ctx->encrypt_compl_lock); - pending = atomic_dec_return(&ctx->encrypt_pending); - - if (!pending && ctx->async_notify) + if (atomic_dec_and_test(&ctx->encrypt_pending)) complete(&ctx->async_wait.completion); - spin_unlock_bh(&ctx->encrypt_compl_lock); if (!ready) return; @@ -512,22 +501,9 @@ static void tls_encrypt_done(crypto_completion_data_t *data, int err) static int tls_encrypt_async_wait(struct tls_sw_context_tx *ctx) { - int pending; - - spin_lock_bh(&ctx->encrypt_compl_lock); - ctx->async_notify = true; - - pending = atomic_read(&ctx->encrypt_pending); - spin_unlock_bh(&ctx->encrypt_compl_lock); - if (pending) + if (!atomic_dec_and_test(&ctx->encrypt_pending)) crypto_wait_req(-EINPROGRESS, &ctx->async_wait); - else - reinit_completion(&ctx->async_wait.completion); - - /* There can be no concurrent accesses, since we have no - * pending encrypt operations - */ - WRITE_ONCE(ctx->async_notify, false); + atomic_inc(&ctx->encrypt_pending); return ctx->async_wait.err; } @@ -578,6 +554,7 @@ static int tls_do_encryption(struct sock *sk, /* Add the record in tx_list */ list_add_tail((struct list_head *)&rec->list, &ctx->tx_list); + DEBUG_NET_WARN_ON_ONCE(atomic_read(&ctx->encrypt_pending) < 1); atomic_inc(&ctx->encrypt_pending); rc = crypto_aead_encrypt(aead_req); @@ -2530,7 +2507,7 @@ static struct tls_sw_context_tx *init_ctx_tx(struct tls_context *ctx, struct soc } crypto_init_wait(&sw_ctx_tx->async_wait); - spin_lock_init(&sw_ctx_tx->encrypt_compl_lock); + atomic_set(&sw_ctx_tx->encrypt_pending, 1); INIT_LIST_HEAD(&sw_ctx_tx->tx_list); INIT_DELAYED_WORK(&sw_ctx_tx->tx_work.work, tx_work_handler); sw_ctx_tx->tx_work.sk = sk; @@ -2551,7 +2528,7 @@ static struct tls_sw_context_rx *init_ctx_rx(struct tls_context *ctx) } crypto_init_wait(&sw_ctx_rx->async_wait); - spin_lock_init(&sw_ctx_rx->decrypt_compl_lock); + atomic_set(&sw_ctx_rx->decrypt_pending, 1); init_waitqueue_head(&sw_ctx_rx->wq); skb_queue_head_init(&sw_ctx_rx->rx_list); skb_queue_head_init(&sw_ctx_rx->async_hold); From cdc8aeb8932c9bde410be00dc708e6f8e2b54530 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 18 Jan 2024 10:56:26 +0100 Subject: [PATCH 22/38] UPSTREAM: netfilter: nft_chain_filter: handle NETDEV_UNREGISTER for inet/ingress basechain commit 01acb2e8666a6529697141a6017edbf206921913 upstream. Remove netdevice from inet/ingress basechain in case NETDEV_UNREGISTER event is reported, otherwise a stale reference to netdevice remains in the hook list. Bug: 332803585 Fixes: 60a3815da702 ("netfilter: add inet ingress support") Cc: stable@vger.kernel.org Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 70f17b48c86622217a58d5099d29242fc9adac58) Signed-off-by: Lee Jones Change-Id: I28482dca416b61dcf2e722ba0aef62d2d41a8f23 --- net/netfilter/nft_chain_filter.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nft_chain_filter.c b/net/netfilter/nft_chain_filter.c index 680fe557686e..274b6f7e6bb5 100644 --- a/net/netfilter/nft_chain_filter.c +++ b/net/netfilter/nft_chain_filter.c @@ -357,9 +357,10 @@ static int nf_tables_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); + struct nft_base_chain *basechain; struct nftables_pernet *nft_net; - struct nft_table *table; struct nft_chain *chain, *nr; + struct nft_table *table; struct nft_ctx ctx = { .net = dev_net(dev), }; @@ -371,7 +372,8 @@ static int nf_tables_netdev_event(struct notifier_block *this, nft_net = nft_pernet(ctx.net); mutex_lock(&nft_net->commit_mutex); list_for_each_entry(table, &nft_net->tables, list) { - if (table->family != NFPROTO_NETDEV) + if (table->family != NFPROTO_NETDEV && + table->family != NFPROTO_INET) continue; ctx.family = table->family; @@ -380,6 +382,11 @@ static int nf_tables_netdev_event(struct notifier_block *this, if (!nft_is_base_chain(chain)) continue; + basechain = nft_base_chain(chain); + if (table->family == NFPROTO_INET && + basechain->ops.hooknum != NF_INET_INGRESS) + continue; + ctx.chain = chain; nft_netdev_event(event, dev, &ctx); } From 5dc2bc2966470f7579d5236bae6888d35ddc4d9e Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 6 Feb 2024 17:18:20 -0800 Subject: [PATCH 23/38] UPSTREAM: tls: fix race between tx work scheduling and socket close commit e01e3934a1b2d122919f73bc6ddbe1cdafc4bbdb upstream. Similarly to previous commit, the submitting thread (recvmsg/sendmsg) may exit as soon as the async crypto handler calls complete(). Reorder scheduling the work before calling complete(). This seems more logical in the first place, as it's the inverse order of what the submitting thread will do. Bug: 326214245 Reported-by: valis Fixes: a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance") Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Reviewed-by: Sabrina Dubroca Signed-off-by: David S. Miller [Lee: Fixed merge-conflict in Stable branches linux-6.1.y and older] Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 196f198ca6fce04ba6ce262f5a0e4d567d7d219d) Signed-off-by: Lee Jones Change-Id: I3128347d1e45018db30b6f2336ece2a4a3a630db (cherry picked from commit e78d26a9ec366b108c89099b148ae3cea6f1a8e9) --- net/tls/tls_sw.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index d135cac39f97..6767e19be79b 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -447,7 +447,6 @@ static void tls_encrypt_done(crypto_completion_data_t *data, int err) struct scatterlist *sge; struct sk_msg *msg_en; struct tls_rec *rec; - bool ready = false; struct sock *sk; rec = container_of(aead_req, struct tls_rec, aead_req); @@ -484,19 +483,16 @@ static void tls_encrypt_done(crypto_completion_data_t *data, int err) /* If received record is at head of tx_list, schedule tx */ first_rec = list_first_entry(&ctx->tx_list, struct tls_rec, list); - if (rec == first_rec) - ready = true; + if (rec == first_rec) { + /* Schedule the transmission */ + if (!test_and_set_bit(BIT_TX_SCHEDULED, + &ctx->tx_bitmask)) + schedule_delayed_work(&ctx->tx_work.work, 1); + } } if (atomic_dec_and_test(&ctx->encrypt_pending)) complete(&ctx->async_wait.completion); - - if (!ready) - return; - - /* Schedule the transmission */ - if (!test_and_set_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask)) - schedule_delayed_work(&ctx->tx_work.work, 1); } static int tls_encrypt_async_wait(struct tls_sw_context_tx *ctx) From 165b01710b995f5ceb3c3db27c1aa668ca264e92 Mon Sep 17 00:00:00 2001 From: Kyle Tso Date: Thu, 4 Apr 2024 21:35:17 +0800 Subject: [PATCH 24/38] FROMGIT: usb: typec: tcpm: Correct the PDO counting in pd_set Off-by-one errors happen because nr_snk_pdo and nr_src_pdo are incorrectly added one. The index of the loop is equal to the number of PDOs to be updated when leaving the loop and it doesn't need to be added one. When doing the power negotiation, TCPM relies on the "nr_snk_pdo" as the size of the local sink PDO array to match the Source capabilities of the partner port. If the off-by-one overflow occurs, a wrong RDO might be sent and unexpected power transfer might happen such as over voltage or over current (than expected). "nr_src_pdo" is used to set the Rp level when the port is in Source role. It is also the array size of the local Source capabilities when filling up the buffer which will be sent as the Source PDOs (such as in Power Negotiation). If the off-by-one overflow occurs, a wrong Rp level might be set and wrong Source PDOs will be sent to the partner port. This could potentially cause over current or port resets. Fixes: cd099cde4ed2 ("usb: typec: tcpm: Support multiple capabilities") Cc: stable@vger.kernel.org Signed-off-by: Kyle Tso Reviewed-by: Heikki Krogerus Link: https://lore.kernel.org/r/20240404133517.2707955-1-kyletso@google.com Signed-off-by: Greg Kroah-Hartman Bug: 206108037 (cherry picked from commit c4128304c2169b4664ed6fb6200f228cead2ab70 git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-linus) Change-Id: Icf86f562c7bbaefe7e27885e107b373aa4b64fd0 Signed-off-by: Kyle Tso --- drivers/usb/typec/tcpm/tcpm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 78948f4ebb68..9aa216db0f10 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -6167,14 +6167,14 @@ static int tcpm_pd_set(struct typec_port *p, struct usb_power_delivery *pd) if (data->sink_desc.pdo[0]) { for (i = 0; i < PDO_MAX_OBJECTS && data->sink_desc.pdo[i]; i++) port->snk_pdo[i] = data->sink_desc.pdo[i]; - port->nr_snk_pdo = i + 1; + port->nr_snk_pdo = i; port->operating_snk_mw = data->operating_snk_mw; } if (data->source_desc.pdo[0]) { for (i = 0; i < PDO_MAX_OBJECTS && data->source_desc.pdo[i]; i++) port->src_pdo[i] = data->source_desc.pdo[i]; - port->nr_src_pdo = i + 1; + port->nr_src_pdo = i; } switch (port->state) { From 4b8e1f520a4187930e16d8c9d3df9c6f54a6b8ca Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 29 Feb 2024 13:42:07 +0530 Subject: [PATCH 25/38] BACKPORT: cpufreq: Don't unregister cpufreq cooling on CPU hotplug Offlining a CPU and bringing it back online is a common operation and it happens frequently during system suspend/resume, where the non-boot CPUs are hotplugged out during suspend and brought back at resume. The cpufreq core already tries to make this path as fast as possible as the changes are only temporary in nature and full cleanup of resources isn't required in this case. For example the drivers can implement online()/offline() callbacks to avoid a lot of tear down of resources. On similar lines, there is no need to unregister the cpufreq cooling device during suspend / resume, but only while the policy is getting removed. Moreover, unregistering the cpufreq cooling device is resulting in an unwanted outcome, where the system suspend is eventually aborted in the process. Currently, during system suspend the cpufreq core unregisters the cooling device, which in turn removes a kobject using device_del() and that generates a notification to the userspace via uevent broadcast. This causes system suspend to abort in some setups. This was also earlier reported (indirectly) by Roman [1]. Maybe there is another way around to fixing that problem properly, but this change makes sense anyways. Move the registering and unregistering of the cooling device to policy creation and removal times onlyy. Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218521 Reported-by: Manaf Meethalavalappu Pallikunhi Reported-by: Roman Stratiienko Link: https://patchwork.kernel.org/project/linux-pm/patch/20220710164026.541466-1-r.stratiienko@gmail.com/ [1] Tested-by: Manaf Meethalavalappu Pallikunhi Signed-off-by: Viresh Kumar Reviewed-by: Dhruva Gole Signed-off-by: Rafael J. Wysocki (cherry picked from commit c4d61a529db788d2e52654f5b02c8d1de4952c5b) Change-Id: I0b9435be1c2b41ea52a26cb578d850fd8121d57a [jstultz: Tweaked to work around collision with existing android_vh calls] Signed-off-by: John Stultz Bug: 333300519 --- drivers/cpufreq/cpufreq.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 53b98d66894a..eeead4566230 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1540,7 +1540,8 @@ static int cpufreq_online(unsigned int cpu) if (cpufreq_driver->ready) cpufreq_driver->ready(policy); - if (cpufreq_thermal_control_enabled(cpufreq_driver)) { + /* Register cpufreq cooling only for a new policy */ + if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver)) { policy->cdev = of_cpufreq_cooling_register(policy); trace_android_vh_thermal_register(policy); } @@ -1626,12 +1627,6 @@ static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy) else policy->last_policy = policy->policy; - if (cpufreq_thermal_control_enabled(cpufreq_driver)) { - cpufreq_cooling_unregister(policy->cdev); - trace_android_vh_thermal_unregister(policy); - policy->cdev = NULL; - } - if (has_target()) cpufreq_exit_governor(policy); @@ -1692,6 +1687,16 @@ static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) return; } + /* + * Unregister cpufreq cooling once all the CPUs of the policy are + * removed. + */ + if (cpufreq_thermal_control_enabled(cpufreq_driver)) { + cpufreq_cooling_unregister(policy->cdev); + trace_android_vh_thermal_unregister(policy); + policy->cdev = NULL; + } + /* We did light-weight exit earlier, do full tear down now */ if (cpufreq_driver->offline) cpufreq_driver->exit(policy); From be55946e207c5ea978b402454a73aec2701df49d Mon Sep 17 00:00:00 2001 From: Chungjui Fan Date: Wed, 10 Apr 2024 12:20:36 +0000 Subject: [PATCH 26/38] ANDROID: Update the ABI symbol list Adding the following symbols: - ksoftirqd - pwmchip_add - pwmchip_remove - pwm_get_chip_data - pwm_set_chip_data Bug: 307424586 Change-Id: I1a73d09feb888394925d23b4cdfce7bc3d1b0d9c Signed-off-by: Chungjui Fan --- android/abi_gki_aarch64_pixel | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/abi_gki_aarch64_pixel b/android/abi_gki_aarch64_pixel index 812a5ac0b34b..116346877ebb 100644 --- a/android/abi_gki_aarch64_pixel +++ b/android/abi_gki_aarch64_pixel @@ -1264,6 +1264,7 @@ kobj_sysfs_ops krealloc ksize + ksoftirqd kstat kstrdup kstrndup @@ -1754,6 +1755,10 @@ put_unused_fd put_vaddr_frames pwm_apply_state + pwmchip_add + pwmchip_remove + pwm_get_chip_data + pwm_set_chip_data queue_delayed_work_on queue_work_on radix_tree_delete_item From 59ef545736e9ffc729f8010a4d18149fb1e5a2ef Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 10 Apr 2024 05:35:06 +0000 Subject: [PATCH 27/38] ANDROID: vendor_hooks: add restricted vendor hook for meminfo To report vendor-specific memory statistics, add restricted vendor hook since normal vendor hook work with only atomic context. Bug: 333482947 Change-Id: I5c32961b30f082a8a4aa78906d2fce1cdf4b0d2b Signed-off-by: Minchan Kim --- drivers/android/vendor_hooks.c | 1 + fs/proc/meminfo.c | 1 + include/trace/hooks/mm.h | 3 +++ 3 files changed, 5 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index f83f72e0e820..9322df8ce828 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -237,6 +237,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gic_v3_affinity_init); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterrupt_tasks); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterrupt_tasks_done); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_meminfo_proc_show); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_meminfo_proc_show); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_exit_mm); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_pages_slowpath); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_show_mem); diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 24a133eb3576..fb82ef502105 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -158,6 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) global_zone_page_state(NR_FREE_CMA_PAGES)); #endif trace_android_vh_meminfo_proc_show(m); + trace_android_rvh_meminfo_proc_show(m); hugetlb_report_meminfo(m); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 50addc57dc10..28dcf14b9d72 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -60,6 +60,9 @@ DECLARE_HOOK(android_vh_filemap_get_folio, DECLARE_HOOK(android_vh_meminfo_proc_show, TP_PROTO(struct seq_file *m), TP_ARGS(m)); +DECLARE_RESTRICTED_HOOK(android_rvh_meminfo_proc_show, + TP_PROTO(struct seq_file *m), + TP_ARGS(m), 1); DECLARE_HOOK(android_vh_exit_mm, TP_PROTO(struct mm_struct *mm), TP_ARGS(mm)); From ca4095789fda0c531922da568fa9971ffd953cba Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 10 Apr 2024 05:41:06 +0000 Subject: [PATCH 28/38] ANDROID: Update the ABI symbol list 1 function symbol(s) added 'int __traceiter_android_rvh_meminfo_proc_show(void*, struct seq_file*)' 1 variable symbol(s) added 'struct tracepoint __tracepoint_android_rvh_meminfo_proc_show' Bug: 333482947 Change-Id: I27ffd601307085f35aa853a214838fda605f901d Signed-off-by: Minchan Kim --- android/abi_gki_aarch64.stg | 20 ++++++++++++++++++++ android/abi_gki_aarch64_pixel | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index aaa41d10b09a..25863710f751 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -338542,6 +338542,15 @@ elf_symbol { type_id: 0x9bc253cf full_name: "__traceiter_android_rvh_is_cpu_allowed" } +elf_symbol { + id: 0xed2646da + name: "__traceiter_android_rvh_meminfo_proc_show" + is_defined: true + symbol_type: FUNCTION + crc: 0x92ecc686 + type_id: 0x9bb62df9 + full_name: "__traceiter_android_rvh_meminfo_proc_show" +} elf_symbol { id: 0x1ea5d323 name: "__traceiter_android_rvh_migrate_queued_task" @@ -342763,6 +342772,15 @@ elf_symbol { type_id: 0x18ccbd2c full_name: "__tracepoint_android_rvh_is_cpu_allowed" } +elf_symbol { + id: 0x2252c1f0 + name: "__tracepoint_android_rvh_meminfo_proc_show" + is_defined: true + symbol_type: OBJECT + crc: 0x0894f789 + type_id: 0x18ccbd2c + full_name: "__tracepoint_android_rvh_meminfo_proc_show" +} elf_symbol { id: 0x3cb4db49 name: "__tracepoint_android_rvh_migrate_queued_task" @@ -404624,6 +404642,7 @@ interface { symbol_id: 0xfc83b254 symbol_id: 0x7e99bc71 symbol_id: 0x7c212080 + symbol_id: 0xed2646da symbol_id: 0x1ea5d323 symbol_id: 0xc1a482d8 symbol_id: 0x9c17d92b @@ -405093,6 +405112,7 @@ interface { symbol_id: 0x4fd98142 symbol_id: 0x695c4baf symbol_id: 0x99d57c12 + symbol_id: 0x2252c1f0 symbol_id: 0x3cb4db49 symbol_id: 0x3a6f3fb2 symbol_id: 0x8b0b932d diff --git a/android/abi_gki_aarch64_pixel b/android/abi_gki_aarch64_pixel index 116346877ebb..fe4e815bf551 100644 --- a/android/abi_gki_aarch64_pixel +++ b/android/abi_gki_aarch64_pixel @@ -1617,6 +1617,7 @@ pci_wake_from_d3 pci_write_config_dword pci_write_config_word + pcpu_nr_pages __per_cpu_offset perf_aux_output_begin perf_aux_output_end @@ -2015,6 +2016,7 @@ __sg_page_iter_start sg_pcopy_from_buffer shmem_file_setup + si_meminfo simple_attr_open simple_attr_read simple_attr_release @@ -2330,6 +2332,7 @@ __traceiter_android_rvh_iommu_limit_align_shift __traceiter_android_rvh_irqs_disable __traceiter_android_rvh_irqs_enable + __traceiter_android_rvh_meminfo_proc_show __traceiter_android_rvh_post_init_entity_util_avg __traceiter_android_rvh_preempt_disable __traceiter_android_rvh_preempt_enable @@ -2453,6 +2456,7 @@ __tracepoint_android_rvh_iommu_limit_align_shift __tracepoint_android_rvh_irqs_disable __tracepoint_android_rvh_irqs_enable + __tracepoint_android_rvh_meminfo_proc_show __tracepoint_android_rvh_post_init_entity_util_avg __tracepoint_android_rvh_preempt_disable __tracepoint_android_rvh_preempt_enable @@ -2762,11 +2766,13 @@ virtqueue_kick_prepare virtqueue_notify vmalloc + vmalloc_nr_pages vmalloc_to_page vmalloc_user vmap vmf_insert_pfn_prot vm_iomap_memory + vm_node_stat vm_zone_stat vprintk vprintk_emit From 354782156070d1383fc8a35823fdb97b6bbfea16 Mon Sep 17 00:00:00 2001 From: lukechang Date: Thu, 11 Apr 2024 08:27:39 +0000 Subject: [PATCH 29/38] ANDROID: softirq: add tasklet to LONG_SOFTIRQ_MASK In commit 35a06697da792f6a8e56a600c671bdd980c10d36 ("FROMLIST: sched: Avoid placing RT threads on cores handling long softirqs"), the patch drop TASKLET_SOFTIRQ from LONG_SOFTIRQS. Some drivers use tasklet softirq for data reception from firmware. When there's a high volume or continuous stream of data from the firmware, it can lead to unexpectedly long execution times for RT tasks and further cause jank or audio glitch. Bug: 333895950 Test: check tasklet are defered when RT task is running Change-Id: I53d6b43fe5a8860758898f09810a52fe319344f9 Signed-off-by: lukechang --- include/linux/interrupt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index 177547593ee4..cfa532cbd2e8 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -590,7 +590,8 @@ enum #define LONG_SOFTIRQ_MASK (BIT(NET_TX_SOFTIRQ) | \ BIT(NET_RX_SOFTIRQ) | \ BIT(BLOCK_SOFTIRQ) | \ - BIT(IRQ_POLL_SOFTIRQ)) + BIT(IRQ_POLL_SOFTIRQ) | \ + BIT(TASKLET_SOFTIRQ)) /* map softirq index to softirq name. update 'softirq_to_name' in * kernel/softirq.c when adding a new softirq. From e6dcd23df8a1e3626e58638cfcbad6db78ef9ba1 Mon Sep 17 00:00:00 2001 From: Norihiko Hama Date: Thu, 11 Apr 2024 13:57:06 +0900 Subject: [PATCH 30/38] ANDROID: GKI: Update honda symbol list for net scheduler Add some missing symbols required for net scheduler 4 function symbol(s) added 'void tc_cleanup_offload_action(struct flow_action*)' 'int tc_setup_offload_action(struct flow_action*, const struct tcf_exts*, struct netlink_ext_ack*)' 'int tcf_action_update_hw_stats(struct tc_action*)' 'int tcf_exts_validate_ex(struct net*, struct tcf_proto*, struct nlattr**, struct nlattr*, struct tcf_exts*, u32, u32, struct netlink_ext_ack*)' Bug: 333795249 Change-Id: I2cefa08e07a6c8b8d9b9032f35792d7df9f94b0d Signed-off-by: Norihiko Hama --- android/abi_gki_aarch64.stg | 84 +++++++++++++++++++++++++++++++++++ android/abi_gki_aarch64_honda | 4 ++ 2 files changed, 88 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index 25863710f751..1deb33e345fd 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -26613,6 +26613,11 @@ pointer_reference { kind: POINTER pointee_type_id: 0xc8994ffb } +pointer_reference { + id: 0x38bb4688 + kind: POINTER + pointee_type_id: 0xc8adfcbd +} pointer_reference { id: 0x38bc670e kind: POINTER @@ -27888,6 +27893,11 @@ pointer_reference { kind: POINTER pointee_type_id: 0xc50f0744 } +pointer_reference { + id: 0x3bd482ed + kind: POINTER + pointee_type_id: 0xc512ed2b +} pointer_reference { id: 0x3bd6fa3a kind: POINTER @@ -32213,6 +32223,11 @@ qualified { qualifier: CONST qualified_type_id: 0x639c2545 } +qualified { + id: 0xc512ed2b + qualifier: CONST + qualified_type_id: 0x640c0226 +} qualified { id: 0xc5274ab2 qualifier: CONST @@ -299826,6 +299841,11 @@ function { parameter_id: 0x6d7f5ff6 parameter_id: 0x6d7f5ff6 } +function { + id: 0x1eb68031 + return_type_id: 0x48b5725f + parameter_id: 0x38bb4688 +} function { id: 0x1eb74850 return_type_id: 0x48b5725f @@ -310453,6 +310473,11 @@ function { parameter_id: 0xc9082b19 parameter_id: 0x07dcdbe1 } +function { + id: 0x926a291d + return_type_id: 0x6720d32f + parameter_id: 0x3fab28c8 +} function { id: 0x926bbb17 return_type_id: 0x6720d32f @@ -311635,6 +311660,13 @@ function { parameter_id: 0x391e6bd6 parameter_id: 0x3e10b518 } +function { + id: 0x934097b0 + return_type_id: 0x6720d32f + parameter_id: 0x38bb4688 + parameter_id: 0x3bd482ed + parameter_id: 0x07dcdbe1 +} function { id: 0x9340e134 return_type_id: 0x6720d32f @@ -327800,6 +327832,18 @@ function { parameter_id: 0xc9082b19 parameter_id: 0x07dcdbe1 } +function { + id: 0x9e8d7e28 + return_type_id: 0x6720d32f + parameter_id: 0x0ca27481 + parameter_id: 0x09451098 + parameter_id: 0x0277bf8a + parameter_id: 0x239e18b5 + parameter_id: 0x1393392e + parameter_id: 0xc9082b19 + parameter_id: 0xc9082b19 + parameter_id: 0x07dcdbe1 +} function { id: 0x9e8fd7cb return_type_id: 0x6720d32f @@ -394260,6 +394304,15 @@ elf_symbol { type_id: 0xf4933b90 full_name: "tasklist_lock" } +elf_symbol { + id: 0xbdf90845 + name: "tc_cleanup_offload_action" + is_defined: true + symbol_type: FUNCTION + crc: 0x17886569 + type_id: 0x1eb68031 + full_name: "tc_cleanup_offload_action" +} elf_symbol { id: 0x1a591d57 name: "tc_setup_cb_add" @@ -394296,6 +394349,15 @@ elf_symbol { type_id: 0x932e1cba full_name: "tc_setup_cb_reoffload" } +elf_symbol { + id: 0x988023d7 + name: "tc_setup_offload_action" + is_defined: true + symbol_type: FUNCTION + crc: 0x77174f16 + type_id: 0x934097b0 + full_name: "tc_setup_offload_action" +} elf_symbol { id: 0xd6059721 name: "tcf_action_check_ctrlact" @@ -394323,6 +394385,15 @@ elf_symbol { type_id: 0xd6fcc6b4 full_name: "tcf_action_set_ctrlact" } +elf_symbol { + id: 0xd4d51230 + name: "tcf_action_update_hw_stats" + is_defined: true + symbol_type: FUNCTION + crc: 0xfb5e97ce + type_id: 0x926a291d + full_name: "tcf_action_update_hw_stats" +} elf_symbol { id: 0x2fba8b59 name: "tcf_action_update_stats" @@ -394395,6 +394466,15 @@ elf_symbol { type_id: 0x9e8d7e1b full_name: "tcf_exts_validate" } +elf_symbol { + id: 0xe0bd8904 + name: "tcf_exts_validate_ex" + is_defined: true + symbol_type: FUNCTION + crc: 0x623630cd + type_id: 0x9e8d7e28 + full_name: "tcf_exts_validate_ex" +} elf_symbol { id: 0x15d83074 name: "tcf_generic_walker" @@ -410832,13 +410912,16 @@ interface { symbol_id: 0x9c77d018 symbol_id: 0x9b3fb280 symbol_id: 0x6c3c9573 + symbol_id: 0xbdf90845 symbol_id: 0x1a591d57 symbol_id: 0xf099d343 symbol_id: 0xadb59b05 symbol_id: 0xbfd2d0d2 + symbol_id: 0x988023d7 symbol_id: 0xd6059721 symbol_id: 0x01cdd14d symbol_id: 0x2d797653 + symbol_id: 0xd4d51230 symbol_id: 0x2fba8b59 symbol_id: 0xcda1c9b0 symbol_id: 0xc924b9c3 @@ -410847,6 +410930,7 @@ interface { symbol_id: 0xcc0525bc symbol_id: 0xb8aeb338 symbol_id: 0xd6adc7e6 + symbol_id: 0xe0bd8904 symbol_id: 0x15d83074 symbol_id: 0x199994d8 symbol_id: 0xf8fc1781 diff --git a/android/abi_gki_aarch64_honda b/android/abi_gki_aarch64_honda index 8ee57762f944..07f0d76d0d51 100644 --- a/android/abi_gki_aarch64_honda +++ b/android/abi_gki_aarch64_honda @@ -23,12 +23,16 @@ skb_flow_dissect_meta skb_flow_dissect_tunnel_info skb_flow_dissector_init + tc_cleanup_offload_action tc_setup_cb_call tc_setup_cb_destroy tc_setup_cb_reoffload tc_setup_cb_add + tc_setup_offload_action + tcf_action_update_hw_stats tcf_exts_num_actions tcf_exts_terse_dump + tcf_exts_validate_ex # required by act_vlan.ko module jiffies_to_clock_t From a6cb9e0acf2b75c460370b2a9026bb02c9069b10 Mon Sep 17 00:00:00 2001 From: Norihiko Hama Date: Thu, 11 Apr 2024 14:38:00 +0900 Subject: [PATCH 31/38] ANDROID: GKI: Update honda symbol list for ebtables Add some missing symbols required for ebtables 2 function symbol(s) added 'int xt_register_target(struct xt_target*)' 'void xt_unregister_target(struct xt_target*)' Bug: 333795249 Change-Id: I8e80c481732ea07cc84c41bb70c18175fc5fd23b Signed-off-by: Norihiko Hama --- android/abi_gki_aarch64.stg | 30 ++++++++++++++++++++++++++++++ android/abi_gki_aarch64_honda | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index 1deb33e345fd..68dce4a1e514 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -300645,6 +300645,11 @@ function { return_type_id: 0x48b5725f parameter_id: 0x3c2dd1ca } +function { + id: 0x1f979e4e + return_type_id: 0x48b5725f + parameter_id: 0x3c3f3f74 +} function { id: 0x1f97abfa return_type_id: 0x48b5725f @@ -310703,6 +310708,11 @@ function { return_type_id: 0x6720d32f parameter_id: 0x3c3fe9a7 } +function { + id: 0x928f2cf2 + return_type_id: 0x6720d32f + parameter_id: 0x3c3f3f74 +} function { id: 0x9291a5ba return_type_id: 0x3e10b518 @@ -404069,6 +404079,15 @@ elf_symbol { type_id: 0x9fdeaef3 full_name: "xt_register_match" } +elf_symbol { + id: 0xb2fbe60e + name: "xt_register_target" + is_defined: true + symbol_type: FUNCTION + crc: 0x52ab20be + type_id: 0x928f2cf2 + full_name: "xt_register_target" +} elf_symbol { id: 0xffcb0fa2 name: "xt_request_find_match" @@ -404096,6 +404115,15 @@ elf_symbol { type_id: 0x12c61c4f full_name: "xt_unregister_match" } +elf_symbol { + id: 0x15f1eb71 + name: "xt_unregister_target" + is_defined: true + symbol_type: FUNCTION + crc: 0xd16885ed + type_id: 0x1f979e4e + full_name: "xt_unregister_target" +} elf_symbol { id: 0x0fc8c78d name: "zap_vma_ptes" @@ -411997,9 +412025,11 @@ interface { symbol_id: 0x8eb67e0f symbol_id: 0xf6d0be30 symbol_id: 0x7a3f2cd6 + symbol_id: 0xb2fbe60e symbol_id: 0xffcb0fa2 symbol_id: 0xa2ee5f12 symbol_id: 0x807b9318 + symbol_id: 0x15f1eb71 symbol_id: 0x0fc8c78d symbol_id: 0xe8e0ea6a symbol_id: 0xa5d58813 diff --git a/android/abi_gki_aarch64_honda b/android/abi_gki_aarch64_honda index 07f0d76d0d51..01ebbe94e0d6 100644 --- a/android/abi_gki_aarch64_honda +++ b/android/abi_gki_aarch64_honda @@ -73,8 +73,14 @@ xt_compat_unlock xt_data_to_user xt_find_match + xt_register_target xt_request_find_match xt_request_find_target + xt_unregister_target + +# commonly required by ebt_*.ko modules + xt_register_match + xt_unregister_match # required by ebt_arpreply.ko module arp_send From 9be03f0456d8344a55878fce92499ccd87697f7b Mon Sep 17 00:00:00 2001 From: Norihiko Hama Date: Thu, 11 Apr 2024 15:17:21 +0900 Subject: [PATCH 32/38] ANDROID: GKI: Update honda symbol list for xt_LOG Add some missing symbols required for xt_LOG 2 function symbol(s) added 'int xt_register_targets(struct xt_target*, unsigned int)' 'void xt_unregister_targets(struct xt_target*, unsigned int)' Bug: 333795249 Change-Id: Idb1f0a8028c822428da9fb1de2dd4b6b497c1f52 Signed-off-by: Norihiko Hama --- android/abi_gki_aarch64.stg | 32 ++++++++++++++++++++++++++++++++ android/abi_gki_aarch64_honda | 2 ++ 2 files changed, 34 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index 68dce4a1e514..90ae8719ab85 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -299670,6 +299670,12 @@ function { return_type_id: 0x48b5725f parameter_id: 0x3863a91c } +function { + id: 0x1e818bd6 + return_type_id: 0x48b5725f + parameter_id: 0x3c3f3f74 + parameter_id: 0x4585663f +} function { id: 0x1e82fda2 return_type_id: 0x48b5725f @@ -312053,6 +312059,12 @@ function { parameter_id: 0x3806390a parameter_id: 0x0665e6b6 } +function { + id: 0x9399396a + return_type_id: 0x6720d32f + parameter_id: 0x3c3f3f74 + parameter_id: 0x4585663f +} function { id: 0x93994651 return_type_id: 0x11c404ba @@ -404088,6 +404100,15 @@ elf_symbol { type_id: 0x928f2cf2 full_name: "xt_register_target" } +elf_symbol { + id: 0x450f3768 + name: "xt_register_targets" + is_defined: true + symbol_type: FUNCTION + crc: 0xd5418617 + type_id: 0x9399396a + full_name: "xt_register_targets" +} elf_symbol { id: 0xffcb0fa2 name: "xt_request_find_match" @@ -404124,6 +404145,15 @@ elf_symbol { type_id: 0x1f979e4e full_name: "xt_unregister_target" } +elf_symbol { + id: 0x7c598ee8 + name: "xt_unregister_targets" + is_defined: true + symbol_type: FUNCTION + crc: 0x621efe3e + type_id: 0x1e818bd6 + full_name: "xt_unregister_targets" +} elf_symbol { id: 0x0fc8c78d name: "zap_vma_ptes" @@ -412026,10 +412056,12 @@ interface { symbol_id: 0xf6d0be30 symbol_id: 0x7a3f2cd6 symbol_id: 0xb2fbe60e + symbol_id: 0x450f3768 symbol_id: 0xffcb0fa2 symbol_id: 0xa2ee5f12 symbol_id: 0x807b9318 symbol_id: 0x15f1eb71 + symbol_id: 0x7c598ee8 symbol_id: 0x0fc8c78d symbol_id: 0xe8e0ea6a symbol_id: 0xa5d58813 diff --git a/android/abi_gki_aarch64_honda b/android/abi_gki_aarch64_honda index 01ebbe94e0d6..602a611b2db9 100644 --- a/android/abi_gki_aarch64_honda +++ b/android/abi_gki_aarch64_honda @@ -99,3 +99,5 @@ nf_log_unset nf_logger_find_get nf_logger_put + xt_register_targets + xt_unregister_targets From cfa154389a656247d15205f7e01a0b10912183bd Mon Sep 17 00:00:00 2001 From: Norihiko Hama Date: Thu, 11 Apr 2024 15:30:01 +0900 Subject: [PATCH 33/38] ANDROID: GKI: Update honda symbol list for asound Additional missing symbols required for vendor audio module 1 function symbol(s) added 'int snd_pcm_suspend_all(struct snd_pcm*)' Bug: 333795249 Change-Id: I8bf2d33b407f76aa528c8160bde1f996e4927b57 Signed-off-by: Norihiko Hama --- android/abi_gki_aarch64.stg | 15 +++++++++++++++ android/abi_gki_aarch64_honda | 3 +++ 2 files changed, 18 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index 90ae8719ab85..41582f25e5aa 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -317709,6 +317709,11 @@ function { parameter_id: 0x1e870478 parameter_id: 0xf017819f } +function { + id: 0x99e386dd + return_type_id: 0x6720d32f + parameter_id: 0x118d97cb +} function { id: 0x99e4a009 return_type_id: 0x6720d32f @@ -391029,6 +391034,15 @@ elf_symbol { type_id: 0x98aeb261 full_name: "snd_pcm_stop_xrun" } +elf_symbol { + id: 0x1fcc9eb7 + name: "snd_pcm_suspend_all" + is_defined: true + symbol_type: FUNCTION + crc: 0x5135cc11 + type_id: 0x99e386dd + full_name: "snd_pcm_suspend_all" +} elf_symbol { id: 0x1f5649eb name: "snd_sgbuf_get_addr" @@ -410603,6 +410617,7 @@ interface { symbol_id: 0xb2f7eb17 symbol_id: 0x8eb5b50d symbol_id: 0xc26d0753 + symbol_id: 0x1fcc9eb7 symbol_id: 0x1f5649eb symbol_id: 0x31ef5894 symbol_id: 0xf19e02b6 diff --git a/android/abi_gki_aarch64_honda b/android/abi_gki_aarch64_honda index 602a611b2db9..4153b8ae27e9 100644 --- a/android/abi_gki_aarch64_honda +++ b/android/abi_gki_aarch64_honda @@ -101,3 +101,6 @@ nf_logger_put xt_register_targets xt_unregister_targets + +# required by audio related modules + snd_pcm_suspend_all From b76ed1185975b0bef765bfcb86ff39e0ea64cfad Mon Sep 17 00:00:00 2001 From: Dylan Chang Date: Fri, 12 Apr 2024 19:41:27 +0800 Subject: [PATCH 34/38] ANDROID: GKI: Add symbol list for Nothing 2 function symbol(s) added 'char* dentry_path_raw(const struct dentry*, char*, int)' 'int fscrypt_file_open(struct inode*, struct file*)' Bug: 334026503 Change-Id: I20b224d5336753a1fa8783178be60dbaae35b3ba Signed-off-by: Dylan Chang --- android/abi_gki_aarch64.stg | 27 +++++++++++++++++++++++++++ android/abi_gki_aarch64_nothing | 2 ++ 2 files changed, 29 insertions(+) diff --git a/android/abi_gki_aarch64.stg b/android/abi_gki_aarch64.stg index 41582f25e5aa..2baf70fbdb50 100644 --- a/android/abi_gki_aarch64.stg +++ b/android/abi_gki_aarch64.stg @@ -301692,6 +301692,13 @@ function { return_type_id: 0x27b71910 parameter_id: 0x1d44326e } +function { + id: 0x30d98140 + return_type_id: 0x0483e6f8 + parameter_id: 0x3bb11c92 + parameter_id: 0x0483e6f8 + parameter_id: 0x6720d32f +} function { id: 0x30dc6fbb return_type_id: 0x17dabdcd @@ -354506,6 +354513,15 @@ elf_symbol { type_id: 0x1f15d172 full_name: "delayed_work_timer_fn" } +elf_symbol { + id: 0x431b7cda + name: "dentry_path_raw" + is_defined: true + symbol_type: FUNCTION + crc: 0xa4942c22 + type_id: 0x30d98140 + full_name: "dentry_path_raw" +} elf_symbol { id: 0x1ef313dc name: "des_expand_key" @@ -365020,6 +365036,15 @@ elf_symbol { type_id: 0x96b04c18 full_name: "fs_param_is_u32" } +elf_symbol { + id: 0xbc2aa09b + name: "fscrypt_file_open" + is_defined: true + symbol_type: FUNCTION + crc: 0x54e4c19d + type_id: 0x9b022eae + full_name: "fscrypt_file_open" +} elf_symbol { id: 0x196ad62a name: "fsg_common_create_luns" @@ -406561,6 +406586,7 @@ interface { symbol_id: 0xf666562b symbol_id: 0xa5179b7b symbol_id: 0xc1583575 + symbol_id: 0x431b7cda symbol_id: 0x1ef313dc symbol_id: 0x67daf3cf symbol_id: 0xe5161e20 @@ -407727,6 +407753,7 @@ interface { symbol_id: 0x9a2423a0 symbol_id: 0x6c9f28bc symbol_id: 0x35a180e7 + symbol_id: 0xbc2aa09b symbol_id: 0x196ad62a symbol_id: 0x804c5038 symbol_id: 0x07715f1a diff --git a/android/abi_gki_aarch64_nothing b/android/abi_gki_aarch64_nothing index ae40328eb56b..2a1b010e4b86 100644 --- a/android/abi_gki_aarch64_nothing +++ b/android/abi_gki_aarch64_nothing @@ -42,6 +42,7 @@ create_empty_buffers current_time current_umask + dentry_path_raw d_find_alias d_instantiate discard_new_inode @@ -69,6 +70,7 @@ __folio_lock __folio_put fs_bio_set + fscrypt_file_open fs_param_is_string fs_param_is_u32 __fs_parse From 99aea323a3fdc9711e7776b318aa1a72c114df0a Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 10 Mar 2024 10:02:41 +0100 Subject: [PATCH 35/38] UPSTREAM: netfilter: nft_set_pipapo: release elements in clone only from destroy path [ Upstream commit b0e256f3dd2ba6532f37c5c22e07cb07a36031ee ] Clone already always provides a current view of the lookup table, use it to destroy the set, otherwise it is possible to destroy elements twice. This fix requires: 212ed75dc5fb ("netfilter: nf_tables: integrate pipapo into commit protocol") which came after: 9827a0e6e23b ("netfilter: nft_set_pipapo: release elements in clone from abort path"). Bug: 330876672 Fixes: 9827a0e6e23b ("netfilter: nft_set_pipapo: release elements in clone from abort path") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin (cherry picked from commit ff90050771412b91e928093ccd8736ae680063c2) Signed-off-by: Lee Jones Change-Id: I8c0811e69f82681c7fcfdca1111f1702e27bb80e --- net/netfilter/nft_set_pipapo.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index 4e1cc31729b8..050672ccfa7e 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -2234,8 +2234,6 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, if (m) { rcu_barrier(); - nft_set_pipapo_match_destroy(ctx, set, m); - #ifdef NFT_PIPAPO_ALIGN free_percpu(m->scratch_aligned); #endif @@ -2250,8 +2248,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, if (priv->clone) { m = priv->clone; - if (priv->dirty) - nft_set_pipapo_match_destroy(ctx, set, m); + nft_set_pipapo_match_destroy(ctx, set, m); #ifdef NFT_PIPAPO_ALIGN free_percpu(priv->clone->scratch_aligned); From 26f2c9be9ebe45429b1c385b10a2bc2e7b4cbf05 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 4 Mar 2024 14:22:12 +0100 Subject: [PATCH 36/38] UPSTREAM: netfilter: nf_tables: mark set as dead when unbinding anonymous set with timeout commit 552705a3650bbf46a22b1adedc1b04181490fc36 upstream. While the rhashtable set gc runs asynchronously, a race allows it to collect elements from anonymous sets with timeouts while it is being released from the commit path. Mingi Cho originally reported this issue in a different path in 6.1.x with a pipapo set with low timeouts which is not possible upstream since 7395dfacfff6 ("netfilter: nf_tables: use timestamp to check for set element timeout"). Fix this by setting on the dead flag for anonymous sets to skip async gc in this case. According to 08e4c8c5919f ("netfilter: nf_tables: mark newset as dead on transaction abort"), Florian plans to accelerate abort path by releasing objects via workqueue, therefore, this sets on the dead flag for abort path too. Bug: 329205787 Cc: stable@vger.kernel.org Fixes: 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane") Reported-by: Mingi Cho Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 406b0241d0eb598a0b330ab20ae325537d8d8163) Signed-off-by: Lee Jones Change-Id: I6170493c267e020c50a739150f8c421deb635b35 --- net/netfilter/nf_tables_api.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 1314e4035517..47ed59b6d651 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5128,6 +5128,7 @@ static void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, if (list_empty(&set->bindings) && nft_set_is_anonymous(set)) { list_del_rcu(&set->list); + set->dead = 1; if (event) nf_tables_set_notify(ctx, set, NFT_MSG_DELSET, GFP_KERNEL); From e27468009d68f737e59450c24b6387e8b7646ac7 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 28 Mar 2024 13:27:36 +0100 Subject: [PATCH 37/38] UPSTREAM: netfilter: nf_tables: release batch on table validation from abort path commit a45e6889575c2067d3c0212b6bc1022891e65b91 upstream. Unlike early commit path stage which triggers a call to abort, an explicit release of the batch is required on abort, otherwise mutex is released and commit_list remains in place. Add WARN_ON_ONCE to ensure commit_list is empty from the abort path before releasing the mutex. After this patch, commit_list is always assumed to be empty before grabbing the mutex, therefore 03c1f1ef1584 ("netfilter: Cleanup nft_net->module_list from nf_tables_exit_net()") only needs to release the pending modules for registration. Bug: 332996726 Cc: stable@vger.kernel.org Fixes: c0391b6ab810 ("netfilter: nf_tables: missing validation from the abort path") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman (cherry picked from commit b0b36dcbe0f24383612e5e62bd48df5a8107f7fc) Signed-off-by: Lee Jones Change-Id: I38f9b05ac4eadd1d2b7b306cccaf0aeacb61b57a --- net/netfilter/nf_tables_api.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 47ed59b6d651..fa431622c2c1 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -9880,10 +9880,11 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action) struct nft_trans *trans, *next; LIST_HEAD(set_update_list); struct nft_trans_elem *te; + int err = 0; if (action == NFNL_ABORT_VALIDATE && nf_tables_validate(net) < 0) - return -EAGAIN; + err = -EAGAIN; list_for_each_entry_safe_reverse(trans, next, &nft_net->commit_list, list) { @@ -10059,7 +10060,7 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action) else nf_tables_module_autoload_cleanup(net); - return 0; + return err; } static int nf_tables_abort(struct net *net, struct sk_buff *skb, @@ -10073,6 +10074,8 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb, ret = __nf_tables_abort(net, action); nft_gc_seq_end(nft_net, gc_seq); + WARN_ON_ONCE(!list_empty(&nft_net->commit_list)); + mutex_unlock(&nft_net->commit_mutex); return ret; @@ -10870,9 +10873,10 @@ static void __net_exit nf_tables_exit_net(struct net *net) gc_seq = nft_gc_seq_begin(nft_net); - if (!list_empty(&nft_net->commit_list) || - !list_empty(&nft_net->module_list)) - __nf_tables_abort(net, NFNL_ABORT_NONE); + WARN_ON_ONCE(!list_empty(&nft_net->commit_list)); + + if (!list_empty(&nft_net->module_list)) + nf_tables_module_autoload_cleanup(net); __nft_release_tables(net); From 77fec6cefe26965c0dfdc1b66510e22fb22dc283 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 28 Mar 2024 14:23:55 +0100 Subject: [PATCH 38/38] UPSTREAM: netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path commit 0d459e2ffb541841714839e8228b845458ed3b27 upstream. The commit mutex should not be released during the critical section between nft_gc_seq_begin() and nft_gc_seq_end(), otherwise, async GC worker could collect expired objects and get the released commit lock within the same GC sequence. nf_tables_module_autoload() temporarily releases the mutex to load module dependencies, then it goes back to replay the transaction again. Move it at the end of the abort phase after nft_gc_seq_end() is called. Bug: 332996726 Cc: stable@vger.kernel.org Fixes: 720344340fb9 ("netfilter: nf_tables: GC transaction race with abort path") Reported-by: Kuan-Ting Chen Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 8038ee3c3e5b59bcd78467686db5270c68544e30) Signed-off-by: Lee Jones Change-Id: I637389421d8eca5ab59a41bd1a4b70432440034c --- net/netfilter/nf_tables_api.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index fa431622c2c1..b458746e4d44 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -10055,11 +10055,6 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action) nf_tables_abort_release(trans); } - if (action == NFNL_ABORT_AUTOLOAD) - nf_tables_module_autoload(net); - else - nf_tables_module_autoload_cleanup(net); - return err; } @@ -10076,6 +10071,14 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb, WARN_ON_ONCE(!list_empty(&nft_net->commit_list)); + /* module autoload needs to happen after GC sequence update because it + * temporarily releases and grabs mutex again. + */ + if (action == NFNL_ABORT_AUTOLOAD) + nf_tables_module_autoload(net); + else + nf_tables_module_autoload_cleanup(net); + mutex_unlock(&nft_net->commit_mutex); return ret;