Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2553914rdb; Fri, 22 Sep 2023 01:53:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEs0Sb23SRShHyvUieTlEtu/MPjfuGxry2SzmZ3r+ebQB7FRwQYNmT3jo+9pcPL4SBaZywe X-Received: by 2002:a05:6808:300e:b0:3ab:843f:76fd with SMTP id ay14-20020a056808300e00b003ab843f76fdmr8737669oib.19.1695372788185; Fri, 22 Sep 2023 01:53:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695372788; cv=none; d=google.com; s=arc-20160816; b=S8v7nnRYMPidz9q4qk+D38kil79a+URnwyPUsWcsk2yR7Psi9LSZunwhQ02zO+jeig Id7ZuJgg52A0aSjq2EU5/eUFOmOZy367LGWFCWn4YjfQJXucWN8jUGQ6kM0c/oPz/gl9 Bxr4VKJ68z/M5IazK6O7wylXANe3wKPUQBs1qG0O2s6PLCVaTfIgcyHjw7ata5Hfnh/L WEOR1W3vKKS3Fz57/ntzkOuXXKHWAXCQ1ns42lOD7DStPcCXvBf/yz/fXAiXJT9A4zxm e3603HvRct5oHf65/Ixg/e29gkwGAmyeIF+quA3Inxqj/xIE1jws2GlyJQLbnDSUhGkl Z/kQ== 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:user-agent:mime-version :date:message-id; bh=5XWPDJ0gxGYJwFk15JtO9BVDAWITGYKqaFod5Fs+8x4=; fh=oDJjc5ckkKmUeq8EhUlRq/ZIq9d2cDKgjXUx7PJLPhs=; b=opmmzrewqDYqv5E6DoUWgSb72q95rEaI47KofycfcTcLXCtCranOkI3VKpZ55uWkbx 1Vxtx+a2YlRZIW4Jv1qa6k+KJKL0Sjt4vR5KzQNeWHTPlC8WKz+LoXtBO9tcuUMrpOR6 UfQ95FBZ9UWCVgiXxiDGxwqNiOK17q+0CE+MsYwmiIgDhZtjHNwX1/zZMT2Xx9kCffDd jyNL+DeUAMGpqdMPRVTCWSYhnkv2qp7qe4wqCXBeZdcLAQrfS2JC61sDnHIMQAHN3mjV 8vp3Jv4jjk9duIIQvXtoP8KJ3XyYWUcxS13ILaEaGajR/K6iAuW7IZMxwSvk1+VPcKqK ff/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id 1-20020a631541000000b00573fa8f2827si3303483pgv.340.2023.09.22.01.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:53:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id A379F8373A31; Fri, 22 Sep 2023 01:36:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232558AbjIVIgY (ORCPT + 99 others); Fri, 22 Sep 2023 04:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjIVIgX (ORCPT ); Fri, 22 Sep 2023 04:36:23 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 279009E; Fri, 22 Sep 2023 01:36:15 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B69FDA7; Fri, 22 Sep 2023 01:36:52 -0700 (PDT) Received: from [10.57.65.11] (unknown [10.57.65.11]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F7F03F67D; Fri, 22 Sep 2023 01:36:09 -0700 (PDT) Message-ID: Date: Fri, 22 Sep 2023 09:36:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 3/8] riscv: hugetlb: Convert set_huge_pte_at() to take vma Content-Language: en-GB To: Alexandre Ghiti , Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org References: <20230921162007.1630149-1-ryan.roberts@arm.com> <20230921162007.1630149-4-ryan.roberts@arm.com> <7bbceed4-c5f6-42d4-5d94-060032b73385@ghiti.fr> From: Ryan Roberts In-Reply-To: <7bbceed4-c5f6-42d4-5d94-060032b73385@ghiti.fr> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 22 Sep 2023 01:36:28 -0700 (PDT) On 22/09/2023 08:54, Alexandre Ghiti wrote: > Hi Ryan, > > On 21/09/2023 18:20, Ryan Roberts wrote: >> In order to fix a bug, arm64 needs access to the vma inside it's >> implementation of set_huge_pte_at(). Provide for this by converting the >> mm parameter to be a vma. Any implementations that require the mm can >> access it via vma->vm_mm. >> >> This commit makes the required riscv modifications. Separate commits >> update the other arches and core code, before the actual bug is fixed in >> arm64. >> >> No behavioral changes intended. >> >> Signed-off-by: Ryan Roberts >> --- >>   arch/riscv/include/asm/hugetlb.h | 2 +- >>   arch/riscv/mm/hugetlbpage.c      | 3 ++- >>   2 files changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h >> index 34e24f078cc1..be1ac8582bc2 100644 >> --- a/arch/riscv/include/asm/hugetlb.h >> +++ b/arch/riscv/include/asm/hugetlb.h >> @@ -17,7 +17,7 @@ void huge_pte_clear(struct mm_struct *mm, unsigned long addr, >>               pte_t *ptep, unsigned long sz); >>     #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT >> -void set_huge_pte_at(struct mm_struct *mm, >> +void set_huge_pte_at(struct vm_area_struct *vma, >>                unsigned long addr, pte_t *ptep, pte_t pte); >>     #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR >> diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c >> index 96225a8533ad..7cdbf0960772 100644 >> --- a/arch/riscv/mm/hugetlbpage.c >> +++ b/arch/riscv/mm/hugetlbpage.c >> @@ -177,11 +177,12 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int >> shift, vm_flags_t flags) >>       return entry; >>   } >>   -void set_huge_pte_at(struct mm_struct *mm, >> +void set_huge_pte_at(struct vm_area_struct *vma, >>                unsigned long addr, >>                pte_t *ptep, >>                pte_t pte) >>   { >> +    struct mm_struct *mm = vma->vm_mm; >>       int i, pte_num; >>         if (!pte_napot(pte)) { > > > You can add: > > Reviewed-by: Alexandre Ghiti Thanks! > > I realize that we may have the same issue with our contig pte implementation > (called napot in riscv) as we don't handle swap/migration entries at all. So I > guess we need something similar, and I'll implement it (unless you want to do it > of course, but I guess it's easier for me to test). Yes -I'll leave you to do the riscv part. > One (maybe stupid) question > though: wouldn't it be possible to extract the contig pte size from the value of > ptep instead of using a vma? Not for arm64: We support contpmd, pmd and contpte entries as backing for the logical huge pte, depending on size. So without the size, we can't distinguish between a coincidentally-aligned pmd entry vs a contpmd entry (which is just a fixed size block of pmd entries). Discussion with Christophe on the powerpc patch triggered some thinking; There is theoretical problem with my current approach because there is one call site in the core code that calls set_huge_pte_at(&init_mm). I've changed that to: struct vm_area_struct vma = TLB_FLUSH_VMA(&init_mm, 0); set_huge_pte_at(&vma); knowing that this will never actually get called for arm64 because we return PAGE_SIZE for arch_vmap_pte_range_map_size() and all other arches just take the mm and ignore the rest of the vma. So it's safe, but fragile. But it looks like riscv overrides arch_vmap_pte_range_map_size() and therefore the call will be made there. And if riscv also needs to determine the size from the vma, then bang. So I'm going to rework it to continue to pass the mm in, but also add a size parameter. Then it's totally safe. Will post a v2 later today. Thanks, Ryan > > Thanks, > > Alex >