From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 987A1EEAA4E for ; Thu, 14 Sep 2023 15:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fW/3ExmeYwKTHY4ycEHPSxnh44NyKPp+xLrzdo2Z0a8=; b=sfDw/W5XulU3iB 5e0IavQFyn4cb2Foi8ULTUNhWlBtxMkLR7978fTqVADl2Qmp9Z7Z5i3R5QjTQklh0U2Gu8BQp7p5I PoK7r/xZDwpjLeih0uPgdf4p/tdHtbgfcUFAeouIPUxt3PrpNlYlmGqC+asZfte21i6bgMADY7dmQ D0MTnGpXididwqhPtiQ2r2iQKjbxmdgoyHf/0uRZ69i9bW6OF5IQSeBH4SGpQP4w5fakkCkHK01zJ inzRxu4RTJqqnVZLfPBfowyH3r2u1jPWR2CTiHS9NEmFdtOjPKomm+b3+ZvCluAoh69OJ+L74XJJ8 Z8QKF3EWUqjYbOC6GHtA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgnyJ-008knj-0e; Thu, 14 Sep 2023 15:09:35 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgnyG-008kl8-1A for linux-arm-kernel@lists.infradead.org; Thu, 14 Sep 2023 15:09:33 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2bcd7a207f7so16904781fa.3 for ; Thu, 14 Sep 2023 08:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694704170; x=1695308970; darn=lists.infradead.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=q0p2Fq5+hhl2cqW/SVj6LzHkxBEiQPEgkqZ0kedkzFo=; b=Eeywg7Szo420ftAKlph3ODD4YHfByWlpU+lL0DJCXpWemjJ1ctU2RIYcgkcEFrI65l gHAVnM7WfrD0MY84swe/OrCLvlVDzSdIw0Q7BVyMu/DY4a9n43ERK6goXP/mKKSpTNZf NVqy9sHKQ+ozfwId5cfsR3ekAeq9+UZHqKvhe/Mguk6AmJURvNVjGh7m1u+qvXmQ1105 1F945vl6f6V3u5tTT8REEhGh9bZZbNHfTdmM3W0CkcUyBAq2r5RYvYvIfGE5pVVFx0W5 QvGVlmnf7RQU/ShBWRPh9nAdYqqdM2wqT+n1Quw62KljtTHVCtrIaX5xLmcCnEpaEODQ g62g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694704170; x=1695308970; 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=q0p2Fq5+hhl2cqW/SVj6LzHkxBEiQPEgkqZ0kedkzFo=; b=m4+LN54kcK0nOQbwJ/OE1xLSzvmG64gtjHFnDfYgQf10BgVB7ecE4maMcEg3ThZAPF YJL4PGF1/qhMjkIKKx5+WEa2WbVBvFLcDVrUX8h7dFNhV10AOEIvd5hbLSN1HM4tDBRZ 1GhnZ/wA0kF0tX9gMVRwlDTlJdpG2RXswGwBpeluyykY82Z3Gz6idLX8Msj+3R/vyis3 luPxhdA+S7Jlf31jLgtUth9uhr2o1OLx2uczXNte+ql9HwlGMsRPur2boTMQ1y+SnfXw ATk2BMpfv72VaFsoByEr5tlt7VHaDdSo+y8hv/n51x/bphOym2hYQZ9xuYd5h8EsnTiW y6ZQ== X-Gm-Message-State: AOJu0YwM1F150PexY466SoOMwsmJqYrBxQyY2I3IgTrBJU3sfrLDFvAP sStCy2H/OXRRZROzsfcOHk4= X-Google-Smtp-Source: AGHT+IH4YOeufwCrX/hbygxPlNKDg8361e4VDmQWvIJ0vsQn9E6uQVWHXteDHYpafcchB+dIAnqyDA== X-Received: by 2002:a05:651c:103b:b0:2b6:dc55:c3c7 with SMTP id w27-20020a05651c103b00b002b6dc55c3c7mr5758747ljm.20.1694704169528; Thu, 14 Sep 2023 08:09:29 -0700 (PDT) Received: from jernej-laptop.localnet (82-149-12-148.dynamic.telemach.net. [82.149.12.148]) by smtp.gmail.com with ESMTPSA id m18-20020a1709066d1200b00993a37aebc5sm1121294ejr.50.2023.09.14.08.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 08:09:29 -0700 (PDT) From: Jernej =?utf-8?B?xaBrcmFiZWM=?= To: joro@8bytes.org, will@kernel.org, Robin Murphy Cc: wens@csie.org, samuel@sholland.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu/sun50i: Convert to map_pages/unmap_pages Date: Thu, 14 Sep 2023 17:09:28 +0200 Message-ID: <5708623.DvuYhMxLoT@jernej-laptop> In-Reply-To: <157d5041-96ac-6bad-9137-19a78fbf3591@arm.com> References: <20230912181941.2971036-1-jernej.skrabec@gmail.com> <157d5041-96ac-6bad-9137-19a78fbf3591@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230914_080932_403537_F1FC0EEE X-CRM114-Status: GOOD ( 31.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Dne sreda, 13. september 2023 ob 22:20:15 CEST je Robin Murphy napisal(a): > On 2023-09-12 19:19, Jernej Skrabec wrote: > > Convert driver to use map_pages and unmap_pages. Since functions operate > > on page table, extend them to be able to operate on whole table, not > > just one entry. > > > > Signed-off-by: Jernej Skrabec > > --- > > Hi! > > > > I'm not sure if it makes sense to check validity of page table entry when > > unmaping pages makes sense. What do you think? > > As things currently stand it's largely a matter of opinion - some > drivers consider that unmapping something which hasn't been mapped is > nonsensical, and almost always represents the caller having gone wrong, > thus report it as an error; others take the view that as long as they > can achieve the requested end result, they're not going to think too > hard about how they got there. The same arguments apply to whether you'd > quietly replace an existing PTE or not when mapping, so I'd say the main > thing is to at least be self-consistent one way or the other. Ok, I preserved strict checks in this update, which is consistent and same as before. Best regards, Jernej > > Cheers, > Robin. > > > Best regards, > > Jernej > > > > drivers/iommu/sun50i-iommu.c | 55 +++++++++++++++++++++--------------- > > 1 file changed, 33 insertions(+), 22 deletions(-) > > > > diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c > > index 74c5cb93e900..be6102730a56 100644 > > --- a/drivers/iommu/sun50i-iommu.c > > +++ b/drivers/iommu/sun50i-iommu.c > > @@ -589,11 +589,12 @@ static u32 *sun50i_dte_get_page_table(struct > > sun50i_iommu_domain *sun50i_domain,> > > } > > > > static int sun50i_iommu_map(struct iommu_domain *domain, unsigned long > > iova,> > > - phys_addr_t paddr, size_t size, int prot, gfp_t gfp) > > + phys_addr_t paddr, size_t pgsize, size_t pgcount, > > + int prot, gfp_t gfp, size_t *mapped) > > > > { > > > > struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); > > struct sun50i_iommu *iommu = sun50i_domain->iommu; > > > > - u32 pte_index; > > + u32 pte_index, count, i; > > > > u32 *page_table, *pte_addr; > > int ret = 0; > > > > @@ -604,45 +605,55 @@ static int sun50i_iommu_map(struct iommu_domain > > *domain, unsigned long iova,> > > } > > > > pte_index = sun50i_iova_get_pte_index(iova); > > > > - pte_addr = &page_table[pte_index]; > > - if (unlikely(sun50i_pte_is_page_valid(*pte_addr))) { > > - phys_addr_t page_phys = sun50i_pte_get_page_address(*pte_addr); > > - dev_err(iommu->dev, > > - "iova %pad already mapped to %pa cannot remap to %pa prot: %#x\n", > > - &iova, &page_phys, &paddr, prot); > > - ret = -EBUSY; > > - goto out; > > + count = min(pgcount, (size_t)NUM_PT_ENTRIES - pte_index); > > + for (i = 0; i < count; i++) { > > + pte_addr = &page_table[pte_index + i]; > > + if (unlikely(sun50i_pte_is_page_valid(*pte_addr))) { > > + phys_addr_t page_phys = sun50i_pte_get_page_address(*pte_addr); > > + > > + dev_err(iommu->dev, > > + "iova %pad already mapped to %pa cannot remap to %pa prot: %#x\n", > > + &iova, &page_phys, &paddr, prot); > > + ret = -EBUSY; > > + goto out; > > + } > > + *pte_addr = sun50i_mk_pte(paddr, prot); > > + paddr += SPAGE_SIZE; > > > > } > > > > - *pte_addr = sun50i_mk_pte(paddr, prot); > > - sun50i_table_flush(sun50i_domain, pte_addr, 1); > > + sun50i_table_flush(sun50i_domain, &page_table[pte_index], i); > > + *mapped = i * SPAGE_SIZE; > > > > out: > > return ret; > > > > } > > > > static size_t sun50i_iommu_unmap(struct iommu_domain *domain, unsigned > > long iova,> > > - size_t size, struct iommu_iotlb_gather *gather) > > + size_t pgsize, size_t pgcount, > > + struct iommu_iotlb_gather *gather) > > > > { > > > > struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); > > > > + u32 dte, count, i, pte_index; > > > > phys_addr_t pt_phys; > > u32 *pte_addr; > > > > - u32 dte; > > > > dte = sun50i_domain->dt[sun50i_iova_get_dte_index(iova)]; > > if (!sun50i_dte_is_pt_valid(dte)) > > > > return 0; > > > > pt_phys = sun50i_dte_get_pt_address(dte); > > > > - pte_addr = (u32 *)phys_to_virt(pt_phys) + > > sun50i_iova_get_pte_index(iova); + pte_index = > > sun50i_iova_get_pte_index(iova); > > + pte_addr = (u32 *)phys_to_virt(pt_phys) + pte_index; > > > > - if (!sun50i_pte_is_page_valid(*pte_addr)) > > - return 0; > > + count = min(pgcount, (size_t)NUM_PT_ENTRIES - pte_index); > > + for (i = 0; i < count; i++) > > + if (!sun50i_pte_is_page_valid(pte_addr[i])) > > + break; > > > > - memset(pte_addr, 0, sizeof(*pte_addr)); > > - sun50i_table_flush(sun50i_domain, pte_addr, 1); > > + memset(pte_addr, 0, sizeof(*pte_addr) * i); > > + sun50i_table_flush(sun50i_domain, pte_addr, i); > > > > - return SZ_4K; > > + return i * SPAGE_SIZE; > > > > } > > > > static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain > > *domain, > > > > @@ -838,8 +849,8 @@ static const struct iommu_ops sun50i_iommu_ops = { > > > > .iotlb_sync_map = sun50i_iommu_iotlb_sync_map, > > .iotlb_sync = sun50i_iommu_iotlb_sync, > > .iova_to_phys = sun50i_iommu_iova_to_phys, > > > > - .map = sun50i_iommu_map, > > - .unmap = sun50i_iommu_unmap, > > + .map_pages = sun50i_iommu_map, > > + .unmap_pages = sun50i_iommu_unmap, > > > > .free = sun50i_iommu_domain_free, > > > > } > > > > }; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel