From patchwork Thu Jun 4 11:13:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 187471 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp1331292ilo; Thu, 4 Jun 2020 04:13:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx03U9y6aS10j3fdeCir0CnYZen2Vg65eUeCn8b0GM1TRE28/CDTFUIRRlJ8rG0uc7jLo9N X-Received: by 2002:a25:4f44:: with SMTP id d65mr7596713ybb.149.1591269228680; Thu, 04 Jun 2020 04:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591269228; cv=none; d=google.com; s=arc-20160816; b=cabcq29WiyKaTp78omakHhJl4JQPI9pi7gZM2AtwcWLsvo6NUqs7QSTW6nhbi70sKF 5+xbts5n5RLknHxShY6hcApWTPt2PjJ85f1mB+VQGJh6jVfTbUZAZVjW+wtK5iU8mi7T 5I4ez2gEuV9o7mCTBk+XXU+eHs4u34nr2d4RSrcIjdeSWri1OeaAYK9VeCgmtMxhU8X9 A9je6LudsH8Qnu4n9tKDl6rwXsjyPUZHM+kKHdpQtWGHzM4WpkVitNiAWQznfOJXtIbU ffG0lyVLf80GPjZ5L2WM+0TJInaKUoPgCNJOw3vJUsSdQyABKrDYgDZDr/zGCnP6hM4J bCmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=hPkAn3Wk+ccPQ0JLMy6+RY9Cyczc0SzA1FixicEebSI=; b=GxZwgICZeAx54VOvODMo3HNHcLi2TuDvJcA+DZjqBl2Ox4iq/tmUm5BLPzGSaxGvbS BHGRD4csJOTZjYQmLmqVNX6BRmK1aUh8VOumtTB8HfUSPRTEe+pRmoUVo8jlhTIM+x7P 5u5SHzQjL9Ubz9U/K2lqUagHAYUWtZOAdT4SL6elAmD73VdAwxUpGSxV+hK8B93mqSwr qcliawiuZVIZqit5cz3QPCIYE9FvZYk9jRh+jLSLhgvhPSw2NwCFclK9JiEIaRqwsPV8 3O9rRjiYG8x6EFUkXULaypPGyEQZKvAtd1CkNZHarDt0PWTovXRMh3Sm+2PLfEe1aM0s 3k9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wz26euMZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q124si4020461ybc.129.2020.06.04.04.13.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jun 2020 04:13:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wz26euMZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgnoi-0004k4-7X for patch@linaro.org; Thu, 04 Jun 2020 07:13:48 -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) 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-Received: by 2002:a05:600c:23ce:: with SMTP id p14mr3546448wmb.77.1591269217057; Thu, 04 Jun 2020 04:13:37 -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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , "Dr . David Alan Gilbert" , Stefan Hajnoczi , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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ée Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Cc: Stefan Hajnoczi --- hw/virtio/vhost.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) -- 2.20.1 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" /* enabled until disconnected backend stabilizes */ @@ -403,26 +404,43 @@ static int vhost_verify_ring_mappings(struct vhost_dev *dev, return r; } +/* + * 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 *section) { - bool result; - bool log_dirty = memory_region_get_dirty_log_mask(section->mr) & - ~(1 << DIRTY_MEMORY_MIGRATION); - result = 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 &= !log_dirty; + enum { OK = 0, NOT_RAM, DIRTY, FILTERED } result = NOT_RAM; + + if (memory_region_is_ram(section->mr) && !memory_region_is_rom(section->mr)) { + uint8_t dirty_mask = memory_region_get_dirty_log_mask(section->mr); + uint8_t handled_dirty; - if (result && dev->vhost_ops->vhost_backend_mem_section_filter) { - result &= - dev->vhost_ops->vhost_backend_mem_section_filter(dev, section); + /* + * Vhost doesn't handle any block which is doing dirty-tracking other + * 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 = (1 << DIRTY_MEMORY_MIGRATION); + if (tcg_enabled()) { + handled_dirty |= (1 << DIRTY_MEMORY_CODE); + } + if (dirty_mask & ~handled_dirty) { + result = DIRTY; + } else if (dev->vhost_ops->vhost_backend_mem_section_filter && + !dev->vhost_ops->vhost_backend_mem_section_filter(dev, section)) { + result = FILTERED; + } else { + result = OK; + } } trace_vhost_section(section->mr->name, result); - return result; + return result == OK; } static void vhost_begin(MemoryListener *listener)