From patchwork Thu Jul 27 18:55:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13330586 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 B76EFC0015E for ; Thu, 27 Jul 2023 18:57:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 551126B0072; Thu, 27 Jul 2023 14:57:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DA0A6B0075; Thu, 27 Jul 2023 14:57:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 353B96B0078; Thu, 27 Jul 2023 14:57:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2675A6B0072 for ; Thu, 27 Jul 2023 14:57:06 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C88271C9B7B for ; Thu, 27 Jul 2023 18:57:05 +0000 (UTC) X-FDA: 81058299210.22.89ADF2D Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by imf25.hostedemail.com (Postfix) with ESMTP id D6B88A000C for ; Thu, 27 Jul 2023 18:57:03 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="rezn/W64"; dmarc=none; spf=pass (imf25.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690484223; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iNM2lfApDpDHo6wA+erk64IwXrZaYOnl0F5llP9QRbw=; b=e4sjI5HL7HuBBjDXmVahVY1ThcRiTDUmAE3Qco3C4ABLyrbkGPZrVUBxeeGswO3fh+TQZM 02VJBNcgbAwHPzbvA54/799nglWyupGCfyjgBO8/bHz9Z70nYKKyGsbmw9lr/++GkglJLV lVGOoXqAngv4jlJya9IZ/ta5+rG+Esk= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="rezn/W64"; dmarc=none; spf=pass (imf25.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690484223; a=rsa-sha256; cv=none; b=S9dZsEX2h5EBhNpL9aqxwPDe3Gljq1vSZ1HS8x8rzzu0x6TMuZviAB6mspBtm41RV80v+B OgOhY4VcBRXWfZ8+oipfTJIFT4wrrb3WOneqnxuhm4woqYWhZgixCz+dE/tYaG6jz5QfQm YxxVpl6AQWNk965hi13Nrq2Gzl8poUc= Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3159d5e409dso1818665f8f.0 for ; Thu, 27 Jul 2023 11:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690484222; x=1691089022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iNM2lfApDpDHo6wA+erk64IwXrZaYOnl0F5llP9QRbw=; b=rezn/W64XZNrrJy+iA17PP4dY7NEgyDtF1IgTecXk40RddgHRKdjQdVLO3Dm1uiPer A/Ii0X04NrJUwOnHByd4OTxbucNLBTZMeUCmg0Q0dLf4NOeYY4NIOM5/xemrnEQdHqM3 3PO1vT7NS3Pz3oSI0IdeDTeUN+MRrZJlAnsoxNG5N9A0RJP7xFhKTwCS9xEYMFj4sKiK upS7cJ6ZI05fw/KrM4vQe5n5xeNNgCxUW9CbTnUp9OdMXMunKs1O9Hg3Uyk0EhlxrNcE bPoSbeW9PJMxsO5k7dAJnx7DOdPk0t+LTa6vDnZpQDrikaZlST3yBaYyPG73FlWwmYXH 6j4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690484222; x=1691089022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iNM2lfApDpDHo6wA+erk64IwXrZaYOnl0F5llP9QRbw=; b=ktE+dycPnihIPcalZRzMsjIsi6qkhiRy8o0ZA6NXN6T7/fCzNIScwlsIw+nt6bio1a yoE/XkUrNXsHAVAvsf6RAN/4yRVL1Ss2sXJwnmjAK3d7r/BJi8gVi+UXg9xgc1fzw9Dr ZyK+mrPIqTifT4ioD7A4Fqz+hNt8c1XxByuBg01W8GvIkrwp3dNKlcGwB8gtIobZx0H8 +SsUQ8eZYSGLU6G4pG+PcWlj6CUch4PC0T57Wzi0r1JVC92XNYQdB83ZgmP2ock8rBLm JAowtmM/IpBLQTOTniih12chlFKnCIOBUFWJiQJRQR6odoyZA5uFm7pxh5KYNwbFGVU9 WFrA== X-Gm-Message-State: ABy/qLZtMdZjTEvXEMI5tKLcyNJd3zddPK9DDa3HRPND/q6Q27M4/nOT MKkX8bctGsF3A9dGd5IEfEknhw== X-Google-Smtp-Source: APBJJlFWr7cvkbR875xoBGCgLZGqrfaKgfeUiW96reSFz9d+/NwsOjVFOGJrqCp4Ny2X3+qOxY92VA== X-Received: by 2002:adf:e692:0:b0:317:36d8:d6e8 with SMTP id r18-20020adfe692000000b0031736d8d6e8mr2479276wrm.25.1690484222369; Thu, 27 Jul 2023 11:57:02 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id z15-20020a05600c114f00b003fbb5506e54sm2443379wmz.29.2023.07.27.11.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 11:57:02 -0700 (PDT) From: Alexandre Ghiti To: Will Deacon , "Aneesh Kumar K . V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Mayuresh Chitale , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v2 1/4] riscv: Improve flush_tlb() Date: Thu, 27 Jul 2023 20:55:50 +0200 Message-Id: <20230727185553.980262-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727185553.980262-1-alexghiti@rivosinc.com> References: <20230727185553.980262-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D6B88A000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: iw66r44o9doo7i1bo816c3zoiozrkmon X-HE-Tag: 1690484223-397324 X-HE-Meta: U2FsdGVkX199wbqr/XSDItVeWOovP3hEyby25LKDkiKjeUznwOsg4JlUWnJOH0UZtngY+tusyKD8ocPC+x2QCmCXXE5CjSo99PMRzv0uIusYwoW1VHqntCKCID/KaI36sd2EP/LN5g2tZNzReN8+zXwyskCpDN1+o4Uetno2V2NkE7M+2Rqj4QII0y3Qo1xS75dxeqnvlOf7RNaYGCoFE9Y2uQ0du5An6e1bn0SozK2HIeTKWd3/Bd0t+GgadFROTUhws6SFDPFW1NajjZab7RinbM+jxaK6q3nUxLsGbZ5y+hBuhuqLwk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yowALST8J1+lIuLCpy5kARPcoUUZyuZGcc1UwDpRaF6RC6YAXY+lOgbgpODh5fzqiZwdu7NsSV5YO+vNaOHDw1Hdcl/UQjvuhcl/YRebX6YxQ== 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: For now, flush_tlb() simply calls flush_tlb_mm() which results in a flush of the whole TLB. So let's use mmu_gather fields to provide a more fine-grained flush of the TLB. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones --- arch/riscv/include/asm/tlb.h | 8 +++++++- arch/riscv/include/asm/tlbflush.h | 3 +++ arch/riscv/mm/tlbflush.c | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/tlb.h b/arch/riscv/include/asm/tlb.h index 120bcf2ed8a8..1eb5682b2af6 100644 --- a/arch/riscv/include/asm/tlb.h +++ b/arch/riscv/include/asm/tlb.h @@ -15,7 +15,13 @@ static void tlb_flush(struct mmu_gather *tlb); static inline void tlb_flush(struct mmu_gather *tlb) { - flush_tlb_mm(tlb->mm); +#ifdef CONFIG_MMU + if (tlb->fullmm || tlb->need_flush_all) + flush_tlb_mm(tlb->mm); + else + flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end, + tlb_get_unmap_size(tlb)); +#endif } #endif /* _ASM_RISCV_TLB_H */ diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index a09196f8de68..f5c4fb0ae642 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -32,6 +32,8 @@ static inline void local_flush_tlb_page(unsigned long addr) #if defined(CONFIG_SMP) && defined(CONFIG_MMU) void flush_tlb_all(void); void flush_tlb_mm(struct mm_struct *mm); +void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, + unsigned long end, unsigned int page_size); void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); @@ -52,6 +54,7 @@ static inline void flush_tlb_range(struct vm_area_struct *vma, } #define flush_tlb_mm(mm) flush_tlb_all() +#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all() #endif /* !CONFIG_SMP || !CONFIG_MMU */ /* Flush a range of kernel pages */ diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 77be59aadc73..fa03289853d8 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -132,6 +132,13 @@ void flush_tlb_mm(struct mm_struct *mm) __flush_tlb_range(mm, 0, -1, PAGE_SIZE); } +void flush_tlb_mm_range(struct mm_struct *mm, + unsigned long start, unsigned long end, + unsigned int page_size) +{ + __flush_tlb_range(mm, start, end - start, page_size); +} + void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) { __flush_tlb_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE);