From nobody Tue May 7 11:08:23 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=1630925007; cv=none; d=zohomail.com; s=zohoarc; b=Iuv/lDKn/hE6NQsC/kyxuMnfY/OFR8xDMZFGLL1pC/RWpTucNcbnN3sDnsc0eXyAzWJd7YHQ5XLw/1JCFest9SJaAxaU7VcUIctV5+jAi36Uk1aeyLTgGtMhhk638N23+c9RN9iEG4vZ43uvjOTw36XnG67AtMNiebnxGYY/3Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630925007; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=flP71HjC8jGMU9xA5z+8rAkdDjbRG9SSiS1OKFek9Fk=; b=gYe34VL39zLnArno9ZKtmGpLsG5Yvg2yXscxjObZ0tKymX7EXWm31S+vaNQ+1OfYys42IjY9vaFSo8Q4dKrPJX2rdnP044CMH0nTubS8RnKe7Seec040LVKjXTskTt4HYQYjJKOgEut4p/CbEdxwMip7kl2GUMTKkp2HwS8HKLE= 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 1630925007763462.8288265020392; Mon, 6 Sep 2021 03:43:27 -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-422-LEvuEOzdO2SCoXr5v9a49w-1; Mon, 06 Sep 2021 06:43:25 -0400 Received: by mail-wr1-f72.google.com with SMTP id h6-20020a5d4fc6000000b00157503046afso1091538wrw.3 for ; Mon, 06 Sep 2021 03:43:25 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (21.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.21]) by smtp.gmail.com with ESMTPSA id f5sm6823938wmb.47.2021.09.06.03.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 03:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630925006; 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=flP71HjC8jGMU9xA5z+8rAkdDjbRG9SSiS1OKFek9Fk=; b=WkkQO/Nj0w5rgEvCXmyfVGrAZQdOwP6DeunO/pEGqJ3Uejv9Nw5q+emNqMGCSGy/N4Jfxz POhJG6Yvu1t0NPh7Acs5NTjrT1cTp8HLUE1NfgTikHdrQ3RxyxI8yQtO5AeDOmsItEbgJX j7ING6zzKjt/6ROG1NrIBVboyg18R/Y= X-MC-Unique: LEvuEOzdO2SCoXr5v9a49w-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=flP71HjC8jGMU9xA5z+8rAkdDjbRG9SSiS1OKFek9Fk=; b=T+kosBdmN1wZ5XMmMKXVqmXwnzrQyVe3l6Kmh+4TabNX6UZnAKtQ+0xJi91Iad09aw WjBBnsZz0LVZ9f/ChVmPIyf09YDN6jjvBIEsAm4j5UwMPZ2q/JHjRoKpoe4A3qg47/OR Cg78dcPYXjdqI4JPot0UzmQy4hTK7+Oo/bRnuJPBVNMsM2MPn5lJnwgsM9sLBr+Ihuel yfU034fkuerUtdMDC7HkzZCr+ux2/fKe85OEmJuxyUw6i9f51Q8mIoijWXlThrRWglgt db9BCmNl3FZ/7cdJ9seRb48wcGCJG1yHICvC4IISNdCOSqqz6uiwsZ7/FyCdbQq+4IbW cBeA== X-Gm-Message-State: AOAM530MmLb6BJw4c5xCnyUvcxAqdZLlA6RiQOepdwv6DAQp/s7MDfIp 7HII/PwijEToM64PBdznFTyqri2CZJ55gUkuMnIIz3k+L2B/hddYxBAQ2Wf66FcG6hlqL+oOggv meojZlT9D7+iE2Q== X-Received: by 2002:a5d:53cf:: with SMTP id a15mr11419737wrw.146.1630925004443; Mon, 06 Sep 2021 03:43:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX5pSkcTBvskmSyos1Xq4rn17eyBB8Dh9wCf2wv3w9XI1PFnJLqFaV/gseZsgrjD8l68SidA== X-Received: by 2002:a5d:53cf:: with SMTP id a15mr11419720wrw.146.1630925004306; Mon, 06 Sep 2021 03:43:24 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Cornelia Huck , Stefano Garzarella , "Michael S. Tsirkin" , Paolo Bonzini , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/3] hw/virtio: Comment virtqueue_flush() must be called with RCU read lock Date: Mon, 6 Sep 2021 12:43:16 +0200 Message-Id: <20210906104318.1569967-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906104318.1569967-1-philmd@redhat.com> References: <20210906104318.1569967-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: 1630925009946100001 Reported-by: Stefano Garzarella Suggested-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- 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 3a1f6c520cb..97f60017466 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -896,6 +896,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 Tue May 7 11:08:23 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=1630925012; cv=none; d=zohomail.com; s=zohoarc; b=EUglfXGejv9u04eEGNLV8aNydpzauZDzz6hVG+HERBAChR2NJ2jk1xFrddKT/M8NmhggcJSC81PDT9i1UBaKvsfZplUs+fK7eQGOGPHQww7bA7Q8hQqoApXwtEKio2gxKiahHQBsQdV0ANTiMz5nhpjMA2TcFqcqf7HGfqwyXmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630925012; 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=CvE9hasXlppQJJkXM6OqLLc/873diOXKOAS+1c6b7unM7j9dOzHYsXy5TVoM4/TBhxlRql07CW02BnIJg9DGKZt+qc0Fsp3lDm1IUk8+hTvbUOOQKXvFBECtSiylDx9XZY3WA7QShZU/WsxAG02522JUdJbO7Y7eVnaZ4ChbEjs= 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 1630925012269714.9888636606629; Mon, 6 Sep 2021 03:43:32 -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-506-Xyte2GM-NYCJNutxBxqE4Q-1; Mon, 06 Sep 2021 06:43:30 -0400 Received: by mail-wm1-f71.google.com with SMTP id s197-20020a1ca9ce000000b002e72ba822dcso3745355wme.6 for ; Mon, 06 Sep 2021 03:43:30 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (21.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.21]) by smtp.gmail.com with ESMTPSA id c15sm6889020wmr.8.2021.09.06.03.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 03:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630925011; 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=b4J2YUHOQqYRG+psoc24G3Poaf5im/8BqqHkepiiRrNxuVmGYzhHrgDZ6Uzye3QU0R3MUr C0+vgdJayLVNefsFHoRE1ZQEUQu7sPekLdO+KNTmSHgdFNlmlMwnaiag6DuS8wyYuGVV4f VHyqq9QTrdEaPUOhnEFFzhl41QzbBEg= X-MC-Unique: Xyte2GM-NYCJNutxBxqE4Q-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=AM1NI4aXI/LVaArmPua5cGt6iuxvtuqlxLySkqmAVCmNqfJM1WljNPZSndm/867i4W 0f1/mRnzpqgP4pMr8eIOq2+ooNQ+4XDVZy59ly6QJvBGHW05kYDmHtT3sBs3RThpmJqp leg+MENUPC/8DzpafU6ikwKG6UqEpFbItyxKShGlQEPRbOtuejargqcVLoH+WhOHqmIU 6fflP6m9YwmocdQwvwTDfkInVLrEylAwwkSq0NHCwL/E0j1P+8a5axvBFXHjjUeuT6C2 +1UoBkCE+Tcy23fFOLa7m/78QJ4m1cD6BrTuzChNY27EM8lG3X6rp7BWFzLvTrBdTMlX WFIQ== X-Gm-Message-State: AOAM532mdwYgqsG/Kg/BEhV5u2sadBfHLMXy3pRknI9YiCbA/CONnfTA N4VralRY+VCT1NvyVUBpr75jcdxYh5kC3NcGt1I1mhcyg4S4rmpbM/2zyCeyHNkrkFJF455dmtm yNKuz1bx1YAaLyQ== X-Received: by 2002:adf:ce85:: with SMTP id r5mr12649796wrn.323.1630925009261; Mon, 06 Sep 2021 03:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHy4hCuzzCoHmbyOxXuF8aQv4fJfICXV4BR/P+IflP/4frkx1GgFT9uF0tP+AARXyUtB+1Jg== X-Received: by 2002:adf:ce85:: with SMTP id r5mr12649777wrn.323.1630925009082; Mon, 06 Sep 2021 03:43:29 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Cornelia Huck , Stefano Garzarella , "Michael S. Tsirkin" , Paolo Bonzini , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 2/3] hw/virtio: Acquire RCU read lock in virtqueue_packed_drop_all() Date: Mon, 6 Sep 2021 12:43:17 +0200 Message-Id: <20210906104318.1569967-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906104318.1569967-1-philmd@redhat.com> References: <20210906104318.1569967-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: 1630925014040100001 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 Reviewed-by: Stefano Garzarella --- 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 Tue May 7 11:08:23 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=1630925017; cv=none; d=zohomail.com; s=zohoarc; b=KWwIcikjSDqCzH+ogrzuES7Da1XYN+Ub6z9JAL4S9e0iJH+WoYl3M5Au8z9P6dyd2x9YMgt/UPiYUaQTCfYHCh2gLBRTyOfb90pnlolm/+mrHjYrmE6nixiqTSQchi46pmx7qJz6UkiSWAaG1Au8OXQnHUsqQg59MKVnE4RAiVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630925017; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=hnQjUJf863/+mR0eVjMS2XLf+nf0liaJ3GnxfaQW96o=; b=HxpXrhhVJrfPqe0oe1ZGtO8PEWQpvIZ0Djw233EleXrWvShWUy5XlrZkoBfIsfGfvUroOTfPE2XE9wEzhoo5cJFM2gb/otoyF4sMu23F3/bHyxprgW6qyZfkvUNAAAaTAypcW5TM+tdn+MPy3yVFZptotys1hfOYPfwJ4CKtwaM= 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 1630925017290725.7745727027611; Mon, 6 Sep 2021 03:43:37 -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-553-XZyNwOJOMUCcPf4W9pYtnA-1; Mon, 06 Sep 2021 06:43:35 -0400 Received: by mail-wr1-f70.google.com with SMTP id z15-20020adff74f000000b001577d70c98dso1085890wrp.12 for ; Mon, 06 Sep 2021 03:43:35 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (21.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.21]) by smtp.gmail.com with ESMTPSA id k18sm6946622wmi.25.2021.09.06.03.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 03:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630925016; 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=QjrYruLEbtV1d+G5Py21h7TXbNV7RwFmZa5OEe39fdabMjNSAqBH6w0gdzz4QGDVZq2Ll5 ircZgq8I9NGiAZ/LKxW08HzJRh6XnJLkz8zE2zrg0QrnifA0URrIc/ENhrrxTLWfdLjAAI Fnb/AThUvfLt68PdTLj3MU6yCweVxZs= X-MC-Unique: XZyNwOJOMUCcPf4W9pYtnA-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=aiCC5Js7x1VijYBGxy/NhgKLGicq4EXIE7Wz1iRlWHMnmrgucG1DUiFc3TTSilDS8U 4zHSjHy8pa6FP2wavwK1HsYaai6lY4Ybg15EFXw1Fv2N/BCVUYgFoDrBImLZDo7TBap1 RllKkDoP6fzGspz2Po1wDDz3g5X9bBtxD97w5rmYKpv4L3XDDRG8nk7t6QZAaO3tzkAp z2/zSKcDvPI8l9g1LGtGn1YB6fLR+utchkE6EmSPo9LcnuWkLjlsA9o28n+CziVhooKr vGGxiLA5Oe2wBKjEYZ5KRFKUGJ4uNYplftMm1DxrTNT6hJbs5eBNRVsUCcBfDLZDBIop c2XQ== X-Gm-Message-State: AOAM530P050BX5idvnTcuLtWuOcZ3v9JrUuA8DdTDcZTp+60yTw0In9+ biHd4321/B3+RT5fczQSW7t5KmZ7oeUmaokgY3hQ2SLxhoyetPObt+fmBrlM2hs+bTq6fYR5NhR nOyKpN4IjU4TeZg== X-Received: by 2002:a1c:2313:: with SMTP id j19mr10432855wmj.189.1630925014342; Mon, 06 Sep 2021 03:43:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJfm5PSRAgm++47QCA949GONjrP8h2cc7vrrvhVpxUSEbp3iABDoCQXGrsno4GUyykO8PS4Q== X-Received: by 2002:a1c:2313:: with SMTP id j19mr10432820wmj.189.1630925013958; Mon, 06 Sep 2021 03:43:33 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jason Wang , Cornelia Huck , Stefano Garzarella , "Michael S. Tsirkin" , Paolo Bonzini , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 3/3] hw/virtio: Have virtqueue_get_avail_bytes() pass caches arg to callees Date: Mon, 6 Sep 2021 12:43:18 +0200 Message-Id: <20210906104318.1569967-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906104318.1569967-1-philmd@redhat.com> References: <20210906104318.1569967-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: 1630925018543100002 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 Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella --- 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