Skip to contentSkip to conversation

rocker: prepare for easy addition of other worlds

PATCH Superseded Jiri Pirko 2 participants 8 messages Feb 19, 2016 – Feb 25, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

cover rocker: prepare for easy addition of other worlds

From: Jiri Pirko <[email protected]>

This patchset does couple of small changes in order to prepare for smooth addition of other worlds, like P4 and BPF. qemu user will be able to request desired rocker world by "world=worldname" property.

Jiri Pirko (3):
rocker: forbid to change world type
rocker: add name field into WorldOps ale let world specify its name
rocker: allow user to specify rocker world by property

 hw/net/rocker/rocker.c        | 35 +++++++++++++++++++++++++++++++++--
 hw/net/rocker/rocker_fp.c     |  5 +++++
 hw/net/rocker/rocker_fp.h     |  1 +
 hw/net/rocker/rocker_of_dpa.c |  1 +
 hw/net/rocker/rocker_world.c  |  7 +------
 hw/net/rocker/rocker_world.h  |  1 +
 6 files changed, 42 insertions(+), 8 deletions(-)
Signature · 1 line
2.4.3
author
#1 lore raw

PATCH 1/3 rocker: forbid to change world type

From: Jiri Pirko <[email protected]>

Port to world assignment should be permitted only by qemu user. Driver should not be able to do it, so forbid that possibility.

---
 hw/net/rocker/rocker.c    | 8 +++++++-
 hw/net/rocker/rocker_fp.c | 5 +++++
 hw/net/rocker/rocker_fp.h | 1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
hw/net/rocker/rocker.c +7 -1
index f3e994d..a1d921d 100644
@@ -400,7 +400,13 @@ static int cmd_set_port_settings(Rocker *r,
 
     if (tlvs[ROCKER_TLV_CMD_PORT_SETTINGS_MODE]) {
         mode = rocker_tlv_get_u8(tlvs[ROCKER_TLV_CMD_PORT_SETTINGS_MODE]);
-        fp_port_set_world(fp_port, r->worlds[mode]);
+        if (mode >= ROCKER_WORLD_TYPE_MAX) {
+            return -ROCKER_EINVAL;
+        }
+        /* We don't support world change. */
+        if (!fp_port_check_world(fp_port, r->worlds[mode])) {
+            return -ROCKER_EINVAL;
+        }
     }
 
     if (tlvs[ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING]) {
hw/net/rocker/rocker_fp.c +5 -0
index af37fef..0149899 100644
@@ -186,6 +186,11 @@ void fp_port_set_world(FpPort *port, World *world)
     port->world = world;
 }
 
+bool fp_port_check_world(FpPort *port, World *world)
+{
+    return port->world == world;
+}
+
 bool fp_port_enabled(FpPort *port)
 {
     return port->enabled;
hw/net/rocker/rocker_fp.h +1 -0
index ab80fd8..04592bb 100644
@@ -40,6 +40,7 @@ int fp_port_set_settings(FpPort *port, uint32_t speed,
 bool fp_port_from_pport(uint32_t pport, uint32_t *port);
 World *fp_port_get_world(FpPort *port);
 void fp_port_set_world(FpPort *port, World *world);
+bool fp_port_check_world(FpPort *port, World *world);
 bool fp_port_enabled(FpPort *port);
 void fp_port_enable(FpPort *port);
 void fp_port_disable(FpPort *port);
Signature · 1 line
2.4.3
author
#3 lore raw

PATCH 3/3 rocker: allow user to specify rocker world by property

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add property to specify rocker world. All ports will be assigned to this world.

---
 hw/net/rocker/rocker.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
hw/net/rocker/rocker.c +26 -1
index a1d921d..d0bdfcb 100644
@@ -43,6 +43,7 @@ struct rocker {
 
     /* switch configuration */
     char *name;                  /* switch name */
+    char *world_name;            /* world name */
     uint32_t fp_ports;           /* front-panel port count */
     NICPeers *fp_ports_peers;
     MACAddr fp_start_macaddr;    /* front-panel port 0 mac addr */
@@ -1286,6 +1287,18 @@ static void rocker_msix_uninit(Rocker *r)
     rocker_msix_vectors_unuse(r, ROCKER_MSIX_VEC_COUNT(r->fp_ports));
 }
 
+static World *rocker_world_type_by_name(Rocker *r, const char *name)
+{
+    int i;
+
+    for (i = 0; i < ROCKER_WORLD_TYPE_MAX; i++) {
+        if (strcmp(name, world_name(r->worlds[i])) == 0) {
+            return r->worlds[i];
+	}
+    }
+    return NULL;
+}
+
 static int pci_rocker_init(PCIDevice *dev)
 {
     Rocker *r = to_rocker(dev);
@@ -1297,7 +1310,18 @@ static int pci_rocker_init(PCIDevice *dev)
     /* allocate worlds */
 
     r->worlds[ROCKER_WORLD_TYPE_OF_DPA] = of_dpa_world_alloc(r);
-    r->world_dflt = r->worlds[ROCKER_WORLD_TYPE_OF_DPA];
+
+    if (!r->world_name) {
+        r->world_name = g_strdup(world_name(r->worlds[ROCKER_WORLD_TYPE_OF_DPA]));
+    }
+
+    r->world_dflt = rocker_world_type_by_name(r, r->world_name);
+    if (!r->world_dflt) {
+        fprintf(stderr,
+                "rocker: requested world \"%s\" does not exist\n",
+                r->world_name);
+        return -EINVAL;
+    }
 
     for (i = 0; i < ROCKER_WORLD_TYPE_MAX; i++) {
         if (!r->worlds[i]) {
@@ -1509,6 +1533,7 @@ static void rocker_reset(DeviceState *dev)
 
 static Property rocker_properties[] = {
     DEFINE_PROP_STRING("name", Rocker, name),
+    DEFINE_PROP_STRING("world", Rocker, world_name),
     DEFINE_PROP_MACADDR("fp_start_macaddr", Rocker,
                         fp_start_macaddr),
     DEFINE_PROP_UINT64("switch_id", Rocker,
Signature · 1 line
2.4.3
author
#2 lore raw

PATCH 2/3 rocker: add name field into WorldOps ale let world specify its name

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Also use this in world_name getter function.

---
 hw/net/rocker/rocker_of_dpa.c | 1 +
 hw/net/rocker/rocker_world.c  | 7 +------
 hw/net/rocker/rocker_world.h  | 1 +
 3 files changed, 3 insertions(+), 6 deletions(-)
hw/net/rocker/rocker_of_dpa.c +1 -0
index da3fc54..0a134eb 100644
@@ -2614,6 +2614,7 @@ RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name,
 }
 
 static WorldOps of_dpa_ops = {
+    .name = "ofdpa",
     .init = of_dpa_init,
     .uninit = of_dpa_uninit,
     .ig = of_dpa_ig,
hw/net/rocker/rocker_world.c +1 -6
index 1ed0fcd..89777e9 100644
@@ -98,10 +98,5 @@ enum rocker_world_type world_type(World *world)
 
 const char *world_name(World *world)
 {
-    switch (world->type) {
-    case ROCKER_WORLD_TYPE_OF_DPA:
-        return "OF_DPA";
-    default:
-        return "unknown";
-    }
+    return world->ops->name;
 }
hw/net/rocker/rocker_world.h +1 -0
index 18d277b..58ade47 100644
@@ -33,6 +33,7 @@ typedef int (world_cmd)(World *world, DescInfo *info,
                         RockerTlv *cmd_info_tlv);
 
 typedef struct world_ops {
+    const char *name;
     world_init *init;
     world_uninit *uninit;
     world_ig *ig;
Signature · 1 line
2.4.3
#4 lore raw

Re: [Qemu-devel] [patch qemu 3/3] rocker: allow user to specify rocker world by property

In reply to Jiri Pirko
Quoted 7 lines · Jiri Pirko
hw/net/rocker/rocker.c +2 -1
@@ -1297,7 +1310,18 @@ static int pci_rocker_init(PCIDevice *dev)
     /* allocate worlds */
 
     r->worlds[ROCKER_WORLD_TYPE_OF_DPA] = of_dpa_world_alloc(r);
-    r->world_dflt = r->worlds[ROCKER_WORLD_TYPE_OF_DPA];
+
+    if (!r->world_name) {

hw/net/rocker/rocker.c static int pci_rocker_init(PCIDevice *dev) · line 1324

Quoted 10 lines
hw/net/rocker/rocker.c +10 -0
+        r->world_name = g_strdup(world_name(r->worlds[ROCKER_WORLD_TYPE_OF_DPA]));
+    }
+
+    r->world_dflt = rocker_world_type_by_name(r, r->world_name);
+    if (!r->world_dflt) {
+        fprintf(stderr,
+                "rocker: requested world \"%s\" does not exist\n",
+                r->world_name);
+        return -EINVAL;
+    }

world_name is leaked here. Please use goto to run the appropriate cleanup code instead of returning directly.

author
#5 lore raw

Re: [Qemu-devel] [patch qemu 3/3] rocker: allow user to specify rocker world by property

Quoted 13 lines · Mon, Feb 22, 2016 at 06:51:50PM CET, [email protected] wrote:
Quoted 12 lines · Jiri Pirko
hw/net/rocker/rocker.c +7 -1
@@ -1297,7 +1310,18 @@ static int pci_rocker_init(PCIDevice *dev)
     /* allocate worlds */
 
     r->worlds[ROCKER_WORLD_TYPE_OF_DPA] = of_dpa_world_alloc(r);
-    r->world_dflt = r->worlds[ROCKER_WORLD_TYPE_OF_DPA];
+
+    if (!r->world_name) {
+        r->world_name = g_strdup(world_name(r->worlds[ROCKER_WORLD_TYPE_OF_DPA]));
+    }
+
+    r->world_dflt = rocker_world_type_by_name(r, r->world_name);
+    if (!r->world_dflt) {
Quoted 8 lines

hw/net/rocker/rocker.c static int pci_rocker_init(PCIDevice *dev) · line 1324

Quoted 5 lines
hw/net/rocker/rocker.c +5 -0
+        fprintf(stderr,
+                "rocker: requested world \"%s\" does not exist\n",
+                r->world_name);
+        return -EINVAL;
+    }

world_name is leaked here. Please use goto to run the appropriate cleanup code instead of returning directly.

I did the same what is done with "r->name = g_strdup(ROCKER)"

I assumed since this is a property, the caller core will take care of that.

#6 lore raw

Re: [Qemu-devel] [patch qemu 3/3] rocker: allow user to specify rocker world by property

Quoted 23 lines · Jiri Pirko
Quoted 13 lines · Mon, Feb 22, 2016 at 06:51:50PM CET, [email protected] wrote:
Quoted 12 lines · Jiri Pirko
hw/net/rocker/rocker.c +7 -1
@@ -1297,7 +1310,18 @@ static int pci_rocker_init(PCIDevice *dev)
     /* allocate worlds */
 
     r->worlds[ROCKER_WORLD_TYPE_OF_DPA] = of_dpa_world_alloc(r);
-    r->world_dflt = r->worlds[ROCKER_WORLD_TYPE_OF_DPA];
+
+    if (!r->world_name) {
+        r->world_name = g_strdup(world_name(r->worlds[ROCKER_WORLD_TYPE_OF_DPA]));
+    }
+
+    r->world_dflt = rocker_world_type_by_name(r, r->world_name);
+    if (!r->world_dflt) {
Quoted 8 lines

hw/net/rocker/rocker.c static int pci_rocker_init(PCIDevice *dev) · line 1324

Quoted 5 lines
hw/net/rocker/rocker.c +5 -0
+        fprintf(stderr,
+                "rocker: requested world \"%s\" does not exist\n",
+                r->world_name);
+        return -EINVAL;
+    }

world_name is leaked here. Please use goto to run the appropriate cleanup code instead of returning directly.

Quoted 4 lines

I did the same what is done with "r->name = g_strdup(ROCKER)"

I assumed since this is a property, the caller core will take care of that.

You are right, the string properties will be freed by qdev property release.

The return statement added by this patch still leaks r->worlds[ROCKER_WORLD_TYPE_OF_DPA] so goto err_world_alloc is needed.

(pci_rocker_uninit() is not called if pci_rocker_init() fails.)

author
#7 lore raw

Re: [Qemu-devel] [patch qemu 3/3] rocker: allow user to specify rocker world by property

Quoted 29 lines · Thu, Feb 25, 2016 at 12:31:58PM CET, [email protected] wrote:
Quoted 23 lines · Jiri Pirko
Quoted 13 lines · Mon, Feb 22, 2016 at 06:51:50PM CET, [email protected] wrote:
Quoted 12 lines · Jiri Pirko
hw/net/rocker/rocker.c +7 -1
@@ -1297,7 +1310,18 @@ static int pci_rocker_init(PCIDevice *dev)
     /* allocate worlds */
 
     r->worlds[ROCKER_WORLD_TYPE_OF_DPA] = of_dpa_world_alloc(r);
-    r->world_dflt = r->worlds[ROCKER_WORLD_TYPE_OF_DPA];
+
+    if (!r->world_name) {
+        r->world_name = g_strdup(world_name(r->worlds[ROCKER_WORLD_TYPE_OF_DPA]));
+    }
+
+    r->world_dflt = rocker_world_type_by_name(r, r->world_name);
+    if (!r->world_dflt) {
Quoted 8 lines

hw/net/rocker/rocker.c static int pci_rocker_init(PCIDevice *dev) · line 1324

Quoted 5 lines
hw/net/rocker/rocker.c +5 -0
+        fprintf(stderr,
+                "rocker: requested world \"%s\" does not exist\n",
+                r->world_name);
+        return -EINVAL;
+    }

world_name is leaked here. Please use goto to run the appropriate cleanup code instead of returning directly.

Quoted 4 lines

I did the same what is done with "r->name = g_strdup(ROCKER)"

I assumed since this is a property, the caller core will take care of that.

Quoted 7 lines

You are right, the string properties will be freed by qdev property release.

The return statement added by this patch still leaks r->worlds[ROCKER_WORLD_TYPE_OF_DPA] so goto err_world_alloc is needed.

(pci_rocker_uninit() is not called if pci_rocker_init() fails.)

Will fix and send v2. Thanks.