From patchwork Fri Aug 11 15:18:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 13351010 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 A12E2EB64DD for ; Fri, 11 Aug 2023 15:20:36 +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=ltrHttqa8vGJLc/RB2v9Dflhvp1BN4ntmf1eXT3qC54=; b=ozu8/sNLTFwc+VCAgiBrNbUzuo ZtFFiZU5zdz/meNteX6JuEzdwq6Q0S1B7ELLqQLdX/aOg9mGajDZx8F00aLnJShdjHfyxcIJfcrpP 6c9VurHY2G5BHh5JTxdvisupQI8oxa+18Q7N4ziiTtiPpumY4yBGSJKTNT8UWNqSMQ5Ba/5JkD+2M yB+TWjRXJZy1/89jAXvBSDlcvVwvrsZiLNwxF+DqtHQpe/vV1lwKbXYP42J6pSO9NL5t2Mli/aHLY TqLOqY/yOWaDIc5BxyVPsanXpIRgT8eLuF+xYJizMCVzIKnHCH1WDH2Tb8/bjMpZ1YO2UsT1f1Ph+ yo8YqJeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qUTvv-00AwP2-1b; Fri, 11 Aug 2023 15:20:11 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qUTvp-00AwKL-0i for linux-arm-kernel@lists.infradead.org; Fri, 11 Aug 2023 15:20:07 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d27ac992539so2033897276.3 for ; Fri, 11 Aug 2023 08:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691767201; x=1692372001; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vr1U486Irq718Y5Vjn28mDb0feV+v+GYGzM/Kj2uczY=; b=m1/D3Wz2gi9Cs3OHDg7iK6vUaVmjXR/mBEkssZ6eiDX4uK2cf5n12+/DqBceY9qgAr 9c5mIs9OODdG0vj3Z1SdlT0fcTpSrTZNrf/sOTYryKqshqCTGV356GH4eUt6zYsDL6Y7 dhMd/RtYG371nzP2IXzmFytLbc22DzMJFtuwlKSf8hoJMP1OexW4RlZQDVTt3UVia3+H pDSddYYq+Gn5j6jgcFealLLycpGh3wDmyJdE0k4/jmlKu4U6VgcoLiWmdS/kwl9mu3qH lOvk1dXUz8tGeXyNfGd+iGsp/NUCifEEp+7HMAhvrl9Lr4g/6LKr5IJiM6YpAahM049Y ri8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691767201; x=1692372001; 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=vr1U486Irq718Y5Vjn28mDb0feV+v+GYGzM/Kj2uczY=; b=SGrLGJpnIzJspi9l6x6zj3XOqEU1B1FsqRQgWEmb1WgAjEcoTdSHsi3AJ7Vhqelld3 7AxYPxJvi1VOM4tnqPIR07eBv2REOTZ71NqLbt6sNg6fek68zoNciq+AM/IEKzOUEK3p qmsNW8lzIPLrPsAaleiM9rCLYqwWUDRw5rntc2QqwSmeMH2dDL/mxm2q9C2AUYB1+iWz 9lE1ecBcSiKFvD+M9ZrGp9HZQE8+9P7Ma0FSDM1EUE/qX8dV/5q5nHI78JM8rs/03Bgj q6KzXhMndkjMfOaNsaB304F0DKpOCrJmviAOoPAb8I6/W88UByoGrCYjNSo64QbaOTL+ 2sfA== X-Gm-Message-State: AOJu0Yzj5kGZKa9IWp6hOHKKJ8uT/lg8McpYLWupU08av6YFsbNDV/eQ wh+3kSN+M37kOA/Yw8dVn3xlxS0T7g== X-Google-Smtp-Source: AGHT+IE1ZLq4HueLWE6jbB2RlK4FqkKfdhzzoJrlx4qj6MjWBU1TM0fjy97D10E3vXrsojL+UjJkhk8T/Q== X-Received: from elver.muc.corp.google.com ([2a00:79e0:9c:201:8dc0:5176:6fda:46a0]) (user=elver job=sendgmr) by 2002:a25:b190:0:b0:d06:cbd:1f3e with SMTP id h16-20020a25b190000000b00d060cbd1f3emr33009ybj.3.1691767200863; Fri, 11 Aug 2023 08:20:00 -0700 (PDT) Date: Fri, 11 Aug 2023 17:18:39 +0200 In-Reply-To: <20230811151847.1594958-1-elver@google.com> Mime-Version: 1.0 References: <20230811151847.1594958-1-elver@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230811151847.1594958-2-elver@google.com> Subject: [PATCH v4 2/4] 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 , Arnd Bergmann , Greg Kroah-Hartman , Paul Moore , James Morris , "Serge E. Hallyn" , 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, linux-security-module@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-20230811_082005_276900_C8641DD1 X-CRM114-Status: GOOD ( 13.73 ) 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);