From nobody Wed Nov 27 02:34:45 2024 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 490E017335C for ; Tue, 15 Oct 2024 01:34:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956048; cv=none; b=oQP5BbgsoEFnd9ReucCovC+qpyy8FUlH3xlQWu8YrFTwA9nEgOYv/DH2S3Lcnj6FV5zItPn6yhqWcVMhE55IU1/era8B6ETM+rowtwlIKBpcgAQsV+lgsyNpWafgiQC92BAHp2LZ+GCdkB1EHuNlQr/FfWrrZ2GpfcQEXio1klg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956048; c=relaxed/simple; bh=FsG1hRAQUYRA/vEnlI+7JEFrFUI5bmUaSjg6v6DcwoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OEMdYLosoddJEIVGFW499NJbMiYrv6J/XqQfruislSdx1qeRzAu3ADEMMrC4KH1l4l7V3xyB57Rf8sCHV0b7sJaDb+5YBWQtM28L0LM1iHAN5QZT6u65T1tWf/uteFXW8/SFluHaESpsHlfdVz5MVktilhaeLOUE9/nlkZ/MNQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ek00m7W4; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ek00m7W4" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7ea76a12c32so1815214a12.1 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=vger.kernel.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=ek00m7W40mLApXCFYCdZiCe+U/CvuqRpi1N+T3rlsTLud1VSHUk6qeaJVCnV4uWH12 CvDlavMfDrtRgV80JC7K0PgJCfdAMXKtsP4XoC14BPIq2s5zUwayi6C714RpYrOTBT24 5FJNcvlMuL4hfQDMjHXHOVZHxxBd8CbFVlMyKPEjlKXZmWWgOLAb5+b1UghcSecdKbLI 6llwnAevU/XOanGmS0w3tgdlkniSvgmJeSYlFR9xvMxUHoJ6pgMI82j+zoG0jTr1uRfF T/A1qYBjs9yan/gdRRRVZj0Lf2mA4Id3C2GpKsnImwC2msq75qdskgLSHpauTqsHSvq0 CKdw== 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=Mds5w0DnBK4fJUPFZ5zOkiYgzgiZyInEH4oNfDETGcizwkQtGpS7NkjptikyTnVxP3 0qwkKIEGSVph9toTl6UifSiN3V9VXJ5IFkgiNgtHqx9QoGjQ+1e++LQQAyrkfNBqkzeg RSDVBnU+30sr4UDwJHIjCCcJFGzy7b4rXwmIwg9NhrbhFeOKAMZ++1I8Bj4O2Oufzbg6 LyR+IIYwD04MTawN1th0yvtrHd5FIBgTNv1eV5PSv/5DKg36STPxSvtkRlZLtZmil8xq WN4+zAm8sQTgrFgkOIbMSC8TL4gGfb+zSwA/J5+zoMsoMYslAhR5xN4UY6DkQ1bgeR7P ucbw== X-Forwarded-Encrypted: i=1; AJvYcCUF0O9ITZLttZ9fKyHoSbq4LGG0HGSLgBk//XxmMNRln3jhr/tYFWoVq/Kws7D60IKIuegu4SLjyEjogkY=@vger.kernel.org X-Gm-Message-State: AOJu0YyxqNYRxaGZ0EcdZuQYXx946JddBAZFTIQK1VoD60drRYAnDUhV CW58Uc7pDAXPOvKD6GGPkgcZP0VxnnS73WtQw/o+u4bVh3qAnh3P 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/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__); } =20 +#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 =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + unsigned long mode =3D htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HP= TE_USE_KERNEL_KEY); + long ret; + + hash =3D 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 =3D 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] =3D ret | 0x80; + raw_spin_unlock(&linear_map_hash_lock); +} + +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lm= i) +{ + unsigned long hash, hidx, slot; + unsigned long vsid =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + + hash =3D 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 =3D linear_map_hash_slots[lmi] & 0x7f; + linear_map_hash_slots[lmi] =3D 0; + raw_spin_unlock(&linear_map_hash_lock); + if (hidx & _PTEIDX_SECONDARY) + hash =3D ~hash; + slot =3D (hash & htab_hash_mask) * HPTES_PER_GROUP; + slot +=3D 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 =3D 0; i < numpages; i++, page++) { + vaddr =3D (unsigned long)page_address(page); + lmi =3D __pa(vaddr) >> PAGE_SHIFT; + if (lmi >=3D 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 h= pte_group) } } =20 -#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 =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - unsigned long mode =3D htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HP= TE_USE_KERNEL_KEY); - long ret; - - hash =3D 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 =3D 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] =3D ret | 0x80; - raw_spin_unlock(&linear_map_hash_lock); -} - -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lm= i) -{ - unsigned long hash, hidx, slot; - unsigned long vsid =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - - hash =3D 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 =3D linear_map_hash_slots[lmi] & 0x7f; - linear_map_hash_slots[lmi] =3D 0; - raw_spin_unlock(&linear_map_hash_lock); - if (hidx & _PTEIDX_SECONDARY) - hash =3D ~hash; - slot =3D (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot +=3D 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 =3D 0; i < numpages; i++, page++) { - vaddr =3D (unsigned long)page_address(page); - lmi =3D __pa(vaddr) >> PAGE_SHIFT; - if (lmi >=3D 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) { --=20 2.46.0