From patchwork Tue Oct 4 14:10:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 612293 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp238505pvb; Tue, 4 Oct 2022 08:11:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7H1Ka7lNc6sq6ObBS4aa/iYrpwLS6EvRsHsbJqxZjBqebKbIOZBm7vxFjo8xe/PYF6CQTn X-Received: by 2002:a05:620a:2954:b0:6cf:9084:f7ab with SMTP id n20-20020a05620a295400b006cf9084f7abmr17093349qkp.355.1664896283863; Tue, 04 Oct 2022 08:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664896283; cv=none; d=google.com; s=arc-20160816; b=RoPq2T2neGsYUXxYRCyfSxnCU5LjNTs6potciNLnIrCDI1OIaKsgUXvTbpWr682Li+ 1rtVeakwQg5bXpHVRl8BjvqasNaHc/IE6OSIav0HqVXKD8Fs74yYnFocsMC7aVG6WAfa SU4F0DRJFPn2bvYJBj7dQerhpT5rHMlEpJ6sHR/2bcTFHroDm9pYh4EOXtuDBCfvfuXx mbpavHsQ4R1Fde1ae8mPDbiVFKnpaxi7RqZ3Eegj6R9qPWftYfSEjvnHhuPrALhOit4p uKuS0c1yHYUWWw390gq46Bv//zBe0I65jtqV9wNy7ppp+eYQOumuQA52JqzP7EKd1XMl bBcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wqv6omjESGpT0GzTsXvELEKQHyruXHoBEMwfSKPGC6w=; b=dNK0hj24I5ZsiANDyHJN4wxHDhiFgP9fOdF0YQlr0rSKAERPhhcNxD//fDhEkXdfFi 1xb8O1sX7aOKFe4ld0u6yq1j/1QnrxHgSxAsmzX5dwuaQLohx9Pas3iUVlZUmBq5X62Q 2a7JAe4Vsl8QekjWtoCyT+DsuxBwOm5044Y+q2O1TrfVJWqt1Iwe80YovnNbdP6AtaHw 4R1gKZNUA11OTaoMQYAbkFri3+6F/XAcRF+gBxifId2YbOSsROMMqK6u/E5kyK1h+rPp /UR+sq4MA7jHbPi68RB2TnW/hsLIf8uBo4UxSWR8UUsa+2mTgzCi/3HhFNJY1c3IUo+u ydmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QZWpJayN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bz10-20020a05622a1e8a00b0035cf238b0c1si5455184qtb.179.2022.10.04.08.11.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Oct 2022 08:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QZWpJayN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofjZr-00037x-Bc for patch@linaro.org; Tue, 04 Oct 2022 11:11:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofida-0002Zw-Cc for qemu-devel@nongnu.org; Tue, 04 Oct 2022 10:11:10 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:41625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofidY-0004Js-4Y for qemu-devel@nongnu.org; Tue, 04 Oct 2022 10:11:10 -0400 Received: by mail-pf1-x429.google.com with SMTP id g130so12656456pfb.8 for ; Tue, 04 Oct 2022 07:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=wqv6omjESGpT0GzTsXvELEKQHyruXHoBEMwfSKPGC6w=; b=QZWpJayNrcbcZCVJOZ8/nudV4umP8OPBIMkcfiW0LCv1dIGYSUMDDXqA/lEEStD1vS YrJ4QcbF6URjT9RlaShVCRG1hhvFyG3wuKqToINM6NzLxog572yaLxXTSQFx6jwedCyg TPTt1ecRXo5v47igZH1ugIqPZDpTCfbYO+JFZjdIjtEe9JZR37Tdx0NC3HyNz8W1Hq2s YPfo5X15gDiFo/Du+5U23QertpaZT/ci4+knReett6XUJK/iYC8IPQM9TuHQ2jwcbyFG Ra5IhNPeZFfPtpwiB7p+UnlXGpaAduWB7a8e1ucrEIwDPV5hKAR9DcT2buxweHaRK+BW QNYQ== 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; bh=wqv6omjESGpT0GzTsXvELEKQHyruXHoBEMwfSKPGC6w=; b=PaU5Ve+SFHPNUpuCe9XIVHHuGOFksAuw6fOhC/2UjyuQVw1DcHPhNsY5rqp9ZXABF2 Add78eAaDxrPl4vNJnDGVr6Hzh5nlWbRIRi9eipKQ7aNlNiMPZJyxvVaQoEGXYfaUzeV likgGBrYWl61fq7sbpIeroxPRFUXCDRU7xGZ+59xsi5rYJGpj30z/T/cY6xYL2TUa6Jb rtijJWKf5uP1q+/o2ei075dz65+NFYoxTXycv189cCkAC21s8AxTNu1JxTwPJHqvozOx IXcBqqfZQ3iaNhMmM5K/plVMTLlq+JwGpEP+s0o9ntIDoNd5cPRawX6xC+kAGKYIQ+IM WG4w== X-Gm-Message-State: ACrzQf16fvshxSHPW786/mXfymzbic8upngkFfm+skmCP0++wMCdJQ3G atycWj50LOr1OkgxQiyEZFt1wT+O/Utn5A== X-Received: by 2002:a62:7b17:0:b0:561:9478:b2bc with SMTP id w23-20020a627b17000000b005619478b2bcmr7360751pfc.34.1664892666616; Tue, 04 Oct 2022 07:11:06 -0700 (PDT) Received: from stoup.. ([2605:ef80:8015:12b0:403e:a15b:ff5e:d439]) by smtp.gmail.com with ESMTPSA id y5-20020aa79ae5000000b00561382a5a25sm1240357pfp.26.2022.10.04.07.11.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 07:11:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v7 07/18] accel/tcg: Introduce probe_access_full Date: Tue, 4 Oct 2022 07:10:40 -0700 Message-Id: <20221004141051.110653-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004141051.110653-1-richard.henderson@linaro.org> References: <20221004141051.110653-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add an interface to return the CPUTLBEntryFull struct that goes with the lookup. The result is not intended to be valid across multiple lookups, so the user must use the results immediately. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 15 +++++++++++++ include/qemu/typedefs.h | 1 + accel/tcg/cputlb.c | 47 +++++++++++++++++++++++++---------------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index bcad607c4e..d255d69bc1 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -434,6 +434,21 @@ int probe_access_flags(CPUArchState *env, target_ulong addr, MMUAccessType access_type, int mmu_idx, bool nonfault, void **phost, uintptr_t retaddr); +#ifndef CONFIG_USER_ONLY +/** + * probe_access_full: + * Like probe_access_flags, except also return into @pfull. + * + * The CPUTLBEntryFull structure returned via @pfull is transient + * and must be consumed or copied immediately, before any further + * access or changes to TLB @mmu_idx. + */ +int probe_access_full(CPUArchState *env, target_ulong addr, + MMUAccessType access_type, int mmu_idx, + bool nonfault, void **phost, + CPUTLBEntryFull **pfull, uintptr_t retaddr); +#endif + #define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */ /* Estimated block size for TB allocation. */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 42f4ceb701..a4aee238c7 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -42,6 +42,7 @@ typedef struct ConfidentialGuestSupport ConfidentialGuestSupport; typedef struct CPUAddressSpace CPUAddressSpace; typedef struct CPUArchState CPUArchState; typedef struct CPUState CPUState; +typedef struct CPUTLBEntryFull CPUTLBEntryFull; typedef struct DeviceListener DeviceListener; typedef struct DeviceState DeviceState; typedef struct DirtyBitmapSnapshot DirtyBitmapSnapshot; diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 264f84a248..e3ee4260bd 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1510,7 +1510,8 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size, static int probe_access_internal(CPUArchState *env, target_ulong addr, int fault_size, MMUAccessType access_type, int mmu_idx, bool nonfault, - void **phost, uintptr_t retaddr) + void **phost, CPUTLBEntryFull **pfull, + uintptr_t retaddr) { uintptr_t index = tlb_index(env, mmu_idx, addr); CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); @@ -1543,10 +1544,12 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, mmu_idx, nonfault, retaddr)) { /* Non-faulting page table read failed. */ *phost = NULL; + *pfull = NULL; return TLB_INVALID_MASK; } /* TLB resize via tlb_fill may have moved the entry. */ + index = tlb_index(env, mmu_idx, addr); entry = tlb_entry(env, mmu_idx, addr); /* @@ -1560,6 +1563,8 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, } flags &= tlb_addr; + *pfull = &env_tlb(env)->d[mmu_idx].fulltlb[index]; + /* Fold all "mmio-like" bits into TLB_MMIO. This is not RAM. */ if (unlikely(flags & ~(TLB_WATCHPOINT | TLB_NOTDIRTY))) { *phost = NULL; @@ -1571,37 +1576,44 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, return flags; } -int probe_access_flags(CPUArchState *env, target_ulong addr, - MMUAccessType access_type, int mmu_idx, - bool nonfault, void **phost, uintptr_t retaddr) +int probe_access_full(CPUArchState *env, target_ulong addr, + MMUAccessType access_type, int mmu_idx, + bool nonfault, void **phost, CPUTLBEntryFull **pfull, + uintptr_t retaddr) { - int flags; - - flags = probe_access_internal(env, addr, 0, access_type, mmu_idx, - nonfault, phost, retaddr); + int flags = probe_access_internal(env, addr, 0, access_type, mmu_idx, + nonfault, phost, pfull, retaddr); /* Handle clean RAM pages. */ if (unlikely(flags & TLB_NOTDIRTY)) { - uintptr_t index = tlb_index(env, mmu_idx, addr); - CPUTLBEntryFull *full = &env_tlb(env)->d[mmu_idx].fulltlb[index]; - - notdirty_write(env_cpu(env), addr, 1, full, retaddr); + notdirty_write(env_cpu(env), addr, 1, *pfull, retaddr); flags &= ~TLB_NOTDIRTY; } return flags; } +int probe_access_flags(CPUArchState *env, target_ulong addr, + MMUAccessType access_type, int mmu_idx, + bool nonfault, void **phost, uintptr_t retaddr) +{ + CPUTLBEntryFull *full; + + return probe_access_full(env, addr, access_type, mmu_idx, + nonfault, phost, &full, retaddr); +} + void *probe_access(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { + CPUTLBEntryFull *full; void *host; int flags; g_assert(-(addr | TARGET_PAGE_MASK) >= size); flags = probe_access_internal(env, addr, size, access_type, mmu_idx, - false, &host, retaddr); + false, &host, &full, retaddr); /* Per the interface, size == 0 merely faults the access. */ if (size == 0) { @@ -1609,9 +1621,6 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, } if (unlikely(flags & (TLB_NOTDIRTY | TLB_WATCHPOINT))) { - uintptr_t index = tlb_index(env, mmu_idx, addr); - CPUTLBEntryFull *full = &env_tlb(env)->d[mmu_idx].fulltlb[index]; - /* Handle watchpoints. */ if (flags & TLB_WATCHPOINT) { int wp_access = (access_type == MMU_DATA_STORE @@ -1632,11 +1641,12 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, MMUAccessType access_type, int mmu_idx) { + CPUTLBEntryFull *full; void *host; int flags; flags = probe_access_internal(env, addr, 0, access_type, - mmu_idx, true, &host, 0); + mmu_idx, true, &host, &full, 0); /* No combination of flags are expected by the caller. */ return flags ? NULL : host; @@ -1655,10 +1665,11 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, void **hostp) { + CPUTLBEntryFull *full; void *p; (void)probe_access_internal(env, addr, 1, MMU_INST_FETCH, - cpu_mmu_index(env, true), false, &p, 0); + cpu_mmu_index(env, true), false, &p, &full, 0); if (p == NULL) { return -1; }