Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5161229rwd; Tue, 23 May 2023 19:45:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5yj21UQndLX0a+Igt6p4Nef/6aNmOFnncOn2OAuOqgwOK25tED/WxmKcm9qRloWXD28BfB X-Received: by 2002:a17:902:cec2:b0:1af:cdd9:e970 with SMTP id d2-20020a170902cec200b001afcdd9e970mr4130365plg.12.1684896351666; Tue, 23 May 2023 19:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684896351; cv=none; d=google.com; s=arc-20160816; b=Qiz1hUb9a27LYfqFUAaLp3zeG/SawMKd6m3j0fBaHyIuGaOlrYlbB2q2J99QEJvrv0 LZ3UgW2JfN1OlmQh+SMvzsxum8UQcfNy9pFmoCj+5/twx9DtyCMQOCfDLV35VRT9UuC1 cT0oF9yoePIPbmwl8nhKLpPSSMjsafqe25pkGZvjUxmZtut8qrLpZzCSRdKXObuS4IzM hbxzxSuOW1ACPd+zlaFEj8kwGBOkbSzN6qwsu05CfKxbJHpIjcPw+XAeYgXcIjWcOhT8 d82OxfTbphLpX3464kgNVv3NASctr4Z68kPHGIsNPTzWKeRfvBd6k3T7sv98K+x4Bdgc 4B/A== 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=dNoZFE15KVCGaDsKWYPa3AXU3xXgJ31/Z6hKlwSh2kQ=; b=HJbQcPphs+IJPp5VgK63njzPEgOwYBjbQDb/ROtz+WwuKhIDp7dlrt8V/HdW9Zsvdy ao+3vL3P5GMUuW8NkGeaoDSevlW3JsVmjTDPoxf8rXnombSF1jqsNspdEu9o9tj77OjX Rnq9K3yqr9DhPjlpGgidHM4FLjjcYjeq8msdEAceYqf3whnvhgFJS0XRS3+o9t47Gv42 Y0FjhmP5hIxWbwTRMNUyM0b9LFU6xiuU8UIul77opbKeYhNPUr2ahf9JSZXduRL8EbN9 hsIJs1XClkcDf8uM3tiC+S6Mq5q0pFVYAImzOAnyKrLYPFAhlX1i5CV7K6BZQSSPa6lp 9j2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=CYHuBQt4; 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 b5-20020a170902e94500b0019f33c0d583si2874907pll.315.2023.05.23.19.45.36; Tue, 23 May 2023 19:45:51 -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=CYHuBQt4; 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 S239114AbjEXCWg (ORCPT + 99 others); Tue, 23 May 2023 22:22:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbjEXCWd (ORCPT ); Tue, 23 May 2023 22:22:33 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7C74CD for ; Tue, 23 May 2023 19:22:32 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-56190515833so9635067b3.0 for ; Tue, 23 May 2023 19:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684894952; x=1687486952; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=dNoZFE15KVCGaDsKWYPa3AXU3xXgJ31/Z6hKlwSh2kQ=; b=CYHuBQt4sNY1VOu7Oe2TF9KvZ6A5MpM3eHBJ3Hfajar8vhIXv3EieQ7KdHlCEj4hBN xRxLPqXXyAVpvGoVZxqv9xRQBK07xF7CxPJnjWwZ1P9UU1jnUYnZl/H+yd4O+yWjScr+ 6f8lLLMPEGj7tc+dNVo35Pgu1j9pjhH1eB2mjv0A2KNN5OosxpXlvr1W8iy5i6riCr1s uZDAZz29t0+rDczY3vYUYMp17f9D0nCVLUQl7f/+4Xq0bJGKkpLfU1xgGu21qcak1VEq X8U2GUv2hE+I0vwadhlJKWzJoI/QEtZ7MyP56j1xnS1Jpxnw4CsYGfk84Q8jhOJjNKpw 0YUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684894952; x=1687486952; 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=dNoZFE15KVCGaDsKWYPa3AXU3xXgJ31/Z6hKlwSh2kQ=; b=W4XyQ9VCm8Nkk0dW7MncSkGkYuOz0WH/GHSUPKrvXm6yIdCdfTGwd5baUE6DtwXGxY PgzEH1eQ//0LEYz6ox2HiBAj/QrzDLl+tbRxVvXac7DR2s8B2RZUiJelnF62dyTukKTd PTM6kt4zj3o1A/Gnu5cFgTMZVqFPQGCkZTdHzDc7b1V3yA132xCV5IUJvPADILxbqh7X 2bsPQc6u5gQOiLKyqYzjHa7kQrJiWrVntBhF9YwnGbSuchlV1juNqvNDWTIlXl8FsSXZ avuNah5W1HEApkNJmgSCp5ZQLyatyCO+5JqFZGUmzdqdERwB8xJ4uGwXrSngMAa4OVRm k8JQ== X-Gm-Message-State: AC+VfDySSRBQTCwNvsHYDS77Wof23Duosf8Dggr+MniQlge0dPsDhTpc 9UsmguKoM5cWEvkirxJw0sPGRA== X-Received: by 2002:a81:981:0:b0:561:b53d:d1f1 with SMTP id 123-20020a810981000000b00561b53dd1f1mr16007563ywj.19.1684894951822; Tue, 23 May 2023 19:22:31 -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 d188-20020a0df4c5000000b0054601ee157fsm3342840ywf.114.2023.05.23.19.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 19:22:31 -0700 (PDT) Date: Tue, 23 May 2023 19:22:28 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Qi Zheng cc: Hugh Dickins , Andrew Morton , 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 Subject: Re: [PATCH 04/31] mm/pgtable: allow pte_offset_map[_lock]() to fail In-Reply-To: <9dc72654-79db-e988-54a8-488550d235ac@linux.dev> Message-ID: <1efc993b-5b41-4895-a4d-20d38eb95de5@google.com> References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> <8218ffdc-8be-54e5-0a8-83f5542af283@google.com> <9dc72654-79db-e988-54a8-488550d235ac@linux.dev> 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 On Mon, 22 May 2023, Qi Zheng wrote: > 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? No, the follow-up patch will only insert the rcu_read_lock() and unlock(); and do something (something!) about the PAE mismatched halves case. > Otherwise, maybe it can be changed to the following check method? > > if (unlikely(pmd_none(pmdval) || pmd_leaf(pmdval))) > goto nomap; Maybe, but I'm not keen. Partly just because pmd_leaf() is quite a (good) new invention (I came across a few instances in updating to the current tree), whereas here I'm just following the old examples, from zap_pmd_range() etc. I'd have to spend a while getting to know pmd_leaf(), and its interaction with strange gotchas like pmd_present(). And partly because I do want as many corrupt cases as possible to reach the pmd_bad() check below, so generating a warning (and clear). I might be wrong, I haven't checked through the architectures and how pmd_leaf() is implemented in each, but my guess is that pmd_leaf() will tend to miss the pmd_bad() check. But if you can demonstrate a performance improvement from using pmd_leaf() there, I expect many people would prefer that improvement to badness catching: send a patch later to make that change if it's justified. Thanks a lot for all your attention to these. Hugh > > > + 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; > > +}