Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp630743lqc; Fri, 8 Mar 2024 07:29:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU/Um9IRTfV6ufJJRaDuv6DQaUYKTFDIIlBs43QArEQzPcIbZpBN8Ws1iPHO5Davx5FPzrExZ3mFjTnoLzc1ZvVKOlK/tz1d24pDVhHgA== X-Google-Smtp-Source: AGHT+IHWpbeYFoVbgh55iHEaqm6OORF977ELbuG3VlJ43nhxzV3Cr5Vn6E+8jF09bpVl9/Tsdkfe X-Received: by 2002:a05:6a00:4f96:b0:6e5:3b8e:bb6b with SMTP id ld22-20020a056a004f9600b006e53b8ebb6bmr23776413pfb.7.1709911762915; Fri, 08 Mar 2024 07:29:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709911762; cv=pass; d=google.com; s=arc-20160816; b=sMk+upDM+8CkBjbzQw7UPeuMPeBUovljBETZEe4GXEiINhXJed/95Fgj2Wo8aYaYwe +y+GyYsiFGWBX5bZ13pARP2cVOybm9Z8W1iWvh05kPCnHjUaiF9whQabB72v7XF/724J tQK5IjyI/7DtWH/PpKivPKXG5KKw6PSzHQl1+9RyRKIh/oz3TQGN7D6XO847NScrageJ JEukcEZTSUKkeTQmLSG1tJz8YNQed3afTakJxoK/vAbvuU6TddY/Z1bcQDc1jQvAuuos 6wGe1rBV5sGLQJKwfDTAOLum4q81bqtXAD0ATvQYl9GE1MRGXulzYaO9QZ146nXqjRgT iYiA== 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=T1lE06rvFcTqXgnH7mAjx6SeA+hYazrdoD509xcGPDM=; fh=E8F5/vp/nAcPVJWJwVt5RE8c2HME7kVqVeSMFxe8huE=; b=SavV9X0DN8Ix6F3NDtG+CalAX1yYX8NgvUTnPsWmyIWessrCDXeDBPG7Bxe859O8dI CGq1fnNVvWBuvdeP04ABbL4EvdbMQeagSWOeUAkveIuyjyxfg1NyMdP+0VH+Coh1g6mE Be6qXS6WsaTj4Zc1X/elxbpyJci6IZ5gWRd3WoU0sorsJnTIQQZFupRNDG2x9+23iIXf 7SZVf5EMg8c9alFOIheat4xi+6sm5u+IybMPkV6h7DSCKm7tU7AzyllO5f/PoQMAlyiy Oh5xIVnEZNnzWIrcslQjypBOKomUNkW3rgUpjud9M2sc/OsY2rwBDkBOGKFlyuZSdK47 UUdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nnCgYEZ4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97233-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97233-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 j26-20020a634a5a000000b005dd565d7626si15763434pgl.900.2024.03.08.07.29.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 07:29:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97233-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=nnCgYEZ4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97233-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97233-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 B9288B21C99 for ; Fri, 8 Mar 2024 15:29:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FD6B250F3; Fri, 8 Mar 2024 15:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nnCgYEZ4" 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 C589D2C869; Fri, 8 Mar 2024 15:28:47 +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=1709911727; cv=none; b=HuofwPDQGA1zmoLicIRLGtcV4JIJ0ceiR224zIza8k2xoEndq3uKuR5yk6gOuUWX6cw8EMCQHPxdoaaUxyIvj/76UjPc5b3w5deCBxeTprXhOcTz8x4duo+HveXCqT9nhLloPo6Dc2pmazTSI/Gdtm0voz0dcwk/7nYgmduV/i0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709911727; c=relaxed/simple; bh=vsrvrkZU89TFmvM4wV64YJV1Q5GWDF7dRggI1U7nSbU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hy3/EstDETaJPmvJwD2mMxQ7nKR2M1gCjwfGFUSzABWlQtwz4SNVCg8Tp+qfe1htg/zXSulf0QNb7eUcSwmV31ogiuLlsEC0Ne2xCY32MRrfFPjDOZyApe0kZQaRqSNqqG+DPZ47czTcb0ZuhGeRd6RAvXf6Ozz6tg09u1+5BMQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nnCgYEZ4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43033C433A6; Fri, 8 Mar 2024 15:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709911727; bh=vsrvrkZU89TFmvM4wV64YJV1Q5GWDF7dRggI1U7nSbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnCgYEZ4nXN7XpgODKCOquD+5BkcgKUeur8d4aB79bU2sc4SuWWcy6VAwYhwe7+zP ixoNMbZ/sQVOuxsh/9cd/IpRmewfqMxY+G9hw6MjE60Gw6CwfLHAzauU2YwbzCIyXi gQcWsxloGV1qbeS0shCTCsAwCthd5x1YSWScXFg+GEMUOF0+rfFfQXv/e60ZE1PJYX Vml2gU8tAe3fz9qkHLN2xMnE/kN5T+Lrico/ySXdv2o/Rw6r2RygqBytam0+Sc057S zVd44SHp8Bt4p39Att83L8GQOsEZtXrwOmZeSvykGG4aCAsyL3wMJ2AP1wqFoX0wlw yFV8dmbVS08iw== 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 v6 3/6] swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() Date: Fri, 8 Mar 2024 15:28:26 +0000 Message-Id: <20240308152829.25754-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240308152829.25754-1-will@kernel.org> References: <20240308152829.25754-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.278.ge034bb2e1d-goog