From nobody Sun Nov 24 06:22:19 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=1724800930; cv=none; d=zohomail.com; s=zohoarc; b=kMv8L+zmmN5cITIwkR0iKzxUqeM4PUnSDsdXZA+RB6VpArurmcBIOERDadcRL6XRcpwSuEgEuAN71L6z6eaaavFPNrV+DvPcMClNyVn6cgbdABdsN46YM+Ui5aQrGzQXMUZEVHmf+ST7ILnG2Z/a308oNen+Qgaeqk0hF0+ReXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800930; 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=wKicxsSUoIM+Q8CHwfOLtvkXELhMGHcyX8ahibvlzBY=; b=hLB4hAza3aB5MYD6C0KURFFLkEqHn033H/zqTd8+64keVnqNa6F/uHlpb00FUHpYwDjvHzDpYDhvyo1J1i1CH7wIxZ9ssFZ0hOU+oopK4dV1WwbyPBbXkdG7mp+5Gb8HNQARmOOR6DMMbILXWYkKNaBWjIpZLd/YVCP+yKkHpzE= 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 1724800930151322.404888371874; Tue, 27 Aug 2024 16:22:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TG-0003Lp-To; Tue, 27 Aug 2024 19:19:30 -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 1sj5T3-0002Xz-1D for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:17 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5Sz-0000pQ-ML for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:16 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2020e83eca1so58261155ad.2 for ; Tue, 27 Aug 2024 16:19:13 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800752; x=1725405552; 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=wKicxsSUoIM+Q8CHwfOLtvkXELhMGHcyX8ahibvlzBY=; b=jHTh+ilkAqpg7OCZ9Uf3C5Z2fdHnjwYPlS1gWVbI4hpFjJDB8x7PeqVnTOtOWck6G0 BdAV8CyPtu6JTVp89g+oP7FALly56PnvTJZ7SiCYJ1EQYYmj6oQeot419NNpE+Ij1MX/ ZoU246oNU45mUKbmpcCZJXwpY69rJKUCPcDETxXYoJwq59QRyv9cytW87w28CDHqsNWX trCqjdBFZDDc8c8vaMu2mDnaxq+UuVMQLc+gJsmyTIYWY4SqiAH1LiRtJQgNP8MQufK4 SJRhj02+EZ2zLjpY0SGPvAAXksZseSIB0tkoQdyFERBUEVEe7iEM0RDU3AlcKSHGgZZf AADw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800752; x=1725405552; 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=wKicxsSUoIM+Q8CHwfOLtvkXELhMGHcyX8ahibvlzBY=; b=Kwbz6KTSVfZpr1YqMWeKroahGTO3RNJgHygLCRF/xwvsnea1zg/i2Bc8n1y8hfBuBw z8YeSI4a87BzLQIHKRNzmMl5UHdxt5Jf1N9QIKcbkG9JANN3z5udOPZUjQs1ncQfUteq k4njTjm2re9KLxdRbMWAfOVa8KU1CdDCE90B7nySnBYhY0Rb/bUI1ITMJqVkw0Exac/h gxO1ZeLPDpkMQMTMV7noF8Drczv9akiHgq4qj7RJdVel2kDpm2qquZi7pophRJ2yg61l z3LBSA2Y12t0s2ylmyiERv0cLZIZL/ppoDBoxwKIT2rT/a/own/j5brBrZsuaxej2idi UoUg== X-Forwarded-Encrypted: i=1; AJvYcCWscLKjrZQ9HKiNfuFabMWHWnSpYXXnaCPqM9P59P5f6Y2wD0bITuvVBM2VST9tfZ5PLEb67jmaJMXb@nongnu.org X-Gm-Message-State: AOJu0YxtOMSagx6tVhBq9CTZKaLx2a7Zih8s/o/DBh1m9VmnS35Uha92 lBXGMecSqrSYW40ejTvHmpAZIE8I3BUFNKTLJfUuxIirAtU9iPUe6BuaYIkVI1s= X-Google-Smtp-Source: AGHT+IGoSmGtqr0bomgMNgtLvy1Ru6xPoeXR3NDWuR5yaozgIOyu7/y1XFZ2wQ7HtXFitcLL8xPsLA== X-Received: by 2002:a17:903:230b:b0:200:aa31:dc8d with SMTP id d9443c01a7336-2039e52cb0fmr163637595ad.63.1724800752148; Tue, 27 Aug 2024 16:19:12 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v10 01/21] target/riscv: expose *envcfg csr and priv to qemu-user as well Date: Tue, 27 Aug 2024 16:18:45 -0700 Message-ID: <20240827231906.553327-2-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::630; envelope-from=debug@rivosinc.com; helo=mail-pl1-x630.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800930703116600 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. `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: Alistair Francis --- target/riscv/cpu.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 87742047ce..270a2a031c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -226,8 +226,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; @@ -429,12 +433,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800901; cv=none; d=zohomail.com; s=zohoarc; b=kBlY6Ehz2h3UG+TvJNSNPyr2uISNjzSIUdWhXFMKC43JGGKqYi7BGhuYxck93fXxxxeu28Hyi2w4N1LIgHhgesC763YUpM9lh0Fj7TSMN0HiTtz0EJYqaJfb8JJucfZSEOzoHS6cWVnXJpzPi76qhjTR6ujSKkx1+9xIt0TrNbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800901; 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=aoOLJ1vSDf5p0Vfqc4dUxk3Eqww8q10OxxejFUrpUPs=; b=I9Q5bmORPz1yBSBD/xwgpzQaFMPv1P5icMbLLIzL7J2ZQvYBXvqRGDzJXh0hD0BZryv3gdR5qFJwoVIbOjA21nETe595XgzKOjHsj7D2JpUor8f+NZGHaNinfxMofHF7uuEnxY4K6wp2EbMSugCsoGGoDY+FbtdwP9tyE4htxK0= 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 17248009019854.276340952910573; Tue, 27 Aug 2024 16:21:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TA-0002xE-OE; Tue, 27 Aug 2024 19:19:24 -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 1sj5T5-0002eL-Vr for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:20 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T1-0000pY-0I for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:19 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-204f52fe74dso3053445ad.1 for ; Tue, 27 Aug 2024 16:19:14 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800753; x=1725405553; 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=aoOLJ1vSDf5p0Vfqc4dUxk3Eqww8q10OxxejFUrpUPs=; b=g02zzFLx8gobhKqyCSiJCa/Ics2Mmrgrrknk1YTPScxC9ZL9RTFj7n3SNoWQaYjpHf Mh7RwIniAWG0yku071ms0MYbPrA/YIdK6M3Pz8C0YSb2+PEnwEQ9wzJRPLsxYyujK0cz JB0zY2rYLQkrWVLoMqDX9WK6+sp99HyOx+NQvjk/Z2L9DCW8BVNQmn7m20Ycy1ZPxQRe 1KHc6JNQ6Q0ftH3IJvzU7vaRjnLiXyYJ6+nSmhBaT7FKhIGyWGbCqrWgP7E17fqAfcHQ YMD8RfIDZkxwBrSBk3Lhj6Hj5IyRcbfCb5d+3wydD+uAI7I0x7X1hKkWK599MzwnriWV Az2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800753; x=1725405553; 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=aoOLJ1vSDf5p0Vfqc4dUxk3Eqww8q10OxxejFUrpUPs=; b=bZ2ccBiOUg18VksvDC8tYSzJbPOBSntFUQlPMCv0OKUjErL+9xubUWWjSnxKyujljZ +URW30S3VWoWXP5ZdJKRxJoFDLqCJ15HWFFyPQ17v96CdAErPE/tgmq9sjzBoRvBC6/h hmT9lSYos4XNM26UHL89SiZLpIIenR3nNog2vAU7VvTXTGoXcCTt3n0cFrc9frreIjlI vHgpHVo3IbRBuYaJoDpj4IPIGmZWnZz989rjrUPKlyWYDYrcMwLpJMOyxMfY8GtBmj7e a07oyjNegmoWX20CZpGaJGBLUlXQK/+f/oUKzsvsYpa2uxPEWDD3c5jvGAVdjH/rn40G TsTQ== X-Forwarded-Encrypted: i=1; AJvYcCVaXrwAMc1WtwAqvZbBbAt8Xo36ha3djFRO+0Dadsl5PjU35wLAXEBDDxRPidNwX6mREg6ykPzxHESZ@nongnu.org X-Gm-Message-State: AOJu0Yzf2GEdVwQseoLYhttgmMSLCSuqijA8xEgoVErOvOtCFI+mWM4w 8hDFuYWTSMoPthJ1L+8xtH2g8gmN7KOeFeazbDwxLrbenGld1+kYkDO0iaRquH0= X-Google-Smtp-Source: AGHT+IHYn6KHMObEsNpk0qA0CvpN+9r3ZY99LW+rC3IeZwuu6QTa8zcxOY2GH8u/15ySi+pEiABONQ== X-Received: by 2002:a17:902:c40c:b0:203:a12e:faa7 with SMTP id d9443c01a7336-204f9b9ccbfmr5322005ad.27.1724800753332; Tue, 27 Aug 2024 16:19:13 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 02/21] linux-user/riscv: set priv for qemu-user and defaults for *envcfg Date: Tue, 27 Aug 2024 16:18:46 -0700 Message-ID: <20240827231906.553327-3-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62a; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62a.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 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: 1724800902510116600 Content-Type: text/plain; charset="utf-8" set priv to be PRV_U for qemu-user on riscv. And set default value for *envcfg CSR. Signed-off-by: Deepak Gupta --- linux-user/riscv/cpu_loop.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index 52c49c2e42..7a68e8717b 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -32,6 +32,10 @@ void cpu_loop(CPURISCVState *env) int trapnr; target_ulong ret; =20 + env->priv =3D PRV_U; + env->senvcfg =3D 0; + env->menvcfg =3D 0; + for (;;) { cpu_exec_start(cs); trapnr =3D cpu_exec(cs); --=20 2.44.0 From nobody Sun Nov 24 06:22:19 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=1724800957; cv=none; d=zohomail.com; s=zohoarc; b=W0B9bjkHbV/P8pdnwUWynBzF59u2ggknXy9UCe5G7YffsAtpHEhu7/f8Wmkb5XNtVbXOcJECYZ34Kol5hcS1xUSgED8QG/RpQgEp3BpmDGwDL1JqlM5lmsw+mal2JnOptkHBUJKaaME3eIpv5bIlYjfDUhQdCqnib7eqKYDv2KA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800957; 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=X3yfBKYZ/gUZE6VcdiduLzbILXUVJYc5iBQsuzG29WA=; b=Fp0QLcxTHH/WOvHvjnuneNmkIoyRF58ABlvZF2vk3pOHE7Og4AEhudoPQrJFFrCkE4kwc/AU2WEx/r/IL55TGjdhF6bfZh7Bb9uquPOvw8TQTQgQXpKFS9ZYh4xZoP8dHV8lQZaSiI7Q9GaWemoS+K7c2IL534ItgNCyjU1RnAE= 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 1724800957870414.5904737544482; Tue, 27 Aug 2024 16:22:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5T8-0002qI-Rl; Tue, 27 Aug 2024 19:19:22 -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 1sj5T4-0002Zp-KC for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:18 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T2-0000pr-5w for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:18 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-201df0b2df4so49646265ad.0 for ; Tue, 27 Aug 2024 16:19:15 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800755; x=1725405555; 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=X3yfBKYZ/gUZE6VcdiduLzbILXUVJYc5iBQsuzG29WA=; b=zAKBDz/4rH3HVGAMvUKMyl+bcIzZ6eZeSWjUVvFLwYgTM4HtY+CLY3ZKfGZxKCkkRK 2pEb5G8zYWz/EnfGZTXGOnK5b0T+B6vZVH7cMfn092zG+fW8HMu+ZS0bQMja1Gp5/alD pbJyw8GcmVaXX59DoDQ4eamjjv1W0w7aqd0840eKFMH+1crl+3d6rHa4dXd/YVNmYUA1 GtZrIvR6wu5AtCQxN5U5nRo8suLki/eeC+ScyZF7ZQYT203diKRm+9fyQEeUBwwCEo7O 73iyUObMLWkx+6rj+p4DABFV4SYZrOE0uo0+qCZSohZxawNaOe6RkA8TxfRAd0qSlJZj YLHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800755; x=1725405555; 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=X3yfBKYZ/gUZE6VcdiduLzbILXUVJYc5iBQsuzG29WA=; b=OebGOhv6MH/yFYcrqoxh5K70BJhcPPzxT9ha2O16w0JZQ+2dfWtpeCGAzCYioMlHtD TBe12itEdu5tS0fcT8Dultci0kqYbr6nSZvC2u7SDq5s90EQlW60MtAVrH1xK5DWLmdC BsteLNan6UqsiE920SUGbegzQgU8HLacDq8CwG5pWI0ODer5T1dXm+ALwUEhMQkneZPf 4JSXUTOQAEqxJyAkjNYSC7zYnIjv1cU/EcSgO6EaYKRMV1Tzi1GZzmQORSQiQ6D2Zdt2 bzISuk4L+f0MZARAN6f2Tz81jSLr48m6O6meUAJkZ9HQL+HTaLPJ/upmHpQVF/PgONr8 /QlA== X-Forwarded-Encrypted: i=1; AJvYcCXztZVzvJFr5KWZ5kWrz0JhSK19W0+933t2CdYQC2U3lkhMoIJ0tf9o5dFQDWhPMCpR+saS5vkAk5qL@nongnu.org X-Gm-Message-State: AOJu0YxlZB5o3HxIugA1k1kdiaoj6zckxzrAYNIhWEMCtAK9HL/5Vkln T22ZIQVoRRbFF/qGLuSDdKjHVRT/eiZ1F/tORpXvUFqgF3MNHQHChOJv+bLHMro= X-Google-Smtp-Source: AGHT+IFqi1k8fzudJ+wJLFva2WaXpTcmaWyaxiOnZwv66fCh3gemhdqEYSLShLaBH1AziHfEtQlnrg== X-Received: by 2002:a17:902:dacc:b0:202:cbf:2d4e with SMTP id d9443c01a7336-2039e554fe8mr166193425ad.64.1724800754525; Tue, 27 Aug 2024 16:19:14 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 03/21] target/riscv: Add zicfilp extension Date: Tue, 27 Aug 2024 16:18:47 -0700 Message-ID: <20240827231906.553327-4-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::633; envelope-from=debug@rivosinc.com; helo=mail-pl1-x633.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800958847116600 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 33ef4eb795..43156ebb92 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 120905a254..88d5defbb5 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 b8814ab753..ed19586c9d 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800868; cv=none; d=zohomail.com; s=zohoarc; b=VZxppy83GOqFHPa9Ux18nr0Iv4JleRFKV9RlAY6DyS9DDMz9g2mCDTOHlR3pL5jAN5OkWIngdWUfDcicM0eYS6+eJ4lUDiFgMBzGgigW1eWd157D35FL8y3OrB81stTVR9R2POm+thXskAh4WvuxZVgc2xPXs7MDzJ5hTjpWLeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800868; 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=AJU77TfvU7ZPp+1sfF/RYEtSXBxdAmuA11pTtSZZME0=; b=Xi5ES53JP25q4P5jDlfBwwR8UstOh6SkEcDFzmbQSsbDb7VYTZMqPtKN8auHjFYhea15RoX9pS2+7Hgtqy8IPEcwcaZxDAix8BVkqffIcqkviHkMmGFX/joXddArKhuZRS2dL0PXqGXvS9slhgsDPGbs6uPrEtPb2Xf+pz0kjvY= 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 1724800868234105.72183288119493; Tue, 27 Aug 2024 16:21:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TS-00047R-NQ; Tue, 27 Aug 2024 19:19: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 1sj5T5-0002da-On for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:19 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T3-0000q2-6C for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:19 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20227ba378eso55185705ad.0 for ; Tue, 27 Aug 2024 16:19:16 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800756; x=1725405556; 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=AJU77TfvU7ZPp+1sfF/RYEtSXBxdAmuA11pTtSZZME0=; b=URELG7foKfQ8I07rUA8W52Q1gne+VNsHjQcPJstYBFx0/pScWvb3Ate2hFOtKC4Ka7 TiA07Ylm7FQIS/jdzjbmae45tnDSc1HSyrcjT62X65i/bUdLgMDRwEeg/jPkj1quObHl yZdXscs00gEhYn4DZz/l84+8IMB0W93kvtHLXj4Q4eUwQfqY+YEMt9UMVlTJS8baZV+b hIwz1JGNBW5MAsu1xK2JSYn0o4tfKpjf82ej0js3Br0tAeZ9w3OclWv0SE7g3plClfwH mrgX8YvI4zaxn70+rAKVvcUAfmfu/g6OEzhq7Bdy1Fk7m9qxzedjo+nEovJ/Y6Ib1uOD tvRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800756; x=1725405556; 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=AJU77TfvU7ZPp+1sfF/RYEtSXBxdAmuA11pTtSZZME0=; b=T4qhN3kN6F2mDxeG8+PSmtWYCcXy7Z27oeWUgmpRf0XwFmg9NO6jL5vIT72WHLdqMK bnWOKvxb1/Pn77EWgFMbUs5MJxvX9vQYI/nqr+z/5tJpiA7srDljxKO8Kpk2SQ/Gk048 8+MykcX9AfbVcOC1uzWd1cdHf6V676kNoXMX2vpg5lr+lhf1wjF4DbCCIv6zuFKcex5S GEHTueJT9sQZsqio3RQrIsEobH91HugZWLLWsP60iaQVh8wWG9a+nzJwsSACsBrc1ij6 tR83T4Z6rCl1+PeIQoGNKYEchI0eIPMskSpy4oZa/QE9nUPP/H0JOGCy+2j+mSeEsdkI rplg== X-Forwarded-Encrypted: i=1; AJvYcCXa0LYPpttSIXOKSAYQgkYuBrK5+Q2amcmz5ajeekT29D9Y8YLAeJqGBr8KsJe6OCQGa0QQm+PVgEk6@nongnu.org X-Gm-Message-State: AOJu0Yzrr6OZCjBYvZ2Bd84zM37dwzUwmLcA3aFJPXiOxgVqWF37k7sz +18Rnsx/k6LcHnI2EAYrdOAfy15DY92D75R5NflVSkmKSnJ0GKbGE2ObrGspvQ0= X-Google-Smtp-Source: AGHT+IEByZASpoK8TdA+BHzt5/GWVyxizkx6+NzFO4g/vVtJADrEx7OJbNabHvjkJgI6gbgX0i5ifA== X-Received: by 2002:a17:902:d502:b0:1f9:d0da:5b2f with SMTP id d9443c01a7336-2039e4c5159mr181032465ad.39.1724800755772; Tue, 27 Aug 2024 16:19:15 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v10 04/21] target/riscv: Introduce elp state and enabling controls for zicfilp Date: Tue, 27 Aug 2024 16:18:48 -0700 Message-ID: <20240827231906.553327-5-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::629; envelope-from=debug@rivosinc.com; helo=mail-pl1-x629.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800868448116600 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 43156ebb92..2d031e3e74 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -994,6 +994,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType= type) /* mmte is supposed to have pm.current hardwired to 1 */ env->mmte |=3D (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT); =20 + /* on reset elp is clear */ + env->elp =3D false; + /* * Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor * extension is enabled. diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 270a2a031c..b2dc419ad0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -222,6 +222,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 c257c5ed7d..b05ebe6f29 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -545,6 +545,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 @@ -575,6 +577,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 @@ -747,6 +750,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) @@ -760,11 +764,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 432c59dc66..5771a14848 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1400,6 +1400,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; @@ -2101,6 +2106,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 @@ -2153,6 +2162,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; } @@ -2190,6 +2203,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); @@ -2654,6 +2671,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; } @@ -2665,6 +2686,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; @@ -2680,6 +2706,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 76f2150f78..873957c4ab 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -351,6 +351,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, @@ -423,6 +441,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800810; cv=none; d=zohomail.com; s=zohoarc; b=gSDKRu1EBVOt6i4d4XYUGNv7JEFqX49M5UuohoQ2TDV8x8muTTIgrw6dAyYW4koMxjQCt+RmYFVdmpV4QFG/K3vfDiz4iWpzZ+zSlxsPwJyJaT1cJX6T8ZT8ZogoPzekTk2ZcOsGZqTZU8nu9emNUhRylO0lKpTKYzLv3MrlxEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800810; 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=hiY0e11LdWr0yJ4C1u8dpw2Ti4FucCf21GJ5876Fq1k=; b=DPVwe7CgCGoXNsyhSOK20EHYz/rQ4tJBsyP9eJ9qv8ijwF+ULpBFjQ3jGmaozU5q8CRT+eLj4Qd+3unOJyALNvYXmaotLPp51bYye+Rvk5E/NrSFH/bfPm+7o1TEaVv8uAM8+t8uPtLz4f1Wc5n9Lk2ksJyWH0GFfEx26RF8eQA= 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 1724800810898339.8771841504122; Tue, 27 Aug 2024 16:20:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5T9-0002rq-DY; Tue, 27 Aug 2024 19:19:23 -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 1sj5T6-0002gH-F0 for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:20 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T4-0000qV-Fm for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:20 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-202508cb8ebso41266635ad.3 for ; Tue, 27 Aug 2024 16:19:18 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800757; x=1725405557; 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=hiY0e11LdWr0yJ4C1u8dpw2Ti4FucCf21GJ5876Fq1k=; b=OZiyu4gdlA9brKIn3woOCM0mq+nD2gJkEiwglUKTMOV6K2cR1bUuHiAYiwTV71lHEw NKa/3skG3l/vYxODRZmjxeEPUFJoYmexJR1dsFIBVAYNjwqeYGJWX5JBUFB8tC68ewsH oaWlaMy5BhVQVhJZE2pHwPgeYAJgYZmxa6EeTTjJjvHu+ZBbvmR9PKywmsvNEII/HFMk LtW3rkdnAZEmbIYs9Nnr3v+WHzgkPBGWvBIZfJ7z8vmPIUKtaHsNckWXads5OIoG8d54 uC2YbHR7+xC+UhDifp2OPybYtSih+1sZe1diD2Ls2i6Tu5MHzlONJ2E2DXGECKn8WtJ5 4B0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800757; x=1725405557; 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=hiY0e11LdWr0yJ4C1u8dpw2Ti4FucCf21GJ5876Fq1k=; b=MnLQPrF4mupcArXrOT++5dU0j+42wPyXFHJ1Ds60Gr3cCOl5w6Rj3oIu+J4p6Sd8VG 59wtTB/4fV6VxufcEkoY96zy92EZQQpnsx8RMfBA1Lkr9LszlyfeURx5GRP3jmTbCRwI LvE/D+1hoGkxJvEO5XXfHeFNkaxwUKz6iT2ccPpy/l46QptYva2u2D2iFtOllyG3YPac dGUtrjKcPz6cyq2Nbwn+2bOCDmZ8pOGcK1k1INrC8dH8TxHyQFLqnp+h7yNGS7WkZpxv kSzb+e9NO4Nc4tkQ/zgmy8m7zoTM1nHnabjRHaIabDhyzAz0W25bolP6lxkCxo/d+GR/ WSVQ== X-Forwarded-Encrypted: i=1; AJvYcCU9iSCoZmcYrOChKw/7slsSEVy4Ux5FQSEe+tXNv8n/pPhAjCs5KfyZ0bSDSDf+776dMhs7qkTvBdJT@nongnu.org X-Gm-Message-State: AOJu0YyPMezsIMftoxePHybSI9vRaJgRbjN0IpyWem02YbbU5UVncB0k DqjnYGfEtxCneqk4OzY35nkFMjNS0JjBhQ+taYj8BjKMQcPzaea33WZKnJJSrvk= X-Google-Smtp-Source: AGHT+IGYus7nmIXTjHRd4rdD2lar3WI+DwrxW2WNnxrcA6wZhdAex/gkXXq/fheDi2D/YCm226nwCw== X-Received: by 2002:a17:902:e550:b0:203:a0ea:63c5 with SMTP id d9443c01a7336-204f99088b6mr4100185ad.0.1724800756934; Tue, 27 Aug 2024 16:19:16 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v10 05/21] target/riscv: save and restore elp state on priv transitions Date: Tue, 27 Aug 2024 16:18:49 -0700 Message-ID: <20240827231906.553327-6-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::634; envelope-from=debug@rivosinc.com; helo=mail-pl1-x634.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800812501116600 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). For qemu-user, a new field `ufcfien` is introduced which is by default set to false and helper function returns value deposited in `ufcfien` for qemu-user. 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 | 18 +++++++++++++ 3 files changed, 73 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b2dc419ad0..a7c970e70c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -531,6 +531,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 6709622dd3..5f38969aa6 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) { @@ -1754,6 +1791,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 @@ -1802,6 +1844,11 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_S); } 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); @@ -1833,6 +1880,13 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_M); } =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 2baf5bc3ca..5848aaf437 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -313,6 +313,15 @@ target_ulong helper_sret(CPURISCVState *env) =20 riscv_cpu_set_mode(env, prev_priv); =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 @@ -357,6 +366,15 @@ target_ulong helper_mret(CPURISCVState *env) riscv_cpu_set_virt_enabled(env, prev_virt); } =20 + /* + * 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); + return retpc; } =20 --=20 2.44.0 From nobody Sun Nov 24 06:22:19 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=1724800803; cv=none; d=zohomail.com; s=zohoarc; b=kbYMiOVVwsM0cqnw7bqM2Y8mTCTVhf92QWKQZYl8cY9soad0cfb6g/jsPpem4LhIW/Yp36ci11SbkcLjJChP5DyAJM8mRP8iR97MvV2MupBGNQk4Go3PsAwwwlm8HsYw2UQFtE72U1O2badLye3iSJTQTwno/BtL9DFhZYxsEmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800803; 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=zfvLnj6XNfSIT8sSl0+fnX4A6Nm3Jxdidu50F7PUqy8=; b=WtBjY5EptYkiaA1Z/KxWyiJNnONJBEBF8Umg46H+4s+B841KnaAlwPW29pKEhtanYFaQF48BYDGxWXj/tjjTmFJiGxczw+XPcJgloO3deOWrItl07/TbditWNOGgeZal/HanznwV7Gv2i8sEymvP9o5281iN/XgER/6OFCTlXNc= 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 1724800803282733.4290011273982; Tue, 27 Aug 2024 16:20:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TB-0002yu-VI; Tue, 27 Aug 2024 19:19:26 -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 1sj5T9-0002sS-B5 for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:23 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T7-0000qw-Je for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:23 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1fec34f94abso62746785ad.2 for ; Tue, 27 Aug 2024 16:19:20 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800758; x=1725405558; 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=zfvLnj6XNfSIT8sSl0+fnX4A6Nm3Jxdidu50F7PUqy8=; b=XmVaZ2qW4F4jwE2NtpsqyPU1jEN2pzHRR199GA/duOlkiq7FK+ZVAKr8sKOv8/au84 7sz7RkbwAQJABXwxikApYynNhWpWzL+tC7pUj7Gyk7H7FuEyZtULVW1lDCIx+e0oDeWB sMuGUQ+xB2ivYsqwiqeTEEoStSMO8sO837tcRcyg/ut+6BzUO7SP/7t57hQSvaWFlZIv 2qgV6sxl/Mbb542/FSlcG5fxqKII3dtJVON/UkeoHU5VOLT4SgIQ4ltE3jDg6X6LiYnp V5eQ1lRxt3cEElheozZOWypuKi278S9qV5rdNo1lTWHj9jR+k0i9hH1j5uBdvKA2QrfH Cdxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800758; x=1725405558; 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=zfvLnj6XNfSIT8sSl0+fnX4A6Nm3Jxdidu50F7PUqy8=; b=I/OjbkqSHK+ZHCHvsPD+HGJFcTW8MUmNnsSBCExxUzNCCgKU0oFtliZpaNvhawCqIE NvdTjo+7FQIkVzu2ybYgoschME9Oqay2RyLqNEXFj4UNdBi1HF1KmgqsGfgjXy+1unZz tKgLWE0z2bABwckqMTXSl1IMLnn2luX9SR5lgifUx9+qMSd75BvERvKCyuSqkWULBxTU CzvrqPEEzstc3zSHKpF6qmh60CIMUgCHjCYw3MctUBh0T1/xLsElX5Ju7RUSWRJ+1Ggw w1TOWCXCYhWzj5f4ym91SZltkJw+eU+ReIql8h56FQQfOBdlnry7xBxU6X36rBj1qm9u bP2A== X-Forwarded-Encrypted: i=1; AJvYcCXV42+BsNMu7xddQ+WVHsRoWFsYpr6I0p7i7RM51tyISUNCcyPxC0UShRvRPNprCeJwGgMCcFeJjFQh@nongnu.org X-Gm-Message-State: AOJu0YyjswqSj6nw++ZCQ+Cx6te4AFZcAmBurZ33pT/UiRNopNOkzAdB Zk+TkpOZrAy0wXqncPdJRzAyXt74GCb4pX+ElnvSXUMrOKYMNCgRjMBWndQK3HM= X-Google-Smtp-Source: AGHT+IEPE65G+n61Ae9A0ikXCgWRNT68qIhkhH4nzikUEGjAPGpWmeUVc7lFmr+YjU9FY4ZQMN3O3g== X-Received: by 2002:a17:902:e842:b0:1fb:90e1:c8c5 with SMTP id d9443c01a7336-2039e4b5193mr116545135ad.33.1724800758168; Tue, 27 Aug 2024 16:19:18 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v10 06/21] target/riscv: additional code information for sw check Date: Tue, 27 Aug 2024 16:18:50 -0700 Message-ID: <20240827231906.553327-7-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::635; envelope-from=debug@rivosinc.com; helo=mail-pl1-x635.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800805576116600 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 a7c970e70c..a0f14c759e 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -224,6 +224,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 5f38969aa6..fffd865cb4 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1760,6 +1760,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 5771a14848..a5a969a377 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1179,6 +1179,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800863; cv=none; d=zohomail.com; s=zohoarc; b=dwbRemhiP0qu0TiqL0ayXu0lzDc/BwtSB1B5S6OIzhWSN6NRYynPFmiaSibpKOvT5NoGFPCowRMBLmGhAl/ZzUcM5ZRZ3KCTOPfMcsLvjaRmPR8M8JbwI8eEibiTeEtdGoQUgxzZNCr7GAd9JmloOjU5ST1Nt4NUEMxDdFZJwHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800863; 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=fvGH26X0+vKupgaNF4mDFcjO25Iuuu3HUu52oa4zQIQ=; b=c6dC1m+gmUKtBCjcpNAz1FXt7J0HRs8AJ8moC8BOixKUW7PVjkER8oOo907siXdyY6bV7cS6jqUI6IGKhhzUkY4CWYJqiHmmRrbybVwAYkNQZVYEE7CvwBoufDgAXhVIdkv4HP24ZUFvxFZh0jG88CkH64AH2yG/dR98GUiwXxc= 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 1724800863125808.8306176736771; Tue, 27 Aug 2024 16:21:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TO-0003cP-53; Tue, 27 Aug 2024 19:19: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 1sj5TA-0002yf-TN for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:25 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T7-0000rM-Ka for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:24 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1fec34f94abso62746945ad.2 for ; Tue, 27 Aug 2024 16:19:20 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800759; x=1725405559; 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=fvGH26X0+vKupgaNF4mDFcjO25Iuuu3HUu52oa4zQIQ=; b=MaDg2GWTPORgVi0nc0S0ByY3Sk6Zz3tTqJIBA5PcdkkYthtzr1Pdr7lW12GechZwSl Zqzz41wqDmErEfQ/+TT/oZU5uPtdh1WmR1vgyUYdfwXj8dkA82JszKxkwZNNRz/kBquH 2RE22GwqBWY+vyaqZ46QQRgcD/sGWbxAxDHsVX1hn+LgqqkgOPk32eOYCLD4/p6choA4 RRmZNutX+E+2IRxRHWO9OXA139Xs4cibX9V9UFAxidL7klMfrlZJPaGaljt3nodWPHo8 bt09Ul0P5VDwvkgSa+sa7FLEqoLbMWrSgr+keNCLtQv9Ze4x+h4srgcn9n8Tsxjd9wEU 6FuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800759; x=1725405559; 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=fvGH26X0+vKupgaNF4mDFcjO25Iuuu3HUu52oa4zQIQ=; b=EiLD3yeW2R5f28hhMGaflAtKpRKeUOotp2oSlL1lx3w/dRrjIvE6PtRcLvsGYrQCzT S9mt8YD/3Jk8q8qANvs/FsInL+wxYas+I2zcyOM0RNfr34Eafa53GeD1WoRn5gBBaOGl Svyw0KzIB5+PsXyseZGeNc04osUkQJybBH6mVnAy6N8B//fDufvRjNImLr17n+oKDQla N6qxz+HeUMT3F33qLAj1U1VLCjMquIj0jMXHdANcgV0q4HvWqAc+loJD0J0kaUPyGhQx 7xZ1cGrKMUOVjT67crmOSlROYIkF85MUdHptj108cWCyRRDtUpyL4J4PwWRoT3b1LbZN 3SHA== X-Forwarded-Encrypted: i=1; AJvYcCVtflt0AJ+MfjsNyQ7O0PqHsHgg8ZzQwaPSVaHdB4cDVkA6BVIflHEbQxAK2L8KwmyGIJ9V1Lsp+uxi@nongnu.org X-Gm-Message-State: AOJu0YwOuLYDRivhYh7xvh1s5/vS81glre7dLWaMpGtaQpSyJcLHnHnp 4xHTw0Elx+OCoRG9PDJPWkshSVef9NoobbfJqkB+wEzh/t60P0g1dsbghUlgIBU= X-Google-Smtp-Source: AGHT+IHG0xb4CrJCXFpIUf6EYgXG1rrC8K/S9ylFbiJXBtNLwE//DsdNVmveyiyzD+ih3zNizMn5gA== X-Received: by 2002:a17:903:41ca:b0:202:ac8:991f with SMTP id d9443c01a7336-2039e48b9a9mr151244315ad.26.1724800759372; Tue, 27 Aug 2024 16:19:19 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v10 07/21] target/riscv: tracking indirect branches (fcfi) for zicfilp Date: Tue, 27 Aug 2024 16:18:51 -0700 Message-ID: <20240827231906.553327-8-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62a; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62a.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800864609116600 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 a0f14c759e..f372a4074b 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -606,6 +606,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 b05ebe6f29..900769ce60 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -685,6 +685,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 fffd865cb4..c3820eff8f 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800861; cv=none; d=zohomail.com; s=zohoarc; b=IV8RQVPDlAZ2g6QFRJdiNaKwkqXroNn2a3kHvgV3t4fYULYrgD4U0LNGx4BUb5sT/oHj2+3ewhNoK8IoGlL9tlDkoBDNLsqY8dn9PjR/IqzVQcKa49LIXnIsgot1xdNi7FxTIRszEYsnyhK3ntsHtQMjbAy62uQcxF8E+n/1BE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800861; 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=XPl61qcPi4IkfbdTv205Sf5xEsPUhvcDE8fgdnhJ6dE=; b=l+YT2igmmAtdUC9rHnwNVRi//L8Aluj9PWh+VJfWOkoCvxaFswIJUeVtVfqV1XLKwW0m7F5t00spWTGpvm3ci2HnK1wxD6N1tk07qs2pkWBTizRnz1Kt40afVWwmUqTjs4y0KuZeGhiQt5jjwcu7fBuLzHaBwHkaTkVBdCGqb7w= 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 1724800861706374.34158910272015; Tue, 27 Aug 2024 16:21:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TF-0003Eq-40; Tue, 27 Aug 2024 19:19:30 -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 1sj5TB-0002zI-12 for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:25 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T8-0000rr-2N for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:24 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-202146e93f6so62351465ad.3 for ; Tue, 27 Aug 2024 16:19:21 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800761; x=1725405561; 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=XPl61qcPi4IkfbdTv205Sf5xEsPUhvcDE8fgdnhJ6dE=; b=v3vQASqs2mb3/wfK3lUYZSagWtUlZpArDAnZsrOO/4qu93Zskmg/6xHybaQTl8ZppR FHecH4KW88rGPnx9w1FIbulGLg2XxVG/NhcUAcvEIaySwIwLkM+CnZDsIhnmHoGeGzFQ jKp+icwjvqgqubb7jwYwoy+x3PMd4TdgHxVGik2kz6Tjqxb90T8KFtJ6fjp7lMWeQDCH iSUZOoLmmMwTcx2LM9dy5BM7opUW9YQ+V6zhl5hLfN8EmhbKaYU9TK6Hh02Cv0+C7EP8 aFck/lTvG0v7idm+sLV5NjHtxe0qA3S3Coati97c8dHTid1ywEMrG/KSsuyS21xfZeqU HOIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800761; x=1725405561; 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=XPl61qcPi4IkfbdTv205Sf5xEsPUhvcDE8fgdnhJ6dE=; b=SRtvD02+pdTTWgk5ciGSI3jr54HwSlld9HMdmP1FQ0CGYQ1D9b85E7HZYwTQIMljFq DqpdoXX2/sB+H8tOL51pvnqr61qr0JKnUVqtImr1pSOAJQTFGbqT7gAR0gjtjKD5zi8e Zra31TJq1iFG6GZHpwXi+HpDC6XVLNBTGMyoH4RuxN9WIiwYi9kDk2K4Yzqtp7TRMrUr 2IFL24xj5w1bE13fcedKqJTKCuD3kkYsyF0d/FakzdhFkQXEe76/zG1keAHGhUSM+BHk mgabDPj7YXy5CQOMHSPCFUg1S/vN1pExojIAjEJ5sDj/Rvl7XENy5SXpCKMVDsVXjJLT isow== X-Forwarded-Encrypted: i=1; AJvYcCWnIln+RPsfx8rO01r2F0cVbIGSClNbcQcSfdsmEsWCcaNW7fR1zYc59KSKfj66BX04KOtnypNMmdEn@nongnu.org X-Gm-Message-State: AOJu0YzgFlkvfNN3+sn9WWfTdeNyjNIvuDdpFdC45TsNXecGCPjtbKv4 bKHZZe4HFJAD8gknEjFCRrEiJYSJa+aR+PNTNsqDxCqdauQS9EiCKjr4VcL1Oz0= X-Google-Smtp-Source: AGHT+IEGwxVs8WMejTrD5t93vGQ+vUdAJYeEqjeX+HJI6csKCbLhmeku3c0+V81kkkSMZpDjWfJmPw== X-Received: by 2002:a17:903:11c5:b0:1fd:a0b9:2be7 with SMTP id d9443c01a7336-2039e44f83dmr175332215ad.13.1724800760608; Tue, 27 Aug 2024 16:19:20 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v10 08/21] target/riscv: zicfilp `lpad` impl and branch tracking Date: Tue, 27 Aug 2024 16:18:52 -0700 Message-ID: <20240827231906.553327-9-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62d; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62d.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800862567116600 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 98e3806d5e..b427f3a939 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800958; cv=none; d=zohomail.com; s=zohoarc; b=DibcngZKrUPVxnwKz4gFCic+yabdOGxrfdLiuRKf8M11UndX8HE1dzWqtuZLpUcNgxapWJ2BqtLXsaZ14LxOEdXdR85Y5xCFjm16oAX0rgygK+u1MCAXq5iiLtAAKAhpFoBil9hhkFPyk9CSgJFoXS5RsbABqlHVBpzcIYkwjvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800958; 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=gJJt5Z8SJGSqiOcjU4U+2C4uQqhkjvrrqsHIDsZi2XU=; b=OtiMtC75JFQ1ZwkzIcummehYLARKJ/h16uxT6Tad99zNfPSsZUvD/SWgIrqtDKRMMoN3Xy6+5wqzYolovSjWR4fuTuPva+KhnDwJNoYJul3wgxySpLO1b2CH3Iild4943+bp7pus+Vq4lPJwZmC/KG/zPYsezI2XDJCuc092CGo= 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 172480095811882.24181708463686; Tue, 27 Aug 2024 16:22:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TU-0004EN-8r; Tue, 27 Aug 2024 19:19: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 1sj5TD-00034c-BG for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:28 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5T9-0000sB-BL for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:26 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2023dd9b86aso48558235ad.1 for ; Tue, 27 Aug 2024 16:19:22 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800762; x=1725405562; 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=gJJt5Z8SJGSqiOcjU4U+2C4uQqhkjvrrqsHIDsZi2XU=; b=oPVsE2HJKOcRgUz4I85zCIconsnrGoxGcqRrefC4jMuuyXbjWKONL//H7JvVOUoeiM PmHLR/+E+5/A7/vgqHxJcRZa1iPiclw06txQdv4AhiA8tkaeSFoZk8rKPYjZrByvU9ro 9Ph84PJ+xwHZWl/RxbmuSNMILaYv1jgzBEjpetIdIY+xJqG18lTctqs8pPB99x9stA4Q JYVufWkKEPtYfTchNT1nWTWt+oIsG8f4HXYXSjfIcdsmVYaDslrhrNQdFwjKs/Swl+gV lmvmOUKfMyr+ze0IKA2dVXFGYizBknnW41aUvfx7Cl9XD52AwgDBuO9YWJV12Vl1kgFj xjSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800762; x=1725405562; 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=gJJt5Z8SJGSqiOcjU4U+2C4uQqhkjvrrqsHIDsZi2XU=; b=f5A6hgHs8gp25VJY9F3Q0hKdX5TM81U9/77wHOB5wzMdE8SkqPF+QVhyL+od8yagOZ FGdMb+28rLCSFd8Zf2F+E16yYCxC5faffbeIjMFS7fWjplim1NyahiI85R0eac7Udugj Ugs0wH2/oTR/2GKB/oAI6RUFg2sarr/ymobQOgcRzBvFJCranjAJta2MZvCoKUODqqp7 hX+Y/87VN/1WRhtIObWNHOuQuG2Qu+cn/5dgLOwl/lbAS3S071sV46F40iliJP2/b7sl PwwMc4JtOiX1C0TZIFcN4f7SWveGY/c2v6yZ3UMeFWpbxo2nFXhUdfnpBdSQZ3KL6/s/ wxAQ== X-Forwarded-Encrypted: i=1; AJvYcCUpoPJNOI3W2M07TKXiQG/S/bkdLFb/8ejzWn6FX1zPNG0B6755j+QVn/DC4JBd8I95i3uott26Rd2z@nongnu.org X-Gm-Message-State: AOJu0Yyi8bqSWIO0zv2oI7PpnbtZfNwb8aX99xBfpU+AQB9/WGpyJlRs waMeYlsJRtg0EFdef2x7t2cJyspA1T1XhldbPgCs565essKxwep52Xoqm4HO8D0= X-Google-Smtp-Source: AGHT+IFutze4KoqjpsYfit810Yp6k1dQlQaQlCZ2mx7VcqEhGJm6rSLtzRgjGMHQrPQt+ZaP3TFv+w== X-Received: by 2002:a17:902:db0a:b0:202:1176:5e2e with SMTP id d9443c01a7336-2039e47b895mr159119345ad.21.1724800761816; Tue, 27 Aug 2024 16:19:21 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v10 09/21] disas/riscv: enable `lpad` disassembly Date: Tue, 27 Aug 2024 16:18:53 -0700 Message-ID: <20240827231906.553327-10-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::631; envelope-from=debug@rivosinc.com; helo=mail-pl1-x631.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800958909116600 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 c8364c2b07..c7c92acef7 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -974,6 +974,7 @@ typedef enum { rv_op_amomaxu_h =3D 943, rv_op_amocas_b =3D 944, rv_op_amocas_h =3D 945, + rv_op_lpad =3D 946, } rv_op; =20 /* register names */ @@ -2232,6 +2233,7 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "amomaxu.h", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "amocas.b", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "amocas.h", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, + { "lpad", rv_codec_lp, rv_fmt_imm, NULL, 0, 0, 0 }, }; =20 /* CSR names */ @@ -2925,7 +2927,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; @@ -4482,6 +4490,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) @@ -4869,6 +4882,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800868; cv=none; d=zohomail.com; s=zohoarc; b=Ys7yPuaA28mxcw0L3h9TfiVnTohLjJoDL5jdlFj9+SzV9P7CDBjGME6VOc43TCAjW3Od1JoRBXFFUo0Z+pilmX4spE9zQhlST2bci0yAGt9olPtxdJHtjOhmpFjEOzikgI0FUvx/MbbLp/8cEEkvQXnPSEOemm4GzLikxtwRtIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800868; 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=TGGmvWw0RY1iWRrruhF6H784nJTg3545+D6bTLHJ0CM=; b=CROLuD5CBUmQMMiFXwcLS4arQVb1z8Z7qonntkHn5pE8et67VHNVPqWso9X1UxJSbSZoD1UsDuZS96Niw8KpyCSkx8baqB9vew3fnoLKJqN59JFCvGKBlYRmDSs64fjQqC/PERWbwnk9wDQiLmLorwG/KPgOcTlqfjlsC7evOv0= 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 1724800868299541.1684163474698; Tue, 27 Aug 2024 16:21:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TV-0004Ik-4l; Tue, 27 Aug 2024 19:19: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 1sj5TC-00035G-FV for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:26 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TA-0000sd-SG for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:26 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-202508cb8ebso41267005ad.3 for ; Tue, 27 Aug 2024 16:19:24 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800763; x=1725405563; 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=TGGmvWw0RY1iWRrruhF6H784nJTg3545+D6bTLHJ0CM=; b=R+B8PPk5vS44DYMhHUw1Br30BOZwvxtrog/4nDVcQuGoS/t+oZUI/TFZvdZvkjeR0t x9LQigZDs4wNv5SMchBtSKK+7ZjI8hExoUL3USDXdnWDa5XukGYNynR6JiaY7adgPprK YdhkbPTQ2ShD0Bzc/wiUWWRMOCL8eb1voq5Dy1qO3OfBzrcCCfke73feLiBW4VZRPTTG Mcyc1HE2DJbTJ7EEyeNZoeuy7GYveG5gFNUtzHSHNk2D1c8CvB+zPIaQu+CFRsW3kknb cnhrBy8BwRbFM6pPaGj1VsAGztHVfDHsQOqm49JLX0JLl3549nozYz8YdpgmuGujviIX Gc2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800763; x=1725405563; 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=TGGmvWw0RY1iWRrruhF6H784nJTg3545+D6bTLHJ0CM=; b=IGzWPIeN4CbIrhM6vgiK5LmFsv1Q1h0tJNx8zAQc7htQ9XzY8abJUmpz7rtxbbJVqL sjslsDB4p/aXLArrEltwsisSTZjt33a9BKN8esTEpvJWdmLPwsSK50g+Og0S2phTjc0B n6XHjpISkG04CFuVQml93K6nPBY+qC+/eoDb/94uW8a/W3nIPJWCtpgziDQ2Qp6Rk7Pq pYGO/0vBbMQJiOI6yp6qhVyt9LnJft7wuGtwoMtqkcUy7u1itjrp0z+oqechXUIgk0iJ 5/BvzhtY8CzWsv2v7CnEMS2OSkWvfc1YA/EcsQaahEYEfy7IOcPWUUzoLtXvxVLLaIib NbcQ== X-Forwarded-Encrypted: i=1; AJvYcCUHncJyHuvDttOQkPNUA3xE4Wmai+wmtcx3YoMUxjUzZY6FnE2FxqPZbPHfoPNPowbAvwtg6nrdqJpG@nongnu.org X-Gm-Message-State: AOJu0YzvZHpeP+0erpCl1b++JyRzy8ZKm88o1ISeA+pb6uPfUX8bw9Dc yf6Ojoq82kf7jEqf+9Up4I8j6VuJbhZmcsJUN6/5IZyfMNsFSjG7TF2SVYcaQkI= X-Google-Smtp-Source: AGHT+IHfX2UEhSLbQ+A+InwOt04wzuJXJKfegKZlrVewVNzS8PQTnKt7bmecIv9OnJCOQw/LlClwMg== X-Received: by 2002:a17:903:2302:b0:203:8b7c:c8eb with SMTP id d9443c01a7336-204f9c87c1amr4792345ad.63.1724800762932; Tue, 27 Aug 2024 16:19:22 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 10/21] target/riscv: Expose zicfilp extension as a cpu property Date: Tue, 27 Aug 2024 16:18:54 -0700 Message-ID: <20240827231906.553327-11-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::629; envelope-from=debug@rivosinc.com; helo=mail-pl1-x629.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800868437116600 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 2d031e3e74..8e1f05e5b1 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1476,6 +1476,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { /* Defaults for standard extensions */ MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800848; cv=none; d=zohomail.com; s=zohoarc; b=QCUagsfz5zQP5hKBxU67ueuVZn0N+tnBnE8ajeFwt/wXDPcdhnzxQ9GVk7e2NBtgKwkOEWajNsXv37xyOKV3eafWB/0aDbqdHjdrla5kmYWggnYsg+NlpCxk26/SvDmci+ZzA+onmdwVqGveKdWWGrsZeeV0wpQiJZ2vJOuXKSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800848; 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=S0CJdxvDGa9NA73ICq+2YegGu+s3jbuadw3iL7vsbu4=; b=RMHFMQW/Te4ApOwYirirs5BE08k5PkxdqK/PIVZTMaORXv3tD/aA6RJL0Cv/FwTBIegJJmAHPTtGnkMOvoczAGzUPBvKVSED+2hs6R7gxbeMyEecN80mChfH/F3PE+6bii7MFfI2F6LIG+e7DgXccpBlXihFGz6BU8eeXBIskqg= 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 1724800848262567.082759491685; Tue, 27 Aug 2024 16:20:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TM-0003Xo-AX; Tue, 27 Aug 2024 19:19: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 1sj5TF-0003FD-2u for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:30 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TC-0000t6-6e for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:28 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-201df0b2df4so49647495ad.0 for ; Tue, 27 Aug 2024 16:19:25 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800765; x=1725405565; 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=S0CJdxvDGa9NA73ICq+2YegGu+s3jbuadw3iL7vsbu4=; b=mA7vKSw3fA8GWg2kzHhzhJdMEHdfoaCKayDBrG0nTWoExDDagFgrIATwKxUKug3+DD it9krSVl8LiR+Q5jJ5SOuhDFQjDXE0DDt2I51FqfaTcXYZxtT3cw9kxZnZZLJmXLuZt5 dIx1X5Fp3PWsU/jWDQkA5BVLrVKi0FVpHI+bJ1sSQyJn6uWnmZBaBIYUiqJq48trKkOb 2Bfs+JsbJc32ca8nWwKC3NokfJFlX/HobMiYny4c5y0E42TX91G6CXdp7mtI4DO1axfw 1k+azkWtfqI+JTiV0E2Q+SjNt+LMQQq9Pn8TU4OOVVN4AVadM38tfV/2UH2ze276nVgk Ee7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800765; x=1725405565; 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=S0CJdxvDGa9NA73ICq+2YegGu+s3jbuadw3iL7vsbu4=; b=ZCd2fdsSiuXIghrI1YnVnrv6CZvzKP5U4hDjxDj4WSZRaKw2pgMFdPqPrhnlX9X8sj m4gPDXxlef7S6j+d07Ti1HjqENE8kXq68Ob2UKxMPyP/GuhrbkTBghxrzw74hydwwrtj A2HJ9Q7067n0WfQWbjCW/iPZrY4/KBS4GSQeiQSkacgVczoyw0mPpVaxrTVbnfk9t/E0 bdV3kp2DJkaAbfO5R3IWt+vfHOmV9FVfyspIt4JvxxrNqVXpykBfU9hUVfAcUnSAWqiC 7wNCSIsFIACK8pTM0slrrZKTmBtie+uLV+l4AIuG/1wCuaWRB8lVaBvTtgYMCfRn6j8/ Yt0A== X-Forwarded-Encrypted: i=1; AJvYcCV8jdsGGhvh8pG0msyuIEJtsioRMqG88Kr/+WJTYPVFc4O0tj515EOqQScNFp1Xzs0uD1mFD13jQJaG@nongnu.org X-Gm-Message-State: AOJu0YwVJeSIhYWEskpex32wW5cmcvrvHzb5sVWCJW24YZLHMa2VF2UH Sv3I0OLgGYR3cJGh9KIRXnZJmROgoYlr+6QbGLRo0KOIW5ocV3DDADFReX0pi4A= X-Google-Smtp-Source: AGHT+IFSZq/rbYzeW85lPDBmJIQSJKx5QRaQ2i4fbbjymHckbPA60ScMDdG82KjxTw5tbhdwuyH1Kg== X-Received: by 2002:a17:903:2445:b0:1fc:327a:1f42 with SMTP id d9443c01a7336-2039e44f7demr163597675ad.6.1724800764579; Tue, 27 Aug 2024 16:19:24 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 11/21] target/riscv: Add zicfiss extension Date: Tue, 27 Aug 2024 16:18:55 -0700 Message-ID: <20240827231906.553327-12-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62a; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62a.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800850326116600 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 | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 8e1f05e5b1..0dab110a3f 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 88d5defbb5..2499f38407 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 ed19586c9d..4da26cb926 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -618,6 +618,25 @@ 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 (!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.44.0 From nobody Sun Nov 24 06:22:19 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=1724801008; cv=none; d=zohomail.com; s=zohoarc; b=AmLOV9QrnWPqnqNcq9SaRQFyrR6RfFrGDN20zxehh//U8xhvllWe1GHGTDZR97fSk4xRbTuowlbEK7jXas4YaW4qchT6Mo9f6IyHxMkiWGO1O+JppIvDIG8Mx16LEzpQNmLACeiHtomkx82Z0DgFXZzz4tLCgb0CV/U0lEHutXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724801008; 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=xt8tPHRhEsX6UWlxFxKrwKdVADrkbOwbkq9Tk+hkRaE=; b=S42ahyU4U8HAqVEnrqnyDq9aWhYQuSn5NAaxm4lLxqMkhZTsYa4FoLEd53VR+rmhehEFetBQSN1ZkM3kONjcwzOQ9K2BBx7a+XvYVAiLvUSR9BUwGyAKrxT5aBKu+2S1D6Oy7FcvGvRD9uDj841x5gHyS0W5Sg88Npf/VOt+dGo= 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 1724801008345912.5754934361474; Tue, 27 Aug 2024 16:23:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TT-00049q-52; Tue, 27 Aug 2024 19:19:43 -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 1sj5TH-0003Nq-51 for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:32 -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 1sj5TD-0000te-Bt for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:30 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7142e002aceso4986525b3a.2 for ; Tue, 27 Aug 2024 16:19:27 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800766; x=1725405566; 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=xt8tPHRhEsX6UWlxFxKrwKdVADrkbOwbkq9Tk+hkRaE=; b=abdTMVVmTHe58YNhreEDGoP8uLoumX1yqUQR88hBqGEazX4wEIdQXEADmXr6w+mTPz 4L3NUpqfzCHgztVsirJZ05JGDhNWAar89iRsM0X35G1jlU8S6SDknpelgraD8N8locL4 qr/UvghZtuZwxBYyuU4U12OtwcHZFD2SJhY/MKJ9TCZuOPyVmpMOyWCmi4Z2Gd/CU64D lsecMDj0ipGkktZygL1DRjBpzvagHqkCNVzIwSKQiPB1/sbBNHwIl3iXTAEQy5Cc8xbb jSz2Th5NHlcEgvkMpKe1YPHJ/w07w1BnDMgCo/LQFYpFAFkgQdm9poefPyKdR8BZf4HJ 9MRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800766; x=1725405566; 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=xt8tPHRhEsX6UWlxFxKrwKdVADrkbOwbkq9Tk+hkRaE=; b=a/X9tDNI2B1Kmx7FwhcvylfphbANSnhjPxS7dqSn7WKD4RS7YoWSFAKqg1DAMVEUuv GSnwEHA/QA1EgH8nXom+Nt55oXySFUxgol2WIk8ya3KnD0O9iyVt2IoY1MZLJ97D6xKJ x6mQ3PAAh/itDFmCKwY9R6cNcZot0Btwq8W+J76NnYA82qB1CVsTGiqpaAzytB9IenTA JSCe8SYLhElFYu1wDlZyEXtVQYtEET8UayP1v2p7rlvp1uOsIyjaX4lwwImsAJmoNqKA ORD12S+Sv60y+XGFcxBcZKrD2Wg6dmPNen7OXVPWdV+GW1V8zUzPfPYPDOzaEBo9c5st VEiQ== X-Forwarded-Encrypted: i=1; AJvYcCU3pvsCXyKZ04NBOMyLVfRvO8tB5Wkoz2NHCo5JH6R7v8C0PspNggqAj/f6GA/9NoBHyhZ4utGLVQRZ@nongnu.org X-Gm-Message-State: AOJu0YxjxySgPF49bfVooKLoGat9cmepO0cnC68zFSjbfjI/ob0BcPYd 5tyYtPRJPf4g7dPzRgpokqgUcx+5gX1Db3kMuIUYzyLPRjQn9B1H2Gqo4edg5N0= X-Google-Smtp-Source: AGHT+IE/4szEjw+xQwOCxzJvozXaViTWIrmUBqnZTRQgtoBAu7rfppQr74iONlw2a8KEUnYBDpnLTg== X-Received: by 2002:a05:6a20:9f91:b0:1cc:c27e:bdee with SMTP id adf61e73a8af0-1ccd286f4acmr113388637.2.1724800765863; Tue, 27 Aug 2024 16:19:25 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v10 12/21] target/riscv: introduce ssp and enabling controls for zicfiss Date: Tue, 27 Aug 2024 16:18:56 -0700 Message-ID: <20240827231906.553327-13-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724801009232116600 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. qemu-user also gets field `ubcfien` indicating whether qemu user has shadow stack enabled 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 --- target/riscv/cpu.c | 3 +++ target/riscv/cpu.h | 3 +++ target/riscv/cpu_bits.h | 6 +++++ target/riscv/cpu_helper.c | 27 ++++++++++++++++++++ target/riscv/csr.c | 52 +++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 19 ++++++++++++++ 6 files changed, 110 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 0dab110a3f..d6cdd81fd8 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -998,6 +998,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType= type) /* on reset elp is clear */ env->elp =3D false; =20 + /* on reset ssp is set to 0 */ + env->ssp =3D 0; + /* * Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor * extension is enabled. diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f372a4074b..4ace54a2eb 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -224,6 +224,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 @@ -534,6 +536,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 900769ce60..48ce24dc32 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 @@ -754,6 +757,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) @@ -768,12 +772,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 c3820eff8f..f7e97eabfa 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -91,6 +91,33 @@ 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 (riscv_has_ext(env, RVS)) { + return env->senvcfg & SENVCFG_SSE; + } + return env->menvcfg & MENVCFG_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 on if hart implements */ + return true; +#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 a5a969a377..ec04b2b32b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -185,6 +185,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) { @@ -596,6 +615,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) @@ -2111,6 +2143,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 @@ -2167,6 +2203,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; } @@ -2208,6 +2251,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); @@ -4663,6 +4712,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 873957c4ab..84d5ecf436 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -369,6 +369,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, @@ -442,6 +460,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { &vmstate_smstateen, &vmstate_jvt, &vmstate_elp, + &vmstate_ssp, NULL } }; --=20 2.44.0 From nobody Sun Nov 24 06:22:19 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=1724801029; cv=none; d=zohomail.com; s=zohoarc; b=OXtAXed0PkOqR/oqxI8gAeMoV0/biDEUklrt+4F9AYgtvhuOpVaHk5/fm8QYkJ38XxrBnE8rKk/QWFgLCTXrKcW/P4IZgJaH+Wse+24mLvz4iB22GLfg53E3FKTZbPZeraEHuBKPZsv2ygPeZmgQKL0aEAudp7uh8Cr38b2YqnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724801029; 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=uqFlP0luzPOIPv6o8uMxmJcQE/TtCWtRiNQMFRFBMB4=; b=QDVyq2vpY7wndiA+yjJfbgudrvLXgDSMV3tzotz4XqIZrQKiMreDnY13B6itIJlmGALZspnvB4vgO3GPPGTGhmNJ9268aoPdU448E49Aw0NY00VCVPMzMQgdqIIGHpNS8rEQG1GCRKdLXgSPA6xZEC3bKEVgRHo5UoNwJxoYQTs= 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 1724801029285880.5876508136306; Tue, 27 Aug 2024 16:23:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TY-0004Xd-KM; Tue, 27 Aug 2024 19:19:48 -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 1sj5TH-0003Qr-UH for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:32 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TE-0000ty-NF for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:31 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2023dd9b86aso48558755ad.1 for ; Tue, 27 Aug 2024 16:19:28 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800767; x=1725405567; 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=uqFlP0luzPOIPv6o8uMxmJcQE/TtCWtRiNQMFRFBMB4=; b=kKKO/HwRSM3NAvwQUOQg/+UH1V73RgRZ68Pp56wWDMeL/9TfFnLYz5NrfhqFo+S4CA 4ZZP/2LH0bVlK/BsACi/6OfUjWCz0kEXA6CPSGoB3HjKd4iW4cCgN+I/IQXai94M4k3+ reB0sbYGNkQ/hab9Qp9u5jALylV6S0mRePxSbN8iXMBJE97y0qHj1889P+n9C21TtLZM u96H8DJhXLYTMRUXznsY1NJc6XiB5ndbzD+6f8fA9ZSDPZ5PYwDg8PBNnNZumpTFag6s 2FI9VgVek/avcped6w42dqGHQMrEnJzpX5yzpWkVUkupRZQUs5RSGHpbyeQNgP86xO+v Y6yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800767; x=1725405567; 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=uqFlP0luzPOIPv6o8uMxmJcQE/TtCWtRiNQMFRFBMB4=; b=g0opdgooPFsxqUSL+cKiieiZ4m0mAmeLPbXaTmqtxKpgGg5luOxy66m21TrZEfOjgA 6jQAhafNKb/CnE6lEPhYlSbEPrnya6e7aD0sOSoYlQQcAQP+WjecaXE+a3AzW3pe6EDN xvCcD2PzvO3JvyoOJ9T+9te/xi4NaXmh3GqlAdwzdg7Hz+/xTm14ImoKwgSs9OWvNDz3 0TRDXq03pHfv9BsehbOU01zudBodDkkIwmkor1zlE1bigiXW0Kig310keY3RM3D3PAcq 8uwWi6EJNJxZ55y2nG4a/Gmdhx2NYAkGWTO9ZPO0IY2QejCxpxvGT4dNG43Pe6gbu69/ OY7Q== X-Forwarded-Encrypted: i=1; AJvYcCXZIVtCoc56AL/G1MtVluQSgxfcCUxWiIFO8AM2HKAyB6e+yGzdcqd1shLtud9iSzeJOylZetb4B2ou@nongnu.org X-Gm-Message-State: AOJu0YxfG2CNfQrgIzzHV1gzVoyiVV7UxiljSQfpGYU7q3iS/a4q17eB t+kMEpFAQtXMHFs0E3WRimg3GLakw2r7mwgc8ZEtkDyF76oe144sjaQ27YAOCJs= X-Google-Smtp-Source: AGHT+IFDLUOwwEanB+EVZrCkNmaPQ3nDOHjVAzTnERXQ0j3ZT4dHi7/oB3nfq/3/PaIgZUaAep0vnA== X-Received: by 2002:a17:902:ce83:b0:202:435b:2112 with SMTP id d9443c01a7336-2039e4c4413mr173109475ad.34.1724800767092; Tue, 27 Aug 2024 16:19:27 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson , Alistair Francis Subject: [PATCH v10 13/21] target/riscv: tb flag for shadow stack instructions Date: Tue, 27 Aug 2024 16:18:57 -0700 Message-ID: <20240827231906.553327-14-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::636; envelope-from=debug@rivosinc.com; helo=mail-pl1-x636.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724801031082116600 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 | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 4ace54a2eb..e758f4497e 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -612,6 +612,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 f7e97eabfa..be4ac3d54e 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -169,6 +169,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..b1d251e893 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,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->bcfi_enabled =3D cpu_get_bcfien(env) && + 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724801015; cv=none; d=zohomail.com; s=zohoarc; b=ktWX6AacP35W0syUjJVi/DTrvm6YNTqf4bgptFaPpdkQV1zH3OddaZFUWH1PRFHYJHg/CqTIwMtfTShdjp6FsEf6wHHnGoQOp62yFvL6Rbnlzm6VOLkl3+w5+K16rItiRBEgsu0UEkIbHZxtpKhdAzpYqAfWp20DuB1MZ9aRKwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724801015; 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=nfT0nIMWBIbJcaqmjwnW5/0Iuog81wXS/GOvLXNs2Eg=; b=FsgSe2lOxdVzqQdhYN3BbLl6CcvEquPBZUUiHGL0Tv+76LReWF8DOYRehyTMQTzHowTWou/v+8N4DqSGsjdgnVEhEZNUpePo3lMVlWhdXscdBYYpHKS9YuAVA1frznzEssJN7/ILtsKMZgBDmEEJn8eew4sKBMJLimMiQdWIgcg= 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 1724801015452155.95187018450042; Tue, 27 Aug 2024 16:23:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TY-0004Vh-7a; Tue, 27 Aug 2024 19:19:48 -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 1sj5TI-0003Ta-Lt for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:32 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TF-0000uJ-RW for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:32 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-204d391f53bso23328115ad.2 for ; Tue, 27 Aug 2024 16:19:29 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800768; x=1725405568; 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=nfT0nIMWBIbJcaqmjwnW5/0Iuog81wXS/GOvLXNs2Eg=; b=E7AUk+LAtyNyud2sVlP+kEhLSjkCTD+IiQylzM2l5wZZO6/KEn/diLOnrNb2eGL0S6 vUpl+Ygfs4KeZr6hvTzSNjz338hYIu+5Pp2kVUmJKrQ2XeQxIOoWp6xGtIDaE170dVRA IDjoAPiHMF4iwlKhX+kvLXr6kDXERCf/sZns7u1nXLyXgOQIxyorBi1nABuvIDknvZIi p4uhRYzd6QEFpleC47yUeWWviHVeXw1cGXCahO/ASLgtr8bfQDGEJEUP1s/FgiGDEasm pqPEE8nJ1RiLknsq746+T2vZMJQ4ZUH26gzga6AWfCA4A8yyOtNcf6PE+1g1uyg4Cc3/ InBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800768; x=1725405568; 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=nfT0nIMWBIbJcaqmjwnW5/0Iuog81wXS/GOvLXNs2Eg=; b=JeeSoCGt7KfdH45gwSrTPk4ofqUktlpBK3FoQDMxBozgTdoa3SXKLPpzoYnzYQUjFj SjRqs9syrNO/9Ko7lxszSdUqwLgW3SOhLGGW2te3/W5EtEhQ9kT0FPycIxG8xV3ldHDB 9ZmyNQz/KaNp8BqbBbl6AIWxXoLA9ZdOXltk6d0G/dw5KUysA5INeBor3VxFSU9Xq89C F950rs3R63CY/OOXZJNL7eqXN4V7FbRt+er1M0+st0NRgM5qMhTYpOkLALka5IjStwMG nTS5u9nsEq0/DTVKAHHatWKb0lMtRo2iq2e+bHcoCMuMkZCM0CvgEDlUAlghl7ilPRNN X9rg== X-Forwarded-Encrypted: i=1; AJvYcCUx6DfipZ7DjcBTN9Ioc7vuqH/aVTQwC2XDzn6dPZ0+oOVug3AiD85XkFmR0lYiAnKVQLk7duyasPDN@nongnu.org X-Gm-Message-State: AOJu0YzJQGcQ0ONvsOlQo3BvNzgrCzzLM+HeND1xYI0Akb9X3LhuES7B 1zMMCFGRxr4TKCV0zDT2EuLRpiGkBVZCkh0dGrCNPWP3DyxnlcILR9v/F3MkB3A= X-Google-Smtp-Source: AGHT+IFfDeExli8LfndZkcAGzdCONswFKV1tE3j3B3hynZl3Pq4wwsQZ122lInma92kEZIu+CbIegw== X-Received: by 2002:a17:902:cec5:b0:203:a046:cb7e with SMTP id d9443c01a7336-204f9c6c567mr3935715ad.58.1724800768264; Tue, 27 Aug 2024 16:19:28 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v10 14/21] target/riscv: mmu changes for zicfiss shadow stack protection Date: Tue, 27 Aug 2024 16:18:58 -0700 Message-ID: <20240827231906.553327-15-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::635; envelope-from=debug@rivosinc.com; helo=mail-pl1-x635.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724801017069116600 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 | 37 +++++++++++++++++++++++++++++++------ target/riscv/internals.h | 3 +++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index be4ac3d54e..39544cade6 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -893,6 +893,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 @@ -1101,21 +1103,36 @@ 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: + /* shadow stack writes to readonly memory are page faults */ + if (is_sstack_idx && access_type =3D=3D MMU_DATA_STORE) { + 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 /* @@ -1160,7 +1177,7 @@ restart: =20 if (!((prot >> access_type) & 1)) { /* Access check failed */ - return TRANSLATE_FAIL; + return sstack_page ? TRANSLATE_PMP_FAIL : TRANSLATE_FAIL; } =20 target_ulong updated_pte =3D pte; @@ -1347,9 +1364,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800869; cv=none; d=zohomail.com; s=zohoarc; b=j/CgrNZmb3y2W6YORcnYXjg1HlKQlJB5+XJJuPpFE8CGUhh/v0z+EiT8J2T+oXfsUmoM3HGVrPY8zESm5zv/Ls4ah7u8fq/BiXOsn+g4l8yGmmcIDSyWPNFNiCTf3HLN6W5bemomcuUer4CD86Zh+PiyBa7KMrjjosnit/pSrOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800869; 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=CPEmPHl2xgwIfEQ7uy7cB8ioUnOYYkMxclwoAyAzOsU=; b=LFUfQ6EhHcYwhp9lBctoeDUh4/LCAUbkRv3rxLHb4yK1c/jMUJJlgazNbo8Ldi0iqgPt48qju5MQaT7yFw8IyI+fOApV8U+yWKpdiqlDARaBsHL4DsmjEpesdzN7Q45QCcg/ONQWQfzAQHeLRJYC6fz8W0HcXKteL65WDrOKN2s= 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 17248008691160.0376104112702933; Tue, 27 Aug 2024 16:21:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5TV-0004LJ-Ln; Tue, 27 Aug 2024 19:19:45 -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 1sj5TK-0003ar-D0 for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:34 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TH-0000ug-2d for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:34 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2023dd9b86aso48558975ad.1 for ; Tue, 27 Aug 2024 16:19:30 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800770; x=1725405570; 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=CPEmPHl2xgwIfEQ7uy7cB8ioUnOYYkMxclwoAyAzOsU=; b=2GuPyW4R3kBzH6dBChnq8d2H06/RybQ2VhIm3rZAQCd7IkLCFhelAn5eE+SBwIbNdW ECzPUfuz4MX+E5ZmjGwFqDB2ZUtyLvJL82x2gAsTr+K9vx1HkTkSlRptDUQrnh7KGKfF dF33HK4PXDJLL4V+Cfu/rRSZevs0uXEkFYhGV8o9IP2XCDYs5WH+E7EiaGKQpIaptMOu ymWCGLxlzsvwZK2gJTkfiUrFIrN4GZC2hdiNilOHzlSmg8NWrfu8CreqUx98Kt0Bk8me f8BoZrNn+WiO7BGoFNK0St9CQG7jFiII79T8FmZqBWomdnyVlUqaDdN8TwskFHBlRKqC QgDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800770; x=1725405570; 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=CPEmPHl2xgwIfEQ7uy7cB8ioUnOYYkMxclwoAyAzOsU=; b=N7gkO2RyEWOtJuX7pDDYjP5lB96WZm1FGCyjaeH9JyxpkHF68bS2nNlcko7WHInNMQ 31C35EnzwxSx44pcwSvkWseQhJSBjP/EWKn9Dpowcm8k4A3paGlNZE7jmqQaZzX3vrMt B7OBByrfTk4RRVpwW3UH1Pdo1J1fkQ3TgBDIw9mKlG6QjlJu+DoVFB5w5DWYIkyovSo3 J0/lIgSr7gxvETL4GAaJR28gqiY9vZ4ftTP+9wbJlVAAtxdaez1hPJzRac7Uke0Xtl9T Vii6dKQEbn0BjnKkqvsVSvgEVcLx4qW9H+cfZMljrXh6iZSEClTU4ktyHlDXQVEnn0iq dIqA== X-Forwarded-Encrypted: i=1; AJvYcCVqtEobmFAbtMJCTaVeqHt5QEKst4xeR2fqKkNe+WPbMc+PYKrh+pu02d2JQoFWvjizCy1CNq3k9l/h@nongnu.org X-Gm-Message-State: AOJu0YzQ9+uQTNr7Mtei58eACJnnHuMtl6Q7H+49SGJ6GgmfT2k/Api4 KrsQAYBZWiZHU122JamoR4FanVqTGNrrtxSkHhaAyq1xHdU9xWmTS++tTfmb0F8= X-Google-Smtp-Source: AGHT+IFTy9uzfajm/Vdt3jmSRiOqnHAp/6ELhPnLFs4Ob/ZKK3uV2xBVQXmFLV9b06tnOt1gIqxorg== X-Received: by 2002:a17:903:22c7:b0:201:feb8:3444 with SMTP id d9443c01a7336-2039e44f06amr209802105ad.2.1724800769605; Tue, 27 Aug 2024 16:19:29 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v10 15/21] target/riscv: AMO operations always raise store/AMO fault Date: Tue, 27 Aug 2024 16:18:59 -0700 Message-ID: <20240827231906.553327-16-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62a; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62a.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800870615116600 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 --- 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 e758f4497e..0a13604e37 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 @@ -226,6 +231,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 39544cade6..8294279b01 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1741,6 +1741,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 * @@ -1752,6 +1768,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; bool write_gva =3D false; + bool always_storeamo =3D (env->excp_uw2 & RISCV_UW2_ALWAYS_STORE_AMO); uint64_t s; =20 /* @@ -1785,6 +1802,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 4da26cb926..83771303a8 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 b1d251e893..16fff70dac 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1265,7 +1265,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724801009; cv=none; d=zohomail.com; s=zohoarc; b=mgAZVTN5t5q50xImgQVdpxoGDDWo0jBG2GXp6gngw19hYyB0MHUqH6KB6SejRalsk8v6AHYz51PiuBwn1Me4dsWE7CCBVXDQtbBL9oH8/arJdV7FC80cg6EUS3lT92D5qzWVAgsRvY+cF6P1VcIT1OZ9M5DyV9/yymvrjRWs2F4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724801009; 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=gNLF33CmIh59bGEa3lPU1W61qqDznaH+0Q0hzd0+oVg=; b=kFtSUEs2XMt8swpjNa+DC9pG33k6Hi7VXQvISHuZsAJgSm1FfRamWT/YTEsOf8YRLavXdxk4/61Bw/aclZTsslf+MxXxagVM5/uKRytEuBOXvBYA+erzmJmuAdxsEQU7scDGmO6h5O/ZU7KX0HFkjbNUB0dQS/AK8opExipxYiI= 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 1724801009630940.5705546366707; Tue, 27 Aug 2024 16:23:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5Tq-0005eV-5i; Tue, 27 Aug 2024 19:20:06 -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 1sj5TK-0003dC-UU for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:36 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TI-0000vD-DQ for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:34 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-201df0b2df4so49648005ad.0 for ; Tue, 27 Aug 2024 16:19:32 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800771; x=1725405571; 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=gNLF33CmIh59bGEa3lPU1W61qqDznaH+0Q0hzd0+oVg=; b=LLRp51kjFaINK0gl4/N3aqjNUSETb2v/Tqc/4dNd3/3F38el2FGMKTz2iaIOnzc2ab 6bjfknzPZ+XPGmLM/wpYVu1yIY7M3ndCYSwkaSFTIAiofDYWBJfeC1shcPjIxkk6x+FA z/D7SFLU4DfXxw6n1Dxx9QmLOr8q+/ZOlmdJoKZ6TOYED2IcFBO9xfHgpvN1Jvp8yGrR mmGMM9FO8MWnPqJ1D9T5m6Yyp8iiu+l7LBFhiAVM0q/bbwZnAmEZOooXLoH3KRNyy+qS 6CcS/Y201qaJv3eCnHfGYGgPhMjLAId5mEO3lhC2AVsPNZKnCcO8IDAV0VTJx4S3oGyp 7nDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800771; x=1725405571; 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=gNLF33CmIh59bGEa3lPU1W61qqDznaH+0Q0hzd0+oVg=; b=quePwPzS3bOMpTunXcK14RL3D7qTMU6w9K0BHO0ZbnpUPPL2aUgTbvuw4iDSn32Heq s/4oHpJGaZR7VSHqUWlaMAEU/WdnKMNYwn35EL/NaT9yrNkKN3QUR316NkI0VZKNBdTF paQVoVi//nfwufdEp5WqPHgQIrqmZztwXG8LjC6TUjCFP1TMYp76hQ3d3VI8PTGsBqnD 26c7uEd5pGKrZBrfdUH+NReMZ6q+RZqCa6b/PYaZTV1E/3P5osqhcddYgng0mAGZCSCG C8DWMGG1Y+KGAE9Zh1X7h958TnorP2bFs1qIhtsNXeJdlvV+TlwXD4/fsqJs8YJc5jqk U2Rg== X-Forwarded-Encrypted: i=1; AJvYcCWc4HmQyuKodp8zWuQKi6Jx0A6eT7xPwe3mxAqlYYHd7KeQNqFqBKvh/XmvPfkIMNf6VkOiv+tdEj9N@nongnu.org X-Gm-Message-State: AOJu0Yzi/XZbtY5myA6dNXr86Z54ZWs/OOetnwp8+qynR8+O5xqyrF8N qJIm4Ei3A0M1PbGqfsGjuVwY7jtAciAJ17sBOwgkJioCCrCUHjIc/6fnEzEp6ew= X-Google-Smtp-Source: AGHT+IFWLA6Vc5pSPo0XHbmxJDa8xq9LHYKtE7sZaS2GMRQGQHW2qDe4pKqMXXqCb7b1WJz21nAugw== X-Received: by 2002:a17:903:2310:b0:203:a22d:6b49 with SMTP id d9443c01a7336-203a22d6dccmr175721515ad.8.1724800770796; Tue, 27 Aug 2024 16:19:30 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v10 16/21] target/riscv: update `decode_save_opc` to store extra word2 Date: Tue, 27 Aug 2024 16:19:00 -0700 Message-ID: <20240827231906.553327-17-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62d; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62d.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724801010961116600 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. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson --- 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 1f5fac65a2..d779ec75c7 100644 --- a/target/riscv/insn_trans/trans_rvd.c.inc +++ b/target/riscv/insn_trans/trans_rvd.c.inc @@ -51,7 +51,7 @@ static bool trans_fld(DisasContext *ctx, arg_fld *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_ld_i64(cpu_fpr[a->rd], addr, ctx->mem_idx, memop); =20 @@ -71,7 +71,7 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *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_rvf.c.inc b/target/riscv/insn_tr= ans/trans_rvf.c.inc index f771aa1939..084c184e65 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 b427f3a939..a619ea7c0e 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 && (ctx->cur_insn_len !=3D 2)) { 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 && (ctx->cur_insn_len !=3D 2)) { 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 16fff70dac..e677062a10 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800896; cv=none; d=zohomail.com; s=zohoarc; b=Hk8awP3aZv+eju3o2+OfKHzBPhVZTun0gUGoSL3MizxvwsmWyery09M0zK3Ze5O+OIHCJ/KF7XEPMSOcYwugReslOPqjLi+wYkYl0KKnGP3M/vAPpIaoumvATElI9pjcfF11dQsRG1sHqTFzT6JMq6iB8Rp+1LKLaxOLOS7fdRo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800896; 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=Y69mKXxyPX8y1KNCgiTZCjHNjCyFk/Zv9Q4fHwap7hc=; b=J7SUWMhlmQ0KwsCTLXhrEhEbE+gUM5OMghFWy2bJi7UNK5WkMaf+ESamZCshsAFCEkcicM9KgsYjYX+0pIOIhjlLMJma8Rma0d95EaVI5Vdj3hH+TfHMYmcQSsT38gDhZqNph60EIfyzk/clZ6Qim/rQJlyGv1MQ2200zsheOeQ= 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 1724800896788144.84016064557318; Tue, 27 Aug 2024 16:21:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5Td-0004lA-Mq; Tue, 27 Aug 2024 19:19:55 -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 1sj5TO-0003qh-F1 for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:39 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TK-0000vj-NS for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:37 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2021c03c13aso421485ad.1 for ; Tue, 27 Aug 2024 16:19:33 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800772; x=1725405572; 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=Y69mKXxyPX8y1KNCgiTZCjHNjCyFk/Zv9Q4fHwap7hc=; b=e7v6WGyPl6qoTdWAriP2zVpi2Yk7n2UPaHIJR8Nm9SSok8b3OV77sQYGvp43SWNGzG NvN95zvAd5mRCeCE4umfd9C24reFKFI4UpCUpsdGIgfgVo4ExEBJZRkZxNt5bd2CP868 k0fxCjN6n1/3LQ5fnyM9N7e2UEtNuLnacrVp66XhHwqAJm1i9vJdP5tpKP1lz9wobZzp rw+BwICqpawUdGM30DAfRffqbK3ew9fvGpMQ+JTt99lzKb1nEkAdqRDRRUme9z4ZLElr hwdzQ3XjVM0N6dbHc1XrNQWO2/JziRDtXjVlLBYQnFxLTV9ikAPN8cdQHBSdGRJQvRNb UA3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800772; x=1725405572; 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=Y69mKXxyPX8y1KNCgiTZCjHNjCyFk/Zv9Q4fHwap7hc=; b=Eua5hIVawcnHkCwMZFxh72kmLfhIFEMGOVxet1UzGwwmvYaW1AoUWVTLVHEdPJ0ODx tf6sJ7udWY4P9USbOJXWuGPPBAJKEHMdv/ZMUCTGSBND0TGQtbirj/zDEBh/oamdQINO GTETKE/txeuOFtF+1cW/yHN60bjS+Dwim5I/HLlGlUiNkJImSTPF/pMdZtSc7F4io8ax 0/CsbL+YlFjlWeU1Bjgjupgng8kmtgrYGIsEiHMZxclw3madCPaBir8mBWjeErIziBg/ kGytAMhJZh/q7gqGfTDA5OcVq/Sr99uPxKV6AFKHwy+wKXB7ExjuEYwFQtWretWhBFTe VvzQ== X-Forwarded-Encrypted: i=1; AJvYcCXfC9p/w3zbVs4WJ6TzrSizpcT0pcstu7J6pJo55zQIgs/kP0nC8zrFNirsIf4dbU1GOdlZT4Lb0Rn1@nongnu.org X-Gm-Message-State: AOJu0YxfcLjNRXetYGlWJ1JtCgwS6Lo0o6r8XLBW0bwsm3lUAJHQTUUp KmU7QyldMPuqkjMHiGbCajkz16Rhg86Ebehge0JDDvMn2tUnPnd3OmnLVbqxHJo= X-Google-Smtp-Source: AGHT+IG6Q+dwwX7azFm/DSDG1jmZ6dgq06aT29bI97JO994qJ0E+xHgokrI3XBlgIjyeRGHMCwKCSw== X-Received: by 2002:a17:902:d490:b0:1fc:54c4:61a7 with SMTP id d9443c01a7336-204f9c868acmr5685295ad.23.1724800772021; Tue, 27 Aug 2024 16:19:32 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 17/21] target/riscv: implement zicfiss instructions Date: Tue, 27 Aug 2024 16:19:01 -0700 Message-ID: <20240827231906.553327-18-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::629; envelope-from=debug@rivosinc.com; helo=mail-pl1-x629.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800898706116600 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 --- target/riscv/cpu_bits.h | 2 + target/riscv/insn32.decode | 21 +++++- target/riscv/insn_trans/trans_rva.c.inc | 39 ++++++++++ target/riscv/insn_trans/trans_rvzicfiss.c.inc | 75 +++++++++++++++++++ target/riscv/translate.c | 5 ++ 5 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 48ce24dc32..bb62fbe9ec 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -690,6 +690,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_rva.c.inc b/target/riscv/insn_tr= ans/trans_rva.c.inc index 9cf3ae8019..a2119393a6 100644 --- a/target/riscv/insn_trans/trans_rva.c.inc +++ b/target/riscv/insn_trans/trans_rva.c.inc @@ -114,6 +114,25 @@ static bool trans_amoswap_w(DisasContext *ctx, arg_amo= swap_w *a) return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_TESL); } =20 +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_amoadd_w(DisasContext *ctx, arg_amoadd_w *a) { REQUIRE_A_OR_ZAAMO(ctx); @@ -183,6 +202,26 @@ static bool trans_amoswap_d(DisasContext *ctx, arg_amo= swap_d *a) return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_TEUQ); } =20 +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; +} + static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a) { REQUIRE_64BIT(ctx); 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..741459003d --- /dev/null +++ b/target/riscv/insn_trans/trans_rvzicfiss.c.inc @@ -0,0 +1,75 @@ +/* + * 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; +} diff --git a/target/riscv/translate.c b/target/riscv/translate.c index e677062a10..2753c154ba 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724801024; cv=none; d=zohomail.com; s=zohoarc; b=TNYFM4OiR2NkYgPGZwE8LLL0/frwkHryuknQEWKZzZjEfGYiE3/CZGGYrMiJYc4e92YI+fy6qrnhYjPXpZKF7u2kDULa0tizWCPcpIk4+IzUpcRXbQJnAWqND05M6kEi4v7bpuy8ZY1syRwY4gjy+oJPUPe/sD6cy/n2Q463Qc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724801024; 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=8Cl5ZRMk7pbT7QMKFwfdbtGEqWg7VKl5rT980Ov9IbY=; b=W4JDR/GT7oDZZIPOb5kLfGyr/HZC0H5psTdmwxr11OjJ9HDCHlsyLIaEwX+C9R33pSq18aiEVdoBiKWfPP/i8n2yVDJPe0/coCI5AwXhSoV0cZzkYa2sOQ47EU0JXkKfDCWo6h8adLMM/cjRKNovUspio/w1ArQxg3BaPZhZjvY= 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 1724801024524685.4522130400433; Tue, 27 Aug 2024 16:23:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5Tq-0005a0-49; Tue, 27 Aug 2024 19:20:06 -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 1sj5TO-0003rz-Pc for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:39 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TK-0000vs-Sy for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:37 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-204f52fe74dso3055475ad.1 for ; Tue, 27 Aug 2024 16:19:34 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800773; x=1725405573; 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=8Cl5ZRMk7pbT7QMKFwfdbtGEqWg7VKl5rT980Ov9IbY=; b=DU4wPHo1CTfZ2dDQxD19WDRvziwcfBmJctdAK66B3miBUIjIPrKlbje5IH1nxRPr11 jj6EnU8P06rwUb6P4ylfb/x4VxOyEA7wz6U9oxemlXxqyzIiM5zKXrpgk22c7QaOvFsB i6MNq6PvvV3cqCxon86OZ4g5ugtMxKHM33hP2lJ+HZD5JP7prpeei51SGoByrq6Q5yQh 1TyylWh94+KAOws1BgPVs9ad2JRlRtGyFI1ewJJG2vFHei+IZb1mhOAlIA8mzBqHfVtD olYndsg37IGS2WewRqtxBDF7jMljf/QwS30BPQ3Zmw5h586D/dK18TO2Yx1YMqvPS/z/ kc5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800773; x=1725405573; 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=8Cl5ZRMk7pbT7QMKFwfdbtGEqWg7VKl5rT980Ov9IbY=; b=P8d7N8iCVWx1cc6pEZq9XI5w6m+zTD/UIcN2XfQi/Cc3iV4nCNArwituqQfsCBCy3O ajJsv2y1VJY5QyWLsK8G4e7FgUnb2jNf1W1QCO+YeeOtkZW48hmhDxP9tZkXe6aPGsNw uXJ93EqNj3rnOhALYpWva3RsTYke2hgHre1NPDGNcCIzv8B4No03QZQdhrd3zjm+zqFf S3c6/aWDtt53wTZUyxRJsMsSbE03ANsC64iw7vbtPCtM6McCxCgT7UclWs6VlRSlYo2F mjEoOHuqe5ULiW4BWazPXSVjVllUVL5TmgMh03fpaP9NmP8CX6oDpYHsikS0b0ZAO4/k UaoQ== X-Forwarded-Encrypted: i=1; AJvYcCU/F5QtoL2ixcybm4DC6C8HWpsYw0RHhRoL+dZOhPoLOTYgdc+aWg88fLgbdmo8tNZAta4goMCUbfhF@nongnu.org X-Gm-Message-State: AOJu0YwdizI6QKI9RPYk29v5YVOxXUW+OdYet2LwxzqiSP4HEQHGXse8 Myk24aK3FJ3ifC4iNwjbiw2m99dkTrJtM0rSd+KRFp+WKj+ezaiNRaz5xN5f0kU= X-Google-Smtp-Source: AGHT+IGMyS2xeV4dfpUDYsoQc7eXN0S8sTA7zeAbjMPkh25dCcTm6dNqreFXiKunFNQLfl2XysLoRg== X-Received: by 2002:a17:902:d504:b0:202:3762:ff88 with SMTP id d9443c01a7336-204f9c88ee1mr3937605ad.63.1724800773193; Tue, 27 Aug 2024 16:19:33 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta , Richard Henderson Subject: [PATCH v10 18/21] target/riscv: compressed encodings for sspush and sspopchk Date: Tue, 27 Aug 2024 16:19:02 -0700 Message-ID: <20240827231906.553327-19-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::632; envelope-from=debug@rivosinc.com; helo=mail-pl1-x632.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724801024994116600 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 --- 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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800952; cv=none; d=zohomail.com; s=zohoarc; b=dZQjIZJnhT/vXmlXhLfrUcV3y3pFLTpdIV6M6TcTNF9+1TLr2EXDleUaREcnWiCcE+WU8ergdUOM70Bu+K7elqmt/iH9Lffp4UNv23J62hpapq1sTbuk5Dz77CXvc1KyMQ8Jk+t8UHVp5y8G2xMBroPFE8OKClCCzY11V491w/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800952; 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=O8YdqZUU8+ncezbzq+2x/I5a8BTFehZZsPQ1BjWfojs=; b=a9htXTwVwQArc2Cg1LE1miodGnKhggOT3EtxR+RkoTduEEGKGlZw00zft03eKjcAecsnP5grsBOMV+HlHZwCPW/MmYOUYGm8O8aWMe/qDRxkOqBnQtfyNxuKByUU4UNgpCGXWaHum39WamhDsHjCjTZvK07NPUFxm0XIfqoTO9Q= 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 1724800952825670.3817048156374; Tue, 27 Aug 2024 16:22:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5Tt-0005qp-4s; Tue, 27 Aug 2024 19:20:09 -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 1sj5TO-0003r1-Gw for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:39 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TL-0000wJ-Lt for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:38 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1fc47abc040so53245945ad.0 for ; Tue, 27 Aug 2024 16:19:35 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800774; x=1725405574; 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=O8YdqZUU8+ncezbzq+2x/I5a8BTFehZZsPQ1BjWfojs=; b=ft48ohBeCZT8G9xDvXV9PxUmfErzWTrXC/5t1pFFv783UifYHlXWkgzqQOSyhuqbOu JjfHh1hw7Rvz62K4Cp2OX9dFVcuUc4gABSnh3c8Ls0X/Dt7YOsAXquD1zmfwfEul13FE 3SOm7exQBD53ON6JDR5VwpWzUmUzlyQJyJ4FZ8Ij6Q0fPnck54kiToiizJdYzKI05hhR sUqA2Z7ZyBdFEPYwgFUdPo+cFFGU7BNU3bzd6QpVUVfVVeaJ92J4tX1Xu6cW65jtKiP0 OQ/cDf+GJJGDW9Tn6yz3hONsVlstovmltEvsS2FiqRXZtiNL4eAWg7Db7oioizYNpVt3 gGrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800774; x=1725405574; 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=O8YdqZUU8+ncezbzq+2x/I5a8BTFehZZsPQ1BjWfojs=; b=IadOV0eniubJ/TDpqpnJ64U59lXHP6YMCY3i82fYnkaYQ4pkTi0MMPmIhJsJr+Kbeb ddtTXV/K1aL1oRpW5ck2wBs9hmy6gW0ysXIw8rATCE+uFW6MnugU2D7pKHk8eys0X1GE aCJyTWdK3dJi4UlJHzg664h8sjwVzApUBmK/Xib0z4VVIrVPfxZYqpQCKoMTAdwCmpMD HwUuDJTf1+ghvoEoELGrVSs7Qo1A07qDOy9BXV2jMjnWf0Knqy1/kMg0YiA0xKO4r1BA 0kCoBfbWDAJNRWD5Nrt/Btk9pp+C+GV6UoBMrls+H8DTMcCjbM8rz7/QlYmxRIlT0Zdg W3tw== X-Forwarded-Encrypted: i=1; AJvYcCWGVToLdp4W6Se2iu7Y+oNBhN1olPlN9c/pn2ABMRVw/tDL87zQwdCyM3WJ8gtvIXjNCkfqimLEy4yY@nongnu.org X-Gm-Message-State: AOJu0Yw2oGStPhOocqK8CBjH5+LT/0rCZJyR26vdoOiX1x5I6S+9aV/R 9tbAfyVDvmlTgOd3itF9WByn+JtS0W9iwHfTgxv4FT2jQ0udsnzsJ8klMiKWxXY= X-Google-Smtp-Source: AGHT+IHYgSD+cO5idqbRuiFIkU1WLyyPnW1hbAWUuIZ8W67sO/+GgC05sNEP1wt3cCUa9X/LaNob6Q== X-Received: by 2002:a17:902:ec8c:b0:202:85e:cf56 with SMTP id d9443c01a7336-2039e4b55c6mr176612475ad.38.1724800774318; Tue, 27 Aug 2024 16:19:34 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 19/21] disas/riscv: enable disassembly for zicfiss instructions Date: Tue, 27 Aug 2024 16:19:03 -0700 Message-ID: <20240827231906.553327-20-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62a; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62a.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800954838116600 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 --- 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 c7c92acef7..5eafb7f7f3 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -975,6 +975,11 @@ typedef enum { rv_op_amocas_b =3D 944, rv_op_amocas_h =3D 945, rv_op_lpad =3D 946, + rv_op_sspush =3D 947, + rv_op_sspopchk =3D 948, + rv_op_ssrdp =3D 949, + rv_op_ssamoswap_w =3D 950, + rv_op_ssamoswap_d =3D 951, } rv_op; =20 /* register names */ @@ -2234,6 +2239,11 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "amocas.b", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "amocas.h", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, 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 */ @@ -2251,6 +2261,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"; @@ -3077,6 +3088,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; @@ -4028,7 +4041,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), @@ -4036,11 +4049,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724801024; cv=none; d=zohomail.com; s=zohoarc; b=ijjOxOPcU8TDofQX0esErAujiZmBagXr7wKKjz3IWYEMz8xFKxjvM1sb0FXrGb6GdkGpzqrxfRVDzlQtNio9Lx3tGPDkRBKSMdiW69Oj8OxwRO89w4UjALrA4pB59msS9Of7A5Q4awU7/yb4wjSieoSrthCp1XVk+LchKaknRfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724801024; 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=SjZWcB+IcGQyCSoIg5tycoGHZJtgwFG54PQXYRnVDCY=; b=iMiTZUrGmZ3r7KqBbYBxPXogNp36GAyzNFPcU/KbCZIcT/ISg2PxfRG9bONVNz0lN98TipTZgr5z1+3D/m26DYVV8c6QC7H66g0Shk/hSGAMbVeobtmY2w/cqDr28PzU/Pi5VWT6s3s8+KWb13gOcMhsDrYg86YsRRqBWAjc06s= 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 1724801024647530.7290186589292; Tue, 27 Aug 2024 16:23:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5Ts-0005q0-Uv; Tue, 27 Aug 2024 19:20:09 -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 1sj5TP-0003tC-3w for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:40 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TN-0000wX-Gt for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:38 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2021c03c13aso421835ad.1 for ; Tue, 27 Aug 2024 16:19:36 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800775; x=1725405575; 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=SjZWcB+IcGQyCSoIg5tycoGHZJtgwFG54PQXYRnVDCY=; b=shDtd8JlTdXPDd+hBgbRK+37zd8aquTb4t23uwQR8zqbU36BTxF5DP4J9JFLC3rN6H azTRueDTwJRlrFCXQy3R7QjnWj+Kta9+wwilr5efpQ2tbpikAA5nTZdW+yiELKuv+HDp ofo8PkVsEqcimVX6eT6vv/Nj0q5Yz1mjB4WSZ0WZHtdORhSyzGr7hk4vUcHwhlZvUhrP vgAM1ICzY5aawuB62fQQNkqPT6HRMgDwJRnC8/+J7Ykvrl2UEkU3sTyVb2NavsEyxj2n UdMiKrKik8FyFYBSIM1tiptO7eYfGDhZw+dMwfIYZSlr5oauYsCiSvdKdFHjP6morObn 0TZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800775; x=1725405575; 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=SjZWcB+IcGQyCSoIg5tycoGHZJtgwFG54PQXYRnVDCY=; b=NGDmcd0ax3067X74kYlpxISVUJUS6U6HpHaDbbrpJkIvsK2jsbRddjtGrZPI+FGtZp WRAr7eXDm/HZSGDcC9X+ypZoN1+O45cOZ7rZJUIrOrFbecMK5TCJSgb2aZr6tMP9Oc6d pbSMA59okbwrnN1OoAUNQwkyxwU/VM/6UGU5vAwEq85ger/5FZfIULqmWrEiX3KF5wST 68T0h4XTiZijlAuGx0ZK9zyXdxc17IFwhjTw1yX/znz4MhfhzzM+muA99WFtRq4InZjU E+ZPTCWOI9e+V6NjV7/JeTBztBeNkkRnoPtyqs0HqlGjRtU7P7NyE/dixGkEN4BKkZZx Upjg== X-Forwarded-Encrypted: i=1; AJvYcCUaarK/YQvEMwGrbGDyZ9o2Q7LxMadCwFCy7kZO7ffiYqBIkJmK4tYKzo4vMgjeC4swg9rAEW8ql80I@nongnu.org X-Gm-Message-State: AOJu0Yxg+Ea38qt3/No9whaUbK7InzDKOdPPIsl489AT7PUjR6bxZreD 58gDRs8frAu/QVWzl0x59lEeS3DdovE+OgmK9slsCHwwPQ4IvcB2hon9eDMUkWo= X-Google-Smtp-Source: AGHT+IGLDQAEioHQ7MD5BtwRUT1ZniIFtwyi5QTVAl6jj47DFW23R6MzrdaRfVbStl9hkydFdJpyOw== X-Received: by 2002:a17:902:e808:b0:1fd:6581:93c5 with SMTP id d9443c01a7336-204f9ca442dmr4359745ad.27.1724800775406; Tue, 27 Aug 2024 16:19:35 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 20/21] disas/riscv: enable disassembly for compressed sspush/sspopchk Date: Tue, 27 Aug 2024 16:19:04 -0700 Message-ID: <20240827231906.553327-21-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::62b; envelope-from=debug@rivosinc.com; helo=mail-pl1-x62b.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724801024977116600 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 --- 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 5eafb7f7f3..6e9ba42edd 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -980,6 +980,8 @@ typedef enum { rv_op_ssrdp =3D 949, rv_op_ssamoswap_w =3D 950, rv_op_ssamoswap_d =3D 951, + rv_op_c_sspush =3D 952, + rv_op_c_sspopchk =3D 953, } rv_op; =20 /* register names */ @@ -2244,6 +2246,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 */ @@ -2604,7 +2610,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; } } @@ -4923,6 +4935,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.44.0 From nobody Sun Nov 24 06:22:19 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=1724800862; cv=none; d=zohomail.com; s=zohoarc; b=FEXvepitRNB4/dfO8ay++AcVNDFNn5/qeoPfW2rSl6Hokhc8PNhEKjTjkl2dsmSumPd4Phu6y43Q5LQ4Bf1XD3qFtTzLBC7AxtZd88r4KIA1ZswSy4155CGpLPwj2xl+StFyyq81UvasG+FKOsAJ3t4VE0j0G/Vpa9RFZ8QYS6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724800862; 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=BkHD6ktn6nmHSyL5ZN67NLJg9JbIK8JaSh/uuJiIwag=; b=J+iRmofmhO5hJ1mffbhnsFkiNh//RDFvSObKwsg5a2nrTHv3FXaBvzAPPf8Mj3krf9fyuBKK/WuRx5QmUPoZ7IZ8f2aCNpI+b6uPKn/VedzaXJM2nIdOWBIe4gPadQJZQBZBJi0VR/eR1iQACNtAkH7pbXT0kI/hw+z62lXJnmc= 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 1724800862031198.31290370280885; Tue, 27 Aug 2024 16:21:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj5Tf-0004lg-LO; Tue, 27 Aug 2024 19:19:55 -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 1sj5TP-0003vV-MH for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:40 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sj5TO-0000wm-6G for qemu-devel@nongnu.org; Tue, 27 Aug 2024 19:19:39 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-204eebfaebdso6639165ad.1 for ; Tue, 27 Aug 2024 16:19:37 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0ee6179sm57785155ad.92.2024.08.27.16.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 16:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724800777; x=1725405577; 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=BkHD6ktn6nmHSyL5ZN67NLJg9JbIK8JaSh/uuJiIwag=; b=rz55DhfN5CdsdChc6fmaVit8DtgMgNYuJxxomgpXqJ9LiPL1fmvpmnY2UEmildNc+t etlI0yEjbheBtDYpsyKmUjNN5bIY8IRwZKJDTfTUSGSp7HxE6p/SxQgsxjmQNcW+Tho8 hnd3Zy6oPfLrh0jFGjHoSnN0WqrlublDEg7CHE8A3grcIhrFlLhnsco040KqjcENkwQ1 OFOGxvvWm2OwYFuhkTmAXV+dHmDpEzpEviZjh/QP/Hy584MYaCy2ztoc1zggAJgI+Q0s VKc4Z1GldT2FCWHn5mxudJMDZHyRX9xhEhxd3eJFkrcyKUY/GTlCooJzDMxQ8rv5U8oV r1ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800777; x=1725405577; 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=BkHD6ktn6nmHSyL5ZN67NLJg9JbIK8JaSh/uuJiIwag=; b=exlkrW1FqHNe1mCkwzvp5ztTDbF75h1mNgNzDOrp/uoPc24xaNa5fjGMpav59BgheM SydGfeaGWG3L8V6NBwQIcLVj2zL7C5n0mnkmog6z939+OUoDJjc8i9aggeuNXirysuUZ EeyyEm4OTiQH6Ye9kCL+wJ98DOmbcYBO82/8O3277gRwXkMnihh4ee98aXYXymJovntL 3GMugIrEu89+W1EeaPQnZszSxOVNeDXE/FlQoq3/bpw4g9JQxebz7GAef7LiVEklzlLd f9pVV26QGT1IJyJCA72Ix0/OtwhjNdStEgthEpS7EemUMoC9SWONXC4o8vtxg8vZAVQG Xlpw== X-Forwarded-Encrypted: i=1; AJvYcCVLpPIgN1QppQ4L7axIAJA5HlAGQoAVFKiNKqAbO3+ajXi9PbRZvWJYewvMBgs6/FSZRXP3U8G37Ukr@nongnu.org X-Gm-Message-State: AOJu0YyJYoD/JAx1i4Mx67VQfEt5o9drT0QF1+jVcqKYYfuvhBvl0EHa jWyuKmUnqOiXfvwhHvZPsiLya0lad228iLamQpdW5bOmZ53neYpSqKCjOpPcaUw= X-Google-Smtp-Source: AGHT+IHBSz27Qp5zxFrjlgeAl0s8oUyUBtGaWP0GS4xrjaawqTc79oQufHeAQVtnq+wIVJI1b5Yyyg== X-Received: by 2002:a17:902:f54e:b0:1fa:fc24:afa5 with SMTP id d9443c01a7336-2039e4890cdmr159817575ad.27.1724800776540; Tue, 27 Aug 2024 16:19:36 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v10 21/21] target/riscv: Expose zicfiss extension as a cpu property Date: Tue, 27 Aug 2024 16:19:05 -0700 Message-ID: <20240827231906.553327-22-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240827231906.553327-1-debug@rivosinc.com> References: <20240827231906.553327-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::630; envelope-from=debug@rivosinc.com; helo=mail-pl1-x630.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1724800862446116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Deepak Gupta --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d6cdd81fd8..66dc5af20c 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1481,6 +1481,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, 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.44.0