Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1208762imm; Fri, 3 Aug 2018 21:41:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcipjaz8NsgTsI1z80VaKuGSTUPIsIcLti49qRXGmLe0tm7Dd0rPCnXpx/9p5ncWoYAE7xL X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr7611930pfa.238.1533357691646; Fri, 03 Aug 2018 21:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533357691; cv=none; d=google.com; s=arc-20160816; b=TNFeXAEPT4nkr2v51U/Ep3Jyw8sFxlij6ltnXSSGuSdeRprQGt0stPJSciFCYLzjBD riaxjwBUr7tInmktZzC6TerRq8dxB4qoYGOKJcD0mSUVRoFP8pps3rk4tGWcx9KS2sZJ WDWFx7pfF57Td+IaajSo6qKeCPvPi4dCCg3e3uLvFY1MUi8hpLTiO01zad0pD7tL4Oje rWr+9hOjzY+or0hdcyMll4IiBaVK+0mi00ODINLHXFCVxXFW725qYgSxF5WPuh2vGOYT S+6O0nmOJL5Zivxz5V4mqjiDjK2ycy4JdYATXt7oqPv97xUUcVaAgYZSO8r7eQ5Eq900 2zqg== 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 :arc-authentication-results; bh=HrFHu5/j/arhYev57DuuXbHoBa5A6DHUXqASBZAO+y8=; b=1I2vVAZ+O2O2/kNGYew6pv3Ej49mHJg3MSgqSCQjKT7wpRvjWgiBl2+g1k1wPOZzDe qq5NU5KUldBxUbW/2uM5BvqGiLy+QfLjPCtT8ZgrfAk/7xMKhLeczpANK66djjvfRxws 1SBPmcdGWMQOEHm9l8LUes7zuag0XVo6MGJ2ovb5hCWm58IXpAYXrbj1yHwO6WlHWziH NELmQnP/R8j/oTxUCimxrbprkQJPMvyQ+9XJMkR1+Swg9uq8OG9K5OHPJpyEkY7um39Z +Wsab8UpqqBB7gNtz0vMvcP2R2SQ48c3jbc6/81FDptOxuy/xWfWLZ2MOp4daiC26KcG m19Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=gXuCQNRD; 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 n11-v6si4996363plg.344.2018.08.03.21.40.46; Fri, 03 Aug 2018 21:41:31 -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=@sifive.com header.s=google header.b=gXuCQNRD; 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 S1727118AbeHDGhe (ORCPT + 99 others); Sat, 4 Aug 2018 02:37:34 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38123 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbeHDGhe (ORCPT ); Sat, 4 Aug 2018 02:37:34 -0400 Received: by mail-pg1-f194.google.com with SMTP id k3-v6so3753376pgq.5 for ; Fri, 03 Aug 2018 21:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=HrFHu5/j/arhYev57DuuXbHoBa5A6DHUXqASBZAO+y8=; b=gXuCQNRDFi1dx2LOE5xSvzMcKW4j4pHiU6Y8P24d4HBcBWtGGcB+eEgOXnPsBU2Qgy hjRrolqypd4KMot0Xx9IGoDKEMkbsqkhWQR19NB31jURVHbO+kxO+sXw9HODauXj2bEC mIUd7DCtGXNsGHY3Liyr0TA9ShZny36eI2RLcsq3JUIxp9RS4SrmWrsd8jJH5zU7WtOt 8IOFsKCv1hgyQ3xps0NBSUqaj3+sLzAa17uZADhEc72cvA7TaQrVkSpJg4uY/PAfNSSw pWvjmAxPB2DNXlaT9Vsg/vbs4mvve2IsMpJZvdM3GeUHbLyEgfuB+tJPLI2GwYto2BlZ wP2A== 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=HrFHu5/j/arhYev57DuuXbHoBa5A6DHUXqASBZAO+y8=; b=uhHhX8YUKoib58uBO0RGxXrBVGnz0rxBlSujtKil6f7fGNpqirYK6JHC+JtxOuWt2x nFm91PY+76UnUl1lMqqNWiJIZAHRqVReuQentCjMs4LmlPA5+Pf9tsbZ0ARnj8kpheqs 0f1KykPFtCS+HPNPcQNdSO9HsUBMQxO0kHgRnIT+7RmWWMZXy37MdpBEclQa/IBsGWMw Ru5ZCrZaDR5CJNbycC5WOIQOu2vdV9WxqYNIhjjjXrn95anhqRjku67odup+Ba9NAtxU NwcY6YNhAB8EJ/VVRTBY45PTPdrJ95PJvYjIpjqbbzV1+DM7mhcXFTAPoGIZpBY36bYY d3xw== X-Gm-Message-State: AOUpUlExgfA3yEn6c+aAvjAVZFNmt34tMPNXaMEXGSw5e0mhr9K3FpD9 Q5zgiMVm33UCbNes9AdT3inB2Q== X-Received: by 2002:a62:3241:: with SMTP id y62-v6mr7568103pfy.4.1533357500919; Fri, 03 Aug 2018 21:38:20 -0700 (PDT) Received: from localhost (c-67-161-15-180.hsd1.ca.comcast.net. [67.161.15.180]) by smtp.gmail.com with ESMTPSA id o27-v6sm9569961pfj.35.2018.08.03.21.38.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 21:38:19 -0700 (PDT) Date: Fri, 03 Aug 2018 21:38:19 -0700 (PDT) X-Google-Original-Date: Fri, 03 Aug 2018 21:14:20 PDT (-0700) Subject: Re: [PATCH] RISC-V: Add the directive for alignment of stvec's value In-Reply-To: CC: zong@andestech.com, linux-riscv@lists.infradead.org, aou@eecs.berkeley.edu, linux-kernel@vger.kernel.org, greentime@adnestech.com From: Palmer Dabbelt To: zongbox@gmail.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 Wed, 01 Aug 2018 18:26:48 PDT (-0700), zongbox@gmail.com wrote: > Palmer Dabbelt 於 2018年8月2日 週四 上午8:38寫道: >> >> On Wed, 20 Jun 2018 18:40:07 PDT (-0700), zong@andestech.com wrote: >> > The stvec's value must be 4 byte alignment by specification definition. >> > This directive avoids to stvec be set the non-alignment value by the >> > following code in head.S >> > >> > /* Point stvec to virtual address of intruction after satp write */ >> > la a0, 1f >> > add a0, a0, a1 >> > csrw stvec, a0 >> > >> > Signed-off-by: Zong Li >> > --- >> > arch/riscv/kernel/head.S | 1 + >> > 1 file changed, 1 insertion(+) >> > >> > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S >> > index 396ec7b349ce..ae7b204f531c 100644 >> > --- a/arch/riscv/kernel/head.S >> > +++ b/arch/riscv/kernel/head.S >> > @@ -94,6 +94,7 @@ relocate: >> > or a0, a0, a1 >> > sfence.vma >> > csrw sptbr, a0 >> > +.align 2 >> > 1: >> > /* Set trap vector to spin forever to help debug */ >> > la a0, .Lsecondary_park >> >> I don't think this is actually correct: you shouldn't be aligning the address >> at which stvec is set, but the address that stvec is set to. If this is fixing >> anything then it's probably just by coincidence as it's causing >> .Lsecondary_park to be aligned. >> >> I think this patch is the correct fix >> >> diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S >> index 6e07ed37bbff..d1beecf1d060 100644 >> --- a/arch/riscv/kernel/head.S >> +++ b/arch/riscv/kernel/head.S >> @@ -143,6 +143,7 @@ relocate: >> tail smp_callin >> #endif >> >> +.align 2 >> .Lsecondary_park: >> /* We lack SMP support or have too many harts, so park this hart */ >> wfi >> >> Thanks for pointing this out! >> > The position which I set in this patch is also be set to stvec for jumping to > correct VA at satp enabling. The label .Lsecondary_park is also be set to stvec, > I don't notice it because as you said, this label address is correct > just by coincidence. > I think there are two places need to be aligned. > > The first setting as following: > relocate: > ... > /* Point stvec to virtual address of intruction after satp write */ > la a0, 1f > add a0, a0, a1 > csrw stvec, a0 <----------- first set > ... > sfence.vma > csrw sptbr, a0 > 1: > /* Set trap vector to spin forever to help debug */ > la a0, .Lsecondary_park > csrw stvec, a0 I agree. I think this should do it: commit a8c5f596bcd528c5468d621bc84cd901632a912a gpg: Signature made Fri 03 Aug 2018 09:13:56 PM PDT gpg: using RSA key 00CE76D1834960DFCE886DF8EF4CA1502CCBAB41 gpg: issuer "palmer@dabbelt.com" gpg: Good signature from "Palmer Dabbelt " [ultimate] gpg: aka "Palmer Dabbelt " [ultimate] Author: Palmer Dabbelt Date: Wed Aug 1 17:38:30 2018 -0700 RISC-V: Align early stvec targets The ISA mandantes that stvec is 4-byte aligned, but we weren't actually respecting in the early boot code. These trap vector are never expected to actually be used unless there's a bug in early in the boot process of the kernel, which explains why the bug wasn't noticed until recently. Thanks to Zong for finding the bug! CC: zong@andestech.com Signed-off-by: Palmer Dabbelt diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 6e07ed37bbff..c4d2c63f9a29 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -94,6 +94,7 @@ relocate: or a0, a0, a1 sfence.vma csrw sptbr, a0 +.align 2 1: /* Set trap vector to spin forever to help debug */ la a0, .Lsecondary_park @@ -143,6 +144,7 @@ relocate: tail smp_callin #endif +.align 2 .Lsecondary_park: /* We lack SMP support or have too many harts, so park this hart */ wfi