Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp657838lqc; Fri, 8 Mar 2024 08:08:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqcuALP9hQLVlBMFY9ueTViiPUaWsRDjOg0kSil3rG21F2Di5klKmOENE9bvhKHTLeqmU1pNP3/jVJShuOXGc8gI9ZpbDLRihKEoDYxA== X-Google-Smtp-Source: AGHT+IFI3JQCuWQ4dfQPzP+cNdUiBC0u5u9vQT/lLZC8FrpKErhQNUGHtx7xS+EiZzQtSOepGTFh X-Received: by 2002:a05:620a:f81:b0:788:1178:195f with SMTP id b1-20020a05620a0f8100b007881178195fmr11302017qkn.18.1709914094883; Fri, 08 Mar 2024 08:08:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709914094; cv=pass; d=google.com; s=arc-20160816; b=H3OKfC883OSst3FURcYV0re8CICAwOmyurJbr7eaK6dYU61wLkuUB7L/wCLGUdt8De IBC+R13+xWHgLgt1kp8LUxgp4usdoS2OCN2v/SjWNtcWMH4sT0EbeN65Co2LoNvKMeGV fQffWzvxbxpLqBmCDs+/V6I3BQeGUAi+T5XncgcjO2q2y9P8pHEICs6y1xH/dfH/82E1 cQDRMbuxGq+UiHE/1lIXpWrt0PDegBNhWzPdGXJxYZHZTbDlCZyLCpOzDdJ4twaHKJ5N mxhXdB8VSHBkqUM2tJtKLM5EyNpesDidNkbidyIV3mG9ioghj6S57Gt716RjJGT1x6J5 6pSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=8p29dEzjoJ04jxE7p+0teX/QQZPK6My6PsbWmwXKII4=; fh=mF+Qm1OEe7XBbQw/Dgh8Z9Y1evyuVSOSAT/oqgZp9wc=; b=Q3a9CPqn4P8kcTU+fA/s0T8Xd5B4ycOV6ENjSMtN6yrHq8lqI0MmWlSYiWmLizy1Wy SuS0SIeRqvBDVY0kTp3NVebI+uGzxjpeJJxgBW65FfXdO48Zi1s9g5Xq0AjZdKCd7vdK xdQrPvZpiJ7Y2QlFtkOhVD8GYoH+f7mMdv1B9Ef84+AHEOtYokplQssaiuhmpHezB285 grVlEyBJF6Lee+DT4tgR4KGLXBTF6wnuy5Cc2/tGHsUFUz4bhwCnrfziwUvXkcLsiqGx 2itzPEmJO3KL/hd5jm0KkaY+6K+ygqZpTmQkiVvwC+qFLp7hRH8ndyCzKijAKApXeXNx Ao4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-97271-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h12-20020a37c44c000000b007882760591dsi11564454qkm.423.2024.03.08.08.08.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 08:08:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97271-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-97271-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 991201C21EF1 for ; Fri, 8 Mar 2024 16:08:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF7AB25774; Fri, 8 Mar 2024 16:08:08 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45517567A for ; Fri, 8 Mar 2024 16:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709914088; cv=none; b=JMvqXmM2XG3bXYY4orj1su4jxuzp5cOvflMQNmloLpxb0i+9oMN2LwvO3bfjrY+nPARY270NKv4aUTZL6aecFE+aO/p9kt39XpuOKNwJEmcjj3DgZ1rIZZbvrUF/f6c8jJybROeY3xWK/QxvtXq852/IiNaaa3VYddT5hMfALDs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709914088; c=relaxed/simple; bh=4776VYAwYZcBlvK+XQSJBOsbq5ySlZEiham03xKgXWA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NlAgMN33pFFdanXi5Cjqm62/qDPnipBkiSha760suTmWtqT9fMgmWEsG81xq7tV2V/iMm+sSQk7K8ajSpuSVaurQXBlcCRZZCIXmxa0/8N+DBtx6yIq29Mj6x7wAOKqpY0tvSlIKhTEx/xjvhAc+m8zzrYJax+Eavm7ktV/Em8I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 04365C15; Fri, 8 Mar 2024 08:08:41 -0800 (PST) Received: from [10.57.68.92] (unknown [10.57.68.92]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A02C33F73F; Fri, 8 Mar 2024 08:08:02 -0800 (PST) Message-ID: <5c7c7407-5356-4e12-a648-ae695fe0d1cb@arm.com> Date: Fri, 8 Mar 2024 16:08:01 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 6/6] swiotlb: Reinstate page-alignment for mappings >= PAGE_SIZE Content-Language: en-GB To: Will Deacon , linux-kernel@vger.kernel.org Cc: kernel-team@android.com, iommu@lists.linux.dev, Christoph Hellwig , Marek Szyprowski , Petr Tesarik , Dexuan Cui , Nicolin Chen , Michael Kelley References: <20240308152829.25754-1-will@kernel.org> <20240308152829.25754-7-will@kernel.org> From: Robin Murphy In-Reply-To: <20240308152829.25754-7-will@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 > 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;