From patchwork Thu Apr 27 00:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13225122 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 10417C7618E for ; Thu, 27 Apr 2023 02:53:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D4A56B0074; Wed, 26 Apr 2023 22:53:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 785736B0075; Wed, 26 Apr 2023 22:53:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64C666B0078; Wed, 26 Apr 2023 22:53:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5594F6B0074 for ; Wed, 26 Apr 2023 22:53:55 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1B07B16010A for ; Thu, 27 Apr 2023 02:53:54 +0000 (UTC) X-FDA: 80725651188.07.5C3D9C0 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 0C29440004 for ; Thu, 27 Apr 2023 02:53:50 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=0j0n+Kwn; spf=pass (imf27.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682564031; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=/klwynvryfeEh0hvbf4HAyTY1q/nlnl3HuBNmoKxWqE=; b=r+OXTyBxhJKyU5s97OTI6Q6dxDbOuP0rFoDh0F99tkNjk/UtmN4Ap2HCjAiZYx9hYa3SPR b0hleTpkMG3lKIS9TYXNTsDvWO3Ji3nwnmPtnjzDZKAHlb0qF9qRsYvX56thu4SGTEax7W Y8boag/YFGg5qkIz0NRJfqQl4rO4OdI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682564031; a=rsa-sha256; cv=none; b=lqtGTKz+oUhGY4WavLf/q2eamF47XiPBw3I+v8P3FoGi7axcLXtxokHqG9ATjAxrBApSgh UHvMVqy3ARZwCdnepor1fGriBlMDdLq7KjAmMRbF6dFBM3EH42F+nxgISn5XXMjuWv4iss B9OyLzEcYxyGb08Qgv90EARlm0d3Qs0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=0j0n+Kwn; spf=pass (imf27.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=none) header.from=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QGx8Pf014802; Thu, 27 Apr 2023 00:09:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-03-30; bh=/klwynvryfeEh0hvbf4HAyTY1q/nlnl3HuBNmoKxWqE=; b=0j0n+Kwn3Bvz2+mjvASxMuPf8yoNwQ+WflTC1dDKD5SawtcQeSwCAX5Kl9PhTbjLM7XR 0SZX9uzBB7nHTzqDuYT3ExaruHA9SVIUtnOMZT42jsPxL3vRnz7XBauO5nY7dbWI8FGa k+a1xB0bz8FRktPPGJfMWdBAzSN67DoN4vn/wLfmsPxiBZXp0NViGyfMYOIiBfLxFYT4 YXmoG776eXjaC1bOyRIBJqyj52I0AsEr/DhPR3yHpLY7noBzb6XnjLZj8fFYuYmVKzKv Q/FhZ+/q1DvdVY6ADsoIdHyzTV0xawqFouIVJzNEoW/6uIlQ72P899/I2IKT1PoYoTBo 0Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q47fatms1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:24 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33QNIv5l007334; Thu, 27 Apr 2023 00:09:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618mpnj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:23 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33R0938m013888; Thu, 27 Apr 2023 00:09:23 GMT Received: from ca-qasparc-x86-2.us.oracle.com (ca-qasparc-x86-2.us.oracle.com [10.147.24.103]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3q4618mp42-14; Thu, 27 Apr 2023 00:09:23 +0000 From: Anthony Yznaga To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, rppt@kernel.org, akpm@linux-foundation.org, ebiederm@xmission.com, keescook@chromium.org, graf@amazon.com, jason.zeng@intel.com, lei.l.li@intel.com, steven.sistare@oracle.com, fam.zheng@bytedance.com, mgalaxy@akamai.com, kexec@lists.infradead.org Subject: [RFC v3 13/21] PKRAM: prevent inadvertent use of a stale superblock Date: Wed, 26 Apr 2023 17:08:49 -0700 Message-Id: <1682554137-13938-14-git-send-email-anthony.yznaga@oracle.com> X-Mailer: git-send-email 1.9.4 In-Reply-To: <1682554137-13938-1-git-send-email-anthony.yznaga@oracle.com> References: <1682554137-13938-1-git-send-email-anthony.yznaga@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_10,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304270000 X-Proofpoint-ORIG-GUID: dA85op-dAowHiRV38HyLZKKt_wYwuMGr X-Proofpoint-GUID: dA85op-dAowHiRV38HyLZKKt_wYwuMGr X-Rspam-User: X-Rspamd-Queue-Id: 0C29440004 X-Rspamd-Server: rspam09 X-Stat-Signature: 4ic33pdhzycaw1kz3mnhfqd5n137n7wt X-HE-Tag: 1682564030-240709 X-HE-Meta: U2FsdGVkX18vhxPqzG9Ie000PWFEM5mU9MgM5umEvWZn/2b3RkxkskpDPJazejc2FeiDkMfMfzMXqeVUpbtUGvRo1+z8Xv1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ack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When pages have been saved to be preserved by the current boot, set a magic number on the super block to be validated by the next kernel. Signed-off-by: Anthony Yznaga --- mm/pkram.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/pkram.c b/mm/pkram.c index c63b27bb711b..befdffc76940 100644 --- a/mm/pkram.c +++ b/mm/pkram.c @@ -22,6 +22,7 @@ #include "internal.h" +#define PKRAM_MAGIC 0x706B726D /* * Represents a reference to a data page saved to PKRAM. @@ -110,6 +111,8 @@ struct pkram_region_list { * The structure occupies a memory page. */ struct pkram_super_block { + __u32 magic; + __u64 node_pfn; /* first element of the node list */ __u64 region_list_pfn; __u64 nr_regions; @@ -179,6 +182,11 @@ void __init pkram_reserve(void) err = PTR_ERR(pkram_sb); goto out; } + if (pkram_sb->magic != PKRAM_MAGIC) { + pr_err("PKRAM: invalid super block\n"); + err = -EINVAL; + goto out; + } /* An empty pkram_sb is not an error */ if (!pkram_sb->node_pfn) { pkram_sb = NULL; @@ -1012,6 +1020,7 @@ static void __pkram_reboot(void) */ memset(pkram_sb, 0, PAGE_SIZE); if (!err && node_pfn) { + pkram_sb->magic = PKRAM_MAGIC; pkram_sb->node_pfn = node_pfn; pkram_sb->region_list_pfn = rl_pfn; pkram_sb->nr_regions = nr_regions;