Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp876907pxb; Tue, 1 Feb 2022 12:15:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMOcBaTIBacf+gcf/f4ov4cDbuujLC7vM4pw6PcgPKn801FCQ6w+iYZJeEA5ygMNikcuSS X-Received: by 2002:a17:906:99c3:: with SMTP id s3mr23017363ejn.696.1643746512356; Tue, 01 Feb 2022 12:15:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643746512; cv=none; d=google.com; s=arc-20160816; b=ki3BbtFbTpgM48crpOsncTua+L5qIFlK/tB1Bu6DskV5FHSCspEKv76vOD1adbBEc9 yvTq5w0bS44KuH4eGK6Xx7xwWnZ8MtL64co0OkwMGi4GhCVllKhhP/fOxrEvQCCm8Ui7 gVZ3WvSN/1/+DRmmFacBj1+51t35RZXzeRwyifzR7+iD4giZmaGDCa+oehTz4wbA5nwR DWINOAYeHveFx66QihK8DmjTLg1YiB1qu9JXpHpi4jP+paEAJt5ayIhIS1LUErb4QTBV M2tnv51kwzwlbmLwDyWlOWkuBFIGmRHOImD7Ij+LQzKMQ+EyJhdVMKLEqkqz6/NKsWrD yFBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=PcKNikI55bDy8w/A2/XpgUqHNUjMqDQm7v+KU8P6jUw=; b=QaIl6xQOE0KbLfBHP10Q/e59TSOxttEfUY8DTYYhOWXB9aWMLq+3QmrqPfcQmrIVxD EWM37p5/rwsCM8y9X+kb+1hyKy6Wk8Ft3ZOFoPXpjIyIxam4x5KwJxP57ZDJgYKLUW7B MFDJ7xzT2U4d6DVZ54VllzctPTw9eMoHeNlVRNqgQe2C4i8uKg0cIaGmME09d2vcRCiO V1VKjTEagD575z/eITxvoH99n/Pmd8V7a6t3yirCTK0F2nNHbIfyyLFuEzdl08pk7y41 jqLfrSsyKqsU/fuG1nhekiq2MK+h0T+5DOv/kNFTOcSqy5fgK7YrVvFns20EDxM5++D4 cNow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZedAg5Is; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o16si8593545ejy.891.2022.02.01.12.14.47; Tue, 01 Feb 2022 12:15:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZedAg5Is; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377785AbiAaMlZ (ORCPT + 99 others); Mon, 31 Jan 2022 07:41:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377723AbiAaMlX (ORCPT ); Mon, 31 Jan 2022 07:41:23 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5C89C06173B for ; Mon, 31 Jan 2022 04:41:23 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id bg23-20020a05600c3c9700b0034bb19dfdc0so2898386wmb.1 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=GRiwpJbOY5tzoVfeyaIijeiu3rySQGfUB9uYK9zSYucGnsad4J3LOvuJ6Nq2AFh/iC BxUiYy3AYT/ok5Ghw16kYWxdgdaKmpT3Rk4pqKc2HtNza7jW3Dim0Nt+ww6+GSjwQ7pW VtKMgXoS5TWlF2WYG7rywtU48n7oePHUBIfu4g1bRYmkht7FwI6K27OgvEiwdCJjvEVR wQH3t+61a2jwjHTOecW1cxKUlxGa/++v9K8++qOjUzviDKKKrp3yGQg1r+chzh2aU/Es qD8anqu6sa/r/TvnpJAc2OlfdiiTXZH6U1QIUNiZmHott2BkCPBdQv00aXZrNIJy3i4q MCeg== X-Gm-Message-State: AOAM533pBoIJNFh7IFcAPq5LaN0+WFYo9+QKNOEa3egebSD9+6zcD/Y/ xgvW2QRy78DQWD4/sqaaQy3sGrSI1w== 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 -- 2.35.0.rc2.247.g8bbb082509-goog