From patchwork Tue Jun 18 06:12:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11000931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25B371395 for ; Tue, 18 Jun 2019 06:13:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 132D7289FA for ; Tue, 18 Jun 2019 06:13:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06E5228A0D; Tue, 18 Jun 2019 06:13:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 23DED289FA for ; Tue, 18 Jun 2019 06:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:MIME-Version:Message-Id:Date: Subject:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=4bJEO2MeUmBZkjU6jFmbU6NkSvDlCdOIJByh/1OD7wQ=; b=dQRt1ym0Xc73jm bs2NfKbuQkw/H3mryuAXEpKAcEAtQzKTM4PZ5vkFPgCAYpN8z3Lm7xoO87rwDhnhzXw48HToNqDY1 PnA/gDrkV9NaOeSNE6ga9TxXCU38zRKJSjkq34Nax6AqmollM93UJP0OqyNiibHxZxYQLPmdM78EU FUb0yuTg0nRQh66AUNBBrBPsLuM6inS0jIJ97wGrV1EZoIp+WgsNCl9tN4n7pFC/69ttM2mwBKk4e bw/pNZLpUKubrixCQU/UxP2J/EQEI88r/jmafB1cRsT0wjjYagnwa8ZIIBUz+I1yWz2OUNGGh1lgk FHRnHbv5cpe9nFF9Sn6g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hd7NQ-0008DO-NX; Tue, 18 Jun 2019 06:13:52 +0000 Received: from mail-io1-f66.google.com ([209.85.166.66]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hd7NN-0008Cf-IX for linux-riscv@lists.infradead.org; Tue, 18 Jun 2019 06:13:50 +0000 Received: by mail-io1-f66.google.com with SMTP id s7so26995211iob.11 for ; Mon, 17 Jun 2019 23:13:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:mime-version :content-transfer-encoding:cc:from:to; bh=tkmzKPJ8v/O/itnNgoUTzaNNri0XyAwxiGBCEfYBcG0=; b=YmdR3VoWtPNL6yU9bJj/8vYa36eDW/GmHIWiHRsr/b1Sx7WrfMByleqYt6UWM7i6mc V9j39IerbTTj4IhD0r0WL/W5I32FBVKLK3QbQ0O9j0Ppm9AbULbqYAnJpdHYiV5fZ9HW 2vim7SnPdHnfLFByuD/CdAPJw53H+Ly5NoVnhVeORtNtvuvGWEPXQnT7FYn9+QfFuVyI kDlh17EKnKITcxBa7+g8biCxdFyL5syeot71aErGMoaEjLOaYy6VAqF7Ycawf1SNaI9Z jywjYrxLTz54g22hiW8Ez8y/wVOjMKa0WufK+V47uCdiR2uZ8ltHdLn30qtFndlu2G1U LLYg== X-Gm-Message-State: APjAAAVJfPknHVRqh/rZM4+2FMNkGVVnCue6ByOSup3o4jakS5I/wpR4 /J9kKnz/fSidP4E6BPSxVVDOp03+kJ5Vrg== X-Google-Smtp-Source: APXvYqyJrTKvL5aqOL4vqLndifQoIftcE6YdC3+xO0ObU+yua7RYLXa3ZnO59zlwbA8zft9/CWY6ZA== X-Received: by 2002:a02:b10b:: with SMTP id r11mr892354jah.140.1560838427896; Mon, 17 Jun 2019 23:13:47 -0700 (PDT) Received: from localhost (210-61-29-234.HINET-IP.hinet.net. [210.61.29.234]) by smtp.gmail.com with ESMTPSA id t133sm28866985iof.21.2019.06.17.23.13.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 17 Jun 2019 23:13:47 -0700 (PDT) Subject: [PATCH] RISC-V: Avoid using invalid intermediate translations Date: Mon, 17 Jun 2019 23:12:03 -0700 Message-Id: <20190618061203.7256-1-palmer@sifive.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 From: Palmer Dabbelt To: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190617_231349_609222_19091B0A X-CRM114-Status: UNSURE ( 9.94 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Palmer Dabbelt Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This is almost entirely a comment. Signed-off-by: Palmer Dabbelt --- arch/riscv/kernel/head.S | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index fe884cd69abd..fc5534e9cf4b 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -99,7 +99,9 @@ relocate: /* * Load trampoline page directory, which will cause us to trap to - * stvec if VA != PA, or simply fall through if VA == PA + * stvec if VA != PA, or simply fall through if VA == PA. We need a + * full fence here because setup_vm() just wrote these PTEs and we need + * to ensure the new translations are in use. */ la a0, trampoline_pg_dir srl a0, a0, PAGE_SHIFT @@ -118,8 +120,14 @@ relocate: la gp, __global_pointer$ .option pop - /* Switch to kernel page tables */ + /* + * Switch to kernel page tables. A full fence is necessary in order to + * avoid using the trampoline translations, which are only correct for + * the first superpage. Fetching the fence is guarnteed to work + * because that first superpage is translated the same way. + */ csrw sptbr, a2 + sfence.vma ret