From patchwork Thu Jul 18 13:20:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 813172 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp290048wro; Thu, 18 Jul 2024 06:21:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUl1MCOlTbTYrzz532IP2Y9XOupyUDfncmo23WQYctWMl8yP4RyMOMNYLbhK2ySxjXgPYzR3VuRdREfJ0NQGuvp X-Google-Smtp-Source: AGHT+IENt/gpmED3YX9yALwNnEtZWY5197a9pcpuWmCVbZsVEDtRnOJcHwVVCJ7NP3ON72N+QuRU X-Received: by 2002:a05:6214:d65:b0:6b2:d335:e914 with SMTP id 6a1803df08f44-6b79c7cd178mr29994616d6.52.1721308900862; Thu, 18 Jul 2024 06:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721308900; cv=none; d=google.com; s=arc-20160816; b=k5Cd0JvrZPS5x1Ct/rStyFJP8A9gXD/HU6DUWkwT9/zQc8LD0hl6ITIx1ZQZcCTAjM Thj6eL4RiyyFqM1X8iTgIObw2lqDPKODcuCV7j6UPUAvB/dDPhx18PUVpvzACHfJezeM ceM5sJGNkWucXzR47GxsSMM2Frxj4nrP2wiGHjgZtn5uoNdSMyavg96zQLMzR+Gi8bBb sfgtPmQaWiOoKwoWtxOong/G+Dd3Lisrfzp7Prp0HkpHvsA/pSe0CHFiCpTylxmsRFVP BKILHGOMckmA5rf+S9/ciX/UinGYF3P8R+waupVT8hcXW4wUo0sONBqIXYS33BmzcFiR ocUg== 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=sA1K5/Oeol4qp2eoj4lcjjemIJtuASvZg2EHT+nPS3A=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=q2QFekhai/Z++CeDw/BCn27hBizsjUtzq6hGPiI7isBqgdCOMerfBgbXBfWo1IkgXd H7J8lwWLtlwr3BfafmwQI35sY8nHGy+KRNIdfAO7u0xMxLWo5p96d9rJxN/qrUVoXl9u 2hPaqlUxPCTS8m1KF3nWGIHed8liHkzlXI6sQf4u446WbFZYmvALt1uTLXUZYLP8Ts93 aJoqbBU5Q6scr1I2vu1AuepaBO2wGcMA97gnvpXC7pjKtCghQUBQUSVWgbTFjZ8RHX0q dJQRrvXuqOQ4sqgdb/h8jk23lwGAniYM6rUoJJZa+WwNfG5QmJWchHc5uBB2DQI1rofv LdxA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SAzlInyZ; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6b79c5eeb92si18344076d6.169.2024.07.18.06.21.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Jul 2024 06:21:40 -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=SAzlInyZ; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sUR49-0001pR-Cz; Thu, 18 Jul 2024 09:21:01 -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 1sUR3q-0008Nb-Vo for qemu-devel@nongnu.org; Thu, 18 Jul 2024 09:20:46 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sUR3o-0004V2-Iq for qemu-devel@nongnu.org; Thu, 18 Jul 2024 09:20:42 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4272738eb9eso2687385e9.3 for ; Thu, 18 Jul 2024 06:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721308838; x=1721913638; 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=sA1K5/Oeol4qp2eoj4lcjjemIJtuASvZg2EHT+nPS3A=; b=SAzlInyZ7HieFRSNQYa9FZTeZpLPRPPNYNx7lPwXIXB0uPEkmZIVdyAzCfYqZrVdAy VFb4YFORKiIRf0xq2k7QsChMhCAytuXBsO0OyuAqbNr66M/vqowa2VFjxZGAdrZrGcwA TNG95dkA6V0spMsv8RCotAQm/7k/Ct9GHS8+AC8hIOGfBBn2viwNGPf4Z2K5b0210deH lyBccN1CGdLBCZaZUOCO7p5J8gkF5oLTYTRkBpWLzb5TmKnIXu8kKqtXy6t+3ZGzT9Fn ZWTHIq2Yfn3ASvWOoTFYfUDxHcHzePCl+kwGBszHV/ur+QjSrwvqLanctxNVwSa03SNi WOGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721308838; x=1721913638; 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=sA1K5/Oeol4qp2eoj4lcjjemIJtuASvZg2EHT+nPS3A=; b=MVn3l1wZtNPjqthAduhc4f/CL50EpTYl7/WgFvyOX00FsQJmdMXMRgejlcOKPmod3w F2VpVOlqJHbBgcAR58K+ktrwWM3NrBi/1CGiEf1i1OwCgvmMsNZblb1mt2HiTTxacrO8 UXtMIlFOffBA/Kn92igd2k1okRsKI0z+FvTaC+b4KTdIAorEDaUvEeCQaf405TNc0kpy NP/TB3YshQXAig7WvU0GtOePbdcoJNZB5D2F6jp9H00YXhKMNMKBekucs+aJW/PIiL7d TuVpWFXUGPZ+aThJCAO5bTTI4/2cpnXnfwkGoHy8atXOamsBtUjl9PHleGSRz5r7gKpJ K0Ng== X-Gm-Message-State: AOJu0YxilnN5s0RKsKvqqnIHqNdRSTEwbZPaNGcSmZS2WFSXQ3UZVbP7 OV4l2G347lACub87CqSkYDs1hygABJ5ZF5hwtfvp4Km61LCpPk46xZQXSr5RVgQDpRPGNtAjAAc M X-Received: by 2002:a05:600c:4e92:b0:426:5c34:b19b with SMTP id 5b1f17b1804b1-427c2cc33damr30765765e9.20.1721308838254; Thu, 18 Jul 2024 06:20:38 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e420sm14059315e9.35.2024.07.18.06.20.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 06:20:38 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 16/26] hw/arm/smmu: Introduce smmu_iotlb_inv_asid_vmid Date: Thu, 18 Jul 2024 14:20:18 +0100 Message-Id: <20240718132028.697927-17-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240718132028.697927-1-peter.maydell@linaro.org> References: <20240718132028.697927-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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 From: Mostafa Saleh Soon, Instead of doing TLB invalidation by ASID only, VMID will be also required. Add smmu_iotlb_inv_asid_vmid() which invalidates by both ASID and VMID. However, at the moment this function is only used in SMMU_CMD_TLBI_NH_ASID which is a stage-1 command, so passing VMID = -1 keeps the original behaviour. Reviewed-by: Jean-Philippe Brucker Reviewed-by: Eric Auger Signed-off-by: Mostafa Saleh Reviewed-by: Alex Bennée Message-id: 20240715084519.1189624-14-smostafa@google.com Signed-off-by: Peter Maydell --- include/hw/arm/smmu-common.h | 2 +- hw/arm/smmu-common.c | 20 +++++++++++++------- hw/arm/smmuv3.c | 2 +- hw/arm/trace-events | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index da9ff45fb5a..eaee867e45c 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -213,7 +213,7 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *entry); SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint64_t iova, uint8_t tg, uint8_t level); void smmu_iotlb_inv_all(SMMUState *s); -void smmu_iotlb_inv_asid(SMMUState *s, int asid); +void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid); void smmu_iotlb_inv_vmid(SMMUState *s, int vmid); void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl); diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 4b0857ab4d7..e7f9c758fa6 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -159,13 +159,14 @@ void smmu_iotlb_inv_all(SMMUState *s) g_hash_table_remove_all(s->iotlb); } -static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value, - gpointer user_data) +static gboolean smmu_hash_remove_by_asid_vmid(gpointer key, gpointer value, + gpointer user_data) { - int asid = *(int *)user_data; + SMMUIOTLBPageInvInfo *info = (SMMUIOTLBPageInvInfo *)user_data; SMMUIOTLBKey *iotlb_key = (SMMUIOTLBKey *)key; - return SMMU_IOTLB_ASID(*iotlb_key) == asid; + return (SMMU_IOTLB_ASID(*iotlb_key) == info->asid) && + (SMMU_IOTLB_VMID(*iotlb_key) == info->vmid); } static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value, @@ -270,10 +271,15 @@ void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, &info); } -void smmu_iotlb_inv_asid(SMMUState *s, int asid) +void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid) { - trace_smmu_iotlb_inv_asid(asid); - g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid, &asid); + SMMUIOTLBPageInvInfo info = { + .asid = asid, + .vmid = vmid, + }; + + trace_smmu_iotlb_inv_asid_vmid(asid, vmid); + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid_vmid, &info); } void smmu_iotlb_inv_vmid(SMMUState *s, int vmid) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index ebf29f3adf7..847fc566762 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1357,7 +1357,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) trace_smmuv3_cmdq_tlbi_nh_asid(asid); smmu_inv_notifiers_all(&s->smmu_state); - smmu_iotlb_inv_asid(bs, asid); + smmu_iotlb_inv_asid_vmid(bs, asid, -1); break; } case SMMU_CMD_TLBI_NH_ALL: diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 7d9c1703da1..4aa71b1b196 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -11,7 +11,7 @@ smmu_ptw_page_pte(int stage, int level, uint64_t iova, uint64_t baseaddr, uint6 smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=%d level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" iova=0x%"PRIx64" block address = 0x%"PRIx64" block size = %d MiB" smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "baseaddr=0x%"PRIx64" index=0x%x, pteaddr=0x%"PRIx64", pte=0x%"PRIx64 smmu_iotlb_inv_all(void) "IOTLB invalidate all" -smmu_iotlb_inv_asid(int asid) "IOTLB invalidate asid=%d" +smmu_iotlb_inv_asid_vmid(int asid, int vmid) "IOTLB invalidate asid=%d vmid=%d" smmu_iotlb_inv_vmid(int vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_iova(int asid, uint64_t addr) "IOTLB invalidate asid=%d addr=0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=%s"