Message ID | 20240131122543.14791-1-will@kernel.org |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-46415-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1850688dyb; Wed, 31 Jan 2024 04:28:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0vRnk7xwzPBfdMA5daASaNfhL2UQ5AMN2K7/8Mqx5zd3+HRBhx/FNYgCHrJPfqAjTXJc6 X-Received: by 2002:a05:6214:19cd:b0:68c:5b0b:601 with SMTP id j13-20020a05621419cd00b0068c5b0b0601mr1407807qvc.59.1706704082397; Wed, 31 Jan 2024 04:28:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706704082; cv=pass; d=google.com; s=arc-20160816; b=Q+P+0hEaX1RLtk/THrmSECpsekyCuj9idYCRd4pByVUCJNSzv1zZi8FXqcb0YtF52R jBIgizosZFaObfC1dSg9neXH5jDrafpZ4OUdcI0upE+X+2D1qZEWjf63SeuNNUf1KF+K YHfdl0/sret3nP1RYi7ET1WdPSsM83INNTcjI2nfToidhTV/Jq10e8VSrcIqGOE0/apM +V09n8wMvU2icHzd9d2bsUJQDiW/VcQnmkI+Ic/PVnqNic4QO+xLctp0gC4ZmPd5dzxU KJPGm8q87tljMm012j207IlGEeRqbkCnYQL4QI0Af1cJrhHG4PFqFHg21XWMioQkeqcw bMkA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=PsvWIebKtf1TTe9k2AdsJl7nXQXsr+9i3wE9mIYd8us=; fh=wzcjd50cI5PCwCsgn1n2KvZ9EihBi8Mm029vcOz7uz4=; b=JQoFV6fVYMqWeMvXcxwRvVbL4KqxxrzTSp3HectJ4jKD+K7zU4+TJyHD3nX87dfmTH SVa0522OiXPiFsNnmEgNzbqfDwRaX42NLK4c7OcW9Q/nbbxHMCp4R2+uo4j23vIEaRVL DRDs/vrW2AokiTuPSDwyUd+e4PfLxZowP+PmO3OmITGdMdWPfcLUeNqrbg96WK0sl57F 8Hakz6YJ5yovM44DMWJV7WNKiju/cIdlSc1Qn/UAb4H1axA5qt4Wo7L1JgrHATC2BSLd UkcW1wlPpQNul4GYfGo72OWtKopdy4w12GfdRhqyAtJMIuOoXaePsJchvbSEzJ//tWTY y99A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P+6Cycw+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-46415-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46415-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCW3vEQqGkiUB3J6mb5aFFzNC8Dto880V70Nq7GAZrN4IaQKvDYhx25qwpPy+pCFMy2wOsa82qQLr1rDjFm73eCF1ZB8UA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jf10-20020a0562142a4a00b0068c6cc81ba8si1086978qvb.392.2024.01.31.04.28.02 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 04:28:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46415-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P+6Cycw+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-46415-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46415-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 721281C285CC for <ouuuleilei@gmail.com>; Wed, 31 Jan 2024 12:26:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A55B79DC4; Wed, 31 Jan 2024 12:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P+6Cycw+" 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 AEC3E762E1; Wed, 31 Jan 2024 12:25:49 +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=1706703949; cv=none; b=GnCSCiOlJdrPxgNCM8Qo6JBeEcbpFxPAOOirJ4LydnB261vLFcEy3kASTHewylvEhOmDTH+XVAr7c0oi/Xxoj2upE2fzATdCxUEIoP1yjKDQtkksPpWT/UqYgs5cj/anPKP+RzCJ3/6hWfiudT50Vr96E05GdN1rAS0N+InY0Ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706703949; c=relaxed/simple; bh=oSiwiqXjL3MXtK5womb3xjmKXeDs/dPHMKiXnUsL/VQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=PgAkPG24+ntY8NodKydJJts+aMsMqc6rzxwvIwC9tj5nLiUM6ivTIemu9mJqSauIutQyIphpVTZyvpH5Gscwr6aKd5uiDxFC3x9f4MkVAQOid+dq5CJ48LqwHVSdT+fZ9DINYVHANJmMfk1lpIL/n3KO2lq+aFS8bKkz5SwkBLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P+6Cycw+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A068C433C7; Wed, 31 Jan 2024 12:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706703949; bh=oSiwiqXjL3MXtK5womb3xjmKXeDs/dPHMKiXnUsL/VQ=; h=From:To:Cc:Subject:Date:From; b=P+6Cycw+R2y+foOUIi6lj8KA+YlmZZniSey1FCiFahbTZbMOi3YSbaYg8avprIhJ8 IGoc3ejn/SmgQFNGGoyodvqxqLzDIRJCvh2gKYSxFpK+mAyyK7cF3Zf9BW/NYCJ9+N S+Sxl5w9Ha/xlpWPM9Hv5LDt+EQagHkqi0FUtm/Lf20lMX16J+Kgiv+JU9K8eMtcq3 n5mA8M5lRBjfDhGcWk3f3sqA3V7km1rzvH0wOkukzFrz4BJ1bv4NBz4CX6N/9MvuAO QfdiE212OqdXX32Flh8o1EngKW7uMCBKafD1GQr49ax09X2hDOZdVs2UMsnMYzE7zf FGQbN8LdAg8Fw== From: Will Deacon <will@kernel.org> To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, Will Deacon <will@kernel.org>, iommu@lists.linux.dev, Christoph Hellwig <hch@lst.de>, Marek Szyprowski <m.szyprowski@samsung.com>, Robin Murphy <robin.murphy@arm.com>, Petr Tesarik <petr.tesarik1@huawei-partners.com>, Dexuan Cui <decui@microsoft.com> Subject: [PATCH v2 0/3] Fix double allocation in swiotlb_alloc() Date: Wed, 31 Jan 2024 12:25:40 +0000 Message-Id: <20240131122543.14791-1-will@kernel.org> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789608939497979474 X-GMAIL-MSGID: 1789608939497979474 |
Series |
Fix double allocation in swiotlb_alloc()
|
|
Message
Will Deacon
Jan. 31, 2024, 12:25 p.m. UTC
Hi all, This is version two of the patches I posted last week: https://lore.kernel.org/r/20240126151956.10014-1-will@kernel.org Many thanks to Petr and Christoph for the discussion on that. Changes since v1 include: - Fix swiotlb_alloc() to honour the alignment requirements of dma_alloc_coherent(). This is a new patch, and I think it's been broken forever (practically stopping at page alignment). I've left swiotlb_map() alone, so that doesn't necessarily return page-aligned DMA addresses, but I think that's ok. - Avoid updating 'alloc_align_mask' and instead just compute the 'stride' directly to avoid a superfluous alignment requirement for mapping requests greater than a page. - Use get_max_slots() instead of open-coding the same logic. - Remove the extra 'goto' in swiotlb_search_pool_area() and collapse the conditionals instead. - Reword warning message when swiotlb_alloc() receives non page-aligned allocation. - Annotate non page-aligned case with unlikely(). Cheers, Will Cc: iommu@lists.linux.dev Cc: Christoph Hellwig <hch@lst.de> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Petr Tesarik <petr.tesarik1@huawei-partners.com> Cc: Dexuan Cui <decui@microsoft.com> --->8 Will Deacon (3): swiotlb: Fix allocation alignment requirement when searching slots swiotlb: Enforce page alignment in swiotlb_alloc() swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() kernel/dma/swiotlb.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-)