Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2302861rdb; Wed, 21 Feb 2024 03:36:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVIKE+S7OyCxuN0e+UlM2VBXRb7nN0qvlR2Kax4Xjtr3wJYEgCIpsCdsPd2a321ckEM6WQQzksMcBRrPtJIq6zHzazCvIRnXmOj8aEG3Q== X-Google-Smtp-Source: AGHT+IG1WFTH4pa6KNovIBRWZxJjkBm+nZjQDbpgaW2CsddKz2Mq9B/4wDq6/Kz/L+1MWIBYv7Qo X-Received: by 2002:a17:902:d48e:b0:1dc:1e7c:6dd4 with SMTP id c14-20020a170902d48e00b001dc1e7c6dd4mr4707339plg.68.1708515374356; Wed, 21 Feb 2024 03:36:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708515374; cv=pass; d=google.com; s=arc-20160816; b=sMzOmUxvV/SiZI8xgdFwsV8Qa4JSNY7ZwiwS6VAL3c8JfEqmFW3J86lF+zOVfKbyTz amz9PbxSmwomZNmHmho/A9KK0tkBlxYzTMMRZWHhyyqLXn/aazMyJi61uvD6E6FweFqM rwkJyYe0EMGm3WiCTjR/wifo4sMevKCSjFSKSaazD+qnlodQj7GCvLpIDCx98M4CHcej V76qg+RxiKlXUOaRej6TtaVc4qSUmbooGRMAOko5q2s2sLmRhKrXRGdZtThXljojTPpv RswqndV4ckyMlbqSS6xUZclGD5x92lI4j/mQNSo8AZDG7lliWGMJvky4n1WvouX22sLR boNw== 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=13G9jCBf1nNYY61kmJ7iMGv8ivyePYOA+02U7DfYeEg=; fh=E8F5/vp/nAcPVJWJwVt5RE8c2HME7kVqVeSMFxe8huE=; b=X241oFWeo9/nKZ+hVCRGfggaAYaOeGVoEkDVNZwTIkJ0+rZPycfiag6Vzc9tcrcScO Am2EXfBvxJABt+OEaRTyxe5PvweXCDmIRAD4tgCzUEgksfZUB9I5wArOQfdZm2f7HXQf /MZZAPCg3+ppymQ6Z1ObVYM8njeS5g/f20CHp0Mk7loA4EkTf9edMrlwIX0PlTmZwxfb cKs0aXAiszHz2be06VenMGKERHViZsJgcJE5RKaQ9sKJScChd1433wQQITPvEhjU5xAb 5elikCrCvEZXkL7adzJ+or4pyKhtn6Y/XPtU83aMqYHBGJidRrumQIiI03R0xv78y4RH 0VrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t0sBwdZ4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-74627-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74627-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 y9-20020a17090264c900b001db719a8428si7715456pli.554.2024.02.21.03.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 03:36:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74627-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=t0sBwdZ4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-74627-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74627-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 2B590B231B5 for ; Wed, 21 Feb 2024 11:35:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1A854176B; Wed, 21 Feb 2024 11:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t0sBwdZ4" 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 25E5546436; Wed, 21 Feb 2024 11:35:19 +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=1708515320; cv=none; b=gzpaFFJsbA0iJQnL2sK8AnVaFDDl7SpoXwjEB3j8eZprJJB2Lv2g0rS1A0Y3JahHerdeDZAKn3WKCPQugCXNFkvkTYUsPpFbDnPiXd8qiss+onToZA17xSjZGUJNvNzdt862W0Xmmk9PvQqO4IOsUGMzcH8g1iusoYA9G99D9Yk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515320; c=relaxed/simple; bh=VIfdB40mPKeGpRjLdseuZPhrPH2I9FgxnF4NhRToiQg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gOrboZjzz0gg7EWqZhKzb/6LGZyuxzhNS4xyuJM31bMC89Wg1LglmzN6hQvU96Ki+Mj+1HWbHXbWttqI6g0JzME8drTsRrh4ZvljrC2c0Hr3it4zkeFx9Y4I85/DVorOWfFydfcw8UNfx9HRKF+0y1OCJIRcx0IIBz+udw+vqFI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t0sBwdZ4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5F70C43390; Wed, 21 Feb 2024 11:35:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708515319; bh=VIfdB40mPKeGpRjLdseuZPhrPH2I9FgxnF4NhRToiQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t0sBwdZ43tBOm8bQ6pbQMpxjNYBZGxcdwUAVZR9mCB1h2pGI/Zarvg+PUGCEocdC8 5Me8Id80ygsdrJQqtOloQh9dbvaMLdvaWzsNgs9InPJQGSB+QJKslKsm2eVvRcvWIn TdAERFKSxNAWbd7MnHnhdHNXNIlW3uFh08nXz6peJ2UyJRYOs9WGYNM88NcuCcETbD KPOzgm4u8M0SdtFm9PiD/BHFlTv5ZjyxDV6FCnNs4YKub1cTJjj4RYD/GEbzuUnvB0 UnRpBQBtVgi4cve1lBQFy6AjtTQU1V5nHYu3IdrWhru/iIoUCA202dCBQjeA0cTUKA B9L5v0vySUmEw== 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 v4 3/5] swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() Date: Wed, 21 Feb 2024 11:35:02 +0000 Message-Id: <20240221113504.7161-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240221113504.7161-1-will@kernel.org> References: <20240221113504.7161-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 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.rc0.258.g7320e95886-goog