From nobody Sun May 5 19:04:52 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=1630601451; cv=none; d=zohomail.com; s=zohoarc; b=DLh7q77loR8lql8czTw93yMzULbrpm8E7ucrZaDyK/bZK47O5L0azf6PVUI2Cdzh5xTOa4dVQoPvCs6Ongk2X+B5c1xCgdArDLoeP855qa7pmuMKcV2VXdt54bh9G2DejZGm9AkytA6s9YwG2q/jZMWVe2FEcPFR5cM294oWQEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630601451; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=/eGHUQIvX/JArvB4+KJ+gL18UNLlwL1F2ZTEfqh6Mms=; b=RrzTE/OlxHhEVVHtK+m6Hqy2JcjJR7AuKszM0zvr3X3cKcTWYVET5Pw+fG0/apI8FEaS6ZY3nojrFBM9F8p9dh0utzBjyJVvsBa6Pwt4in4GrbWTPUFqo5XiokJFtXdWgngSNEsrXExR0o5s0coZzG5L097OOzGZjbVAQouyEJ4= 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 163060145119385.25882581097017; Thu, 2 Sep 2021 09:50:51 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-sfxUmKZKM7eNIKw1qEEVAg-1; Thu, 02 Sep 2021 12:50:47 -0400 Received: by mail-wm1-f70.google.com with SMTP id m22-20020a7bca56000000b002e7508f3faeso941684wml.2 for ; Thu, 02 Sep 2021 09:50:46 -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 j20sm2238091wrb.5.2021.09.02.09.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 09:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601450; 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=/eGHUQIvX/JArvB4+KJ+gL18UNLlwL1F2ZTEfqh6Mms=; b=RCxU/p5D5E36X5fPnCIdLhFJLXTgTx4TIM0eAba/lkNuX1qfdGrmRz6MjiBcccvg7MZX4A DClfh8OjcSPgPmhPda621019CwGZNSInsBKJoliAcNh4P5TZW4xmSd0GkxSNUsVLgGbTpF 6OvLWwnfsPohOXuX8tEdFbFPlKgH3w0= X-MC-Unique: sfxUmKZKM7eNIKw1qEEVAg-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=/eGHUQIvX/JArvB4+KJ+gL18UNLlwL1F2ZTEfqh6Mms=; b=ru5jgvh0jCLPel9AQ+AtLYK9s4uQA4eiUCagaXEAaGnlptJauOeApo0qQceJ+H+t5m 9wt5fqP7r7pPCmob1jjcaThKSyyIOZ5kuzf9bi4HJA5Z06PSKvMYAGePtG5BqXdhofpq NU38Jwt8X74DPPHWswIzwxKcm9hClEIviqQB5cMxaMgdMOR13V/X88qis2Qqp0mnvjNY 2cOO+/oaiOf2zAyhtgnYACFznHNnP7b8GmB2bG4S9XKLnjWhQIM1a8mB4DXudn3RlAfm Z9x5BWUyTNAH1NiwVmaQNuVsHYBdq5qh3hIIV3pfnFqHf6jK8P3HpnUCU8/OZHS9DC/b fnig== X-Gm-Message-State: AOAM530tKzssq+u3WB/j/sTsqpg1/PXW781FyOsspaO571SB7RYCA/jV 3rDzsOSupJlZ+1br8XqRzSXIMQAbETzPmOUWtnXAdbG83bCVlJmwd7tDz6J0CcyJx8QgGXsIhd1 bSSz09rEZwWrMaA== X-Received: by 2002:a5d:4564:: with SMTP id a4mr4751612wrc.81.1630601445911; Thu, 02 Sep 2021 09:50:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUN/r+OzlPsXuR7hUMv5dVYJDYJQg9pcwlQiunXkOKzRqH6E1GuQIemVsqaKxx27E2RfvbTw== X-Received: by 2002:a5d:4564:: with SMTP id a4mr4751600wrc.81.1630601445779; Thu, 02 Sep 2021 09:50:45 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Cornelia Huck , Stefano Garzarella , Paolo Bonzini , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/5] hw/virtio: Document virtio_queue_packed_empty_rcu is called within RCU Date: Thu, 2 Sep 2021 18:50:35 +0200 Message-Id: <20210902165039.432786-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902165039.432786-1-philmd@redhat.com> References: <20210902165039.432786-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: 1630601452206100001 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. Reviewed-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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 Sun May 5 19:04:52 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=1630601453; cv=none; d=zohomail.com; s=zohoarc; b=MZEPHj4wJBU7JRc96LYaVprkbJTLBJf3Mfa2J7JLWU9SJQeZrXNdbA/8vq4MAuJFPXX877UlW4Iow7wYJBmOCd3qq7eZ/bR7/NJlqa6u69FjLiq7nnokbqnOFSUT4fG9MKtDogvTO8rm4Upvf9CrXtMFKGh1MlCjUoyrbBB1SzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630601453; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=VN2G/4wJSGOaP1i/981uZGnXCojQFUj+WUAJBtOHkIY=; b=IFe8UcUM02xTLgEdw6pbwNNo0nMjaGiSATJ/xGlXdD+YNrb5yEfWt404OQaVJlNGCV5lewQg2nERn4vRsLm1uBRO32KQiNNq4cAh9ShyfWPVnHxpVP1ou8ZxFqVnCxoHPhK2KBystYbybSjfaXue4y45YfDk10XVDrZWYbYDNwY= 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 1630601453474492.9877964928869; Thu, 2 Sep 2021 09:50:53 -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-83-wydODskpMTy-in9lTwLXBg-1; Thu, 02 Sep 2021 12:50:51 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5-20020a1c00050000b02902e67111d9f0so939802wma.4 for ; Thu, 02 Sep 2021 09:50:51 -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 w29sm2347646wra.88.2021.09.02.09.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 09:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601452; 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=VN2G/4wJSGOaP1i/981uZGnXCojQFUj+WUAJBtOHkIY=; b=VJDZdsSaDTIp0DUcQTZHWkHy6kry6e1nlF+LVtk/sUocMGlodknSGNT9NezZu40+qmofOC ahKWiZTKWeYZ4Q1JFPCtxU09sGI6CRhkBvNWrp2Y9+Q5lCEbis4s4jRSa8B+5lEHGhfC23 ukgCKAt9GA9n04wMV5ooVVm9Lb6ADX0= X-MC-Unique: wydODskpMTy-in9lTwLXBg-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=VN2G/4wJSGOaP1i/981uZGnXCojQFUj+WUAJBtOHkIY=; b=G6W+iOfhRU31MSIUqZo4KokbDn2AuP/1elSVECHOY14X/k9W8x7MZ4jgmt59OsxPZR Hr+/GOSGYWWWkR94TBBqjLLZdbdRQVEye51Dq/ZoZfc27RTktdMlvYcnXGsyxic/8qjm R8YTkukWmZa1aOjDcKV3q1Syzxpo/P+qSlVIuW9tuyxqp3YMsHQ05w7k8xT1yB54o+Bm XYJuSsK6Phptl1LDSTTjBhKruOp7Mr4RqbDE78x8w0IrDpBYFlzMFRGsreQT5bWiPKSP lLImVFei6sJIwdFzAnvGYmbkmdcxQaB+rNVEG6BJGKH5vG3Bs+pYqTcAPURMeCQ6Pt88 wwmw== X-Gm-Message-State: AOAM53241U6uk/nuEIHBOONb+e0Je1VXmXnthm4017nhu8lXSxI+G/sW ygrtFbxUQvr5cyplcdKmqbDVolOwCU1aP8IyzwEMQn7V2jpllOoY5fCQ5smkxCrazeXi0cFru20 heCcjts/y+O2sUA== X-Received: by 2002:adf:910b:: with SMTP id j11mr5126805wrj.114.1630601450181; Thu, 02 Sep 2021 09:50:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwea8iZWd3qA+Endbq2SjCFcM8b7KRnOUYgTlw5Dootfy65if7i4AgBT9x2JXBQc1DO38984A== X-Received: by 2002:adf:910b:: with SMTP id j11mr5126787wrj.114.1630601450033; Thu, 02 Sep 2021 09:50:50 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Cornelia Huck , Stefano Garzarella , Paolo Bonzini , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 2/5] hw/virtio: Comment virtqueue_flush() must be called with RCU read lock Date: Thu, 2 Sep 2021 18:50:36 +0200 Message-Id: <20210902165039.432786-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902165039.432786-1-philmd@redhat.com> References: <20210902165039.432786-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: 1630601454290100003 Reported-by: Stefano Garzarella Suggested-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/virtio/virtio.h | 7 +++++++ hw/virtio/virtio.c | 1 + 2 files changed, 8 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 8bab9cfb750..c1c5f6e53c8 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -186,6 +186,13 @@ void virtio_delete_queue(VirtQueue *vq); =20 void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len); +/** + * virtqueue_flush: + * @vq: The #VirtQueue + * @count: Number of elements to flush + * + * Must be called within RCU critical section. + */ void virtqueue_flush(VirtQueue *vq, unsigned int count); void virtqueue_detach_element(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index a5214bca612..b37344bb5e1 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -898,6 +898,7 @@ static void virtqueue_packed_flush(VirtQueue *vq, unsig= ned int count) } } =20 +/* Called within rcu_read_lock(). */ void virtqueue_flush(VirtQueue *vq, unsigned int count) { if (virtio_device_disabled(vq->vdev)) { --=20 2.31.1 From nobody Sun May 5 19:04:52 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=1630601459; cv=none; d=zohomail.com; s=zohoarc; b=dx2ELBJr9pszwx/IhZfQPpLCDPVTKeiDZGY6+dBL5PAjbm7i+LQyJGCLQFTXUMJmxEweOIsESxC6EDf6E5gk1y1ZhK9kdSrRWyaZw1FHtiq2UQpksaCvwIxn5EuRv5vnIdov5gEjxZBSQm56fhPzynRomLj1E1SGjGPFyjZVmxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630601459; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ZfztDw0T+IxqiSXV2YqDwUKK0y6/AeZln0/z1gPaV7s=; b=WchPlIH4F1dmY9DMruH67flPCY/44SzVFfB5pm9fVMGtMmxF+jSnjSq4LhJo8fOS/Pwa0jwqoYQLei0liyliRpQNAYwLxE2LE6kyJPpOaSbS9nmKYUkuK4EjeHf3RFKrdA2MUycIOSq8XxBp/MwtTjavvz/LuOndkvmrG9U11QA= 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 1630601459981286.2838187456491; Thu, 2 Sep 2021 09:50:59 -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-239-61bhesxlNLiNCUxUl4RYxg-1; Thu, 02 Sep 2021 12:50:56 -0400 Received: by mail-wm1-f71.google.com with SMTP id s197-20020a1ca9ce000000b002e72ba822dcso1285328wme.6 for ; Thu, 02 Sep 2021 09:50:55 -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 a12sm2207407wmm.42.2021.09.02.09.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 09:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601459; 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=ZfztDw0T+IxqiSXV2YqDwUKK0y6/AeZln0/z1gPaV7s=; b=KZoXscVTcld4gYH/ucbt0UtpHudD8bNXOGN09fjgxJflrL8B38DTSaOeohPUkkhx8iNXsb P4RyKRs+mij8YT8vJOEaxd9ef6DJoW/8sSQtRO2UaXAk3NGWy9NxH/Z+EvqL1jT614tdtm Lh0mTcHTvWfdpJ0ByLJkQTUrheNNBFY= X-MC-Unique: 61bhesxlNLiNCUxUl4RYxg-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=ZfztDw0T+IxqiSXV2YqDwUKK0y6/AeZln0/z1gPaV7s=; b=SbJMNQp+WybkjpI2ibl0EjmaTW0COcRb9GA7BDZqq7n8vG72vN1QRgsbvBxARtrjqh W3KTtgn1Wg40XovX3h156WkoqKIXJ0C9/bv/lRwCXhsc5AcsgHLySFUan55qBQwsfS+T FNc7s5jrxX4qs7PDt34Md710FuDO1iXj9Qa0io762RB8zNmU5mGt7EYPKdnUyMbcZAhL pwklRfEjESyn8ad8uM68XBMN34RCBFy1ZcN2y4tojd8hKYtHpGXkrqD04AZ7IVo9U3xe IToSjSRv0jjq1qgygSFxkNwYHU9eDQUnoL62OjfEneHhJy1zXiNxReFXK8VZxriWEJzr hxeA== X-Gm-Message-State: AOAM53342lT2npKDvyNVxzjvTNsdDs8ns6M/T74d6/H9Op3kkIxjKwWS dsnoHoQaK1qgGGlaf/NjbDaO/RFnFFwiOnMwRwtWzZXvsSflXPG8+G4FJPuQbqHyM7YFr+hMMpB hJFer/qGMEhzw5A== X-Received: by 2002:a1c:19c1:: with SMTP id 184mr4206748wmz.98.1630601454629; Thu, 02 Sep 2021 09:50:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzd3LRNbsJqd5qvimCtL2xxLJh/vNZ6XFLyopyhIFapV8NKMbi7jX4inkmwlQeFGpGDgL0Zg== X-Received: by 2002:a1c:19c1:: with SMTP id 184mr4206730wmz.98.1630601454395; Thu, 02 Sep 2021 09:50:54 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Cornelia Huck , Stefano Garzarella , Paolo Bonzini , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 3/5] hw/virtio: Remove NULL check in virtio_free_region_cache() Date: Thu, 2 Sep 2021 18:50:37 +0200 Message-Id: <20210902165039.432786-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902165039.432786-1-philmd@redhat.com> References: <20210902165039.432786-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: 1630601461337100001 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(). Reviewed-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- Worth mentioning the left-over from c611c76417f? ("virtio: add MemoryListener to cache ring translations") --- 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 b37344bb5e1..97f60017466 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 Sun May 5 19:04:52 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=1630601462; cv=none; d=zohomail.com; s=zohoarc; b=N01pe/qV39ASJuuGS5ckKyJAmb1HHNNiQOZ0P0ouRtcJmKG892N8XiVKM6qzgsxTBQGjHS+JEVpBS2JVOfBCDXpdxzCRu7Ai201dI9Bnog1TM7XZBpClt4xTP/7IqV+opg847th2iHu0PnnyzpeSW9Ngg6gF+w7Jp0kixY411MI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630601462; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ydqzmpwIS7w421UnF6h3bFe+Afko4IEnGxAHt+H+82o=; b=WDBL+GBhci8iKfMxIPdUzQf0r2RejBNIuqpjhHhWEC39yAL6iGaazU2QT2JY3hTJqyFo7qXlaPyKZwAI/oGWVNcD+rbpMhn6/eRRTPy/PCiX7Ikx1S20W5ypr6mrODyh+4kOh3EqWfKQdPzzIx9IRrxF58LwMAJT0tMM/Y2SMYA= 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 1630601462537374.3745877124089; Thu, 2 Sep 2021 09:51:02 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-W4_GVXwhPCaw3dxHEpRjSg-1; Thu, 02 Sep 2021 12:51:00 -0400 Received: by mail-wr1-f69.google.com with SMTP id p18-20020a5d4e12000000b0015940dc586aso756758wrt.6 for ; Thu, 02 Sep 2021 09:50:59 -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 s1sm2386940wrs.53.2021.09.02.09.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 09:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601461; 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=ydqzmpwIS7w421UnF6h3bFe+Afko4IEnGxAHt+H+82o=; b=H/DdrcNaA1sjw+SjVVOjviZlZFfCN8qQqe79eeHNdv7ifFafQdv6G4m2fvOpZ1fx7IXgYP 99/xkf85GypYGZMFikzxbSSk/r2pxsrsynIhTwmlPkHT9XvvukF83dWrDQibIVTOXgTF6C 2/H0DlEfxHsuTBl37ln7iDhq1AkZoNA= X-MC-Unique: W4_GVXwhPCaw3dxHEpRjSg-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=ydqzmpwIS7w421UnF6h3bFe+Afko4IEnGxAHt+H+82o=; b=jf87ZNSLl7Xx7Vd7vaYJIFxhE1p+Eb2FDMnpprSpvfvkGNoetrYmT+Wi3cKmAvK27q flAroU7p7QauAYz7BZu8FeC8/nnzqURK6EYio83VBT43vT9GLRAPsqygapqNjJqkn0K2 U4xSH0h9Vtaz6ZrwgPhAf5j/BWA6tXdIdRn7Hn32I6w9dzAxX8EYH5pfEcBe8tBzKpZq 8ir697zEwJFu37SW/r4+4aX+NFA3at1lmSt5T2jKJh1xAYToQ+hQYPoleOHrI6o10GoC Ez+Jz89aeYZeQHN9FwHk8HAf1AM8QSXBE3SPaY4QB/9j2chyTz8Mygq2g6T1MzcX2Pz4 kHgg== X-Gm-Message-State: AOAM533nFkC0JA8WIfE+vPJr0SMqqDzv8q83vfrbXjyNtdgbHG2UzFhR gVMy0oMbKOPds1MJYHG167vZfzYzARAbxH/EsXmrY0Ru/fME/rak9Okdw/elb1+oYPVkNOqOi3l blnSAIidQltOP+A== X-Received: by 2002:adf:c405:: with SMTP id v5mr4922730wrf.183.1630601458983; Thu, 02 Sep 2021 09:50:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsxF6ASqU+vuAstoHC6qZ4CFufNOz4O5rFfyQl1kKl5jUCnlfv2zuQ3t5UWCXVSXXQq2K+Gw== X-Received: by 2002:adf:c405:: with SMTP id v5mr4922718wrf.183.1630601458855; Thu, 02 Sep 2021 09:50:58 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Cornelia Huck , Stefano Garzarella , Paolo Bonzini , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 4/5] hw/virtio: Acquire RCU read lock in virtqueue_packed_drop_all() Date: Thu, 2 Sep 2021 18:50:38 +0200 Message-Id: <20210902165039.432786-5-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902165039.432786-1-philmd@redhat.com> References: <20210902165039.432786-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: 1630601463730100001 vring_get_region_caches() must be called with the RCU read lock acquired. virtqueue_packed_drop_all() does not, and uses the 'caches' pointer. Fix that by using the RCU_READ_LOCK_GUARD() macro. Reported-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/virtio/virtio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 97f60017466..7d3bf9091ee 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1704,6 +1704,8 @@ static unsigned int virtqueue_packed_drop_all(VirtQue= ue *vq) VirtIODevice *vdev =3D vq->vdev; VRingPackedDesc desc; =20 + RCU_READ_LOCK_GUARD(); + caches =3D vring_get_region_caches(vq); if (!caches) { return 0; --=20 2.31.1 From nobody Sun May 5 19:04:52 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=1630601468; cv=none; d=zohomail.com; s=zohoarc; b=bP0dTXT3I+dqpUzlupboWL5csKr+rj0BNlVGa3VZjpNJ0oMIXkyseDkxXf4P+U29whDHFpjsq8ScvpuJ80tMQx8Ec+8nKdYBu1CUj0JLi2vf4Beti8SDPiGk1y+HkWbsQWVwhhrmp4PIirpJC/4ShZ+MhNcQ7iJ9BkESJfRA4kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630601468; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=hnQjUJf863/+mR0eVjMS2XLf+nf0liaJ3GnxfaQW96o=; b=HIlaGe6tOTewCchMZZV4V1pNVP0b0Qn2nwUfshWCY7BMWwyApvSMVe6BXQdu6cKjz+fwuKQZ06it5UX7AITYIMDcgCbLaNjIlU7etF+Bm4OXa4vUnvyvbwcGh73aks7u/2o2jB1g7MgnCgj+Dw0PlaJS4K5/lAbLplkDmykVTkU= 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 1630601468896262.0174778257117; Thu, 2 Sep 2021 09:51:08 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-cvMU-AtaN4q2e2QOC9xY6g-1; Thu, 02 Sep 2021 12:51:04 -0400 Received: by mail-wr1-f69.google.com with SMTP id d10-20020adffbca000000b00157bc86d94eso751023wrs.20 for ; Thu, 02 Sep 2021 09:51:04 -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 f20sm2031259wmb.32.2021.09.02.09.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 09:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601467; 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=hnQjUJf863/+mR0eVjMS2XLf+nf0liaJ3GnxfaQW96o=; b=FH3V1eMNVVvQNkQkFi4DrbiKseKGgKQ2RbICV/b4n3FQwjPdqyJBHkZVzsVsxRww6RJgc7 VmDaQxayFVshdryJ6LfM6HI1uqJrx0evFb2sCh6AO42CMPgpB1j7bA2DjTailwkKPQ0chy lPCgaohh6sdC5s6UQ2/rcg+N21DEd8Q= X-MC-Unique: cvMU-AtaN4q2e2QOC9xY6g-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=hnQjUJf863/+mR0eVjMS2XLf+nf0liaJ3GnxfaQW96o=; b=A/Kv84Hh8rvx6LGvdRsDc9gOOjZYw+ZIPfHdYr2xqzkEfwoDZROCvx2odiQjmWbc5f sO6BVol0FWURzkJ2pNZnGvoR0Orly4of2zojcj0g7pkf2XVi3feUkvVJJ1rdCZKJYa6Z xgX6jJltTXOqieKRWpvyULhZe0Kkevkt4YFjbGTwnc01O0QqblFa4jiyqHXL8Qv73nW4 qSeOzcQeZGdZleXJtAoqa+/N2YxtuhvCdz2bYfpJB0mGf1ysTWtLJqmI8YNpDLR7baeI ie97kdu4p1eDwT4Wa5KNNvw+FLTJ5eJ65Wv4C+TrFg2a09Uy48USyw2w17ZvCjqR+KeI AqMw== X-Gm-Message-State: AOAM53316vzG1P3NkzsPjUiWBrd8e2ltsEFLrtJ2Yk1yW4KwlAnyPBo+ qKCvVOCZo+qLUPOWclDJRHPpGPEWD3z3PWS3UbZVTB94QDwVl3eT4I6MZl4DJCEQ0zFQSamLN67 5+HmnzNYxRHA8NA== X-Received: by 2002:a05:600c:2186:: with SMTP id e6mr4061390wme.71.1630601463511; Thu, 02 Sep 2021 09:51:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv883Bvgb+qGXKSmCFdDdyubVsEgDw9NLGLvTI0wvsT8O4RJLHjIHboVbrto2GgSQTbifupg== X-Received: by 2002:a05:600c:2186:: with SMTP id e6mr4061382wme.71.1630601463349; Thu, 02 Sep 2021 09:51:03 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Cornelia Huck , Stefano Garzarella , Paolo Bonzini , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 5/5] hw/virtio: Have virtqueue_get_avail_bytes() pass caches arg to callees Date: Thu, 2 Sep 2021 18:50:39 +0200 Message-Id: <20210902165039.432786-6-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902165039.432786-1-philmd@redhat.com> References: <20210902165039.432786-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: 1630601470338100001 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 --- 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 7d3bf9091ee..0dbfb53e51b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -985,28 +985,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; @@ -1125,32 +1120,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; @@ -1251,6 +1242,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; } @@ -1269,10 +1262,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