From nobody Mon Apr 6 13:29:11 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28EF6C07E9D for ; Tue, 27 Sep 2022 16:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232220AbiI0Q2Y (ORCPT ); Tue, 27 Sep 2022 12:28:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232404AbiI0Q2F (ORCPT ); Tue, 27 Sep 2022 12:28:05 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECA48DCEA8 for ; Tue, 27 Sep 2022 09:27:52 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id f193so9909501pgc.0 for ; Tue, 27 Sep 2022 09:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=qop4kS7tfgVAWONSShTjlSwOzcS5SD4NChZjNU/F2nQ=; b=bdViRXIQLD0mZYILY5hdkcVtOxo8rJzC8pDOup5INaReSB1+OZFg6CNzWUIE5BoKlO dIfOAa7OJkvup0fHXtjsFxciDPdJadIVweVlvWKGvO2J76yDUKyS7/4vW/gC7WkYZs+z DjMDXYiEJKmynMd3aq1VffDohQY92eIALGOII45QcStOgx2Njh9+LvLHMKgwnYac70o8 UEWJq/Mfz6mKV0ZjGssEda6J8o3Kkm3c9ViszcnWDOV9ZkMgxvOEeA9nediWg8YVLG+i UyaB5tsMUGqhRx+froXMyrEMO+198iLRw+fWEwE2kkwxAU7DSzokRX22Ez3PAJf2iINy Xq2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=qop4kS7tfgVAWONSShTjlSwOzcS5SD4NChZjNU/F2nQ=; b=AphDjZJAPXtTaanakdjAovQD2GR9LFAmHk4hVYT/1s+TqCokJ1f05y1622NPHQq6g8 Z9XDymnwv+ppAGGzo3YiJU709wGGElBdLcUGp0dCdGpwPEkQq3Dy1MIG3NciWZFdrzAy wK6ftGai2URI3bkIDvg/W43c5TLoMWvwYxkeYngFd7oOfbTDJCxvcJlWueASFt4B5nsV Q8sj5dhXR9fwzbKrsY869Ixw8xYgYaIqVZxStrix6ONxZdp1laXffEpJ3FB+1YWpraMB 4AO3fF8ZQpa9RUExrY4sS3IUo9enkZ11G5CeIVcS0cbAz8lH5DytZ6HXDE+ZZveXfODC bKvw== X-Gm-Message-State: ACrzQf1hb/J65newZgNjgJKUmaKi/2FdIdTuFUfutr2sGwZKJSNyQtF7 KcBVPij2MnxE4iFEneKgDM0= X-Google-Smtp-Source: AMsMyM7VMvbPQOTjzD9+Ao59BdB9ZhHh61sNAq/kZfwKTlLP+8k0zXC+njFiksYsSQsqL75utiqfnA== X-Received: by 2002:a63:3c5:0:b0:43c:8455:d67d with SMTP id 188-20020a6303c5000000b0043c8455d67dmr15487199pgd.73.1664296072465; Tue, 27 Sep 2022 09:27:52 -0700 (PDT) Received: from archlinux.localdomain ([140.121.198.213]) by smtp.googlemail.com with ESMTPSA id 9-20020a17090a0f0900b001f333fab3d6sm8602360pjy.18.2022.09.27.09.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 09:27:51 -0700 (PDT) From: Chih-En Lin To: Andrew Morton , Qi Zheng , David Hildenbrand , Matthew Wilcox , Christophe Leroy Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Luis Chamberlain , Kees Cook , Iurii Zaikin , Vlastimil Babka , William Kucharski , "Kirill A . Shutemov" , Peter Xu , Suren Baghdasaryan , Arnd Bergmann , Tong Tiangen , Pasha Tatashin , Li kunyu , Nadav Amit , Anshuman Khandual , Minchan Kim , Yang Shi , Song Liu , Miaohe Lin , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , Fenghua Yu , Dinglan Peng , Pedro Fonseca , Jim Huang , Huichun Feng , Chih-En Lin Subject: [RFC PATCH v2 3/9] mm, pgtable: Add ownership to PTE table Date: Wed, 28 Sep 2022 00:29:51 +0800 Message-Id: <20220927162957.270460-4-shiyn.lin@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220927162957.270460-1-shiyn.lin@gmail.com> References: <20220927162957.270460-1-shiyn.lin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Introduce the ownership to the PTE table. It uses the address of PMD index to track the ownership to identify which process can update their page table state from the COWed PTE table. Signed-off-by: Chih-En Lin --- include/linux/mm.h | 1 + include/linux/mm_types.h | 5 ++++- include/linux/pgtable.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 21f8b27bd9fd3..965523dcca3b8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2289,6 +2289,7 @@ static inline bool pgtable_pte_page_ctor(struct page = *page) return false; __SetPageTable(page); inc_lruvec_page_state(page, NR_PAGETABLE); + page->cow_pte_owner =3D NULL; return true; } =20 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index cf97f3884fda2..42798b59cec4e 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -152,7 +152,10 @@ struct page { struct list_head deferred_list; }; struct { /* Page table pages */ - unsigned long _pt_pad_1; /* compound_head */ + union { + unsigned long _pt_pad_1; /* compound_head */ + pmd_t *cow_pte_owner; /* cow pte: pmd */ + }; pgtable_t pmd_huge_pte; /* protected by page->ptl */ unsigned long _pt_pad_2; /* mapping */ union { diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index d03d01aefe989..9dca787a3f4dd 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -615,6 +615,16 @@ static inline int pte_unused(pte_t pte) } #endif =20 +static inline void set_cow_pte_owner(pmd_t *pmd, pmd_t *owner) +{ + smp_store_release(&pmd_page(*pmd)->cow_pte_owner, owner); +} + +static inline bool cow_pte_owner_is_same(pmd_t *pmd, pmd_t *owner) +{ + return smp_load_acquire(&pmd_page(*pmd)->cow_pte_owner) =3D=3D owner; +} + #ifndef pte_access_permitted #define pte_access_permitted(pte, write) \ (pte_present(pte) && (!(write) || pte_write(pte))) --=20 2.37.3