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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61DA7C48BEB for ; Thu, 22 Feb 2024 08:05:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=21+g7d4OAqpn4XKZat4ybxSivWh8XyOaGRlpOCtEVfY=; b=gv/UFhVHOgiZ0D J1mZa9o7c2L+XulKv94001LrFmLkCgQHaZBMe4WlWOJMIa3X/WWEGSnldwcH39cmXuPmzDzEKjJff /JU7KSztWtL2oESXFvLdkU9fVvt+HqNwOgkBQRnctVrFg3OLtka597hQJy01cddLcNzhFHndboMhl EuaDIHsi5nMDqacYpE9hUokjbUylK5qjO6djHUBF8ARwqPmYsQ8Cq9qOkoctW4wchy7/pfXV1xGGO zlN6isxOcTP4OTnfe44t+w4PtECTmLQ1PjI0YJcO/xw7276uNVflu+0kqA13dYl0jbF+8u85D7NJK z0MsNmmldEfaUS1nbCyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd44j-00000003vSR-2E3X; Thu, 22 Feb 2024 08:05:01 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd44g-00000003vP5-0ZQs for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2024 08:04:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708589097; 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=2Qz0IA0kUehz+OG0swe7slV1s58KjzFRhgWAnSqUkqI=; b=JEEpIkD7fF0fubtTHixoC7awT8Ng3Ynt3mdi5bZd9tsQNzCakQKuT1lD/ybxvJ5gXuW5QO 3tcS1RpngI4DQ3312RNEyWYmWVdiV4bmuGUtdOkncPwhoOcSCzF+eFQ3LcTi2SmvhYyCuT 4puPWbkaywMsP8XT0dGAPw1NuFBSwOY= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-116-ltIYbs-sPfGKIKpp7ixNGg-1; Thu, 22 Feb 2024 03:04:53 -0500 X-MC-Unique: ltIYbs-sPfGKIKpp7ixNGg-1 Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-6e430252451so2031467a34.1 for ; Thu, 22 Feb 2024 00:04:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708589092; x=1709193892; 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 :message-id:reply-to; bh=2Qz0IA0kUehz+OG0swe7slV1s58KjzFRhgWAnSqUkqI=; b=i5q67ucLW8HqOXfF8TZbptf7yF5853Wrb+U8B8cmB3uDhSU/sWSJixlBZFrckOpp01 bg/Zp/JGMTC7PxAwkxn3eN+st7qleosoN9XIivNVnY+6iThrBnwtz7yZ02CHAqPVuF/7 b/Da6G/GlmuIzI50h6fbdyCaJKlyYG3Zi0vCHI+IQ1zrKW5MNpeS+Erhph9mFGF98T/0 1fzE+VYQLgtq3/niS6OcYm/4StSRtUjxwKSeZe137NgeYhE7IqGi0O01O4MjJ8TM/Yo3 0e4kRBrZia8vgtlA+jMq2lLWxr/5T2Mqs8WoEg2F1KqgyTwhbnsYqPAE9Hxxg8cO/h6u 5Xpw== X-Forwarded-Encrypted: i=1; AJvYcCU03M8XEzLYc6Sywgh/xe+ejUjC+lh57PUOXV00QCORx9t0m5MlH1/nc1L0xfKr5tHzvhxEbz+nXRptGzdK8xIT4SKRE0l6PrpJcxJZlHsj1ITCBH0= X-Gm-Message-State: AOJu0YxVJ4xLApHppZIED69xC2lYbkNWmb7eyReQabDsN3mYx1iWIJ8R E0slUMX2jl49g+/H1tn11ixrJnpaFh7VRwTb9OMrE/ohASS4KEakoeiMpbUKepNbO8YR/VrRaM5 oevfGRhkcWMUetSVRFNdXHFisrbudxETWd6oMQUbSOvJl2vC/UwKs+RHlR21NB9Uroz2kWwXi X-Received: by 2002:a05:6359:4113:b0:176:6149:5558 with SMTP id kh19-20020a056359411300b0017661495558mr16051646rwc.1.1708589092300; Thu, 22 Feb 2024 00:04:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZ/pl9m1WfSqai2cvVXv5Lf1ZKvJ4xKR9ln5/WSKPeld/1kI04FNn1XDkCL6gJC29eFxMWrw== X-Received: by 2002:a05:6359:4113:b0:176:6149:5558 with SMTP id kh19-20020a056359411300b0017661495558mr16051606rwc.1.1708589091922; Thu, 22 Feb 2024 00:04:51 -0800 (PST) Received: from x1n ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id a21-20020a056a0011d500b006e0d1e6036bsm10300214pfu.129.2024.02.22.00.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:04:51 -0800 (PST) Date: Thu, 22 Feb 2024 16:04:38 +0800 From: Peter Xu To: Jason Gunthorpe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton , David Hildenbrand , "Kirill A . Shutemov" , Yang Shi , linux-riscv@lists.infradead.org, Andrew Morton , "Aneesh Kumar K . V" , Rik van Riel , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , John Hubbard , Vlastimil Babka , Michael Ellerman , Christophe Leroy , Andrew Jones , linuxppc-dev@lists.ozlabs.org, Mike Kravetz , Muchun Song , linux-arm-kernel@lists.infradead.org, Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox Subject: Re: [PATCH v2 03/13] mm: Provide generic pmd_thp_or_huge() Message-ID: References: <20240103091423.400294-1-peterx@redhat.com> <20240103091423.400294-4-peterx@redhat.com> <20240115175551.GP734935@nvidia.com> <20240221125753.GQ13330@nvidia.com> MIME-Version: 1.0 In-Reply-To: <20240221125753.GQ13330@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_000458_291695_C8E54D17 X-CRM114-Status: GOOD ( 36.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Feb 21, 2024 at 08:57:53AM -0400, Jason Gunthorpe wrote: > On Wed, Feb 21, 2024 at 05:37:37PM +0800, Peter Xu wrote: > > On Mon, Jan 15, 2024 at 01:55:51PM -0400, Jason Gunthorpe wrote: > > > On Wed, Jan 03, 2024 at 05:14:13PM +0800, peterx@redhat.com wrote: > > > > From: Peter Xu > > > > > > > > ARM defines pmd_thp_or_huge(), detecting either a THP or a huge PMD. It > > > > can be a helpful helper if we want to merge more THP and hugetlb code > > > > paths. Make it a generic default implementation, only exist when > > > > CONFIG_MMU. Arch can overwrite it by defining its own version. > > > > > > > > For example, ARM's pgtable-2level.h defines it to always return false. > > > > > > > > Keep the macro declared with all config, it should be optimized to a false > > > > anyway if !THP && !HUGETLB. > > > > > > > > Signed-off-by: Peter Xu > > > > --- > > > > include/linux/pgtable.h | 4 ++++ > > > > mm/gup.c | 3 +-- > > > > 2 files changed, 5 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > > > > index 466cf477551a..2b42e95a4e3a 100644 > > > > --- a/include/linux/pgtable.h > > > > +++ b/include/linux/pgtable.h > > > > @@ -1362,6 +1362,10 @@ static inline int pmd_write(pmd_t pmd) > > > > #endif /* pmd_write */ > > > > #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > > > > > > > > +#ifndef pmd_thp_or_huge > > > > +#define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) > > > > +#endif > > > > > > Why not just use pmd_leaf() ? > > > > > > This GUP case seems to me exactly like what pmd_leaf() should really > > > do and be used for.. > > > > I think I mostly agree with you, and these APIs are indeed confusing. IMHO > > the challenge is about the risk of breaking others on small changes in the > > details where evil resides. > > These APIs are super confusing, which is why I brought it up.. Adding > even more subtly different variations is not helping. > > I think pmd_leaf means the entry is present and refers to a physical > page not another radix level. > > > > eg x86 does: > > > > > > #define pmd_leaf pmd_large > > > static inline int pmd_large(pmd_t pte) > > > return pmd_flags(pte) & _PAGE_PSE; > > > > > > static inline int pmd_trans_huge(pmd_t pmd) > > > return (pmd_val(pmd) & (_PAGE_PSE|_PAGE_DEVMAP)) == _PAGE_PSE; > > > > > > int pmd_huge(pmd_t pmd) > > > return !pmd_none(pmd) && > > > (pmd_val(pmd) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT; > > > > For example, here I don't think it's strictly pmd_leaf()? As pmd_huge() > > will return true if PRESENT=0 && PSE=0 (as long as none pte ruled out > > first), while pmd_leaf() will return false; I think that came from > > cbef8478bee5. > > Yikes, but do you even want to handle non-present entries in GUP > world? Isn't everything gated by !present in the first place? I am as confused indeed. > > > Besides that, there're also other cases where it's not clear of such direct > > replacement, not until further investigated. E.g., arm-3level has: > > > > #define pmd_leaf(pmd) pmd_sect(pmd) > > #define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \ > > PMD_TYPE_SECT) > > #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0) > > > > While pmd_huge() there relies on PMD_TABLE_BIT () > > I looked at tht, it looked OK.. > > #define PMD_TYPE_MASK (_AT(pmdval_t, 3) << 0) > #define PMD_TABLE_BIT (_AT(pmdval_t, 1) << 1) > > It is the same stuff, just a little confusingly written True, my eyes decided to skip all the shifts. :-( Ok then, let me see whether I can give it a stab on the pXd_huge() mess. Thanks, -- Peter Xu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel