From patchwork Wed Feb 14 20:44:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 201119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1489080dyb; Wed, 14 Feb 2024 12:46:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUvR9ffuGgTEZMbFP+q2JUE100jH5Ud63nWvLgBZqklAhMHO42yXxAf6Ile55vPqZhnrE62uqvwV+NsIhDWKCnMTlYR4A== X-Google-Smtp-Source: AGHT+IFbB+9/6Gsm7CuDqdIcGtt+3ypX0Qp6LBT0YCdXFRco7DzvUU5dSn5AZBC3LKrJ2Nc/Ws7x X-Received: by 2002:ad4:5cc3:0:b0:68c:a85a:9f69 with SMTP id iu3-20020ad45cc3000000b0068ca85a9f69mr4707438qvb.15.1707943614296; Wed, 14 Feb 2024 12:46:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707943614; cv=pass; d=google.com; s=arc-20160816; b=X3YR7QggjtaIJUqSFWEf6WjmhYIdmkESofhHYZLLiLK2VjWHNXZ08AdW4XwZSBlL1G x8nWB4kW81erVIG0ya9k/sF8G96u+fAmbboWYf3greNDRMx8RLPBf0SKznmjfZSw87Cg LhXt+do6HahgSmeltu8QInqHqUZ1dfvbpGHOPln6eQjrQRpiLp3ulUpPgyd+vzRCJsFk aLEAlVShN7E+a/p2m5c9QuRgMWHrhPdK0t80wtvfX+X1BByrqQ23g4THXlAvLVeabHjS wYRGEFJNFYb0EekZ8Q1DTJbJtxeLn8526qfqsJd1MojHUPsbq379AbCJ3GOJl2xc/5wM sWjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=X4BN9bDZrrapc7Xd1FDfmQmuEZxXG5tNILRPdL9R2lg=; fh=qM5WU//Ax+zqtHcjD3ii9JYU2NrMVe7mr1He8PcXObg=; b=y5FTX1ec4TQ9p0Cl3ukXlnw8UBrCTbaS3mkNtQXzGObAoz5QBFBvUwT+kiMvMVlxRT eP7HEVZ/70JkBK4TGPslNNC3tTDBvWY9sgryzebpawFAGsaPc0m9UfwyBNXMsCweLafQ oi+y9bZ/lK1G5u1fD9wzr5kQRoWxFXQxO7O1vlzNeObGSwEKSrDGPZ20BTqa6AvbnD8f ulP03uT8km0NOyXOAjEAmS39jtqvPUbRhxsYso9RLh71GCb3ez2FmPOCH7oEDdDuF03X yNMAz52Fa6TD8NpOGwur2uoz7SnCwzyrOzZnbY3/MoLiHHWlsZOGcFt6gPy4Y0/w4TCv Q6Qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zd5fCEfy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-65953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65953-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXnmL5f9SxWHVcfPw2GItG/+ZD/BS6Q4NDtcuwUrbYvrcG860kBXPLTQHQgY7cP8/nMRAV3JBHmnBzmehqnvK/iUzKNVQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jx14-20020a0562142b0e00b0068ed5efaf47si5392182qvb.244.2024.02.14.12.46.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 12:46:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zd5fCEfy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-65953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65953-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1B42E1C2099E for ; Wed, 14 Feb 2024 20:46:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 498ED13F000; Wed, 14 Feb 2024 20:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Zd5fCEfy" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4388E1420BD for ; Wed, 14 Feb 2024 20:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707943517; cv=none; b=Pqw2pr8pb+eZNLOMXyiLSfteGtB1TQvBSkwUHh5Zyrv+xo/l9vLB2m+ANVHA0XnZUrU7O14aE3i+9FnlteZh3FUpyHp43K4+hZLkMrHXFbOiEZyn0z0kxsjfIXm5QhQHjSzhtmGv/IpIeRjIxMHXGYYF7E1a4lGkvNK++o9y7dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707943517; c=relaxed/simple; bh=3PQfbTkS/vd68uh/N1+tvV3UXJ8B0ItANJG44cGwxXU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qx0nlfygZ840Ax1qqpPidkPxGyppbw7w6XCiWfcJ2Of+cwzJ0lZV4oYCLqYVP3VARZwJXOWHOLCjoUJvx501lA1TlLDVqqyjmZHApo/i5JDgF6ON5mwFWdBG19NrC/1UXTi1fDftYfX7lPNBH59w5VyRUqbROkiuSdt42Ds2UOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Zd5fCEfy; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707943515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X4BN9bDZrrapc7Xd1FDfmQmuEZxXG5tNILRPdL9R2lg=; b=Zd5fCEfyBfpu+FQ/1A82MOcZyIcWwqwMQVk9sVixLzuQ7mXDOJTMt5plnz+favBpSl/HD9 qB1X78F0GEPUL7oOIjCDoHE5rShqYP0TSfq4ptFvPjkgbgZAhQpq66QqlFDHG5cV+GnU85 +yp9au8rEpKzytB2V1u3JxIOlfVVQxs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-D3IZQFsSNhyFuV3-aH76jg-1; Wed, 14 Feb 2024 15:45:09 -0500 X-MC-Unique: D3IZQFsSNhyFuV3-aH76jg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6ACBD811E79; Wed, 14 Feb 2024 20:45:08 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.174]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3DCE1C066A9; Wed, 14 Feb 2024 20:45:04 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Ryan Roberts , Catalin Marinas , Yin Fengwei , Michal Hocko , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org Subject: [PATCH v3 07/10] mm/mmu_gather: add tlb_remove_tlb_entries() Date: Wed, 14 Feb 2024 21:44:32 +0100 Message-ID: <20240214204435.167852-8-david@redhat.com> In-Reply-To: <20240214204435.167852-1-david@redhat.com> References: <20240214204435.167852-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790908683390794498 X-GMAIL-MSGID: 1790908683390794498 Let's add a helper that lets us batch-process multiple consecutive PTEs. Note that the loop will get optimized out on all architectures except on powerpc. We have to add an early define of __tlb_remove_tlb_entry() on ppc to make the compiler happy (and avoid making tlb_remove_tlb_entries() a macro). Reviewed-by: Ryan Roberts Signed-off-by: David Hildenbrand --- arch/powerpc/include/asm/tlb.h | 2 ++ include/asm-generic/tlb.h | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/powerpc/include/asm/tlb.h b/arch/powerpc/include/asm/tlb.h index b3de6102a907..1ca7d4c4b90d 100644 --- a/arch/powerpc/include/asm/tlb.h +++ b/arch/powerpc/include/asm/tlb.h @@ -19,6 +19,8 @@ #include +static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, + unsigned long address); #define __tlb_remove_tlb_entry __tlb_remove_tlb_entry #define tlb_flush tlb_flush diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 2eb7b0d4f5d2..95d60a4f468a 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -608,6 +608,26 @@ static inline void tlb_flush_p4d_range(struct mmu_gather *tlb, __tlb_remove_tlb_entry(tlb, ptep, address); \ } while (0) +/** + * tlb_remove_tlb_entries - remember unmapping of multiple consecutive ptes for + * later tlb invalidation. + * + * Similar to tlb_remove_tlb_entry(), but remember unmapping of multiple + * consecutive ptes instead of only a single one. + */ +static inline void tlb_remove_tlb_entries(struct mmu_gather *tlb, + pte_t *ptep, unsigned int nr, unsigned long address) +{ + tlb_flush_pte_range(tlb, address, PAGE_SIZE * nr); + for (;;) { + __tlb_remove_tlb_entry(tlb, ptep, address); + if (--nr == 0) + break; + ptep++; + address += PAGE_SIZE; + } +} + #define tlb_remove_huge_tlb_entry(h, tlb, ptep, address) \ do { \ unsigned long _sz = huge_page_size(h); \