Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2018638rdf; Mon, 6 Nov 2023 02:09:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcYAwMqAhjzcohdi4Yw6AKlQp3ReD4Ry16BDYCDhLAGQFZk3/zshVB8sz7KQb9c0ZZmAgD X-Received: by 2002:a05:6e02:164b:b0:357:677e:50e7 with SMTP id v11-20020a056e02164b00b00357677e50e7mr42234644ilu.27.1699265370350; Mon, 06 Nov 2023 02:09:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699265370; cv=none; d=google.com; s=arc-20160816; b=JroWHhwvA7embqvJ8bUNkWa+xZ9cOnmj33bYL2l/Nx5ecxv8N7n+62QLwfh/VLafK+ QWQCoOpZfOEwkyO5HB6ZfQ1ahhSPAtuUDlghRMJrFlFgm6yCCaoZsX4xqhtjpvmioD0M qT5XC1II+hbNUdQFtNQQQD3Q31KaEiTzbUracJErgyZtjWDr7BiQRmzROxaboSXL15s9 A76KoCUBf+Ii8JvnvYDySFfKoQg1P7xHyHwBNVH5zgt8L1sRTtLHcXTeFLAJlB42LPCr 4TwicYNWQlMMYEQg30xN06LwPOTqfmAoTbWCeqhz4BEUDuaQZPbkE8QgfQVL943yumsY Rq8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=r+aarlL2H82YLzRQAyKOowUBNf7+/61K2JZ3ILC5APA=; fh=934VArS2l7oZVlxk19JeiIcO6PMDd8PouxNh/SEm1hg=; b=F/phTXE0jGodNQ5vd6nmM8WIZmvl0VRxwWVQteePKQ/JxskA6Jr3zjVGOMgkfc3t9H baAkkN+q8bhI+N82dlQE86KNBy3ph6mWeBmwcERyHpV6yyB0br2a2y40msYhNE0Dcjve MVyf3s8cNgut9oEaX0KXGYc/EAgy2OGPSAUCH5mOdZmegSUvmB6e6t9mSngNG24hXWxo E5Q/ZbE5SqtNiAgX7KrqSOUNTrPfJPWq10UiyRg9ncdOiEZMd1sgeuCZcxG8XvqI0gbT vK94QeSJkPy/7tRJ//XcMFdXRU59+ZnLEmjnhZBBXRlXLORjAZI4ydfYAJkQObug3UkI Derw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lswr8Tgg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id 11-20020a63020b000000b005b93eb7d322si7539956pgc.481.2023.11.06.02.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 02:09:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lswr8Tgg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3987280A4ACE; Mon, 6 Nov 2023 02:09:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230340AbjKFKJG (ORCPT + 99 others); Mon, 6 Nov 2023 05:09:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230421AbjKFKJD (ORCPT ); Mon, 6 Nov 2023 05:09:03 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E95FD1BF; Mon, 6 Nov 2023 02:08:59 -0800 (PST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A69GR0M022738; Mon, 6 Nov 2023 10:08:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=pp1; bh=r+aarlL2H82YLzRQAyKOowUBNf7+/61K2JZ3ILC5APA=; b=lswr8Tggtlt6v32NsjakaA+fjX2D3IPSntIob56AFlmx2oSl9QAVS8MxMUmhl/A9mx4A /R366vAKFm78uaAjO32knr5UVtX6juEtLrZnJErdECUc13ddd0mI3zVifm1/J1V7g2cT VsG9VPyMHoqdZygCRXaRvKPA4ZhzNl64Pt5sQK2RNcY/g+jPenujQoVIkRxSHCs0fwYk LTwz6YYsFWTgihuDkjzcBRtTfAGwmS5f8HY24zPGISIhhs+gl7o4V/8eJSCii+76SuTC lPIQ0cyhF6ov+4sDNwUigL8d2nN3xPkw3Kn7oA/wvO4IC+wxZLFRvE71wvvs7mW8InfJ Xg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u6uj0n521-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Nov 2023 10:08:28 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3A69Gefb024600; Mon, 6 Nov 2023 10:08:28 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u6uj0n514-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Nov 2023 10:08:27 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3A67qrbe007992; Mon, 6 Nov 2023 10:08:26 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3u60ny8kq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Nov 2023 10:08:26 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A6A8N4422020764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Nov 2023 10:08:23 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B77B20076; Mon, 6 Nov 2023 10:08:23 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9255720075; Mon, 6 Nov 2023 10:08:22 +0000 (GMT) Received: from li-ce58cfcc-320b-11b2-a85c-85e19b5285e0 (unknown [9.171.62.82]) by smtpav03.fra02v.mail.ibm.com (Postfix) with SMTP; Mon, 6 Nov 2023 10:08:22 +0000 (GMT) Date: Mon, 6 Nov 2023 11:08:20 +0100 From: Halil Pasic To: Petr =?UTF-8?B?VGVzYcWZw61r?= Cc: Niklas Schnelle , Christoph Hellwig , Bjorn Helgaas , Marek Szyprowski , Robin Murphy , Petr Tesarik , Ross Lagerwall , linux-pci , linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Matthew Rosato , Halil Pasic Subject: Re: Memory corruption with CONFIG_SWIOTLB_DYNAMIC=y Message-ID: <20231106110820.2bc70130.pasic@linux.ibm.com> In-Reply-To: <20231103214831.26d29f4d@meshulam.tesarici.cz> References: <104a8c8fedffd1ff8a2890983e2ec1c26bff6810.camel@linux.ibm.com> <20231103171447.02759771.pasic@linux.ibm.com> <20231103214831.26d29f4d@meshulam.tesarici.cz> Organization: IBM X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) Content-Type: text/plain; charset=UTF-8 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: uIaTFOuqP_nB6juhOpnD6g8sASr2ro47 X-Proofpoint-GUID: vlRs8r-Z4w7NX1o3vr7N-vTbSUM_1Wgm Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-06_08,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1011 mlxlogscore=802 spamscore=0 malwarescore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311060085 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 06 Nov 2023 02:09:27 -0800 (PST) On Fri, 3 Nov 2023 21:50:53 +0100 Petr Tesařík wrote: > >[...] > > In our case min_align_mask == 0 and a) is thus not applicable, because b) and > > c) we end up with iotlb_align_mask = 0x800. And because orig_add & 0x800 == > > 0x800 but pool->start & 0x800 == 0 and the slot at index i is skipped over. The > > slot 0 is skipped over because it is page aligned, when !!((1UL << PAGE_SHIFT) > > & orig_addr) > > Wait. These mask values can quickly become confusing. Do you mean > iotlb_align_mask == 0xfff? I mean iotlb_align_mask == 0x800. Because of iotlb_align_mask &= ~(IO_TLB_SIZE - 1); in line 994 masks away the 0x7FF part (https://github.com/torvalds/linux/blob/d2f51b3516dade79269ff45eae2a7668ae711b25/kernel/dma/swiotlb.c#L994C2-L994C41) what remains of 0xfff (when PAGE_SHIFT == 12). My idea was to write 0x800 differently with a reference to PAGE_SHIFT, because for a larger PAGE_SHIFT we end up with a different pattern and thus requirement, but didn't really think it through properly because even (1UL << (PAGE_SHIFT- 1)) (which is for PAGE_SHIFT == 12 0x800) does not tell the full story. Because all bits in the interval [PAGE_SHIFT,IO_TLB_SHIFT) matter and not just the most significant one (for PAGE_SHIFT == 12 and IO_TLB_SHIFT == 1 there is just one). Shame on me! Sorry for the confusion! Regards, Halil