gre: Wait for an RCU grace period before freeing port.
authorJesse Gross <jesse@nicira.com>
Thu, 15 Jul 2010 01:35:58 +0000 (18:35 -0700)
committerJesse Gross <jesse@nicira.com>
Thu, 15 Jul 2010 22:09:08 +0000 (15:09 -0700)
We currently remove ports from the GRE hash table and then immediately
free the ports.  Since received packets could be using that port this
can lead to a crash (the port has already been detached from the
datapath so this can't happen for transmitted packets).  As a result
we need to wait for an RCU grace period to elapse before actually
freeing the port.

In an ideal world we would actually remove the port from the hash
table in a hypothetical gre_detach() function since this is one of
the purposes of detaching.  However, we also use the hash table to
look for collisions in the lookup criteria and don't want to allow
two identical ports to exist.  It doesn't matter though because we
aren't blocking on the freeing of resources.

datapath/vport-gre.c

index 883e5dc..33966db 100644 (file)
@@ -55,6 +55,7 @@ struct mutable_config {
 };
 
 struct gre_vport {
+       struct rcu_head rcu;
        struct tbl_node tbl_node;
 
        char name[IFNAMSIZ];
@@ -1296,6 +1297,14 @@ error:
        return err;
 }
 
+static void free_port(struct rcu_head *rcu)
+{
+       struct gre_vport *gre_vport = container_of(rcu, struct gre_vport, rcu);
+
+       kfree(gre_vport->mutable);
+       vport_free(gre_vport_to_vport(gre_vport));
+}
+
 static int gre_destroy(struct vport *vport)
 {
        struct gre_vport *gre_vport = gre_vport_priv(vport);
@@ -1314,8 +1323,7 @@ static int gre_destroy(struct vport *vport)
            gre_vport->mutable->port_config.in_key, port_type, &old_mutable))
                del_port(vport);
 
-       kfree(gre_vport->mutable);
-       vport_free(vport);
+       call_rcu(&gre_vport->rcu, free_port);
 
        return 0;
 }