From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 41427A0A0F; Wed, 30 Jun 2021 07:52:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AE46240040; Wed, 30 Jun 2021 07:52:34 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2069.outbound.protection.outlook.com [40.107.244.69]) by mails.dpdk.org (Postfix) with ESMTP id C97204003C; Wed, 30 Jun 2021 07:52:32 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cWqHHeRWHc5BNRhmVoDCLwrTwYF4+AmJMsLUO4M/v+RgxlZ8C+aigfuWFjsOvviS+9cV666vfpeIRhyIYPZKN4rR9uyL7dvz7BY2GqEvqA644svhg4IvGv1PuhSPXrOkdsuD18c3HRk7v9LslcBfwemDjiB/QKYfpKm+xYoQ5JL9SKMDMEj3jz9ialgsfulJRHpXmAaTz6Gy2P+0X/b4oHKhKWPOEltXS7LRhYOxWfPtvSUvsHVGck2c5eHbVKOMfOnDkEOOKPyA6Ne8rX9m4aw9SnXsAA83n7kTaZfyUofYJRL/YOet3vEiBKiHF/A+TN1CkzgT45Pz2+nikUZWQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olKclb0jeqrxFqR147ZIYtviRXJnP4CIvQ7AfiaBqK8=; b=RWvZq2hSFVjXxHw8OQa3cz19ifsSYkB5+cU4RfTpBINQErtne7qYfqfdFAMmLLtaJvkeTOMjuQAvhS6EGRzitHqmobyw0tI/tAdXLbK+S0O9paBUvvxv8DAAWKxkJE/a0coNN2AhpKqhg+elvpGI1/6/swr7/R1EvqojXxO+byrcQjaIJCx4NXDjMhZM1XAiTYdDa/0ttX5GRun3xraqiRmu4gi3EujKmFiLkXK3bd0i46ciVMYYM9DBI9gob4eBFsVE/xh3Q9VK8nTzqpr9JumhmdbUKfYNPfjPIrtS4CFL1ovogHYokl8+71PinMKJTMW5CFb+/59r3Q1QQCwnZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olKclb0jeqrxFqR147ZIYtviRXJnP4CIvQ7AfiaBqK8=; b=jPJrlbjRQKe/4UsbWtCGg4vWeWkiaJvPUTa91i9y8cASof5OguKrKqOxQ1cbt+oN5LX69ophRtxdrgwOoIyp2GjxWUPi4Q9xhleNxj5yjimWW12HaSGgUCm6e4oG7rRzs1Ns65+HpT0YZbtRjxK+bHrAVgS4X6ekhdLqxtuuTVtuMgQfLeNfGqQE4L/X+5EAaoEBWYyF+MrrKayWXGRxeXkkEbl3MagXCHr9GNp1GBAnU4hsOOppvkQSp9u5M4oUlF4sQZePgrMZAkKSwO045WC3sy8Q84Fi0TELtp/xz/fqZYB0fkmbyqopNkR3zkHbGIxiO5Ry7YhGrU1ct4xS4g== Received: from DM4PR12MB5389.namprd12.prod.outlook.com (2603:10b6:5:39a::7) by DM4PR12MB5152.namprd12.prod.outlook.com (2603:10b6:5:393::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Wed, 30 Jun 2021 05:52:31 +0000 Received: from DM4PR12MB5389.namprd12.prod.outlook.com ([fe80::6823:63cc:f7d6:dd00]) by DM4PR12MB5389.namprd12.prod.outlook.com ([fe80::6823:63cc:f7d6:dd00%7]) with mapi id 15.20.4287.023; Wed, 30 Jun 2021 05:52:30 +0000 From: Matan Azrad To: Michael Baum , "dev@dpdk.org" CC: Raslan Darawsheh , Slava Ovsiienko , "stable@dpdk.org" Thread-Topic: [PATCH 1/3] regex/mlx5: fix memory region unregistration Thread-Index: AQHXbFM03+by/IFLt0yJtSyjNFfWSqssDzvA Date: Wed, 30 Jun 2021 05:52:30 +0000 Message-ID: References: <20210628192347.1825713-1-michaelba@nvidia.com> In-Reply-To: <20210628192347.1825713-1-michaelba@nvidia.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: nvidia.com; dkim=none (message not signed) header.d=none;nvidia.com; dmarc=none action=none header.from=nvidia.com; x-originating-ip: [109.67.13.216] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 47daab16-47ec-454a-8938-08d93b8b3ff6 x-ms-traffictypediagnostic: DM4PR12MB5152: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: UrhrGG82qGHhWvJ/uMpxnlU+jKZ5DakMt6SosD/3soXk+8wslbLrf6oTdxvYXLWwJUzsXxwZDPBsIV5pK6Xb5u9DNyBnGYtus6gmeNIVBpMlVXBALh3LUInGyrMgH6zQapmMHNslkv/eTUKSqjhbhHIgVR3Ogc7M7BbzXoWJkGuDvM7BPB5XYJb6cemF8girB/DOWRV1RWvdwnFNjZsH7Aq/6uUTFObty5eEIsEH87dyBgGe++tare/loN1iWzTbzdataKRVlvWaISp1QxVQG6goou0G2Rq7gUGvcrGXg81ScHlFo3NIOOPEBz3EiomxxVtxVBMBmgXBkPwyV6LkDH9anYgVX8poYqx7MReADv8z0TMHTdoxHbY/BlVvW4GNObbKOFb9VnwDA58KEXwQyvt3IO1bgJDb9lB/o0qEP2qjuwqFO9uQGMIldAf0VYZT0YyiEOfWx6K6Va/Djtb9kApQbYn97YWYvG2nudrc4eTjtFd2Fju4c/je/gnmSn/p8yzPNOQS5Cb3484Q37F2NajOGD4rRZJtoFxWGyudijTUe9O3NcPRj0VfHES0/w6AnQcJGZ0jhuTUJOujrzxBxn54ivOIgYWaUnGuN3ZxaidetRdUYQwFWOjcdYQdstCamjL/MptJhDn+t3d82uk/OwDOxQQdzz6bY3jHm4eH4zaQ6nSV/T0pKQElOUVZ4bongbkmMx0H7zyR23GyocVVnTxezKMmFZa7x9mEMVq/LUwecvP31xhtuKATQnuT6H/fYH8uoYZeNP5YwpihJV+xyw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR12MB5389.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(346002)(376002)(396003)(5660300002)(33656002)(66446008)(64756008)(76116006)(86362001)(66946007)(7696005)(66556008)(66476007)(6506007)(478600001)(2906002)(9686003)(55016002)(26005)(8676002)(71200400001)(966005)(83380400001)(186003)(52536014)(54906003)(450100002)(8936002)(110136005)(316002)(4326008)(38100700002)(122000001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?lPpy/frAkMXezyUjGPG73ya0+Vz/ezLeM0pTKhjVjE077+GdxaLgB/2U7iRa?= =?us-ascii?Q?OzIW01Ir263buJ58c7rtB01CjD81jkRjY3m17GHz0X4L61G/zfAv6OvC+DTF?= =?us-ascii?Q?4gfWOFWFyV8hwV954Pj182BxQk6/FjYv1lJjHC8jjZ06kNjAWoQrJsK4JfCt?= =?us-ascii?Q?Jgkwfup54hh8iL3GctL24t7o9NPyAGA8MkxLTOz+i/Z2rBBSCnE9XG3F+dYZ?= =?us-ascii?Q?nhWxl5Iu/aVGe+LIXz4w64MDvXUJIoLDhOvnFRm5LTXzilaA2DGQfDXCG/34?= =?us-ascii?Q?tSx1b4r18hEk9lUBm+tk+Vk+kUNX5/T6M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ascii?Q?XVBBsFU8ktZ67edqUIavK9k+vsJsCAVR++sQzo5bk2UtnDfefStI7TO2Y4J8?= =?us-ascii?Q?0boM8YhHnkwTgtF9xX8szp/pdWC+iLplcJwDWifANq7seyqAxo1CSNYoj7Dg?= =?us-ascii?Q?l0lkRDQCzpr3k2fLdkwLTDzF?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5389.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 47daab16-47ec-454a-8938-08d93b8b3ff6 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jun 2021 05:52:30.8155 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Kooq3W6jYhlSsS2Gs6I4qi9c2t/7Pg2P+KLQ8DURHfHVsT8NIBxOY3TGEzV2R/OmdfZGh7DnfpMi4kMvPwqo6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5152 Subject: Re: [dpdk-dev] [PATCH 1/3] regex/mlx5: fix memory region unregistration X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: Michael Baum > The issue can cause illegal physical address access while a huge-page A i= s > released and huge-page B is allocated on the same virtual address. > The old MR can be matched using the virtual address of huge-page B but th= e > HW will access the physical address of huge-page A which is no more part = of > the DPDK process. >=20 > Register a driver callback for memory event in order to free out all the = MRs of > memory that is going to be freed from the dpdk process. >=20 > Fixes: cda883bbb655 ("regex/mlx5: add dynamic memory registration to > datapath") > Cc: stable@dpdk.org >=20 > Signed-off-by: Michael Baum > --- >=20 > This series depends on this patch: > https://patchwork.dpdk.org/project/dpdk/patch/20210628150614.1769507- > 1-michaelba@nvidia.com/ > Please don't apply it only before this patch is integrated. >=20 > drivers/regex/mlx5/mlx5_regex.c | 55 ++++++++++++++++++++++++ > drivers/regex/mlx5/mlx5_regex.h | 2 + > drivers/regex/mlx5/mlx5_regex_fastpath.c | 39 +++++++++++++++-- > 3 files changed, 92 insertions(+), 4 deletions(-) >=20 > diff --git a/drivers/regex/mlx5/mlx5_regex.c > b/drivers/regex/mlx5/mlx5_regex.c index dcb2ced88e..0f12d94d7e 100644 > --- a/drivers/regex/mlx5/mlx5_regex.c > +++ b/drivers/regex/mlx5/mlx5_regex.c > @@ -11,6 +11,7 @@ > #include >=20 > #include > +#include > #include > #include > #include > @@ -24,6 +25,10 @@ >=20 > int mlx5_regex_logtype; >=20 > +TAILQ_HEAD(regex_mem_event, mlx5_regex_priv) mlx5_mem_event_list > =3D > + > TAILQ_HEAD_INITIALIZER(mlx5_mem_event_list); > +static pthread_mutex_t mem_event_list_lock =3D > PTHREAD_MUTEX_INITIALIZER; > + > const struct rte_regexdev_ops mlx5_regexdev_ops =3D { > .dev_info_get =3D mlx5_regex_info_get, > .dev_configure =3D mlx5_regex_configure, @@ -82,6 +87,40 @@ > mlx5_regex_get_name(char *name, struct rte_pci_device *pci_dev > __rte_unused) > pci_dev->addr.devid, pci_dev->addr.function); } >=20 > +/** > + * Callback for memory event. > + * > + * @param event_type > + * Memory event type. > + * @param addr > + * Address of memory. > + * @param len > + * Size of memory. > + */ > +static void > +mlx5_regex_mr_mem_event_cb(enum rte_mem_event event_type, > const void *addr, > + size_t len, void *arg __rte_unused) { > + struct mlx5_regex_priv *priv; > + > + /* Must be called from the primary process. */ > + MLX5_ASSERT(rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY); > + switch (event_type) { > + case RTE_MEM_EVENT_FREE: > + pthread_mutex_lock(&mem_event_list_lock); > + /* Iterate all the existing mlx5 devices. */ > + TAILQ_FOREACH(priv, &mlx5_mem_event_list, > mem_event_cb) > + mlx5_free_mr_by_addr(&priv->mr_scache, > + priv->ctx->device->name, > + addr, len); > + pthread_mutex_unlock(&mem_event_list_lock); > + break; > + case RTE_MEM_EVENT_ALLOC: > + default: > + break; > + } > +} > + > static int > mlx5_regex_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, > struct rte_pci_device *pci_dev) > @@ -193,6 +232,15 @@ mlx5_regex_pci_probe(struct rte_pci_driver > *pci_drv __rte_unused, > rte_errno =3D ENOMEM; > goto error; > } > + /* Register callback function for global shared MR cache > management. */ > + if (TAILQ_EMPTY(&mlx5_mem_event_list)) > + > rte_mem_event_callback_register("MLX5_MEM_EVENT_CB", > + > mlx5_regex_mr_mem_event_cb, > + NULL); > + /* Add device to memory callback list. */ > + pthread_mutex_lock(&mem_event_list_lock); > + TAILQ_INSERT_TAIL(&mlx5_mem_event_list, priv, mem_event_cb); > + pthread_mutex_unlock(&mem_event_list_lock); > DRV_LOG(INFO, "RegEx GGA is %s.", > priv->has_umr ? "supported" : "unsupported"); > return 0; > @@ -225,6 +273,13 @@ mlx5_regex_pci_remove(struct rte_pci_device > *pci_dev) > return 0; > priv =3D dev->data->dev_private; > if (priv) { > + /* Remove from memory callback device list. */ > + pthread_mutex_lock(&mem_event_list_lock); > + TAILQ_REMOVE(&mlx5_mem_event_list, priv, > mem_event_cb); > + pthread_mutex_unlock(&mem_event_list_lock); > + if (TAILQ_EMPTY(&mlx5_mem_event_list)) > + > rte_mem_event_callback_unregister("MLX5_MEM_EVENT_CB", > + NULL); > if (priv->pd) > mlx5_glue->dealloc_pd(priv->pd); > if (priv->uar) > diff --git a/drivers/regex/mlx5/mlx5_regex.h > b/drivers/regex/mlx5/mlx5_regex.h index 51a2101e53..61f59ba873 100644 > --- a/drivers/regex/mlx5/mlx5_regex.h > +++ b/drivers/regex/mlx5/mlx5_regex.h > @@ -70,6 +70,8 @@ struct mlx5_regex_priv { > uint32_t nb_engines; /* Number of RegEx engines. */ > struct mlx5dv_devx_uar *uar; /* UAR object. */ > struct ibv_pd *pd; > + TAILQ_ENTRY(mlx5_regex_priv) mem_event_cb; > + /**< Called by memory event callback. */ > struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. > */ > uint8_t is_bf2; /* The device is BF2 device. */ > uint8_t sq_ts_format; /* Whether SQ supports timestamp formats. > */ diff --git a/drivers/regex/mlx5/mlx5_regex_fastpath.c > b/drivers/regex/mlx5/mlx5_regex_fastpath.c > index b57e7d7794..437009dcb6 100644 > --- a/drivers/regex/mlx5/mlx5_regex_fastpath.c > +++ b/drivers/regex/mlx5/mlx5_regex_fastpath.c > @@ -109,6 +109,40 @@ set_wqe_ctrl_seg(struct mlx5_wqe_ctrl_seg *seg, > uint16_t pi, uint8_t opcode, > seg->imm =3D imm; > } >=20 > +/** > + * Query LKey from a packet buffer for QP. If not found, add the mempool= . > + * > + * @param priv > + * Pointer to the priv object. > + * @param mr_ctrl > + * Pointer to per-queue MR control structure. > + * @param op > + * Pointer to the RegEx operations object. > + * > + * @return > + * Searched LKey on success, UINT32_MAX on no match. > + */ > +static inline uint32_t > +mlx5_regex_addr2mr(struct mlx5_regex_priv *priv, struct mlx5_mr_ctrl > *mr_ctrl, > + struct rte_regex_ops *op) > +{ > + uintptr_t addr =3D rte_pktmbuf_mtod(op->mbuf, uintptr_t); > + uint32_t lkey; > + > + /* Check generation bit to see if there's any change on existing MRs. > */ > + if (unlikely(*mr_ctrl->dev_gen_ptr !=3D mr_ctrl->cur_gen)) > + mlx5_mr_flush_local_cache(mr_ctrl); Where is dev_gen_ptr initialized? > + /* Linear search on MR cache array. */ > + lkey =3D mlx5_mr_lookup_lkey(mr_ctrl->cache, &mr_ctrl->mru, > + MLX5_MR_CACHE_N, addr); > + if (likely(lkey !=3D UINT32_MAX)) > + return lkey; > + /* Take slower bottom-half on miss. */ > + return mlx5_mr_addr2mr_bh(priv->pd, 0, &priv->mr_scache, > mr_ctrl, addr, > + !!(op->mbuf->ol_flags & > EXT_ATTACHED_MBUF)); } > + > + > static inline void > __prep_one(struct mlx5_regex_priv *priv, struct mlx5_regex_sq *sq, > struct rte_regex_ops *op, struct mlx5_regex_job *job, @@ -160,10 > +194,7 @@ prep_one(struct mlx5_regex_priv *priv, struct mlx5_regex_qp > *qp, > struct mlx5_klm klm; >=20 > klm.byte_count =3D rte_pktmbuf_data_len(op->mbuf); > - klm.mkey =3D mlx5_mr_addr2mr_bh(priv->pd, 0, > - &priv->mr_scache, &qp->mr_ctrl, > - rte_pktmbuf_mtod(op->mbuf, uintptr_t), > - !!(op->mbuf->ol_flags & > EXT_ATTACHED_MBUF)); > + klm.mkey =3D mlx5_regex_addr2mr(priv, &qp->mr_ctrl, op); > klm.address =3D rte_pktmbuf_mtod(op->mbuf, uintptr_t); > __prep_one(priv, sq, op, job, sq->pi, &klm); > sq->db_pi =3D sq->pi; > -- > 2.25.1