From patchwork Fri Oct 18 17:29:48 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: 13842089 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 C0891D3DEA0 for ; Fri, 18 Oct 2024 17:31:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FFC46B0082; Fri, 18 Oct 2024 13:31:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4887E6B0083; Fri, 18 Oct 2024 13:31:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3291E6B00A1; Fri, 18 Oct 2024 13:31:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 11DFE6B0082 for ; Fri, 18 Oct 2024 13:31:00 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0413F1C6191 for ; Fri, 18 Oct 2024 17:30:45 +0000 (UTC) X-FDA: 82687413186.15.FF46108 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf25.hostedemail.com (Postfix) with ESMTP id 0EFD9A0029 for ; Fri, 18 Oct 2024 17:30:49 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nCBbwVPo; spf=pass (imf25.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272583; a=rsa-sha256; cv=none; b=oe/85ygahj2+WP7YvURLj7khtLGhbCUea6BXgazyyalpuakNzumQHOZl3VU7/G38N2qYiN sBB2NCvVoVACLzEzi/FSHLyyO1aT++DsyNKLnFl3R1D+anuEKiSKY/+fEf+n00HemiQkwy IY7/xuOQP532ZcUGi2E7brWiHihOxlU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nCBbwVPo; spf=pass (imf25.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272583; 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=SYv3qxbJ8XzSYVM3O5y7o2xiEmCUj8b+8LHRXlL50QE=; b=l9z3fys1nwWmD+Eb1G38xdzGuJnc3uZAViWgnDxEKqXJyHKB0tTGB9RWX2195RgAhLcjox rB/+DzU2xBVV+flRqN5SWbJybysXWnyxpP2ytlAcdnogJdrkoFjVMVaWzzOp/cjQD8g7z7 A/7KnnUvkyUPbJwbuRpTvz0xqS1mg0k= Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7ea784aea63so1301514a12.3 for ; Fri, 18 Oct 2024 10:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272657; x=1729877457; 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=SYv3qxbJ8XzSYVM3O5y7o2xiEmCUj8b+8LHRXlL50QE=; b=nCBbwVPoOK7LHMPFekvf9pmHPfomgnHbR+A8PIzml6tYPvhAstOh+llKWTW3FpWbKm MNJDHkZJHjroLShK4n6zyWTDdZvyXCI9IeJUS231AsHaoawyPvkhDi0Kj8xcOtdII+wh 3gpXZ9KBcsLDxQkup+UYTi+zld1wL8EIo8NwqtvWxKkj5RmnuDEgdqI15qsORZncQGB3 shCdc6h67HCjf/1FExR8Z9WMyAJ94u2MeGzvFHj+XSlQYPhwt98xJAAZ84yHRtBS9bgz JF5qVRpre3HnRZ2tYloxpHygX5cjPRs2FqpW3z3jKErfszA+7+zfADACUdej0oDQTier VhgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272657; x=1729877457; 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=SYv3qxbJ8XzSYVM3O5y7o2xiEmCUj8b+8LHRXlL50QE=; b=XZEodEELJeo7nlawbLFxH6xO93Ke9nyEYCH7UmTD97OOd4LQOunku9ti6m6ZXEaCqD LVqbu11PnOZqsOO7dWAZbFixiuXdeLktbbgYG8M+pFgGUa/EGyWi+KHQ3PbP7BjK0fwA WASzzakZWeRtBQ64bTvnHZiFojIo8bm4OD3S4krG7Ec8qfdWWJuT56lTCgKpifzD4BJa pGNPgEyqCoiGozgj6KM+JoGhPBtAIfugAZjY1gkuuEuJV7P2p+p/PPCcPeZrkN8d/d+T r4qTc2Qbf/3OJlCuevwvMTA+au/IqUR4CN2OQuVr58uwHKUFTfJ+0FlxG/A/cJZUIUfm EBow== X-Forwarded-Encrypted: i=1; AJvYcCXHoHxDCKXeM+KqgIu2kk8IWs9B+7tC1fDnrFzysq8h3er+Dv4pbG7KqWz61ZDDexQMHzxvgHQDxw==@kvack.org X-Gm-Message-State: AOJu0Yy5LAtObKiT3e+ye6xbiIso1IdEffbJO8W6i8Z2wHwIxVp56P/d SxfeBU8Kwrh0D3LIVgP8FbXXU2iIKtoxfHK/u7GqRQ+REDXf3pgC X-Google-Smtp-Source: AGHT+IGzdUgXGWS3Rnfne00N0lzoqmJmv13oE/GEcsOOigglv7dM20Xc4zaopt4Axws81Q8JXv67zw== X-Received: by 2002:a05:6a21:a4c1:b0:1d8:f1f4:f4ee with SMTP id adf61e73a8af0-1d92c4baaaemr4986521637.8.1729272656623; Fri, 18 Oct 2024 10:30:56 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea3311f51sm1725242b3a.36.2024.10.18.10.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:55 -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: [PATCH v3 07/12] book3s64/hash: Make kernel_map_linear_page() generic Date: Fri, 18 Oct 2024 22:59:48 +0530 Message-ID: <5b67df7b29e68d7c78d6fc1f42d41137299bac6b.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: k6dzbxays561neio1u1kf9hocp8ckrod X-Rspamd-Queue-Id: 0EFD9A0029 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729272649-900658 X-HE-Meta: U2FsdGVkX193uBHu8HRBhBNJMfQtBOaV9xNy+SioOV2obam1U550j5P8sLZO8sdZPieJ5AvzNtKBf5gXNDPPDO75oz0FCuCg/e7+mqev9Y+qhTbPnnDXBFcth09JIkgJ/udTRilS+zO2oeRwico5V0aUbWa3Wfy21a8xKoUi/z/zGl/bWJwKiVNkIWDtJVtuCF7czP/UWIKgvvAOvPk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YgkE/a2xRlcOBikpQQrwXLOg3MQHdb6kRmxtFWC3MvD3CukFuFc0XajCm0iql8DOzQ== 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: 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/book3s64/hash_utils.c index ab50bb33a390..11975a2f7403 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) } #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 = 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; - if (linear_map_hash_slots[lmi] & 0x80) + if (slots[idx] & 0x80) return; ret = hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, @@ -298,36 +295,40 @@ static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) 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); + raw_spin_lock(lock); + BUG_ON(slots[idx] & 0x80); + slots[idx] = ret | 0x80; + raw_spin_unlock(lock); } -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long idx, + u8 *slots, raw_spinlock_t *lock) { - unsigned long hash, hidx, slot; + unsigned long hash, hslot, 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); + raw_spin_lock(lock); + if (!(slots[idx] & 0x80)) { + raw_spin_unlock(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) + hslot = slots[idx] & 0x7f; + slots[idx] = 0; + raw_spin_unlock(lock); + if (hslot & _PTEIDX_SECONDARY) hash = ~hash; slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot += hidx & _PTEIDX_GROUP_IX; + slot += hslot & _PTEIDX_GROUP_IX; mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, mmu_linear_psize, mmu_kernel_ssize, 0); } +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 >= 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;