Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp631113lqc; Fri, 8 Mar 2024 07:29:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXbYA0o9Qzjim+bLuf8C2ca6AWVj7sWcf6Ho1zEcepXUb+neOnDA5uX0acElGtqv8hZc/9VD549+AWrKa3V9v73ZAeBMkN6GxEFPlN6jQ== X-Google-Smtp-Source: AGHT+IHhOULskivH45wzqReZAamTrlXsS2g20TR9ESpLRaw/vpMkcdr0DUlnvBBUP/jG+8jDuXt4 X-Received: by 2002:a05:6808:30a5:b0:3c1:8039:c6a5 with SMTP id bl37-20020a05680830a500b003c18039c6a5mr13818921oib.35.1709911795870; Fri, 08 Mar 2024 07:29:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709911795; cv=pass; d=google.com; s=arc-20160816; b=hd0KU2c/5QCkI5X5QEQ6qq9fNC1bF6HLRoaqCnZUz1eUnEJLGJt8Jf7dnH7J6HkeAR gHagymW3aQ5dO4i+t8VCVYGXWNvpoJ4yYl2Whkr/odnKCNn7ZnHHeJp9HHUSFAzacpSh qydGOHzRAgXmLWwGq9t3PVsRQ85aaksQDDL/7wxTjecDDDkwp4U6u2yGADoaR33WmqTJ m/JInGnJTLfvvbzUSbo1B6DySHkztdHYoIGstXLLxXISGoSiD61j2inFiyhz0xsJsrWl CLx1Cxb2wfLpYn4pdidfyzomeSciaSvngVKY1zjcUJg+PniTWUBwkmv3DnHLedwu7/fW 874g== 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=bFjI0C3z5XVYSnzCxYdAEOnpaElmXsv40bkWvI6/6qo=; fh=E8F5/vp/nAcPVJWJwVt5RE8c2HME7kVqVeSMFxe8huE=; b=PchIlZ4aDDi2UX8rksa8A2XsWfjpArnmAuNO+fc1fm41ro/cbDgV15iq0UdP6Emp9x E+e1nnqxWpNF9UWiSKC09VMAiyTuWmkPhd5naIaGRRcXqzZlsiMzgJIjxjGtDG73LKJD uRU5LV+xGT+XeADiE7RKxAuJS497724sLG2FvdnlkWibmumafoVRtKp1gF9jY8gSRXD2 sug48G24sWS5yhHkjhpdcWJFwRFjeZRfatqUIKmpBFJ3FJPf8jjuGqCytLzuV5axA2/t I0eeXtMH4+YiHGSdQV8tOjnv+kFgichqlHKAlWyDN0aGsz0wCJk3V7tfj7KlbzfG+iOB PQmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CWbYXEOa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97236-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j13-20020a63230d000000b005ceb5338d74si16170913pgj.510.2024.03.08.07.29.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 07:29:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97236-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CWbYXEOa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97236-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97236-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 8A0A6284D65 for ; Fri, 8 Mar 2024 15:29:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AB14208A0; Fri, 8 Mar 2024 15:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CWbYXEOa" 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 A328E5674C; Fri, 8 Mar 2024 15:28:55 +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=1709911735; cv=none; b=iO2hrzPkdoi3qrLDmb1dAY0cLifzR2qDUXNVj/NWb7c6GoVng7MkXT+Zmte4VFbzb/PJahB2Hq7EYNHR8egh4rU77KZ0Xct6BfYT7CFr4bLGYllEFPk3n6dFRyyxaqY8atPTvNEik7h+3pCk8n6GGVnpf4C78hYCnbyuM1pWfAk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709911735; c=relaxed/simple; bh=bMtbuNa4OfY3K2WJdXy/zJcV5S/fCzZ4bwmKbkY1b0s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NyAhIp+RHj60HXP9ePW06+K6mV1GSwvi+FhT3jQxcu43u2/4cgWRaS9GMJfQjPYCce0sfc7umX58XNUl+oRlbZR5tMf5U/ctumdE+W+M5OOYDwbbQi1ZCOp+6ACSxE8YVZMysVkny7ysB3NiIlxvXRbP/sCPDv6Qdzong1Jw3XE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CWbYXEOa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C4AAC43399; Fri, 8 Mar 2024 15:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709911735; bh=bMtbuNa4OfY3K2WJdXy/zJcV5S/fCzZ4bwmKbkY1b0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CWbYXEOa6wE27t0jsLOmA9bTsLR6V2AlvBrk9RktDdS3R6g9SZe+VXXgiqY5iCmQM BLsOZxtpGCfCeilWAcXaUoe01rL/2+jfsdkGBtf1Mp8hYwzzgT/apZ99IIIK5kBrVq RhHjx7Tb8sR7LP3hknRbpH86ZV/wDKXlRloDx6rQUHWfHd6KgoAIpmzBNdLrPOiE9s RP6DvfPeGP+eQfGB1u93rLXhVuGS+TUzmblBNlnulL7USEx9Z6yh9tPswczTDxQ3m4 wGbeGkVm1EKuGnWCWy/P1ueOqelDsezPCP+2b43C3kIcartNXssO36WKyf+3i2OP6B AdWdNeBf6S+TQ== 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 6/6] swiotlb: Reinstate page-alignment for mappings >= PAGE_SIZE Date: Fri, 8 Mar 2024 15:28:29 +0000 Message-Id: <20240308152829.25754-7-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 For swiotlb allocations >= PAGE_SIZE, the slab search historically adjusted the stride to avoid checking unaligned slots. This had the side-effect of aligning large mapping requests to PAGE_SIZE, but that was broken by 0eee5ae10256 ("swiotlb: fix slot alignment checks"). Since this alignment could be relied upon drivers, reinstate PAGE_SIZE alignment for swiotlb mappings >= PAGE_SIZE. Reported-by: Michael Kelley Signed-off-by: Will Deacon --- kernel/dma/swiotlb.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index c381a7ed718f..c5851034523f 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -992,6 +992,17 @@ static int swiotlb_search_pool_area(struct device *dev, struct io_tlb_pool *pool BUG_ON(!nslots); BUG_ON(area_index >= pool->nareas); + /* + * Historically, swiotlb allocations >= PAGE_SIZE were guaranteed to be + * page-aligned in the absence of any other alignment requirements. + * 'alloc_align_mask' was later introduced to specify the alignment + * explicitly, however this is passed as zero for streaming mappings + * and so we preserve the old behaviour there in case any drivers are + * relying on it. + */ + if (!alloc_align_mask && !iotlb_align_mask && alloc_size >= PAGE_SIZE) + alloc_align_mask = PAGE_SIZE - 1; + /* * Ensure that the allocation is at least slot-aligned and update * 'iotlb_align_mask' to ignore bits that will be preserved when @@ -1006,13 +1017,6 @@ static int swiotlb_search_pool_area(struct device *dev, struct io_tlb_pool *pool */ stride = get_max_slots(max(alloc_align_mask, iotlb_align_mask)); - /* - * For allocations of PAGE_SIZE or larger only look for page aligned - * allocations. - */ - if (alloc_size >= PAGE_SIZE) - stride = umax(stride, PAGE_SHIFT - IO_TLB_SHIFT + 1); - spin_lock_irqsave(&area->lock, flags); if (unlikely(nslots > pool->area_nslabs - area->used)) goto not_found; -- 2.44.0.278.ge034bb2e1d-goog