Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2792565rwd; Mon, 22 May 2023 04:34:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4YClqlg3zXtOZ0QKSk4tF/7vX2hIJXcKKqnGQ9ZmRgM+CgShyxC9YXcHzu1EvVzvnqJenW X-Received: by 2002:a17:902:efd3:b0:1ad:164:74ee with SMTP id ja19-20020a170902efd300b001ad016474eemr9883409plb.15.1684755278637; Mon, 22 May 2023 04:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684755278; cv=none; d=google.com; s=arc-20160816; b=Hu1EgJgW1OguKdw0gUDXpNrfEOwmXALXpGwEbGEDHzeTCwJYFEkuZrbv1ctYnhLZdo 6HM4+GX4QPKlMKQhKaeBIyeGxiOoc07wJUZDMtnJQx1KyXGz09bUujCCcLy7uWJ04U7f lAxQIBCUlFnF0atlmxgSd86mg6OV5E9Lr8uAQZd9fvV1Igw+8hOZhEwMkjStD9l1og5V Um6f2FfOYT7m9YC8diphPxrFAdyX1+74038zRSbjEI+KnS4q/D6uPlB6p/oPcrJcUj2x fDX8NSr8dNwQ4xVGCaihgySjAgqlPEPdiQO6vQSax398AZI+23JAeg2nntulrXlR+87R /iag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=3BNPsU4rNUqUjN43wlS41FKIQSqyrj6MltULGYMl8TA=; b=XyhnyBdze5uyA74+SWBr4C/YWN+0wW/POlyu9NLJ3kmYqgGXuHy+LkrrTkkLld75Kn Jc1D6Z1nS0L2Fd1pzebceD/kARFO8tPAE+wJO8fS48cveW5q+771XS7MvtqI8i8SkeY1 mdIkNCF9E254z7C3dCMcDvmInMx+keliiJkT/bEPjP+bmQB4JEnFRLVu8KrlOFLZWbAL DhIzWysAc/4cGIK1sHEdtZYETKSI/egvyZSRL8uh/ZrlXsuhAJjh3Z2Q2XX0HFJq8/Ea GgA6/C4RuEJPmAzOntJ1B9cmXGnW12txUFlbSpvKksDGxloSC1+e4r3w5Fofo88tmxO4 Z4bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=dkzcgRbs; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s19-20020a170902a51300b0019ec2a633f4si4255752plq.505.2023.05.22.04.34.26; Mon, 22 May 2023 04:34:38 -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=@linux.dev header.s=key1 header.b=dkzcgRbs; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233352AbjEVLZx (ORCPT + 99 others); Mon, 22 May 2023 07:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233634AbjEVLZU (ORCPT ); Mon, 22 May 2023 07:25:20 -0400 X-Greylist: delayed 14812 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 22 May 2023 04:22:34 PDT Received: from out-62.mta1.migadu.com (out-62.mta1.migadu.com [IPv6:2001:41d0:203:375::3e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94D7C212A for ; Mon, 22 May 2023 04:22:34 -0700 (PDT) Message-ID: <9dc72654-79db-e988-54a8-488550d235ac@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1684754244; 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=3BNPsU4rNUqUjN43wlS41FKIQSqyrj6MltULGYMl8TA=; b=dkzcgRbsbeMyA8WuRNLFxGPf+kefcNrXeWfOoPgOxGVvRYK/kTHZvSS2JE+w2quBdOzMr0 e5sSlGZgGRFN8iE5U3L7qkVTBaJFJnFZf+soYncMIncoNch7colJt7oyjKHuFT/KmYxDNW VN5qJGHn6LMvUSikM0IlvbDC1uY4BN0= Date: Mon, 22 May 2023 19:17:11 +0800 MIME-Version: 1.0 Subject: Re: [PATCH 04/31] mm/pgtable: allow pte_offset_map[_lock]() to fail Content-Language: en-US To: Hugh Dickins , Andrew Morton Cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> <8218ffdc-8be-54e5-0a8-83f5542af283@google.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Qi Zheng In-Reply-To: <8218ffdc-8be-54e5-0a8-83f5542af283@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Hi Hugh, On 2023/5/22 12:53, Hugh Dickins wrote: [...] > > @@ -229,3 +231,57 @@ pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address, > } > #endif > #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > + > +pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp) > +{ > + pmd_t pmdval; > + > + /* rcu_read_lock() to be added later */ > + pmdval = pmdp_get_lockless(pmd); > + if (pmdvalp) > + *pmdvalp = pmdval; > + if (unlikely(pmd_none(pmdval) || is_pmd_migration_entry(pmdval))) > + goto nomap; > + if (unlikely(pmd_trans_huge(pmdval) || pmd_devmap(pmdval))) > + goto nomap; Will the follow-up patch deal with the above situation specially? Otherwise, maybe it can be changed to the following check method? if (unlikely(pmd_none(pmdval) || pmd_leaf(pmdval))) goto nomap; > + if (unlikely(pmd_bad(pmdval))) { > + pmd_clear_bad(pmd); > + goto nomap; > + } > + return __pte_map(&pmdval, addr); > +nomap: > + /* rcu_read_unlock() to be added later */ > + return NULL; > +} > + > +pte_t *pte_offset_map_nolock(struct mm_struct *mm, pmd_t *pmd, > + unsigned long addr, spinlock_t **ptlp) > +{ > + pmd_t pmdval; > + pte_t *pte; > + > + pte = __pte_offset_map(pmd, addr, &pmdval); > + if (likely(pte)) > + *ptlp = pte_lockptr(mm, &pmdval); > + return pte; > +} > + > +pte_t *__pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd, > + unsigned long addr, spinlock_t **ptlp) > +{ > + spinlock_t *ptl; > + pmd_t pmdval; > + pte_t *pte; > +again: > + pte = __pte_offset_map(pmd, addr, &pmdval); > + if (unlikely(!pte)) > + return pte; > + ptl = pte_lockptr(mm, &pmdval); > + spin_lock(ptl); > + if (likely(pmd_same(pmdval, pmdp_get_lockless(pmd)))) { > + *ptlp = ptl; > + return pte; > + } > + pte_unmap_unlock(pte, ptl); > + goto again; > +} -- Thanks, Qi