From patchwork Thu Aug 26 17:26:56 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: 1521267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iKXJ1XPr; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4GwVlZ3bHZz9sXM for ; Fri, 27 Aug 2021 03:51:38 +1000 (AEST) Received: from localhost ([::1]:57792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJJXM-0001uX-6g for incoming@patchwork.ozlabs.org; Thu, 26 Aug 2021 13:51:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJJ9i-0005pA-30 for qemu-devel@nongnu.org; Thu, 26 Aug 2021 13:27:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28622) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJJ9g-0007OI-Hc for qemu-devel@nongnu.org; Thu, 26 Aug 2021 13:27:09 -0400 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= 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-584-8G1BImrqP-2R5jE6VgXbIg-1; Thu, 26 Aug 2021 13:27:06 -0400 X-MC-Unique: 8G1BImrqP-2R5jE6VgXbIg-1 Received: by mail-wr1-f72.google.com with SMTP id d12-20020a056000186cb02901548bff164dso1069585wri.18 for ; Thu, 26 Aug 2021 10:27:06 -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=6H+L02mu2VtYZ9Ci4vq9bPbkxedEevnpYIa7Jf3+z/I=; b=NpKYAahOO7uzfeaju+HdT0VwmwBiZMSiezQ4RZ8ghXZwNBdUTw6cMUu6X/ze/Jhfbw 9yRrHSVr43EUmciv5tyaeYOU/rVMxJOqLiKY75xgcW/E0+ZDBpR9R7mU0pRUtTFYByf0 4O46dsKJtmJ7Ye1+wZ1ixSHeeihAsMaOmxMZRtLGOFC8pbtRF82FQpXrhbWq1dWYgvrg rgvWXdwzLiH6RgQCb8NzUJcs5yZ9zBJYGewbRWEbgWr3o0q3WxWGSWOyyAwto9JJQ7Cy v5ntjk0wCrtavo5lwEObUp05mmUs307iN39FmjIrhSYsWBGR6gEB1Pt+MavlnHi2WYXg siLw== X-Gm-Message-State: AOAM533QHSKVM0JReDeNIu64gMhNBRf86RIaqIF8Kiiy2EDA+1C8q2JZ 8Zb+0HwXHPIKqUpY9mIGPDLpoWp6S6gdMh4PeX8xjtftOlAthGDWHwzmNhf5ZMNIfr2JClQn0wZ Mv+VbjhEb3c5oUGSPsTKOqkpdBSmDJTuDaZV3WvDbonYA2c7xNsDwDHyliMfZBVEY X-Received: by 2002:a1c:2042:: with SMTP id g63mr15507757wmg.27.1629998824996; Thu, 26 Aug 2021 10:27:04 -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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, 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?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi --- 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 Aug 26 17:26:57 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: 1521241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hFIT9Z21; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4GwVFt4tdNz9sWX for ; Fri, 27 Aug 2021 03:29:22 +1000 (AEST) Received: from localhost ([::1]:36226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJJBo-0001Fm-ES for incoming@patchwork.ozlabs.org; Thu, 26 Aug 2021 13:29:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJJ9m-00065g-Jt for qemu-devel@nongnu.org; Thu, 26 Aug 2021 13:27:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJJ9l-0007RY-27 for qemu-devel@nongnu.org; Thu, 26 Aug 2021 13:27:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629998832; 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=hFIT9Z21/C0brBsPFrjPF9B9oteA8KUwxGK6VNC3R7nE0gMK57X8LeXuoILVDzL+ricB03 T8bSiVwPm0R0oOeoOCQ1cwOgjQ7+qC/QHEpy6AP/5J1ix/o3c8n0xAxCIat/L4nY2eZu6x pst5383L3sMXZH4+wqTyEGxorSKNCvw= 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-376-e2xJz4alOUCjfOsF6f2zLQ-1; Thu, 26 Aug 2021 13:27:11 -0400 X-MC-Unique: e2xJz4alOUCjfOsF6f2zLQ-1 Received: by mail-wr1-f70.google.com with SMTP id v18-20020adfe2920000b029013bbfb19640so1066809wri.17 for ; Thu, 26 Aug 2021 10:27:11 -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=KDBZg389G66cuuXg1cBtciC2SPgn2cHOhDyJJyO+H/o=; b=svYjLJEhr62Qu2Aonje0pAOTjzo76ba3zDAh/s8ddWneC4rYoQ/nmcsas/PeJnHMUO i5XSkFfYMGXVW6jEP5aZRu/cvLQ4rbHT2OGkBKbF+ppjaMUWkiQ3BeJy1TVowX29nJRw EmOGs1lek8hxowFIYdAT09ZZti8DbN1M++Fq48Bl7Mclc1vSgSzlScDq1NMj88XEt6r7 AND54C+//jmJ0gZgt6KXBW48UKDI25zuGpFLE438Fn5VkVhZSloRlcFv3x5bhMBC1R46 T8Eej7BDLSpFs2+AcaDYK9dbQORuB3cgAZUU+gStIDCAlQN1wcDom2gXFqFyMMRuGrrH 5aDA== X-Gm-Message-State: AOAM531hiP4TR9d24+clDOBB9/DtaqaTdgIHCvduITJz6WvHdGFv39pi QuU3QjkepNMQIif66c1yL6p/3oz73RZpKN+1277mBG4wQKIiKubmtTSNpXlS7umEi7JS67f2b98 zWe3U4kJvqppnavWrC28WkJIPkk1diDDbiycnyR4N9iHULHDyaVc1eRFB/V1tm/xY X-Received: by 2002:a7b:c92b:: with SMTP id h11mr4831153wml.62.1629998829541; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, 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?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi --- 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; }; +/* 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 Aug 26 17:26:58 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: 1521270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cVY++T/b; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4GwVpg10hlz9sWc for ; Fri, 27 Aug 2021 03:54:19 +1000 (AEST) Received: from localhost ([::1]:36364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJJZw-0006RZ-TM for incoming@patchwork.ozlabs.org; Thu, 26 Aug 2021 13:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJJ9q-0006Iz-W8 for qemu-devel@nongnu.org; Thu, 26 Aug 2021 13:27:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJJ9p-0007UH-62 for qemu-devel@nongnu.org; Thu, 26 Aug 2021 13:27:18 -0400 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= 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-232-ZYgXQIfHMd-HMS0lC01rxw-1; Thu, 26 Aug 2021 13:27:15 -0400 X-MC-Unique: ZYgXQIfHMd-HMS0lC01rxw-1 Received: by mail-wm1-f72.google.com with SMTP id j135-20020a1c238d000000b002e87aa95b5aso3808440wmj.4 for ; Thu, 26 Aug 2021 10:27:15 -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=u6X8NyK5dk4UMskkp60riuy7ptxhQXw1NrJ4q4sajpM=; b=cEI7893NidSOcDfpVADbulz/ZE8/BWzJfCu2vfPfca9ZDtXx60bbb3UF6EaBaRrHZL SoEmD95YZBwHp9HP8HHytrG+EULLvF+7fIUFmdwIBHrqA8PNhWs8JmDi5LFkTUb7hnT4 V2BhZo/MYZOkdvF7mPiUyRr/4zqJRroZAuRazuv4UiQXHxDKhQ9YhERXoLSzgUM0nbHf m6Q9Aqwpff/77gg3+speiNtgF1Nh9Dj/eYuDOqZfUmSfcPPrcqWdeAX6VnjWscoN1q5t hKnUIlcxz1FJ62pdZ25+mbJEdHN4I66TkD11ymOQKyekCNfeasXm2CvGwg2gFYhfzb3i BB1Q== X-Gm-Message-State: AOAM530lwuh82lCmLm3AGwRsakjan97p/vKevS5Wbt8TOIt0FfZ/EVFA g7g41Y9rIiQa0x4ZmNqr5CQlCZgl9XsNvzo2i/L0QozvIHTKJO5Bu9ldvGa0fs30YhJBx1wk7QT 4gGMWgMP0EU1469XUlOC+nhoO30p/R2Stz/crhufkM7IOP6SzWG28RQMnlyRVW1pN X-Received: by 2002:a5d:58c8:: with SMTP id o8mr5506609wrf.361.1629998834003; Thu, 26 Aug 2021 10:27:14 -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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, 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?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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é --- 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(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; @@ -1124,32 +1119,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; @@ -1250,6 +1241,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; } @@ -1268,10 +1261,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;