From patchwork Wed May 10 04:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13236318 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 1B5D6C77B7C for ; Wed, 10 May 2023 04:42:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C35A6B0071; Wed, 10 May 2023 00:42:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 373136B0072; Wed, 10 May 2023 00:42:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2132B6B0074; Wed, 10 May 2023 00:42:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 112196B0071 for ; Wed, 10 May 2023 00:42:58 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D0DAB120455 for ; Wed, 10 May 2023 04:42:57 +0000 (UTC) X-FDA: 80773100394.28.A9ABA9F Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf10.hostedemail.com (Postfix) with ESMTP id 10D52C0008 for ; Wed, 10 May 2023 04:42:55 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ATuPznBP; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683693776; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1YvWeTkG3kfP7WDkFLxY3Kk7w85fUEyISH4lFagFGGw=; b=3JX1FpvyES7EcRdMa2LTZg48facKu+cmcsldQrPKmgjjKx76cHomm7wUsoAA2p8HCeWaxe vavmZ9p8XarerV9O+TCh/ciIgjJ9+CkTCVAhzBfjBF7G9OKGfeWI9788gBR0BcY1TtKf/A guScOHWeo1HfpwuFJhzbcKF+8hv3KBM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ATuPznBP; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683693776; a=rsa-sha256; cv=none; b=weUgIFX+iTMUPfvYGcqf2trHGzFAetfNkPkdg43Mame4Smxi6GpMqDqIaOHCEtbWb9LH76 K54QiYiWQM/pbP/cYYDJlf3367SXPv3CLTYMyKhtGFGaUoxcAI4wBu2LjuCAHS8kuhgJSH RnctYN+FtmkED5WpS8NiEz7Ce0Tfx78= Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-b9a879cd49cso8811486276.0 for ; Tue, 09 May 2023 21:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683693775; x=1686285775; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=1YvWeTkG3kfP7WDkFLxY3Kk7w85fUEyISH4lFagFGGw=; b=ATuPznBP6lohY0dnWFYXaaNOQNunJEFtD7eF3OFa8KJJUXbFYwyofisXF7mtL2ymFH oTBz56agCcLhFx8YonoqBW6ZmAtrhlvPrmdJAcSpRqyP2mLR5Z/WoSQhVEg2s8MVqDuy Ip95cEIMx73t6Gdt8YSQEVRJTa89FntSD+Di4V6VUK9+4KRIMxTr8+RCmD6ANZu4Rjel BJF/aQ9/sAdSWOQreL897UcsYcMJJWTONr2aX5YmKG/bIAxUtAEn1GX4Jh5f4y/r990Z htjctO7o35ZbKLLksPTYN1h3aK5mSo9ZrVIIV1mS/G/Fv32O9W6ivMXImV5mGNDY0z+m 21CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683693775; x=1686285775; 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=1YvWeTkG3kfP7WDkFLxY3Kk7w85fUEyISH4lFagFGGw=; b=S0cZx1ZVvbGztGhwmw35er76b5qiowQ6B9SME/p6bLFqQYq6kmXWmS+25Th/zVbnKu dTlMzrEw7uE+9f3oMNHalIXZNV5L+m8IhAEX0hE6UKQ3Fy09Jzj9pPmqtlE+KY/WBBpV wEDvXFldZUWzmpuNXJrL9Uaxm/VWhRwzE6wh+ZVuLITXnFeamCDsn3CUgvFAwyChZu5u iCklJ952iOHf4YJ28vLDdKSoyaEDCjDkuKVCjWKomvjn3To6Qcz3wr2TOfpMebPeqgm4 Dgg5voIIRlbfcJKi76/8lqBfmfCp3eCB6yoD/RJs9UvzWcYt5YbCYQeUGsGoqpedSLq9 wMNQ== X-Gm-Message-State: AC+VfDwX5VBBhddgscTw2ZWh+kOVyoPKBoxoXposSzzffMaobj7gFyQe SNDwlfFOnVyOr4KoYROv2CXd9w== X-Google-Smtp-Source: ACHHUZ7fYX2z0RAKmyNqdeM/8QuAhHW9rcUGOaUpv5crEQfaAc/gCUyRWpV2+01J2c8XG3m8+G8szg== X-Received: by 2002:a25:ad98:0:b0:b9d:a8fa:fd6d with SMTP id z24-20020a25ad98000000b00b9da8fafd6dmr17660831ybi.12.1683693775053; Tue, 09 May 2023 21:42:55 -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 x4-20020a056902102400b00b9def138173sm3425234ybt.1.2023.05.09.21.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 21:42:54 -0700 (PDT) Date: Tue, 9 May 2023 21:42: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 01/23] arm: allow pte_offset_map[_lock]() to fail In-Reply-To: <77a5d8c-406b-7068-4f17-23b7ac53bc83@google.com> Message-ID: <5011977-d876-6a24-a3fc-c7e6a02877b8@google.com> References: <77a5d8c-406b-7068-4f17-23b7ac53bc83@google.com> MIME-Version: 1.0 X-Stat-Signature: 94fuhhc44dm6rgfx85sk1rg3fef3szwi X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 10D52C0008 X-Rspam-User: X-HE-Tag: 1683693775-342448 X-HE-Meta: U2FsdGVkX18VMJ143ST2tQ7O3Oqi2KhCPElrbT8dloi1W4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/PKyardoDAdBcGhnqLSAdh4w+TJ0ijKv8ED6Em6E5V6pmApK7NGpB1Z3Xkofsu2xMxk6Qy6RnDv2vW9SclgSYLPKtfwdRGNlBEyxKIgRvUymgRcB1uXxYGYbkwlrpfkKbnzGVb+UAifybVdd5SvL3jOOBQomVMYLRDLY56mRcErhfb6Ij040wjezgdwNinG0myoAnb/z2FYAsRPFhOZYbCU8LywOLTzDydaFI6UyxqXRHHLibWQL43fyV5Yt37t7yje5WoMwqSB2G6B35T2gb6FEWjLAGLvw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In rare transient cases, not yet made possible, pte_offset_map() and pte_offset_map_lock() may not find a page table: handle appropriately. Signed-off-by: Hugh Dickins --- arch/arm/lib/uaccess_with_memcpy.c | 3 +++ arch/arm/mm/fault-armv.c | 5 ++++- arch/arm/mm/fault.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c index e4c2677cc1e9..2f6163f05e93 100644 --- a/arch/arm/lib/uaccess_with_memcpy.c +++ b/arch/arm/lib/uaccess_with_memcpy.c @@ -74,6 +74,9 @@ pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp) return 0; pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl); + if (unlikely(!pte)) + return 0; + if (unlikely(!pte_present(*pte) || !pte_young(*pte) || !pte_write(*pte) || !pte_dirty(*pte))) { pte_unmap_unlock(pte, ptl); diff --git a/arch/arm/mm/fault-armv.c b/arch/arm/mm/fault-armv.c index 0e49154454a6..ca5302b0b7ee 100644 --- a/arch/arm/mm/fault-armv.c +++ b/arch/arm/mm/fault-armv.c @@ -117,8 +117,11 @@ static int adjust_pte(struct vm_area_struct *vma, unsigned long address, * must use the nested version. This also means we need to * open-code the spin-locking. */ - ptl = pte_lockptr(vma->vm_mm, pmd); pte = pte_offset_map(pmd, address); + if (!pte) + return 0; + + ptl = pte_lockptr(vma->vm_mm, pmd); do_pte_lock(ptl); ret = do_adjust_pte(vma, address, pfn, pte); diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 2418f1efabd8..83598649a094 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -85,6 +85,9 @@ void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr) break; pte = pte_offset_map(pmd, addr); + if (!pte) + break; + pr_cont(", *pte=%08llx", (long long)pte_val(*pte)); #ifndef CONFIG_ARM_LPAE pr_cont(", *ppte=%08llx",