From patchwork Mon Nov 6 14:59:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 13447085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EC1FC4332F for ; Mon, 6 Nov 2023 15:03:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6C518D001E; Mon, 6 Nov 2023 10:03:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B1C328D0002; Mon, 6 Nov 2023 10:03:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BE5A8D001E; Mon, 6 Nov 2023 10:03:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8CA818D0002 for ; Mon, 6 Nov 2023 10:03:24 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 585C41A075F for ; Mon, 6 Nov 2023 15:03:24 +0000 (UTC) X-FDA: 81427847928.03.958564C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 65CD9180032 for ; Mon, 6 Nov 2023 15:03:10 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NdL9HNXa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of mpatocka@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpatocka@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699282990; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MvbDfj8UoB/iWWxf+0USaZxvp1nymUg9UUSbnVJnGJg=; b=FRd/mHYN95xflJxIRJBTubMNt9oG6foDvKsXSGx96bBzZpQMEMjgOXxa8QZNol5pah0aFW rTKZXynczaRRxUG5F8v4oWId72Bsg+8rp1E2pvEUPOH5s+2uypKkZVuJLtNuMZECda04kS HB8Bk9busuopal3QZXwj1jbUr3Pic1A= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NdL9HNXa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of mpatocka@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpatocka@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699282990; a=rsa-sha256; cv=none; b=CoR3OE1UIO3/J6u5DIu6RH5n9nHfUhLYVXe3lEP9JHfGP+xoAknav6Ls2Y3uN+FDA0Yp4S zQI0DvK9g7nxCkoDLek/+usMsrE38qny6h5DJ2rK7dfM6EAyPAsSCaim9SBmz78zwIcQSr +g9tFIiIY4Fqfy8ZUurWuOHnBKM7A+Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699282989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MvbDfj8UoB/iWWxf+0USaZxvp1nymUg9UUSbnVJnGJg=; b=NdL9HNXajhS3oNHsb+TS4mfYijT9QToTeG5wy1tpILmIIcdx44dcLXNEI8VgE67ObCYFGN rdRIOHKAEPBItw6DAx+YppRZTLtv6lq2aRhfN8FWboiqRbhUdQ15iZAAcbB/f4Xp7xO6Bl fqmx+h5RNMaTgaZlXXHUQ6XIaL6ScN4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-wo667hKyNIaLrPo-Wqz7rg-1; Mon, 06 Nov 2023 09:59:42 -0500 X-MC-Unique: wo667hKyNIaLrPo-Wqz7rg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4D89F811001; Mon, 6 Nov 2023 14:59:40 +0000 (UTC) Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 270FE492BFA; Mon, 6 Nov 2023 14:59:40 +0000 (UTC) Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668) id 0FFB830C72A7; Mon, 6 Nov 2023 14:59:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id 0CADB3FD16; Mon, 6 Nov 2023 15:59:40 +0100 (CET) Date: Mon, 6 Nov 2023 15:59:40 +0100 (CET) From: Mikulas Patocka To: Christoph Hellwig , Juergen Gross , Stefano Stabellini , xen-devel@lists.xenproject.org, iommu@lists.linux.dev cc: Keith Busch , Marek Marczykowski-G'orecki , Jens Axboe , Sagi Grimberg , Jan Kara , Vlastimil Babka , Andrew Morton , Matthew Wilcox , Michal Hocko , stable@vger.kernel.org, regressions@lists.linux.dev, Alasdair Kergon , Mike Snitzer , dm-devel@lists.linux.dev, linux-mm@kvack.org Subject: [PATCH] swiotlb-xen: provide the "max_mapping_size" method In-Reply-To: <20231106071008.GB17022@lst.de> Message-ID: <928b5df7-fada-cf2f-6f6a-257a84547c3@redhat.com> References: <3cb4133c-b6db-9187-a678-11ed8c9456e@redhat.com> <11a9886d-316c-edcd-d6da-24ad0b9a2b4@redhat.com> <20231106071008.GB17022@lst.de> MIME-Version: 1.0 Content-ID: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Queue-Id: 65CD9180032 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: b7cz8c6wpgotwwdzp5gaf39ingksgiiz X-HE-Tag: 1699282990-703952 X-HE-Meta: U2FsdGVkX187faLDsAkaaRYUhIKfa2Cmf7fnx+sLrpOgwlZEgwMHYicb2M+oZLdDkfYFVPDjKRh286338ZK2PN44ovY3782vc8QIRSLooEzaZBPi/MeovnadY82p5gNuSinnXMDqRyT/MyUKZy0NWvTy9PU4JBR6CLGiw5qMTvtnbsYhxOFTxVhQRbfn8U4F+84ZpR0EDeYWoDK6Ocum/Gx9SPQBJ36Vg/Y8rkH+Aupl1QEn/ALa7azg8wO5hwnvaAhtsBhRn70y8k6E6sJ2XHDUGyjDWq9MqghwkKhhLp7QWl2DHzZZBrPmR6DHo9bw16OsMCSYl4rXPw+tNfqkXzB0iKrQNBbjmaKAl8MTAMGuecU5Mn9FZIoLwLvzME5/O251LMAfzdrvDdg+6tOSDcZ4yBTgYdMwh5LsrQN8qsIG6vnxNIEiT3DDCZUytdk2e49zXYm4HV6mcrU/Gq4fX9RWaeRcCB43RCn18Rg7ZDgE3M8Agv7Cj7SJARdBcnJ9W+HLJHjflRFDec9Zvt3A0m1QGd1H66eSuZPWCViUK0+1rhu1CyQw6eJxxTAEzthYDJ3Ijml0svwjorzTyRYhTiFfeOYS4MP+FttvZp4+UjcxZvFU7bN7WW/GetrPx94ZXfxdEOKOo18/7Sx6/V761/qjwbI/mKRl+G33cbSH3E20P3zLNkIZRKA7RaCiyO2+evKqeaEEmBzS1K41EHBhFQ8SS/Ls1Rg21VXjWwGGBzpULV4TjeyFnszNI1JxEiilUdIJ0pjTE/dhVY/NakusBw/8abmt/JF/O3osxDdL56fR37gtYd96n+Z6H0FJXjVfNPGXxTGJw8IomnZhcuSONotq78FVIw59TQ9fSAvGE9n/sOt2nNrnESuJFGIpwVDmDBr4j5cyTbR+1zFX0SwfHuq95CShx8/1FwQk3XBJ/fVhQugPc0QtGJcVDODYHjBadZ71o8Acsfb+KrTDksa mFXvYUeE atBlTTHxswsllCs16IPaOPdxykhETR6/8t2rTOfd27pq65FVVtM75kELGzyuzI3dKgNw0Q/nWz3Fae/tyzaqFj0IBVUAOM6URRXkO8ylvCr6DwbG8MTLktO2OFfcL8mc5dGrdgR1ohlso4GHPqt7XWi7DLJoGup4+g0Ha/p6R9KO4m0vfT4Hn+g6UastsP3c82WQ6obyquFOrw2CqSwu0WgRpQN7IssJxnkWFdI2rT69IX/pXbB0VcSQvJ+pXZKlJ50FDC8AFuyZjlxYrge8rirxSXpmKRpkevWNz8x3KZ3Ro/yzpp9paCegzenUR0b5ohpBYV/uI7Qrm3cfAVzHkFeJFQfgMaV6XRZhy29FylM6sKsRLZjkKFbUZNEW7uYfT6PayK7pdHeRX3BUsZmVYr9p7OlCQgOFX6vZsFp4g6wh+hQM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There's a bug that when using the XEN hypervisor with dm-crypt on NVMe, the kernel deadlocks [1]. The deadlocks are caused by inability to map a large bio vector - dma_map_sgtable always returns an error, this gets propagated to the block layer as BLK_STS_RESOURCE and the block layer retries the request indefinitely. XEN uses the swiotlb framework to map discontiguous pages into contiguous runs that are submitted to the PCIe device. The swiotlb framework has a limitation on the length of a mapping - this needs to be announced with the max_mapping_size method to make sure that the hardware drivers do not create larger mappings. Without max_mapping_size, the NVMe block driver would create large mappings that overrun the maximum mapping size. [1] https://lore.kernel.org/stable/ZTNH0qtmint%2FzLJZ@mail-itl/ Signed-off-by: Mikulas Patocka Reported-by: Marek Marczykowski-Górecki Tested-by: Marek Marczykowski-Górecki Suggested-by: Keith Busch Suggested-by: Christoph Hellwig Cc: stable@vger.kernel.org Acked-by: Keith Busch --- drivers/xen/swiotlb-xen.c | 1 + 1 file changed, 1 insertion(+) Index: linux-stable/drivers/xen/swiotlb-xen.c =================================================================== --- linux-stable.orig/drivers/xen/swiotlb-xen.c 2023-11-03 17:57:18.000000000 +0100 +++ linux-stable/drivers/xen/swiotlb-xen.c 2023-11-06 15:30:59.000000000 +0100 @@ -405,4 +405,5 @@ const struct dma_map_ops xen_swiotlb_dma .get_sgtable = dma_common_get_sgtable, .alloc_pages = dma_common_alloc_pages, .free_pages = dma_common_free_pages, + .max_mapping_size = swiotlb_max_mapping_size, };