Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp685218lqc; Fri, 8 Mar 2024 08:47:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXyV3bVyZnlCAYAyaNhRPa73bMuKS3DyMs3gS6lwrGkcHjUZgSG1ETyy4010gUowJf0ZhVdmW7w4Y5YHqzsjcMPqbrxiD89S9dz6dzO4A== X-Google-Smtp-Source: AGHT+IFiOBlFebvyzJfLaG+cbXIsZV3dkkNxckf7K/mJ5ziCE/SuxpjGk5bPwxQVBeOFPSKk7i/l X-Received: by 2002:a9d:6959:0:b0:6e4:dc33:e8c1 with SMTP id p25-20020a9d6959000000b006e4dc33e8c1mr14603575oto.12.1709916468152; Fri, 08 Mar 2024 08:47:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709916468; cv=pass; d=google.com; s=arc-20160816; b=o1afVeeUnWYTBoj3zOSFDaA7ZZcH8v5BeP7uRmbG0MEVlLUQxAlLcnK+yzgcN4BNhi FNUklsM65ypBqkqKiVHbh+9OSGiT2In1+5Naj+C8oRw7KhE8jyw8Wz3GA6tINZBVhKQd 1np0xJ8g9g7TKPHaWvA/tnrdT5xTqv3sn6rKpHxiKSSNqYIlvHSLscamVjiO2a4Bsn2I VqwFtTv2sfdy7MNundxvRp/X82E82cmkLI8PMTGzsvbkTQfmVn3sN00XgdCedDhd7Rg9 4B3fdehYfbWaM+5XPFFFesyH+C/UdRb9eWui/aWRR/iS9/i/ZkCiLRgDOmWoRZMY+DcU YyCg== 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=wYkGaMnNecZ484j/sTojyqfZAtdlr73D93VzoZo94XQ=; fh=7uvZ7/EHB5jbjIQkSagmoiGOqtPIkqZnDa8J0Z9z6hk=; b=tP1rVp5Ib/vBiItNkvDRnMQOYO88oPumQNXYnBS7MFBqOIoGbLR5kpelX9rSwKVSSY ytlF2lg+tsXAgWg+cfT6+jlhvU3uhtQDWHy6r+ow43brclwoehNlIhcMxujpp0vLbyG/ EwMqpOX9s2e2KmAoG4nNQegCBnlxN+h39XVSvW3YYzjAcZ9NxZGpY/ahReFUsFFFPNKh qpnOMpl7X4zQ6V53pzOm7OvKwNJAFsMDpWuIWI3gt9jz34xC/Y8wDXA0/r8QPJdaAZhJ OnD/epx6N1QSrDlDEtDASziwIYyWNoVsmRGP5ej8Ch+94hk6aaEHVDGifqKMdL/Gr8aw 0BOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=X8APzAw4; 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-97315-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97315-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 dr5-20020a056a020fc500b005dc8719cdfasi16438617pgb.298.2024.03.08.08.47.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 08:47:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97315-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=X8APzAw4; 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-97315-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97315-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 B4A2928799E for ; Fri, 8 Mar 2024 16:41:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6EA8E572; Fri, 8 Mar 2024 16:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="X8APzAw4" 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 3326DDDD7 for ; Fri, 8 Mar 2024 16:41:13 +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=1709916077; cv=none; b=QGVJ6N2L+fjMhhE9nv7f7qEhoM83r/D0RmYQuf/oHu2bIKKG+0Tzxw8mZiS5zmklTyVW24UVq+5OAr69D7uDQdA+i+kslr8x8la90CR+C87H0+aCc6s+ZGW+Gi47bo39rZn/IyIA8wHZG4I02gv8/U8ghttVtWl2+PeIeqTAS7s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709916077; c=relaxed/simple; bh=E7xjUr7XFDIgxAuAR5skBYnGfcngAPHjHTPg0v/bj90=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A7mmg+qBWH9+4L+yiYwTMcoKqygT2Kj8LtZLZC0Zkll3dX2hu+csn8bE5SouGlSw4VPn2GcnMgU5c0gISQ8X3PegO5q7fR2SnafmKPSJQum2EAicS9CQ5aECm/HLe9TIGD0F5KCNPW/7aVUWnmBpgvZK/+cLShXSsMRQrLlbrYI= 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=X8APzAw4; 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 2658B1CD4D4; Fri, 8 Mar 2024 17:38:17 +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=1709915897; bh=wYkGaMnNecZ484j/sTojyqfZAtdlr73D93VzoZo94XQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=X8APzAw4QGRrwmr7uU8EBQQaxdnUXixKcfd9Vy2bIaRqtOf5kFsoTuZNJJRCBwH76 Y5OT/bsLx439Bwnr1nMTq85VUAx4SnXhTHkdwUrxfK88Z31Brx7MY9S3FaE5zt6r6+ AOGk+0T7l3E6rahfyR3sNlMs/wdv+TiAY60PxgF8U8gRgPfHia7QiKS6CrAgtVabyP tCdn12xxZfn3/X/R9vQ8GMkbSRpgaimKOppaQQ71aNKjD1GK55ZrbJ2fRF13BNgHqs y6WrvJZxu57KnchJ5ah5QANXRSwEN0nHF2HGs0v50/yiEUaeuw2VDN7g+BQMy9D8rK JJGs1fkc6A0Iw== Date: Fri, 8 Mar 2024 17:38:16 +0100 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Robin Murphy Cc: Will Deacon , linux-kernel@vger.kernel.org, kernel-team@android.com, iommu@lists.linux.dev, Christoph Hellwig , Marek Szyprowski , Petr Tesarik , Dexuan Cui , Nicolin Chen , Michael Kelley Subject: Re: [PATCH v6 6/6] swiotlb: Reinstate page-alignment for mappings >= PAGE_SIZE Message-ID: <20240308173816.5351ea58@meshulam.tesarici.cz> In-Reply-To: <5c7c7407-5356-4e12-a648-ae695fe0d1cb@arm.com> References: <20240308152829.25754-1-will@kernel.org> <20240308152829.25754-7-will@kernel.org> <5c7c7407-5356-4e12-a648-ae695fe0d1cb@arm.com> 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 16:08:01 +0000 Robin Murphy wrote: > On 2024-03-08 3:28 pm, 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. > > This seems clear enough to keep me happy now, thanks! And apologies that > I managed to confuse even myself in the previous thread... > > Reviewed-by: Robin Murphy I thought we agreed that this stricter alignment is unnecessary: https://lore.kernel.org/linux-iommu/20240305140833.GC3659@lst.de/ But if everybody else wants to have it... Petr T > > 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; > > + > > /* > > * 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; >