Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1621047rdb; Wed, 31 Jan 2024 04:27:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9+QGwx20bpM/OfeYi5y2P2cOxS2AHzJjp17wEemz+catjRQo+zW/nOqi9BtoD0Ppffmyd X-Received: by 2002:a05:6214:19cd:b0:68c:5b0b:601 with SMTP id j13-20020a05621419cd00b0068c5b0b0601mr1407630qvc.59.1706704078010; Wed, 31 Jan 2024 04:27:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706704077; cv=pass; d=google.com; s=arc-20160816; b=fwd76SXRo+kyxu6KyQKLI8MiJtmbR84XLCCQcQjfHHlm4fVg3pt7lI8U7NDS8PdZOz QuKTnA0MWhJgQCkgY3Ghf+jzxuACAvoogE7P/QkieCC1j4hHY37hIen3uDuxhdrPKiZq NEaOABNyI1Yj9a/MjWTbL9LQa/2ZPT965GRYmVw+LvNkk5nryaodzA1VvjNWJV38iyQh 7I1QnzdeWDfBExEG/SbkZEFx24Xk2sAAYn2XGkNb/JQ+3DWJYfiwAqlWwrOEKgAkg+ym +y2a9a6/bCONpMsDvZTAL8dvz48Jxv48BcUTg9Gemu9wGpgy00mF3ADEJzlXE95f1/Un Qf5w== 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=3YgnL7KWuWd7K+aCy4oarsAFjSYPQaePTT6lrRYBdYI=; b=KgSYLONXj8NZcvk2GFBnas+Wt2l9/xPOIE0CPvtfzMgJBVzu/eSPI5wG1CFdJmiTkk 5nYPgd+5Ke7/PSwUe0yx0DhtP7gZLrACk0JBaMs/PWoxMgDY/72iW6mjQ/3Xi1ibQBwr F1Abvu2QE5s7IJ+doU0Jx+rzBtRVRKhurlx1rpnkKkot7RJEKpFg6XFTd7u6PhjlfhJl 3SdgGSwaXELDADCJBHO0cqnHQ5aqubtp0HYTHM1ZftE6u2xPv+FFeg20R9VEB8DxuJ9v swgGMQY/FyDUaxraCFjn7CKV9TWK/twQLuyL76n+EltKhZC9EevdJA0NOkwECp+9HB6i Z3MQ==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46415-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; AJvYcCUSiL9BGB5R4sL14Hj5+8nsvvsWGqZevzB41zpfyIu3AFzQssfUKCpS45ufW4IVn3J1I9bnyjuRZgXhkcdOhOSjj+d8kcO5+NocIDbYfA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id wg19-20020a05620a569300b0078407b4492fsi4176527qkn.19.2024.01.31.04.27.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 04:27:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46415-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46415-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 102071C281AE for ; Wed, 31 Jan 2024 12:26:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8855978B6C; Wed, 31 Jan 2024 12:25:50 +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 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 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Marek Szyprowski Cc: Robin Murphy Cc: Petr Tesarik Cc: Dexuan Cui --->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(-) -- 2.43.0.429.g432eaa2c6b-goog