From patchwork Tue Oct 15 01:33:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13835650 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 2C8A1CFC505 for ; Tue, 15 Oct 2024 01:34:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A14C46B0096; Mon, 14 Oct 2024 21:34:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C2CF6B0098; Mon, 14 Oct 2024 21:34:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83DD36B0099; Mon, 14 Oct 2024 21:34:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 622306B0096 for ; Mon, 14 Oct 2024 21:34:10 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6F50B406B7 for ; Tue, 15 Oct 2024 01:34:04 +0000 (UTC) X-FDA: 82674115608.23.6F13B9B Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf10.hostedemail.com (Postfix) with ESMTP id A8FE1C000C for ; Tue, 15 Oct 2024 01:34:04 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LVy8isbc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728956016; a=rsa-sha256; cv=none; b=mQGkWnYzQSoHcH1ixxP1XyKgwWQ7mZChKOJs4OvRlwsroqSF746nWS/YfFgI5OT6hCyx6H YsA5nxjNyZg7OtcSrDbTrlzgFNImhx9AKfvt2LO37hdiBYK562YMePJ+usgn2e1SBXXweJ WhySV9GA0LR4HmYfqJcn0AcR7zvt0RI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LVy8isbc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728956016; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=axWsqNzIpvlhLR7DqrnxUdvbHKQsISEkZ4mTeZAqu9w=; b=kzVJvEBURtYPYciIQJOEM5OGQZxkCjWThJ+JPzBEIo2TwC7msckIXVN0XPtgvhmRTbfaH4 DpydfVxjBXSip9EcY1z4ouyi0Na+HhsnWTAg9sEFMFsdtzkhzfbFkg9iKsjlFoNBOFeuCP jzb7XdjMz7inMELVRWNmNfK0CBJzXis= Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so4010471a12.3 for ; Mon, 14 Oct 2024 18:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956046; x=1729560846; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=axWsqNzIpvlhLR7DqrnxUdvbHKQsISEkZ4mTeZAqu9w=; b=LVy8isbcxJ5VtL9xxr48R4pAzvfsUloK4mSr6wqAjurcwIXXn4UxVsZGFzUE4Cb9dU Q918qns6qnClj4nuX+LTaoIlbUxMyDHjvOKP2VFjc6aWsoQtNK3olWZGhRm6dw3CWA/q QskIJ2hPxWdXCsswVYwvgMqILy2yOTYr6ZZ6JJcjDYA4qGXmqD/GhwvANUTd9H/94p8V EgqeuPecjo6TdNJqQoeeZ5UcZ2JHf8raemVFu8HkLO7O8hFrQp5/fX2ReoemWHjJY8yq D0pCtVuBfjOoySBMtfiWWDWsxhFa3jBEM+N6JZdy3qXgJYFK3n0AeFJQDMWjuIXEP8pP S0iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956046; x=1729560846; 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:message-id:reply-to; bh=axWsqNzIpvlhLR7DqrnxUdvbHKQsISEkZ4mTeZAqu9w=; b=q0NfaZex75EYHqCnu09nH+gzrdR6Gu8WdohmgeWwUTrLpTVrFT8ziwfZ6lXskj/2Z5 nnSra6IV2jUu2PThkCu9bLWOVFvM+nukyk8xvFd1s2lMcDe41wfcXI7n+Hv5FuoMvAxf 6FlDgNYvu4Pfh0HACQDNxFcVHN9Lgm1lMGFOFP2LARtB5hWNF8XLkPS/3V2Ka+HYW1dr qzhFQqWpPw6A6hiO/PYfgiQiKjVK2nSNCQXsTdxbleY7Ool/XNxICrbBCzOfFs2h0S24 ATK50Ms6P31p9NfzKqjUQUWw/2pLjCbgv/892MLnpKcwzAwpDk1/+TxvCCG+mfIs7nR4 DSMQ== X-Forwarded-Encrypted: i=1; AJvYcCV96uiUacuC88N5JQrvFlKWNmBGby9rhW3mTBtu/pflSMYjl9qwbpJdQI/GwrVNsHFM6d3MQkBuqQ==@kvack.org X-Gm-Message-State: AOJu0Ywo4Pt29usHktrpaij7+M+lQ0U9I0pLeLNgmmH7pQ8QcPRyIquL 1FeGCn6tleSXe/4uzT6vJofHpiwKLRNqJRBPyrcgV2Qj+54nn694647T0g== X-Google-Smtp-Source: AGHT+IG4I/3JRaWO1s0Oc1G3nloW3mFZD9rynaJ4QyFbWI1r3K+RwAKvmgR5I5AwDy8LCEp8stlWhw== X-Received: by 2002:a05:6a20:2d1f:b0:1d8:a899:8899 with SMTP id adf61e73a8af0-1d8bcf561dfmr20114300637.29.1728956046508; Mon, 14 Oct 2024 18:34:06 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:05 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 04/13] book3s64/hash: Refactor kernel linear map related calls Date: Tue, 15 Oct 2024 07:03:27 +0530 Message-ID: <5a4522af03014d41d98809dd58fab57b187e8b51.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: ntzac3srr4kbei49axhayzmwyppea99n X-Rspamd-Queue-Id: A8FE1C000C X-Rspamd-Server: rspam02 X-HE-Tag: 1728956044-436627 X-HE-Meta: U2FsdGVkX1/uXlmxBxqalZEdDchNbVDcPHnI2Yr+kGbpYWknno3il+AFEVdIduBrTndk3gZGGImJA6oJVFjOVSwpn7ydX0duU2pe+VI4zfjWfUcSVkrZWgCOxAdMpEsYNxG7c2YxbLQyrdkVXvBFnEwY5YAc5xxeWCf5qtmyaYgsc5cXpQk9NjQ0OsTmE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XQo+IfEthoN5D 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: List-Subscribe: List-Unsubscribe: This just brings all linear map related handling at one place instead of having those functions scattered in hash_utils file. Makes it easy for review. No functionality changes in this patch. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 164 +++++++++++++------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 296bb74dbf40..82151fff9648 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -273,6 +273,88 @@ void hash__tlbiel_all(unsigned int action) WARN(1, "%s called on pre-POWER7 CPU\n", __func__); } +#ifdef CONFIG_DEBUG_PAGEALLOC +static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); + +static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) +{ + unsigned long hash; + unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + unsigned long mode = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HPTE_USE_KERNEL_KEY); + long ret; + + hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); + + /* Don't create HPTE entries for bad address */ + if (!vsid) + return; + + if (linear_map_hash_slots[lmi] & 0x80) + return; + + ret = hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, + HPTE_V_BOLTED, + mmu_linear_psize, mmu_kernel_ssize); + + BUG_ON (ret < 0); + raw_spin_lock(&linear_map_hash_lock); + BUG_ON(linear_map_hash_slots[lmi] & 0x80); + linear_map_hash_slots[lmi] = ret | 0x80; + raw_spin_unlock(&linear_map_hash_lock); +} + +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) +{ + unsigned long hash, hidx, slot; + unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + + hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); + raw_spin_lock(&linear_map_hash_lock); + if (!(linear_map_hash_slots[lmi] & 0x80)) { + raw_spin_unlock(&linear_map_hash_lock); + return; + } + hidx = linear_map_hash_slots[lmi] & 0x7f; + linear_map_hash_slots[lmi] = 0; + raw_spin_unlock(&linear_map_hash_lock); + if (hidx & _PTEIDX_SECONDARY) + hash = ~hash; + slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; + slot += hidx & _PTEIDX_GROUP_IX; + mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, + mmu_linear_psize, + mmu_kernel_ssize, 0); +} + +int hash__kernel_map_pages(struct page *page, int numpages, int enable) +{ + unsigned long flags, vaddr, lmi; + int i; + + local_irq_save(flags); + for (i = 0; i < numpages; i++, page++) { + vaddr = (unsigned long)page_address(page); + lmi = __pa(vaddr) >> PAGE_SHIFT; + if (lmi >= linear_map_hash_count) + continue; + if (enable) + kernel_map_linear_page(vaddr, lmi); + else + kernel_unmap_linear_page(vaddr, lmi); + } + local_irq_restore(flags); + return 0; +} +#else /* CONFIG_DEBUG_PAGEALLOC */ +int hash__kernel_map_pages(struct page *page, int numpages, + int enable) +{ + return 0; +} +#endif /* CONFIG_DEBUG_PAGEALLOC */ + /* * 'R' and 'C' update notes: * - Under pHyp or KVM, the updatepp path will not set C, thus it *will* @@ -2120,88 +2202,6 @@ void hpt_do_stress(unsigned long ea, unsigned long hpte_group) } } -#ifdef CONFIG_DEBUG_PAGEALLOC -static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); - -static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) -{ - unsigned long hash; - unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - unsigned long mode = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HPTE_USE_KERNEL_KEY); - long ret; - - hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); - - /* Don't create HPTE entries for bad address */ - if (!vsid) - return; - - if (linear_map_hash_slots[lmi] & 0x80) - return; - - ret = hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, - HPTE_V_BOLTED, - mmu_linear_psize, mmu_kernel_ssize); - - BUG_ON (ret < 0); - raw_spin_lock(&linear_map_hash_lock); - BUG_ON(linear_map_hash_slots[lmi] & 0x80); - linear_map_hash_slots[lmi] = ret | 0x80; - raw_spin_unlock(&linear_map_hash_lock); -} - -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) -{ - unsigned long hash, hidx, slot; - unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - - hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); - raw_spin_lock(&linear_map_hash_lock); - if (!(linear_map_hash_slots[lmi] & 0x80)) { - raw_spin_unlock(&linear_map_hash_lock); - return; - } - hidx = linear_map_hash_slots[lmi] & 0x7f; - linear_map_hash_slots[lmi] = 0; - raw_spin_unlock(&linear_map_hash_lock); - if (hidx & _PTEIDX_SECONDARY) - hash = ~hash; - slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot += hidx & _PTEIDX_GROUP_IX; - mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, - mmu_linear_psize, - mmu_kernel_ssize, 0); -} - -int hash__kernel_map_pages(struct page *page, int numpages, int enable) -{ - unsigned long flags, vaddr, lmi; - int i; - - local_irq_save(flags); - for (i = 0; i < numpages; i++, page++) { - vaddr = (unsigned long)page_address(page); - lmi = __pa(vaddr) >> PAGE_SHIFT; - if (lmi >= linear_map_hash_count) - continue; - if (enable) - kernel_map_linear_page(vaddr, lmi); - else - kernel_unmap_linear_page(vaddr, lmi); - } - local_irq_restore(flags); - return 0; -} -#else /* CONFIG_DEBUG_PAGEALLOC */ -int hash__kernel_map_pages(struct page *page, int numpages, - int enable) -{ - return 0; -} -#endif /* CONFIG_DEBUG_PAGEALLOC */ - void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base, phys_addr_t first_memblock_size) {