Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp592814rdb; Mon, 29 Jan 2024 11:30:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEn+DD8Kzmlt+F8cO62EwaWT3VkCYeU8vqhBvmjLEQLtpuYJRVKjRRgTBz+FLQJQqBs2idS X-Received: by 2002:a05:6a00:2d28:b0:6de:10a2:3951 with SMTP id fa40-20020a056a002d2800b006de10a23951mr4079586pfb.4.1706556652500; Mon, 29 Jan 2024 11:30:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706556652; cv=pass; d=google.com; s=arc-20160816; b=bhePlS0JusCsTKcUiZJiAXOb1H2VPUWioTfwcRN4ov9P6RTxWIR76gY0YhL9AkNRT8 +DFZeS3CrBdvcj6yq0klNE5w9Y1nkv0MEN3oyFxGfqNp5kWYv8cxi6nGyhro4O+stgYX GK4g5kpn438ZtiPcMigPKipAjyWC129pXwCBoJE7DTjs56nL3aS2nh5UkGgMmHzxlCNr 9ucvYKaRnAMctjzvH7EoHBNDdtbNkQoMngT+bzBRCxiFrp9i/a/hyBQNrkkoXENDBi0u zCNj+UtSxqkSWxNoBD7ejw0AJibyB/tskCwf9w45q/gsingzTKmNbHdO5XDlJsWYEev1 q62w== 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=Z8YBilWYmuclfPiBKJwljKoqpbdv7xEmMq/selk+0b4=; fh=Pt/vLgYoachKTmrGCk8iX6cxHu3EQKHMuGxf+QrSHvI=; b=tfeDv/Rggj8mAdYNTQeh6jL2RkRnjka+ftZtQA7IyVKaZP+tVfu4b/2Pixf+jEE/ov kS+cGsS+D6uRTf4B/DQIL/WjXcbn2tLT2SJQ7HACG6a9yPx5eDextdvJvVwaf03qrMSn FS9yY7czBzOoD9zvbKbNYhOgpmuWgcMFk9iNkrg3KSoCN1Q7JDGmged33zhii4FDDwOj 5ZxrmCj622i5J9XsQqhdvxnyaR54FcioABiOvKsptF8l/yc6Aj1VYaoi9x4FlI1jq0V4 QayPqKLnBi0p2PNoRL3ftwqtq82L9JcmJtHZ3yvJbVuk5wW5L7o1J9qEW3wrD9KUMC8S MLFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=UJeR+Nt0; 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-43400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fb7-20020a056a002d8700b006db62c4e73asi6265446pfb.223.2024.01.29.11.30.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 11:30:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=UJeR+Nt0; 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-43400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 713DCB24069 for ; Mon, 29 Jan 2024 19:26:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DC1D6F083; Mon, 29 Jan 2024 19:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="UJeR+Nt0" 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 ADACA657A8 for ; Mon, 29 Jan 2024 19:26:23 +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=1706556386; cv=none; b=gz8q6rc4p+RWMGlxYg+RzzHw/r47FtQnWArYIos7R+VhKPHpn69I6h4EjL4xH06wA7ofB1gPMUi0TRB94OFjkI62OJ9jQ0v16Rt7P20GAgKGlPBiq9iZma+9VGkPZO7f0yV+FTIEBcxBaD4n89DF5zUgXzkdAoLm/SwKL5s/Gbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706556386; c=relaxed/simple; bh=eRPRewGUYrmJB7VHNVS88AqNYzIaeHgFC2AnrKWWbtQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JGG6tgTVqPIgmwskbbJuduoKTtjwvZf27ETcVdyNXRbbCWFdP8x8W2rNAxb2EKNvHRCdRS3KtmwbqsZp7juTR6Fdfwug40gvLLoPzdV/dTf3k5gnhk8VkekoPmO4mjGmOPI8xPKrsiwMhHgHvVxoTb1eiEpR+Bl1joNY7CEZNGY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=UJeR+Nt0; arc=none smtp.client-ip=77.93.223.253 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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 26A9619A629; Mon, 29 Jan 2024 20:26:21 +0100 (CET) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=quarantine dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1706556381; bh=eRPRewGUYrmJB7VHNVS88AqNYzIaeHgFC2AnrKWWbtQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UJeR+Nt0DKoETJWrxdRAiyM+J2e/o9p+yX33ckYyEr8foaq6h/iqk49xDD5wY1o73 TOoE9f9UM4Eb6Fai5OB2pvYXq1CXCyQ+uWMgncQjJuogOkW8kor58smy3fc9nw9WfG 9XajgC+9R1MweY7RZjUvPxXTktk0GtGgBEulK+G00D1GVr0c4mry4oj3r5dWIPyL2f 6XiK30IvAedqtMWiP5JE6EruLql3lv+MslXQlz3HCmB0WY9XNhHYc3uBOQs948QDEp HS7lbubyUCoi0H9zn1wHXDHA8A2mFoWrkGtZhJOOflBSqhk40TciR5sZlujSklBC8Z eIqL0S7QG/FhA== Date: Mon, 29 Jan 2024 20:26:19 +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: <20240129202619.69178dea@meshulam.tesarici.cz> In-Reply-To: <20240129184255.GA12631@willie-the-truck> References: <20240126151956.10014-1-will@kernel.org> <20240126172059.48ad7b9f@meshulam.tesarici.cz> <20240129184255.GA12631@willie-the-truck> 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 29 Jan 2024 18:42:55 +0000 Will Deacon wrote: > On Fri, Jan 26, 2024 at 05:20:59PM +0100, Petr Tesa=C5=99=C3=ADk wrote: > > On Fri, 26 Jan 2024 15:19:54 +0000 > > Will Deacon wrote: > > =20 > > > Hi folks, > > >=20 > > > These two patches fix a nasty double allocation problem in swiotlb_al= loc() > > > 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_mas= k). =20 > >=20 > > Welcome to the club. I believe you had to re-discover what I described = here: > >=20 > > https://lore.kernel.org/linux-iommu/20231108101347.77cab795@meshulam.= tesarici.cz/ =20 >=20 > Lucky me... >=20 > > The relevant part would be this: > >=20 > > To sum it up, there are two types of alignment: > >=20 > > 1. specified by a device's min_align_mask; this says how many low > > bits of a buffer's physical address must be preserved, > >=20 > > 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. =20 > >=20 > > Fix for that has been sitting on my TODO list for too long. :-( =20 >=20 > FWIW, it did _used_ to work (or appear to work), so it would be good to > at least get it back to the old behaviour if nothing else. Yes, now that I look at the code, it was probably misunderstanding on my side as to how the three different alignment requirements are supposed to work together. AFAICT your patch addresses everything that has ever worked. The rest needs some more thought, and before I touch this loop again, I'll write a proper test case. Petr T > Anyway, cheers for reviewing the patches. I'll go through your > comments now... >=20 > Will