From patchwork Tue Aug 8 10:17:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 13345925 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7553C04A94 for ; Tue, 8 Aug 2023 10:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=5QnwP4a0EhiGVeqrOc0NoYPtCTDAE1CTmLN/b07kk2g=; b=5CNL8XqVmQXdZmGx7XhHJ7Ljrc X9gEuSGamqveILuieRuhyNs0wVlX53FE8JiYTIYHN6Uld6+t/d9ppebt1tpeNUlBLEmDk5QuwNPrC IaUhhGqqHO/Q0mMiu63H7Ta1i9O+nssZ7QHrntUKoAzMwK04izQedgte8dvzsyvAYeOJtEJqoFXSQ zzVss1lJX5Q/gWifTfjCuWVIRXHaiJpkZnX5jqomc1iwSI6zHCDLLrl7CJdCFKWxmZtYsmAWC2JES f4dfiqGk7zBE56EVKwvmHH69SVZoiR9AuC5CMQ1r1kisBnSU7k+EyceB1TYutwUFLmnhr+ykCWwlH IJAU+7iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qTJqK-002DcE-0p; Tue, 08 Aug 2023 10:21:36 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qTJqH-002DZn-0Y for linux-arm-kernel@lists.infradead.org; Tue, 08 Aug 2023 10:21:34 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-586a5cd0ea9so50039277b3.2 for ; Tue, 08 Aug 2023 03:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691490089; x=1692094889; 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=eGKzGkRmwHjO3/n1QcWNjJOltyC41u0duV0TVTZ3fBMgGDl0nlQ5QiRp7lOQAsE7QO OGr2AAIfLtRW2QiBskIUQSU2DGwjDOx7UMVUgMhvxWw/gE++HwEMAvv7dC/CU3+R4HMt GzhlZLUY2AGzPICPTPx5NbJmIyVj52XRkSbsKdm9qGLcq7/xfg0KX88jfLPuSqFKZFv2 ha1KlWQw7jxa9v/R0N3pMeV5TzG0W+8X0/EZX7J+jnqEG00HIpJFpFLo2GvWg7evJYo1 ewY4Ufv9e369vjGwh85Jn1JoVfJCD1dE9/tT9sf7m+Wi9s2I9JgifsHU2zq8qO0/nbKl FnWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691490089; x=1692094889; 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=JLr8NPqZnWpFMnIOL4zP1UM9hQ3ZqxVa3OG+1L/AejKEniw7x6/yTjXX9accFcZTcI M+dT6VP0zqgdIcJETtcNgH/8aWUWfzZ61lLcl75lmbuOGH4YAytAjJ1v8Ob1eOVt9Vkf alCoUtkYVuuiN8KJQZnenT1t0TkvKJ1DEkYAIWKLeasj8AzMfSNgyiSP9vm1Ctd3Ikrp AZsMbgANNYYSSfPpIoTVNx4MMiToY3EZSZlo9rZg2woiFxXvRhj472XktluZBlod+Xhj SIHXWk1h3zJsKVQI9MrH2w+5WHiO/yDTDeBn7pK7Zvx/SArG6084TNi9KvCOD6TJTVyC PXPw== X-Gm-Message-State: AOJu0YzwqKA3kyI48+ubBPlMVGJ1xy/CI6lVpAHN9x64/Rils28naad+ 5L9HCoNT3+wwtW9GI7oh3bUmNiJ86w== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230808_032133_214649_B3C9B8E6 X-CRM114-Status: GOOD ( 14.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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);