From patchwork Thu Apr 27 00:08:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13225038 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 BDE0CC7EE26 for ; Thu, 27 Apr 2023 00:10:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 469DE6B0081; Wed, 26 Apr 2023 20:09:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4193E6B0082; Wed, 26 Apr 2023 20:09:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BBBE6B0083; Wed, 26 Apr 2023 20:09:54 -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 1A4C86B0081 for ; Wed, 26 Apr 2023 20:09:54 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E979C1404F9 for ; Thu, 27 Apr 2023 00:09:53 +0000 (UTC) X-FDA: 80725237866.15.17A9CD6 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf21.hostedemail.com (Postfix) with ESMTP id E31E91C0011 for ; Thu, 27 Apr 2023 00:09:51 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=Fr50Imkc; spf=pass (imf21.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=1682554192; 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=GKXPxESVfvIM+pNIB5lGbZkr/9+GXI6AMF73iO2olBA=; b=JvrBhBy1Iw1fuKJSehZZkkwa5yFN95TYDxKEDBcS2fAiIda2pl0vCIhWQP1G4POLgicWra HU8ZWtLcEuuh7VMBGXsUC70n9bZZlQhtmnU7qkzq5W0uLzict5M+bd19v12uzsVlB2P01+ p65GfZ26kNPyI9bDs7tW6ZoeFzxZJ5E= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=Fr50Imkc; spf=pass (imf21.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=1682554192; a=rsa-sha256; cv=none; b=cm9CaNTZqDHL0vQr4WgvDprJsJBG9mIu0Tj7a7brJj2vpcjutp92EJm0d6sth6JPNxOYFB NqeVE04g6+Y+dDkHUkOyyOwAwfYHKH/Lx8cPn+CNjtx09s2e2VS2NaJdk7mVtWeuFIhdjd TAToYsDcxekEOPXS1PHWfLI7Fx2ykYc= 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 33QGxJYE009644; Thu, 27 Apr 2023 00:09:31 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=GKXPxESVfvIM+pNIB5lGbZkr/9+GXI6AMF73iO2olBA=; b=Fr50ImkcFewD5fhKQE2bdokl3ohNxwbCvzToQ3b3qQt8nmwfevLzs25EG7cuy39H0eWI n1LOh78LxZm9im3r9t7TbZe9BB3hn1nNdRiHeT9nPO+1uIo0+IM7jW8Nhi9WY9+llkpC C/hv+kIvPkuBGcQeWZeAHkGuhJKvx2Q2mu4mdrCOq9O3mqjJWFFzeVRC6bkX+TU9BPew B3hlYsgLWoUYC/EAzBBk2Kj2SXpbhsLn6xM59mCHDWHbJINIhPBxQtipbfWF6rvidti+ y2+4OGsrI+sJd8YTcewFfgjMScpiVf/CVq/hrFB+6a2eCVKnpqU302dIFuD/UE0e+l+f Ew== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q484utq2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:30 +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 33QN01rh007153; Thu, 27 Apr 2023 00:09:30 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618mpsr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:30 +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 33R0938u013888; Thu, 27 Apr 2023 00:09:29 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-18; Thu, 27 Apr 2023 00:09:29 +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 17/21] kexec: PKRAM: avoid clobbering already preserved pages Date: Wed, 26 Apr 2023 17:08:53 -0700 Message-Id: <1682554137-13938-18-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: AvvXex8oIgFKryG_FPd3JZhh5CVfptob X-Proofpoint-ORIG-GUID: AvvXex8oIgFKryG_FPd3JZhh5CVfptob X-Stat-Signature: 9pxzhcxxnhpubdziytkfk5aqyk1bimyj X-Rspam-User: X-Rspamd-Queue-Id: E31E91C0011 X-Rspamd-Server: rspam06 X-HE-Tag: 1682554191-166040 X-HE-Meta: U2FsdGVkX1/7vjg3WKN3lU/1mjgLwhEhUpacnzAxNQ5OsNTlNjTTGPYtBSIqB4zVwiKOVpnM5OjUKKnwn1FOC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=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Ensure destination ranges of the kexec segments do not overlap with any kernel pages marked to be preserved across kexec. For kexec_load, return EADDRNOTAVAIL if overlap is detected. For kexec_file_load, skip ranges containing preserved pages when seaching for available ranges to use. Signed-off-by: Anthony Yznaga --- kernel/kexec_core.c | 3 +++ kernel/kexec_file.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 3d578c6fefee..e0d52f70cb48 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -178,6 +179,8 @@ int sanity_check_segment_list(struct kimage *image) return -EADDRNOTAVAIL; if (mend >= KEXEC_DESTINATION_MEMORY_LIMIT) return -EADDRNOTAVAIL; + if (pkram_has_preserved_pages(mstart, mend)) + return -EADDRNOTAVAIL; } /* Verify our destination addresses do not overlap. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index ca2aa2d61955..8bca01060d32 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -490,6 +490,11 @@ static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end, continue; } + if (pkram_has_preserved_pages(temp_start, temp_end + 1)) { + temp_start = temp_start - PAGE_SIZE; + continue; + } + /* We found a suitable memory range */ break; } while (1);