Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2561965rbb; Wed, 28 Feb 2024 05:57:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWJa1b6Yqo1jRaPuzpLj9Yim2CSQ7arOJVyXDShVJLAe0N/pRslYVzk5xCVmFip4kfIaXBjIc8H2XoeznmtqAu/RE+1Ve9QYOsItpvmOw== X-Google-Smtp-Source: AGHT+IHQ+wgpqj8FvCUfxqmo4MHgSLjWHqqY54wLs3UzP1XhhMvE+b7c4UZEiGNm0Pnf8mYleIDC X-Received: by 2002:a05:6808:e8a:b0:3c1:4d83:30dd with SMTP id k10-20020a0568080e8a00b003c14d8330ddmr5671656oil.13.1709128667687; Wed, 28 Feb 2024 05:57:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709128667; cv=pass; d=google.com; s=arc-20160816; b=C2N9i6Wf6Iyq6blJU/wvVtwt8f71a3Yi0yJ5LkxGLzz3wA5DldGwpDSvqWvR/BuJIM E+Lt/rGz3JoBepoQHfUSJyPdzwKz9T0ursyJM2zcZo3A60/Ax47/am19iLsYLEB/3Zdg 5JamWQaVK/W2dzrsUk9p//hNgXNut2iGdn2502jQwMCRS+ZMrZKFpuN3zQuVusOFOQom NHeNeNgmBqGNDAZn/9YPOgNwJmeUAlLnxZsF739vgiL0fxlp5OHvfkp2NmnoYkTQ8U/d LM+05F316fUzojCSaczaIbfQxQ/eX+orFtcq+wI63p0Pz+uOKuWx1AwAx82bbhrr/2Za jy8A== 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 :date:subject:cc:to:from:dkim-signature; bh=OtYD9aRdpfMAuS8bpkhyLRlhrT8jp+UArwjUknxsdpM=; fh=E8F5/vp/nAcPVJWJwVt5RE8c2HME7kVqVeSMFxe8huE=; b=mftGSCy09gu3MCWKAN35S4Tlbf8lIHy5Ig6NOPceZFEmh9AcqvPQyfEPyj0YaI2yz3 qCLH0cLKNjRrQ7a42tgbJD6Duql0zRPjGd0/dnYyq+SroX7S2qPi89+UlMnTTKZKjbtl a46PgbgdL8gFMCJyUaBrRwsWNAdwg8CNFwxMAqI0+EzSWmfaGoIMiUmUjFvqgIRgXrO6 Zhr+57t3kfcgrVAOwdA+LG1T6R6xtplcFj4DD5akwMjt319ofh1GVdk6yHLFy7CXLAC7 m3lATn7BovZD7WMddZzp4jr5T0r4m+xFegxSvLU9Z99PBaA6TED7MclwEvlj6OwqvxNF +dwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J76irrat; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-85111-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85111-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e5-20020a656885000000b005d8c55d9669si7430035pgt.366.2024.02.28.05.57.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 05:57:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85111-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=@kernel.org header.s=k20201202 header.b=J76irrat; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-85111-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85111-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5F1FEB24DF1 for ; Wed, 28 Feb 2024 13:40:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9371155A4D; Wed, 28 Feb 2024 13:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J76irrat" 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 0D8511552FD; Wed, 28 Feb 2024 13:39:44 +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=1709127585; cv=none; b=fHzmmAtty6rHpm9ctxom1Au3pzkd4SMnNl1Ep1H9vv7awZwGdBtz53gapUCWkfNI/kipRE/2/3e3e4W1AC0TbzY+V5h93ykZ5VFolHPcHUpPLLkDN/xhkcjEApq3m+LBrpnnVh4zVoMYhm47GvFLrDZj3zXgt1JaYiaRy1hsLEQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709127585; c=relaxed/simple; bh=b49x/ykHm5o5bbMJSwQ3cpWnXqcs2XbmjOgH/NQ/iTs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=okOc/Aw272V09JZSPPg03wlrF1r7uHwmrx/N2RmclNCpG1hxlQ/fKknad1uZLir9n5Xbi+VW7KFq4pLD8UnejZQQ+6EHgSL0j/EWY5bu93KLJHKLt5Jr5Ljf7EhUVDXjKPLwrTTibV2h9kPmr04mpBgyCCMCA6dZgMKLdNWV/H8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J76irrat; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 663EEC433A6; Wed, 28 Feb 2024 13:39:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709127584; bh=b49x/ykHm5o5bbMJSwQ3cpWnXqcs2XbmjOgH/NQ/iTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J76irratocajmW2SDy9/e8xnA86MTWtA4xigYvKgjwwqiU7OWZwV0TtDgMu/4RZgv BahN412H0Btlb79CeteXuM7H93PJSljNMNet9W+MtP3SPJjIHIzf5btlJGjP7/WVkn kCuJWuHCsxgdFuNVQyhgTaf8QaWHG0itHhL6A3ybkgGYS87LNMkPsl83+DZ/aAgQO3 ZjqBrSwlEI81LLJso7aCifnSya/zOyFwyptMWg6/x5fpPNR+/+U7T4dKoE9+TjHbsg kD1v8wOLf/s8gVLxIEfJ121wRZA7/PsNtMntJs3kgE6lGEDGyunYDpBb6zIlgD6Nfr yHnCtsGlW9WFQ== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, Will Deacon , iommu@lists.linux.dev, Christoph Hellwig , Marek Szyprowski , Robin Murphy , Petr Tesarik , Dexuan Cui , Nicolin Chen , Michael Kelley Subject: [PATCH v5 3/6] swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() Date: Wed, 28 Feb 2024 13:39:27 +0000 Message-Id: <20240228133930.15400-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240228133930.15400-1-will@kernel.org> References: <20240228133930.15400-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(). Cc: Christoph Hellwig Cc: Marek Szyprowski Cc: Robin Murphy Cc: Dexuan Cui Fixes: e81e99bacc9f ("swiotlb: Support aligned swiotlb buffers") Reviewed-by: Petr Tesarik Tested-by: Nicolin Chen Reviewed-by: Michael Kelley 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 ab7fbb40bc55..c20324fba814 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1633,12 +1633,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; -- 2.44.0.rc1.240.g4c46232300-goog