Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1966405lqg; Mon, 4 Mar 2024 08:53:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXOGbUuYjGwZTmqnziZEpb6pbZhzM0ck9SRevoztN1Ny1bfxxSDXc6UHtKR3yYF00odjDPh3x0i0rythCSD8JLhRHm9C16wxAfbeKeeLQ== X-Google-Smtp-Source: AGHT+IGUpF1586pjddFl8FoIOXwEt7uFCRdR+HHvSq3oZZTz7iuCfmdKHDqcEd3b2SIZunaDDr+j X-Received: by 2002:a19:f710:0:b0:512:e1e3:792f with SMTP id z16-20020a19f710000000b00512e1e3792fmr6199347lfe.3.1709571239274; Mon, 04 Mar 2024 08:53:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709571239; cv=pass; d=google.com; s=arc-20160816; b=nI55hNcTt/muy/f7ckPyNliF+OMx5hSUpT66hLowe+tTjb1EU/ZJ8+3NMT9WZLu3a7 5XXEcr9b/wXDdng9ORiMh5doyIVPOQ9T0ArSPqB7DcU4dxclikCfL5W9uGC7QBC1CLe3 CLuXnW6p2fGFrHLdvdfAyv2aMWfUmyJjCYj9ux2IdSfD/Pps72HK0/cvZo3QTakYCWJS GqpsnO86i9Bsfex3n9AZCZL5FsB37j2+GZOdlJR5VBSufnFVL5d4d6Fff8EzrJWw0YSA eCS6dzNuEmUqbz2LrJBm+LAirZ73c0t/HqeXXyzJi8ORuSqEFrQSSBQunhbIwrl6DJcI HQJw== 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=mlsu/8X2+K7LcuLRF4uaZ7eALwQ6CaB/x9gRIRN1vIQ=; fh=jA+hJORgzQndNYctznQ94vkHpB1J7dPb82mPqB3eZAA=; b=QSH11FbwfBscb6DmQSRijjyPjj1nGojKTh4BOEQomNC6HW43XyEpvd/KE46HB4F0Jz z9vjNrDUfY+LsVNjlN+XzBMcltUj5SlJsqdt92R7hxTfny+qs/cxmN1oLhQVNrvsSvb1 hyDvW8O7+WFxm/FlS2N4aD9V5onYwiXBfalkoDhNZW9PEY2jkyknFzbZBhu75YDayP6o l1niMU1Ce0m9KNe2WU/dzQNU2Nl0XNVvAyRZVrBK8MsrvCxLzgw2YoBDmBgVgMG3iV6t drHHC3/6T1zLFyA3xhnzOywmKiMit/xwyESPf60A7Wbxa4rss1UJxWEfFMD2w3WzmFSr T1Qg==; 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-90965-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90965-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ec14-20020a170906b6ce00b00a455711ad06si831864ejb.170.2024.03.04.08.53.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 08:53:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90965-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-90965-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90965-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 am.mirrors.kernel.org (Postfix) with ESMTPS id EA8441F210D9 for ; Mon, 4 Mar 2024 16:53:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 860375D47F; Mon, 4 Mar 2024 16:53:40 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61453A20 for ; Mon, 4 Mar 2024 16:53:37 +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=1709571219; cv=none; b=Ndvaqk8aEHr/v3/dEURtBLf3oo9CCWqoOdp9yjjyBbmVpPRPvEB43BgqOshjWvJhNH3zTx0WQP0AUNJD5H1dQZ7ZGGua3t33Wau8gxTyRGYsRHXC0dyAeu7nbTnQy0xyNryUkiAalKkQUab0ReFmzo+cInCj8O/dAO1PNnAh3e0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709571219; c=relaxed/simple; bh=odLag6z4EVrHLDoxIhELyF6yH/BXlNlYTSx9r0KRJf8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TMfO6F4yJ4ErX5yd6QQtR1iHV8tZra4JsEvnEHo2MpURgOuuw20IPbRp0MctFddDBYyFrLTlXvJLuMoThrIFVzjZYjWCFB3jw00ddj/D0Wb9xilcx1SnBcm8CUoQh1HGdCkct0xllkjTiKUfGAgReeysFZncCD7rFeqVGw7b4Ak= 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 260FA1FB; Mon, 4 Mar 2024 08:54:13 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A3FB73F73F; Mon, 4 Mar 2024 08:53:34 -0800 (PST) Message-ID: Date: Mon, 4 Mar 2024 16:53:32 +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 v5 6/6] swiotlb: Remove pointless stride adjustment for allocations >= PAGE_SIZE Content-Language: en-GB To: Michael Kelley , Will Deacon , =?UTF-8?B?UGV0ciBUZXNhxZnDrWs=?= Cc: Christoph Hellwig , "linux-kernel@vger.kernel.org" , Petr Tesarik , "kernel-team@android.com" , "iommu@lists.linux.dev" , Marek Szyprowski , Dexuan Cui , Nicolin Chen References: <20240229154756.GA10137@lst.de> <20240301163927.18358ee2@meshulam.tesarici.cz> <20240301180853.5ac20b27@meshulam.tesarici.cz> <8869c8b2-29c3-41e4-8f8a-5bcf9c0d22bb@arm.com> <20240301194212.3c64c9b2@meshulam.tesarici.cz> <20240304120055.56035c21@meshulam.tesarici.cz> <20240304165506.49e3b2d3@meshulam.tesarici.cz> <20240304160210.GB21077@willie-the-truck> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 04/03/2024 4:10 pm, Michael Kelley wrote: > From: Will Deacon Sent: Monday, March 4, 2024 8:02 AM >> >> Hi folks, >> >> On Mon, Mar 04, 2024 at 04:55:06PM +0100, Petr Tesařík wrote: >>> On Mon, 4 Mar 2024 13:37:56 +0000 >>> Robin Murphy wrote: >>>> On 04/03/2024 11:00 am, Petr Tesařík wrote: >>>> [...] >>>>>> Here's my take on tying all the threads together. There are >>>>>> four alignment combinations: >>>>>> >>>>>> 1. alloc_align_mask: zero; min_align_mask: zero >> >> Based on this ^^^ ... >> >>>>>> xen_swiotlb_map_page() and dma_direct_map_page() are #1 or #2 >>>>>> via swiotlb_map() and swiotlb_tbl_map_single() >>>>>> >>>>>> iommu_dma_map_page() is #3 and #4 via swiotlb_tbl_map_single() >>>>>> >>>>>> swiotlb_alloc() is #3, directly to swiotlb_find_slots() >>>>>> >>>>>> For #1, the returned physical address has no constraints if >>>>>> the requested size is less than a page. For page size or >>>>>> greater, the discussed historical requirement for page >>>>>> alignment applies. >> >> ... and this ^^^ ... >> >> >>> I believe this patch series is now good as is, except the commit >>> message should make it clear that alloc_align_mask and min_align_mask >>> can both be zero, but that simply means no alignment constraints. >> >> ... my (possibly incorrect!) reading of the thread so far is that we >> should preserve page-aligned allocation in this case if the allocation >> size is >= PAGE_SIZE. >> >> Something like the diff below, to replace this final patch? >> >> Will >> >> --->8 >> >> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c >> index c381a7ed718f..67eac05728c0 100644 >> --- a/kernel/dma/swiotlb.c >> +++ b/kernel/dma/swiotlb.c >> @@ -992,6 +992,14 @@ static int swiotlb_search_pool_area(struct device >> *dev, struct io_tlb_pool *pool >> BUG_ON(!nslots); >> BUG_ON(area_index >= pool->nareas); >> >> + /* >> + * Historically, allocations >= PAGE_SIZE were guaranteed to be >> + * page-aligned in the absence of any other alignment requirements. >> + * Since drivers may be relying on this, preserve the old behaviour. >> + */ >> + if (!alloc_align_mask && !iotlb_align_mask && alloc_size >= PAGE_SIZE) >> + alloc_align_mask = PAGE_SIZE - 1; >> + > > Yes, I think that should do it. In principle it might be more logical to fudge this into iotlb_align_mask rather than alloc_align_mask - since that's really the effective behaviour to preserve for streaming mappings - and then pass an explicit alloc_align_mask from swiotlb_alloc() to honour the dma-coherent requirements. However I also wouldn't really object to not going that far and instead just making the comment a bit clearer that this is still serving both purposes. Cheers, Robin. > > Michael > >> /* >> * Ensure that the allocation is at least slot-aligned and update >> * 'iotlb_align_mask' to ignore bits that will be preserved when >> @@ -1006,13 +1014,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; >