Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6774013rwr; Tue, 9 May 2023 22:05:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4s/93yhPU/zHzT3nm2VsW0sTeJU/6sWUWWiK+MW9AgQeB5o5DAtGGJoxgaOLK/hnEns5S6 X-Received: by 2002:a17:902:e852:b0:1a9:433e:41e7 with SMTP id t18-20020a170902e85200b001a9433e41e7mr12323345plg.43.1683695117905; Tue, 09 May 2023 22:05:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683695117; cv=none; d=google.com; s=arc-20160816; b=Nn11gjw3yuGY5/s4t1AVt976nuGcdFZQrJmHiVhHawi3gCtXAd7o9pwgqNeCgPYZQ0 oCwinqPBhrkBcxLPYCSX1tdDy+kEiGc6Vg0bD2LCLXGYQAlG+Mkv/VRmdjU4RIo0Tmuq 37c+76BK74joThLCPV/A/TzT35kVdSyDTQkMF4h/c1rIteG8p9wGuIMbNi86BTDINJ7J Uj5pHp2vkYjvm09KDtXgFb6fD3Wnx9nsrXPB1CkeUBLuzvmDGVv5kPbQOyPJcHigfwNA uVNF1PP31OqX64CizaDEoaTqUK3HpAIypoYGQWZwZeA7u2vFzUDjtebuzYviy/DtxB9H HZzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=9SgMoVTm6P3R+1xCqI0Wv3sobczW81YJURPfTY0JVMk=; b=aUajSOMs0WdtYNdi/T9DwAwzB0IBLOSDPTwC1m/QcqalZAvSwol8hTfW7jCjw5KvKL m5Q9aCVj4CJqNAk1I1b8DpsclotoFnd3/+sZZ9U2reBBVZAvWg1IPGQlP8ilgl42FqPV dbyh46uOeSmkPSP6qca6sT1F4wd2qlV6mBwBdyh6AbCaFGktt9UpddJ2Ttm3lj9cmdwE DpaQrK09/t+4oRvFiPVaa6yhOTIwilGID43yA0XwdEVfKSQwhny+1XvyIqe4ourISih8 QrRWo0aouSq2P+meI/4txDWKmttDqu6N/8dm11HD8LUam5cgp8c8UDw9tCtiiFbaOV0h zTQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=i6tseWUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a17090301c300b0019ca3bea310si3401714plh.303.2023.05.09.22.05.05; Tue, 09 May 2023 22:05:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=i6tseWUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235731AbjEJE5w (ORCPT + 99 others); Wed, 10 May 2023 00:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjEJE5u (ORCPT ); Wed, 10 May 2023 00:57:50 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 053201FD2 for ; Tue, 9 May 2023 21:57:49 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-b9e2b65d006so10156545276.3 for ; Tue, 09 May 2023 21:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683694668; x=1686286668; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=9SgMoVTm6P3R+1xCqI0Wv3sobczW81YJURPfTY0JVMk=; b=i6tseWUgvEolfXZtL5Oh35hld4r7UV7sxfAxp1Wi6J/AehneZgxtbpNMAbNVTBMmUI qj7UvqeEgFSQZ2qZW0AaYuuFH6wgQTMaPrP4VLoxCobR28SZjACKnu9c6qIW0PnqI4Hr Cld1tJ0wYqRvaAQ5bpmGPde8cyPQwKjxVNuL2CFu9bbXCawQw2nI4D6D+XCv12mgx2PV ij2tQ1g5xq9+W7BXEvJIwPrFkB6RWDWF/jzluSASWAsWg+TJDk0nuDAAmqQM+N4N23X5 wmyc1MG831sFfWvE1Fo8gZjKKd7Tp0yVdZJzwu/TKEXh0IxxU0wZHa09QO6ZhQjWluyJ QdrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683694668; x=1686286668; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9SgMoVTm6P3R+1xCqI0Wv3sobczW81YJURPfTY0JVMk=; b=C6CUbNZGDweOQWAgQgYNzfdPNtSpXnW/BH5BYfWGhCJUt77Wz3D9n7fj/UjTEHrXSL sCX33PNQKAt6aYQntaQvmQhGscTiAfYMH/MQ6pYI4C9hRUYINXCZ8ar4pFkmfS6SGmiK 2JNyjC269ZG6DWKfpdugzOSjbuerJdP424P7F8T/YcjorwSNCmS0rx3AJ3qlnKI/4JNz 7XvrTgTeFTu/zkgtRbXELz0vvb2m3T2nwgfAQg88g1KKPgWsvODPvD+r8WkGsZeKaw+7 KZqVwJRnwhRluYOkjf2mlaB6EjI1S+ng0H88Eg9VVwxwCfngdlBJQkYjzXowzZ23nqcc /djQ== X-Gm-Message-State: AC+VfDzSo0WzWB9vLOm2xkI4MO6OFEmDzYTLj7kOoMTEQ25kuNPePyNY tOYhVklOWVd39bOwNMXJ4QCxKg== X-Received: by 2002:a25:4d87:0:b0:b9d:5691:3ef6 with SMTP id a129-20020a254d87000000b00b9d56913ef6mr14812915ybb.27.1683694668013; Tue, 09 May 2023 21:57:48 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 23-20020a250d17000000b00b9e4a9b91b9sm3508848ybn.30.2023.05.09.21.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 21:57:47 -0700 (PDT) Date: Tue, 9 May 2023 21:57:44 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Greg Ungerer , Michal Simek , Thomas Bogendoerfer , Helge Deller , John David Anglin , "Aneesh Kumar K.V" , Michael Ellerman , Alexandre Ghiti , Palmer Dabbelt , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda , John Paul Adrian Glaubitz , "David S. Miller" , Chris Zankel , Max Filippov , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 12/23] powerpc: allow pte_offset_map[_lock]() to fail In-Reply-To: <77a5d8c-406b-7068-4f17-23b7ac53bc83@google.com> Message-ID: References: <77a5d8c-406b-7068-4f17-23b7ac53bc83@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In rare transient cases, not yet made possible, pte_offset_map() and pte_offset_map_lock() may not find a page table: handle appropriately. Balance successful pte_offset_map() with pte_unmap() where omitted. Signed-off-by: Hugh Dickins --- arch/powerpc/mm/book3s64/hash_tlb.c | 4 ++++ arch/powerpc/mm/book3s64/subpage_prot.c | 2 ++ arch/powerpc/xmon/xmon.c | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/hash_tlb.c b/arch/powerpc/mm/book3s64/hash_tlb.c index a64ea0a7ef96..21fcad97ae80 100644 --- a/arch/powerpc/mm/book3s64/hash_tlb.c +++ b/arch/powerpc/mm/book3s64/hash_tlb.c @@ -239,12 +239,16 @@ void flush_hash_table_pmd_range(struct mm_struct *mm, pmd_t *pmd, unsigned long local_irq_save(flags); arch_enter_lazy_mmu_mode(); start_pte = pte_offset_map(pmd, addr); + if (!start_pte) + goto out; for (pte = start_pte; pte < start_pte + PTRS_PER_PTE; pte++) { unsigned long pteval = pte_val(*pte); if (pteval & H_PAGE_HASHPTE) hpte_need_flush(mm, addr, pte, pteval, 0); addr += PAGE_SIZE; } + pte_unmap(start_pte); +out: arch_leave_lazy_mmu_mode(); local_irq_restore(flags); } diff --git a/arch/powerpc/mm/book3s64/subpage_prot.c b/arch/powerpc/mm/book3s64/subpage_prot.c index b75a9fb99599..0dc85556dec5 100644 --- a/arch/powerpc/mm/book3s64/subpage_prot.c +++ b/arch/powerpc/mm/book3s64/subpage_prot.c @@ -71,6 +71,8 @@ static void hpte_flush_range(struct mm_struct *mm, unsigned long addr, if (pmd_none(*pmd)) return; pte = pte_offset_map_lock(mm, pmd, addr, &ptl); + if (!pte) + return; arch_enter_lazy_mmu_mode(); for (; npages > 0; --npages) { pte_update(mm, addr, pte, 0, 0, 0); diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index 728d3c257e4a..69447bdf0bcf 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -3376,12 +3376,15 @@ static void show_pte(unsigned long addr) printf("pmdp @ 0x%px = 0x%016lx\n", pmdp, pmd_val(*pmdp)); ptep = pte_offset_map(pmdp, addr); - if (pte_none(*ptep)) { + if (!ptep || pte_none(*ptep)) { + if (ptep) + pte_unmap(ptep); printf("no valid PTE\n"); return; } format_pte(ptep, pte_val(*ptep)); + pte_unmap(ptep); sync(); __delay(200); -- 2.35.3