Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp636772ybb; Fri, 3 Apr 2020 09:06:28 -0700 (PDT) X-Google-Smtp-Source: APiQypL28VO4xx/SgkJ5pJHJ0EaENfjiy70MIy2bL2ee4PKePKDmP/pUhGFaV4FB+9sJ2QXMaKve X-Received: by 2002:aca:4142:: with SMTP id o63mr3502541oia.118.1585929987929; Fri, 03 Apr 2020 09:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585929987; cv=none; d=google.com; s=arc-20160816; b=EYuZO3HjfMApMpxg404+MEXw53ulkAh+JUUZlSGfdU5GUl109NSOy4FgPNe9HQddJo aR+OiBlSoIx76tuWWbXbH6b2reFd7sK6Pvnu4JCO53Hin0n2bESKGrX8KHoTpGiRtmkS R28VtHbhPuP6Vfd3CVEdY2B7QAvxZ28Ut6edQ15n1ItTpLz8dkOnpcI9+f/ZSLyKaW24 MWyV/JNQce595zBWQll8bZnU/LuC7r0xoMC8VXik3pYkbKzR3dSQrXbozZWeVAuGA3r2 usZBnku+7PcSGyabdTK+iyZ6LReF3reXEcLy7n/zFI0EThI5lEoJ7fp1HUQTsYLQGdB8 1QFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=DTKHsm8Q5bJhu3UTT4PCRZaQwVAbDrF/ulx8WyttahM=; b=tYieMzy9fKWOWdc0GCuzg+czsxoVw+i19ZIeCzR2u4T69pCfwZQrtFvvdJlyMgvoPA bvFRILTMfhbQdlJKCLSvHK3X4F+CgN6voCv8B6iuOVq4Kgo3GJgkln6jB4gNZHNssyOe +Q7xVcR29YGjAxlnqODz1qixGHrm2lYx2KEce+BYJzgxSr89JrKWwFJRiAQq5ePsmXte GxeTxvgvivG1hVehJwbb7lWl5y8xpx3VH0dV6SPDa3ShvlbaPPxO5RFu039SAywIJTwU g1fBS+9DXkDGjwEhkTMR5lyNjy3dUjNdMldK45r+rgwsAh19/O55l3rAuCcWMGrbpQoj xaIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=madpdA2I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w203si3837420oie.193.2020.04.03.09.06.01; Fri, 03 Apr 2020 09:06:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=madpdA2I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390839AbgDCQDf (ORCPT + 99 others); Fri, 3 Apr 2020 12:03:35 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43225 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728066AbgDCQDf (ORCPT ); Fri, 3 Apr 2020 12:03:35 -0400 Received: by mail-pf1-f196.google.com with SMTP id f206so3663676pfa.10 for ; Fri, 03 Apr 2020 09:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=DTKHsm8Q5bJhu3UTT4PCRZaQwVAbDrF/ulx8WyttahM=; b=madpdA2IZsdgOJo7MhH9aIn36WnyTvf608VJNjKU4iQQnucZhT80EAfp8b5iaHLY33 LSYMLiu30MGYQ2eY6huT6/vbDK2QXwsRGx2IDE0vfuf628W+WPHsUFyRcOyxzWNEkEb/ cKNLyPO2tHnPFQ0gvQ+EAz+FeGw8lYU4LyeH9kS2XjJgi6fCfhK4gNYNoniPuc2Z9o61 UmT0irwwMz67xe5HPJeTVth2tZl5jbMI/1MSsKLPl+NPmIckAnS1WRuMKKI333Y2bOMM sLiczLpvNYRE+J+kFgg7/AnUK+ylht12j4YFpVxc/15pFgZll6Mpx1TnmpQYNwhU2puc Tf1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=DTKHsm8Q5bJhu3UTT4PCRZaQwVAbDrF/ulx8WyttahM=; b=RWUMDGMOrKRVf0HDml3Bb/FBOfD6UwAgfGq1S1vqBcTmpoxhdGr/1fTzpclRMzInRI TxRjv8VFPV+DMAiRgBu9j+80RzD5SuKaaXk3R9aF8UkOiWfHVsPAYQJecmi4T5iEYa7a Gjg9OySsOBugJ6XUzqvr0TmWB4OpJ6IfNYfa3+iTce5oGj1JTwbbleWlD20qh4+THDL9 GnfTXr1ukk/z+phSsOvKiCUOBT67wpXq680+xhsCoANtwouMwT0owVzhvmRneLvTqtNY 0SYHBOW3VwTkzcGDHLy72Zcfaw0HhIs3pZP7NruhpQvzgb/7oU8tJbcv181BIFzu0gYV 0QSQ== X-Gm-Message-State: AGi0PuY/Nb9lPlU7Uz1utHh+6aVldtxYaewaDGsRznriqAZK/a1xHWdH bLn0E6MhD5jGge1ibLbAyp2cGQ== X-Received: by 2002:a65:5a87:: with SMTP id c7mr8682833pgt.237.1585929812310; Fri, 03 Apr 2020 09:03:32 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id l9sm4212358pff.16.2020.04.03.09.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 09:03:31 -0700 (PDT) Date: Fri, 03 Apr 2020 09:03:31 -0700 (PDT) X-Google-Original-Date: Fri, 03 Apr 2020 09:03:23 PDT (-0700) Subject: Re: [PATCH] riscv: mm: synchronize MMU after page table update In-Reply-To: <20200324054945.26733-1-nickhu@andestech.com> CC: Paul Walmsley , aou@eecs.berkeley.edu, guoren@kernel.org, akpm@linux-foundation.org, rppt@linux.ibm.com, nickhu@andestech.com, mark.rutland@arm.com, nylon7@andestech.com, alankao@andestech.com, alexios.zavras@intel.com, tglx@linutronix.de, npiggin@gmail.com, anup@brainfault.org, zong.li@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org From: Palmer Dabbelt To: nickhu@andestech.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Mar 2020 22:49:45 PDT (-0700), nickhu@andestech.com wrote: > Similar to commit bf587caae305 ("riscv: mm: synchronize MMU after pte change") > > For those riscv implementations whose TLB cannot synchronize with dcache, > an SFENCE.VMA is necessary after page table update. > This patch fixed two functions: > > 1. pgd_alloc > During fork, a parent process prepares pgd for its child and updates satp > later, but they may not run on the same core. Adding a remote SFENCE.VMA to > invalidate TLB in other cores is needed. Thus use flush_tlb_all() instead > of local_flush_tlb_all() here. > Similar approaches can be found in arm and csky. > > 2. __set_fixmap > Add a SFENCE.VMA after fixmap pte update. > Similar approaches can be found in arm and sh. > > Signed-off-by: Nick Hu > Signed-off-by: Nylon Chen > Cc: Alan Kao > --- > arch/riscv/include/asm/pgalloc.h | 1 + > arch/riscv/mm/init.c | 2 +- > 2 files changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h > index 3f601ee8233f..071468fa14b7 100644 > --- a/arch/riscv/include/asm/pgalloc.h > +++ b/arch/riscv/include/asm/pgalloc.h > @@ -51,6 +51,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm) > memcpy(pgd + USER_PTRS_PER_PGD, > init_mm.pgd + USER_PTRS_PER_PGD, > (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); > + flush_tlb_all(); > } > return pgd; > } > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index fab855963c73..a7f329503ed0 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -203,8 +203,8 @@ void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot) > set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot)); > } else { > pte_clear(&init_mm, addr, ptep); > - local_flush_tlb_page(addr); > } > + local_flush_tlb_page(addr); > } > > static pte_t *__init get_pte_virt(phys_addr_t pa) As a general rule, any fences are supposed to have a comment describing why they're there. The generic fences will be caught by checkpatch, but I don't remember if these are.