From nobody Sat May 18 20:15:16 2024 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591269257; cv=none; d=zohomail.com; s=zohoarc; b=AD+lv8VGO7BCiYI1cpNgnZk7wcc+Rh+1meL8WdMgICZ6h68AR8tyG4keNvCxlGWbIsnPXwEtYgOCP8TZKAzX8AACahqgu9MDbOQsYmrAXOtiCDd8rznOLvHg1D1F03MOxdtftcBY/0EBhZJQFa8/NuyTprfVpz2f9Iv1hpmwRoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591269257; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=hPkAn3Wk+ccPQ0JLMy6+RY9Cyczc0SzA1FixicEebSI=; b=kZjK/V8wtU2cSWJFqf+x7OhhfCMphl5wWgaclGIQmbJd6OVZmdbBtPnQuS9rxMBdTPzMMl9hQA5t4uXmo2UkHU0sBtinWkyJQxQBbXgfiHLiYDvRrD7WVRvUuYNdOc0sm1uedWYoDEnk+o0JX3OGPZ3R/DWuYkcGsITf2nnTqI8= 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 1591269257280164.1900225192884; Thu, 4 Jun 2020 04:14:17 -0700 (PDT) Received: from localhost ([::1]:42818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgnpA-0005Az-14 for importer@patchew.org; Thu, 04 Jun 2020 07:14:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgnoa-0004jp-4Q for qemu-devel@nongnu.org; Thu, 04 Jun 2020 07:13:40 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jgnoY-0007Cm-Ms for qemu-devel@nongnu.org; Thu, 04 Jun 2020 07:13:39 -0400 Received: by mail-wm1-x342.google.com with SMTP id u26so6592412wmn.1 for ; Thu, 04 Jun 2020 04:13:38 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w3sm7353254wmg.44.2020.06.04.04.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 04:13:35 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B29DC1FF7E; Thu, 4 Jun 2020 12:13:34 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hPkAn3Wk+ccPQ0JLMy6+RY9Cyczc0SzA1FixicEebSI=; b=wz26euMZehF3KIKOaWhQ3qo95B/jWzHXiHsQNUzDczui5/Duf/it41VGopEqK5QzS3 CcbavhhidF+AV4+cN7VsISVXJ6n6oDo77wfb14c411m2Ufyrq6MafmJbEATixYyY3xnD h0ocy5+Cs8J2HhGcsmQ9wBP9ca33fo/BmsWJxrnHGWWnSebfvhb6qixjwR6buM+kCHfc YY1yaCpxXymXditc6GM7E4b/rHu+S5jGfYfxobSpuy98R+PP7pp+VG3qhbApz9QQdBKq wAN5ySQqAiOh5Ttc2jkw87YXjT7TMO2N4uW7KphUUeBN26aV9J2bpBZzZmwT5aUIbjlq /4pw== 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:mime-version :content-transfer-encoding; bh=hPkAn3Wk+ccPQ0JLMy6+RY9Cyczc0SzA1FixicEebSI=; b=PocgNpUb0h7WvcaQAVyOJoH71I3fof51xue7D+JQqcrOFR1CQJlxOn9eZflkam5ZoR Vt8YvtHwRwxulmdbeskcoJn2ViwIzF2AzsejoDquUEJxqYtiJgFn4HUeVf2hfowpmx1k R/o1PjfmZtD72+1fP1PotcotfQbMpJDi01j2d5mSv2YU9rBHu64BhW3UinTFcpuDw7U2 rV3W8pkzkKEQHoo9+/Kl+ulKIGYwx0M5U0jISbmyT0EAs1SU7fVdN0q//70gDydkv7fk 8Sr2LojFKD8r+RzaJAm0OEY1Qh07Q0dIQM538+ic+vC1a97pgbPuqnYHMeRIIG3Kjftz 0m5Q== X-Gm-Message-State: AOAM533vmdGUc6RwYGsaPxgT4QB13H/QCYssvAWNkipoTFnjKpgY7Gur kbfb0Zh6nwBhB2Hx2zmwFUyU5w== X-Google-Smtp-Source: ABdhPJw3oQOKNN84mBKtLGl82hysnvpuhzFo9KW15YBMJqV2g6PcCUXOG+aWoj2pl285qZPIp7Ru5Q== X-Received: by 2002:a05:600c:23ce:: with SMTP id p14mr3546448wmb.77.1591269217057; Thu, 04 Jun 2020 04:13:37 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH] hw/virtio/vhost: re-factor vhost-section and allow DIRTY_MEMORY_CODE Date: Thu, 4 Jun 2020 12:13:23 +0100 Message-Id: <20200604111323.7458-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 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=2a00:1450:4864:20::342; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x342.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Dr . David Alan Gilbert" , Stefan Hajnoczi , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The purpose of vhost_section is to identify RAM regions that need to be made available to a vhost client. However when running under TCG all RAM sections have DIRTY_MEMORY_CODE set which leads to problems down the line. The original comment implies VGA regions are a problem but doesn't explain why vhost has a problem with it. Re-factor the code so: - steps are clearer to follow - reason for rejection is recorded in the trace point - we allow DIRTY_MEMORY_CODE when TCG is enabled Signed-off-by: Alex Benn=C3=A9e Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Cc: Stefan Hajnoczi --- hw/virtio/vhost.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index aff98a0ede5..f81fc87e74c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -27,6 +27,7 @@ #include "migration/blocker.h" #include "migration/qemu-file-types.h" #include "sysemu/dma.h" +#include "sysemu/tcg.h" #include "trace.h" =20 /* enabled until disconnected backend stabilizes */ @@ -403,26 +404,43 @@ static int vhost_verify_ring_mappings(struct vhost_de= v *dev, return r; } =20 +/* + * vhost_section: identify sections needed for vhost access + * + * We only care about RAM sections here (where virtqueue can live). If + * we find one we still allow the backend to potentially filter it out + * of our list. + */ static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *sect= ion) { - bool result; - bool log_dirty =3D memory_region_get_dirty_log_mask(section->mr) & - ~(1 << DIRTY_MEMORY_MIGRATION); - result =3D memory_region_is_ram(section->mr) && - !memory_region_is_rom(section->mr); - - /* Vhost doesn't handle any block which is doing dirty-tracking other - * than migration; this typically fires on VGA areas. - */ - result &=3D !log_dirty; + enum { OK =3D 0, NOT_RAM, DIRTY, FILTERED } result =3D NOT_RAM; + + if (memory_region_is_ram(section->mr) && !memory_region_is_rom(section= ->mr)) { + uint8_t dirty_mask =3D memory_region_get_dirty_log_mask(section->m= r); + uint8_t handled_dirty; =20 - if (result && dev->vhost_ops->vhost_backend_mem_section_filter) { - result &=3D - dev->vhost_ops->vhost_backend_mem_section_filter(dev, section); + /* + * Vhost doesn't handle any block which is doing dirty-tracking ot= her + * than migration; this typically fires on VGA areas. However + * for TCG we also do dirty code page tracking which shouldn't + * get in the way. + */ + handled_dirty =3D (1 << DIRTY_MEMORY_MIGRATION); + if (tcg_enabled()) { + handled_dirty |=3D (1 << DIRTY_MEMORY_CODE); + } + if (dirty_mask & ~handled_dirty) { + result =3D DIRTY; + } else if (dev->vhost_ops->vhost_backend_mem_section_filter && + !dev->vhost_ops->vhost_backend_mem_section_filter(dev, section= )) { + result =3D FILTERED; + } else { + result =3D OK; + } } =20 trace_vhost_section(section->mr->name, result); - return result; + return result =3D=3D OK; } =20 static void vhost_begin(MemoryListener *listener) --=20 2.20.1