From nobody Mon Feb 9 19:05:58 2026 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=1630566062; cv=none; d=zohomail.com; s=zohoarc; b=hbR2zYu708s/hUT6ZtE9KaKF+27scjGHIM2BiEj26/FYmJ/XUmT/5MyjxZ05sXtIW7Kup8R1I/zCJP775coSF8Q6f6H77kblbrN8VSd8e5NQUf5Bo1at8TXQhjreU5Z36L0/xngfK1lv5l1DpFLCnI/W9AJrCJCZig0Bd8Hge/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630566062; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=arguNxflA2S+jzgAEya6eTJ5GHl9dYzb/Yt+fBA14Bw=; b=eGeCPw9BccJpxsMYLdBDodnrhoihXGjJHqF9IyVfP+fyihQ7Osv3E6SUyQo6PjNSJR+UvjgHu0PWo40G5wHbMg79ytXmtNzxpY8FG4yK595iz5QQ21dYReJXk0Sd69BUHQqDVoumg2T6PptXqkClhMYXWOQb33MNWFZ+K4yvofI= 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 1630566062261120.8960605145279; Thu, 2 Sep 2021 00:01:02 -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-34-8in48CUXPY2SgyatCrj3lg-1; Thu, 02 Sep 2021 03:01:00 -0400 Received: by mail-wr1-f70.google.com with SMTP id 102-20020adf82ef000000b001576e345169so212977wrc.7 for ; Thu, 02 Sep 2021 00:00:59 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id j20sm820512wrb.5.2021.09.02.00.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 00:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630566061; 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: in-reply-to:in-reply-to:references:references; bh=arguNxflA2S+jzgAEya6eTJ5GHl9dYzb/Yt+fBA14Bw=; b=Tv/9TN9NJGLh480VUVDtWMA2+8hGYhQXl2D38u0Ugr289XCd53FSq3R6Rdfg4vz0Y1nRSy q1yh9X82a09GvoN9ei9JTzXmgju+0wrVwpEWZNqnMSc5PWNfE1lCHPpFF40MfX1fvTN3qS wR8udDMouyLLYv33WaFuDRgP8eUu00E= X-MC-Unique: 8in48CUXPY2SgyatCrj3lg-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:in-reply-to :references:mime-version:content-transfer-encoding; bh=arguNxflA2S+jzgAEya6eTJ5GHl9dYzb/Yt+fBA14Bw=; b=CzvRHWu5ARwEEIYQb0hFtTtaf2oRLsrSwyjwlOjIQOosqEXe+No3OnSM8SzndwjWwJ hCEYNnee8Nuuh2g5emGEksD/z6i3w3tgyfkdxaT2uRIFf2f7o61ddo97lMXGD+wGFZUl 4IrqqZH4C3d123RJTEDA+0ThFs9KBoXFRMSeHvgGXR35Z5Wz0zGfy8pSxbwTINUbFBVG NX7KwCQS8Xe4+HcIf9tHvC1tNtUz+uMLOeo6jXJ0hg2lHXfSLXCYtAlsqMANKJRM8rW0 DxpDvAeFgxfPtxbyPy8CCRJZ4gxZaizmCqzrlxj4iFrZljHd5TjQHXWwV+m31dJDWwnl myog== X-Gm-Message-State: AOAM531K5pOKBEg4NwVLIh3Vmy5I15oWPayua0/Gd7v8Tn04mTAJVqxY Gk4PutLvPEJ8U5iUz4GA6cMPEmDxo7VWGPXYVtW18X4z2fee2SXE97KYchxFCoIy7l8b+jIm83H XjJlerNPe7yrWIQ== X-Received: by 2002:adf:d1a4:: with SMTP id w4mr1776954wrc.233.1630566058894; Thu, 02 Sep 2021 00:00:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwce3M7LpyeIDl7aBBNIHUUHA094XTA5fvajruqoP7By1cxn/DNw3jIgN5FiCaS/c9LeIrCjg== X-Received: by 2002:adf:d1a4:: with SMTP id w4mr1776935wrc.233.1630566058742; Thu, 02 Sep 2021 00:00:58 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Klaus Jensen , Hanna Reitz , Auger Eric , qemu-block@nongnu.org, Stefan Hajnoczi Subject: [PATCH v3 07/11] util/vfio-helpers: Extract qemu_vfio_water_mark_reached() Date: Thu, 2 Sep 2021 09:00:21 +0200 Message-Id: <20210902070025.197072-8-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902070025.197072-1-philmd@redhat.com> References: <20210902070025.197072-1-philmd@redhat.com> 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) X-ZM-MESSAGEID: 1630566064161100001 Extract qemu_vfio_water_mark_reached() for readability, and have it provide an error hint it its Error* handle. Suggested-by: Klaus Jensen Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- util/vfio-helpers.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 77cdec845d9..306b5a83e48 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -721,6 +721,21 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size= , uint64_t *iova) return -ENOMEM; } =20 +/** + * qemu_vfio_water_mark_reached: + * + * Returns %true if high watermark has been reached, %false otherwise. + */ +static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size, + Error **errp) +{ + if (s->high_water_mark - s->low_water_mark + 1 < size) { + error_setg(errp, "iova exhausted (water mark reached)"); + return true; + } + return false; +} + /* Map [host, host + size) area into a contiguous IOVA address space, and = store * the result in @iova if not NULL. The caller need to make sure the area = is * aligned to page size, and mustn't overlap with existing mapping areas (= split @@ -742,7 +757,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, if (mapping) { iova0 =3D mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->h= ost); } else { - if (s->high_water_mark - s->low_water_mark + 1 < size) { + if (qemu_vfio_water_mark_reached(s, size, errp)) { ret =3D -ENOMEM; goto out; } --=20 2.31.1