Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2683079rwb; Mon, 7 Aug 2023 01:26:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGb7zbCK1rI09s4PIeo0y5BDFgn/fReD1FIcyBBU16hcESxtpFN+CqTj/0x0r4GZShUqh4k X-Received: by 2002:a05:6a20:d409:b0:140:2805:6cce with SMTP id il9-20020a056a20d40900b0014028056ccemr5335872pzb.19.1691396798063; Mon, 07 Aug 2023 01:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691396798; cv=none; d=google.com; s=arc-20160816; b=fDRAg7rewTrGvgLktS85vDq/jvRrCruKXBLsw+Afg3SZilmpoOaaBWi+qdJb6pUjF2 Td36YWH/e5DVxEpyzzQyGqdKndz8iJ7DavM/PIMYYvpCsHygInyw1vwI3yemDsIdKiii YaRgfzFWktSctjPu0KAzhuxuV2e31EnNGm0ANjRsiNqHQwWfhqMyxP8H2mFVa3VKKZhF rKtNN3LM6npiijefBDPqQwmpM1/rg2NMVsIvo17IiOdG0dVv0AACdiOqrRN9YmIAYOeq EV7Ojcpq0aZ9Hq/AYB/e9FXl1rzDwsE1wCwJGWhGrEt4Irs+OspNL17CghzrBQWNvcaA FIrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XixaZNuiN0YZx7uLmJJUib0AlVhV3rWpXWLycet0C2A=; fh=ZYlRn2g767F43XtOdyo3SRNTefo0p1j7iXRdr3U7KxE=; b=elfno0upGOYYlKEaZk6qOjzf4+9ZMYjCqOMvsA/biOtMgvEtEtgkb4Ma+F1qEuRIdU /QEmeo+CjbjmwMaL/Cm22SpiA4LL2e5iNbgbBIUACAIyn4w2pbIkiwF3NeKI8UZ9Rl3d fLb2sx4/ifMw2rNbU7Z3erQFhGRaPbyS/uJIIMnc/lCEBcXS+1sw7XDJ4Lu6SkiVBv5P jVrbueZVIftQSFF4h9KnZc+AZU2s/mYcRTgb23dbXWKpFCnrutq6ZBjnYHXc9sY73+y2 9Hpk870D0OCMqibIR05ZPxe2Eatc5ZkVlmklOZjUGyCm8dodavqlT2MNSe7etdv6XuZK QIqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx9-20020a170903138900b001bb2093efb6si5231347plb.45.2023.08.07.01.26.26; Mon, 07 Aug 2023 01:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231131AbjHGIXb (ORCPT + 99 others); Mon, 7 Aug 2023 04:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbjHGIXa (ORCPT ); Mon, 7 Aug 2023 04:23:30 -0400 Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04F0C170A for ; Mon, 7 Aug 2023 01:23:27 -0700 (PDT) Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 3778NDqf098860; Mon, 7 Aug 2023 16:23:13 +0800 (+08) (envelope-from dylan@andestech.com) Received: from atctrx.andestech.com (10.0.15.173) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Mon, 7 Aug 2023 16:23:10 +0800 From: Dylan Jhong To: , , , , , , , , , , , , , CC: , , , Dylan Jhong Subject: [PATCH 1/1] riscv: Implement arch_sync_kernel_mappings() for "preventive" TLB flush Date: Mon, 7 Aug 2023 16:23:05 +0800 Message-ID: <20230807082305.198784-2-dylan@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082305.198784-1-dylan@andestech.com> References: <20230807082305.198784-1-dylan@andestech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.15.173] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 3778NDqf098860 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,PDS_RDNS_DYNAMIC_FP, RCVD_IN_DNSWL_BLOCKED,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since RISC-V is a microarchitecture that allows caching invalid entries in the TLB, it is necessary to issue a "preventive" SFENCE.VMA to ensure that each core obtains the correct kernel mapping. The patch implements TLB flushing in arch_sync_kernel_mappings(), ensuring that kernel page table mappings created via vmap/vmalloc() are updated before switching MM. Signed-off-by: Dylan Jhong --- arch/riscv/include/asm/page.h | 2 ++ arch/riscv/mm/tlbflush.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index b55ba20903ec..6c86ab69687e 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -21,6 +21,8 @@ #define HPAGE_MASK (~(HPAGE_SIZE - 1)) #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) +#define ARCH_PAGE_TABLE_SYNC_MASK PGTBL_PTE_MODIFIED + /* * PAGE_OFFSET -- the first address of the first page of memory. * When not using MMU this corresponds to the first free page in diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 77be59aadc73..d63364948c85 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -149,3 +149,15 @@ void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, __flush_tlb_range(vma->vm_mm, start, end - start, PMD_SIZE); } #endif + +/* + * Since RISC-V is a microarchitecture that allows caching invalid entries in the TLB, + * it is necessary to issue a "preventive" SFENCE.VMA to ensure that each core obtains + * the correct kernel mapping. arch_sync_kernel_mappings() will ensure that kernel + * page table mappings created via vmap/vmalloc() are updated before switching MM. + */ +void arch_sync_kernel_mappings(unsigned long start, unsigned long end) +{ + if (start < VMALLOC_END && end > VMALLOC_START) + flush_tlb_all(); +} \ No newline at end of file -- 2.34.1