From nobody Wed May 15 08:37:48 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=1677195939; cv=none; d=zohomail.com; s=zohoarc; b=N0e0tu9D5t1P2DoAoQUh+/y9REyb2QhYrJ/Q0FUzEIylYV6yv7jlmyQ4rGX5/FBQ+OEfHFGOIBko7R65aLuNY6f7/Y1q+JFFIXEHJyeF11Cos4NL8OHKrCTHh9cVYLqScEMBgnUpigRlCCOKBeTDVLMojx8sggwP9Pc7LeDS2wI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677195939; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=niOll0s/PDcnOMdRIUOVBVVgsiBEkn8iEUg3l/2iVTQ=; b=eKtywXFrCRkAoyyUw/4zwSciIB12T55Pczcnt7rvarU+DCE/KVBQjZcF1dbuMBlFIqmXhpH+e0a1zLHCk1fzoyUUwOnUokDzlN8JrpwCq0sWhRFH2BPaPV0w/ZVutflXd5Bl/F973w8hs0PzDSieTUBhZJt4xZZJGQkkhMxW6sA= 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 1677195939662525.9049152574153; Thu, 23 Feb 2023 15:45:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVLGa-0002nT-J6; Thu, 23 Feb 2023 18:44:49 -0500 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 1pVLGS-0002kC-3q for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:41 -0500 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVLGQ-00017p-5Y for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:39 -0500 Received: by mail-oi1-x230.google.com with SMTP id bg11so14380583oib.5 for ; Thu, 23 Feb 2023 15:44:37 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([189.110.112.117]) by smtp.gmail.com with ESMTPSA id v6-20020acaac06000000b0037facb2c5fasm2415037oie.1.2023.02.23.15.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 15:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=niOll0s/PDcnOMdRIUOVBVVgsiBEkn8iEUg3l/2iVTQ=; b=hHmeCJSocilNvFU/5MelF/wzn7O7Ubjo4kJhAyw5Xy4o3Li2GmyDsC5igGPONTYcv0 eEo/NNp6omt8IOQs1L8NRTquwV5aL+TAJnFfYTxZ5xSj4UKmkXirtfHAriGHPR6rQvEG B9xzJ2SbqWEA7syI8XJU9BcjIgP1LAOnm7m6h83NzqHjoA5DOx6JFsm4vYp9tNKi1FKk qrptQ9CbsODhxq3yEnbo2szlhaaRIJSqKEnnTNA/YXIxKW5iyLPaHy/s15eUc5mGZ40P Twmx5sXrOrAeSCbtZ3I1X2oC2zNqzr0JqanBBzmyo24OoWtyjq+C3dBDebAbMnRyatLq c2Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=niOll0s/PDcnOMdRIUOVBVVgsiBEkn8iEUg3l/2iVTQ=; b=PutIoR+9czVmvSFFHnzLBLkFHfkHtwHMowgGbxRzdOeyoZVjd0sqeAoo5ls4A48fF/ UoAZ85533jGKY1KuF2FbiSOKZ+8GLPZdZWDdetvqAtA04PeQRMPIkhg7G9o84F7Vs94j fiFKwYF5zd2hIOyt5MMRbNtfwcTrXfPRrzB2H3sIyqanBvxELIu5RBaiWjVEeHhnfev5 KHlSpp9VY9haU0IrzSksPB7ZMxyM8+I2Q1Z7Sx8fAkAaWVeZy8v9t3mVwnk0tYn4XR8N VLeE6+QmX7dCVUr4Ct749uAyH4SSuhqhD55BnuoDdynkslBIAg1tydK2veaR7hKX7mML dN4w== X-Gm-Message-State: AO0yUKU9SkXjiNKT4U9nQ1/+Hovduw8QB2Gy3sqA+7ZX0aOozIBZhWC3 jF0dxPb0cepIR4dg2chB1ZmbfjfDsJ++xBad X-Google-Smtp-Source: AK7set/WdUygpuMPTB7z2o5ctXaknf6NLEB28UZ7C6eSclTAUD70Tu0FF2+yuf+elkR0Zn0Zk5FT4Q== X-Received: by 2002:a05:6808:8ea:b0:37e:aa97:4660 with SMTP id d10-20020a05680808ea00b0037eaa974660mr5878983oic.16.1677195877080; Thu, 23 Feb 2023 15:44:37 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza Subject: [PATCH v7 1/4] tcg: add 'size' param to probe_access_flags() Date: Thu, 23 Feb 2023 20:44:24 -0300 Message-Id: <20230223234427.521114-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230223234427.521114-1-dbarboza@ventanamicro.com> References: <20230223234427.521114-1-dbarboza@ventanamicro.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::230; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1677195940279100001 Content-Type: text/plain; charset="utf-8" probe_access_flags() as it is today uses probe_access_full(), which in turn uses probe_access_internal() with size =3D 0. probe_access_internal() then uses the size to call the tlb_fill() callback for the given CPU. This size param ('fault_size' as probe_access_internal() calls it) is ignored by most existing .tlb_fill callback implementations, e.g. arm_cpu_tlb_fill(), ppc_cpu_tlb_fill(), x86_cpu_tlb_fill() and mips_cpu_tlb_fill() to name a few. But RISC-V riscv_cpu_tlb_fill() actually uses it. The 'size' parameter is used to check for PMP (Physical Memory Protection) access. This is necessary because PMP does not make any guarantees about all the bytes of the same page having the same permissions, i.e. the same page can have different PMP properties, so we're forced to make sub-page range checks. To allow RISC-V emulation to do a probe_acess_flags() that covers PMP, we need to either add a 'size' param to the existing probe_acess_flags() or create a new interface (e.g. probe_access_range_flags). There are quite a few probe_* APIs already, so let's add a 'size' param to probe_access_flags() and re-use this API. This is done by open coding what probe_access_full() does inside probe_acess_flags() and passing the 'size' param to probe_acess_internal(). Existing probe_access_flags() callers use size =3D 0 to not change their current API usage. 'size' is asserted to enforce single page access like probe_access() already does. No behavioral changes intended. Signed-off-by: Daniel Henrique Barboza Acked-by: Palmer Dabbelt Reviewed-by: Richard Henderson --- accel/stubs/tcg-stub.c | 2 +- accel/tcg/cputlb.c | 17 ++++++++++++++--- accel/tcg/user-exec.c | 5 +++-- include/exec/exec-all.h | 3 ++- semihosting/uaccess.c | 2 +- target/arm/ptw.c | 2 +- target/arm/sve_helper.c | 2 +- target/s390x/tcg/mem_helper.c | 6 +++--- 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c index c1b05767c0..96af23dc5d 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -25,7 +25,7 @@ void tcg_flush_jmp_cache(CPUState *cpu) { } =20 -int probe_access_flags(CPUArchState *env, target_ulong addr, +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, bool nonfault, void **phost, uintptr_t retaddr) { diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 4812d83961..fc27e34457 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1606,14 +1606,25 @@ int probe_access_full(CPUArchState *env, target_ulo= ng addr, return flags; } =20 -int probe_access_flags(CPUArchState *env, target_ulong addr, +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, bool nonfault, void **phost, uintptr_t retaddr) { CPUTLBEntryFull *full; + int flags; + + g_assert(-(addr | TARGET_PAGE_MASK) >=3D size); + + flags =3D probe_access_internal(env, addr, size, access_type, mmu_idx, + nonfault, phost, &full, retaddr); =20 - return probe_access_full(env, addr, access_type, mmu_idx, - nonfault, phost, &full, retaddr); + /* Handle clean RAM pages. */ + if (unlikely(flags & TLB_NOTDIRTY)) { + notdirty_write(env_cpu(env), addr, 1, full, retaddr); + flags &=3D ~TLB_NOTDIRTY; + } + + return flags; } =20 void *probe_access(CPUArchState *env, target_ulong addr, int size, diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index ae67d84638..7b37fd229e 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -761,13 +761,14 @@ static int probe_access_internal(CPUArchState *env, t= arget_ulong addr, cpu_loop_exit_sigsegv(env_cpu(env), addr, access_type, maperr, ra); } =20 -int probe_access_flags(CPUArchState *env, target_ulong addr, +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, bool nonfault, void **phost, uintptr_t ra) { int flags; =20 - flags =3D probe_access_internal(env, addr, 0, access_type, nonfault, r= a); + g_assert(-(addr | TARGET_PAGE_MASK) >=3D size); + flags =3D probe_access_internal(env, addr, size, access_type, nonfault= , ra); *phost =3D flags ? NULL : g2h(env_cpu(env), addr); return flags; } diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 54585a9954..b0d4916573 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -446,6 +446,7 @@ static inline void *probe_read(CPUArchState *env, targe= t_ulong addr, int size, * probe_access_flags: * @env: CPUArchState * @addr: guest virtual address to look up + * @size: size of the access * @access_type: read, write or execute permission * @mmu_idx: MMU index to use for lookup * @nonfault: suppress the fault @@ -460,7 +461,7 @@ static inline void *probe_read(CPUArchState *env, targe= t_ulong addr, int size, * Do handle clean pages, so exclude TLB_NOTDIRY from the returned flags. * For simplicity, all "mmio-like" flags are folded to TLB_MMIO. */ -int probe_access_flags(CPUArchState *env, target_ulong addr, +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, bool nonfault, void **phost, uintptr_t retaddr); =20 diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 8018828069..7505eb6d1b 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -37,7 +37,7 @@ ssize_t softmmu_strlen_user(CPUArchState *env, target_ulo= ng addr) /* Find the number of bytes remaining in the page. */ left_in_page =3D TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); =20 - flags =3D probe_access_flags(env, addr, MMU_DATA_LOAD, + flags =3D probe_access_flags(env, addr, 0, MMU_DATA_LOAD, mmu_idx, true, &h, 0); if (flags & TLB_INVALID_MASK) { return -1; diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 2b125fff44..1ecefb2027 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -407,7 +407,7 @@ static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t= old_val, void *discard; =20 env->tlb_fi =3D fi; - flags =3D probe_access_flags(env, ptw->out_virt, MMU_DATA_STORE, + flags =3D probe_access_flags(env, ptw->out_virt, 0, MMU_DATA_STORE, arm_to_core_mmu_idx(ptw->in_ptw_idx), true, &discard, 0); env->tlb_fi =3D NULL; diff --git a/target/arm/sve_helper.c b/target/arm/sve_helper.c index 521fc9b969..51909c44ac 100644 --- a/target/arm/sve_helper.c +++ b/target/arm/sve_helper.c @@ -5352,7 +5352,7 @@ bool sve_probe_page(SVEHostPage *info, bool nofault, = CPUARMState *env, addr =3D useronly_clean_ptr(addr); =20 #ifdef CONFIG_USER_ONLY - flags =3D probe_access_flags(env, addr, access_type, mmu_idx, nofault, + flags =3D probe_access_flags(env, addr, 0, access_type, mmu_idx, nofau= lt, &info->host, retaddr); #else CPUTLBEntryFull *full; diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index d6725fd18c..c9fd4142f1 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -143,14 +143,14 @@ static int s390_probe_access(CPUArchState *env, targe= t_ulong addr, int size, bool nonfault, void **phost, uintptr_t ra) { #if defined(CONFIG_USER_ONLY) - return probe_access_flags(env, addr, access_type, mmu_idx, + return probe_access_flags(env, addr, 0, access_type, mmu_idx, nonfault, phost, ra); #else int flags; =20 env->tlb_fill_exc =3D 0; - flags =3D probe_access_flags(env, addr, access_type, mmu_idx, nonfault= , phost, - ra); + flags =3D probe_access_flags(env, addr, 0, access_type, mmu_idx, + nonfault, phost, ra); if (env->tlb_fill_exc) { return env->tlb_fill_exc; } --=20 2.39.2 From nobody Wed May 15 08:37:48 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=1677195953; cv=none; d=zohomail.com; s=zohoarc; b=dSPNp2Tfq04vrUUtlB9HK8ZmioYAuJYErMPODVXaRWhBKnyV9TEP/D5Tn/rTN3EBV1r7cEcPMbIlGw1bLdvaHNcjfE5oLlLRv4GduKqbLiKTj+MNyuufhmbwitjL/hIDG7pSS2lNrUEOApGj+6qiEFF0J5zOTbWa7FBfU1btDgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677195953; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dZDbXER3cLYndDU0pjfWPomBwr9zC6LtNZhhj2mBt8M=; b=S45p5rUDVcVEkypOF4CHZIEYorLVPXpAiXKtZQ7iPkulcjUlNEnCbTvFPpdW0VRI2/nRD/4ICuTyw51T2uW+IzOMN1TxkU2yZfsBuf4QafArmdJHEYRyJb6FL14OiOvLmn6Wqxo7XWzIygSXcHFR5s3a0wZqugPqqFJZrvA4lX0= 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 1677195953785932.5618628971336; Thu, 23 Feb 2023 15:45:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVLGh-00039O-V8; Thu, 23 Feb 2023 18:44:56 -0500 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 1pVLGY-0002oO-R3 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:47 -0500 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVLGU-00017n-0h for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:44 -0500 Received: by mail-oi1-x22e.google.com with SMTP id bk2so13512718oib.10 for ; Thu, 23 Feb 2023 15:44:41 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([189.110.112.117]) by smtp.gmail.com with ESMTPSA id v6-20020acaac06000000b0037facb2c5fasm2415037oie.1.2023.02.23.15.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 15:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=dZDbXER3cLYndDU0pjfWPomBwr9zC6LtNZhhj2mBt8M=; b=epTXuHz70SUiC6YYXPnV7abqmrerMVVAPXB8nYcGINotEw9Xwj3yZV8JGFP/gVz5I/ M7RIKbITAj0er7uwT9TtScFEkkxUGodqcQLFUbkJA+uoPDFSlMGDCk76l2ULIXLOc3ac xdwNkkasHU62kvwZIfQ4zzlcQQXuoF08WvY78qJ8MzKmeSEEtS+BWA6ArNHFFP/puZbt Omcm54rDKalqVYcgVbqfPeHfmZIZ0D33HWrLtcT6yK7ZPO/mLJXhytcJy57kRdfMNKnx 7U7ix3uYctvo848vpj2Ws1VSAg37+mXHVwPIWT9BMG9TxN8RWVKoeqOnbkkROZu1LS5b zTBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=dZDbXER3cLYndDU0pjfWPomBwr9zC6LtNZhhj2mBt8M=; b=ej8rEgyMR/527UdU3lpC/Rxqk7YzlPrg4CrE/w7cNDDU4aNt3qs+whbMSIf5bhBHhM 0TfB5keXq8S4fKx77vwVkU95TGceQQgn3mfTjTW03BJM1LXaD0CWEB9nT8u9OTbTPcrh eEz22Ha/YiUpojaQ6ymYeKrqhAHICZfV0MvhbBAEHtN/FAMMr3nxAU4K/GnV14hq6DPh 4jBxGGM14Zb9aJj4Rh0R3QMpTqATm5c/DdtyPofM9qYHtB5bU0370hKlUpdWckZdvu3e aAvqm0kfVBvf1nKyRFqqsJ9+uHzHbsDPmbPYaFdnRKqo6jcjpQ7jMmUtrEHHJjO6QY2S u1Zg== X-Gm-Message-State: AO0yUKXc0ItpmW/jYMPt17wIawVsHDbZbAA0RYha+Ueoon0pDT8Zwzvi 2wntVOEEPWxJoWHhbm1JTzZvJkOEzRv4w2N2 X-Google-Smtp-Source: AK7set8Jn8dw7Vau4vqaJmr5zAcEa801A95KWF6dtTmFpg/oJsGGSVT9xVYamo5aDKbqBocrBCYQRg== X-Received: by 2002:a05:6808:1183:b0:383:e7ad:efaf with SMTP id j3-20020a056808118300b00383e7adefafmr1357923oil.8.1677195880849; Thu, 23 Feb 2023 15:44:40 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Christoph Muellner , Philipp Tomsich , Daniel Henrique Barboza Subject: [PATCH v7 2/4] target/riscv: implement Zicboz extension Date: Thu, 23 Feb 2023 20:44:25 -0300 Message-Id: <20230223234427.521114-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230223234427.521114-1-dbarboza@ventanamicro.com> References: <20230223234427.521114-1-dbarboza@ventanamicro.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::22e; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1677195954419100001 Content-Type: text/plain; charset="utf-8" From: Christoph Muellner The RISC-V base cache management operation (CBO) ISA extension has been ratified. It defines three extensions: Cache-Block Management, Cache-Block Prefetch and Cache-Block Zero. More information about the spec can be found at [1]. Let's start by implementing the Cache-Block Zero extension, Zicboz. It uses the cbo.zero instruction that, as with all CBO instructions that will be added later, needs to be implemented in an overlap group with the LQ instruction due to overlapping patterns. cbo.zero throws a Illegal Instruction/Virtual Instruction exception depending on CSR state. This is also the case for the remaining cbo instructions we're going to add next, so create a check_zicbo_envcfg() that will be used by all Zicbo[mz] instructions. [1] https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-= v1.0.1.pdf Co-developed-by: Philipp Tomsich Signed-off-by: Christoph Muellner Signed-off-by: Daniel Henrique Barboza Acked-by: Palmer Dabbelt Reviewed-by: Richard Henderson --- target/riscv/cpu.c | 4 ++ target/riscv/cpu.h | 2 + target/riscv/helper.h | 3 + target/riscv/insn32.decode | 10 +++- target/riscv/insn_trans/trans_rvzicbo.c.inc | 30 ++++++++++ target/riscv/op_helper.c | 65 +++++++++++++++++++++ target/riscv/translate.c | 1 + 7 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 target/riscv/insn_trans/trans_rvzicbo.c.inc diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 93b52b826c..7dd37de7f9 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -74,6 +74,7 @@ struct isa_ext_data { static const struct isa_ext_data isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(h, false, PRIV_VERSION_1_12_0, ext_h), ISA_EXT_DATA_ENTRY(v, false, PRIV_VERSION_1_10_0, ext_v), + ISA_EXT_DATA_ENTRY(zicboz, true, PRIV_VERSION_1_12_0, ext_icboz), ISA_EXT_DATA_ENTRY(zicsr, true, PRIV_VERSION_1_10_0, ext_icsr), ISA_EXT_DATA_ENTRY(zifencei, true, PRIV_VERSION_1_10_0, ext_ifencei), ISA_EXT_DATA_ENTRY(zihintpause, true, PRIV_VERSION_1_10_0, ext_zihintp= ause), @@ -1126,6 +1127,9 @@ static Property riscv_cpu_extensions[] =3D { DEFINE_PROP_BOOL("zhinx", RISCVCPU, cfg.ext_zhinx, false), DEFINE_PROP_BOOL("zhinxmin", RISCVCPU, cfg.ext_zhinxmin, false), =20 + DEFINE_PROP_BOOL("zicboz", RISCVCPU, cfg.ext_icboz, true), + DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64), + DEFINE_PROP_BOOL("zmmul", RISCVCPU, cfg.ext_zmmul, false), =20 /* Vendor-specific custom extensions */ diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7128438d8e..6b4c714d3a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -447,6 +447,7 @@ struct RISCVCPUConfig { bool ext_zkt; bool ext_ifencei; bool ext_icsr; + bool ext_icboz; bool ext_zihintpause; bool ext_smstateen; bool ext_sstc; @@ -494,6 +495,7 @@ struct RISCVCPUConfig { char *vext_spec; uint16_t vlen; uint16_t elen; + uint16_t cboz_blocksize; bool mmu; bool pmp; bool epmp; diff --git a/target/riscv/helper.h b/target/riscv/helper.h index 0497370afd..ce165821b8 100644 --- a/target/riscv/helper.h +++ b/target/riscv/helper.h @@ -97,6 +97,9 @@ DEF_HELPER_FLAGS_2(fcvt_h_l, TCG_CALL_NO_RWG, i64, env, t= l) DEF_HELPER_FLAGS_2(fcvt_h_lu, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fclass_h, TCG_CALL_NO_RWG_SE, tl, env, i64) =20 +/* Cache-block operations */ +DEF_HELPER_2(cbo_zero, void, env, tl) + /* Special functions */ DEF_HELPER_2(csrr, tl, env, int) DEF_HELPER_3(csrw, void, env, int, tl) diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index b7e7613ea2..3985bc703f 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -179,7 +179,15 @@ sraw 0100000 ..... ..... 101 ..... 0111011 @r =20 # *** RV128I Base Instruction Set (in addition to RV64I) *** ldu ............ ..... 111 ..... 0000011 @i -lq ............ ..... 010 ..... 0001111 @i +{ + [ + # *** RV32 Zicboz Standard Extension *** + cbo_zero 0000000 00100 ..... 010 00000 0001111 @sfence_vm + ] + + # *** RVI128 lq *** + lq ............ ..... 010 ..... 0001111 @i +} sq ............ ..... 100 ..... 0100011 @s addid ............ ..... 000 ..... 1011011 @i sllid 000000 ...... ..... 001 ..... 1011011 @sh6 diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/ins= n_trans/trans_rvzicbo.c.inc new file mode 100644 index 0000000000..feabc28342 --- /dev/null +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc @@ -0,0 +1,30 @@ +/* + * RISC-V translation routines for the RISC-V CBO Extension. + * + * Copyright (c) 2021 Philipp Tomsich, philipp.tomsich@vrull.eu + * + * 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 . + */ + +#define REQUIRE_ZICBOZ(ctx) do { \ + if (!ctx->cfg_ptr->ext_icboz) { \ + return false; \ + } \ +} while (0) + +static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) +{ + REQUIRE_ZICBOZ(ctx); + gen_helper_cbo_zero(cpu_env, cpu_gpr[a->rs1]); + return true; +} diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 48f918b71b..72a8ca31fc 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -3,6 +3,7 @@ * * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu * Copyright (c) 2017-2018 SiFive, Inc. + * Copyright (c) 2022 VRULL GmbH * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -123,6 +124,70 @@ target_ulong helper_csrrw_i128(CPURISCVState *env, int= csr, return int128_getlo(rv); } =20 + +/* + * check_zicbo_envcfg + * + * Raise virtual exceptions and illegal instruction exceptions for + * Zicbo[mz] instructions based on the settings of [mhs]envcfg as + * specified in section 2.5.1 of the CMO specification. + */ +static void check_zicbo_envcfg(CPURISCVState *env, target_ulong envbits, + uintptr_t ra) +{ +#ifndef CONFIG_USER_ONLY + if (((env->priv < PRV_M) && !get_field(env->menvcfg, envbits)) || + ((env->priv < PRV_S) && !get_field(env->senvcfg, envbits))) { + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); + } + + if (riscv_cpu_virt_enabled(env) && + (((env->priv < PRV_H) && !get_field(env->henvcfg, envbits)) || + ((env->priv < PRV_S) && !get_field(env->senvcfg, envbits)))) { + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, ra); + } +#endif +} + +void helper_cbo_zero(CPURISCVState *env, target_ulong address) +{ + RISCVCPU *cpu =3D env_archcpu(env); + uint16_t cbozlen =3D cpu->cfg.cboz_blocksize; + int mmu_idx =3D cpu_mmu_index(env, false); + uintptr_t ra =3D GETPC(); + void *mem; + + check_zicbo_envcfg(env, MENVCFG_CBZE, ra); + + /* Mask off low-bits to align-down to the cache-block. */ + address &=3D ~(cbozlen - 1); + + /* + * cbo.zero requires MMU_DATA_STORE access. Do a probe_write() + * to raise any exceptions, including PMP. + */ + mem =3D probe_write(env, address, cbozlen, mmu_idx, ra); + + if (likely(mem)) { + memset(mem, 0, cbozlen); + } else { + /* + * This means that we're dealing with an I/O page. Section 4.2 + * of cmobase v1.0.1 says: + * + * "Cache-block zero instructions store zeros independently + * of whether data from the underlying memory locations are + * cacheable." + * + * Write zeros in address + cbozlen regardless of not being + * a RAM page. + */ + for (int i =3D 0; i < cbozlen; i++) { + cpu_stb_mmuidx_ra(env, address + i, 0, mmu_idx, ra); + } + } +} + #ifndef CONFIG_USER_ONLY =20 target_ulong helper_sret(CPURISCVState *env) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 772f9d7973..7f687a7e37 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1104,6 +1104,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, t= arget_ulong pc) #include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" #include "insn_trans/trans_rvzawrs.c.inc" +#include "insn_trans/trans_rvzicbo.c.inc" #include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_rvk.c.inc" #include "insn_trans/trans_privileged.c.inc" --=20 2.39.2 From nobody Wed May 15 08:37:48 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=1677195981; cv=none; d=zohomail.com; s=zohoarc; b=nVci868q2Kmw0jo0PWVO/vl0nzTd8mbK2PiQ51YjUBIk0MjuKrWw1lzxkv3LII9Wkd2Bo3iyyHhOmdVd1MBHTM5FqBvmwXNHWlY5HLpxyQ/HUktbFsmOYAXGJTnWAUF3V7+JevffWBCHjfidgGQgWcMrtbiSl969bAclY3RVz8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677195981; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JNbi5H36ASaeDW+e0iHDtVKZ/uQp4e0NUvwnUsfHDEg=; b=ePpSLEQYSBpf/dezII6QopZWiDlgr6jS3ZvhX87H4CLnoyozWDfxNjZ2INznz8kTPHE+r41+8WrAESowpOySCAR8SrQuuNdv3W6o19TQ3OvSLewHyj+4dLSTahMskfpMGpppw9EsOIoGX8Zj+x219csEUOfVTlwxqHSbNm09u+o= 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 1677195981411140.34485754401646; Thu, 23 Feb 2023 15:46:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVLGi-0003Ek-Qt; Thu, 23 Feb 2023 18:44:56 -0500 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 1pVLGa-0002pR-Lk for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:49 -0500 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVLGY-0001EZ-9O for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:48 -0500 Received: by mail-oi1-x233.google.com with SMTP id w7so14441959oik.13 for ; Thu, 23 Feb 2023 15:44:45 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([189.110.112.117]) by smtp.gmail.com with ESMTPSA id v6-20020acaac06000000b0037facb2c5fasm2415037oie.1.2023.02.23.15.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 15:44:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=JNbi5H36ASaeDW+e0iHDtVKZ/uQp4e0NUvwnUsfHDEg=; b=BtU/bOA85mGot6OavoDvOXepquZiJjPT0e8wQYAFNbepwJnHM315cPELjRAGI9Tb4x HE+HJ570fyh0fJv43eHZ8r3NBRe2+l7HNtOeRwBS7HR93L9hVrB5pRGfarKE84HZYWh+ bRmJ6da3lsr28q3A9J2l6OKx6+DB9slu2M9VXPQGTpVXjyLKwzgl/lWbNAwygR1k52Xv sBZk7yzhzaslK9+2qrc0ObeoyIhdf39tV/bPSs7PlUZh/dXzQp+V2P7mf8Fu6btxvpdv 9Orrh5v2bEu6UpZgBXR2suz7hmvnueWHbgIEgGlVFttTZYbJ97B0dlenUzQu6koK+e/l LlQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JNbi5H36ASaeDW+e0iHDtVKZ/uQp4e0NUvwnUsfHDEg=; b=QQS9iCfX3TZK6onDIv0nWFQcDF9ZNXag+0b94bFkJI6i1z+Wn+yWpEm3+7m1g7zIul Nn6FSTn0jSMv8yoKjgTFX+buolvuEYqsCWaB155l+Il/1AUkUS/DUh9RVh922YVT0TLz nSOnLQ6dDVoVah3hZNX67SDMvyurIRVv9P6HzwgrLWWtodUZVFC/qYnyiZioDAOoWFxF CfNAhzfh4w9jGRE6/nur1116qkQiHZ8sELuu5FpBYILgLiGXHM26xmy1e7MLrt4rIx+0 HbtJcH1/wBj7WjKiDn1WoPpuCVvslX+ADcUGiW+2isNfAMYvQnV1WjGo+G80acSpb+3o Dn5g== X-Gm-Message-State: AO0yUKUBd+1+FROBKMdRQEj0beJqNcE28Ub9QR6525joMUgRASOaoq/B sQKXpGnbstgdauIe0DQBPindCtxDT+Op+Jpe X-Google-Smtp-Source: AK7set9+VQTS25cnq9kebcDJK9kQmVyCm3MXd7Il+EKe2X+peMu3CUuxxrzVSI9TLycnIYE6H2Xbkg== X-Received: by 2002:aca:2806:0:b0:383:d3ae:30df with SMTP id 6-20020aca2806000000b00383d3ae30dfmr3340759oix.3.1677195884253; Thu, 23 Feb 2023 15:44:44 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Christoph Muellner , Philipp Tomsich , Daniel Henrique Barboza Subject: [PATCH v7 3/4] target/riscv: implement Zicbom extension Date: Thu, 23 Feb 2023 20:44:26 -0300 Message-Id: <20230223234427.521114-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230223234427.521114-1-dbarboza@ventanamicro.com> References: <20230223234427.521114-1-dbarboza@ventanamicro.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::233; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x233.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1677195982477100003 Content-Type: text/plain; charset="utf-8" From: Christoph Muellner Zicbom is the Cache-Block Management extension defined in the already ratified RISC-V Base Cache Management Operation (CBO) ISA extension [1]. The extension contains three instructions: cbo.clean, cbo.flush and cbo.inval. All of them must be implemented in the same group as LQ and cbo.zero due to overlapping patterns. All these instructions can throw a Illegal Instruction/Virtual Instruction exception, similar to the existing cbo.zero. The same check_zicbo_envcfg() is used to handle these exceptions. Aside from that, these instructions also need to handle page faults and guest page faults. This is done in a new check_zicbom_access() helper. As with Zicboz, the cache block size for Zicbom is also configurable. Note that the spec determines that Zicbo[mp] and Zicboz can have different cache sizes (Section 2.7 of [1]), so we also include a 'cbom_blocksize' to go along with the existing 'cboz_blocksize'. They are set to the same size, so unless users want to play around with the settings both sizes will be the same. [1] https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-= v1.0.1.pdf Co-developed-by: Philipp Tomsich Signed-off-by: Christoph Muellner Signed-off-by: Daniel Henrique Barboza Acked-by: Palmer Dabbelt Reviewed-by: Richard Henderson Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 3 + target/riscv/cpu.h | 2 + target/riscv/helper.h | 2 + target/riscv/insn32.decode | 5 ++ target/riscv/insn_trans/trans_rvzicbo.c.inc | 27 +++++++++ target/riscv/op_helper.c | 67 +++++++++++++++++++++ 6 files changed, 106 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7dd37de7f9..4b779b1775 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -74,6 +74,7 @@ struct isa_ext_data { static const struct isa_ext_data isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(h, false, PRIV_VERSION_1_12_0, ext_h), ISA_EXT_DATA_ENTRY(v, false, PRIV_VERSION_1_10_0, ext_v), + ISA_EXT_DATA_ENTRY(zicbom, true, PRIV_VERSION_1_12_0, ext_icbom), ISA_EXT_DATA_ENTRY(zicboz, true, PRIV_VERSION_1_12_0, ext_icboz), ISA_EXT_DATA_ENTRY(zicsr, true, PRIV_VERSION_1_10_0, ext_icsr), ISA_EXT_DATA_ENTRY(zifencei, true, PRIV_VERSION_1_10_0, ext_ifencei), @@ -1127,6 +1128,8 @@ static Property riscv_cpu_extensions[] =3D { DEFINE_PROP_BOOL("zhinx", RISCVCPU, cfg.ext_zhinx, false), DEFINE_PROP_BOOL("zhinxmin", RISCVCPU, cfg.ext_zhinxmin, false), =20 + DEFINE_PROP_BOOL("zicbom", RISCVCPU, cfg.ext_icbom, true), + DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64), DEFINE_PROP_BOOL("zicboz", RISCVCPU, cfg.ext_icboz, true), DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64), =20 diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6b4c714d3a..a0673b4604 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -447,6 +447,7 @@ struct RISCVCPUConfig { bool ext_zkt; bool ext_ifencei; bool ext_icsr; + bool ext_icbom; bool ext_icboz; bool ext_zihintpause; bool ext_smstateen; @@ -495,6 +496,7 @@ struct RISCVCPUConfig { char *vext_spec; uint16_t vlen; uint16_t elen; + uint16_t cbom_blocksize; uint16_t cboz_blocksize; bool mmu; bool pmp; diff --git a/target/riscv/helper.h b/target/riscv/helper.h index ce165821b8..37b54e0991 100644 --- a/target/riscv/helper.h +++ b/target/riscv/helper.h @@ -98,6 +98,8 @@ DEF_HELPER_FLAGS_2(fcvt_h_lu, TCG_CALL_NO_RWG, i64, env, = tl) DEF_HELPER_FLAGS_2(fclass_h, TCG_CALL_NO_RWG_SE, tl, env, i64) =20 /* Cache-block operations */ +DEF_HELPER_2(cbo_clean_flush, void, env, tl) +DEF_HELPER_2(cbo_inval, void, env, tl) DEF_HELPER_2(cbo_zero, void, env, tl) =20 /* Special functions */ diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index 3985bc703f..3788f86528 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -181,6 +181,11 @@ sraw 0100000 ..... ..... 101 ..... 0111011 @r ldu ............ ..... 111 ..... 0000011 @i { [ + # *** RV32 Zicbom Standard Extension *** + cbo_clean 0000000 00001 ..... 010 00000 0001111 @sfence_vm + cbo_flush 0000000 00010 ..... 010 00000 0001111 @sfence_vm + cbo_inval 0000000 00000 ..... 010 00000 0001111 @sfence_vm + # *** RV32 Zicboz Standard Extension *** cbo_zero 0000000 00100 ..... 010 00000 0001111 @sfence_vm ] diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/ins= n_trans/trans_rvzicbo.c.inc index feabc28342..7df9c30b58 100644 --- a/target/riscv/insn_trans/trans_rvzicbo.c.inc +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc @@ -16,12 +16,39 @@ * this program. If not, see . */ =20 +#define REQUIRE_ZICBOM(ctx) do { \ + if (!ctx->cfg_ptr->ext_icbom) { \ + return false; \ + } \ +} while (0) + #define REQUIRE_ZICBOZ(ctx) do { \ if (!ctx->cfg_ptr->ext_icboz) { \ return false; \ } \ } while (0) =20 +static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a) +{ + REQUIRE_ZICBOM(ctx); + gen_helper_cbo_clean_flush(cpu_env, cpu_gpr[a->rs1]); + return true; +} + +static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a) +{ + REQUIRE_ZICBOM(ctx); + gen_helper_cbo_clean_flush(cpu_env, cpu_gpr[a->rs1]); + return true; +} + +static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a) +{ + REQUIRE_ZICBOM(ctx); + gen_helper_cbo_inval(cpu_env, cpu_gpr[a->rs1]); + return true; +} + static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) { REQUIRE_ZICBOZ(ctx); diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 72a8ca31fc..5e0f0b622d 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -188,6 +188,73 @@ void helper_cbo_zero(CPURISCVState *env, target_ulong = address) } } =20 +/* + * check_zicbom_access + * + * Check access permissions (LOAD, STORE or FETCH as specified in + * section 2.5.2 of the CMO specification) for Zicbom, raising + * either store page-fault (non-virtualized) or store guest-page + * fault (virtualized). + */ +static void check_zicbom_access(CPURISCVState *env, + target_ulong address, + uintptr_t ra) +{ + RISCVCPU *cpu =3D env_archcpu(env); + int mmu_idx =3D cpu_mmu_index(env, false); + uint16_t cbomlen =3D cpu->cfg.cbom_blocksize; + void *phost; + int ret; + + /* Mask off low-bits to align-down to the cache-block. */ + address &=3D ~(cbomlen - 1); + + /* + * Section 2.5.2 of cmobase v1.0.1: + * + * "A cache-block management instruction is permitted to + * access the specified cache block whenever a load instruction + * or store instruction is permitted to access the corresponding + * physical addresses. If neither a load instruction nor store + * instruction is permitted to access the physical addresses, + * but an instruction fetch is permitted to access the physical + * addresses, whether a cache-block management instruction is + * permitted to access the cache block is UNSPECIFIED." + */ + ret =3D probe_access_flags(env, address, cbomlen, MMU_DATA_LOAD, + mmu_idx, true, &phost, ra); + if (ret !=3D TLB_INVALID_MASK) { + /* Success: readable */ + return; + } + + /* + * Since not readable, must be writable. On failure, store + * fault/store guest amo fault will be raised by + * riscv_cpu_tlb_fill(). PMP exceptions will be caught + * there as well. + */ + probe_write(env, address, cbomlen, mmu_idx, ra); +} + +void helper_cbo_clean_flush(CPURISCVState *env, target_ulong address) +{ + uintptr_t ra =3D GETPC(); + check_zicbo_envcfg(env, MENVCFG_CBCFE, ra); + check_zicbom_access(env, address, ra); + + /* We don't emulate the cache-hierarchy, so we're done. */ +} + +void helper_cbo_inval(CPURISCVState *env, target_ulong address) +{ + uintptr_t ra =3D GETPC(); + check_zicbo_envcfg(env, MENVCFG_CBIE, ra); + check_zicbom_access(env, address, ra); + + /* We don't emulate the cache-hierarchy, so we're done. */ +} + #ifndef CONFIG_USER_ONLY =20 target_ulong helper_sret(CPURISCVState *env) --=20 2.39.2 From nobody Wed May 15 08:37:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1677195939661187.1036738548935; Thu, 23 Feb 2023 15:45:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVLGj-0003Hx-FT; Thu, 23 Feb 2023 18:44:57 -0500 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 1pVLGe-0002xb-1M for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:53 -0500 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVLGb-0001KY-3T for qemu-devel@nongnu.org; Thu, 23 Feb 2023 18:44:50 -0500 Received: by mail-oi1-x22d.google.com with SMTP id q15so6372781oiw.11 for ; Thu, 23 Feb 2023 15:44:48 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([189.110.112.117]) by smtp.gmail.com with ESMTPSA id v6-20020acaac06000000b0037facb2c5fasm2415037oie.1.2023.02.23.15.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 15:44:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=h8I3/loqCXLPJq7Ot2kL3eJ1UPZjr/7NB5ZYHvYcxs4=; b=imujGTV38KanAbz+1syHxNbF7Vn546Ubi4yOTuN9p25GAxwMzcZUkuVUc2x9Vtx4Q4 A2ZIiDseVxZaK8mB3ZGBDB9UKh0cQfoJGZuKSzU0/sLccPbyj6YSz3un2RFpeZlx96aa 330GnM3rhcON7Wl+WfVpeXjnNc+gtysvIioUbxLscqcUGNLwKkw1qv9KJ8dJwBZEKpUq K2/DVO09KnVZXEhewnrq/FqmD0tSKmYfRsnnaUd9JqMZhiUxxGYKwYIvNxGtE4LGJooN UoyF3QdfwNOpQGaZL8S049rfEXR9gXjIw8pMjXE8fNzeY+II9L/4jSkrPnEEp2EWDB+T aSRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=h8I3/loqCXLPJq7Ot2kL3eJ1UPZjr/7NB5ZYHvYcxs4=; b=nHngbZhTxcjpEf82Hp+5OYl8l27CJN+kzPsK/9EtRk71TzayEbRXIzV9HtKpORXejt MSZIeIZripUWdN2IUPwfxLwdAv/VOqVhKtwtwQYly1v/7+sJQdT7iFP4BrPw3lieUTGn bNvWWSYLR/5HwZAr5KzdUJfqTKZSoCHdjAXbuO81Y7lPqx35T24EJztLG1wga9pQAe+q OOo7IuoXSu7tPw9hCZzm6a1ZvWfNsjWJY0zBAFXkvC8MBqeULnzMtmNdcNWYp663p067 +G8i2/ZJazciX59dEwDvNPA541d+aewzS68a2/9UXMEZvZEVz+eo+ChKoOhF9rz3IK4a AWZg== X-Gm-Message-State: AO0yUKWIcQnwYScW6wX5fJKn4NlUUXiU1xeVUogRz1tS5Ny4WHpPS1uR DuqRKE0F7WzT8GBW9LRLCagmpVii0oRvuNmy X-Google-Smtp-Source: AK7set88f6pzFSx0pk4VL/FFSoXGpCHrk0NAlGC+mBUzJ4RalCNjgoZYMuW67wBAnB+VBHT1HeAL6g== X-Received: by 2002:a05:6808:4089:b0:37b:2977:4889 with SMTP id db9-20020a056808408900b0037b29774889mr3102154oib.52.1677195887601; Thu, 23 Feb 2023 15:44:47 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Christoph Muellner , Philipp Tomsich , Daniel Henrique Barboza Subject: [PATCH v7 4/4] target/riscv: add Zicbop cbo.prefetch{i, r, m} placeholder Date: Thu, 23 Feb 2023 20:44:27 -0300 Message-Id: <20230223234427.521114-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230223234427.521114-1-dbarboza@ventanamicro.com> References: <20230223234427.521114-1-dbarboza@ventanamicro.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::22d; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1677195940291100002 Content-Type: text/plain; charset="utf-8" From: Christoph Muellner The cmo.prefetch instructions are nops for QEMU (no emulation of the memory hierarchy, no illegal instructions, no permission faults, no traps). Add a comment noting where they would be decoded in case cbo.prefetch instructions become relevant in the future. Co-developed-by: Philipp Tomsich Signed-off-by: Christoph Muellner Signed-off-by: Daniel Henrique Barboza Reviewed-by: Richard Henderson Acked-by: Palmer Dabbelt Reviewed-by: Weiwei Li --- target/riscv/insn32.decode | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index 3788f86528..1aebd37572 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -134,6 +134,7 @@ addi ............ ..... 000 ..... 0010011 @i slti ............ ..... 010 ..... 0010011 @i sltiu ............ ..... 011 ..... 0010011 @i xori ............ ..... 100 ..... 0010011 @i +# cbo.prefetch_{i,r,m} instructions are ori with rd=3Dx0 and not decoded. ori ............ ..... 110 ..... 0010011 @i andi ............ ..... 111 ..... 0010011 @i slli 00000. ...... ..... 001 ..... 0010011 @sh --=20 2.39.2