Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E207DC3DA7F for ; Wed, 7 Aug 2024 22:58:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sbpbi-0007Zk-OO; Wed, 07 Aug 2024 18:58:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sbpbh-0007XV-0g for qemu-riscv@nongnu.org; Wed, 07 Aug 2024 18:58:13 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sbpbf-0001Kz-47 for qemu-riscv@nongnu.org; Wed, 07 Aug 2024 18:58:12 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so261597a12.3 for ; Wed, 07 Aug 2024 15:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1723071488; x=1723676288; darn=nongnu.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=dNtlUwRE0dZsEwVFmBEuRpBpGeatpEHPUj93pPjtvuY=; b=eST/a9IpxAgwQrlPvBEmr2gVDIZqSLE33DEqXH5WokVgslymdIyKVDy+twFTMPUF+s bPQjzc2WxFjuT+T2NZkm77+z9Hx4wuJdUmVJ5sXFwjEhOZ2u7krEUFLizSmUwoP1vD1q PaPvJqGQHALfY+4DoDNwPTAEjNpMfxoUtUvOE9o0s95PWI8/KBm9r7pwGvVl08NZ56vo Ows9uijncP12KsjOEsjsS1fBiyqdMlZgNTHB63FUEuCk5ci4RSiavxkBgdw7I5derotq 1PyQIwUi6BopKEoUh6ZRimr+eXIzA4L8lADZxABgEXqU0KEcaIvPnoS+F4wE8MiHG7M+ SAFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723071488; x=1723676288; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dNtlUwRE0dZsEwVFmBEuRpBpGeatpEHPUj93pPjtvuY=; b=YH7KPlT50Z7qwQk5X+HUliJwIw35NC/DuJeO6Q7+9YYT48a3NiSw3K6PLi2NkPVnjv eAKeiYhzMTz8hqdRFV/4x0fIRIeDBxxgQMWsBoOpN+L0QYge9FBlFAJZkQgzgv6Me7vg b167MlhLHZK/TLzryTQw11WjLvI30cdAZhRk1xNbdW61v74tHjeUWqYGBgTV//2FP9U1 H872MR8y26R+tp0wafQyo0pBTPNFuenqJyFOS9cwDyOK/jUENM3ZIlwqxE+qRBeDF9F9 pdYtEXQW8TckbZZ91zBFnO9vhzX/o+B/3hsSObT60pg7aOnD+NsQ3QWiaf2vkBQRKIFW +QPA== X-Forwarded-Encrypted: i=1; AJvYcCXPlx1UzmbbjLUaw3WY8ddUL39/zFnbPakcshYIzq7zmbH+kHl/+SM4Ng+wn8lfc1s8gGu+MAoy1n9WWX07amWLJ0cGzSc= X-Gm-Message-State: AOJu0Yz19T7NR60H6rlYxYq1r69kY9Jq+dAqGdwgm7h0lk52RezUsJ06 gc5RaJhg7YqRtOVlt4wB6xtpHzBuvBg3Ysa5VAkVYrcWmjAxdgTVLYAqN/bPYUE= X-Google-Smtp-Source: AGHT+IEhoyEfsFqwSqOg9CxngFExaobGHESvQZ6zRYiVnia/+qGxB8Hs/b3UnFAg15BwjC4/iDBp9w== X-Received: by 2002:a05:6a20:4387:b0:1c4:d05c:a967 with SMTP id adf61e73a8af0-1c69968d112mr25935095637.51.1723071488102; Wed, 07 Aug 2024 15:58:08 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2ccf1esm23752b3a.129.2024.08.07.15.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 15:58:07 -0700 (PDT) Date: Wed, 7 Aug 2024 15:58:05 -0700 From: Deepak Gupta To: Richard Henderson Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, pbonzini@redhat.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, Jim Shu , Andy Chiu Subject: Re: [PATCH v3 04/20] target/riscv: save and restore elp state on priv transitions Message-ID: References: <20240807000652.1417776-1-debug@rivosinc.com> <20240807000652.1417776-5-debug@rivosinc.com> <0f68fb8e-9821-4639-a934-ca1f4a668e4c@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0f68fb8e-9821-4639-a934-ca1f4a668e4c@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=debug@rivosinc.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, 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-riscv@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org On Thu, Aug 08, 2024 at 08:40:08AM +1000, Richard Henderson wrote: >On 8/8/24 06:11, Deepak Gupta wrote: >>>>+    /* >>>>+     * If forward cfi enabled for new priv, restore elp status >>>>+     * and clear spelp in mstatus >>>>+     */ >>>>+    if (cpu_get_fcfien(env)) { >>>>+        env->elp = get_field(env->mstatus, MSTATUS_SPELP); >>>>+        env->mstatus = set_field(env->mstatus, MSTATUS_SPELP, 0); >>>>+    } >>> >>>The spec is perhaps poorly written here.  I read >>> >>> ... if xPP holds the value y, then ELP is set to the value of xPELP if yLPE is 1; >>> otherwise, it is set to NO_LP_EXPECTED; xPELP is set to NO_LP_EXPECTED. >>> >>>as xPELP always being cleared, regardless of yLPE. >> >>Yes that's what code above is also doing. restore elp status from SPELP field and clear >>it at SPELP. > >No, my point is that the text doesn't seem to be > > if (enabled) { > restore elp > clear pelp > } > >but > > if (enabled) { > restore elp > } > clear pelp > >I.e. the clear is unconditional. hmm. that's right. good catch here. > > >r~