Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1639745rdb; Wed, 31 Jan 2024 05:03:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXj59sfHgd8mK4/I9kVo1XkXrLAmNAW2y6xTPglKh9KIM0mfsb6Cb+FkiMkATDN0wQgMC4 X-Received: by 2002:a05:6358:15c9:b0:177:2e7:cd54 with SMTP id t9-20020a05635815c900b0017702e7cd54mr1278388rwh.32.1706706224841; Wed, 31 Jan 2024 05:03:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706706224; cv=pass; d=google.com; s=arc-20160816; b=KpL0kUWcnUQlDrdJ7hiJ9E7uxq2ADFpFVzKoOJQcYQ1ZCp0ZUKglFYEx5xvmySHr7q TdZz2rQdrzh6+FFj1G0yQUhFcQ5XvDkUyonThfWk41Hj+whcVo5krUfxFNTxqj5VP4sb hE5I43MA8SGuQ9/cvT85LswlUAGGITcSOdI041UgcEaNbEqKikNSUB2r6p652C2iErit fea4np1nVWsbDQJmWqg4YeTX2zlRbOEDmw2IEQ/qpR64dC6LSWtCH4nurkzcph1PN7mJ 9Ic4ErcF0zdWtRsRhKUIlIbonxM8hXN+7bxfF6ckBD7PIQ8WR/JAx4ef5JYmE6epeN6U NNOg== 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=vN0PppCRl3fPf1FUdVod8fxZZ++AN2Z20bzt44AeK/A=; fh=2LE43JrSz3Ad+yzsS1eIyRr4RuB+n6FMJBLErV58ngA=; b=gu4QfgqTNls1M5FdJGMtE8hya34HE4725WJHzCb2tXzOE9uaXTzvahOVZmbLeUWkQT fpK8tnzfmG+shDPpSOrBWpgzwnMfErie/OZxhuonLHKw9eWdcYgApp84ncyBRruOwI51 a7puhydHE0rfP8aThDDMBarclWiKdmz/ogmwSPVXybEjqcPcmlCPr58z3LhetkG8Hg9a 7tQSQdWIb9LZwpIutMwZaxQRzlb4IvKpyFRWQZN0N5ccHkNFD+g2iHPXpCwvmXhFRGGJ ERwjT3/HO79JhdZlGUuywiGTbdSO/rPbUyf0K/U5FpflWEOXzMjQQX62AXzyYUrqP4kl KLNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PS8Lt+3J; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-46418-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46418-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; AJvYcCWGhG9oavButpZwTDWKPN72zLIeLA1heidS3Ng+rgtvbQVHgqkGWXJaHAOXbeXIZNMPucJmJ1wKlMtMaSBaXzLQjap3etNFRdxIxfjNzg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j193-20020a638bca000000b005c6deead022si9333423pge.603.2024.01.31.05.03.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 05:03:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46418-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PS8Lt+3J; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-46418-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46418-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 9D29AB2C2F2 for ; Wed, 31 Jan 2024 12:26:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60F717B3E3; Wed, 31 Jan 2024 12:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PS8Lt+3J" 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 8891479938; Wed, 31 Jan 2024 12:25:56 +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=1706703956; cv=none; b=phvaHaEcwLKqBV2fiNoGuOD/ucxEQvoY0bd+Xy23s5ZZ64kfb2y2C/ODJBwmEDlyjAw59+ezHOsO1YuwIa2ocu2mVgmeSqAwBsuecNLLAeWLmV+AfPCbjnHGW5hUWIeOnqZakIQNyARAGkx8R9qcC60VaD/4DTOVOOh+AAAwAXE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706703956; c=relaxed/simple; bh=97FSX4oU5s9ZlUZoIaV1rFcSltgv+fl+Z/Ia3ZsihrQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jdgpoiukA4FV2jxJ4idtvsyjbiE5U9LLtO5VxEEPlNbG0ecZljKTvoEjT51/r27YjA8Q4j7oOxXVSqzJC1soqCnrnaOPm1d6VWkfWY4+Ha035OXis+IdrEVNepm27wmE/c3RWPEX/a/Lb8mSGoElS4W7AR+6ty9yNtKWv8LYFTg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PS8Lt+3J; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AAD9C43390; Wed, 31 Jan 2024 12:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706703956; bh=97FSX4oU5s9ZlUZoIaV1rFcSltgv+fl+Z/Ia3ZsihrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PS8Lt+3J3Xs0kHh+rJD0hfTP0DSeJUPH7CN4ilOfxfaxEBTtABTQKFhU1Vt6Fpl2h SXSdHDwsTGoxoDqLkFJctSVVpGe6bcg8D+ruZJSMQ9FtOZvbd2j6ArIUmJTydEP6Vq EtyOYy0RIbZaKV+hZb32fZ/s5BBWwSM3KYRey7qNdeHvVKj0KOC2C77zkelgMAGfM6 f1BcJFsEuDj8878ZiNGUZ8oz51mPpdupW5+NYpRewfsMIkoqZRWfkwondppd3ymkBO vNd4nflHvdfxun1SphQ32VxWLLgyY6a49tQ2rU989y6BJ5OHpugMz8mm/PWTuiVa8W nJvTjeNIafLhA== 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 v2 3/3] swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() Date: Wed, 31 Jan 2024 12:25:43 +0000 Message-Id: <20240131122543.14791-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240131122543.14791-1-will@kernel.org> References: <20240131122543.14791-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 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; -- 2.43.0.429.g432eaa2c6b-goog