Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp225149lqp; Tue, 11 Jun 2024 02:34:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX4srYJPdQ9ZkqQNvnXc0Lzw84yK/J02lth7H0XzjFDdzR7qaBE5u6b7e7/UV927/Yf1m8Va0LOvfkPxv/NVJyLqH4UbkGPL+vRQuzOgQ== X-Google-Smtp-Source: AGHT+IGEHHj1MVOtjjFEar0NJmhsy7lS7HK+WH1dVSMGIyyZGhzSEjxr5FrS5X17ZWLJu678PzS8 X-Received: by 2002:a05:622a:256:b0:440:5eed:890b with SMTP id d75a77b69052e-4405eed8adcmr94910871cf.15.1718098477810; Tue, 11 Jun 2024 02:34:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718098477; cv=pass; d=google.com; s=arc-20160816; b=j40TN5IHtT+wHjFSlIziYlrpn2Twbq4epgHg6HCu+gn234siQcYh1dqPExpnF+BfyT rp53DnPnv4QgV9gnocf+TkD2Ta29YbnGSgONE3ODjdZwyogWbzjDO6yZA1mp07JFe+44 nzeqRd4byhVaT6uJIS70A7tBSHnYF5BiZUjKqZCQGVqN23HUDTxq3abw61HJS05fmvag U5/kZML6K0kFShKkQA72ZNeuJstL1kBo950eZEnSrlzRWt1vuYlwgxghNiIZvlfNtRwk uGH6eJOz6+KYzhWdZ8udOt/PjkhjH76uD/cErAteEV7BHPJ3cZjoyaqgHN3GiTew/Y9b nKWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=bXl9G+kh6CJWJjfSYdY3mI/mE/xXvq102BbFQ15gmgk=; fh=7FqQY95/6dNosXCjFkEopk0YDb4YCNocz5tbx4U0IiY=; b=eG/ImIZSJnO61+PjFwWtxmLGgcXIgSzkH00hKHjb9Sa9q7F7ZJ1m+sT7oPGjUhwuP6 iEIGQzKB9oQIP/XSPsMdyqSbOP3G56jow9jHvFiZsl+HWkAw0kb7ulefjBEjZ7rUwKeZ IX1LjcO8z37UpziLooGyptbnf3w3wu3IyoycLLIRDAxm4puA3NTHr9wlqX5t28mLPkVg Y3PTaMgFysiLbV/Hq+hP3ZT6NxA/e+smcSH+9WZcstSCAEj81LCw3UmUm7i7lhnwH52u Yagr0BJyb8EmstIUdDOBypTFV2laf9plccjHnVUlVp4dAtTksohsMfrKlCkIJtjvHCnY l/QQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1h9kfKoU; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1h9kfKoU; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-209578-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038b62833si127530971cf.591.2024.06.11.02.34.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 02:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209578-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1h9kfKoU; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1h9kfKoU; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-209578-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 74D9F1C21179 for ; Tue, 11 Jun 2024 09:34:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87DD52230F; Tue, 11 Jun 2024 09:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1h9kfKoU"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Wyti0idM"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1h9kfKoU"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Wyti0idM" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAE891BF2A for ; Tue, 11 Jun 2024 09:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718098468; cv=none; b=VIB2KizszWRfJYHjM4DstMe7AGXvXXbVRBDbUqdxXNJKmnX4Mdp99a3Lv8vaERGVA/GLTBEU8HohfAu3EEElNCWHPgFPUb5NjrnxdvdFlCBjJWqzXkKXskd76ITn90Kj72zk5gXL5k6uek2GyOkQMwdPqzCweDUK5qFisYWn3Ow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718098468; c=relaxed/simple; bh=039KEOjJTO3YVS9SW6PakeGw3N0m3XJPvPkiVlagfm8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z1Tfui3JjGxRTZE/wim9tQiPZRl5FXmF6nk9YdlW4b7MLwHHfXS6ZI4RFWZyQoQDx8NZVY1wYKd2/ZD7b92Npi7wNc3I9ACG9EWlcCCqszB+2tYn2QQnNSg2bTqhjtJaQ7xanHAXhW/OF+P7d5cmh1vv+86cBAGQFsINO3+FuK8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1h9kfKoU; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Wyti0idM; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1h9kfKoU; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Wyti0idM; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2FB9133686; Tue, 11 Jun 2024 09:34:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718098465; h=from:from:reply-to: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=bXl9G+kh6CJWJjfSYdY3mI/mE/xXvq102BbFQ15gmgk=; b=1h9kfKoUjzUX7Pg0FYO4/Hn86ca25G+Dw0AJG6LeaEH4SJ+Pr27qT5mX6xNgxC6+O6nlft br7k3/K0BFcSDett6c63kGZre4r1PJdSH5PsMsFXqyiITD7SPqMSS1uvPAn4oCFafdgeLW Px/kUM1cWdNYU4YVxTTrQ2a7A0yPIFM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718098465; h=from:from:reply-to: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=bXl9G+kh6CJWJjfSYdY3mI/mE/xXvq102BbFQ15gmgk=; b=Wyti0idMR4rKs3LoThTM+Y8V0nVad7j2jppVkPhnwFxzg/7HdB6YPRlKnU0DR4KISNMvTk 44kaEKvNEVIr0MBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718098465; h=from:from:reply-to: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=bXl9G+kh6CJWJjfSYdY3mI/mE/xXvq102BbFQ15gmgk=; b=1h9kfKoUjzUX7Pg0FYO4/Hn86ca25G+Dw0AJG6LeaEH4SJ+Pr27qT5mX6xNgxC6+O6nlft br7k3/K0BFcSDett6c63kGZre4r1PJdSH5PsMsFXqyiITD7SPqMSS1uvPAn4oCFafdgeLW Px/kUM1cWdNYU4YVxTTrQ2a7A0yPIFM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718098465; h=from:from:reply-to: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=bXl9G+kh6CJWJjfSYdY3mI/mE/xXvq102BbFQ15gmgk=; b=Wyti0idMR4rKs3LoThTM+Y8V0nVad7j2jppVkPhnwFxzg/7HdB6YPRlKnU0DR4KISNMvTk 44kaEKvNEVIr0MBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A858413A55; Tue, 11 Jun 2024 09:34:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Jbt2JiAaaGapdAAAD6G6ig (envelope-from ); Tue, 11 Jun 2024 09:34:24 +0000 Date: Tue, 11 Jun 2024 11:34:23 +0200 From: Oscar Salvador To: Christophe Leroy Cc: Andrew Morton , Jason Gunthorpe , Peter Xu , Michael Ellerman , Nicholas Piggin , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH v5 02/18] mm: Define __pte_leaf_size() to also take a PMD entry Message-ID: References: <172b11c93e0de7a84937af2da9f80bd17c56b8c9.1717955558.git.christophe.leroy@csgroup.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <172b11c93e0de7a84937af2da9f80bd17c56b8c9.1717955558.git.christophe.leroy@csgroup.eu> X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_TLS_ALL(0.00)[]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[linux-foundation.org,nvidia.com,redhat.com,ellerman.id.au,gmail.com,vger.kernel.org,kvack.org,lists.ozlabs.org]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -4.30 X-Spam-Flag: NO On Mon, Jun 10, 2024 at 07:54:47AM +0200, Christophe Leroy wrote: > On powerpc 8xx, when a page is 8M size, the information is in the PMD > entry. So allow architectures to provide __pte_leaf_size() instead of > pte_leaf_size() and provide the PMD entry to that function. > > When __pte_leaf_size() is not defined, define it as a pte_leaf_size() > so that architectures not interested in the PMD arguments are not > impacted. > > Only define a default pte_leaf_size() when __pte_leaf_size() is not > defined to make sure nobody adds new calls to pte_leaf_size() in the > core. Hi Christophe, Now I am going to give you a hard time, so sorry in advance. I should have raised this before, but I was not fully aware of it. There is an ongoing effort of unifying pagewalkers [1], so hugetlb does not have to be special-cased anymore, and the operations we do for THP on page-table basis work for hugetlb as well. The most special bit about this is huge_ptep_get. huge_ptep_get() gets special handled on arm/arm64/riscv and s390. arm64 and riscv is about cont-pmd/pte and propagate the dirty/young bits bits, so that is fine as walkers can already understand that. s390 is a funny one because it converts pud/pmd to pte and viceversa, because hugetlb *works* with ptes, so before returning the pte it has to transfer all bits from PUD/PMD level into a something that PTE level can understand. As you can imagine, this can be gone as we already have all the information in PUD/PMD and that is all pagewalkers need. But we are left with the one you will introduce in patch#8. 8MB pages get mapped as cont-pte, but all the information is stored in the PMD entries (size, dirtiness, present etc). huge_ptep_get() will return the PMD for 8MB, and so all operations hugetlb code performs with what huge_ptep_get returns will be performed on those PMDs. Which brings me to this point: I do not think __pte_leaf_size is needed. AFAICS, it should be enough to define pmd_leaf on 8xx, and return 8MB if it is a 8MB hugepage. #define pmd_leaf pmd_leaf static inline bool pmd_leaf(pmd_t pmd) { return pmd_val(pmd) & _PMD_PAGE_8M); } and then pmd_leaf_size to return _PMD_PAGE_8M. This will help because on the ongoing effort of unifying hugetlb and getting rid of huge_ptep_get() [1], pagewalkers will stumble upon the 8mb-PMD as they do for regular PMDs. Which means that they would be caught in the following code: ptl = pmd_huge_lock(pmd, vma); if (ptl) { - 8MB hugepages will be handled here smaps_pmd_entry(pmd, addr, walk); spin_unlock(ptl); } /* pte stuff */ ... where pmd_huge_lock is: static inline spinlock_t *pmd_huge_lock(pmd_t *pmd, struct vm_area_struct *vma) { spinlock_t *ptl = pmd_lock(vma->vm_mm, pmd); if (pmd_leaf(*pmd) || pmd_devmap(*pmd)) return ptl; spin_unlock(ptl); return NULL; } So, since pmd_leaf() will return true for 8MB hugepages, we are fine, because anyway we want to perform pagetable operations on *that* PMD and not the ptes that are cont-mapped, which is different for e.g: 512K hugepages, where we perform it on pte level. So I would suggest that instead of this patch, we have one implementing pmd_leaf and pmd_leaf_size for 8Mb hugepages on power8xx, as that takes us closer to our goal of unifying hugetlb. [1] https://github.com/leberus/linux/tree/hugetlb-pagewalk-v2 -- Oscar Salvador SUSE Labs