Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp204919rdb; Sun, 28 Jan 2024 22:09:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEsPj+zFAPZ3YpDkZ/iZqG+Wv5Jr69d/WdEaRCmHC2Tf8dZ3OchVE1AaZ4m1e8ejbVQiBsp X-Received: by 2002:a17:902:d34c:b0:1d8:d87a:a40b with SMTP id l12-20020a170902d34c00b001d8d87aa40bmr1017148plk.11.1706508555341; Sun, 28 Jan 2024 22:09:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706508555; cv=pass; d=google.com; s=arc-20160816; b=N3NTJH7pHCBXElvToxzi6efo55ovGn6wzsoUz2VQe5HLOQB9YdiPXtLiSczUvHSa/C ef2aAgJl5X8BK4U2WmgIq/BWXo/DxlNQ9JHcNykZm7o34QuuMMEL3hbcKBee2T8UadB6 0pTSv1ueC1VL56PElv0vu/DQcKazsuIW9AdKKQvY+isQTtHhrfOYyAOLF9kJN/zfGS7V kHwmIeYxwCfFd3x/oTwHFovoB6COyHNH70xUg31QLwLq6nJT2UIGuOew70n8svCa6KpK tj2NFrQ6ovcZZh4vTqT4sGJzPPcEEzln+6Ec4uvALMSZyMjpqVt6I3Udqeggrw5gzdUu 8yuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date; bh=g6SiaZZZ6I03UZ92elY16uRZmXbvhRQN+uSoR2HxxIw=; fh=Pt/vLgYoachKTmrGCk8iX6cxHu3EQKHMuGxf+QrSHvI=; b=nfOl559eQNoF2qCS2zIgc1fdk+2uu22pMju3xLElZWR65N5q1Mt5M0lp4M7G3pKdCH gaOgwFlMstQeiQDV40lCHnBDzHzSqvjrklTPUeK6QhNtM4nuZxJdR+913W6D1LVj8lWs ItWJjc6Ifx1+9IychZxDCOxd9QNULt3xAPce/14aekkh/6Oa+fD0OvKyHHjvUECimvMI uusvMRiUkkU2+ucOTYoP/5lsAatVMdjfjvhd+Yc0biyoMc/mJFR7BnbbMa4ihnKmElLA lmD8/N2gRGDwU3xqqutmhT4pJGNv+PxGACXR5vO2K+CvUwUj4bdkbvMKFhYubCoI+WjE L39Q== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=lst.de); spf=pass (google.com: domain of linux-kernel+bounces-42213-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42213-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ck12-20020a17090afe0c00b002903e315e4bsi5237142pjb.81.2024.01.28.22.09.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:09:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42213-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=lst.de); spf=pass (google.com: domain of linux-kernel+bounces-42213-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42213-linux.lists.archive=gmail.com@vger.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 A2D0AB21AEB for ; Mon, 29 Jan 2024 06:09:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C766E45BF9; Mon, 29 Jan 2024 06:09:01 +0000 (UTC) Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (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 870984C618 for ; Mon, 29 Jan 2024 06:08:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706508541; cv=none; b=isj7wsY36ASKaRPaFqTxTx6KlWFaHz+OY/RzZ8dOW/fITr51x4t2EdYpib7sy6LliDANJ1tyn/kdjjq/qOmJKhnk+cCYF/aGIF9X3TCv1xHlYP/AVjvhik88Soq5lGLrhZCkvCy+iqbKmaAjl+Pv6tol+JhuiKlRtynMKVskbd0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706508541; c=relaxed/simple; bh=jAALexVfdB8CH5+NUTWXDLvoHfK5Y5gEBA7XS2daLRE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J5ohcnCZpGL6d/sggYF46BmUUDL+WQ3CySyhzpf36wS1QGDZzGJKwqUEyEOHMVEnPLjw8xYflILvhr1KnZJ5FBXyJ6HpHLDavbqxq7PwEp+R/Mp3WlBbU1U9PyGAUFRMorhdH1AqkGdZZ4tHKyJ9C+HxJiFpsDAjG8nSm0/487A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de Received: by verein.lst.de (Postfix, from userid 2407) id 50B8C68B05; Mon, 29 Jan 2024 07:08:54 +0100 (CET) Date: Mon, 29 Jan 2024 07:08:53 +0100 From: Christoph Hellwig To: Will Deacon Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, iommu@lists.linux.dev, Christoph Hellwig , Marek Szyprowski , Robin Murphy , Petr Tesarik , Dexuan Cui Subject: Re: [PATCH 2/2] swiotlb: Enforce page alignment in swiotlb_alloc() Message-ID: <20240129060853.GB19258@lst.de> References: <20240126151956.10014-1-will@kernel.org> <20240126151956.10014-3-will@kernel.org> 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-Disposition: inline In-Reply-To: <20240126151956.10014-3-will@kernel.org> User-Agent: Mutt/1.5.17 (2007-11-01) 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. Maybe just throw a WARN_ON_ONCE into slot_addr() ? > } > -- > 2.43.0.429.g432eaa2c6b-goog ---end quoted text---