From nobody Sun Apr 19 13:43:32 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 C52B3C43334 for ; Thu, 30 Jun 2022 15:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235853AbiF3Pcf (ORCPT ); Thu, 30 Jun 2022 11:32:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235422AbiF3Pcd (ORCPT ); Thu, 30 Jun 2022 11:32:33 -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 E1DC43DDDB for ; Thu, 30 Jun 2022 08:32:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656603151; 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=rRre2mmiUkpHj1mcdypLppTGL5vL6JLZXVbGfJnDALg=; b=OQ4u4Nh0FDZDABTecc6CHcgtW+jyslG3ctatVGBLz9NZT2Dlh1iefhCduo9m8evMbxLdMh mGkiTXtV4FrbW7T4Ho5GKXLC7aTz2l0YL7YmeDR/5Dg52Idm9v8yVJAZA/MUyQb2CpnHNP uRZBUNNRYR3/PVT0eTwS9wNFmglYHLM= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-360-9sevPzYQMLOayiV0NYkCng-1; Thu, 30 Jun 2022 11:32:29 -0400 X-MC-Unique: 9sevPzYQMLOayiV0NYkCng-1 Received: by mail-qv1-f70.google.com with SMTP id e10-20020a0ce3ca000000b004702b8819beso18719456qvl.4 for ; Thu, 30 Jun 2022 08:32:29 -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=rRre2mmiUkpHj1mcdypLppTGL5vL6JLZXVbGfJnDALg=; b=kcOpQDlePHAJIBtEb9s/F2pxOKkr3kBV1gEVIzvbIM5gotyzlQ28T1nlJW+NkAU1tL e7uzaMSnuRqCXV34SW1UnpZmoU5Pj/eSTfr8CAOlH6kAevSVox2bIe1D6n8Vzs20sxog ymye3HkiuZQbjjxPq18HONcpHAsMHC+IU6YReL/j2L7ZbYC7ip1bm5OpFa6P9oUQvqX3 MqpMbovsEk95P2S7ZW83npx7J4KShTeFG4upmSYoYJQ7VKE39n5iMGxJzNVQbzKkclSx wVdcskxJ2jKYidAs0DHA5tnXD5g69HMMAsl2Agtu1hiCcWJWIBwFOy2OlubwgPRVugs0 SSQw== X-Gm-Message-State: AJIora/4fXQMJ3q3RTHDAmXf4kluc2/TaHGabikVZ2NEUFPBynqD2z6l DDCX42+AmL2e3ssSY/Nc52CDvDvLUYNk6pZ5issCWPBb04Jod9NMLHqIR7lOhP9FOYek58YkjMB ToCCJjWKekNy64I1LOj7vtOBm X-Received: by 2002:a05:620a:40cf:b0:6b1:41dd:9710 with SMTP id g15-20020a05620a40cf00b006b141dd9710mr6329771qko.727.1656603149351; Thu, 30 Jun 2022 08:32:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tAcFYzWpyw+b6fujbaqZt6VZhUiFDHom86OOiiyoqB6cQlPZGEL6VrqMoaZqdOzN2T9zXkXA== X-Received: by 2002:a05:620a:40cf:b0:6b1:41dd:9710 with SMTP id g15-20020a05620a40cf00b006b141dd9710mr6329749qko.727.1656603149110; Thu, 30 Jun 2022 08:32:29 -0700 (PDT) Received: from step1.redhat.com (host-87-11-6-149.retail.telecomitalia.it. [87.11.6.149]) by smtp.gmail.com with ESMTPSA id y20-20020a05620a44d400b006af0639f7casm16089325qkp.12.2022.06.30.08.32.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 08:32:28 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [PATCH v2 1/3] vdpa_sim_blk: use dev_dbg() to print errors Date: Thu, 30 Jun 2022 17:32:19 +0200 Message-Id: <20220630153221.83371-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220630153221.83371-1-sgarzare@redhat.com> References: <20220630153221.83371-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 Acked-by: Jason Wang Signed-off-by: Stefano Garzarella --- 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 19 13:43:32 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 79C51CCA47B for ; Thu, 30 Jun 2022 15:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235893AbiF3Pcn (ORCPT ); Thu, 30 Jun 2022 11:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235866AbiF3Pch (ORCPT ); Thu, 30 Jun 2022 11:32:37 -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 853AD3E0E9 for ; Thu, 30 Jun 2022 08:32:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656603155; 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=YJ2kJ9M3J473925A1Sz+6DavMX+WtsWN9FnXUNFiskQ=; b=HKNvjVWLlf7aKwZqCy7lihLm0rTY86mSLzFhto+6KgXSrbJQMd7TTivOSAnRCyxMFUJ7H2 e8XMDhnVvACV9A9lyn5y1hqUR5a6mkn6s7Pcc0JinHsdamhe1ZwUMlT2hjGT2t2s3Xm5aQ bt3M0vEc1DpgK/PkmfVFgjynvkc2r7s= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-64--ctdSa9bO9GcFTH-5sRXTg-1; Thu, 30 Jun 2022 11:32:33 -0400 X-MC-Unique: -ctdSa9bO9GcFTH-5sRXTg-1 Received: by mail-qv1-f70.google.com with SMTP id j6-20020a05621419c600b004704e6665caso18676325qvc.6 for ; Thu, 30 Jun 2022 08:32:33 -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=YJ2kJ9M3J473925A1Sz+6DavMX+WtsWN9FnXUNFiskQ=; b=bj/qsDub7uXNif6wvd6J+QkXMEJ/C8PYPmhj9851tHvBYfGNiN1pYVVAoh486EFoXm IIMrHxMHwSDeSVmUqgpRsS/ChENjbLrIDn/rdcynvJs31QvC7hY+tdRx9XFlxAjHRz+m iR2ZRNsDKxYO5UqwHQ6waAI6tCGG4CmBpkGtXtned6VDfPjLuzxR7UTMG9tAC7bQt2/n +qXL/5D7P+q5GNON74DoZu50CSg0KIXyAirOXhQeEE4sJRmU3HqwIJU0C5Ago2AShfjf C+BG5nqzc35UF1lvWdZby/4CadFA8VNihnjXcQE7YtvRlc63t246XX5TnSbqOwNSEA3l R/xg== X-Gm-Message-State: AJIora+EFAWyAVWjG3N+664quwcqLBloZb2NcG3dExhGqRtWMgkj6hU9 s07nlLUOIrZ31dsBdeiL/OLSiW9zw833vRl/1XAoS8Cd1eN3PyG2U04gFiRoBZ3cVMepJXDNJut J8FQnR0SIsfDa+Yl6hyjS71yJ X-Received: by 2002:a05:6214:2307:b0:46e:5fbc:3c30 with SMTP id gc7-20020a056214230700b0046e5fbc3c30mr12691619qvb.21.1656603152643; Thu, 30 Jun 2022 08:32:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1syyg6jTK7iMokKvzkf30z0DmBsGln/1Z2e4Epr35QPBJLcZ3UXJlIecbQRWimM+K/3INQ4BQ== X-Received: by 2002:a05:6214:2307:b0:46e:5fbc:3c30 with SMTP id gc7-20020a056214230700b0046e5fbc3c30mr12691583qvb.21.1656603152249; Thu, 30 Jun 2022 08:32:32 -0700 (PDT) Received: from step1.redhat.com (host-87-11-6-149.retail.telecomitalia.it. [87.11.6.149]) by smtp.gmail.com with ESMTPSA id y20-20020a05620a44d400b006af0639f7casm16089325qkp.12.2022.06.30.08.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 08:32:31 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [PATCH v2 2/3] vdpa_sim_blk: limit the number of request handled per batch Date: Thu, 30 Jun 2022 17:32:20 +0200 Message-Id: <20220630153221.83371-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220630153221.83371-1-sgarzare@redhat.com> References: <20220630153221.83371-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 Acked-by: Jason Wang --- v2: - restored previous behaviour, exiting the loop immediately if the request is malformed [Jason] --- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_blk.c index a83a5c76f620..b2d75efec63a 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,6 +207,7 @@ 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]; + int reqs =3D 0; =20 if (!vq->ready) continue; @@ -218,10 +220,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) { + reschedule =3D true; + break; + } } } 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 19 13:43:32 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 CE6C5C43334 for ; Thu, 30 Jun 2022 15:32:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235923AbiF3Pcr (ORCPT ); Thu, 30 Jun 2022 11:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235885AbiF3Pcj (ORCPT ); Thu, 30 Jun 2022 11:32:39 -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 5C4DD3E5F5 for ; Thu, 30 Jun 2022 08:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656603157; 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=zyBXlP1VN/1Hl0hvlI7YsnhG2HRfml5jOvtsaK2qf2k=; b=B/KcYY2shGmNtfcDC2cc0d/vN6gQ6EI07j6yk3ZYPZ5zPRk350+BJIMs4irQxflqwCa67K pWuLDIw1e3YNCEaheSlPWaNc/SuRXkcM7xWNv2kyzCIfHUuKqpYiqFCDe4wVLpsuD+bXvd s/e1Ayb8HBs2Ezw/JS6mIDow5Tl8DSw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-D0PnVWjNOQCqgGSK4tHyyw-1; Thu, 30 Jun 2022 11:32:36 -0400 X-MC-Unique: D0PnVWjNOQCqgGSK4tHyyw-1 Received: by mail-qv1-f72.google.com with SMTP id u18-20020a0cf1d2000000b00470427ccfa5so18699703qvl.18 for ; Thu, 30 Jun 2022 08:32:35 -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=zyBXlP1VN/1Hl0hvlI7YsnhG2HRfml5jOvtsaK2qf2k=; b=d1doogTgvh/1+C6lH332mzHNvmrb5ebsNyKv0B3V5VbesG/5HaGAHggz4u00IcGaxt 2dci0Nszab7eZYis2aXSnifrDnC/ColOEGEDicpxxrXyp+0y8/4eC1hlMWTSXZMq8a/j uJTkQezt9n2uL64YlcjJPnB0dTDEbOWYOIH4qg5AojYJy4w4o1WZ1fU7pgAKU6syWE8N qy3WEwRiWUFhmGqoIu/bBKZhMig4QnJEFvnlrfhXOXiEox1McqjJGmXA2u+ivPYUaiSI glDaFRloh71G9JlspefzTxiAJywYhtJ0EqQU5GHm7xUwPzg29dSMvI/Snmo7PUuoj++z HMYA== X-Gm-Message-State: AJIora+8sEX4J3eUIp/xu43kv5UIHAA6FuSc/Lk0JFdf8XsytgVg7JX7 wbenj/8H9YXnj3EhpornJgL26hTBuBqjLZiyFDe87teZKwLrQrDwSkM6g6DL//JTnIoNADZzlC7 071qyN41LVpgtU21dK/BMgn1d X-Received: by 2002:a05:620a:270b:b0:6af:18bb:277c with SMTP id b11-20020a05620a270b00b006af18bb277cmr6751637qkp.510.1656603155409; Thu, 30 Jun 2022 08:32:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vTc+Nr9zLyCxjBRj8LAHRagLUk1vEK4xwZW8noBEmXngs6Q+g5xoMvq7ks4Sz5hZUgCP5u0A== X-Received: by 2002:a05:620a:270b:b0:6af:18bb:277c with SMTP id b11-20020a05620a270b00b006af18bb277cmr6751612qkp.510.1656603155026; Thu, 30 Jun 2022 08:32:35 -0700 (PDT) Received: from step1.redhat.com (host-87-11-6-149.retail.telecomitalia.it. [87.11.6.149]) by smtp.gmail.com with ESMTPSA id y20-20020a05620a44d400b006af0639f7casm16089325qkp.12.2022.06.30.08.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 08:32:34 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [PATCH v2 3/3] vdpa_sim_blk: call vringh_complete_iotlb() also in the error path Date: Thu, 30 Jun 2022 17:32:21 +0200 Message-Id: <20220630153221.83371-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220630153221.83371-1-sgarzare@redhat.com> References: <20220630153221.83371-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. Acked-by: Jason Wang Signed-off-by: Stefano Garzarella --- 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 b2d75efec63a..43422b3854d2 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