* [PATCH] : bug fix in multipath drr code.
@ 2005-05-23 12:26 pravin
2005-05-23 23:22 ` Herbert Xu
0 siblings, 1 reply; 6+ messages in thread
From: pravin @ 2005-05-23 12:26 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Herbert Xu
[-- Attachment #1: Type: text/plain, Size: 786 bytes --]
hi
AFAIU, there is a race condition in multipath_drr code,
these code paths try to access & change last_selection variable
without any synchronization.
Please correct me if I am wrong.
Code Path - 1
__ip_route_output_key(...)
{
...
calls drr_select_route
if(FLOWI_FLAG_MULTIPATHOLDROUTE set){
check last_selection.
return last_selection //so it can return NULL pointer
}
....
}
Code Path - 2
rt_secret_rebuild()
{
.....
rt_run_flush(..);
->rt_free(rth);
-> multipath_remove(rt)
->drr_remove()
reset last_selection.
....
}
Attached patch also fixes bug in function drr_init ::
multipath_alg_register(..) is called with wrong algorithm ID.
Regards
Pravin.
[-- Attachment #2: multipath-last_selection-race-fix.patch --]
[-- Type: text/x-patch, Size: 1913 bytes --]
Signed-off by: Pravin B. Shelar <pravins@calsoftinc.com>
Index: linux-2.6.12-rc4/net/ipv4/multipath_drr.c
===================================================================
--- linux-2.6.12-rc4.orig/net/ipv4/multipath_drr.c 2005-05-06 22:20:31.000000000 -0700
+++ linux-2.6.12-rc4/net/ipv4/multipath_drr.c 2005-05-22 06:41:39.000000000 -0700
@@ -145,11 +145,13 @@
int cur_min_devidx = -1;
/* if necessary and possible utilize the old alternative */
- if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 &&
- last_selection != NULL) {
- result = last_selection;
- *rp = result;
- return;
+ if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 ) {
+ struct rtable *last_result = last_selection;
+ if(last_result != NULL &&
+ multipath_comparekeys(&last_result->fl, flp)) {
+ *rp = last_result;
+ return;
+ }
}
/* 1. make sure all alt. nexthops have the same GC related data */
@@ -244,7 +246,7 @@
if (err)
return err;
- err = multipath_alg_register(&drr_ops, IP_MP_ALG_RR);
+ err = multipath_alg_register(&drr_ops, IP_MP_ALG_DRR);
if (err)
goto fail;
Index: linux-2.6.12-rc4/net/ipv4/multipath_rr.c
===================================================================
--- linux-2.6.12-rc4.orig/net/ipv4/multipath_rr.c 2005-05-06 22:20:31.000000000 -0700
+++ linux-2.6.12-rc4/net/ipv4/multipath_rr.c 2005-05-22 06:41:20.000000000 -0700
@@ -64,10 +64,13 @@
int min_use = -1;
/* if necessary and possible utilize the old alternative */
- if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 &&
- last_used != NULL) {
- result = last_used;
- goto out;
+ if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 ) {
+ struct rtable *last_result = last_used;
+ if(last_result != NULL &&
+ multipath_comparekeys(&last_result->fl, flp)) {
+ result = last_result;
+ goto out;
+ }
}
/* 1. make sure all alt. nexthops have the same GC related data
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] : bug fix in multipath drr code.
2005-05-23 12:26 [PATCH] : bug fix in multipath drr code pravin
@ 2005-05-23 23:22 ` Herbert Xu
2005-05-24 6:46 ` pravin b shelar
0 siblings, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2005-05-23 23:22 UTC (permalink / raw)
To: pravin; +Cc: netdev, David S. Miller
On Mon, May 23, 2005 at 05:56:39PM +0530, pravin wrote:
> AFAIU, there is a race condition in multipath_drr code,
> these code paths try to access & change last_selection variable
> without any synchronization.
Yes you're right.
> Index: linux-2.6.12-rc4/net/ipv4/multipath_drr.c
> ===================================================================
> --- linux-2.6.12-rc4.orig/net/ipv4/multipath_drr.c 2005-05-06 22:20:31.000000000 -0700
> +++ linux-2.6.12-rc4/net/ipv4/multipath_drr.c 2005-05-22 06:41:39.000000000 -0700
> @@ -145,11 +145,13 @@
> int cur_min_devidx = -1;
>
> /* if necessary and possible utilize the old alternative */
> - if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 &&
> - last_selection != NULL) {
> - result = last_selection;
> - *rp = result;
> - return;
> + if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 ) {
> + struct rtable *last_result = last_selection;
> + if(last_result != NULL &&
> + multipath_comparekeys(&last_result->fl, flp)) {
> + *rp = last_result;
> + return;
> + }
> }
You don't need all this code. All you need to do is do
result = last_selection before the if condition and then
check result in the if condition instead of last_selection.
The multipath_comparekeys isn't necessary either.
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] : bug fix in multipath drr code.
2005-05-23 23:22 ` Herbert Xu
@ 2005-05-24 6:46 ` pravin b shelar
2005-05-24 7:11 ` Herbert Xu
0 siblings, 1 reply; 6+ messages in thread
From: pravin b shelar @ 2005-05-24 6:46 UTC (permalink / raw)
To: Herbert Xu; +Cc: netdev, David S. Miller
Herbert Xu wrote:
>On Mon, May 23, 2005 at 05:56:39PM +0530, pravin wrote:
>
>
>> /* if necessary and possible utilize the old alternative */
>>- if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 &&
>>- last_selection != NULL) {
>>- result = last_selection;
>>- *rp = result;
>>- return;
>>+ if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 ) {
>>+ struct rtable *last_result = last_selection;
>>+ if(last_result != NULL &&
>>+ multipath_comparekeys(&last_result->fl, flp)) {
>>+ *rp = last_result;
>>+ return;
>>+ }
>> }
>>
>>
>
>You don't need all this code. All you need to do is do
>result = last_selection before the if condition and then
>check result in the if condition instead of last_selection.
>
>The multipath_comparekeys isn't necessary either.
>
>
>
In concurrent invocations of drr_select_route() last_selection will
change to different route.
So in that case we can not use last_selection route on basis of
FLOWI_FLAG_MULTIPATHOLDROUTE flag only, since old
route might be totally different due another invocation of same function.
So, I think multipath_comparekeys is necessary.
Please correct me if I am wrong.
Regards,
Pravin.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] : bug fix in multipath drr code.
2005-05-24 6:46 ` pravin b shelar
@ 2005-05-24 7:11 ` Herbert Xu
2005-05-24 9:57 ` pravin b shelar
0 siblings, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2005-05-24 7:11 UTC (permalink / raw)
To: pravin b shelar; +Cc: netdev, David S. Miller
On Tue, May 24, 2005 at 12:16:38PM +0530, pravin b shelar wrote:
>
> >The multipath_comparekeys isn't necessary either.
>
> In concurrent invocations of drr_select_route() last_selection will
> change to different route.
> So in that case we can not use last_selection route on basis of
> FLOWI_FLAG_MULTIPATHOLDROUTE flag only, since old
> route might be totally different due another invocation of same function.
> So, I think multipath_comparekeys is necessary.
Indeed. In fact this whole MULTIPATHOLDROUTE thing can't possibly
work at all. I'd suggest that it be removed.
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] : bug fix in multipath drr code.
2005-05-24 7:11 ` Herbert Xu
@ 2005-05-24 9:57 ` pravin b shelar
2005-05-26 22:13 ` David S. Miller
0 siblings, 1 reply; 6+ messages in thread
From: pravin b shelar @ 2005-05-24 9:57 UTC (permalink / raw)
To: Herbert Xu; +Cc: netdev, David S. Miller
[-- Attachment #1: Type: text/plain, Size: 379 bytes --]
Herbert Xu wrote:
>On Tue, May 24, 2005 at 12:16:38PM +0530, pravin b shelar wrote:
>
>
>In fact this whole MULTIPATHOLDROUTE thing can't possibly
>work at all. I'd suggest that it be removed.
>
>
So I think we should ignore MULTIPATHOLDROUTE flag
in drr and rr multipath algorithms as done in random multipath algorithm.
Attached patch does same thing.
Regards,
Pravin.
[-- Attachment #2: multipath-drr_rr-last_use-fix.patch --]
[-- Type: text/x-patch, Size: 3512 bytes --]
Signed-off by: Pravin B. Shelar <pravins@calsoftinc.com>
Index: linux-2.6.12-rc4/include/net/route.h
===================================================================
--- linux-2.6.12-rc4.orig/include/net/route.h 2005-05-06 22:20:31.000000000 -0700
+++ linux-2.6.12-rc4/include/net/route.h 2005-05-24 02:37:10.000000000 -0700
@@ -181,9 +181,6 @@
memcpy(&fl, &(*rp)->fl, sizeof(fl));
fl.fl_ip_sport = sport;
fl.fl_ip_dport = dport;
-#if defined(CONFIG_IP_ROUTE_MULTIPATH_CACHED)
- fl.flags |= FLOWI_FLAG_MULTIPATHOLDROUTE;
-#endif
ip_rt_put(*rp);
*rp = NULL;
return ip_route_output_flow(rp, &fl, sk, 0);
Index: linux-2.6.12-rc4/net/ipv4/multipath_drr.c
===================================================================
--- linux-2.6.12-rc4.orig/net/ipv4/multipath_drr.c 2005-05-06 22:20:31.000000000 -0700
+++ linux-2.6.12-rc4/net/ipv4/multipath_drr.c 2005-05-24 02:37:10.000000000 -0700
@@ -57,7 +57,6 @@
static struct multipath_device state[MULTIPATH_MAX_DEVICECANDIDATES];
static DEFINE_SPINLOCK(state_lock);
-static struct rtable *last_selection = NULL;
static int inline __multipath_findslot(void)
{
@@ -111,11 +110,6 @@
.notifier_call = drr_dev_event,
};
-static void drr_remove(struct rtable *rt)
-{
- if (last_selection == rt)
- last_selection = NULL;
-}
static void drr_safe_inc(atomic_t *usecount)
{
@@ -144,14 +138,6 @@
int devidx = -1;
int cur_min_devidx = -1;
- /* if necessary and possible utilize the old alternative */
- if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 &&
- last_selection != NULL) {
- result = last_selection;
- *rp = result;
- return;
- }
-
/* 1. make sure all alt. nexthops have the same GC related data */
/* 2. determine the new candidate to be returned */
result = NULL;
@@ -229,12 +215,10 @@
}
*rp = result;
- last_selection = result;
}
static struct ip_mp_alg_ops drr_ops = {
.mp_alg_select_route = drr_select_route,
- .mp_alg_remove = drr_remove,
};
static int __init drr_init(void)
@@ -244,7 +228,7 @@
if (err)
return err;
- err = multipath_alg_register(&drr_ops, IP_MP_ALG_RR);
+ err = multipath_alg_register(&drr_ops, IP_MP_ALG_DRR);
if (err)
goto fail;
Index: linux-2.6.12-rc4/net/ipv4/multipath_rr.c
===================================================================
--- linux-2.6.12-rc4.orig/net/ipv4/multipath_rr.c 2005-05-06 22:20:31.000000000 -0700
+++ linux-2.6.12-rc4/net/ipv4/multipath_rr.c 2005-05-24 02:37:10.000000000 -0700
@@ -47,29 +47,12 @@
#include <net/checksum.h>
#include <net/ip_mp_alg.h>
-#define MULTIPATH_MAX_CANDIDATES 40
-
-static struct rtable* last_used = NULL;
-
-static void rr_remove(struct rtable *rt)
-{
- if (last_used == rt)
- last_used = NULL;
-}
-
static void rr_select_route(const struct flowi *flp,
struct rtable *first, struct rtable **rp)
{
struct rtable *nh, *result, *min_use_cand = NULL;
int min_use = -1;
- /* if necessary and possible utilize the old alternative */
- if ((flp->flags & FLOWI_FLAG_MULTIPATHOLDROUTE) != 0 &&
- last_used != NULL) {
- result = last_used;
- goto out;
- }
-
/* 1. make sure all alt. nexthops have the same GC related data
* 2. determine the new candidate to be returned
*/
@@ -90,15 +73,12 @@
if (!result)
result = first;
-out:
- last_used = result;
result->u.dst.__use++;
*rp = result;
}
static struct ip_mp_alg_ops rr_ops = {
.mp_alg_select_route = rr_select_route,
- .mp_alg_remove = rr_remove,
};
static int __init rr_init(void)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] : bug fix in multipath drr code.
2005-05-24 9:57 ` pravin b shelar
@ 2005-05-26 22:13 ` David S. Miller
0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2005-05-26 22:13 UTC (permalink / raw)
To: pravins; +Cc: herbert, netdev
From: pravin b shelar <pravins@calsoftinc.com>
Date: Tue, 24 May 2005 15:27:16 +0530
> So I think we should ignore MULTIPATHOLDROUTE flag
> in drr and rr multipath algorithms as done in random multipath algorithm.
>
> Attached patch does same thing.
I've applied this patch, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-05-26 22:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-23 12:26 [PATCH] : bug fix in multipath drr code pravin
2005-05-23 23:22 ` Herbert Xu
2005-05-24 6:46 ` pravin b shelar
2005-05-24 7:11 ` Herbert Xu
2005-05-24 9:57 ` pravin b shelar
2005-05-26 22:13 ` David S. Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).