From mboxrd@z Thu Jan 1 00:00:00 1970 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 89AE7C7EE23 for ; Wed, 24 May 2023 14:31:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AA666B0074; Wed, 24 May 2023 10:31:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05ABB900003; Wed, 24 May 2023 10:31:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6410900002; Wed, 24 May 2023 10:31:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D48846B0074 for ; Wed, 24 May 2023 10:31:51 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4564BC09B1 for ; Wed, 24 May 2023 14:31:51 +0000 (UTC) X-FDA: 80825387622.28.A20A136 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 5168E40042 for ; Wed, 24 May 2023 14:31:45 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=d5DwlCeM; dkim=pass header.d=linutronix.de header.s=2020e header.b=mrzoO3ao; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf01.hostedemail.com: domain of tglx@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=tglx@linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684938706; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7GK0LfE71lcuCBkxocxbv2QT9GP9EBHCIWxyV9RNUrY=; b=t5kdcuakzS3Isgz+7PbgS3p/fsvX2oETpcKjbN1on9FoHYht1T+mtDd9cXoYw0KaFZS/sw kiSGya/m3mYjWM18HeaFcR4gEQ4q4f5fvZ9KMhdRqRIbzOxwmuWUCjwYC1wt3tTMnNimhV lcoUOiTqbIrqza134GZA1QsYlB2ZA9g= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=d5DwlCeM; dkim=pass header.d=linutronix.de header.s=2020e header.b=mrzoO3ao; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf01.hostedemail.com: domain of tglx@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=tglx@linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684938706; a=rsa-sha256; cv=none; b=pHGRppaVLFhjUnALauZxmVuR2xpA/tr3kUyPycX+t56/vg+kI0Nl7fpOU7gax4sQBO8S/v GP7BpvupwlQQKRTvnCgf/tlbmOcegn20HqqUGyE5H5RmJVeJ1YpfRfTRWPK9yiaucjuaGe NjcUn25z9qyKqHSnXLERCDpLf6IzBZA= From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684938703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7GK0LfE71lcuCBkxocxbv2QT9GP9EBHCIWxyV9RNUrY=; b=d5DwlCeMHpmHq9K3KaDtBeFAb4f0tbmALbLc5aEpe8oOdx4Ri7AAIKDOWb2VgjiW1WK2m6 TsRge46dZZCLWQVYQpTHcKh8+jRn3JbtJCzZoTlG2ghjegJDYMq0K2tgmoTVuH0/lGKSMw sJX0Jes6G/IQ9UjWJB/9JVXqQy4zGrAfj7ou5MNWQ1i49r5+Rr3b2oMo3l6ed61uBFYFzi p5sbhR52RlJzKjLH7Kif3d5Pa5HqvN5OcNQhLktm46qG59VQuYWOasVkinNRgwnq7uI1+a JFk8bTBldgpGdJNlwY24WLZY7dBhBXmCnSeWY9IANEo8jJUiJYA5w0oUV/e3xw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684938703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7GK0LfE71lcuCBkxocxbv2QT9GP9EBHCIWxyV9RNUrY=; b=mrzoO3aonF6TUo0R9A0T8+5dKVyoVsN3xXHN1PvW/GsSB4gi9Ygz9xkG14lmfVlfWcr+iQ ewW5abwuEP0vsFDQ== To: Baoquan He Cc: linux-mm@kvack.org, Andrew Morton , Christoph Hellwig , Uladzislau Rezki , Lorenzo Stoakes , Peter Zijlstra Subject: Re: [patch 1/6] mm/vmalloc: Prevent stale TLBs in fully utilized blocks In-Reply-To: References: <20230523135902.517032811@linutronix.de> <20230523140002.575854344@linutronix.de> <87mt1um508.ffs@tglx> <87fs7lnbko.ffs@tglx> Date: Wed, 24 May 2023 16:31:43 +0200 Message-ID: <877csxn6ls.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5168E40042 X-Stat-Signature: xt69o7fstkdxbhsfk6nqsct9bfezud81 X-Rspam-User: X-HE-Tag: 1684938705-712544 X-HE-Meta: U2FsdGVkX18HpSk2y4dZlU108BJYh36zOdGZgqXLyceCVocLkV9eVnjowNBpHgfiX83TH9c58cw/E+k3AkNXf4utvvfDGSTMeBno/6ZUCrnJVyAn+k5BbCA05WUjmBhU7uYU6N4Pu92uUvqSKD+5J87XhI2ANwP3UsYBffOt0AiNZw19lJ+69trfgPQ9NJgpF4k5hmKC7OgXp5+dIwKrXpXhr9ntDkQLy5P07LOAWxZ4M4sLY9WD9ZZs/O0tTun7WFrFKILjfVyklktpjzBqZjVXbZaLuRE0izhdBKOqTfJmYaC0GKBqttugt3VA31XUyQoNr+phhjGPWyerz4lIm2jcywAxAQDywrzP/vGXzUWf3p6xCsbY8H1ENBO41SZ8wTLIGjlZnbpG2/6bAsDUX5wtVljIvSAKprqiQ2kxRkXvze8RObQmyoQKdz0cc6Dx6B7x9vTWASKkY2AkPo3ppS11Xia+m7L+RAM/CRmdXzEq0DnKNDJchFdKAqXcC5NZ1jcPWLWYUmmhfsnvAcBMAqKTXaRNkZK/TMWluFNqwmt2e6X6xXTHbPlZoCTbLjHo7y/gOQlqBxCSLQqX1jHKsK154mug9FKmD29v0jzhW4O2Od7rExT+22+ZPN43fxG/kpEfb2I1NqenE8gMJjNPh0yEZJfD0pvBvMdUrfITbSwrPHNOXPt9O9HE53j07kEVZ6XQffQztCqEzo7spiR1bHhaM38zLdAfbApXxmpEdvWou+0AZ9yjmNnXlnWdFNWqhlRwFV7BZJs5hyhh2zF7LJIyefE4f04S2FiMpiggsQb6w5BlB3jHX0nAgjamMW/Szotr08dT7oAuQi6RVjUw90vGHADPOlPnIt/WZ/IM+uQHP5m0YATlmzlmpg/RK5+nZSPe7h/PHPGrjXoe7Y0LXHz26yyqUaZLArJxkDrmGW5iPwZ8CAqI/hIlPRpWwAonNiZFE8oqsijff/3TkgF NwRhc1Wp Nv/zHDlBj05b5blgpbwVlr9cikierNPDiFaZ97gdIJNP9OKI= 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: On Wed, May 24 2023 at 21:41, Baoquan He wrote: > On 05/24/23 at 02:44pm, Thomas Gleixner wrote: >> On Wed, May 24 2023 at 19:24, Baoquan He wrote: >> Again: It _CANNOT_ be on the purge list because it has active mappings: >> >> 1 X = vb_alloc() >> ... >> Y = vb_alloc() >> vb->free -= order; // Free space goes to 0 >> if (!vb->vb_free) >> 2 list_del(vb->free_list); // Block is removed from free list >> ... >> vb_free(Y) >> vb->dirty += order; >> 3 if (vb->dirty == VMAP_BBMAP_BITS) // Condition is _false_ >> // because #1 $X is still mapped >> // so block is _NOT_ freed and >> // _NOT_ put on the purge list > > So what if $X is unmapped via vb_free($X)? Does the condition satisfied > and can the vb put into purge list? Yes, but it is _irrelevant_ for the problem at hand. > In your above example, $Y's flush is deferred, but not missed? Yes, but that violates the guarantee of vm_unmap_aliases(): * The vmap/vmalloc layer lazily flushes kernel virtual mappings primarily * to amortize TLB flushing overheads. What this means is that any page you * have now, may, in a former life, have been mapped into kernel virtual * address by the vmap layer and so there might be some CPUs with TLB entries * still referencing that page (additional to the regular 1:1 kernel mapping). * * vm_unmap_aliases flushes all such lazy mappings. After it returns, we can * be sure that none of the pages we have control over will have any aliases * from the vmap layer. >> 4 unmap_aliases() >> walk_free_list() // Does not find it because of #2 >> walk_purge_list() // Does not find it because of #3 >> >> If the resulting flush range is not covering the $Y TLBs then stale TLBs >> stay around. > > OK, your mean the TLB of $Y will stay around after vb_free() until > the whole vb becomes dirty, and fix that in this patch, you are right. > vm_unmap_aliases() may need try to flush all unmapped ranges in > this case but failed on $Y, while the page which is being reused has the > old alias of $Y. vm_unmap_aliases() _must_ guarantee that the old TLBs for $Y are gone. > My thought was attracted to the repeated flush of vmap_block va on purge > list. > > By the way, you don't fix issue that in vm_reset_perms(), the direct map > range will be accumulated with vb va and purge va and could produce > flushing range including huge gap, do you still plan to fix that? I > remember you said you will use array to gather ranges and flush them one > by one. One thing at a time. This series is a prerequisite. Thanks, tglx