From nobody Fri May 17 05:50:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1624267968; cv=none; d=zohomail.com; s=zohoarc; b=SR/Rh8eQ2PpbWlV+0RSnmrJaIzPLamZvaOT75mqBH8l3hlCZImXXeGhLHYuaNpcyE4hS9xJp0F4+fJTVwLTVia1/L/EjNd6AdGzqdM8dEqb5DJkuWIa3va7dG4FTR3DXM9cTNzkOhVYgB+web/LwXB4K9a30bHWGQqrc3uK7PRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624267968; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=f0b6se3TDz1Edzu8h/EAKxwMAMM6tNdPKOeMtXEb59o=; b=DiWmjFbK8qdBB4UGOXae3Z8BQb/wiNhZ9v3eT5WvsUxCJNto3mkHnNUg0yAeo/93xLkPERUeXLxE8Tx1YWz5sXe+h3W5NN+lmfCDDBWK4bf4emZcwdSl+Qbhu33yBMBcWz6EJgn4uTJTZaS+M0ghIrtUZl95SJ9yVlTF+9s/WVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1624267968062216.20039063297384; Mon, 21 Jun 2021 02:32:48 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-dAUzaIC8MgW4HnPzQpKIgw-1; Mon, 21 Jun 2021 05:32:43 -0400 Received: by mail-wr1-f70.google.com with SMTP id q15-20020adfc50f0000b0290111f48b865cso8218842wrf.4 for ; Mon, 21 Jun 2021 02:32:43 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (93.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.93]) by smtp.gmail.com with ESMTPSA id d12sm5337595wrn.69.2021.06.21.02.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 02:32:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624267967; 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: content-transfer-encoding:content-transfer-encoding; bh=f0b6se3TDz1Edzu8h/EAKxwMAMM6tNdPKOeMtXEb59o=; b=LBhsyOMBunWv0jxnvN6aK1jYQWwREInuptj9dIGA0kx5x8mohuNvRUwt304cT0Ix/ofILX LARPpHCd8A8DqXuc7bxzPnzXNlgReYTeutdqpb7wxjnM9VMVvJJ9FV829VLXeLaXr1LwJZ 7TOKTrqyjZwk3lZY6t3VoDVym/DQCjI= X-MC-Unique: dAUzaIC8MgW4HnPzQpKIgw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f0b6se3TDz1Edzu8h/EAKxwMAMM6tNdPKOeMtXEb59o=; b=qXLpj4+orIvVnyMhKrNfoyfPANOt4Nm6jSZya6zkIPGzf4ObRZrh09OBCYV1ZH4Ovp PNzTFlKXqFBQmeMcsFy26Z1pxaIP1mczjhk1yRNzFOsnrWU9xGFoJVP4okLmU5bceNvF 7Bka7r77NT0gsbzicnsKgAZX3BahAcAgSq0q4ZnhKO7R9XzrB84UT5TREMf7X6R3hF9O 3mxfOCyJQHlHfLmzxu1CFuMB87AHhT/7l0IkW5zFUjHeayqwoswrFY6a72lLjMml4oWo owTkckay3eFV2AQH0gOvvHpFS33WwLXVMwXEQyPOOjsNKLTSAaJdgdlX+9P0BYXyd36t J/8w== X-Gm-Message-State: AOAM532D8XGtELuW0sIw8yvY11JknYU/ZmsLttcUe68ekzkJJRbKNFsm Eh4VC9IwH4py/67h02LGGXH2ecRvwF0kjx89QjmWQynYtWSauLvAKvorkBlPRx/UobbNr2fSrfM BKankS/6BY/IHcQ== X-Received: by 2002:a05:600c:4145:: with SMTP id h5mr5778213wmm.108.1624267962192; Mon, 21 Jun 2021 02:32:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhVDmqYqPrJ+z/L1hmDyM+IXCpX+RuIoV30YH1hjsoyzI8KjVezH2dAI3Gv2R1vJ81xPklcg== X-Received: by 2002:a05:600c:4145:: with SMTP id h5mr5778186wmm.108.1624267962007; Mon, 21 Jun 2021 02:32:42 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Max Reitz , Maxim Levitsky , Fam Zheng , Kevin Wolf , Stefan Hajnoczi , Eric Auger , Alex Williamson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org, =?UTF-8?q?Michal=20Pr=C3=ADvozn=C3=ADk?= Subject: [PATCH v2] block/nvme: Fix VFIO_MAP_DMA failed: No space left on device Date: Mon, 21 Jun 2021 11:32:40 +0200 Message-Id: <20210621093240.4170701-1-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) When the NVMe block driver was introduced (see commit bdd6a90a9e5, January 2018), Linux VFIO_IOMMU_MAP_DMA ioctl was only returning -ENOMEM in case of error. The driver was correctly handling the error path to recycle its volatile IOVA mappings. To fix CVE-2019-3882, Linux commit 492855939bdb ("vfio/type1: Limit DMA mappings per container", April 2019) added the -ENOSPC error to signal the user exhausted the DMA mappings available for a container. The block driver started to mis-behave: qemu-system-x86_64: VFIO_MAP_DMA failed: No space left on device (qemu) (qemu) info status VM status: paused (io-error) (qemu) c VFIO_MAP_DMA failed: No space left on device qemu-system-x86_64: block/block-backend.c:1968: blk_get_aio_context: Asse= rtion `ctx =3D=3D blk->ctx' failed. Fix by handling the new -ENOSPC error (when DMA mappings are exhausted) without any distinction to the current -ENOMEM error, so we don't change the behavior on old kernels where the CVE-2019-3882 fix is not present. An easy way to reproduce this bug is to restrict the DMA mapping limit (65535 by default) when loading the VFIO IOMMU module: # modprobe vfio_iommu_type1 dma_entry_limit=3D666 Cc: qemu-stable@nongnu.org Reported-by: Michal Pr=C3=ADvozn=C3=ADk Fixes: bdd6a90a9e5 ("block: Add VFIO based NVMe driver") Buglink: https://bugs.launchpad.net/qemu/+bug/1863333 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/65 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Fam Zheng --- v2: KISS checking both errors undistinguishedly (Maxim) --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 2b5421e7aa6..c3d2a49866c 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1030,7 +1030,7 @@ try_map: r =3D qemu_vfio_dma_map(s->vfio, qiov->iov[i].iov_base, len, true, &iova); - if (r =3D=3D -ENOMEM && retry) { + if ((r =3D=3D -ENOMEM || r =3D=3D -ENOSPC) && retry) { retry =3D false; trace_nvme_dma_flush_queue_wait(s); if (s->dma_map_count) { --=20 2.31.1