From patchwork Thu Apr 27 00:08:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13225035 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 B0B58C7EE24 for ; Thu, 27 Apr 2023 00:10:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D8596B007D; Wed, 26 Apr 2023 20:09:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8ACD86B007E; Wed, 26 Apr 2023 20:09:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 727796B0080; Wed, 26 Apr 2023 20:09:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 61F796B007D for ; Wed, 26 Apr 2023 20:09:50 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2339816045A for ; Thu, 27 Apr 2023 00:09:50 +0000 (UTC) X-FDA: 80725237740.06.FAF4B35 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 1B44840021 for ; Thu, 27 Apr 2023 00:09:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=Yy0rDZNc; spf=pass (imf01.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=1682554188; 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=VjHtF6foxcpPkuDRLURypMKoHlv1VKb82EFT44hMcWo=; b=1syJRBFRut2dCg7tG+QyhAYVkTrVCJgJz4uC8ngUzQUTmY540ed5DRPbDsYXRnsueAlEbS ePwpy5/u47hydW3nORgUWw8EDVOhfeX1kNhHjqTito9c/T8pEfrmEjNCK/XsK9S6pvh/yR alQ7Pchr7oZ72kzvvODiUcgPq7H0R6E= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=Yy0rDZNc; spf=pass (imf01.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682554188; a=rsa-sha256; cv=none; b=ny6rFjqpUZJNAB9J6gIWAMkIfktj3uHRWjVakEy+3qiKFn6TMDK2um5NGHioMuYoWFr7o5 55QvdwHOkwtsW/ocbBzzOeaMiuFbNcc19XI7m4Dddo9+qx2a10vAMwAgN0NErQpX1iyZiH nFNBt5Fr+GijwnBSiyOzO2YOgeN3AK8= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QGxIC6009633; Thu, 27 Apr 2023 00:09:28 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=VjHtF6foxcpPkuDRLURypMKoHlv1VKb82EFT44hMcWo=; b=Yy0rDZNcm0K3+32Kv5Kt0bnPhZ+cjF+9HlcT8JjGanst6ujGlEFRgGR7Ty79CgHZnvhb 7RTmGajtoDcdzYpnzsTA+k/ABNEC1jZn22VcWZc0OANw7MpS0eOUswTIk1JBI0ub4N37 IxTv2QvPe0bmDiAlAOcHmJTDoHO8Zod3IT83urwFmtn2gzLy+JH6nmLGe+e863aIch4A WuzSrCLKVsUPlRJ9BwvFUGWu9PKDq5sFRAeU5XrJbS8BjGunh37SO3dCp9KefjeNn9CB s3FOGBZB1g9Z9GtLUzadHIQb3UVXkgecu+FEa8rdMXsWTpQtMXS/5i1nqDt2NMBR19YD 5w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q484utq26-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:27 +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 33QNUjaj007380; Thu, 27 Apr 2023 00:09:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618mpqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:26 +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 33R0938q013888; Thu, 27 Apr 2023 00:09:26 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-16; Thu, 27 Apr 2023 00:09:26 +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 15/21] kexec: PKRAM: prevent kexec clobbering preserved pages in some cases Date: Wed, 26 Apr 2023 17:08:51 -0700 Message-Id: <1682554137-13938-16-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-GUID: -pxnJnsePK2q5pM0GAqWo7YuzPwuh3pz X-Proofpoint-ORIG-GUID: -pxnJnsePK2q5pM0GAqWo7YuzPwuh3pz X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: npux4x6jhhotsja7hx3fcykikuhn4i7c X-Rspamd-Queue-Id: 1B44840021 X-HE-Tag: 1682554187-148689 X-HE-Meta: U2FsdGVkX18TSd9lpdG+nND4caax4lxySF3qXLZW235R9tpjMnFrEv3K+O46R2+Z6ankSXJcGetnx9XxmDUgw/aTWeWKSXHcVRWtZm44xXZmneQ+nmRNa8icw+nsIt7A8obr6DlCxoEqWJHPzxRReFpRima6AUH/TOjZsZIylDPYZtjZdLK5zh105OyD3K80oYhipdi8NSBfffIblzqoZkQ64Tca1gwUWPMk7+EXNwPlLcf2ljFPWozQh8WkaMwAuUofdKuZFl/aeJicjg38Iw/js4nAKE2aJEZOkmh/yCIU8LdijE0/VRz981dag2pZzALuUksSudgkz8VpQ+8p+4GItmSYW2u3oOgh/P4vvv4lKkf0CB20BBoV5GQFSdi+xhbeIlWNoHi3Xe1rhuFSA8Q0eXcaa9ECOu2XlC2Ss3HLwSCAHr8qgFmrZDXGN8itITyWTvYua+AOckRoiEGe6w8vbjwej8teTEY1btIr3OQbnbMGj82s4SCyxbXdZ1KC/LX6Mj003vl/RHOQ9unKsUTz35WE16EcmBj0hINc3FBX//QeqayXWiuEss3ac0fpeXtvsuItqFKpQnQOsptJHTnLOqarf2Pe3l/QqF0exnVn3+fc/wzU+PeAxoHJS28gEJ86Kinh9bKrcfdIJIj841YFNJHthqvq57HSK8EHbkjyVrcjcHCBrVs+Wi8qKhpoibhybTIPaPRgUiD9hzSNJJm1an7vj5Oxdt5e4/F6Ddukka/EJo7NcYqw+Uhg2uSnYTXxY8k6XntUYnLVx9U6RYoJPCgTTapJO2I3UUEiwd94tirV0rGhDH65b9nJN0JaJLfl67CPnKXbUPRXxB96dr8rjKVStXHqwyGz2/lXn/GPLjqfq596Hq8QGK2BRWaXYrZ2t4N9NuE22Fq9VjeT69pGtmgboKiS1qXImWwnuANJ2jSS5McfGZc5tVc5KnF7d0A3VQAQlGQj7d/217w JShfqb8Z /fTJ9q1PVp1XknvYFWlP7bReexqcURhEuKTMMt8vIKacuvDoGotx6YLQmbW1TElrAfl2hGV41me/ieEe0MUPDilSXHod1oK9KMPqSkqU9cNSYrl1/rvqTV8gp5c9+KbCcjzosnJ3nlemivPq5V6uswA66RVECQ7cX7FFNBTQJhH5C4Vk= 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: When loading a kernel for kexec, dynamically update the list of physical ranges that are not to be used for storing preserved pages with the ranges where kexec segments will be copied to on reboot. This ensures no pages preserved after the new kernel has been loaded will reside in these ranges on reboot. Not yet handled is the case where pages have been preserved before a kexec kernel is loaded. This will be covered by a later patch. Signed-off-by: Anthony Yznaga --- kernel/kexec.c | 9 +++++++++ kernel/kexec_file.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/kernel/kexec.c b/kernel/kexec.c index 92d301f98776..cd871fc07c65 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "kexec_internal.h" @@ -153,6 +154,14 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, if (ret) goto out; + for (i = 0; i < nr_segments; i++) { + unsigned long mem = image->segment[i].mem; + size_t memsz = image->segment[i].memsz; + + if (memsz) + pkram_ban_region(PFN_DOWN(mem), PFN_UP(mem + memsz) - 1); + } + /* Install the new kernel and uninstall the old */ image = xchg(dest_image, image); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f1a0e4e3fb5c..ca2aa2d61955 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -27,6 +27,8 @@ #include #include #include +#include + #include "kexec_internal.h" #ifdef CONFIG_KEXEC_SIG @@ -403,6 +405,14 @@ static int kexec_image_verify_sig(struct kimage *image, void *buf, if (ret) goto out; + for (i = 0; i < image->nr_segments; i++) { + unsigned long mem = image->segment[i].mem; + size_t memsz = image->segment[i].memsz; + + if (memsz) + pkram_ban_region(PFN_DOWN(mem), PFN_UP(mem + memsz) - 1); + } + /* * Free up any temporary buffers allocated which are not needed * after image has been loaded