From patchwork Wed Mar 13 12:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13591383 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 7170CC54791 for ; Wed, 13 Mar 2024 12:59:30 +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=lxtXeDJYHZ4O4Fi7VVe89yv9TSfzUpw5FBliI5iOssA=; b=Q0fHsAec6v2Yhd oW4Wq5+SOkuVUXoRLCvzum4COZkbnkSz/tMWuGzzzaNjv2ftBDgp9TrMpe7YncnQV24K2cew7ldrS sd8VWF4vpt/OGaE8y4JPyYhKq16Bf7sgrIGV8lsfCw7+eoAig8Cd9QP9KLADoJGMNKt6yAv49xOVX jBXX5B1O1RnmnMY2uAXFNcxZ8WYSEJH/Dkg6/v3eewgmj6J4FvLRNOhxovboDnYcwnn2vd9AjEAol MT+DYhhtnylDirmdu0gPXSYz09YFwLMmZKP62sSmvcYCApVpwwyS5lHxyFPYtcs9O4aDGoWJT1LUI rhYmYvp6t6JOCy3Bfn8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkOCV-0000000A8wp-1miS; Wed, 13 Mar 2024 12:59:19 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkOCU-0000000A8w6-1KFY for linux-arm-kernel@bombadil.infradead.org; Wed, 13 Mar 2024 12:59:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=4oWWkBxQCWLUXpAAFNHy9pFVbXBDN9dLJmUvQs17o7Q=; b=hbPnq1FdgJu9r9bVBGilFMMefQ /Vwq7k8wT4FFnog/CpJ2FT+HKrVYCvyPCi42SlkLiAu9PGmFs2bTk5u5DgSfMEgyFUlBRt0vlY+5d pxSFNay8MCzDHeU9JAGdwHALotVFWCCIziMzRcGL3/uwmX5qd3+eiUIeUVAt54/ZWdLwS9/2KiRy3 qSyR7UQt8Hrrq1MG5KjVjy0rVl5BZjKZAbeivHZK2rxD53MnJnz8tIYWG/1sRz0nA/ZM/BlomT1ST agN3DXnyoVM6LL6y3MIA5yAs6zOEStiNjUpvyHHJ+eLcNjSMFaJt83iojcBKJHhqfZCjqsi+gIvJ9 nn/YKXfw==; Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by casper.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkOCQ-00000005QOU-0rXF for linux-arm-kernel@lists.infradead.org; Wed, 13 Mar 2024 12:59:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710334671; 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=4oWWkBxQCWLUXpAAFNHy9pFVbXBDN9dLJmUvQs17o7Q=; b=NdPQAAU7GbJkSXxRYm0A93dZrM9uzJwDAw+70fqA5qUoVk7xpTASH5FZNKSfilUSkRZtli IvA+U3wMqfoTuaebh9ZZABVWQLl3ybAhRPGXRZAOcSk0JBe/FdCaowLzlxSITKz2lYktXp 6D+XjdG3+6RrcWHMppJdd/8pxD4U+IQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710334679; 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=4oWWkBxQCWLUXpAAFNHy9pFVbXBDN9dLJmUvQs17o7Q=; b=EkxEsnDdQRlyJgpagdIiDBHabESJePvTDb0RQcnKRFLEpuDg7o6LTmvJKSiAc5aMVsKwL/ kUhQOUCZwACxCyfE4wQrq4+cDoc1LbUWBMaEWxShbEw8QYN2eDtQ59XDi3cYdG970aahVZ hA93q2rkfni3VSZFItBJrfQykZwWCSI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710334687; 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=4oWWkBxQCWLUXpAAFNHy9pFVbXBDN9dLJmUvQs17o7Q=; b=ZoFc9WFYBS/xUcqtvZ8xwHyUuKoeTaSRgHh2mCl/Zk7R27rVZVPmjlHraFuRrWVtU7WXmI QeXxgYTWDm+QybjNpZuDFO7gh6QjInAOzs70FPRG7K/+Dj6lrMbJ9XuiAuGIq+a0I7afdM SK1pO61VdVZOz7PU85MzuQxohFF2QCg= 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-428-nNTM5Bk5MBO14FAo3SeRmQ-1; Wed, 13 Mar 2024 08:57:49 -0400 X-MC-Unique: nNTM5Bk5MBO14FAo3SeRmQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 B22D5800268; Wed, 13 Mar 2024 12:57:48 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DCB510E47; Wed, 13 Mar 2024 12:57:45 +0000 (UTC) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Ard Biesheuvel , Catalin Marinas , Will Deacon , Mark Rutland Subject: [PATCH 07/10] arm64: mm: Introduce head_pool routines to enable pgtabl allocation Date: Wed, 13 Mar 2024 20:57:05 +0800 Message-ID: <20240313125711.20651-8-piliu@redhat.com> In-Reply-To: <20240313125711.20651-1-piliu@redhat.com> References: <20240313125711.20651-1-piliu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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-20240313_125914_780594_6FAD3298 X-CRM114-Status: GOOD ( 10.49 ) 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 __create_pgd_mapping_locked() needs pgtable_alloc parameter to allocate memory for page table. During the early boot, the memory for page table should be allocated from init_idmap_pg_dir or init_pg_dir. This patch introduces routines to allocate PAGE from the above pool. Signed-off-by: Pingfan Liu Cc: Ard Biesheuvel Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland To: linux-arm-kernel@lists.infradead.org --- arch/arm64/mm/mmu_head.c | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/arch/arm64/mm/mmu_head.c b/arch/arm64/mm/mmu_head.c index 2df91e62ddb0..801ebffe4209 100644 --- a/arch/arm64/mm/mmu_head.c +++ b/arch/arm64/mm/mmu_head.c @@ -54,6 +54,8 @@ #include "mmu_inc.c" +phys_addr_t headpool_pgtable_alloc(int unused_shift); + void INSTRUMENT_OPTION mmu_head_create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys, unsigned long virt, phys_addr_t size, pgprot_t prot, @@ -86,3 +88,43 @@ void INSTRUMENT_OPTION mmu_head_create_pgd_mapping(pgd_t *pgdir, phys_addr_t phy } __create_pgd_mapping_locked(pgdir, phys, virt, size, prot, pgtable_alloc, flags); } + +struct headpool { + phys_addr_t start; + unsigned long size; + unsigned long next_idx; +} __aligned(8); + +struct headpool head_pool __initdata; + +void INSTRUMENT_OPTION headpool_init(phys_addr_t start, unsigned long size) +{ + struct headpool *pool; + + asm volatile( + "adrp %0, head_pool;" + "add %0, %0, #:lo12:head_pool;" + : "=r" (pool) + : + : + ); + pool->start = start; + pool->size = size; + pool->next_idx = 0; +} + +phys_addr_t INSTRUMENT_OPTION headpool_pgtable_alloc(int unused_shift) +{ + struct headpool *pool; + unsigned long idx; + + asm volatile( + "adrp %0, head_pool;" + "add %0, %0, #:lo12:head_pool;" + : "=r" (pool) + : + : + ); + idx = pool->next_idx++; + return pool->start + (idx << PAGE_SHIFT); +}