OVN cannot apply COPP because ovn-controller unable to allocate
a meter ID from id_pool.
The id_pool_create(base, n_ids) is supposing the base + n_ds
does not overlap  uint32 upper border. However this is not true
for combination of the base = 1 (provided by ovn) and
n_ids = 0xFFFFFFFF provided from some old openvswitch kmods
(prior kernel 5.8).
I have provided a sanity check for OVS id_pool_init(), so now
an ovs_assert will be launched if a pair of base/n_ids is not proper.

This fix corrects OVN call of id_pool_create and adjusts n_ids
if it is too big.

Signed-off-by: Aleksandr Smirnov <[email protected]>
---
 lib/extend-table.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/extend-table.c b/lib/extend-table.c
index 8e79d7177..03bec516e 100644
--- a/lib/extend-table.c
+++ b/lib/extend-table.c
@@ -33,11 +33,15 @@ void
 ovn_extend_table_init(struct ovn_extend_table *table, const char *table_name,
                       uint32_t n_ids)
 {
+    /* Table id 0 is invalid, set id-pool base to 1. */
+    uint32_t meter_base = 1;
+
+    n_ids = MIN(n_ids, UINT32_MAX - meter_base);
+
     *table = (struct ovn_extend_table) {
         .name = xstrdup(table_name),
         .n_ids = n_ids,
-        /* Table id 0 is invalid, set id-pool base to 1. */
-        .table_ids = id_pool_create(1, n_ids),
+        .table_ids = id_pool_create(meter_base, n_ids),
         .desired = HMAP_INITIALIZER(&table->desired),
         .lflow_to_desired = HMAP_INITIALIZER(&table->lflow_to_desired),
         .existing = HMAP_INITIALIZER(&table->existing),
@@ -47,10 +51,15 @@ ovn_extend_table_init(struct ovn_extend_table *table, const 
char *table_name,
 void
 ovn_extend_table_reinit(struct ovn_extend_table *table, uint32_t n_ids)
 {
+    /* Table id 0 is invalid, set id-pool base to 1. */
+    uint32_t meter_base = 1;
+
+    n_ids = MIN(n_ids, UINT32_MAX - meter_base);
+
     if (n_ids != table->n_ids) {
         ovn_extend_table_clear(table, true);
         id_pool_destroy(table->table_ids);
-        table->table_ids = id_pool_create(1, n_ids);
+        table->table_ids = id_pool_create(meter_base, n_ids);
         table->n_ids = n_ids;
     }
 }
-- 
2.49.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to