From patchwork Mon Nov 12 20:01:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slava Ovsiienko X-Patchwork-Id: 48012 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D83764F9C; Mon, 12 Nov 2018 21:01:51 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80050.outbound.protection.outlook.com [40.107.8.50]) by dpdk.org (Postfix) with ESMTP id 66D0C4CAD for ; Mon, 12 Nov 2018 21:01:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=81c9MYZ+mKc4xxeDsn3mIJg3I8uBn9syCJ6P+7QqiwQ=; b=HPOG9EFsRqeSIeemmIM4eHchutA4o60bQYfN9UsuI6flb69znApWSsIPUHt0rEXjPQwCe4/DHac7P4BBqwI+ClAU6g2TrRSb2LDmdXgzoGRnQkFae8cIkI0Zk1BGjJHarPrY/iSBX3IK1TfCQ9sm/95smtiNZ2oudaih3y3RMdw= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.186.150) by AM4PR05MB3377.eurprd05.prod.outlook.com (10.171.187.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Mon, 12 Nov 2018 20:01:42 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::544b:a68d:e6a5:ba6e]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::544b:a68d:e6a5:ba6e%2]) with mapi id 15.20.1294.044; Mon, 12 Nov 2018 20:01:42 +0000 From: Slava Ovsiienko To: Shahaf Shuler , Yongseok Koh CC: "dev@dpdk.org" , Slava Ovsiienko Thread-Topic: [PATCH 4/4] net/mlx5: add E-switch rule hardware offload flag check Thread-Index: AQHUesKHT/ly+14K3Ue8Lo61d0IE1w== Date: Mon, 12 Nov 2018 20:01:42 +0000 Message-ID: <1542052877-41512-5-git-send-email-viacheslavo@mellanox.com> References: <1541225876-8817-2-git-send-email-viacheslavo@mellanox.com> <1542052877-41512-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1542052877-41512-1-git-send-email-viacheslavo@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0161.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::29) To AM4PR05MB3265.eurprd05.prod.outlook.com (2603:10a6:205:4::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR05MB3377; 6:heamtGp3L8uhabYLUkCDTdP2GLLi1FtCCcyV+U6TMOV2clmuvreeIpybv1X6SPwNx7ib7EPs4hyqFiUvmi+hb5lXpEu8Z5RP/Gn/4fFCbyb9M2ICC0JXPVGgGUyzPZggv42pjA7OlWSh20gdCKr0mShuLORtqh43vgW7TpOM3Bs6H8Z/vcbwHdvyVSrJar7F6U0WLm16v7tFctwVwQcYf+i6VMBLK3hNbUrZi8UAOSUacmIT2csXke5RGwpra0f8jkRA1cB6vyoLxWrvxBDUJ/+HT4jeNBwniGejwOnsElFPNEhS8s1DLqyXVZZ8RmYTlU2c0SOigmwN/KnKiMspCtMwmMgo7uVmIxNjG5vCFccgtskIL3d9KuLNR81lQScCWINYIFpH2k4n/05fMzr2Xa4eeavRQ3F4qbQ7zOGhlqJX2ATXz69Dg/7FKQe90XlqlK6O8nKlyV024mF+9OTXuw==; 5:8CEPiH0+sRTPx5QK+aw8U7XexMIQT/c/2owBlLTqJ4T1j9nomkmWxNyBeUz5lSlUEi5EZJtZUx2oMptsrEQidPBt4AqE3JiyU6alvUSNcx98qhaX0JjxPn0YAA5eoQwwqyl2bWzYZ08pZi82mOOV9Lcgrl52+03R3DPTX+Z1HuE=; 7:BdcxdeTqT+9MawOivkKUAyls2Dp1NaX0OC8v0NhchIt+lqQFpwd4Wp6Mk2QMsjVx6kqSW7Hr8ZtdmkXwdlZEaByfyDnqnEMdQhAJcDG4y7oxVZOBpR9X+AlVjvs6ui0MHhL4cBYs00qceexDW4kSSA== x-ms-office365-filtering-correlation-id: 4363eece-cdca-460c-49fa-08d648d9aa3b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390040)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM4PR05MB3377; x-ms-traffictypediagnostic: AM4PR05MB3377: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231382)(944501410)(52105112)(3002001)(93006095)(93001095)(6055026)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:AM4PR05MB3377; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB3377; x-forefront-prvs: 0854128AF0 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(346002)(136003)(376002)(396003)(39860400002)(189003)(199004)(71200400001)(86362001)(71190400001)(97736004)(6486002)(446003)(478600001)(256004)(6636002)(14444005)(486006)(36756003)(2616005)(110136005)(54906003)(105586002)(68736007)(85306007)(316002)(25786009)(99286004)(2906002)(14454004)(106356001)(8676002)(102836004)(81166006)(107886003)(81156014)(2900100001)(6116002)(3846002)(66066001)(305945005)(7736002)(386003)(186003)(6436002)(53936002)(76176011)(6512007)(8936002)(4326008)(11346002)(5660300001)(6506007)(52116002)(476003)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3377; H:AM4PR05MB3265.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: +vcmw6S2PGZSRnR3hizs7s9gXm2o7Q/5KJ3RbmSZAAXOlGBbtF1VR6ecCtkouiVbvgJbpLDxC+UtX35wmnOYb1CcgRtZ2JLjpULioXy1o7cr25qjubSqimmGmu3rmwyPg4J0uNcMSNJIhqPsJbghFJWLdoYClcwvyFZB7t3BIjHAqO7BYtCKbPPcds8UHKYy4oFUjXTm5CBCwYwdk/lmvSxWA/UYExosY9JzZVCIQycwKl3ZnKxhqTXqa0FUS0+3Fp/nPRTF/I4RqnoE+09FWdd2H8Utz1SItgAlPE2B+X7ArnoSeMgqqQKSbAF5lkRSw7K74fwS5PF8PCFrd7nE9HYgtUbigTgezKO0JEnoC24= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4363eece-cdca-460c-49fa-08d648d9aa3b X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Nov 2018 20:01:42.3921 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3377 Subject: [dpdk-dev] [PATCH 4/4] net/mlx5: add E-switch rule hardware offload flag check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds the in_hw flag check for tc flower filter rules. If rule is applied without skip_sw flag set driver should check whether the in_hw flag is set after rule applying. If no in_hw flag set found it means the rule is not hardware offloaded and error should be returned to application. Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5_flow_tcf.c | 142 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c index 5bfb2d8..91deb88 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -5082,6 +5082,134 @@ struct tcf_nlcb_context { pthread_mutex_unlock(&vtep_list_mutex); } +struct tcf_nlcb_query { + uint32_t handle; + uint32_t tc_flags; + uint32_t flags_valid:1; +}; + +/** + * Collect queried rule attributes. This is callback routine called by + * libmnl mnl_cb_run() in loop for every message in received packet. + * Current implementation collects the flower flags only. + * + * @param[in] nlh + * Pointer to reply header. + * @param[in, out] arg + * Context pointer for this callback. + * + * @return + * A positive, nonzero value on success (required by libmnl + * to continue messages processing). + */ +static int +flow_tcf_collect_query_cb(const struct nlmsghdr *nlh, void *arg) +{ + struct tcf_nlcb_query *query = arg; + struct tcmsg *tcm = mnl_nlmsg_get_payload(nlh); + struct nlattr *na, *na_opt; + bool flower = false; + + if (nlh->nlmsg_type != RTM_NEWTFILTER || + tcm->tcm_handle != query->handle) + return 1; + mnl_attr_for_each(na, nlh, sizeof(*tcm)) { + switch (mnl_attr_get_type(na)) { + case TCA_KIND: + if (strcmp(mnl_attr_get_payload(na), "flower")) { + /* Not flower filter, drop entire message. */ + return 1; + } + flower = true; + break; + case TCA_OPTIONS: + if (!flower) { + /* Not flower options, drop entire message. */ + return 1; + } + /* Check nested flower options. */ + mnl_attr_for_each_nested(na_opt, na) { + switch (mnl_attr_get_type(na_opt)) { + case TCA_FLOWER_FLAGS: + query->flags_valid = 1; + query->tc_flags = + mnl_attr_get_u32(na_opt); + break; + } + } + break; + } + } + return 1; +} + +/** + * Query a TC flower rule flags via netlink. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_context_create(). + * @param[in] dev_flow + * Pointer to the flow. + * @param[out] pflags + * pointer to the data retrieved by the query. + * + * @return + * 0 on success, a negative errno value otherwise. + */ +static int +flow_tcf_query_flags(struct mlx5_flow_tcf_context *tcf, + struct mlx5_flow *dev_flow, + uint32_t *pflags) +{ + struct nlmsghdr *nlh; + struct tcmsg *tcm; + struct tcf_nlcb_query query = { + .handle = dev_flow->tcf.tcm->tcm_handle, + }; + + nlh = mnl_nlmsg_put_header(tcf->buf); + nlh->nlmsg_type = RTM_GETTFILTER; + nlh->nlmsg_flags = NLM_F_REQUEST; + tcm = mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm)); + memcpy(tcm, dev_flow->tcf.tcm, sizeof(*tcm)); + /* + * Ignore Netlink error for filter query operations. + * The reply length is sent by kernel as errno. + * Just check we got the flags option. + */ + flow_tcf_nl_ack(tcf, nlh, flow_tcf_collect_query_cb, &query); + if (!query.flags_valid) { + *pflags = 0; + return -ENOENT; + } + *pflags = query.tc_flags; + return 0; +} + +/** + * Query and check the in_hw set for specified rule. + * + * @param[in] tcf + * Context object initialized by mlx5_flow_tcf_context_create(). + * @param[in] dev_flow + * Pointer to the flow to check. + * + * @return + * 0 on success, a negative errno value otherwise. + */ +static int +flow_tcf_check_inhw(struct mlx5_flow_tcf_context *tcf, + struct mlx5_flow *dev_flow) +{ + uint32_t flags; + int ret; + + ret = flow_tcf_query_flags(tcf, dev_flow, &flags); + if (ret) + return ret; + return (flags & TCA_CLS_FLAGS_IN_HW) ? 0 : -ENOENT; +} + /** * Remove flow from E-Switch by sending Netlink message. * @@ -5173,6 +5301,20 @@ struct tcf_nlcb_context { } if (!flow_tcf_nl_ack(ctx, nlh, NULL, NULL)) { dev_flow->tcf.applied = 1; + if (*dev_flow->tcf.ptc_flags & TCA_CLS_FLAGS_SKIP_SW) + return 0; + /* + * Rule was applied without skip_sw flag set. + * We should check whether the rule was acctually + * accepted by hardware (have look at in_hw flag). + */ + if (flow_tcf_check_inhw(ctx, dev_flow)) { + flow_tcf_remove(dev, flow); + return rte_flow_error_set + (error, ENOENT, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "netlink: rule has no in_hw flag set"); + } return 0; } if (dev_flow->tcf.tunnel) {