From nobody Fri Nov 29 16:27:02 2024 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 EB7E41CD2C for ; Thu, 19 Sep 2024 02:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726714607; cv=none; b=Vq6edVUUeDTYha9xZLAqjqpfzuxFBVBjKsX4dQ6MG6aToIFZQuwem2DnQ3HRDs8dnha2zOFp5sVvDBeC1TFR6ykN/W2Z0ruJvJ/4F0pjlvb/uZoFSOSSRYJzT8hyRVDe/Or1ptb0JIj3sbRo01SbIxbw9x+9HyLnT846Pd19YUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726714607; c=relaxed/simple; bh=FsG1hRAQUYRA/vEnlI+7JEFrFUI5bmUaSjg6v6DcwoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JEiy+pCTqcQtjZwy2Xfj1+1jyw0jkM94Hr+f3ymdlXQfncTTa8NYhjUePDxwxnzsBPjFCyl1q4jr4/h3YTR2qRACOCBapOJv2bn1P7kDfB/taLtJQrgJsKB/AdxE087uhnPzRsweTmN2bOiH2aR5KJJQ1CRZ6Ke0r+mQM0Sy68E= 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=f/E+EXOK; arc=none smtp.client-ip=209.85.214.173 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="f/E+EXOK" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20688fbaeafso4765125ad.0 for ; Wed, 18 Sep 2024 19:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726714605; x=1727319405; 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=f/E+EXOKmuJvfkC26qQrLP3yn3K3DQQLvL4Zhxh/sS1zylYG5D1DSeMtmS4SEVsOMk AwoekJYliLtIVE2XVrbNRvftwRibXlwmH/HX/MQZixqg0iugMOuSvFbgjSkWbyQdultJ GTTLB89ezzy4RKTqhhjrVC0VgIk43qU4kIg7XmgANm4hk8MQxaR13/u6/WPNdL1MX2qp hW4JyKl1/G+Y2N6QLuhjOjVoTbUPUVFhzaNCbXMFeI9jrzdynkaV6zlqGyipB15fzLwZ fMO0xnaY+ob4k3p5KRW8Sv0AlSmIIOGnAKhq1lFaqxWMRtQdSYP1VJW60qUTuSmyZT3M X94A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726714605; x=1727319405; 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=Fh77DJcN/FDDNCjHyucXprd/CiOtogXsWxcRSbnek8O3j+3hv35knTppZ7NwlL+Y1M zCRTWzC7M+Hh+IwBUMzyQv9fcI0O1Gvt3mSoyHZPgXVnSWWaYGLvgAHUIM0aK7pE+gdd pNao6uxp8USvFKkITH41p/+wXlXTPYEqo0Uq4ePYziQtGTupuHFQh+hoKOw7miCDbrPg HMdJn6K2kxL91AZh73fQVxhA7sbPOfx1M0Le034xmZfpnvw3bTlizUy3JjqeA1r+GDtB HttVu8MQg78eA+taQmt3U9/DAVCARXmhJJV1/e5Ui5pBrp22mZy9FWB0fBJf3TEcdCxZ hCFg== X-Forwarded-Encrypted: i=1; AJvYcCU9FWaiHssgMKIHjPsTeON5akjUAjFiQ/pIVxW0BJan3kpHdJaCJWAhn3WT3pftoXiyvL6O75ASAxKmcHw=@vger.kernel.org X-Gm-Message-State: AOJu0YwlRsMMDI6zlI26CW0SAVXO2Vbz3atjKBm1tO4HNaXLhMrCAWPg RCsCpjv14lbgp9r9u/Q4EmMZPcJCx89f5H5XdTEKx//xwU5mmPGx X-Google-Smtp-Source: AGHT+IHA1Q2JlW37EA2VKdDDVikQbbi1MnJIFVGu950hUG+dA+q41WmFWBJe/jOOl1HWU88lYqBIzQ== X-Received: by 2002:a17:902:d4d2:b0:206:f065:f45d with SMTP id d9443c01a7336-2078252bd1emr238945975ad.31.1726714605103; Wed, 18 Sep 2024 19:56:45 -0700 (PDT) Received: from dw-tp.. ([171.76.85.129]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-207946d2823sm71389105ad.148.2024.09.18.19.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 19:56:44 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , Nirjhar Roy , LKML , kasan-dev@googlegroups.com, "Ritesh Harjani (IBM)" Subject: [RFC v2 04/13] book3s64/hash: Refactor kernel linear map related calls Date: Thu, 19 Sep 2024 08:26:02 +0530 Message-ID: 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