From patchwork Sun Apr 25 14:13:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12223337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84747C433ED for ; Sun, 25 Apr 2021 14:16:56 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18F46600EF for ; Sun, 25 Apr 2021 14:16:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18F46600EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=fhcXQX9ApKBmSGaWYPQVSs5GGdRH5Y0txJxFeqpxm0s=; b=OaXbxOLpOU/u5rUGtt1RXqXNE 2GPOpqdyzjFjGWfCmnXuxYG0chV8EzuuG3tmGr5NqPICpAUBujBkna7cKDsopFU0OIqQwpyeWTy/c vBic0PVMek5K/dS89kPvQMHSggl0+LltZWVeUuQskY+G1jXzFqmmSuKuGZMvgUfwlE2etzH6boXD5 +5pRVorofRZSDmpwX0Or3ZLJ8C9CSP5kVnSSa1EkOm88G9QONzeVMH21RaVEHF+UQ7rRDJAjwDxeN HM4XK/pl3zchK38EWSA9fJkPbzKeO90Wi/YHAlZARQFJEeheH0fYCA0gJM0niHr0iQY2Cs7O0Eywj yDRyVztag==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lafXc-005ieU-MW; Sun, 25 Apr 2021 14:15:20 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lafWZ-005iKA-V0 for linux-arm-kernel@desiato.infradead.org; Sun, 25 Apr 2021 14:14:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=vt5vkYYlE+SDTKBQiglJcgWctT1ZgrBGHis8MwF7xGs=; b=RyPDmGArpnjklTi6Gsf+U4OwcT bfUIDmY8pvxL/u/aj/z2GD2Y5UUUpPs5YoKQWmixra2F0rifp3szdclVI0xiFhJIgAKnTxJa+JS70 JqaoAB+URZtn3Tbs+MKWz6XAFjbPyjxAI9xHcOyukKWwI+7xvDytp6Z3/Ykv5q7CeLN4n+H0+7Fad syywP6VsugLXkSjOPMDtfhgaCtswbtW9fZCxE+mBHZJGHH1HWwKQtIYoiJinN9u1E/xFa6ejjcVIS aRb7PuIwqHSw65NZb9DSFlOLsZP8EOjC+O5ffd/YoQrTE9zGEFRnzneJXk0kd7Y2WW0D5BvpSnPD0 Q00dGbwg==; Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lafWX-00FT6V-9r for linux-arm-kernel@lists.infradead.org; Sun, 25 Apr 2021 14:14:14 +0000 Received: by mail-pg1-x529.google.com with SMTP id p12so38387019pgj.10 for ; Sun, 25 Apr 2021 07:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vt5vkYYlE+SDTKBQiglJcgWctT1ZgrBGHis8MwF7xGs=; b=ZGW4dxTLR1ywkEZMm3pGUTPepv3RRxKUm+iGtdx+JtB1Glm58Ig1bLt+OKi2PtAz+C SPzje4pptubUnH+AJc3tMvypN/B0Z9gegfUy1vMJddR7KN/AA4wiHfOl45O91c6eXK4q 8ViY5qkwjnFRczFxokV88W2lhcor/LXKRy46KqX8WBPI3/vVzLSrsM8IlD//79zEptca 7+ZD6R/C/bxL3JvkLkgN+e7k1cluupo16SS9fyp5boVGm91g9bnRblsOetRb24nOvZTg KdRnsUWmFssVEVcg89L6en6STdGBSQ0/IOxRlB3fkoTL0U8SWWhnDleyV/U/7e3H1zDy uUUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vt5vkYYlE+SDTKBQiglJcgWctT1ZgrBGHis8MwF7xGs=; b=CS65F6MxL20sybBxsKHjyu8wod0GXh+tez9sUOfNeeBEOrDtFdaCo6jBA2I82+GnhV ZUJLxmT5FnulP4R6Mzbez25bJpUVPlUFWWR3KJebsR6VEwRhCU6wZWnRYcDJpL7XIrD4 eNMNfIObnTj60CJo0VYe3r/YZAE4Mrh2RKsNkNzRNSV0+RRd59RP3Brn5NG7rhqT6A+L peGWqHrBZziLANdbFXx01ZhlgnefkNwTgcVHHtX79ZOB9fhQVS5PG/0kAQM11+Nm5+IB EZRkHwvw2Qvon6fk6Ww6EpGtOUDTP2sGQRUkDQxw0XItFNE3TLhtNUbAnDj4oGZYeOHD ldgg== X-Gm-Message-State: AOAM5322MdG6gQ4tOnnvkq4liENRXgKRqcxdy/3pPD+oIQGtpnFRwXES t6glGNrQ62Iv9bkWDYW+mofTIiyruA== X-Google-Smtp-Source: ABdhPJyRPFhgVJrpUb1hCADgLT8SRG6NynC0DHa2xotzRW73zU1/q5ugApElxtmKttYEOCX69dkADw== X-Received: by 2002:a63:b515:: with SMTP id y21mr12788026pge.253.1619360052320; Sun, 25 Apr 2021 07:14:12 -0700 (PDT) Received: from x1pad.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r32sm1007139pgm.49.2021.04.25.07.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 07:14:11 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Marc Zyngier , Kristina Martsenko , James Morse , Steven Price , Jonathan Cameron , Pavel Tatashin , Anshuman Khandual , Atish Patra , Mike Rapoport , Logan Gunthorpe , Mark Brown Subject: [PATCHv2 08/10] arm64/mmu_include.c: disable WARN_ON() and BUG_ON() when booting. Date: Sun, 25 Apr 2021 22:13:02 +0800 Message-Id: <20210425141304.32721-9-kernelfans@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210425141304.32721-1-kernelfans@gmail.com> References: <20210425141304.32721-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210425_071413_365018_C94EA7BE X-CRM114-Status: GOOD ( 16.82 ) 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 This patch is still one of the preparation for calling __create_pgd_mapping() from head.S When calling from head.S, printk is not ready to work. Hence define SAFE_BUG_ON()/SAFE_WARN_ON(), wrapping around BUG_ON()/WARN_ON() to protect against early calling. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Marc Zyngier Cc: Kristina Martsenko Cc: James Morse Cc: Steven Price Cc: Jonathan Cameron Cc: Pavel Tatashin Cc: Anshuman Khandual Cc: Atish Patra Cc: Mike Rapoport Cc: Logan Gunthorpe Cc: Mark Brown To: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/pgalloc.h | 1 + arch/arm64/mm/mmu_include.c | 36 +++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 8e6638b4d1dd..c3875af99432 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -105,5 +105,6 @@ extern void create_idmap(pgd_t *pgdir, phys_addr_t phys, #define NO_BLOCK_MAPPINGS BIT(0) #define NO_CONT_MAPPINGS BIT(1) #define NO_FIXMAP BIT(2) +#define BOOT_HEAD BIT(3) #endif diff --git a/arch/arm64/mm/mmu_include.c b/arch/arm64/mm/mmu_include.c index 98c560197ea9..746cb2b502a3 100644 --- a/arch/arm64/mm/mmu_include.c +++ b/arch/arm64/mm/mmu_include.c @@ -5,6 +5,14 @@ * and MMU-enable */ +/* + * printk is not ready in the very early stage. And this pair macro should be used + * instead + */ +#define SAFE_BUG_ON(x, y) if (likely(!(x & BOOT_HEAD))) { BUG_ON(y); } +#define SAFE_WARN_ON(x, y) \ + ({ int _ret; _ret = (x & BOOT_HEAD) ? false : WARN_ON(y); }) + static bool pgattr_change_is_safe(u64 old, u64 new) { /* @@ -57,7 +65,7 @@ static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end, * After the PTE entry has been populated once, we * only allow updates to the permission attributes. */ - BUG_ON(!pgattr_change_is_safe(pte_val(old_pte), + SAFE_BUG_ON(flags, !pgattr_change_is_safe(pte_val(old_pte), READ_ONCE(pte_val(*ptep)))); phys += PAGE_SIZE; @@ -77,16 +85,16 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, unsigned long next; pmd_t pmd = READ_ONCE(*pmdp); - BUG_ON(pmd_sect(pmd)); + SAFE_BUG_ON(flags, pmd_sect(pmd)); if (pmd_none(pmd)) { phys_addr_t pte_phys; - BUG_ON(!allocator); + SAFE_BUG_ON(flags, !allocator); pte_phys = allocator(PAGE_SHIFT, info); __pmd_populate(pmdp, pte_phys, PMD_TYPE_TABLE); pmd = READ_ONCE(*pmdp); } - BUG_ON(pmd_bad(pmd)); + SAFE_BUG_ON(flags, pmd_bad(pmd)); do { pgprot_t __prot = prot; @@ -131,13 +139,13 @@ static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end, * After the PMD entry has been populated once, we * only allow updates to the permission attributes. */ - BUG_ON(!pgattr_change_is_safe(pmd_val(old_pmd), + SAFE_BUG_ON(flags, !pgattr_change_is_safe(pmd_val(old_pmd), READ_ONCE(pmd_val(*pmdp)))); } else { alloc_init_cont_pte(pmdp, addr, next, phys, prot, allocator, info, flags); - BUG_ON(pmd_val(old_pmd) != 0 && + SAFE_BUG_ON(flags, pmd_val(old_pmd) != 0 && pmd_val(old_pmd) != READ_ONCE(pmd_val(*pmdp))); } phys += next - addr; @@ -160,16 +168,16 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, /* * Check for initial section mappings in the pgd/pud. */ - BUG_ON(pud_sect(pud)); + SAFE_BUG_ON(flags, pud_sect(pud)); if (pud_none(pud)) { phys_addr_t pmd_phys; - BUG_ON(!allocator); + SAFE_BUG_ON(flags, !allocator); pmd_phys = allocator(PMD_SHIFT, info); __pud_populate(pudp, pmd_phys, PUD_TYPE_TABLE); pud = READ_ONCE(*pudp); } - BUG_ON(pud_bad(pud)); + SAFE_BUG_ON(flags, pud_bad(pud)); do { pgprot_t __prot = prot; @@ -213,12 +221,12 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, if (p4d_none(p4d)) { phys_addr_t pud_phys; - BUG_ON(!allocator); + SAFE_BUG_ON(flags, !allocator); pud_phys = allocator(PUD_SHIFT, info); __p4d_populate(p4dp, pud_phys, PUD_TYPE_TABLE); p4d = READ_ONCE(*p4dp); } - BUG_ON(p4d_bad(p4d)); + SAFE_BUG_ON(flags, p4d_bad(p4d)); if (likely(!(flags & NO_FIXMAP))) pudp = pud_set_fixmap_offset(p4dp, addr); @@ -240,13 +248,13 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, * After the PUD entry has been populated once, we * only allow updates to the permission attributes. */ - BUG_ON(!pgattr_change_is_safe(pud_val(old_pud), + SAFE_BUG_ON(flags, !pgattr_change_is_safe(pud_val(old_pud), READ_ONCE(pud_val(*pudp)))); } else { alloc_init_cont_pmd(pudp, addr, next, phys, prot, allocator, info, flags); - BUG_ON(pud_val(old_pud) != 0 && + SAFE_BUG_ON(flags, pud_val(old_pud) != 0 && pud_val(old_pud) != READ_ONCE(pud_val(*pudp))); } phys += next - addr; @@ -275,7 +283,7 @@ static void __create_pgd_mapping(pgd_t *pgdir, unsigned int entries_cnt, phys_ad * If the virtual and physical address don't have the same offset * within a page, we cannot map the region as the caller expects. */ - if (WARN_ON((phys ^ virt) & ~PAGE_MASK)) + if (SAFE_WARN_ON(flags, (phys ^ virt) & ~PAGE_MASK)) return; phys &= PAGE_MASK;