Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1092602rwd; Tue, 13 Jun 2023 04:57:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48tJzgvZbMI+Iqf4ffoiZMs8aZqGB2n+Le32A8eUkm7sDKCBBKk2vcjT0uyK/dwJnAM7Vl X-Received: by 2002:a17:907:e8b:b0:973:da59:7c76 with SMTP id ho11-20020a1709070e8b00b00973da597c76mr10648778ejc.56.1686657460874; Tue, 13 Jun 2023 04:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686657460; cv=none; d=google.com; s=arc-20160816; b=fMNGqRn5Ki8C+ZwHNyvpe15X+tO/aBfSna6bt9qeVfEyUYX+UBplBMi4KEc+wmDLMd rfR6ELm83TrWu1+cApdwCNVQy3PGcGgsHV8ElzGhKuGycNrM+ZCY7k8dlLervOGD6HKy 6RVozKnAdWODk2q/qGcujKPPU01TgSbTU0FiYIWGPBlcoU2O5Q0LXAhi0DGR0W4U0NyM Rw25a6qyN792QQpm6HcQjNXk23uehvICuuriyRW1kafOWlbdCOcpDZ5Ef33hXp15+Usg BGNaw0/RLa7L5Lbr1U1ZFXJAy+5S1a9ijk5DiFznQWzvz4pqr5Mru0Psvo6twsd+1Ebg CNCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=YW8dFle4FwBo/xSGfxj/YlaloUxuRpkH0geiv0yOSDw=; b=QcDh9upZ4lRiAeFuQnkV8Ukae5UNDYKUYGB3lG1BdZXicsJtM1TZr1NC42ccoIntLo R8V65OKE4MEaiNfgwXRk4mjvKZIyWYNm7gZYT+SOdbexUmqqiIhP+aZNvnTf0tK31xyn jaaEWdQ20AeF2QaC1ilsMtFRKWe7xjlncn1zKk6flKGolGDz0WmbaRcsa1lsj6HZVP+i TsN5TffQ/pzOsG5gBI7PU8OHxC4H9NCLzaVJrIZIwSt2uwEgrWtdjE6YdIXqMckH7TqW uM40uXndShU2+uKSdkPusHeBeKXA28uXoPwE8LRMOsK0SNVUiX1AsZ+BaYPMnLA/vdTP 8aUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=T5i9ZjoL; 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=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r26-20020a1709067fda00b009764ec2c5cbsi7405414ejs.886.2023.06.13.04.57.15; Tue, 13 Jun 2023 04:57:40 -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=@ibm.com header.s=pp1 header.b=T5i9ZjoL; 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=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240695AbjFMLr4 (ORCPT + 99 others); Tue, 13 Jun 2023 07:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235301AbjFMLry (ORCPT ); Tue, 13 Jun 2023 07:47:54 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CE56E47; Tue, 13 Jun 2023 04:47:53 -0700 (PDT) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35DBHqbe019547; Tue, 13 Jun 2023 11:46:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=YW8dFle4FwBo/xSGfxj/YlaloUxuRpkH0geiv0yOSDw=; b=T5i9ZjoLCtD5qW5i8NKsB6igZlD7dMJC6lq2OsnNDPy7oI/IJwCWRx4SPn5FJJpROxmM XGoOjoVssuM9/IjC8/J3XlUqvCz3C3iOZBKCzWeoF0IhoZ+avSBdbwNZr59eAY+Y/MwT m2mG+QlqXNAIO2Pu40I08q6zflwJsJOVsijb4rqfpucHx1YhsAfZE7071II3obN8oK0Q NnZiT60lRymQXLae3bIOY+/57zmLGsf/tJ23yvopK4qH2zkFEV55XJ0NU4UIbN/4AKyx fHREytSGkFNXaEKXdBvC+qFh/1F0GU1+NwGoF/v4zbQshn2s5Y75imb05ioVeOAk3wU9 uA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r6qey0j7t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 11:46:25 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35DBbbht032708; Tue, 13 Jun 2023 11:46:24 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r6qey0j6c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 11:46:24 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35D3i4Ui022712; Tue, 13 Jun 2023 11:45:14 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3r4gt523ws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 11:45:14 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35DBjA1w19399178 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Jun 2023 11:45:11 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC35620043; Tue, 13 Jun 2023 11:45:10 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D6D1F20040; Tue, 13 Jun 2023 11:45:09 +0000 (GMT) Received: from p-imbrenda (unknown [9.152.224.66]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 13 Jun 2023 11:45:09 +0000 (GMT) Date: Tue, 13 Jun 2023 13:45:08 +0200 From: Claudio Imbrenda To: Hugh Dickins Cc: Andrew Morton , Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Peter Zijlstra , 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 , Alexander Gordeev , 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: Re: [PATCH v2 15/23] s390: allow pte_offset_map_lock() to fail Message-ID: <20230613134508.6018e70c@p-imbrenda> In-Reply-To: <3ff29363-336a-9733-12a1-5c31a45c8aeb@google.com> References: <3ff29363-336a-9733-12a1-5c31a45c8aeb@google.com> Organization: IBM X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: NSzf1M38pnx2z8GhXfyd2zkrTyue7I-U X-Proofpoint-ORIG-GUID: Jl-BWVCZvUKcympIO9JuW2YKR9vYO4UE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 clxscore=1011 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130102 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Thu, 8 Jun 2023 12:27:22 -0700 (PDT) Hugh Dickins wrote: > In rare transient cases, not yet made possible, pte_offset_map() and > pte_offset_map_lock() may not find a page table: handle appropriately. > > Add comment on mm's contract with s390 above __zap_zero_pages(), > and fix old comment there: must be called after THP was disabled. > > Signed-off-by: Hugh Dickins Acked-by: Claudio Imbrenda > --- > arch/s390/kernel/uv.c | 2 ++ > arch/s390/mm/gmap.c | 9 ++++++++- > arch/s390/mm/pgtable.c | 12 +++++++++--- > 3 files changed, 19 insertions(+), 4 deletions(-) > > diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c > index cb2ee06df286..3c62d1b218b1 100644 > --- a/arch/s390/kernel/uv.c > +++ b/arch/s390/kernel/uv.c > @@ -294,6 +294,8 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) > > rc = -ENXIO; > ptep = get_locked_pte(gmap->mm, uaddr, &ptelock); > + if (!ptep) > + goto out; > if (pte_present(*ptep) && !(pte_val(*ptep) & _PAGE_INVALID) && pte_write(*ptep)) { > page = pte_page(*ptep); > rc = -EAGAIN; > diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c > index dc90d1eb0d55..3a2a31a15ea8 100644 > --- a/arch/s390/mm/gmap.c > +++ b/arch/s390/mm/gmap.c > @@ -2537,7 +2537,12 @@ static inline void thp_split_mm(struct mm_struct *mm) > * Remove all empty zero pages from the mapping for lazy refaulting > * - This must be called after mm->context.has_pgste is set, to avoid > * future creation of zero pages > - * - This must be called after THP was enabled > + * - This must be called after THP was disabled. > + * > + * mm contracts with s390, that even if mm were to remove a page table, > + * racing with the loop below and so causing pte_offset_map_lock() to fail, > + * it will never insert a page table containing empty zero pages once > + * mm_forbids_zeropage(mm) i.e. mm->context.has_pgste is set. > */ > static int __zap_zero_pages(pmd_t *pmd, unsigned long start, > unsigned long end, struct mm_walk *walk) > @@ -2549,6 +2554,8 @@ static int __zap_zero_pages(pmd_t *pmd, unsigned long start, > spinlock_t *ptl; > > ptep = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); > + if (!ptep) > + break; > if (is_zero_pfn(pte_pfn(*ptep))) > ptep_xchg_direct(walk->mm, addr, ptep, __pte(_PAGE_INVALID)); > pte_unmap_unlock(ptep, ptl); > diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c > index 6effb24de6d9..3bd2ab2a9a34 100644 > --- a/arch/s390/mm/pgtable.c > +++ b/arch/s390/mm/pgtable.c > @@ -829,7 +829,7 @@ int set_guest_storage_key(struct mm_struct *mm, unsigned long addr, > default: > return -EFAULT; > } > - > +again: > ptl = pmd_lock(mm, pmdp); > if (!pmd_present(*pmdp)) { > spin_unlock(ptl); > @@ -850,6 +850,8 @@ int set_guest_storage_key(struct mm_struct *mm, unsigned long addr, > spin_unlock(ptl); > > ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); > + if (!ptep) > + goto again; > new = old = pgste_get_lock(ptep); > pgste_val(new) &= ~(PGSTE_GR_BIT | PGSTE_GC_BIT | > PGSTE_ACC_BITS | PGSTE_FP_BIT); > @@ -938,7 +940,7 @@ int reset_guest_reference_bit(struct mm_struct *mm, unsigned long addr) > default: > return -EFAULT; > } > - > +again: > ptl = pmd_lock(mm, pmdp); > if (!pmd_present(*pmdp)) { > spin_unlock(ptl); > @@ -955,6 +957,8 @@ int reset_guest_reference_bit(struct mm_struct *mm, unsigned long addr) > spin_unlock(ptl); > > ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); > + if (!ptep) > + goto again; > new = old = pgste_get_lock(ptep); > /* Reset guest reference bit only */ > pgste_val(new) &= ~PGSTE_GR_BIT; > @@ -1000,7 +1004,7 @@ int get_guest_storage_key(struct mm_struct *mm, unsigned long addr, > default: > return -EFAULT; > } > - > +again: > ptl = pmd_lock(mm, pmdp); > if (!pmd_present(*pmdp)) { > spin_unlock(ptl); > @@ -1017,6 +1021,8 @@ int get_guest_storage_key(struct mm_struct *mm, unsigned long addr, > spin_unlock(ptl); > > ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); > + if (!ptep) > + goto again; > pgste = pgste_get_lock(ptep); > *key = (pgste_val(pgste) & (PGSTE_ACC_BITS | PGSTE_FP_BIT)) >> 56; > paddr = pte_val(*ptep) & PAGE_MASK;