Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp234222rdb; Sun, 28 Jan 2024 23:44:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEAE4c+QDCobYuftLyZM+6hT1LywI06THpBO4/57OPIvKGKBI02ddRnlew/eCkmVk/CqiGo X-Received: by 2002:a05:6808:1145:b0:3be:37ff:47d5 with SMTP id u5-20020a056808114500b003be37ff47d5mr1240242oiu.32.1706514247049; Sun, 28 Jan 2024 23:44:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706514247; cv=pass; d=google.com; s=arc-20160816; b=r4SZe1g9SQAxTDGHZQx3L+XR0B3rJhGLlHSsNqJH66XLl/fPzespS+rfIf1NUNdoG+ CZibXBWgZBOE74X8uwJ964CCIzMhaYCLjqqaM7+Dfuyj4uUgND3IYJLVYw6qq2GIz8lr 3Rc5i+HBBljl6HC1N96TS2DOzWsEd1QyqvbvFKdDA2jXkQzt00fsTRTJMQM1TtrNttQn 5i1XistSRU3BeSWweXEECOzwFETagaEgAI5J51CfGoJ2UhXI7BVMYcPdYP2oRKT6L+eM bhKOshGD6+k+G36Y05KvCt0YKKJjgYHRYOeU6wgHT2tp9S0SSpB3P+xexWXWyg2mb0dN SeBg== 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 :subject:cc:to:from:date:dkim-signature; bh=F7jlXD31dMH7VtK7M8CcJCPHWxqoAGgO7497O58MxX4=; fh=jgBtM3j/2YdgGTLlZV3S2S4BnYKnDL/quFVKzWmzh9s=; b=II4PwnOLa/Dp5byMxgklVASsZV/DpZI+u53rQ8t28IczKncp8EiUrVPubYDSOm3TVK 9ZgE9Ylf8PCNQG1CWAXbkqiU1LXlHo21XqpgffOcrnboiJEoP/d4tuNFHtX7RIH9abCa QsGjMeoDiPv0AfHP9phCUWjbiTqT8JBz+W0f7LO+OfkM/EIBoPMAkzMKmiqWQkeVtXb7 8cXMs7gXpliRJGWlf6nzk39KngGiXP/l40CeHoycF1UpZysyeplzuFWbYtRHJ8sqnI2s mSAGgdowvLrQArSOG7zLV6jeBlvy9p95IwQ8XbZtwZy4KzBawE/GAnmLPhhhCfgBkQZD P2sQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=396NALZi; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-42292-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w128-20020a626286000000b006dd87292a93si5274513pfb.378.2024.01.28.23.44.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 23:44:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42292-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=@tesarici.cz header.s=mail header.b=396NALZi; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-42292-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz 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 9B61F281C89 for ; Mon, 29 Jan 2024 07:43:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46D594EB49; Mon, 29 Jan 2024 07:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="396NALZi" Received: from bee.tesarici.cz (bee.tesarici.cz [77.93.223.253]) (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 0BE3F4EB23 for ; Mon, 29 Jan 2024 07:43:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.93.223.253 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706514213; cv=none; b=V5PaKoyibRvS+fCpEf/cHB2lLFZh/ZDU7H5lRRyul4OA9+FWw0e8vtZW4oInRI7iyKwUeF5PBpWqI22iYlJCa1iCE80A9xhCGpeA/toXf1rx40NUVMTiZiP3hAqB8Ueq8WV6GWYNyGwYU8g3mM1uShVREKu5bNExKe4zh4ICGJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706514213; c=relaxed/simple; bh=PfhvtgDD3AmzalLTRpYnRygPfaJzOhGOT0f1zwC+1+4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nH2kA6U99bwAoSKAs9Z/1lplzA65DaoPFVGbND+6vvPP+uJXcnislX/Lv7Esty1CByZ9nqbp0VxIHE02FrSiMoMH0Gb8br42K+Y8NMdXuxz/echFZYjht14TviUIs7dDufYUL9uzGW9OXFLfw6GJbldsfm1equGQnaDUQySOpSg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tesarici.cz; spf=pass smtp.mailfrom=tesarici.cz; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b=396NALZi; arc=none smtp.client-ip=77.93.223.253 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tesarici.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tesarici.cz Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id 3D0DF198C58; Mon, 29 Jan 2024 08:43:28 +0100 (CET) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=none dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1706514208; bh=PfhvtgDD3AmzalLTRpYnRygPfaJzOhGOT0f1zwC+1+4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=396NALZi9bz0Hc3HaCVtYWxpKsv86czZ2xXWoAOID5ZJIJZQRwyRZ3zTl0zDRv5WS Q8U4X0w4p739RKhe4B7YW4Et80YDlgYMJ3j4qEgawYI0mEA8m8pbN0vLR8hCyf5SHe xwbz8xnpuce/8Eax6iJFQCXMwVEkr9ATHNz3+GYeb4MV0DsijTUIUpZzFnxchYigsH SW4LVvP8CX2gaDw8m2Wc2P98H77hsRT5rmznZDlHED2HbgfZVq93q9ibl0UpymFNDV bfLTcucxEZ27l9nn5B6OPcSHwM8cU7obOm7Chd9SP0WMjo6z8cwSK3iIZBXRnlmuzY bSZF9Gm6w27zg== Date: Mon, 29 Jan 2024 08:43:26 +0100 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Christoph Hellwig Cc: Will Deacon , linux-kernel@vger.kernel.org, kernel-team@android.com, iommu@lists.linux.dev, Marek Szyprowski , Robin Murphy , Petr Tesarik , Dexuan Cui Subject: Re: [PATCH 2/2] swiotlb: Enforce page alignment in swiotlb_alloc() Message-ID: <20240129084326.4667af6a@meshulam.tesarici.cz> In-Reply-To: <20240129060853.GB19258@lst.de> References: <20240126151956.10014-1-will@kernel.org> <20240126151956.10014-3-will@kernel.org> <20240129060853.GB19258@lst.de> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.39; x86_64-suse-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 29 Jan 2024 07:08:53 +0100 Christoph Hellwig wrote: > On Fri, Jan 26, 2024 at 03:19:56PM +0000, Will Deacon wrote: > > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > > index 25febb9e670c..92433ea9f2d2 100644 > > --- a/kernel/dma/swiotlb.c > > +++ b/kernel/dma/swiotlb.c > > @@ -1647,6 +1647,12 @@ struct page *swiotlb_alloc(struct device *dev, size_t size) > > return NULL; > > > > tlb_addr = slot_addr(pool->start, index); > > + if (!PAGE_ALIGNED(tlb_addr)) { > > + dev_WARN_ONCE(dev, 1, "Cannot return 'struct page *' for non page-aligned swiotlb addr 0x%pa.\n", > > + &tlb_addr); > > + swiotlb_release_slots(dev, tlb_addr); > > + return NULL; > > + } > > > > return pfn_to_page(PFN_DOWN(tlb_addr)); > > So PFN_DOWN aligns the address and thus per se converting the unaligned > address isn't a problem. That being said swiotlb obviously should never > allocate unaligned addresses, but the placement of this check feels > odd to me. Also because it only catches swiotlb_alloc and not the > map side. We may have to rethink how alignment constraints are interpreted. See also my reply to PATCH 1/2. > Maybe just throw a WARN_ON_ONCE into slot_addr() ? Yes. Or, what if I write a KUnit test suite for swiotlb to combat this constant stream of various regressions? Petr T