Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp709943rdb; Fri, 26 Jan 2024 08:21:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1RtNXHnJvKbBjVmDNgIRy9pwKnn2GC1RtTIyLcVSRcfBBOGd1XEGKlEe+FHV7P5bHzOea X-Received: by 2002:a17:907:100a:b0:a2e:6044:83ce with SMTP id ox10-20020a170907100a00b00a2e604483cemr786939ejb.54.1706286094495; Fri, 26 Jan 2024 08:21:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706286094; cv=pass; d=google.com; s=arc-20160816; b=vq2E8Nb3nsAbOk7AvrJiiqpd14MOG+mnHzv3DGeqbvCx05vvlhNaBaf99aAZqr1qTU kC/Md4Sah1+f2zQt9TLIY+wjp3Lax66Uis1/8Geyci+4qCgPXuOAJ1wg/ZQaP12jcr9N MNz4fg1YziheYF43XlC/lVKtkCSowprc2Q53wZr0/TPjzs0hqWR7PeMp86mpG26rulFT RMI8jmGtRilbBJRPEdOmBjo649hnUzz24ZyYqxyi4RrxTij9ktH9pECUcNOIsxpkl9Ze IntzKsfNROzGwM/KANYiXUecSV7og5xngZQK/0erBk29MzLcHf8xOZNDRxcisMNPWqKa NdDQ== 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=Prf2cptf/5i9CzRda/YE0Sk9ZbF0fcl25XRo22nIyl0=; fh=Pt/vLgYoachKTmrGCk8iX6cxHu3EQKHMuGxf+QrSHvI=; b=r5C+1J/ZfNHVKlWVp51jz8xyNTXdKQWWLU9rETGtmQW7JR7gncttUf6voi/vw4uoin nwozyrMz2zmNNHeLxFf84wzmlVjKBJj1Sdhluapv7UALQNJeQtCywBFVR3hRLfV7iuzk jzx3S8Lo69iJJkYa7W4bY91ht/mh55x2vFcdvbUV4jrhYyCgR6X/XqvXbb4mZKe5/Hk/ jc/yAmS2VXuD118cds9Rd29wxAuB2et9pAXYzceb9aRfSP1laO7xbVCc56J1hVNSolRB V+AP+zjzEWnWUL7Gy1NLgxBFxUhYmYJRyrl7o8Ri23vq+NhsPk0qKEOgVTMsul53EkIo xSBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=L+pJ0gQW; 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-40324-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40324-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ce8-20020a170906b24800b00a34b0e1a75bsi765516ejb.432.2024.01.26.08.21.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 08:21:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40324-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=L+pJ0gQW; 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-40324-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40324-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 116BF1F22463 for ; Fri, 26 Jan 2024 16:21:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96CEC1D6BE; Fri, 26 Jan 2024 16:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="L+pJ0gQW" 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 1AC361CF90 for ; Fri, 26 Jan 2024 16:21:04 +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=1706286069; cv=none; b=W75CxVDLKzF9u60cgTwB7uvajZ8WKJg77BaXebQeNTd/duFmGIpo4WZkiTX2n6nsbX+PHXcOfCMKVK+IpFTXeERadBRTCp9KBALojf754YoQe55SQ754oMNjco26DYWJfygXE4sdCrae+HXrcF5W0Hh/BLZx8sPUK6l6ivZh9ok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706286069; c=relaxed/simple; bh=XbFTSyVW06Iaz2yZpMZPpFNnQ89qLLom1HMrMNtKv1M=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wi4vdTZIRFe1D1HW6CzyBxoJZlrppznd6UMAwBGZ4YPVP+mWYuyoAdXVRarGIBWxpmzJJmM8QmBK5f4bPiDNzpg2AMQ2YhEbHfEfzlWv1HCxTI0FFuuzB+Tn66NiF9YJu9JpKjbj14qynNX2E9mnQdj+NqUDmZY+I3jRnQWAyhU= 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=L+pJ0gQW; 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 DBF8618C8FB; Fri, 26 Jan 2024 17:21:00 +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=1706286061; bh=XbFTSyVW06Iaz2yZpMZPpFNnQ89qLLom1HMrMNtKv1M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=L+pJ0gQWzLC5yCJtUQqqH9mAvCH4/F462d1zWXlEM++WR33kntMzS6tLrRn2K8PIq FI7tFkAAnLFa5HKSI9TNRkivufjpN72EYx6pa5HxKYbtzFIqVRNog1C8Lk7NE4g8H2 ODQe1OqjOQFWg4JldbY6TATkm8np0jzjvjJasCKW+VO+OD0IB+zs08h621FeOIIxvA dnZc2VcVNtK+qEA1jNGADY78yxUOS+LdBRYW+3p3Czqxgfo4sscfMZMjMFmKfU8jh3 p1WboComAH7QjDtX6700UxTKqVU+cHmKW5j3fdwKC9W4f0z6s7VJjubxl22CXhuRpo +uaVEZ5TicAuQ== Date: Fri, 26 Jan 2024 17:20:59 +0100 From: Petr =?UTF-8?B?VGVzYcWZw61r?= 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 0/2] Fix double allocation in swiotlb_alloc() Message-ID: <20240126172059.48ad7b9f@meshulam.tesarici.cz> In-Reply-To: <20240126151956.10014-1-will@kernel.org> References: <20240126151956.10014-1-will@kernel.org> 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 Hi Will, On Fri, 26 Jan 2024 15:19:54 +0000 Will Deacon wrote: > Hi folks, > > These two patches fix a nasty double allocation problem in swiotlb_alloc() > and add a diagnostic to help catch any similar issues in future. This was > a royal pain to track down and I've had to make a bit of a leap at the > correct alignment semantics (i.e. iotlb_align_mask vs alloc_align_mask). Welcome to the club. I believe you had to re-discover what I described here: https://lore.kernel.org/linux-iommu/20231108101347.77cab795@meshulam.tesarici.cz/ The relevant part would be this: To sum it up, there are two types of alignment: 1. specified by a device's min_align_mask; this says how many low bits of a buffer's physical address must be preserved, 2. specified by allocation size and/or the alignment parameter; this says how many low bits in the first IO TLB slot's physical address must be zero. Fix for that has been sitting on my TODO list for too long. :-( Petr T > Without these changes, we've been observing random vsock hangs when > communicating with virtual machines in Android. > > Please have a look! > > 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 (2): > swiotlb: Fix allocation alignment requirement when searching slots > swiotlb: Enforce page alignment in swiotlb_alloc() > > kernel/dma/swiotlb.c | 32 ++++++++++++++++++++++---------- > 1 file changed, 22 insertions(+), 10 deletions(-) >