Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4017dbdc authored by Ben Hutchings's avatar Ben Hutchings
Browse files

sfc: Fix loop condition for efx_filter_search() when !for_insert



efx_filter_remove_filter() fails to remove inserted filters in some cases.

For example:

  1. Two filters A and B have specifications that result in an initial
     hash collision.
  2. A is inserted first, followed by B.
  3. An attempt to remove B first succeeds, but if A is removed first
     a subsequent attempt to remove B fails.

When searching for an existing filter (!for_insert),
efx_filter_search() must always continue to the maximum search depth
for the given type rather than stopping at the first unused entry.

Signed-off-by: default avatarBen Hutchings <bhutchings@solarflare.com>
parent 22c8c934
Loading
Loading
Loading
Loading
+24 −17
Original line number Diff line number Diff line
@@ -335,30 +335,37 @@ static int efx_filter_search(struct efx_filter_table *table,
			     bool for_insert, int *depth_required)
{
	unsigned hash, incr, filter_idx, depth, depth_max;
	struct efx_filter_spec *cmp;

	hash = efx_filter_hash(key);
	incr = efx_filter_increment(key);
	depth_max = (spec->priority <= EFX_FILTER_PRI_HINT ?
		     FILTER_CTL_SRCH_HINT_MAX : FILTER_CTL_SRCH_MAX);

	for (depth = 1, filter_idx = hash & (table->size - 1);
	     depth <= depth_max && test_bit(filter_idx, table->used_bitmap);
	     ++depth) {
		cmp = &table->spec[filter_idx];
		if (efx_filter_equal(spec, cmp))
			goto found;
		filter_idx = (filter_idx + incr) & (table->size - 1);
	}
	if (!for_insert)
		return -ENOENT;
	if (depth > depth_max)
		return -EBUSY;
found:

	filter_idx = hash & (table->size - 1);
	depth = 1;
	depth_max = (for_insert ?
		     (spec->priority <= EFX_FILTER_PRI_HINT ?
		      FILTER_CTL_SRCH_HINT_MAX : FILTER_CTL_SRCH_MAX) :
		     table->search_depth[spec->type]);

	for (;;) {
		/* Return success if entry is used and matches this spec
		 * or entry is unused and we are trying to insert.
		 */
		if (test_bit(filter_idx, table->used_bitmap) ?
		    efx_filter_equal(spec, &table->spec[filter_idx]) :
		    for_insert) {
			*depth_required = depth;
			return filter_idx;
		}

		/* Return failure if we reached the maximum search depth */
		if (depth == depth_max)
			return for_insert ? -EBUSY : -ENOENT;

		filter_idx = (filter_idx + incr) & (table->size - 1);
		++depth;
	}
}

/* Construct/deconstruct external filter IDs */

static inline int