From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38DD6C433ED for ; Fri, 16 Apr 2021 11:36:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 97AD76101E for ; Fri, 16 Apr 2021 11:36:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 97AD76101E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lXMmM-0005jB-VY for qemu-devel@archiver.kernel.org; Fri, 16 Apr 2021 07:36:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lXMkO-000499-Vr; Fri, 16 Apr 2021 07:34:52 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:44886) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lXMkN-0002uL-8w; Fri, 16 Apr 2021 07:34:52 -0400 Received: by mail-ed1-x52c.google.com with SMTP id f8so31849372edd.11; Fri, 16 Apr 2021 04:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=N8klAhgCyaEwa0TiMOJwHXJKTXvCrrhpztUoJxQL32Y=; b=QPCWkXCLixy3iA3zTIo9nPepaGPw4nK0rO3RdWa13NxWdJzqJUUovqekGvoqyjOTdw O4YRzRHsozi2DCFk4LnV+A4RF8JVINYHr1gX0juppMcZw/ENRwrwjxBOEx9Ds6D/I27T luPQzgBos4+YlITXzVK8vDIoVDJZCLlB3yhTNknsAnRJNpAzx05tcu3Y+SXxmI2xfxFM vS8BjYk+OcEQGnpiM00rMgwNwKTDnQogQjQNLFIdc5oAp4KKrKafWwExKDhNaED7b3P2 V7p9ZpRCdj4IMRLR02e/PoDRV2v51LEVCA2AZKUShMNnqfoqn/BAIFnp2heXt+rMmOn8 we0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=N8klAhgCyaEwa0TiMOJwHXJKTXvCrrhpztUoJxQL32Y=; b=jq+3X90tkUzT50+sEwamvohsyqlfCJPCVqipQm+XuV8gqx7mJ18REiHKDGYCDomgwe 3aqUSOH+icWWLKcAOIupxLTb3xD/mYJtFnyS3alXpNpbm93TdAZYw9cCrqFB85N3++Ur HbQi42UobfTZ8CzGe1LaxqNKViRTdxp95vKNeK0b2mUn4uCntqOIF8jveyLuPJ1EI/nb jBaVIBpAZtzLaHvxBOTkyJdGQG1dser1V0plQ4NjelxICrmMHv4oEeSwn7QAS7sC280G 1TRjBSO4Rdp12goKO89USHZyCWKtf4R9yegkI3XLdZ84FLQnM1pd8OoQ68WDEJ+iZ2b1 MT6w== X-Gm-Message-State: AOAM530FDNTX41lj+B8iNSfsV9hsiK8JTsT5fkXt/Yu1wC5hLVicu2s/ FWThzkxajzrw8Cdkli/Nb7TwrgDhhWPOQf4kB+s= X-Google-Smtp-Source: ABdhPJwr3zDVKkZSBmSlBcBMh36Nx/Oj0vijI7HOPPYy1ZN9oD/AIMITcDm30pOGqkygMCJZqKyrpWa8xhzXs+S02pU= X-Received: by 2002:a05:6402:350:: with SMTP id r16mr1921676edw.227.1618572888636; Fri, 16 Apr 2021 04:34:48 -0700 (PDT) MIME-Version: 1.0 References: <20210410194047.559189-1-josemartins90@gmail.com> In-Reply-To: From: Jose Martins Date: Fri, 16 Apr 2021 12:34:37 +0100 Message-ID: Subject: Re: [PATCH] target/riscv: fix wfi exception behavior To: Alistair Francis Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=josemartins90@gmail.com; helo=mail-ed1-x52c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:RISC-V TCG CPUs" , Sagar Karandikar , Bastian Koppelmann , "qemu-devel@nongnu.org Developers" , Alistair Francis , Palmer Dabbelt Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" > > - if ((env->priv =3D=3D PRV_S && > > - get_field(env->mstatus, MSTATUS_TW)) || > > - riscv_cpu_virt_enabled(env)) { > > + if ((!riscv_cpu_virt_enabled(env) && env->priv =3D=3D PRV_U) || > > > + (env->priv =3D=3D PRV_S && get_field(env->mstatus, MSTATUS_TW)= )) { > > Shouldn't we check here that we aren't virtualised? > In section 5.4, the spec states that mstatus.tw has effect regardless of virtualization mode: "The TW field affects execution in all modes except M-mode.". I interpret "all modes" as being all supervisor modes since section 3.1.6.5 states that "When S-mode is implemented, then executing WFI in U-mode causes an illegal instruction exception" and later chapter 5 says that a virtual instruction exception should be generated when "in VU-mode, attempts to execute WFI (...)" regardless of the state of any status bit. Plus, it should be an illegal instruction exception and not a virtual instruction exception even in VS-mode when mstatus.tw =3D 1 because the spec also states only "When VTW=3D1 *(and assuming mstatus.TW=3D0)*, an attempt in VS-mode to execute WFI raises a virtual instruction exception". But just now I realized the patch is assuming S-mode is present and not taking into account M/U only harts. If this is the case TW should affect U-mode WFIs. I will fix this and submit a new version of the patch. Jos=C3=A9