Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1305664lqp; Fri, 22 Mar 2024 10:52:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHjWH7Utce8n/wzNPLk+zgIj3/eX2vPj3rrC9xJOODwRCe5ZGSPxCtjQi8SbA9NJlJQIBmvnV0VvE+ttjm5urK0FsUtaSqGlJ4LuQ8hA== X-Google-Smtp-Source: AGHT+IHbzpRL8ahM65BAjPl42Bho7FsktnClvXQnTYJuVKGkSVe4zoEumv25C6jWp03SILKfU5Rn X-Received: by 2002:a05:6870:9886:b0:220:873d:dbcc with SMTP id eg6-20020a056870988600b00220873ddbccmr364648oab.49.1711129926632; Fri, 22 Mar 2024 10:52:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711129926; cv=pass; d=google.com; s=arc-20160816; b=BcfkAvRCm37ReBhdl6zYL/XFDHgNT+s5x6DL5tbWBq6rXu3N+jhMmfJQaX6d5G1PP4 cpwdFb0oqrWiTVrg/wFNDEgI+2oVy5YtqQABFf4QeR8Gt9a6XmU2z1wfLslS+nrcZNoY +3f/FJycUgw20FsCM3QYhbiVedyj12Qo7RZHTCQ7rGxyCwmuLdNOiFfHFj6Irz1BtRUx s9d9f3Ui2gaPgE+Cq5C/16yUl8ZiLyp3/P9vsPc83EDps12igMgoZYnOnKitcpTOVyYF cSuHBLNFydS6ySu01KOXE+jPCDAR34UdlngKcToOaunixaV0SAiMuHomV1EWRB/ZLcAW JEBQ== 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=sCQm32WrW4hxeQOlo4+CbAT/ApEBh72zUZUhSQ2FlmU=; fh=QHy/abdxAvqUcdaSLXzWcfQH/hJ3sh+RPymszvFiAA8=; b=1D+wrESdG2OpY+ycdTmbl4wC7yIFwpW4/m7gFeNwDA2PR7+7Z8J6fY9wbaxNGfgkpf CRJ7xQk+zaP+wGcLLfglRt6emkIOOETPPPZ5OuyW9GmH6lD+3crDj+kZGkRhLGMe3ETQ 6XJVIZLBeXX8qUP/QQpbueSe4WljdZrogvm7hKb/JlPVVot8vvOZ9X6iEy0aD5XDYGE9 9gw2eGB7Kdv8xpnrMj9JNcKGynNUEChkANwdoyiFhBHT+q9zTTbj3VJ+POChfjWsujZ5 69LX0KimDIT5hhUv0gjnsiMuT7Em87f5WL5YR3I00sUO8D4eAkexH/BD4pjPGGrthDzn PnuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b="CIWEdOc/"; 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-111884-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111884-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q9-20020a63e209000000b005ced65a49e8si2488524pgh.734.2024.03.22.10.52.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 10:52:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111884-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b="CIWEdOc/"; 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-111884-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111884-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0220DB21E4C for ; Fri, 22 Mar 2024 17:51:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B61C4605D1; Fri, 22 Mar 2024 17:51:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="CIWEdOc/" 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 5E280605C8 for ; Fri, 22 Mar 2024 17:51:42 +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=1711129903; cv=none; b=AmgkzNom9zfVYYEkN1+oNULhfkMnUpwLe1chaIe+wKi8klJObA/dGUM8z1evxGDOCmJJQyfyt8w7GzmFpnKjaOpTBNVHi6Ws/Lfilu5oo0pA+3vf/TkjryZ2ErTBCLAFmKYIv+Yg9pG0VKfbFqATTRH+o/tpSL0dwgU9Gph4CXg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711129903; c=relaxed/simple; bh=Xy6fuGyBECIuY3ohH/7MY26gAGWyuhCMWaGAqdMGGpI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CaJYPLASWC3wGfPJ8Br8jAywupZNS9ha+X5br33TSWXEp4xL8ZueXWMEnC14J+77mLicgyuYu6mgZrRye9t2rSWShI628pLuiHBEK3dfDSNXWsMQqBpX28PfC6Gt7AgsLuc18hFax8ewPP7J2AsLVnMfH22UnMyO/bo7cdzwcg4= 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=CIWEdOc/; 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-b985-910f-39e1-703f.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:b985:910f:39e1:703f]) (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 C1B5F1AB84A; Fri, 22 Mar 2024 18:51:39 +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=1711129900; bh=sCQm32WrW4hxeQOlo4+CbAT/ApEBh72zUZUhSQ2FlmU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CIWEdOc/zZZOq3Ugq1EiC64RPQBV1sLQ2pjEBrhs3AXf9pxLWNPAPFapLHzEiRjpN PPb1mJLNvqMLoPONcnTd2HhDQYQH8QdMXabERrfl4fTn51uy7THsY+Z14WkuZfWXKM Vl+vBWlDxL2V4dDrypYmn0cz+a4lEpF+8RiZ4SEW4WU5RiRSoxnHsyW5GS5LdjUWo/ fiNEQeSRvP0cUGmu/dJUxftJz9le+ZR6mrOI0I+v4/D6HjsHDAANceeEbuNtcpA8Si wMQmrT5zH0hBbUbkAeYTivIOM3bGCQA6Ecq8x9xnYr4RXnhr9zWngSAt7+qVRUtFna 8omHoOUpjRsqw== Date: Fri, 22 Mar 2024 18:51:38 +0100 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Will Deacon Cc: Christoph Hellwig , Marek Szyprowski , Robin Murphy , Petr Tesarik , Michael Kelley , open list , "open list:DMA MAPPING HELPERS" , Roberto Sassu Subject: Re: [PATCH v3 0/2] swiotlb: allocate padding slots if necessary Message-ID: <20240322185138.1af83c61@meshulam.tesarici.cz> In-Reply-To: <20240322150941.GA5634@willie-the-truck> References: <20240321171902.85-1-petrtesarik@huaweicloud.com> <20240322150941.GA5634@willie-the-truck> 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, 22 Mar 2024 15:09:41 +0000 Will Deacon wrote: > Hi Petr, > > On Thu, Mar 21, 2024 at 06:19:00PM +0100, Petr Tesarik wrote: > > From: Petr Tesarik > > > > If the allocation alignment is bigger than IO_TLB_SIZE and min_align_mask > > covers some bits in the original address between IO_TLB_SIZE and > > alloc_align_mask, preserve these bits by allocating additional padding > > slots before the actual swiotlb buffer. > > Thanks for fixing this! I was out at a conference last week, so I didn't > get very far with it myself, but I ended up in a pickle trying to avoid > extending 'struct io_tlb_slot'. Your solution is much better than the > crazy avenue I started going down... > > With your changes, can we now simplify swiotlb_align_offset() to ignore > dma_get_min_align_mask() altogether and just: > > return addr & (IO_TLB_SIZE - 1); I have also thought about this but I don't think it's right. If we removed dma_get_min_align_mask() from swiotlb_align_offset(), we would always ask to preserve the lowest IO_TLB_SHIFT bits. This may cause less efficient use of the SWIOTLB. For example, if a device does not specify any min_align_mask, it is presumably happy with any buffer alignment, so SWIOTLB may allocate at the beginning of a slot, like here: orig_addr | ++|++ | tlb_addr |++++ | | Without dma_get_min_align_mask() in swiotlb_align_offset(), it would have to allocate two mostly-empty slots: tlb_addr | ++|++ | where: | mark a multiple of IO_TLB_SIZE (in physical address space) + used memory free memory Petr T