From patchwork Sat Sep 16 03:30:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 723542 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp708589wro; Fri, 15 Sep 2023 20:31:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDfG50q8I6qPKhSy814FWEu44Te16LebRkSS4JJicEADMBZ/2RgmmDz7KbUKuX+i1SWDLD X-Received: by 2002:a05:622a:1789:b0:400:84e2:74d8 with SMTP id s9-20020a05622a178900b0040084e274d8mr3549674qtk.25.1694835090834; Fri, 15 Sep 2023 20:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694835090; cv=none; d=google.com; s=arc-20160816; b=CHEMFpzxEdlfjjqY928rnblGWsX0SXXkgyLi3H2S56CahZHv1iRiXcbINn/Cng1sLK /7I/E2qWVCY3HSc3CnLWkyoJ/Q5w4bwJ4PxaIUdtd0BV+bJGAqN6dSKqQ0Vwhuv0tiEJ De4Cpu51eGNdctXATwbpgBhzsHpfuvwEzXEsB2HA/bpPFHApOs3Ijd7HENSrHeES+db4 IlRZFa6xhtGuSvnb4Aq/8yRxbH3N33uXX0u0Rso6Fsd8nAXZVfbEFS9furCNxura+9vy x0S6Z5/N5n7CiWukQ0/U7NAl1uywvQnvtRkgLjIeO97BDZaMDfOc4T+sBhBW2eY03BEl YgOA== 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:to:from :dkim-signature; bh=ubygpiVeUMd0fcLsHm6UxwLECdzjZTk+vbU50/H9Zgo=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=d5VTMfQq1/LDlTpJP+4EPAVRv5MpF+htMApX5ah6upu8hRrNtCFXgVvmt6TiPIyJsJ AnKXUUxS7PEHE9N0tP5itw57DlQh9DH5MMo1XL1EIXvdlIFTRKw7Z3zjtCBHxq6mOwhr Z/OwyQI1AUZYcDmLeG0PmGQdYFk+5W4Y1JWhnpwGGmGjur6oOXayvqtSn9VFQG1KlKp7 A8AliECwxzzEDNUxxkZQ+B69uiKDTykH6IUygDpu+uwR3gx6J1cmrrEeOEvmNnKNCzOw PGgxVs5jnsmHEwrppGpIUZtie4Y0b/Lbnzg3MF2PCMQmAk1tkSbRL5XTEScCIzPkO8E3 alOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UzbQay9o; 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 w16-20020ac857d0000000b00406a59248adsi3305256qta.790.2023.09.15.20.31.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Sep 2023 20:31:30 -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=UzbQay9o; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhM19-000676-DY; Fri, 15 Sep 2023 23:30:47 -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 1qhM15-00064l-NS for qemu-devel@nongnu.org; Fri, 15 Sep 2023 23:30:43 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhM14-00085D-3e for qemu-devel@nongnu.org; Fri, 15 Sep 2023 23:30:43 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68fac346f6aso2577509b3a.3 for ; Fri, 15 Sep 2023 20:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694835041; x=1695439841; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ubygpiVeUMd0fcLsHm6UxwLECdzjZTk+vbU50/H9Zgo=; b=UzbQay9oiC/QDLSXpj6wz2EvWGTyim/j2d4GtFRVL06lGCqHk86tgzf3GFi3iF9C8T Go9BMOszYagT7gjCQjXLnx90gs/QaSzLb/IAN7qeC1VWMyK9HNqpz1HD47jpSR8iMsAm 4djK4BG4R1fBQVXwqYC487b5faqxvY14hc1B7z6POkn8QOapQK/OkKGL05iQRfKQv6uR obN8kPD1IxYiDbImuBI5kXJJV4tThMOlGcO57cvNoniefnoJrJz8oAVB47C0pR+uddgu 7NESMOhJeGhiY6HhJSJ9hKaRNOZ2b76ClRBNfn4wWRw1vpoI4kl3UwowWqjGp75B5OSj FOEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694835041; x=1695439841; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ubygpiVeUMd0fcLsHm6UxwLECdzjZTk+vbU50/H9Zgo=; b=XGzI4itnQFs0jodjuH1q4j+MttHn4YWct9GtUGnLhOyX4oWR86/NfNM20rlu3FsySm QM1q5LxyS/B+PVdYwmXKqsHbXn74MuF07BIBVIVdVMW9F663B11C4buId8L20t7Btqun Mh16Qj6nL5cpgIqkccEAKA/2ruvn/cwaIR+90eRsYMO2tHaoRvcQLxXzic1E2hRGNSzW BO5YiR7rWLcnOWJxdl+Xa34mUNFiRpbS6otFYoloSO7lVZvDqGpanP6j5ECL1A/35Czv bVVCm5Q6kMo/beDeD2KlkksYNTvr8qejG9PubQtXYEQxHIsg6qMD+bYkzcXbDO4pQ0eB kKMQ== X-Gm-Message-State: AOJu0Yz9BRgteIb77P3vfGFF8ITHjq0nsFWfOrIWTRHcchPSe47WQAIH SoNslLxI9AeO6hab/mzmRs3kjs8EFUhHDUfkS68= X-Received: by 2002:a05:6a00:1594:b0:68a:6305:a4cc with SMTP id u20-20020a056a00159400b0068a6305a4ccmr4035728pfk.5.1694835040879; Fri, 15 Sep 2023 20:30:40 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j26-20020aa783da000000b00687a4b70d1esm3577320pfn.218.2023.09.15.20.30.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 20:30:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 30/39] accel/tcg: Merge io_readx into do_ld_mmio_beN Date: Fri, 15 Sep 2023 20:30:02 -0700 Message-Id: <20230916033011.479144-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230916033011.479144-1-richard.henderson@linaro.org> References: <20230916033011.479144-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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-bounces+patch=linaro.org@nongnu.org Avoid multiple calls to io_prepare for unaligned acceses. One call to do_ld_mmio_beN will never cross pages. Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 84 +++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 54 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index cc36e681a7..6cf69bd79d 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1388,32 +1388,6 @@ static void io_failed(CPUArchState *env, CPUTLBEntryFull *full, vaddr addr, } } -static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, - int mmu_idx, vaddr addr, uintptr_t retaddr, - MMUAccessType access_type, MemOp op) -{ - MemoryRegionSection *section; - hwaddr mr_offset; - MemoryRegion *mr; - MemTxResult r; - uint64_t val; - - section = io_prepare(&mr_offset, env, full->xlat_section, - full->attrs, addr, retaddr); - mr = section->mr; - - { - QEMU_IOTHREAD_LOCK_GUARD(); - r = memory_region_dispatch_read(mr, mr_offset, &val, op, full->attrs); - } - - if (r != MEMTX_OK) { - io_failed(env, full, addr, memop_size(op), access_type, mmu_idx, - r, retaddr); - } - return val; -} - static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, uint64_t val, vaddr addr, uintptr_t retaddr, MemOp op) @@ -2062,40 +2036,42 @@ static uint64_t do_ld_mmio_beN(CPUArchState *env, CPUTLBEntryFull *full, uint64_t ret_be, vaddr addr, int size, int mmu_idx, MMUAccessType type, uintptr_t ra) { - uint64_t t; + MemoryRegionSection *section; + hwaddr mr_offset; + MemoryRegion *mr; + MemTxAttrs attrs; tcg_debug_assert(size > 0 && size <= 8); + + attrs = full->attrs; + section = io_prepare(&mr_offset, env, full->xlat_section, attrs, addr, ra); + mr = section->mr; + do { + MemOp this_mop; + unsigned this_size; + uint64_t val; + MemTxResult r; + /* Read aligned pieces up to 8 bytes. */ - switch ((size | (int)addr) & 7) { - case 1: - case 3: - case 5: - case 7: - t = io_readx(env, full, mmu_idx, addr, ra, type, MO_UB); - ret_be = (ret_be << 8) | t; - size -= 1; - addr += 1; - break; - case 2: - case 6: - t = io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUW); - ret_be = (ret_be << 16) | t; - size -= 2; - addr += 2; - break; - case 4: - t = io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUL); - ret_be = (ret_be << 32) | t; - size -= 4; - addr += 4; - break; - case 0: - return io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUQ); - default: - qemu_build_not_reached(); + this_mop = ctz32(size | (int)addr | 8); + this_size = 1 << this_mop; + this_mop |= MO_BE; + + r = memory_region_dispatch_read(mr, mr_offset, &val, this_mop, attrs); + if (unlikely(r != MEMTX_OK)) { + io_failed(env, full, addr, this_size, type, mmu_idx, r, ra); } + if (this_size == 8) { + return val; + } + + ret_be = (ret_be << (this_size * 8)) | val; + addr += this_size; + mr_offset += this_size; + size -= this_size; } while (size); + return ret_be; }