From nobody Fri May 17 11:28:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1595267541; cv=none; d=zohomail.com; s=zohoarc; b=JRQmmZt3sDx/XlxvXxsh6CGH/EFHlKNktXPXXZ4BHCqtC2JYu4iA/ogZmH1OjSNpEIn42idAkdBzQw9otWagirNPd8idLPVTwRSKYHsl1faSXK2M3Fn0dBuezZE/sTlpLBeA9hMgQOXRvEGzlI3+r+6/wR9ZUsNAsXZ5ZmlV7SI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595267541; h=Content-Type:Content-Transfer-Encoding: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=8xPqwSKZbL19VmcpEGdAEfQGyxRaLAdfuPGoNzIkPJw=; b=i7qYGuZsGiB9D8x2Zr0Lfs6ocgCKdJHiH4FuZylvb/l0rn1kVo6PBvg2ChD10FDSEQsYBsxMS32nUuU3hyQsSsDXEgw/XrMtJy6SWWU+rC0q8PCwQMCnhct5bc/1763GCG15/f5uEy5NkP+CIOpGCqL3lNsDSjT6NLN80Vb54WY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1595267541354671.0396745402666; Mon, 20 Jul 2020 10:52:21 -0700 (PDT) Received: from localhost ([::1]:51542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxZxb-0000S0-UZ for importer@patchew.org; Mon, 20 Jul 2020 13:52:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxZwd-0007hb-QN for qemu-devel@nongnu.org; Mon, 20 Jul 2020 13:51:19 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:36433) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jxZwc-0007hx-7N for qemu-devel@nongnu.org; Mon, 20 Jul 2020 13:51:19 -0400 Received: by mail-pl1-x644.google.com with SMTP id t6so9007056plo.3 for ; Mon, 20 Jul 2020 10:51:17 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id cv3sm198351pjb.45.2020.07.20.10.51.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jul 2020 10:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=8xPqwSKZbL19VmcpEGdAEfQGyxRaLAdfuPGoNzIkPJw=; b=URoUCuQBXxHz36riS6Vr3Osyk/spb7yq9gyMDvRCl4embd3rcjUqJFtHjPveQvXRSa Z1GCJPf7AxNiY+j5ZrXz7mH6gXPlqzK+nbRL6AUsd+GmrlbrxRK9YbqN8DWXzGAmkBs6 6ys9GcCFjsWkMOzG/S3pjq7XVMWvM0lYkHgXA/imFwaKY5g+iJzSQuxfRvp/u0KWMfB5 RYgZ6mH3MUIQIuLsMJStKMUMnF2yi/UYC7RyMIahE5l2SNIvruEwAhMWX3E8Gz+N6NjB hOx6a+DGNoLcwe3/yQZT73eMY7Z5ghfkSggRkJprQXVmU63MuvbaTNxlY2EdKRF5qin9 5Qmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=8xPqwSKZbL19VmcpEGdAEfQGyxRaLAdfuPGoNzIkPJw=; b=Qy5CkZaTDewWzRRVXMn8humgYbUFNgqH0icwRtGvIh2+sBYESI6ggyxZtAQ1PSEA6n EdtOKc2wFl6Co/NWuW7RnKv2neXO7GIjryW5fwZ+u4VVUlheYcehEgZJgamQO6MZLxwR T5rex94ji6G9e9RAYwOnPNrXS6BcHXFROIxja+DsuERoLJX52jctvdEZ5owGd/3Ovqx/ 42I8v6pBoPbiTN8qrCnjJNm8t6mhw0PuavWe6aKqf/Z6DZaWJQ8nDQsqKA6pbyIOm7g3 thyaNBrZBqXCEnMCIjnmwpBlYphypsa1kk+THmtyprjYhPuKJhKXduwiy986K6AV0OAD /pRg== X-Gm-Message-State: AOAM531AMjMOqFAXN4o4tY+0FTYFMiwF90Tjxnqm2bfAGjdgl0/O2h9R FXsJ/dshG5DHYLzhPjwiQD0= X-Google-Smtp-Source: ABdhPJw3QB1td88FSdMZtdbMS0qeAFM5qMvmKDoERxIx9vZ4hzdQ0h/Pxqsk880tA49Ys1MjUBdtWg== X-Received: by 2002:a17:90a:ce90:: with SMTP id g16mr551128pju.109.1595267476904; Mon, 20 Jul 2020 10:51:16 -0700 (PDT) Subject: [PATCH v3 QEMU 1/3] virtio-balloon: Prevent guest from starting a report when we didn't request one From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Mon, 20 Jul 2020 10:51:15 -0700 Message-ID: <20200720175115.21935.99563.stgit@localhost.localdomain> In-Reply-To: <20200720175030.21935.80052.stgit@localhost.localdomain> References: <20200720175030.21935.80052.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::644; envelope-from=alexander.duyck@gmail.com; helo=mail-pl1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) From: Alexander Duyck Based on code review it appears possible for the driver to force the device out of a stopped state when hinting by repeating the last ID it was provided. Prevent this by only allowing a transition to the start state when we are in the requested state. This way the driver is only allowed to send one descriptor that will transition the device into the start state. All others will leave it in the stop state once it has finished. Fixes: c13c4153f76d ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT") Acked-by: David Hildenbrand Signed-off-by: Alexander Duyck --- hw/virtio/virtio-balloon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index e670f1e59534..ce70adcc6925 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -526,7 +526,8 @@ static bool get_free_page_hints(VirtIOBalloon *dev) ret =3D false; goto out; } - if (id =3D=3D dev->free_page_report_cmd_id) { + if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_REQUEST= ED && + id =3D=3D dev->free_page_report_cmd_id) { dev->free_page_report_status =3D FREE_PAGE_REPORT_S_START; } else { /* From nobody Fri May 17 11:28:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1595267548; cv=none; d=zohomail.com; s=zohoarc; b=Y9J1sB7Mlo64BYL37epJTpV6hSmOMMtQs1cW0N6X3ifVh34gko97vyhlvlAm1aDjsPkvqqrUpRL0txDh+PqHbuyEL9hyI8nwX+2o5Laq0FtR5Ai1PYOP/D6OB02IAMQjLAGaN1EcjoiitU2SClA28sL6/PigMP8DFbYzp3PxtZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595267548; h=Content-Type:Content-Transfer-Encoding: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=nCKUBraGXRlMO/ENL1FojgjZW4PKZM/+PVsaTrP9Vag=; b=FnTBzMTbQQ33EcQy2byLdSoYNyTKE0qEVx9/89OxQuMJ1VTCKjcTZfMoBwQfkffVimJ76Y6hcfhEIdP/+rXRRuMecqGHCJKW3K/lUakJxR5K798IEOS6RuuIsSgY0Ua+6WBEAMotd8OzwFZV1htrwaDjVXfDiXGPdxRtSX1WVLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1595267548616488.22564669672965; Mon, 20 Jul 2020 10:52:28 -0700 (PDT) Received: from localhost ([::1]:52174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxZxj-0000hy-G0 for importer@patchew.org; Mon, 20 Jul 2020 13:52:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxZwj-0007rK-Uu for qemu-devel@nongnu.org; Mon, 20 Jul 2020 13:51:25 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:52934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jxZwi-0007iZ-BO for qemu-devel@nongnu.org; Mon, 20 Jul 2020 13:51:25 -0400 Received: by mail-pj1-x1041.google.com with SMTP id gc9so187795pjb.2 for ; Mon, 20 Jul 2020 10:51:23 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id g28sm17087908pfr.70.2020.07.20.10.51.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jul 2020 10:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=nCKUBraGXRlMO/ENL1FojgjZW4PKZM/+PVsaTrP9Vag=; b=V8uirNNRA5UV1t0s7+TCIyz7WsX+UPn4LHC6d8SaNUkDulrAvhiGM5SZ91iBk6izpW GfyRWVg0h0AI0xVBiNxo8b3/XOYEenMtmpzNxox/lsKdfmZE4E3JRPf7t8evvVdM3R4B ih2kIEQG+PHwiDH0BaRcB89Y5m6g5W6yu6wrXflAK7/kDI3reWPjOa86komoJ5bJFREm iSi8tYKz9fQGhAT/a+et6VEc/FRkcxih6vGdCKOr7qLPZbJ01dpvMELQJe2ZqYJG7h+/ +waFQ0ByRbHDX/WmYwnlWLRDNw4CZlLofYsayPl1URFxLVf0E02zZLr01dq5HA0vKCXy SA8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=nCKUBraGXRlMO/ENL1FojgjZW4PKZM/+PVsaTrP9Vag=; b=cHR1dDhnFkPhQI9GeJ8K3ZT4uoOIn2aQKjVhrK+XGFXWHZJKA4G4G6znSXBspgasP2 48nnHlvc8NaRW7UOFjJhbOy2XbeoJxVhukCCa7qBkdOf4oyGgMPlyq0sYC47mCBpzYPT a8l6cp8r63C7nDfSOyjTVlXHRh+6f9hDBiAYyIMxWvmKQAj+m/t0Rxld/FWlKDMUx++Z hEuiXO9kYsQPTaTaMED39g8nIgEyd+6tTjVrNNFyn/Po7GInNv/ZwdgJC78nhRHcZRDL C0bD8X9u8aBgwNHtKV/+2c7hvQ3TV4uW8kOjNRn1f62wTFM88NPfXt/bC8Rwj7P6nEFh cHEw== X-Gm-Message-State: AOAM532N0o0VS1t1fq4P7tY5WQbwqx13+0lRdF24vaPwRguqXJwl9yxu YCFX+QPe3gVeKM/5xYqI8yc= X-Google-Smtp-Source: ABdhPJxBxMKYWsEEQsVFaX+bDOXBAjSsPcA2rsUjyVGVCJ4chEqcdQEugziEbRXruJCCOmXrSASGhQ== X-Received: by 2002:a17:90b:102:: with SMTP id p2mr540561pjz.227.1595267483054; Mon, 20 Jul 2020 10:51:23 -0700 (PDT) Subject: [PATCH v3 QEMU 2/3] virtio-balloon: Add locking to prevent possible race when starting hinting From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Mon, 20 Jul 2020 10:51:22 -0700 Message-ID: <20200720175122.21935.78013.stgit@localhost.localdomain> In-Reply-To: <20200720175030.21935.80052.stgit@localhost.localdomain> References: <20200720175030.21935.80052.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1041; envelope-from=alexander.duyck@gmail.com; helo=mail-pj1-x1041.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) 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 --- 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 ce70adcc6925..6e2d1293402f 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 From nobody Fri May 17 11:28:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1595267623; cv=none; d=zohomail.com; s=zohoarc; b=XEw1ww4FoEqBGQaAkpKXQuuMtMCKMcVdVF3y0axkhbRVE64HJSv9RoP+rGL6uRty7HOK1gDwiuPEfaUMb7cPFfgJGZb4leewLK9/f9ZgCKxhmHmvZQ9ilVzh3shjwYUlfNiHBsna409DfW14EsgTOBDb4Ka5aZN79J0JSGoAwjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595267623; h=Content-Type:Content-Transfer-Encoding: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=kdnUznMZUhuIP+t9g+9Wy3UnTwyDe92Jvtq48h5lZsM=; b=OHT3zUs+gooplaPVUZV8h6WcD4YVRAVbEZlKOuGrKNeEThfSZhjypLgFUkETZsqF2MyqISBtWN66yZ2Aduo4jZbL42+TIDBoz4EixhZZrAcIz75dVwWsfnc1pSW+H7BrdKVL+YrYBilahOhbmsSwsZ+ImvEVBST2hHeaBmAr9+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1595267623527967.6665514923486; Mon, 20 Jul 2020 10:53:43 -0700 (PDT) Received: from localhost ([::1]:55964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxZyw-0002Iq-4g for importer@patchew.org; Mon, 20 Jul 2020 13:53:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxZwq-00085i-Vl for qemu-devel@nongnu.org; Mon, 20 Jul 2020 13:51:33 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:55046) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jxZwo-0007ix-PP for qemu-devel@nongnu.org; Mon, 20 Jul 2020 13:51:32 -0400 Received: by mail-pj1-x1042.google.com with SMTP id mn17so182146pjb.4 for ; Mon, 20 Jul 2020 10:51:30 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id r191sm17852412pfr.181.2020.07.20.10.51.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jul 2020 10:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=kdnUznMZUhuIP+t9g+9Wy3UnTwyDe92Jvtq48h5lZsM=; b=LenBnXq7ZlqdH+mGO/CaLv9a1/5IItalJDLBgF9MDL4gpea7Qy71IhPpOdCMnmlnMw 9xGJsiW3wbs1LkTUMHyJL7UVxVGcHZD7cceVlYhIC2dgBljGWxYVc8wFUVd9oqtOHj7P KISFZo/+NFLHYd2g0daUyiHlftQrrc8JdizqQMOhJ8QOMf6Xrcf9eISKvbG7tejTBrw6 lQ+9Gwa6/2pdF2tv9OnzPOvgz6/Edaqjp7wDbRed7hzjVSiSUnbJzvx1eXRRP+fZ+m8P rarToOvY7QLiJYVR8ug7hpiTmEiYc0yPxrVfucWLeSWbeChDZqGdrGaEkc3heDQMw944 msMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=kdnUznMZUhuIP+t9g+9Wy3UnTwyDe92Jvtq48h5lZsM=; b=GnUwn/jUoSQHB82dYUP/Qzmd8b9AJhgh/MJjlz4ZVZi6hpnZUzySuZw/CzrmYiSbvf 1qapw2DBXtST8z0hhyOnEgyzY2foSnvJJNNNtaDVufRbxAuUgvoknbq15cBfWV/LE7Vv UZnqggZ/mJ/oorO8+EaLvANQxDerfemQlSjkf36hOO0S9mHotd1qAEGPHKOIPbu3RdPH oR3LW/WeesrEn3pEW8yP1THJUjCDPCP+98OcnqpTxnEUxxoNRj/T7wjiCPkSAPz/AZ1J es+0F9+ktNOAOaWLfU1ebpicL4yqsr/MFFrIlekberpDUDjv6iihRhLOvfN8RCHqSzb+ xfWg== X-Gm-Message-State: AOAM532F2jKUFPZjIbziekMBOgAZi8SNSyjB9Nhol4T5Xz48gYsOUqV8 tfHo/AprmfC81dViFcxFx7Y= X-Google-Smtp-Source: ABdhPJxHgd3fNgF/cAM95kmjdsDlt8vqDqERf3i7mWcSPrHn2DKM3+7m0YRvS+OgbMnCFn67rfzIdg== X-Received: by 2002:a17:902:161:: with SMTP id 88mr19389162plb.325.1595267489229; Mon, 20 Jul 2020 10:51:29 -0700 (PDT) Subject: [PATCH v3 QEMU 3/3] virtio-balloon: Replace free page hinting references to 'report' with 'hint' From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Mon, 20 Jul 2020 10:51:28 -0700 Message-ID: <20200720175128.21935.93927.stgit@localhost.localdomain> In-Reply-To: <20200720175030.21935.80052.stgit@localhost.localdomain> References: <20200720175030.21935.80052.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1042; envelope-from=alexander.duyck@gmail.com; helo=mail-pj1-x1042.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) From: Alexander Duyck Recently a feature named Free Page Reporting was added to the virtio balloon. In order to avoid any confusion we should drop the use of the word 'report' when referring to Free Page Hinting. So what this patch does is go through and replace all instances of 'report' with 'hint" when we are referring to free page hinting. Acked-by: David Hildenbrand Signed-off-by: Alexander Duyck --- hw/virtio/virtio-balloon.c | 76 ++++++++++++++++++--------------= ---- include/hw/virtio/virtio-balloon.h | 20 +++++---- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 6e2d1293402f..22cb5df717b1 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -526,22 +526,22 @@ static bool get_free_page_hints(VirtIOBalloon *dev) ret =3D false; goto out; } - if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_REQUEST= ED && - id =3D=3D dev->free_page_report_cmd_id) { - dev->free_page_report_status =3D FREE_PAGE_REPORT_S_START; + if (dev->free_page_hint_status =3D=3D FREE_PAGE_HINT_S_REQUESTED && + id =3D=3D dev->free_page_hint_cmd_id) { + dev->free_page_hint_status =3D FREE_PAGE_HINT_S_START; } else { /* * Stop the optimization only when it has started. This * avoids a stale stop sign for the previous command. */ - if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_STA= RT) { - dev->free_page_report_status =3D FREE_PAGE_REPORT_S_STOP; + if (dev->free_page_hint_status =3D=3D FREE_PAGE_HINT_S_START) { + dev->free_page_hint_status =3D FREE_PAGE_HINT_S_STOP; } } } =20 if (elem->in_num) { - if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_START) { + if (dev->free_page_hint_status =3D=3D FREE_PAGE_HINT_S_START) { qemu_guest_free_page_hint(elem->in_sg[0].iov_base, elem->in_sg[0].iov_len); } @@ -567,11 +567,11 @@ static void virtio_ballloon_get_free_page_hints(void = *opaque) qemu_mutex_unlock(&dev->free_page_lock); virtio_notify(vdev, vq); /* - * Start to poll the vq once the reporting started. Otherwise, conti= nue + * Start to poll the vq once the hinting started. Otherwise, continue * only when there are entries on the vq, which need to be given bac= k. */ } while (continue_to_get_hints || - dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_START); + dev->free_page_hint_status =3D=3D FREE_PAGE_HINT_S_START); virtio_queue_set_notification(vq, 1); } =20 @@ -594,14 +594,14 @@ static void virtio_balloon_free_page_start(VirtIOBall= oon *s) =20 qemu_mutex_lock(&s->free_page_lock); =20 - 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; + if (s->free_page_hint_cmd_id =3D=3D UINT_MAX) { + s->free_page_hint_cmd_id =3D + VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN; } else { - s->free_page_report_cmd_id++; + s->free_page_hint_cmd_id++; } =20 - s->free_page_report_status =3D FREE_PAGE_REPORT_S_REQUESTED; + s->free_page_hint_status =3D FREE_PAGE_HINT_S_REQUESTED; qemu_mutex_unlock(&s->free_page_lock); =20 virtio_notify_config(vdev); @@ -611,18 +611,18 @@ static void virtio_balloon_free_page_stop(VirtIOBallo= on *s) { VirtIODevice *vdev =3D VIRTIO_DEVICE(s); =20 - if (s->free_page_report_status !=3D FREE_PAGE_REPORT_S_STOP) { + if (s->free_page_hint_status !=3D FREE_PAGE_HINT_S_STOP) { /* * The lock also guarantees us that the * virtio_ballloon_get_free_page_hints exits after the - * free_page_report_status is set to S_STOP. + * free_page_hint_status is set to S_STOP. */ qemu_mutex_lock(&s->free_page_lock); /* - * The guest hasn't done the reporting, so host sends a notificati= on - * to the guest to actively stop the reporting. + * The guest isn't done hinting, so send a notification + * to the guest to actively stop the hinting. */ - s->free_page_report_status =3D FREE_PAGE_REPORT_S_STOP; + s->free_page_hint_status =3D FREE_PAGE_HINT_S_STOP; qemu_mutex_unlock(&s->free_page_lock); virtio_notify_config(vdev); } @@ -632,20 +632,20 @@ static void virtio_balloon_free_page_done(VirtIOBallo= on *s) { VirtIODevice *vdev =3D VIRTIO_DEVICE(s); =20 - if (s->free_page_report_status !=3D FREE_PAGE_REPORT_S_DONE) { + if (s->free_page_hint_status !=3D FREE_PAGE_HINT_S_DONE) { /* See virtio_balloon_free_page_stop() */ qemu_mutex_lock(&s->free_page_lock); - s->free_page_report_status =3D FREE_PAGE_REPORT_S_DONE; + s->free_page_hint_status =3D FREE_PAGE_HINT_S_DONE; qemu_mutex_unlock(&s->free_page_lock); virtio_notify_config(vdev); } } =20 static int -virtio_balloon_free_page_report_notify(NotifierWithReturn *n, void *data) +virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data) { VirtIOBalloon *dev =3D container_of(n, VirtIOBalloon, - free_page_report_notify); + free_page_hint_notify); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); PrecopyNotifyData *pnd =3D data; =20 @@ -703,7 +703,7 @@ static size_t virtio_balloon_config_size(VirtIOBalloon = *s) if (virtio_has_feature(features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { return offsetof(struct virtio_balloon_config, poison_val); } - return offsetof(struct virtio_balloon_config, free_page_report_cmd_id); + return offsetof(struct virtio_balloon_config, free_page_hint_cmd_id); } =20 static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_= data) @@ -715,14 +715,14 @@ static void virtio_balloon_get_config(VirtIODevice *v= dev, uint8_t *config_data) config.actual =3D cpu_to_le32(dev->actual); config.poison_val =3D cpu_to_le32(dev->poison_val); =20 - if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_REQUESTED) { - config.free_page_report_cmd_id =3D - cpu_to_le32(dev->free_page_report_cmd_id); - } else if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_STOP= ) { - config.free_page_report_cmd_id =3D + if (dev->free_page_hint_status =3D=3D FREE_PAGE_HINT_S_REQUESTED) { + config.free_page_hint_cmd_id =3D + cpu_to_le32(dev->free_page_hint_cmd_id); + } else if (dev->free_page_hint_status =3D=3D FREE_PAGE_HINT_S_STOP) { + config.free_page_hint_cmd_id =3D cpu_to_le32(VIRTIO_BALLOON_CMD_ID_STOP); - } else if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_DONE= ) { - config.free_page_report_cmd_id =3D + } else if (dev->free_page_hint_status =3D=3D FREE_PAGE_HINT_S_DONE) { + config.free_page_hint_cmd_id =3D cpu_to_le32(VIRTIO_BALLOON_CMD_ID_DONE); } =20 @@ -835,14 +835,14 @@ static int virtio_balloon_post_load_device(void *opaq= ue, int version_id) return 0; } =20 -static const VMStateDescription vmstate_virtio_balloon_free_page_report = =3D { +static const VMStateDescription vmstate_virtio_balloon_free_page_hint =3D { .name =3D "virtio-balloon-device/free-page-report", .version_id =3D 1, .minimum_version_id =3D 1, .needed =3D virtio_balloon_free_page_support, .fields =3D (VMStateField[]) { - VMSTATE_UINT32(free_page_report_cmd_id, VirtIOBalloon), - VMSTATE_UINT32(free_page_report_status, VirtIOBalloon), + VMSTATE_UINT32(free_page_hint_cmd_id, VirtIOBalloon), + VMSTATE_UINT32(free_page_hint_status, VirtIOBalloon), VMSTATE_END_OF_LIST() } }; @@ -869,7 +869,7 @@ static const VMStateDescription vmstate_virtio_balloon_= device =3D { VMSTATE_END_OF_LIST() }, .subsections =3D (const VMStateDescription * []) { - &vmstate_virtio_balloon_free_page_report, + &vmstate_virtio_balloon_free_page_hint, &vmstate_virtio_balloon_page_poison, NULL } @@ -908,7 +908,7 @@ static void virtio_balloon_device_realize(DeviceState *= dev, Error **errp) VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); - precopy_add_notifier(&s->free_page_report_notify); + precopy_add_notifier(&s->free_page_hint_notify); =20 object_ref(OBJECT(s->iothread)); s->free_page_bh =3D aio_bh_new(iothread_get_aio_context(s->iothrea= d), @@ -932,7 +932,7 @@ static void virtio_balloon_device_unrealize(DeviceState= *dev) qemu_bh_delete(s->free_page_bh); object_unref(OBJECT(s->iothread)); virtio_balloon_free_page_stop(s); - precopy_remove_notifier(&s->free_page_report_notify); + precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); qemu_remove_balloon_handler(s); @@ -1004,8 +1004,8 @@ static void virtio_balloon_instance_init(Object *obj) =20 qemu_mutex_init(&s->free_page_lock); qemu_cond_init(&s->free_page_cond); - s->free_page_report_cmd_id =3D VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_= MIN; - s->free_page_report_notify.notify =3D virtio_balloon_free_page_report_= notify; + s->free_page_hint_cmd_id =3D VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN; + s->free_page_hint_notify.notify =3D virtio_balloon_free_page_hint_noti= fy; =20 object_property_add(obj, "guest-stats", "guest statistics", balloon_stats_get_all, NULL, NULL, s); diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-= balloon.h index d49fef00cef2..28fd2b396087 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -23,7 +23,7 @@ #define VIRTIO_BALLOON(obj) \ OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON) =20 -#define VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN 0x80000000 +#define VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN 0x80000000 =20 typedef struct virtio_balloon_stat VirtIOBalloonStat; =20 @@ -33,20 +33,20 @@ typedef struct virtio_balloon_stat_modern { uint64_t val; } VirtIOBalloonStatModern; =20 -enum virtio_balloon_free_page_report_status { - FREE_PAGE_REPORT_S_STOP =3D 0, - FREE_PAGE_REPORT_S_REQUESTED =3D 1, - FREE_PAGE_REPORT_S_START =3D 2, - FREE_PAGE_REPORT_S_DONE =3D 3, +enum virtio_balloon_free_page_hint_status { + FREE_PAGE_HINT_S_STOP =3D 0, + FREE_PAGE_HINT_S_REQUESTED =3D 1, + FREE_PAGE_HINT_S_START =3D 2, + FREE_PAGE_HINT_S_DONE =3D 3, }; =20 typedef struct VirtIOBalloon { VirtIODevice parent_obj; VirtQueue *ivq, *dvq, *svq, *free_page_vq, *reporting_vq; - uint32_t free_page_report_status; + uint32_t free_page_hint_status; uint32_t num_pages; uint32_t actual; - uint32_t free_page_report_cmd_id; + uint32_t free_page_hint_cmd_id; uint64_t stats[VIRTIO_BALLOON_S_NR]; VirtQueueElement *stats_vq_elem; size_t stats_vq_offset; @@ -55,7 +55,7 @@ typedef struct VirtIOBalloon { QEMUBH *free_page_bh; /* * Lock to synchronize threads to access the free page reporting relat= ed - * fields (e.g. free_page_report_status). + * fields (e.g. free_page_hint_status). */ QemuMutex free_page_lock; QemuCond free_page_cond; @@ -64,7 +64,7 @@ typedef struct VirtIOBalloon { * stopped. */ bool block_iothread; - NotifierWithReturn free_page_report_notify; + NotifierWithReturn free_page_hint_notify; int64_t stats_last_update; int64_t stats_poll_interval; uint32_t host_features;