From patchwork Mon Jan 31 12:40:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keir Fraser X-Patchwork-Id: 12730674 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 6B540C433F5 for ; Mon, 31 Jan 2022 12:43:01 +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:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=7Jl1heePjJysjvt3C6XjoQntqwmOiCiU6TGSh0+w4OI=; b=vfZ xe5eo/y43EIB2GZontsWyH1BNyb0zDdkUyTEBQQDb1OBiNl0q0hZeepUnjuLlW6VBF/kFIk8oy5MZ BsgftKGLK1YjE1keuPdI13ck6LqgdPiWpThS1UOKy0ZLUKVzOSN8aq8GD6BkYPmBC5PnUory44O+R k0h3nFlvjU4gIGi8Xv5TQcHsfJMmIcnuXNvG/oKmA33JKWaAHGrNG/LpY0zw/cLHg8WlCAhNVbAiR 05fUylDehl3nZqTfpPqQTH4O3ngG2YIdEMKXJrLc/qV09xpQbN5oB+1IxrfOc/WBUDEkQj0gCAYUI yitkn9Goifh6JIf9xwa7qXCVF4OsXnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEVzs-009NCD-6q; Mon, 31 Jan 2022 12:41:28 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEVzo-009NBW-Ml for linux-arm-kernel@lists.infradead.org; Mon, 31 Jan 2022 12:41:26 +0000 Received: by mail-wr1-x44a.google.com with SMTP id b3-20020a5d4b83000000b001d676462248so4785168wrt.17 for ; Mon, 31 Jan 2022 04:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=PcKNikI55bDy8w/A2/XpgUqHNUjMqDQm7v+KU8P6jUw=; b=ZedAg5IsAwnYYvRJ/slW9PVXqVh6BAZ3kdHrRnBQoYf7wiHTyZKjveOe7YXnVEe5hP yPUPut/r2Qk7KWFPFcGNBm2SE5zg5sDltAxYo4G7B4heLVKv2qAHpFm06Wsalcr3zu3g 3PHmeGOC10U2ZaArFU8ocDjO4TkyMSp3GUOvFHCXS1jGA9emquJCdQ9J0d9feaWzkHzO +rwBDjqhqFIRvy0IwvKkqArF1VRsL895WEF5D3dXCM7dDzwSxZ+JVPT7fMz90mXGyPxn zpsK4aNQcWyt/1fWq6JVHCzzWsWgox8bjxfUfbIi/ZattNOOq57oLM57K5q1tbAiR2md q/xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=PcKNikI55bDy8w/A2/XpgUqHNUjMqDQm7v+KU8P6jUw=; b=HFAlXLcll05TjQTHDVe/77uAAUvbtaq33Z8HeLUtt35wQbQ0m7PAFktaCiTMC4Q51I D7USFHThN8Mh2lDBV9Ix0HIWCMvVaVqWKG0U+0b7EDn/1p9JBjtYgk8xzU31NNenIeHt 6+feR1bsQ5B9TYInwj81qTroMHLTUJKiJ5Lge6uNXVfS7NIAlkvy0bBF/Zmjruvtnk5g cdf2oCK8QFNPzmgW09VBapQHR6t6tHiVYnReAV0ndWHRHn6QZ+9y1mT2rF+rUwaDZ8/D xS57LbhjBST8e+L+bM4Lb2Cy7M+MSibNK1djrE5H4GWxV1lyju53ppeTMmQouNCNH99Z QgUQ== X-Gm-Message-State: AOAM531aZCGaRMWbuNAYtO0Ar92wBve1rOnnWbbz+XZO+YSYYXVGGKXZ a/IVNzi6Eokdhqq2oOIRRifZKDyHW7eGlZarlTvGWnlCA8LSbaaLTWyHZMMFyBWOT9E9rRiasYr obHLuBAHjW0OeSeKeFht2EpjYB8HkWbcuiG/T9OyHSeWnU5wPQfG9X0ADqltZ5/j7wLH0b3PDj/ 99cQ== X-Google-Smtp-Source: ABdhPJxEMVqxK9VFD8U6hh5jEgX20oC9m+6rJ8uxexwyoP/dRPBjb+gbo3+XuJgFltlFVrGro+z8K8VcqA== X-Received: from keirf-1.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:17ba]) (user=keirf job=sendgmr) by 2002:a05:6000:16c9:: with SMTP id h9mr17519944wrf.272.1643632882051; Mon, 31 Jan 2022 04:41:22 -0800 (PST) Date: Mon, 31 Jan 2022 12:40:53 +0000 Message-Id: <20220131124114.3103337-1-keirf@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog Subject: [PATCH v2] KVM: arm64: pkvm: Implement CONFIG_DEBUG_LIST at Hyp From: Keir Fraser To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Keir Fraser , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Quentin Perret , Fuad Tabba , Kees Cook , Kefeng Wang , Sami Tolvanen , Zenghui Yu , linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220131_044124_779709_8792266F X-CRM114-Status: GOOD ( 17.20 ) 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 Currently the check functions are stubbed out at EL2. Implement versions suitable for the constrained EL2 environment. Signed-off-by: Keir Fraser --- arch/arm64/kvm/hyp/nvhe/Makefile | 3 +- arch/arm64/kvm/hyp/nvhe/list_debug.c | 54 ++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/stub.c | 22 ------------ 3 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/list_debug.c delete mode 100644 arch/arm64/kvm/hyp/nvhe/stub.c diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile index 24b2c2425b38..f9fe4dc21b1f 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -13,10 +13,11 @@ lib-objs := clear_page.o copy_page.o memcpy.o memset.o lib-objs := $(addprefix ../../../lib/, $(lib-objs)) obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ - hyp-main.o hyp-smp.o psci-relay.o early_alloc.o stub.o page_alloc.o \ + hyp-main.o hyp-smp.o psci-relay.o early_alloc.o page_alloc.o \ cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o +obj-$(CONFIG_DEBUG_LIST) += list_debug.o obj-y += $(lib-objs) ## diff --git a/arch/arm64/kvm/hyp/nvhe/list_debug.c b/arch/arm64/kvm/hyp/nvhe/list_debug.c new file mode 100644 index 000000000000..d68abd7ea124 --- /dev/null +++ b/arch/arm64/kvm/hyp/nvhe/list_debug.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2022 - Google LLC + * Author: Keir Fraser + */ + +#include +#include + +static inline __must_check bool nvhe_check_data_corruption(bool v) +{ + return v; +} + +#define NVHE_CHECK_DATA_CORRUPTION(condition) \ + nvhe_check_data_corruption(({ \ + bool corruption = unlikely(condition); \ + if (corruption) { \ + if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \ + BUG_ON(1); \ + } else \ + WARN_ON(1); \ + } \ + corruption; \ + })) + +/* 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) +{ + if (NVHE_CHECK_DATA_CORRUPTION(next->prev != prev) || + NVHE_CHECK_DATA_CORRUPTION(prev->next != next) || + NVHE_CHECK_DATA_CORRUPTION(new == prev || new == next)) + return false; + + return true; +} + +bool __list_del_entry_valid(struct list_head *entry) +{ + struct list_head *prev, *next; + + prev = entry->prev; + next = entry->next; + + if (NVHE_CHECK_DATA_CORRUPTION(next == LIST_POISON1) || + NVHE_CHECK_DATA_CORRUPTION(prev == LIST_POISON2) || + NVHE_CHECK_DATA_CORRUPTION(prev->next != entry) || + NVHE_CHECK_DATA_CORRUPTION(next->prev != entry)) + return false; + + return true; +} diff --git a/arch/arm64/kvm/hyp/nvhe/stub.c b/arch/arm64/kvm/hyp/nvhe/stub.c deleted file mode 100644 index c0aa6bbfd79d..000000000000 --- a/arch/arm64/kvm/hyp/nvhe/stub.c +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Stubs for out-of-line function calls caused by re-using kernel - * infrastructure at EL2. - * - * Copyright (C) 2020 - Google LLC - */ - -#include - -#ifdef CONFIG_DEBUG_LIST -bool __list_add_valid(struct list_head *new, struct list_head *prev, - struct list_head *next) -{ - return true; -} - -bool __list_del_entry_valid(struct list_head *entry) -{ - return true; -} -#endif