From patchwork Thu Mar 28 11:56:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13608431 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D68C0C54E67 for ; Thu, 28 Mar 2024 11:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=P57O/K4ocDT9bathb96wax8m9T0WY6vhXHsybR2p1hg=; b=SBEp3ouzMdl1YJ /arp3/w7slugNSul5pA7dNdBpbmvBphIepvVvlvNTXyiLCvLHntIe1dluoUgHTywn6+2d3MXAEN12 pQFzQCdriNPpDsgPCRLNS+B3y2rz8P1PBzHAMEnC+JMrQY9Tv9nLtFv1Adl4zJsP2vWGHCZRoELvz Vd9yiM7qo867wj0wNGqGwGcMZQ2uSSJdeNIIXU/Y9Im54bmvjzXsQEKCEAFkdnCS4OBA9eJuwvbhx lSqfKNoGY+F27qJK3G2ThLmrm1Vx52mKWgnk6H4HsHJhHYt4qCJWFvxS9jyjY3Y9FzRCp+21S2yR0 fe6vish7ZK1AIB86yCtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpoNx-0000000DoAS-0Okm; Thu, 28 Mar 2024 11:57:33 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpoNq-0000000Do8h-1wmG for linux-arm-kernel@lists.infradead.org; Thu, 28 Mar 2024 11:57:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711627045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oVr0pDknD7eE+qcvrSyGL3UT9DYidTr2J136fWz2sOw=; b=e69npG7GKkE6l3PXgIVzAG/GnHWTj2TDsWuNLDWeY/SYDUqOXfEbvED23o+jkn5RhDyxFr s4PloR3dzJPjnLiiSv1XosBCGE5KjaIvYh5pnPpPopFPkoUb3aAkMIl3V5h9A+0ww1YJ1P IDpoAr8ig7GC0VSnN9z+BlX+GAjPsVg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-OYs_cn_iM66AdCnE_v7ESA-1; Thu, 28 Mar 2024 07:57:22 -0400 X-MC-Unique: OYs_cn_iM66AdCnE_v7ESA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D707C84B166; Thu, 28 Mar 2024 11:57:21 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id C057D1C060D0; Thu, 28 Mar 2024 11:57:18 +0000 (UTC) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Ard Biesheuvel , Kees Cook , Mark Rutland , Pasha Tatashin Subject: [PATCH 2/4] arm64: mm: Provide prot param in trans_pgd_idmap_page()'s prototype Date: Thu, 28 Mar 2024 19:56:52 +0800 Message-ID: <20240328115656.24090-3-piliu@redhat.com> In-Reply-To: <20240328115656.24090-1-piliu@redhat.com> References: <20240328115656.24090-1-piliu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_045726_611989_E2462B35 X-CRM114-Status: GOOD ( 14.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since relocate_kernel code will build stack at the rear of the page, it requires 'wx' on the page. Adapting the prototype of trans_pgd_idmap_page() to make it doable. The trans_pgd_idmap_page() can be enhanced further to support multiple pages. But since the change has met the requirement, it is not necessary to enhance for the time being. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Kees Cook Cc: Mark Rutland Cc: Pasha Tatashin To: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/trans_pgd.h | 2 +- arch/arm64/kernel/hibernate.c | 3 ++- arch/arm64/kernel/machine_kexec.c | 4 ++-- arch/arm64/mm/trans_pgd.c | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/trans_pgd.h b/arch/arm64/include/asm/trans_pgd.h index 033d400a4ea4..c55a8a5670a8 100644 --- a/arch/arm64/include/asm/trans_pgd.h +++ b/arch/arm64/include/asm/trans_pgd.h @@ -31,7 +31,7 @@ int trans_pgd_create_copy(struct trans_pgd_info *info, pgd_t **trans_pgd, unsigned long start, unsigned long end); int trans_pgd_idmap_page(struct trans_pgd_info *info, phys_addr_t *trans_ttbr0, - unsigned long *t0sz, void *page); + unsigned long *t0sz, void *page, pgprot_t prot); int trans_pgd_copy_el2_vectors(struct trans_pgd_info *info, phys_addr_t *el2_vectors); diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 02870beb271e..0c5ce99b7acf 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -203,7 +203,8 @@ static int create_safe_exec_page(void *src_start, size_t length, memcpy(page, src_start, length); caches_clean_inval_pou((unsigned long)page, (unsigned long)page + length); - rc = trans_pgd_idmap_page(&trans_info, &trans_ttbr0, &t0sz, page); + rc = trans_pgd_idmap_page(&trans_info, &trans_ttbr0, &t0sz, page, + PAGE_KERNEL_ROX); if (rc) return rc; diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index b38aae5b488d..de4e9e0ad682 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -141,8 +141,8 @@ int machine_kexec_post_load(struct kimage *kimage) reloc_size = __relocate_new_kernel_end - __relocate_new_kernel_start; memcpy(reloc_code, __relocate_new_kernel_start, reloc_size); kimage->arch.kern_reloc = __pa(reloc_code); - rc = trans_pgd_idmap_page(&info, &kimage->arch.ttbr0, - &kimage->arch.t0sz, reloc_code); + rc = trans_pgd_idmap_page(&info, &kimage->arch.ttbr0, &kimage->arch.t0sz, + reloc_code, PAGE_KERNEL_EXEC); if (rc) return rc; kimage->arch.phys_offset = virt_to_phys(kimage) - (long)kimage; diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c index 7b14df3c6477..4dfe6a9f9a8b 100644 --- a/arch/arm64/mm/trans_pgd.c +++ b/arch/arm64/mm/trans_pgd.c @@ -230,7 +230,7 @@ int trans_pgd_create_copy(struct trans_pgd_info *info, pgd_t **dst_pgdp, * maximum T0SZ for this page. */ int trans_pgd_idmap_page(struct trans_pgd_info *info, phys_addr_t *trans_ttbr0, - unsigned long *t0sz, void *page) + unsigned long *t0sz, void *page, pgprot_t prot) { phys_addr_t dst_addr = virt_to_phys(page); unsigned long pfn = __phys_to_pfn(dst_addr); @@ -240,7 +240,7 @@ int trans_pgd_idmap_page(struct trans_pgd_info *info, phys_addr_t *trans_ttbr0, int this_level, index, level_lsb, level_msb; dst_addr &= PAGE_MASK; - prev_level_entry = pte_val(pfn_pte(pfn, PAGE_KERNEL_ROX)); + prev_level_entry = pte_val(pfn_pte(pfn, prot)); for (this_level = 3; this_level >= 0; this_level--) { levels[this_level] = trans_alloc(info);