[OVS_KEY_ATTR_DP_HASH]   = { .len = sizeof(u32) },
        [OVS_KEY_ATTR_TUNNEL]    = { .len = OVS_ATTR_NESTED,
                                     .next = ovs_tunnel_key_lens, },
-       [OVS_KEY_ATTR_MPLS]      = { .len = sizeof(struct ovs_key_mpls) },
+       [OVS_KEY_ATTR_MPLS]      = { .len = OVS_ATTR_VARIABLE },
        [OVS_KEY_ATTR_CT_STATE]  = { .len = sizeof(u32) },
        [OVS_KEY_ATTR_CT_ZONE]   = { .len = sizeof(u16) },
        [OVS_KEY_ATTR_CT_MARK]   = { .len = sizeof(u32) },
 
        if (attrs & (1 << OVS_KEY_ATTR_MPLS)) {
                const struct ovs_key_mpls *mpls_key;
+               u32 hdr_len;
+               u32 label_count, label_count_mask, i;
 
                mpls_key = nla_data(a[OVS_KEY_ATTR_MPLS]);
-               SW_FLOW_KEY_PUT(match, mpls.top_lse,
-                               mpls_key->mpls_lse, is_mask);
+               hdr_len = nla_len(a[OVS_KEY_ATTR_MPLS]);
+               label_count = hdr_len / sizeof(struct ovs_key_mpls);
+
+               if (label_count == 0 || label_count > MPLS_LABEL_DEPTH ||
+                   hdr_len % sizeof(struct ovs_key_mpls))
+                       return -EINVAL;
+
+               label_count_mask =  GENMASK(label_count - 1, 0);
+
+               for (i = 0 ; i < label_count; i++)
+                       SW_FLOW_KEY_PUT(match, mpls.lse[i],
+                                       mpls_key[i].mpls_lse, is_mask);
+
+               SW_FLOW_KEY_PUT(match, mpls.num_labels_mask,
+                               label_count_mask, is_mask);
 
                attrs &= ~(1 << OVS_KEY_ATTR_MPLS);
         }
                ether_addr_copy(arp_key->arp_sha, output->ipv4.arp.sha);
                ether_addr_copy(arp_key->arp_tha, output->ipv4.arp.tha);
        } else if (eth_p_mpls(swkey->eth.type)) {
+               u8 i, num_labels;
                struct ovs_key_mpls *mpls_key;
 
-               nla = nla_reserve(skb, OVS_KEY_ATTR_MPLS, sizeof(*mpls_key));
+               num_labels = hweight_long(output->mpls.num_labels_mask);
+               nla = nla_reserve(skb, OVS_KEY_ATTR_MPLS,
+                                 num_labels * sizeof(*mpls_key));
                if (!nla)
                        goto nla_put_failure;
+
                mpls_key = nla_data(nla);
-               mpls_key->mpls_lse = output->mpls.top_lse;
+               for (i = 0; i < num_labels; i++)
+                       mpls_key[i].mpls_lse = output->mpls.lse[i];
        }
 
        if ((swkey->eth.type == htons(ETH_P_IP) ||
 static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
                                  const struct sw_flow_key *key,
                                  struct sw_flow_actions **sfa,
-                                 __be16 eth_type, __be16 vlan_tci, bool log);
+                                 __be16 eth_type, __be16 vlan_tci,
+                                 u32 mpls_label_count, bool log);
 
 static int validate_and_copy_sample(struct net *net, const struct nlattr *attr,
                                    const struct sw_flow_key *key,
                                    struct sw_flow_actions **sfa,
                                    __be16 eth_type, __be16 vlan_tci,
-                                   bool log, bool last)
+                                   u32 mpls_label_count, bool log, bool last)
 {
        const struct nlattr *attrs[OVS_SAMPLE_ATTR_MAX + 1];
        const struct nlattr *probability, *actions;
                return err;
 
        err = __ovs_nla_copy_actions(net, actions, key, sfa,
-                                    eth_type, vlan_tci, log);
+                                    eth_type, vlan_tci, mpls_label_count, log);
 
        if (err)
                return err;
                                   const struct sw_flow_key *key,
                                   struct sw_flow_actions **sfa,
                                   __be16 eth_type, __be16 vlan_tci,
-                                  bool log, bool last)
+                                  u32 mpls_label_count, bool log, bool last)
 {
        int start, err;
        u32 exec;
                return err;
 
        err = __ovs_nla_copy_actions(net, attr, key, sfa,
-                                    eth_type, vlan_tci, log);
+                                    eth_type, vlan_tci, mpls_label_count, log);
        if (err)
                return err;
 
                                           const struct sw_flow_key *key,
                                           struct sw_flow_actions **sfa,
                                           __be16 eth_type, __be16 vlan_tci,
+                                          u32 mpls_label_count,
                                           bool log, bool last)
 {
        const struct nlattr *acts_if_greater, *acts_if_lesser_eq;
                return nested_acts_start;
 
        err = __ovs_nla_copy_actions(net, acts_if_lesser_eq, key, sfa,
-                                    eth_type, vlan_tci, log);
+                                    eth_type, vlan_tci, mpls_label_count, log);
 
        if (err)
                return err;
                return nested_acts_start;
 
        err = __ovs_nla_copy_actions(net, acts_if_greater, key, sfa,
-                                    eth_type, vlan_tci, log);
+                                    eth_type, vlan_tci, mpls_label_count, log);
 
        if (err)
                return err;
 static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
                                  const struct sw_flow_key *key,
                                  struct sw_flow_actions **sfa,
-                                 __be16 eth_type, __be16 vlan_tci, bool log)
+                                 __be16 eth_type, __be16 vlan_tci,
+                                 u32 mpls_label_count, bool log)
 {
        u8 mac_proto = ovs_key_mac_proto(key);
        const struct nlattr *a;
                             !eth_p_mpls(eth_type)))
                                return -EINVAL;
                        eth_type = mpls->mpls_ethertype;
+                       mpls_label_count++;
                        break;
                }
 
-               case OVS_ACTION_ATTR_POP_MPLS:
+               case OVS_ACTION_ATTR_POP_MPLS: {
+                       __be16  proto;
                        if (vlan_tci & htons(VLAN_CFI_MASK) ||
                            !eth_p_mpls(eth_type))
                                return -EINVAL;
 
-                       /* Disallow subsequent L2.5+ set and mpls_pop actions
-                        * as there is no check here to ensure that the new
-                        * eth_type is valid and thus set actions could
-                        * write off the end of the packet or otherwise
-                        * corrupt it.
+                       /* Disallow subsequent L2.5+ set actions and mpls_pop
+                        * actions once the last MPLS label in the packet is
+                        * is popped as there is no check here to ensure that
+                        * the new eth type is valid and thus set actions could
+                        * write off the end of the packet or otherwise corrupt
+                        * it.
                         *
                         * Support for these actions is planned using packet
                         * recirculation.
                         */
-                       eth_type = htons(0);
+                       proto = nla_get_be16(a);
+                       mpls_label_count--;
+
+                       if (!eth_p_mpls(proto) || !mpls_label_count)
+                               eth_type = htons(0);
+                       else
+                               eth_type =  proto;
+
                        break;
+               }
 
                case OVS_ACTION_ATTR_SET:
                        err = validate_set(a, key, sfa,
 
                        err = validate_and_copy_sample(net, a, key, sfa,
                                                       eth_type, vlan_tci,
+                                                      mpls_label_count,
                                                       log, last);
                        if (err)
                                return err;
 
                        err = validate_and_copy_clone(net, a, key, sfa,
                                                      eth_type, vlan_tci,
+                                                     mpls_label_count,
                                                      log, last);
                        if (err)
                                return err;
 
                        err = validate_and_copy_check_pkt_len(net, a, key, sfa,
                                                              eth_type,
-                                                             vlan_tci, log,
-                                                             last);
+                                                             vlan_tci,
+                                                             mpls_label_count,
+                                                             log, last);
                        if (err)
                                return err;
                        skip_copy = true;
                         struct sw_flow_actions **sfa, bool log)
 {
        int err;
+       u32 mpls_label_count = 0;
 
        *sfa = nla_alloc_flow_actions(min(nla_len(attr), MAX_ACTIONS_BUFSIZE));
        if (IS_ERR(*sfa))
                return PTR_ERR(*sfa);
 
+       if (eth_p_mpls(key->eth.type))
+               mpls_label_count = hweight_long(key->mpls.num_labels_mask);
+
        (*sfa)->orig_len = nla_len(attr);
        err = __ovs_nla_copy_actions(net, attr, key, sfa, key->eth.type,
-                                    key->eth.vlan.tci, log);
+                                    key->eth.vlan.tci, mpls_label_count, log);
        if (err)
                ovs_nla_free_flow_actions(*sfa);