From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E5B0C001B0 for ; Tue, 8 Aug 2023 17:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234518AbjHHR00 (ORCPT ); Tue, 8 Aug 2023 13:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234524AbjHHRZj (ORCPT ); Tue, 8 Aug 2023 13:25:39 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405BE205D9 for ; Tue, 8 Aug 2023 09:11:06 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id af79cd13be357-76ce59841d5so710754885a.3 for ; Tue, 08 Aug 2023 09:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691511020; x=1692115820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LIkYxQB49dC0FQNHu2erIkpIfETNvfhvCz995ch8SuY=; b=c25NXJWnfKXvxvAA8etge8MPfNfUuQ/pXLYTu7TWIPo+76fZPJSLHzz+puYTXOdq0e 8b+25u9z/dOyg1FztVK8Hb+LP7S9KC+wWuerH7Fv9l7zsDEJUn6Kea9NKiqBPkZCVmTH 0gRysum5AvUwRdYeAF53Vldu+N/lXb4fvvCRWTBBX8bjPb5mcOVLNN8hyo0A56Qk6W8K v2K8y10PtbzWBLsYF7BuDL4iGuRfKIc7A6U9MVFLoFqsY0W1zm4gKTGdCoq3HQNgWNA5 pEiD79nPQEg95Dhrbrb88FCwCobUuT6VRDU67P55HpHkKIDGEsvk7miR3eg/s9QZqHBe rGFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691511020; x=1692115820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LIkYxQB49dC0FQNHu2erIkpIfETNvfhvCz995ch8SuY=; b=SP5h7+DKII2uGfSQP+olhujDxHan71VvhyzJC5SuIBTvNNis5xfARmKsYdxu26rbB/ 6PYsTNnaZBRdVf2sxhK8Ti0v8l1G59NHnzj4AYbFYQvzJR/11Y6dN3HF2n/0A6yJFv+n HGr5CebA5H5d3GqJoMTfdirn2vMWSxa+JfHNcU/YhbKRyEVu2cakiu73eSjKxcGdsY5Q +TqWC/XrcdwWXdw/nZDi/MFC9n6ZgzjhWfzqAQn+hmexHJt0guxm8590zFretUSkLDAQ o+tDFwthkc62NT+n3a9Zs8GfjbE2quTnoAuCc+zTMsx+ptNynJpi1SYJSGcspnARq6MU Z9oA== X-Gm-Message-State: AOJu0YzJERHU019Uy5+yeGA+Pgyv9lWfRWiO6sUChtrQSsgMi4AsRnOb ielL446lYZ3ILwnl2ZlC3IqJIUxV5Q== X-Google-Smtp-Source: AGHT+IHxvhUVKdMAT1tPy5MkypgIrF/CSoYfvgc0eKx9Lu6TYjeI7LJ8ieHcAdveSGPemZkzK5rR5O62Ng== X-Received: from elver.muc.corp.google.com ([2a00:79e0:9c:201:39c0:833d:c267:7f64]) (user=elver job=sendgmr) by 2002:a81:451f:0:b0:577:617b:f881 with SMTP id s31-20020a81451f000000b00577617bf881mr88047ywa.8.1691490089320; Tue, 08 Aug 2023 03:21:29 -0700 (PDT) Date: Tue, 8 Aug 2023 12:17:26 +0200 In-Reply-To: <20230808102049.465864-1-elver@google.com> Mime-Version: 1.0 References: <20230808102049.465864-1-elver@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Message-ID: <20230808102049.465864-2-elver@google.com> Subject: [PATCH v3 2/3] list_debug: Introduce inline wrappers for debug checks From: Marco Elver To: elver@google.com, Andrew Morton , Kees Cook Cc: Guenter Roeck , Peter Zijlstra , Mark Rutland , Steven Rostedt , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Nathan Chancellor , Nick Desaulniers , Tom Rix , Miguel Ojeda , Sami Tolvanen , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Dmitry Vyukov , Alexander Potapenko , kasan-dev@googlegroups.com, linux-toolchains@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org Turn the list debug checking functions __list_*_valid() into inline functions that wrap the out-of-line functions. Care is taken to ensure the inline wrappers are always inlined, so that additional compiler instrumentation (such as sanitizers) does not result in redundant outlining. This change is preparation for performing checks in the inline wrappers. No functional change intended. Signed-off-by: Marco Elver --- v3: * Rename ___list_*_valid() to __list_*_valid_or_report(). * Some documentation. --- arch/arm64/kvm/hyp/nvhe/list_debug.c | 6 ++--- include/linux/list.h | 37 +++++++++++++++++++++++++--- lib/list_debug.c | 11 ++++----- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/list_debug.c b/arch/arm64/kvm/hyp/nvhe/list_debug.c index d68abd7ea124..16266a939a4c 100644 --- a/arch/arm64/kvm/hyp/nvhe/list_debug.c +++ b/arch/arm64/kvm/hyp/nvhe/list_debug.c @@ -26,8 +26,8 @@ static inline __must_check bool nvhe_check_data_corruption(bool v) /* The predicates checked here are taken from lib/list_debug.c. */ -bool __list_add_valid(struct list_head *new, struct list_head *prev, - struct list_head *next) +bool __list_add_valid_or_report(struct list_head *new, struct list_head *prev, + struct list_head *next) { if (NVHE_CHECK_DATA_CORRUPTION(next->prev != prev) || NVHE_CHECK_DATA_CORRUPTION(prev->next != next) || @@ -37,7 +37,7 @@ bool __list_add_valid(struct list_head *new, struct list_head *prev, return true; } -bool __list_del_entry_valid(struct list_head *entry) +bool __list_del_entry_valid_or_report(struct list_head *entry) { struct list_head *prev, *next; diff --git a/include/linux/list.h b/include/linux/list.h index f10344dbad4d..130c6a1bb45c 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -39,10 +39,39 @@ static inline void INIT_LIST_HEAD(struct list_head *list) } #ifdef CONFIG_DEBUG_LIST -extern bool __list_add_valid(struct list_head *new, - struct list_head *prev, - struct list_head *next); -extern bool __list_del_entry_valid(struct list_head *entry); +/* + * Performs the full set of list corruption checks before __list_add(). + * On list corruption reports a warning, and returns false. + */ +extern bool __list_add_valid_or_report(struct list_head *new, + struct list_head *prev, + struct list_head *next); + +/* + * Performs list corruption checks before __list_add(). Returns false if a + * corruption is detected, true otherwise. + */ +static __always_inline bool __list_add_valid(struct list_head *new, + struct list_head *prev, + struct list_head *next) +{ + return __list_add_valid_or_report(new, prev, next); +} + +/* + * Performs the full set of list corruption checks before __list_del_entry(). + * On list corruption reports a warning, and returns false. + */ +extern bool __list_del_entry_valid_or_report(struct list_head *entry); + +/* + * Performs list corruption checks before __list_del_entry(). Returns false if a + * corruption is detected, true otherwise. + */ +static __always_inline bool __list_del_entry_valid(struct list_head *entry) +{ + return __list_del_entry_valid_or_report(entry); +} #else static inline bool __list_add_valid(struct list_head *new, struct list_head *prev, diff --git a/lib/list_debug.c b/lib/list_debug.c index d98d43f80958..2def33b1491f 100644 --- a/lib/list_debug.c +++ b/lib/list_debug.c @@ -17,8 +17,8 @@ * attempt). */ -bool __list_add_valid(struct list_head *new, struct list_head *prev, - struct list_head *next) +bool __list_add_valid_or_report(struct list_head *new, struct list_head *prev, + struct list_head *next) { if (CHECK_DATA_CORRUPTION(prev == NULL, "list_add corruption. prev is NULL.\n") || @@ -37,9 +37,9 @@ bool __list_add_valid(struct list_head *new, struct list_head *prev, return true; } -EXPORT_SYMBOL(__list_add_valid); +EXPORT_SYMBOL(__list_add_valid_or_report); -bool __list_del_entry_valid(struct list_head *entry) +bool __list_del_entry_valid_or_report(struct list_head *entry) { struct list_head *prev, *next; @@ -65,6 +65,5 @@ bool __list_del_entry_valid(struct list_head *entry) return false; return true; - } -EXPORT_SYMBOL(__list_del_entry_valid); +EXPORT_SYMBOL(__list_del_entry_valid_or_report); -- 2.41.0.640.ga95def55d0-goog