Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1752482rdb; Wed, 31 Jan 2024 08:05:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjgV3tzJMnOhr36f3PisX8FQVbzJUTzRT2t44yjO/i3ZzX0V5DA5cCQJExT1+cPIm5Fu0k X-Received: by 2002:a05:6602:2352:b0:7c0:25e3:343d with SMTP id r18-20020a056602235200b007c025e3343dmr1381729iot.0.1706717103936; Wed, 31 Jan 2024 08:05:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706717103; cv=pass; d=google.com; s=arc-20160816; b=cMUAub41tSYniAJZacPz6Md6bS6n5Zy1kcsn7abEuOjR+BN6tFIOMk6pRFfx4UTl4D VUF2WJqqAjvivj+BFanXopJt7nSh/wlLdMGEAP/1e+J2V9Q4QPZQ1IeJAjLjJCKH1dGo mRAYERCwVn/uImvetnuhnIS2U1rt5BU0JXZ4gFcOuciBG1FC5enV54tfu3AZXKRqnqEq GjfEbw+xqt177iAAnPSzloDAQ//SKJyrXT7Dwyfs5l1IxTNZ6Dn+yCyrKCyQtbK2cXBA 41n3kvlg4zBySB0Far26uqTGuEJpEy/ubEYalR6uOEK+g7vtWPTKipv5RV2TTXPoC3tb ++Ug== 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=VpX5PeRUpFqb+r3AZaDYCn5huv8zRvoejzFvSRyvQZ4=; fh=10ci2LqfSETa+e+ZG1P7QgAUjJoUG2Tm4RjyM8nNky4=; b=nTefykNsKDzQx8bi/8Du0Cqupxz5YHMAMdvLDNeBxaaGN5trNGdskLfDlKBP9IMaTJ Uylb1mFkLiuq1WUkiVKO50LTUwJKgey/HK/tcl0CV9HwP2ODra3pnSOPvGnWg3p8Q4Ul 03HsKxEx2ZST5rhFSEMYGfdZ1KNc87GKwTuRg4UMOt9ZZG8x82ZPo6QeTALabJI1Yruc T3JILmSpD8pfPY8ndI1G4HCHZigdXgEKY+jn1EvIrAWoRgSwgnHbUCmZgkgyR7KU6qMH aOSpLi1cVaPLumTp+HD4usmybhECMrJZHa7hHfbiD5D+wSjXitbCGsDT1jJlou8ywwux Qpsg==; 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-46755-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46755-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCUrZbP9xxrmcNKDHw7lbUnd+bz7IRrqU7MNQxBHXqn2eu7//O89kZxLI9/DKyeAvlxHRIjza1nPjdhKOjbmMgb42s7uTXeSY2EVEOlLRA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t23-20020a02ab97000000b00470b59cde06si2958551jan.32.2024.01.31.08.05.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 08:05:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46755-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-46755-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46755-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4228F28EAF5 for ; Wed, 31 Jan 2024 16:03:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0150312AAD1; Wed, 31 Jan 2024 16:03:43 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B29C9129A9B for ; Wed, 31 Jan 2024 16:03:40 +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=1706717022; cv=none; b=OWSQIioVjjdkivA5MlxnYUltSmbi07iJA8XeaANNFIJZbBr9RgdSYKActGINaGQqrWIAisoWcs3mAw2EwwdbShvt037d9LWWR/DufQqTeNh02yaX049Cjkqfr4mIroF6MaUk0QxT6ghTkmUmoNBGx+oDBQ9s6wZ5mQ/c44AiI04= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706717022; c=relaxed/simple; bh=6hiDNbhb/+VDQF3BwWp275eYEH+NUPFv+MUhFzE56uY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GP2NKvR5cG2K1ah0mAf61TXV+7SVrVG86cczSIyedFaSGZvkk35R5luwxRwT/Pe7gc8bnrebx3fO4/vLQ0A0ILTBCzBmp2YYRECiEvkI2xL62ci6OP9U5QJQ/gxt7W5UTaJYsGORgd3Xb6rPhCM+CK95prnRczbkfeZR6RnFR7A= 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 7E52ADA7; Wed, 31 Jan 2024 08:04:23 -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 3CB803F762; Wed, 31 Jan 2024 08:03:39 -0800 (PST) Message-ID: <82f03af0-6505-4c1a-8002-272fa5a7a7d5@arm.com> Date: Wed, 31 Jan 2024 16:03:38 +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 v2 3/3] swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() 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 References: <20240131122543.14791-1-will@kernel.org> <20240131122543.14791-4-will@kernel.org> From: Robin Murphy In-Reply-To: <20240131122543.14791-4-will@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 31/01/2024 12:25 pm, Will Deacon wrote: > core-api/dma-api-howto.rst states the following properties of > dma_alloc_coherent(): > > | The CPU virtual address and the DMA address are both guaranteed to > | be aligned to the smallest PAGE_SIZE order which is greater than or > | equal to the requested size. > > However, swiotlb_alloc() passes zero for the 'alloc_align_mask' > parameter of swiotlb_find_slots() and so this property is not upheld. > Instead, allocations larger than a page are aligned to PAGE_SIZE, > > Calculate the mask corresponding to the page order suitable for holding > the allocation and pass that to swiotlb_find_slots(). I guess this goes back to at least e81e99bacc9f ("swiotlb: Support aligned swiotlb buffers") when the explicit argument was added - not sure what we do about 5.15 LTS though (unless the answer is to not care...) As before, though, how much of patch #1 is needed if this comes first? Cheers, Robin. > Cc: Christoph Hellwig > Cc: Marek Szyprowski > Cc: Robin Murphy > Cc: Petr Tesarik > Cc: Dexuan Cui > Signed-off-by: Will Deacon > --- > kernel/dma/swiotlb.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index 4485f216e620..8ec37006ac70 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -1632,12 +1632,14 @@ struct page *swiotlb_alloc(struct device *dev, size_t size) > struct io_tlb_mem *mem = dev->dma_io_tlb_mem; > struct io_tlb_pool *pool; > phys_addr_t tlb_addr; > + unsigned int align; > int index; > > if (!mem) > return NULL; > > - index = swiotlb_find_slots(dev, 0, size, 0, &pool); > + align = (1 << (get_order(size) + PAGE_SHIFT)) - 1; > + index = swiotlb_find_slots(dev, 0, size, align, &pool); > if (index == -1) > return NULL; >