From nobody Fri Dec 19 06:56:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1563570273; cv=none; d=zoho.com; s=zohoarc; b=nQ1z4QRniD/TVLjBq5mHMCE/e35xth1OUEfaqINZwc4vieYrgpS4MDvQzhSGbK0OP9M8qXGMsIc9euPvPMkn5m9Sf1YUsOnhlz1u/pm5nlzoHM4L7CgZs96VWWDgJTqZQxi5MdmbfUYxL0/7DmbQnjADnO8yGk6aEqGoaLvvf48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563570273; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=qSAk/ikU/Yd5/thTZP7TzeGfcBAUft8dVvQCioYm2gw=; b=UmaM+p9Rv5GzIQdIkVYq7mlGxCMRAjkkPb2L9cn5mROGdbsgfE0OV1k0zFlrNeeaZfNcyFRIv5qMDnW8E9RldGboMSxQJvhrHAlOu65/WfW7dx+RTIDHw5nnLUcVLecXp/OBs5An8J3iqnOilQS9x2+D8WjsaxWfFZnUlwNBYiU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563570273863860.3653199351436; Fri, 19 Jul 2019 14:04:33 -0700 (PDT) Received: from localhost ([::1]:48164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoa3M-00072G-Nr for importer@patchew.org; Fri, 19 Jul 2019 17:04:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54891) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoa2T-0003MF-34 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 17:03:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hoa2O-000560-IG for qemu-devel@nongnu.org; Fri, 19 Jul 2019 17:03:35 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:37500) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hoa2O-00055a-80 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 17:03:32 -0400 Received: by mail-pg1-x542.google.com with SMTP id i70so4229448pgd.4 for ; Fri, 19 Jul 2019 14:03:32 -0700 (PDT) Received: from localhost.localdomain (97-126-117-207.tukw.qwest.net. [97.126.117.207]) by smtp.gmail.com with ESMTPSA id i6sm32724751pgi.40.2019.07.19.14.03.30 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 19 Jul 2019 14:03:30 -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=qSAk/ikU/Yd5/thTZP7TzeGfcBAUft8dVvQCioYm2gw=; b=uJN1bFrSINBPl/sff9/uuCWdSGOdrG4D0Xwy+7pcEI535MjV2m5NRtoHx148aQnRTl eG4Hdphz3jfZtmpre8EVNrop//i2bAe+7SoUY7F3YS9QpMKUl24V4NUb2HJ71SSZaJUj dSFHmWCn+0YiPQLH9Rlzdd/COaWFXQtjafdUCJ3MHhichKwkDGcnWPJCW4KZ7LR34/0T ymXFwV6iRF9ynVZ3Db42fzMulXN7zO4+9j5ypr0M4ycwB9SyRw7Xbk/6XoAIbW53yc8H oXWOmhvLeJ+beJCA6qGurTCj7gAJoMRw6RsHfn4niLt4GBZ4Y0rKkYQKxecgoT45u0Qb bFgQ== 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=qSAk/ikU/Yd5/thTZP7TzeGfcBAUft8dVvQCioYm2gw=; b=Qx0R7f5cvJCLMdBDf/IQ2MxKQRQo4XV4viUZz1SW0RIcptKVDkKK60rk9fMO9sDZaD eJ5J4TV6JKRmwV7jvAr0v+PtgINzm0Kcxz1yL385barpoB1nmMdZYRaEpJFVC0l4y9nB MvRVmodH/E/c7mNGYOxwV1IfKB9zCZ+y+2bSJaa6Ud1ew0dhkL/ibMu0npsYrND6GuBR CnYcivH8tofg15+bGIyY+U5qTP9jwvnEMXIBk+mQR4OiYKVZSOjOIr0Mac1BeR4AJ3Ui UILEdfeK69z4ErBv65e59g/K1fhsN0UKmmfXGazHji+2R0wr5Z27wOureBDywWnUUhUr m4dw== X-Gm-Message-State: APjAAAXMwHwyMjwoKLuu4+X8GFzNalLJB2Jqn+dQvnQ/BaQpw7iEyg6T L9i3Stm1D2MdWQ3P9ZbJyDzllo2tdYE= X-Google-Smtp-Source: APXvYqxK+yzyLZY7jxU7RMZyqSd3epPzljzDYILzVXrmI9OEpVzd2qyKN1FlQLZriJt5HlIVOj/low== X-Received: by 2002:a63:460c:: with SMTP id t12mr55854546pga.69.1563570211022; Fri, 19 Jul 2019 14:03:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 19 Jul 2019 14:03:04 -0700 Message-Id: <20190719210326.15466-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190719210326.15466-1-richard.henderson@linaro.org> References: <20190719210326.15466-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::542 Subject: [Qemu-devel] [PATCH for-4.2 02/24] cputlb: Add tlb_flush_asid_by_mmuidx and friends 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, beata.michalska@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since we have remembered ASIDs, we can further minimize flushing by comparing against the one we want to flush. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e --- include/exec/exec-all.h | 16 +++++++++++++ include/qom/cpu.h | 1 + accel/tcg/cputlb.c | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 9c77aa5bf9..0d890e1e60 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -240,6 +240,22 @@ void tlb_flush_by_mmuidx_all_cpus_synced(CPUState *cpu= , uint16_t idxmap); */ void tlb_set_asid_for_mmuidx(CPUState *cpu, uint32_t asid, uint16_t idxmap, uint16_t dep_idxmap); +/** + * tlb_flush_asid_by_mmuidx: + * @cpu: Originating CPU of the flush + * @asid: Address Space Identifier + * @idxmap: bitmap of MMU indexes to flush if asid matches + * + * For each mmu index, if @asid matches the value previously saved via + * tlb_set_asid_for_mmuidx, flush the index. + */ +void tlb_flush_asid_by_mmuidx(CPUState *cpu, uint32_t asid, uint16_t idxma= p); +/* Similarly, broadcasting to all cpus. */ +void tlb_flush_asid_by_mmuidx_all_cpus(CPUState *cpu, uint32_t asid, + uint16_t idxmap); +/* Similarly, waiting for the broadcast to complete. */ +void tlb_flush_asid_by_mmuidx_all_cpus_synced(CPUState *cpu, uint32_t asid, + uint16_t idxmap); /** * tlb_set_page_with_attrs: * @cpu: CPU to add this TLB entry for diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 5ee0046b62..4ae6ea3e1d 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -283,6 +283,7 @@ struct hax_vcpu_state; typedef union { int host_int; unsigned long host_ulong; + uint64_t host_uint64; void *host_ptr; vaddr target_ptr; } run_on_cpu_data; diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index c68f57755b..3ef68a11bf 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -540,6 +540,57 @@ void tlb_flush_page_all_cpus_synced(CPUState *src, tar= get_ulong addr) tlb_flush_page_by_mmuidx_all_cpus_synced(src, addr, ALL_MMUIDX_BITS); } =20 +static void tlb_flush_asid_by_mmuidx_async_work(CPUState *cpu, + run_on_cpu_data data) +{ + CPUTLB *tlb =3D cpu_tlb(cpu); + uint32_t asid =3D data.host_uint64; + uint16_t idxmap =3D data.host_uint64 >> 32; + uint16_t to_flush =3D 0, work; + + assert_cpu_is_self(cpu); + + for (work =3D idxmap; work !=3D 0; work &=3D work - 1) { + int mmu_idx =3D ctz32(work); + if (tlb->d[mmu_idx].asid =3D=3D asid) { + to_flush |=3D 1 << mmu_idx; + } + } + + if (to_flush) { + tlb_flush_by_mmuidx_async_work(cpu, RUN_ON_CPU_HOST_INT(to_flush)); + } +} + +void tlb_flush_asid_by_mmuidx(CPUState *cpu, uint32_t asid, uint16_t idxma= p) +{ + run_on_cpu_data data =3D { .host_uint64 =3D deposit64(asid, 32, 32, id= xmap) }; + + if (cpu->created && !qemu_cpu_is_self(cpu)) { + async_run_on_cpu(cpu, tlb_flush_asid_by_mmuidx_async_work, data); + } else { + tlb_flush_asid_by_mmuidx_async_work(cpu, data); + } +} + +void tlb_flush_asid_by_mmuidx_all_cpus(CPUState *src_cpu, + uint32_t asid, uint16_t idxmap) +{ + run_on_cpu_data data =3D { .host_uint64 =3D deposit64(asid, 32, 32, id= xmap) }; + + flush_all_helper(src_cpu, tlb_flush_asid_by_mmuidx_async_work, data); + tlb_flush_asid_by_mmuidx_async_work(src_cpu, data); +} + +void tlb_flush_asid_by_mmuidx_all_cpus_synced(CPUState *src_cpu, + uint32_t asid, uint16_t idxm= ap) +{ + run_on_cpu_data data =3D { .host_uint64 =3D deposit64(asid, 32, 32, id= xmap) }; + + flush_all_helper(src_cpu, tlb_flush_asid_by_mmuidx_async_work, data); + async_safe_run_on_cpu(src_cpu, tlb_flush_asid_by_mmuidx_async_work, da= ta); +} + void tlb_set_asid_for_mmuidx(CPUState *cpu, uint32_t asid, uint16_t idxmap, uint16_t depmap) { --=20 2.17.1