From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f3.google.com (mail-pj2-f3.google.com [74.125.227.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 702243254A2 for ; Fri, 10 Jul 2026 06:05:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783663522; cv=none; b=hBk31BahENLpHte5SqobtGMleAQvfG/uKmczbuJJKQ6r06DBRKoEzqUBc/LN92+bKdThrTM43MBA66EB3Fc2K8mq4Y8mYiax6SP2iQvUnI7keDXSb1VYjqQq3GJWWBk4ThYmRjwZTmPTxSqYVyhaXaRRGcfi6CPeA7Ne3+FKzsE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783663522; c=relaxed/simple; bh=+TSl9lWGvPOhVvtGbRmV7Zvub/yR8s6/knDkK3HGmbo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=U2Ko3gwvJ0Jaz3R9Ex7iVSNnaRzwSB1J9+IjBFHi1H8e5UUvgEPuGHg3QyaC+n14NFnbywXWhzCyspwUJ3LwB9E4PtjaAAW2YgocP1TAVP94wLAvCcCgi0zC552HJNULtL02KdNA46SidAXvbHzzIu5SU9GIgVLmFEVoMXpaubc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=oC8PiQI3; arc=none smtp.client-ip=74.125.227.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oC8PiQI3" Received: by mail-pj2-f3.google.com with SMTP id d9443c01a7336-2cc8ed77bbcso8474485ad.0 for ; Thu, 09 Jul 2026 23:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783663521; x=1784268321; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=pQgPhs+dZcfRNPuJReU9TiVxwha1e01HcHWKyyYl0NE=; b=oC8PiQI3x7cexYcsQ67+gdqyWOBZ/+OoDjHllzMKM4tKscoyQJIXdMjngwp4L7+Q+k zRMwFvib+DIMWf1BkEsGv2phwhcmEJtx2wLeK+Hs3NFylZxsxmp+oGboRUue59d0XBD/ SJeFpOx/nvNmJzoMkxqvlioQFygLZOvfbGMcwKNaJInUtSvclMxw2t2IhTpVB7ipornU 6C1hKZUU4NAGf/PMlwHPuLcIBIuJgNgrNalAvCGSHoVROIznyaR0l/Hd5puB2YV+vYE5 fxlFKlflR+0NVMvyliDjqVmDyvrdNXusBt4SvYhvAlSIJF43pMDWqGfPZJHrsQK/haPk IfGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783663521; x=1784268321; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pQgPhs+dZcfRNPuJReU9TiVxwha1e01HcHWKyyYl0NE=; b=iYXiJqc8uqG/9OMc5yinubwxL4KswdrRGaOUHRc2Yn58ViH8JUOB6E8RYNTk5sl2Ea ib8q69S+n8pqXZWhJZwFkiOedZ3YKVCqoUfbuAunl0aKRkgSds72Q64KVHkSCUt+Ct0i jhQD7J9LyDFVWAlDPiU1Hn2MNW75xwUqWHrfMBFoN2A/JlrAyFMY1efWYrr5SSpm+N6S HCo6jMwzVFWaftfnAXeEt1UFroromJaEeWZ4SdUW5lOEMu3ZPVDPEeJk/cbncsCWldMF 1Bm75O02aqw5wdxR2VZureHVgPgA9/OJpAHy3c81KGukP7ie5vWDUeaDDipKaYJjwNsJ ij7g== X-Forwarded-Encrypted: i=1; AHgh+RqtyQ9HWUqio+e4Kwt75r6dPQpUf0kYyxzQDkMRfPMsMn8uSg9RRewvbzxodf5O+slf73Bxq71osIAfu20=@vger.kernel.org X-Gm-Message-State: AOJu0YwnefcGcSO8jr20ylYiHPErPnXLqb1o1Np1oBVm3i35akVHVHZS hwlnX7DO2LlysYxA47JGP0meVvoDYY1bYF0Mju1jPoKV1d5ZCt/J8oAayMae0KtvbPh2kQ== X-Gm-Gg: AfdE7cmg5ZOCry9gR439MX8LV+raYpFjzBLHcyMXkmuZWwdk9d5PKrPKY8nKuRucEvG saisjfY/3t1HW+IFurhlsLMBKyuqSP+Ojdona8k0vkJw4nCHHbl+Y0KcH0Tk8IgCk+QPBgudUja OY/QYwBeGKflFDj8LWm9rFVcOeaSl9yp3j+GYhI0pHzftI8yZBL6/GxBlFvYL9iTm7p8Ul3AikY uTMqY0TOgDyGyQg2gIxvoQFUJijjSJJ008sJwvBHpBq716jgLblmM7kPKgQlGtihBhr7+H2Gjv9 P7iofCgW+Dc7jQ80yoomgEjYEwRJ06eZHIYAjNA3XzP/CCfGVsjZnrsb/tI1eC8Zlw6lJYYELFg SBJNDB1VvXy2WnaDZsgX2doH2kbFPY09r7ulT6CiA24ykdS0THK4+wXwlkXA36ay+lqPayzCCBv 1qctfwodCZFeauS5vh0yOLme8NffKkzV8Zqlm3hOIq+1HTDfNFuex9MZP/v+BqV+zaZO6PvsM= X-Received: by 2002:a17:903:1b0f:b0:2c9:c95e:5836 with SMTP id d9443c01a7336-2ccea2a5748mr105552515ad.5.1783663520722; Thu, 09 Jul 2026 23:05:20 -0700 (PDT) Received: from ubuntu-gnu-linux-24-04-3.hub ([2407:7000:af23:3e00:61b7:bd9d:8d64:1bac]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc9bdb76asm56314635ad.12.2026.07.09.23.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 23:05:19 -0700 (PDT) From: Jiaxing Hu To: Heiko Stuebner , Joerg Roedel , Will Deacon Cc: Robin Murphy , iommu@lists.linux.dev, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] iommu/rockchip: implement .flush_iotlb_all Date: Fri, 10 Jul 2026 18:05:13 +1200 Message-ID: <20260710060513.863714-1-huhuvmb88@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit rk_iommu invalidates the IOTLB synchronously in .unmap (via rk_iommu_zap_iova), so it stays consistent without a deferred .iotlb_sync and does not advertise IOMMU_CAP_DEFERRED_FLUSH. It never implemented the optional .flush_iotlb_all op, though, and iommu_flush_iotlb_all() is a no-op when that op is absent -- so on Rockchip a driver that owns an rk_iommu domain and calls it to flush the whole domain's TLB (e.g. before reusing a mapping, without unmapping it) gets nothing, even though the hardware can do it: rk_iommu already issues ZAP_CACHE for range shootdowns. Implement it with that same primitive: ZAP_CACHE every bank of every IOMMU on the domain, under the runtime-PM + clk guard already used by rk_iommu_zap_iova(). Found while bringing up an out-of-tree RK3576 NPU (accel/rocket) driver that flushes before each submit; on Rockchip that flush did nothing. Signed-off-by: Jiaxing Hu --- diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1202,6 +1202,30 @@ return 0; } +/* shootdown the entire tlb on all iommus using this domain */ +static void rk_iommu_flush_iotlb_all(struct iommu_domain *domain) +{ + struct rk_iommu_domain *rk_domain = to_rk_domain(domain); + struct list_head *pos; + unsigned long flags; + + spin_lock_irqsave(&rk_domain->iommus_lock, flags); + list_for_each(pos, &rk_domain->iommus) { + struct rk_iommu *iommu = list_entry(pos, struct rk_iommu, node); + int ret = pm_runtime_get_if_in_use(iommu->dev); + + if (WARN_ON_ONCE(ret < 0)) + continue; + if (ret) { + WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks)); + rk_iommu_command(iommu, RK_MMU_CMD_ZAP_CACHE); + clk_bulk_disable(iommu->num_clocks, iommu->clocks); + pm_runtime_put(iommu->dev); + } + } + spin_unlock_irqrestore(&rk_domain->iommus_lock, flags); +} + static const struct iommu_ops rk_iommu_ops = { .identity_domain = &rk_identity_domain, .domain_alloc_paging = rk_iommu_domain_alloc_paging, @@ -1214,6 +1245,7 @@ .map_pages = rk_iommu_map, .unmap_pages = rk_iommu_unmap, .iova_to_phys = rk_iommu_iova_to_phys, + .flush_iotlb_all = rk_iommu_flush_iotlb_all, .free = rk_iommu_domain_free, } };