From nobody Sat May 18 14:25:17 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=1591278071; cv=none; d=zohomail.com; s=zohoarc; b=bqWA5Eup1hG072GE0kRuK8k5ElMT8D/af5bfaheNl3aPlUY4y+LIJ/X4hRYaz6dbpWdO5kJUEQDos1EI+XwindHee8UUH9ERZ3nZQvgrjC9DNIhKnFfoIE2+wcLEVZC0+1FqB71dCFERX1fVYnJcpmKwm1sRdDwGu3gJIasZaQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591278071; 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=yYKjpgihVM7BIyrybHg74VcmdTrT1AUmeK/VFZsIFzI=; b=nkGHO3V2W+cnWUwExlv7pIAPtgTzCC2n2iQBBNkHEf5xMo3mAfCYp7FEl9QPXIlXbz51ZXo8enXwe++irSmF0Z/SNUKMXXfCZ8WewnzR+rM6W1ZaS46i/htuicx5g+PV79GHOjKtq2jQdrHXNyw1OL7q6v3tqgvrQhx+pkTSvwo= 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 1591278071040919.8255623426779; Thu, 4 Jun 2020 06:41:11 -0700 (PDT) Received: from localhost ([::1]:38310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgq7J-0003Gk-N5 for importer@patchew.org; Thu, 04 Jun 2020 09:41:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgq6h-0002kN-Hj for qemu-devel@nongnu.org; Thu, 04 Jun 2020 09:40:31 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jgq6g-00079D-IH for qemu-devel@nongnu.org; Thu, 04 Jun 2020 09:40:31 -0400 Received: by mail-wr1-x444.google.com with SMTP id x6so6107098wrm.13 for ; Thu, 04 Jun 2020 06:40:30 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l17sm6935484wmi.3.2020.06.04.06.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:40:27 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id ECC1A1FF7E; Thu, 4 Jun 2020 14:40:26 +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=yYKjpgihVM7BIyrybHg74VcmdTrT1AUmeK/VFZsIFzI=; b=hZF1F4ysXVU2AugW0bO6FfwtcoS9YvDGxhRoGTw6O1GimdcfBNglpCQY0+VllMY6M1 A9Fgir/DhqT30lRGFCct3sd+l150owQr8hJmgv/phqQ2N8pHzu84QtiNouCvOZK6VSG3 JN+oIDjdp/b6OPFjwsWIVO0I+bjdhdaBG0RMAsLwB3Cq+FaY/GqVPNnvzqjvzrWVu8gJ i0M253KVoI25mvt4mnO9P4KhmT7U8MNMLhIRFkX4ZpZZq+cPGuLWCsCaEd9McmL5b+2Y xffLFo7BZgS5fUia0U/Dspfl9XpeiuVJNnr2crOGtCGUvIpMg8SJmKaw6eG+lHneLMp1 7qzg== 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=yYKjpgihVM7BIyrybHg74VcmdTrT1AUmeK/VFZsIFzI=; b=j3OMqrl0+CooA/s/1vfSI7b15Q2eX/dF+nsbvpa/JqpMylqtYfpQdUHVLbGEwmiAgm Y8veATZiKSUH6uXQlshIl2JB+CMMwOogwONQo19MT/CKZ6yS8If2oUXAgO1kEFA4Kxvr z1edsjPlGfxJee9MmrtXPlZUFpnT1t5TLMbSCbQErZSrywQ7or5mxPEyy9VRXXeJIHHL NSLEdra22qtr1kRH5sVjaoIoHuBVHEUCmu4yP8iVMm2mGrTQmQow0KLL2qzzROrXoVSN MOd0zfGzIf3t5kvVhcJeryaRIHnn9apwDp3X3gjXNZU/AOHJ4CDoU0HKduo+sFQu7ahg ST/g== X-Gm-Message-State: AOAM531SY7FQSISQPHpvKEiyLGRuk+SIlt/z3wbMizuCUg89npFp0bw0 AMKJeidgbgH1F4qVjDV6FRoF4g== X-Google-Smtp-Source: ABdhPJxsQTJ/WIBkeiA9PCzRUl7fpj2pngBT4jenGnS88l551b7svJPTGB+gqvoy1LyEvR8gY5H9gA== X-Received: by 2002:adf:f512:: with SMTP id q18mr4903285wro.38.1591278029014; Thu, 04 Jun 2020 06:40:29 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2] hw/virtio/vhost: re-factor vhost-section and allow DIRTY_MEMORY_CODE Date: Thu, 4 Jun 2020 14:40:22 +0100 Message-Id: <20200604134022.10564-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::444; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x444.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. 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 We expand the comment to explain that kernel based vhost has specific support for migration tracking. Signed-off-by: Alex Benn=C3=A9e Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Cc: Stefan Hajnoczi Tested-by: Fabiano Rosas --- v2 - drop enum, add trace_vhost_reject_section - return false at any fail point - unconditionally add DIRTY_MEMORY_CODE to handled cases - slightly re-word the explanatory comment and commit message --- hw/virtio/vhost.c | 55 ++++++++++++++++++++++++++++++------------ hw/virtio/trace-events | 3 ++- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index aff98a0ede5..120c0cc747b 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,48 @@ 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; + MemoryRegion *mr =3D section->mr; + + if (memory_region_is_ram(mr) && !memory_region_is_rom(mr)) { + uint8_t dirty_mask =3D memory_region_get_dirty_log_mask(mr); + uint8_t handled_dirty; + + /* + * Kernel based vhost doesn't handle any block which is doing + * dirty-tracking other than migration for which it has + * specific logging support. However for TCG the kernel never + * gets involved anyway so we can also ignore it's + * self-modiying code detection flags. + */ + handled_dirty =3D (1 << DIRTY_MEMORY_MIGRATION); + handled_dirty |=3D (1 << DIRTY_MEMORY_CODE); =20 - if (result && dev->vhost_ops->vhost_backend_mem_section_filter) { - result &=3D - dev->vhost_ops->vhost_backend_mem_section_filter(dev, section); - } + if (dirty_mask & ~handled_dirty) { + trace_vhost_reject_section(mr->name, 1); + return false; + } + + if (dev->vhost_ops->vhost_backend_mem_section_filter && + !dev->vhost_ops->vhost_backend_mem_section_filter(dev, section= )) { + trace_vhost_reject_section(mr->name, 2); + return false; + } =20 - trace_vhost_section(section->mr->name, result); - return result; + trace_vhost_section(mr->name); + return true; + } else { + trace_vhost_reject_section(mr->name, 3); + return false; + } } =20 static void vhost_begin(MemoryListener *listener) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 84ecb85d445..22427126b97 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -5,7 +5,8 @@ vhost_commit(bool started, bool changed) "Started: %d Chang= ed: %d" vhost_region_add_section(const char *name, uint64_t gpa, uint64_t size, ui= nt64_t host) "%s: 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64 vhost_region_add_section_merge(const char *name, uint64_t new_size, uint64= _t gpa, uint64_t owr) "%s: size: 0x%"PRIx64 " gpa: 0x%"PRIx64 " owr: 0x%"PR= Ix64 vhost_region_add_section_aligned(const char *name, uint64_t gpa, uint64_t = size, uint64_t host) "%s: 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64 -vhost_section(const char *name, int r) "%s:%d" +vhost_section(const char *name) "%s" +vhost_reject_section(const char *name, int d) "%s:%d" vhost_iotlb_miss(void *dev, int step) "%p step %d" =20 # vhost-user.c --=20 2.20.1