Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp713643lqc; Fri, 8 Mar 2024 09:30:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV0+9ZWbxEJLSGEANwyFb6OfJp1FLPkm427kcxCh1QOazROgGNcQc40IWPHigaPSy/2mZhfksKKx2YyHrKIec1IMXe4sPf+1Ztcv4EA2g== X-Google-Smtp-Source: AGHT+IHr13yZXz70nf2w3iYSsROFF7EN8uCERjXcWPyEiKcR5BumHSauUWZKIZf6aV+y40/VgzEF X-Received: by 2002:a17:902:aa07:b0:1dc:38c7:ba1a with SMTP id be7-20020a170902aa0700b001dc38c7ba1amr10999582plb.25.1709919013198; Fri, 08 Mar 2024 09:30:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709919013; cv=pass; d=google.com; s=arc-20160816; b=RDFxBQoSZLK13hcLC7TrWTJQSICjubroeXXn0urZfBkOK9puJSqzVIcPmEAIcDCSFO fdQ/vPAofD570x9+gJTWV4MkcVi8POHSXCKjz3jWSfh3LO9TkZ32O2gC3UdESbzdSw/b ENtEZaYpIWH60kxOsTT7jNfST2c3HOXf9UH0OQBprbYhIv4eUClqfhFkMBXsyyp3ZzKC 9SzM8igf/pWNiSeDs8/M+euT4CNwLREh4h2BoBTV7N1IG9m4zfI5totUVc7zSmMAHDWU 8J9ANCGN69pbHBm96ossl80b7W9yS8QPQjC6OaJTm5q+HsERlsmMk0a1H72VYQb7WrA9 A7RQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=Kh5qXYlmNI8yXj7FHKJySjYJ+bgEs1XYPseFJ0PQC3I=; fh=CB6POrSIkdk+RyfbFm+yqa9KLR3zsLngk1fk1KLAoy0=; b=ewnODL3NT8moxlwvhg6agZPUyFPflHXebuTdu9IYOcOLKMcdHHB5cvAc1ooVNUJOt8 wH17CDuB5zd0luDluPuX/ONbV4q+gYbywcBIy/N8KZrEMmfKjx+XIxUDTIi+rz/kUnoa yRmQrLctSxN48yPJzzJg/GFgbfsF8/IzDPsENczMl+QVe3NUiMOGp0D91/LHqTU2Nxrk lRIC4D5lFODwzgfTCjBkmnoC7MpOBbI9limG3Hk369tMMQbvNYVB822j+kXWrzimZBnu JX4FvV2XZgDc+EGV6myD0ZX+ITPaW1SAT5ftpcbJeq46enYRR90nXvOgbv+IkIcrFgYQ hGVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=dtDlJ6AJ; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-97389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s15-20020a17090302cf00b001dbc6f9e3a8si16826871plk.66.2024.03.08.09.30.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 09:30:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=dtDlJ6AJ; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-97389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D7C7528351B for ; Fri, 8 Mar 2024 17:30:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73DB55D8E4; Fri, 8 Mar 2024 17:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="dtDlJ6AJ" Received: from bee.tesarici.cz (bee.tesarici.cz [37.205.15.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A331D5B5C3 for ; Fri, 8 Mar 2024 17:28:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=37.205.15.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709918902; cv=none; b=aJtCmssRpuCxKC1GNlo/Jn9FNFNBAp/bwInN+9c3hToPi4EaZkWHr1zvfGlrNBRT6DcCDvNAgHr6TeToHEeUV0QdwDLApNuL74WFX1QBMZcsvzhbEPLBNydV5s98w3GbZ7njwRbC2yzxJgnQn/t+Wvk5P6DozmJTokiSYxyb2HY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709918902; c=relaxed/simple; bh=RpplHZoWRCwJBQzacp1/sEZWsMwTazs9ZvYuQaaQW3s=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fw1JeKMVCa77R+n0MBaNKVkL/pOE1uiOvEOyrOGCDsqfiFC5jNFAQWkHBkEd9hza7DnvTu8KV9ca6iSn6ZG/h2I3+iNgViXiZW2wByK24dMvJq/8p/25yYz3dV+g+OaHBU0mnmurXVaIWp+CqZQLHsmga0jl44l+lAPfqvkJrxY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tesarici.cz; spf=pass smtp.mailfrom=tesarici.cz; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b=dtDlJ6AJ; arc=none smtp.client-ip=37.205.15.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tesarici.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tesarici.cz Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id 5ACC91CDD3D; Fri, 8 Mar 2024 18:28:18 +0100 (CET) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=quarantine dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tesarici.cz; s=mail; t=1709918898; bh=Kh5qXYlmNI8yXj7FHKJySjYJ+bgEs1XYPseFJ0PQC3I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dtDlJ6AJTV0HohsVWIa/BdsZ4tUcZ5RlOZUFwSV8B9JYNQgwfQgXneqKDPmCRxOhi 4I4k4NziEPUCjyPt1FiY4D4ePPb144pZCdZku48qsHlz5D5bt1HnSgUb0wJwr1YxDF od4lXCx4tVaXSPqACZiKZwKXXmOMxChMZR+Jp1bB5kvFx60CXZBE+mgDRZa9XGgxm5 Lhi11D7770Ypj/PmD4aeKmeqFYltqDCqOba2A+RfeihUAaXh7BF2tv6mUE3DnROdxJ xhSJh0xI+8YX0Axo5fo5dQcKQH/qR7dRPLvani5ohkdP1vrpmZ22V9JXUBNHb1DoAq El/mgKgHc6+8Q== Date: Fri, 8 Mar 2024 18:28:17 +0100 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Will Deacon Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, iommu@lists.linux.dev, Christoph Hellwig , Marek Szyprowski , Robin Murphy , Petr Tesarik , Dexuan Cui , Nicolin Chen , Michael Kelley Subject: Re: [PATCH v6 6/6] swiotlb: Reinstate page-alignment for mappings >= PAGE_SIZE Message-ID: <20240308182817.7687329f@meshulam.tesarici.cz> In-Reply-To: <20240308152829.25754-7-will@kernel.org> References: <20240308152829.25754-1-will@kernel.org> <20240308152829.25754-7-will@kernel.org> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.39; x86_64-suse-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 8 Mar 2024 15:28:29 +0000 Will Deacon wrote: > For swiotlb allocations >= PAGE_SIZE, the slab search historically > adjusted the stride to avoid checking unaligned slots. This had the > side-effect of aligning large mapping requests to PAGE_SIZE, but that > was broken by 0eee5ae10256 ("swiotlb: fix slot alignment checks"). > > Since this alignment could be relied upon drivers, reinstate PAGE_SIZE > alignment for swiotlb mappings >= PAGE_SIZE. > > Reported-by: Michael Kelley > Signed-off-by: Will Deacon > > --- > kernel/dma/swiotlb.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index c381a7ed718f..c5851034523f 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -992,6 +992,17 @@ static int swiotlb_search_pool_area(struct device *dev, struct io_tlb_pool *pool > BUG_ON(!nslots); > BUG_ON(area_index >= pool->nareas); > > + /* > + * Historically, swiotlb allocations >= PAGE_SIZE were guaranteed to be > + * page-aligned in the absence of any other alignment requirements. > + * 'alloc_align_mask' was later introduced to specify the alignment > + * explicitly, however this is passed as zero for streaming mappings > + * and so we preserve the old behaviour there in case any drivers are > + * relying on it. > + */ > + if (!alloc_align_mask && !iotlb_align_mask && alloc_size >= PAGE_SIZE) > + alloc_align_mask = PAGE_SIZE - 1; > + This could be moved up the call chain to swiotlb_tbl_map_single(), but since there is already a plan to modify the call signatures for the next release, let's keep it here. Reviewed-by: Petr Tesarik Petr T > /* > * Ensure that the allocation is at least slot-aligned and update > * 'iotlb_align_mask' to ignore bits that will be preserved when > @@ -1006,13 +1017,6 @@ static int swiotlb_search_pool_area(struct device *dev, struct io_tlb_pool *pool > */ > stride = get_max_slots(max(alloc_align_mask, iotlb_align_mask)); > > - /* > - * For allocations of PAGE_SIZE or larger only look for page aligned > - * allocations. > - */ > - if (alloc_size >= PAGE_SIZE) > - stride = umax(stride, PAGE_SHIFT - IO_TLB_SHIFT + 1); > - > spin_lock_irqsave(&area->lock, flags); > if (unlikely(nslots > pool->area_nslabs - area->used)) > goto not_found;