From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185525; cv=none; d=zohomail.com; s=zohoarc; b=NRBvqh5iHubTOzzeZ/BHjzys0i9RGgIo0EuenwvGp2MEa3pL4saAFEFF0oywRD5M7hQUrPxDQvQK1zgR7sJbBA/SdaMu31pGGfFDRQ+4aHiJKeLg8NFgS209Yb6kPOwlEdkMqeN1Gzed83iBgOWEb3b0kMbEOmiPE2Pm22q/IBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185525; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TMePisP4WQCzboJNarE0AWmbKJNyXZU7VtdMcudOguQ=; b=ehsWKz5vKxQ7JXXappJFmSd84uQEwi+YSK8+3Ee5Ru1ckKpwjjDinwfbxPoTAsXv4lyYsA7/+E8TTaIAvfSu14FZ4zdMQYVYAUGbbM+OQQF1agrvFNIqQAn+atD7ufeQ3OnBEgvoHWe3JzCt+0xnDmVn3jrhryeDDcQq+xZ9EvY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172618552519058.937647597117575; Thu, 12 Sep 2024 16:58:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd0-0004Qq-1O; Thu, 12 Sep 2024 19:53:34 -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 1sotcw-0004Hu-Uf for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:30 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotct-00087A-G2 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:30 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-7d50e865b7aso1438189a12.0 for ; Thu, 12 Sep 2024 16:53:26 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185206; x=1726790006; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TMePisP4WQCzboJNarE0AWmbKJNyXZU7VtdMcudOguQ=; b=ZjAOEDzlcsXVfwF3HZx57uFQt2QUyH6HEbKSawT9SPg/Y0M6+PGm4/f6ubhOFizI22 VNA2za4r3AT2j8CZsX+62BFAXm2xMiWo2MFjvGl24zeuBNK0LyIysx6ulz9S0p2TgzmA FF1+VYWOmzyJeFcBMpb88Tphdn1wLJdN2TWWbFVExbFaNgnaovn2uYqUKijxbm6OPonx RWJrUEzO+fw5K31X+DWLKdcU67+fQDORLA7tJRG699b/LkKA4tY14s9BNRe7zAjL2a/G rtlxZVAIAdeTow8gLMIvuBatvHOXOzal7CPlvhOZ9RTr97M3ueNwnG1liiatUjXTRvOh 6NYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185206; x=1726790006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TMePisP4WQCzboJNarE0AWmbKJNyXZU7VtdMcudOguQ=; b=AzmJKkupbc8dAhrWjH8JQAoqbe51+vL/+dpbnK7p/UTgm2fZvyW5dcG+MNqZwZpRyS 5q6swWCTtR+Gpw+kC2oxo+9vlEzqZ97jMk7GVUdwwFWZu/GaXumYxvwzyVIIsF+UAUmG Vq6XHWkN0YvGi+bcHULoI1+jg8I7vZn9YfZ+oc1coUppa7w+gLqBlmxYZe44sfIDVtaX fKVJm1DadPOB6ORDVeYiZNFFKxY59UYbsWtsgrotIgjC2d6TMosgVmC6CpZszfP5hNnX hY/+T+sOT/yU64nY3w/CNz9EbXHe3q5dniRyixUB6gQuM2hmVCSrxteCvPBDzmHSa5xU w2yg== X-Forwarded-Encrypted: i=1; AJvYcCUJjYBodZgAVhrcs0TxARIi8OeE5OfYLEk6peTq6YL+0HwcQGoHwSbDmOVU2X/SAxvWfyNduNsZBuiZ@nongnu.org X-Gm-Message-State: AOJu0YzoOyiLxH6DKoMzPtLz8xlCelwciXl1iPZnbVL8EcMVwGos9t4q Xds/Vob869xi5Vr8LPdN2QML38dztGzOBgabvxQnDSq3sRuqPCqZpa1bwFpIGpg= X-Google-Smtp-Source: AGHT+IGcROfhgI7acfcQOPNZzTECr48kuMlHpAdGSECyx2jP0g8PE+lABTw0kcrrKAuNauC+5tkjQQ== X-Received: by 2002:a05:6a20:c793:b0:1cf:e5e5:24ad with SMTP id adf61e73a8af0-1cfe5e524e3mr4435082637.30.1726185205661; Thu, 12 Sep 2024 16:53:25 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 01/20] target/riscv: expose *envcfg csr and priv to qemu-user as well Date: Thu, 12 Sep 2024 16:53:01 -0700 Message-ID: <20240912235320.3768582-2-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=debug@rivosinc.com; helo=mail-pg1-x535.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185525655116600 Content-Type: text/plain; charset="utf-8" Execution environment config CSR controlling user env and current privilege state shouldn't be limited to qemu-system only. *envcfg CSRs control enabling of features in next lesser mode. In some cases bits *envcfg CSR can be lit up by kernel as part of kernel policy or software (user app) can choose to opt-in by issuing a system call (e.g. prctl). In case of qemu-user, it should be no different because qemu is providing underlying execution environment facility and thus either should provide some default value in *envcfg CSRs or react to system calls (prctls) initiated from application. priv is set to PRV_U and menvcfg/senvcfg set to 0 for qemu-user on reest. `henvcfg` has been left for qemu-system only because it is not expected that someone will use qemu-user where application is expected to have hypervisor underneath which is controlling its execution environment. If such a need arises then `henvcfg` could be exposed as well. Relevant discussion: https://lore.kernel.org/all/CAKmqyKOTVWPFep2msTQVdUmJErkH+bqCcKEQ4hAnyDFPdW= Ke0Q@mail.gmail.com/ Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 5 +++++ target/riscv/cpu.h | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index cb675f0278..3538c2ae2e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1024,7 +1024,12 @@ static void riscv_cpu_reset_hold(Object *obj, ResetT= ype type) } =20 pmp_unlock_entries(env); +#else + env->priv =3D PRV_U; + env->senvcfg =3D 0; + env->menvcfg =3D 0; #endif + env->xl =3D riscv_cpu_mxl(env); riscv_cpu_update_mask(env); cs->exception_index =3D RISCV_EXCP_NONE; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 1619c3acb6..2623f6cf75 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -234,8 +234,12 @@ struct CPUArchState { uint32_t elf_flags; #endif =20 -#ifndef CONFIG_USER_ONLY target_ulong priv; + /* CSRs for execution environment configuration */ + uint64_t menvcfg; + target_ulong senvcfg; + +#ifndef CONFIG_USER_ONLY /* This contains QEMU specific information about the virt state. */ bool virt_enabled; target_ulong geilen; @@ -445,12 +449,9 @@ struct CPUArchState { target_ulong upmmask; target_ulong upmbase; =20 - /* CSRs for execution environment configuration */ - uint64_t menvcfg; uint64_t mstateen[SMSTATEEN_MAX_COUNT]; uint64_t hstateen[SMSTATEEN_MAX_COUNT]; uint64_t sstateen[SMSTATEEN_MAX_COUNT]; - target_ulong senvcfg; uint64_t henvcfg; #endif target_ulong cur_pmmask; --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185523; cv=none; d=zohomail.com; s=zohoarc; b=TigUoFCEKWmqSt39VeLaSLTadx0niSapQITXP19JvA5eWFeS6eFhgWSRGDLVynVphov7kzSVH9oHaxrE+OU8JUqKyJfHqDCEzplNztcPPGAce36XO4N3gH1XRrDSbz1+kdlanv+ehD738Ae4SejxUACbtF+aV+Nj2TnttqRD3DE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185523; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tKWLA1wBspGoBsf/BOw/3kLwYELdIQ/tonPN4Kip9A0=; b=bk1VL8d6Jw8rbc6BPRZPMJHyyvxUumaVborTsWMgyNwNSTM+YomF+5K45tX8oUJGslDeaVlJGFk3Ym9qnxhYHxZtZuU2Lz/vQlfhlhMJp6Bmr3Zji4VhrqpoTunDFeX1tlXQ9cXq0wE5xXm6X7svfmg1SV6lPBVo87ke++scPhk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185523701472.8358710684636; Thu, 12 Sep 2024 16:58:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd0-0004RB-1k; Thu, 12 Sep 2024 19:53:34 -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 1sotcx-0004I4-2n for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:31 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotcu-00087J-IF for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:30 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-71790ed8c2dso1292810b3a.3 for ; Thu, 12 Sep 2024 16:53:28 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185207; x=1726790007; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tKWLA1wBspGoBsf/BOw/3kLwYELdIQ/tonPN4Kip9A0=; b=DGBm++ysgUfQZOIIHOE94XJJ6OcPANrKj0Q328OfJz/pPMmaqyEtHSuW7zKWScYkgw ohQKnsRJC04kMPEh6GgsVFICta/CXlLvxrtshwXdfGerfuHWIKh4h0d719NlCElkSnbU AlgvMDUR3eJ878UG01WWub2FwVoLbyb1TJE+nyBR8mNINpmwjuONh/bZieErARW4Bew+ MkC/w0dPaHkjZWF1zJ7+rrGriebMyh6Gorbk4tdWcr8IkhOCG4psYWeB0ufdXW5KP8CO iWyuWYegW7aAh+xdyUJ7dC5qfd2TZSVgAxfszDE7uJ7HHsPtKa75yWgzmSK8OCaAdzlU wYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185207; x=1726790007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tKWLA1wBspGoBsf/BOw/3kLwYELdIQ/tonPN4Kip9A0=; b=ibN88AEW1b+w2BcORVEc8qKWPxDrvaGO89rJC95+hBwGc9aZRc0BYBYw9vvXta/HDP 7CVtjxpansV+yWcfqwdhx8Yq2V0RoveLhCAVR/fgQ+c2F7IDepJbATExslnWosW0Oex9 iyFkFr8TFbRoMIBiFQ4cHNKy8zPHuQozVl1uoL4NnSHHSGRB1ldcLOTkGHtF5XUX+j6k 8/PtHd2B5a1eb0KiKJH/ozE5NH6UpCtzrCZeYXhGHxZgKi3/YB+DVlhTAXIYe2gI4Few zfuYnI9GjqgrmPOJwa7qhpfJQx3FzI3LeiImYzbNMnj+95GTQty18vEKx4+7Movim4OE HVKw== X-Forwarded-Encrypted: i=1; AJvYcCXQ8kTt8Vjp//2vkQ7J6kXXLhHjMqwFKT9Z59oPj9ykKLFPOajt4cvWXX+qX61vPhl+08AuXV3DKYsW@nongnu.org X-Gm-Message-State: AOJu0YypBWGudX79PhRztc2aVg0xX0ziE6CKKVwPazflxDL5eUss8Lxw yvRM9YXxWdVHhaY6P7mB+lOV7/nW8Scjic2KlkEDcCJkbmGKS/v7d4zJjX/2vXE= X-Google-Smtp-Source: AGHT+IEVUalst5W/Wq6nXcIIJ0xljO++bMS938YDzA4jtCb2dP+VrT1vs7pHuy7UWPwRAX4ZvZhDXw== X-Received: by 2002:a05:6a00:14d0:b0:717:9768:a4ed with SMTP id d2e1a72fcca58-7192609318dmr7903494b3a.16.1726185206997; Thu, 12 Sep 2024 16:53:26 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Alistair Francis Subject: [PATCH v14 02/20] target/riscv: Add zicfilp extension Date: Thu, 12 Sep 2024 16:53:02 -0700 Message-ID: <20240912235320.3768582-3-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42d.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185525604116600 Content-Type: text/plain; charset="utf-8" zicfilp [1] riscv cpu extension enables forward control flow integrity. If enabled, all indirect calls must land on a landing pad instruction. This patch sets up space for zicfilp extension in cpuconfig. zicfilp is dependend on zicsr. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 3538c2ae2e..ed2d8a90da 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -106,6 +106,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(ziccif, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, has_priv_1_11), + ISA_EXT_DATA_ENTRY(zicfilp, PRIV_VERSION_1_12_0, ext_zicfilp), ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), ISA_EXT_DATA_ENTRY(zicntr, PRIV_VERSION_1_12_0, ext_zicntr), ISA_EXT_DATA_ENTRY(zicsr, PRIV_VERSION_1_10_0, ext_zicsr), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 355afedfd3..fe7ad85b66 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -67,6 +67,7 @@ struct RISCVCPUConfig { bool ext_zicbom; bool ext_zicbop; bool ext_zicboz; + bool ext_zicfilp; bool ext_zicond; bool ext_zihintntl; bool ext_zihintpause; diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index dea8ab7a43..963c1c604a 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -623,6 +623,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, = Error **errp) cpu->pmu_avail_ctrs =3D 0; } =20 + if (cpu->cfg.ext_zicfilp && !cpu->cfg.ext_zicsr) { + error_setg(errp, "zicfilp extension requires zicsr extension"); + return; + } + /* * Disable isa extensions based on priv spec after we * validated and set everything we need. --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185440; cv=none; d=zohomail.com; s=zohoarc; b=HzNbSJf0yFUQNOtBNq5XGfg3dJFm0JV1Ja9Fs0QYgZyhbNTWK/sopk9AYXxJaO5EL1Jy5oklgb8sEAYxQTCm+GfElyNfOQrdfXGiKCfY4SzzOYiXUrUtHDgNJ+PiJ9NjouqnPTnZFEnRbLwHiYmccxq/uTskGbUpVPXIA8UDx5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185440; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EvRE8oM2uFjwFXIZ5uL/gQquoap3FaO+kJgkT4MKr8Y=; b=W1lXWgiQYBfWvWmqIKa2tcqYnSLbwfslOivu2xoFVBJUOrav9/i+LjJg1Yc2J4lwW3ynvDGtXzTCg4Pxb7TW0ke462KcQLCPEP1D4fSzMSaEHsIwGGBx7FgAWteeiDNaRoOeIs7qX4eA/6OHnkMy0awusW4UjJHq1jpvmnxhDx4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185439996276.8365049530297; Thu, 12 Sep 2024 16:57:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd1-0004W5-4s; Thu, 12 Sep 2024 19:53:35 -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 1sotcy-0004NO-Vg for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:33 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotcw-00087S-06 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:32 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-718f28f77f4so1434124b3a.1 for ; Thu, 12 Sep 2024 16:53:29 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185208; x=1726790008; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EvRE8oM2uFjwFXIZ5uL/gQquoap3FaO+kJgkT4MKr8Y=; b=f1Z99ClWq4S6m1BXcJrwqgjfeQ3EyViURA/KxxSH73dwnTLcaymUpuDSuQgJpU+H5s GhyI8ergcJZuvRgj+yXKcnv/OLZrOLfaUYymWhqhU2dAAboXq1OqVJzhoaAo99H1s5dp vKRRqMEs9TZfYESL12NNX7fxWdt8puIH/nhGX45OXkRR3CyemeH1tg/eygfqSaDEu5+K 9KGSOQ7Fr2xtaGOGf/gI9irY+QzvQ833yatruCIZCKvGs04ftJbfy1Luar//be6DSfnA rDH1eVVyQlbhbwB3MyOA2/OXctNG8HLHPu/yWVmZQJz6+NcJ4+8rqZ9c8zCCuPIwYvY5 hHzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185208; x=1726790008; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EvRE8oM2uFjwFXIZ5uL/gQquoap3FaO+kJgkT4MKr8Y=; b=b+3hhAdBaN4MUmoWCcBOgqyXMc20VCeyZNsgTJ3fX3YfiJMzCZgd9RpUJDWJXUsulY 3udVXBOcdn+mIY4VG1+bqnQNXji9cmGUCfr5bSa6IyUPF0E6EU1XbIDEkfJjkDBODtrG izST+WEkD64ZN9KxCXBhDkm88jvems6ay6J2jZb/grpaamu1+bvS8ga0RGOBP6MQAeoA rtXocP50PWRDajir94XLDvvQK/DNN474S0Lx7bk4XLAwVyz4jq9cp5pwr5ymVT8VPmCZ 0K0rVJGtsKtTWz5he+wUDviSRtCgNuFtmLI53RiSPS8HOVNRNA0qPOf2jlMbKaVj9DWO 4M1w== X-Forwarded-Encrypted: i=1; AJvYcCURFlt46r76TpPpgmLW9X0Yzqsj+w5WvyAHeTiJHEHlrDqBq1aLXRp/l9RHLbw5PTHY7EpRHuW3VsrH@nongnu.org X-Gm-Message-State: AOJu0YwrtW5HQ2LhQ6DTWi9/8y5E+SjbBM2A2Qnrvo6W4ak3FwuWimr8 noX+GMIrqOrtQ/Ygr/bcMuK7iW9yk1bSvyiqBeCjfpZtP5KTW+3L0o6/zCJyN1U= X-Google-Smtp-Source: AGHT+IGeFPSr8QFgtivRmVpqtkiwISQeJR+fLC72zI+J4/diHFI6zukc9qcYqt0p6xaxzZPzCzW3iw== X-Received: by 2002:a05:6a00:2d11:b0:714:2198:26a1 with SMTP id d2e1a72fcca58-7192620d8d3mr7099337b3a.27.1726185208429; Thu, 12 Sep 2024 16:53:28 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 03/20] target/riscv: Introduce elp state and enabling controls for zicfilp Date: Thu, 12 Sep 2024 16:53:03 -0700 Message-ID: <20240912235320.3768582-4-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=debug@rivosinc.com; helo=mail-pf1-x432.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185441274116600 Content-Type: text/plain; charset="utf-8" zicfilp introduces a new state elp ("expected landing pad") in cpu. During normal execution, elp is idle (NO_LP_EXPECTED) i.e not expecting landing pad. On an indirect call, elp moves LP_EXPECTED. When elp is LP_EXPECTED, only a subsquent landing pad instruction can set state back to NO_LP_EXPECTED. On reset, elp is set to NO_LP_EXPECTED. zicfilp is enabled via bit2 in *envcfg CSRs. Enabling control for M-mode is in mseccfg CSR at bit position 10. On trap, elp state is saved away in *status. Adds elp to the migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 3 +++ target/riscv/cpu.h | 2 ++ target/riscv/cpu_bits.h | 6 ++++++ target/riscv/csr.c | 31 +++++++++++++++++++++++++++++++ target/riscv/machine.c | 19 +++++++++++++++++++ target/riscv/pmp.c | 5 +++++ target/riscv/pmp.h | 3 ++- 7 files changed, 68 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ed2d8a90da..a0490e29f9 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1031,6 +1031,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetTy= pe type) env->menvcfg =3D 0; #endif =20 + /* on reset elp is clear */ + env->elp =3D false; + env->xl =3D riscv_cpu_mxl(env); riscv_cpu_update_mask(env); cs->exception_index =3D RISCV_EXCP_NONE; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 2623f6cf75..e9f26b5121 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -230,6 +230,8 @@ struct CPUArchState { =20 target_ulong jvt; =20 + /* elp state for zicfilp extension */ + bool elp; #ifdef CONFIG_USER_ONLY uint32_t elf_flags; #endif diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 7e3f629356..8df6043ef1 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -552,6 +552,8 @@ #define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */ #define MSTATUS_TW 0x00200000 /* since: priv-1.10 */ #define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */ +#define MSTATUS_SPELP 0x00800000 /* zicfilp */ +#define MSTATUS_MPELP 0x020000000000 /* zicfilp */ #define MSTATUS_GVA 0x4000000000ULL #define MSTATUS_MPV 0x8000000000ULL =20 @@ -582,6 +584,7 @@ typedef enum { #define SSTATUS_XS 0x00018000 #define SSTATUS_SUM 0x00040000 /* since: priv-1.10 */ #define SSTATUS_MXR 0x00080000 +#define SSTATUS_SPELP MSTATUS_SPELP /* zicfilp */ =20 #define SSTATUS64_UXL 0x0000000300000000ULL =20 @@ -754,6 +757,7 @@ typedef enum RISCVException { =20 /* Execution environment configuration bits */ #define MENVCFG_FIOM BIT(0) +#define MENVCFG_LPE BIT(2) /* zicfilp */ #define MENVCFG_CBIE (3UL << 4) #define MENVCFG_CBCFE BIT(6) #define MENVCFG_CBZE BIT(7) @@ -767,11 +771,13 @@ typedef enum RISCVException { #define MENVCFGH_STCE BIT(31) =20 #define SENVCFG_FIOM MENVCFG_FIOM +#define SENVCFG_LPE MENVCFG_LPE #define SENVCFG_CBIE MENVCFG_CBIE #define SENVCFG_CBCFE MENVCFG_CBCFE #define SENVCFG_CBZE MENVCFG_CBZE =20 #define HENVCFG_FIOM MENVCFG_FIOM +#define HENVCFG_LPE MENVCFG_LPE #define HENVCFG_CBIE MENVCFG_CBIE #define HENVCFG_CBCFE MENVCFG_CBCFE #define HENVCFG_CBZE MENVCFG_CBZE diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ea3560342c..57cef9e682 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1598,6 +1598,11 @@ static RISCVException write_mstatus(CPURISCVState *e= nv, int csrno, } } =20 + /* If cfi lp extension is available, then apply cfi lp mask */ + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D (MSTATUS_MPELP | MSTATUS_SPELP); + } + mstatus =3D (mstatus & ~mask) | (val & mask); =20 env->mstatus =3D mstatus; @@ -2344,6 +2349,10 @@ static RISCVException write_menvcfg(CPURISCVState *e= nv, int csrno, mask |=3D (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | (cfg->ext_sstc ? MENVCFG_STCE : 0) | (cfg->ext_svadu ? MENVCFG_ADUE : 0); + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D MENVCFG_LPE; + } } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 @@ -2396,6 +2405,10 @@ static RISCVException write_senvcfg(CPURISCVState *e= nv, int csrno, return ret; } =20 + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SENVCFG_LPE; + } + env->senvcfg =3D (env->senvcfg & ~mask) | (val & mask); return RISCV_EXCP_NONE; } @@ -2433,6 +2446,10 @@ static RISCVException write_henvcfg(CPURISCVState *e= nv, int csrno, =20 if (riscv_cpu_mxl(env) =3D=3D MXL_RV64) { mask |=3D env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_A= DUE); + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D HENVCFG_LPE; + } } =20 env->henvcfg =3D (env->henvcfg & ~mask) | (val & mask); @@ -2897,6 +2914,10 @@ static RISCVException read_sstatus_i128(CPURISCVStat= e *env, int csrno, mask |=3D SSTATUS64_UXL; } =20 + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SSTATUS_SPELP; + } + *val =3D int128_make128(sstatus, add_status_sd(MXL_RV128, sstatus)); return RISCV_EXCP_NONE; } @@ -2908,6 +2929,11 @@ static RISCVException read_sstatus(CPURISCVState *en= v, int csrno, if (env->xl !=3D MXL_RV32 || env->debugger) { mask |=3D SSTATUS64_UXL; } + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SSTATUS_SPELP; + } + /* TODO: Use SXL not MXL. */ *val =3D add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask); return RISCV_EXCP_NONE; @@ -2923,6 +2949,11 @@ static RISCVException write_sstatus(CPURISCVState *e= nv, int csrno, mask |=3D SSTATUS64_UXL; } } + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SSTATUS_SPELP; + } + target_ulong newval =3D (env->mstatus & ~mask) | (val & mask); return write_mstatus(env, CSR_MSTATUS, newval); } diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 492c2c6d9d..c3a06c288d 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -350,6 +350,24 @@ static const VMStateDescription vmstate_jvt =3D { } }; =20 +static bool elp_needed(void *opaque) +{ + RISCVCPU *cpu =3D opaque; + + return cpu->cfg.ext_zicfilp; +} + +static const VMStateDescription vmstate_elp =3D { + .name =3D "cpu/elp", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D elp_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_BOOL(env.elp, RISCVCPU), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_riscv_cpu =3D { .name =3D "cpu", .version_id =3D 10, @@ -422,6 +440,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { &vmstate_debug, &vmstate_smstateen, &vmstate_jvt, + &vmstate_elp, NULL } }; diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 9eea397e72..1111d08d08 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -598,6 +598,11 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulon= g val) val &=3D ~(MSECCFG_MMWP | MSECCFG_MML | MSECCFG_RLB); } =20 + /* M-mode forward cfi to be enabled if cfi extension is implemented */ + if (env_archcpu(env)->cfg.ext_zicfilp) { + val |=3D (val & MSECCFG_MLPE); + } + env->mseccfg =3D val; } =20 diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index f5c10ce85c..e0530a17a3 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -44,7 +44,8 @@ typedef enum { MSECCFG_MMWP =3D 1 << 1, MSECCFG_RLB =3D 1 << 2, MSECCFG_USEED =3D 1 << 8, - MSECCFG_SSEED =3D 1 << 9 + MSECCFG_SSEED =3D 1 << 9, + MSECCFG_MLPE =3D 1 << 10, } mseccfg_field_t; =20 typedef struct { --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185373; cv=none; d=zohomail.com; s=zohoarc; b=Sb7oBNPlRWoq6eDMktUzBPK43PihV7qDPUiHEY1SQONfGn0PWJFO4V2SjmhK65LhUw5nJXh6UVkOXKUpMwL2kkqmyp4UCK9IrhlEc6BjWYwisY8IoKji7u5dF1+aIP7K2F1E9w3ELMCsy9T/BqIdhj/jfOxihv5je0uayj90nd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185373; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=P3fhINZSx5ghMlTitfFFmHEIn/w1CK0xQ5bZQ2eIF2c=; b=UICJf0LahOuyJGRRM//AtNk+filZl+u+2zQWP58NsOBtg7HvEngHTX+wLMW9+xWKSHsJkUxfxlagki2zad0c9yl9NZRUnoSJaPWAon2WxJ4oSSdkEHdQYK8uw6VxYKWV8czibasNY/ovFaptEIdaUck+HW6tPcqibA+GJuhr+0c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17261853731391012.0388466153561; Thu, 12 Sep 2024 16:56:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd2-0004aC-0a; Thu, 12 Sep 2024 19:53:36 -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 1sotcz-0004O1-96 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:33 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotcx-00087o-EB for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:33 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-7cf5e179b68so1297322a12.1 for ; Thu, 12 Sep 2024 16:53:30 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185210; x=1726790010; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P3fhINZSx5ghMlTitfFFmHEIn/w1CK0xQ5bZQ2eIF2c=; b=LhHvJ2ocyZKPVDsIN9PHndguWMEuo4j5S66tXyZrU5KS6/KVfACMzE2lbn1SascheP boHIQgtrveeNYhCCKWmoV2xz2OPIMVxKb9evw4+73znXmMxRgHq+YKWrnXsOPz8Exe2k SjEDfbfSdBtjr2A4GE7sVLijvKAlnAMWZGxOyUeY8SRAO9TYcRNvn07Gr0iw/uMzwSXk L3UbRSgrA2qbdswvN15+k3UBi8IaeOLqGTF59OyWFRRQWjf7AHQLOQ6WkY3YUAOn1gb7 a5f7PYHRBsgbQkco8tBq4IXR0rw1EnyWVmEWkhDKFjmFI5/W6TdvTepH3shmXX5DghED nBRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185210; x=1726790010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P3fhINZSx5ghMlTitfFFmHEIn/w1CK0xQ5bZQ2eIF2c=; b=RVFXZOk5tsYxAWncYj1M/xo66hGzNehT39qL4qDZExQWO+/DNQzEYjUALnxWZV5AFA O0oWsQUDJfA9HyRb97woW7m3Zg+HCFg5o9Gfux3B/qixUOU2YW6PcEbAipAb88KxOP24 lFHYtZtsQ15OqzDUBWSpGoLGAUzAPZ+qBMWOQTU6UUfb5I9WnEa8NaIc5xZyanRprTW0 FVtHPZZm08aevEQ1loX0JwywMmhcfhMXkr0ldcfmKXGnAYUeBWeqNMearWXNbXlE/5Tt lNIdbpwj1AxbwZGVr4qQzy1HUxY9byFKo9yi3txiOfYip6oTr5S87QmQYDm0i21cfn0/ 37IA== X-Forwarded-Encrypted: i=1; AJvYcCUCPoQWCaM1l3i5ocxvXDi87vZ5QZt24nuYBCm5lFRGh6gIfvoL0AJK5UDfs6kl+UMWP1HLq8Ray13f@nongnu.org X-Gm-Message-State: AOJu0Yx0qTUA7owPwxZutdH0toRUuODQOkE/i8vskfM28tYaZcEB2lY6 vYrMz7UuCyonNj67gK2GUrHZEWoqWeKhhwFOHRWS8MXIxZ1/mWoenszvpGBOvjU= X-Google-Smtp-Source: AGHT+IEcCb9TOgBjE8aK6ahF+TnHQYpQoa9LoPFFyRoH7ZJNdDsfNn41H8H5Lya9YC9PiK3gnOx2Kw== X-Received: by 2002:a05:6a21:4d8c:b0:1cc:e101:ee64 with SMTP id adf61e73a8af0-1cf75599a20mr7231736637.1.1726185209767; Thu, 12 Sep 2024 16:53:29 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v14 04/20] target/riscv: save and restore elp state on priv transitions Date: Thu, 12 Sep 2024 16:53:04 -0700 Message-ID: <20240912235320.3768582-5-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=debug@rivosinc.com; helo=mail-pg1-x52e.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185375367116600 Content-Type: text/plain; charset="utf-8" elp state is recorded in *status on trap entry (less privilege to higher privilege) and restored in elp from *status on trap exit (higher to less privilege). Additionally this patch introduces a forward cfi helper function to determine if current privilege has forward cfi is enabled or not based on *envcfg (for U, VU, S, VU, HS) or mseccfg csr (for M). Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 54 +++++++++++++++++++++++++++++++++++++++ target/riscv/op_helper.c | 17 ++++++++++++ 3 files changed, 72 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e9f26b5121..6c5e199e72 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -547,6 +547,7 @@ void riscv_cpu_set_geilen(CPURISCVState *env, target_ul= ong geilen); bool riscv_cpu_vector_enabled(CPURISCVState *env); void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); int riscv_env_mmu_index(CPURISCVState *env, bool ifetch); +bool cpu_get_fcfien(CPURISCVState *env); G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t reta= ddr); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index a935377b4a..d7b776c556 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -33,6 +33,7 @@ #include "cpu_bits.h" #include "debug.h" #include "tcg/oversized-guest.h" +#include "pmp.h" =20 int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) { @@ -63,6 +64,33 @@ int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) #endif } =20 +bool cpu_get_fcfien(CPURISCVState *env) +{ + /* no cfi extension, return false */ + if (!env_archcpu(env)->cfg.ext_zicfilp) { + return false; + } + + switch (env->priv) { + case PRV_U: + if (riscv_has_ext(env, RVS)) { + return env->senvcfg & SENVCFG_LPE; + } + return env->menvcfg & MENVCFG_LPE; +#ifndef CONFIG_USER_ONLY + case PRV_S: + if (env->virt_enabled) { + return env->henvcfg & HENVCFG_LPE; + } + return env->menvcfg & MENVCFG_LPE; + case PRV_M: + return env->mseccfg & MSECCFG_MLPE; +#endif + default: + g_assert_not_reached(); + } +} + void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, uint64_t *cs_base, uint32_t *pflags) { @@ -546,6 +574,15 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) } bool current_virt =3D env->virt_enabled; =20 + /* + * If zicfilp extension available and henvcfg.LPE =3D 1, + * then apply SPELP mask on mstatus + */ + if (env_archcpu(env)->cfg.ext_zicfilp && + get_field(env->henvcfg, HENVCFG_LPE)) { + mstatus_mask |=3D SSTATUS_SPELP; + } + g_assert(riscv_has_ext(env, RVH)); =20 if (current_virt) { @@ -1760,6 +1797,11 @@ void riscv_cpu_do_interrupt(CPUState *cs) if (env->priv <=3D PRV_S && cause < 64 && (((deleg >> cause) & 1) || s_injected || vs_injected)) { /* handle the trap in S-mode */ + /* save elp status */ + if (cpu_get_fcfien(env)) { + env->mstatus =3D set_field(env->mstatus, MSTATUS_SPELP, env->e= lp); + } + if (riscv_has_ext(env, RVH)) { uint64_t hdeleg =3D async ? env->hideleg : env->hedeleg; =20 @@ -1808,6 +1850,11 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_S, virt); } else { /* handle the trap in M-mode */ + /* save elp status */ + if (cpu_get_fcfien(env)) { + env->mstatus =3D set_field(env->mstatus, MSTATUS_MPELP, env->e= lp); + } + if (riscv_has_ext(env, RVH)) { if (env->virt_enabled) { riscv_cpu_swap_hypervisor_regs(env); @@ -1839,6 +1886,13 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_M, virt); } =20 + /* + * Interrupt/exception/trap delivery is asynchronous event and as per + * zicfilp spec CPU should clear up the ELP state. No harm in clearing + * unconditionally. + */ + env->elp =3D false; + /* * NOTE: it is not necessary to yield load reservations here. It is on= ly * necessary for an SC from "another hart" to cause a load reservation diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 25a5263573..eddedacf4b 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -309,6 +309,15 @@ target_ulong helper_sret(CPURISCVState *env) =20 riscv_cpu_set_mode(env, prev_priv, prev_virt); =20 + /* + * If forward cfi enabled for new priv, restore elp status + * and clear spelp in mstatus + */ + if (cpu_get_fcfien(env)) { + env->elp =3D get_field(env->mstatus, MSTATUS_SPELP); + } + env->mstatus =3D set_field(env->mstatus, MSTATUS_SPELP, 0); + return retpc; } =20 @@ -349,6 +358,14 @@ target_ulong helper_mret(CPURISCVState *env) } =20 riscv_cpu_set_mode(env, prev_priv, prev_virt); + /* + * If forward cfi enabled for new priv, restore elp status + * and clear mpelp in mstatus + */ + if (cpu_get_fcfien(env)) { + env->elp =3D get_field(env->mstatus, MSTATUS_MPELP); + } + env->mstatus =3D set_field(env->mstatus, MSTATUS_MPELP, 0); =20 return retpc; } --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185465; cv=none; d=zohomail.com; s=zohoarc; b=JiWlIi+5oAaAFnBqaWSzzmU6q7rmfvLNq7eg25hNA9QY0FgcxpRnF1JBhdFiK9RE94nCv83vxcijVLynm8pnTisquNJLGjMHno621XjOEJKLR6IP8vc2fdYILbLz3yoAl8y38GVrEbRGssXlAPnq5KmFCQorMrnOeoZb8EUyZtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185465; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dKczBHanLSZvcjjGDp0D2cgwbOL2pYUmrFfrlbX195U=; b=QizUhT7A0FPLs8UQFW6CuzNJmPEzKV1mVgxNZAX5+sOUOxmYEqjyHJO2LKnht3mrZJPD1gtjp60/DiMkN4eHJx+raMx4SlqVksGV5F+bk0wBiu+p1OBumgVsFPbwgvdNapGE2ed7mSJN9gkwmnYptP5qUc4lHqAHF1GsPPSE9SY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185465952898.2441826669966; Thu, 12 Sep 2024 16:57:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd4-0004lZ-TS; Thu, 12 Sep 2024 19:53:38 -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 1sotd0-0004Rn-4U for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:34 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotcy-00088L-H9 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:33 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7191df6b5f5so1175204b3a.0 for ; Thu, 12 Sep 2024 16:53:32 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185211; x=1726790011; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dKczBHanLSZvcjjGDp0D2cgwbOL2pYUmrFfrlbX195U=; b=kYAScM9+2kP7igid2xZO60ej8ViD/1YK6cvgIqKfHJolAW4j9WcDDCpFBSXDv94L8M TptRgZyHAYmZ9F16J7vM77O9DMPK2iAEoKWMGbHXTZSZYFvvlzxmkyPHY7/2w8bWBpEe wjM4xr4cdFw/EQ7X0yeNOVyFMfDCd+X2+LXXlS3z5bMZC0YmvP6hWe8uBvI0mDyib/1U kD0vU6c1AiCkLplCnvFpL8csp4L4KCK3PhYAHER7i88Au2OhhaRbvdeQbnR66Oogq2ti Mbuw1MEaDcODgknnQ4rK4HCI6NjeXkP191j4E01L/Ghk3cn6U49VoOdhYLYZUsl7J/Rx fMlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185211; x=1726790011; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dKczBHanLSZvcjjGDp0D2cgwbOL2pYUmrFfrlbX195U=; b=MTcMVYJDj8rU5yvvggv6n5wb9TEQzGeAKx2KcAQ6wxqyo65AV0FvfK6Coht9Q+J4Be W9f625B71P8zFrkkmhZuwuR6/2Ti615vlUbm34z/QKhBG9cOH23ywrtIsTdjMaX4iUOL RFktyVxNzF8eUsDMjmGirIZifWag0hLEcUzGfquCGTHyWNuB7eNDrB/Y28aTFWIo/mJR XF/06MnR0T1e3VDniaXYQDQA0LbDcQTmmwIZd4NCuaD4sPu8J3ufHKinZcRQMBEOSA+J +Kzc87NO9hZON7ESN4yqF38S6kVH2Lhi6Tzl9RSDFicoPHvIrUo+UQBiklxx+7XygpcY OIpw== X-Forwarded-Encrypted: i=1; AJvYcCXjT3Mys+onY7oWi7bTOUCnao+H3f4mFp0BGoiS4BndoTbeiK/2Ti9/c+vYsxEtjRIfid3JBcCo4lyF@nongnu.org X-Gm-Message-State: AOJu0YxNuRXXpuhoTfFADSD8mogNc8s7izzU+gGNBMROuK2IxE6N3Ko+ EclMhlfX66/uu7Dm2BbHZgNEWSUnNb7n9Ym1JvAKZ2lrPSxJZd717dOgkOAvtUQ= X-Google-Smtp-Source: AGHT+IGim91aSRG5N+S7DnK/re7jlC/4e141Sy+7wqe3HedhlLeGJW649lVOXL7Rbkf57ojzZcvmLg== X-Received: by 2002:a05:6a00:1953:b0:70e:a524:6490 with SMTP id d2e1a72fcca58-71926063f80mr6369964b3a.1.1726185211124; Thu, 12 Sep 2024 16:53:31 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 05/20] target/riscv: additional code information for sw check Date: Thu, 12 Sep 2024 16:53:05 -0700 Message-ID: <20240912235320.3768582-6-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=debug@rivosinc.com; helo=mail-pf1-x435.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185467335116600 Content-Type: text/plain; charset="utf-8" sw check exception support was recently added. This patch further augments sw check exception by providing support for additional code which is provided in *tval. Adds `sw_check_code` field in cpuarchstate. Whenever sw check exception is raised *tval gets the value deposited in `sw_check_code`. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 3 +++ target/riscv/csr.c | 1 + 3 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6c5e199e72..dc33604b13 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -232,6 +232,8 @@ struct CPUArchState { =20 /* elp state for zicfilp extension */ bool elp; + /* sw check code for sw check exception */ + target_ulong sw_check_code; #ifdef CONFIG_USER_ONLY uint32_t elf_flags; #endif diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index d7b776c556..8ad24ed2a6 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1766,6 +1766,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) cs->watchpoint_hit =3D NULL; } break; + case RISCV_EXCP_SW_CHECK: + tval =3D env->sw_check_code; + break; default: break; } diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 57cef9e682..919de7970c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1377,6 +1377,7 @@ static const uint64_t all_ints =3D M_MODE_INTERRUPTS = | S_MODE_INTERRUPTS | (1ULL << (RISCV_EXCP_INST_PAGE_FAULT)) | \ (1ULL << (RISCV_EXCP_LOAD_PAGE_FAULT)) | \ (1ULL << (RISCV_EXCP_STORE_PAGE_FAULT)) | \ + (1ULL << (RISCV_EXCP_SW_CHECK)) | \ (1ULL << (RISCV_EXCP_INST_GUEST_PAGE_FAULT)) | \ (1ULL << (RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT)) | \ (1ULL << (RISCV_EXCP_VIRT_INSTRUCTION_FAULT)) | \ --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185294; cv=none; d=zohomail.com; s=zohoarc; b=ZJkrldWPZO9oI/NaOznxNLdSsirhk+qQP5MhOtuXc1WNyUMy298svGErK4Riyqe3dQ/i7BY99NlNsIrgUbJ8Ed3zWXDfeJMlVBmhWPUFs7pHWLpsDoewM8jf8MlwKk8DeZzs4feN3DnIgq7z77/djj+VC/EdtrVAna5Uo4hdHSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185294; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GbPMA8V02IhGiYCVVpIFsu9ZY03XMdmnvfupdjIe6iY=; b=kpb/OcXAhqEVGQrBhnxLgjPHUEshHNh93qeqIeo5mgbFxIXp8vnC5qdO7tBFmr3jckHL8FMl+ZQ7s63QiiUwzgfzWqoQJYoOTX9Z2Muny6HkHWTeHT7n5JiRrFHNjHk6cmmZ2U7SIbKre4d2HHu/cR/SmBv1AdpZRGMpS4ZL3uA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185294427522.394098189475; Thu, 12 Sep 2024 16:54:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd3-0004ez-8N; Thu, 12 Sep 2024 19:53:37 -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 1sotd1-0004ZC-Pe for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:35 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotcz-00088j-Tv for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:35 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-718d962ad64so1255977b3a.0 for ; Thu, 12 Sep 2024 16:53:33 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185212; x=1726790012; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GbPMA8V02IhGiYCVVpIFsu9ZY03XMdmnvfupdjIe6iY=; b=jGoeYyimf3gTkc/nijc0O3iLgEJm9TU8aPMKLSPGZ7EQ45ebJB94jldODpe9Zuneiw 2WevhiZL8iujxhbdqt+Kpi8PLEqQTCBT2YuUa2jmapPgnoV/ByCGENHmHhQ4npN3Wy46 bISpgeS6C33BbY6ZINSghjc6Z92AcoBKgzhnV865+fjA0wQhfRwzR32eoJf4ntdRrrfF G1/m+GLMNux4a0JLjq2cOGW/eJlllY9V6FCbdlZ+90nsgViLIuc9c+auPgSGf50SgC+r OXQW5g9Su/6vsHhyt0jhb5AQ0QyQpjbfZWGOWEqDr1LvcdfJKbi6YBEuEW0p24xdDk29 zyfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185212; x=1726790012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GbPMA8V02IhGiYCVVpIFsu9ZY03XMdmnvfupdjIe6iY=; b=q06Orzm5axHtSvAsAUx8F9efkZBj+JdGjd182hjpeBFE7UySDqwF3gjZOifyaIQu2u GhLLzM0MDiN6+mkZxfFy2L4qOTLgIvqw1LUKLrJAHqqD9U3Y4mv/4ED9S2WW+JNwtYTz ZB3eec6+7vSEuirthPfe006MmbiHZ0mMSHjY55zoFASjQSebL5ICgSDyPs3wcGoIssJH dzXhz827OpfuMWa+e80fWvmlimATeF8ekcYMFzYtUHZerE0FvxfTK85sRpGrmaS/wJi+ 05LMZhJpkoxelWie7TcCjerccvu+3vRLkIaTVXLw741C3Z0rt+DuWVu+O2vsZUeO4Lyp fDvQ== X-Forwarded-Encrypted: i=1; AJvYcCWL6DHoYCVQ8kULY96fLhj0viguChupgVAfaXKFBdUDJTTVFEE+pCKH0GojswcSCnK5LBIN9Zx+GlgM@nongnu.org X-Gm-Message-State: AOJu0Yyo6vGPofFNBNCUrDpfJ7yjJsadw8ZkKEC7+z3hIROU2ULdPzGZ XLqyKO0QVPnSmd1Smr3GCeTWSjmxDuicE+X8Sl8Qu9cAxv/FYASiQKTaLau4ABg= X-Google-Smtp-Source: AGHT+IH9uQ8qMSJ4P/eAVnghn6aFozZoi8rGcX2zQ4uht/oaYsd2whhP8Pxrhci11T/hqnO0YovcKg== X-Received: by 2002:a05:6300:6681:b0:1cf:22d4:382e with SMTP id adf61e73a8af0-1cf7624b255mr6904655637.37.1726185212504; Thu, 12 Sep 2024 16:53:32 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 06/20] target/riscv: tracking indirect branches (fcfi) for zicfilp Date: Thu, 12 Sep 2024 16:53:06 -0700 Message-ID: <20240912235320.3768582-7-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=debug@rivosinc.com; helo=mail-pf1-x430.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185295157116600 Content-Type: text/plain; charset="utf-8" zicfilp protects forward control flow (if enabled) by enforcing all indirect call and jmp must land on a landing pad instruction `lpad`. If target of an indirect call or jmp is not `lpad` then cpu/hart must raise a sw check exception with tval =3D 2. This patch implements the mechanism using TCG. Target architecture branch instruction must define the end of a TB. Using this property, during translation of branch instruction, TB flag =3D FCFI_LP_EXPECTED can be set. Translation of target TB can check if FCFI_LP_EXPECTED flag is set and a flag (fcfi_lp_expected) can be set in DisasContext. If `lpad` gets translated, fcfi_lp_expected flag in DisasContext can be cleared. Else it'll fault. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 3 +++ target/riscv/cpu_bits.h | 3 +++ target/riscv/cpu_helper.c | 10 ++++++++++ target/riscv/translate.c | 23 +++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index dc33604b13..ba4bc212c7 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -622,6 +622,9 @@ FIELD(TB_FLAGS, ITRIGGER, 22, 1) FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) FIELD(TB_FLAGS, PRIV, 24, 2) FIELD(TB_FLAGS, AXL, 26, 2) +/* zicfilp needs a TB flag to track indirect branches */ +FIELD(TB_FLAGS, FCFI_ENABLED, 28, 1) +FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 29, 1) =20 #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 8df6043ef1..e7387c9b8f 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -692,6 +692,9 @@ typedef enum RISCVException { RISCV_EXCP_SEMIHOST =3D 0x3f, } RISCVException; =20 +/* zicfilp defines lp violation results in sw check with tval =3D 2*/ +#define RISCV_EXCP_SW_CHECK_FCFI_TVAL 2 + #define RISCV_EXCP_INT_FLAG 0x80000000 #define RISCV_EXCP_INT_MASK 0x7fffffff =20 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 8ad24ed2a6..1c89b126dd 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -132,6 +132,16 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, flags =3D FIELD_DP32(flags, TB_FLAGS, VILL, 1); } =20 + if (cpu_get_fcfien(env)) { + /* + * For Forward CFI, only the expectation of a lpad at + * the start of the block is tracked via env->elp. env->elp + * is turned on during jalr translation. + */ + flags =3D FIELD_DP32(flags, TB_FLAGS, FCFI_LP_EXPECTED, env->elp); + flags =3D FIELD_DP32(flags, TB_FLAGS, FCFI_ENABLED, 1); + } + #ifdef CONFIG_USER_ONLY fs =3D EXT_STATUS_DIRTY; vs =3D EXT_STATUS_DIRTY; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index acba90f170..b5c0511b4b 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -116,6 +116,9 @@ typedef struct DisasContext { bool frm_valid; bool insn_start_updated; const GPtrArray *decoders; + /* zicfilp extension. fcfi_enabled, lp expected or not */ + bool fcfi_enabled; + bool fcfi_lp_expected; } DisasContext; =20 static inline bool has_ext(DisasContext *ctx, uint32_t ext) @@ -1238,6 +1241,8 @@ static void riscv_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cs) ctx->pm_base_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLE= D); ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); + ctx->fcfi_lp_expected =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_LP_EXPEC= TED); + ctx->fcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_ENABLED); ctx->zero =3D tcg_constant_tl(0); ctx->virt_inst_excp =3D false; ctx->decoders =3D cpu->decoders; @@ -1270,6 +1275,24 @@ static void riscv_tr_translate_insn(DisasContextBase= *dcbase, CPUState *cpu) decode_opc(env, ctx, opcode16); ctx->base.pc_next +=3D ctx->cur_insn_len; =20 + /* + * If 'fcfi_lp_expected' is still true after processing the instructio= n, + * then we did not see an 'lpad' instruction, and must raise an except= ion. + * Insert code to raise the exception at the start of the insn; any ot= her + * code the insn may have emitted will be deleted as dead code followi= ng + * the noreturn exception + */ + if (ctx->fcfi_lp_expected) { + /* Emit after insn_start, i.e. before the op following insn_start.= */ + tcg_ctx->emit_before_op =3D QTAILQ_NEXT(ctx->base.insn_start, link= ); + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + tcg_ctx->emit_before_op =3D NULL; + ctx->base.is_jmp =3D DISAS_NORETURN; + } + /* Only the first insn within a TB is allowed to cross a page boundary= . */ if (ctx->base.is_jmp =3D=3D DISAS_NEXT) { if (ctx->itrigger || !is_same_page(&ctx->base, ctx->base.pc_next))= { --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185292; cv=none; d=zohomail.com; s=zohoarc; b=MMRBqiX22hFTFBzNNhqicSdX+P6zN0XoVkaEF/96mHB/4ymq506u55nn+S+aCa3GKmrOiVvmb401mqsYrLSX3ZHaslXe8MGai0xFP55VAgVkqwh20aVjk3l/7649Ct8JioOYRSTiwLcAMqvIjhjFFARRVOaZjxRw/XoKoFT4zz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185292; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4w8EQzzS8x/AP9HynEBDyPrYuUiwLotAgsmDd3Ae1DI=; b=aN5zMoojm5FJcB2zrhFJbwR8GaEfHIkALhpap6oK3a47zPbXmTFJSYDGDQqqFm7ZjJ+xYGhfFqSMY0/R2JHdPySguAUL3qKBxI3MfqiprV2RnMJccN8G+C9FCWV/onuYZAWW0VuXhvhJKP3Ve8lI8veGQs4JAHJYz59BPZALUNg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185292143626.5967325934313; Thu, 12 Sep 2024 16:54:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd5-0004qT-Qs; Thu, 12 Sep 2024 19:53:39 -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 1sotd3-0004eQ-0J for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:37 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotd1-00089E-9L for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:36 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-718da0821cbso1214632b3a.0 for ; Thu, 12 Sep 2024 16:53:34 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185214; x=1726790014; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4w8EQzzS8x/AP9HynEBDyPrYuUiwLotAgsmDd3Ae1DI=; b=wYaJ62oQoH3Fp4C0e8yHeQh83TUTAaIkGUsmFfsNu3bVEbf1tjSno3wwlihCGDZDb7 CfXNQoZvt4FRQiM9QZ4zSLWucsXLdNdKAek19R3se7YqFuYjPUo9juBnaDHXWtk/fAkn NQ5NwfmXhV7c8zMYbkIiuUGdnjCn5ilWf4GkKBrNqxyg546qkoyE7ihSB1XFb9bISw76 A3xcu8YiXIo1XxAiQX/ZNfPOwXNK72VJyLpok5CIeRJFmaCQ4RkHSlUnBQnCL+pK7tah EsL3Hj/oxmn4AOkmkpU11mIfKyhv9O088Phniz+JyBUg+pLdM42c/gGczT+vepmNoZpO 7Gnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185214; x=1726790014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4w8EQzzS8x/AP9HynEBDyPrYuUiwLotAgsmDd3Ae1DI=; b=kmUv0n75cvjtdp95m8TPnZfDn9LF3UxwTpdq/XSYzKAH3QV9gin7db3I+6Cxpoieb8 J3l2mgh3w5ko/4iAl0oxOLAfzyVb4AXkXbgwImNK1O1eZ8/VyWHONLYT2n2E6N0OgCbL XCksb6gVmGLY/CLfM1L+Wi4NTRHiEUmLkB/TpKpJFmwxtNLQOlIynQMgaSnBC2FvdxIS w+kEaMCfzRDAKXqESaPGUAhp/TXHJ7+KIwrGx7PTQOO8Ip4cAuqpHfbzwPmMa2mEpk88 hqWlbrgvjamjKHUDE6ZXjxm7UAfTGhq0AbTRagKHKzSZtt2woL08tGF6WGWz+5EH1ilX dNxQ== X-Forwarded-Encrypted: i=1; AJvYcCUZt/oNbiPWYFohgKnuRdqWoO+rceImd+mB2PTylMd+g5vP0reHo1Znj202dA2VZpy4Sa4SAsEcu3gh@nongnu.org X-Gm-Message-State: AOJu0Ywjuulj8sImuPjwRlJ/UaRAhiGWXK+nB4gNgM/Y7+HOCm6GJjYR Kpd1clZVIpPeSx3TMR6Y+eiYFZ/0GZWzpBSYCTY9WZXsOGLEbyE7QnE8WL/w2Bs= X-Google-Smtp-Source: AGHT+IH1DMVmcUpFJvCz8YBQGkPHxuXC5eAq4ujijaI3+s/Mto+e2vK0kUVgghcKqjDcf1FLjG+G+Q== X-Received: by 2002:a05:6a20:ac43:b0:1cf:476f:2cef with SMTP id adf61e73a8af0-1cf7624b4bamr5444449637.49.1726185213829; Thu, 12 Sep 2024 16:53:33 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 07/20] target/riscv: zicfilp `lpad` impl and branch tracking Date: Thu, 12 Sep 2024 16:53:07 -0700 Message-ID: <20240912235320.3768582-8-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42a.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185294705116600 Content-Type: text/plain; charset="utf-8" Implements setting lp expected when `jalr` is encountered and implements `lpad` instruction of zicfilp. `lpad` instruction is taken out of auipc x0, . This is an existing HINTNOP space. If `lpad` is target of an indirect branch, cpu checks for 20 bit value in x7 upper with 20 bit value embedded in `lpad`. If they don't match, cpu raises a sw check exception with tval =3D 2. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu_user.h | 1 + target/riscv/insn32.decode | 5 ++- target/riscv/insn_trans/trans_rvi.c.inc | 55 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu_user.h b/target/riscv/cpu_user.h index 02afad608b..e6927ff847 100644 --- a/target/riscv/cpu_user.h +++ b/target/riscv/cpu_user.h @@ -15,5 +15,6 @@ #define xA6 16 #define xA7 17 /* syscall number for RVI ABI */ #define xT0 5 /* syscall number for RVE ABI */ +#define xT2 7 =20 #endif diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index c45b8fa1d8..27108b992b 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -123,7 +123,10 @@ sfence_vm 0001000 00100 ..... 000 00000 1110011 @= sfence_vm =20 # *** RV32I Base Instruction Set *** lui .................... ..... 0110111 @u -auipc .................... ..... 0010111 @u +{ + lpad label:20 00000 0010111 + auipc .................... ..... 0010111 @u +} jal .................... ..... 1101111 @j jalr ............ ..... 000 ..... 1100111 @i beq ....... ..... ..... 000 ..... 1100011 @b diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index fab5c06719..638fc0fb7b 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -36,6 +36,49 @@ static bool trans_lui(DisasContext *ctx, arg_lui *a) return true; } =20 +static bool trans_lpad(DisasContext *ctx, arg_lpad *a) +{ + /* + * fcfi_lp_expected can set only if fcfi was eanbled. + * translate further only if fcfi_lp_expected set. + * lpad comes from NOP space anyways, so return true if + * fcfi_lp_expected is false. + */ + if (!ctx->fcfi_lp_expected) { + return true; + } + + ctx->fcfi_lp_expected =3D false; + if ((ctx->base.pc_next) & 0x3) { + /* + * misaligned, according to spec we should raise sw check exception + */ + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + return true; + } + + /* per spec, label check performed only when embedded label non-zero */ + if (a->label !=3D 0) { + TCGLabel *skip =3D gen_new_label(); + TCGv tmp =3D tcg_temp_new(); + tcg_gen_extract_tl(tmp, get_gpr(ctx, xT2, EXT_NONE), 12, 20); + tcg_gen_brcondi_tl(TCG_COND_EQ, tmp, a->label, skip); + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + gen_set_label(skip); + } + + tcg_gen_st8_tl(tcg_constant_tl(0), tcg_env, + offsetof(CPURISCVState, elp)); + + return true; +} + static bool trans_auipc(DisasContext *ctx, arg_auipc *a) { TCGv target_pc =3D dest_gpr(ctx, a->rd); @@ -75,6 +118,18 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) gen_set_gpr(ctx, a->rd, succ_pc); =20 tcg_gen_mov_tl(cpu_pc, target_pc); + if (ctx->fcfi_enabled) { + /* + * return from functions (i.e. rs1 =3D=3D xRA || rs1 =3D=3D xT0) a= re not + * tracked. zicfilp introduces sw guarded branch as well. sw guard= ed + * branch are not tracked. rs1 =3D=3D xT2 is a sw guarded branch. + */ + if (a->rs1 !=3D xRA && a->rs1 !=3D xT0 && a->rs1 !=3D xT2) { + tcg_gen_st8_tl(tcg_constant_tl(1), + tcg_env, offsetof(CPURISCVState, elp)); + } + } + lookup_and_goto_ptr(ctx); =20 if (misaligned) { --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185332; cv=none; d=zohomail.com; s=zohoarc; b=SEBbvxrtb/uzK6jGFOlLlNZzMuRYnboaUCnoczBtt0KfoTSplGkSS+1a2KH8YAU0bYGVWjHbhqoQk4H80nlwH4Wk4mNxXu+T2+ivcsbPUpG9onjR0ZKUxmUm00MbaRwQXjP6afINL/pDQ7CdeptGBQqnYATS+q28RBzGKZulegI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185332; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NpvZYJph47UbMl7k6pfcf7IX44LlneT6ofd0Ip0BFwA=; b=CavuU0Gfvszr6P2CqViLhipNwg5udneIaMBkbUI3jzmksK309RTmruZIcJ4BcqHXPGVCGvi8XN7U2yPS35oHrk4fNzbPQI0kBeir76KUgpAm/y/P5vAm+OK8WgUxgS5mnUhaqygbKjfTxgUElYjY1AlIjxcezaTQP946p7YiWdQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185332882360.4187382582696; Thu, 12 Sep 2024 16:55:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd6-0004t2-EB; Thu, 12 Sep 2024 19:53:40 -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 1sotd4-0004kQ-AY for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:38 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotd2-00089a-KK for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:37 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-718d6ad6050so341076b3a.0 for ; Thu, 12 Sep 2024 16:53:36 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185215; x=1726790015; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NpvZYJph47UbMl7k6pfcf7IX44LlneT6ofd0Ip0BFwA=; b=Y5nzrjje6XFqK+xgCDRBR4MqJgm6+iTu47XBDPd0KGvwblh6He7dXMOzJOgHwYF4K7 hRR7Sabm8VASJNrBxz2IpWruy5yFRpxdc7ONgCOZr7d0CdQnW2FB6xxd5Qj9rQe1/2ny xMFtke9kAFx8scgUMUDUXbwbIs3rlUiRpfMXJig/8zgBFmj4aFQVq8YW6W+6emEqJIMm EsnIqVVKaH2OPVIj/IQSRLMCnwNX9ym6hA8vvuLwTK5egba+tBSyklW7YS3OBvbX5rUf yiKT++d3fk2btkHcpMIxLQ4C1lGTFtezZLY/3Sez84ZaKOVA6Pp81hmLS81sHOQg2RVY p70w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185215; x=1726790015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NpvZYJph47UbMl7k6pfcf7IX44LlneT6ofd0Ip0BFwA=; b=pOzk4OPgP1MAShlEJUYMMx5vdRXTuDP7akQUayG3daABA6ZkTJYnChFneuGn1HkN9T 6T8VO5a3oM4+N4wfL5T281PBrDNlnVG4oUwUrKT4art42/5rf4kAoPAuNRBVxEekGmFJ Dn6Zt8lWBkvclDNG/Tt1WMvV2KfKUxa++hXOpNxK/6S9E0UIlUJqYcExUh+oG2o+oax8 LGmcIH4dik5eIBBUyKLeoPXiNcoHT0hd/eZg0HpnI0+dRbnuGHmavQPtu73CA2fbOqc6 4aYSPC3xJk9vNiRWER0GM02wlaY4lBL5KmXVvLzOJPaq4t0QimcIXQO1LG6wpL4Wjwkc PZoQ== X-Forwarded-Encrypted: i=1; AJvYcCXE9V5UcjQgvlS+5DY1WsYebJm3pENGl2klGg3qjINkyAyQ3nVNodVxLY//yRarYFG22ogrUTfd82HM@nongnu.org X-Gm-Message-State: AOJu0YxjeekdQjy7qnPI/ai/8cL+lR2RYMp0dAoj2D350nAQi2g/julT cglQVmUkuqMtgnvBX09HV2YjwvJYeIDJUvsjAlmSaUSI8sPmdjG6cXVIJRpQ79k= X-Google-Smtp-Source: AGHT+IHbskV/JqaouCz0QIKkOkmvBDdiySasVVS7ojHUSqW66Z5JA2JyUNgM6AM/4WPLeZENHjkVHg== X-Received: by 2002:a05:6a00:2d89:b0:706:74be:686e with SMTP id d2e1a72fcca58-71936b1b38amr1305478b3a.26.1726185215270; Thu, 12 Sep 2024 16:53:35 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 08/20] disas/riscv: enable `lpad` disassembly Date: Thu, 12 Sep 2024 16:53:08 -0700 Message-ID: <20240912235320.3768582-9-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42d.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185333236116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- disas/riscv.c | 18 +++++++++++++++++- disas/riscv.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas/riscv.c index 5965574d87..2942a5800f 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -976,6 +976,7 @@ typedef enum { rv_op_amocas_h =3D 945, rv_op_wrs_sto =3D 946, rv_op_wrs_nto =3D 947, + rv_op_lpad =3D 948, } rv_op; =20 /* register names */ @@ -2236,6 +2237,7 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "amocas.h", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "wrs.sto", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 }, { "wrs.nto", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 }, + { "lpad", rv_codec_lp, rv_fmt_imm, NULL, 0, 0, 0 }, }; =20 /* CSR names */ @@ -2929,7 +2931,13 @@ static void decode_inst_opcode(rv_decode *dec, rv_is= a isa) case 7: op =3D rv_op_andi; break; } break; - case 5: op =3D rv_op_auipc; break; + case 5: + op =3D rv_op_auipc; + if (dec->cfg->ext_zicfilp && + (((inst >> 7) & 0b11111) =3D=3D 0b00000)) { + op =3D rv_op_lpad; + } + break; case 6: switch ((inst >> 12) & 0b111) { case 0: op =3D rv_op_addiw; break; @@ -4488,6 +4496,11 @@ static uint32_t operand_tbl_index(rv_inst inst) return ((inst << 54) >> 56); } =20 +static uint32_t operand_lpl(rv_inst inst) +{ + return inst >> 12; +} + /* decode operands */ =20 static void decode_inst_operands(rv_decode *dec, rv_isa isa) @@ -4875,6 +4888,9 @@ static void decode_inst_operands(rv_decode *dec, rv_i= sa isa) dec->imm =3D sextract32(operand_rs2(inst), 0, 5); dec->imm1 =3D operand_imm2(inst); break; + case rv_codec_lp: + dec->imm =3D operand_lpl(inst); + break; }; } =20 diff --git a/disas/riscv.h b/disas/riscv.h index 16a08e4895..1182457aff 100644 --- a/disas/riscv.h +++ b/disas/riscv.h @@ -166,6 +166,7 @@ typedef enum { rv_codec_r2_immhl, rv_codec_r2_imm2_imm5, rv_codec_fli, + rv_codec_lp, } rv_codec; =20 /* structures */ @@ -228,6 +229,7 @@ enum { #define rv_fmt_rs1_rs2 "O\t1,2" #define rv_fmt_rd_imm "O\t0,i" #define rv_fmt_rd_uimm "O\t0,Ui" +#define rv_fmt_imm "O\ti" #define rv_fmt_rd_offset "O\t0,o" #define rv_fmt_rd_uoffset "O\t0,Uo" #define rv_fmt_rd_rs1_rs2 "O\t0,1,2" --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185529; cv=none; d=zohomail.com; s=zohoarc; b=VdWDJkXwCzL8qWJsWALkxyVmDA/aqUZiyqgI1tIFnbUzMDpR69AWgAJxIQGKqHY4yKMc6hXcRJtT4dj5xB7DBROQgHWqPfdlkAfbp9fW30Whj2CzMf60+b4wDJ54ibzfZahtN0HrwrSQ5sqdTH09dAuAk7rMZ/TX6dEW3kjFfnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185529; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yhLU431wzLJ+L96jZIVSfco4No4B8gvVcyEMQe0t1zo=; b=fFYauFaEtKSCkE2ORDgjaJxMuOyqNSRZB/IN+hNX+6e7BK/PqCcLkhQokZ/YMJiAZ/srPFjWAYXUzktmfY7cuxtUb0IDg6B+zvWyKGR7zD9VHwvjgtBYTtr3B4fmFCdUmhCjAJdD+gdwV4URg4Zm2+hW/qGwYPgBYlhDLEcYMss= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185529665521.8079410212015; Thu, 12 Sep 2024 16:58:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd7-0004yI-Ke; Thu, 12 Sep 2024 19:53:41 -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 1sotd5-0004qX-P3 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:39 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotd4-00089u-4z for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:39 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-719270b7c94so285052b3a.3 for ; Thu, 12 Sep 2024 16:53:37 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185217; x=1726790017; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yhLU431wzLJ+L96jZIVSfco4No4B8gvVcyEMQe0t1zo=; b=g9vfbSIIJksA3rW2cSPFqLuWVyfIm1S2dBzFLX+cg/c/60wmMsmv8DX0MOF3zo7UOb 1vwk71TN7mLuvNt5bAEFPC/hTc4ZYIgr5hVDpkTTjQDRqbS1ti5UWeuvY2PETyI9AYsa V/0sIXrqz7jgk+u+LyBcm4clZuFsfwyezM0Z74jWcogRQNh1IECRU/mzIdtq47Ky8hnV HBWBNF4K+aYzk+h9qfgbCQ8wJkTCVwKORQBZlv7ab+rLUJ8Dds8OFdw8aJPvoCVX/Qav FTArG8kJTBmjHqVJoEB9Lg/Bw9PHWYd0YymIbYuiFhK6c49nhfUEjUkBa1y7RNyVL8d4 HLNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185217; x=1726790017; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yhLU431wzLJ+L96jZIVSfco4No4B8gvVcyEMQe0t1zo=; b=A4YoYKjMYD0Eniadcg56ogl2kSochCQ3f1F88tZH064e+qP+SJ/vkshaYtv9EfhcUP f0eDNaY3x4qhUPJLHTGkpbdWwIixHHqxDR5RNg8mKEYVwGB9iPFxShD8fMCOGj9SXoY2 zZGpBL7Vg7Xuc7jEm3leq3zv10+aMxNh8FjYtFn42J4jRn+UtORY856O0lof8CH8t2kV F5gT8ZnWC72PB6ZVnsGDIPtDrnWMWLqI5kCllRRnOtvBbDr5QvYDaZvfT9sToA4lUHq/ TqzN+AlxytNojI+SV9NorRS3gg2ywkg2Y5V9R6mJ46n6eKMuhMG+UGNEjPWN6RkDovEs QoMw== X-Forwarded-Encrypted: i=1; AJvYcCWqeWR8zfAvbV2aVEFmiCTgT6RVjfFdFk+JEFHp+wsADJaWhMaQIJ02LdV/u4oe7WrbDnwB+SqUhzYl@nongnu.org X-Gm-Message-State: AOJu0YyWGmihaM4z6odjiBjt6NcxzSFVd4dW7Xu6BJ7pUt3u/lex4jWV KD6OIn8cVt6wHDjZKpQEX/tpgC3iN0TfpDE1yR/VHaSj9PAWJslK8iBRnfZQ5Rc= X-Google-Smtp-Source: AGHT+IE6WKVZPmnHjtufG0J/4yDM5hZm77TSjY5NJol8s2967xefmWPypCa33VQJjcjZFLItMMiN1g== X-Received: by 2002:a05:6a00:23c3:b0:70d:3337:7820 with SMTP id d2e1a72fcca58-71936a4d269mr1535066b3a.8.1726185216657; Thu, 12 Sep 2024 16:53:36 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Alistair Francis Subject: [PATCH v14 09/20] target/riscv: Expose zicfilp extension as a cpu property Date: Thu, 12 Sep 2024 16:53:09 -0700 Message-ID: <20240912235320.3768582-10-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=debug@rivosinc.com; helo=mail-pf1-x435.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185531554116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index a0490e29f9..b4b578003f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1495,6 +1495,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), MULTI_EXT_CFG_BOOL("smcntrpmf", ext_smcntrpmf, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), + MULTI_EXT_CFG_BOOL("zicfilp", ext_zicfilp, false), MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true), MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true), --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185412; cv=none; d=zohomail.com; s=zohoarc; b=H2Fo0CYkqdfxyxJTb5oq9UcYHEKUDlIXXakha/9jz9tozNXYqNxkUZWF7sX+VK5nz2+9DUnunvTljP3wpOX7MmKezA3PL4gTuRRfwaQmYYQK9OHzR02/29y6FRnWjUnW+i9mg+SW1Whtm0BoUJevWp+ap7BZPh+vo3JvyiasUsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185412; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ptLKI6zAL4gMRldT6p+gGB6HQA07aljcoRmiuZiPzyA=; b=bpH56bfGcC726SdR+z30GlPrSJksFSNrx45qlHFbwjh/Qbd8TYjmXDpdNKm1R/pqUIzoosf2eUNa1pJ0BhnrHvrI1ajgKWovc/5ykytFGif7E4Kj1lD391ktT2xbxlliw28FhPer+QiBrgB/ofIwKNWB94uITk/CIY8e1QMKVS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185412570153.94249863178732; Thu, 12 Sep 2024 16:56:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotd8-00052Q-I3; Thu, 12 Sep 2024 19:53:42 -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 1sotd7-0004vd-0s for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:41 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotd5-0008AE-B7 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:40 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7178df70f28so1180558b3a.2 for ; Thu, 12 Sep 2024 16:53:38 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185218; x=1726790018; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ptLKI6zAL4gMRldT6p+gGB6HQA07aljcoRmiuZiPzyA=; b=QTkRX2sexD3Jvr6URU091PYaIJCrvKsn2wWlsUiMEKt6P/7iisWFogW1OksmIH1Ard 7T/HTyR8Sb8mY86KEivXCYbZ7C5p53G4t9wgdoCD6g6iC4SmpMtxvqKPHdyHhruRQ7QA hQob/vXnaBbNKAVRjjvxRklFyj5wj5Ogr6dcYWvqFRhnTanqv7IP1OrdomXmxzZKS6ZS yeGig+2dv2LnDCI2l2nRT7gmy9ir+2QWkDlr60Uv81skhIoQOp3YnsZ+IZQ8jneVgDqj 48lx808dikZHqiO51Z1bJBGZJ4803RiCI2YE7VdcQ63mtG5MEsApSfwFJ3ezDvZLjvRD ejsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185218; x=1726790018; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ptLKI6zAL4gMRldT6p+gGB6HQA07aljcoRmiuZiPzyA=; b=lb6sBUyhyyZxkCTfunYlsBQzxJN6aHRGBfjQ0emMSVlRLAA5+9tL3mMvWizk15A1PL MSfu9AUIFadZvSX4ndcH345Ibb9P/39fa+01KnQpqHd9LUSvhbT8AtZqCjK8ZHsyFSH2 YeCohpiU+/gEL4qsSqIZMHvIZirh4x2rOGj/MsBFfIlz9wZ4h3ZMDnqpX9McHYvIS3wu ZZtRtFP4CWhDmSyXunZwRDJaQxAqD4SDY910kElPmSCQLZqeHLmb7reerymR6QeBwL1Y XCqwyUsiaHLTULfUHTpvumaXrax2ah45Z0/xHvcAjOBZWQ4AtCsZrsKtyzAzoFUvocFc HtdQ== X-Forwarded-Encrypted: i=1; AJvYcCUt71KMy8hFivMHPxVd7h7JOB8lF5BdLyvTwaF3O58dg5oSfYy2P/vj+Tf5EWIBpH3hrtTsc/D4qALs@nongnu.org X-Gm-Message-State: AOJu0YxNsk+HXHDXv86eNo+zWPox6UIWVva86+If+nvg4eldKc95W4CA BSvmL9j/v7c6yMDxsXu8DcafyIqy3LdPkKHtzKOj7ZRTydyOCnRDvwuH54EcKWY= X-Google-Smtp-Source: AGHT+IGFjMvOJTucEL6Ra7B4Kp86Sp3PNSjYf4PaEKGPvdcxNwucT7gfRDkpP2gU7r90WMpZ7Ek9lw== X-Received: by 2002:aa7:88c8:0:b0:70d:3938:f1a5 with SMTP id d2e1a72fcca58-719261e1596mr6478363b3a.22.1726185218061; Thu, 12 Sep 2024 16:53:38 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Alistair Francis Subject: [PATCH v14 10/20] target/riscv: Add zicfiss extension Date: Thu, 12 Sep 2024 16:53:10 -0700 Message-ID: <20240912235320.3768582-11-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42c.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185415111116600 Content-Type: text/plain; charset="utf-8" zicfiss [1] riscv cpu extension enables backward control flow integrity. This patch sets up space for zicfiss extension in cpuconfig. And imple- ments dependency on A, zicsr, zimop and zcmop extensions. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index b4b578003f..f5513fab03 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -107,6 +107,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(zicfilp, PRIV_VERSION_1_12_0, ext_zicfilp), + ISA_EXT_DATA_ENTRY(zicfiss, PRIV_VERSION_1_13_0, ext_zicfiss), ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), ISA_EXT_DATA_ENTRY(zicntr, PRIV_VERSION_1_12_0, ext_zicntr), ISA_EXT_DATA_ENTRY(zicsr, PRIV_VERSION_1_10_0, ext_zicsr), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index fe7ad85b66..59d6fc445d 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -68,6 +68,7 @@ struct RISCVCPUConfig { bool ext_zicbop; bool ext_zicboz; bool ext_zicfilp; + bool ext_zicfiss; bool ext_zicond; bool ext_zihintntl; bool ext_zihintpause; diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 963c1c604a..6c0c319499 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -618,6 +618,29 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, = Error **errp) cpu->cfg.ext_zihpm =3D false; } =20 + if (cpu->cfg.ext_zicfiss) { + if (!cpu->cfg.ext_zicsr) { + error_setg(errp, "zicfiss extension requires zicsr extension"); + return; + } + if (!riscv_has_ext(env, RVA)) { + error_setg(errp, "zicfiss extension requires A extension"); + return; + } + if (!riscv_has_ext(env, RVS)) { + error_setg(errp, "zicfiss extension requires S"); + return; + } + if (!cpu->cfg.ext_zimop) { + error_setg(errp, "zicfiss extension requires zimop extension"); + return; + } + if (cpu->cfg.ext_zca && !cpu->cfg.ext_zcmop) { + error_setg(errp, "zicfiss with zca requires zcmop extension"); + return; + } + } + if (!cpu->cfg.ext_zihpm) { cpu->cfg.pmu_mask =3D 0; cpu->pmu_avail_ctrs =3D 0; --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185377; cv=none; d=zohomail.com; s=zohoarc; b=NBIdTQ4znPN52BvPd2Ur/glVhOKi0TKt1v7yEEVKBTOUcO4v67vgnom2v4SV8whlDfqBEtJEMar7qrZTDNdyP0rVDlUiCWet3RrbGwTGu5hcfEZUj5zlJvPg9PVDLMRf1bimC899wz/wbi1izIJ1cvQnZ4tP5lglp71ovbyLMwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185377; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q2U753PKEt+vnSNTrfcmtA4tw3Grxus2FebHFCCNQ+g=; b=i7AMVF/8xD9Cf4XWExf3tY5BiJ6dGpY8WMe80DuyGiDTpP2M36gwuTok7JqYvlgYB2vcK6/w3q/bBn05NBLrm5Y97wMMP5nQu+eUPtgLBvm1y6rbheJX+Zje8qZBlGNV9+JomGounkPfPeZnX3RbCAksuwvo51z5wh7F1VeQGUU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185377248594.5684370716895; Thu, 12 Sep 2024 16:56:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdA-0005BU-Oq; Thu, 12 Sep 2024 19:53:44 -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 1sotd8-00053g-QY for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:42 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotd6-0008Ai-Ph for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:42 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-718e9c8bd83so1947778b3a.1 for ; Thu, 12 Sep 2024 16:53:40 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185219; x=1726790019; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q2U753PKEt+vnSNTrfcmtA4tw3Grxus2FebHFCCNQ+g=; b=1ASdpFinzYDWg8Vs8MBPNzRIrsKeCF+ENxAYlHkt5JtKWIC+Qp7ixmrYCTW2ggsh2c +GulUO3JDB43UslfkF52ooTD7pAIGa2ByRCWSbg1NGS1DItWlsEHc28o3Eqb1xSXvi47 RGnLklyd5NgX80Ss0d10o3Caxgdhy5ldk/KllcnkR/xFWBI85tuzgxC9BQLrCRUEg6Tr +eWx7a5TzLcyf+YlKgP3NX50n2WVxZkveMcQUMF493J6dJo0V8WfQugs6BLfr2hIhNxs Jnn7VM52lBavWMaHijKUmf1pOs2V0p6XpUtgJuV7ln8xrPigO5nI0bzVgD5RZY+MNtjz xcfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185219; x=1726790019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q2U753PKEt+vnSNTrfcmtA4tw3Grxus2FebHFCCNQ+g=; b=mqWcR3DgxINVTOkQQhnCEj3eqgRjqUYcNmrZswSQpS8IF7Eo/hwSYI1Ie1LfKDS8YV iZ/WHu+z3Y9fBGKpNgaFrRQJaR5hhlmhZZK8Qf/W0cDgLlYtJJmEWr9tJl8OBaMNTh+l +m+JkzOlkN5IpwqRnt2zevFKflcokrLivqfWiLjSKtrmTRgLM5545awxmPu8vvz3PX88 4iXbAn93gn206NisFyPu7u7GukRSM6vLOo+la/tKD2+Rgb9q9Aasq5A3Aa5v1dXV2fKg GVbdorqv7DV92Fg07IjFJflITC7fSGQOJKie5zEDWMhGY6vveshKotlU4Z8XVXYGWc7C YdBg== X-Forwarded-Encrypted: i=1; AJvYcCU5vBRagHIIjoUs/LPvQt9FVXGvzFUdfVWrHyYdRf4ANWxPgHj8NHca22FRXg/jqGiDx+z1PIXH0mIm@nongnu.org X-Gm-Message-State: AOJu0YyKx8BlxS9kJI8hdU+CvvDYdj9OBo4OtzCE2dw4z9VWBMGZ4Ge+ 4nOGsOmoDw/7bnyC51a8ZxvQeVDTi0DZbvR6QlElkvS3ate8N6oGFHGp+xIhd5o= X-Google-Smtp-Source: AGHT+IFKsgRLHI36gDDtXoQolyGwNTzL3lGSZu/oGdpbK8nXtDlPe9/QGzH88HFWT3vEPtCQ78hVJw== X-Received: by 2002:a05:6a00:61cb:b0:717:92d8:ca5c with SMTP id d2e1a72fcca58-71907e8ca91mr16166797b3a.3.1726185219451; Thu, 12 Sep 2024 16:53:39 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 11/20] target/riscv: introduce ssp and enabling controls for zicfiss Date: Thu, 12 Sep 2024 16:53:11 -0700 Message-ID: <20240912235320.3768582-12-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=debug@rivosinc.com; helo=mail-pf1-x435.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185379639116600 Content-Type: text/plain; charset="utf-8" zicfiss introduces a new state ssp ("shadow stack register") in cpu. ssp is expressed as a new unprivileged csr (CSR_SSP=3D0x11) and holds virtual address for shadow stack as programmed by software. Shadow stack (for each mode) is enabled via bit3 in *envcfg CSRs. Shadow stack can be enabled for a mode only if it's higher privileged mode had it enabled for itself. M mode doesn't need enabling control, it's always available if extension is available on cpu. This patch also implements helper bcfi function which determines if bcfi is enabled at current privilege or not. Adds ssp to migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 2 ++ target/riscv/cpu.h | 3 +++ target/riscv/cpu_bits.h | 6 +++++ target/riscv/cpu_helper.c | 29 ++++++++++++++++++++++ target/riscv/csr.c | 52 +++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 19 ++++++++++++++ 6 files changed, 111 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f5513fab03..4172774087 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1034,6 +1034,8 @@ static void riscv_cpu_reset_hold(Object *obj, ResetTy= pe type) =20 /* on reset elp is clear */ env->elp =3D false; + /* on reset ssp is set to 0 */ + env->ssp =3D 0; =20 env->xl =3D riscv_cpu_mxl(env); riscv_cpu_update_mask(env); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ba4bc212c7..997b579526 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -232,6 +232,8 @@ struct CPUArchState { =20 /* elp state for zicfilp extension */ bool elp; + /* shadow stack register for zicfiss extension */ + target_ulong ssp; /* sw check code for sw check exception */ target_ulong sw_check_code; #ifdef CONFIG_USER_ONLY @@ -550,6 +552,7 @@ bool riscv_cpu_vector_enabled(CPURISCVState *env); void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); int riscv_env_mmu_index(CPURISCVState *env, bool ifetch); bool cpu_get_fcfien(CPURISCVState *env); +bool cpu_get_bcfien(CPURISCVState *env); G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t reta= ddr); diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index e7387c9b8f..8223beaceb 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -34,6 +34,9 @@ =20 /* Control and Status Registers */ =20 +/* zicfiss user ssp csr */ +#define CSR_SSP 0x011 + /* User Trap Setup */ #define CSR_USTATUS 0x000 #define CSR_UIE 0x004 @@ -761,6 +764,7 @@ typedef enum RISCVException { /* Execution environment configuration bits */ #define MENVCFG_FIOM BIT(0) #define MENVCFG_LPE BIT(2) /* zicfilp */ +#define MENVCFG_SSE BIT(3) /* zicfiss */ #define MENVCFG_CBIE (3UL << 4) #define MENVCFG_CBCFE BIT(6) #define MENVCFG_CBZE BIT(7) @@ -775,12 +779,14 @@ typedef enum RISCVException { =20 #define SENVCFG_FIOM MENVCFG_FIOM #define SENVCFG_LPE MENVCFG_LPE +#define SENVCFG_SSE MENVCFG_SSE #define SENVCFG_CBIE MENVCFG_CBIE #define SENVCFG_CBCFE MENVCFG_CBCFE #define SENVCFG_CBZE MENVCFG_CBZE =20 #define HENVCFG_FIOM MENVCFG_FIOM #define HENVCFG_LPE MENVCFG_LPE +#define HENVCFG_SSE MENVCFG_SSE #define HENVCFG_CBIE MENVCFG_CBIE #define HENVCFG_CBCFE MENVCFG_CBCFE #define HENVCFG_CBZE MENVCFG_CBZE diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 1c89b126dd..934bbff579 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -91,6 +91,35 @@ bool cpu_get_fcfien(CPURISCVState *env) } } =20 +bool cpu_get_bcfien(CPURISCVState *env) +{ + /* no cfi extension, return false */ + if (!env_archcpu(env)->cfg.ext_zicfiss) { + return false; + } + + switch (env->priv) { + case PRV_U: + /* + * If S is not implemented then shadow stack for U can't be turned= on + * It is checked in `riscv_cpu_validate_set_extensions`, so no nee= d to + * check here or assert here + */ + return env->senvcfg & SENVCFG_SSE; +#ifndef CONFIG_USER_ONLY + case PRV_S: + if (env->virt_enabled) { + return env->henvcfg & HENVCFG_SSE; + } + return env->menvcfg & MENVCFG_SSE; + case PRV_M: /* M-mode shadow stack is always off */ + return false; +#endif + default: + g_assert_not_reached(); + } +} + void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, uint64_t *cs_base, uint32_t *pflags) { diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 919de7970c..604c2698ad 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -184,6 +184,25 @@ static RISCVException zcmt(CPURISCVState *env, int csr= no) return RISCV_EXCP_NONE; } =20 +static RISCVException cfi_ss(CPURISCVState *env, int csrno) +{ + if (!env_archcpu(env)->cfg.ext_zicfiss) { + return RISCV_EXCP_ILLEGAL_INST; + } + + /* if bcfi not active for current env, access to csr is illegal */ + if (!cpu_get_bcfien(env)) { +#if !defined(CONFIG_USER_ONLY) + if (env->debugger) { + return RISCV_EXCP_NONE; + } +#endif + return RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; +} + #if !defined(CONFIG_USER_ONLY) static RISCVException mctr(CPURISCVState *env, int csrno) { @@ -622,6 +641,19 @@ static RISCVException seed(CPURISCVState *env, int csr= no) #endif } =20 +/* zicfiss CSR_SSP read and write */ +static int read_ssp(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->ssp; + return RISCV_EXCP_NONE; +} + +static int write_ssp(CPURISCVState *env, int csrno, target_ulong val) +{ + env->ssp =3D val; + return RISCV_EXCP_NONE; +} + /* User Floating-Point CSRs */ static RISCVException read_fflags(CPURISCVState *env, int csrno, target_ulong *val) @@ -2354,6 +2386,10 @@ static RISCVException write_menvcfg(CPURISCVState *e= nv, int csrno, if (env_archcpu(env)->cfg.ext_zicfilp) { mask |=3D MENVCFG_LPE; } + + if (env_archcpu(env)->cfg.ext_zicfiss) { + mask |=3D MENVCFG_SSE; + } } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 @@ -2410,6 +2446,13 @@ static RISCVException write_senvcfg(CPURISCVState *e= nv, int csrno, mask |=3D SENVCFG_LPE; } =20 + /* Higher mode SSE must be ON for next-less mode SSE to be ON */ + if (env_archcpu(env)->cfg.ext_zicfiss && + get_field(env->menvcfg, MENVCFG_SSE) && + (env->virt_enabled ? get_field(env->henvcfg, HENVCFG_SSE) : true))= { + mask |=3D SENVCFG_SSE; + } + env->senvcfg =3D (env->senvcfg & ~mask) | (val & mask); return RISCV_EXCP_NONE; } @@ -2451,6 +2494,12 @@ static RISCVException write_henvcfg(CPURISCVState *e= nv, int csrno, if (env_archcpu(env)->cfg.ext_zicfilp) { mask |=3D HENVCFG_LPE; } + + /* H can light up SSE for VS only if HS had it from menvcfg */ + if (env_archcpu(env)->cfg.ext_zicfiss && + get_field(env->menvcfg, MENVCFG_SSE)) { + mask |=3D HENVCFG_SSE; + } } =20 env->henvcfg =3D (env->henvcfg & ~mask) | (val & mask); @@ -4966,6 +5015,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { /* Zcmt Extension */ [CSR_JVT] =3D {"jvt", zcmt, read_jvt, write_jvt}, =20 + /* zicfiss Extension, shadow stack register */ + [CSR_SSP] =3D { "ssp", cfi_ss, read_ssp, write_ssp }, + #if !defined(CONFIG_USER_ONLY) /* Machine Timers and Counters */ [CSR_MCYCLE] =3D { "mcycle", any, read_hpmcounter, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index c3a06c288d..99f0af5077 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -368,6 +368,24 @@ static const VMStateDescription vmstate_elp =3D { } }; =20 +static bool ssp_needed(void *opaque) +{ + RISCVCPU *cpu =3D opaque; + + return cpu->cfg.ext_zicfiss; +} + +static const VMStateDescription vmstate_ssp =3D { + .name =3D "cpu/ssp", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D ssp_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_UINTTL(env.ssp, RISCVCPU), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_riscv_cpu =3D { .name =3D "cpu", .version_id =3D 10, @@ -441,6 +459,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { &vmstate_smstateen, &vmstate_jvt, &vmstate_elp, + &vmstate_ssp, NULL } }; --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185316; cv=none; d=zohomail.com; s=zohoarc; b=e9uWYDmFdW/Y76EEXiPmGdFK4TONbeMMUwdYTDifsrAyPC8Q9m50EIxb1AjdQoR6gqfG71CpN8DBfjVogpGGIyk9XtRQWUR7luoeBtpoUi33KTij5beER/d4Sh9AfbY2rC7VzColKQHpiKbbzqYhDY5Xp0IUfGOi7ahbU6FVt38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185316; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FgQKcewfbnTfEcrsbPUbZIBiPMivs9PSGeqvWwo32SM=; b=NjEcFVlCPLaLuPJoIfKpgpukTT/2yX/Xxa1vhFEcAuI6JZl/DSdY5OyMiGb0D6Eik7LLLilyS8vodAbg6JttVMiYMZ4db/epUPMJiLC82OV3tp7DYXvFafTBSK9V966W23jihUrLFU5mHk8ZT6SzRo5uGRq7aK117Z4DX+aSQtg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185316113445.8048497485096; Thu, 12 Sep 2024 16:55:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdC-0005Hi-6t; Thu, 12 Sep 2024 19:53:46 -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 1sotdA-00058j-1r for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:44 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotd8-0008B1-E9 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:43 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-718e11e4186so1409209b3a.2 for ; Thu, 12 Sep 2024 16:53:42 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185221; x=1726790021; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FgQKcewfbnTfEcrsbPUbZIBiPMivs9PSGeqvWwo32SM=; b=qvK8WKEwsB5jhTpoPoAWgCdD4yIHYbViwLwWGqAYcxY135chOGzrDygtMg60GJiq5f RmLGh+Eh1sfTsw0m/wBdDWe7wxJuYn58k+aHJsXvIK7hBoVLOMIwTCvkOMaA4kE9ki0v ATPltwT6p7D5Ypil8mvT1ouR1aBNAnxtPgNWdP5/GaAbmQaLaq6JMxPI0Pc2CG9rG4EJ meGo37eW46B0bMlyjxEUGKswWzr2AZ7K/jJqQGjGB3Gnue48tVGU5jY+c9U+ghZGvKP+ +4KjsYcHTLLWyXxWfjjHORZSO9DJyT/2zylRyA9sQxp9hzctbsHRt3oq9ge1wI3tw+A1 DZIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185221; x=1726790021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FgQKcewfbnTfEcrsbPUbZIBiPMivs9PSGeqvWwo32SM=; b=aEDdrJC57dSJPX99TDFywdhdkYqKebgZ/brR9C1gTbKj2WZUMz4OLzM6hzv8/s6gOp MRGahLhe+PIC5nsN074msAE3Z7K6Ha90i3PrOR1lo0oHOMnWGrNF+jCkYewJzW1XYi0h wD84peO1FyGvq1ADo7ni9eK6RsL9mPWSJyvGSD+MHrZl9VNrQ/4Hg4fBLGt+c7zqcFCk sEa0AvTa3B+EmiIyR/Y7r7e5/+ia9Bn3VyoIfVy36Zg8iRVn91qvl7n98uQnyN/8dQkz bjiAhCiIR1oTbm/ETx4lmVm99/HcQYt9iBWu84nlfeXPirKut3mgAtmMhxs+0yMIyutK iArw== X-Forwarded-Encrypted: i=1; AJvYcCXT1iRDZxMxT0MNITFAsLtCwoZzjf84uxzK2kEzMyuw+GAeJ7DAalq98tqk0nIT9GHsik//uw9/xRM/@nongnu.org X-Gm-Message-State: AOJu0YxujjL1WJQS71yaKdJTkZaPdpwrNA0n6cjiZRgY9G38hymBzT6d Kms/IYEWkSTHW+Dgf1iOGf+GblbpQRwTO52u6g1wd96EIHoEQAGlG7pQ7+jTO5M= X-Google-Smtp-Source: AGHT+IGWWohQrkoIlXk+defS75cNWlR8Vmu4UbrvXT8+FQReFr9r2zQbX9kCrHzIC4orOmSEqQm6jA== X-Received: by 2002:a05:6a00:3e15:b0:714:2533:1b82 with SMTP id d2e1a72fcca58-71926205fa6mr7701065b3a.23.1726185220917; Thu, 12 Sep 2024 16:53:40 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 12/20] target/riscv: tb flag for shadow stack instructions Date: Thu, 12 Sep 2024 16:53:12 -0700 Message-ID: <20240912235320.3768582-13-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42c.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185317193116600 Content-Type: text/plain; charset="utf-8" Shadow stack instructions can be decoded as zimop / zcmop or shadow stack instructions depending on whether shadow stack are enabled at current privilege. This requires a TB flag so that correct TB generation and correct TB lookup happens. `DisasContext` gets a field indicating whether bcfi is enabled or not. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 4 ++++ target/riscv/translate.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 997b579526..d39650636c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -628,6 +628,8 @@ FIELD(TB_FLAGS, AXL, 26, 2) /* zicfilp needs a TB flag to track indirect branches */ FIELD(TB_FLAGS, FCFI_ENABLED, 28, 1) FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 29, 1) +/* zicfiss needs a TB flag so that correct TB is located based on tb flags= */ +FIELD(TB_FLAGS, BCFI_ENABLED, 30, 1) =20 #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 934bbff579..93d199748e 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -171,6 +171,10 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, flags =3D FIELD_DP32(flags, TB_FLAGS, FCFI_ENABLED, 1); } =20 + if (cpu_get_bcfien(env)) { + flags =3D FIELD_DP32(flags, TB_FLAGS, BCFI_ENABLED, 1); + } + #ifdef CONFIG_USER_ONLY fs =3D EXT_STATUS_DIRTY; vs =3D EXT_STATUS_DIRTY; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index b5c0511b4b..afa2ed4e3a 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -119,6 +119,8 @@ typedef struct DisasContext { /* zicfilp extension. fcfi_enabled, lp expected or not */ bool fcfi_enabled; bool fcfi_lp_expected; + /* zicfiss extension, if shadow stack was enabled during TB gen */ + bool bcfi_enabled; } DisasContext; =20 static inline bool has_ext(DisasContext *ctx, uint32_t ext) @@ -1241,6 +1243,7 @@ static void riscv_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cs) ctx->pm_base_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLE= D); ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); + ctx->bcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED); ctx->fcfi_lp_expected =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_LP_EXPEC= TED); ctx->fcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_ENABLED); ctx->zero =3D tcg_constant_tl(0); --=20 2.45.0 From nobody Thu Nov 14 04:04:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185328; cv=none; d=zohomail.com; s=zohoarc; b=QWv5SmlK3cU5wi+iWQa3BjHyJgPFeZx2tFlp8WwnJ0WPFT5B3zPXAjO8CnBkuY1SFQhZobxR9ku+yxaOunU+FL1qkUJELV+x09gW2Eji2aD4X7+Pc7WrYuXM7JICqpYJTpvOsCRTkWF4VYZKUzBljNiYGtGQkflI9NOZK3NaANs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185328; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qMl0wOVdpYR1ANnhlgzvb07hHsnxQN9qOy6OtOfW7ZU=; b=AVfv1jhZE/f0cXPntuQpm0ak9P+oLIqNkiun0E+jn9B7te8eK0dqcLoEYbG6WmNQgKA+Amq4BjebDkfKTeRtiIqKYA/rn/QpeOZKjObsa0CzB44teVxPpOKATLWNAmFRbeY8EzsVW7H32t/JUi51NCh5kXbi3txZ1c7cUywYrS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185328813842.6484132386734; Thu, 12 Sep 2024 16:55:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdD-0005LW-4k; Thu, 12 Sep 2024 19:53:47 -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 1sotdB-0005Ec-Br for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:45 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotd9-0008BJ-Kp for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:45 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7179069d029so320714b3a.2 for ; Thu, 12 Sep 2024 16:53:43 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185222; x=1726790022; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qMl0wOVdpYR1ANnhlgzvb07hHsnxQN9qOy6OtOfW7ZU=; b=gqXW7wnVDWZASS84OR1ziMg213q1oVtPabSDaKIcgmx0vQmjvRn5NaATKIbmXiBnXZ tbtn+4DMWuJyKxFW2bV6t5aIIWCNutDXuxM8LpaU9xaVteq71Ni/Hmi03lKQfMKRqrKM Un9rzdfQv2MMGbGbmh+2ZZcuDOJczFpv+rhnpWgFcmU2z7WfCseoVXIUJzMnDQr2xLlX GPymNKC5BWbsYA/ox5nRLmSqq5n9x5vzXZ9fi0V81Z+xX8KBzY/x5rbv8izjMPK7WMxk b0TiIrxd1yDQL7qLdzVKLYSzYaZxARgSwqwRATxClli/cQgnvPYabjBAMtqLPtuKFn48 iqXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185222; x=1726790022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qMl0wOVdpYR1ANnhlgzvb07hHsnxQN9qOy6OtOfW7ZU=; b=wvKkwjg8mhzAPHPqhOdl1hY/SdHEHNmkP0zI01RSLSB2nZ/iOaDa0wpZpX61Wvn4vK /1Z2G/DXxXCVhvDvi6kJosx327qlzBPuC8XMCO+wREAfrCcOJlL8lGssZoAnZHKTQlWl cNl6dWgnclbiqlsnOK9poRe/YptrnjIvpF52SKij0i2c5Cdq24pSCQeyesE4Uqu624AB 4GtpqWHg6/iQicVcxR+w2WSHF8wer7gTIEfGlmwQey1EbMv9O+MJuBJrUAHPrwv62P/0 9n2jPsNg+kNY8nsS1r3IMcKuy07z7+7ZV+3ShyC3gxxpD9KrzzDX61aPnlJhhDjl14sA w7Ag== X-Forwarded-Encrypted: i=1; AJvYcCVSKwMkr4l1nayimHbEgPOXaYGOKGlTFitAo8uP+dhfrhOdoK75TcbaO53gVyttMwKBu5IGSEWMMdFv@nongnu.org X-Gm-Message-State: AOJu0Yx5Kd26nIvOgPQNuB4pUc1xAKy9PymVglwVCcq4FlFl/vdOqHCK Rd3LUsOVAxOmZ/mjroaneAw+O+Sl1jvk7OGwYzvU4rWmuBbB8IpXaa509AHEqDk= X-Google-Smtp-Source: AGHT+IF4HyqBbzke/+ieS3rcVRqZA8tmRvffSRg7bcd/svDH+SgI2LKovvCygjZ3rDFRdpYBpwgAjg== X-Received: by 2002:a05:6a20:c99a:b0:1cc:e47f:1004 with SMTP id adf61e73a8af0-1d112db38c5mr1103019637.26.1726185222355; Thu, 12 Sep 2024 16:53:42 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v14 13/20] target/riscv: mmu changes for zicfiss shadow stack protection Date: Thu, 12 Sep 2024 16:53:13 -0700 Message-ID: <20240912235320.3768582-14-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42b.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185329406116600 Content-Type: text/plain; charset="utf-8" zicfiss protects shadow stack using new page table encodings PTE.W=3D1, PTE.R=3D0 and PTE.X=3D0. This encoding is reserved if zicfiss is not implemented or if shadow stack are not enabled. Loads on shadow stack memory are allowed while stores to shadow stack memory leads to access faults. Shadow stack accesses to RO memory leads to store page fault. To implement special nature of shadow stack memory where only selected stores (shadow stack stores from sspush) have to be allowed while rest of regular stores disallowed, new MMU TLB index is created for shadow stack. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson --- target/riscv/cpu_helper.c | 46 +++++++++++++++++++++++++++++++++------ target/riscv/internals.h | 3 +++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 93d199748e..5580f5f3f3 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -898,6 +898,8 @@ static int get_physical_address(CPURISCVState *env, hwa= ddr *physical, hwaddr ppn; int napot_bits =3D 0; target_ulong napot_mask; + bool is_sstack_idx =3D ((mmu_idx & MMU_IDX_SS_WRITE) =3D=3D MMU_IDX_SS= _WRITE); + bool sstack_page =3D false; =20 /* * Check if we should use the background registers for the two @@ -1106,21 +1108,40 @@ restart: return TRANSLATE_FAIL; } =20 + target_ulong rwx =3D pte & (PTE_R | PTE_W | PTE_X); /* Check for reserved combinations of RWX flags. */ - switch (pte & (PTE_R | PTE_W | PTE_X)) { - case PTE_W: + switch (rwx) { case PTE_W | PTE_X: return TRANSLATE_FAIL; + case PTE_W: + /* if bcfi enabled, PTE_W is not reserved and shadow stack page */ + if (cpu_get_bcfien(env) && first_stage) { + sstack_page =3D true; + /* if ss index, read and write allowed. else only read allowed= */ + rwx =3D is_sstack_idx ? PTE_R | PTE_W : PTE_R; + break; + } + return TRANSLATE_FAIL; + case PTE_R: + /* + * no matter what's the `access_type`, shadow stack access to read= only + * memory are always store page faults. During unwind, loads will = be + * promoted as store fault. + */ + if (is_sstack_idx) { + return TRANSLATE_FAIL; + } + break; } =20 int prot =3D 0; - if (pte & PTE_R) { + if (rwx & PTE_R) { prot |=3D PAGE_READ; } - if (pte & PTE_W) { + if (rwx & PTE_W) { prot |=3D PAGE_WRITE; } - if (pte & PTE_X) { + if (rwx & PTE_X) { bool mxr =3D false; =20 /* @@ -1164,8 +1185,11 @@ restart: } =20 if (!((prot >> access_type) & 1)) { - /* Access check failed */ - return TRANSLATE_FAIL; + /* + * Access check failed, access check failures for shadow stack are + * access faults. + */ + return sstack_page ? TRANSLATE_PMP_FAIL : TRANSLATE_FAIL; } =20 target_ulong updated_pte =3D pte; @@ -1352,9 +1376,17 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vad= dr addr, break; case MMU_DATA_LOAD: cs->exception_index =3D RISCV_EXCP_LOAD_ADDR_MIS; + /* shadow stack mis aligned accesses are access faults */ + if (mmu_idx & MMU_IDX_SS_WRITE) { + cs->exception_index =3D RISCV_EXCP_LOAD_ACCESS_FAULT; + } break; case MMU_DATA_STORE: cs->exception_index =3D RISCV_EXCP_STORE_AMO_ADDR_MIS; + /* shadow stack mis aligned accesses are access faults */ + if (mmu_idx & MMU_IDX_SS_WRITE) { + cs->exception_index =3D RISCV_EXCP_STORE_AMO_ACCESS_FAULT; + } break; default: g_assert_not_reached(); diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 0ac17bc5ad..ddbdee885b 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -30,12 +30,15 @@ * - U+2STAGE 0b100 * - S+2STAGE 0b101 * - S+SUM+2STAGE 0b110 + * - Shadow stack+U 0b1000 + * - Shadow stack+S 0b1001 */ #define MMUIdx_U 0 #define MMUIdx_S 1 #define MMUIdx_S_SUM 2 #define MMUIdx_M 3 #define MMU_2STAGE_BIT (1 << 2) +#define MMU_IDX_SS_WRITE (1 << 3) =20 static inline int mmuidx_priv(int mmu_idx) { --=20 2.45.0 From nobody Thu Nov 14 04:04:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185292; cv=none; d=zohomail.com; s=zohoarc; b=i5SwzSqY2JE41AC1yiabuE1zm0zMXPihvsPa9c+spXy9KN2SsNwyDoKKyEEm0SvMgxQHCxNlgDnA7/BiDgAEXfw9mz142QfIRD+kymisxIMZdQYUDDCEJky8H7SZQBabmxNI7ULxh9dB0ykOBX+CDbcqPgpC4oJRsyvd/Qq+gEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185292; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O++ZZhLnxmHlgJhOA2pY97AskiBevFhww8e1bltmHXM=; b=TKtX3yD+6/CfgOarxzHvPy8WWWALX/dLbS5amvQyW/v+w9/o+yCV7i43wOXZN55NnaBF8g4P7FOdI1TpFqr1pfR9r0G5YQer/SQUgKroAzfWofjKbRMUze/hVhfoXnQa+w8HHglnTQlQrlaT0OdsbNDxt1g5S4+lmmT+1nxUv3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185292012594.2943040566231; Thu, 12 Sep 2024 16:54:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdF-0005UK-KT; Thu, 12 Sep 2024 19:53:49 -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 1sotdC-0005LD-VV for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:46 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotdB-0008Bh-97 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:46 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7193010d386so342987b3a.1 for ; Thu, 12 Sep 2024 16:53:44 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185224; x=1726790024; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O++ZZhLnxmHlgJhOA2pY97AskiBevFhww8e1bltmHXM=; b=F77JrISQ65r1TIAjZ6hBTuD4ZipDZ1AYuUYApOTmSM1/kzW3g+RGw6OWwXmb6kvCVI LxizQalE7/7AuNTn6Y5dXG3CziQsc5+tOfJpLJ9cFldRY+R5sEWHLMMTDt8dTqPrCjik +Y+8aTvFq4Wyb2nU8NoGbr4Y7DjqY/Bu7+fQt4pXDjKJ8eFckGze6c6I2AM+hCEcZofI 4Mfadq/Y82QG1fi1Bv4lrxPKEvsOVbZVueRtBHltWcpnr7pXawfHmH8uBgXjZ1g0sXUY 764xjJaSEkoR/XLcmvt0lE18YCJDqm9uXcCqs1Ua8UYpC3kb/EtcwDE6P6WIz+IjnP3E fCrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185224; x=1726790024; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O++ZZhLnxmHlgJhOA2pY97AskiBevFhww8e1bltmHXM=; b=PlQ6cdnqqD+UHD5CC655Vr+nPCZjlne0OWNaoajevd5BXSOprQoBWQGtefA3upfLus DAJDPd1Xk1dC3iHo0eud28hy6nr5yHcda8p/JpbBqaRQpoAfU9AjG0KJyo5kIEqj3+Xh 1dxqICIz+Nbg/jnn7NL2zirDwdygiRjfmRhGZy0ROLNR3av/9wC7fXBOOfc3v8RDcwL8 Nh8JTxbufFs/ksd6gYi+HkHDJhLzYNjvu25SUj3BdsZZaZ9YPYtQ5LWzJM4O1jdT7Blg ZokrFEDWDWugoeDI0cdVTLEiERmJEj8s0X2g7OT2r93GcDKlUQMqL9nXGLjtoep8qk0p N0uw== X-Forwarded-Encrypted: i=1; AJvYcCXVFR3lCZLOomLPy1S6fYwLVApQ85ns4Bylq4r0753AnD/HaGna9sfZ7EdCo85kIWWML9dYa7257AuW@nongnu.org X-Gm-Message-State: AOJu0YzXRG8SOV2f3wh4ObVfyGZ25k/Zq3BsytUY+6/klVaHOV3HjNYl 2KwYxphx7VIm3S7sDidDGbhyFeT1cgrf857yRq7flySuzKZh5qRqS/W+6/kKjB8= X-Google-Smtp-Source: AGHT+IEXsr634fSF2bqRt6awSvATMNE/sWL7G6pYxr3DlDD8T03A2+qmYxFf4J+0brW/gOCa+85b4w== X-Received: by 2002:a05:6a00:2ea8:b0:718:d5fb:2fc4 with SMTP id d2e1a72fcca58-71936a4b816mr1357979b3a.9.1726185223767; Thu, 12 Sep 2024 16:53:43 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 14/20] target/riscv: AMO operations always raise store/AMO fault Date: Thu, 12 Sep 2024 16:53:14 -0700 Message-ID: <20240912235320.3768582-15-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42c.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185294693116600 Content-Type: text/plain; charset="utf-8" This patch adds one more word for tcg compile which can be obtained during unwind time to determine fault type for original operation (example AMO). Depending on that, fault can be promoted to store/AMO fault. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 9 ++++++++- target/riscv/cpu_helper.c | 20 ++++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 1 + target/riscv/translate.c | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d39650636c..fb93b0c859 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -46,8 +46,13 @@ typedef struct CPUArchState CPURISCVState; /* * RISC-V-specific extra insn start words: * 1: Original instruction opcode + * 2: more information about instruction */ -#define TARGET_INSN_START_EXTRA_WORDS 1 +#define TARGET_INSN_START_EXTRA_WORDS 2 +/* + * b0: Whether a instruction always raise a store AMO or not. + */ +#define RISCV_UW2_ALWAYS_STORE_AMO 1 =20 #define RV(x) ((target_ulong)1 << (x - 'A')) =20 @@ -234,6 +239,8 @@ struct CPUArchState { bool elp; /* shadow stack register for zicfiss extension */ target_ulong ssp; + /* env place holder for extra word 2 during unwind */ + target_ulong excp_uw2; /* sw check code for sw check exception */ target_ulong sw_check_code; #ifdef CONFIG_USER_ONLY diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 5580f5f3f3..1fcdf556b8 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1753,6 +1753,22 @@ static target_ulong riscv_transformed_insn(CPURISCVS= tate *env, return xinsn; } =20 +static target_ulong promote_load_fault(target_ulong orig_cause) +{ + switch (orig_cause) { + case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT: + return RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; + + case RISCV_EXCP_LOAD_ACCESS_FAULT: + return RISCV_EXCP_STORE_AMO_ACCESS_FAULT; + + case RISCV_EXCP_LOAD_PAGE_FAULT: + return RISCV_EXCP_STORE_PAGE_FAULT; + } + + /* if no promotion, return original cause */ + return orig_cause; +} /* * Handle Traps * @@ -1765,6 +1781,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) CPURISCVState *env =3D &cpu->env; bool virt =3D env->virt_enabled; bool write_gva =3D false; + bool always_storeamo =3D (env->excp_uw2 & RISCV_UW2_ALWAYS_STORE_AMO); uint64_t s; =20 /* @@ -1800,6 +1817,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) case RISCV_EXCP_STORE_AMO_ACCESS_FAULT: case RISCV_EXCP_LOAD_PAGE_FAULT: case RISCV_EXCP_STORE_PAGE_FAULT: + if (always_storeamo) { + cause =3D promote_load_fault(cause); + } write_gva =3D env->two_stage_lookup; tval =3D env->badaddr; if (env->two_stage_indirect_lookup) { diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 6c0c319499..c62c221696 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -129,6 +129,7 @@ static void riscv_restore_state_to_opc(CPUState *cs, env->pc =3D pc; } env->bins =3D data[1]; + env->excp_uw2 =3D data[2]; } =20 static const TCGCPUOps riscv_tcg_ops =3D { diff --git a/target/riscv/translate.c b/target/riscv/translate.c index afa2ed4e3a..0322597bf6 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1264,7 +1264,7 @@ static void riscv_tr_insn_start(DisasContextBase *dcb= ase, CPUState *cpu) pc_next &=3D ~TARGET_PAGE_MASK; } =20 - tcg_gen_insn_start(pc_next, 0); + tcg_gen_insn_start(pc_next, 0, 0); ctx->insn_start_updated =3D false; } =20 --=20 2.45.0 From nobody Thu Nov 14 04:04:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185467; cv=none; d=zohomail.com; s=zohoarc; b=HHd9/QimR/nKAuMMoGux7Gd8jUGBgUJGu3/rZZO/pJR3yD7OTQAjUgJB4a1Dq/Sr2eKqLR29HCQ1YpdgVKAJNlynfsLgmA2mB0SHXDzSgeMMse66DYdI2bSwGAZ1Htoan8ITinPx6rGo77FCEMcJBV2GBsZsooHLv8cwfD6wuIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185467; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rSoL3SXlNF/tYJc6qw9RykMfpe2L0Nqr6O9wZWAdkWA=; b=jC/kDHs5HpXylAUCiaz+8c9pUAm2oaUCFmYIl8K0UFRCDi0Wh32mWzc8W1xexrAAtiaMIe6f2w6rv/1MKqFLstZVCSoV1+iX/10RA7J+tpwX2lHk0RzWBXmTi3m6iCUJR5Zvi1Iw2Qx4xHvgFzx1f+jKt4BiUzh64Hiwdao4jrM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185467256188.6027054578982; Thu, 12 Sep 2024 16:57:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdM-0005y2-9z; Thu, 12 Sep 2024 19:53:56 -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 1sotdH-0005eE-Fr for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:51 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotdD-0008CI-UQ for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:51 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-7d666fb3fb9so802972a12.0 for ; Thu, 12 Sep 2024 16:53:47 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185225; x=1726790025; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rSoL3SXlNF/tYJc6qw9RykMfpe2L0Nqr6O9wZWAdkWA=; b=Y86YbwPSHIoL44NSfXvhRE7xpcKOnXgnY+3D0w7Nz513OLcGAuJzV/aX4wB31GLHUf WW+1ZxddmQQZtMa1cqY11X2KKhmCamMJaxcUjtJxGH+pDpYlXCEZnsQsbtUA5bZ/pifX RiRo0GiG/P/Qymwf9LlroPORIO6+5vVOkWTvkYiQGmJYCN10HP5k1WsNB3RXRm1Ht/4U YhGnP5sWvBfZPVvqUTLm3xaDb6/G4VBtFpBD/+6Y9s6SFVuTm1YESxAqjyduuMu33hJ+ 2veZJRfdZqofgErZ0h5k9gg+hTcOjM3JJ8KqvqANJZy7+5RL3hXWM3kLQJcFbXTnkTz7 /ocw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185225; x=1726790025; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rSoL3SXlNF/tYJc6qw9RykMfpe2L0Nqr6O9wZWAdkWA=; b=cQE0b2hAoA1WXu/Rhw6HLs7FUhC9q6mUGZfjEfywZtWOWJ4RfmVuvG0XJrQAvzgvG7 WyX7EJ/aph1c17z7eUIc2D3hqqbBspmXaM39WBca2SFLANAPQo3YO16Bk2zCwbW6gIMh GXvoQAV8r/NRJnW65GYxNUifTkEtgpNn1z1uE1pPN7rSTbectPRNp1Abcz1LB25gPegp PCxJoWLmPFQhZugeFAHfzohO9HUjdECoO+2Mvko7ZPlQEu/0E7SVHnM5woJmSIEEbx2G zMZjVVR+TQQfHGzaZeZ7CZH0nmoMSEy99YgaXufDmMTalfYn8vNLTsYznuvZFLhGZQHo 7Fgg== X-Forwarded-Encrypted: i=1; AJvYcCVIMbUbAkddjEgNv++yOFyh+DNBgxvv2qBAXtVJmtSb+UlgRtcr7D+CvM9gt6DFjIiwg6WMRs2qCBwX@nongnu.org X-Gm-Message-State: AOJu0YxB/nISWIReyz/nYPJzGsMyg17pzgLkV+BYJ+Hu4y1PFA8vQca4 +oEmOqysCXerBNknSxmqlZJxkMMQEXtEBGJlNHGN6o8kTz9ik4TRrjlg+9x3lJY= X-Google-Smtp-Source: AGHT+IHeEidIL5lXYmJh78kVu+XB5RW/AP46nLguTzyK7fpnMmyoik7W3TeEBXDB9adliEav4XBc+Q== X-Received: by 2002:a05:6a20:c6ce:b0:1cf:6d67:fe55 with SMTP id adf61e73a8af0-1cf75599409mr7292717637.5.1726185225269; Thu, 12 Sep 2024 16:53:45 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 15/20] target/riscv: update `decode_save_opc` to store extra word2 Date: Thu, 12 Sep 2024 16:53:15 -0700 Message-ID: <20240912235320.3768582-16-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=debug@rivosinc.com; helo=mail-pg1-x535.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185469531116600 Content-Type: text/plain; charset="utf-8" Extra word 2 is stored during tcg compile and `decode_save_opc` needs additional argument in order to pass the value. This will be used during unwind to get extra information about instruction like how to massage exceptions. Updated all callsites as well. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/594 Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/insn_trans/trans_privileged.c.inc | 8 ++++---- target/riscv/insn_trans/trans_rva.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvd.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvf.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvh.c.inc | 8 ++++---- target/riscv/insn_trans/trans_rvi.c.inc | 6 +++--- target/riscv/insn_trans/trans_rvvk.c.inc | 10 +++++----- target/riscv/insn_trans/trans_rvzacas.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvzfh.c.inc | 4 ++-- target/riscv/insn_trans/trans_svinval.c.inc | 6 +++--- target/riscv/translate.c | 11 ++++++----- 11 files changed, 35 insertions(+), 34 deletions(-) diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/= insn_trans/trans_privileged.c.inc index bc5263a4e0..ecd3b8b2c9 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -78,7 +78,7 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) { #ifndef CONFIG_USER_ONLY if (has_ext(ctx, RVS)) { - decode_save_opc(ctx); + decode_save_opc(ctx, 0); translator_io_start(&ctx->base); gen_helper_sret(cpu_pc, tcg_env); exit_tb(ctx); /* no chaining */ @@ -95,7 +95,7 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) static bool trans_mret(DisasContext *ctx, arg_mret *a) { #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); translator_io_start(&ctx->base); gen_helper_mret(cpu_pc, tcg_env); exit_tb(ctx); /* no chaining */ @@ -109,7 +109,7 @@ static bool trans_mret(DisasContext *ctx, arg_mret *a) static bool trans_wfi(DisasContext *ctx, arg_wfi *a) { #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_update_pc(ctx, ctx->cur_insn_len); gen_helper_wfi(tcg_env); return true; @@ -121,7 +121,7 @@ static bool trans_wfi(DisasContext *ctx, arg_wfi *a) static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a) { #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_tlb_flush(tcg_env); return true; #endif diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_tr= ans/trans_rva.c.inc index 39bbf60f3c..9cf3ae8019 100644 --- a/target/riscv/insn_trans/trans_rva.c.inc +++ b/target/riscv/insn_trans/trans_rva.c.inc @@ -34,7 +34,7 @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemO= p mop) { TCGv src1; =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); src1 =3D get_address(ctx, a->rs1, 0); if (a->rl) { tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); @@ -61,7 +61,7 @@ static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemO= p mop) TCGLabel *l1 =3D gen_new_label(); TCGLabel *l2 =3D gen_new_label(); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); src1 =3D get_address(ctx, a->rs1, 0); tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1); =20 diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_tr= ans/trans_rvd.c.inc index 8a46124f98..30883ea37c 100644 --- a/target/riscv/insn_trans/trans_rvd.c.inc +++ b/target/riscv/insn_trans/trans_rvd.c.inc @@ -61,7 +61,7 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a) memop |=3D MO_ATOM_IFALIGN; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); tcg_gen_qemu_ld_i64(cpu_fpr[a->rd], addr, ctx->mem_idx, memop); =20 @@ -85,7 +85,7 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a) memop |=3D MO_ATOM_IFALIGN; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, memop); return true; diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_tr= ans/trans_rvf.c.inc index 0222a728df..ed73afe089 100644 --- a/target/riscv/insn_trans/trans_rvf.c.inc +++ b/target/riscv/insn_trans/trans_rvf.c.inc @@ -52,7 +52,7 @@ static bool trans_flw(DisasContext *ctx, arg_flw *a) memop |=3D MO_ATOM_WITHIN16; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); dest =3D cpu_fpr[a->rd]; tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, memop); @@ -74,7 +74,7 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a) memop |=3D MO_ATOM_WITHIN16; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, memop); return true; diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_tr= ans/trans_rvh.c.inc index aa9d41c18c..03c6694430 100644 --- a/target/riscv/insn_trans/trans_rvh.c.inc +++ b/target/riscv/insn_trans/trans_rvh.c.inc @@ -44,7 +44,7 @@ static bool do_hlv(DisasContext *ctx, arg_r2 *a, TCGv dest =3D dest_gpr(ctx, a->rd); TCGv addr =3D get_gpr(ctx, a->rs1, EXT_NONE); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); func(dest, tcg_env, addr); gen_set_gpr(ctx, a->rd, dest); return true; @@ -56,7 +56,7 @@ static bool do_hsv(DisasContext *ctx, arg_r2_s *a, TCGv addr =3D get_gpr(ctx, a->rs1, EXT_NONE); TCGv data =3D get_gpr(ctx, a->rs2, EXT_NONE); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); func(tcg_env, addr, data); return true; } @@ -147,7 +147,7 @@ static bool trans_hfence_gvma(DisasContext *ctx, arg_sf= ence_vma *a) { REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_hyp_gvma_tlb_flush(tcg_env); return true; #endif @@ -158,7 +158,7 @@ static bool trans_hfence_vvma(DisasContext *ctx, arg_sf= ence_vma *a) { REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_hyp_tlb_flush(tcg_env); return true; #endif diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index 638fc0fb7b..96c218a9d7 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -326,7 +326,7 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemO= p memop) if (ctx->cfg_ptr->ext_zama16b) { memop |=3D MO_ATOM_WITHIN16; } - decode_save_opc(ctx); + decode_save_opc(ctx, 0); if (get_xl(ctx) =3D=3D MXL_RV128) { out =3D gen_load_i128(ctx, a, memop); } else { @@ -427,7 +427,7 @@ static bool gen_store(DisasContext *ctx, arg_sb *a, Mem= Op memop) if (ctx->cfg_ptr->ext_zama16b) { memop |=3D MO_ATOM_WITHIN16; } - decode_save_opc(ctx); + decode_save_opc(ctx, 0); if (get_xl(ctx) =3D=3D MXL_RV128) { return gen_store_i128(ctx, a, memop); } else { @@ -889,7 +889,7 @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_= i *a) static bool do_csr_post(DisasContext *ctx) { /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ - decode_save_opc(ctx); + decode_save_opc(ctx, 0); /* We may have changed important cpu state -- exit to main loop. */ gen_update_pc(ctx, ctx->cur_insn_len); exit_tb(ctx); diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_t= rans/trans_rvvk.c.inc index ae1f40174a..27bf3f0b68 100644 --- a/target/riscv/insn_trans/trans_rvvk.c.inc +++ b/target/riscv/insn_trans/trans_rvvk.c.inc @@ -249,7 +249,7 @@ GEN_OPIVI_WIDEN_TRANS(vwsll_vi, IMM_ZX, vwsll_vx, vwsll= _vx_check) = \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { = \ /* save opcode for unwinding in case we throw an exception= */ \ - decode_save_opc(s); = \ + decode_save_opc(s, 0); = \ egs =3D tcg_constant_i32(EGS); = \ gen_helper_egs_check(egs, tcg_env); = \ } = \ @@ -322,7 +322,7 @@ GEN_V_UNMASKED_TRANS(vaesem_vs, vaes_check_vs, ZVKNED_E= GS) = \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { = \ /* save opcode for unwinding in case we throw an exception= */ \ - decode_save_opc(s); = \ + decode_save_opc(s, 0); = \ egs =3D tcg_constant_i32(EGS); = \ gen_helper_egs_check(egs, tcg_env); = \ } = \ @@ -389,7 +389,7 @@ GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED= _EGS) = \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { = \ /* save opcode for unwinding in case we throw an exception= */ \ - decode_save_opc(s); = \ + decode_save_opc(s, 0); = \ egs =3D tcg_constant_i32(EGS); = \ gen_helper_egs_check(egs, tcg_env); = \ } = \ @@ -440,7 +440,7 @@ static bool trans_vsha2cl_vv(DisasContext *s, arg_rmrr = *a) =20 if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { /* save opcode for unwinding in case we throw an exception */ - decode_save_opc(s); + decode_save_opc(s, 0); egs =3D tcg_constant_i32(ZVKNH_EGS); gen_helper_egs_check(egs, tcg_env); } @@ -471,7 +471,7 @@ static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr = *a) =20 if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { /* save opcode for unwinding in case we throw an exception */ - decode_save_opc(s); + decode_save_opc(s, 0); egs =3D tcg_constant_i32(ZVKNH_EGS); gen_helper_egs_check(egs, tcg_env); } diff --git a/target/riscv/insn_trans/trans_rvzacas.c.inc b/target/riscv/ins= n_trans/trans_rvzacas.c.inc index fcced99fc7..15e688a033 100644 --- a/target/riscv/insn_trans/trans_rvzacas.c.inc +++ b/target/riscv/insn_trans/trans_rvzacas.c.inc @@ -76,7 +76,7 @@ static bool gen_cmpxchg64(DisasContext *ctx, arg_atomic *= a, MemOp mop) TCGv src1 =3D get_address(ctx, a->rs1, 0); TCGv_i64 src2 =3D get_gpr_pair(ctx, a->rs2); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); tcg_gen_atomic_cmpxchg_i64(dest, src1, dest, src2, ctx->mem_idx, mop); =20 gen_set_gpr_pair(ctx, a->rd, dest); @@ -121,7 +121,7 @@ static bool trans_amocas_q(DisasContext *ctx, arg_amoca= s_q *a) =20 tcg_gen_concat_i64_i128(src2, src2l, src2h); tcg_gen_concat_i64_i128(dest, destl, desth); - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); tcg_gen_atomic_cmpxchg_i128(dest, src1, dest, src2, ctx->mem_idx, (MO_ALIGN | MO_TEUO)); =20 diff --git a/target/riscv/insn_trans/trans_rvzfh.c.inc b/target/riscv/insn_= trans/trans_rvzfh.c.inc index 1eb458b491..bece48e600 100644 --- a/target/riscv/insn_trans/trans_rvzfh.c.inc +++ b/target/riscv/insn_trans/trans_rvzfh.c.inc @@ -48,7 +48,7 @@ static bool trans_flh(DisasContext *ctx, arg_flh *a) REQUIRE_FPU; REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); t0 =3D get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) { TCGv temp =3D tcg_temp_new(); @@ -71,7 +71,7 @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a) REQUIRE_FPU; REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); t0 =3D get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) { TCGv temp =3D tcg_temp_new(); diff --git a/target/riscv/insn_trans/trans_svinval.c.inc b/target/riscv/ins= n_trans/trans_svinval.c.inc index 0f692a1088..a06c3b214f 100644 --- a/target/riscv/insn_trans/trans_svinval.c.inc +++ b/target/riscv/insn_trans/trans_svinval.c.inc @@ -28,7 +28,7 @@ static bool trans_sinval_vma(DisasContext *ctx, arg_sinva= l_vma *a) /* Do the same as sfence.vma currently */ REQUIRE_EXT(ctx, RVS); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_tlb_flush(tcg_env); return true; #endif @@ -57,7 +57,7 @@ static bool trans_hinval_vvma(DisasContext *ctx, arg_hinv= al_vvma *a) /* Do the same as hfence.vvma currently */ REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_hyp_tlb_flush(tcg_env); return true; #endif @@ -70,7 +70,7 @@ static bool trans_hinval_gvma(DisasContext *ctx, arg_hinv= al_gvma *a) /* Do the same as hfence.gvma currently */ REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_hyp_gvma_tlb_flush(tcg_env); return true; #endif diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 0322597bf6..0ca10818f3 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -209,11 +209,12 @@ static void gen_check_nanbox_s(TCGv_i64 out, TCGv_i64= in) tcg_gen_movcond_i64(TCG_COND_GEU, out, in, t_max, in, t_nan); } =20 -static void decode_save_opc(DisasContext *ctx) +static void decode_save_opc(DisasContext *ctx, target_ulong excp_uw2) { assert(!ctx->insn_start_updated); ctx->insn_start_updated =3D true; tcg_set_insn_start_param(ctx->base.insn_start, 1, ctx->opcode); + tcg_set_insn_start_param(ctx->base.insn_start, 2, excp_uw2); } =20 static void gen_pc_plus_diff(TCGv target, DisasContext *ctx, @@ -699,7 +700,7 @@ static void gen_set_rm(DisasContext *ctx, int rm) } =20 /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_set_rounding_mode(tcg_env, tcg_constant_i32(rm)); } =20 @@ -712,7 +713,7 @@ static void gen_set_rm_chkfrm(DisasContext *ctx, int rm) ctx->frm_valid =3D true; =20 /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_set_rounding_mode_chkfrm(tcg_env, tcg_constant_i32(rm)); } =20 @@ -1096,7 +1097,7 @@ static bool gen_amo(DisasContext *ctx, arg_atomic *a, mop |=3D MO_ALIGN; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); src1 =3D get_address(ctx, a->rs1, 0); func(dest, src1, src2, ctx->mem_idx, mop); =20 @@ -1110,7 +1111,7 @@ static bool gen_cmpxchg(DisasContext *ctx, arg_atomic= *a, MemOp mop) TCGv src1 =3D get_address(ctx, a->rs1, 0); TCGv src2 =3D get_gpr(ctx, a->rs2, EXT_NONE); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); tcg_gen_atomic_cmpxchg_tl(dest, src1, dest, src2, ctx->mem_idx, mop); =20 gen_set_gpr(ctx, a->rd, dest); --=20 2.45.0 From nobody Thu Nov 14 04:04:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185292; cv=none; d=zohomail.com; s=zohoarc; b=ee1azH/6hcMn4yLh6GxgrPTwmGVKzJKOflQOK9+csyMCvH+fLKWyW/yGnLz7LC0ADWd3SHQsD5Aeab1f264qZyapcnMzIdUQD7pa0AiXay3qWI7nNb4zvoVZ8fiCONXn9ppzzQlDDTaZxh34Eft+Zvc/X++aN6w2zEQh0TQ+B9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185292; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KJsIEp3dUpjenXL1nJorQgXYMQj8ivUVxFHUoOeY65U=; b=mo9HVEWNRjMF3YERsyHr/CU8TxpkBQyrO8Pvc9mB6aslwpUeqfOliWCBke1/dZtAzZCu83vfA9o87KN7P8EPv7R3cFBjkh+bWdKDR2KefW9tl8c+oIB3sKgoJz7aZKInKMPX9B7MndqynzAJ22RihTSrouvK7g9pdf7bLKACPtc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185292081494.6270986444973; Thu, 12 Sep 2024 16:54:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdJ-0005kV-LN; Thu, 12 Sep 2024 19:53:53 -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 1sotdG-0005aH-JT for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:50 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotdD-0008CN-UJ for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:49 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7191ee537cbso1194057b3a.2 for ; Thu, 12 Sep 2024 16:53:47 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185227; x=1726790027; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KJsIEp3dUpjenXL1nJorQgXYMQj8ivUVxFHUoOeY65U=; b=HZzym6JPXfucwgbF4wKj3R8Xfrkh89dVX5mKbNDa0pGKvwWZAQ8cKKIpuU+b6ggu9z TEweRGJeMrBcQTpTvR8GIU/17I72LdElVm2r0RMIWT2vT+EkYq++8yAJaOodZtEDpj6O 3ULNENYDKw98MWTjZ1R/nD3xDVXkmU5vzOeuzU2g9hI6GDu9bt2OGdFF3CuBbb9e4+ss +cNnko3+bTnEgNoXCDZhoPEr+/gwNUCzoHCTPQJw7Mi6MmBTEjXMw0wA+AGTswVTKA5N kRbRgW9PxplhGUBrs6lxAzckqp3IgfoL3nbZJK2HUDBUhVDMOTbK5xEOqHtijtOcJDlK o/gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185227; x=1726790027; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KJsIEp3dUpjenXL1nJorQgXYMQj8ivUVxFHUoOeY65U=; b=Mfv+S6m2rQUJ7bJvHyNBkCwQfjCVrFAqHoGTxoVdz535Kb+EFXFbgyjjupMh0FV2Ds jabtPLIECTdDWNAayhEFLa1b3TpPL/A9+MnWDG9rCiHOv+Hrbmd87PVs4EkBHKSwlKV1 utPkHXzkGPr8QTzuFGxjFsCTS9/AaKMgomuu0WDXezMtU5qwnESjtWZPDkyqfzrYRZvp fhqLSBYx3FHRG31JH0Z+gaappMbohTlcLobux3Xp3fcjnMNGcVuTsd3Li+P6ZgF4eGkn pZmbGCz6yJ83mAyZQ75/GVM+gAKDfeUN3IOcR0mMyva6K+v2HF2zn0xGBiK8txUnu9Rn sv3Q== X-Forwarded-Encrypted: i=1; AJvYcCWWg7oxfbJsBxtrnxun60QB3OdYL1eBv4FL/Yzhse+329yS9iEUTyp7NFEHIhSHoCMjQDMRtdoUr78M@nongnu.org X-Gm-Message-State: AOJu0YwW+Oy3RoZIKsrsV39sgXs2iHCweYEHjXenZyFJ536PU19n6qp9 hph+xmo9a8GATo2MRRKeFrNVfKbGso5HahXgGr7IUxErh/HRg9oQvjrNvOLVOGQ= X-Google-Smtp-Source: AGHT+IGlUICmHvF8MprCA45pNP0OzLvVMAMOXToHsDLGKgKX53vQxcYFgxRiUvTiIe5fxzDZS3P7Sg== X-Received: by 2002:a05:6a20:8428:b0:1cf:ff65:3680 with SMTP id adf61e73a8af0-1cfff653b08mr5297121637.6.1726185226617; Thu, 12 Sep 2024 16:53:46 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Alistair Francis Subject: [PATCH v14 16/20] target/riscv: implement zicfiss instructions Date: Thu, 12 Sep 2024 16:53:16 -0700 Message-ID: <20240912235320.3768582-17-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=debug@rivosinc.com; helo=mail-pf1-x436.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185294755116600 Content-Type: text/plain; charset="utf-8" zicfiss has following instructions - sspopchk: pops a value from shadow stack and compares with x1/x5. If they dont match, reports a sw check exception with tval =3D 3. - sspush: pushes value in x1/x5 on shadow stack - ssrdp: reads current shadow stack - ssamoswap: swaps contents of shadow stack atomically sspopchk/sspush/ssrdp default to zimop if zimop implemented and SSE=3D0 If SSE=3D0, ssamoswap is illegal instruction exception. This patch implements shadow stack operations for qemu-user and shadow stack is not protected. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Alistair Francis --- target/riscv/cpu_bits.h | 2 + target/riscv/insn32.decode | 21 +++- target/riscv/insn_trans/trans_rvzicfiss.c.inc | 114 ++++++++++++++++++ target/riscv/translate.c | 5 + 4 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 target/riscv/insn_trans/trans_rvzicfiss.c.inc diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 8223beaceb..385a2c67c2 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -697,6 +697,8 @@ typedef enum RISCVException { =20 /* zicfilp defines lp violation results in sw check with tval =3D 2*/ #define RISCV_EXCP_SW_CHECK_FCFI_TVAL 2 +/* zicfiss defines ss violation results in sw check with tval =3D 3*/ +#define RISCV_EXCP_SW_CHECK_BCFI_TVAL 3 =20 #define RISCV_EXCP_INT_FLAG 0x80000000 #define RISCV_EXCP_INT_MASK 0x7fffffff diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index 27108b992b..e9139ec1b9 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -246,6 +246,7 @@ remud 0000001 ..... ..... 111 ..... 1111011 @r lr_w 00010 . . 00000 ..... 010 ..... 0101111 @atom_ld sc_w 00011 . . ..... ..... 010 ..... 0101111 @atom_st amoswap_w 00001 . . ..... ..... 010 ..... 0101111 @atom_st +ssamoswap_w 01001 . . ..... ..... 010 ..... 0101111 @atom_st amoadd_w 00000 . . ..... ..... 010 ..... 0101111 @atom_st amoxor_w 00100 . . ..... ..... 010 ..... 0101111 @atom_st amoand_w 01100 . . ..... ..... 010 ..... 0101111 @atom_st @@ -259,6 +260,7 @@ amomaxu_w 11100 . . ..... ..... 010 ..... 0101111 @ato= m_st lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st +ssamoswap_d 01001 . . ..... ..... 011 ..... 0101111 @atom_st amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st @@ -1022,8 +1024,23 @@ amocas_d 00101 . . ..... ..... 011 ..... 0101111 = @atom_st amocas_q 00101 . . ..... ..... 100 ..... 0101111 @atom_st =20 # *** Zimop may-be-operation extension *** -mop_r_n 1 . 00 .. 0111 .. ..... 100 ..... 1110011 @mop5 -mop_rr_n 1 . 00 .. 1 ..... ..... 100 ..... 1110011 @mop3 +{ + # zicfiss instructions carved out of mop.r + [ + ssrdp 1100110 11100 00000 100 rd:5 1110011 + sspopchk 1100110 11100 00001 100 00000 1110011 &r2 rs1=3D1 rd=3D0 + sspopchk 1100110 11100 00101 100 00000 1110011 &r2 rs1=3D5 rd=3D0 + ] + mop_r_n 1 . 00 .. 0111 .. ..... 100 ..... 1110011 @mop5 +} +{ + # zicfiss instruction carved out of mop.rr + [ + sspush 1100111 00001 00000 100 00000 1110011 &r2_s rs2=3D1 rs1=3D0 + sspush 1100111 00101 00000 100 00000 1110011 &r2_s rs2=3D5 rs1=3D0 + ] + mop_rr_n 1 . 00 .. 1 ..... ..... 100 ..... 1110011 @mop3 +} =20 # *** Zabhb Standard Extension *** amoswap_b 00001 . . ..... ..... 000 ..... 0101111 @atom_st diff --git a/target/riscv/insn_trans/trans_rvzicfiss.c.inc b/target/riscv/i= nsn_trans/trans_rvzicfiss.c.inc new file mode 100644 index 0000000000..e3ebc4977c --- /dev/null +++ b/target/riscv/insn_trans/trans_rvzicfiss.c.inc @@ -0,0 +1,114 @@ +/* + * RISC-V translation routines for the Control-Flow Integrity Extension + * + * Copyright (c) 2024 Rivos Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ +static bool trans_sspopchk(DisasContext *ctx, arg_sspopchk *a) +{ + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv addr =3D tcg_temp_new(); + TCGLabel *skip =3D gen_new_label(); + uint32_t tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? 8 : 4; + TCGv data =3D tcg_temp_new(); + tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + tcg_gen_qemu_ld_tl(data, addr, SS_MMU_INDEX(ctx), + mxl_memop(ctx) | MO_ALIGN); + TCGv rs1 =3D get_gpr(ctx, a->rs1, EXT_NONE); + tcg_gen_brcond_tl(TCG_COND_EQ, data, rs1, skip); + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_BCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + gen_set_label(skip); + tcg_gen_addi_tl(addr, addr, tmp); + tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + + return true; +} + +static bool trans_sspush(DisasContext *ctx, arg_sspush *a) +{ + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv addr =3D tcg_temp_new(); + int tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? -8 : -4; + TCGv data =3D get_gpr(ctx, a->rs2, EXT_NONE); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_addi_tl(addr, addr, tmp); + tcg_gen_qemu_st_tl(data, addr, SS_MMU_INDEX(ctx), + mxl_memop(ctx) | MO_ALIGN); + tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + + return true; +} + +static bool trans_ssrdp(DisasContext *ctx, arg_ssrdp *a) +{ + if (!ctx->bcfi_enabled || a->rd =3D=3D 0) { + return false; + } + + TCGv dest =3D dest_gpr(ctx, a->rd); + tcg_gen_ld_tl(dest, tcg_env, offsetof(CPURISCVState, ssp)); + gen_set_gpr(ctx, a->rd, dest); + + return true; +} + +static bool trans_ssamoswap_w(DisasContext *ctx, arg_amoswap_w *a) +{ + REQUIRE_A_OR_ZAAMO(ctx); + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv dest =3D dest_gpr(ctx, a->rd); + TCGv src1, src2 =3D get_gpr(ctx, a->rs2, EXT_NONE); + + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + src1 =3D get_address(ctx, a->rs1, 0); + + tcg_gen_atomic_xchg_tl(dest, src1, src2, SS_MMU_INDEX(ctx), + (MO_ALIGN | MO_TESL)); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_ssamoswap_d(DisasContext *ctx, arg_amoswap_w *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_A_OR_ZAAMO(ctx); + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv dest =3D dest_gpr(ctx, a->rd); + TCGv src1, src2 =3D get_gpr(ctx, a->rs2, EXT_NONE); + + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + src1 =3D get_address(ctx, a->rs1, 0); + + tcg_gen_atomic_xchg_tl(dest, src1, src2, SS_MMU_INDEX(ctx), + (MO_ALIGN | MO_TESQ)); + gen_set_gpr(ctx, a->rd, dest); + return true; +} diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 0ca10818f3..bccaf8e89a 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -144,6 +144,8 @@ static inline bool has_ext(DisasContext *ctx, uint32_t = ext) #define get_address_xl(ctx) ((ctx)->address_xl) #endif =20 +#define mxl_memop(ctx) ((get_xl(ctx) + 1) | MO_TE) + /* The word size for this machine mode. */ static inline int __attribute__((unused)) get_xlen(DisasContext *ctx) { @@ -1127,6 +1129,8 @@ static uint32_t opcode_at(DisasContextBase *dcbase, t= arget_ulong pc) return translator_ldl(env, &ctx->base, pc); } =20 +#define SS_MMU_INDEX(ctx) (ctx->mem_idx | MMU_IDX_SS_WRITE) + /* Include insn module translation function */ #include "insn_trans/trans_rvi.c.inc" #include "insn_trans/trans_rvm.c.inc" @@ -1157,6 +1161,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, t= arget_ulong pc) #include "decode-insn16.c.inc" #include "insn_trans/trans_rvzce.c.inc" #include "insn_trans/trans_rvzcmop.c.inc" +#include "insn_trans/trans_rvzicfiss.c.inc" =20 /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" --=20 2.45.0 From nobody Thu Nov 14 04:04:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185494; cv=none; d=zohomail.com; s=zohoarc; b=SHPIkAdUxd0JIJHEGd784+jd3EqN7IRvSEFkuesa13ehELY8nwXJkvz+R4hOEjpVe0xlSG1b+InH+AG1vxq/2qMURpEQA/THD68eog8+Lv+Su1VGuk1zSFXRJCJzzhSllUYGW4Ud48CMkK1eFVkcTfrxLG90q+bFhbd4OGSDw4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185494; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M7nGUkC8AoqQkvdlZ/4VsRGMOV3aEFYCGC3UA04clbY=; b=CX0sSyw4W524z7poQpNVaIzMalucUq9ewWLiroyuCiYBZe9o7LBetU+wiJH5EEjLNpaeu5dJt9POeReN5qlYqyiMHGnYTrKxbsGgevTCKPHhaVe/S99guM5Pwjz1/hwD61lCKSf+qeR+BTDxBlrR53v8N2F4K1IbdCQ5g9yUChE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185494805706.6691468416795; Thu, 12 Sep 2024 16:58:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdK-0005rA-Hi; Thu, 12 Sep 2024 19:53:54 -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 1sotdH-0005c6-1I for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:51 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotdF-0008Cj-GY for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:50 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-7191df6b5f5so1175296b3a.0 for ; Thu, 12 Sep 2024 16:53:49 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185228; x=1726790028; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M7nGUkC8AoqQkvdlZ/4VsRGMOV3aEFYCGC3UA04clbY=; b=IIt3uC6ifhgIRSZctlsje96rxW7rrPQzHTrl+Ff7++bOC8axZSG9oIpN8q4zY3AoTc imusBUDP2lDXKxXUfZyDRFqYt73h0WTKLXzBSU+dDE6oQhhdz3JQW6eSiRQaE+kDfxh3 NKICLoBBkzv4hzAaekR4RsQOZldh8cjxlihaKO1sn9Dqas+hdyv/SQk5gOW8ZhoX4U4S qj3+zZ4jtg+q01lkuqyZCWJMC5ZeQIRgJktufKGw5aZoZHkss7aOzwt8WOiU8Gk/lJ+h e7dxyP8iCxKDICrv9BmlrM/aSQOP4pxxAvjjjbbExQ1zuOl7VSMGJAzinvLMZUG34Gl4 wjBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185228; x=1726790028; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M7nGUkC8AoqQkvdlZ/4VsRGMOV3aEFYCGC3UA04clbY=; b=bgrO1POav+0IthuYX3HUoyUBpkxgHKJ/FsPDzBPrNGJN2qFUQEEEo1gvHHlWDeHnfy iv32oAzsXCnChzrXCsKYX4fgAKrjOmnKJWGQnagTIHCDLfA2/qscFGybEfPhTSJ0D9EL vtu17QE5xxVQv/AEWUlCkmI8yu1EJD90ymagNMKGfxLtfQITHjN2HsjlnNXVXoihXO1E YiLWul4T8vgP+hwPdQngW5ngZHE3Acgr1JkacwNN82e5XzCe8YCHVWMEYr6ExxbIu5RS rte4rysRiIxBViJepmAQxSkilQINH5ztJfHGNrP46yFADLV7NCHU/9wdWS9tFqln1V2D S4kw== X-Forwarded-Encrypted: i=1; AJvYcCUn9dSj3yrZIo1gOocSyTYVWHE3dFWS382BsBKOStLiiyJarA/pqvYl71JDWMuj+O4eUmDlGtI2IuM5@nongnu.org X-Gm-Message-State: AOJu0Yyk4v840W+kXhMNr3aC+6VqVT+ZRDqL3J4Kwjx+JDTB9loOpcLj uPrrMZ8j2h7wW/IB8QkH6royeOTGN+gIHPJrzvX4y2JahZXk0TOqGHVpw93+VBs= X-Google-Smtp-Source: AGHT+IExiWNfKNLjn0iPglMO27St8rleP2T2e4jGVxAiasXFgViDBbyK80qHBEkWgtNQRizXshX0IQ== X-Received: by 2002:a05:6a00:1248:b0:70c:f1fa:d7bf with SMTP id d2e1a72fcca58-71926065246mr6561368b3a.4.1726185228106; Thu, 12 Sep 2024 16:53:48 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v14 17/20] target/riscv: compressed encodings for sspush and sspopchk Date: Thu, 12 Sep 2024 16:53:17 -0700 Message-ID: <20240912235320.3768582-18-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42a.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185495466116600 Content-Type: text/plain; charset="utf-8" sspush/sspopchk have compressed encodings carved out of zcmops. compressed sspush is designated as c.mop.1 while compressed sspopchk is designated as c.mop.5. Note that c.sspush x1 exists while c.sspush x5 doesn't. Similarly c.sspopchk x5 exists while c.sspopchk x1 doesn't. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/insn16.decode | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/riscv/insn16.decode b/target/riscv/insn16.decode index 3953bcf82d..bf893d1c2e 100644 --- a/target/riscv/insn16.decode +++ b/target/riscv/insn16.decode @@ -140,6 +140,10 @@ sw 110 ... ... .. ... 00 @cs_w addi 000 . ..... ..... 01 @ci addi 010 . ..... ..... 01 @c_li { + # c.sspush x1 carving out of zcmops + sspush 011 0 00001 00000 01 &r2_s rs2=3D1 rs1=3D0 + # c.sspopchk x5 carving out of zcmops + sspopchk 011 0 00101 00000 01 &r2 rs1=3D5 rd=3D0 c_mop_n 011 0 0 n:3 1 00000 01 illegal 011 0 ----- 00000 01 # c.addi16sp and c.lui, RES nzimm= =3D0 addi 011 . 00010 ..... 01 @c_addi16sp --=20 2.45.0 From nobody Thu Nov 14 04:04:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185455; cv=none; d=zohomail.com; s=zohoarc; b=JCi5JLoJJelmmyuvxWr7Oz3AVFAJK4BDjrs/9boG0vQvLktZXNq/0BEzKtGkHioIe00gyueJk5G1GFG5jAbiQ0MW86r+nff6ahFCY/9W/eGdxGTohJgLNoZfcfx/e6WvVp2rcREcUpQk2IhyUgYrqenWBpedZCT7/5/bpg2gyn8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185455; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3TSRZRYfN0fde9td8T2Zgyxq8CzAPhtR30l69z8A4EM=; b=GMhcNm/gKK+nsJYBJ++khvyMfBTT+jCsHbBkc0SwZNsWxMPH2cs+M+6uE0/w6kkfoLrPS2dBKHCx+hGnBWEVmtJYfvgM7qfYGpM0W6KUhupkdfaOAgkTIerCk2d9W1/tibN8g0+xO2TEih9XILfySfkiZAm2m64VnE9N8GS5WoU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185455371942.8283357357986; Thu, 12 Sep 2024 16:57:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdN-00062A-8C; Thu, 12 Sep 2024 19:53:57 -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 1sotdI-0005iY-Ja for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:52 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotdG-0008D1-SI for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:52 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-718e11e4186so1409307b3a.2 for ; Thu, 12 Sep 2024 16:53:50 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185229; x=1726790029; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3TSRZRYfN0fde9td8T2Zgyxq8CzAPhtR30l69z8A4EM=; b=D0Agr4Qz8LWXCFpYC8ZHH/THyXl6sAaD65KRSM1cCxZCKfreCSjSf1FAm2we6wictg B3q344yD8jiis74Z0RTjl69kKae1q/p+SJmdwbgqUCe99/YLNsPyaR//RiG+66ugWJ3J 0RsSu7+re/BVaLI18/cC3nQpp8FW2KBdO8J43dO9D6c13tYV4wP3x/lmbnCi38ayfY5Y KynOa4Nc6IJt3udbNQo1NNAfsnxpdTdlPaFNuPGtlOCklUKomnbRuaeqs3wp9mNxVK7J dcEPsR+eIWAevvz4SHtKFvoIGXNXIRnkba9PztWD8opaoHQZAsCRiFmd7v8QVGuBovA0 8ohw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185229; x=1726790029; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3TSRZRYfN0fde9td8T2Zgyxq8CzAPhtR30l69z8A4EM=; b=f7Xat6NcnRZOgi78eHyMdLNZoJBFAspnFByWvnxR3I2PTsGa0YkRJQIYczsfvsGUII fwNKcA5PXdzqQM0Mg70r3tOVBZ2zB9yuqvVL32LVaUCQijhlzuO+JZMQTnruIFY3I6aF dFLXOqtXGkIXpPJOLTJPeifnu92C8SNb7eJulYMGwBNKDG9iwYinl25bnOl2g9z1aCVO IgYsAszybO0TrJGEN4CqHcE7+SNGJdG7kCZBYMEQGxA+bhauEnmtaRxY5G8Bl5wnrmRh JSltzQQeCmzzc5woILc9FLLdkZSB0wk/wncrzwlgNRWmLZmvRBwTfI59FTi7YYQJHFW6 xN4w== X-Forwarded-Encrypted: i=1; AJvYcCVZPHkC039lLfany9F2Vl3f+Br5oaTc6+ixdVTYXCc76WhhUjhDjRuxziro5Tp/UUiY1UH6tUmOA0bi@nongnu.org X-Gm-Message-State: AOJu0YwHyhI7YjRC/MrTCNE0FG8xitDTArvVDQzHqXMeGigFJqWLl3vq Tvr/0A7+MPDQFpT1/GlT60Ee5uYWBHoKuJjX3aWxIaJ6Zpb0XR+x5jXBRJPCD+ERaRfHsxx1pUp V X-Google-Smtp-Source: AGHT+IH23JisdNoWYLW3pIlVmGpRDzxa0xKecKQJsAqLoTrw4g9+81325RmWHoJHJQIg0kzmlYdmKg== X-Received: by 2002:a05:6a21:648b:b0:1cf:20a7:ec4e with SMTP id adf61e73a8af0-1cf76358daemr6604671637.40.1726185229635; Thu, 12 Sep 2024 16:53:49 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Alistair Francis Subject: [PATCH v14 18/20] disas/riscv: enable disassembly for zicfiss instructions Date: Thu, 12 Sep 2024 16:53:18 -0700 Message-ID: <20240912235320.3768582-19-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=debug@rivosinc.com; helo=mail-pf1-x434.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185457378116600 Content-Type: text/plain; charset="utf-8" Enable disassembly for sspush, sspopchk, ssrdp & ssamoswap. Disasembly is only enabled if zimop and zicfiss ext is set to true. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 40 +++++++++++++++++++++++++++++++++++++++- disas/riscv.h | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas/riscv.c index 2942a5800f..0f9ecd8a14 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -977,6 +977,11 @@ typedef enum { rv_op_wrs_sto =3D 946, rv_op_wrs_nto =3D 947, rv_op_lpad =3D 948, + rv_op_sspush =3D 949, + rv_op_sspopchk =3D 950, + rv_op_ssrdp =3D 951, + rv_op_ssamoswap_w =3D 952, + rv_op_ssamoswap_d =3D 953, } rv_op; =20 /* register names */ @@ -2238,6 +2243,11 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "wrs.sto", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 }, { "wrs.nto", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 }, { "lpad", rv_codec_lp, rv_fmt_imm, NULL, 0, 0, 0 }, + { "sspush", rv_codec_r, rv_fmt_rs2, NULL, 0, 0, 0 }, + { "sspopchk", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 }, + { "ssrdp", rv_codec_r, rv_fmt_rd, NULL, 0, 0, 0 }, + { "ssamoswap.w", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, + { "ssamoswap.d", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, }; =20 /* CSR names */ @@ -2255,6 +2265,7 @@ static const char *csr_name(int csrno) case 0x0009: return "vxsat"; case 0x000a: return "vxrm"; case 0x000f: return "vcsr"; + case 0x0011: return "ssp"; case 0x0015: return "seed"; case 0x0017: return "jvt"; case 0x0040: return "uscratch"; @@ -3081,6 +3092,8 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa= isa) case 66: op =3D rv_op_amoor_w; break; case 67: op =3D rv_op_amoor_d; break; case 68: op =3D rv_op_amoor_q; break; + case 74: op =3D rv_op_ssamoswap_w; break; + case 75: op =3D rv_op_ssamoswap_d; break; case 96: op =3D rv_op_amoand_b; break; case 97: op =3D rv_op_amoand_h; break; case 98: op =3D rv_op_amoand_w; break; @@ -4034,7 +4047,7 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa= isa) case 3: op =3D rv_op_csrrc; break; case 4: if (dec->cfg->ext_zimop) { - int imm_mop5, imm_mop3; + int imm_mop5, imm_mop3, reg_num; if ((extract32(inst, 22, 10) & 0b1011001111) =3D=3D 0b1000000111) { imm_mop5 =3D deposit32(deposit32(extract32(inst, 2= 0, 2), @@ -4042,11 +4055,36 @@ static void decode_inst_opcode(rv_decode *dec, rv_i= sa isa) extract32(inst, 26,= 2)), 4, 1, extract32(inst, 30, 1)); op =3D rv_mop_r_0 + imm_mop5; + /* if zicfiss enabled and mop5 is shadow stack */ + if (dec->cfg->ext_zicfiss && + ((imm_mop5 & 0b11100) =3D=3D 0b11100)) { + /* rs1=3D0 means ssrdp */ + if ((inst & (0b011111 << 15)) =3D=3D 0) { + op =3D rv_op_ssrdp; + } + /* rd=3D0 means sspopchk */ + reg_num =3D (inst >> 15) & 0b011111; + if (((inst & (0b011111 << 7)) =3D=3D 0) && + ((reg_num =3D=3D 1) || (reg_num =3D=3D= 5))) { + op =3D rv_op_sspopchk; + } + } } else if ((extract32(inst, 25, 7) & 0b1011001) =3D=3D 0b1000001) { imm_mop3 =3D deposit32(extract32(inst, 26, 2), 2, 1, extract32(inst, 30, 1)); op =3D rv_mop_rr_0 + imm_mop3; + /* if zicfiss enabled and mop3 is shadow stack */ + if (dec->cfg->ext_zicfiss && + ((imm_mop3 & 0b111) =3D=3D 0b111)) { + /* rs1=3D0 and rd=3D0 means sspush */ + reg_num =3D (inst >> 20) & 0b011111; + if (((inst & (0b011111 << 15)) =3D=3D 0) && + ((inst & (0b011111 << 7)) =3D=3D 0) && + ((reg_num =3D=3D 1) || (reg_num =3D=3D= 5))) { + op =3D rv_op_sspush; + } + } } } break; diff --git a/disas/riscv.h b/disas/riscv.h index 1182457aff..4895c5a301 100644 --- a/disas/riscv.h +++ b/disas/riscv.h @@ -224,6 +224,7 @@ enum { =20 #define rv_fmt_none "O\t" #define rv_fmt_rs1 "O\t1" +#define rv_fmt_rs2 "O\t2" #define rv_fmt_offset "O\to" #define rv_fmt_pred_succ "O\tp,s" #define rv_fmt_rs1_rs2 "O\t1,2" --=20 2.45.0 From nobody Thu Nov 14 04:04:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185466; cv=none; d=zohomail.com; s=zohoarc; b=C9kQD8pmYGyylHgY+37xg3nMrh+gOolmY9z0hi/GmhTziKsulDYS3oXbHD0uZN6mzegAR/J0RY+/PWlbasMIFlKYuvDKGogZ44HZljGmiEfPujQBdeHrAJqfqsfSTCMDxacuBOdOnslPN9VHUiVRWBvWoXletJ9jjCq/tSurtq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185466; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/P67wf325xKMcU48G4zBDiTLVG8mpptFQ7OMFFPf2ww=; b=jphJ9utFhxGfL0jYpp9qwfGCFVGZPPbfcGu2WPYa9u1JlA5TTTnOlipB+oqcyIOLshPqdm4QY/kukq1kLdbkx3pE5v4Oht6L7unIiQIKX7rjdCJEXw+iaqVs7zRtbMgwksbkVFkSCZaidesqxAN2iddUEZbLtHB52q0HM3rRUKo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185466741623.0304462166359; Thu, 12 Sep 2024 16:57:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdK-0005s1-R9; Thu, 12 Sep 2024 19:53:54 -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 1sotdJ-0005nZ-P6 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:53 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotdI-0008Da-7Y for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:53 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-718e11e4186so1409326b3a.2 for ; Thu, 12 Sep 2024 16:53:51 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185231; x=1726790031; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/P67wf325xKMcU48G4zBDiTLVG8mpptFQ7OMFFPf2ww=; b=ymQRmh0537hibBJHyq1XQQyKJcPpsHKBS3H2Nd6322uW3q+U/7YbV0S5c/J6fkbvAy VEqERTSaTYp99KS59glUijvQ552C562OnO/kHwEZsW8yjcu9wjhFxUZQ4yuCQWIvR5OD YbJosY9NoaFjVzMhteB+TkCY1Qu3SWRA3c07qiPVVjr9g7qxliqjqJMOd1nUN1ZnzpRd Ulk39D0aBvwYiPcjLx3xk87STwU0lZ5BYtlHu1CkV87UpPEx4ZctxsXPrbyZ0p9a7S2U 1g22wkQOV+auYpiY2gdDLDdWTuyVWS2agTw34ZoHvNx49o2cXmpP32DGcmB/ak5H0njU q63g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185231; x=1726790031; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/P67wf325xKMcU48G4zBDiTLVG8mpptFQ7OMFFPf2ww=; b=YOaYM+T1pvNu/k+3FiJ4k8sUzPy66p3G7a1jrRzEG8DKHvQ1eFO8QSxDa7ZvXbsH+v lGHbq3tl2ldwDDH9Ep3Qg1z36RVlbhgfQh5BysXwWJSOVla3DGYjJeg2VMKulGMEKI/+ TCiWiyIhemwp7vY0MAlue1mYGq02V3Qpk8Zcw8AEljwCrms9gfRhPFFKoRV0V3NlYKhm QcQswywi0MxCAFAPGpeUwrSTWdsOJkKdDwvtYCZKo0+eCsquFKOO1TON53jFatBOfRKM fc8RCMh6Xnnr+AA2GuBfZczEhWuFF8L1PB4+XiAEUc+3etHOUy+U2WR7sQkWRO73jRpU fHJg== X-Forwarded-Encrypted: i=1; AJvYcCW0n5oeQyZX8bn2Pv+dvzfdsgRBeMJl9oS6JSaZrhQaqD90R2zxEmc0pErSq+rNFFkLWrz1pyzvjkgS@nongnu.org X-Gm-Message-State: AOJu0YzHEF4M0LdUK96Nxp6latUw/yICDSEXCYhXMmRcGX5Vo+UGvXyg kyB6+6P1J2e1jaATqbidXyRQ5c75XTQo7aAiki3+8AJLwFhv8rASBRPMORQSFxk= X-Google-Smtp-Source: AGHT+IGsHZRakxi+bmgmrkFBUBklKoyreF5dQIDQVKdit3k9wYLwnY37WZIyy/gyzMiKwhw99Ldd7A== X-Received: by 2002:a05:6a00:2393:b0:718:dc55:728a with SMTP id d2e1a72fcca58-7192607f65amr6710518b3a.8.1726185230943; Thu, 12 Sep 2024 16:53:50 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Alistair Francis Subject: [PATCH v14 19/20] disas/riscv: enable disassembly for compressed sspush/sspopchk Date: Thu, 12 Sep 2024 16:53:19 -0700 Message-ID: <20240912235320.3768582-20-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=debug@rivosinc.com; helo=mail-pf1-x436.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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185467351116600 Content-Type: text/plain; charset="utf-8" sspush and sspopchk have equivalent compressed encoding taken from zcmop. cmop.1 is sspush x1 while cmop.5 is sspopchk x5. Due to unusual encoding for both rs1 and rs2 from space bitfield, this required a new codec. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 19 ++++++++++++++++++- disas/riscv.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas/riscv.c index 0f9ecd8a14..d557c0cda8 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -982,6 +982,8 @@ typedef enum { rv_op_ssrdp =3D 951, rv_op_ssamoswap_w =3D 952, rv_op_ssamoswap_d =3D 953, + rv_op_c_sspush =3D 954, + rv_op_c_sspopchk =3D 955, } rv_op; =20 /* register names */ @@ -2248,6 +2250,10 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "ssrdp", rv_codec_r, rv_fmt_rd, NULL, 0, 0, 0 }, { "ssamoswap.w", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "ssamoswap.d", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, + { "c.sspush", rv_codec_cmop_ss, rv_fmt_rs2, NULL, rv_op_sspush, + rv_op_sspush, 0 }, + { "c.sspopchk", rv_codec_cmop_ss, rv_fmt_rs1, NULL, rv_op_sspopchk, + rv_op_sspopchk, 0 }, }; =20 /* CSR names */ @@ -2608,7 +2614,13 @@ static void decode_inst_opcode(rv_decode *dec, rv_is= a isa) if (dec->cfg->ext_zcmop) { if ((((inst >> 2) & 0b111111) =3D=3D 0b100000) && (((inst >> 11) & 0b11) =3D=3D 0b0)) { - op =3D rv_c_mop_1 + ((inst >> 8) & 0b111); + unsigned int cmop_code =3D 0; + cmop_code =3D ((inst >> 8) & 0b111); + op =3D rv_c_mop_1 + cmop_code; + if (dec->cfg->ext_zicfiss) { + op =3D (cmop_code =3D=3D 0) ? rv_op_c_sspush : op; + op =3D (cmop_code =3D=3D 2) ? rv_op_c_sspopchk : o= p; + } break; } } @@ -4929,6 +4941,11 @@ static void decode_inst_operands(rv_decode *dec, rv_= isa isa) case rv_codec_lp: dec->imm =3D operand_lpl(inst); break; + case rv_codec_cmop_ss: + dec->rd =3D rv_ireg_zero; + dec->rs1 =3D dec->rs2 =3D operand_crs1(inst); + dec->imm =3D 0; + break; }; } =20 diff --git a/disas/riscv.h b/disas/riscv.h index 4895c5a301..6a3b371cd3 100644 --- a/disas/riscv.h +++ b/disas/riscv.h @@ -167,6 +167,7 @@ typedef enum { rv_codec_r2_imm2_imm5, rv_codec_fli, rv_codec_lp, + rv_codec_cmop_ss, } rv_codec; =20 /* structures */ --=20 2.45.0 From nobody Thu Nov 14 04:04:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726185485; cv=none; d=zohomail.com; s=zohoarc; b=Hvl5OkDZm3Z+eaxIn5V4lltKYmxUSIZ4CV/7a0XJu6rzGWTVtPQdN1CtkuMjpnisalRcjgm7bt+6v32E+auFSw8egiTOgBrdJ1lH02+NbU3CLHmI2e5IByQMA4jv+9ugXaK9N5wTyPs09l1HYIt8/Qv4bVUIbuWPeQVUMTF3PAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726185485; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mFWVRWsANXTqcHXOvM2OwmQgl5qrgw/0uXyC/jmwSHI=; b=Y/J2g4LGqXNHt/UXC0yNHNcl/3ug9ArSuA8h161QZ+24lEstYpye5EY//3ul4kZ6t35MTF+IrttatLZsglhgSb+JHqhIFa2CnvMZmO9EqEa/Htb7hjJaQPRjmzmWPcY1ica9Fml+kfr8FnDDBPfJxx2cPfW3rEczq+RzroMMfIA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726185485565797.3450616847861; Thu, 12 Sep 2024 16:58:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sotdN-00061V-2J; Thu, 12 Sep 2024 19:53:57 -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 1sotdL-0005tl-5E for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:55 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sotdJ-0008E1-Nd for qemu-devel@nongnu.org; Thu, 12 Sep 2024 19:53:54 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-718e56d7469so327289b3a.0 for ; Thu, 12 Sep 2024 16:53:53 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe22e6sm5102229b3a.66.2024.09.12.16.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726185232; x=1726790032; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mFWVRWsANXTqcHXOvM2OwmQgl5qrgw/0uXyC/jmwSHI=; b=cLefDXWM0FcYR8raI/2tWD9FCMNGSJEitVU8vMwIchpgiZjDY8Crt1l/FjkDc5V3qi uYE/hHjAqZC8vchvZzF3Th8qu+JHqTU1WzOLqfnW2B+7iBR6o4r9QA9HjEo3Nu+Rczo7 Aztv3za+TPAPmvHhn22xrw4JANsz1bnLkfV8NnaRzhcJB5529N2QLEAu1oW275FGv27f r/bJ2bzIRItCt/mgSkbsq/+FL6cOIssZY0LAKl2EePZxMsOKSGdQp9Rb/v6DnWxpe7z+ 8qpldJ7f4SQWJjp0xaJ+CHjfma9aLlJIx3b3n1ov4oM025+8KWF6nuOjv5tWgucASPKK JrfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726185232; x=1726790032; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mFWVRWsANXTqcHXOvM2OwmQgl5qrgw/0uXyC/jmwSHI=; b=WFLjtPKSV7MgA5G2E74lyumd6FyxwkZ4lI4+xzAOeXrl6ICMiiiolS3d10zu9XNA1V g326SWWeiBrurOJHy8aVLBqn/BxbZSbi11yiKbykDFRigpsSU5igBdlwZY1hP4IU//0F RrurRYmTdL4mx+VU21fifiAvhbWB0Xl4ibSsgLA4Z9/O1Lhvq4d6CXtV7Xty5XojO7Mc wl0DiTA0nuL1glKWLAUHmiscycXWD3rrgHxuQG4IW2cL4ulyqw1kyj3uwRVBDbfWqqL/ naV8wzbSx9WTkqpzZgQWVCOtESqFDySX2FPTGyeUU62wRCxvpuKGM+4Af6Ma9stc/31D SExw== X-Forwarded-Encrypted: i=1; AJvYcCU3uXgIklddClx8e7kWsEsupxPaaQ28R1Kq48eqM6Z15otCJuNj7EEs3jvcoE5BfSf4zGHp5X8Rqtw5@nongnu.org X-Gm-Message-State: AOJu0Yy2tcxqO+if03RrIbH9q03M/QunNznmGzTi/DK+uSi6ntt5nG31 9qbNUTjVD/aBAcEpsW0OfRmnFMgpD/Bj8N4rk3lGGKImLk97H4QAWk/pRZZLlm8MuX2P3wiRo4U l X-Google-Smtp-Source: AGHT+IHH5lsfZWsWqR2Ve8GHcDs8nwISMVUb6vxVEvvprHbeVx9E0fa0LZOs291N0KbESFBmQSXjDQ== X-Received: by 2002:a05:6a00:1706:b0:719:1f10:d1c9 with SMTP id d2e1a72fcca58-71936a2f82bmr1477352b3a.2.1726185232295; Thu, 12 Sep 2024 16:53:52 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Alistair Francis Subject: [PATCH v14 20/20] target/riscv: Expose zicfiss extension as a cpu property Date: Thu, 12 Sep 2024 16:53:20 -0700 Message-ID: <20240912235320.3768582-21-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912235320.3768582-1-debug@rivosinc.com> References: <20240912235320.3768582-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42b.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726185487431116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4172774087..3e72df6ef8 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1499,6 +1499,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("smcntrpmf", ext_smcntrpmf, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), MULTI_EXT_CFG_BOOL("zicfilp", ext_zicfilp, false), + MULTI_EXT_CFG_BOOL("zicfiss", ext_zicfiss, false), MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true), MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true), --=20 2.45.0