From mboxrd@z Thu Jan 1 00:00:00 1970 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 CF28BC54EE9 for ; Thu, 8 Sep 2022 18:20:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69F2C6B0072; Thu, 8 Sep 2022 14:20:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64E878D0003; Thu, 8 Sep 2022 14:20:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5173C8D0002; Thu, 8 Sep 2022 14:20:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4524F6B0072 for ; Thu, 8 Sep 2022 14:20:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 218D7AAC54 for ; Thu, 8 Sep 2022 18:20:59 +0000 (UTC) X-FDA: 79889734638.29.970CD3F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf31.hostedemail.com (Postfix) with ESMTP id 96BBA20097 for ; Thu, 8 Sep 2022 18:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662661257; 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: in-reply-to:in-reply-to:references:references; bh=Fq82aHZbVB5eLHvyHBC7VyGWz1mPN6C6p69Q0sIwiJE=; b=Ty3x+kHJsLhafjvIQ8TRhjYtkPU/Kq09EDtMBQxzqUhOt5y4gQa2ezggb/uy7USAJEGlWT T0ureZ7/tCVemiFF9mbYucgseF2abMygo9Z9TubJh/0AFgH2C4LfGmKGHmVbB31AOKkHLs ya06qSj63JqtEtU0r/f7eMg01taF5CU= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-447-z1j4Cj52P96aHsA_WPzjjg-1; Thu, 08 Sep 2022 14:20:54 -0400 X-MC-Unique: z1j4Cj52P96aHsA_WPzjjg-1 Received: by mail-qv1-f71.google.com with SMTP id ec8-20020ad44e68000000b004aab01f3eaaso4753537qvb.4 for ; Thu, 08 Sep 2022 11:20:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=Fq82aHZbVB5eLHvyHBC7VyGWz1mPN6C6p69Q0sIwiJE=; b=QAUAsG+Zy2qfbkU+GWpNhCjnRjUddCga0Elc3KBL+dau313F+Lo3GKpNvsfvmp3iq/ e9ePpjN/zFON4mI9UZrjZDn0h2ou0OIyTDPEJ6HnopY3Xn5VTVRqB4oJQjqE6wa/NMen zgmQHrMY+1g5AwxLO6PKS6MM4NrUW1utHYLZ71cdFY3WN5FVxMkkr+/+UgDhF9A/WKfu gtczLdq03j7nEhqCgWL2EXrjIuQ6tIxVEHvxiP2iIVv3K4WEG2yXZhXDc6OqsT2wkSU2 z3j4Bht+KhZSdyppAXdvora/ZrpF+Bnt3HOzv1uqOxPOCw0WZwPCnwX1Q7nt+hycwXmL D1HA== X-Gm-Message-State: ACgBeo1QNZ4fbcd9YLrL0fWBtYVCnwNwIZWPgTyJpuX1tO6dDn6MkgvT srHEwyijv/VC9G6qKgrx2nIUHhUTKVjZA2IdOkVQIhI/VM29xdLUlI9F9FQvuTGJNy7dq2LNp9f YSN9aa2i+bTI= X-Received: by 2002:a05:620a:2451:b0:6cb:b4db:a3ad with SMTP id h17-20020a05620a245100b006cbb4dba3admr5570204qkn.216.1662661254448; Thu, 08 Sep 2022 11:20:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR4UyQ8BldktqUXf3NND++hWgTsT32ASuiVTrEFM97vuCDpMTfuI2lGAwnelYvjmwScRjX2i7Q== X-Received: by 2002:a05:620a:2451:b0:6cb:b4db:a3ad with SMTP id h17-20020a05620a245100b006cbb4dba3admr5570182qkn.216.1662661254188; Thu, 08 Sep 2022 11:20:54 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id e5-20020ac80105000000b00342b7e4241fsm15385553qtg.77.2022.09.08.11.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 11:20:53 -0700 (PDT) Date: Thu, 8 Sep 2022 14:20:52 -0400 From: Peter Xu To: James Houghton Cc: Mike Kravetz , Muchun Song , David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , Jue Wang , Manish Mishra , "Dr . David Alan Gilbert" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 11/26] hugetlb: add hugetlb_walk_to to do PT walks Message-ID: References: <20220624173656.2033256-1-jthoughton@google.com> <20220624173656.2033256-12-jthoughton@google.com> MIME-Version: 1.0 In-Reply-To: <20220624173656.2033256-12-jthoughton@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662661257; a=rsa-sha256; cv=none; b=JSXwLQzVC6AbTouLz/Y6+HLHVnQcm1hdUYTgNnxhsqCHyqUL49TXhgeWM7B8ZYByIJzfKh bJKWIoPIXR/g3an8OarkDS2NpvVTbo5pJXWiKQmW3jVolSj8sZBfJxiSNzxOTcLX6uYCSn 2urGmKYBRLagKdvJB563KkrrHsQ3dO0= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ty3x+kHJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf31.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662661257; 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=Fq82aHZbVB5eLHvyHBC7VyGWz1mPN6C6p69Q0sIwiJE=; b=F+hDaBB9qbr2li68b0qb71RxJJa3TCxAAEpqkjXjw/7ENMew4BZpmRZ5QhDB/zxtpIHSjT GqGhVfe/PvbtFNkiaseYP8Ezi/be/G8jszUrub0d8SDGlr7je0/gx6Np9DCtRGzedBJ80q QFmxPr5l8LREUE/gxGmnQ29HcA1rGnU= X-Rspam-User: X-Stat-Signature: whapypq4ei7gpt7ay1ajxwqc9ny75nfc X-Rspamd-Queue-Id: 96BBA20097 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ty3x+kHJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf31.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam05 X-HE-Tag: 1662661257-490156 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: On Fri, Jun 24, 2022 at 05:36:41PM +0000, James Houghton wrote: > This adds it for architectures that use GENERAL_HUGETLB, including x86. > > Signed-off-by: James Houghton > --- > include/linux/hugetlb.h | 2 ++ > mm/hugetlb.c | 45 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 47 insertions(+) > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index e7a6b944d0cc..605aa19d8572 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -258,6 +258,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, > unsigned long addr, unsigned long sz); > pte_t *huge_pte_offset(struct mm_struct *mm, > unsigned long addr, unsigned long sz); > +int hugetlb_walk_to(struct mm_struct *mm, struct hugetlb_pte *hpte, > + unsigned long addr, unsigned long sz, bool stop_at_none); > int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, > unsigned long *addr, pte_t *ptep); > void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 557b0afdb503..3ec2a921ee6f 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -6981,6 +6981,51 @@ pte_t *huge_pte_offset(struct mm_struct *mm, > return (pte_t *)pmd; > } > > +int hugetlb_walk_to(struct mm_struct *mm, struct hugetlb_pte *hpte, > + unsigned long addr, unsigned long sz, bool stop_at_none) > +{ > + pte_t *ptep; > + > + if (!hpte->ptep) { > + pgd_t *pgd = pgd_offset(mm, addr); > + > + if (!pgd) > + return -ENOMEM; > + ptep = (pte_t *)p4d_alloc(mm, pgd, addr); > + if (!ptep) > + return -ENOMEM; > + hugetlb_pte_populate(hpte, ptep, P4D_SHIFT); > + } > + > + while (hugetlb_pte_size(hpte) > sz && > + !hugetlb_pte_present_leaf(hpte) && > + !(stop_at_none && hugetlb_pte_none(hpte))) { > + if (hpte->shift == PMD_SHIFT) { > + ptep = pte_alloc_map(mm, (pmd_t *)hpte->ptep, addr); I had a feeling that the pairing pte_unmap() was lost. I think most distros are not with CONFIG_HIGHPTE at all, but still.. > + if (!ptep) > + return -ENOMEM; > + hpte->shift = PAGE_SHIFT; > + hpte->ptep = ptep; > + } else if (hpte->shift == PUD_SHIFT) { > + ptep = (pte_t *)pmd_alloc(mm, (pud_t *)hpte->ptep, > + addr); > + if (!ptep) > + return -ENOMEM; > + hpte->shift = PMD_SHIFT; > + hpte->ptep = ptep; > + } else if (hpte->shift == P4D_SHIFT) { > + ptep = (pte_t *)pud_alloc(mm, (p4d_t *)hpte->ptep, > + addr); > + if (!ptep) > + return -ENOMEM; > + hpte->shift = PUD_SHIFT; > + hpte->ptep = ptep; > + } else > + BUG(); > + } > + return 0; > +} > + > #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ > > #ifdef CONFIG_HUGETLB_HIGH_GRANULARITY_MAPPING > -- > 2.37.0.rc0.161.g10f37bed90-goog > -- Peter Xu