From patchwork Fri Feb 9 22:15:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 199131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1161997dyd; Fri, 9 Feb 2024 14:17:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX58V/VDSXDcJlUjCeP/taRoWXdoEcGqm2WVQaH71FQyxLWVxCIA0ZdlxA5BhrXrxLlOP04lRq6FT/AedUi+FFsAD4DXA== X-Google-Smtp-Source: AGHT+IHVSqYPVetjYdTsJ904MoU+utlgOW7hBI7WMXlDTE+DhWQ8UrahLCbW58hi1bSpHEf9ySDF X-Received: by 2002:a05:6a21:680b:b0:19c:a3de:647d with SMTP id wr11-20020a056a21680b00b0019ca3de647dmr594783pzb.19.1707517057241; Fri, 09 Feb 2024 14:17:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707517057; cv=pass; d=google.com; s=arc-20160816; b=USfJ6u/SnlyS5/QdT6K2bHU6h93qbuzllYfP5C8tW8ksiRn8bCCv5cE/iOGmf97p5K Cb/L8D3zAyY68f5MLYK22x79K4XFdYgK0num+2SYvvcIEHI3vaj77OgjGH0scvjMwJ83 OffT0Qh+PXc3UnKDeHcCzshvo6pZNdolmtySqwS4Mw9pVO4X6xaCIg9QLa1cUUyTUmFW /c9keq78tRfNpO8r0LpH4Q4Q2VSSDo1bZwzs0iNZS7TgPz7W7c6vdtUN/6uwky8V78se XHAg9mTYrx3OAPTuqcZ20D2xjxJtTWoBIXZ8IvbrnQBo307DFcuZMFdUZTqVaCNOkEbG foFA== 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=y4VstOrZYRUB9RkGghFcn/3lTEEFm1Sq4kAycYylzns=; b=BO9GUL0JUI93G7rw3se3d+LuiYc0/Sq6uBIxRkRNrKUO/sOAZSjdcDshaRwKusCMH1 bE6SneFRug2/6Y5InSww4LTQRxSU+JSXVN+D3uE00MveLU04gLIWgivxmkwIGSLPJ6Ll w16KoV++M2ObWK4cHMWlaKyvi0qiexoMpZwB97g0AaFy2TXnoQYDgbbPFT2MQv57ah9N GKGdLxYP0QtAqoGS6N77YjJBFETZx1vB1qomDZzZqm6mqiDIz9hya0QIFRIRadJjLqd0 jOg0NRazJM064UrPru5G4F1OJXukgyMwz3shUiUFkImVYtxFuc4NosXc7kjfAaGN5xdK 7d7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PNAyHPtf; 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-60079-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60079-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCUhJ1Wapev1Qmbf0FMK6fy1s/xGZdzxLsQL2BUKLnIwFptL/fyEuoE+7w9CN/uocGHlt6rmkYDm5oMo2FHigWwf3+zsTQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ca33-20020a056a0206a100b005dc359329ffsi2595522pgb.123.2024.02.09.14.17.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:17:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60079-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PNAyHPtf; 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-60079-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60079-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9FE52284C44 for ; Fri, 9 Feb 2024 22:17:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 515CA39AE9; Fri, 9 Feb 2024 22:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PNAyHPtf" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 1ED1336AEF for ; Fri, 9 Feb 2024 22:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707516960; cv=none; b=bqYUfTV/LXzO3IhLsRFyXEpaaMDjgmMF9McgVkmx5Q+MIq8Vep92Mzljw0UsnH9XCC2vJ02dcIMp/U2bduIuVEDfrDuoNIsoLfbANyK0DSg1WQJDSpj7yWJl3cLA56X7JXXBQ480YrK0GIk5xk17+u1BqooG8RrXAX5IaXIy19E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707516960; c=relaxed/simple; bh=3PQfbTkS/vd68uh/N1+tvV3UXJ8B0ItANJG44cGwxXU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nDP4z+jRGlhpq+mVrj6S3JwWIJ4/H8XvPD955KFEH/aTM9VnQ37ZME2EOMviZNNyJ4yschoCR4o3qwIbzWF1yGEcHj/pjJ0WVmlUrlOvVi8SJeoThrcVeax5iYTvY4Nv76mbOfp3zCnwSbIeG6TuRqQmQDm06nu0VP9+ibMx5yc= 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=PNAyHPtf; arc=none smtp.client-ip=170.10.129.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=1707516958; 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=PNAyHPtfJPw9kdskRJq+fXgxFH3vYP1viGXv3Re4GGsn4DPnwOb5hrKK87xksgv5GSLFWY DF81JeQVfNXAZ7oGt19XbXtC3GPSwv9DM9ksDneFguqkXUHcxEqlnpgwSeK7eZ2I9gdgZ3 yyeO7epHcuG7S1SIRO84+IFOT7kei9Q= 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-373-AMAEvJNUPyeeH3DHaeR2Bw-1; Fri, 09 Feb 2024 17:15:52 -0500 X-MC-Unique: AMAEvJNUPyeeH3DHaeR2Bw-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 9B6CF83722E; Fri, 9 Feb 2024 22:15:51 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.194.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 666531C14B04; Fri, 9 Feb 2024 22:15:47 +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 v2 07/10] mm/mmu_gather: add tlb_remove_tlb_entries() Date: Fri, 9 Feb 2024 23:15:06 +0100 Message-ID: <20240209221509.585251-8-david@redhat.com> In-Reply-To: <20240209221509.585251-1-david@redhat.com> References: <20240209221509.585251-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: 1790461405970774246 X-GMAIL-MSGID: 1790461405970774246 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); \