From patchwork Tue Jul 23 20:38:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 813968 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2488797wro; Tue, 23 Jul 2024 13:39:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW3kC/4klW6RDXmFkAOWeYIoEGF1qKAvfh29Z+tPhieWWs2igblDwHKP/m0Fm+8TAuB3/k04X7RhuESOXWhFHpA X-Google-Smtp-Source: AGHT+IGAIMBdGsVpcvUoH3Nbdaer8qN77s5n2UyzXUdUeqKVpKpymgcJrg8i4zqxr7zTnR0VhpvF X-Received: by 2002:a05:6808:2028:b0:3da:a4f7:74bb with SMTP id 5614622812f47-3db08f78e34mr127373b6e.41.1721767184283; Tue, 23 Jul 2024 13:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721767184; cv=none; d=google.com; s=arc-20160816; b=bXWi0NoZB4wlZ7zYQAc2uW2RUuQPTkPFxiuU+p46wti6grFZTHucOw71kzdf59yn9v KAXhLdkz0ZpDmghTmlO+2139Cp0KL0DouKwbbCFTiwoPrd07D0EAEIdi320ZxzXRKWS6 VrrS0SwC6gsCNnqSn3quRwswG5jOdaWLW5NquSgvNBKOgDO1Rd1YjkT2doa+eLIDlYXj 8FXX3rvTquuYboY95sgwNRAwTecriHZWajFCjCgPp1LYPhfS5ZEI912XA5I8Wh6R0v0h M8U6qfSMG3Xz7VrwQIavI0CRLBxJX3Iog1v+iUVhMRt3JXZ7nn6anMv6kYTq+igbABWI jbaA== 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:cc:to :from:dkim-signature; bh=07s3gAboUiyqxdzn5K8IrlmeguSj0H4h3EuvIHEUowk=; fh=P5Uuv03EGnSUdvHiKODzE1tmjpKkES0C3Jo663h3TmI=; b=pTDalBz3rDU1pn+AbJOmJHkJY3UY2DtRF1/Q2kwfYSGpByJAWVKQJXhlAKbvMPy1Gh sEuJPYajXT3JizwMzyHua0li5GfCLuhYRYKzneSU0u9ig5a+2vb2LaxCtUkZqlNJNEL/ hv7jzvGhPFCwLMZtftGLc55lnoovskikZao9up/kBmQ8lLYBNs2olGkfI3H8ZWmTDfbQ F6zPMqP5mlpCsQ7IJvUes64u3amc9N/aHbyiU7LE1GgPZJlJosDAQ7HH7saaj88Loqdx LY/O19JsDL2arQXbtICrf1Aw6AFshClHFNUKKiTaHRf9iZaPNJ92RLmZ7au0cKH45tch B1KA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u6t+O6Sz; 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 d75a77b69052e-44f9cd29a4csi108582711cf.203.2024.07.23.13.39.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2024 13:39:44 -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=u6t+O6Sz; 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 1sWMHz-0003V5-Bt; Tue, 23 Jul 2024 16:39:15 -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 1sWMHx-0003RK-Ae for qemu-devel@nongnu.org; Tue, 23 Jul 2024 16:39:13 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWMHv-0003v1-KZ for qemu-devel@nongnu.org; Tue, 23 Jul 2024 16:39:13 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4266fcb311cso44609795e9.1 for ; Tue, 23 Jul 2024 13:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721767150; x=1722371950; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=07s3gAboUiyqxdzn5K8IrlmeguSj0H4h3EuvIHEUowk=; b=u6t+O6SzM9ytBu9h2IU95IyQzBh77auCijdrLJ7tIhgAkzohTWLY0VVpI4GItdeeDz WruGSSkzoKz7g3g9Xe25jVzbSoyoDQhmMmmYcblgK6Q6vFKeHOfYfYXcEwReZxyEhI3k fqsvkTr1Ufkhhnaej9uJtWUpg7xq1K8V+bvzJcUgg0yca3K0zvV1aseSBggIANWuEkI0 uVZ7A+vnL8ziWfOosQHi7S/g3avW6HXDX4HEaqTsBM4EBqf12t/e4U6TE60DANAyn1DV dNlrVO39gL4zfkqPVAiD06xho5klxFq1nIcgqrws5YSWokoFBwNicbZxoCoFdj2SejjH ahsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721767150; x=1722371950; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=07s3gAboUiyqxdzn5K8IrlmeguSj0H4h3EuvIHEUowk=; b=NqPLN85TdIprcZcUEbQ3A5X+20eepi8Qp3YyE7adyUD/KYxTgl6kl63n/9pKi1fBU+ pKdqAkWoF0LF/ETqi+MeNUNwpsP8Iut7NAG3iSGLB7dlpag010Eh09Y7m4qYQwiqKzMc 3OPU160Saw0PGCKobUKIzoBvCVLT3ReJSSkuFJecGonc5jg7S+1mNwAXPvVCAL8nVF17 pefQrkMZgAdfn4qrx8HKVblLmOsAcYGE5/I60PWJ7eTURYI6Bkcqp30pNVyNa2BU9RsH 5ZTkswk4zKj0K02ZOHlhzHYwA0sk4CRs8GFKNbG0bHWg16N2MVdVpbr5kXr4nqWX8tKL 69wg== X-Gm-Message-State: AOJu0YwjrPfpppaosh38Ooao/RW8IF2XExPl2VJ5QHN+TG7kKte+ZutK O7nWqX+dCMcfP6VrGQX7ltoAjSovWq5shg31FXMfEp7toFztD5oB2N8GGXuRdt6ZADrkKO8YKIg ztx4= X-Received: by 2002:a05:6000:1108:b0:368:667a:3dec with SMTP id ffacd0b85a97d-369f5b30273mr22511f8f.18.1721767149874; Tue, 23 Jul 2024 13:39:09 -0700 (PDT) Received: from localhost.localdomain (vbo91-h01-176-184-50-4.dsl.sta.abo.bbox.fr. [176.184.50.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-368787ebab0sm12538751f8f.92.2024.07.23.13.39.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Jul 2024 13:39:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Cl=C3=A9ment_Mathieu--Drif?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Zhenzhong Duan Subject: [PULL 02/28] hw/i386/intel_iommu: Extract device IOTLB invalidation logic Date: Tue, 23 Jul 2024 22:38:29 +0200 Message-ID: <20240723203855.65033-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240723203855.65033-1-philmd@linaro.org> References: <20240723203855.65033-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=philmd@linaro.org; helo=mail-wm1-x32c.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: Clément Mathieu--Drif This piece of code can be shared by both IOTLB invalidation and PASID-based IOTLB invalidation No functional changes intended. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Clément Mathieu--Drif Signed-off-by: Zhenzhong Duan Message-ID: <20240718081636.879544-12-zhenzhong.duan@intel.com> Signed-off-by: Philippe Mathieu-Daudé --- hw/i386/intel_iommu.c | 57 +++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 37c21a0aec6..536994c3107 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2666,13 +2666,43 @@ static bool vtd_process_inv_iec_desc(IntelIOMMUState *s, return true; } +static void do_invalidate_device_tlb(VTDAddressSpace *vtd_dev_as, + bool size, hwaddr addr) +{ + /* + * According to ATS spec table 2.4: + * S = 0, bits 15:12 = xxxx range size: 4K + * S = 1, bits 15:12 = xxx0 range size: 8K + * S = 1, bits 15:12 = xx01 range size: 16K + * S = 1, bits 15:12 = x011 range size: 32K + * S = 1, bits 15:12 = 0111 range size: 64K + * ... + */ + + IOMMUTLBEvent event; + uint64_t sz; + + if (size) { + sz = (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT); + addr &= ~(sz - 1); + } else { + sz = VTD_PAGE_SIZE; + } + + event.type = IOMMU_NOTIFIER_DEVIOTLB_UNMAP; + event.entry.target_as = &vtd_dev_as->as; + event.entry.addr_mask = sz - 1; + event.entry.iova = addr; + event.entry.perm = IOMMU_NONE; + event.entry.translated_addr = 0; + memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event); +} + static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { VTDAddressSpace *vtd_dev_as; - IOMMUTLBEvent event; hwaddr addr; - uint64_t sz; uint16_t sid; bool size; @@ -2697,28 +2727,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, goto done; } - /* According to ATS spec table 2.4: - * S = 0, bits 15:12 = xxxx range size: 4K - * S = 1, bits 15:12 = xxx0 range size: 8K - * S = 1, bits 15:12 = xx01 range size: 16K - * S = 1, bits 15:12 = x011 range size: 32K - * S = 1, bits 15:12 = 0111 range size: 64K - * ... - */ - if (size) { - sz = (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT); - addr &= ~(sz - 1); - } else { - sz = VTD_PAGE_SIZE; - } - - event.type = IOMMU_NOTIFIER_DEVIOTLB_UNMAP; - event.entry.target_as = &vtd_dev_as->as; - event.entry.addr_mask = sz - 1; - event.entry.iova = addr; - event.entry.perm = IOMMU_NONE; - event.entry.translated_addr = 0; - memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event); + do_invalidate_device_tlb(vtd_dev_as, size, addr); done: return true;