From nobody Fri Nov 29 16:48:07 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 67F6D2746C for ; Thu, 19 Sep 2024 02:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726714626; cv=none; b=nP6gxWyN7lSM9Hkq8KFiE1MtAA889+TodljFkbyYrt2bCn1MZJSapL7R/3i0IFYta81lPjJoU0PGtobGWx3NzBK91y1WYRyUG15Ld6Yb1NkhM583OFLShf7+eFkMdvLPBHsmBvglYN3WhFxUlf1qetm3Do3H/t8KtLyXdJSCsCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726714626; c=relaxed/simple; bh=R968dba8OE7cCpOttgpeILQbdzMZ+6PWqhvC1JS2Eaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N/ucsEzbdUS1ZK8gcdP7Q8BfAEvppYWwuqyNNLzIvBRZnYQHnwjrzbXaXwRzrjW7nqEtjVcNcWSIsLzylvEVujWqDKQZTsR3s6PDr1yIaer64xVb7YsCbzhvfISOryrbcq8GMdJsjOvTFHnifELwYetjrqxWSY/5PI4SiGoCDQ8= 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=br5qtc9g; arc=none smtp.client-ip=209.85.214.175 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="br5qtc9g" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2057835395aso4875385ad.3 for ; Wed, 18 Sep 2024 19:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726714624; x=1727319424; 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=ww6ZbzhcNbPuRWG0GzwKnAEreEL780mKVa0cmRg0+f0=; b=br5qtc9glKdvd1LpRpBgryge7vQoBf4X54SmlekMMj1jWwdP2NyKxVSkc2BZ3If6kv Z8X0No8MApOmmbt9cQu1yvk8WBrDNqSLbaTIMAL/Oe8NhDXCzte04J3NRM2uoNOnogZe vHucmb7x0pNisU6i3uQCPtDDU3wLaeZAxcq/hnkB4XlAg+7cXdspkEE683Khl7vMunVp CQQEA7ObuXyMBNYFtjZwCsdDsHvBCAoLxSHIsAK3AbLK7mIpqGWOt9Na0OFXsIbLZ+nc 7NXwMtGQx9tzKA6VTOQ1v65wemjUAT5WpG/X9e+bLWXnTana/gKGwQHCJF5iY/Zc3tyG 1qOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726714625; x=1727319425; 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=ww6ZbzhcNbPuRWG0GzwKnAEreEL780mKVa0cmRg0+f0=; b=OKYIMv3aX3uSchnbFVblhpXpyLdZ75kkjiZdhKrgw3NughqI0e9FQxngcztXPMLebq MHjXjgrt+YVAOW5R/6xJN0QpFNlwvMA5j1wbbkt3QaXLdLVspzkKw9RmPFdwnF/7R584 atojdpmppGvZmkTwvEnXnbTPAE/YW0j0S8NyPGx4Av1woVYJlM1kMiUVAaz2pQhLIOCJ z4AnqbPulvcyGV91lWIiuuGIOvJNPDhJjYSn0RINrAZMMRKTMgsbaikiZoHPuxEes9IR Xhu/wU9eAzSsog73yJUQSITngXY3aGiKnTlqUbCYujZdMIUawfZBYN0K1Gh6IhBA3k8E cH4Q== X-Forwarded-Encrypted: i=1; AJvYcCXqmycqKt7Jl/lpi0bUJMpDst8lhA63uxfr7QES4qKLb30p6dtMj9Qbh7CANRNfHSHb2Gv89HS7Gmy7mlY=@vger.kernel.org X-Gm-Message-State: AOJu0YxskdjmHC98t9wUqctdGtq731f9cOwAOflrMVy3ndiEhPzpGdPA Hm01N7QIyau2URlHd9QBuP2Kb+FF1xLjmKdkS4w3++BGoeUuiG2a X-Google-Smtp-Source: AGHT+IEGqIOz4HsQttBODX4offSohXpn6nX19SV5HvK4k8qFlVoDJsalsJ6Y9uSYNEbB3JibzB2xxg== X-Received: by 2002:a17:902:f689:b0:206:96bf:b0d6 with SMTP id d9443c01a7336-2076e41703amr412516255ad.51.1726714624534; Wed, 18 Sep 2024 19:57:04 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 19:57:03 -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 08/13] book3s64/hash: Make kernel_map_linear_page() generic Date: Thu, 19 Sep 2024 08:26:06 +0530 Message-ID: <8d06f263a903b5867fb23c319c4ddf7db7b7a431.1726571179.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" Currently kernel_map_linear_page() function assumes to be working on linear_map_hash_slots array. But since in later patches we need a separate linear map array for kfence, hence make kernel_map_linear_page() take a linear map array and lock in it's function argument. This is needed to separate out kfence from debug_pagealloc infrastructure. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 47 ++++++++++++++------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s= 64/hash_utils.c index da9b089c8e8b..cc2eaa97982c 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -272,11 +272,8 @@ void hash__tlbiel_all(unsigned int action) } =20 #ifdef CONFIG_DEBUG_PAGEALLOC -static u8 *linear_map_hash_slots; -static unsigned long linear_map_hash_count; -static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); - -static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) +static void kernel_map_linear_page(unsigned long vaddr, unsigned long idx, + u8 *slots, raw_spinlock_t *lock) { unsigned long hash; unsigned long vsid =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); @@ -290,7 +287,7 @@ static void kernel_map_linear_page(unsigned long vaddr,= unsigned long lmi) if (!vsid) return; =20 - if (linear_map_hash_slots[lmi] & 0x80) + if (slots[idx] & 0x80) return; =20 ret =3D hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, @@ -298,36 +295,40 @@ static void kernel_map_linear_page(unsigned long vadd= r, unsigned long lmi) mmu_linear_psize, mmu_kernel_ssize); =20 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); + raw_spin_lock(lock); + BUG_ON(slots[idx] & 0x80); + slots[idx] =3D ret | 0x80; + raw_spin_unlock(lock); } =20 -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lm= i) +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long id= x, + u8 *slots, raw_spinlock_t *lock) { - unsigned long hash, hidx, slot; + unsigned long hash, hslot, slot; unsigned long vsid =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); =20 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); + raw_spin_lock(lock); + if (!(slots[idx] & 0x80)) { + raw_spin_unlock(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) + hslot =3D slots[idx] & 0x7f; + slots[idx] =3D 0; + raw_spin_unlock(lock); + if (hslot & _PTEIDX_SECONDARY) hash =3D ~hash; slot =3D (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot +=3D hidx & _PTEIDX_GROUP_IX; + slot +=3D hslot & _PTEIDX_GROUP_IX; mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, mmu_linear_psize, mmu_kernel_ssize, 0); } =20 +static u8 *linear_map_hash_slots; +static unsigned long linear_map_hash_count; +static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); static inline void hash_debug_pagealloc_alloc_slots(void) { if (!debug_pagealloc_enabled()) @@ -362,9 +363,11 @@ static int hash_debug_pagealloc_map_pages(struct page = *page, int numpages, if (lmi >=3D linear_map_hash_count) continue; if (enable) - kernel_map_linear_page(vaddr, lmi); + kernel_map_linear_page(vaddr, lmi, + linear_map_hash_slots, &linear_map_hash_lock); else - kernel_unmap_linear_page(vaddr, lmi); + kernel_unmap_linear_page(vaddr, lmi, + linear_map_hash_slots, &linear_map_hash_lock); } local_irq_restore(flags); return 0; --=20 2.46.0