From patchwork Thu Sep 2 16:50:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12472165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90B52C83026 for ; Thu, 2 Sep 2021 16:52:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2287660FDC for ; Thu, 2 Sep 2021 16:52:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2287660FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:60222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLpxF-0004bG-B0 for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 12:52:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvQ-0001r2-OK for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:50:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvM-0000GG-Tb for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:50:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601448; 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=SuFeVcpU7a/AtapXrO/jgjhH1FPTrkDNIsXRe4suRZdYoVkb3ueKt9eJKbqb3K52YZ45Tj PeBYOms6DK8bLWFshSY8TElMt4o8Tv57FIXglkOvdV5qnfpC/Z0CkPzL3XBBz/MWOCiqz2 ZeBmlw/Kw1mzuwLGl4Am3o1yYodG+Mk= 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-585-nWCKUwssPcy1iQL1eiiXVQ-1; Thu, 02 Sep 2021 12:50:47 -0400 X-MC-Unique: nWCKUwssPcy1iQL1eiiXVQ-1 Received: by mail-wr1-f70.google.com with SMTP id v18-20020adfe2920000b029013bbfb19640so747612wri.17 for ; Thu, 02 Sep 2021 09:50:47 -0700 (PDT) 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=D2LfKM2MLO7dI/2WbgBIejM4okTeZPRFh30kX9UHiMjtITb/kCCqzsvyVhj6SCToc+ WbSe7mfsiMwjOAUzfz07mv8Tv8amxlqXX+sL1RbgMjOncauBPpNJu+WB82OB6s8QMUjz 2fhshg3wWRVmHNh+zUWJzGcRiP1ZrDUk4najL6gh4L78Scn3BcN4G9UT4ygFPs2zg2Z+ fPMlUj0fO54+4tyVfjl6vVV9dgdrEjcZx+gMoVAethXCE5sMkEkm7oCnL5Rzp+nUCh4q hG98KhO83HzZT0AiW0mgiKz6x79gGPpVnWm2QaIqaGEUJTrjCrSSzPiXkaDoYWUL+1S/ Aftw== X-Gm-Message-State: AOAM532+FAbHZo1y4DwK9jrvXBqFUdaquD3SGK+wQ1jkXGg+1cM7GW3y bZmD0oboFYs0kHyNDOEZb5xSgR7qarLuar7bIUK5D7lOeJrvU0AALW1lZRK3m+5lbLCbi9+N/9a fvuY3ioyLFWoRTR31+U1gb5OlqEHrrtvhUxmtiWS2yHTEw7qP+6y/W1u7zV4F28ds X-Received: by 2002:a5d:4564:: with SMTP id a4mr4751622wrc.81.1630601445950; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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; } +/* Called within rcu_read_lock(). */ static int virtio_queue_packed_empty_rcu(VirtQueue *vq) { struct VRingPackedDesc desc; From patchwork Thu Sep 2 16:50:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12472161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51941C8302A for ; Thu, 2 Sep 2021 16:52:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B9E560FDC for ; Thu, 2 Sep 2021 16:52:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1B9E560FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:60174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLpxE-0004Zz-63 for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 12:52:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvU-0001ro-In for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:50:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvR-0000KH-VG for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:50:56 -0400 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= 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-34-AkvlXLCDPhW4fcgCSD2k9A-1; Thu, 02 Sep 2021 12:50:51 -0400 X-MC-Unique: AkvlXLCDPhW4fcgCSD2k9A-1 Received: by mail-wr1-f70.google.com with SMTP id h6-20020a5d4fc6000000b00157503046afso749772wrw.3 for ; Thu, 02 Sep 2021 09:50:51 -0700 (PDT) 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=PnrAYT/aD6fIrWk000VfFHFM4aSNsQzxvSiyZ4tYld4Wb2ouTB4RHS0BO3qUVWSsJ0 5Ci2eW8ikQIEr5O06gMtil+MHVL0sco3jQNxp8J/88RFAslJwjmedq4DGcNYY/iDKZ19 edaNwxewVI64vH0bd1fd/r7EMdWg2xqqFRrsQMsInhL7VklskTcNcXU5JbteS6mCmwTe ToNR1QXoHgYN1/2TtKO7ymtA4E57FHEnuvPCikiQMvAF/LwnfyKTd4IGmCQClfadtwF8 UxAAfx5bf68mWUfRlo19/jxKhjsjbcZotyk79RLIUl4VZpxBAWT6f5bYHUeqoCkab/wX qrEw== X-Gm-Message-State: AOAM530WqQ28bD94WxYLylPm4TLyjr1T9pf6bhdeKGRA2ifR1nT1kVb9 BLJYdz8lJGFWf8o6yCaICIP/6c81HljndeSo7pxAb46KkMQcbVWbo2GXFM8yUpo7vb8JR8EeEi2 lpb0CQdsFoYN39U8iMQE3RlfECgwU9oclcel05o+cYlMsSA50r4Cvr1Gzccdvwjbk X-Received: by 2002:adf:910b:: with SMTP id j11mr5126814wrj.114.1630601450260; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reported-by: Stefano Garzarella Suggested-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- 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); 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, unsigned int count) } } +/* Called within rcu_read_lock(). */ void virtqueue_flush(VirtQueue *vq, unsigned int count) { if (virtio_device_disabled(vq->vdev)) { From patchwork Thu Sep 2 16:50:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12472169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89812C83028 for ; Thu, 2 Sep 2021 16:55:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2BA2760698 for ; Thu, 2 Sep 2021 16:55:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2BA2760698 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:40024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLpzi-0001TN-Bj for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 12:55:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvX-0001v0-DJ for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:51:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvV-0000PU-PS for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:50:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601457; 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=SO/TRkzX4zfm+LHbj6So0EjAAQF96/MqXl4jXMXmdt4LiC3MPX6eN28XaZDNReZpIzghf4 Z8SwDOF21Lti7U/6XOXiaDSWv060yheovdr4yxv8VVV+d/1tcFpm6izFbupIjcMNZp0ZD8 OumJAhgKrT/xazbqd6KfcBD9xJBsv94= 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-514-DWnRze0hOEWp_9ED-Ys6ZQ-1; Thu, 02 Sep 2021 12:50:56 -0400 X-MC-Unique: DWnRze0hOEWp_9ED-Ys6ZQ-1 Received: by mail-wr1-f69.google.com with SMTP id 102-20020adf82ef000000b001576e345169so753095wrc.7 for ; Thu, 02 Sep 2021 09:50:56 -0700 (PDT) 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=d9iuk6JrqM5cvE2kVx4noSQ6xs2uM9J4ULlmzhBM5ups7/vXN6c6WJF17/4Snrpx3G NAj90TEzMYFFaI4O4fVMuL/e2qWna6sg770JzZcNxJRojb0TRvxIlN7KTmZ9hniO3mjO Cm1jmsFNirYzXVVeINr03KXNMHv3ym0lxRHVNLeJSwjYmWy9uUVPcDvUaZVspKcoisg8 cTfOWx4GCcdz9lh/IDpZyY2KbH28Jp44xxbiazYOSFkTGZUlxnEZBafvid90C82tO5UW GQnqpuES3p4ihtU43zOt4cMuL/3hOlw3tuQFD2ZyDXga42+aL1mT6IbUb44xnTGklIm+ i4jg== X-Gm-Message-State: AOAM533a19Uy5NbOUXYMJqdGE1rWzNr3k1NlXxvbOSAoN5nwaEn6OZDW Np1cujdZ7lH/y/B9GTxBXzCF/L2XGF2ItfTLGsyHZlpDiCLhHTcHGFiCy3ioCUexIIXEwVnIhkI dYmKJJpm/OZqa0ChelB9LsKqFLmbFnB7Xvz+h3EP0hS53omnRvzIJbuE8KaezTQ95 X-Received: by 2002:a1c:19c1:: with SMTP id 184mr4206766wmz.98.1630601454803; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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; }; +/* Called within call_rcu(). */ static void virtio_free_region_cache(VRingMemoryRegionCaches *caches) { - if (!caches) { - return; - } - + assert(caches != NULL); address_space_cache_destroy(&caches->desc); address_space_cache_destroy(&caches->avail); address_space_cache_destroy(&caches->used); From patchwork Thu Sep 2 16:50:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12472167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 490F2C83026 for ; Thu, 2 Sep 2021 16:53:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0B30960FDC for ; Thu, 2 Sep 2021 16:53:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0B30960FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLpyC-0006ev-7l for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 12:53:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvc-0001x9-4t for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:51:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46120) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvZ-0000Tv-VP for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:51:03 -0400 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= 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-54-RVdAuWNsOzuJezT50lpmRw-1; Thu, 02 Sep 2021 12:51:00 -0400 X-MC-Unique: RVdAuWNsOzuJezT50lpmRw-1 Received: by mail-wr1-f70.google.com with SMTP id h6-20020a5d4fc6000000b00157503046afso749886wrw.3 for ; Thu, 02 Sep 2021 09:51:00 -0700 (PDT) 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=uS8KdUlWHXIp4mhcfRoM4R/HXnoPIuU9oflhRVS9ahLlEhrBxqwx+5Zzp1Epn3jHIi pfvR77U9EEo7V1dnvnUiAPG7fYKeEXXtyCALGu99XkTzdgTQiLG8UyfJ0Eg7o2wSLn0Z jFZJAwvkATrEACXoYvkoHZ9LbIPESvmSw/BuhVc61nB2TciH9rB03pzP+BS+iMocg517 PG5uHVGjCFArmaMjBc5SUmrVVcXNT7joOeuWEBVyh4TjaLg8mB/mIUewzDnZyTXf0aoN WqlI2kevBFBZSc6n5C7pNGIC+23k+euOSpzSCvw2XZeLALyyEDaDoT+SU8lus4CpsSVQ JcQg== X-Gm-Message-State: AOAM531N7Radx7+9Lz6MLs+USMdGcDr8hUWB+LE3UwBOwww7pfdGtuGO r93gYGly1Yde/DCnLJ4ZsWnNxpxLT1yLZJhiAiJ1CWITst2hLvSv8VAeDGMarEkybpcq6x1/LU9 s1H7SonqHzE5p31cgtmIUWF6TCKrtr2GDzkbInoLNr/lWZMLp63FgvmWoVWGTce8b X-Received: by 2002:adf:c405:: with SMTP id v5mr4922742wrf.183.1630601459025; Thu, 02 Sep 2021 09:50:59 -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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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(VirtQueue *vq) VirtIODevice *vdev = vq->vdev; VRingPackedDesc desc; + RCU_READ_LOCK_GUARD(); + caches = vring_get_region_caches(vq); if (!caches) { return 0; From patchwork Thu Sep 2 16:50:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12472171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54BFEC83026 for ; Thu, 2 Sep 2021 16:55:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC13360698 for ; Thu, 2 Sep 2021 16:55:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EC13360698 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:40072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLpzj-0001V4-5k for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 12:55:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpvi-0002D5-MQ for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:51:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42137) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLpve-0000Zk-Iv for qemu-devel@nongnu.org; Thu, 02 Sep 2021 12:51:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630601465; 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=HieHzo+91sdOlE7OXlNiF6si3EkEnPB03giDPOjO49LtjYhKPas3mVn07TeO80PuwT7v0S 642+0N4ICd6JIBqzZUJv3ujsv0yUNaFA1qWXgD/wxnxDubhn232/ZisKfB82XFVDVl1pCy lsNlkVHq7o+605/lOnpPb3NX7A7I1qQ= 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-591-RrmMJfjTOH2D2dWzNzLrMg-1; Thu, 02 Sep 2021 12:51:05 -0400 X-MC-Unique: RrmMJfjTOH2D2dWzNzLrMg-1 Received: by mail-wr1-f69.google.com with SMTP id z15-20020adff74f000000b001577d70c98dso750573wrp.12 for ; Thu, 02 Sep 2021 09:51:04 -0700 (PDT) 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=qUTsE2TH2f3ytzUL+g2DXOO+DNY11J92J+7IFHaipMmSPsNYmQLk0xH0bRpAvahtbF C+rnHujJ73XNFAan4xsIhw5Is2qShzIlerbvyVg04ULHS0rodKRh8apWa0/eE05Za7YE QIzveKP9wTI/sU2V6G4WBCzu8myhJB/1KKc0L01kUpbC92CE4TKjSlj77m2RGbBPc4mx EzHSTxmKcSGBDVLkU+ebROEh36C2iisB15snyB9F7Ojv9PUXdb4PUk3TNsJFwFltJgBf JHNAsYD1VCVG87CUemcJKFWxorzXs5OsVHMLMmeHjzZJnPfzYmaW2+NJLnOooegVatsk TEhw== X-Gm-Message-State: AOAM531SvmSdni67Ej6tk1t3ywLJs0PeumNsRDTXLAKmBOHriTFoxBEx trajCvClUzPCt7K1tHj/m8dG4XFZV5hxHZC9y3IckxXB4kb41+UqGN+1vK6WcyJy1ZUnDnfv8HJ XhAEBEHdIMhkO5gw5HEZr3fGgUV/IyAQTtiGI4jYu+wZPpa/z3IOw28GjWsMWRBr7 X-Received: by 2002:a05:600c:2186:: with SMTP id e6mr4061401wme.71.1630601463556; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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(VirtIODevice *vdev, VRingDesc *desc, return VIRTQUEUE_READ_DESC_MORE; } +/* Called within rcu_read_lock(). */ static void virtqueue_split_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, unsigned int *out_bytes, - unsigned max_in_bytes, unsigned max_out_bytes) + unsigned max_in_bytes, unsigned max_out_bytes, + VRingMemoryRegionCaches *caches) { VirtIODevice *vdev = vq->vdev; unsigned int max, idx; unsigned int total_bufs, in_total, out_total; - VRingMemoryRegionCaches *caches; MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID; int64_t len = 0; int rc; - RCU_READ_LOCK_GUARD(); - idx = vq->last_avail_idx; total_bufs = in_total = out_total = 0; max = vq->vring.num; - caches = vring_get_region_caches(vq); - if (!caches) { - goto err; - } while ((rc = virtqueue_num_heads(vq, idx)) > 0) { MemoryRegionCache *desc_cache = &caches->desc; @@ -1125,32 +1120,28 @@ static int virtqueue_packed_read_next_desc(VirtQueue *vq, return VIRTQUEUE_READ_DESC_MORE; } +/* 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 *caches) { VirtIODevice *vdev = vq->vdev; unsigned int max, idx; unsigned int total_bufs, in_total, out_total; MemoryRegionCache *desc_cache; - VRingMemoryRegionCaches *caches; MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID; int64_t len = 0; VRingPackedDesc desc; bool wrap_counter; - RCU_READ_LOCK_GUARD(); idx = vq->last_avail_idx; wrap_counter = vq->last_avail_wrap_counter; total_bufs = in_total = out_total = 0; max = vq->vring.num; - caches = vring_get_region_caches(vq); - if (!caches) { - goto err; - } for (;;) { unsigned int num_bufs = total_bufs; @@ -1251,6 +1242,8 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, uint16_t desc_size; VRingMemoryRegionCaches *caches; + RCU_READ_LOCK_GUARD(); + if (unlikely(!vq->vring.desc)) { goto err; } @@ -1269,10 +1262,12 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, 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); } return;