net: ipa: properly limit modem routing table use
PATCH v2 1/1 net: ipa: properly limit modem routing table use
IPA can route packets between IPA-connected entities. The AP and modem are currently the only such entities supported, and no routing is required to transfer packets between them.
The number of entries in each routing table is fixed, and defined at initialization time. Some of these entries are designated for use by the modem, and the rest are available for the AP to use. The AP sends a QMI message to the modem which describes (among other things) information about routing table memory available for the modem to use.
Currently the QMI initialization packet gives wrong information in its description of routing tables. What *should* be supplied is the maximum index that the modem can use for the routing table memory located at a given location. The current code instead supplies the total *number* of routing table entries. Furthermore, the modem is granted the entire table, not just the subset it's supposed to use.
This patch fixes this. First, the ipa_mem_bounds structure is generalized so its "end" field can be interpreted either as a final byte offset, or a final array index. Second, the IPv4 and IPv6 (non-hashed and hashed) table information fields in the QMI ipa_init_modem_driver_req structure are changed to be ipa_mem_bounds rather than ipa_mem_array structures. Third, we set the "end" value for each routing table to be the last index, rather than setting the "count" to be the number of indices. Finally, instead of allowing the modem to use all of a routing table's memory, it is limited to just the portion meant to be used by the modem. In all versions of IPA currently supported, that is IPA_ROUTE_MODEM_COUNT (8) entries.
Update a few comments for clarity.
---
v2: Update the element info arrays defining the modified QMI message
so it uses the ipa_mem_bounds_ei structure rather than the ipa_mem_array_ei structure. The message format is identical, but the code was incorrect without that change.
drivers/net/ipa/ipa_qmi.c | 8 ++++---- drivers/net/ipa/ipa_qmi_msg.c | 8 ++++---- drivers/net/ipa/ipa_qmi_msg.h | 37 ++++++++++++++++++++--------------- drivers/net/ipa/ipa_table.c | 2 -- drivers/net/ipa/ipa_table.h | 3 +++ 5 files changed, 32 insertions(+), 26 deletions(-)
drivers/net/ipa/ipa_qmi.c +4 -4
@@ -308,12 +308,12 @@ init_modem_driver_req(struct ipa_qmi *ipa_qmi) mem =ipa_mem_find (ipa,IPA_MEM_V4_ROUTE ); req.v4_route_tbl_info_valid =1 ; req.v4_route_tbl_info.start = ipa->mem_offset + mem->offset; - req.v4_route_tbl_info.count = mem->size /sizeof (__le64); + req.v4_route_tbl_info.end =IPA_ROUTE_MODEM_COUNT -1 ; mem =ipa_mem_find (ipa,IPA_MEM_V6_ROUTE ); req.v6_route_tbl_info_valid =1 ; req.v6_route_tbl_info.start = ipa->mem_offset + mem->offset; - req.v6_route_tbl_info.count = mem->size /sizeof (__le64); + req.v6_route_tbl_info.end =IPA_ROUTE_MODEM_COUNT -1 ; mem =ipa_mem_find (ipa,IPA_MEM_V4_FILTER ); req.v4_filter_tbl_start_valid =1 ;
@@ -352,7 +352,7 @@ init_modem_driver_req(struct ipa_qmi *ipa_qmi) req.v4_hash_route_tbl_info_valid =1 ; req.v4_hash_route_tbl_info.start = ipa->mem_offset + mem->offset; - req.v4_hash_route_tbl_info.count = mem->size /sizeof (__le64); + req.v4_hash_route_tbl_info.end =IPA_ROUTE_MODEM_COUNT -1 ; } mem =ipa_mem_find (ipa,IPA_MEM_V6_ROUTE_HASHED );
@@ -360,7 +360,7 @@ init_modem_driver_req(struct ipa_qmi *ipa_qmi) req.v6_hash_route_tbl_info_valid =1 ; req.v6_hash_route_tbl_info.start = ipa->mem_offset + mem->offset; - req.v6_hash_route_tbl_info.count = mem->size /sizeof (__le64); + req.v6_hash_route_tbl_info.end =IPA_ROUTE_MODEM_COUNT -1 ; } mem =ipa_mem_find (ipa,IPA_MEM_V4_FILTER_HASHED );
drivers/net/ipa/ipa_qmi_msg.c +4 -4
@@ -311,7 +311,7 @@ struct qmi_elem_info ipa_init_modem_driver_req_ei[] = { .tlv_type = 0x12, .offset = offsetof(struct ipa_init_modem_driver_req, v4_route_tbl_info), - .ei_array = ipa_mem_array_ei, + .ei_array = ipa_mem_bounds_ei, }, { .data_type = QMI_OPT_FLAG,
@@ -332,7 +332,7 @@ struct qmi_elem_info ipa_init_modem_driver_req_ei[] = { .tlv_type = 0x13, .offset = offsetof(struct ipa_init_modem_driver_req, v6_route_tbl_info), - .ei_array = ipa_mem_array_ei, + .ei_array = ipa_mem_bounds_ei, }, { .data_type = QMI_OPT_FLAG,
@@ -496,7 +496,7 @@ struct qmi_elem_info ipa_init_modem_driver_req_ei[] = { .tlv_type = 0x1b, .offset = offsetof(struct ipa_init_modem_driver_req, v4_hash_route_tbl_info), - .ei_array = ipa_mem_array_ei, + .ei_array = ipa_mem_bounds_ei, }, { .data_type = QMI_OPT_FLAG,
@@ -517,7 +517,7 @@ struct qmi_elem_info ipa_init_modem_driver_req_ei[] = { .tlv_type = 0x1c, .offset = offsetof(struct ipa_init_modem_driver_req, v6_hash_route_tbl_info), - .ei_array = ipa_mem_array_ei, + .ei_array = ipa_mem_bounds_ei, }, { .data_type = QMI_OPT_FLAG,
drivers/net/ipa/ipa_qmi_msg.h +21 -16
@@ -86,9 +86,11 @@ enum ipa_platform_type { IPA_QMI_PLATFORM_TYPE_MSM_QNX_V01 = 0x5, /* QNX MSM */ }; -/* This defines the start and end offset of a range of memory. Both -* fields are offsets relative to the start of IPA shared memory. -* The end value is the last addressable byte *within* the range. +/* This defines the start and end offset of a range of memory. The start +* value is a byte offset relative to the start of IPA shared memory. The +* end value is the last addressable unit *within* the range. Typically +* the end value is in units of bytes, however it can also be a maximum +* array index value. */ struct ipa_mem_bounds {u32 start;
@@ -129,18 +131,19 @@ struct ipa_init_modem_driver_req {u8 hdr_tbl_info_valid;struct ipa_mem_bounds hdr_tbl_info; -/* Routing table information. These define the location and size of -* non-hashable IPv4 and IPv6 filter tables. The start values are -* offsets relative to the start of IPA shared memory. +/* Routing table information. These define the location and maximum +* *index* (not byte) for the modem portion of non-hashable IPv4 and +* IPv6 routing tables. The start values are byte offsets relative +* to the start of IPA shared memory. */ u8 v4_route_tbl_info_valid; -struct ipa_mem_array v4_route_tbl_info; +struct ipa_mem_bounds v4_route_tbl_info;u8 v6_route_tbl_info_valid; -struct ipa_mem_array v6_route_tbl_info; +struct ipa_mem_bounds v6_route_tbl_info;/* Filter table information. These define the location of the * non-hashable IPv4 and IPv6 filter tables. The start values are -* offsets relative to the start of IPA shared memory. +* byte offsets relative to the start of IPA shared memory. */ u8 v4_filter_tbl_start_valid;u32 v4_filter_tbl_start;
@@ -181,18 +184,20 @@ struct ipa_init_modem_driver_req {u8 zip_tbl_info_valid;struct ipa_mem_bounds zip_tbl_info; -/* Routing table information. These define the location and size -* of hashable IPv4 and IPv6 filter tables. The start values are -* offsets relative to the start of IPA shared memory. +/* Routing table information. These define the location and maximum +* *index* (not byte) for the modem portion of hashable IPv4 and IPv6 +* routing tables (if supported by hardware). The start values are +* byte offsets relative to the start of IPA shared memory. */ u8 v4_hash_route_tbl_info_valid; -struct ipa_mem_array v4_hash_route_tbl_info; +struct ipa_mem_bounds v4_hash_route_tbl_info;u8 v6_hash_route_tbl_info_valid; -struct ipa_mem_array v6_hash_route_tbl_info; +struct ipa_mem_bounds v6_hash_route_tbl_info;/* Filter table information. These define the location and size -* of hashable IPv4 and IPv6 filter tables. The start values are -* offsets relative to the start of IPA shared memory. +* of hashable IPv4 and IPv6 filter tables (if supported by hardware). +* The start values are byte offsets relative to the start of IPA +* shared memory. */ u8 v4_hash_filter_tbl_start_valid;u32 v4_hash_filter_tbl_start;
drivers/net/ipa/ipa_table.c +0 -2
@@ -108,8 +108,6 @@/* Assignment of route table entries to the modem and AP */ #define IPA_ROUTE_MODEM_MIN 0 -#define IPA_ROUTE_MODEM_COUNT 8 -#define IPA_ROUTE_AP_MIN IPA_ROUTE_MODEM_COUNT#define IPA_ROUTE_AP_COUNT \ (IPA_ROUTE_COUNT_MAX - IPA_ROUTE_MODEM_COUNT)
drivers/net/ipa/ipa_table.h +3 -0
@@ -13,6 +13,9 @@ struct ipa;/* The maximum number of filter table entries (IPv4, IPv6; hashed or not) */ #define IPA_FILTER_COUNT_MAX 14 +/* The number of route table entries allotted to the modem */ +#define IPA_ROUTE_MODEM_COUNT 8 +/* The maximum number of route table entries (IPv4, IPv6; hashed or not) */ #define IPA_ROUTE_COUNT_MAX 15
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 32 lines · On Tue, 13 Sep 2022 15:46:02 -0500 Alex Elder wrote:
IPA can route packets between IPA-connected entities. The AP and modem are currently the only such entities supported, and no routing is required to transfer packets between them.
The number of entries in each routing table is fixed, and defined at initialization time. Some of these entries are designated for use by the modem, and the rest are available for the AP to use. The AP sends a QMI message to the modem which describes (among other things) information about routing table memory available for the modem to use.
Currently the QMI initialization packet gives wrong information in its description of routing tables. What *should* be supplied is the maximum index that the modem can use for the routing table memory located at a given location. The current code instead supplies the total *number* of routing table entries. Furthermore, the modem is granted the entire table, not just the subset it's supposed to use.
This patch fixes this. First, the
ipa_mem_boundsstructure is generalized so its "end" field can be interpreted either as a final byte offset, or a final array index. Second, the IPv4 and IPv6 (non-hashed and hashed) table information fields in the QMIipa_init_modem_driver_reqstructure are changed to beipa_mem_boundsrather thanipa_mem_arraystructures. Third, we set the "end" value for each routing table to be the last index, rather than setting the "count" to be the number of indices. Finally, instead of allowing the modem to use all of a routing table's memory, it is limited to just the portion meant to be used by the modem. In all versions of IPA currently supported, that isIPA_ROUTE_MODEM_COUNT(8) entries.Update a few comments for clarity.
Quoted 7 lines
Fixes 530f9216a9537 ("soc: qcom: ipa: AP/modem communications")Signed-off-by Alex Elder <[email protected]>---
v2: Update the element info arrays defining the modified QMI message
so it uses theipa_mem_bounds_eistructure rather than theipa_mem_array_eistructure. The message format is identical, but the code was incorrect without that change.
Unclear to me why, ipa_mem_bounds_ei and ipa_mem_array_ei seem identical, other than s/end/count/. Overall the patch feels a touch too verbose for a fix, makes it harder to grasp the key functional change IMHO. I could be misunderstanding but please keep the goal of making fixes small and crisp in mind for the future.
Quoted 9 lines · Jakub Kicinski
Quoted 4 lines
v2: Update the element info arrays defining the modified QMI message
so it uses theipa_mem_bounds_eistructure rather than theipa_mem_array_eistructure. The message format is identical, but the code was incorrect without that change.Unclear to me why,
ipa_mem_bounds_eiandipa_mem_array_eiseem identical, other than s/end/count/. Overall the patch feels a touch too verbose for a fix, makes it harder to grasp the key functional change IMHO. I could be misunderstanding but please keep the goal of making fixes small and crisp in mind for the future.
I see you've already accepted the patch, and I appreciate that.
The verbosity was because it was maybe a subtle difference and I failed to be more concise describing it.
Over the wire, the ipa_mem_bounds and ipa_mem_array *look* identical (both are a pair of 32-bit unsigned values).
But they are *semantically* different. The "array" is a base offset and number of entries. The "bounds" specifies the start and last offset (one less than the number of entries).
So the type has changed to try to make the distinction clearer. I realize neither the compiler nor the QMI implementation will distinguish it, but the hope is that the human reader can derive some value from it.
I don't want to be any more verbose, so I'll leave it at that.
-Alex
Jakub Kicinski
maintainerQuoted 2 lines · On Tue, 20 Sep 2022 11:16:18 -0500 Alex Elder wrote:
I don't want to be any more verbose, so I'll leave it at that.
;) To be clear I meant code changes only.
For the commit message and discussions the more verbose the better.
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 4 lines · On Tue, 13 Sep 2022 15:46:02 -0500 you wrote:
IPA can route packets between IPA-connected entities. The AP and modem are currently the only such entities supported, and no routing is required to transfer packets between them.
Quoted 8 lines
The number of entries in each routing table is fixed, and defined at initialization time. Some of these entries are designated for use by the modem, and the rest are available for the AP to use. The AP sends a QMI message to the modem which describes (among other things) information about routing table memory available for the modem to use.
[...]
Here is the summary with links:
- [net,v2] net: ipa: properly limit modem routing table use
https://git.kernel.org/netdev/net/c/cf412ec33325
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html