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 95FEAC77B7E for ; Thu, 25 May 2023 18:05:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE8D9900002; Thu, 25 May 2023 14:05:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C97826B0075; Thu, 25 May 2023 14:05:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5E58900002; Thu, 25 May 2023 14:05:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A58836B0074 for ; Thu, 25 May 2023 14:05:55 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1CE9B40D5D for ; Thu, 25 May 2023 18:05:55 +0000 (UTC) X-FDA: 80829555870.23.159532C Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by imf07.hostedemail.com (Postfix) with ESMTP id EDE7B400C5 for ; Thu, 25 May 2023 18:04:40 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=NoHSm+P+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685037881; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YHz1MnM6TYYio2C+7LZLfrVXy67ugaabkk4Lxt+VEKA=; b=nkIsXfKbPv/PdeW+/lkBquS8wfZQQdko05vkJW0Y8qGq/UMuegDQwk33IRkIF3M09/wwvr emSsxkm2Qft3axrHplqdCkqE8MC1UUin5MIgKj9Ox+EcfwzXYW1p81+Ro0+jKYi5N2vHFD 1gV75RGjEYIjFJwKqkU92AJm/o+p7kE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=NoHSm+P+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685037881; a=rsa-sha256; cv=none; b=0CrPfQYj9cEO0Dixaa25xxPNMyrn1dK8jN0Uq4BCu76nhXqBxyVC0udh9gh1sOYw8xAxJW d3eV1Ka/fCFwkp/HvobBiRkOBzBiA+8E7CIDW1rTizmbQnDupe3HAcE7GYnI+ZO2BN67jj 4I+KXbVLyHnjyQwlF+t8m463AzoUcM8= Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-ba86ea269e0so1230814276.1 for ; Thu, 25 May 2023 11:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685037879; x=1687629879; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YHz1MnM6TYYio2C+7LZLfrVXy67ugaabkk4Lxt+VEKA=; b=NoHSm+P+R3f9P1hTtI0Aa2538QwCPLtSoQPrBLURQdxmp107FQ1F0pBnbEQWwggzlT fiTACnc6uzA/OAWqwR1JVWYYICkwBDdnIXj4ERwntlgZc/Oij0dm8rv+0LrV+CltMo3B fKyXLHfkdRh4xQKVcMe8OCp5giU3Tnn12LZCznOtQl1pIuAziPLT4fePeWe5Cvh7ZNzP bRQ3kdfBju0tbpe4F8kOJL6Oz3PfBgKD+/0uu8kOUyKFxwwoV5gkGDAbnMcHEgSeCLSi HSGZ+QgYvXiydUgpNmaTWLnoPbGEK3dVe0T9hw+SN0OStPQTocdixTet+7JhvERZXcH+ xYiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685037879; x=1687629879; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YHz1MnM6TYYio2C+7LZLfrVXy67ugaabkk4Lxt+VEKA=; b=e26tZrAnvZ6dhYGmRSKi80Kdk70Edcrl7sXEe/KQJr116p98ussdNK/H7WPYdMHM/h NlNNE2rVjPHuT5/1SaWtnrLwwPVMQxgnwDCFM2ACuHj/m2vVZXnpO1v2ZrR0xz3sDHug SZyFNsu06FdSrcIibwPPsmQ4jTCMBnLiWUtkGU5pFlUYUksDsZmJrtyJx1TLttZ11D31 uElzhJy9P1+2+Plc6VCj7xi9BJ1Ttwuv44xbRB7yfZ+oG1DGRE+G+qG7v7uqZecuwNvf kbudiDfFMwR6ymH4udHuBAvR6Bciwui40rLj0+K56EDjXiHgCqU2AgLPKLo6qAgG4iq0 AUAA== X-Gm-Message-State: AC+VfDz0KtC7+v6qUyZJquqO8ybtbYn+8iriioFhayl3HIfj2Nsp+gux gndDfap+DT5qAxagj88pB2W4JL+0NUBeseiAQLk= X-Google-Smtp-Source: ACHHUZ7leu3e42UYud7EgWJZoN6PW1XGYdS9PCBG/tq5rzS7YnuUSWzFoklHW8B2kAANtPb/IRvLBp1ufSDbPWAmKj4= X-Received: by 2002:a25:7493:0:b0:ba8:15a3:f2e4 with SMTP id p141-20020a257493000000b00ba815a3f2e4mr4848492ybc.0.1685037879336; Thu, 25 May 2023 11:04:39 -0700 (PDT) MIME-Version: 1.0 References: <20230501192829.17086-1-vishal.moola@gmail.com> <20230501192829.17086-6-vishal.moola@gmail.com> <20230525090956.GX4967@kernel.org> In-Reply-To: <20230525090956.GX4967@kernel.org> From: Vishal Moola Date: Thu, 25 May 2023 11:04:28 -0700 Message-ID: Subject: Re: [PATCH v2 05/34] mm: add utility functions for ptdesc To: Mike Rapoport Cc: Andrew Morton , Matthew Wilcox , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: EDE7B400C5 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 1fpxy8dimdwrysnmjgugsnd8h3fb56em X-HE-Tag: 1685037880-88400 X-HE-Meta: U2FsdGVkX1+bGiOhVsOgoLuqRZ6qU7xu5iRfOMYEPzrt4RLBoF5XR4ai85XZ3oeyfT5NcTveV9mbOKfMNpJY3jJM+3lYwpL8Xxrt1pIsi7gUJ0x0oKPE7YeVLCOLrTheGfU1zYKfVNF1YHKhWw9csVALnJB0VNXlr4KWweKPczomTJ73gxdK3UYD1t8lxdolmig3ONIgdcrMESOAuDJkoqRhKq7qtPlpBiYw7/dI6sbkqxN4m/1xai+vSFfs03Xfs6Z1+PVxyccsrLwavr0uWhu8ZDky2t3CMhBupOFsM11AA+iBfSiucA9Qf47ENRY/sxnp0+Lfp3872OwyOr8T4A/fQfxVc+rz+cjoBV8NEK+9SYEPrB2S3IJIE7rCAnorHvD81amwCTDej2Omx33lHudYo9hQqBjc3tXRY05z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000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, May 25, 2023 at 2:10=E2=80=AFAM Mike Rapoport wro= te: > > On Mon, May 01, 2023 at 12:28:00PM -0700, Vishal Moola (Oracle) wrote: > > Introduce utility functions setting the foundation for ptdescs. These > > will also assist in the splitting out of ptdesc from struct page. > > > > ptdesc_alloc() is defined to allocate new ptdesc pages as compound > > pages. This is to standardize ptdescs by allowing for one allocation > > and one free function, in contrast to 2 allocation and 2 free functions= . > > > > Signed-off-by: Vishal Moola (Oracle) > > --- > > include/asm-generic/tlb.h | 11 ++++++++++ > > include/linux/mm.h | 44 +++++++++++++++++++++++++++++++++++++++ > > include/linux/pgtable.h | 12 +++++++++++ > > 3 files changed, 67 insertions(+) > > > > diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h > > index b46617207c93..6bade9e0e799 100644 > > --- a/include/asm-generic/tlb.h > > +++ b/include/asm-generic/tlb.h > > @@ -481,6 +481,17 @@ static inline void tlb_remove_page(struct mmu_gath= er *tlb, struct page *page) > > return tlb_remove_page_size(tlb, page, PAGE_SIZE); > > } > > > > +static inline void tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) > > +{ > > + tlb_remove_table(tlb, pt); > > +} > > + > > +/* Like tlb_remove_ptdesc, but for page-like page directories. */ > > +static inline void tlb_remove_page_ptdesc(struct mmu_gather *tlb, stru= ct ptdesc *pt) > > +{ > > + tlb_remove_page(tlb, ptdesc_page(pt)); > > +} > > + > > static inline void tlb_change_page_size(struct mmu_gather *tlb, > > unsigned int page_si= ze) > > { > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index b18848ae7e22..258f3b730359 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -2744,6 +2744,45 @@ static inline pmd_t *pmd_alloc(struct mm_struct = *mm, pud_t *pud, unsigned long a > > } > > #endif /* CONFIG_MMU */ > > > > +static inline struct ptdesc *virt_to_ptdesc(const void *x) > > +{ > > + return page_ptdesc(virt_to_head_page(x)); > > Do we ever use compound pages for page tables? Mips and s390 crst tables use multi-order (but not compound) pages. The ptdesc api *should* change that, but until all the allocation/free path= s are changed it may cause problems. Thanks for catching that, I'll change it in v3. > > +} > > + > > +static inline void *ptdesc_to_virt(const struct ptdesc *pt) > > +{ > > + return page_to_virt(ptdesc_page(pt)); > > +} > > + > > +static inline void *ptdesc_address(const struct ptdesc *pt) > > +{ > > + return folio_address(ptdesc_folio(pt)); > > +} > > + > > +static inline bool ptdesc_is_reserved(struct ptdesc *pt) > > +{ > > + return folio_test_reserved(ptdesc_folio(pt)); > > +} > > + > > +static inline struct ptdesc *ptdesc_alloc(gfp_t gfp, unsigned int orde= r) > > +{ > > + struct page *page =3D alloc_pages(gfp | __GFP_COMP, order); > > + > > + return page_ptdesc(page); > > +} > > + > > +static inline void ptdesc_free(struct ptdesc *pt) > > +{ > > + struct page *page =3D ptdesc_page(pt); > > + > > + __free_pages(page, compound_order(page)); > > +} > > The ptdesc_{alloc,free} API does not sound right to me. The name > ptdesc_alloc() implies the allocation of the ptdesc itself, rather than > allocation of page table page. The same goes for free. I'm not sure I see the difference. Could you elaborate? > > + > > +static inline void ptdesc_clear(void *x) > > +{ > > + clear_page(x); > > +} > > + > > #if USE_SPLIT_PTE_PTLOCKS > > #if ALLOC_SPLIT_PTLOCKS > > void __init ptlock_cache_init(void); > > @@ -2970,6 +3009,11 @@ static inline void mark_page_reserved(struct pag= e *page) > > adjust_managed_page_count(page, -1); > > } > > > > +static inline void free_reserved_ptdesc(struct ptdesc *pt) > > +{ > > + free_reserved_page(ptdesc_page(pt)); > > +} > > + > > /* > > * Default method to free all the __init memory into the buddy system. > > * The freed pages will be poisoned with pattern "poison" if it's with= in > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > > index 5e0f51308724..b067ac10f3dd 100644 > > --- a/include/linux/pgtable.h > > +++ b/include/linux/pgtable.h > > @@ -1041,6 +1041,18 @@ TABLE_MATCH(ptl, ptl); > > #undef TABLE_MATCH > > static_assert(sizeof(struct ptdesc) <=3D sizeof(struct page)); > > > > +#define ptdesc_page(pt) (_Generic((pt), = \ > > + const struct ptdesc *: (const struct page *)(pt), \ > > + struct ptdesc *: (struct page *)(pt))) > > + > > +#define ptdesc_folio(pt) (_Generic((pt), \ > > + const struct ptdesc *: (const struct folio *)(pt), \ > > + struct ptdesc *: (struct folio *)(pt))) > > + > > +#define page_ptdesc(p) (_Generic((p), = \ > > + const struct page *: (const struct ptdesc *)(p), \ > > + struct page *: (struct ptdesc *)(p))) > > + > > /* > > * No-op macros that just return the current protection value. Defined= here > > * because these macros can be used even if CONFIG_MMU is not defined. > > -- > > 2.39.2 > > > > > > -- > Sincerely yours, > Mike.