Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp817771rba; Wed, 27 Mar 2024 12:42:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfuGTnv4bZXZ1jAR1SThhvO4WGc8EwWF70e9G6NlB7evfp9I09ExCq1/vp5tyx8CfykDc4Cb7PhpBdTNHcbpeVEi+5hdNWxP+goLRhAg== X-Google-Smtp-Source: AGHT+IEDZMn6qUdXSE/ZnlHmSuyFxBmPhICgQiSdcu+lWsyDR1UMtRFVqSZqgk/FZV8BsB40OOHV X-Received: by 2002:a05:6358:b001:b0:17f:1c95:7b94 with SMTP id l1-20020a056358b00100b0017f1c957b94mr455174rwn.12.1711568533326; Wed, 27 Mar 2024 12:42:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711568533; cv=pass; d=google.com; s=arc-20160816; b=fz/XnYzK4XBLn0mpdMNdbXyg1/HbyYAAFtN3IYxM4/a51d063clm9AYkZxBGU4hc3s R2OZVra2iBAC763wA8bcGKBrWZNP3wNvriYdeq4FuFfUlaoe3IwHNl7yUWQOccylN84S jv+c1J/g2A9NIra1PB0vyU1CoN+PMW4joFBHTkkJzzxC8ehdq4tmLjD3B7nT1eu5jSEp DSAyfV1qVupWzADH8yrbeZRNGf2iTbp7GnUSKcRgOmR2YLnTTcLXZBXcfY7Zmr5ZaPhc LUJQcc5pag6rjS3mdybugMBqLQUy5dTAfBcOZ2k/fygkcjjlu2Lfj30VHStkJ6tKZThh JJ7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:cc:to:from:date :dkim-signature; bh=CcYqvG9O/908J8vMmdr5z1QpL1fTOEZsvjzD8j4cvpc=; fh=Qaj7WXG/E4n1Fa++kijA16X4m7zzcWsoLp7VZudMo40=; b=rLUW5vVsrv7XFrBRCYtRMIuhWdt+iedxpTqUbJSPLXg5skzi2qifkMC+bLvGGgwaRX 615AqKOkH/yBmFU/cetskn+S8JrsdLzXrlDBFRgFaic875Ej4//AxgvuiAMuTxsDMpjO sOFgQ/kRvfk4d0s9B4S1o9YgsOb8BlR2F9VW/zjeKSx2yhuiWjri5T8YlgE7OPNluumz g1O6fYScG0aDHE0cuHJYOrLgFARNG02R3nyRWP+N8CwoHHydrGSCRXtrzgXU+MaJldBh fu0F6ZZJZeRF0FmPCVLT/z7zrl6UXngVqygA5JGp2kRiJTVKndEgYM4neKjKLaySP2zr fzuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="b748I/Rb"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-121919-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t16-20020a639550000000b005d72fd9d73asi12604785pgn.602.2024.03.27.12.42.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 12:42:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121919-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="b748I/Rb"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-121919-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ECCC929FE40 for ; Wed, 27 Mar 2024 19:42:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0D9714C5AF; Wed, 27 Mar 2024 19:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b748I/Rb" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D966A14F9DD; Wed, 27 Mar 2024 19:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711568526; cv=none; b=QFbR9X37yBnbNXYhb4D1VxyDKqTF3a7dmCzhp8VEz/JKWOW5uIIMm7Z1rXKU0wcK2dYRFWtrCJjZyqs1l0aS1fAlv042GiN0AQIKt65rkD3/82M0pwy67Vhh+TbgJY8058zmob9d5zjiBBOHHnndquU8YlAf5IGyqYWIWToJL1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711568526; c=relaxed/simple; bh=PsoqOSc/ZsnGjVOPPElixDYOJ7dkP9VdeqNpiyZI00A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Aqwab01CMfDtWbjsrk2IcfQC+xEsasfQygGu/gfABESlXReBQh80jtQIrHaR7JdiP/HQDGBasNj7RSw1kkR4GjZzC/BeT8DKowjsHF574yNh7MRPWYdEKnDF7qK829x56u9pq9Sv0ajAWal+uvtwrrFb/gU0VLPzTVQQ4ety7/w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b748I/Rb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4F6BC433C7; Wed, 27 Mar 2024 19:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711568526; bh=PsoqOSc/ZsnGjVOPPElixDYOJ7dkP9VdeqNpiyZI00A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=b748I/RbWhZJV3AxMeOrTcHuMLbzL1ocVl7qHn/xvp9P/MwKhxWQeq5FuIcBP5JHn DcpEe64QIsTLiAoIE1xxp5ZybwxHIgAKXRHRJ/V0CTwVE7TO6f3gIrZy9wULp1SpBd 7ukVgrHzkzmLeju6LdhgAZH9XVYgkf86tShw0luVvX/WeNsFVsR5m3uhSaZzjl1lAA GXDN491AnrTvWyuuvN1z7X72VSe9iMDZpc3kCjKIv/eaKn/U3pXkxtM6t8Eu8Kfxs/ GGLiRyz1f/DvsuzoxdOmSy0IhmuBFbYpmz5Ub6Vljnq/WVErAl5UT6stRjWpsBPsVD B7UKb7ga6Cj8Q== Date: Wed, 27 Mar 2024 19:42:01 +0000 From: Will Deacon To: Petr =?utf-8?B?VGVzYcWZw61r?= 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: <20240327194200.GA12000@willie-the-truck> References: <20240321171902.85-1-petrtesarik@huaweicloud.com> <20240322150941.GA5634@willie-the-truck> <20240322185138.1af83c61@meshulam.tesarici.cz> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240322185138.1af83c61@meshulam.tesarici.cz> User-Agent: Mutt/1.10.1 (2018-07-13) On Fri, Mar 22, 2024 at 06:51:38PM +0100, Petr Tesařík wrote: > 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 Thanks for the patient explanation. I'd got so caught up with the DMA alignment mask that I forgot the usual case where it's not specified at all! Will