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 161A0EB64D7 for ; Fri, 30 Jun 2023 16:27:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C3F18E0037; Fri, 30 Jun 2023 12:27:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 574148E000F; Fri, 30 Jun 2023 12:27:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ED398E0037; Fri, 30 Jun 2023 12:27:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2DCAF8E000F for ; Fri, 30 Jun 2023 12:27:03 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 00BEAB05E3 for ; Fri, 30 Jun 2023 16:27:02 +0000 (UTC) X-FDA: 80959943526.12.09A9A86 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf24.hostedemail.com (Postfix) with ESMTP id 11D9118001C for ; Fri, 30 Jun 2023 16:26:57 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=rfJRDjaZ; spf=pass (imf24.hostedemail.com: domain of imbrenda@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=imbrenda@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688142419; 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=5FleP/0R2I7M2ntcJjERxzq9JuYOAoAyKjmikS2wBhs=; b=PffoT4Rgl+4NIvm8Pj2fK+C4HnoNt3bbfA1efyIW0ZhLiGfWl981uL2tXxpgfQO/MDRyNp v2NsN9bwv+3a/x/Hzf03kIP7ASnpWl/17n3kQ8IPJX/nY2SC+HO1p9d+z4iMWmtG5rmwTM /qua2ciqnI4uvl0rQxW8j+2VtZiQWZw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688142419; a=rsa-sha256; cv=none; b=D5cnX70hD/2M3eDU2AbhSGzKL2o8GDOfMzoSFSJEG3+SCbAQtwAv49DH7URwW3OYbPHFr3 ZIIkOISL7uKKjp5D95EWVvHsgvwFI0sEov3cdoOb4vNeLY60qwwoORsMG4DQpRLEnOfzpI k3auhIvSdO0ClxMgHh8JOET76XuCkhI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=rfJRDjaZ; spf=pass (imf24.hostedemail.com: domain of imbrenda@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=imbrenda@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35UGGhGg032422; Fri, 30 Jun 2023 16:26:07 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=5FleP/0R2I7M2ntcJjERxzq9JuYOAoAyKjmikS2wBhs=; b=rfJRDjaZJEmkfL3bAbOBfQgWWuV8fu4M4tJ60QgQix7BNqhCbdDa0fe4ogQDW2D0rhik WZFSh31VTe2dd7zFvMHKxG8NjyG3/mWCsRT1NXjIHQvQHnNlmreeNv4kJSHIJCm3/3cY 8Vo/gAsNL9CsVvHpA8vJRL3ec/c0OClfPpaT/H/wliIlFpB+pKNBdZpCsR1Qrs3tbal4 7d0rN+mrAqlZlfZyoi1wzQXr023CgKAdYBD22hdZ2NbPDWJ/V0kCq3Mtq78VI3Dqy9+g O2ZyQjIgWrj1sU0NRnKHUUlc8tPezuNGTeemTtA37ErNfK/9zqnLWTWZQoNSZFFDrx8/ 3w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rj2e387t8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Jun 2023 16:26:07 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35UGH63B001290; Fri, 30 Jun 2023 16:26:06 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rj2e387rm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Jun 2023 16:26:05 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35UFkuwi000452; Fri, 30 Jun 2023 16:26:02 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3rdr453513-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Jun 2023 16:26:02 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35UGPxmU43516216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Jun 2023 16:25:59 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E9A4120043; Fri, 30 Jun 2023 16:25:58 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CAC6F20040; Fri, 30 Jun 2023 16:25:57 +0000 (GMT) Received: from p-imbrenda (unknown [9.152.224.66]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 30 Jun 2023 16:25:57 +0000 (GMT) Date: Fri, 30 Jun 2023 18:25:56 +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: <20230630182556.7727ef50@p-imbrenda> In-Reply-To: <062b19-4cf1-261-a9bf-9cefd32382fc@google.com> References: <54cb04f-3762-987f-8294-91dafd8ebfb0@google.com> <20230630153852.31163592@p-imbrenda> <062b19-4cf1-261-a9bf-9cefd32382fc@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-GUID: NGGI7X7RNOwVeaZnozOHUb2n61vBAppx X-Proofpoint-ORIG-GUID: ZwpwS0v6kbksCuiFRJdCAInx0_OzLG0C 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_08,2023-06-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 mlxscore=0 impostorscore=0 phishscore=0 suspectscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 bulkscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306300137 X-Rspamd-Queue-Id: 11D9118001C X-Rspam-User: X-Stat-Signature: fi1hwr9fbzd5y9xhh385chtggnx7cxbx X-Rspamd-Server: rspam03 X-HE-Tag: 1688142417-767009 X-HE-Meta: U2FsdGVkX18ZLDk+pSMWNw7X8f1zVWuFby4W6cK565T0vRU7MQPPngyxGGNKQYE7GJ05d1mVz+DI2MDzL1kd7/SZrna1t+KSolB5uSDjnhMLMcq+b7Dknk+desdniMCRQRDTRxPuNjQIfEdAxs7FfojeVciAQiF1/QkCSH+1d/ycxsYTnI1L9wJq41pkNTC7axsGQtJIv3JBG2Zixbd+f4OosAEL8j3+vkoA3dPKM7NeggMa4zznNM6SRibblEdwhb41OZ36L0o/61YKUfzS7JiOaj9o5BSz9Ym1ejsR7sFh6YPuGsfpDqK3lSUmNRc/x9LU0Jrd8gFxuKAaMLuevL46BHbdYaVnUGKoDYwCi4Be9+hayDp06PXy0WDCn9CMg5j6yf+GE+aeraSLBS1MmJcduDsJeeap5aA8FKu+Ia5vGlgZZw37At1QITVZkVAX0vcgsuwfodR8zdnrECd2up8Fig8FalwrvNP6SBUD8Gfh6waneXuFo+XuzyYHLjrcBSPXMvRKAgfbHxTNMtqOEz1evdS9pAC5CYX9bEuodUxo7rEM6sVBbAvipEw0bPkI8meJ1/CgiZxabLnDVo26Mfw/GEeHt33TtNWuHpcVxqUhSxySHXmapv+frLTltfdmV1eN+UlyDNqoKycbIWkXHTUpc6yAcC6aIQtHfM5uW58gyqtOqKt7DS5rtz/91Sbq5r8RYQgOE3/OK0cQEjNe1wwe2fgc3LIpSQVWUC5coNcl87t0JZGhNR0sr5nnMtaZf5WpebgVcMMySt5mQlRsXNZvpBzHf7cQtsvWhbTyfDeAD6ZOUhw/A60mKxBD859TwPY60CJGCtpeaM0gvBZ57UZ3qlvauT8/WyCTT0QNbfNP/kdUUp7ayvfS5GWxH4zVMFe6XltVCAP8bQ4rWXNw3Uh0XEqRYnb0CvAY0bY6BwHlms1LTdCEsWFIIkMHoG5BlyzzVMcjAaxs0B9ssb9 CTGp0//E 0PZ5t9z9RXm8NkaD+fz58URiW0T5tlHLsN7Isd0CxvHux8iRngk2NEJcJ5twJVbLslyGVh31tpM0r7esLbQosWlN//EwyDK7ABI/XT43Kte3NAm1MLYwn5I9fumab1ygaAEKhG+x4T9cHYH1Wg1aeUvw6ueXz0hU/ymhesuRA2nBvtBfdWLGoeUtvPyeei8z3XNixyX0wM4mq5uiEMlcgqXVhvRu2I9hinm/CZjT01VQ0AcRXekx7eIWCeLmewfjHPTmJS4s6am2mR6gCH9cRmxhvOuTlGQrFt0XLKoa9eJtBpXIBqtT12I/ar6OAGKwPr8EfE16IeQPNEvM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 30 Jun 2023 08:28:54 -0700 (PDT) Hugh Dickins wrote: > On Fri, 30 Jun 2023, Claudio Imbrenda wrote: > > On Tue, 20 Jun 2023 00:51:19 -0700 (PDT) > > Hugh Dickins wrote: > > > > [...] > > > > > +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? > > No. > > All pte_free_defer() is being used for (in this series; and any future > use beyond this series will have to undertake its own evaluations) is > for the case of removing an empty page table, which used to map a group > of PTE mappings of a file, in order to make way for one PMD mapping of > the huge page which those scattered pages have now been gathered into. > > You're worried by that mm_alloc_pgste() block: it's something I didn't actually no, but thanks for bringing it up :D > have at all in my first draft, then I thought that perhaps the pgste > case might be able to come this way, so it seemed stupid to leave out > the handling for it. > > I hope that you're implying that should be dead code here? Perhaps, > that the pgste case corresponds to the case in s390 where THPs are > absolutely forbidden? That would be good news for us. > > Gerald, in his version of this block, added a comment asking: > /* > * TODO: Do we need gmap_unlink(mm, pgtable, addr), like in > * page_table_free_rcu()? > * If yes -> need addr parameter here, like in pte_free_tlb(). > */ > Do you have the answer to that? Neither of us could work it out. this is the thing I'm worried about; removing a page table that was used to map a guest will leave dangling pointers in the gmap that will cause memory corruption (I actually ran into that problem myself for another patchseries). gmap_unlink() is needed to clean up the pointers before they become dangling (and also potentially do some TLB purging as needed) the point here is: we need that only for page_table_free_rcu(); all other users of page_table_free() cannot act on guest page tables (because we don't allow THP for KVM guests). and that is why page_table_free() does not do gmap_unlink() currently. > > > > > or will it be used instead of page_table_free? > > Not always; but yes, this case of removing a page table used > page_table_free() before; but now, with the lighter locking, needs > to keep the page table valid until the RCU grace period expires. so if I understand correctly your code will, sometimes, under some circumstances, replace what page_table_free() does, but it will never replace page_table_free_rcu()? because in that case there would be no issues > > > > > this is actually quite important for KVM on s390 > > None of us are wanting to break KVM on s390: your guidance appreciated! > > Thanks, > Hugh