Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1683685pxk; Fri, 18 Sep 2020 21:45:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqn37Tog/9vI/QBdHdcB0iZ89NrrVSyuLG9fcq/KYuGWUJ8YppH8GCy5KVuErTkhoi0kbg X-Received: by 2002:a50:ab1d:: with SMTP id s29mr43654825edc.246.1600490703442; Fri, 18 Sep 2020 21:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600490703; cv=none; d=google.com; s=arc-20160816; b=Hgw17/PTwwQxMmHndOKbJWb4B5SlbL0TG1oK1u0GeFGVrJpnKIsCh68w1OthpvfGSw WE6EylzEzom/1VH+Dzi1uhmKwn1xyZktuUjYBvxfnWaPsbfjxN2cgCSNz0EyuSVaVOqP qq49RVkzoDdeOgRN5UPuRj9CJuSVFP4h7FXZQ9sgOXGC+5o5sDUNAlW9VXr43Z4TsKkl x0vUNNVGRYLHvyj9THC6qZxse6GO8gvHw53y+TgNRt6z7bn2EAd1dSgpOU4i1t8rfYzv HC6x9VuT1ZggOl6UveKRFNFD/dBGVuEbjSrtZcgyG3TUe6lkcmXfpOnfY2/KzT1VmUvl lfVg== 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 :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=0U+Dbiw8JUnuvLwJ+RFlNrwPxKsZPBsQuslXlMIRDCg=; b=F+oXTVQdwb7DvgEaC9fGD60Ssj4fbgCR8+Gimv904mKCGx+etoR2mczx7RaBji8Wxl RWX2WVztRMnlwhcTeqfQBteZQTCTTRpTk5PcQ9eDl8J0UVRRPoy22lk1VtOocnqmBGDF 44Y6x6gGQgFx9hQa8zXRQUOY+mFGlMhmTAtTi3q6YO36uPc8ivK1H65s3sF59XG+tR97 OSVzP3PAjeZO6uDsJDZS0/rX66qOj5nwduwExgI1509QZga5X1I+euJblzR520UPC1ll u3datYB7D1bB3yuaLWIeEBZiMrEaeP/gQPx7gT/f2CFFxfIV5HScQc754kjRztwpxVRw I0JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=VYQfGUEA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si617366ejx.264.2020.09.18.21.43.42; Fri, 18 Sep 2020 21:45:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=VYQfGUEA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726129AbgISEl3 (ORCPT + 99 others); Sat, 19 Sep 2020 00:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbgISEl3 (ORCPT ); Sat, 19 Sep 2020 00:41:29 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4600EC0613CE for ; Fri, 18 Sep 2020 21:41:29 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id k13so4055823plk.3 for ; Fri, 18 Sep 2020 21:41:29 -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=0U+Dbiw8JUnuvLwJ+RFlNrwPxKsZPBsQuslXlMIRDCg=; b=VYQfGUEAu1xJLuJK5YTF17kGuh93Q5ohcNEDSoejfjVEt3m7CxO8A7tcG7NArx8/0E a5W1lLZgVlcr9x/t/TSsOh2I4v/4F1aoa4LLr0iNm1aRfzTu0TQZXVb317zLs+BSlnSH ARB6Z5n+2hRN6Hc0xVMTnSBKaSSDCHpBLI3ddFtup8AdiSi3n56bbU6wCkQLqud595Wx mL9wyWOI6o7OJ2xnlVXivkB0Pva17j0PCM/kknp6x4WwqC0IdNGZZjiXmCXdW8zRUIcT SabCsY2uLEzb3bLZ8mhu1kQPmSVDMp7N1CkybT5fiJ+/kH0dTfNcxmIiHBd2xK7ctNjF GfXQ== 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=0U+Dbiw8JUnuvLwJ+RFlNrwPxKsZPBsQuslXlMIRDCg=; b=oYl580o6yoMxNC9ckT+dN0kWDPRkGTnWCBnB8rZRNqQ729zpuP+wA6ywwjKAuhZ6hd CZNOjDpHEcm6cZrfhTrxD33lIZXsLJdNAbH6UhPtTzVh5HaxNDS9JSsBBrBuZV31kQsi pIQY5i7espHc1hhUdJU7OPdYmiINiai/QWWSC/AiX4khuLSQzraU1HexRyn1BVn9vvKd PVwlULYUGYL3Jr5FYqBoL5vwSocDewvlXJmi6ByN6hD6biyLbzuS6+UlFRYSQuNKBh9b IEy+D1alDfVf8xxOQl636a6wrMx94p/Er5QNtsPJTx/lGgINwwBcevplRb8Qpf8BQTmQ URUg== X-Gm-Message-State: AOAM530XUUPBybnC9k6Rpw7DsLosobmVR4SLZ3ZxLAM2W74Vx2GIEuXg FdkpLeJ8ZbAT0f1T/8wXV26ong== X-Received: by 2002:a17:902:ee54:b029:d1:f2ae:e2 with SMTP id 20-20020a170902ee54b02900d1f2ae00e2mr14059738plo.3.1600490488574; Fri, 18 Sep 2020 21:41:28 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id o20sm5044877pgh.63.2020.09.18.21.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 21:41:27 -0700 (PDT) Date: Fri, 18 Sep 2020 21:41:27 -0700 (PDT) X-Google-Original-Date: Fri, 18 Sep 2020 21:41:25 PDT (-0700) Subject: Re: [PATCH] riscv: Add sfence.vma after page table changed In-Reply-To: CC: catalin.marinas@arm.com, Will Deacon , Marc Zyngier , mark.rutland@arm.com, anup@brainfault.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu, Paul Walmsley , syven.wang@sifive.com From: Palmer Dabbelt To: greentime.hu@sifive.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 14 Sep 2020 20:58:13 PDT (-0700), greentime.hu@sifive.com wrote: > Palmer Dabbelt 於 2020年8月5日 週三 上午10:03寫道: >> >> On Mon, 03 Aug 2020 20:29:32 PDT (-0700), anup@brainfault.org wrote: >> > On Tue, Aug 4, 2020 at 8:32 AM Greentime Hu wrote: >> >> >> >> This patch addes local_flush_tlb_page(addr) to use sfence.vma after the >> > >> > s/addes/adds >> > >> >> page table changed. That address will be used immediately in >> >> memset(nextp, 0, PAGE_SIZE) to cause this issue so we should add the >> >> sfence.vma before we use it. >> > >> > Alternate version of this commit description can be: >> > >> > Invalidate local TLB after both set_pet() and clear_pte() because the >> > address can be used immediately after page table change. >> > >> >> Fixes: f2c17aabc917 ("RISC-V: Implement compile-time fixed mappings") >> >> >> >> Reported-by: Syven Wang >> >> Signed-off-by: Syven Wang >> >> Signed-off-by: Greentime Hu >> >> --- >> >> arch/riscv/mm/init.c | 7 +++---- >> >> 1 file changed, 3 insertions(+), 4 deletions(-) >> >> >> >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> >> index f4adb3684f3d..29b0f7108054 100644 >> >> --- a/arch/riscv/mm/init.c >> >> +++ b/arch/riscv/mm/init.c >> >> @@ -202,12 +202,11 @@ void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot) >> >> >> >> ptep = &fixmap_pte[pte_index(addr)]; >> >> >> >> - if (pgprot_val(prot)) { >> >> + if (pgprot_val(prot)) >> >> set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot)); >> >> - } else { >> >> + else >> >> pte_clear(&init_mm, addr, ptep); >> >> - local_flush_tlb_page(addr); >> >> - } >> >> + local_flush_tlb_page(addr); >> >> } >> >> arm64 appears to be upgrading all set_pte()s on valid kernel mappings to >> include the fence. It looks like the message from 7f0b1bf04511 ("arm64: Fix >> barriers used for page table modifications") is out of date, as I can't find >> create_mapping() any more. If that was some generic kernel thing then we >> should probably upgrade ours as well, but if it was arch/arm64/ code then this >> approach seems fine as __set_fixmap() isn't on the hot path -- I guess this is >> fine either way, but there may be other issues that the arm64 approach fixes. >> >> Do you guys happen to remember what was going on here? > > Hi Palmer, > > Some architectures add cache writeback in set_pte(), just like nds32, csky. > > https://github.com/torvalds/linux/blob/master/arch/nds32/include/asm/pgtable.h#L213 > https://github.com/torvalds/linux/blob/master/arch/csky/include/asm/pgtable.h#L104 > > Would you like to pick this patch or should I send another patch to > implement it in set_pte()? Sorry, I forgot about this. I'm picking up this patch on fixes, as it clearly fixes a bug. We might also have uncovered another bug, but there's no sense in letting this one hang around until we figure that out. I've cleaned up the comment text a bit, as Anup pointed out some issuses. Thanks!