From nobody Mon May 6 04:26:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1629998828; cv=none; d=zohomail.com; s=zohoarc; b=WI7wDjv2eQeOoJag+fsNeIMxkJ2D4GINODI3elKzG8WpDvK6bTgVgUgpjp9/EyRzrf0cyR5NxZmHXhifibNZLrFEeU034K+aIbPfO93x1D7l5b5dL0Ye87XSB+6NCe3U90j98MO9Bpnv1D3GsoDt62JG5Efkgb+jmSVulvrdIC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629998828; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=6H+L02mu2VtYZ9Ci4vq9bPbkxedEevnpYIa7Jf3+z/I=; b=mmT83V7c7nSx98rZ4cMRPAsXAjG82atg+pWRDh9rK0Mz6H3bqHH0fFlyrbi4qUrrNjyIGsD9PjgEcG8BnnLs3Q3WURKA0jIuDGcSV0rpsUFnuqJyQpwab5H7jouwia/XSo6zf5C0hx0bR8ZmsFYinM4FD5oVzeygqBbtaAcm0VA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629998828444711.9813609162545; Thu, 26 Aug 2021 10:27:08 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-529-cdQteZkTMbmm9Hdqr8yUGQ-1; Thu, 26 Aug 2021 13:27:06 -0400 Received: by mail-wm1-f71.google.com with SMTP id m22-20020a7bca56000000b002e7508f3faeso1180030wml.2 for ; Thu, 26 Aug 2021 10:27:05 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id o12sm3774338wro.51.2021.08.26.10.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 10:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629998827; 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=6H+L02mu2VtYZ9Ci4vq9bPbkxedEevnpYIa7Jf3+z/I=; b=iKXJ1XPrErwt0ac40In1fs3GgTd5BZFzrs0hWJVRMBeVRc+IW5w/Ozd2nV/tBtg/XaY7OS JmQ9ugppX5QfqP4gCUZo11ure1O4xoJnGBA6nIiyzpZ9vsDh81NBySyEOox491pAedJbpI Rl23tyL9YDeYkYlQFyOfVq2K0H5lQag= X-MC-Unique: cdQteZkTMbmm9Hdqr8yUGQ-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=6H+L02mu2VtYZ9Ci4vq9bPbkxedEevnpYIa7Jf3+z/I=; b=pj2UfkOo/1Nk1T+iDuVO25EJhyriuwZXMmtM9ctMLJOHHQTGGg7evi0B1LsXom5MUu nQnDyL4U/OR3e1wdywK0cN1gxGMOUJT5cFb7W/xxgcuV03rdFkiuEKdrelTxemTFNuVg jlx4TZ7Exe7vcuw9iXvNBvtCp0/6mOHPvdSSLTm+mbHBx4rgtdr2GOm4NIDGY+U3LgTv 0fdqYAkPudoQcxBc3H8JpDLpixm7C0JTjzLQB1i16AUkUR9UWFe3zFD47ZL1YTyae8V6 jwbKZ8ifidBKgW6oTqvt4AnG/zuXT54F8HbhtiNsa1YcjcgyY9DlxTSJFSi6N9Uv4Zfz o79g== X-Gm-Message-State: AOAM532NWTmZCL7yaOaZ8HHSY2skB5g+ucwCxHl8PkLAkRuMnx+vGGka tUIil32OxG+NcDEBoBCWYEUyR5eBBnZxFHhboW+rUCo0toBvZd3LFkks3bZpxW/gxbQ5y5dWe1K tKGEWNLjGMgtI7w== X-Received: by 2002:a1c:2042:: with SMTP id g63mr15507761wmg.27.1629998825017; Thu, 26 Aug 2021 10:27:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvQGEW9fnsUvH7lMnEtqbSRyVAYs06PBOgNAaQkgzx/G8LWn12Eva/kw5BO1E2Kyw/aObfaA== X-Received: by 2002:a1c:2042:: with SMTP id g63mr15507729wmg.27.1629998824766; Thu, 26 Aug 2021 10:27:04 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Paolo Bonzini , "Michael S. Tsirkin" , Cornelia Huck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 1/3] hw/virtio: Document virtio_queue_packed_empty_rcu is called within RCU Date: Thu, 26 Aug 2021 19:26:56 +0200 Message-Id: <20210826172658.2116840-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826172658.2116840-1-philmd@redhat.com> References: <20210826172658.2116840-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: 1629998829573100001 While virtio_queue_packed_empty_rcu() uses the '_rcu' suffix, it is not obvious it is called within rcu_read_lock(). All other functions from this file called with the RCU locked have a comment describing it. Document this one similarly for consistency. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella --- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 874377f37a7..a5214bca612 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -634,6 +634,7 @@ static int virtio_queue_split_empty(VirtQueue *vq) return empty; } =20 +/* Called within rcu_read_lock(). */ static int virtio_queue_packed_empty_rcu(VirtQueue *vq) { struct VRingPackedDesc desc; --=20 2.31.1 From nobody Mon May 6 04:26:19 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=1629998832; cv=none; d=zohomail.com; s=zohoarc; b=i+6LPSbkJ1VxLzsiciBeZJH+P29W8L5J4mDRelsGKcZqn1TQBsiy+P5kDEDwzBQNSXGRTyrMtWHcY5mcLgEwVJH3XBHwMKuAo11Z4O3OPA0Z9T9oC97IE86afVOwOFOiu4rjDUjYl4xuH4bZ/JoOo81IzFMRwBH43RydkG4Qq/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629998832; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=KDBZg389G66cuuXg1cBtciC2SPgn2cHOhDyJJyO+H/o=; b=OAl3XVxHgyuuDtbo2SFs4E39UTLzP7cLLS4byU2WzfZmfpNcLqpofm8OIvnfukbQYTcg8oAzDULFHeH+lb2zYKWQEoGSC24eNSudnru/Yy1pJ5EoKDiazV/bd++J32Io6O6/H7UAMTvxIt4Pz3SSvgmjV29Hcc5foJJDdU8NBVQ= 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 1629998832793684.0620473724764; Thu, 26 Aug 2021 10:27:12 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-9rlGr-AOOZ2JUT7Hc377KQ-1; Thu, 26 Aug 2021 13:27:10 -0400 Received: by mail-wm1-f72.google.com with SMTP id r126-20020a1c4484000000b002e8858850abso1191308wma.0 for ; Thu, 26 Aug 2021 10:27:10 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id x21sm2244941wmi.15.2021.08.26.10.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 10:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629998831; 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=KDBZg389G66cuuXg1cBtciC2SPgn2cHOhDyJJyO+H/o=; b=HXujJFvSLBvj5Si2fBVEeMdYioOlr9F8YINtfdt8fbnroF0NNN6xue2SDaHVBM0/TJvQ5u lwyMoS2j1a+WORWaeAjrgdY5If4wDVX5QaIjnlF+BTtj1n3ZKLvOEtGSFsZBtsjKlxLsut j46hkwq500VYDkwvbYZE2pxVqSnf5Mg= X-MC-Unique: 9rlGr-AOOZ2JUT7Hc377KQ-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=KDBZg389G66cuuXg1cBtciC2SPgn2cHOhDyJJyO+H/o=; b=ibl1OADK3Y8hYh/K7KWqT3kk4DNaAQQsqKLXrSTLAOGAD75XFIi96QUDg0XQw0htLD 4LSUlnrdO+/38kjHsawGI4Lsz7dlPS+TPmqvdEa42DFSbuI92yW5zfkOKi0429UhDFDj WHHfk9j7+lGL5oitgtQkTXE8xNiv3XYwcURXsHfPBUqLI+Eyz5zssyGrkes/Hp5L0xCZ 6nHu19BmSwCcMkshDguQwS2Rr9Kzvw7oPZBnhKsJWgR1ThQoFNVWgTaaKT+VdEmCnFqp gRGWlZqewX6XgIA7z8o/aXwmFFFMSSw1XVPI+OeafSI9nlRzNMsYDF8rmbWKybMuaUXm LzvQ== X-Gm-Message-State: AOAM532yiAjg2502Wun5ZQrt1VCGXr4dQi3gwIEb1QvlUuFX+PFlemmR QWYSVTQO/OgirCgphVWeHhoTS36E+Lil2uJ4bhCA0M0gx4cZMDd2rKjoVxdtYlmbkIy5vbE5a8x BS9pjGkRKBAC8nA== X-Received: by 2002:a7b:c92b:: with SMTP id h11mr4831139wml.62.1629998829429; Thu, 26 Aug 2021 10:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyR0d2R747B2ykwsUpswHtUeBjMLaGGar4KOKo5H4tP6yWonqaC+Xx2wx0tbFSZjG34mFrQ7Q== X-Received: by 2002:a7b:c92b:: with SMTP id h11mr4831127wml.62.1629998829257; Thu, 26 Aug 2021 10:27:09 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Paolo Bonzini , "Michael S. Tsirkin" , Cornelia Huck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 2/3] hw/virtio: Remove NULL check in virtio_free_region_cache() Date: Thu, 26 Aug 2021 19:26:57 +0200 Message-Id: <20210826172658.2116840-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826172658.2116840-1-philmd@redhat.com> References: <20210826172658.2116840-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: 1629998833855100001 virtio_free_region_cache() is called within call_rcu(), always with a non-NULL argument. Ensure new code keep it that way by replacing the NULL check by an assertion. Add a comment this function is called within call_rcu(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella --- hw/virtio/virtio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index a5214bca612..3a1f6c520cb 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -133,12 +133,10 @@ struct VirtQueue QLIST_ENTRY(VirtQueue) node; }; =20 +/* Called within call_rcu(). */ static void virtio_free_region_cache(VRingMemoryRegionCaches *caches) { - if (!caches) { - return; - } - + assert(caches !=3D NULL); address_space_cache_destroy(&caches->desc); address_space_cache_destroy(&caches->avail); address_space_cache_destroy(&caches->used); --=20 2.31.1 From nobody Mon May 6 04:26:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1629998837; cv=none; d=zohomail.com; s=zohoarc; b=em0dxriCyeUborddrRZNOS9VmtrWvbT/xoJDhAdf1GZVe1uR6Ga0+mlf9okoCfckMzjhR3GbAxm6k5nX8VzYLrb7VU50IFiDDKekTWbgRZFkD9x3dA+j+lsN2ogBRE0EMX4N7zFzt+DklTCokLsAijJh0+tQf6WiNRi/OWeQdpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629998837; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=u6X8NyK5dk4UMskkp60riuy7ptxhQXw1NrJ4q4sajpM=; b=mrM9FP2XsUJFfdWHHXSnqXcaFsPppetuTTOfuffhCvOhdfOeQY7qtvWAKnKoPnuqWDtjMZPKuGgixrjvlVXaRXo8C6xf7YD86wvOollKdvG+BDZJrE7msTnFH6BcVkn60KC0lk+RJqRqIAwKNi101UlgHSBcZJ3Ccfbwo3hZORA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629998837428928.1916316016914; Thu, 26 Aug 2021 10:27:17 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-Hxqh3FPYM92ozIZomYwlQg-1; Thu, 26 Aug 2021 13:27:15 -0400 Received: by mail-wr1-f72.google.com with SMTP id r17-20020adfda510000b02901526f76d738so1103558wrl.0 for ; Thu, 26 Aug 2021 10:27:14 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id f17sm3086742wmq.17.2021.08.26.10.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 10:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629998836; 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=u6X8NyK5dk4UMskkp60riuy7ptxhQXw1NrJ4q4sajpM=; b=cVY++T/b6OjvNK10pSxrcasGp9tActIgol8IWAw7iWrHwbDbqtBT/Z8cUo3BQQtjSQTcg3 tFa5c4SRG5EZYbaXp2222THNUQDK67stcI2UwFRPSKsfFNiFKJNp7mmRP4tE5bWkVg44MN eFkc1zsr2DU+MAJfKk+WAMOJolokXF0= X-MC-Unique: Hxqh3FPYM92ozIZomYwlQg-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=u6X8NyK5dk4UMskkp60riuy7ptxhQXw1NrJ4q4sajpM=; b=KvD0BnVeqvUIg63qwXdTEK3L6DCfG2omIzUR6RB3sBWMRbIf5PNW8yf54BjDMfmTbo S1Kfy1iMBTVYzQ+pM3RBpCdVhP9jqdSsRC/qCB81molGDpU2GG26Z2vrTjil8MIH9Q4H on2NqJ4sJOlinVe00+5K0BUjuVkwvsV6krW7XPbeeSa5In8GmDiZAEbftzyFUEGnfqNF LZHPEJg0YmHhJ/BHGZe4iW76VTarYLnqGvgiM2KAEp3aaXDYMgzHj1c0GuIWTL3Q69tB 9alI/quQfsV4rw+hffv0VFTk9h1/ad9YPWqgaNbPSVyljq4nv2gY/Et5D44iAoNYswDb ePrw== X-Gm-Message-State: AOAM532u0DPZT18jyIUWtVwyXSaB1B8mgxalDMObCBvNXX7QYkA8AtJf wbkGM1OihFV5wEa6cPFtTU7VRKKU1pT0m+lcRp5IDJuc0UQsKGTDjr0AzPJaS4/A+aE1kgCxsD1 NgKIpQJdXnDX+EA== X-Received: by 2002:a5d:58c8:: with SMTP id o8mr5506600wrf.361.1629998833962; Thu, 26 Aug 2021 10:27:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwErpc98NO68+MUutfIByeCyHkpxiyIPjG2+peayvoErVmjgBGYYUv9Eg0Fzv8rNcdkUG2+LA== X-Received: by 2002:a5d:58c8:: with SMTP id o8mr5506587wrf.361.1629998833828; Thu, 26 Aug 2021 10:27:13 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Paolo Bonzini , "Michael S. Tsirkin" , Cornelia Huck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 3/3] hw/virtio: Have virtqueue_get_avail_bytes() pass caches arg to callees Date: Thu, 26 Aug 2021 19:26:58 +0200 Message-Id: <20210826172658.2116840-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826172658.2116840-1-philmd@redhat.com> References: <20210826172658.2116840-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: 1629998838132100001 Both virtqueue_packed_get_avail_bytes() and virtqueue_split_get_avail_bytes() access the region cache, but their caller also does. Simplify by having virtqueue_get_avail_bytes calling both with RCU lock held, and passing the caches as argument. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- RFC because I'm not sure this is safe enough --- hw/virtio/virtio.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3a1f6c520cb..8237693a567 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -984,28 +984,23 @@ static int virtqueue_split_read_next_desc(VirtIODevic= e *vdev, VRingDesc *desc, return VIRTQUEUE_READ_DESC_MORE; } =20 +/* Called within rcu_read_lock(). */ static void virtqueue_split_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, unsigned int *out_byte= s, - unsigned max_in_bytes, unsigned max_out_bytes) + unsigned max_in_bytes, unsigned max_out_bytes, + VRingMemoryRegionCaches *caches) { VirtIODevice *vdev =3D vq->vdev; unsigned int max, idx; unsigned int total_bufs, in_total, out_total; - VRingMemoryRegionCaches *caches; MemoryRegionCache indirect_desc_cache =3D MEMORY_REGION_CACHE_INVALID; int64_t len =3D 0; int rc; =20 - RCU_READ_LOCK_GUARD(); - idx =3D vq->last_avail_idx; total_bufs =3D in_total =3D out_total =3D 0; =20 max =3D vq->vring.num; - caches =3D vring_get_region_caches(vq); - if (!caches) { - goto err; - } =20 while ((rc =3D virtqueue_num_heads(vq, idx)) > 0) { MemoryRegionCache *desc_cache =3D &caches->desc; @@ -1124,32 +1119,28 @@ static int virtqueue_packed_read_next_desc(VirtQueu= e *vq, return VIRTQUEUE_READ_DESC_MORE; } =20 +/* Called within rcu_read_lock(). */ static void virtqueue_packed_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, unsigned int *out_bytes, unsigned max_in_bytes, - unsigned max_out_bytes) + unsigned max_out_bytes, + VRingMemoryRegionCaches *cach= es) { VirtIODevice *vdev =3D vq->vdev; unsigned int max, idx; unsigned int total_bufs, in_total, out_total; MemoryRegionCache *desc_cache; - VRingMemoryRegionCaches *caches; MemoryRegionCache indirect_desc_cache =3D MEMORY_REGION_CACHE_INVALID; int64_t len =3D 0; VRingPackedDesc desc; bool wrap_counter; =20 - RCU_READ_LOCK_GUARD(); idx =3D vq->last_avail_idx; wrap_counter =3D vq->last_avail_wrap_counter; total_bufs =3D in_total =3D out_total =3D 0; =20 max =3D vq->vring.num; - caches =3D vring_get_region_caches(vq); - if (!caches) { - goto err; - } =20 for (;;) { unsigned int num_bufs =3D total_bufs; @@ -1250,6 +1241,8 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigne= d int *in_bytes, uint16_t desc_size; VRingMemoryRegionCaches *caches; =20 + RCU_READ_LOCK_GUARD(); + if (unlikely(!vq->vring.desc)) { goto err; } @@ -1268,10 +1261,12 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsig= ned int *in_bytes, =20 if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { virtqueue_packed_get_avail_bytes(vq, in_bytes, out_bytes, - max_in_bytes, max_out_bytes); + max_in_bytes, max_out_bytes, + caches); } else { virtqueue_split_get_avail_bytes(vq, in_bytes, out_bytes, - max_in_bytes, max_out_bytes); + max_in_bytes, max_out_bytes, + caches); } =20 return; --=20 2.31.1