From nobody Sun Apr 26 22:57:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0918C433EF for ; Tue, 21 Jun 2022 16:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353657AbiFUQJW (ORCPT ); Tue, 21 Jun 2022 12:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353740AbiFUQJQ (ORCPT ); Tue, 21 Jun 2022 12:09:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BD9F22DAA7 for ; Tue, 21 Jun 2022 09:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827746; 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=QwdoYcSexrOCzV1teWJ7RyQQyOgHsOoOsUPcLIRzoFM=; b=VBqKbmtnn78BqU52r6XPrKrm133FzkCRmI+bknxwa2L25nB7UJfduHsjL/WWzYedoWBgf5 +T3bgGFO8L8+oc+ihgsSzHL9QkZtc9aSRJ6wJuT6/1Bb1xGyaid0qSkI5JC1o7MI2h7WZZ DP6LZ3A8Hh8UhUN88vWnjzeb1drBW3U= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-259-Ir05w2w4Ns2RmbY2blr5gw-1; Tue, 21 Jun 2022 12:09:05 -0400 X-MC-Unique: Ir05w2w4Ns2RmbY2blr5gw-1 Received: by mail-wm1-f71.google.com with SMTP id i188-20020a1c3bc5000000b0039db971c6d9so7336932wma.7 for ; Tue, 21 Jun 2022 09:09:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QwdoYcSexrOCzV1teWJ7RyQQyOgHsOoOsUPcLIRzoFM=; b=mNJOY9OwTyxHq3r9tsRohJBJJ/2qAHZRCsqmNP8Ff+CfdWOLJlqTMuS7/2Yk9eoDay 2tsomzEsz/sDM5bpK6DzuirgxWcuwsY+P1ifX9ZGaL+GofL3OEJ+XlEDhb61hYfT+1yz VpaFewjvVua445KC8W5KYZp8tX3GWx4MJ/K1OlJKSUIK57qEtERp2VUc52sIs78kUG3g X3ICt8HVbQLJcweSBtQvgnKYc3s7NOPsfQRklRqilrKfTrvisqeLyf6C6e4kCIFPWUmR TQfGUMhtzA7V1AcM5kZzmUQGHTIuKLptooWOMmEHTKYS/VafUXoU/X/8zA+KFGtIH56C e+Sw== X-Gm-Message-State: AJIora9oCdwPSgp+5Z1uhYRfYyQCdTik7chuHU+Tox3RaD3rD7LOa19Z 6zqk2yytCfdNdDEGpJ3gZuLD8u4FH9VF6U+qMJ+IqmpZIwiuyCD+lCOYLJpI6Imb3HTLTj1jQwt MeIbc6zBMw9ZZ0Ze8kjKwZZbS X-Received: by 2002:a05:600c:3489:b0:39d:b58f:6797 with SMTP id a9-20020a05600c348900b0039db58f6797mr31017434wmq.205.1655827744244; Tue, 21 Jun 2022 09:09:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vtz1/kwO2GKBAW1YJVuUDOT0/wuEhfMdbVmbF7WpAqjGTrMqa7Xyd1gz62UtYc+FOogELr3Q== X-Received: by 2002:a05:600c:3489:b0:39d:b58f:6797 with SMTP id a9-20020a05600c348900b0039db58f6797mr31017415wmq.205.1655827743985; Tue, 21 Jun 2022 09:09:03 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-40.retail.telecomitalia.it. [79.46.200.40]) by smtp.gmail.com with ESMTPSA id ba7-20020a0560001c0700b0021b903a018bsm6531560wrb.92.2022.06.21.09.09.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 09:09:03 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, Stefano Garzarella Subject: [PATCH 1/3] vdpa_sim_blk: use dev_dbg() to print errors Date: Tue, 21 Jun 2022 18:08:57 +0200 Message-Id: <20220621160859.196646-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621160859.196646-1-sgarzare@redhat.com> References: <20220621160859.196646-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use dev_dbg() instead of dev_err()/dev_warn() to avoid flooding the host with prints, when the guest driver is misbehaving. In this way, prints can be dynamically enabled when the vDPA block simulator is used to validate a driver. Suggested-by: Jason Wang Signed-off-by: Stefano Garzarella Acked-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_blk.c index 42d401d43911..a83a5c76f620 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -76,13 +76,13 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, return false; =20 if (vq->out_iov.used < 1 || vq->in_iov.used < 1) { - dev_err(&vdpasim->vdpa.dev, "missing headers - out_iov: %u in_iov %u\n", + dev_dbg(&vdpasim->vdpa.dev, "missing headers - out_iov: %u in_iov %u\n", vq->out_iov.used, vq->in_iov.used); return false; } =20 if (vq->in_iov.iov[vq->in_iov.used - 1].iov_len < 1) { - dev_err(&vdpasim->vdpa.dev, "request in header too short\n"); + dev_dbg(&vdpasim->vdpa.dev, "request in header too short\n"); return false; } =20 @@ -96,7 +96,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasi= m, bytes =3D vringh_iov_pull_iotlb(&vq->vring, &vq->out_iov, &hdr, sizeof(hdr)); if (bytes !=3D sizeof(hdr)) { - dev_err(&vdpasim->vdpa.dev, "request out header too short\n"); + dev_dbg(&vdpasim->vdpa.dev, "request out header too short\n"); return false; } =20 @@ -110,7 +110,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, switch (type) { case VIRTIO_BLK_T_IN: if (!vdpasim_blk_check_range(sector, to_push)) { - dev_err(&vdpasim->vdpa.dev, + dev_dbg(&vdpasim->vdpa.dev, "reading over the capacity - offset: 0x%llx len: 0x%zx\n", offset, to_push); status =3D VIRTIO_BLK_S_IOERR; @@ -121,7 +121,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, vdpasim->buffer + offset, to_push); if (bytes < 0) { - dev_err(&vdpasim->vdpa.dev, + dev_dbg(&vdpasim->vdpa.dev, "vringh_iov_push_iotlb() error: %zd offset: 0x%llx len: 0x%zx\n", bytes, offset, to_push); status =3D VIRTIO_BLK_S_IOERR; @@ -133,7 +133,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, =20 case VIRTIO_BLK_T_OUT: if (!vdpasim_blk_check_range(sector, to_pull)) { - dev_err(&vdpasim->vdpa.dev, + dev_dbg(&vdpasim->vdpa.dev, "writing over the capacity - offset: 0x%llx len: 0x%zx\n", offset, to_pull); status =3D VIRTIO_BLK_S_IOERR; @@ -144,7 +144,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, vdpasim->buffer + offset, to_pull); if (bytes < 0) { - dev_err(&vdpasim->vdpa.dev, + dev_dbg(&vdpasim->vdpa.dev, "vringh_iov_pull_iotlb() error: %zd offset: 0x%llx len: 0x%zx\n", bytes, offset, to_pull); status =3D VIRTIO_BLK_S_IOERR; @@ -157,7 +157,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, vdpasim_blk_id, VIRTIO_BLK_ID_BYTES); if (bytes < 0) { - dev_err(&vdpasim->vdpa.dev, + dev_dbg(&vdpasim->vdpa.dev, "vringh_iov_push_iotlb() error: %zd\n", bytes); status =3D VIRTIO_BLK_S_IOERR; break; @@ -167,8 +167,8 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, break; =20 default: - dev_warn(&vdpasim->vdpa.dev, - "Unsupported request type %d\n", type); + dev_dbg(&vdpasim->vdpa.dev, + "Unsupported request type %d\n", type); status =3D VIRTIO_BLK_S_IOERR; break; } --=20 2.36.1 From nobody Sun Apr 26 22:57:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E5D1C43334 for ; Tue, 21 Jun 2022 16:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353796AbiFUQJ0 (ORCPT ); Tue, 21 Jun 2022 12:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353760AbiFUQJT (ORCPT ); Tue, 21 Jun 2022 12:09:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4FC0E2E081 for ; Tue, 21 Jun 2022 09:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827749; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+bAhmFC/hjGzAWfV3jJm6JhUFvDtTISGABduARBAGlA=; b=e6Ypuf3EsqI4IwKi4Fp1It6nDNcar9Z02vQugp/pUWnw1cPPTvsx4UHFThi4JVwe5FrAXV PGQq3HsblU5b96zkTGaBhKoNK2xyjORDU2uKMF99/BdQWqN7y2TUh2pvS9e21rRbdXPWGD LRQ7jeOwpUMdORJsexbKmqr5EEDE2Sk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-588-VRfi1tzjO0mxScI7HTA63w-1; Tue, 21 Jun 2022 12:09:08 -0400 X-MC-Unique: VRfi1tzjO0mxScI7HTA63w-1 Received: by mail-wm1-f69.google.com with SMTP id m23-20020a05600c3b1700b0039c6e3c169aso6596619wms.2 for ; Tue, 21 Jun 2022 09:09:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+bAhmFC/hjGzAWfV3jJm6JhUFvDtTISGABduARBAGlA=; b=cBXlsuzTIzMr825OkDT70Xgnwue7+o13aw+k/ho1m9KTY9g25+rWcvxGhU33+Ah4xj QwM2/ov7HBeFchJ+M6T6heo5I5A77HrD+wJ3BbwHk8v4PCot+jsHA1qHKVBcX2Kkkce5 osiP3/zdNKxP8oPObyLi1mLUKZTWquJGHfqM3z207/pXxCsiAPM3N+5D5ZF0NQJP5Wpo 8tQtkoXR73XF+JI2DaFS7pWg7agHoC7+6XTFt3BT4bVEpEmMatCh0twhz1/oFXrTN5uc sVAyoGfPNzweyGmGjtaRjUNWBZS5gb5pobfCCLtQX/lJg0EMCzh9KnyaPXVrVDiCDl47 6YNQ== X-Gm-Message-State: AOAM533wD8BuqMcF1id8mGh6Lv5alpwt5uZIGdv7z/q0A6LwEisekMiP PgE7+w2RnyMjeHDadAwPdLdmGtyu66RhdTPBWr7qz/QrPBZXTmjoUAx7eJRSNNn70Z3gX17GATK JFD7oEJlqTCzdNdu17RLOoLvj X-Received: by 2002:a05:600c:42c9:b0:39c:3808:5479 with SMTP id j9-20020a05600c42c900b0039c38085479mr41301674wme.4.1655827746250; Tue, 21 Jun 2022 09:09:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3l84ij+5Pi9MrXnI7nrsOXu5NGSIn7YSrgA1eUFOkpS4ItURWuYfMpqa4odA2HMkGBOrEKQ== X-Received: by 2002:a05:600c:42c9:b0:39c:3808:5479 with SMTP id j9-20020a05600c42c900b0039c38085479mr41301654wme.4.1655827746039; Tue, 21 Jun 2022 09:09:06 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-40.retail.telecomitalia.it. [79.46.200.40]) by smtp.gmail.com with ESMTPSA id ba7-20020a0560001c0700b0021b903a018bsm6531560wrb.92.2022.06.21.09.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 09:09:05 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, Stefano Garzarella Subject: [PATCH 2/3] vdpa_sim_blk: limit the number of request handled per batch Date: Tue, 21 Jun 2022 18:08:58 +0200 Message-Id: <20220621160859.196646-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621160859.196646-1-sgarzare@redhat.com> References: <20220621160859.196646-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Limit the number of requests (4 per queue as for vdpa_sim_net) handled in a batch to prevent the worker from using the CPU for too long. Suggested-by: Eugenio P=C3=A9rez Signed-off-by: Stefano Garzarella --- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_blk.c index a83a5c76f620..ac86478845b6 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -197,6 +197,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, static void vdpasim_blk_work(struct work_struct *work) { struct vdpasim *vdpasim =3D container_of(work, struct vdpasim, work); + bool reschedule =3D false; int i; =20 spin_lock(&vdpasim->lock); @@ -206,11 +207,15 @@ static void vdpasim_blk_work(struct work_struct *work) =20 for (i =3D 0; i < VDPASIM_BLK_VQ_NUM; i++) { struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[i]; + bool vq_work =3D true; + int reqs =3D 0; =20 if (!vq->ready) continue; =20 - while (vdpasim_blk_handle_req(vdpasim, vq)) { + while (vq_work) { + vq_work =3D vdpasim_blk_handle_req(vdpasim, vq); + /* Make sure used is visible before rasing the interrupt. */ smp_wmb(); =20 @@ -218,10 +223,18 @@ static void vdpasim_blk_work(struct work_struct *work) if (vringh_need_notify_iotlb(&vq->vring) > 0) vringh_notify(&vq->vring); local_bh_enable(); + + if (++reqs > 4) { + vq_work =3D false; + reschedule =3D true; + } } } out: spin_unlock(&vdpasim->lock); + + if (reschedule) + schedule_work(&vdpasim->work); } =20 static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config) --=20 2.36.1 From nobody Sun Apr 26 22:57:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C797ECCA473 for ; Tue, 21 Jun 2022 16:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353853AbiFUQNO (ORCPT ); Tue, 21 Jun 2022 12:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353913AbiFUQND (ORCPT ); Tue, 21 Jun 2022 12:13:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0633CEB5 for ; Tue, 21 Jun 2022 09:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827981; 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=Us38wkS1w1HtLwDGe0amETwreFLuOach8d2EKXd31Cw=; b=GsxuVcuUVajaIt6OwoHzXwOFIwWpMwsca4qTB/IV7xw40N/9J90p4vpJp4mpW/C1z5vqpd 360bUErhkUx9SXmVwvwU2atspAc5WgP3IdANAWmHBU+OOJVOhtnqpzNfEuTidIXCErFY7L D7yD2WZbuB8XOTmXnwRVi2gXusX7vig= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-36ubX7ofPSSvIJYNNNsjHw-1; Tue, 21 Jun 2022 12:13:00 -0400 X-MC-Unique: 36ubX7ofPSSvIJYNNNsjHw-1 Received: by mail-qk1-f200.google.com with SMTP id ay8-20020a05620a178800b006a76e584761so16890391qkb.13 for ; Tue, 21 Jun 2022 09:13:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Us38wkS1w1HtLwDGe0amETwreFLuOach8d2EKXd31Cw=; b=ixTDcBQgXRbDZrJqpWnxjJQUesMTZx6BHOInNOOvnzTwDogpTgcQhTEAWZKJmDzyyB h8G/tFK72ijJD8Y70t3d/u4TF8Ye6uHI0bIdywXyCsoffu1qhRIU4Tiu+hV5O1KMHEmg HMyejy94sG7/+MNQYL0J8zKzNKx7FGRi9JCn+1HhfI0Do5OgpJKOZVNKLwEY+b4QRQ2t uQknwJvP5pXBBcafD8eJu2X/wSgg9MzVxhNOgmK9B9f2/907R5Zx/O0rXUZVBuFaEPoc SKSUk3vZU8tnaYWD8FECiwDu+s/iBkU+Wk4OvaFq+TPvDkTnKbS+0YK/xIjEpWyAzbV+ lB0w== X-Gm-Message-State: AJIora+CG9RXJp/r7CBlnA+fJBy9rtyqvRjlvXvE4Bv0myUxZS1yZU2x 6ZYopUD2dTkF0e2WK9oonpD5JYkmBIczG/0UQZ+4xT14/Oc+5f7K+qzbq/ObhckFLGojak+rqf5 wm6i9UN15Po2FivEg+pqR/h0P X-Received: by 2002:a05:6214:260c:b0:470:4ef5:7148 with SMTP id gu12-20020a056214260c00b004704ef57148mr5662127qvb.64.1655827978822; Tue, 21 Jun 2022 09:12:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tvrFRrNcJ+au4R/VYre6s+gKDS5BiaCvxaBCHNWnLGeGFqTWc18xHBZcCYjImLqyQYkzHdrQ== X-Received: by 2002:a05:6214:260c:b0:470:4ef5:7148 with SMTP id gu12-20020a056214260c00b004704ef57148mr5662096qvb.64.1655827978503; Tue, 21 Jun 2022 09:12:58 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-40.retail.telecomitalia.it. [79.46.200.40]) by smtp.gmail.com with ESMTPSA id 20-20020ac85754000000b002f93554c009sm11663915qtx.59.2022.06.21.09.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 09:12:57 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [PATCH 3/3] vdpa_sim_blk: call vringh_complete_iotlb() also in the error path Date: Tue, 21 Jun 2022 18:12:52 +0200 Message-Id: <20220621161252.197173-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621160859.196646-1-sgarzare@redhat.com> References: <20220621160859.196646-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Call vringh_complete_iotlb() even when we encounter a serious error that prevents us from writing the status in the "in" header (e.g. the header length is incorrect, etc.). The guest is misbehaving, so maybe the ring is in a bad state, but let's avoid making things worse. Signed-off-by: Stefano Garzarella Acked-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_blk.c index ac86478845b6..de9cd9843143 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -63,6 +63,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasi= m, { size_t pushed =3D 0, to_pull, to_push; struct virtio_blk_outhdr hdr; + bool handled =3D false; ssize_t bytes; loff_t offset; u64 sector; @@ -78,12 +79,12 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, if (vq->out_iov.used < 1 || vq->in_iov.used < 1) { dev_dbg(&vdpasim->vdpa.dev, "missing headers - out_iov: %u in_iov %u\n", vq->out_iov.used, vq->in_iov.used); - return false; + goto err; } =20 if (vq->in_iov.iov[vq->in_iov.used - 1].iov_len < 1) { dev_dbg(&vdpasim->vdpa.dev, "request in header too short\n"); - return false; + goto err; } =20 /* The last byte is the status and we checked if the last iov has @@ -97,7 +98,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasi= m, sizeof(hdr)); if (bytes !=3D sizeof(hdr)) { dev_dbg(&vdpasim->vdpa.dev, "request out header too short\n"); - return false; + goto err; } =20 to_pull -=3D bytes; @@ -182,16 +183,19 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vd= pasim, /* Last byte is the status */ bytes =3D vringh_iov_push_iotlb(&vq->vring, &vq->in_iov, &status, 1); if (bytes !=3D 1) - return false; + goto err; =20 pushed +=3D bytes; =20 /* Make sure data is wrote before advancing index */ smp_wmb(); =20 + handled =3D true; + +err: vringh_complete_iotlb(&vq->vring, vq->head, pushed); =20 - return true; + return handled; } =20 static void vdpasim_blk_work(struct work_struct *work) --=20 2.36.1