From patchwork Tue Sep 3 16:08:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 172834 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp64715ily; Tue, 3 Sep 2019 09:17:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqw617JAnZSOWOKIMQdmzK8ZIsr+GXcDqSFiFwsIscWdgma72R4FJveiueJgE85HQpdRwk6A X-Received: by 2002:a37:9e0d:: with SMTP id h13mr34991428qke.473.1567527432329; Tue, 03 Sep 2019 09:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567527432; cv=none; d=google.com; s=arc-20160816; b=XtLjff41lRXxkGMxm7qhGtAKaNr6V79Wx8CIUxlJEADn+mo5UFEoMrVDFKLrI16bfb dOst3rqeq+t7/EvOtUXu97MWDqj1bdjkbTpOI+8sJ6GtKOQPy8cTgF4fFsTRNYxXJQ3n k18Wlx9KD5uAaQU3SP8d+IH08ajiYWnQfhI0454Wt9tqit8hUtmqKTByRBE8WIStYnto UJVrmSVMSfyHl6QTQdzGrCNVIdiJNS4xrmuTc0iBG6MijOk24kU+FBvIM8qi3e4WU4sP eqBqyKpX8+8r+2pBd76Mp4kvSX6falID5EMEZ4z2IGvzVZvKnvUk0TqRtt5ForpZFHJ0 tX6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=Skix+hAgqMkCzdxrRQp/gwNaGRFVNBB95exG932vdjo=; b=0jz5HLXzR7sRcGxlwTm+dPxcrOv/x5au04hlIS31cXNTBTMOjUdQJEs7HEUwWKJ1SG 3iegm2VZwZT83rD7LvoJBFHs24X0f+sepEIe2HoHD4lpLe4gtKpItOHF+ZAfln8PDKbq jOAS+RQl9XgWeJdH72dG6vtydRt5t4stiLsTL+hvEMz+5kOVHnejgJJLkxS2ZqAAoqxF ZiaOJVZ4NVZSLgiIS5A3gm91z1HKWFx+wyP8WrInRli+GuZi6SDKwaTAQKymr9TWIrHH pbXISE0vRlRlIMVAM+nSPn2b++xgJQGt0hvZnA3E9QosVbMPKYq3t4YPKI0hfBIo9khM jKmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TpBdmGv+; 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=fail (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 c4si6949533qkg.74.2019.09.03.09.17.12 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Sep 2019 09:17:12 -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=fail header.i=@linaro.org header.s=google header.b=TpBdmGv+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5BUV-0000BH-2k for patch@linaro.org; Tue, 03 Sep 2019 12:17:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37343) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5BN5-0001Ql-2y for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5BN3-0003tV-AL for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:30 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:44927) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i5BN3-0003t6-2m for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:29 -0400 Received: by mail-pg1-x541.google.com with SMTP id i18so9387464pgl.11 for ; Tue, 03 Sep 2019 09:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Skix+hAgqMkCzdxrRQp/gwNaGRFVNBB95exG932vdjo=; b=TpBdmGv+5MkNpu9HvgSnqMGezjjxtUG7IbwCXvaNUvm7cuNgdW8F5V64tMRFQ94R64 ZugxkV1tGUTK1D7cv3yUqDk1fkXj9fUn6oEsLFAC5L3ROxhyl0mtweMA4X1v5VgFSCQ5 ehyHvceNQStg+ilWq34uoY5kVrijlHHre3Kb5LGQUZ2mFM8cPxqxoVENk0NMWmvv8rYL DTscR4DOUuX6qEV044XTFN9G/qczbXiiav0EZgeaMM3XrqBTe0lNQ9G6EaYAxs48cyH6 v5xG5fDtpCXl1mpXCRiFViw6fA7jeSf+reruHCHM+530QeYmhccp4TbFtPzPytk55zgf 1lnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Skix+hAgqMkCzdxrRQp/gwNaGRFVNBB95exG932vdjo=; b=TZMmCvPXIMEK4FbkP49rH8/KgUtydl/aN8eFndHNBjinSsw/rwLH8QraFCrzW04bCd c1/tgYw0eBdJObyh+3y6BjcgzmyUYrvo1rmvVPolSk78GjXRFfnVLezChOaXks2g5ql9 O0njKkN38ax/k8hLtp3Mr+Tld8+9NsPyv45G1sZDmLv07Vh9HtQ3nexBRv7TbwNRxDPK RKFocuvJCsuUT8rt0snyILTgYqnneqD22foQ/nD/seEo3PQRXvaLz8l4vv57gch7Y7Y6 X1XxYGdSAWTn3tSms88eXX21DOLAVAbtX1bDq63g6AdLu6z4eMHCuD7Xoc3ChzFfM3cE sQeg== X-Gm-Message-State: APjAAAUYbNbg7nVLDG84RW6L8QA+38f6183MCUwnoE7cvgLFKE0bvbMI ovJjirGrh9LbR4X+7g2mqjXoRhVOT40= X-Received: by 2002:a17:90a:734a:: with SMTP id j10mr20125pjs.63.1567526967815; Tue, 03 Sep 2019 09:09:27 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id 127sm28089711pfy.56.2019.09.03.09.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 09:09:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 3 Sep 2019 09:08:44 -0700 Message-Id: <20190903160858.5296-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190903160858.5296-1-richard.henderson@linaro.org> References: <20190903160858.5296-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH 22/36] cputlb: Fold TLB_RECHECK into TLB_INVALID_MASK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We had two different mechanisms to force a recheck of the tlb. Before TLB_RECHECK was introduced, we had a PAGE_WRITE_INV bit that would immediate set TLB_INVALID_MASK, which automatically means that a second check of the tlb entry fails. We can use the same mechanism to handle small pages. Conserve TLB_* bits by removing TLB_RECHECK. Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 5 +-- accel/tcg/cputlb.c | 86 +++++++++++------------------------------- 2 files changed, 24 insertions(+), 67 deletions(-) -- 2.17.1 diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 8323094648..8d07ae23a5 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -329,14 +329,11 @@ CPUArchState *cpu_copy(CPUArchState *env); #define TLB_NOTDIRTY (1 << (TARGET_PAGE_BITS - 2)) /* Set if TLB entry is an IO callback. */ #define TLB_MMIO (1 << (TARGET_PAGE_BITS - 3)) -/* Set if TLB entry must have MMU lookup repeated for every access */ -#define TLB_RECHECK (1 << (TARGET_PAGE_BITS - 4)) /* Use this mask to check interception with an alignment mask * in a TCG backend. */ -#define TLB_FLAGS_MASK (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO \ - | TLB_RECHECK) +#define TLB_FLAGS_MASK (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO) /** * tlb_hit_page: return true if page aligned @addr is a hit against the diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index d9787cc893..c9576bebcf 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -732,11 +732,8 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, address = vaddr_page; if (size < TARGET_PAGE_SIZE) { - /* - * Slow-path the TLB entries; we will repeat the MMU check and TLB - * fill on every access. - */ - address |= TLB_RECHECK; + /* Repeat the MMU check and TLB fill on every access. */ + address |= TLB_INVALID_MASK; } if (attrs.byte_swap) { /* Force the access through the I/O slow path. */ @@ -1026,10 +1023,15 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index, victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ (ADDR) & TARGET_PAGE_MASK) -/* NOTE: this function can trigger an exception */ -/* NOTE2: the returned address is not exactly the physical address: it - * is actually a ram_addr_t (in system mode; the user mode emulation - * version of this function returns a guest virtual address). +/* + * Return a ram_addr_t for the virtual address for execution. + * + * Return -1 if we can't translate and execute from an entire page + * of RAM. This will force us to execute by loading and translating + * one insn at a time, without caching. + * + * NOTE: This function will trigger an exception if the page is + * not executable. */ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) { @@ -1043,19 +1045,20 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) tlb_fill(env_cpu(env), addr, 0, MMU_INST_FETCH, mmu_idx, 0); index = tlb_index(env, mmu_idx, addr); entry = tlb_entry(env, mmu_idx, addr); + + if (unlikely(entry->addr_code & TLB_INVALID_MASK)) { + /* + * The MMU protection covers a smaller range than a target + * page, so we must redo the MMU check for every insn. + */ + return -1; + } } assert(tlb_hit(entry->addr_code, addr)); } - if (unlikely(entry->addr_code & (TLB_RECHECK | TLB_MMIO))) { - /* - * Return -1 if we can't translate and execute from an entire - * page of RAM here, which will cause us to execute by loading - * and translating one insn at a time, without caching: - * - TLB_RECHECK: means the MMU protection covers a smaller range - * than a target page, so we must redo the MMU check every insn - * - TLB_MMIO: region is not backed by RAM - */ + if (unlikely(entry->addr_code & TLB_MMIO)) { + /* The region is not backed by RAM. */ return -1; } @@ -1180,7 +1183,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, } /* Notice an IO access or a needs-MMU-lookup access */ - if (unlikely(tlb_addr & (TLB_MMIO | TLB_RECHECK))) { + if (unlikely(tlb_addr & TLB_MMIO)) { /* There's really nothing that can be done to support this apart from stop-the-world. */ goto stop_the_world; @@ -1258,6 +1261,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, entry = tlb_entry(env, mmu_idx, addr); } tlb_addr = code_read ? entry->addr_code : entry->addr_read; + tlb_addr &= ~TLB_INVALID_MASK; } /* Handle an IO access. */ @@ -1265,27 +1269,6 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, if ((addr & (size - 1)) != 0) { goto do_unaligned_access; } - - if (tlb_addr & TLB_RECHECK) { - /* - * This is a TLB_RECHECK access, where the MMU protection - * covers a smaller range than a target page, and we must - * repeat the MMU check here. This tlb_fill() call might - * longjump out if this access should cause a guest exception. - */ - tlb_fill(env_cpu(env), addr, size, - access_type, mmu_idx, retaddr); - index = tlb_index(env, mmu_idx, addr); - entry = tlb_entry(env, mmu_idx, addr); - - tlb_addr = code_read ? entry->addr_code : entry->addr_read; - tlb_addr &= ~TLB_RECHECK; - if (!(tlb_addr & ~TARGET_PAGE_MASK)) { - /* RAM access */ - goto do_aligned_access; - } - } - return io_readx(env, &env_tlb(env)->d[mmu_idx].iotlb[index], mmu_idx, addr, retaddr, access_type, op); } @@ -1314,7 +1297,6 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, return res & MAKE_64BIT_MASK(0, size * 8); } - do_aligned_access: haddr = (void *)((uintptr_t)addr + entry->addend); switch (op) { case MO_UB: @@ -1509,27 +1491,6 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, if ((addr & (size - 1)) != 0) { goto do_unaligned_access; } - - if (tlb_addr & TLB_RECHECK) { - /* - * This is a TLB_RECHECK access, where the MMU protection - * covers a smaller range than a target page, and we must - * repeat the MMU check here. This tlb_fill() call might - * longjump out if this access should cause a guest exception. - */ - tlb_fill(env_cpu(env), addr, size, MMU_DATA_STORE, - mmu_idx, retaddr); - index = tlb_index(env, mmu_idx, addr); - entry = tlb_entry(env, mmu_idx, addr); - - tlb_addr = tlb_addr_write(entry); - tlb_addr &= ~TLB_RECHECK; - if (!(tlb_addr & ~TARGET_PAGE_MASK)) { - /* RAM access */ - goto do_aligned_access; - } - } - io_writex(env, &env_tlb(env)->d[mmu_idx].iotlb[index], mmu_idx, val, addr, retaddr, op); return; @@ -1579,7 +1540,6 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, return; } - do_aligned_access: haddr = (void *)((uintptr_t)addr + entry->addend); switch (op) { case MO_UB: