Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2588964rdb; Mon, 5 Feb 2024 11:03:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6cBoKetJbttYVyNO9+NchAMAXYPIu/14/dWJ786piNt67Meq0+5g3c8CIYxlbY4CIOLfU X-Received: by 2002:a05:6a20:a11e:b0:19e:2d22:c3ec with SMTP id q30-20020a056a20a11e00b0019e2d22c3ecmr499706pzk.13.1707159789244; Mon, 05 Feb 2024 11:03:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707159789; cv=pass; d=google.com; s=arc-20160816; b=d3uQO6jklrUlsKzvGeczuxvblsfPoX6EiJBZrEwjGS2/KJEIBMr4Zp2b+K6DCZqiuy ez1FtJYMh9Yfth60g0lsIXIxStWSh/g7UcGlzd1FdzWoJmSfCX8HatolOnzCdSMXwmen sHs8uIw6mKSFtq5DUfN7bY1hUAUU3W1OumzPfd9BK0PKNNiuohwJp/5zv3PxAwpJaBN8 htJgYRUoiCkv5W7EPKWZjrpieBdC91UBzDg2Ng6LzHRbzVd3CvZFV+tugK0H2YtOIC7n A0dNUf+R579uwtKeXM3rRlVyKiA3yW0ev1l2EzdYpgARD5L6X//x6j2tJ5QpBtK8r2fL genA== 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=TYWd+25EZKHgv9DFcU1CxEQiMmgf4I9Lf1cAo66RCbk=; fh=A5DCM63Ard4kiCCGH5fClM4qeItUKEb4EsL2T6U8dc8=; b=sDZqeV45DMa20chvjgsaShd0+0QXsxHJlHbVB47ny/6KIDKPGvs+xpKdRfhNf8/eMT WwMX6tTDy7c9RZrDCNAcPwl5oBtVY7KzfrIdu3Cw6f1Nl01xp+44bkekpNi8Pp1C0lVj vZ0klqIK+RzaHkDfXyPZiWUW5FNvAZA6XGkwT6gR3NQ/a9BpKGiZc8MWJtdL9qTO+rwP 9u7Xdfj+8cGvtZhEBtEOnzRZSWbDhZKmUMiQqHdqTm2zckF3c6g91XomAKhsUxstty7S ApF6Uv7jSRJlN1NPAAk4LYrZoBhRnp55sL/Cv9Dxo2jrMuhRgAo+gWHrLh7CZV92FPeC zfHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lmoQR25l; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-53276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53276-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX4G7VVsKVqmXWJZ27jMsG6AFvDxP2h1lf2tDAH+Fh2CPYIqCg5DcI48D0j4RTTg/VZkNF1qkkf2MVa4yOHJId2XvO339AVb3u2RSkpbg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bx19-20020a056a00429300b006e03390378fsi208170pfb.297.2024.02.05.11.03.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 11:03:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lmoQR25l; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-53276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53276-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 E0D3828B62C for ; Mon, 5 Feb 2024 19:03:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 965B44D9EB; Mon, 5 Feb 2024 19:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lmoQR25l" 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 BFE5B4D5A2; Mon, 5 Feb 2024 19:01:43 +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=1707159703; cv=none; b=TEStmv/W4HEh2xs4ZnHa0gMW9L6OKfT5dd/ZnZrdYylJca7xzWOugSZFR1MzqAbnkTqyYOGJ9E9jhPdnrI/X9Wx8jActuSQ2WMcASEbf9Jp82yoz/FOn4CinjUhVinFdQj6fDaF+NAf1DQmDhhp88/PAZIDesDPc49zS/53SdWY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159703; c=relaxed/simple; bh=hQZUe3sC6qvAlN4FEOPtkqPiMEdJZuABY+olfP99JFc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=onhezXw0PNdLALIc2dmdLq9lhso9r6kdxNd6q45rbosFwGI5wClEpu6DyIYCXyLYeHlNgIEALwSMeglPE1Lpp+DZSzj/6BUvHlO70B0CHDp2BIEt5eqZVNHmSaYNde6pyt+JTG6CTTcmjGA53lKajO3xserM8g9Q2ztUSz4mrA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lmoQR25l; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FB3AC433F1; Mon, 5 Feb 2024 19:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707159703; bh=hQZUe3sC6qvAlN4FEOPtkqPiMEdJZuABY+olfP99JFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lmoQR25ludhgwq7pg6I1EhIk/p8uQEqt8nLNz7TzzLBOX2wlnQlMhVmrCVOaVrDmI oGP61dg+FoZ3JflOYRYPQgaDLxt6gMLeGUImiWBiwoQi3A+DFrUxQWBbvpgteIh7Nf RoNzLKYE075wvJp57XGu+9niQCouMmcWRsD/PyMTjOekbdS4ajwjOj4Y8yNQFANaT6 caBhmNO0eWy25b0h8FlrrDvpIze5J1cKCt2I8dfPMPV0j0PkszJ/02+LMdXZgYQQWn BUra+IidX2GQ5qUJH3X0XnOHipUoBWgrjTEas1zkICOsnv7QJwUUWmJ53edEGpT7qN FI3PM05JbV7fA== 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 Subject: [PATCH v3 3/3] swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() Date: Mon, 5 Feb 2024 19:01:27 +0000 Message-Id: <20240205190127.20685-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240205190127.20685-1-will@kernel.org> References: <20240205190127.20685-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: Petr Tesarik Cc: Dexuan Cui Fixes: e81e99bacc9f ("swiotlb: Support aligned swiotlb buffers") 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 adbb3143238b..283eea33dd22 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.43.0.594.gd9cf4e227d-goog