From patchwork Mon Oct 28 21:31:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13854171 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 9A6821E0B7C; Mon, 28 Oct 2024 21:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730151326; cv=none; b=uIxYfO0EKSgXfLvQ2G6C8ltd8NJPkxK+hrQM1zZneTwqdMihEFttpYhfvwM4iat2RlB4W0yL+QV7azunn/RmUvHZBfWiYnLUggzE87LpL+tZvvKPkOF1u3bWGvdVPEqiiBNoign0ikMoCFRNSMzpLStHsUYLYTptBrYKBIZLWSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730151326; c=relaxed/simple; bh=7uXbqAU2Rs+FdAUI0yMJyvdaxWyQLWN4ppo3xQU6jME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VdT9kyu0489heUd4s/GlaNY6nDvgxrIjvkNq0h29r6n3lMfsPpDqssuhnt2S+a54Bek0Nq7wF5Frf/ttWtylQgSl8ClqHMUsnn3MfGr2fNDGw1q1wN1k9eD2lzmlz0NibzpVq1tsx3lFsXo3i2PN6kEU+2+NZzJFwoQMkiIyTqo= 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=VB2LS+XT; arc=none smtp.client-ip=209.85.216.53 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="VB2LS+XT" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2e56df894d4so3797777a91.3; Mon, 28 Oct 2024 14:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730151324; x=1730756124; darn=vger.kernel.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=m061Pyg3UwMZEnlvYwP1sOYnaFDaV5Le181aUe2JWFs=; b=VB2LS+XTjryCjKvZh5lj9Fv3uhuKi5QcNfbMZJh+jmBvKEaBfnxMuALD35n2NUYL3O EDl2Y03OSzCtFm8G0gO5dDUfo8hu4tG0ewNGeFvAOU6D0ve4JUyN9zMaD/mpttirmpxZ L/mo9CxKtYzm2glM0hs5Ccxdrop4aHlmp+F0C9cn6m1WM4HN76Gt1NKe0gSGlDLtDyhI eBMFhmWKkL+pg+0VzxWsgEJIKAm/8aPp6ETSdOI+WW5KIu4M2oPf/dtYGiP3glxKhTm3 gqBQnjUYRc4nDw8tbl5z7MeN3XOkOCLdybY6BhI6HlOc+73aBVmhrNB+Avr4UMNTLrZU oe3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730151324; x=1730756124; 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=m061Pyg3UwMZEnlvYwP1sOYnaFDaV5Le181aUe2JWFs=; b=Hspff4bNac8jEC28G7uzFzh65Fq79TAI6+LnLUItujeE0uBI/0Ghd1x/wTX/tOZhAm 8zKxifvdzD80KgKhMFBeyT3X5ZIAgKiCpzkA3KXZlx0v7PbA+61f3h2h+yMY4A1IZRlv WTzg+SY/+cAzggAkeDX8UWFYB84oQRZoyz2Ful93+UwH1281Iz3grIFMaa2/iT+8p7ey qjeh1WBAnnkI7/zpNNY+AmZJumDV1uh84I1oOsDDKfl5AQwTktyOYL3B8UiWu264Z7Ey A/MyyxuMQE3TK66n7x4zO+rRnsYtATlHH10INtUVjZLLas5gu1y17oHyBatVaEN25pD8 cJIg== X-Forwarded-Encrypted: i=1; AJvYcCVPD6fBL8y1j0nBxa0Om12cBV+upOvdET/3SkBLWgvj0jFomM2KdCXvWY4EYxbBMsRg+Aeulnsj1ONkz7c=@vger.kernel.org X-Gm-Message-State: AOJu0YzvZbji98eb3aRvEXoRIdeXvCd5euu/QRiSB174PX8KyBjA9DwI VH6j9QxF4luqgCxADUX1/YaBIj9YwtckDvnKodmW1z0xdxvbjOor X-Google-Smtp-Source: AGHT+IFMkNPD4yFz3qyWlzboYMBT0a0xBeKCCszOPUsi1vknNqZcTwRtbyVqgGg1MSNysN4Mc2hgGA== X-Received: by 2002:a17:90a:c90b:b0:2e2:e092:5323 with SMTP id 98e67ed59e1d1-2e8f11a9716mr11015208a91.29.1730151323871; Mon, 28 Oct 2024 14:35:23 -0700 (PDT) Received: from localhost ([2a00:79e1:2e00:1301:12e9:d196:a1e9:ab67]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e4c2a9dsm9890110a91.15.2024.10.28.14.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 14:35:23 -0700 (PDT) From: Rob Clark To: iommu@lists.linux.dev Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Will Deacon , Robin Murphy , Mostafa Saleh , Rob Clark , Joerg Roedel , linux-arm-kernel@lists.infradead.org (moderated list:ARM SMMU DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v10 1/4] iommu/io-pgtable-arm: Make pgtable walker more generic Date: Mon, 28 Oct 2024 14:31:37 -0700 Message-ID: <20241028213146.238941-2-robdclark@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028213146.238941-1-robdclark@gmail.com> References: <20241028213146.238941-1-robdclark@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Rob Clark We can re-use this basic pgtable walk logic in a few places. Signed-off-by: Rob Clark --- drivers/iommu/io-pgtable-arm.c | 67 ++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 0e67f1721a3d..7e9c0f8ae138 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -749,33 +749,33 @@ static phys_addr_t arm_lpae_iova_to_phys(struct io_pgtable_ops *ops, } struct io_pgtable_walk_data { - struct iommu_dirty_bitmap *dirty; + struct io_pgtable *iop; + void *data; + int (*visit)(struct io_pgtable_walk_data *walk_data, int lvl, + arm_lpae_iopte *ptep, size_t size); unsigned long flags; u64 addr; const u64 end; }; -static int __arm_lpae_iopte_walk_dirty(struct arm_lpae_io_pgtable *data, - struct io_pgtable_walk_data *walk_data, - arm_lpae_iopte *ptep, - int lvl); +static int __arm_lpae_iopte_walk(struct arm_lpae_io_pgtable *data, + struct io_pgtable_walk_data *walk_data, + arm_lpae_iopte *ptep, + int lvl); -static int io_pgtable_visit_dirty(struct arm_lpae_io_pgtable *data, - struct io_pgtable_walk_data *walk_data, - arm_lpae_iopte *ptep, int lvl) +static int io_pgtable_visit(struct arm_lpae_io_pgtable *data, + struct io_pgtable_walk_data *walk_data, + arm_lpae_iopte *ptep, int lvl) { struct io_pgtable *iop = &data->iop; arm_lpae_iopte pte = READ_ONCE(*ptep); - if (iopte_leaf(pte, lvl, iop->fmt)) { - size_t size = ARM_LPAE_BLOCK_SIZE(lvl, data); + size_t size = ARM_LPAE_BLOCK_SIZE(lvl, data); + int ret = walk_data->visit(walk_data, lvl, ptep, size); + if (ret) + return ret; - if (iopte_writeable_dirty(pte)) { - iommu_dirty_bitmap_record(walk_data->dirty, - walk_data->addr, size); - if (!(walk_data->flags & IOMMU_DIRTY_NO_CLEAR)) - iopte_set_writeable_clean(ptep); - } + if (iopte_leaf(pte, lvl, iop->fmt)) { walk_data->addr += size; return 0; } @@ -784,13 +784,13 @@ static int io_pgtable_visit_dirty(struct arm_lpae_io_pgtable *data, return -EINVAL; ptep = iopte_deref(pte, data); - return __arm_lpae_iopte_walk_dirty(data, walk_data, ptep, lvl + 1); + return __arm_lpae_iopte_walk(data, walk_data, ptep, lvl + 1); } -static int __arm_lpae_iopte_walk_dirty(struct arm_lpae_io_pgtable *data, - struct io_pgtable_walk_data *walk_data, - arm_lpae_iopte *ptep, - int lvl) +static int __arm_lpae_iopte_walk(struct arm_lpae_io_pgtable *data, + struct io_pgtable_walk_data *walk_data, + arm_lpae_iopte *ptep, + int lvl) { u32 idx; int max_entries, ret; @@ -805,7 +805,7 @@ static int __arm_lpae_iopte_walk_dirty(struct arm_lpae_io_pgtable *data, for (idx = ARM_LPAE_LVL_IDX(walk_data->addr, lvl, data); (idx < max_entries) && (walk_data->addr < walk_data->end); ++idx) { - ret = io_pgtable_visit_dirty(data, walk_data, ptep + idx, lvl); + ret = io_pgtable_visit(data, walk_data, ptep + idx, lvl); if (ret) return ret; } @@ -813,6 +813,23 @@ static int __arm_lpae_iopte_walk_dirty(struct arm_lpae_io_pgtable *data, return 0; } +static int visit_dirty(struct io_pgtable_walk_data *walk_data, int lvl, + arm_lpae_iopte *ptep, size_t size) +{ + struct iommu_dirty_bitmap *dirty = walk_data->data; + + if (!iopte_leaf(*ptep, lvl, walk_data->iop->fmt)) + return 0; + + if (iopte_writeable_dirty(*ptep)) { + iommu_dirty_bitmap_record(dirty, walk_data->addr, size); + if (!(walk_data->flags & IOMMU_DIRTY_NO_CLEAR)) + iopte_set_writeable_clean(ptep); + } + + return 0; +} + static int arm_lpae_read_and_clear_dirty(struct io_pgtable_ops *ops, unsigned long iova, size_t size, unsigned long flags, @@ -821,7 +838,9 @@ static int arm_lpae_read_and_clear_dirty(struct io_pgtable_ops *ops, struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops); struct io_pgtable_cfg *cfg = &data->iop.cfg; struct io_pgtable_walk_data walk_data = { - .dirty = dirty, + .iop = &data->iop, + .data = dirty, + .visit = visit_dirty, .flags = flags, .addr = iova, .end = iova + size, @@ -836,7 +855,7 @@ static int arm_lpae_read_and_clear_dirty(struct io_pgtable_ops *ops, if (data->iop.fmt != ARM_64_LPAE_S1) return -EINVAL; - return __arm_lpae_iopte_walk_dirty(data, &walk_data, ptep, lvl); + return __arm_lpae_iopte_walk(data, &walk_data, ptep, lvl); } static void arm_lpae_restrict_pgsizes(struct io_pgtable_cfg *cfg)