Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22388571rwd; Fri, 30 Jun 2023 07:27:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlE1GxpjN0d5TG3vhvfIZZMSN0EgAlCoQRYr56XB0qYz4mR2U1zMgJWSOw8ue9AvbOKUtvba X-Received: by 2002:a92:d8ca:0:b0:345:db9b:4e62 with SMTP id l10-20020a92d8ca000000b00345db9b4e62mr2553467ilo.16.1688135264548; Fri, 30 Jun 2023 07:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688135264; cv=none; d=google.com; s=arc-20160816; b=xbxuBv7qh7oUg6qm21TmrUNHIwKzl5gYGNPfSFTKKOldy0pZg957e+Vg2LRhC/yxC5 o6E0tM9DrJotFc4Djqn6amRBfIFFU5xKu6DZ/MpR4hcTAijd4newX2T72hwEOv0fSvme p7vzcyruC9PQEDeCJ02IJ7O0OiC7nUA9Ylyv5QP6wP2Hv7wtIa1i+h4DIbdHW4/40coA ChWCnHEgxmBo8VZnYuSQLdU1wwLxpWq57D8t706y+o94KO/qes/r19mVcHy/fTSvyn8C 8La/IzAWyn9tBpCrr/evosLFqq8HAXdEHWL8UxMV/TxmqAHM/r5XAdkAUQ2dZ1ouyBVZ kUeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=MILFYyEh0bzy33IA0yZToAfVYRzb2Mhl3gp0isRO4pM=; fh=xPXtWGq68Ij76Xptpm5midO5wdklTLKvZ6lDUVw4ni4=; b=vXSoeKCL22XFfs77sFingqHdKoP2cXBpFrTzvsXeOlAuHC/zf9k1Pxtbrcpq2pyXHD XHL5Hh4pA5m7BR4AeI7JqwNG5r4Vl8YbzRAuVf2qif54hlTZnE4Fbys3G9oidK4p8lOo U+H9Bw6oPBnfO1MsLnPk036jISJjoQWcPYOCotaYrSz2TSMNjtmbCdDmq+HKLtqFe1u9 sZhFAlZetKivJeIAz2NyNc/Zr5S/KjOKupsiOj5wR3nWJl3vBSOwdktFVT3IL9nX8GkC xcYh0K1orivn5uuoLkOj+0OtViqSwD4eOhnDeqbOh0wDPWZko/psKnQ0ecQmM1CXQcz8 P3ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=WWpOuUBl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a63e64d000000b0054b57b5e049si12777838pgj.28.2023.06.30.07.27.31; Fri, 30 Jun 2023 07:27:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=WWpOuUBl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232748AbjF3NkK (ORCPT + 99 others); Fri, 30 Jun 2023 09:40:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232338AbjF3NkI (ORCPT ); Fri, 30 Jun 2023 09:40:08 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9EEC1FE8; Fri, 30 Jun 2023 06:40:05 -0700 (PDT) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35UDXtkF024475; Fri, 30 Jun 2023 13:39:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=MILFYyEh0bzy33IA0yZToAfVYRzb2Mhl3gp0isRO4pM=; b=WWpOuUBll0GcMgF6UkEAPv1U/0AELyMv08YfNFH5QWoGlgD30nDBbxmr3vbfSbir1zDF v1n3VFiHTI2iKdl0ajnyVN8bMun8YmP3twJ0zeA20CJqamSbFHDi0WTEGFk62XbzPkt+ 3sQv6xziupU8flvhfEio8DJeUkwPyzL/3LA2kAIq72vI2CbDVcUIXbqzP5IohDPsH4/K nxBzmnoEp2WjhyoNKxCZ0dgzhxUGvSu0SNRrFBSAmnnreNuicuHYPiLqqUjRWB61jY4q YJ78SFBrwbAkYFxbT96VF4dSAcOaIN/gb7fOJsJGxvv6qHAnXFv+w90Oi5zo4zs12bA4 wA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rj01vr5v8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Jun 2023 13:39:02 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35UDXvp4024557; Fri, 30 Jun 2023 13:39:01 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rj01vr5rt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Jun 2023 13:39:01 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35U4eiGQ004048; Fri, 30 Jun 2023 13:38:59 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3rdr45463d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Jun 2023 13:38:59 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35UDctix16253646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Jun 2023 13:38:55 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6250B2004F; Fri, 30 Jun 2023 13:38:55 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C36332004E; Fri, 30 Jun 2023 13:38:53 +0000 (GMT) Received: from p-imbrenda (unknown [9.152.224.66]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 30 Jun 2023 13:38:53 +0000 (GMT) Date: Fri, 30 Jun 2023 15:38:52 +0200 From: Claudio Imbrenda To: Hugh Dickins Cc: Andrew Morton , Gerald Schaefer , Vasily Gorbik , Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Russell King , "David S. Miller" , Michael Ellerman , "Aneesh Kumar K.V" , Heiko Carstens , Christian Borntraeger , Alexander Gordeev , Jann Horn , Vishal Moola , Vlastimil Babka , linux-arm-kernel@lists.infradead.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 07/12] s390: add pte_free_defer() for pgtables sharing page Message-ID: <20230630153852.31163592@p-imbrenda> In-Reply-To: References: <54cb04f-3762-987f-8294-91dafd8ebfb0@google.com> Organization: IBM X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: EBLZMsFsdvv19REZEqy1DFVn4Lc2XsWt X-Proofpoint-GUID: t0PdQmyDLcbJVGOB3mJ29fow46RM-DV8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-30_05,2023-06-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1011 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306300116 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 20 Jun 2023 00:51:19 -0700 (PDT) Hugh Dickins wrote: [...] > @@ -407,6 +429,77 @@ void __tlb_remove_table(void *_table) > __free_page(page); > } > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > +static void pte_free_now0(struct rcu_head *head); > +static void pte_free_now1(struct rcu_head *head); > + > +static void pte_free_pgste(struct rcu_head *head) > +{ > + unsigned long *table; > + struct page *page; > + > + page = container_of(head, struct page, rcu_head); > + table = (unsigned long *)page_to_virt(page); > + table = (unsigned long *)((unsigned long)table | 0x03U); > + __tlb_remove_table(table); > +} > + > +static void pte_free_half(struct rcu_head *head, unsigned int bit) > +{ > + unsigned long *table; > + struct page *page; > + unsigned int mask; > + > + page = container_of(head, struct page, rcu_head); > + mask = atomic_xor_bits(&page->_refcount, 0x04U << (bit + 24)); > + > + table = (unsigned long *)page_to_virt(page); > + table += bit * PTRS_PER_PTE; > + table = (unsigned long *)((unsigned long)table | (0x01U << bit)); > + __tlb_remove_table(table); > + > + /* If pte_free_defer() of the other half came in, queue it now */ > + if (mask & 0x0CU) > + call_rcu(&page->rcu_head, bit ? pte_free_now0 : pte_free_now1); > +} > + > +static void pte_free_now0(struct rcu_head *head) > +{ > + pte_free_half(head, 0); > +} > + > +static void pte_free_now1(struct rcu_head *head) > +{ > + pte_free_half(head, 1); > +} > + > +void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable) > +{ > + unsigned int bit, mask; > + struct page *page; > + > + page = virt_to_page(pgtable); > + if (mm_alloc_pgste(mm)) { > + call_rcu(&page->rcu_head, pte_free_pgste); so is this now going to be used to free page tables instead of page_table_free_rcu? or will it be used instead of page_table_free? this is actually quite important for KVM on s390 > + return; > + } > + bit = ((unsigned long)pgtable & ~PAGE_MASK) / > + (PTRS_PER_PTE * sizeof(pte_t)); > + > + spin_lock_bh(&mm_pgtable_list_lock); > + mask = atomic_xor_bits(&page->_refcount, 0x15U << (bit + 24)); > + mask >>= 24; > + /* Other half not allocated? Other half not already pending free? */ > + if ((mask & 0x03U) == 0x00U && (mask & 0x30U) != 0x30U) > + list_del(&page->lru); > + spin_unlock_bh(&mm_pgtable_list_lock); > + > + /* Do not relink on rcu_head if other half already linked on rcu_head */ > + if ((mask & 0x0CU) != 0x0CU) > + call_rcu(&page->rcu_head, bit ? pte_free_now1 : pte_free_now0); > +} > +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > + > /* > * Base infrastructure required to generate basic asces, region, segment, > * and page tables that do not make use of enhanced features like EDAT1. > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 306a3d1a0fa6..1667a1bdb8a8 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -146,7 +146,7 @@ struct page { > pgtable_t pmd_huge_pte; /* protected by page->ptl */ > unsigned long _pt_pad_2; /* mapping */ > union { > - struct mm_struct *pt_mm; /* x86 pgds only */ > + struct mm_struct *pt_mm; /* x86 pgd, s390 */ > atomic_t pt_frag_refcount; /* powerpc */ > }; > #if ALLOC_SPLIT_PTLOCKS