From patchwork Thu Mar 3 19:15:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 547794 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:3c7:0:0:0:0 with SMTP id b7csp1177860wrg; Thu, 3 Mar 2022 11:18:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkunF9bGAUxdx8lR4TkPu8Mm5UP8PGdcnFJFFKWHc3pz78Qpx4hYnReJHKU3SC8SvS3B3f X-Received: by 2002:a81:1a09:0:b0:2dc:1455:52a3 with SMTP id a9-20020a811a09000000b002dc145552a3mr8714839ywa.236.1646335123596; Thu, 03 Mar 2022 11:18:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646335123; cv=none; d=google.com; s=arc-20160816; b=sm7DCV3A7DxfkxkAPqWIoAfoiLDKZ+UuYkjaAoGpx4UG7UyQVBiJQzJ7yoDV9Fhwmj xsyOfnxrdyE55RC7bI2JkP73rEEahe3B+lrwDtwgtj/5JUlcu3cNHRRlISdmRAyMrA25 +zkOgbBUEC/WpX1CfUkLvBQvZ6Idc259sVfnETIAYx4zoaQ3Umkx3niQO+3yPgsdGVsO JSpwn+Dg1HhPQfvAbMWLxoASlhcT4aCLExXBZ3njC4/MhPm0ltKD7DP1Ysbo/1ARgTUy QbvW6r05tZaq4hH+G7AZFYw+W790UwxcPC+T0ob5iWnjIXGDKBA/iXKdgtWGBMbHcNhU JWdQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=f5NF1Xhw+Erdj+thQwPRUzILFmSAD0uMaYQuiNMvI6I=; b=U3XPw0YIDU9TssJh78a88QJ775WRLMd5Dfwb4lAw10iSSfVfo7gw0m8Wd17OhM87lg AVWysbOFCB9Upwckb6YRCGSOfDTfWY2p6jGZ0znFpizcyl09LLKNG9WgUClLO/DiNlD+ oIC+n3kbb5IqoCjwVO8U6kRB0LxYIyIOaAgw93MlmR4WJMGtcWT4YQPChkTAF6lelVvD SLIhKF5Ubitp78peIukressw5Xlg894UhxkFuzOkcMtRngoQRi2ciz8Ucs9iiLK/GhKn BprMP925lv5KWkZEVN8duvK0rSUFr9B5y9Lr6pLeZ1ep7N6nESzn4follZnJZhfIuYA/ VMQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CTTYz6SR; 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 v8-20020a258488000000b00628b259eb9csi2718246ybk.147.2022.03.03.11.18.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Mar 2022 11:18:43 -0800 (PST) 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=CTTYz6SR; 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]:60156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPqyI-0002vR-Tm for patch@linaro.org; Thu, 03 Mar 2022 14:18:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPqvo-0001sN-La for qemu-devel@nongnu.org; Thu, 03 Mar 2022 14:16:08 -0500 Received: from [2607:f8b0:4864:20::52b] (port=41813 helo=mail-pg1-x52b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nPqvk-0007SQ-0B for qemu-devel@nongnu.org; Thu, 03 Mar 2022 14:16:08 -0500 Received: by mail-pg1-x52b.google.com with SMTP id o26so5450723pgb.8 for ; Thu, 03 Mar 2022 11:15:57 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=f5NF1Xhw+Erdj+thQwPRUzILFmSAD0uMaYQuiNMvI6I=; b=CTTYz6SRD4maCA0i70BHCznp+kU+4cuT7ar01WLuhcim92aPZHQaT5xcbtU7I1UEsn lxrlEgM05kKu4BX34Bnal8cfTXBwzh6spoDoMhBnFRybL64izNK/GKvRudfN+DtG7lCH hA1IwV2hRl5KRL/Pe0ht7p5oxrxWmrXn0ZHuoYFgz9eYKSsoeWLHyHvnzg1vL99pz5mK q8pP4HG3Bffm+yYMZjB0WKcY/ekDq4GPud49aPFYtwRW0Lj72Hegbj0Q3wtx9l3qbPZC Sw6ot4j7f/vwVsavaYHRNSoU6wp/6ucqGyHxYPII9428SA62pbCetMPcJ7e5vSB6EmIg lClw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f5NF1Xhw+Erdj+thQwPRUzILFmSAD0uMaYQuiNMvI6I=; b=qwATwJjeN6I6pCzHgFs2YjKqMfwr8I+ckhz8/NHNdI5O1LMk3Vq6IRoPOC95eyoeY7 dWsaENOCK9BwR4fhhM1n7FX7BGWh4jhJe7564iIzA2VT8O1xDkJ8BlhAFW2hHQfNILhe BQkWhF7od+xpKCmCaIsv6MqJJs03hirL09JbfIGTtSqlsv/IswEtPVzTCV4d/sxrDag4 6R41OHjWkmkOO97GWBFMeiT2HvfnRkb5uJqTBByGOTWtffwnEAtkRxa52fLgePLDzJoW uvVBzvo6wL/QggLyUwriiNge8wmGbg1LxSplfcUXAQZuCfD1XHBdrHZfY3Ax1+pWD158 9Y3Q== X-Gm-Message-State: AOAM532Iu51fC82Bk8PSdnr4fQySlQ/87R0bxl/aiKjLzBRhoeyLkK2D EMzv4oUvw+5Rim2ZgRgIlKDBRIBQ8IbNsw== X-Received: by 2002:a05:6a00:24c7:b0:4e1:cb76:32d1 with SMTP id d7-20020a056a0024c700b004e1cb7632d1mr39486434pfv.36.1646334956978; Thu, 03 Mar 2022 11:15:56 -0800 (PST) Received: from localhost.localdomain (2603-800c-1201-c600-119c-490c-a4ee-08e8.res6.spectrum.com. [2603:800c:1201:c600:119c:490c:a4ee:8e8]) by smtp.gmail.com with ESMTPSA id u25-20020a62ed19000000b004f140515d56sm3318043pfh.46.2022.03.03.11.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 11:15:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 2/9] accel/tcg: Split out g2h_tlbe Date: Thu, 3 Mar 2022 09:15:44 -1000 Message-Id: <20220303191551.466631-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220303191551.466631-1-richard.henderson@linaro.org> References: <20220303191551.466631-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52b (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: WANG Xuerui , Alistair Francis , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create a new function to combine a CPUTLBEntry addend with the guest address to form a host address. Reviewed-by: WANG Xuerui Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 3b918fe018..0e62aa5d7c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -91,6 +91,11 @@ static inline size_t sizeof_tlb(CPUTLBDescFast *fast) return fast->mask + (1 << CPU_TLB_ENTRY_BITS); } +static inline uintptr_t g2h_tlbe(const CPUTLBEntry *tlb, target_ulong gaddr) +{ + return tlb->addend + (uintptr_t)gaddr; +} + static void tlb_window_reset(CPUTLBDesc *desc, int64_t ns, size_t max_entries) { @@ -986,8 +991,7 @@ static void tlb_reset_dirty_range_locked(CPUTLBEntry *tlb_entry, if ((addr & (TLB_INVALID_MASK | TLB_MMIO | TLB_DISCARD_WRITE | TLB_NOTDIRTY)) == 0) { - addr &= TARGET_PAGE_MASK; - addr += tlb_entry->addend; + addr = g2h_tlbe(tlb_entry, addr & TARGET_PAGE_MASK); if ((addr - start) < length) { #if TCG_OVERSIZED_GUEST tlb_entry->addr_write |= TLB_NOTDIRTY; @@ -1537,7 +1541,7 @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, return -1; } - p = (void *)((uintptr_t)addr + entry->addend); + p = (void *)g2h_tlbe(entry, addr); if (hostp) { *hostp = p; } @@ -1629,7 +1633,7 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, } /* Everything else is RAM. */ - *phost = (void *)((uintptr_t)addr + entry->addend); + *phost = (void *)g2h_tlbe(entry, addr); return flags; } @@ -1737,7 +1741,7 @@ bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx, data->v.io.offset = (iotlbentry->addr & TARGET_PAGE_MASK) + addr; } else { data->is_io = false; - data->v.ram.hostaddr = (void *)((uintptr_t)addr + tlbe->addend); + data->v.ram.hostaddr = (void *)g2h_tlbe(tlbe, addr); } return true; } else { @@ -1836,7 +1840,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, goto stop_the_world; } - hostaddr = (void *)((uintptr_t)addr + tlbe->addend); + hostaddr = (void *)g2h_tlbe(tlbe, addr); if (unlikely(tlb_addr & TLB_NOTDIRTY)) { notdirty_write(env_cpu(env), addr, size, @@ -1967,7 +1971,7 @@ load_helper(CPUArchState *env, target_ulong addr, MemOpIdx oi, access_type, op ^ (need_swap * MO_BSWAP)); } - haddr = (void *)((uintptr_t)addr + entry->addend); + haddr = (void *)g2h_tlbe(entry, addr); /* * Keep these two load_memop separate to ensure that the compiler @@ -2004,7 +2008,7 @@ load_helper(CPUArchState *env, target_ulong addr, MemOpIdx oi, return res & MAKE_64BIT_MASK(0, size * 8); } - haddr = (void *)((uintptr_t)addr + entry->addend); + haddr = (void *)g2h_tlbe(entry, addr); return load_memop(haddr, op); } @@ -2375,7 +2379,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, notdirty_write(env_cpu(env), addr, size, iotlbentry, retaddr); } - haddr = (void *)((uintptr_t)addr + entry->addend); + haddr = (void *)g2h_tlbe(entry, addr); /* * Keep these two store_memop separate to ensure that the compiler @@ -2400,7 +2404,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, return; } - haddr = (void *)((uintptr_t)addr + entry->addend); + haddr = (void *)g2h_tlbe(entry, addr); store_memop(haddr, val, op); }