From ee6cbb754ea460fcf843defabf3870394cbf3f51 Mon Sep 17 00:00:00 2001 From: Liu Jian Date: Thu, 8 Jun 2023 21:37:20 +0800 Subject: [PATCH 1/5] xfrm: Reinject transport-mode packets through workqueue mainline inclusion from mainline-v6.1-rc1 commit 4f4920669d21e1060b7243e5118dc3b71ced1276 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5K0NK CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4f4920669d21e1060b7243e5118dc3b71ced1276 -------------------------------- The following warning is displayed when the tcp6-multi-diffip11 stress test case of the LTP test suite is tested: watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [ns-tcpserver:48198] CPU: 0 PID: 48198 Comm: ns-tcpserver Kdump: loaded Not tainted 6.0.0-rc6+ #39 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : des3_ede_encrypt+0x27c/0x460 [libdes] lr : 0x3f sp : ffff80000ceaa1b0 x29: ffff80000ceaa1b0 x28: ffff0000df056100 x27: ffff0000e51e5280 x26: ffff80004df75030 x25: ffff0000e51e4600 x24: 000000000000003b x23: 0000000000802080 x22: 000000000000003d x21: 0000000000000038 x20: 0000000080000020 x19: 000000000000000a x18: 0000000000000033 x17: ffff0000e51e4780 x16: ffff80004e2d1448 x15: ffff80004e2d1248 x14: ffff0000e51e4680 x13: ffff80004e2d1348 x12: ffff80004e2d1548 x11: ffff80004e2d1848 x10: ffff80004e2d1648 x9 : ffff80004e2d1748 x8 : ffff80004e2d1948 x7 : 000000000bcaf83d x6 : 000000000000001b x5 : ffff80004e2d1048 x4 : 00000000761bf3bf x3 : 000000007f1dd0a3 x2 : ffff0000e51e4780 x1 : ffff0000e3b9a2f8 x0 : 00000000db44e872 Call trace: des3_ede_encrypt+0x27c/0x460 [libdes] crypto_des3_ede_encrypt+0x1c/0x30 [des_generic] crypto_cbc_encrypt+0x148/0x190 crypto_skcipher_encrypt+0x2c/0x40 crypto_authenc_encrypt+0xc8/0xfc [authenc] crypto_aead_encrypt+0x2c/0x40 echainiv_encrypt+0x144/0x1a0 [echainiv] crypto_aead_encrypt+0x2c/0x40 esp6_output_tail+0x1c8/0x5d0 [esp6] esp6_output+0x120/0x278 [esp6] xfrm_output_one+0x458/0x4ec xfrm_output_resume+0x6c/0x1f0 xfrm_output+0xac/0x4ac __xfrm6_output+0x130/0x270 xfrm6_output+0x60/0xec ip6_xmit+0x2ec/0x5bc inet6_csk_xmit+0xbc/0x10c __tcp_transmit_skb+0x460/0x8c0 tcp_write_xmit+0x348/0x890 __tcp_push_pending_frames+0x44/0x110 tcp_rcv_established+0x3c8/0x720 tcp_v6_do_rcv+0xdc/0x4a0 tcp_v6_rcv+0xc24/0xcb0 ip6_protocol_deliver_rcu+0xf0/0x574 ip6_input_finish+0x48/0x7c ip6_input+0x48/0xc0 ip6_rcv_finish+0x80/0x9c xfrm_trans_reinject+0xb0/0xf4 tasklet_action_common.constprop.0+0xf8/0x134 tasklet_action+0x30/0x3c __do_softirq+0x128/0x368 do_softirq+0xb4/0xc0 __local_bh_enable_ip+0xb0/0xb4 put_cpu_fpsimd_context+0x40/0x70 kernel_neon_end+0x20/0x40 sha1_base_do_update.constprop.0.isra.0+0x11c/0x140 [sha1_ce] sha1_ce_finup+0x94/0x110 [sha1_ce] crypto_shash_finup+0x34/0xc0 hmac_finup+0x48/0xe0 crypto_shash_finup+0x34/0xc0 shash_digest_unaligned+0x74/0x90 crypto_shash_digest+0x4c/0x9c shash_ahash_digest+0xc8/0xf0 shash_async_digest+0x28/0x34 crypto_ahash_digest+0x48/0xcc crypto_authenc_genicv+0x88/0xcc [authenc] crypto_authenc_encrypt+0xd8/0xfc [authenc] crypto_aead_encrypt+0x2c/0x40 echainiv_encrypt+0x144/0x1a0 [echainiv] crypto_aead_encrypt+0x2c/0x40 esp6_output_tail+0x1c8/0x5d0 [esp6] esp6_output+0x120/0x278 [esp6] xfrm_output_one+0x458/0x4ec xfrm_output_resume+0x6c/0x1f0 xfrm_output+0xac/0x4ac __xfrm6_output+0x130/0x270 xfrm6_output+0x60/0xec ip6_xmit+0x2ec/0x5bc inet6_csk_xmit+0xbc/0x10c __tcp_transmit_skb+0x460/0x8c0 tcp_write_xmit+0x348/0x890 __tcp_push_pending_frames+0x44/0x110 tcp_push+0xb4/0x14c tcp_sendmsg_locked+0x71c/0xb64 tcp_sendmsg+0x40/0x6c inet6_sendmsg+0x4c/0x80 sock_sendmsg+0x5c/0x6c __sys_sendto+0x128/0x15c __arm64_sys_sendto+0x30/0x40 invoke_syscall+0x50/0x120 el0_svc_common.constprop.0+0x170/0x194 do_el0_svc+0x38/0x4c el0_svc+0x28/0xe0 el0t_64_sync_handler+0xbc/0x13c el0t_64_sync+0x180/0x184 Get softirq info by bcc tool: ./softirqs -NT 10 Tracing soft irq event time... Hit Ctrl-C to end. 15:34:34 SOFTIRQ TOTAL_nsecs block 158990 timer 20030920 sched 46577080 net_rx 676746820 tasklet 9906067650 15:34:45 SOFTIRQ TOTAL_nsecs block 86100 sched 38849790 net_rx 676532470 timer 1163848790 tasklet 9409019620 15:34:55 SOFTIRQ TOTAL_nsecs sched 58078450 net_rx 475156720 timer 533832410 tasklet 9431333300 The tasklet software interrupt takes too much time. Therefore, the xfrm_trans_reinject executor is changed from tasklet to workqueue. Add add spin lock to protect the queue. This reduces the processing flow of the tcp_sendmsg function in this scenario. Fixes: acf568ee859f0 ("xfrm: Reinject transport-mode packets through tasklet") Signed-off-by: Liu Jian Signed-off-by: Steffen Klassert Conflicts: net/xfrm/xfrm_input.c Signed-off-by: Liu Jian (cherry picked from commit 12093737b30f657f96aa2141b33d5b9d233d3df7) --- net/xfrm/xfrm_input.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c index 77e82033ad70..90af125aa770 100644 --- a/net/xfrm/xfrm_input.c +++ b/net/xfrm/xfrm_input.c @@ -24,7 +24,8 @@ #include "xfrm_inout.h" struct xfrm_trans_tasklet { - struct tasklet_struct tasklet; + struct work_struct work; + spinlock_t queue_lock; struct sk_buff_head queue; }; @@ -760,18 +761,22 @@ int xfrm_input_resume(struct sk_buff *skb, int nexthdr) } EXPORT_SYMBOL(xfrm_input_resume); -static void xfrm_trans_reinject(unsigned long data) +static void xfrm_trans_reinject(struct work_struct *work) { - struct xfrm_trans_tasklet *trans = (void *)data; + struct xfrm_trans_tasklet *trans = container_of(work, struct xfrm_trans_tasklet, work); struct sk_buff_head queue; struct sk_buff *skb; __skb_queue_head_init(&queue); + spin_lock_bh(&trans->queue_lock); skb_queue_splice_init(&trans->queue, &queue); + spin_unlock_bh(&trans->queue_lock); + local_bh_disable(); while ((skb = __skb_dequeue(&queue))) XFRM_TRANS_SKB_CB(skb)->finish(XFRM_TRANS_SKB_CB(skb)->net, NULL, skb); + local_bh_enable(); } int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb, @@ -789,8 +794,10 @@ int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb, XFRM_TRANS_SKB_CB(skb)->finish = finish; XFRM_TRANS_SKB_CB(skb)->net = net; + spin_lock_bh(&trans->queue_lock); __skb_queue_tail(&trans->queue, skb); - tasklet_schedule(&trans->tasklet); + spin_unlock_bh(&trans->queue_lock); + schedule_work(&trans->work); return 0; } EXPORT_SYMBOL(xfrm_trans_queue_net); @@ -817,8 +824,8 @@ void __init xfrm_input_init(void) struct xfrm_trans_tasklet *trans; trans = &per_cpu(xfrm_trans_tasklet, i); + spin_lock_init(&trans->queue_lock); __skb_queue_head_init(&trans->queue); - tasklet_init(&trans->tasklet, xfrm_trans_reinject, - (unsigned long)trans); + INIT_WORK(&trans->work, xfrm_trans_reinject); } } -- Gitee From 50a00ef6f20893e4533ce8dce6b2803a4f71e1e0 Mon Sep 17 00:00:00 2001 From: Hesham Almatary Date: Fri, 9 Jun 2023 13:06:49 +0800 Subject: [PATCH 2/5] ACPICA: Add support for Arm's MPAM ACPI table version 2 mainline inclusion from mainline-v6.4-rc1 commit 47920aae34e295f4ffbeac0b10698ceda52eec99 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I77UDW CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=47920aae34e295f4ffbeac0b10698ceda52eec99 -------------------------------- ACPICA commit 005e24bcaa6e4c7db327b4f81fb63b2715aac7e6 Complies with ACPI for Memory System Resource Partitioning and Monitoring 2.0 [1]. Document number: DEN0065, as of December 2022. Support for all types of MPAM resources. No support yet for: 1) MPAM PCC Interface Type 2) The optional Resource-specific data per MSC node, introduced in v2 of the MPAM ACPI spec. [1] https://developer.arm.com/documentation/den0065/latest Link: https://github.com/acpica/acpica/commit/005e24bc Signed-off-by: Hesham Almatary Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki Conflicts: include/acpi/actbl2.h Signed-off-by: Yu Liao (cherry picked from commit 6143a624bc9288dedcf2979a0d306c95f32c51b1) --- include/acpi/actbl2.h | 111 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index cbe7b567ab3b..0df6012703d6 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -1106,6 +1106,117 @@ struct acpi_mpam_node_memory { u8 reserved1[3]; }; +/******************************************************************************* + * + * MPAM - Memory System Resource Partitioning and Monitoring + * + * Conforms to "ACPI for Memory System Resource Partitioning and Monitoring 2.0" + * Document number: ARM DEN 0065, December, 2022. + * + ******************************************************************************/ + +/* MPAM RIS locator types. Table 11, Location types */ +enum acpi_mpam_locator_type { + ACPI_MPAM_LOCATION_TYPE_PROCESSOR_CACHE = 0, + ACPI_MPAM_LOCATION_TYPE_MEMORY = 1, + ACPI_MPAM_LOCATION_TYPE_SMMU = 2, + ACPI_MPAM_LOCATION_TYPE_MEMORY_CACHE = 3, + ACPI_MPAM_LOCATION_TYPE_ACPI_DEVICE = 4, + ACPI_MPAM_LOCATION_TYPE_INTERCONNECT = 5, + ACPI_MPAM_LOCATION_TYPE_UNKNOWN = 0xFF +}; + +/* MPAM Functional dependency descriptor. Table 10 */ +struct acpi_mpam_func_deps { + u32 producer; + u32 reserved; +}; + +/* MPAM Processor cache locator descriptor. Table 13 */ +struct acpi_mpam_resource_cache_locator { + u64 cache_reference; + u32 reserved; +}; + +/* MPAM Memory locator descriptor. Table 14 */ +struct acpi_mpam_resource_memory_locator { + u64 proximity_domain; + u32 reserved; +}; + +/* MPAM SMMU locator descriptor. Table 15 */ +struct acpi_mpam_resource_smmu_locator { + u64 smmu_interface; + u32 reserved; +}; + +/* MPAM Memory-side cache locator descriptor. Table 16 */ +struct acpi_mpam_resource_memcache_locator { + u8 reserved[7]; + u8 level; + u32 reference; +}; + +/* MPAM ACPI device locator descriptor. Table 17 */ +struct acpi_mpam_resource_acpi_locator { + u64 acpi_hw_id; + u32 acpi_unique_id; +}; + +/* MPAM Interconnect locator descriptor. Table 18 */ +struct acpi_mpam_resource_interconnect_locator { + u64 inter_connect_desc_tbl_off; + u32 reserved; +}; + +/* MPAM Locator structure. Table 12 */ +struct acpi_mpam_resource_generic_locator { + u64 descriptor1; + u32 descriptor2; +}; + +union acpi_mpam_resource_locator { + struct acpi_mpam_resource_cache_locator cache_locator; + struct acpi_mpam_resource_memory_locator memory_locator; + struct acpi_mpam_resource_smmu_locator smmu_locator; + struct acpi_mpam_resource_memcache_locator mem_cache_locator; + struct acpi_mpam_resource_acpi_locator acpi_locator; + struct acpi_mpam_resource_interconnect_locator interconnect_ifc_locator; + struct acpi_mpam_resource_generic_locator generic_locator; +}; + +/* Memory System Component Resource Node Structure Table 9 */ +struct acpi_mpam_resource_node { + u32 identifier; + u8 ris_index; + u16 reserved1; + u8 locator_type; + union acpi_mpam_resource_locator locator; + u32 num_functional_deps; +}; + +/* Memory System Component (MSC) Node Structure. Table 4 */ +struct acpi_mpam_msc_node { + u16 length; + u8 interface_type; + u8 reserved; + u32 identifier; + u64 base_address; + u32 mmio_size; + u32 overflow_interrupt; + u32 overflow_interrupt_flags; + u32 reserved1; + u32 overflow_interrupt_affinity; + u32 error_interrupt; + u32 error_interrupt_flags; + u32 reserved2; + u32 error_interrupt_affinity; + u32 max_nrdy_usec; + u64 hardware_id_linked_device; + u32 instance_id_linked_device; + u32 num_resouce_nodes; +}; + /******************************************************************************* * * MSDM - Microsoft Data Management table -- Gitee From a60c622dcecdfb6c86338bfb5c2b11fac0274f39 Mon Sep 17 00:00:00 2001 From: Erik Kaneda Date: Fri, 9 Jun 2023 13:06:50 +0800 Subject: [PATCH 3/5] ACPICA: ACPI 6.4: PPTT: add new version of subtable type 1 mainline inclusion from mainline-v5.13-rc1 commit 5e2e86c0b9970e6f70869e76a1c6417036fd3a7e category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I77UDW CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5e2e86c0b9970e6f70869e76a1c6417036fd3a7e -------------------------------- This commit squashes the following: ACPICA commit 475c5e89f8f701ccdfee6ca567e33c854ecd6c9e ACPICA commit 82cf78ac175a4b7d8842c5b786be24031c817cfd This new subtable is only valid for PPTT version 3. Elyes fixed a misspelled identifier in this commit. Link: https://github.com/acpica/acpica/commit/475c5e89 Link: https://github.com/acpica/acpica/commit/82cf78ac Signed-off-by: Elyes HAOUAS Signed-off-by: Erik Kaneda Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki Signed-off-by: Yu Liao (cherry picked from commit d651243352a4066636cd04126bc747c3beefafb4) --- include/acpi/actbl2.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 0df6012703d6..2fe351437140 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -1806,6 +1806,12 @@ struct acpi_pptt_cache { u16 line_size; }; +/* 1: Cache Type Structure for PPTT version 3 */ + +struct acpi_pptt_cache_v1 { + u32 cache_id; +}; + /* Flags */ #define ACPI_PPTT_SIZE_PROPERTY_VALID (1) /* Physical property valid */ @@ -1815,6 +1821,7 @@ struct acpi_pptt_cache { #define ACPI_PPTT_CACHE_TYPE_VALID (1<<4) /* Cache type valid */ #define ACPI_PPTT_WRITE_POLICY_VALID (1<<5) /* Write policy valid */ #define ACPI_PPTT_LINE_SIZE_VALID (1<<6) /* Line size valid */ +#define ACPI_PPTT_CACHE_ID_VALID (1<<7) /* Cache ID valid */ /* Masks for Attributes */ -- Gitee From 05df0bc5933acdc6e3ce542c5e189f7a4a9216f8 Mon Sep 17 00:00:00 2001 From: Yu Liao Date: Fri, 9 Jun 2023 13:06:51 +0800 Subject: [PATCH 4/5] ACPI / PPTT: Find PPTT processor node by cache id openeuler inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I77UDW CVE: NA -------------------------------- The MPAM table identifies caches by id, but the driver also wants to know the processor node. Add a helper that walks every possible cache, until it finds the one identified by id, then return processor node. Signed-off-by: Yu Liao (cherry picked from commit 534ad2fc53af6da735b49732a7b8cdfb3540d6b3) --- drivers/acpi/pptt.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 5 ++++ 2 files changed, 60 insertions(+) diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c index 3d9403ded527..c0f722ecb3c7 100644 --- a/drivers/acpi/pptt.c +++ b/drivers/acpi/pptt.c @@ -958,3 +958,58 @@ int __init acpi_pptt_init(void) return 0; } + +struct acpi_pptt_processor *find_acpi_processor_node_from_cache_id(u32 cache_id) +{ + u32 acpi_cpu_id; + acpi_status status; + int level, cpu, num_levels; + struct acpi_pptt_cache *cache; + struct acpi_table_header *table; + struct acpi_pptt_cache_v1 *cache_v1; + struct acpi_pptt_processor *cpu_node; + + status = acpi_get_table(ACPI_SIG_PPTT, 0, &table); + if (ACPI_FAILURE(status)) { + acpi_pptt_warn_missing(); + return NULL; + } + + if (table->revision < 3) { + acpi_put_table(table); + return NULL; + } + + /* + * If we found the cache first, we'd still need to walk from each CPU + * to find the level... + */ + for_each_possible_cpu(cpu) { + acpi_cpu_id = get_acpi_id_for_cpu(cpu); + cpu_node = acpi_find_processor_node(table, acpi_cpu_id); + if (!cpu_node) + break; + num_levels = acpi_count_levels(table, cpu_node); + + for (level = 0; level <= num_levels; level++) { + cache = acpi_find_cache_node(table, acpi_cpu_id, + ACPI_PPTT_CACHE_TYPE_UNIFIED, + level, &cpu_node); + if (!cache) + continue; + + cache_v1 = ACPI_ADD_PTR(struct acpi_pptt_cache_v1, + cache, + sizeof(struct acpi_pptt_cache)); + + if (cache->flags & ACPI_PPTT_CACHE_ID_VALID && + cache_v1->cache_id == cache_id) { + acpi_put_table(table); + return cpu_node; + } + } + } + + acpi_put_table(table); + return NULL; +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 7c14b71464df..ce073553510f 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1367,6 +1367,7 @@ int find_acpi_cpu_topology_cluster(unsigned int cpu); int find_acpi_cpu_topology_package(unsigned int cpu); int find_acpi_cpu_topology_hetero_id(unsigned int cpu); int find_acpi_cpu_cache_topology(unsigned int cpu, int level); +struct acpi_pptt_processor *find_acpi_processor_node_from_cache_id(u32 cache_id); #else static inline int acpi_pptt_cpu_is_thread(unsigned int cpu) { @@ -1392,6 +1393,10 @@ static inline int find_acpi_cpu_cache_topology(unsigned int cpu, int level) { return -EINVAL; } +static inline struct acpi_pptt_processor *find_acpi_processor_node_from_cache_id(u32 cache_id) +{ + return NULL; +} #endif #ifdef CONFIG_ACPI -- Gitee From f4e900a6d5b3f0559c1a53d21920731c273aa8ef Mon Sep 17 00:00:00 2001 From: Yu Liao Date: Fri, 9 Jun 2023 13:06:52 +0800 Subject: [PATCH 5/5] ACPI/MPAM: Adapt to Arm's MPAM ACPI table version 2 openeuler inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I77UDW CVE: NA -------------------------------- Support ACPI for MPAM 2.0 [1]. Compatible with MPAM ACPI 1.0 by reading ACPI revision. [1] https://developer.arm.com/documentation/den0065/latest Signed-off-by: Yu Liao (cherry picked from commit 6a2cb7bc198d589aaee7e140c313496240398f6c) --- arch/arm64/kernel/mpam/mpam_device.c | 2 +- drivers/acpi/arm64/Makefile | 2 +- drivers/acpi/arm64/mpam.c | 23 +++- drivers/acpi/arm64/mpam_v2.c | 175 +++++++++++++++++++++++++++ include/linux/arm_mpam.h | 2 +- 5 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 drivers/acpi/arm64/mpam_v2.c diff --git a/arch/arm64/kernel/mpam/mpam_device.c b/arch/arm64/kernel/mpam/mpam_device.c index 50bdc56ca005..c59f7f09308d 100644 --- a/arch/arm64/kernel/mpam/mpam_device.c +++ b/arch/arm64/kernel/mpam/mpam_device.c @@ -1865,7 +1865,7 @@ static int __init arm_mpam_driver_init(void) if (acpi_disabled) return platform_driver_register(&arm_mpam_driver); else - return acpi_mpam_parse(); + return acpi_mpam_parse_version(); } /* diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile index e306086bfe22..2bae08207e51 100644 --- a/drivers/acpi/arm64/Makefile +++ b/drivers/acpi/arm64/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_ACPI_IORT) += iort.o obj-$(CONFIG_ACPI_GTDT) += gtdt.o -obj-$(CONFIG_ACPI_MPAM) += mpam.o +obj-$(CONFIG_ACPI_MPAM) += mpam.o mpam_v2.o diff --git a/drivers/acpi/arm64/mpam.c b/drivers/acpi/arm64/mpam.c index 6f4572193eb2..f625f539d50a 100644 --- a/drivers/acpi/arm64/mpam.c +++ b/drivers/acpi/arm64/mpam.c @@ -32,6 +32,8 @@ #include #include +extern int __init acpi_mpam_parse_table_v2(struct acpi_table_header *table, + struct acpi_table_header *pptt); /** * acpi_mpam_label_cache_component_id() - Recursivly find @min_physid * for all leaf CPUs below @cpu_node, use numa node id of @min_cpu_node @@ -40,7 +42,7 @@ * @cpu_node: The point in the toplogy to start the walk * @component_id: The id labels the structure mpam_node cache */ -static int +int acpi_mpam_label_cache_component_id(struct acpi_table_header *table_hdr, struct acpi_pptt_processor *cpu_node, u32 *component_id) @@ -187,10 +189,10 @@ static int __init acpi_mpam_parse_table(struct acpi_table_header *table, pr_warn_once("Unknown node type %u offset %ld.", node_hdr->type, (table_offset-(char *)table)); - /* fall through */ + fallthrough; case ACPI_MPAM_TYPE_SMMU: /* not yet supported */ - /* fall through */ + fallthrough; case ACPI_MPAM_TYPE_UNKNOWN: break; } @@ -213,7 +215,7 @@ static int __init acpi_mpam_parse_table(struct acpi_table_header *table, return ret; } -int __init acpi_mpam_parse(void) +int __init acpi_mpam_parse_version(void) { struct acpi_table_header *mpam, *pptt; acpi_status status; @@ -234,7 +236,18 @@ int __init acpi_mpam_parse(void) if (ACPI_FAILURE(status)) pptt = NULL; - ret = acpi_mpam_parse_table(mpam, pptt); + /* + * The BIOS of Kunpeng 920 supports MPAM ACPI 1.0, but the ACPI + * revision is wrongly written as 1, so distinguished by + * oem_table_id here. + */ + if (mpam->revision == 0 || strncmp(mpam->oem_table_id, "HIP08", 5) == 0) + ret = acpi_mpam_parse_table(mpam, pptt); + else if (mpam->revision == 1) + ret = acpi_mpam_parse_table_v2(mpam, pptt); + else + pr_err("unsupported MPAM ACPI version: %u\n", mpam->revision); + acpi_put_table(pptt); acpi_put_table(mpam); diff --git a/drivers/acpi/arm64/mpam_v2.c b/drivers/acpi/arm64/mpam_v2.c new file mode 100644 index 000000000000..6a9a4d013380 --- /dev/null +++ b/drivers/acpi/arm64/mpam_v2.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Common code for ARM v8 MPAM ACPI 2.0 + * + * Copyright (C) 2019-2022 Huawei Technologies Co., Ltd + * + * Author: Yu Liao + * + * Code was partially borrowed from http://www.linux-arm.org/git?p= + * linux-jm.git;a=commit;h=10fe7d6363ae96b25f584d4a91f9d0f2fd5faf3b. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ + +/* Parse the MPAM ACPI table feeding the discovered nodes into the driver */ +#define pr_fmt(fmt) "ACPI MPAM: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +extern int +acpi_mpam_label_cache_component_id(struct acpi_table_header *table_hdr, + struct acpi_pptt_processor *cpu_node, + u32 *component_id); + +static int __init acpi_mpam_parse_cache_v2(struct acpi_mpam_msc_node *msc, + struct acpi_table_header *pptt) +{ + int ret = 0; + int level; + u32 component_id; + struct mpam_device *dev; + struct cacheinfo *ci; + struct acpi_pptt_processor *pptt_cpu_node; + struct acpi_mpam_resource_node *resources; + + resources = (struct acpi_mpam_resource_node *)(msc + 1); + + pptt_cpu_node = find_acpi_processor_node_from_cache_id(resources->locator.cache_locator.cache_reference); + if (!pptt_cpu_node) { + pr_err("Failed to find processor cpu node\n"); + return -EINVAL; + } + + ret = acpi_mpam_label_cache_component_id(pptt, pptt_cpu_node, + &component_id); + if (ret) { + pr_err("Failed to label cache component id\n"); + return -EINVAL; + } + + cpus_read_lock(); + ci = cacheinfo_shared_cpu_map_search(pptt_cpu_node); + if (!ci) { + pr_err_once("No CPU has cache with PPTT reference %#llx", + resources->locator.cache_locator.cache_reference); + pr_err_once("All CPUs must be online to probe mpam.\n"); + cpus_read_unlock(); + return -ENODEV; + } + + level = ci->level; + ci = NULL; + cpus_read_unlock(); + + /* + * Possible we can get cpu-affinity in next MPAM ACPI version, + * now we have to set it to NULL and use default possible_aff- + * inity. + */ + dev = mpam_device_create_cache(level, component_id, NULL, + msc->base_address); + if (IS_ERR(dev)) { + pr_err("Failed to create cache node\n"); + return -EINVAL; + } + + return mpam_register_device_irq(dev, + msc->overflow_interrupt, msc->overflow_interrupt_flags, + msc->error_interrupt, msc->error_interrupt_flags); +} + +static int __init acpi_mpam_parse_memory_v2(struct acpi_mpam_msc_node *msc) +{ + u32 component_id; + struct mpam_device *dev; + struct acpi_mpam_resource_node *resources; + + resources = (struct acpi_mpam_resource_node *)(msc + 1); + + component_id = acpi_map_pxm_to_node(resources->locator.memory_locator.proximity_domain); + if (component_id == NUMA_NO_NODE) + component_id = 0; + + dev = mpam_device_create_memory(component_id, msc->base_address); + if (IS_ERR(dev)) { + pr_err("Failed to create memory node\n"); + return -EINVAL; + } + + return mpam_register_device_irq(dev, + msc->overflow_interrupt, msc->overflow_interrupt_flags, + msc->error_interrupt, msc->error_interrupt_flags); +} + +int __init acpi_mpam_parse_table_v2(struct acpi_table_header *table, + struct acpi_table_header *pptt) +{ + char *table_offset = (char *)(table + 1); + char *table_end = (char *)table + table->length; + struct acpi_mpam_msc_node *node_hdr; + struct acpi_mpam_resource_node *resources; + int ret = 0; + + ret = mpam_discovery_start(); + + if (ret) + return ret; + + node_hdr = (struct acpi_mpam_msc_node *)table_offset; + resources = (struct acpi_mpam_resource_node *)(node_hdr + 1); + + while (table_offset < table_end) { + switch (resources->locator_type) { + + case ACPI_MPAM_LOCATION_TYPE_PROCESSOR_CACHE: + ret = acpi_mpam_parse_cache_v2(node_hdr, pptt); + break; + case ACPI_MPAM_LOCATION_TYPE_MEMORY: + ret = acpi_mpam_parse_memory_v2(node_hdr); + break; + default: + pr_warn_once("Unknown node type %u offset %ld.", + (resources->locator_type), + (table_offset-(char *)table)); + fallthrough; + case ACPI_MPAM_LOCATION_TYPE_SMMU: + /* not yet supported */ + fallthrough; + case ACPI_MPAM_TYPE_UNKNOWN: + break; + } + if (ret) + break; + + table_offset += node_hdr->length; + node_hdr = (struct acpi_mpam_msc_node *)table_offset; + resources = (struct acpi_mpam_resource_node *)(node_hdr + 1); + } + + if (ret) { + pr_err("discovery failed: %d\n", ret); + mpam_discovery_failed(); + } else { + ret = mpam_discovery_complete(); + if (!ret) + pr_info("Successfully init mpam by ACPI.\n"); + } + + return ret; +} diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h index 01498a5c06ba..ced59348a882 100644 --- a/include/linux/arm_mpam.h +++ b/include/linux/arm_mpam.h @@ -116,6 +116,6 @@ static inline int mpam_register_device_irq(struct mpam_device *dev, return ret; } -int __init acpi_mpam_parse(void); +int __init acpi_mpam_parse_version(void); #endif -- Gitee