From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (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 5899420766D for ; Fri, 10 Jan 2025 20:29:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=96.67.55.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540968; cv=none; b=hLhfVmAjCjNSF9KlWHeghukt5TJbVMljAIllVCLuAX7rf/Pmhfe076wi0vhjdXskiP9hCbIbV7Nz4Lw5FbvJr03K9t9XvVYZecwzaY5EoQTl49T6btM3o+myO8txo6n80sFqKNfhz47URj1U+bwrMMJLXGAHHJ1JWU4PzwBkWuo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540968; c=relaxed/simple; bh=E26pr1tg0y/0KD/VTFzzDvaEgOcE9bpDbv4GgswhVrM=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=GNeatUDuCRYeJVsmkTkjqZw9KD8zxEzIFWPvwAWi/aWfCmiRMrpS1z3ruuwFuS8e+8QKpByLg3xOsG7yCSN0ev6rbGU0mbc7GfLnSGVJjrdjrSeDt7GMXvVVG4SXdoGOW12AHXIYRfZtFjUMMpGL3ZIfkSWGY4uswO9BKYkC4nM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com; spf=pass smtp.mailfrom=shelob.surriel.com; arc=none smtp.client-ip=96.67.55.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shelob.surriel.com Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tWLd6-000000006fs-3H13; Fri, 10 Jan 2025 15:29:16 -0500 Message-ID: Subject: Re: [PATCH 06/12] x86/mm: use INVLPGB for kernel TLB flushes From: Rik van Riel To: Tom Lendacky , x86@kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, akpm@linux-foundation.org, nadav.amit@gmail.com, zhengqi.arch@bytedance.com, linux-mm@kvack.org Date: Fri, 10 Jan 2025 15:29:16 -0500 In-Reply-To: References: <20241230175550.4046587-1-riel@surriel.com> <20241230175550.4046587-7-riel@surriel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.1 (3.54.1-1.fc41) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sender: riel@surriel.com On Fri, 2025-01-10 at 12:53 -0600, Tom Lendacky wrote: > On 12/30/24 11:53, Rik van Riel wrote: > > Use broadcast TLB invalidation for kernel addresses when available. > >=20 > > +static void broadcast_kernel_range_flush(unsigned long start, > > unsigned long end) > > +{ > > + unsigned long addr; > > + unsigned long maxnr =3D invlpgb_count_max; > > + unsigned long threshold =3D tlb_single_page_flush_ceiling * > > maxnr; > > + > > + /* > > + * TLBSYNC only waits for flushes originating on the same > > CPU. > > + * Disabling migration allows us to wait on all flushes. > > + */ > > + guard(preempt)(); > > + > > + if (end =3D=3D TLB_FLUSH_ALL || > > + =C2=A0=C2=A0=C2=A0 (end - start) > threshold << PAGE_SHIFT) { > > + invlpgb_flush_all(); > > + } else { > > + unsigned long nr; > > + for (addr =3D start; addr < end; addr +=3D nr << > > PAGE_SHIFT) { > > + nr =3D min((end - addr) >> PAGE_SHIFT, > > maxnr); > > + invlpgb_flush_addr(addr, nr); > > + } >=20 > Would it be better to put this loop in the actual invlpgb_flush* > function(s)? Then callers don't have to worry about it, similar to > what is > done in clflush_cache_range() / clflush_cache_range_opt(). Maybe? We only have one caller, though. --=20 All Rights Reversed.