From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 5D9552609D0 for ; Fri, 2 May 2025 17:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746205652; cv=none; b=NQIxlHEzpTlbQW3mbaZ0JAT9CxH+MoMtHUHM3ehCZb+B3m/0NECkkQsiwTWKfwOI0WzOA/qV3RFnB7AhjMw6JkLURnEc+suSh9xX/zJrmnP4ikZi1hDZulwR/iFCSys3dM8+Ktux8BYt3cijHMdyP9P7cF6Dt8Cieo5RCyZG0Z4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746205652; c=relaxed/simple; bh=P9zhJAkj3h5VMm4SNK1BFPXcBd1oAhZOq+LKwMgtwOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uprxquiZLZju1v/rmQLAmXl/fiv1N1y53yPVo2m7X2EBFnkjqYAU0UAIvkDU6438Qt2Ky58AVgEfAZcq6I+eTitdU5mXgwb/CuMA1v48vY5stWRTF8mwuVa9VpFPYljfOhPBMmySRdI4nyhtOc8LdsHMmDREzsJ9SroMcOlzPBg= 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=Oo1wf1ge; arc=none smtp.client-ip=209.85.210.178 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="Oo1wf1ge" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-736a72220edso2741278b3a.3 for ; Fri, 02 May 2025 10:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746205650; x=1746810450; darn=lists.linux.dev; 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=3i4/8hB9ZUNUdDsq/JRsaRdSSjXpcATq5zvWh4Rsiyk=; b=Oo1wf1gecUHAdcRH5RNp7fc0g27FXi3dtzF0DNkJmgnFdWRarhXzBW3uKCRrqiEXbJ g8n+IP5mqpQA9PLO8n7og2m+aYi80ya8v0n41zd1DLeYk2sUHGEf/Ij9GNOSIDH1y/LO +qdlrJvXFWjLQKu3CU2IdfFTemVgohSuMLKsVur56weLSNktltRPJr8Njz/KXlMyHDiP /T2vy10uhTjOe/vMEBIC6gro4X4EG250YfSNAcuupu6RHrcwBXVXeHLWONNXR36O9D2M Lkog84BPJu+SoiGdtf2qqDghxuVD8b/3Vai6VMbvMIDvviJrC5yAk/N0Z0AH2u9hDz3Y VVMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746205650; x=1746810450; 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=3i4/8hB9ZUNUdDsq/JRsaRdSSjXpcATq5zvWh4Rsiyk=; b=JPvSZpjZQMpwCUqr5TVvEhFkWCNYEMjE3R3dMOo3bpOlN6GHGTuu+h8hV6YGxHipHf P3gfyJLnxZULtgquUUgBUXfqItmHlNxGkGAS330TGijRE0MjsSYMHjBzPog7qQ/YxUHp y37xNtZBhBxh1us0MpPnG3Zn+D9eAB/73qhxyBwpQGIbqq9OlRws8USN8L9dwxG0pHjL +r1QBfYxv+hrF3QfDsO3+W8T5UhviUJ33gkUS7uJSL3WZ5Kx2ZWvs4Gz3Nhy5kzDyocw FJULc9L0Y9ss9KDaOO6ZDwxnKKkiwRuD+z6J+EBIf/9DMmJ+NHSXAV7JrB04jc9d5c1c 9hNg== X-Forwarded-Encrypted: i=1; AJvYcCWYFRYohyugjsCl7DWLOm++oFV0NK5+sxBtqnen9xhVSq4oG/Jr3ZZCaxRyMUI97gYouUVO7A==@lists.linux.dev X-Gm-Message-State: AOJu0Yy0V+/bGMiofjH+4yjTgdpwc9NyPBQqTHw8MSMQ8ilh9jdRBbEE +pzl4k9QJSVfZUSZ+/M+JFFDrrxSYGqEKv6+lf1vruwdhAxQldaJ X-Gm-Gg: ASbGnctp9N6xVKFvT/D/54zsPpHqUIJmuukwh4lsH2I7Eo8KvEEmQPt12Tbv2cFf5BR qoOH9eQP4EIo41N4bx9qWlGdO1+xg6THsfpKXvOKPyLUzhWPvbWc039cgeH1Qu05WdRILgLRF/T S7+MpmAFUVMrIFMSq9i6fVuOgHqEPx2Fj21Fo65dES1DMQrSl0LMoQyq1VGQDDTS8SRThXy1XNK hvVS2697VJCKMh/xfb+jlDFF0aO9ShOa1EIzi9l8N7XUd7SfRt4F6LCYJtgKWtS1nuaBgxUhMP0 ERmTaSluQIvokY87MvUBCYSII/MxwV2EMeO+DSErkHR2d4LAP6rDFSkJeD4kqXlPc4sdX7Dxk3m Z6C1g9/hgRQcjDo8= X-Google-Smtp-Source: AGHT+IEUwhe6OOxxpEfNaCe738T3WyLHsdbg2eSe+3G4ctBrxQHhEeqFNHAxJs2mvqfoOjBLOVf4Qg== X-Received: by 2002:a05:6a00:2985:b0:736:3c2b:c38e with SMTP id d2e1a72fcca58-7406735b5a1mr68276b3a.13.1746205650438; Fri, 02 May 2025 10:07:30 -0700 (PDT) Received: from localhost ([2a00:79e0:3e00:2601:3afc:446b:f0df:eadc]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74058dc45basm1890164b3a.69.2025.05.02.10.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 10:07:29 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Connor Abbott , Rob Clark , Will Deacon , Robin Murphy , Joerg Roedel , Jason Gunthorpe , Kevin Tian , Nicolin Chen , Joao Martins , linux-arm-kernel@lists.infradead.org (moderated list:ARM SMMU DRIVERS), iommu@lists.linux.dev (open list:IOMMU SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 03/33] iommu/io-pgtable-arm: Add quirk to quiet WARN_ON() Date: Fri, 2 May 2025 09:56:30 -0700 Message-ID: <20250502165831.44850-4-robdclark@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502165831.44850-1-robdclark@gmail.com> References: <20250502165831.44850-1-robdclark@gmail.com> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Rob Clark In situations where mapping/unmapping squence can be controlled by userspace, attempting to map over a region that has not yet been unmapped is an error. But not something that should spam dmesg. Now that there is a quirk, we can also drop the selftest_running flag, and use the quirk instead for selftests. Signed-off-by: Rob Clark --- drivers/iommu/io-pgtable-arm.c | 27 ++++++++++++++------------- include/linux/io-pgtable.h | 8 ++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index f27965caf6a1..a535d88f8943 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -253,8 +253,6 @@ static inline bool arm_lpae_concat_mandatory(struct io_pgtable_cfg *cfg, (data->start_level == 1) && (oas == 40); } -static bool selftest_running = false; - static dma_addr_t __arm_lpae_dma_addr(void *pages) { return (dma_addr_t)virt_to_phys(pages); @@ -373,7 +371,7 @@ static int arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, for (i = 0; i < num_entries; i++) if (iopte_leaf(ptep[i], lvl, data->iop.fmt)) { /* We require an unmap first */ - WARN_ON(!selftest_running); + WARN_ON(!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_NO_WARN_ON)); return -EEXIST; } else if (iopte_type(ptep[i]) == ARM_LPAE_PTE_TYPE_TABLE) { /* @@ -475,7 +473,7 @@ static int __arm_lpae_map(struct arm_lpae_io_pgtable *data, unsigned long iova, cptep = iopte_deref(pte, data); } else if (pte) { /* We require an unmap first */ - WARN_ON(!selftest_running); + WARN_ON(!(cfg->quirks & IO_PGTABLE_QUIRK_NO_WARN_ON)); return -EEXIST; } @@ -649,8 +647,10 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data); ptep += unmap_idx_start; pte = READ_ONCE(*ptep); - if (WARN_ON(!pte)) - return 0; + if (!pte) { + WARN_ON(!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_NO_WARN_ON)); + return -ENOENT; + } /* If the size matches this level, we're in the right place */ if (size == ARM_LPAE_BLOCK_SIZE(lvl, data)) { @@ -660,8 +660,10 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, /* Find and handle non-leaf entries */ for (i = 0; i < num_entries; i++) { pte = READ_ONCE(ptep[i]); - if (WARN_ON(!pte)) + if (!pte) { + WARN_ON(!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_NO_WARN_ON)); break; + } if (!iopte_leaf(pte, lvl, iop->fmt)) { __arm_lpae_clear_pte(&ptep[i], &iop->cfg, 1); @@ -976,7 +978,8 @@ arm_64_lpae_alloc_pgtable_s1(struct io_pgtable_cfg *cfg, void *cookie) if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_ARM_TTBR1 | IO_PGTABLE_QUIRK_ARM_OUTER_WBWA | - IO_PGTABLE_QUIRK_ARM_HD)) + IO_PGTABLE_QUIRK_ARM_HD | + IO_PGTABLE_QUIRK_NO_WARN_ON)) return NULL; data = arm_lpae_alloc_pgtable(cfg); @@ -1079,7 +1082,8 @@ arm_64_lpae_alloc_pgtable_s2(struct io_pgtable_cfg *cfg, void *cookie) struct arm_lpae_io_pgtable *data; typeof(&cfg->arm_lpae_s2_cfg.vtcr) vtcr = &cfg->arm_lpae_s2_cfg.vtcr; - if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_S2FWB)) + if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_S2FWB | + IO_PGTABLE_QUIRK_NO_WARN_ON)) return NULL; data = arm_lpae_alloc_pgtable(cfg); @@ -1320,7 +1324,6 @@ static void __init arm_lpae_dump_ops(struct io_pgtable_ops *ops) #define __FAIL(ops, i) ({ \ WARN(1, "selftest: test failed for fmt idx %d\n", (i)); \ arm_lpae_dump_ops(ops); \ - selftest_running = false; \ -EFAULT; \ }) @@ -1336,8 +1339,6 @@ static int __init arm_lpae_run_tests(struct io_pgtable_cfg *cfg) size_t size, mapped; struct io_pgtable_ops *ops; - selftest_running = true; - for (i = 0; i < ARRAY_SIZE(fmts); ++i) { cfg_cookie = cfg; ops = alloc_io_pgtable_ops(fmts[i], cfg, cfg); @@ -1426,7 +1427,6 @@ static int __init arm_lpae_run_tests(struct io_pgtable_cfg *cfg) free_io_pgtable_ops(ops); } - selftest_running = false; return 0; } @@ -1448,6 +1448,7 @@ static int __init arm_lpae_do_selftests(void) .tlb = &dummy_tlb_ops, .coherent_walk = true, .iommu_dev = &dev, + .quirks = IO_PGTABLE_QUIRK_NO_WARN_ON, }; /* __arm_lpae_alloc_pages() merely needs dev_to_node() to work */ diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h index bba2a51c87d2..639b8f4fb87d 100644 --- a/include/linux/io-pgtable.h +++ b/include/linux/io-pgtable.h @@ -88,6 +88,13 @@ struct io_pgtable_cfg { * * IO_PGTABLE_QUIRK_ARM_HD: Enables dirty tracking in stage 1 pagetable. * IO_PGTABLE_QUIRK_ARM_S2FWB: Use the FWB format for the MemAttrs bits + * + * IO_PGTABLE_QUIRK_NO_WARN_ON: Do not WARN_ON() on conflicting + * mappings, but silently return -EEXISTS. Normally an attempt + * to map over an existing mapping would indicate some sort of + * kernel bug, which would justify the WARN_ON(). But for GPU + * drivers, this could be under control of userspace. Which + * deserves an error return, but not to spam dmesg. */ #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) @@ -97,6 +104,7 @@ struct io_pgtable_cfg { #define IO_PGTABLE_QUIRK_ARM_OUTER_WBWA BIT(6) #define IO_PGTABLE_QUIRK_ARM_HD BIT(7) #define IO_PGTABLE_QUIRK_ARM_S2FWB BIT(8) + #define IO_PGTABLE_QUIRK_NO_WARN_ON BIT(9) unsigned long quirks; unsigned long pgsize_bitmap; unsigned int ias; -- 2.49.0