From patchwork Wed Oct 2 16:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Ryabinin X-Patchwork-Id: 13820018 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 988ADCF6D3E for ; Wed, 2 Oct 2024 16:09:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D9906B03A3; Wed, 2 Oct 2024 12:09:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 38A486B03A5; Wed, 2 Oct 2024 12:09:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 190376B03A4; Wed, 2 Oct 2024 12:09:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D54D16B0384 for ; Wed, 2 Oct 2024 12:09:09 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 72F411A0962 for ; Wed, 2 Oct 2024 16:09:09 +0000 (UTC) X-FDA: 82629146418.09.0A18FB4 Received: from forwardcorp1d.mail.yandex.net (forwardcorp1d.mail.yandex.net [178.154.239.200]) by imf18.hostedemail.com (Postfix) with ESMTP id 6BF501C001D for ; Wed, 2 Oct 2024 16:09:07 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=yandex-team.com header.s=default header.b=QJ6MOGmC; spf=pass (imf18.hostedemail.com: domain of arbn@yandex-team.com designates 178.154.239.200 as permitted sender) smtp.mailfrom=arbn@yandex-team.com; dmarc=pass (policy=none) header.from=yandex-team.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727885220; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0gXnv/qrKYuE/cS8ZBx3ikqYeKs1eCUWKuL7cMB0Reg=; b=h5gN1Y7+BkKtTRbJqggagf9+dSy18Avpyo/+2NMw/ZtT989g6ikZx/rKbH/Te9wkxCtkjL gsHpOka3F9n/mgdNXMWEzXPEoTbF4N7/kyHQB0/aeOUxEKs+YSHy0T510heywIrgMRzZGn VqpkOf8zNOG1h7Peg0TtOrnCxFJo3rM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727885220; a=rsa-sha256; cv=none; b=6oYssR9/NsvRs+7Y1sA6AZWhLZZBi7uInrB+5eOPacEBrFAfyRsPbLUS4STz4jjhrCeOCl 9wpcgT+VvnEyzsfViwAA34zcU05+gMjVd2eCJcDky21suJfFj17urtbEHddrr5rKhGCVZB O7UnhG4RGg6e46gO8FwImpvFMierlbY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=yandex-team.com header.s=default header.b=QJ6MOGmC; spf=pass (imf18.hostedemail.com: domain of arbn@yandex-team.com designates 178.154.239.200 as permitted sender) smtp.mailfrom=arbn@yandex-team.com; dmarc=pass (policy=none) header.from=yandex-team.com Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:b1cb:0:640:2a1e:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E548260A23; Wed, 2 Oct 2024 19:09:05 +0300 (MSK) Received: from dellarbn.yandex.net (unknown [10.214.35.248]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id Z8emWD2IhiE0-nRmmw9QO; Wed, 02 Oct 2024 19:09:05 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.com; s=default; t=1727885345; bh=0gXnv/qrKYuE/cS8ZBx3ikqYeKs1eCUWKuL7cMB0Reg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=QJ6MOGmC2WXQfZHzJZ1VaR1B8rKzNr7QnMVdzqdp+QQv3P0S3FHMiPewEj2rscP08 wpInBKldjvUn90+GV+UmlmIIYMJDqh6JpsBqKYkROXaqaEMgJ2zuIgRq06YpaV+5qL OvdxqE3T7r9VwN+6lIu4k91/bcBG6keVqTB4vvQk= From: Andrey Ryabinin To: linux-kernel@vger.kernel.org Cc: Alexander Graf , James Gowans , Mike Rapoport , Andrew Morton , linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Eric Biederman , kexec@lists.infradead.org, Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , linux-trace-kernel@vger.kernel.org, valesini@yandex-team.com, Andrey Ryabinin Subject: [RFC PATCH 6/7] kstate, test: add test module for testing kstate subsystem. Date: Wed, 2 Oct 2024 18:07:21 +0200 Message-ID: <20241002160722.20025-7-arbn@yandex-team.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241002160722.20025-1-arbn@yandex-team.com> References: <20241002160722.20025-1-arbn@yandex-team.com> MIME-Version: 1.0 X-Yandex-Filter: 1 X-Rspamd-Queue-Id: 6BF501C001D X-Stat-Signature: jfainoec9dc9k3tr1u8y3f17943kg56r X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727885347-950031 X-HE-Meta: U2FsdGVkX19VvuJyL/PNMvcPDK4iAZJWnj+LWvlE9FcJBBbj5XZdZYgM0PvScCD/DLQLZKz5MvxxAMg6oRcfaajHuv/gICG2cMybnTF4JnP0rDVrccKvye7AUnx2Xavhlg4ke1RcNHqDiQ+uBCWk99c3/cpJfEDheVU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yhaNP/XNn07y3pBlEfoa/xPwA3HqBdKk60sUBIqH8/EToDDF0WKRYW61d3V4eU/wjDcvLeqohjpX4dVW4TKt3yvVMwwUDs4A5pDXcGZm8XXm41qJo0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This is simple test and playground useful kstate subsystem development. It contains some structure with different kind of data which migrated across kexec to the new kernel using kstate. Signed-off-by: Andrey Ryabinin --- include/linux/kstate.h | 1 + lib/Makefile | 2 + lib/test_kstate.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 lib/test_kstate.c diff --git a/include/linux/kstate.h b/include/linux/kstate.h index 855acb339d5d7..2ddbe41a1f171 100644 --- a/include/linux/kstate.h +++ b/include/linux/kstate.h @@ -31,6 +31,7 @@ struct kstate_field { enum kstate_ids { KSTATE_PAGE_ID, KSTATE_RSVD_MEM_ID, + KSTATE_TEST_ID, KSTATE_LAST_ID = -1, }; diff --git a/lib/Makefile b/lib/Makefile index 773adf88af416..2432e47664c35 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -354,6 +354,8 @@ obj-$(CONFIG_PARMAN) += parman.o obj-y += group_cpus.o +obj-$(CONFIG_KSTATE) += test_kstate.o + # GCC library routines obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o diff --git a/lib/test_kstate.c b/lib/test_kstate.c new file mode 100644 index 0000000000000..e95e3110f8949 --- /dev/null +++ b/lib/test_kstate.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +unsigned long ulong_val; +struct kstate_test_data { + int i; + unsigned long *p_ulong; + char s[10]; + struct page *page; +}; + +struct kstate_description test_state = { + .name = "test", + .version_id = 1, + .id = KSTATE_TEST_ID, + .state_list = LIST_HEAD_INIT(test_state.state_list), + .fields = (const struct kstate_field[]) { + KSTATE_SIMPLE(i, struct kstate_test_data), + KSTATE_SIMPLE(s, struct kstate_test_data), + KSTATE_POINTER(p_ulong, struct kstate_test_data), + { + .name = "page", + .flags = KS_CUSTOM, + .offset = offsetof(struct kstate_test_data, page), + .save = kstate_page_save, + }, + KSTATE_SIMPLE(page, struct kstate_test_data), + KSTATE_END_OF_LIST() + }, +}; + +static struct kstate_test_data test_data; + +static int init_test_data(void) +{ + struct page *page; + int i; + + test_data.i = 10; + ulong_val = 20; + memcpy(test_data.s, "abcdefghk", sizeof(test_data.s)); + page = alloc_page(GFP_KERNEL); + if (!page) + return -ENOMEM; + + for (i = 0; i < PAGE_SIZE/4; i += 4) + *((u32 *)page_address(page) + i) = 0xdeadbeef; + test_data.page = page; + return 0; +} + +static void validate_test_data(void) +{ + int i; + + WARN_ON(test_data.i != 10); + WARN_ON(*test_data.p_ulong != 20); + WARN_ON(strcmp(test_data.s, "abcdefghk") != 0); + + for (i = 0; i < PAGE_SIZE/4; i += 4) { + u32 val = *((u32 *)page_address(test_data.page) + i); + + WARN_ON(val != 0xdeadbeef); + } +} + +static int __init test_kstate_init(void) +{ + int ret = 0; + + test_data.p_ulong = &ulong_val; + + if (!is_migrate_kernel()) { + ret = init_test_data(); + if (ret) + goto out; + } + + kstate_register(&test_state, &test_data); + + validate_test_data(); + +out: + return ret; +} +__initcall(test_kstate_init);