From nobody Sat Nov 15 16:05:50 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595419978; cv=none; d=zohomail.com; s=zohoarc; b=T7ALr7IGiTrd512hXGE/XIo4oMSwozaJqPCF8eH9dlufnPe2YsPutSMw6TWkeRapyPqbT8l0BWySX6PE6jT7SdV0jgPhMzXp/kIJqVvLqna1p0iSfhust20qubKOKd9P2MPzpufg4aW5Wq87A3OSvv0WeOgSoMXdLyUk8MT8nUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595419978; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NUjKfU8xPyPB+FtStfFVhRssHx17cxqyTATNtRp+vz4=; b=JnX3Yis5kIo+8JGL16qnBAGUf/X7zv41FfgwbThfCuHxgTCD/pjqi3+K514d4CzX8xsX69VqNvLJerKmKRhxf8B5jUNY5zIH6Mip0E1iXPTTgKdJqrLoxuTR1l/gqUCac/sN9OpuwetIoz8yZrd/EwEbkAsRw2MrVmfwJomRMpU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15954199782221022.3421200743435; Wed, 22 Jul 2020 05:12:58 -0700 (PDT) Received: from localhost ([::1]:33558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyDcG-0002Kl-B0 for importer@patchew.org; Wed, 22 Jul 2020 08:12:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyDYw-0005tb-5I for qemu-devel@nongnu.org; Wed, 22 Jul 2020 08:09:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:33856 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyDYu-0006b5-HU for qemu-devel@nongnu.org; Wed, 22 Jul 2020 08:09:29 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-243-3oi3DBhcM5uXede-ro2VkQ-1; Wed, 22 Jul 2020 08:09:25 -0400 Received: by mail-wr1-f71.google.com with SMTP id f7so548017wrs.8 for ; Wed, 22 Jul 2020 05:09:25 -0700 (PDT) Received: from redhat.com ([192.117.173.58]) by smtp.gmail.com with ESMTPSA id c15sm7030290wme.23.2020.07.22.05.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595419767; 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: in-reply-to:in-reply-to:references:references; bh=NUjKfU8xPyPB+FtStfFVhRssHx17cxqyTATNtRp+vz4=; b=PCWzggehhV14DZpxZxcf/0h6ye+3/43JwbrYa5YexRsVKr57b+ACPeWvsMjVEITW+GRPA7 ucxDGk94KNs6SFWdT1ygv4gA/gw/KClt4fS9+mkwurdIWdNWNbTbl3WiwGcaxXR8fNNz8V qemMVq/yjuluK1KcWEtgBJEZdXZU7IM= X-MC-Unique: 3oi3DBhcM5uXede-ro2VkQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NUjKfU8xPyPB+FtStfFVhRssHx17cxqyTATNtRp+vz4=; b=Ovno1iCvVW+/oldduIn70gwxE93BC5RE3zxGV48tIsTlFusxD7JfLhcgDpfCJ+675W 08RL1GyB3+re3R5VKJkxCdkpM7h6uCFgYNDhbBsd787gwsVJkDws623NuOjfjGGttJV4 uMjbDRnlPnAetuB/J7IUWEUo9GQko45V8pqkL4NAXdD+coPsG5ORPl/qvACt0htW/FTk LjtcMHU7S75Flc0ntzXb+ghTcQ+rZaH6iY/TWmhdqQGvFZg/Q0PTjx2DddG0Sd5vcVcp raYLTTfKrtkRU4Yz9rdLCTJvl/pJF/lxq8SUGlu7MNBeo+HPJAa0LNcRk+AvIpdraJSP IINA== X-Gm-Message-State: AOAM530b6lP+1IvG5dfTd0qYgqryjFQ98KBsOpzlz7xGAY9OwNsxFGvd gELLgbwLZfBXVV3IGhrrmiHoHCzlZwK1Zpg92I5HRr18PWLzbSlI5b4W1TK8aULfEYbgFBMVI81 O3nOOInIMiYzbfs8= X-Received: by 2002:a5d:6452:: with SMTP id d18mr30214148wrw.284.1595419764451; Wed, 22 Jul 2020 05:09:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywLvE/HpaJUjLAnM/Buzt27JVDJOexcCH/TOfLWPum0pulI5tfRhbdYFN6f4VH0laKb/SwyQ== X-Received: by 2002:a5d:6452:: with SMTP id d18mr30214130wrw.284.1595419764269; Wed, 22 Jul 2020 05:09:24 -0700 (PDT) Date: Wed, 22 Jul 2020 08:09:21 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 4/9] virtio-balloon: Add locking to prevent possible race when starting hinting Message-ID: <20200722120853.9144-5-mst@redhat.com> References: <20200722120853.9144-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200722120853.9144-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/22 00:40:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: Peter Maydell , Alexander Duyck , qemu-stable@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alexander Duyck There is already locking in place when we are stopping free page hinting but there is not similar protections in place when we start. I can only assume this was overlooked as in most cases the page hinting should not be occurring when we are starting the hinting, however there is still a chance we could be processing hints by the time we get back around to restarting the hinting so we are better off making sure to protect the state with the mutex lock rather than just updating the value with no protections. Based on feedback from Peter Maydell this issue had also been spotted by Coverity: CID 1430269 Acked-by: David Hildenbrand Signed-off-by: Alexander Duyck Message-Id: <20200720175122.21935.78013.stgit@localhost.localdomain> Cc: qemu-stable@nongnu.org Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-balloon.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index ce70adcc69..6e2d129340 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -592,6 +592,8 @@ static void virtio_balloon_free_page_start(VirtIOBalloo= n *s) return; } =20 + qemu_mutex_lock(&s->free_page_lock); + if (s->free_page_report_cmd_id =3D=3D UINT_MAX) { s->free_page_report_cmd_id =3D VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN; @@ -600,6 +602,8 @@ static void virtio_balloon_free_page_start(VirtIOBalloo= n *s) } =20 s->free_page_report_status =3D FREE_PAGE_REPORT_S_REQUESTED; + qemu_mutex_unlock(&s->free_page_lock); + virtio_notify_config(vdev); } =20 --=20 MST