From patchwork Mon Oct 30 13:30:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13440586 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 D3D00C4332F for ; Mon, 30 Oct 2023 13:32:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 604266B0183; Mon, 30 Oct 2023 09:32:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58DEC6B01A2; Mon, 30 Oct 2023 09:32:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42F486B01A4; Mon, 30 Oct 2023 09:32:08 -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 2E9E26B0183 for ; Mon, 30 Oct 2023 09:32:08 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F26071408CD for ; Mon, 30 Oct 2023 13:32:07 +0000 (UTC) X-FDA: 81402216294.06.C38B240 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf21.hostedemail.com (Postfix) with ESMTP id 061111C000C for ; Mon, 30 Oct 2023 13:32:04 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=MPEK4tDy; dmarc=none; spf=pass (imf21.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.52 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=1698672725; 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=hd/FLevx18XhR5UIn9smwlv93JRL3lzcOo0hNfovrwU=; b=hvdQSVyqGbfuN4DmlZ91tRNb1hx72Fm/ovDl8T+QEWlk5DjibEunF3JKNLeuQPhTnAacKM AF3FM1/0Ec76RHT2V8P51jasVtX0XqCosxfKicrOxr9C3uG41xvm6/nj0c+9Kvlhvex5e2 RYg+SzaWF+BkSrMQwOXLwonsxI/Ph6c= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=MPEK4tDy; dmarc=none; spf=pass (imf21.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698672725; a=rsa-sha256; cv=none; b=LqoSIP2xIpIycuh+8ITFUY4hKuUgLMx2qx5uA9Ujj9AZ5GzuzhPHG8nZMbuyLY2tXNBZST tP5s+FoJDyzvI+7Q0muCGS3o9NBYSOlj4zhS0tgAP2uBjR/luIRHkEWikAft4Hw+gp18uH 0NDH8xkPpIyJPhj7/GvBLlea3P5PdKc= Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-32f7c80ab33so1215143f8f.0 for ; Mon, 30 Oct 2023 06:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698672723; x=1699277523; darn=kvack.org; 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=hd/FLevx18XhR5UIn9smwlv93JRL3lzcOo0hNfovrwU=; b=MPEK4tDyPZrJQxYlihIj0q2/PHgXKr8FgiPU9dn6eMMQ5VXGMTleJKHqBhgZ8LouBC BIj7C2zV9QAIwz38LThlyeeMbiCCsrB7k7cBeeM3uRNYd34Ozu3sjgYxf+neENzkw/jW FWFUHqMPM3O8SU12ugPxvsGQF5c4GK9GLIHtLTjZUHY+yx3I6SzPC3EVu6rcivNhbiKD ANCCjjW/OWkATMBwrbVyBOGAUJX0qw39SaRQw2rWNVaX4OMVuJrM4Xo0EQdFA9id0J4x F78LI8lROYfiSpXpfckTnUMBwyuReTGUoX/Zrnm0X+ii4O8iODvXH7q0qt/w25SPdt9d YHEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698672723; x=1699277523; 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=hd/FLevx18XhR5UIn9smwlv93JRL3lzcOo0hNfovrwU=; b=QDPRsp/fxrbobgSVZsnxGzZgFf7q62PBQ65NYIeFEZwHNFYkL3v/MqZlBe7XyYDhuY MKdKgLKQuZE2wYXOw3EVtkXEjy8yh/m9tTNk8Yt2xN287LzKMoYmrGAKUsss0vVUyK9b sSFhT20OTDbRBkYv+VgutUiGTIEW7uXMjXyeDP0JRDGrGtAAiowgLOmKMrmv9tFTbcIX hJQ/gcStQlSPB9jTwqHbRSmjSBZ3oaRSeQKqhYKOS1rL5BaVcMq6MIxf/iosv9WeSQsR ErIU8PzjTf/MzjtCDPjfu+gCReVFEGtUy9fnNpjsWvM1xa1rtWWRxMMEfbgHBPwfnjk+ SNHw== X-Gm-Message-State: AOJu0Yw3WHjmPmti4TlaTk5bzKoQ7TpcC7VHfSuVQsn8vO6vH9bHk0H5 8jI93lwpOxy0hsQ6RsCpocLaZw== X-Google-Smtp-Source: AGHT+IGz8B0HEGjTPMhdhfOE7+2f/YykM3hv3LZ+YFlrU3T3FZRfdHfdZDwT6aaKJLc5fO13EcZA5Q== X-Received: by 2002:a5d:4b0c:0:b0:32c:f8cb:f908 with SMTP id v12-20020a5d4b0c000000b0032cf8cbf908mr8512441wrq.59.1698672723353; Mon, 30 Oct 2023 06:32:03 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id a15-20020adfed0f000000b0032d88e370basm8262398wro.34.2023.10.30.06.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:32: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, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti , Andrew Jones , Samuel Holland , Lad Prabhakar Subject: [PATCH v6 1/4] riscv: Improve tlb_flush() Date: Mon, 30 Oct 2023 14:30:25 +0100 Message-Id: <20231030133027.19542-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231030133027.19542-1-alexghiti@rivosinc.com> References: <20231030133027.19542-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 061111C000C X-Stat-Signature: hjtordhychzdk7a3aqyk7dka49gst6gn X-Rspam-User: X-HE-Tag: 1698672724-372919 X-HE-Meta: U2FsdGVkX1/d3uyINCu4PZFP5qPGtKOImf1QRjOtvPgS60mZeo+4/jilS20XJVeSC5f5mkp6pnmCDjC6ifQsE0pbs1IjOpJMIPZCxwvZEO+6+vizktbX96/LMhgSohQ686RKNeBDRjKVFgQKQoCsB5eRuS94wDBMsaoLf7y8gvBN1f/8cFCv6Q1gK5Fol2kIvRMhhQZ6irsDfQ9C31VbmviweNsSwE923p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eJsH8EwRterrnYWbjL8AOJ6VcOSBpjO27o9F8BAEgDXMxeiRe58WDVbW1e/Ri8hqH4wZbIGGuiV6qS5Rule4+cnwNSkjax+vMDlj3GqUo6iB9Fv2arBDXhi0neeIPn+1jJT6XFyEHm+03nxD05GriIfP/CAv1AmpXBD0NDfLjoUS6Eut9lkyIG/JZHgQ6mMb8YUtF2VE9pfNa8tsh/5wZ4rfPH8+THtrwZ9OIUidIGEY4NPZ5UwDlZsZ6LrQhSo31STXSegeyrsq5JuHtNAfGfXjWW+Jz4EPvd2WJdI8w+60XDMAamulHVdBGit4KlUqgdZCOi3gyHYgqyDfOGVtVLMHvRAdJrtNJ3et751V/ptSYT5QsALFrQCzqnDocpVs= 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: List-Subscribe: List-Unsubscribe: For now, tlb_flush() 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 Reviewed-by: Samuel Holland Tested-by: Lad Prabhakar # On RZ/Five SMARC --- 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); From patchwork Mon Oct 30 13:30:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13440590 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 C1795C4332F for ; Mon, 30 Oct 2023 13:33:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A67C6B01F4; Mon, 30 Oct 2023 09:33:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 456536B01F7; Mon, 30 Oct 2023 09:33:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31E636B01F8; Mon, 30 Oct 2023 09:33:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2160E6B01F4 for ; Mon, 30 Oct 2023 09:33:08 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E3B92C0595 for ; Mon, 30 Oct 2023 13:33:07 +0000 (UTC) X-FDA: 81402218814.20.FAAE5C8 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by imf26.hostedemail.com (Postfix) with ESMTP id 146CE140028 for ; Mon, 30 Oct 2023 13:33:05 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="Os/AAsoL"; dmarc=none; spf=pass (imf26.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=1698672786; 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=Lg+2phEYGkxNvU/hCz5W3gC6On0lJ4QhzztTYgaxDUQ=; b=Fn33FcirvhUvnSkWXcvEEqoYsVDf8ezbmtjM6hHyHb/E0bIBqs+xZrhhWm0BYenANYB2VX MAIqDsrx/U0oZWPWEtgRYEe2EiBkmh8RMIcdSfMGUZi84gDEto+w6igZgexRm8YGO0Y7gu ynBzClbxXQkjrjQSLGXfp8PERW6DUKo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="Os/AAsoL"; dmarc=none; spf=pass (imf26.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=1698672786; a=rsa-sha256; cv=none; b=Idl+b/elWphjtA3M28KiZJfrGcknbceBRO97F2pbA58cluO7bpV/rHodShz/Q3T6qXKtU0 J1ohruDJ4DLEBij//rOQMNfI3dPAmF6pjpo9W2m0wnkHcrlNyMTKHZzkV44H+hgVDk/JFN tHJUvLB3gJ0N5a3b84oxxlSwXDTXA9s= Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-32d834ec222so2823976f8f.0 for ; Mon, 30 Oct 2023 06:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698672785; x=1699277585; darn=kvack.org; 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=Lg+2phEYGkxNvU/hCz5W3gC6On0lJ4QhzztTYgaxDUQ=; b=Os/AAsoLzxmGyjn5KcASvHh+KCVAGpmRKtMmsUM95Zq5vl6fhqH5LNt/8XL5Qc0cxY eQaykx8GJmnSFoYENQww/K8nkYMLtCAcHOXPgXSGwAVoacNBqoIwZ+Sm/FVfx2uyJ3TN TcDBQ6thfrsVQwQ45JrQynsxBl9I7hueFJrHH8l4RkgA3XBPAlZy60THHqps06kmNRJb 3LlV/5HRQFBObjqJhw4iGvhEm1Fzudm1ryfi5r/qrhVc1deyWr1wd58JeM7F712eWOEG NlpHyZuSt0d4XhhyY76sw5fiTgoGzXxjuPdqMJSqaPFseqEeBtWgGC2LtflZBXW+Lgbx BiMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698672785; x=1699277585; 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=Lg+2phEYGkxNvU/hCz5W3gC6On0lJ4QhzztTYgaxDUQ=; b=Qtw6TEOvIfsnFndp+KeL1ro5RpUFDURQ76FNlKOh76Urwox4XdPijjHcvIt7lFYmM7 2ZO2nmswe4SlLI92lnw4GFjjE/0/qRkFCEb0XlC5Zyx2IHU+aY3n4A++30d3leiltQ2y mtTikhzKsNdDqiUIaoQdJMDXi/GDPaMRBF8Rzo9U2R8Lcd9MlK43yurF3g+Phmv5X4eK yQw8aLHQ6wIMk8KC7M5yQy+H7iICkzeuT79AubfzcMgDv7mVimTpHXwDEyb1jNPj47Yb dvo5nqDGBP4fr2VAuuOgKPZGMM4LlR6CXO4k11CIisCi9KMqNPitbJ7Gsapw2x49gpMT Qlaw== X-Gm-Message-State: AOJu0YxNhuliRTIcad0LY1a82lAB+gfBOcJXeKbQINvgCBByVNpySBE7 gfCITNwO4oLb7VUhJ3F/LaZbnQ== X-Google-Smtp-Source: AGHT+IFSVGIn3GkkCdVjrv9GJYab3GvRdyYNVKTc+rLB8DHUCDxVeEERoRHJ6rwLZ6Dt9ZCmv4emsA== X-Received: by 2002:adf:d1ca:0:b0:32f:7967:aa4d with SMTP id b10-20020adfd1ca000000b0032f7967aa4dmr5491624wrd.68.1698672784653; Mon, 30 Oct 2023 06:33:04 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id d25-20020adfa419000000b0032f79e55eb8sm6061601wra.16.2023.10.30.06.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:33:04 -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, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti , Samuel Holland , Lad Prabhakar Subject: [PATCH v6 2/4] riscv: Improve flush_tlb_range() for hugetlb pages Date: Mon, 30 Oct 2023 14:30:26 +0100 Message-Id: <20231030133027.19542-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231030133027.19542-1-alexghiti@rivosinc.com> References: <20231030133027.19542-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 146CE140028 X-Stat-Signature: r5shiiwxoxz88nakgr3nmqerbi9r7xaa X-Rspam-User: X-HE-Tag: 1698672785-369857 X-HE-Meta: U2FsdGVkX199nFpxxRXlc3/hDOpFXx72QCacSwKy1v6t5nUubXg+J3iqg+SgBNIK5ZTemCkopk+8JOlim7e7PoIbEaT27PgL2B5xmVYZSK4yjxHPqnQHGxoiHjDv2FoG9UJgTLffNNAqlAanPDSYhRJsIswOIs5UlPNKRGsf0/c0W/2Lai0Yzb5IGJr/Ok7aHhWc9YKbWwawyb7vi7XkUsPk1cLkFZlAU78nDpCQUaaTGOFJOd7zgEfjcH0calWMdypUZOEWzFeetNFnBwevpETyuOjc7kREYlgBUAjPCnna6xB9XOzu+nN/9o9VMJClsJTc7AnhfT/LhBDl1kcBOU9G6P9nTut8lzInAI5bDWZ8YvfUXf4MDHI3+EYVMfaHav63kqZ/brGOXvpmRsMpV2XNkV1dntN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YcLUKOQqZenMos/UJ44K8EA7qVgYj12lN+mbYtHW5XNkKVo6IqgXUouDJ2LOUxAe9n4st38AJQkHYaHl6RRzK1HJo6PXLB0pKjocKry950mG8TE/5UoDwEyqlOG6UcYhYhPlQr5zIXQoaDHiA= 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: List-Subscribe: List-Unsubscribe: flush_tlb_range() uses a fixed stride of PAGE_SIZE and in its current form, when a hugetlb mapping needs to be flushed, flush_tlb_range() flushes the whole tlb: so set a stride of the size of the hugetlb mapping in order to only flush the hugetlb mapping. However, if the hugepage is a NAPOT region, all PTEs that constitute this mapping must be invalidated, so the stride size must actually be the size of the PTE. Note that THPs are directly handled by flush_pmd_tlb_range(). Signed-off-by: Alexandre Ghiti Reviewed-by: Samuel Holland Tested-by: Lad Prabhakar # On RZ/Five SMARC --- arch/riscv/mm/tlbflush.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index fa03289853d8..b6d712a82306 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -147,7 +148,33 @@ 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) { - __flush_tlb_range(vma->vm_mm, start, end - start, PAGE_SIZE); + unsigned long stride_size; + + if (!is_vm_hugetlb_page(vma)) { + stride_size = PAGE_SIZE; + } else { + stride_size = huge_page_size(hstate_vma(vma)); + + /* + * As stated in the privileged specification, every PTE in a + * NAPOT region must be invalidated, so reset the stride in that + * case. + */ + if (has_svnapot()) { + if (stride_size >= PGDIR_SIZE) + stride_size = PGDIR_SIZE; + else if (stride_size >= P4D_SIZE) + stride_size = P4D_SIZE; + else if (stride_size >= PUD_SIZE) + stride_size = PUD_SIZE; + else if (stride_size >= PMD_SIZE) + stride_size = PMD_SIZE; + else + stride_size = PAGE_SIZE; + } + } + + __flush_tlb_range(vma->vm_mm, start, end - start, stride_size); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, From patchwork Mon Oct 30 13:30:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13440591 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 8BC34C4332F for ; Mon, 30 Oct 2023 13:34:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FDDD6B01F8; Mon, 30 Oct 2023 09:34:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AE596B01F9; Mon, 30 Oct 2023 09:34:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB8416B01FA; Mon, 30 Oct 2023 09:34:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DA28F6B01F8 for ; Mon, 30 Oct 2023 09:34:09 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A84BFB5A83 for ; Mon, 30 Oct 2023 13:34:09 +0000 (UTC) X-FDA: 81402221418.18.7D42343 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by imf03.hostedemail.com (Postfix) with ESMTP id C05D020003 for ; Mon, 30 Oct 2023 13:34:07 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QdHp+5zI; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698672847; 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=WjbHAGeb+QJH3Z54LpRLDIACfKOrdrc4j0Xi4VRv9pM=; b=qfFlLcw3QK41HQo9FXBjUScya2SOWhwFS8STVCsFM27n06qBnj3xMdWDvDt4ZflOI9oouL IwV8U38KnSffaj99HQ0+qwz2b7jDb2JNe3IBQnGmIq+9bCsHfGZJRAyzuANo3qgjpMqbGO w/JTtaRJayXScqNX3oBqSIpT1QKXGyw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698672847; a=rsa-sha256; cv=none; b=W6SFzJ6ScjclsMfhBzI9wLxDD0IseghwZdgJI+VjWdNjeysoqn/pvSgH3r8aMttkTVB96+ jXbhJca/n5DBERHlNgHX4FPywEs92v8a4OTtIOsik4S2JFnSRPjdokip1Xm9+ZBHQ7x3mB BBNaAaAcCuXCcGti7S51u3/hd2t8H1c= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QdHp+5zI; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40806e4106dso26236295e9.1 for ; Mon, 30 Oct 2023 06:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698672846; x=1699277646; darn=kvack.org; 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=WjbHAGeb+QJH3Z54LpRLDIACfKOrdrc4j0Xi4VRv9pM=; b=QdHp+5zIWf+62H93ac0wZZIhkyef3coR5kwq699DvpfNtiRNZLucQkMGBYIq55Lz9E J0meyXK+zBK8xHil735SaRXAwQ0yV1n2exOA+fogDmzDO3xv0MhjHo02t0dsv2RSaXC5 grdD7wxZNbzh2241FAWQ/vingb7BUlIjthpFBN5chgwP4U0kkdHBt15Xl2goQgdUNGAX iuR2S6R2Bx/dUxHazxp4c0AMaw0zZ/QpJwHQyoL8Gl71OMRDrbur81Qq+JXZeApFMer0 hRlhQ2jrFDp94o3OXOW63Dvh1lQwlsqnJIVTZGT6FH6Y493H+Je6/mS28sbXAAGjUAJU qasQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698672846; x=1699277646; 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=WjbHAGeb+QJH3Z54LpRLDIACfKOrdrc4j0Xi4VRv9pM=; b=KOag2dpcTSeKaOQjkIFtQPzWhdYKjHNFVKt7asNgLQmY49AI5M8B5LeA5lK8/kBlJx qZ6IyjUJDB6lXTaGDsMOr+wuX71VXYdwfGRbQECH/iLjb2gFer1mEbwk8tNeI4g+BHBM BFYrZDsQYTsNEl7jKqh1HjmjTQjHo7ya1FGtL/rrkNXeNkOLYbp0pBA3TFDNp09LaiXX HfI/8UQrDmrUk8ZucqAgA24IaegY8ru4jSz267xiRY0ZGubNr+m/xJr2+ba/M7ZJuliq WwCtS+VkmKASjrz3BpmUj3XMgUYn1STbckn9tQ/c2DyFge/04qKtgt6DMxS13wbGQ1vm 9saA== X-Gm-Message-State: AOJu0Yz8AVrpS2JVDfVdylPw9KPGrSM3kVJym5BYD2TNnU5cckMUK4WG kNNnnd+o+fFzTvxN8xnHP3BhIA== X-Google-Smtp-Source: AGHT+IFEwmaXHp3jmsk1vb25lVzXIQCUCLQ6L9e+gIHQJU/IHdkS+vcxqaHWYOIB/ULsgQSEOHAiyQ== X-Received: by 2002:a05:600c:1c14:b0:405:358c:ba74 with SMTP id j20-20020a05600c1c1400b00405358cba74mr14533940wms.0.1698672846098; Mon, 30 Oct 2023 06:34:06 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id o38-20020a05600c512600b00407752f5ab6sm9384422wms.6.2023.10.30.06.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:34:05 -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, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti , Andrew Jones , Lad Prabhakar , Samuel Holland Subject: [PATCH v6 3/4] riscv: Make __flush_tlb_range() loop over pte instead of flushing the whole tlb Date: Mon, 30 Oct 2023 14:30:27 +0100 Message-Id: <20231030133027.19542-4-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231030133027.19542-1-alexghiti@rivosinc.com> References: <20231030133027.19542-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C05D020003 X-Rspam-User: X-Stat-Signature: kx6aasj3dknps3mynettp171skb755aa X-Rspamd-Server: rspam03 X-HE-Tag: 1698672847-512364 X-HE-Meta: U2FsdGVkX19+1NLeas3QKxQ0+8gKC3j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bGAOV/TRKBzIEI7ZFvd1pgA+SuL50bE/SsgqnLE2nhZHA7kPk8/KnrT6XT22REJpXpfJHraL5xhfNeZpZF0zz1/mjEoc32v6qP7HeLuTdCmd/tJ5ScU7laWhRNFBKd6DqqGgTtxslj48p1MXSPptuVOV78RHlBtXBdp6GQ2Q6ZrUDbTBRFEolhTTXo02ko2s4uHV5KdiFinR9K1cuvW7YyTRPfQOn6QCq8ajJ6v8xqYgJ7qvQPD2aBtAjujhQpto8egkJbdigAtuLl1B6Ire1HP/TauyCp2hZI/3eM04z9KKY/MalfODy5GwDzt1Nspss4/4ovMnoKw4yZNtas6CSxJSG4GoGQc/clv3QPqAmlVbRXywMZ/o/4tIKgEtDusLhPEDzs0dTlRV8OMDmkzHni0yUG6OxXooAe5qEOqwXdSLgtxnAfY5eSdZPNbWjdd4/RHMwgogEv/BI0afDfV6jYLM0upgze7FRmF9obudgoQzg0YRWL3ABq4i8gwuVdqRjWaQG9AnJ/peO5lcHjrBXfyB5b02TrAA5epCeEpChtVg8Tw3gY1IgNlP+q+yqc5YAXKD0zxwSIhqAtrgeBJDaDT+4wk= 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: List-Subscribe: List-Unsubscribe: Currently, when the range to flush covers more than one page (a 4K page or a hugepage), __flush_tlb_range() flushes the whole tlb. Flushing the whole tlb comes with a greater cost than flushing a single entry so we should flush single entries up to a certain threshold so that: threshold * cost of flushing a single entry < cost of flushing the whole tlb. Co-developed-by: Mayuresh Chitale Signed-off-by: Mayuresh Chitale Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones Tested-by: Lad Prabhakar # On RZ/Five SMARC Reviewed-by: Samuel Holland Tested-by: Samuel Holland --- arch/riscv/include/asm/sbi.h | 3 - arch/riscv/include/asm/tlbflush.h | 3 + arch/riscv/kernel/sbi.c | 32 +++------ arch/riscv/mm/tlbflush.c | 115 +++++++++++++++--------------- 4 files changed, 72 insertions(+), 81 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 12dfda6bb924..0892f4421bc4 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -280,9 +280,6 @@ void sbi_set_timer(uint64_t stime_value); void sbi_shutdown(void); void sbi_send_ipi(unsigned int cpu); int sbi_remote_fence_i(const struct cpumask *cpu_mask); -int sbi_remote_sfence_vma(const struct cpumask *cpu_mask, - unsigned long start, - unsigned long size); int sbi_remote_sfence_vma_asid(const struct cpumask *cpu_mask, unsigned long start, diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index f5c4fb0ae642..170a49c531c6 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -11,6 +11,9 @@ #include #include +#define FLUSH_TLB_MAX_SIZE ((unsigned long)-1) +#define FLUSH_TLB_NO_ASID ((unsigned long)-1) + #ifdef CONFIG_MMU extern unsigned long asid_mask; diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index c672c8ba9a2a..5a62ed1da453 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -11,6 +11,7 @@ #include #include #include +#include /* default SBI version is 0.1 */ unsigned long sbi_spec_version __ro_after_init = SBI_SPEC_VERSION_DEFAULT; @@ -376,32 +377,15 @@ int sbi_remote_fence_i(const struct cpumask *cpu_mask) } EXPORT_SYMBOL(sbi_remote_fence_i); -/** - * sbi_remote_sfence_vma() - Execute SFENCE.VMA instructions on given remote - * harts for the specified virtual address range. - * @cpu_mask: A cpu mask containing all the target harts. - * @start: Start of the virtual address - * @size: Total size of the virtual address range. - * - * Return: 0 on success, appropriate linux error code otherwise. - */ -int sbi_remote_sfence_vma(const struct cpumask *cpu_mask, - unsigned long start, - unsigned long size) -{ - return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, - cpu_mask, start, size, 0, 0); -} -EXPORT_SYMBOL(sbi_remote_sfence_vma); - /** * sbi_remote_sfence_vma_asid() - Execute SFENCE.VMA instructions on given - * remote harts for a virtual address range belonging to a specific ASID. + * remote harts for a virtual address range belonging to a specific ASID or not. * * @cpu_mask: A cpu mask containing all the target harts. * @start: Start of the virtual address * @size: Total size of the virtual address range. - * @asid: The value of address space identifier (ASID). + * @asid: The value of address space identifier (ASID), or FLUSH_TLB_NO_ASID + * for flushing all address spaces. * * Return: 0 on success, appropriate linux error code otherwise. */ @@ -410,8 +394,12 @@ int sbi_remote_sfence_vma_asid(const struct cpumask *cpu_mask, unsigned long size, unsigned long asid) { - return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, - cpu_mask, start, size, asid, 0); + if (asid == FLUSH_TLB_NO_ASID) + return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, + cpu_mask, start, size, 0, 0); + else + return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, + cpu_mask, start, size, asid, 0); } EXPORT_SYMBOL(sbi_remote_sfence_vma_asid); diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index b6d712a82306..e46fefc70927 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -9,28 +9,50 @@ static inline void local_flush_tlb_all_asid(unsigned long asid) { - __asm__ __volatile__ ("sfence.vma x0, %0" - : - : "r" (asid) - : "memory"); + if (asid != FLUSH_TLB_NO_ASID) + __asm__ __volatile__ ("sfence.vma x0, %0" + : + : "r" (asid) + : "memory"); + else + local_flush_tlb_all(); } static inline void local_flush_tlb_page_asid(unsigned long addr, unsigned long asid) { - __asm__ __volatile__ ("sfence.vma %0, %1" - : - : "r" (addr), "r" (asid) - : "memory"); + if (asid != FLUSH_TLB_NO_ASID) + __asm__ __volatile__ ("sfence.vma %0, %1" + : + : "r" (addr), "r" (asid) + : "memory"); + else + local_flush_tlb_page(addr); } -static inline void local_flush_tlb_range(unsigned long start, - unsigned long size, unsigned long stride) +/* + * Flush entire TLB if number of entries to be flushed is greater + * than the threshold below. + */ +static unsigned long tlb_flush_all_threshold __read_mostly = 64; + +static void local_flush_tlb_range_threshold_asid(unsigned long start, + unsigned long size, + unsigned long stride, + unsigned long asid) { - if (size <= stride) - local_flush_tlb_page(start); - else - local_flush_tlb_all(); + unsigned long nr_ptes_in_range = DIV_ROUND_UP(size, stride); + int i; + + if (nr_ptes_in_range > tlb_flush_all_threshold) { + local_flush_tlb_all_asid(asid); + return; + } + + for (i = 0; i < nr_ptes_in_range; ++i) { + local_flush_tlb_page_asid(start, asid); + start += stride; + } } static inline void local_flush_tlb_range_asid(unsigned long start, @@ -38,8 +60,10 @@ static inline void local_flush_tlb_range_asid(unsigned long start, { if (size <= stride) local_flush_tlb_page_asid(start, asid); - else + else if (size == FLUSH_TLB_MAX_SIZE) local_flush_tlb_all_asid(asid); + else + local_flush_tlb_range_threshold_asid(start, size, stride, asid); } static void __ipi_flush_tlb_all(void *info) @@ -52,7 +76,7 @@ void flush_tlb_all(void) if (riscv_use_ipi_for_rfence()) on_each_cpu(__ipi_flush_tlb_all, NULL, 1); else - sbi_remote_sfence_vma(NULL, 0, -1); + sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID); } struct flush_tlb_range_data { @@ -69,18 +93,12 @@ static void __ipi_flush_tlb_range_asid(void *info) local_flush_tlb_range_asid(d->start, d->size, d->stride, d->asid); } -static void __ipi_flush_tlb_range(void *info) -{ - struct flush_tlb_range_data *d = info; - - local_flush_tlb_range(d->start, d->size, d->stride); -} - static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long size, unsigned long stride) { struct flush_tlb_range_data ftd; struct cpumask *cmask = mm_cpumask(mm); + unsigned long asid = FLUSH_TLB_NO_ASID; unsigned int cpuid; bool broadcast; @@ -90,39 +108,24 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, cpuid = get_cpu(); /* check if the tlbflush needs to be sent to other CPUs */ broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; - if (static_branch_unlikely(&use_asid_allocator)) { - unsigned long asid = atomic_long_read(&mm->context.id) & asid_mask; - - if (broadcast) { - if (riscv_use_ipi_for_rfence()) { - ftd.asid = asid; - ftd.start = start; - ftd.size = size; - ftd.stride = stride; - on_each_cpu_mask(cmask, - __ipi_flush_tlb_range_asid, - &ftd, 1); - } else - sbi_remote_sfence_vma_asid(cmask, - start, size, asid); - } else { - local_flush_tlb_range_asid(start, size, stride, asid); - } + + if (static_branch_unlikely(&use_asid_allocator)) + asid = atomic_long_read(&mm->context.id) & asid_mask; + + if (broadcast) { + if (riscv_use_ipi_for_rfence()) { + ftd.asid = asid; + ftd.start = start; + ftd.size = size; + ftd.stride = stride; + on_each_cpu_mask(cmask, + __ipi_flush_tlb_range_asid, + &ftd, 1); + } else + sbi_remote_sfence_vma_asid(cmask, + start, size, asid); } else { - if (broadcast) { - if (riscv_use_ipi_for_rfence()) { - ftd.asid = 0; - ftd.start = start; - ftd.size = size; - ftd.stride = stride; - on_each_cpu_mask(cmask, - __ipi_flush_tlb_range, - &ftd, 1); - } else - sbi_remote_sfence_vma(cmask, start, size); - } else { - local_flush_tlb_range(start, size, stride); - } + local_flush_tlb_range_asid(start, size, stride, asid); } put_cpu(); @@ -130,7 +133,7 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, void flush_tlb_mm(struct mm_struct *mm) { - __flush_tlb_range(mm, 0, -1, PAGE_SIZE); + __flush_tlb_range(mm, 0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE); } void flush_tlb_mm_range(struct mm_struct *mm, From patchwork Mon Oct 30 13:30:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13440592 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 CCA98C4167B for ; Mon, 30 Oct 2023 13:35:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F1976B01FA; Mon, 30 Oct 2023 09:35:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A2046B01FB; Mon, 30 Oct 2023 09:35:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56A3A6B01FC; Mon, 30 Oct 2023 09:35:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 43C9C6B01FA for ; Mon, 30 Oct 2023 09:35:11 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2B2F4B5538 for ; Mon, 30 Oct 2023 13:35:11 +0000 (UTC) X-FDA: 81402224022.03.9A9C1AB Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf01.hostedemail.com (Postfix) with ESMTP id 32A0140006 for ; Mon, 30 Oct 2023 13:35:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=N93X7x4H; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698672909; a=rsa-sha256; cv=none; b=bjU/s8yNHSwyCWWDnigIf0qsvB5pNOeCpJJ7ROewEuyy0pjKhLzCw3W2xNYWTIVHHwHiXk 8JVA9P4HsCk4V60tPCaYTgxDHYZXJ9lFQfPWsVZ1Dp00zk4vPdioI6Yni6L3CgFweUZhOc H2c4WIDgvmp+Gg96D+LpAtPtkNPbKAs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=N93X7x4H; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698672909; 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=Z+Voqb64JUu/S+my4bjKiePrsxn/AGTGcWHZA6URcLY=; b=7sKBr8+vCSrPCSR1LgRBikOvQH/BprOZeSzGa9uRIVRXw+7NEbikVA8/CGdYHicguPw+WZ Z5veZn5N/XXvxnw07XKEleD90OwfnmCFOBBA4SCKNr2u8RpHGWz0hMCj5dCtVSsWrRDzM1 0w3EH+7gbnHSRFDnjCdP2LtblJ5G2p4= Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-32f5b83f254so3087610f8f.3 for ; Mon, 30 Oct 2023 06:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698672908; x=1699277708; darn=kvack.org; 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=Z+Voqb64JUu/S+my4bjKiePrsxn/AGTGcWHZA6URcLY=; b=N93X7x4HCIBDVnzfy1AB7Bp+oMg7f9xpnPm6M4xF/hAAsiD93dAWqID0XD08AXP2cM FAQZbcCNXwljho0wPM9EEHQabuNJSgqz+z2CkYGCY85nu55lmGDtdHB/pTLZEZBYEAfp LMpUMudXZSxnnt8r8T1CPUP0f10/RQPb5cVq0i+76g4r4ty7lqP9cG1UfbIeGDZiLp4p jdfAnP9Vpp/PZk7CG2uwcsswW0zD5XMn+eJ2R9irGPBT4E8KW+HRKGtS3PXYVLRg3L09 Qoz91d0Xy2JFdSdX203ALNJ1n+yRQQ8mCkFIcMzEV4BS7vzMiPzPEhdF4E3ppEJ22rFf OqCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698672908; x=1699277708; 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=Z+Voqb64JUu/S+my4bjKiePrsxn/AGTGcWHZA6URcLY=; b=bAbtzsUw4CuAPoSiQ2SqfXBB3zBZPQ90iDK98c99SzFV6bBsT7Ss5CSvnjnt2fUVNC QRH7HalaI9cQtXc07EdDNwwcDVC7UqiSWJuySYYY9LUeRGOkbAguuhrAvScUf6ohChsi XTP7+RB3JLpwH+dLhBDRuiMhDz68h7CMMmpPUmrdolVakMTE6Z/SvMsqRj7NZW9yBQ7Q 7ljl9B7lkdW0tG7/ft3JGZSKtZn50qb2A5tSSVpBDEodkfeV+RZvZwumdZBb31TVs8ex KXWK9UFIxUYzWnWAVzcMwV1T2hOWHm9HiQgwpgiJJjLn70rRwtvI5F1XeASSeEmYLVUK k4rg== X-Gm-Message-State: AOJu0YwBfUTD/wNDIDcAYeZOhLtVMULSESwFm1W2HdG8Pzih2bUEPPn5 Cov0G1OMeI3tUMqhjC/CdLUgLQ== X-Google-Smtp-Source: AGHT+IHEw6T+OK2cXmEQUaFlVp9JTsP+3ENAfV/VP4H/l3hIJec/QWwZbGuNwmLLAlaAsmBtrNDznA== X-Received: by 2002:a05:6000:1882:b0:32f:7f03:9a with SMTP id a2-20020a056000188200b0032f7f03009amr4279324wri.55.1698672907709; Mon, 30 Oct 2023 06:35:07 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id o12-20020a056000010c00b003232f167df5sm8252241wrx.108.2023.10.30.06.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:35:07 -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, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti , Andrew Jones , Lad Prabhakar , Samuel Holland Subject: [PATCH v6 4/4] riscv: Improve flush_tlb_kernel_range() Date: Mon, 30 Oct 2023 14:30:28 +0100 Message-Id: <20231030133027.19542-5-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231030133027.19542-1-alexghiti@rivosinc.com> References: <20231030133027.19542-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 32A0140006 X-Stat-Signature: aqmn347i1h564rfhbcattsq71op1456x X-Rspam-User: X-HE-Tag: 1698672908-207394 X-HE-Meta: U2FsdGVkX185+QeSO2PF3uyW2RVARmuOYyPLanArGb9gXuMViluvMxFmUfPYkrYYUzSzCtQn1tt40oENNHROd+yqSLgMbqKXhCjGRtwW4XztS6JqNkBBGpK2eC1x0UNiSyZhl4YyonW4mBN+4fRv3WKj7pzLqJNnOgt/MUDos4jYsiUyCTrroptFI4YqyjINaA6hYBgk+ySJ49tdLpAYNGJGnC1upVNPKTalNUs1Ezz6IiNHRtZwKMERBPr/elmUB4+Qkg0FYPhEBw4izzE/5WkxeRNCcexl3izyVPI9T4jla1uK46YKGXXrfqobqr0K+/VQ+Hymx6hHedQicOVQ9CpWGA9kxo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j5C/oqmHFe3PYUyJfVxQbd3q94lokzhopN3caujJFObxsLiqm+mzZzfmcY7EVQl6+OjVZ9L0Dzm5xGlNrkFGT/vs4wDEOkSOCdTFiY125NRzUMtIysdLVZGML14R3GCZGj8GWMC2Lb/6Yoww/IYduhEC2txjQdyiD02oUwZ3h/XhiM/d7LERW3wDDzWjHI6wznpEiKcIyCIgPqlkE3zsnnCp7KB6UYSER6X2BkT5CNwztSTVKMXBSBOFP9X4FlaIiVF8PjBIZRieS3IEhnmb774PhzQ= 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: List-Subscribe: List-Unsubscribe: This function used to simply flush the whole tlb of all harts, be more subtile and try to only flush the range. The problem is that we can only use PAGE_SIZE as stride since we don't know the size of the underlying mapping and then this function will be improved only if the size of the region to flush is < threshold * PAGE_SIZE. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones Tested-by: Lad Prabhakar # On RZ/Five SMARC Reviewed-by: Samuel Holland Tested-by: Samuel Holland --- arch/riscv/include/asm/tlbflush.h | 11 +++++----- arch/riscv/mm/tlbflush.c | 34 ++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index 170a49c531c6..8f3418c5f172 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -40,6 +40,7 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, 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); +void flush_tlb_kernel_range(unsigned long start, unsigned long end); #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, @@ -56,15 +57,15 @@ static inline void flush_tlb_range(struct vm_area_struct *vma, local_flush_tlb_all(); } -#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 */ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end) { - flush_tlb_all(); + local_flush_tlb_all(); } +#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 */ + #endif /* _ASM_RISCV_TLBFLUSH_H */ diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index e46fefc70927..e6659d7368b3 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -97,20 +97,27 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long size, unsigned long stride) { struct flush_tlb_range_data ftd; - struct cpumask *cmask = mm_cpumask(mm); + const struct cpumask *cmask; unsigned long asid = FLUSH_TLB_NO_ASID; - unsigned int cpuid; bool broadcast; - if (cpumask_empty(cmask)) - return; + if (mm) { + unsigned int cpuid; + + cmask = mm_cpumask(mm); + if (cpumask_empty(cmask)) + return; - cpuid = get_cpu(); - /* check if the tlbflush needs to be sent to other CPUs */ - broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; + cpuid = get_cpu(); + /* check if the tlbflush needs to be sent to other CPUs */ + broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; - if (static_branch_unlikely(&use_asid_allocator)) - asid = atomic_long_read(&mm->context.id) & asid_mask; + if (static_branch_unlikely(&use_asid_allocator)) + asid = atomic_long_read(&mm->context.id) & asid_mask; + } else { + cmask = cpu_online_mask; + broadcast = true; + } if (broadcast) { if (riscv_use_ipi_for_rfence()) { @@ -128,7 +135,8 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, local_flush_tlb_range_asid(start, size, stride, asid); } - put_cpu(); + if (mm) + put_cpu(); } void flush_tlb_mm(struct mm_struct *mm) @@ -179,6 +187,12 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, __flush_tlb_range(vma->vm_mm, start, end - start, stride_size); } + +void flush_tlb_kernel_range(unsigned long start, unsigned long end) +{ + __flush_tlb_range(NULL, start, end - start, PAGE_SIZE); +} + #ifdef CONFIG_TRANSPARENT_HUGEPAGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)