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 X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55200C07E97 for ; Sat, 3 Jul 2021 05:14:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A3DE613FE for ; Sat, 3 Jul 2021 05:14:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A3DE613FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D75D86B0011; Sat, 3 Jul 2021 01:14:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D252D6B0036; Sat, 3 Jul 2021 01:14:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC61E6B005D; Sat, 3 Jul 2021 01:14:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 952696B0011 for ; Sat, 3 Jul 2021 01:14:48 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 303E3824556B for ; Sat, 3 Jul 2021 05:14:48 +0000 (UTC) X-FDA: 78320111856.24.B175449 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) by imf30.hostedemail.com (Postfix) with ESMTP id CEFC0E0016B0 for ; Sat, 3 Jul 2021 05:14:47 +0000 (UTC) Received: by mail-oi1-f169.google.com with SMTP id 22so13985099oix.10 for ; Fri, 02 Jul 2021 22:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=eQxbF2ka00EcYVsDRXeRxiGJcZxPSvtP/SHd1/OGxlc=; b=UVqx69n8/IJdOIjvtMMarIGzJAscY5qTxd3ntwDrmXn2Xr7jbjqkNqw9q2LeMikJKJ RyGWGPD8WCrkKnN/OoPXMMkZxiD6veCtjavG6XS9V35jnouiOmBOjPKsWbtmDAs2u3Ex 9cJXntU76d3/BedLHbh+GrW05owgHBaEquMlp3Pu29gj+rAxLBCg/NRr6JtEM7fsFGwS leJHQpX48kNoQ5972uCxQGx67Qoc5j4U0MAaQTGOKEYz1j5KO1xUfsq2rb3W1jlQIRjk IQv/CYJUiKJjROSGLt1QnLUEv6vwFQKHmy3rw7iE86qowe7G+hyqbKNitdNKiWMB/aXJ mP8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mime-version:content-disposition; bh=eQxbF2ka00EcYVsDRXeRxiGJcZxPSvtP/SHd1/OGxlc=; b=iq6G3xyno4WBFaXKow+SIlDLXL8Xh8v3Z8557ZgqAtYhmdE7n5DaBMPGa/C+uo8T8+ 3I/t3/7eWjwZbr55SI7pReg3cTIALejvZ1o00AntuHw9i4PJSgWzzGH3grQLPcrGa8/1 OgkocPf6iDB4VfPadUund5xB+MbsJc949b27wtPEq2WhaM5ZmM1DnpPqWGZBCabiw8EF d7JrWS7DdcYHJjxfeZFfXCr+RDDzngi5sxyrnWphMWUQ0fH58MWG0Z7fGsJIEQpBwFKF FI8uoy3TeXy5N/2Db5Ff/lgyU+FNOXiSBSWGLNiGUWEsc7qkdDIaw3guMrEh0kF00LAO e7Rg== X-Gm-Message-State: AOAM533TH78/Bh9WBS1iupvVMYf2ir4RQbI4wck3klAj7xCJzNzQyZRF INITKcGzbk0UoB2wN7mJZd4= X-Google-Smtp-Source: ABdhPJymc0nt+FrkZ7BS5ru98/uEkMhYCThRyD1sDhdB3c33wR1tBGhLKU1CaV4tkbNsA6b6yeOolw== X-Received: by 2002:aca:4e8d:: with SMTP id c135mr2567086oib.21.1625289287153; Fri, 02 Jul 2021 22:14:47 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id r25sm1058290otp.21.2021.07.02.22.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 22:14:46 -0700 (PDT) Date: Fri, 2 Jul 2021 22:14:44 -0700 From: Guenter Roeck To: Dennis Zhou Cc: Tejun Heo , Christoph Lameter , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] percpu: flush tlb after pcpu_depopulate_chunk() Message-ID: <20210703051444.GA3786429@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=UVqx69n8; spf=pass (imf30.hostedemail.com: domain of groeck7@gmail.com designates 209.85.167.169 as permitted sender) smtp.mailfrom=groeck7@gmail.com; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CEFC0E0016B0 X-Stat-Signature: csm4th9kjpadc1w36gdszhwgywssgemk X-HE-Tag: 1625289287-124660 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 Sat, Jul 03, 2021 at 04:04:49AM +0000, Dennis Zhou wrote: > Prior to "percpu: implement partial chunk depopulation", > pcpu_depopulate_chunk() was called only on the destruction path. This > meant the virtual address range was on its way back to vmalloc which > will handle flushing the tlbs for us. > > However, now that we call pcpu_depopulate_chunk() during the active > lifecycle of a chunk, we need to flush the tlb as well otherwise we can > end up accessing the wrong page through an invalid tlb mapping. > > This was reported in [1]. > > [1] https://lore.kernel.org/lkml/20210702191140.GA3166599@roeck-us.net/ > > Fixes: f183324133ea ("percpu: implement partial chunk depopulation") > Reported-by: Guenter Roeck > Signed-off-by: Dennis Zhou Tested-by: Guenter Roeck Thanks! Guenter > --- > mm/percpu-km.c | 3 ++- > mm/percpu-vm.c | 11 +++++++++-- > mm/percpu.c | 7 ++++--- > 3 files changed, 15 insertions(+), 6 deletions(-) > > diff --git a/mm/percpu-km.c b/mm/percpu-km.c > index c9d529dc7651..6875fc3b2ed7 100644 > --- a/mm/percpu-km.c > +++ b/mm/percpu-km.c > @@ -39,7 +39,8 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, > } > > static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, > - int page_start, int page_end) > + int page_start, int page_end, > + bool flush_tlb) > { > /* nada */ > } > diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c > index ee5d89fcd66f..6353cda1718e 100644 > --- a/mm/percpu-vm.c > +++ b/mm/percpu-vm.c > @@ -299,6 +299,7 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, > * @chunk: chunk to depopulate > * @page_start: the start page > * @page_end: the end page > + * @flush_tlb: if should we flush the tlb > * > * For each cpu, depopulate and unmap pages [@page_start,@page_end) > * from @chunk. > @@ -307,7 +308,8 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, > * pcpu_alloc_mutex. > */ > static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, > - int page_start, int page_end) > + int page_start, int page_end, > + bool flush_tlb) > { > struct page **pages; > > @@ -324,7 +326,12 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, > > pcpu_unmap_pages(chunk, pages, page_start, page_end); > > - /* no need to flush tlb, vmalloc will handle it lazily */ > + /* > + * We need to flush the tlb unless the caller will pass it to vmalloc, > + * which will handle flushing for us. > + */ > + if (flush_tlb) > + pcpu_post_unmap_tlb_flush(chunk, page_start, page_end); > > pcpu_free_pages(chunk, pages, page_start, page_end); > } > diff --git a/mm/percpu.c b/mm/percpu.c > index b4cebeca4c0c..e23ba0d22220 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -1580,7 +1580,8 @@ static void pcpu_chunk_depopulated(struct pcpu_chunk *chunk, > static int pcpu_populate_chunk(struct pcpu_chunk *chunk, > int page_start, int page_end, gfp_t gfp); > static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, > - int page_start, int page_end); > + int page_start, int page_end, > + bool flush_tlb); > static struct pcpu_chunk *pcpu_create_chunk(gfp_t gfp); > static void pcpu_destroy_chunk(struct pcpu_chunk *chunk); > static struct page *pcpu_addr_to_page(void *addr); > @@ -2016,7 +2017,7 @@ static void pcpu_balance_free(bool empty_only) > > bitmap_for_each_set_region(chunk->populated, rs, re, 0, > chunk->nr_pages) { > - pcpu_depopulate_chunk(chunk, rs, re); > + pcpu_depopulate_chunk(chunk, rs, re, false); > spin_lock_irq(&pcpu_lock); > pcpu_chunk_depopulated(chunk, rs, re); > spin_unlock_irq(&pcpu_lock); > @@ -2189,7 +2190,7 @@ static void pcpu_reclaim_populated(void) > continue; > > spin_unlock_irq(&pcpu_lock); > - pcpu_depopulate_chunk(chunk, i + 1, end + 1); > + pcpu_depopulate_chunk(chunk, i + 1, end + 1, true); > cond_resched(); > spin_lock_irq(&pcpu_lock); > > -- > 2.32.0.93.g670b81a890-goog >