From patchwork Mon Jun 1 09:15:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 5032 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 941D8B3D6; Mon, 1 Jun 2015 11:15:57 +0200 (CEST) Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com [74.125.82.41]) by dpdk.org (Postfix) with ESMTP id 11C5B9A8F for ; Mon, 1 Jun 2015 11:15:56 +0200 (CEST) Received: by wgez8 with SMTP id z8so108568511wge.0 for ; Mon, 01 Jun 2015 02:15:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Kc1EXrGwdUPbCSxe73f7kc8gzCRh7XxgUQvQ57lYMnk=; b=YgOgPAzzaKKUBlmWxS+zdwC9Q3EdleD+DFcOscPtHZZBtjGjUAtlDW7O1pKN3BTMmM 4EyG0MZqIhE+th86TI7VTiYQz9KdBdlx+J+SSw4yxgKbnFFzwxMMVq3yMzkdQfHgJq7x H1ocpbPriu9Tpz65DctAwHdmBNsLuKfHuFyFM73b2669StrCK2oBlyZgUdWHWVaSnZWu eyLsJUjZnUWKHAj4zJFDfg8hseQuWn8yupi5EMut9Nk8EcI5eu7U2PtlmwKrRbeaj2de RFPQyBRjQmcdcvz2MkzLQDuyAWC0w4dfuhXdAleoZ6vRdDUL0sCdxzH4lmtwSTS6zBS0 SvBg== X-Gm-Message-State: ALoCoQk/zsj6wWx2LHzxhFlPRgrM7rTp4+O4sC3uzPF3JcyymnmGELwjlihS2v7kfDoerLtbrRSR X-Received: by 10.194.81.169 with SMTP id b9mr29494942wjy.126.1433150155964; Mon, 01 Jun 2015 02:15:55 -0700 (PDT) Received: from glumotte.dev.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id k2sm15690031wix.4.2015.06.01.02.15.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jun 2015 02:15:55 -0700 (PDT) From: Olivier Matz To: dev@dpdk.org Date: Mon, 1 Jun 2015 11:15:42 +0200 Message-Id: <1433150143-5842-3-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433150143-5842-1-git-send-email-olivier.matz@6wind.com> References: <1433150143-5842-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH 2/3] mempool: introduce objtlr structure for object trailers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Each object stored in mempools are suffixed by a trailer, storing a cookie in debug mode which help to detect memory corruptions. Like for headers, introduce a structure that materializes the content of this trailer. Signed-off-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 4 +++- lib/librte_mempool/rte_mempool.h | 42 +++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index b2d8700..60369cf 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -131,6 +131,7 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx, rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg) { struct rte_mempool_objhdr *hdr; + struct rte_mempool_objtlr *tlr __rte_unused; obj = (char *)obj + mp->header_size; @@ -140,7 +141,8 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx, #ifdef RTE_LIBRTE_MEMPOOL_DEBUG hdr->cookie = RTE_MEMPOOL_HEADER_COOKIE2; - __mempool_write_trailer_cookie(obj); + tlr = __mempool_get_trailer(obj); + tlr->cookie = RTE_MEMPOOL_TRAILER_COOKIE; #endif /* call the initializer */ if (obj_init) diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 5058940..cdb8f67 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -155,6 +155,18 @@ struct rte_mempool_objhdr { }; /** + * Mempool object trailer structure + * + * In debug mode, each object stored in mempools are suffixed by this + * trailer structure containing a cookie preventing memory corruptions. + */ +struct rte_mempool_objtlr { +#ifdef RTE_LIBRTE_MEMPOOL_DEBUG + uint64_t cookie; /**< Debug cookie. */ +#endif +}; + +/** * The RTE mempool structure. */ struct rte_mempool { @@ -249,6 +261,13 @@ static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj) sizeof(struct rte_mempool_objhdr)); } +/* return the trailer of a mempool object (internal) */ +static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj) +{ + return (struct rte_mempool_objtlr *)((char *)obj - + sizeof(struct rte_mempool_objtlr)); +} + /** * Return a pointer to the mempool owning this object. * @@ -264,25 +283,6 @@ static inline struct rte_mempool *rte_mempool_from_obj(void *obj) return hdr->mp; } -#ifdef RTE_LIBRTE_MEMPOOL_DEBUG -/* get trailer cookie value */ -static inline uint64_t __mempool_read_trailer_cookie(void *obj) -{ - struct rte_mempool **mpp = __mempool_from_obj(obj); - return *(uint64_t *)((char *)obj + (*mpp)->elt_size); - -} - -/* write trailer cookie value */ -static inline void __mempool_write_trailer_cookie(void *obj) -{ - uint64_t *cookie_p; - struct rte_mempool **mpp = __mempool_from_obj(obj); - cookie_p = (uint64_t *)((char *)obj + (*mpp)->elt_size); - *cookie_p = RTE_MEMPOOL_TRAILER_COOKIE; -} -#endif /* RTE_LIBRTE_MEMPOOL_DEBUG */ - /** * @internal Check and update cookies or panic. * @@ -306,6 +306,7 @@ static inline void __mempool_check_cookies(const struct rte_mempool *mp, unsigned n, int free) { struct rte_mempool_objhdr *hdr; + struct rte_mempool_objtlr *tlr; uint64_t cookie; void *tmp; void *obj; @@ -356,7 +357,8 @@ static inline void __mempool_check_cookies(const struct rte_mempool *mp, rte_panic("MEMPOOL: bad header cookie (audit)\n"); } } - cookie = __mempool_read_trailer_cookie(obj); + tlr = __mempool_get_trailer(obj); + cookie = tlr->cookie; if (cookie != RTE_MEMPOOL_TRAILER_COOKIE) { rte_log_set_history(0); RTE_LOG(CRIT, MEMPOOL,