From patchwork Fri Jul 3 09:03:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iQeZzHuF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yptR2C2Lz9sRW for ; Fri, 3 Jul 2020 19:04:15 +1000 (AEST) Received: from localhost ([::1]:40366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHcC-0006Su-QQ for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:04:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbh-0006SE-KI for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:41 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34772 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 1jrHbe-0004MT-Rt for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767017; 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=kwK+YtoN3ISvSonZG8pWmnKbUjP97LUVMTrPci50qGM=; b=iQeZzHuFTRtUmdliBzss1d9LfbJKxNu4WdLwHm2a7mdMPq7Dy3t5+ZtjZl365VGF/1wYIv UamYWX7R/vsYcmzYX1BcjAyRV9/Y2E3yF3Oqe0Mf6w1iAZrhMwK/wkdefwwXE8UMfBYfnU pTBXdWBtEw/5r932xy8sD661LMr5c1A= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-lPws3eSMOmOH8B9AHLZgLQ-1; Fri, 03 Jul 2020 05:03:36 -0400 X-MC-Unique: lPws3eSMOmOH8B9AHLZgLQ-1 Received: by mail-wr1-f70.google.com with SMTP id i12so30979719wrx.11 for ; Fri, 03 Jul 2020 02:03:35 -0700 (PDT) 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=kwK+YtoN3ISvSonZG8pWmnKbUjP97LUVMTrPci50qGM=; b=cMloNYdBabau0HVecCUs45tNRRkoW9076B36zPlxvLmQe/xT837lYiwzVh4k3kMgEB H2fpelDjbqeM5krgTVNyFmCcJfAAqDwxxvVqU5tN+E9ecKA0d+yNBWqqhG3a1npBxPZQ o2jnvTMZhLnah/n8HbU42VgdDm6RMUyxYF5IR5jkykh6Yba21KHrQ74+4sPTl+IT3r/X osb37+ab1p2TKTMxVKZT7zitsxaMiD59AI8A9U9C3sGe84uZmoJHRpxrfbqf2OX4RGHG dvs3KHrXbhYHGfGPDJwBRZeTA/5JHkN94CRtEDy5QZmLaBqb93krhJVvo1rqUsQUO2nn cHqg== X-Gm-Message-State: AOAM532NhbpcMAO8lR4G0NB9PH73PW/zKNCzdMCpfpuCUXcjEunmlBdk nu2/I25hFlSBnsO3nVL+NzhP8U5MuF/H3KawPGoclTDsGCmb1KzwkwEMhW3i+oWFq8aFsimUcde W4G6NeqPwZUkBrTc= X-Received: by 2002:a5d:4d0b:: with SMTP id z11mr6276359wrt.24.1593767014438; Fri, 03 Jul 2020 02:03:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5M03g9peiqlIfmW3GR09VEhfBAjPu6TTxyZxqiajk+3z56ZUEV9yQxCmm7rqqubok8jpriw== X-Received: by 2002:a5d:4d0b:: with SMTP id z11mr6276346wrt.24.1593767014241; Fri, 03 Jul 2020 02:03:34 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id e8sm13586676wrp.26.2020.07.03.02.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:33 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:31 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 01/41] tests: disassemble-aml.sh: generate AML in readable format Message-ID: <20200703090252.368694-2-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, 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: Peter Maydell , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" On systems where the IASL tool exists, we can convert extected ACPI tables to ASL format, which is useful for debugging and documentation purposes. This script does this for all ACPI tables under tests/data/acpi/. Signed-off-by: Michael S. Tsirkin --- tests/data/acpi/disassemle-aml.sh | 52 +++++++++++++++++++++++++ tests/data/acpi/rebuild-expected-aml.sh | 1 + 2 files changed, 53 insertions(+) create mode 100755 tests/data/acpi/disassemle-aml.sh diff --git a/tests/data/acpi/disassemle-aml.sh b/tests/data/acpi/disassemle-aml.sh new file mode 100755 index 0000000000..1d8a4d0301 --- /dev/null +++ b/tests/data/acpi/disassemle-aml.sh @@ -0,0 +1,52 @@ +#!/usr/bin/bash + +outdir= +while getopts "o:" arg; do + case ${arg} in + o ) + outdir=$OPTARG + ;; + \? ) + echo "Usage: ./tests/data/acpi/disassemle-aml.sh [-o ]" + exit 1 + ;; + + esac +done + +for machine in tests/data/acpi/* +do + if [[ ! -d "$machine" ]]; + then + continue + fi + + if [[ "${outdir}" ]]; + then + mkdir -p "${outdir}"/${machine} || exit $? + fi + for aml in $machine/* + do + if [[ "$aml" == $machine/*.dsl ]]; + then + continue + fi + if [[ "$aml" == $machine/SSDT*.* ]]; + then + dsdt=${aml/SSDT*./DSDT.} + extra="-e ${dsdt}" + elif [[ "$aml" == $machine/SSDT* ]]; + then + dsdt=${aml/SSDT*/DSDT}; + extra="-e ${dsdt}" + else + extra="" + fi + asl=${aml}.dsl + if [[ "${outdir}" ]]; + then + asl="${outdir}"/${machine}/${asl} + fi + iasl -d -p ${asl} ${extra} ${aml} + done +done diff --git a/tests/data/acpi/rebuild-expected-aml.sh b/tests/data/acpi/rebuild-expected-aml.sh index 9cbaab1a4d..76cd797d1e 100755 --- a/tests/data/acpi/rebuild-expected-aml.sh +++ b/tests/data/acpi/rebuild-expected-aml.sh @@ -36,6 +36,7 @@ old_allowed_dif=`grep -v -e 'List of comma-separated changed AML files to ignore echo '/* List of comma-separated changed AML files to ignore */' > ${SRC_PATH}/tests/qtest/bios-tables-test-allowed-diff.h echo "The files were rebuilt and can be added to git." +echo "You can use ${SRC_PATH}/tests/data/acpi/disassemle-aml.sh to disassemble them to ASL." if [ -z "$old_allowed_dif" ]; then echo "Note! Please do not commit expected files with source changes" From patchwork Fri Jul 3 09:03:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322207 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aFlcqx/3; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yptW4Nhnz9sRW for ; Fri, 3 Jul 2020 19:04:19 +1000 (AEST) Received: from localhost ([::1]:40576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHcG-0006YE-Mr for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:04:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbl-0006Wi-4s for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:45 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:45908 helo=us-smtp-delivery-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 1jrHbj-0004Mx-E8 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767022; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZqj3bTam91VJKMgXj5mJaby8iNVg3MqxY1e+jpggf8=; b=aFlcqx/3vcke3nbIlpYeh3UhfvXWTySBbPxF5FD0CXoEFmo3+b1zQI4+EIF7DXmKhUDmS8 aNQFVs3UQ4OJRLnsZwdWuPk1+KWFyp8Wbqv/oqn69yg11VTtQCQzsmQMvJPqCcT6TKdPZR v4FrTtbceVj7AprCG/qlvS7abhnlJ/I= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-V_WzGbf8NfeAIg1YKSX-WQ-1; Fri, 03 Jul 2020 05:03:38 -0400 X-MC-Unique: V_WzGbf8NfeAIg1YKSX-WQ-1 Received: by mail-wm1-f72.google.com with SMTP id g6so28645033wmk.4 for ; Fri, 03 Jul 2020 02:03:38 -0700 (PDT) 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:content-transfer-encoding :in-reply-to; bh=AZqj3bTam91VJKMgXj5mJaby8iNVg3MqxY1e+jpggf8=; b=GYXrGfvHYRrJ8O+ITIt7UEajzRZu7LnuT/gnHROiMbQe3zUWpHxhfQ0HYjX1/E6JSf nJlWKvjRmBCIeTUacD/DLLkmYdQ6jINPZ2MjuwWfyKV7GM+QtSvbU4Vm1FeR/XzVmoIv Fpl82GXOLEMGo/6Yc6tAGbtSAz+TKNbKSauTwKWFEiBSaj0IcZ2di1KWf0WPC3iCMdo9 2TRESfuRbwooKH2xzA6joptQEWe5hrXTbXGJPhF+MnfOTAlSkltpo0YnWonVAmay2A10 ScAsjZs3uDzb4P0VxrF09b7IOXU5iYRIEfT+V0kwJobh/6GykRLsfHEB/nfX9RlQfNrN ZH2w== X-Gm-Message-State: AOAM532csp1GwMEXrzoLoOn5E0ethGfol0UPjyQmn1dw6N7iIsZ+eXDj iOeY+Zgd3m5Ug4Kfjr9CFVTHwm+t5pON2W34yS34FXA0zXgKltGG8SSMvxc14UtYv7mA6vwB64/ i/oKWj08d4amMjhg= X-Received: by 2002:adf:e944:: with SMTP id m4mr36398271wrn.252.1593767017154; Fri, 03 Jul 2020 02:03:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznoot4RKu6ewktM7kVzYViOQ+YF9Kf/tp8FAaPlHR1r42c6UpGWD9YwduYyhKcX5Jl3NuvhQ== X-Received: by 2002:adf:e944:: with SMTP id m4mr36398265wrn.252.1593767016996; Fri, 03 Jul 2020 02:03:36 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id u65sm12684816wmg.5.2020.07.03.02.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:36 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:34 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 02/41] Revert "tests/migration: Reduce autoconverge initial bandwidth" Message-ID: <20200703090252.368694-3-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Laurent Vivier , Peter Maydell , Thomas Huth , Juan Quintela , "Dr . David Alan Gilbert" , Paolo Bonzini , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This reverts commit 6d1da867e65f ("tests/migration: Reduce autoconverge initial bandwidth") since that change makes unit tests much slower for all developers, while it's not a robust way to fix migration tests. Migration tests need to find a more robust way to discover a reasonable bandwidth without slowing things down for everyone. Fixes: 6d1da867e65f ("tests/migration: Reduce autoconverge initial bandwidth") Signed-off-by: Michael S. Tsirkin Acked-by: Dr. David Alan Gilbert Acked-by: Philippe Mathieu-Daudé Acked-by: Thomas Huth --- tests/qtest/migration-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index dc3490c9fa..21ea5ba1d2 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1211,7 +1211,7 @@ static void test_migrate_auto_converge(void) * without throttling. */ migrate_set_parameter_int(from, "downtime-limit", 1); - migrate_set_parameter_int(from, "max-bandwidth", 1000000); /* ~1Mb/s */ + migrate_set_parameter_int(from, "max-bandwidth", 100000000); /* ~100Mb/s */ /* To check remaining size after precopy */ migrate_set_capability(from, "pause-before-switchover", true); From patchwork Fri Jul 3 09:03:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=X/FpPoxH; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yptY2rFfz9sPF for ; Fri, 3 Jul 2020 19:04:21 +1000 (AEST) Received: from localhost ([::1]:40752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHcJ-0006cm-2K for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:04:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbm-0006aD-Rn for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:46 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47567 helo=us-smtp-delivery-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 1jrHbl-0004N1-2J for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767023; 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=3SejujQmFP8i9uGegxOHZH22A3MzEqNQC/7kkGUHxhs=; b=X/FpPoxHXxDTjPYC3C8sD3wW8SFrHj6OlEpN3ybbYwjOJoVh1d8NhHBtFgd3aeOkF6KCyc IZhKaWmKqCo69pjx63Wt1usPAnWRxx2LPfKyuxPobKwtHZPuH1EnJRxsMzPYj5bsSqcCvH zjCxaO5d+4GfYFIQbLRzhKkMQ6kytD8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-196-64dmjPcOOfOi4XMFXrTgVw-1; Fri, 03 Jul 2020 05:03:42 -0400 X-MC-Unique: 64dmjPcOOfOi4XMFXrTgVw-1 Received: by mail-wm1-f72.google.com with SMTP id v11so15781891wmb.1 for ; Fri, 03 Jul 2020 02:03:41 -0700 (PDT) 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=3SejujQmFP8i9uGegxOHZH22A3MzEqNQC/7kkGUHxhs=; b=tIMrBlh/CpZfin2JNrcmZQPxkmpi5suwv5bi+UaaSXWk4ut6E7SvliWO6M4MBx+f1B Y4YOcyzpTr1JQZL9tSy5FrqYRKjrlwBAUm04vj93PEuPgS3D7w/5A5c6/SakWTYv+BqZ sckrjQ+c8M6EbbPNc/e8XYlaWGFRsRWgsHAKUJ0EFvttnorisOfwFyBvu/DrLjuoVqnt 8t1wweOozA3aQtCqFaN8DrcAhlV7HRPRSpVWB5WPOOJ4xHw8KrAlsOlzU637aW1ExuI8 MStFKeBUkDrpfn3W3lHTRvq3FbwLKeitGGGfnas9OpT3qYcbSKy74dBwMoWg5bvl1+/L iB2Q== X-Gm-Message-State: AOAM530twIcRyh06s2q/E64vNbRHc9Q036o/DnBCB1Y9S+eF3sZgBkoK MnP0eYKoeCm+J+j6rDG9iI+3NzoXE233E8Qk2U/nxq01yqqDmqV2XA0yvXF81R6SnM43Iusl0CT CsRynw7r/zUlPg1w= X-Received: by 2002:a1c:bcd4:: with SMTP id m203mr35307708wmf.124.1593767019911; Fri, 03 Jul 2020 02:03:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx54lyMEhYehJC9RdYF6g0URy/LZ1hAqBXGniXvFqkXRx8GH3aV/DPBPqhphpWlQA8ellUFbA== X-Received: by 2002:a1c:bcd4:: with SMTP id m203mr35307685wmf.124.1593767019691; Fri, 03 Jul 2020 02:03:39 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id h84sm13809795wme.22.2020.07.03.02.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:39 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:37 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 03/41] virtio-balloon: always indicate S_DONE when migration fails Message-ID: <20200703090252.368694-4-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.61; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:17:33 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Alexander Duyck , Wei Wang , Alexander Duyck , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand If something goes wrong during precopy, before stopping the VM, we will never send a S_DONE indication to the VM, resulting in the hinted pages not getting released to be used by the guest OS (e.g., Linux). Easy to reproduce: 1. Start migration (e.g., HMP "migrate -d 'exec:gzip -c > STATEFILE.gz'") 2. Cancel migration (e.g., HMP "migrate_cancel") 3. Oberve in the guest (e.g., cat /proc/meminfo) that there is basically no free memory left. While at it, add similar locking to virtio_balloon_free_page_done() as done in virtio_balloon_free_page_stop. Locking is still weird, but that has to be sorted out separately. There is nothing to do in the PRECOPY_NOTIFY_COMPLETE case. Add some comments regarding S_DONE handling. Fixes: c13c4153f76d ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT") Reviewed-by: Alexander Duyck Cc: Wei Wang Cc: Alexander Duyck Signed-off-by: David Hildenbrand Message-Id: <20200629080615.26022-1-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-balloon.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 10507b2a43..8a84718490 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -628,8 +628,13 @@ static void virtio_balloon_free_page_done(VirtIOBalloon *s) { VirtIODevice *vdev = VIRTIO_DEVICE(s); - s->free_page_report_status = FREE_PAGE_REPORT_S_DONE; - virtio_notify_config(vdev); + if (s->free_page_report_status != FREE_PAGE_REPORT_S_DONE) { + /* See virtio_balloon_free_page_stop() */ + qemu_mutex_lock(&s->free_page_lock); + s->free_page_report_status = FREE_PAGE_REPORT_S_DONE; + qemu_mutex_unlock(&s->free_page_lock); + virtio_notify_config(vdev); + } } static int @@ -653,17 +658,26 @@ virtio_balloon_free_page_report_notify(NotifierWithReturn *n, void *data) case PRECOPY_NOTIFY_SETUP: precopy_enable_free_page_optimization(); break; - case PRECOPY_NOTIFY_COMPLETE: - case PRECOPY_NOTIFY_CLEANUP: case PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC: virtio_balloon_free_page_stop(dev); break; case PRECOPY_NOTIFY_AFTER_BITMAP_SYNC: if (vdev->vm_running) { virtio_balloon_free_page_start(dev); - } else { - virtio_balloon_free_page_done(dev); + break; } + /* + * Set S_DONE before migrating the vmstate, so the guest will reuse + * all hinted pages once running on the destination. Fall through. + */ + case PRECOPY_NOTIFY_CLEANUP: + /* + * Especially, if something goes wrong during precopy or if migration + * is canceled, we have to properly communicate S_DONE to the VM. + */ + virtio_balloon_free_page_done(dev); + break; + case PRECOPY_NOTIFY_COMPLETE: break; default: virtio_error(vdev, "%s: %d reason unknown", __func__, pnd->reason); From patchwork Fri Jul 3 09:03:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Bfe/Njzg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypwC3x3tz9sPF for ; Fri, 3 Jul 2020 19:05:47 +1000 (AEST) Received: from localhost ([::1]:48526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHdh-0001X1-8Q for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:05:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbo-0006dT-Gq for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:48 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:47010 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 1jrHbm-0004ND-Jr for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767025; 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=zAm2WZsz8jFA4V7I3jZT5e4XH4Wdo1IJW/sufln0SFE=; b=Bfe/Njzg9k2XPtkrfhyxRp/zdDChCt+pxI4PPxj5fiajsUUJG180kdTghiGFSP9pT0TSlt Zf/11IbixrRi9znTb9tt9te2wxkEEqRAKirIouZRa0OzosY/1C+lSYHU2wf8yHNhyE661Y 8Xkc+1dYepUUSjCzE5r2gWxNpBqcZC0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-250-fWeBs5jfMnWlc70NENxPag-1; Fri, 03 Jul 2020 05:03:44 -0400 X-MC-Unique: fWeBs5jfMnWlc70NENxPag-1 Received: by mail-wm1-f70.google.com with SMTP id g187so34473955wme.0 for ; Fri, 03 Jul 2020 02:03:44 -0700 (PDT) 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=zAm2WZsz8jFA4V7I3jZT5e4XH4Wdo1IJW/sufln0SFE=; b=iTZzCG9InuDNZ09Q/yeCyt2usd6QVVUQGrSR/AP1AiyvFWVi+CxyEMaRcLXR4rbqu5 zzQUpqv+NRXp4oQL5nQnSBbydGq1SPIRq/N/6OgWtsLPtP5h0Zm10lualiblWQTx7+t5 O4Zd4+jWHHLY0vOp7WywETAfUw1FLfiArZtof3j+8/AZjHidZi4/AI8bCht+AI6aMrbV HO5Q+vcqdZa8gqI1FzT4TUV8rtfZLtm+ESYMw7OG8iMlzurl9Qkm0+hiWNYIxh7mzhWT 6Hx+cCz9ezPrlKBHVsgjsJAXVWIgakNY7lZo+lzs+GltRPGzb+VfTeOdEUY7i0Gi4mZZ Kvgw== X-Gm-Message-State: AOAM53267JbBPy87kgBpG8BFs0bxXGtzyq3rOuBJwF0KCSCPC2hmvFO1 h6LvLs0waVFrifHT9VTE7Qehzy0CPRtccvC6SzS9NRESPzpCDxmpJb04l25Kjcac5DJR4p1cyyp 083Qm99Fn/QttdDE= X-Received: by 2002:a1c:b103:: with SMTP id a3mr35426326wmf.186.1593767022776; Fri, 03 Jul 2020 02:03:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAwOkXJuUflto4b9dJWf5KWO22GkGrEzGFgLtLk73NjZ1tIdVgpxkN0p7zfjsDkR4HJo7w9Q== X-Received: by 2002:a1c:b103:: with SMTP id a3mr35426314wmf.186.1593767022605; Fri, 03 Jul 2020 02:03:42 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id q1sm13319920wro.82.2020.07.03.02.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:42 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:40 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 04/41] pc: Support coldplugging of virtio-pmem-pci devices on all buses Message-ID: <20200703090252.368694-5-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Eduardo Habkost , Pankaj Gupta , David Hildenbrand , Paolo Bonzini , Igor Mammedov , Vivek Goyal , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand E.g., with "pc-q35-4.2", trying to coldplug a virtio-pmem-pci devices results in "virtio-pmem-pci not supported on this bus" Reasons is, that the bus does not support hotplug and, therefore, does not have a hotplug handler. Let's allow coldplugging virtio-pmem devices on such buses. The hotplug order is only relevant for virtio-pmem-pci when the guest is already alive and the device is visible before memory_device_plug() wired up the memory device bits. Hotplug attempts will still fail with: "Error: Bus 'pcie.0' does not support hotplugging" Hotunplug attempts will still fail with: "Error: Bus 'pcie.0' does not support hotplugging" Reported-by: Vivek Goyal Reviewed-by: Pankaj Gupta Cc: Pankaj Gupta Cc: Igor Mammedov Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-2-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/pc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4af9679d03..58b1425c17 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1643,13 +1643,13 @@ static void pc_virtio_pmem_pci_pre_plug(HotplugHandler *hotplug_dev, HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev); Error *local_err = NULL; - if (!hotplug_dev2) { + if (!hotplug_dev2 && dev->hotplugged) { /* * Without a bus hotplug handler, we cannot control the plug/unplug - * order. This should never be the case on x86, however better add - * a safety net. + * order. We should never reach this point when hotplugging on x86, + * however, better add a safety net. */ - error_setg(errp, "virtio-pmem-pci not supported on this bus."); + error_setg(errp, "virtio-pmem-pci hotplug not supported on this bus."); return; } /* @@ -1658,7 +1658,7 @@ static void pc_virtio_pmem_pci_pre_plug(HotplugHandler *hotplug_dev, */ memory_device_pre_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev), NULL, &local_err); - if (!local_err) { + if (!local_err && hotplug_dev2) { hotplug_handler_pre_plug(hotplug_dev2, dev, &local_err); } error_propagate(errp, local_err); @@ -1676,9 +1676,11 @@ static void pc_virtio_pmem_pci_plug(HotplugHandler *hotplug_dev, * device bits. */ memory_device_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev)); - hotplug_handler_plug(hotplug_dev2, dev, &local_err); - if (local_err) { - memory_device_unplug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev)); + if (hotplug_dev2) { + hotplug_handler_plug(hotplug_dev2, dev, &local_err); + if (local_err) { + memory_device_unplug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev)); + } } error_propagate(errp, local_err); } From patchwork Fri Jul 3 09:03:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322213 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dSIv/mBQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypyB0c5pz9sPF for ; Fri, 3 Jul 2020 19:07:29 +1000 (AEST) Received: from localhost ([::1]:56942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHfK-00053F-5l for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:07:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbr-0006iD-Sb for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:47733 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 1jrHbp-0004NX-31 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767028; 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=6yJ2lEFwsgpUTZUMhX5VCO54V4eVVZ3IAAzP+xX7YP4=; b=dSIv/mBQGHJkmTZutoDj9ts/0HNGFiJHgIiO9lAsYhYR6RJP3tjNeQITjXJJO4yQuZes8U eQDgmmW1DfQFqcPgT+8MLlsOPSE2DPebSR6r6Th+leq4Z1a3kfHHzmSMeifnNWkhBVTg61 vrM69+jd5w/5Jot1agkkkbNtfICm2AI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-Q02zI4SXPrCm-dtkPa0u8w-1; Fri, 03 Jul 2020 05:03:46 -0400 X-MC-Unique: Q02zI4SXPrCm-dtkPa0u8w-1 Received: by mail-wm1-f71.google.com with SMTP id v24so34593230wmh.3 for ; Fri, 03 Jul 2020 02:03:46 -0700 (PDT) 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=6yJ2lEFwsgpUTZUMhX5VCO54V4eVVZ3IAAzP+xX7YP4=; b=R8Kz5nAVCXWFLP3dmoJMgQPUNC1vLCjklEPzinRDHKxe267+FafABG7v0wnU4pJ0sb Q14jABRBfDkG5LHNReif4WgxXZ8TaYQfjGxQiAS6zH9r9Hvr2ZNnAd23xAz2XzC7OTt2 ciWsj0rCFQAdbiqQwbkYTfdeX2MmkzNAoSvbBtgjDjY7+wJgr0F7R1UDlRlIKLRC894z QyfqmtTVOOaZN6pR4UqXqOiFb61KMb2PMQ00qLkR/xtcIisICCkH2g9J0+jiH46ttMp1 5gsJkpQCk3mSbgNpmdvS1Mcy6ypKiCwqWIe1dggT1TzU/s1rijOAXz9cTzXu8groSfox 05hw== X-Gm-Message-State: AOAM530lo8cyq5nxZF1Zcxe0MW0sFhnVgVcnV5+s9ksgIkgxkIqwMVFo dv/mfiwIOe9Tlc87Ej2P8mJoHH9ur6mq0GmRi/aReBSr29bS0GGsCr8GVYsCYLHotZAzigDesRg S2oR0w9HoWoSb3Oo= X-Received: by 2002:a7b:c775:: with SMTP id x21mr20899705wmk.34.1593767025436; Fri, 03 Jul 2020 02:03:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweeRo12c2BXZNh5i8Tzc97T+IRHVG3vUM5YjbssAXsdK0BhKK4oSD6Kwubo6WQzaEv6ZgmHg== X-Received: by 2002:a7b:c775:: with SMTP id x21mr20899692wmk.34.1593767025254; Fri, 03 Jul 2020 02:03:45 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id f14sm14495181wro.90.2020.07.03.02.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:44 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:43 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 05/41] exec: Introduce ram_block_discard_(disable|require)() Message-ID: <20200703090252.368694-6-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Richard Henderson , "Dr . David Alan Gilbert" , Paolo Bonzini , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We want to replace qemu_balloon_inhibit() by something more generic. Especially, we want to make sure that technologies that really rely on RAM block discards to work reliably to run mutual exclusive with technologies that effectively break it. E.g., vfio will usually pin all guest memory, turning the virtio-balloon basically useless and make the VM consume more memory than reported via the balloon. While the balloon is special already (=> no guarantees, same behavior possible afer reboots and with huge pages), this will be different, especially, with virtio-mem. Let's implement a way such that we can make both types of technology run mutually exclusive. We'll convert existing balloon inhibitors in successive patches and add some new ones. Add the check to qemu_balloon_is_inhibited() for now. We might want to make virtio-balloon an acutal inhibitor in the future - however, that requires more thought to not break existing setups. Reviewed-by: Dr. David Alan Gilbert Cc: "Michael S. Tsirkin" Cc: Richard Henderson Cc: Paolo Bonzini Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-3-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 41 ++++++++++++++++++++++++++++++++++ balloon.c | 3 ++- exec.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 7207025bd4..38ec38b9a8 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2472,6 +2472,47 @@ static inline MemOp devend_memop(enum device_endian end) } #endif +/* + * Inhibit technologies that require discarding of pages in RAM blocks, e.g., + * to manage the actual amount of memory consumed by the VM (then, the memory + * provided by RAM blocks might be bigger than the desired memory consumption). + * This *must* be set if: + * - Discarding parts of a RAM blocks does not result in the change being + * reflected in the VM and the pages getting freed. + * - All memory in RAM blocks is pinned or duplicated, invaldiating any previous + * discards blindly. + * - Discarding parts of a RAM blocks will result in integrity issues (e.g., + * encrypted VMs). + * Technologies that only temporarily pin the current working set of a + * driver are fine, because we don't expect such pages to be discarded + * (esp. based on guest action like balloon inflation). + * + * This is *not* to be used to protect from concurrent discards (esp., + * postcopy). + * + * Returns 0 if successful. Returns -EBUSY if a technology that relies on + * discards to work reliably is active. + */ +int ram_block_discard_disable(bool state); + +/* + * Inhibit technologies that disable discarding of pages in RAM blocks. + * + * Returns 0 if successful. Returns -EBUSY if discards are already set to + * broken. + */ +int ram_block_discard_require(bool state); + +/* + * Test if discarding of memory in ram blocks is disabled. + */ +bool ram_block_discard_is_disabled(void); + +/* + * Test if discarding of memory in ram blocks is required to work reliably. + */ +bool ram_block_discard_is_required(void); + #endif #endif diff --git a/balloon.c b/balloon.c index f104b42961..5fff79523a 100644 --- a/balloon.c +++ b/balloon.c @@ -40,7 +40,8 @@ static int balloon_inhibit_count; bool qemu_balloon_is_inhibited(void) { - return atomic_read(&balloon_inhibit_count) > 0; + return atomic_read(&balloon_inhibit_count) > 0 || + ram_block_discard_is_disabled(); } void qemu_balloon_inhibit(bool state) diff --git a/exec.c b/exec.c index 21926dc9c7..893636176e 100644 --- a/exec.c +++ b/exec.c @@ -4115,4 +4115,56 @@ void mtree_print_dispatch(AddressSpaceDispatch *d, MemoryRegion *root) } } +/* + * If positive, discarding RAM is disabled. If negative, discarding RAM is + * required to work and cannot be disabled. + */ +static int ram_block_discard_disabled; + +int ram_block_discard_disable(bool state) +{ + int old; + + if (!state) { + atomic_dec(&ram_block_discard_disabled); + return 0; + } + + do { + old = atomic_read(&ram_block_discard_disabled); + if (old < 0) { + return -EBUSY; + } + } while (atomic_cmpxchg(&ram_block_discard_disabled, old, old + 1) != old); + return 0; +} + +int ram_block_discard_require(bool state) +{ + int old; + + if (!state) { + atomic_inc(&ram_block_discard_disabled); + return 0; + } + + do { + old = atomic_read(&ram_block_discard_disabled); + if (old > 0) { + return -EBUSY; + } + } while (atomic_cmpxchg(&ram_block_discard_disabled, old, old - 1) != old); + return 0; +} + +bool ram_block_discard_is_disabled(void) +{ + return atomic_read(&ram_block_discard_disabled) > 0; +} + +bool ram_block_discard_is_required(void) +{ + return atomic_read(&ram_block_discard_disabled) < 0; +} + #endif From patchwork Fri Jul 3 09:03:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ir1sxXKC; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypwN13m7z9sPF for ; Fri, 3 Jul 2020 19:05:56 +1000 (AEST) Received: from localhost ([::1]:49308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHdp-0001rd-Qa for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:05:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbw-0006lq-2c for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:56 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:46961 helo=us-smtp-delivery-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 1jrHbt-0004Nt-Mp for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767033; 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=NzAsGQePlosdLQbLXcIzQnsWDyi+eddzAIRrHxLygng=; b=Ir1sxXKCtI8oJak2XMApnVT245lQdPCYUvCKWsCoAfmf/Ez/lXzGPkfNbWwpFauMUo7tqR BMdDENaILyELXMbQnaAIQpJYYHuUOOR03Cn4xHqDsW1BigNv9vG23M0RRPEE26h23xMjhh oRLiX+q6IfFFgcydE331fcL6UUT8QF8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-56-c4vSwhfVM-yVu-jADz6jFw-1; Fri, 03 Jul 2020 05:03:50 -0400 X-MC-Unique: c4vSwhfVM-yVu-jADz6jFw-1 Received: by mail-wm1-f70.google.com with SMTP id z11so34451800wmg.5 for ; Fri, 03 Jul 2020 02:03:49 -0700 (PDT) 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=NzAsGQePlosdLQbLXcIzQnsWDyi+eddzAIRrHxLygng=; b=JCVKQrRuAxghgBq3ZgTxoJp0j+lkWGksHamq4ByKsO049N/L8OsbbtLRHqlWbToWIb mavU9zMvShgj9z4Fzr5A2Pa3xEbnVjF+05LT10OlVnByFDmheiwFaOJAwl3GXdnN9iQ4 3LQqGabDtRhrJqfPZPjQ7nPxzWcPTQZ309pjs/NkhBj833fndzRfB6KYdrnL8+vRDuq0 DY00GY8kDybx61HAcDPbfgGF/bntNdO4mSgG9La+I9n3hg3tISXQyp0qVZ81QObuxM2O faC/2ezFMucyLAKRKQ3WwxLMK2bcXZ2HcU1BBen+ZYHhvlXUWj10I/CEvp3INxd2WdtH Tz2w== X-Gm-Message-State: AOAM530BCqDjX85z6jyoTBJ3+bjV0Wig/W7HlhA5wZmetKPbYNjUmdFd I6lIB0uW5AicEtaRiwneURC8r27va5vZzv5HEvoroq7hAKdNzi2LQ8224HQx3xVo+T9YmYLrRj5 yY+dFoMAViWRd0aw= X-Received: by 2002:a1c:4b09:: with SMTP id y9mr22082106wma.46.1593767028517; Fri, 03 Jul 2020 02:03:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK1rxaaCVCu536XXLqnrBYk1xt+aKqWRr6i6ZQM/Tr7IkSwpJNYOkjyvQ2NtgYHinFFiAIZQ== X-Received: by 2002:a1c:4b09:: with SMTP id y9mr22082073wma.46.1593767028164; Fri, 03 Jul 2020 02:03:48 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 63sm14297122wra.86.2020.07.03.02.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:47 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:45 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 06/41] vfio: Convert to ram_block_discard_disable() Message-ID: <20200703090252.368694-7-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.61; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:17:33 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, 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: Tony Krowiak , Peter Maydell , Eric Farman , Pierre Morel , David Hildenbrand , qemu-s390x@nongnu.org, Cornelia Huck , Thomas Huth , Halil Pasic , Christian Borntraeger , Alex Williamson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand VFIO is (except devices without a physical IOMMU or some mediated devices) incompatible with discarding of RAM. The kernel will pin basically all VM memory. Let's convert to ram_block_discard_disable(), which can now fail, in contrast to qemu_balloon_inhibit(). Leave "x-balloon-allowed" named as it is for now. Reviewed-by: Tony Krowiak Acked-by: Cornelia Huck Cc: Cornelia Huck Cc: Alex Williamson Cc: Christian Borntraeger Cc: Tony Krowiak Cc: Halil Pasic Cc: Pierre Morel Cc: Eric Farman Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-4-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/vfio/vfio-common.h | 4 +-- hw/vfio/ap.c | 8 +++--- hw/vfio/ccw.c | 11 ++++---- hw/vfio/common.c | 53 +++++++++++++++++++---------------- hw/vfio/pci.c | 6 ++-- 5 files changed, 44 insertions(+), 38 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index fd564209ac..c78f3ff559 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -108,7 +108,7 @@ typedef struct VFIODevice { bool reset_works; bool needs_reset; bool no_mmap; - bool balloon_allowed; + bool ram_block_discard_allowed; VFIODeviceOps *ops; unsigned int num_irqs; unsigned int num_regions; @@ -128,7 +128,7 @@ typedef struct VFIOGroup { QLIST_HEAD(, VFIODevice) device_list; QLIST_ENTRY(VFIOGroup) next; QLIST_ENTRY(VFIOGroup) container_next; - bool balloon_allowed; + bool ram_block_discard_allowed; } VFIOGroup; typedef struct VFIODMABuf { diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 95564c17ed..b9330a8e6f 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -105,12 +105,12 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) vapdev->vdev.dev = dev; /* - * vfio-ap devices operate in a way compatible with - * memory ballooning, as no pages are pinned in the host. + * vfio-ap devices operate in a way compatible with discarding of + * memory in RAM blocks, as no pages are pinned in the host. * This needs to be set before vfio_get_device() for vfio common to - * handle the balloon inhibitor. + * handle ram_block_discard_disable(). */ - vapdev->vdev.balloon_allowed = true; + vapdev->vdev.ram_block_discard_allowed = true; ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp); if (ret) { diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 06e69d7066..ff7f369779 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -574,12 +574,13 @@ static void vfio_ccw_get_device(VFIOGroup *group, VFIOCCWDevice *vcdev, /* * All vfio-ccw devices are believed to operate in a way compatible with - * memory ballooning, ie. pages pinned in the host are in the current - * working set of the guest driver and therefore never overlap with pages - * available to the guest balloon driver. This needs to be set before - * vfio_get_device() for vfio common to handle the balloon inhibitor. + * discarding of memory in RAM blocks, ie. pages pinned in the host are + * in the current working set of the guest driver and therefore never + * overlap e.g., with pages available to the guest balloon driver. This + * needs to be set before vfio_get_device() for vfio common to handle + * ram_block_discard_disable(). */ - vcdev->vdev.balloon_allowed = true; + vcdev->vdev.ram_block_discard_allowed = true; if (vfio_get_device(group, vcdev->cdev.mdevid, &vcdev->vdev, errp)) { goto out_err; diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0b3593b3c0..33357140b8 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -33,7 +33,6 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/range.h" -#include "sysemu/balloon.h" #include "sysemu/kvm.h" #include "sysemu/reset.h" #include "trace.h" @@ -1215,31 +1214,36 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, space = vfio_get_address_space(as); /* - * VFIO is currently incompatible with memory ballooning insofar as the + * VFIO is currently incompatible with discarding of RAM insofar as the * madvise to purge (zap) the page from QEMU's address space does not * interact with the memory API and therefore leaves stale virtual to * physical mappings in the IOMMU if the page was previously pinned. We - * therefore add a balloon inhibit for each group added to a container, + * therefore set discarding broken for each group added to a container, * whether the container is used individually or shared. This provides * us with options to allow devices within a group to opt-in and allow - * ballooning, so long as it is done consistently for a group (for instance + * discarding, so long as it is done consistently for a group (for instance * if the device is an mdev device where it is known that the host vendor * driver will never pin pages outside of the working set of the guest - * driver, which would thus not be ballooning candidates). + * driver, which would thus not be discarding candidates). * * The first opportunity to induce pinning occurs here where we attempt to * attach the group to existing containers within the AddressSpace. If any - * pages are already zapped from the virtual address space, such as from a - * previous ballooning opt-in, new pinning will cause valid mappings to be + * pages are already zapped from the virtual address space, such as from + * previous discards, new pinning will cause valid mappings to be * re-established. Likewise, when the overall MemoryListener for a new * container is registered, a replay of mappings within the AddressSpace * will occur, re-establishing any previously zapped pages as well. * - * NB. Balloon inhibiting does not currently block operation of the - * balloon driver or revoke previously pinned pages, it only prevents - * calling madvise to modify the virtual mapping of ballooned pages. + * Especially virtio-balloon is currently only prevented from discarding + * new memory, it will not yet set ram_block_discard_set_required() and + * therefore, neither stops us here or deals with the sudden memory + * consumption of inflated memory. */ - qemu_balloon_inhibit(true); + ret = ram_block_discard_disable(true); + if (ret) { + error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken"); + return ret; + } QLIST_FOREACH(container, &space->containers, next) { if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) { @@ -1405,7 +1409,7 @@ close_fd_exit: close(fd); put_space_exit: - qemu_balloon_inhibit(false); + ram_block_discard_disable(false); vfio_put_address_space(space); return ret; @@ -1526,8 +1530,8 @@ void vfio_put_group(VFIOGroup *group) return; } - if (!group->balloon_allowed) { - qemu_balloon_inhibit(false); + if (!group->ram_block_discard_allowed) { + ram_block_discard_disable(false); } vfio_kvm_device_del_group(group); vfio_disconnect_container(group); @@ -1565,22 +1569,23 @@ int vfio_get_device(VFIOGroup *group, const char *name, } /* - * Clear the balloon inhibitor for this group if the driver knows the - * device operates compatibly with ballooning. Setting must be consistent - * per group, but since compatibility is really only possible with mdev - * currently, we expect singleton groups. + * Set discarding of RAM as not broken for this group if the driver knows + * the device operates compatibly with discarding. Setting must be + * consistent per group, but since compatibility is really only possible + * with mdev currently, we expect singleton groups. */ - if (vbasedev->balloon_allowed != group->balloon_allowed) { + if (vbasedev->ram_block_discard_allowed != + group->ram_block_discard_allowed) { if (!QLIST_EMPTY(&group->device_list)) { - error_setg(errp, - "Inconsistent device balloon setting within group"); + error_setg(errp, "Inconsistent setting of support for discarding " + "RAM (e.g., balloon) within group"); close(fd); return -1; } - if (!group->balloon_allowed) { - group->balloon_allowed = true; - qemu_balloon_inhibit(false); + if (!group->ram_block_discard_allowed) { + group->ram_block_discard_allowed = true; + ram_block_discard_disable(false); } } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 6838bcc4b3..d020ea9f82 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2789,7 +2789,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) } /* - * Mediated devices *might* operate compatibly with memory ballooning, but + * Mediated devices *might* operate compatibly with discarding of RAM, but * we cannot know for certain, it depends on whether the mdev vendor driver * stays in sync with the active working set of the guest driver. Prevent * the x-balloon-allowed option unless this is minimally an mdev device. @@ -2802,7 +2802,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) trace_vfio_mdev(vdev->vbasedev.name, is_mdev); - if (vdev->vbasedev.balloon_allowed && !is_mdev) { + if (vdev->vbasedev.ram_block_discard_allowed && !is_mdev) { error_setg(errp, "x-balloon-allowed only potentially compatible " "with mdev devices"); vfio_put_group(group); @@ -3156,7 +3156,7 @@ static Property vfio_pci_dev_properties[] = { VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), DEFINE_PROP_BOOL("x-no-mmap", VFIOPCIDevice, vbasedev.no_mmap, false), DEFINE_PROP_BOOL("x-balloon-allowed", VFIOPCIDevice, - vbasedev.balloon_allowed, false), + vbasedev.ram_block_discard_allowed, false), DEFINE_PROP_BOOL("x-no-kvm-intx", VFIOPCIDevice, no_kvm_intx, false), DEFINE_PROP_BOOL("x-no-kvm-msi", VFIOPCIDevice, no_kvm_msi, false), DEFINE_PROP_BOOL("x-no-kvm-msix", VFIOPCIDevice, no_kvm_msix, false), From patchwork Fri Jul 3 09:03:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FP0EXywQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypwH12WJz9sPF for ; Fri, 3 Jul 2020 19:05:51 +1000 (AEST) Received: from localhost ([::1]:48924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHdk-0001h3-Sx for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:05:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbx-0006ms-Gi for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44760 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 1jrHbu-0004OA-V1 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767034; 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=+xCzX5pjcy148tNCg3zvK7ruz7b/+qmBTdtfJlorfws=; b=FP0EXywQPYve3andIja13grksnTH+92dSXSij0ZnnrdYOFyB54YLam3HMwCQXQpem1nT1L pmhmC0d07mHcUy7P2TLXAtJkkdmPxjCXmjz7oCHWGCKBnQ/jM4put3iV7cvVsKXfOP8IdU g5r0bq4rcUYPhA6f+JHRwy12VfCH18U= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-vmMN7A47MDmRCQJFHrgEbg-1; Fri, 03 Jul 2020 05:03:52 -0400 X-MC-Unique: vmMN7A47MDmRCQJFHrgEbg-1 Received: by mail-wm1-f71.google.com with SMTP id f68so16189767wmf.1 for ; Fri, 03 Jul 2020 02:03:52 -0700 (PDT) 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=+xCzX5pjcy148tNCg3zvK7ruz7b/+qmBTdtfJlorfws=; b=WQyAF8ZUGyUX/lK8aDcgcDz+NDsyxlTrn1BJ6KmNGRt4Lt9U9L2EkxVGlCzi1Hl9Qt HrqZeB6lrTwWSzsPgwNFk8dS3UPNgMh6BlAdreCjQW/IlMt75ZEDKueMiDZ600j3UXCr /w6E6lQay3KWsTYgp5gKdbNDTUc8DsvdP0mJiGekjt4Ab8tlxZ3K2S6edmYsEzrqLDZt +gs7c/8NnfktnwXrQ/LGk/W5vne7AnGfKyB8MypDOFmg0kqNJPdXXeUEMEjA8TOZNYcN IekeN/rVKpBVteHQY8haEnV4BtqacD6rhvrk2AgIl1GI2EyosOeSFbmNvoXjc47tjRZa LnBw== X-Gm-Message-State: AOAM532A5NRCSsv8eB8NCgcxGi0QEzqPIJos4BsB95FiU7OWlSbR1ocy wYgWovmDvHry1G4BgDdJrU7Mkz4KAfGUVgK/sEUUJcOZq2qnN6+b8E/U4GyuIfqi0iL7kwrox+T 9caRStRrP1HMw2PI= X-Received: by 2002:a7b:c14a:: with SMTP id z10mr34465110wmi.19.1593767030947; Fri, 03 Jul 2020 02:03:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH6CgeufSo9JwIW+9iWhgBDRu9Y5rZ/6J6Jir103NVXBTOiQlnZIXgjcjYMvIQK8/q4Sijiw== X-Received: by 2002:a7b:c14a:: with SMTP id z10mr34465084wmi.19.1593767030736; Fri, 03 Jul 2020 02:03:50 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id r1sm13030791wrt.73.2020.07.03.02.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:50 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:48 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 07/41] accel/kvm: Convert to ram_block_discard_disable() Message-ID: <20200703090252.368694-8-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Paolo Bonzini , "Dr . David Alan Gilbert" , kvm@vger.kernel.org, David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Discarding memory does not work as expected. At the time this is called, we cannot have anyone active that relies on discards to work properly. Reviewed-by: Dr. David Alan Gilbert Cc: Paolo Bonzini Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-5-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- accel/kvm/kvm-all.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d54a8701d8..ab36fbfa0c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -40,7 +40,6 @@ #include "trace.h" #include "hw/irq.h" #include "sysemu/sev.h" -#include "sysemu/balloon.h" #include "qapi/visitor.h" #include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" @@ -2229,7 +2228,8 @@ static int kvm_init(MachineState *ms) s->sync_mmu = !!kvm_vm_check_extension(kvm_state, KVM_CAP_SYNC_MMU); if (!s->sync_mmu) { - qemu_balloon_inhibit(true); + ret = ram_block_discard_disable(true); + assert(!ret); } return 0; From patchwork Fri Jul 3 09:03:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bO8zki5Y; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypyL0hYTz9sPF for ; Fri, 3 Jul 2020 19:07:38 +1000 (AEST) Received: from localhost ([::1]:57796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHfT-0005OE-Rl for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:07:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHbz-0006ol-Mk for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43203 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 1jrHbx-0004Ok-Ns for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:03:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767037; 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=6ynQiUfJj9vMi7GVuuET1BQ3U6a6e7jBcQmv7JseED4=; b=bO8zki5YCD0ZywMd2brcPpjbBoJnjsYNhzIu1zittEgxtJbarz8i9efMNP1z79najZ0XXl Fomamq759QZ8IEtitL0sjB48QdKr2A6lu2q3NWMmvnfSzR6jVlVessJkF/k1x/NhEez8ye cVlG04tafywt52czobfPiag0vpIrOGo= 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-13-gLsxcn0rN-SY7XcV47nrSA-1; Fri, 03 Jul 2020 05:03:55 -0400 X-MC-Unique: gLsxcn0rN-SY7XcV47nrSA-1 Received: by mail-wr1-f71.google.com with SMTP id v3so1396879wrq.10 for ; Fri, 03 Jul 2020 02:03:55 -0700 (PDT) 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=6ynQiUfJj9vMi7GVuuET1BQ3U6a6e7jBcQmv7JseED4=; b=KVS9sBcPxFLp6roKOTRJe85FS/2cmN3cSpzWuFCSyjc14ByapgBzIpecn2r/UC4CmQ fTfge+8ddMYZ0bnmHoGbfZfEFowd+caDRav8mgvCc8KYXdU2Zued8HXiz1uhgcidHGkV j+K66BNjV9EaHADgyXEqQCIJvtNfz8pbpjAcsUaOp2I7vJI/i47l/8yYKG3/FHmxj6GD I/Azm6cEaDrdJbwOP4RH4znaa29QYTeBr3o0uqct1gYS0uY6jh4ZMeGqh2f/cP403U3w KE3UeLhqcbKg5qUhCI9BKzqNHHArolzmAN77F0/Ofq2ERf+m7YlcrvNuYTB3tiHYSIWR DRIA== X-Gm-Message-State: AOAM5329QMMEKQoxKmofErC4S6uADvASp/YBZE2PZ8giRWEeH1qMoLpt TgAksgolbTM/g9YknJm5XSoSmCGToOdHufZFlaWICh82AR200aOairInpCGZ05SJFGaJTGEDBkd 2juWzWKTmd99mMUY= X-Received: by 2002:a5d:68cc:: with SMTP id p12mr35289659wrw.111.1593767033827; Fri, 03 Jul 2020 02:03:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxesfTVNtPHNhuPmoGIeyeHTT4TOp0oSZI8kjOLZmNGrO79bo3yF4jUZuNXO0WAqaehzPRmw== X-Received: by 2002:a5d:68cc:: with SMTP id p12mr35289649wrw.111.1593767033680; Fri, 03 Jul 2020 02:03:53 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 30sm14315670wrm.74.2020.07.03.02.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:53 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:51 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 08/41] s390x/pv: Convert to ram_block_discard_disable() Message-ID: <20200703090252.368694-9-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Discarding RAM does not work as expected with protected VMs. Let's switch to ram_block_discard_disable() for now, as we want to get rid of qemu_balloon_inhibit(). Note that it will currently never fail, but might fail in the future with new technologies (e.g., virtio-mem). Acked-by: Cornelia Huck Cc: Richard Henderson Cc: Cornelia Huck Cc: Halil Pasic Cc: Christian Borntraeger Cc: Janosch Frank Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-6-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/s390x/s390-virtio-ccw.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index b111406d56..023fd25f2b 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -43,7 +43,6 @@ #include "hw/qdev-properties.h" #include "hw/s390x/tod.h" #include "sysemu/sysemu.h" -#include "sysemu/balloon.h" #include "hw/s390x/pv.h" #include "migration/blocker.h" @@ -329,7 +328,7 @@ static void s390_machine_unprotect(S390CcwMachineState *ms) ms->pv = false; migrate_del_blocker(pv_mig_blocker); error_free_or_abort(&pv_mig_blocker); - qemu_balloon_inhibit(false); + ram_block_discard_disable(false); } static int s390_machine_protect(S390CcwMachineState *ms) @@ -338,17 +337,22 @@ static int s390_machine_protect(S390CcwMachineState *ms) int rc; /* - * Ballooning on protected VMs needs support in the guest for - * sharing and unsharing balloon pages. Block ballooning for - * now, until we have a solution to make at least Linux guests - * either support it or fail gracefully. + * Discarding of memory in RAM blocks does not work as expected with + * protected VMs. Sharing and unsharing pages would be required. Disable + * it for now, until until we have a solution to make at least Linux + * guests either support it (e.g., virtio-balloon) or fail gracefully. */ - qemu_balloon_inhibit(true); + rc = ram_block_discard_disable(true); + if (rc) { + error_report("protected VMs: cannot disable RAM discard"); + return rc; + } + error_setg(&pv_mig_blocker, "protected VMs are currently not migrateable."); rc = migrate_add_blocker(pv_mig_blocker, &local_err); if (rc) { - qemu_balloon_inhibit(false); + ram_block_discard_disable(false); error_report_err(local_err); error_free_or_abort(&pv_mig_blocker); return rc; @@ -357,7 +361,7 @@ static int s390_machine_protect(S390CcwMachineState *ms) /* Create SE VM */ rc = s390_pv_vm_enable(); if (rc) { - qemu_balloon_inhibit(false); + ram_block_discard_disable(false); migrate_del_blocker(pv_mig_blocker); error_free_or_abort(&pv_mig_blocker); return rc; From patchwork Fri Jul 3 09:03:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZsMbGbGu; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypyC5hCZz9sRW for ; Fri, 3 Jul 2020 19:07:31 +1000 (AEST) Received: from localhost ([::1]:57232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHfN-0005AJ-GB for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:07:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHc5-000749-8F for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:60328 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 1jrHc3-0004Ph-2I for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767042; 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=zm5yAzYb8Njf/7lXhPa4kHkewLVdbaNS9bfJJo2eVkw=; b=ZsMbGbGuosJhVGKiw/iDfuj9I/cjjtDa2u6Dif/mFbs+DQ2cHVjMaWM+BgEzPt6iAkXqWF taM6AdwxlfKUAebpIWyd4jlw5CeUZu3+7ymFmQmzWrfbPVdH/uElqaB56WH7W91WgetzuP ORE+LlMWQMwZc1spQvvT82HMdVrbWJo= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-237-eaEJnR4-PnSq0ljaVH2Ktg-1; Fri, 03 Jul 2020 05:03:58 -0400 X-MC-Unique: eaEJnR4-PnSq0ljaVH2Ktg-1 Received: by mail-wm1-f70.google.com with SMTP id v6so32315472wmg.1 for ; Fri, 03 Jul 2020 02:03:58 -0700 (PDT) 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=zm5yAzYb8Njf/7lXhPa4kHkewLVdbaNS9bfJJo2eVkw=; b=mlWd0iQhtciEnevtnYh1RCaUf+j0gaIe77G2HEGlSielCY5yLg9rMwuZqKQA/KL97T r+U2WKMVMFjSmt+tOENk7GbTasfrzwNxyS4iP5DCXSRYwIQJmQHz1+fu6nvj4bc2zTcf 3a1cnaq2H+iWetFrxuscbISnqsOduOlOHV6MIG2ujPd6KnkHa54Ne8SzQJM25dmxdWFH SaRy2PXI0ZIYTtStcCjVpV/XT2VY1g/Qx6EAT1P/i1nJfXhf+RKmxOVhZNUAjp30mFNY M8rxIGsYctt15FcnWczM2rUMn3hHQ3o5qtY1xkc3Yyrbo76qneTSTOjLuz5VEdKsUk/r W90A== X-Gm-Message-State: AOAM531YVu6audk4zeOYnp6RG37RxHy1t6fBaJ/GXp9DrwuVM7uCZWmw qbFcfOKPphFtkqNXc/vPIl67GH38p8Z7EVznjW1mVXB7FTtSH4fjDU1b0/lAXJ2yIi4TNwkPOdA ImzqEOGADDgTv7YQ= X-Received: by 2002:adf:b312:: with SMTP id j18mr33621334wrd.195.1593767036776; Fri, 03 Jul 2020 02:03:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoc2SLnAmxavs/V1L0Gt/mcTc8+oh7NxCl3MFrxWyaXbsKflvPf2rchkFGYn254VUSAmPXUQ== X-Received: by 2002:adf:b312:: with SMTP id j18mr33621309wrd.195.1593767036481; Fri, 03 Jul 2020 02:03:56 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id r3sm15071975wrg.70.2020.07.03.02.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:55 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:54 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 09/41] virtio-balloon: Rip out qemu_balloon_inhibit() Message-ID: <20200703090252.368694-10-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Juan Quintela , "Dr . David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand The only remaining special case is postcopy. It cannot handle concurrent discards yet, which would result in requesting already sent pages from the source. Special-case it in virtio-balloon instead. Introduce migration_in_incoming_postcopy(), to find out if incoming postcopy is active. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Cc: "Michael S. Tsirkin" Cc: Juan Quintela Cc: "Dr. David Alan Gilbert" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-7-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/migration/misc.h | 2 ++ include/sysemu/balloon.h | 2 -- balloon.c | 18 ------------------ hw/virtio/virtio-balloon.c | 10 ++++++++-- migration/migration.c | 7 +++++++ migration/postcopy-ram.c | 23 ----------------------- 6 files changed, 17 insertions(+), 45 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index d2762257aa..34e7d75713 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -69,6 +69,8 @@ bool migration_has_failed(MigrationState *); /* ...and after the device transmission */ bool migration_in_postcopy_after_devices(MigrationState *); void migration_global_dump(Monitor *mon); +/* True if incomming migration entered POSTCOPY_INCOMING_DISCARD */ +bool migration_in_incoming_postcopy(void); /* migration/block-dirty-bitmap.c */ void dirty_bitmap_mig_init(void); diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h index aea0c44985..20a2defe3a 100644 --- a/include/sysemu/balloon.h +++ b/include/sysemu/balloon.h @@ -23,7 +23,5 @@ typedef void (QEMUBalloonStatus)(void *opaque, BalloonInfo *info); int qemu_add_balloon_handler(QEMUBalloonEvent *event_func, QEMUBalloonStatus *stat_func, void *opaque); void qemu_remove_balloon_handler(void *opaque); -bool qemu_balloon_is_inhibited(void); -void qemu_balloon_inhibit(bool state); #endif diff --git a/balloon.c b/balloon.c index 5fff79523a..354408c6ea 100644 --- a/balloon.c +++ b/balloon.c @@ -36,24 +36,6 @@ static QEMUBalloonEvent *balloon_event_fn; static QEMUBalloonStatus *balloon_stat_fn; static void *balloon_opaque; -static int balloon_inhibit_count; - -bool qemu_balloon_is_inhibited(void) -{ - return atomic_read(&balloon_inhibit_count) > 0 || - ram_block_discard_is_disabled(); -} - -void qemu_balloon_inhibit(bool state) -{ - if (state) { - atomic_inc(&balloon_inhibit_count); - } else { - atomic_dec(&balloon_inhibit_count); - } - - assert(atomic_read(&balloon_inhibit_count) >= 0); -} static bool have_balloon(Error **errp) { diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 8a84718490..ae31f0817a 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -63,6 +63,12 @@ static bool virtio_balloon_pbp_matches(PartiallyBalloonedPage *pbp, return pbp->base_gpa == base_gpa; } +static bool virtio_balloon_inhibited(void) +{ + /* Postcopy cannot deal with concurrent discards, so it's special. */ + return ram_block_discard_is_disabled() || migration_in_incoming_postcopy(); +} + static void balloon_inflate_page(VirtIOBalloon *balloon, MemoryRegion *mr, hwaddr mr_offset, PartiallyBalloonedPage *pbp) @@ -336,7 +342,7 @@ static void virtio_balloon_handle_report(VirtIODevice *vdev, VirtQueue *vq) * accessible by another device or process, or if the guest is * expecting it to retain a non-zero value. */ - if (qemu_balloon_is_inhibited() || dev->poison_val) { + if (virtio_balloon_inhibited() || dev->poison_val) { goto skip_element; } @@ -421,7 +427,7 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq) trace_virtio_balloon_handle_output(memory_region_name(section.mr), pa); - if (!qemu_balloon_is_inhibited()) { + if (!virtio_balloon_inhibited()) { if (vq == s->ivq) { balloon_inflate_page(s, section.mr, section.offset_within_region, &pbp); diff --git a/migration/migration.c b/migration/migration.c index 481a590f72..d365d82209 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1772,6 +1772,13 @@ bool migration_in_postcopy_after_devices(MigrationState *s) return migration_in_postcopy() && s->postcopy_after_devices; } +bool migration_in_incoming_postcopy(void) +{ + PostcopyState ps = postcopy_state_get(); + + return ps >= POSTCOPY_INCOMING_DISCARD && ps < POSTCOPY_INCOMING_END; +} + bool migration_is_idle(void) { MigrationState *s = current_migration; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a36402722b..b41a9fe2fd 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -27,7 +27,6 @@ #include "qemu/notify.h" #include "qemu/rcu.h" #include "sysemu/sysemu.h" -#include "sysemu/balloon.h" #include "qemu/error-report.h" #include "trace.h" #include "hw/boards.h" @@ -520,20 +519,6 @@ int postcopy_ram_incoming_init(MigrationIncomingState *mis) return 0; } -/* - * Manage a single vote to the QEMU balloon inhibitor for all postcopy usage, - * last caller wins. - */ -static void postcopy_balloon_inhibit(bool state) -{ - static bool cur_state = false; - - if (state != cur_state) { - qemu_balloon_inhibit(state); - cur_state = state; - } -} - /* * At the end of a migration where postcopy_ram_incoming_init was called. */ @@ -565,8 +550,6 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) mis->have_fault_thread = false; } - postcopy_balloon_inhibit(false); - if (enable_mlock) { if (os_mlock() < 0) { error_report("mlock: %s", strerror(errno)); @@ -1160,12 +1143,6 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis) } memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_size); - /* - * Ballooning can mark pages as absent while we're postcopying - * that would cause false userfaults. - */ - postcopy_balloon_inhibit(true); - trace_postcopy_ram_enable_notify(); return 0; From patchwork Fri Jul 3 09:03:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b5TWfZLp; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq033Bhzz9sPF for ; Fri, 3 Jul 2020 19:09:07 +1000 (AEST) Received: from localhost ([::1]:37384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHgv-000074-6t for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:09:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHc7-0007AH-Eu for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:07 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:51399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jrHc5-0004Py-Nr for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767044; 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=rJ+ftu7sRo4+D1GoB2r1H/Xv24+UlICQh28kpGHM9w0=; b=b5TWfZLpKK+M2seSXbm8a1peCuUSVBFWHkBcDlqjqeLYqtcArCe01hRuZ4CHuJwbAZD4FY KtmUX77NPSpSRjIYzUth5iaAAbkR3QOqA0ws7bHr1nC6Ilj46pCt+pbvaltLXUe56JYdIq eUjRLdw83T+7WTYjDc7DNjDqLwC8Psg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-By23FoaXMGmtU0AnyMML1w-1; Fri, 03 Jul 2020 05:04:01 -0400 X-MC-Unique: By23FoaXMGmtU0AnyMML1w-1 Received: by mail-wm1-f69.google.com with SMTP id o13so34540893wmh.9 for ; Fri, 03 Jul 2020 02:04:00 -0700 (PDT) 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=rJ+ftu7sRo4+D1GoB2r1H/Xv24+UlICQh28kpGHM9w0=; b=iOFam0qrKDu2qQXNIQACxp2JqgfSfcYpnAg+d3vmgDKTEzOqj9U4Mqtcou2vp60vYJ JqmAGjxaBzBp1jnHiueZmQ5FGbYCskJCv+cIVPl+D78e66/y3UrqwgDuObdUt8luR5/F RuDXXwfBo2sbqOGLH0S4PQhaK/wm5ldVKvb/DtFzgZYO+aqbOcDrqcOeY+doeWS94P+c v3zF4Vl0qZ3wtwBWG8owUFuZK96fwwrpFN9H9y4YW7nN/+a1IOYPk/eCdjdfqLXr9N7j emn6lTK8gTci5XNKVv1sBYytK/iKYCnfBtDZZEOPYWVHhEh32seL8Ce4hVMwFaTkMpyW okZQ== X-Gm-Message-State: AOAM530rcr3QbJHcHRnP03+FTrI9hzIJQ8V2+bU7Drs2/7C3pdRrE0lK GXwASa8OkwX2nOuwXbR5otDkJXwtST06KsY9ROB+8/O3BkdF6rqWMR54mk3YzdSqmOSGwH6K0P0 2fcMA/sXl4G7bGME= X-Received: by 2002:adf:8501:: with SMTP id 1mr39287481wrh.153.1593767039336; Fri, 03 Jul 2020 02:03:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYqzI2lS1iFqxyE6OANc6HkegOhXR4P4a8ODviE/ZORnUP/WPyr8tUGKr55WuL++m5AZNR3A== X-Received: by 2002:adf:8501:: with SMTP id 1mr39287463wrh.153.1593767039131; Fri, 03 Jul 2020 02:03:59 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id q7sm1404083wra.56.2020.07.03.02.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:03:58 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:56 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 10/41] target/i386: sev: Use ram_block_discard_disable() Message-ID: <20200703090252.368694-11-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.61; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:17:33 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Eduardo Habkost , David Hildenbrand , "Dr . David Alan Gilbert" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand AMD SEV will pin all guest memory, mark discarding of RAM broken. At the time this is called, we cannot have anyone active that relies on discards to work properly - let's still implement error handling. Reviewed-by: Dr. David Alan Gilbert Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-8-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- target/i386/sev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index d273174ad3..f100a53231 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -680,6 +680,12 @@ sev_guest_init(const char *id) uint32_t host_cbitpos; struct sev_user_data_status status = {}; + ret = ram_block_discard_disable(true); + if (ret) { + error_report("%s: cannot disable RAM discard", __func__); + return NULL; + } + sev = lookup_sev_guest_info(id); if (!sev) { error_report("%s: '%s' is not a valid '%s' object", @@ -751,6 +757,7 @@ sev_guest_init(const char *id) return sev; err: sev_guest = NULL; + ram_block_discard_disable(false); return NULL; } From patchwork Fri Jul 3 09:03:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322211 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Xj7l8D4u; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypwJ3ffFz9sRk for ; Fri, 3 Jul 2020 19:05:52 +1000 (AEST) Received: from localhost ([::1]:48892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHdm-0001gS-85 for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:05:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHc8-0007Au-40 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:08 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:40745 helo=us-smtp-delivery-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 1jrHc5-0004Q0-PC for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767044; 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=rnwhkibuuryD3VaVsetE4dEaQSFYlxZxsA4QPNf181w=; b=Xj7l8D4u3VhP8Tjlii1PypY3HvAtpxwvUtuftOb1UZ5SaQ9NoCCghR3zRRSe/nr5fclFW4 6/H13Vjbl2/byrVxV8XlIiqhLhtdF+itzdJRQyG0zPly0mNw3hfhS0Fzaf82uAtsM5TxY7 cFM/AfqCFqaJf38gxtrBvbLzujPoBog= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-33-302NP6nFOmatqi4d9xgkTQ-1; Fri, 03 Jul 2020 05:04:03 -0400 X-MC-Unique: 302NP6nFOmatqi4d9xgkTQ-1 Received: by mail-wr1-f72.google.com with SMTP id o12so30996158wrj.23 for ; Fri, 03 Jul 2020 02:04:03 -0700 (PDT) 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=rnwhkibuuryD3VaVsetE4dEaQSFYlxZxsA4QPNf181w=; b=XwifsuSxPfgOSLnv9ZLm5LlQJM3f2YPtioL6ghnQle5ZWDRyjXYXR4ecTTd2syjnBs YdZmdAtAiFJevoyXpH8UCPMIlGt4z3y7X4M3KWNO9DqBTddS2qMazaH8LHZ60tGmKxvy 4hOK9JSxtTHc1OdO4AA8os5Z/iPN/HoBi9s9zDn9BpsJDC/RR1oj8cYPHenIbA5ByGag iibhNoY2h8VCfSuHfg4mM6iZJTrwyA+cuAOyXC+66R1DfHPqnzzD4UcMTunmddOoFX+x 1qtqyfELsRAMtnHEC3Ogv8243HEzRYu698wVPHeZgX87J0KoUtfwHISEnw4CuvvP2Z+A 32Bg== X-Gm-Message-State: AOAM533JRRQ/KGf7GaArXmSmAeBw5P8pLYI8ge1dOOiDS+RqGfzolTmN ewEUGC58RJINxNYOryOrDAw61QBkLDUulwDzqTa7+ILa1p1jX7ovNq2vPfg8cPlfHEsL7SldrmF MMwSRXUfrWEcajNA= X-Received: by 2002:a1c:8117:: with SMTP id c23mr34101336wmd.157.1593767041866; Fri, 03 Jul 2020 02:04:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOB+uxXEgl2dQNx7bkwmysvny+NE4Cr1joxpCN8CulWI2eXMmPmxTBel5s32ijgBWWgEbDJw== X-Received: by 2002:a1c:8117:: with SMTP id c23mr34101328wmd.157.1593767041706; Fri, 03 Jul 2020 02:04:01 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id h84sm13810740wme.22.2020.07.03.02.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:01 -0700 (PDT) Date: Fri, 3 Jul 2020 05:03:59 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 11/41] migration/rdma: Use ram_block_discard_disable() Message-ID: <20200703090252.368694-12-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Juan Quintela , "Dr . David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand RDMA will pin all guest memory (as documented in docs/rdma.txt). We want to disable RAM block discards - however, to keep it simple use ram_block_discard_is_required() instead of inhibiting. Note: It is not sufficient to limit disabling to pin_all. Even when only conditionally pinning 1 MB chunks, as soon as one page within such a chunk was discarded and one page not, the discarded pages will be pinned as well. Reviewed-by: Dr. David Alan Gilbert Cc: "Michael S. Tsirkin" Cc: Juan Quintela Cc: "Dr. David Alan Gilbert" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-9-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- migration/rdma.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index ec45d33ba3..bbe6f36627 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -29,6 +29,7 @@ #include "qemu/sockets.h" #include "qemu/bitmap.h" #include "qemu/coroutine.h" +#include "exec/memory.h" #include #include #include @@ -4017,8 +4018,14 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp) Error *local_err = NULL; trace_rdma_start_incoming_migration(); - rdma = qemu_rdma_data_init(host_port, &local_err); + /* Avoid ram_block_discard_disable(), cannot change during migration. */ + if (ram_block_discard_is_required()) { + error_setg(errp, "RDMA: cannot disable RAM discard"); + return; + } + + rdma = qemu_rdma_data_init(host_port, &local_err); if (rdma == NULL) { goto err; } @@ -4067,10 +4074,17 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp) { MigrationState *s = opaque; - RDMAContext *rdma = qemu_rdma_data_init(host_port, errp); RDMAContext *rdma_return_path = NULL; + RDMAContext *rdma; int ret = 0; + /* Avoid ram_block_discard_disable(), cannot change during migration. */ + if (ram_block_discard_is_required()) { + error_setg(errp, "RDMA: cannot disable RAM discard"); + return; + } + + rdma = qemu_rdma_data_init(host_port, errp); if (rdma == NULL) { goto err; } From patchwork Fri Jul 3 09:04:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VhX8BgxQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqJW37Fdz9sPF for ; Fri, 3 Jul 2020 19:23:23 +1000 (AEST) Received: from localhost ([::1]:46874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHuj-0004Df-2k for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:23:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHf0-0005Qk-9W for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:07:06 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20404 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 1jrHex-0004yU-36 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:07:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767222; 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=ZxzgbY0wTkljt/EIcrPmrPRKcNp5zQS1Y4vQ0bafojw=; b=VhX8BgxQq2bZavQNN//1Omt5nKMHHs/uS84PX+BdBybOtp8paHWdIW8lKpJS9EUf/uPGS0 +uPv0E8rqYDdidCVjpPmXsKuhHTejVABfVeBm97LwMyf53U9jaQbK9Scrt1QKiHcPfCKu4 BYxb/2HwikUGmWEmqqOo2N6rFsdjUJk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-415-ysxpQMUKNm-44GLJukqC5g-1; Fri, 03 Jul 2020 05:04:05 -0400 X-MC-Unique: ysxpQMUKNm-44GLJukqC5g-1 Received: by mail-wr1-f69.google.com with SMTP id y13so31107281wrp.13 for ; Fri, 03 Jul 2020 02:04:05 -0700 (PDT) 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=ZxzgbY0wTkljt/EIcrPmrPRKcNp5zQS1Y4vQ0bafojw=; b=OU4zneLBt/vsoy7sdktpCtKMk5bDFS8Ejzs75aRNMbbswXSeFguiUUtzvBurQg8bmG FfyGIbRT2ESw+naaCt9ma3/FhCQNn9PDBGMeGewIzFjoIsAmS0MR6X/G2CyIfumW3anL KVXu+Gk/zFN6HUPgXNVEnlac1kyA+ycjKYSmzN/fIN2Xm83sJAVPzT9hF3PdSuAfcp1r dCSTgnHFDvInil1W+kQkZNunS1NkGgT4vcVAROdU6WtpqwR+3r3ZrGczHNm3qPV+d51R 43Jj/d2cJeX8sCmEQBzDG5wZVgVZOodZ2GYDP0LYn7coSBAOlS1LJIGafo/e+8lgIjQS DuCQ== X-Gm-Message-State: AOAM533AHQo3D3MsvO6dkyjfP+vWzAS6362E+GmK34qgGjkaSqWCAU6L WgtEnuRu5ku5GJkFJc/W6t6usMYyhHeTHee5862WeMhycdyRIORtci2HGuOQyxxkDJqoUIPgEV+ IyEEM6Y00ppm6jvA= X-Received: by 2002:a05:600c:2182:: with SMTP id e2mr35090392wme.186.1593767044428; Fri, 03 Jul 2020 02:04:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoXMe/rD/7RnQBvEfegqwXv7OIm23PiFFWYgzAgjS4lFwwQLu2bFpHNTFcrV601IursYfejA== X-Received: by 2002:a05:600c:2182:: with SMTP id e2mr35090378wme.186.1593767044206; Fri, 03 Jul 2020 02:04:04 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id z25sm12292724wmk.28.2020.07.03.02.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:03 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:01 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 12/41] migration/colo: Use ram_block_discard_disable() Message-ID: <20200703090252.368694-13-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Lukas Straub , Hailiang Zhang , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand COLO will copy all memory in a RAM block, disable discarding of RAM. Reviewed-by: Dr. David Alan Gilbert Tested-by: Lukas Straub Cc: "Michael S. Tsirkin" Cc: Hailiang Zhang Cc: Juan Quintela Cc: "Dr. David Alan Gilbert" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-10-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/migration/colo.h | 2 +- migration/migration.c | 8 +++++++- migration/savevm.c | 11 +++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/migration/colo.h b/include/migration/colo.h index 1636e6f907..768e1f04c3 100644 --- a/include/migration/colo.h +++ b/include/migration/colo.h @@ -25,7 +25,7 @@ void migrate_start_colo_process(MigrationState *s); bool migration_in_colo_state(void); /* loadvm */ -void migration_incoming_enable_colo(void); +int migration_incoming_enable_colo(void); void migration_incoming_disable_colo(void); bool migration_incoming_colo_enabled(void); void *colo_process_incoming_thread(void *opaque); diff --git a/migration/migration.c b/migration/migration.c index d365d82209..92e44e021e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -338,12 +338,18 @@ bool migration_incoming_colo_enabled(void) void migration_incoming_disable_colo(void) { + ram_block_discard_disable(false); migration_colo_enabled = false; } -void migration_incoming_enable_colo(void) +int migration_incoming_enable_colo(void) { + if (ram_block_discard_disable(true)) { + error_report("COLO: cannot disable RAM discard"); + return -EBUSY; + } migration_colo_enabled = true; + return 0; } void migrate_add_address(SocketAddress *address) diff --git a/migration/savevm.c b/migration/savevm.c index b979ea6e7f..6e01724605 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2111,8 +2111,15 @@ static int loadvm_handle_recv_bitmap(MigrationIncomingState *mis, static int loadvm_process_enable_colo(MigrationIncomingState *mis) { - migration_incoming_enable_colo(); - return colo_init_ram_cache(); + int ret = migration_incoming_enable_colo(); + + if (!ret) { + ret = colo_init_ram_cache(); + if (ret) { + migration_incoming_disable_colo(); + } + } + return ret; } /* From patchwork Fri Jul 3 09:04:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=A+jfsu9u; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq274Tlhz9sR4 for ; Fri, 3 Jul 2020 19:10:55 +1000 (AEST) Received: from localhost ([::1]:45748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHif-0003hy-Au for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:10:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcG-0007VR-44 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:16 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:33816 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 1jrHcC-0004Qi-I5 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767051; 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=XBtLpnVcYK2eR3KdFAMCEyZ8NUHfZ5JHGIaS6wrLkPg=; b=A+jfsu9uoyNa+qOFJmXP7uqlr6dCtU6TVkwfdNFBZanREcIeW8wGxX3ziXsRr+DMVcZtIC ETdBt36DMf9O3D2QyAOGc1su2BVbDTmdrBx3XyLXrJybtvx+Zn7a6xSE1m5U9jK36PNQ/n l7S8d4Xnoj2PY1lRaGISzxwYUmATDUI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-334-awwaUhxCMpWARrV29tjT2A-1; Fri, 03 Jul 2020 05:04:09 -0400 X-MC-Unique: awwaUhxCMpWARrV29tjT2A-1 Received: by mail-wm1-f71.google.com with SMTP id g6so28645853wmk.4 for ; Fri, 03 Jul 2020 02:04:09 -0700 (PDT) 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=XBtLpnVcYK2eR3KdFAMCEyZ8NUHfZ5JHGIaS6wrLkPg=; b=U4a5gx9n+3xPGyqRyQfQoxbz1veqsLXTO8wHmPD+3GPNkJhaScUTdcSd2Roa+HPhli MhG01Gn/B3ND+ur01GtZ2WV84zfgLOl4/pefpstxKct9ibZqx525mzf/40vA38oHQdOa u+Yh7Eyao8CBFNEyxfZlK1IskulJSNCNPoNcq8HlA1WXb3emn+x4tWe9jT9Vyoj/nRUf 02EdS8aNP+9fgCmUVYL5Dr6shX336GRThGGU+QUigF1Tk3QZTm7mtZI8zcRu0PEAfFwX +fF7n3+PaWMTVN6NJNZoLnKTGM6GW+ZKAJum/78NnjdRmiGRCXrNfduPBWlFsCEAtVQj lz4g== X-Gm-Message-State: AOAM533WgXQ2Z+zaaKkDTzAdKcuNjjXOl8evaRm88Y3nz2THLYJWdUhe ymijNTxPVFi3at1biurpHn9F+BK17zNfF6Thpb9EzYF9HEKxasqtx7yOUCjFe2CnKjOKwvhtGjx z8bhIljkqJ8rhIQE= X-Received: by 2002:a1c:4343:: with SMTP id q64mr35632793wma.20.1593767047443; Fri, 03 Jul 2020 02:04:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1h2kaOHI+UQWh61ltnGJkXrEglouxvI6wmVyIeNmboHxvM6y+cspDYkWdTShJ6NXq5O63Ug== X-Received: by 2002:a1c:4343:: with SMTP id q64mr35632760wma.20.1593767047005; Fri, 03 Jul 2020 02:04:07 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id x185sm13489475wmg.41.2020.07.03.02.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:06 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:04 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 13/41] virtio-mem: Paravirtualized memory hot(un)plug Message-ID: <20200703090252.368694-14-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , David Hildenbrand , Markus Armbruster , "Dr. David Alan Gilbert" , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand This is the very basic/initial version of virtio-mem. An introduction to virtio-mem can be found in the Linux kernel driver [1]. While it can be used in the current state for hotplug of a smaller amount of memory, it will heavily benefit from resizeable memory regions in the future. Each virtio-mem device manages a memory region (provided via a memory backend). After requested by the hypervisor ("requested-size"), the guest can try to plug/unplug blocks of memory within that region, in order to reach the requested size. Initially, and after a reboot, all memory is unplugged (except in special cases - reboot during postcopy). The guest may only try to plug/unplug blocks of memory within the usable region size. The usable region size is a little bigger than the requested size, to give the device driver some flexibility. The usable region size will only grow, except on reboots or when all memory is requested to get unplugged. The guest can never plug more memory than requested. Unplugged memory will get zapped/discarded, similar to in a balloon device. The block size is variable, however, it is always chosen in a way such that THP splits are avoided (e.g., 2MB). The state of each block (plugged/unplugged) is tracked in a bitmap. As virtio-mem devices (e.g., virtio-mem-pci) will be memory devices, we now expose "VirtioMEMDeviceInfo" via "query-memory-devices". -------------------------------------------------------------------------- There are two important follow-up items that are in the works: 1. Resizeable memory regions: Use resizeable allocations/RAM blocks to grow/shrink along with the usable region size. This avoids creating initially very big VMAs, RAM blocks, and KVM slots. 2. Protection of unplugged memory: Make sure the gust cannot actually make use of unplugged memory. Other follow-up items that are in the works: 1. Exclude unplugged memory during migration (via precopy notifier). 2. Handle remapping of memory. 3. Support for other architectures. -------------------------------------------------------------------------- Example usage (virtio-mem-pci is introduced in follow-up patches): Start QEMU with two virtio-mem devices (one per NUMA node): $ qemu-system-x86_64 -m 4G,maxmem=20G \ -smp sockets=2,cores=2 \ -numa node,nodeid=0,cpus=0-1 -numa node,nodeid=1,cpus=2-3 \ [...] -object memory-backend-ram,id=mem0,size=8G \ -device virtio-mem-pci,id=vm0,memdev=mem0,node=0,requested-size=0M \ -object memory-backend-ram,id=mem1,size=8G \ -device virtio-mem-pci,id=vm1,memdev=mem1,node=1,requested-size=1G Query the configuration: (qemu) info memory-devices Memory device [virtio-mem]: "vm0" memaddr: 0x140000000 node: 0 requested-size: 0 size: 0 max-size: 8589934592 block-size: 2097152 memdev: /objects/mem0 Memory device [virtio-mem]: "vm1" memaddr: 0x340000000 node: 1 requested-size: 1073741824 size: 1073741824 max-size: 8589934592 block-size: 2097152 memdev: /objects/mem1 Add some memory to node 0: (qemu) qom-set vm0 requested-size 500M Remove some memory from node 1: (qemu) qom-set vm1 requested-size 200M Query the configuration again: (qemu) info memory-devices Memory device [virtio-mem]: "vm0" memaddr: 0x140000000 node: 0 requested-size: 524288000 size: 524288000 max-size: 8589934592 block-size: 2097152 memdev: /objects/mem0 Memory device [virtio-mem]: "vm1" memaddr: 0x340000000 node: 1 requested-size: 209715200 size: 209715200 max-size: 8589934592 block-size: 2097152 memdev: /objects/mem1 [1] https://lkml.kernel.org/r/20200311171422.10484-1-david@redhat.com Cc: "Michael S. Tsirkin" Cc: Eric Blake Cc: Markus Armbruster Cc: "Dr. David Alan Gilbert" Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-11-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qapi/misc.json | 39 +- include/hw/virtio/virtio-mem.h | 78 ++++ hw/virtio/virtio-mem.c | 724 +++++++++++++++++++++++++++++++++ hw/virtio/Kconfig | 11 + hw/virtio/Makefile.objs | 1 + 5 files changed, 852 insertions(+), 1 deletion(-) create mode 100644 include/hw/virtio/virtio-mem.h create mode 100644 hw/virtio/virtio-mem.c diff --git a/qapi/misc.json b/qapi/misc.json index a5a0beb902..65ca3edf32 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1356,19 +1356,56 @@ } } +## +# @VirtioMEMDeviceInfo: +# +# VirtioMEMDevice state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @requested-size: the user requested size of the device +# +# @size: the (current) size of memory that the device provides +# +# @max-size: the maximum size of memory that the device can provide +# +# @block-size: the block size of memory that the device provides +# +# @node: NUMA node number where device is assigned to +# +# @memdev: memory backend linked with the region +# +# Since: 5.1 +## +{ 'struct': 'VirtioMEMDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': 'size', + 'requested-size': 'size', + 'size': 'size', + 'max-size': 'size', + 'block-size': 'size', + 'node': 'int', + 'memdev': 'str' + } +} + ## # @MemoryDeviceInfo: # # Union containing information about a memory device # # nvdimm is included since 2.12. virtio-pmem is included since 4.1. +# virtio-mem is included since 5.1. # # Since: 2.1 ## { 'union': 'MemoryDeviceInfo', 'data': { 'dimm': 'PCDIMMDeviceInfo', 'nvdimm': 'PCDIMMDeviceInfo', - 'virtio-pmem': 'VirtioPMEMDeviceInfo' + 'virtio-pmem': 'VirtioPMEMDeviceInfo', + 'virtio-mem': 'VirtioMEMDeviceInfo' } } diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h new file mode 100644 index 0000000000..6981096f7c --- /dev/null +++ b/include/hw/virtio/virtio-mem.h @@ -0,0 +1,78 @@ +/* + * Virtio MEM device + * + * Copyright (C) 2020 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_VIRTIO_MEM_H +#define HW_VIRTIO_MEM_H + +#include "standard-headers/linux/virtio_mem.h" +#include "hw/virtio/virtio.h" +#include "qapi/qapi-types-misc.h" +#include "sysemu/hostmem.h" + +#define TYPE_VIRTIO_MEM "virtio-mem" + +#define VIRTIO_MEM(obj) \ + OBJECT_CHECK(VirtIOMEM, (obj), TYPE_VIRTIO_MEM) +#define VIRTIO_MEM_CLASS(oc) \ + OBJECT_CLASS_CHECK(VirtIOMEMClass, (oc), TYPE_VIRTIO_MEM) +#define VIRTIO_MEM_GET_CLASS(obj) \ + OBJECT_GET_CLASS(VirtIOMEMClass, (obj), TYPE_VIRTIO_MEM) + +#define VIRTIO_MEM_MEMDEV_PROP "memdev" +#define VIRTIO_MEM_NODE_PROP "node" +#define VIRTIO_MEM_SIZE_PROP "size" +#define VIRTIO_MEM_REQUESTED_SIZE_PROP "requested-size" +#define VIRTIO_MEM_BLOCK_SIZE_PROP "block-size" +#define VIRTIO_MEM_ADDR_PROP "memaddr" + +typedef struct VirtIOMEM { + VirtIODevice parent_obj; + + /* guest -> host request queue */ + VirtQueue *vq; + + /* bitmap used to track unplugged memory */ + int32_t bitmap_size; + unsigned long *bitmap; + + /* assigned memory backend and memory region */ + HostMemoryBackend *memdev; + + /* NUMA node */ + uint32_t node; + + /* assigned address of the region in guest physical memory */ + uint64_t addr; + + /* usable region size (<= region_size) */ + uint64_t usable_region_size; + + /* actual size (how much the guest plugged) */ + uint64_t size; + + /* requested size */ + uint64_t requested_size; + + /* block size and alignment */ + uint64_t block_size; +} VirtIOMEM; + +typedef struct VirtIOMEMClass { + /* private */ + VirtIODevice parent; + + /* public */ + void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi); + MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp); +} VirtIOMEMClass; + +#endif diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c new file mode 100644 index 0000000000..d8a0c974d3 --- /dev/null +++ b/hw/virtio/virtio-mem.c @@ -0,0 +1,724 @@ +/* + * Virtio MEM device + * + * Copyright (C) 2020 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/iov.h" +#include "qemu/cutils.h" +#include "qemu/error-report.h" +#include "qemu/units.h" +#include "sysemu/numa.h" +#include "sysemu/sysemu.h" +#include "sysemu/reset.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/virtio-access.h" +#include "hw/virtio/virtio-mem.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "exec/ram_addr.h" +#include "migration/misc.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "config-devices.h" + +/* + * Use QEMU_VMALLOC_ALIGN, so no THP will have to be split when unplugging + * memory (e.g., 2MB on x86_64). + */ +#define VIRTIO_MEM_MIN_BLOCK_SIZE QEMU_VMALLOC_ALIGN +/* + * Size the usable region bigger than the requested size if possible. Esp. + * Linux guests will only add (aligned) memory blocks in case they fully + * fit into the usable region, but plug+online only a subset of the pages. + * The memory block size corresponds mostly to the section size. + * + * This allows e.g., to add 20MB with a section size of 128MB on x86_64, and + * a section size of 1GB on arm64 (as long as the start address is properly + * aligned, similar to ordinary DIMMs). + * + * We can change this at any time and maybe even make it configurable if + * necessary (as the section size can change). But it's more likely that the + * section size will rather get smaller and not bigger over time. + */ +#if defined(__x86_64__) +#define VIRTIO_MEM_USABLE_EXTENT (2 * (128 * MiB)) +#else +#error VIRTIO_MEM_USABLE_EXTENT not defined +#endif + +static bool virtio_mem_is_busy(void) +{ + /* + * Postcopy cannot handle concurrent discards and we don't want to migrate + * pages on-demand with stale content when plugging new blocks. + */ + return migration_in_incoming_postcopy(); +} + +static bool virtio_mem_test_bitmap(VirtIOMEM *vmem, uint64_t start_gpa, + uint64_t size, bool plugged) +{ + const unsigned long first_bit = (start_gpa - vmem->addr) / vmem->block_size; + const unsigned long last_bit = first_bit + (size / vmem->block_size) - 1; + unsigned long found_bit; + + /* We fake a shorter bitmap to avoid searching too far. */ + if (plugged) { + found_bit = find_next_zero_bit(vmem->bitmap, last_bit + 1, first_bit); + } else { + found_bit = find_next_bit(vmem->bitmap, last_bit + 1, first_bit); + } + return found_bit > last_bit; +} + +static void virtio_mem_set_bitmap(VirtIOMEM *vmem, uint64_t start_gpa, + uint64_t size, bool plugged) +{ + const unsigned long bit = (start_gpa - vmem->addr) / vmem->block_size; + const unsigned long nbits = size / vmem->block_size; + + if (plugged) { + bitmap_set(vmem->bitmap, bit, nbits); + } else { + bitmap_clear(vmem->bitmap, bit, nbits); + } +} + +static void virtio_mem_send_response(VirtIOMEM *vmem, VirtQueueElement *elem, + struct virtio_mem_resp *resp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(vmem); + VirtQueue *vq = vmem->vq; + + iov_from_buf(elem->in_sg, elem->in_num, 0, resp, sizeof(*resp)); + + virtqueue_push(vq, elem, sizeof(*resp)); + virtio_notify(vdev, vq); +} + +static void virtio_mem_send_response_simple(VirtIOMEM *vmem, + VirtQueueElement *elem, + uint16_t type) +{ + struct virtio_mem_resp resp = { + .type = cpu_to_le16(type), + }; + + virtio_mem_send_response(vmem, elem, &resp); +} + +static bool virtio_mem_valid_range(VirtIOMEM *vmem, uint64_t gpa, uint64_t size) +{ + if (!QEMU_IS_ALIGNED(gpa, vmem->block_size)) { + return false; + } + if (gpa + size < gpa || !size) { + return false; + } + if (gpa < vmem->addr || gpa >= vmem->addr + vmem->usable_region_size) { + return false; + } + if (gpa + size > vmem->addr + vmem->usable_region_size) { + return false; + } + return true; +} + +static int virtio_mem_set_block_state(VirtIOMEM *vmem, uint64_t start_gpa, + uint64_t size, bool plug) +{ + const uint64_t offset = start_gpa - vmem->addr; + int ret; + + if (virtio_mem_is_busy()) { + return -EBUSY; + } + + if (!plug) { + ret = ram_block_discard_range(vmem->memdev->mr.ram_block, offset, size); + if (ret) { + error_report("Unexpected error discarding RAM: %s", + strerror(-ret)); + return -EBUSY; + } + } + virtio_mem_set_bitmap(vmem, start_gpa, size, plug); + return 0; +} + +static int virtio_mem_state_change_request(VirtIOMEM *vmem, uint64_t gpa, + uint16_t nb_blocks, bool plug) +{ + const uint64_t size = nb_blocks * vmem->block_size; + int ret; + + if (!virtio_mem_valid_range(vmem, gpa, size)) { + return VIRTIO_MEM_RESP_ERROR; + } + + if (plug && (vmem->size + size > vmem->requested_size)) { + return VIRTIO_MEM_RESP_NACK; + } + + /* test if really all blocks are in the opposite state */ + if (!virtio_mem_test_bitmap(vmem, gpa, size, !plug)) { + return VIRTIO_MEM_RESP_ERROR; + } + + ret = virtio_mem_set_block_state(vmem, gpa, size, plug); + if (ret) { + return VIRTIO_MEM_RESP_BUSY; + } + if (plug) { + vmem->size += size; + } else { + vmem->size -= size; + } + return VIRTIO_MEM_RESP_ACK; +} + +static void virtio_mem_plug_request(VirtIOMEM *vmem, VirtQueueElement *elem, + struct virtio_mem_req *req) +{ + const uint64_t gpa = le64_to_cpu(req->u.plug.addr); + const uint16_t nb_blocks = le16_to_cpu(req->u.plug.nb_blocks); + uint16_t type; + + type = virtio_mem_state_change_request(vmem, gpa, nb_blocks, true); + virtio_mem_send_response_simple(vmem, elem, type); +} + +static void virtio_mem_unplug_request(VirtIOMEM *vmem, VirtQueueElement *elem, + struct virtio_mem_req *req) +{ + const uint64_t gpa = le64_to_cpu(req->u.unplug.addr); + const uint16_t nb_blocks = le16_to_cpu(req->u.unplug.nb_blocks); + uint16_t type; + + type = virtio_mem_state_change_request(vmem, gpa, nb_blocks, false); + virtio_mem_send_response_simple(vmem, elem, type); +} + +static void virtio_mem_resize_usable_region(VirtIOMEM *vmem, + uint64_t requested_size, + bool can_shrink) +{ + uint64_t newsize = MIN(memory_region_size(&vmem->memdev->mr), + requested_size + VIRTIO_MEM_USABLE_EXTENT); + + if (!requested_size) { + newsize = 0; + } + + if (newsize < vmem->usable_region_size && !can_shrink) { + return; + } + + vmem->usable_region_size = newsize; +} + +static int virtio_mem_unplug_all(VirtIOMEM *vmem) +{ + RAMBlock *rb = vmem->memdev->mr.ram_block; + int ret; + + if (virtio_mem_is_busy()) { + return -EBUSY; + } + + ret = ram_block_discard_range(rb, 0, qemu_ram_get_used_length(rb)); + if (ret) { + error_report("Unexpected error discarding RAM: %s", strerror(-ret)); + return -EBUSY; + } + bitmap_clear(vmem->bitmap, 0, vmem->bitmap_size); + vmem->size = 0; + + virtio_mem_resize_usable_region(vmem, vmem->requested_size, true); + return 0; +} + +static void virtio_mem_unplug_all_request(VirtIOMEM *vmem, + VirtQueueElement *elem) +{ + if (virtio_mem_unplug_all(vmem)) { + virtio_mem_send_response_simple(vmem, elem, VIRTIO_MEM_RESP_BUSY); + } else { + virtio_mem_send_response_simple(vmem, elem, VIRTIO_MEM_RESP_ACK); + } +} + +static void virtio_mem_state_request(VirtIOMEM *vmem, VirtQueueElement *elem, + struct virtio_mem_req *req) +{ + const uint16_t nb_blocks = le16_to_cpu(req->u.state.nb_blocks); + const uint64_t gpa = le64_to_cpu(req->u.state.addr); + const uint64_t size = nb_blocks * vmem->block_size; + struct virtio_mem_resp resp = { + .type = cpu_to_le16(VIRTIO_MEM_RESP_ACK), + }; + + if (!virtio_mem_valid_range(vmem, gpa, size)) { + virtio_mem_send_response_simple(vmem, elem, VIRTIO_MEM_RESP_ERROR); + return; + } + + if (virtio_mem_test_bitmap(vmem, gpa, size, true)) { + resp.u.state.state = cpu_to_le16(VIRTIO_MEM_STATE_PLUGGED); + } else if (virtio_mem_test_bitmap(vmem, gpa, size, false)) { + resp.u.state.state = cpu_to_le16(VIRTIO_MEM_STATE_UNPLUGGED); + } else { + resp.u.state.state = cpu_to_le16(VIRTIO_MEM_STATE_MIXED); + } + virtio_mem_send_response(vmem, elem, &resp); +} + +static void virtio_mem_handle_request(VirtIODevice *vdev, VirtQueue *vq) +{ + const int len = sizeof(struct virtio_mem_req); + VirtIOMEM *vmem = VIRTIO_MEM(vdev); + VirtQueueElement *elem; + struct virtio_mem_req req; + uint16_t type; + + while (true) { + elem = virtqueue_pop(vq, sizeof(VirtQueueElement)); + if (!elem) { + return; + } + + if (iov_to_buf(elem->out_sg, elem->out_num, 0, &req, len) < len) { + virtio_error(vdev, "virtio-mem protocol violation: invalid request" + " size: %d", len); + g_free(elem); + return; + } + + if (iov_size(elem->in_sg, elem->in_num) < + sizeof(struct virtio_mem_resp)) { + virtio_error(vdev, "virtio-mem protocol violation: not enough space" + " for response: %zu", + iov_size(elem->in_sg, elem->in_num)); + g_free(elem); + return; + } + + type = le16_to_cpu(req.type); + switch (type) { + case VIRTIO_MEM_REQ_PLUG: + virtio_mem_plug_request(vmem, elem, &req); + break; + case VIRTIO_MEM_REQ_UNPLUG: + virtio_mem_unplug_request(vmem, elem, &req); + break; + case VIRTIO_MEM_REQ_UNPLUG_ALL: + virtio_mem_unplug_all_request(vmem, elem); + break; + case VIRTIO_MEM_REQ_STATE: + virtio_mem_state_request(vmem, elem, &req); + break; + default: + virtio_error(vdev, "virtio-mem protocol violation: unknown request" + " type: %d", type); + g_free(elem); + return; + } + + g_free(elem); + } +} + +static void virtio_mem_get_config(VirtIODevice *vdev, uint8_t *config_data) +{ + VirtIOMEM *vmem = VIRTIO_MEM(vdev); + struct virtio_mem_config *config = (void *) config_data; + + config->block_size = cpu_to_le64(vmem->block_size); + config->node_id = cpu_to_le16(vmem->node); + config->requested_size = cpu_to_le64(vmem->requested_size); + config->plugged_size = cpu_to_le64(vmem->size); + config->addr = cpu_to_le64(vmem->addr); + config->region_size = cpu_to_le64(memory_region_size(&vmem->memdev->mr)); + config->usable_region_size = cpu_to_le64(vmem->usable_region_size); +} + +static uint64_t virtio_mem_get_features(VirtIODevice *vdev, uint64_t features, + Error **errp) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + + if (ms->numa_state) { +#if defined(CONFIG_ACPI) + virtio_add_feature(&features, VIRTIO_MEM_F_ACPI_PXM); +#endif + } + return features; +} + +static void virtio_mem_system_reset(void *opaque) +{ + VirtIOMEM *vmem = VIRTIO_MEM(opaque); + + /* + * During usual resets, we will unplug all memory and shrink the usable + * region size. This is, however, not possible in all scenarios. Then, + * the guest has to deal with this manually (VIRTIO_MEM_REQ_UNPLUG_ALL). + */ + virtio_mem_unplug_all(vmem); +} + +static void virtio_mem_device_realize(DeviceState *dev, Error **errp) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + int nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0; + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtIOMEM *vmem = VIRTIO_MEM(dev); + uint64_t page_size; + RAMBlock *rb; + int ret; + + if (!vmem->memdev) { + error_setg(errp, "'%s' property is not set", VIRTIO_MEM_MEMDEV_PROP); + return; + } else if (host_memory_backend_is_mapped(vmem->memdev)) { + char *path = object_get_canonical_path_component(OBJECT(vmem->memdev)); + + error_setg(errp, "'%s' property specifies a busy memdev: %s", + VIRTIO_MEM_MEMDEV_PROP, path); + g_free(path); + return; + } else if (!memory_region_is_ram(&vmem->memdev->mr) || + memory_region_is_rom(&vmem->memdev->mr) || + !vmem->memdev->mr.ram_block) { + error_setg(errp, "'%s' property specifies an unsupported memdev", + VIRTIO_MEM_MEMDEV_PROP); + return; + } + + if ((nb_numa_nodes && vmem->node >= nb_numa_nodes) || + (!nb_numa_nodes && vmem->node)) { + error_setg(errp, "'%s' property has value '%" PRIu32 "', which exceeds" + "the number of numa nodes: %d", VIRTIO_MEM_NODE_PROP, + vmem->node, nb_numa_nodes ? nb_numa_nodes : 1); + return; + } + + if (enable_mlock) { + error_setg(errp, "Incompatible with mlock"); + return; + } + + rb = vmem->memdev->mr.ram_block; + page_size = qemu_ram_pagesize(rb); + + if (vmem->block_size < page_size) { + error_setg(errp, "'%s' property has to be at least the page size (0x%" + PRIx64 ")", VIRTIO_MEM_BLOCK_SIZE_PROP, page_size); + return; + } else if (!QEMU_IS_ALIGNED(vmem->requested_size, vmem->block_size)) { + error_setg(errp, "'%s' property has to be multiples of '%s' (0x%" PRIx64 + ")", VIRTIO_MEM_REQUESTED_SIZE_PROP, + VIRTIO_MEM_BLOCK_SIZE_PROP, vmem->block_size); + return; + } else if (!QEMU_IS_ALIGNED(memory_region_size(&vmem->memdev->mr), + vmem->block_size)) { + error_setg(errp, "'%s' property memdev size has to be multiples of" + "'%s' (0x%" PRIx64 ")", VIRTIO_MEM_MEMDEV_PROP, + VIRTIO_MEM_BLOCK_SIZE_PROP, vmem->block_size); + return; + } + + if (ram_block_discard_require(true)) { + error_setg(errp, "Discarding RAM is disabled"); + return; + } + + ret = ram_block_discard_range(rb, 0, qemu_ram_get_used_length(rb)); + if (ret) { + error_setg_errno(errp, -ret, "Unexpected error discarding RAM"); + ram_block_discard_require(false); + return; + } + + virtio_mem_resize_usable_region(vmem, vmem->requested_size, true); + + vmem->bitmap_size = memory_region_size(&vmem->memdev->mr) / + vmem->block_size; + vmem->bitmap = bitmap_new(vmem->bitmap_size); + + virtio_init(vdev, TYPE_VIRTIO_MEM, VIRTIO_ID_MEM, + sizeof(struct virtio_mem_config)); + vmem->vq = virtio_add_queue(vdev, 128, virtio_mem_handle_request); + + host_memory_backend_set_mapped(vmem->memdev, true); + vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem)); + qemu_register_reset(virtio_mem_system_reset, vmem); +} + +static void virtio_mem_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtIOMEM *vmem = VIRTIO_MEM(dev); + + qemu_unregister_reset(virtio_mem_system_reset, vmem); + vmstate_unregister_ram(&vmem->memdev->mr, DEVICE(vmem)); + host_memory_backend_set_mapped(vmem->memdev, false); + virtio_del_queue(vdev, 0); + virtio_cleanup(vdev); + g_free(vmem->bitmap); + ram_block_discard_require(false); +} + +static int virtio_mem_restore_unplugged(VirtIOMEM *vmem) +{ + RAMBlock *rb = vmem->memdev->mr.ram_block; + unsigned long first_zero_bit, last_zero_bit; + uint64_t offset, length; + int ret; + + /* Find consecutive unplugged blocks and discard the consecutive range. */ + first_zero_bit = find_first_zero_bit(vmem->bitmap, vmem->bitmap_size); + while (first_zero_bit < vmem->bitmap_size) { + offset = first_zero_bit * vmem->block_size; + last_zero_bit = find_next_bit(vmem->bitmap, vmem->bitmap_size, + first_zero_bit + 1) - 1; + length = (last_zero_bit - first_zero_bit + 1) * vmem->block_size; + + ret = ram_block_discard_range(rb, offset, length); + if (ret) { + error_report("Unexpected error discarding RAM: %s", + strerror(-ret)); + return -EINVAL; + } + first_zero_bit = find_next_zero_bit(vmem->bitmap, vmem->bitmap_size, + last_zero_bit + 2); + } + return 0; +} + +static int virtio_mem_post_load(void *opaque, int version_id) +{ + if (migration_in_incoming_postcopy()) { + return 0; + } + + return virtio_mem_restore_unplugged(VIRTIO_MEM(opaque)); +} + +static const VMStateDescription vmstate_virtio_mem_device = { + .name = "virtio-mem-device", + .minimum_version_id = 1, + .version_id = 1, + .post_load = virtio_mem_post_load, + .fields = (VMStateField[]) { + VMSTATE_UINT64(usable_region_size, VirtIOMEM), + VMSTATE_UINT64(size, VirtIOMEM), + VMSTATE_UINT64(requested_size, VirtIOMEM), + VMSTATE_BITMAP(bitmap, VirtIOMEM, 0, bitmap_size), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_virtio_mem = { + .name = "virtio-mem", + .minimum_version_id = 1, + .version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_VIRTIO_DEVICE, + VMSTATE_END_OF_LIST() + }, +}; + +static void virtio_mem_fill_device_info(const VirtIOMEM *vmem, + VirtioMEMDeviceInfo *vi) +{ + vi->memaddr = vmem->addr; + vi->node = vmem->node; + vi->requested_size = vmem->requested_size; + vi->size = vmem->size; + vi->max_size = memory_region_size(&vmem->memdev->mr); + vi->block_size = vmem->block_size; + vi->memdev = object_get_canonical_path(OBJECT(vmem->memdev)); +} + +static MemoryRegion *virtio_mem_get_memory_region(VirtIOMEM *vmem, Error **errp) +{ + if (!vmem->memdev) { + error_setg(errp, "'%s' property must be set", VIRTIO_MEM_MEMDEV_PROP); + return NULL; + } + + return &vmem->memdev->mr; +} + +static void virtio_mem_get_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + const VirtIOMEM *vmem = VIRTIO_MEM(obj); + uint64_t value = vmem->size; + + visit_type_size(v, name, &value, errp); +} + +static void virtio_mem_get_requested_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + const VirtIOMEM *vmem = VIRTIO_MEM(obj); + uint64_t value = vmem->requested_size; + + visit_type_size(v, name, &value, errp); +} + +static void virtio_mem_set_requested_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + VirtIOMEM *vmem = VIRTIO_MEM(obj); + Error *err = NULL; + uint64_t value; + + visit_type_size(v, name, &value, &err); + if (err) { + error_propagate(errp, err); + return; + } + + /* + * The block size and memory backend are not fixed until the device was + * realized. realize() will verify these properties then. + */ + if (DEVICE(obj)->realized) { + if (!QEMU_IS_ALIGNED(value, vmem->block_size)) { + error_setg(errp, "'%s' has to be multiples of '%s' (0x%" PRIx64 + ")", name, VIRTIO_MEM_BLOCK_SIZE_PROP, + vmem->block_size); + return; + } else if (value > memory_region_size(&vmem->memdev->mr)) { + error_setg(errp, "'%s' cannot exceed the memory backend size" + "(0x%" PRIx64 ")", name, + memory_region_size(&vmem->memdev->mr)); + return; + } + + if (value != vmem->requested_size) { + virtio_mem_resize_usable_region(vmem, value, false); + vmem->requested_size = value; + } + /* + * Trigger a config update so the guest gets notified. We trigger + * even if the size didn't change (especially helpful for debugging). + */ + virtio_notify_config(VIRTIO_DEVICE(vmem)); + } else { + vmem->requested_size = value; + } +} + +static void virtio_mem_get_block_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + const VirtIOMEM *vmem = VIRTIO_MEM(obj); + uint64_t value = vmem->block_size; + + visit_type_size(v, name, &value, errp); +} + +static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VirtIOMEM *vmem = VIRTIO_MEM(obj); + Error *err = NULL; + uint64_t value; + + if (DEVICE(obj)->realized) { + error_setg(errp, "'%s' cannot be changed", name); + return; + } + + visit_type_size(v, name, &value, &err); + if (err) { + error_propagate(errp, err); + return; + } + + if (value < VIRTIO_MEM_MIN_BLOCK_SIZE) { + error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name, + VIRTIO_MEM_MIN_BLOCK_SIZE); + return; + } else if (!is_power_of_2(value)) { + error_setg(errp, "'%s' property has to be a power of two", name); + return; + } + vmem->block_size = value; +} + +static void virtio_mem_instance_init(Object *obj) +{ + VirtIOMEM *vmem = VIRTIO_MEM(obj); + + vmem->block_size = VIRTIO_MEM_MIN_BLOCK_SIZE; + + object_property_add(obj, VIRTIO_MEM_SIZE_PROP, "size", virtio_mem_get_size, + NULL, NULL, NULL); + object_property_add(obj, VIRTIO_MEM_REQUESTED_SIZE_PROP, "size", + virtio_mem_get_requested_size, + virtio_mem_set_requested_size, NULL, NULL); + object_property_add(obj, VIRTIO_MEM_BLOCK_SIZE_PROP, "size", + virtio_mem_get_block_size, virtio_mem_set_block_size, + NULL, NULL); +} + +static Property virtio_mem_properties[] = { + DEFINE_PROP_UINT64(VIRTIO_MEM_ADDR_PROP, VirtIOMEM, addr, 0), + DEFINE_PROP_UINT32(VIRTIO_MEM_NODE_PROP, VirtIOMEM, node, 0), + DEFINE_PROP_LINK(VIRTIO_MEM_MEMDEV_PROP, VirtIOMEM, memdev, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_mem_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VirtIOMEMClass *vmc = VIRTIO_MEM_CLASS(klass); + + device_class_set_props(dc, virtio_mem_properties); + dc->vmsd = &vmstate_virtio_mem; + + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + vdc->realize = virtio_mem_device_realize; + vdc->unrealize = virtio_mem_device_unrealize; + vdc->get_config = virtio_mem_get_config; + vdc->get_features = virtio_mem_get_features; + vdc->vmsd = &vmstate_virtio_mem_device; + + vmc->fill_device_info = virtio_mem_fill_device_info; + vmc->get_memory_region = virtio_mem_get_memory_region; +} + +static const TypeInfo virtio_mem_info = { + .name = TYPE_VIRTIO_MEM, + .parent = TYPE_VIRTIO_DEVICE, + .instance_size = sizeof(VirtIOMEM), + .instance_init = virtio_mem_instance_init, + .class_init = virtio_mem_class_init, + .class_size = sizeof(VirtIOMEMClass), +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_mem_info); +} + +type_init(virtio_register_types) diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 83122424fa..0eda25c4e1 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -47,3 +47,14 @@ config VIRTIO_PMEM depends on VIRTIO depends on VIRTIO_PMEM_SUPPORTED select MEM_DEVICE + +config VIRTIO_MEM_SUPPORTED + bool + +config VIRTIO_MEM + bool + default y + depends on VIRTIO + depends on LINUX + depends on VIRTIO_MEM_SUPPORTED + select MEM_DEVICE diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 13e75f171f..f3a65e01b7 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -19,6 +19,7 @@ obj-$(call land,$(CONFIG_VHOST_USER_FS),$(CONFIG_VIRTIO_PCI)) += vhost-user-fs-p obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-common.o vhost-vsock.o obj-$(CONFIG_VHOST_USER_VSOCK) += vhost-vsock-common.o vhost-user-vsock.o +obj-$(CONFIG_VIRTIO_MEM) += virtio-mem.o ifeq ($(CONFIG_VIRTIO_PCI),y) obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o From patchwork Fri Jul 3 09:04:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OqtRuuGT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypzr5R4mz9sPF for ; Fri, 3 Jul 2020 19:08:56 +1000 (AEST) Received: from localhost ([::1]:37010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHgk-0008P2-Eq for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:08:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcH-0007Z4-Hi for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:17 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:29868 helo=us-smtp-delivery-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 1jrHcD-0004Qm-VA for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767053; 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=0fQeQikRy8Q2V3Lt7CmPVpto3iu6bzueyFNbeNFBh7o=; b=OqtRuuGTo1RdpURLl+gc5J2FtS6UfbR8OML7z7X5x2B0LgdSl5jNivMczpaQ1TJtdUW1mT yzrF8i8AuFWXqrDz5+Ej7fOe7etZGND5A5A8YE3vYA8IlLXebRJPGXJzmx4OIR2fNp5tWL pM0waXsayZABYTZomL7txyXkwxj6gI4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-mPtG_W0hNkWSc20MU6UPPQ-1; Fri, 03 Jul 2020 05:04:11 -0400 X-MC-Unique: mPtG_W0hNkWSc20MU6UPPQ-1 Received: by mail-wm1-f71.google.com with SMTP id 65so14770578wmd.8 for ; Fri, 03 Jul 2020 02:04:11 -0700 (PDT) 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=0fQeQikRy8Q2V3Lt7CmPVpto3iu6bzueyFNbeNFBh7o=; b=hozBu6rAfUNXtqsA90EICW3QsZbHrUqrBeuYS/b0sntDht/lvVNBa+Qh40r0arls3T RI/Xp7G6LaSSEQdFnXmB50TnuTn/YFvw5EmXGChFG+7XvOhH5pyULDfyJ46D75l9AA+L nAc2ihXdEFT5WCgwKxgY6DHbmlyJ86UE/9LMQ6ueoz76mymT2igWNYZG0uX+Bkyn5YpH riy8ml9zDauIVEHSnWzx3fVEYvQQ/Golu0nQK1ksV5lz5z0HMlP4BwP8leW/z9hfpvb+ cpG8VcElzKYnVmc22lru0+YFMiRPLoBe8G7I+/Y6ZkSPudfzCFiZG6eFcS5Ncm1q/cV3 3iAw== X-Gm-Message-State: AOAM530VehuucVhoAz+ky8g4AONmZJYV+JR22y03UF8ciqYLa98c6imh I1gEtnVocFz9IWY1rvz5G7PrgHRqboQIHRB1xiQq0Kdhg3xOzmXAkVcJ00AXZu/ZlnWhzE0TBAM nJBmPXKVSH/n8he0= X-Received: by 2002:adf:dfd1:: with SMTP id q17mr33714648wrn.94.1593767050252; Fri, 03 Jul 2020 02:04:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBrAtMXwZFwIhqO+/FzLGRRIFJ9tEa0Ohl9r9GU3QrcpTXcmczn0vPjC4fs5u3grGVltYiRg== X-Received: by 2002:adf:dfd1:: with SMTP id q17mr33714630wrn.94.1593767050037; Fri, 03 Jul 2020 02:04:10 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id c25sm12464324wml.46.2020.07.03.02.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:09 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:07 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 14/41] virtio-pci: Proxy for virtio-mem Message-ID: <20200703090252.368694-15-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Pankaj Gupta , David Hildenbrand , "Dr. David Alan Gilbert" , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's add a proxy for virtio-mem, make it a memory device, and pass-through the properties. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Cc: "Dr. David Alan Gilbert" Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-12-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mem-pci.h | 33 ++++++++++ include/hw/pci/pci.h | 1 + hw/virtio/virtio-mem-pci.c | 129 +++++++++++++++++++++++++++++++++++++ hw/virtio/Makefile.objs | 1 + 4 files changed, 164 insertions(+) create mode 100644 hw/virtio/virtio-mem-pci.h create mode 100644 hw/virtio/virtio-mem-pci.c diff --git a/hw/virtio/virtio-mem-pci.h b/hw/virtio/virtio-mem-pci.h new file mode 100644 index 0000000000..8820cd6628 --- /dev/null +++ b/hw/virtio/virtio-mem-pci.h @@ -0,0 +1,33 @@ +/* + * Virtio MEM PCI device + * + * Copyright (C) 2020 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_VIRTIO_MEM_PCI_H +#define QEMU_VIRTIO_MEM_PCI_H + +#include "hw/virtio/virtio-pci.h" +#include "hw/virtio/virtio-mem.h" + +typedef struct VirtIOMEMPCI VirtIOMEMPCI; + +/* + * virtio-mem-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VIRTIO_MEM_PCI "virtio-mem-pci-base" +#define VIRTIO_MEM_PCI(obj) \ + OBJECT_CHECK(VirtIOMEMPCI, (obj), TYPE_VIRTIO_MEM_PCI) + +struct VirtIOMEMPCI { + VirtIOPCIProxy parent_obj; + VirtIOMEM vdev; +}; + +#endif /* QEMU_VIRTIO_MEM_PCI_H */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index a4e9c33416..c1bf7d5356 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -87,6 +87,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012 #define PCI_DEVICE_ID_VIRTIO_PMEM 0x1013 #define PCI_DEVICE_ID_VIRTIO_IOMMU 0x1014 +#define PCI_DEVICE_ID_VIRTIO_MEM 0x1015 #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 diff --git a/hw/virtio/virtio-mem-pci.c b/hw/virtio/virtio-mem-pci.c new file mode 100644 index 0000000000..b325303b32 --- /dev/null +++ b/hw/virtio/virtio-mem-pci.c @@ -0,0 +1,129 @@ +/* + * Virtio MEM PCI device + * + * Copyright (C) 2020 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "virtio-mem-pci.h" +#include "hw/mem/memory-device.h" +#include "qapi/error.h" + +static void virtio_mem_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VirtIOMEMPCI *mem_pci = VIRTIO_MEM_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&mem_pci->vdev); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void virtio_mem_pci_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), addr, VIRTIO_MEM_ADDR_PROP, errp); +} + +static uint64_t virtio_mem_pci_get_addr(const MemoryDeviceState *md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_ADDR_PROP, + &error_abort); +} + +static MemoryRegion *virtio_mem_pci_get_memory_region(MemoryDeviceState *md, + Error **errp) +{ + VirtIOMEMPCI *pci_mem = VIRTIO_MEM_PCI(md); + VirtIOMEM *vmem = VIRTIO_MEM(&pci_mem->vdev); + VirtIOMEMClass *vmc = VIRTIO_MEM_GET_CLASS(vmem); + + return vmc->get_memory_region(vmem, errp); +} + +static uint64_t virtio_mem_pci_get_plugged_size(const MemoryDeviceState *md, + Error **errp) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_SIZE_PROP, + errp); +} + +static void virtio_mem_pci_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + VirtioMEMDeviceInfo *vi = g_new0(VirtioMEMDeviceInfo, 1); + VirtIOMEMPCI *pci_mem = VIRTIO_MEM_PCI(md); + VirtIOMEM *vmem = VIRTIO_MEM(&pci_mem->vdev); + VirtIOMEMClass *vpc = VIRTIO_MEM_GET_CLASS(vmem); + DeviceState *dev = DEVICE(md); + + if (dev->id) { + vi->has_id = true; + vi->id = g_strdup(dev->id); + } + + /* let the real device handle everything else */ + vpc->fill_device_info(vmem, vi); + + info->u.virtio_mem.data = vi; + info->type = MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM; +} + +static void virtio_mem_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc = MEMORY_DEVICE_CLASS(klass); + + k->realize = virtio_mem_pci_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_MEM; + pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id = PCI_CLASS_OTHERS; + + mdc->get_addr = virtio_mem_pci_get_addr; + mdc->set_addr = virtio_mem_pci_set_addr; + mdc->get_plugged_size = virtio_mem_pci_get_plugged_size; + mdc->get_memory_region = virtio_mem_pci_get_memory_region; + mdc->fill_device_info = virtio_mem_pci_fill_device_info; +} + +static void virtio_mem_pci_instance_init(Object *obj) +{ + VirtIOMEMPCI *dev = VIRTIO_MEM_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_MEM); + object_property_add_alias(obj, VIRTIO_MEM_BLOCK_SIZE_PROP, + OBJECT(&dev->vdev), VIRTIO_MEM_BLOCK_SIZE_PROP); + object_property_add_alias(obj, VIRTIO_MEM_SIZE_PROP, OBJECT(&dev->vdev), + VIRTIO_MEM_SIZE_PROP); + object_property_add_alias(obj, VIRTIO_MEM_REQUESTED_SIZE_PROP, + OBJECT(&dev->vdev), + VIRTIO_MEM_REQUESTED_SIZE_PROP); +} + +static const VirtioPCIDeviceTypeInfo virtio_mem_pci_info = { + .base_name = TYPE_VIRTIO_MEM_PCI, + .generic_name = "virtio-mem-pci", + .instance_size = sizeof(VirtIOMEMPCI), + .instance_init = virtio_mem_pci_instance_init, + .class_init = virtio_mem_pci_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void virtio_mem_pci_register_types(void) +{ + virtio_pci_types_register(&virtio_mem_pci_info); +} +type_init(virtio_mem_pci_register_types) diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index f3a65e01b7..a986708186 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -20,6 +20,7 @@ obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-common.o vhost-vsock.o obj-$(CONFIG_VHOST_USER_VSOCK) += vhost-vsock-common.o vhost-user-vsock.o obj-$(CONFIG_VIRTIO_MEM) += virtio-mem.o +common-obj-$(call land,$(CONFIG_VIRTIO_MEM),$(CONFIG_VIRTIO_PCI)) += virtio-mem-pci.o ifeq ($(CONFIG_VIRTIO_PCI),y) obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o From patchwork Fri Jul 3 09:04:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322221 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=URsdPstX; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq2323gHz9sRW for ; Fri, 3 Jul 2020 19:10:51 +1000 (AEST) Received: from localhost ([::1]:45456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHia-0003b4-WF for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:10:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcK-0007gw-Oq for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:20 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:25605 helo=us-smtp-delivery-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 1jrHcI-0004R4-Fd for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767057; 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=P6r2FskKwB1C7cd0JfHkwqOjL7yF8DU7eDQFn/2WuCI=; b=URsdPstXbIRMJlecVJRPGjvhpoIdOPMfzuetcJk9VSIBZIzKoQLmWtu9fVfkp40YJbC+jJ HkGITV9QS2krJkU9vgOb+0tLPssABBBpLUZVVxe6aeHx2hrpYxHpHVaEY+Jb5oVG+LEk7O f6wvLJ3ra0rviU26/Ws8RKvmRDqHv4o= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-PejkPt9pOOqRY1bWuln9jA-1; Fri, 03 Jul 2020 05:04:14 -0400 X-MC-Unique: PejkPt9pOOqRY1bWuln9jA-1 Received: by mail-wr1-f69.google.com with SMTP id 89so7685250wrr.15 for ; Fri, 03 Jul 2020 02:04:14 -0700 (PDT) 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=P6r2FskKwB1C7cd0JfHkwqOjL7yF8DU7eDQFn/2WuCI=; b=nUVDvCr+689DdWLBda+ACuoqjuUk5UQHwL6JK4dG56K/1uK5m5Y6upwDDjlDNpdxgN 8mAylJGLYED5rAqiZh6pa1Q2wIdXG2dF9P+/Px4jOy2oxKFiWWeMS6d/p93RCM1pMLhz jjRaJny5K4XlGWgX4qm7JMtRFMJ091d8Jmwl3GfbQnIpQRn5mox15ta3KnqX+SjfRFn3 jDm+oHN3E5nmc1ikj4p7cY8FxgV8pez+ojAVQzygpAzgo539meTqr+t+MGE7kX3tPrKB 79PUuDPiWIB63/HdWrh+8ygBR64Ug/InObBZ08YPSkSGXVfzR+JFOHdwOjwEbqSBWEfK Mh1Q== X-Gm-Message-State: AOAM5309LcsaRaVZI9V42csEkOeh5rqLhqAJYQqvNhzXJOCtXEZfaUYE YLukEhlHt7hIUtKvd0dG9BVQq9av6KFnvWQ4dAYv+HB2pPuR1ljoXtf8KIWTeJ2Dfk6+2DK10Tn c6PdGqrnyEMn7cyE= X-Received: by 2002:a1c:e303:: with SMTP id a3mr34579936wmh.26.1593767053107; Fri, 03 Jul 2020 02:04:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyULuYM79VfesmYoDfTAtNW1iVtfC6NfFHPE6PFOiNAZbnmQ3dtxKI/PHw0T5AdCb2v3GOGSA== X-Received: by 2002:a1c:e303:: with SMTP id a3mr34579920wmh.26.1593767052894; Fri, 03 Jul 2020 02:04:12 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id c25sm1208719wml.18.2020.07.03.02.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:12 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:10 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 15/41] MAINTAINERS: Add myself as virtio-mem maintainer Message-ID: <20200703090252.368694-16-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.61; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:17:33 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, 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: Peter Maydell , David Hildenbrand , Alex =?utf-8?q?Benn=C3=A9e?= , "Dr . David Alan Gilbert" , Markus Armbruster , Aleksandar Markovic , Philippe =?utf-8?q?M?= =?utf-8?q?athieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's make sure patches/bug reports find the right person. Reviewed-by: Dr. David Alan Gilbert Cc: "Michael S. Tsirkin" Cc: Peter Maydell Cc: Markus Armbruster Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-13-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index dec252f38b..5f02160436 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1790,6 +1790,15 @@ F: hw/virtio/virtio-crypto.c F: hw/virtio/virtio-crypto-pci.c F: include/hw/virtio/virtio-crypto.h +virtio-mem +M: David Hildenbrand +S: Supported +W: https://virtio-mem.gitlab.io/ +F: hw/virtio/virtio-mem.c +F: hw/virtio/virtio-mem-pci.h +F: hw/virtio/virtio-mem-pci.c +F: include/hw/virtio/virtio-mem.h + nvme M: Keith Busch L: qemu-block@nongnu.org From patchwork Fri Jul 3 09:04:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aKVtC2fL; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq085Yqlz9sPF for ; Fri, 3 Jul 2020 19:09:12 +1000 (AEST) Received: from localhost ([::1]:37922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHh0-0000Mj-D9 for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:09:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcL-0007iN-CV for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:21 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:51184 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 1jrHcJ-0004RB-ID for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767058; 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=iWDsFI9FTPaIYFz+N5tNzGyrP1poUpyqulcQXZoBxbc=; b=aKVtC2fLFR9+H7iT9tWrPr6p2+xtjfavzIupeie9hjBRLQs38l1j6ybzeVqpmS+bl5uSdC rFojmbauhoLsENS12QuHzRIYemicJ3txYtN3XoDJ8Fc34yw3IUPZwI56Pagrv+2L0BGu0b Cp53qfmyCihJFBw2adfxqqLPH0aitGQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-13-3PfUPGCzN8KdeycEsYG3eQ-1; Fri, 03 Jul 2020 05:04:17 -0400 X-MC-Unique: 3PfUPGCzN8KdeycEsYG3eQ-1 Received: by mail-wm1-f72.google.com with SMTP id g138so25731787wme.7 for ; Fri, 03 Jul 2020 02:04:17 -0700 (PDT) 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=iWDsFI9FTPaIYFz+N5tNzGyrP1poUpyqulcQXZoBxbc=; b=Ud7MTEpphywaCXfAtUQ3dgioIJ8AffILcmztmLRgy0t7Y1VssPzboBEmxv0FroAzo0 ZWRqhPQs1V3WQEjyVcIhKpwUBb3hjoj0TDZVcZIn81383WfDJpOxySOH4dzKWxXyt2G3 iXwmqQFyr24Pk2Ip0NRaC+HQ+ouL/QDZDBty+HdXyoMbQqq9peBJGOiYCwQckVTUR5dy 2UVKjaW/Ruha+8f3I2eh8xBl2XrrqzelN7E2wZj6ccAYJcjyg5dS5SWo/ZlRgqNO4BPK 3yh8uuDh0DsOvL10L3A0VYzzysNPnDf+AepCnhY0scvUfXHv+tXu1mLzuF9T9einrnfh PiJQ== X-Gm-Message-State: AOAM5335dYG69bHBnKG2ifDpK9tjShQGOk1QIZUFiP0ovtMTeSyO1CRJ 2nAIYGSIE45R67fKPZOMRWUcsmXeV2/EV/1l9vh4ntSRpFntynDFRqBloSjXawmZNKv8bRHGfuK D29vql4JSBhrYFNY= X-Received: by 2002:a5d:4603:: with SMTP id t3mr38494057wrq.38.1593767055689; Fri, 03 Jul 2020 02:04:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAamEJACZ2FMMDWl3FI9MjmizxGI5ridVvi7fdJxRmdrV7hlGMJqyo/ith6avmhbV30vvjPg== X-Received: by 2002:a5d:4603:: with SMTP id t3mr38494036wrq.38.1593767055484; Fri, 03 Jul 2020 02:04:15 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id v11sm49816438wmb.3.2020.07.03.02.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:14 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:13 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 16/41] hmp: Handle virtio-mem when printing memory device info Message-ID: <20200703090252.368694-17-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , "Dr . David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Print the memory device info just like for other memory devices. Reviewed-by: Dr. David Alan Gilbert Cc: "Dr. David Alan Gilbert" Cc: "Michael S. Tsirkin" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-14-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- monitor/hmp-cmds.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 2b0b58a336..2ec13e4cc3 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1821,6 +1821,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); MemoryDeviceInfoList *info; VirtioPMEMDeviceInfo *vpi; + VirtioMEMDeviceInfo *vmi; MemoryDeviceInfo *value; PCDIMMDeviceInfo *di; @@ -1855,6 +1856,21 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); monitor_printf(mon, " memdev: %s\n", vpi->memdev); break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM: + vmi = value->u.virtio_mem.data; + monitor_printf(mon, "Memory device [%s]: \"%s\"\n", + MemoryDeviceInfoKind_str(value->type), + vmi->id ? vmi->id : ""); + monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr); + monitor_printf(mon, " node: %" PRId64 "\n", vmi->node); + monitor_printf(mon, " requested-size: %" PRIu64 "\n", + vmi->requested_size); + monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size); + monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size); + monitor_printf(mon, " block-size: %" PRIu64 "\n", + vmi->block_size); + monitor_printf(mon, " memdev: %s\n", vmi->memdev); + break; default: g_assert_not_reached(); } From patchwork Fri Jul 3 09:04:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h4R63ePP; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ypys0p8mz9sR4 for ; Fri, 3 Jul 2020 19:08:05 +1000 (AEST) Received: from localhost ([::1]:60556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHfu-0006VM-QV for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:08:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcQ-0007v0-C3 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:26 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:53535 helo=us-smtp-delivery-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 1jrHcO-0004Rc-Co for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767063; 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=R6v2kcHm1yafmRwNtVM4TnE2cecweMPkWTwUrJuLZnU=; b=h4R63ePPjbotzcZ2zskdZIssEh8I6mm71SS1g8ysQtM01apKarnny8ysgov49zq2LuEavn nus0xkiugsTKw17bpsizDMYoYwBi5qtwJNVsUdggmIz2R1tWvViiIoVogqlkzay0B5Eiwy 9/kyhZW4pZk3WIEVgFSLxKUKLETyNUg= 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-282-nzM1CqzNO1i42tSHCTEpnw-1; Fri, 03 Jul 2020 05:04:19 -0400 X-MC-Unique: nzM1CqzNO1i42tSHCTEpnw-1 Received: by mail-wr1-f71.google.com with SMTP id j16so25789364wrw.3 for ; Fri, 03 Jul 2020 02:04:19 -0700 (PDT) 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=R6v2kcHm1yafmRwNtVM4TnE2cecweMPkWTwUrJuLZnU=; b=GlUtf9qDTZ0YpElIu9iijzx6M5bFqzbl6Q5/NZhl0YO1Mi0+9JsBfvGszgyKhUosZr pkITkOW+pHkhxBMYTKuotsfvJJEGH4BqROR5MZqVzRDziINFxIS+U2kjeOtgvArnEqVS gEUNVVx0g5XCqidgI9U5LlitJTt58k29Pt7uywDsEZgTFHg2GT0iTv75Yi9TNmzSw4Z6 kShwNulTLXVRCY5/YDzBmGGTiOyx5GjR/XMyNtwChpfa+fGF3r3A5LS8oGY28eVeaj1D qvbmFDMpj1m21JUsLSuzY5yE8SGBZqSn0pM3hUtVy28LgIfb0fUeGBkumj1rUzRSnUBe xbtA== X-Gm-Message-State: AOAM530ZXcE/jWUwp4YSwNgN/kX0pjOun8je9fUuc0pn1KKI4lYVfu7i hT7/BmyK8IzrxN3Sx65JHjbGa72NDKOtbgXDb6c9y3mQGZdPvVU18nLQJqKaEwqdCRg85akiMQN sxepnaQK3Tn1KDPA= X-Received: by 2002:a1c:2842:: with SMTP id o63mr20442951wmo.169.1593767058369; Fri, 03 Jul 2020 02:04:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyX13F5rNl5wkLnQF3uIQ7bjHGzLfg2YT9BI2s8cjEPte+6QLIUVG3Wcy4GPdmrHd1g1g/kvA== X-Received: by 2002:a1c:2842:: with SMTP id o63mr20442937wmo.169.1593767058223; Fri, 03 Jul 2020 02:04:18 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id k14sm13241600wrn.76.2020.07.03.02.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:17 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:15 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 17/41] numa: Handle virtio-mem in NUMA stats Message-ID: <20200703090252.368694-18-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.61; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:17:33 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Pankaj Gupta , Eduardo Habkost , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Account the memory to the configured nid. Reviewed-by: Pankaj Gupta Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: "Michael S. Tsirkin" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-15-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/core/numa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/core/numa.c b/hw/core/numa.c index 2725886d06..e9aec69afd 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -824,6 +824,7 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[]) MemoryDeviceInfoList *info; PCDIMMDeviceInfo *pcdimm_info; VirtioPMEMDeviceInfo *vpi; + VirtioMEMDeviceInfo *vmi; for (info = info_list; info; info = info->next) { MemoryDeviceInfo *value = info->value; @@ -844,6 +845,11 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[]) node_mem[0].node_mem += vpi->size; node_mem[0].node_plugged_mem += vpi->size; break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM: + vmi = value->u.virtio_mem.data; + node_mem[vmi->node].node_mem += vmi->size; + node_mem[vmi->node].node_plugged_mem += vmi->size; + break; default: g_assert_not_reached(); } From patchwork Fri Jul 3 09:04:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bnTPkkDf; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq0k37dJz9sSJ for ; Fri, 3 Jul 2020 19:09:42 +1000 (AEST) Received: from localhost ([::1]:40744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHhU-0001hF-6q for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:09:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcR-0007xL-9R for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:27 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:51245 helo=us-smtp-delivery-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 1jrHcO-0004Rg-VC for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767064; 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=JOwCv9MKVFDSFgjABrGrn+AVAUp/DMrwQ11TkrNg4cg=; b=bnTPkkDfkwtwRhdR4z3WPw1iSYuypkf+Wng10l3I2lEOT+kOdfEeTd+y3kix5N1mXpXQDx qlyC1wxiPuLKu61IpuF3YpECDhB8D4JX/tT45XgfnWxrT5gswH/AcZ/Z4qRafqsiJ35A+I 1X/WX25AIpvD9JMKsX65o1OPOrSCMEE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-GRmi2qAvPgKs8ZVYQfG6uA-1; Fri, 03 Jul 2020 05:04:22 -0400 X-MC-Unique: GRmi2qAvPgKs8ZVYQfG6uA-1 Received: by mail-wm1-f69.google.com with SMTP id g187so34474872wme.0 for ; Fri, 03 Jul 2020 02:04:22 -0700 (PDT) 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=JOwCv9MKVFDSFgjABrGrn+AVAUp/DMrwQ11TkrNg4cg=; b=a9zRpiAmetJde+cjSg4AKbdbDBMqJHoMeFqvtmhUyohnKH1N/eEV4USM+gRWzrEy1w POca/O6rInRlQXerhqKXhk/wfnERR1DWjVAbSuBpxATlhp2qs05QHe/hXRVNdCAwPd0f 5rtDFdUEcV8V5dLVtp2RXmo96Xlk0yN7Ygc+fHUtadbBZZGRP8kk3dX2sfC6m0PxSUMV lSRdxYoS/qUoDlelLZNTIcqCC7dgmpzhAYrOzTD+zuG1wmwyQDxmfajERVNVpgmxgM/U GuEykTHY6EfvCCNMxo51Jw8gD5KB6qlVAIgvHkkZpdxFhUniNWQbftkKexlCRobhchRH uXkg== X-Gm-Message-State: AOAM532tDdYFlrK2FyyHJZjrh2h0J1Tv8uyv6GPDWhFQhgzbdSaZetXs lJiZ4yDjM9oRs1vKDUbpz6FtXbhOQjbJ14zZU+l2K19nVkVnKcx+tjubXqvwYFuwQVJcnTYUxLB gl5AZ8hwqnA0ZwSc= X-Received: by 2002:a1c:1bc4:: with SMTP id b187mr37826824wmb.105.1593767061152; Fri, 03 Jul 2020 02:04:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQCNrOeSgCuomBHLwJ+zIIFuOCU0nGTwysyqUvOJCp70aRX3M5s90EG/CfQJcxNztXtvSteg== X-Received: by 2002:a1c:1bc4:: with SMTP id b187mr37826802wmb.105.1593767060891; Fri, 03 Jul 2020 02:04:20 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id q4sm12516783wmc.1.2020.07.03.02.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:20 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:18 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 18/41] pc: Support for virtio-mem-pci Message-ID: <20200703090252.368694-19-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Eduardo Habkost , Pankaj Gupta , David Hildenbrand , Markus Armbruster , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's wire it up similar to virtio-pmem. Also disallow unplug, so it's harder for users to shoot themselves into the foot. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Eric Blake Cc: Markus Armbruster Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-16-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/pc.c | 49 ++++++++++++++++++++++++++++--------------------- hw/i386/Kconfig | 1 + 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 58b1425c17..576f2502f9 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -88,6 +88,7 @@ #include "hw/net/ne2000-isa.h" #include "standard-headers/asm-x86/bootparam.h" #include "hw/virtio/virtio-pmem-pci.h" +#include "hw/virtio/virtio-mem-pci.h" #include "hw/mem/memory-device.h" #include "sysemu/replay.h" #include "qapi/qmp/qerror.h" @@ -1637,8 +1638,8 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, numa_cpu_pre_plug(cpu_slot, dev, errp); } -static void pc_virtio_pmem_pci_pre_plug(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) +static void pc_virtio_md_pci_pre_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev); Error *local_err = NULL; @@ -1649,7 +1650,8 @@ static void pc_virtio_pmem_pci_pre_plug(HotplugHandler *hotplug_dev, * order. We should never reach this point when hotplugging on x86, * however, better add a safety net. */ - error_setg(errp, "virtio-pmem-pci hotplug not supported on this bus."); + error_setg(errp, "hotplug of virtio based memory devices not supported" + " on this bus."); return; } /* @@ -1664,8 +1666,8 @@ static void pc_virtio_pmem_pci_pre_plug(HotplugHandler *hotplug_dev, error_propagate(errp, local_err); } -static void pc_virtio_pmem_pci_plug(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) +static void pc_virtio_md_pci_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev); Error *local_err = NULL; @@ -1685,17 +1687,17 @@ static void pc_virtio_pmem_pci_plug(HotplugHandler *hotplug_dev, error_propagate(errp, local_err); } -static void pc_virtio_pmem_pci_unplug_request(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) +static void pc_virtio_md_pci_unplug_request(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { - /* We don't support virtio pmem hot unplug */ - error_setg(errp, "virtio pmem device unplug not supported."); + /* We don't support hot unplug of virtio based memory devices */ + error_setg(errp, "virtio based memory devices cannot be unplugged."); } -static void pc_virtio_pmem_pci_unplug(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) +static void pc_virtio_md_pci_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { - /* We don't support virtio pmem hot unplug */ + /* We don't support hot unplug of virtio based memory devices */ } static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, @@ -1705,8 +1707,9 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, pc_memory_pre_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_pre_plug(hotplug_dev, dev, errp); - } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { - pc_virtio_pmem_pci_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { + pc_virtio_md_pci_pre_plug(hotplug_dev, dev, errp); } } @@ -1717,8 +1720,9 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev, pc_memory_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_plug(hotplug_dev, dev, errp); - } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { - pc_virtio_pmem_pci_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { + pc_virtio_md_pci_plug(hotplug_dev, dev, errp); } } @@ -1729,8 +1733,9 @@ static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, pc_memory_unplug_request(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_unplug_request_cb(hotplug_dev, dev, errp); - } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { - pc_virtio_pmem_pci_unplug_request(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { + pc_virtio_md_pci_unplug_request(hotplug_dev, dev, errp); } else { error_setg(errp, "acpi: device unplug request for not supported device" " type: %s", object_get_typename(OBJECT(dev))); @@ -1744,8 +1749,9 @@ static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, pc_memory_unplug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_unplug_cb(hotplug_dev, dev, errp); - } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { - pc_virtio_pmem_pci_unplug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { + pc_virtio_md_pci_unplug(hotplug_dev, dev, errp); } else { error_setg(errp, "acpi: device unplug for not supported device" " type: %s", object_get_typename(OBJECT(dev))); @@ -1757,7 +1763,8 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, { if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || object_dynamic_cast(OBJECT(dev), TYPE_CPU) || - object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { return HOTPLUG_HANDLER(machine); } diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index c93f32f657..03e347b207 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -35,6 +35,7 @@ config PC select ACPI_PCI select ACPI_VMGENID select VIRTIO_PMEM_SUPPORTED + select VIRTIO_MEM_SUPPORTED config PC_PCI bool From patchwork Fri Jul 3 09:04:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AjbqJG23; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqDY4K6fz9sRW for ; Fri, 3 Jul 2020 19:19:57 +1000 (AEST) Received: from localhost ([::1]:32958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHrP-0006Ur-D8 for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:19:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHey-0005NL-VG for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:07:05 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:45569 helo=us-smtp-delivery-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 1jrHew-0004yS-Su for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:07:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767222; 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=QL569dPvFUzG3LRggM07g4Qliw+yzL9OH4YIUOzaWWE=; b=AjbqJG23+1ApWn9YbYZfPMK4L6F0mRri6FNYVslDGohvikbULkwl0AfhmfAK8YwIIl/NBJ 55LtFyJJfAmezvUX7YXmeGEDcbWvNdoXUzCXGiC7kC0ygCUb2/I9bRLkxm4tY8TKtXCZy+ DhPUBq9XaCLniKQUEsgy/tPIZxPyN10= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-315-o0aPy3O6Mj2Dia1w1iUxqQ-1; Fri, 03 Jul 2020 05:04:25 -0400 X-MC-Unique: o0aPy3O6Mj2Dia1w1iUxqQ-1 Received: by mail-wm1-f69.google.com with SMTP id s134so34552299wme.6 for ; Fri, 03 Jul 2020 02:04:25 -0700 (PDT) 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=QL569dPvFUzG3LRggM07g4Qliw+yzL9OH4YIUOzaWWE=; b=hmQZJY1B8FcSsrk2JGtbZwyja/sCDG5ldkeIOe6koVUDt13JVMHFqp4/7C0BCppdro q+SPL2iZvEU8oQw0uYH84EnlJTMmuE8rJSu2a/hRk8U0P6SUciAHHQTR4dW5KNKHDCSr DgsUfpq3WC96635wK9FEWIIrh/TQtJxV3NNa9Ic7tiWMZksdrbmIo75q63/ly1KBLra5 Qb3bKIvbOsinPiIYB7lALf/KiOZMXtTByYVKjxqgQ6FFvL4ayFT+ETuRw4cXxqivv364 aZRbveOYQIhMlrLTbFL0vce4bGBHIaDze4Aa45tE4NSmGEyto7FSVqoU6zNxtX0u8rJR ngtg== X-Gm-Message-State: AOAM533/3/DRHWoROzzc6byQFLulbwQqij2tErYsUbr5yTAEJe7ku7cg 4wAMPb74LUkRetupny4vnuvPGQYdy6gStemzr9FHuX7N1AmzGWJ/9Ep15wn2TJMRnKVOCAeEn7X yRYFdQ9fT0UhPIPU= X-Received: by 2002:a05:6000:1008:: with SMTP id a8mr36837796wrx.416.1593767063857; Fri, 03 Jul 2020 02:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxP1o7esVN4yIiQeE/fa9oq5EysEalIma9POx2y1Sykx8g4c9XWKz+RdLq6uRzqkdeGZ600vg== X-Received: by 2002:a05:6000:1008:: with SMTP id a8mr36837775wrx.416.1593767063625; Fri, 03 Jul 2020 02:04:23 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id v9sm5089346wri.3.2020.07.03.02.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:23 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:21 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 19/41] virtio-mem: Allow notifiers for size changes Message-ID: <20200703090252.368694-20-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Igor Mammedov , "Dr . David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We want to send qapi events in case the size of a virtio-mem device changes. This allows upper layers to always know how much memory is actually currently consumed via a virtio-mem device. Unfortuantely, we have to report the id of our proxy device. Let's provide an easy way for our proxy device to register, so it can send the qapi events. Piggy-backing on the notifier infrastructure (although we'll only ever have one notifier registered) seems to be an easy way. Reviewed-by: Dr. David Alan Gilbert Cc: "Michael S. Tsirkin" Cc: "Dr. David Alan Gilbert" Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-17-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-mem.h | 5 +++++ hw/virtio/virtio-mem.c | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h index 6981096f7c..b74c77cd42 100644 --- a/include/hw/virtio/virtio-mem.h +++ b/include/hw/virtio/virtio-mem.h @@ -64,6 +64,9 @@ typedef struct VirtIOMEM { /* block size and alignment */ uint64_t block_size; + + /* notifiers to notify when "size" changes */ + NotifierList size_change_notifiers; } VirtIOMEM; typedef struct VirtIOMEMClass { @@ -73,6 +76,8 @@ typedef struct VirtIOMEMClass { /* public */ void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi); MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp); + void (*add_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier); + void (*remove_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier); } VirtIOMEMClass; #endif diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index d8a0c974d3..2df33f9125 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -184,6 +184,7 @@ static int virtio_mem_state_change_request(VirtIOMEM *vmem, uint64_t gpa, } else { vmem->size -= size; } + notifier_list_notify(&vmem->size_change_notifiers, &vmem->size); return VIRTIO_MEM_RESP_ACK; } @@ -242,7 +243,10 @@ static int virtio_mem_unplug_all(VirtIOMEM *vmem) return -EBUSY; } bitmap_clear(vmem->bitmap, 0, vmem->bitmap_size); - vmem->size = 0; + if (vmem->size) { + vmem->size = 0; + notifier_list_notify(&vmem->size_change_notifiers, &vmem->size); + } virtio_mem_resize_usable_region(vmem, vmem->requested_size, true); return 0; @@ -561,6 +565,18 @@ static MemoryRegion *virtio_mem_get_memory_region(VirtIOMEM *vmem, Error **errp) return &vmem->memdev->mr; } +static void virtio_mem_add_size_change_notifier(VirtIOMEM *vmem, + Notifier *notifier) +{ + notifier_list_add(&vmem->size_change_notifiers, notifier); +} + +static void virtio_mem_remove_size_change_notifier(VirtIOMEM *vmem, + Notifier *notifier) +{ + notifier_remove(notifier); +} + static void virtio_mem_get_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { @@ -668,6 +684,7 @@ static void virtio_mem_instance_init(Object *obj) VirtIOMEM *vmem = VIRTIO_MEM(obj); vmem->block_size = VIRTIO_MEM_MIN_BLOCK_SIZE; + notifier_list_init(&vmem->size_change_notifiers); object_property_add(obj, VIRTIO_MEM_SIZE_PROP, "size", virtio_mem_get_size, NULL, NULL, NULL); @@ -705,6 +722,8 @@ static void virtio_mem_class_init(ObjectClass *klass, void *data) vmc->fill_device_info = virtio_mem_fill_device_info; vmc->get_memory_region = virtio_mem_get_memory_region; + vmc->add_size_change_notifier = virtio_mem_add_size_change_notifier; + vmc->remove_size_change_notifier = virtio_mem_remove_size_change_notifier; } static const TypeInfo virtio_mem_info = { From patchwork Fri Jul 3 09:04:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FO9Xw4sL; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq2x1YCJz9sRk for ; Fri, 3 Jul 2020 19:11:37 +1000 (AEST) Received: from localhost ([::1]:49082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHjK-0005Qd-UB for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:11:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcW-0008Bn-R1 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:24923 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 1jrHcU-0004SB-ML for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767069; 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=63AWt5cO2CoZEQSqdOKoxy7llPnRyvRbfqBM0GohP60=; b=FO9Xw4sLw0MCTTo3zUG9EkqqKWY212nN+kqR35ZqjBIV06N1lTZkPJ/d2PHbQlrcwd9uFt doXAZwFxo5237umaX8woY7QIHuI26kB/1P1f92bpMOOOHHXvrsvrnIKuqGfQ2/myczWdQC wJbC0nc2GQUr3wD3+USVrVK84r+1eCM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-393-5YEFzm62NC2JWr7uttG7KQ-1; Fri, 03 Jul 2020 05:04:28 -0400 X-MC-Unique: 5YEFzm62NC2JWr7uttG7KQ-1 Received: by mail-wr1-f69.google.com with SMTP id b8so17077919wro.19 for ; Fri, 03 Jul 2020 02:04:28 -0700 (PDT) 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=63AWt5cO2CoZEQSqdOKoxy7llPnRyvRbfqBM0GohP60=; b=kf3NWDBZPCyzsffSiAgoF3ho7mKW6M76xVsizWrQgEj6Bs595TD5FfG7HNPc3DhzEz YFXxyKPOea7c8grsEaF7EvJo3Rp2TGanf75Cf/lmS89my+zLJmuijTcr0Z4DjxfvrEW5 sjZGHUcIXZoNS+ZEa/clSagj8mEc7gDk1kbfPsS8Mzi+sqVn2OZH3/VJHkykm3y6D0T5 o48lxeBe5d6O6Q9/RoNUXFpVlxPZ7zFt1X14jrxWRXmKfvIWWDVyAKZhU6zFiAIrrFD0 rSFPx1QJye6JFvJKWP5pEwfSZ8/SQt+Kl4THjcT7tKyohzA8lFRd8Wlfkl8qxYYsc7w6 i0uA== X-Gm-Message-State: AOAM533OCYAV0Pf/fkXSc9YkSRIushUV2s7DFfw8K1s5lsnQ/D7hJ2xe GqwWag/aQa060iLiQ9Y8sPA0R9ly9RNHhQWvKNMxdMQ+u0H32BiD5ewcjIiJ1ssiRv/H8G3Htak 1RJpipUlX9agyl5A= X-Received: by 2002:adf:f10a:: with SMTP id r10mr5333507wro.406.1593767066749; Fri, 03 Jul 2020 02:04:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCM3jERWDd1pSYkgmB/OKSNIEZKvj/eqFcNPPKvJIkoyFXnCACYot/nf5FrH14yeIWRjTfMA== X-Received: by 2002:adf:f10a:: with SMTP id r10mr5333479wro.406.1593767066517; Fri, 03 Jul 2020 02:04:26 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id z8sm10849847wmg.39.2020.07.03.02.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:25 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:24 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 20/41] virtio-pci: Send qapi events when the virtio-mem size changes Message-ID: <20200703090252.368694-21-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , David Hildenbrand , Markus Armbruster , "Dr. David Alan Gilbert" , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's register the notifier and trigger the qapi event with the right device id. MEMORY_DEVICE_SIZE_CHANGE is similar to BALLOON_CHANGE, however on a memory device level. Don't unregister the notifier (we neither have finalize() nor unrealize() for VirtIOPCIProxy, so it's not that simple to do it) - both devices are expected to vanish at the same time. Cc: "Michael S. Tsirkin" Cc: Markus Armbruster Cc: "Dr. David Alan Gilbert" Cc: Eric Blake Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-18-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qapi/misc.json | 25 +++++++++++++++++++++++++ hw/virtio/virtio-mem-pci.h | 1 + hw/virtio/virtio-mem-pci.c | 28 ++++++++++++++++++++++++++++ monitor/monitor.c | 1 + 4 files changed, 55 insertions(+) diff --git a/qapi/misc.json b/qapi/misc.json index 65ca3edf32..149c925246 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1434,6 +1434,31 @@ ## { 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] } +## +# @MEMORY_DEVICE_SIZE_CHANGE: +# +# Emitted when the size of a memory device changes. Only emitted for memory +# devices that can actually change the size (e.g., virtio-mem due to guest +# action). +# +# @id: device's ID +# @size: the new size of memory that the device provides +# +# Note: this event is rate-limited. +# +# Since: 5.1 +# +# Example: +# +# <- { "event": "MEMORY_DEVICE_SIZE_CHANGE", +# "data": { "id": "vm0", "size": 1073741824}, +# "timestamp": { "seconds": 1588168529, "microseconds": 201316 } } +# +## +{ 'event': 'MEMORY_DEVICE_SIZE_CHANGE', + 'data': { '*id': 'str', 'size': 'size' } } + + ## # @MEM_UNPLUG_ERROR: # diff --git a/hw/virtio/virtio-mem-pci.h b/hw/virtio/virtio-mem-pci.h index 8820cd6628..b51a28b275 100644 --- a/hw/virtio/virtio-mem-pci.h +++ b/hw/virtio/virtio-mem-pci.h @@ -28,6 +28,7 @@ typedef struct VirtIOMEMPCI VirtIOMEMPCI; struct VirtIOMEMPCI { VirtIOPCIProxy parent_obj; VirtIOMEM vdev; + Notifier size_change_notifier; }; #endif /* QEMU_VIRTIO_MEM_PCI_H */ diff --git a/hw/virtio/virtio-mem-pci.c b/hw/virtio/virtio-mem-pci.c index b325303b32..1a8e854123 100644 --- a/hw/virtio/virtio-mem-pci.c +++ b/hw/virtio/virtio-mem-pci.c @@ -14,6 +14,7 @@ #include "virtio-mem-pci.h" #include "hw/mem/memory-device.h" #include "qapi/error.h" +#include "qapi/qapi-events-misc.h" static void virtio_mem_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) { @@ -74,6 +75,21 @@ static void virtio_mem_pci_fill_device_info(const MemoryDeviceState *md, info->type = MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM; } +static void virtio_mem_pci_size_change_notify(Notifier *notifier, void *data) +{ + VirtIOMEMPCI *pci_mem = container_of(notifier, VirtIOMEMPCI, + size_change_notifier); + DeviceState *dev = DEVICE(pci_mem); + const uint64_t * const size_p = data; + const char *id = NULL; + + if (dev->id) { + id = g_strdup(dev->id); + } + + qapi_event_send_memory_device_size_change(!!id, id, *size_p); +} + static void virtio_mem_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -98,9 +114,21 @@ static void virtio_mem_pci_class_init(ObjectClass *klass, void *data) static void virtio_mem_pci_instance_init(Object *obj) { VirtIOMEMPCI *dev = VIRTIO_MEM_PCI(obj); + VirtIOMEMClass *vmc; + VirtIOMEM *vmem; virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_MEM); + + dev->size_change_notifier.notify = virtio_mem_pci_size_change_notify; + vmem = VIRTIO_MEM(&dev->vdev); + vmc = VIRTIO_MEM_GET_CLASS(vmem); + /* + * We never remove the notifier again, as we expect both devices to + * disappear at the same time. + */ + vmc->add_size_change_notifier(vmem, &dev->size_change_notifier); + object_property_add_alias(obj, VIRTIO_MEM_BLOCK_SIZE_PROP, OBJECT(&dev->vdev), VIRTIO_MEM_BLOCK_SIZE_PROP); object_property_add_alias(obj, VIRTIO_MEM_SIZE_PROP, OBJECT(&dev->vdev), diff --git a/monitor/monitor.c b/monitor/monitor.c index 125494410a..19dcb8fbe3 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -235,6 +235,7 @@ static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = { [QAPI_EVENT_QUORUM_REPORT_BAD] = { 1000 * SCALE_MS }, [QAPI_EVENT_QUORUM_FAILURE] = { 1000 * SCALE_MS }, [QAPI_EVENT_VSERPORT_CHANGE] = { 1000 * SCALE_MS }, + [QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE] = { 1000 * SCALE_MS }, }; /* From patchwork Fri Jul 3 09:04:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D8eAk4Te; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq4M2xd2z9sPF for ; Fri, 3 Jul 2020 19:12:51 +1000 (AEST) Received: from localhost ([::1]:54768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHkX-0007mJ-3w for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:12:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcY-0008Hc-UC for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59455 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 1jrHcW-0004SS-UA for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767072; 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=uSInzZZOVtvDs03ohDRy+d+1DDBJCJjbf1omcuqWWj8=; b=D8eAk4TeNPouVDVz/rxAzZoZIrwRuDmnUAaFQaxoS6QqFaBEPPUZ4/ecsG6cmOhPswu9e+ kvtRAfjBTMPbSFCyjFL1yUMdvXA46t/DvP+3sjTjFmbA3GpPxKvlAGrutvuB48wVRTmw1x aTrpFhsGl6+5OsrvaivW+/G7x0veKrw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-hI7QqC82Mx-LB-VTY_YCFg-1; Fri, 03 Jul 2020 05:04:30 -0400 X-MC-Unique: hI7QqC82Mx-LB-VTY_YCFg-1 Received: by mail-wm1-f72.google.com with SMTP id h25so20587980wmb.0 for ; Fri, 03 Jul 2020 02:04:30 -0700 (PDT) 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=uSInzZZOVtvDs03ohDRy+d+1DDBJCJjbf1omcuqWWj8=; b=JHavszoQOMzbUEsAY64iCsPzniBDgBugnvofFxM3tZ3JjpwccCWekaEd7A94VgbyeS mblnCItFiJD+kdC43AX5tr5O/fMd8F+Gfh4KFgHKJdHVOIVsEuyi1FPEiALzq1oESPIf 3LA4sR9u5P7FFMJE+x44x9qtwYsdvCCaYGCFPqZgDIj0orSpQRjhYyG6HDbnnMUvVEPp pjbhNOQGE5iqsabbuuUpS8JpubDjMLi1BgN3d9AawNYi35euzjBdIFPcm9N5yai3y8f8 sb1pDjsJZjbXTnJd/sVgqNpaHdwHNq4zyHm8g+8U9nill7eo6Oej2eUMRJN7vh2T/Ydz Ifjw== X-Gm-Message-State: AOAM530+rvGyH8YtX9ZUd2wxi7HdWyjiiR3SeJnq5dIVVCv8syZW6yIv aOsZYmKgRFYhQXD+qfQnV+zmTfkoEgVMdG28ROLYpNqH3uVAcGpvQ+yTH7odd5eAPNAb4PcwPX5 693YUFySPqNSgvnE= X-Received: by 2002:a5d:4ecc:: with SMTP id s12mr35256296wrv.57.1593767069100; Fri, 03 Jul 2020 02:04:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzH+oBuJjnQ6hLs899IiE80qK4i6kqsBvEONniO47iru7HYAFBSPpe4d1W2DdeB7iG/VHEhrg== X-Received: by 2002:a5d:4ecc:: with SMTP id s12mr35256278wrv.57.1593767068874; Fri, 03 Jul 2020 02:04:28 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id x124sm8139956wmx.16.2020.07.03.02.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:28 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:26 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 21/41] virtio-mem: Migration sanity checks Message-ID: <20200703090252.368694-22-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , "Dr . David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We want to make sure that certain properties don't change during migration, especially to catch user errors in a nice way. Let's migrate a temporary structure and validate that the properties didn't change. Reviewed-by: Dr. David Alan Gilbert Cc: "Michael S. Tsirkin" Cc: "Dr. David Alan Gilbert" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-19-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mem.c | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 2df33f9125..6ed5409669 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -519,12 +519,82 @@ static int virtio_mem_post_load(void *opaque, int version_id) return virtio_mem_restore_unplugged(VIRTIO_MEM(opaque)); } +typedef struct VirtIOMEMMigSanityChecks { + VirtIOMEM *parent; + uint64_t addr; + uint64_t region_size; + uint64_t block_size; + uint32_t node; +} VirtIOMEMMigSanityChecks; + +static int virtio_mem_mig_sanity_checks_pre_save(void *opaque) +{ + VirtIOMEMMigSanityChecks *tmp = opaque; + VirtIOMEM *vmem = tmp->parent; + + tmp->addr = vmem->addr; + tmp->region_size = memory_region_size(&vmem->memdev->mr); + tmp->block_size = vmem->block_size; + tmp->node = vmem->node; + return 0; +} + +static int virtio_mem_mig_sanity_checks_post_load(void *opaque, int version_id) +{ + VirtIOMEMMigSanityChecks *tmp = opaque; + VirtIOMEM *vmem = tmp->parent; + const uint64_t new_region_size = memory_region_size(&vmem->memdev->mr); + + if (tmp->addr != vmem->addr) { + error_report("Property '%s' changed from 0x%" PRIx64 " to 0x%" PRIx64, + VIRTIO_MEM_ADDR_PROP, tmp->addr, vmem->addr); + return -EINVAL; + } + /* + * Note: Preparation for resizeable memory regions. The maximum size + * of the memory region must not change during migration. + */ + if (tmp->region_size != new_region_size) { + error_report("Property '%s' size changed from 0x%" PRIx64 " to 0x%" + PRIx64, VIRTIO_MEM_MEMDEV_PROP, tmp->region_size, + new_region_size); + return -EINVAL; + } + if (tmp->block_size != vmem->block_size) { + error_report("Property '%s' changed from 0x%" PRIx64 " to 0x%" PRIx64, + VIRTIO_MEM_BLOCK_SIZE_PROP, tmp->block_size, + vmem->block_size); + return -EINVAL; + } + if (tmp->node != vmem->node) { + error_report("Property '%s' changed from %" PRIu32 " to %" PRIu32, + VIRTIO_MEM_NODE_PROP, tmp->node, vmem->node); + return -EINVAL; + } + return 0; +} + +static const VMStateDescription vmstate_virtio_mem_sanity_checks = { + .name = "virtio-mem-device/sanity-checks", + .pre_save = virtio_mem_mig_sanity_checks_pre_save, + .post_load = virtio_mem_mig_sanity_checks_post_load, + .fields = (VMStateField[]) { + VMSTATE_UINT64(addr, VirtIOMEMMigSanityChecks), + VMSTATE_UINT64(region_size, VirtIOMEMMigSanityChecks), + VMSTATE_UINT64(block_size, VirtIOMEMMigSanityChecks), + VMSTATE_UINT32(node, VirtIOMEMMigSanityChecks), + VMSTATE_END_OF_LIST(), + }, +}; + static const VMStateDescription vmstate_virtio_mem_device = { .name = "virtio-mem-device", .minimum_version_id = 1, .version_id = 1, .post_load = virtio_mem_post_load, .fields = (VMStateField[]) { + VMSTATE_WITH_TMP(VirtIOMEM, VirtIOMEMMigSanityChecks, + vmstate_virtio_mem_sanity_checks), VMSTATE_UINT64(usable_region_size, VirtIOMEM), VMSTATE_UINT64(size, VirtIOMEM), VMSTATE_UINT64(requested_size, VirtIOMEM), From patchwork Fri Jul 3 09:04:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KixL9Ry/; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq6S3PW4z9sPF for ; Fri, 3 Jul 2020 19:14:40 +1000 (AEST) Received: from localhost ([::1]:34968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHmI-0003Ha-6e for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:14:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcb-0008MO-Iv for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:26760 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 1jrHcZ-0004Ty-Iv for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767074; 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=zKfOMeb80edcLFenYqj0ugS/WcCDRNzf8rPuIVf+r7A=; b=KixL9Ry/e3Z1Roi07rrLqiPHid40S5HEUBRSoSPmz04eDnvjOAH4eL6mmJc/lvIc64w+t7 OpGJStunmXlGABCZgLLfJqtErYkYHFAwJ794k37lFgQYrjCrs+eyWhA0SOhjWN1xYV/0Bt GDYhQBs3FNfocr/MIvxYoK6nd7t8LR0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-268-5ttbS1-mNoy-3ByITTVypA-1; Fri, 03 Jul 2020 05:04:33 -0400 X-MC-Unique: 5ttbS1-mNoy-3ByITTVypA-1 Received: by mail-wr1-f72.google.com with SMTP id b8so17078036wro.19 for ; Fri, 03 Jul 2020 02:04:32 -0700 (PDT) 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=zKfOMeb80edcLFenYqj0ugS/WcCDRNzf8rPuIVf+r7A=; b=Rydwiw/06l0IaJKOOuTK0YbWIVD1j6Lt9158fL011J+HRe7pma1L7oslviDko41mRP uBUhPPnfEDXuGiB3DzSOObizUm26GCwnEmZZKKOb9wqEVIq6Cg7Mu5YD1KcomzGeeEWQ 7sraGLjQtlQ9P88pbX4UkQMIMOabHATA8CLdRJWYdRgJfo6iUn0tJbZK3X7WUbSa3YEl lEDbr6JEWpoKlvrZSTreEHcO4Vo2Gmbl5PQVH9xPDsu57q4AY9qF844d2ZS5Hdv4X/fn DED0EEbqTWE+a3UUXYfBGZ0d8MSge3afNnF9o40yyW4ZLGxITOnxqsmFbmJCpBFndt4M KVBg== X-Gm-Message-State: AOAM531Nk2ZhpIiRrrYvasfvN5iDYAN3Jhy0LUwkrSL7Vfty4AMUSIyV Z2yJ5poCH5YMRmSXrFSHig6aP7uPHcEWVFr8CQYwFyMg4PxPFFisqMTPCXE5LFByKvCDwSWtvvw 8xR+8l4bWeo6xCf0= X-Received: by 2002:a1c:2842:: with SMTP id o63mr20443804wmo.169.1593767071569; Fri, 03 Jul 2020 02:04:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzloWGEE4QTiyiBS6m7hTJJ+iumHhz4F90o9MEyRgcBgspemvVJD3D4UJrzq1galFpln8iL7Q== X-Received: by 2002:a1c:2842:: with SMTP id o63mr20443789wmo.169.1593767071392; Fri, 03 Jul 2020 02:04:31 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id w17sm14404130wra.42.2020.07.03.02.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:30 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:29 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 22/41] virtio-mem: Add trace events Message-ID: <20200703090252.368694-23-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , "Dr. David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's add some trace events that might come in handy later. Cc: "Michael S. Tsirkin" Cc: "Dr. David Alan Gilbert" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-20-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mem.c | 10 +++++++++- hw/virtio/trace-events | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 6ed5409669..fdd4dbb42c 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -30,6 +30,7 @@ #include "hw/boards.h" #include "hw/qdev-properties.h" #include "config-devices.h" +#include "trace.h" /* * Use QEMU_VMALLOC_ALIGN, so no THP will have to be split when unplugging @@ -100,6 +101,7 @@ static void virtio_mem_send_response(VirtIOMEM *vmem, VirtQueueElement *elem, VirtIODevice *vdev = VIRTIO_DEVICE(vmem); VirtQueue *vq = vmem->vq; + trace_virtio_mem_send_response(le16_to_cpu(resp->type)); iov_from_buf(elem->in_sg, elem->in_num, 0, resp, sizeof(*resp)); virtqueue_push(vq, elem, sizeof(*resp)); @@ -195,6 +197,7 @@ static void virtio_mem_plug_request(VirtIOMEM *vmem, VirtQueueElement *elem, const uint16_t nb_blocks = le16_to_cpu(req->u.plug.nb_blocks); uint16_t type; + trace_virtio_mem_plug_request(gpa, nb_blocks); type = virtio_mem_state_change_request(vmem, gpa, nb_blocks, true); virtio_mem_send_response_simple(vmem, elem, type); } @@ -206,6 +209,7 @@ static void virtio_mem_unplug_request(VirtIOMEM *vmem, VirtQueueElement *elem, const uint16_t nb_blocks = le16_to_cpu(req->u.unplug.nb_blocks); uint16_t type; + trace_virtio_mem_unplug_request(gpa, nb_blocks); type = virtio_mem_state_change_request(vmem, gpa, nb_blocks, false); virtio_mem_send_response_simple(vmem, elem, type); } @@ -225,6 +229,7 @@ static void virtio_mem_resize_usable_region(VirtIOMEM *vmem, return; } + trace_virtio_mem_resized_usable_region(vmem->usable_region_size, newsize); vmem->usable_region_size = newsize; } @@ -247,7 +252,7 @@ static int virtio_mem_unplug_all(VirtIOMEM *vmem) vmem->size = 0; notifier_list_notify(&vmem->size_change_notifiers, &vmem->size); } - + trace_virtio_mem_unplugged_all(); virtio_mem_resize_usable_region(vmem, vmem->requested_size, true); return 0; } @@ -255,6 +260,7 @@ static int virtio_mem_unplug_all(VirtIOMEM *vmem) static void virtio_mem_unplug_all_request(VirtIOMEM *vmem, VirtQueueElement *elem) { + trace_virtio_mem_unplug_all_request(); if (virtio_mem_unplug_all(vmem)) { virtio_mem_send_response_simple(vmem, elem, VIRTIO_MEM_RESP_BUSY); } else { @@ -272,6 +278,7 @@ static void virtio_mem_state_request(VirtIOMEM *vmem, VirtQueueElement *elem, .type = cpu_to_le16(VIRTIO_MEM_RESP_ACK), }; + trace_virtio_mem_state_request(gpa, nb_blocks); if (!virtio_mem_valid_range(vmem, gpa, size)) { virtio_mem_send_response_simple(vmem, elem, VIRTIO_MEM_RESP_ERROR); return; @@ -284,6 +291,7 @@ static void virtio_mem_state_request(VirtIOMEM *vmem, VirtQueueElement *elem, } else { resp.u.state.state = cpu_to_le16(VIRTIO_MEM_STATE_MIXED); } + trace_virtio_mem_state_response(le16_to_cpu(resp.u.state.state)); virtio_mem_send_response(vmem, elem, &resp); } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 6427a0047d..292fc15e29 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -74,3 +74,13 @@ virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d" virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d" virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uint64_t addr) "FAULT reason=%d flags=%d endpoint=%d address =0x%"PRIx64 + +# virtio-mem.c +virtio_mem_send_response(uint16_t type) "type=%" PRIu16 +virtio_mem_plug_request(uint64_t addr, uint16_t nb_blocks) "addr=0x%" PRIx64 " nb_blocks=%" PRIu16 +virtio_mem_unplug_request(uint64_t addr, uint16_t nb_blocks) "addr=0x%" PRIx64 " nb_blocks=%" PRIu16 +virtio_mem_unplugged_all(void) "" +virtio_mem_unplug_all_request(void) "" +virtio_mem_resized_usable_region(uint64_t old_size, uint64_t new_size) "old_size=0x%" PRIx64 "new_size=0x%" PRIx64 +virtio_mem_state_request(uint64_t addr, uint16_t nb_blocks) "addr=0x%" PRIx64 " nb_blocks=%" PRIu16 +virtio_mem_state_response(uint16_t state) "state=%" PRIu16 From patchwork Fri Jul 3 09:04:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FZsRj5BQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq4D53TBz9sPF for ; Fri, 3 Jul 2020 19:12:43 +1000 (AEST) Received: from localhost ([::1]:53788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHkN-0007Ln-IF for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:12:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHce-0008ST-CB for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:40 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:43460 helo=us-smtp-delivery-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 1jrHcc-0004UC-1t for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767077; 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=hGpCgrRFdoVzKCBas1IVjEPttxJKy83HIMW4QM2zJOM=; b=FZsRj5BQcKS+0IMXXTL6+DRrv/4y5G2i4tzchMoGqZa0Oef01nbr1oiIotSwAqn90jMLqN NuGmAMdxgDJbfqqAZZbfPMW79+p97qsElx+jelQAPD4WT8rixrJ0cOQCshZ7oXSZVIOZF0 nItdqem1YHKHbp692gyd0GTBwgHDrTE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-62-sOrxS6zOMgKKptljnin_8w-1; Fri, 03 Jul 2020 05:04:35 -0400 X-MC-Unique: sOrxS6zOMgKKptljnin_8w-1 Received: by mail-wm1-f70.google.com with SMTP id g124so34477477wmg.6 for ; Fri, 03 Jul 2020 02:04:35 -0700 (PDT) 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=hGpCgrRFdoVzKCBas1IVjEPttxJKy83HIMW4QM2zJOM=; b=pNUruMgfLYsQMmtswuvFUjR4l1rUOMbddjyyzh3HLrRktpiMIYp7edeH0+O9WzihDF d92gAoichcpKfb+RtG6rNPQYGStF18HTaEKvmSku6n1jAduMHsoW0t8aN4rGnv1XK2um Z3yJc1LAiuO0spnz700rCu/I4p+u6ZOvYWj6b7mVi54kGJWW9nnvg7vAZ9XxoziD7cz0 ySzVANDnt0M75aXG0tPsd9JcEHMib5PTBM04qsDEiU9F1Zw75SwtS/u+DtelTBXrUKIC YeXaYGuIy4GNY0MeLZM0DBe0HyrRL7dhmocmSDWrMxX/5jgCfpZoG1tItW2zZtj8RCWh pEAw== X-Gm-Message-State: AOAM533ilEk0zlQy6Ee9YcfwQLnIJipyUr5XGwescxAz/jsLNlQa+eIt mIUaeuvBTKRKaXcmT7A6nZ1HAYUk/pZS/KyCarSrQ+dpG0FCJPDR58tFBgP2KAFzddaDV1LCFJW a/xrflOwn/bbRLb4= X-Received: by 2002:adf:9524:: with SMTP id 33mr34231402wrs.156.1593767074016; Fri, 03 Jul 2020 02:04:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZab7vJPZc4fhDrSidyEQBsca/ETtBbyzZ2EVhu9i6l86qLJuIs+gPmFIRfZGeYkAxp1PXUA== X-Received: by 2002:adf:9524:: with SMTP id 33mr34231387wrs.156.1593767073813; Fri, 03 Jul 2020 02:04:33 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id d10sm13687828wrx.66.2020.07.03.02.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:33 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:31 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 23/41] virtio-mem: Exclude unplugged memory during migration Message-ID: <20200703090252.368694-24-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.61; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:17:33 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , "Dr. David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand The content of unplugged memory is undefined and should not be migrated, ever. Exclude all unplugged memory during precopy using the precopy notifier infrastructure introduced for free page hinting in virtio-balloon. Unplugged memory is marked as "not dirty", meaning it won't be considered for migration. Cc: "Michael S. Tsirkin" Cc: "Dr. David Alan Gilbert" Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-21-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-mem.h | 3 ++ hw/virtio/virtio-mem.c | 54 +++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h index b74c77cd42..0778224964 100644 --- a/include/hw/virtio/virtio-mem.h +++ b/include/hw/virtio/virtio-mem.h @@ -67,6 +67,9 @@ typedef struct VirtIOMEM { /* notifiers to notify when "size" changes */ NotifierList size_change_notifiers; + + /* don't migrate unplugged memory */ + NotifierWithReturn precopy_notifier; } VirtIOMEM; typedef struct VirtIOMEMClass { diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index fdd4dbb42c..bf9b414522 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -62,8 +62,14 @@ static bool virtio_mem_is_busy(void) /* * Postcopy cannot handle concurrent discards and we don't want to migrate * pages on-demand with stale content when plugging new blocks. + * + * For precopy, we don't want unplugged blocks in our migration stream, and + * when plugging new blocks, the page content might differ between source + * and destination (observable by the guest when not initializing pages + * after plugging them) until we're running on the destination (as we didn't + * migrate these blocks when they were unplugged). */ - return migration_in_incoming_postcopy(); + return migration_in_incoming_postcopy() || !migration_is_idle(); } static bool virtio_mem_test_bitmap(VirtIOMEM *vmem, uint64_t start_gpa, @@ -475,6 +481,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp) host_memory_backend_set_mapped(vmem->memdev, true); vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem)); qemu_register_reset(virtio_mem_system_reset, vmem); + precopy_add_notifier(&vmem->precopy_notifier); } static void virtio_mem_device_unrealize(DeviceState *dev) @@ -482,6 +489,7 @@ static void virtio_mem_device_unrealize(DeviceState *dev) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOMEM *vmem = VIRTIO_MEM(dev); + precopy_remove_notifier(&vmem->precopy_notifier); qemu_unregister_reset(virtio_mem_system_reset, vmem); vmstate_unregister_ram(&vmem->memdev->mr, DEVICE(vmem)); host_memory_backend_set_mapped(vmem->memdev, false); @@ -757,12 +765,56 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, vmem->block_size = value; } +static void virtio_mem_precopy_exclude_unplugged(VirtIOMEM *vmem) +{ + void * const host = qemu_ram_get_host_addr(vmem->memdev->mr.ram_block); + unsigned long first_zero_bit, last_zero_bit; + uint64_t offset, length; + + /* + * Find consecutive unplugged blocks and exclude them from migration. + * + * Note: Blocks cannot get (un)plugged during precopy, no locking needed. + */ + first_zero_bit = find_first_zero_bit(vmem->bitmap, vmem->bitmap_size); + while (first_zero_bit < vmem->bitmap_size) { + offset = first_zero_bit * vmem->block_size; + last_zero_bit = find_next_bit(vmem->bitmap, vmem->bitmap_size, + first_zero_bit + 1) - 1; + length = (last_zero_bit - first_zero_bit + 1) * vmem->block_size; + + qemu_guest_free_page_hint(host + offset, length); + first_zero_bit = find_next_zero_bit(vmem->bitmap, vmem->bitmap_size, + last_zero_bit + 2); + } +} + +static int virtio_mem_precopy_notify(NotifierWithReturn *n, void *data) +{ + VirtIOMEM *vmem = container_of(n, VirtIOMEM, precopy_notifier); + PrecopyNotifyData *pnd = data; + + switch (pnd->reason) { + case PRECOPY_NOTIFY_SETUP: + precopy_enable_free_page_optimization(); + break; + case PRECOPY_NOTIFY_AFTER_BITMAP_SYNC: + virtio_mem_precopy_exclude_unplugged(vmem); + break; + default: + break; + } + + return 0; +} + static void virtio_mem_instance_init(Object *obj) { VirtIOMEM *vmem = VIRTIO_MEM(obj); vmem->block_size = VIRTIO_MEM_MIN_BLOCK_SIZE; notifier_list_init(&vmem->size_change_notifiers); + vmem->precopy_notifier.notify = virtio_mem_precopy_notify; object_property_add(obj, VIRTIO_MEM_SIZE_PROP, "size", virtio_mem_get_size, NULL, NULL, NULL); From patchwork Fri Jul 3 09:04:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SmE1Smjs; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq576yGNz9sSJ for ; Fri, 3 Jul 2020 19:13:31 +1000 (AEST) Received: from localhost ([::1]:57428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHlB-0000VQ-Lt for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:13:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcl-0000JD-Pw for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:47 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:60459 helo=us-smtp-delivery-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 1jrHcf-0004Ua-9E for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767080; 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=c5tdu84EsYu030A7xZkXJlQoGtXOTX2WueiDbJOGS4I=; b=SmE1SmjsnXvnPl57zYZ9nLcQ4wz92yua/XOnRmrIw9ldHgi5+HPXgholBBeHVCwP8X51lF 1W2F+QghFiuaKsQjvgMIY0Kwlya/GbQW3gpXyWxB7g3g/M6oANllUOMBp0LYAbmMlywEN7 Y8N2xaYw4GiPwgXcErzhk8BvFa//eBo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-n_kCMByxNQOWK_FmE4bvlg-1; Fri, 03 Jul 2020 05:04:38 -0400 X-MC-Unique: n_kCMByxNQOWK_FmE4bvlg-1 Received: by mail-wr1-f69.google.com with SMTP id 89so7685723wrr.15 for ; Fri, 03 Jul 2020 02:04:38 -0700 (PDT) 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=c5tdu84EsYu030A7xZkXJlQoGtXOTX2WueiDbJOGS4I=; b=UiHPRMfHYyNi10XrjcTTDoW3pfbfJOArm7s06kS3lkmiyXcaYsN0MVM8le21WiAss8 NzTtkN2YfVhsZ/FYm9mUE/BjUTdSLYcZrg0y2yuqekTuP/fcF2njzqb7k3AKWkcwovfn UGk2BUC3k953OgPasCPkJ4d97iRLO/yiqa85x9NFhuDJZy1uMV49ajYeclStPG5BV3oY nLmTk3G4cQgUshcG9ZRY6UNg86mvf6+VDpyKU3S1WtHhXWLqL1WZzmKX9x295VxgwwoR embESfO/3C1DNVdSH57unVDHoDVEzsdpgf4Sm99Quny4MnHEPoTRfPH4YfJYAqTvVcfO KlZw== X-Gm-Message-State: AOAM532lY4mCcHaZVgY+s73O028nNRtQ0CSez4X08d+p3TToc6KhG3ws DX9AIBrqxDNob5pj4vHCDEam1RInDiYG0x+FZ23BEksVsiJTDSn79cKiXySKPMHpLtRihbZy73T 9Zxk5BCYTgC2KLw4= X-Received: by 2002:a1c:b182:: with SMTP id a124mr33866091wmf.114.1593767077142; Fri, 03 Jul 2020 02:04:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVOY4TvhikLMVstjU3wXl+ftQ+Rs9F/kNmVJrga8v+b2EPC/UoLYQ6F5T/cQ+W7boy9mqzgg== X-Received: by 2002:a1c:b182:: with SMTP id a124mr33866071wmf.114.1593767076894; Fri, 03 Jul 2020 02:04:36 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id f12sm13711084wrw.53.2020.07.03.02.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:36 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:34 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 24/41] numa: Auto-enable NUMA when any memory devices are possible Message-ID: <20200703090252.368694-25-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Eduardo Habkost , Sergio Lopez , David Hildenbrand , "qemu-arm @ nongnu . org" , Igor Mammedov , Paolo Bonzini , Alex Shi , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's auto-enable it also when maxmem is specified but no slots are defined. This will result in us properly creating ACPI srat tables, indicating the maximum possible PFN to the guest OS. Based on this, e.g., Linux will enable the swiotlb properly. This avoids having to manually force the switolb on (swiotlb=force) in Linux in case we're booting only using DMA memory (e.g., 2GB on x86-64), and virtio-mem adds memory later on that really needs the swiotlb to be used for DMA. Let's take care of backwards compatibility if somebody has a setup that specifies "maxram" without "slots". Reported-by: Alex Shi Cc: Peter Maydell Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Sergio Lopez Cc: Paolo Bonzini Cc: Richard Henderson Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: qemu-arm@nongnu.org Signed-off-by: David Hildenbrand Message-Id: <20200626072248.78761-22-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/boards.h | 1 + hw/arm/virt.c | 2 ++ hw/core/numa.c | 11 ++++++----- hw/i386/microvm.c | 1 + hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + 7 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 18815d9be2..426ce5f625 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -207,6 +207,7 @@ struct MachineClass { const char **valid_cpu_types; strList *allowed_dynamic_sysbus_devices; bool auto_enable_numa_with_memhp; + bool auto_enable_numa_with_memdev; void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes, int nb_nodes, ram_addr_t size); bool ignore_boot_device_suffixes; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index cd0834ce7f..f97be80a86 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2373,6 +2373,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->unplug = virt_machine_device_unplug_cb; mc->nvdimm_supported = true; mc->auto_enable_numa_with_memhp = true; + mc->auto_enable_numa_with_memdev = true; mc->default_ram_id = "mach-virt.ram"; object_class_property_add(oc, "acpi", "OnOffAuto", @@ -2485,6 +2486,7 @@ static void virt_machine_5_0_options(MachineClass *mc) virt_machine_5_1_options(mc); compat_props_add(mc->compat_props, hw_compat_5_0, hw_compat_5_0_len); mc->numa_mem_supported = true; + mc->auto_enable_numa_with_memdev = false; } DEFINE_VIRT_MACHINE(5, 0) diff --git a/hw/core/numa.c b/hw/core/numa.c index e9aec69afd..6a20ce7cf1 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -688,8 +688,9 @@ void numa_complete_configuration(MachineState *ms) NodeInfo *numa_info = ms->numa_state->nodes; /* - * If memory hotplug is enabled (slots > 0) but without '-numa' - * options explicitly on CLI, guestes will break. + * If memory hotplug is enabled (slot > 0) or memory devices are enabled + * (ms->maxram_size > ram_size) but without '-numa' options explicitly on + * CLI, guests will break. * * Windows: won't enable memory hotplug without SRAT table at all * @@ -704,9 +705,9 @@ void numa_complete_configuration(MachineState *ms) * assume there is just one node with whole RAM. */ if (ms->numa_state->num_nodes == 0 && - ((ms->ram_slots > 0 && - mc->auto_enable_numa_with_memhp) || - mc->auto_enable_numa)) { + ((ms->ram_slots && mc->auto_enable_numa_with_memhp) || + (ms->maxram_size > ms->ram_size && mc->auto_enable_numa_with_memdev) || + mc->auto_enable_numa)) { NumaNodeOptions node = { }; parse_numa_node(ms, &node, &error_abort); numa_info[0].node_mem = ram_size; diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 5e931975a0..81d0888930 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -464,6 +464,7 @@ static void microvm_class_init(ObjectClass *oc, void *data) mc->max_cpus = 288; mc->has_hotpluggable_cpus = false; mc->auto_enable_numa_with_memhp = false; + mc->auto_enable_numa_with_memdev = false; mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE; mc->nvdimm_supported = false; mc->default_ram_id = "microvm.ram"; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 576f2502f9..61acc9e530 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1975,6 +1975,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) mc->get_default_cpu_node_id = x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; mc->auto_enable_numa_with_memhp = true; + mc->auto_enable_numa_with_memdev = true; mc->has_hotpluggable_cpus = true; mc->default_boot_order = "cad"; mc->hot_add_cpu = pc_hot_add_cpu; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 1d832b2878..fae487f57d 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -444,6 +444,7 @@ static void pc_i440fx_5_0_machine_options(MachineClass *m) m->numa_mem_supported = true; compat_props_add(m->compat_props, hw_compat_5_0, hw_compat_5_0_len); compat_props_add(m->compat_props, pc_compat_5_0, pc_compat_5_0_len); + m->auto_enable_numa_with_memdev = false; } DEFINE_I440FX_MACHINE(v5_0, "pc-i440fx-5.0", NULL, diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 047ea8db28..acd6d405f0 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -372,6 +372,7 @@ static void pc_q35_5_0_machine_options(MachineClass *m) m->numa_mem_supported = true; compat_props_add(m->compat_props, hw_compat_5_0, hw_compat_5_0_len); compat_props_add(m->compat_props, pc_compat_5_0, pc_compat_5_0_len); + m->auto_enable_numa_with_memhp = false; } DEFINE_Q35_MACHINE(v5_0, "pc-q35-5.0", NULL, From patchwork Fri Jul 3 09:04:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322223 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FtY1QITD; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq2D0g9Yz9sR4 for ; Fri, 3 Jul 2020 19:11:00 +1000 (AEST) Received: from localhost ([::1]:46294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHij-0003vO-34 for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:10:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcj-0000Dt-Oy for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:51497 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 1jrHch-0004Ux-TF for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767083; 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=60yJhhl8dxn2TqcFbclvoZcJECXRC60a4szFbHzWcWo=; b=FtY1QITDIGg9thjUK+O5IPK53SPx3P7TAqt9ZJneEcWaRfAVqaQTYn6b/YZK/Sgx8jNLkU 7YYuzDokBKT7ACQ37n4e2+WimmEHkYnnUZ+ueH2vE5sZpPU+djN8ClXHJzTv3OSQUlfckv juk2lV5uAjlBTJphPG98wioEKUbbUck= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-183-xHZ4uCk0MxeHYfyFjXEjmQ-1; Fri, 03 Jul 2020 05:04:41 -0400 X-MC-Unique: xHZ4uCk0MxeHYfyFjXEjmQ-1 Received: by mail-wr1-f69.google.com with SMTP id y18so11473134wrq.4 for ; Fri, 03 Jul 2020 02:04:41 -0700 (PDT) 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=60yJhhl8dxn2TqcFbclvoZcJECXRC60a4szFbHzWcWo=; b=lDrTNt2j6mupFukEJykhxWLAZ2quRtjilGx8v3Lu32R/+wZEvMqTOHKHBBCoX9TRgB SW42hOHQ+d9ThBgUb1w9C5Q3CpWWBcuIVFpYjsbT2z26ycSVes44ervzXZw6N3fQRkGR nGLP9/ITyxCJMoo4cRUnJbfcZ+1czOYhjMzT50aah/HYohn6spb0aRda6321PpC79kue pmovCR/u9TRLx5Pv1DhTam0nnkF04/kZ1K8i/TxyRaZquTUU1gGJrvkT9IBQ0Bti6r9H QZYmJkEsfAGz3s4q6cefz4OZBOr2WUfj6US3rp6lBxI3605nqXZKSTJKE5HWyPfVad/G 3Rww== X-Gm-Message-State: AOAM5310S+yTcm5eLKloTpAOSCth47P3T1Qo9Iw9jBQyEuPBDD2eylbn dV7d5FqmJ2PL0mNYtqByL5QHKkKDiYABD1eCL5O+3UYJ6NejzpqBrOc+k9pZ5i91VGY1KRBCljt r6ALq4lVSJUMsKvw= X-Received: by 2002:adf:e948:: with SMTP id m8mr36629162wrn.398.1593767080010; Fri, 03 Jul 2020 02:04:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkC3UKolfnEOb4uXIMxFZe2mf7pVOLgDQpuEJfxfHRhhm0v34ckTl6xU5fu8YL/gjd/WIxMA== X-Received: by 2002:adf:e948:: with SMTP id m8mr36629139wrn.398.1593767079711; Fri, 03 Jul 2020 02:04:39 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id s8sm13408268wru.38.2020.07.03.02.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:39 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:37 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 25/41] tests/acpi: remove stale allowed tables Message-ID: <20200703090252.368694-26-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_SUBJ_WIPE_DEBT=1.004 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: Peter Maydell , Andrew Jones , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Andrew Jones Fixes: 93dd625f8bf7 ("tests/acpi: update expected data files") Signed-off-by: Andrew Jones Message-Id: <20200629140938.17566-2-drjones@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/bios-tables-test-allowed-diff.h | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h index 8992f1f12b..dfb8523c8b 100644 --- a/tests/qtest/bios-tables-test-allowed-diff.h +++ b/tests/qtest/bios-tables-test-allowed-diff.h @@ -1,19 +1 @@ /* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/pc/DSDT", -"tests/data/acpi/pc/DSDT.acpihmat", -"tests/data/acpi/pc/DSDT.bridge", -"tests/data/acpi/pc/DSDT.cphp", -"tests/data/acpi/pc/DSDT.dimmpxm", -"tests/data/acpi/pc/DSDT.ipmikcs", -"tests/data/acpi/pc/DSDT.memhp", -"tests/data/acpi/pc/DSDT.numamem", -"tests/data/acpi/q35/DSDT", -"tests/data/acpi/q35/DSDT.acpihmat", -"tests/data/acpi/q35/DSDT.bridge", -"tests/data/acpi/q35/DSDT.cphp", -"tests/data/acpi/q35/DSDT.dimmpxm", -"tests/data/acpi/q35/DSDT.ipmibt", -"tests/data/acpi/q35/DSDT.memhp", -"tests/data/acpi/q35/DSDT.mmio64", -"tests/data/acpi/q35/DSDT.numamem", -"tests/data/acpi/q35/DSDT.tis", From patchwork Fri Jul 3 09:04:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322231 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ca4QGZ3g; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq6y41zzz9sR4 for ; Fri, 3 Jul 2020 19:15:06 +1000 (AEST) Received: from localhost ([::1]:37656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHmi-0004Og-7E for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:15:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcm-0000Kk-8h for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:48 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:26794 helo=us-smtp-delivery-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 1jrHck-0004VM-F1 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767085; 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=XsBDJFEC04b3XTFz4nBxIO5zxhzyAGQ01hQLAAQIsGo=; b=Ca4QGZ3gweIhWD73RAngXCTbx/BkVP2eYmMTs860Knjq4kyE1mgNltg9uboGM1pkiHlPl+ +wnUpo0/kwL8lGKAw3BcsA1sLlmop/n42g+28gfmVn5AkEsL8aItd2T6NVLoRMYU28K/Mg bKt6KnmLwko0D7R81mgtHLKI0X7A1hI= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-115-sS_u22rpMeKNyreZnOPoGg-1; Fri, 03 Jul 2020 05:04:43 -0400 X-MC-Unique: sS_u22rpMeKNyreZnOPoGg-1 Received: by mail-wm1-f72.google.com with SMTP id v11so15783232wmb.1 for ; Fri, 03 Jul 2020 02:04:43 -0700 (PDT) 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=XsBDJFEC04b3XTFz4nBxIO5zxhzyAGQ01hQLAAQIsGo=; b=rINOm4tiyW/C4ViOVRNJI3xnAU27nENJ1p9cC800Yoco+XycZSV+VXRrrSjqRc6RWa BXgV3RCbrQ3igXfq7j79EHYYMQbTxX/NFOqcgubJz3NJAQlgeoMHleTX7S/uyZsPivtn wtI75fouJTNs5nRApGoLdkF2CwAd8Y5Fy9T/W3gKiOlC5KiXXpqxUJWyAGYsgCKgrIm2 UPKvXwz4Ly2i/B+g/OaEPu/AqJ4akjZdoKwfTwiY7ULAkOhAHSgxo3TT+XlbxNcZw/60 pgtbx8FmDAwZuxa85FPD+wB+grrl0d8z5BsVuk5dorUPfFiugk1+y3shD5p9TOMnHPKc ob4Q== X-Gm-Message-State: AOAM5312L2WIv+42BShceqJYDVZKkt1gRKMWSy6vkNXfjbZwKPXhfu60 76dcMOXDeoyMwT777dZ2JA/s9x8u5I28sREYQAHG7FlhKyzZjJ1G6Orgz7BUJsSReHfDPMs9dwW 9RrcDerIknnGHylw= X-Received: by 2002:a1c:4c16:: with SMTP id z22mr35382196wmf.103.1593767082450; Fri, 03 Jul 2020 02:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO5hCTXeCjk7blI3Vkd1MJkF1PN2PvQwjS4znBUidE+10H62+1eOwLvRQvKfScofsX7SsYwQ== X-Received: by 2002:a1c:4c16:: with SMTP id z22mr35382179wmf.103.1593767082253; Fri, 03 Jul 2020 02:04:42 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id g82sm11053191wma.37.2020.07.03.02.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:41 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:40 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 26/41] docs: vhost-user: add Virtio status protocol feature Message-ID: <20200703090252.368694-27-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Maxime Coquelin , Jason Wang , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Maxime Coquelin This patch specifies the VHOST_USER_SET_STATUS and VHOST_USER_GET_STATUS requests, which are sent by the master to update and query the Virtio status in the backend. Signed-off-by: Maxime Coquelin Message-Id: <20200618134501.145747-1-maxime.coquelin@redhat.com> Acked-by: Jason Wang Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/interop/vhost-user.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index 688b7c6900..10e3e3475e 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -816,6 +816,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_RESET_DEVICE 13 #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 15 + #define VHOST_USER_PROTOCOL_F_STATUS 16 Master message types -------------------- @@ -1307,6 +1308,29 @@ Master message types ``VHOST_USER_ADD_MEM_REG`` message, this message is used to set and update the memory tables of the slave device. +``VHOST_USER_SET_STATUS`` + :id: 39 + :equivalent ioctl: VHOST_VDPA_SET_STATUS + :slave payload: N/A + :master payload: ``u64`` + + When the ``VHOST_USER_PROTOCOL_F_STATUS`` protocol feature has been + successfully negotiated, this message is submitted by the master to + notify the backend with updated device status as defined in the Virtio + specification. + +``VHOST_USER_GET_STATUS`` + :id: 40 + :equivalent ioctl: VHOST_VDPA_GET_STATUS + :slave payload: ``u64`` + :master payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_STATUS`` protocol feature has been + successfully negotiated, this message is submitted by the master to + query the backend for its device status as defined in the Virtio + specification. + + Slave message types ------------------- From patchwork Fri Jul 3 09:04:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322226 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=equi0d0s; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq4K6CDqz9sPF for ; Fri, 3 Jul 2020 19:12:49 +1000 (AEST) Received: from localhost ([::1]:54556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHkV-0007fF-Fw for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:12:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHco-0000S1-RA for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59681 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 1jrHcn-0004W0-2a for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767088; 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=b+cCdkPsrD4TM/VrIcZdX3Ig4P6coUYr9PkA+fapcI0=; b=equi0d0sQYedatw5+x6vxQouzcufhHWuXtUYA7dyod7YD7sPIlVS/sl63vzYTMD8hUZtD9 0+/T/BA0UYYzyG3EeO4P1LTsc5XxsMTncw0Cmy5MUn4cvGahnz0/ahmAd04U7ImRaFyD26 odKKvMC3+VzPyXf8+UrAE41sxFQ9bbk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-KfvdTBizMKOBYV-MwNEpuQ-1; Fri, 03 Jul 2020 05:04:46 -0400 X-MC-Unique: KfvdTBizMKOBYV-MwNEpuQ-1 Received: by mail-wr1-f69.google.com with SMTP id z1so1301377wrn.18 for ; Fri, 03 Jul 2020 02:04:46 -0700 (PDT) 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=b+cCdkPsrD4TM/VrIcZdX3Ig4P6coUYr9PkA+fapcI0=; b=FyPls+KiFQP9eC0sGpEOm+2g+vOB42Ekx28PXrj/n/RnvZThyYS09xIJ9ycSz7q1vY TE3JKLZy7mzYRehs4hMxUwp9cxqVRHLbsl87gsNRlGcTo1H1PMv8G3yn3vAVEO7EL84p dhfeFxGnlRaqB2b4N9sIM2/dSpMsKQl/G2JKKli6Q0CSB4XQyiq3TQaVxzXvz0aWE87W AeDW0aNX4Fv1ir4ztI8IMAg1/wyXhgf6piCloQ48uZMZKVIF1G/4Di97fWIXsxWKL4H4 IwiTuSH1U6v3aqP/HWbwZwiebNzK2yoCbA5IAElpopeGMTnZO/OwnpHFWYxkudnZNeEe NMrw== X-Gm-Message-State: AOAM532D2+/1N0TYSwwX56ySimKAx3hzt5agXRGpwav4G7WdW9tcvEh2 QPF9lXL3ThpfbDnMS8MyS0JpFeXKJc+0Z+lM2ZtEGaSc1nL25XMXoy5Y3xpw1+xjdEUjG4kIANv 1nxS6li7jtKjGcuU= X-Received: by 2002:a1c:18e:: with SMTP id 136mr5374228wmb.93.1593767085282; Fri, 03 Jul 2020 02:04:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8k11ax1hga9RvwoEl3X4POoGOckBMufTY3rTD6NLb52ZpW3akWdluSOLrWXWu2FgDdUxrOg== X-Received: by 2002:a1c:18e:: with SMTP id 136mr5374204wmb.93.1593767085097; Fri, 03 Jul 2020 02:04:45 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id s15sm12972235wmj.41.2020.07.03.02.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:44 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:42 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 27/41] MAINTAINERS: add VT-d entry Message-ID: <20200703090252.368694-28-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Alex =?utf-8?q?Benn=C3=A9e?= , Jason Wang , Laurent Vivier , Peter Xu , Aleksandar Markovic , Paolo Bonzini , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Xu Add this entry as suggested by Jason and Michael. CC: Jason Wang CC: Michael S. Tsirkin CC: Paolo Bonzini Signed-off-by: Peter Xu Message-Id: <20200701124418.63060-1-peterx@redhat.com> Acked-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 5f02160436..49a0d837d7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2624,6 +2624,15 @@ F: tests/uefi-test-tools/ F: .gitlab-ci.d/edk2.yml F: .gitlab-ci.d/edk2/ +VT-d Emulation +M: Michael S. Tsirkin +M: Peter Xu +R: Jason Wang +S: Supported +F: hw/i386/intel_iommu.c +F: hw/i386/intel_iommu_internal.h +F: include/hw/i386/intel_iommu.h + Usermode Emulation ------------------ Overall usermode emulation From patchwork Fri Jul 3 09:04:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PktqJYCF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq9X2sxnz9sR4 for ; Fri, 3 Jul 2020 19:17:20 +1000 (AEST) Received: from localhost ([::1]:45976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHos-0000Cg-17 for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:17:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcr-0000YX-8w for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37318 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 1jrHcp-0004WM-GX for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767090; 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=J87y6/ALZV5j2hxcU6iv08lRd5sVzb2p1LKaAZ1dyww=; b=PktqJYCFDRVdf16AcozFUD05+JoA3j5QkHjEqV8UakyoNCX1KaDzWU+f+mRKy4xUOip80Y EUbCLLjIgMMcJ5xHJIAcBCSnTEfX+9dpaDQcUBn6XtLuRiEuEpCEJKRB8fiKFUVgA6gykZ 9MVWoLg8gPuicUf4RZ5S8oUg4jk/BCM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-315-Yh3HwYPuN9ezq8KJMRgMlg-1; Fri, 03 Jul 2020 05:04:49 -0400 X-MC-Unique: Yh3HwYPuN9ezq8KJMRgMlg-1 Received: by mail-wr1-f70.google.com with SMTP id 89so7685945wrr.15 for ; Fri, 03 Jul 2020 02:04:48 -0700 (PDT) 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=J87y6/ALZV5j2hxcU6iv08lRd5sVzb2p1LKaAZ1dyww=; b=rmO7/UF4yxVyAENMHlKpVfitutcWNSCsmNcFWyZD4J2A7KW7qiSSHhYA7rwm1IJZ8g VwUBKub83cR3d8mdu6bQK4zeE9GLJMltI4uQMTlDIW8SiCJpnIlcj66ApyiCe6t30Sfw 7PQ/cb0nPInYpE3o5WOeOaZLZofotamn1E2+hVpFYZ+Dw4Q4s6LLV/tGFtkIG7eisuBh OibZQeP4fkStbsmQbGod9pI0XYX6PSd+z+80itX0eKZnsInHfUabNWeKwBLdh60+Tk81 b6LQso3V3/4Xs+zGdPBC2TqmtLlniBPmDj/9cW27rr5ihfBWltu+/rqcomZNN9Ekp781 wl2A== X-Gm-Message-State: AOAM533WAjrVPn/qtWqSOTK4vFUsOdgAfXuQJLbta4n6VlwZ3QOUvAmP 1k4Zw0tBtsr1mg8xAYksXYeTYdabIUY6TMc5Vl0cqalHpvW2OS/A1X3rPNkGIYX0Y3iYLjWIfWW ON0o/ciNnlEpmmr8= X-Received: by 2002:adf:ef89:: with SMTP id d9mr38010490wro.124.1593767087724; Fri, 03 Jul 2020 02:04:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSYSfj3xYoukHI0nOCXK7dVWXT/4kzB734/IOwzyT6AJ8eKiFl1wqTUJigyr1s6tJp2eFNgg== X-Received: by 2002:adf:ef89:: with SMTP id d9mr38010467wro.124.1593767087490; Fri, 03 Jul 2020 02:04:47 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id r12sm13030188wrc.22.2020.07.03.02.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:46 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:45 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 28/41] net: introduce qemu_get_peer Message-ID: <20200703090252.368694-29-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu This is a small function that can get the peer from given NetClientState and queue_index Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-2-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- include/net/net.h | 1 + net/net.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 39085d9444..e7ef42d62b 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); /* NIC info */ diff --git a/net/net.c b/net/net.c index d1130296e1..9099a327dd 100644 --- a/net/net.c +++ b/net/net.c @@ -325,6 +325,13 @@ void *qemu_get_nic_opaque(NetClientState *nc) return nic->opaque; } +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) +{ + assert(nc != NULL); + NetClientState *ncs = nc + queue_index; + return ncs->peer; +} + static void qemu_cleanup_net_client(NetClientState *nc) { QTAILQ_REMOVE(&net_clients, nc, next); From patchwork Fri Jul 3 09:04:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322232 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VuOitSzR; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq9F5fb6z9sR4 for ; Fri, 3 Jul 2020 19:17:05 +1000 (AEST) Received: from localhost ([::1]:44396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHod-0007i5-CB for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:17:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcu-0000gg-8y for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25376 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 1jrHcs-0004Wf-9E for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767093; 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=qOJsVqrCvYFr1+pi9ZUb1wgSPCHp9bN1XR/9RybzirU=; b=VuOitSzRaHIb4QJNXcS72/ISJjX5Hr4MZByCuFWI0Vs9qvG0Rq2I+mnMvjzr0hBAGxF6i+ AWXncfrGua/FcZUsPIJ3IGRnJ1MSIEzQR6dABWgmEZSLkH14rmSpCtLDoLfqLFpjmfIA5l JIOs9W+x/vyOKKdXEkGafqaZT6Dy3dk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-394-0F0PfGihPfOKVHV1GBOmmA-1; Fri, 03 Jul 2020 05:04:52 -0400 X-MC-Unique: 0F0PfGihPfOKVHV1GBOmmA-1 Received: by mail-wm1-f72.google.com with SMTP id h6so34436054wmb.7 for ; Fri, 03 Jul 2020 02:04:51 -0700 (PDT) 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=qOJsVqrCvYFr1+pi9ZUb1wgSPCHp9bN1XR/9RybzirU=; b=t6wMhs8dl3VHruOIyh2vYsdaNXmYt2p5KDlqlRHZMnkuJ9Kbpj7+MEfCR1MvtFQKtd 1+U3v8o3WwzY0feISFF/SO6ONSP0b6oPxFV0cwXr7vG4yhL/kvdYv2C6lGTMju5+Yj4i PeqwN/pGxpqOv0UG2QscdQua4nTvTNARAgscsHxXpqyX86VavQaOjxkjEdTT64u8lmGX 4sZSynuikmClgaEsthJDisvOahdbqRTCLQhPraxsGPMWf9fX1Or4uPn6WpqzjInWfpVw n7bgt2Vk+tJBgrOsNqZxBTr721X0r1ev9Bo9wdbbVCZ9SEpTuSQsVpnak1YJ5LOz6rkC cn9Q== X-Gm-Message-State: AOAM533KNLspFN7EWF5QRrrJXrjqW4OmzfbcUEwxp4ebBuRFAFYE3vGI TXnKsHxPeE+OdRsHq491M5l3kEGjax/r+a0fhKXUfuewFxtYEPwTxxZMEEaVAtXoPTc9SB6vLqZ RI0rKI30k/ROB/QA= X-Received: by 2002:adf:f889:: with SMTP id u9mr39235924wrp.149.1593767090098; Fri, 03 Jul 2020 02:04:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzySN1/QREO4c5w90k2hJ1JxA3lvy9YL/6xY6hlGJyqClhZmdp042tt2BsRx5fcoQ9gOZZIHQ== X-Received: by 2002:adf:f889:: with SMTP id u9mr39235906wrp.149.1593767089927; Fri, 03 Jul 2020 02:04:49 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id d81sm40383962wmc.0.2020.07.03.02.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:49 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:47 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 29/41] vhost_net: use the function qemu_get_peer Message-ID: <20200703090252.368694-30-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Laurent Vivier , Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu user the qemu_get_peer to replace the old process Signed-off-by: Cindy Lu Reviewed-by: Laurent Vivier Message-Id: <20200701145538.22333-3-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- hw/net/vhost_net.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..4096d64aaf 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); + struct vhost_net *net; int r, e, i; + NetClientState *peer; if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { - struct vhost_net *net; - net = get_vhost_net(ncs[i].peer); + peer = qemu_get_peer(ncs, i); + net = get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); /* Suppress the masking guest notifiers on vhost user @@ -335,15 +337,16 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { - r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); + peer = qemu_get_peer(ncs, i); + r = vhost_net_start_one(get_vhost_net(peer), dev); if (r < 0) { goto err_start; } - if (ncs[i].peer->vring_enable) { + if (peer->vring_enable) { /* restore vring enable state */ - r = vhost_set_vring_enable(ncs[i].peer, ncs[i].peer->vring_enable); + r = vhost_set_vring_enable(peer, peer->vring_enable); if (r < 0) { goto err_start; @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, err_start: while (--i >= 0) { - vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); + peer = qemu_get_peer(ncs , i); + vhost_net_stop_one(get_vhost_net(peer), dev); } e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); if (e < 0) { From patchwork Fri Jul 3 09:04:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EWcEKsxb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq6N4qXsz9sPF for ; Fri, 3 Jul 2020 19:14:36 +1000 (AEST) Received: from localhost ([::1]:34638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHmE-000397-Cj for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:14:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcw-0000m5-Fs for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:58 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:50545 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 1jrHcu-0004Wx-Kp for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:04:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767096; 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=p8xQzlc8evAUo7O9syva6ExL2iB8bosWtyuBg9IIFRI=; b=EWcEKsxb2S5khNGrF/OBuPDb2bzVAGEXSl4B/u834uQfQd2yYntHfRI65DdIVUhEA64StP RAbq7e9aB5qizf6mN1rYuReCV/QbRvS/72Ud53HkcSyfUZoBAh2McgS/EoIEr+liYLCLSE sST+Oq1z1y5HTxbNm8+rhBXPgunTOSg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-wN8ZjjPBMoGbIpX3MTpRlQ-1; Fri, 03 Jul 2020 05:04:54 -0400 X-MC-Unique: wN8ZjjPBMoGbIpX3MTpRlQ-1 Received: by mail-wr1-f69.google.com with SMTP id j16so25790043wrw.3 for ; Fri, 03 Jul 2020 02:04:54 -0700 (PDT) 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=p8xQzlc8evAUo7O9syva6ExL2iB8bosWtyuBg9IIFRI=; b=F6B0K5kO281PiWgUm1mZxp9ZKsZgWFX1ighujQ8SnXxoSYd/LXvhR+ePz9K8TQVKkq U+buTn3q2hh2VeCiZhzmDDG2Sa6f/cJxi91RU39YVZWevXOUsXFdD60NfWJry+8qKP4V 4bKujohgHTBjGPHzyvPatB7Gz0ET99XYqBgZBBLbLZr8JHPZRHdDiOt1OlrT9DXz79md BKqbkgglldegurOx+gJ+4y9pjxj6h6W6A6Dlqj+xuaYuLejCyAdNirwq/WCLe0QoRqMP oNiUSdICk2Tzz4f9gLuieSrKFWyq3t6c9TjoYBMc9XvSQ06ttSG1c2GzTJLwnk6k/L+b f1bQ== X-Gm-Message-State: AOAM530+FfBuVsXdhQbp1Qj1t/ZRQbYdWEVct18nqm8+/Mb0EsLfblDU 4l5ShhVGB5ErQa+jX66Yv8Z/f5P3PslvKR/a6UeRGXb900t3ZWQD0KelXJ/BGW1FFVGrfe3+smQ v9GlcQ2jfOF3WkEk= X-Received: by 2002:a1c:1fc2:: with SMTP id f185mr35665323wmf.0.1593767092510; Fri, 03 Jul 2020 02:04:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/+NCQY/8s+fYN/U36NCE9Z30ec1RCDY0E24HVBQ280WACb+OaFy9RKxUR/WSYxJ3VgSHywg== X-Received: by 2002:a1c:1fc2:: with SMTP id f185mr35665308wmf.0.1593767092343; Fri, 03 Jul 2020 02:04:52 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 65sm14121679wre.6.2020.07.03.02.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:51 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:50 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 30/41] virtio-bus: introduce queue_enabled method Message-ID: <20200703090252.368694-31-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jason Wang This patch introduces queue_enabled() method which allows the transport to implement its own way to report whether or not a queue is enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-4-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- include/hw/virtio/virtio-bus.h | 4 ++++ hw/virtio/virtio.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 38c9399cd4..0f6f215925 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); + /* + * Whether queue number n is enabled. + */ + bool (*queue_enabled)(DeviceState *d, int n); /* * Does the transport have variable vring alignment? * (ie can it ever call virtio_queue_set_align()?) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index cc9c9dc162..5bd2a2f621 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3286,6 +3286,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n) bool virtio_queue_enabled(VirtIODevice *vdev, int n) { + BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + + if (k->queue_enabled) { + return k->queue_enabled(qbus->parent, n); + } return virtio_queue_get_desc_addr(vdev, n) != 0; } From patchwork Fri Jul 3 09:04:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JbjnYPJy; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqC40CLHz9sR4 for ; Fri, 3 Jul 2020 19:18:40 +1000 (AEST) Received: from localhost ([::1]:54172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHq9-0003eJ-Pi for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:18:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHcy-0000rE-SK for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:00 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:29557 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 1jrHcx-0004Xr-3L for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767098; 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=YKm01s4uoYNcg0A8gRDSfiSMGc6pTEcCI5zK0YNeAPM=; b=JbjnYPJybIEbQvoTzd80zVOMLM7elHMOCRVFkkDGTuoCZ8Fm7Q0Jyd4yrRfVKnmeTJGde7 RcN12+03LbbrAQBpQJe1W53vedlqBwsnDBSBDFPmFI59J/iwPmF3E2JwqIwkugBIBZJYLr 9JMoh+1gHDKH4eWbOOf7VmyxO6y3+tw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466-Oi0hS4KXMo6kOUzPO01Bug-1; Fri, 03 Jul 2020 05:04:56 -0400 X-MC-Unique: Oi0hS4KXMo6kOUzPO01Bug-1 Received: by mail-wr1-f70.google.com with SMTP id d11so13664866wrw.12 for ; Fri, 03 Jul 2020 02:04:56 -0700 (PDT) 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=YKm01s4uoYNcg0A8gRDSfiSMGc6pTEcCI5zK0YNeAPM=; b=MR3xDpDfaI5SZ2FroKw6SB/Pu7VCMWpw8HGEi+G7LIh0KKwDmLgkwSKyggZpmzOfbY Lwu9drv+imYEACpq4sxrUt6x0fO/tYgIFVhY8DBNwl/B7wLXg3qjQvrP92UPEvW1ohvh uuw9KMcXzJaXK+j3PWJn9/Y+1LtsRPtrvqVy06gNIy3JeXUYr0ZRVyddXO6hf/MN0hbJ 6E5f16RPFpHNMxNR9lNXsTltHuMIjTUMqNFSjBN3U8cotQohvXMDmT+WOWJcMoIedL1t p1Dae/NYjEj3DTQWb+VtI0Hgo1a2S9VHvQ8idN3HN4fGmdrvhxiImJXO2adThDaQXUKt 1iAQ== X-Gm-Message-State: AOAM530Au1pv0WFukzJlur1YZZZjQCMn4I3NFD5QuC7J0BvjFmx4cS8d aDWtkYNUzbYcDcyIcZfedFL99DzKhsuJNKB6gFtiBCpdLMbok9VuUaGO02SDjBLMzqjIuCoLy+k SLxg93WmoAoz/2bI= X-Received: by 2002:a7b:c956:: with SMTP id i22mr35994531wml.95.1593767095296; Fri, 03 Jul 2020 02:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzE+j8JfhCoGRTyPd3wNH7Y2r8D/VAARyUoEkr8lIOXDJOiyLMDxJou2MrUXPzUD9oColpYmA== X-Received: by 2002:a7b:c956:: with SMTP id i22mr35994520wml.95.1593767095141; Fri, 03 Jul 2020 02:04:55 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id z132sm13041650wmb.21.2020.07.03.02.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:54 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:52 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 31/41] virtio-pci: implement queue_enabled method Message-ID: <20200703090252.368694-32-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jason Wang With version 1, we can detect whether a queue is enabled via queue_enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-5-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- hw/virtio/virtio-pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 7bc8c1c056..8554cf2a03 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1107,6 +1107,18 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d) return pci_get_address_space(dev); } +static bool virtio_pci_queue_enabled(DeviceState *d, int n) +{ + VirtIOPCIProxy *proxy = VIRTIO_PCI(d); + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { + return proxy->vqs[vdev->queue_sel].enabled; + } + + return virtio_queue_enabled(vdev, n); +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2064,6 +2076,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; k->ioeventfd_assign = virtio_pci_ioeventfd_assign; k->get_dma_as = virtio_pci_get_dma_as; + k->queue_enabled = virtio_pci_queue_enabled; } static const TypeInfo virtio_pci_bus_info = { From patchwork Fri Jul 3 09:04:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XW8lgFww; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yq9Y4Nrkz9sR4 for ; Fri, 3 Jul 2020 19:17:21 +1000 (AEST) Received: from localhost ([::1]:46014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHot-0000Dt-9B for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:17:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHd1-0000wd-Cz for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:03 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:22906 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 1jrHcz-0004Z4-Ep for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767100; 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=tXbtGjuArFU0L6axuc9oufytf20N/xVITacNIR/IrnQ=; b=XW8lgFwwz/p7nDFGwShyOS03a5VHhvFg5RkeZ4HE0onKwtzqb1gc/R2VVGwVoi8S+XYiVO rFBNv8Z2ottpyPY2j3Gop/keBbj28DrQm1Za0CWhUvCCQupgYGw5VBvd9lWXibTxn3vet0 ZZ7tiNW6+JluVtJYAv6BMuhMx3XDSAM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-268-jROEz1ldOU6kAwe7gPCFtg-1; Fri, 03 Jul 2020 05:04:59 -0400 X-MC-Unique: jROEz1ldOU6kAwe7gPCFtg-1 Received: by mail-wm1-f72.google.com with SMTP id g187so34475540wme.0 for ; Fri, 03 Jul 2020 02:04:59 -0700 (PDT) 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=tXbtGjuArFU0L6axuc9oufytf20N/xVITacNIR/IrnQ=; b=ofHP26QxPLe/W7Pi56mMEhg9xYi8gGD0KH9bC4MsE/xR4HIl38ZPzK7l5eZYJvHj9g fCNcnngPbtQ935fi7jDnI2i953JDxStiTPlD6mONSoDIIt3fPmWh990QIEUP5gDW4Qc3 GnZLcnxsgix6vhQDt84BpKjGSyQDKvNxx3unywPvpedlGejRuBdqpe8OgcioWQbfCYjX K1UxbCoGFiaTPMBo2ztJw56rf5Y/TFRPvM+vPJgX6IpELhr0sfTq/OVMd43S6xn03tu3 JIMjSSflh5ZQVDLkkmYGT2I/91QYxfZA3aC2HBT9SQQD/kqgr2GE1FFPdaxHEsiMmcsa h0dA== X-Gm-Message-State: AOAM533Y6z88s2bx0znXHQPYWI+7autNd3i7lgMCEZr7zWEUw+uKR9MP khRBmRKy5dyNQJ41ipTrnZ7iMqxnSKkS7gsPKcm92Sp/r5NiIFI3jkgyWfqOlExuAqXf1Bq3yBT ZkevJq1h5j3iO/To= X-Received: by 2002:a05:6000:10c4:: with SMTP id b4mr33552587wrx.50.1593767097664; Fri, 03 Jul 2020 02:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv9FCMfwSGdRhF0oXPmZmMf7It5RcWIjtd3s9RDzXtez9CWlg0rbOpmP1MSZtCHfYeKn70+g== X-Received: by 2002:a05:6000:10c4:: with SMTP id b4mr33552574wrx.50.1593767097509; Fri, 03 Jul 2020 02:04:57 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id d13sm13143399wrn.61.2020.07.03.02.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:57 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:55 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 32/41] vhost: check the existence of vhost_set_iotlb_callback Message-ID: <20200703090252.368694-33-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jason Wang Add the check of vhost_set_iotlb_callback before calling Signed-off-by: Jason Wang Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-6-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- hw/virtio/vhost.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 5fd25fe520..10304b583e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1686,8 +1686,9 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } - if (vhost_dev_has_iommu(hdev)) { - hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); + if (vhost_dev_has_iommu(hdev) && + hdev->vhost_ops->vhost_set_iotlb_callback) { + hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); /* Update used ring information for IOTLB to work correctly, * vhost-kernel code requires for this.*/ @@ -1730,7 +1731,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) } if (vhost_dev_has_iommu(hdev)) { - hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); + if (hdev->vhost_ops->vhost_set_iotlb_callback) { + hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); + } memory_listener_unregister(&hdev->iommu_listener); } vhost_log_put(hdev, true); From patchwork Fri Jul 3 09:04:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hYhq/mkS; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqC639J2z9sR4 for ; Fri, 3 Jul 2020 19:18:42 +1000 (AEST) Received: from localhost ([::1]:54364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHqC-0003j3-64 for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHd3-00010T-E6 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:05 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:46766 helo=us-smtp-delivery-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 1jrHd1-0004aB-NX for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767103; 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=YYDftXcBQrqsgbkpJ5iu6MhYnQVu4atwyoFfOVtYo8s=; b=hYhq/mkSFcE1hSanAG0Vunxbf6oXXbILxrQW6YTiP0YbYH7z4ggY2Lr255ntSMEldISn5h 8Av/Bi8VoifBeuW7uzjkGNZK+J6BL7ZAzcxccwb6trh60sPHx49ck3dMLeM2ingYvV5EKB AFUljdVUFn5hvknDCzTTAWrf/opN9W0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-mmEnlFeaM5GIELTe7mxE6Q-1; Fri, 03 Jul 2020 05:05:01 -0400 X-MC-Unique: mmEnlFeaM5GIELTe7mxE6Q-1 Received: by mail-wm1-f70.google.com with SMTP id h6so34436220wmb.7 for ; Fri, 03 Jul 2020 02:05:01 -0700 (PDT) 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=YYDftXcBQrqsgbkpJ5iu6MhYnQVu4atwyoFfOVtYo8s=; b=kHgXtkAeG/PHOjHDupdYIdm1fNEp6TJjqoElfiLjxaRnRZwoyx9QurjF0zIb6610Qc zV74f8/Tk7hYfjwk/eaVGqYB4E8Qang5oK4rwLxJh2naOvWvkupF65z+sluYUKbAM3Eh /oPyXyC18fDjaABOWVL1qGRA4GYUyGYBV7afM42vX5Dr6ztbTm5HhQ5kY5Yo/ADyFYTO w2Wijzv0VomA7G6/02qQe0nl2YAE2Smc9dg0a/UEsLxBNL/22z9e9TGM4FuPhz/npzQu 6CgUSEZwiS4yrFj6o/NJTKKjT9V8p0d13almSCk/H2AZn9YVSAvKLmoLkjSKpSsHUPFU Vtsg== X-Gm-Message-State: AOAM532oxF18bciFkqZ50ePVm23EOXykuzPd0145vUCcGNMTIttAqqwt e4iNqdEmpJOErYphWqR2i7sycrmk04VC1Wq3gWipEPfH6lv5r+wGJWM/cFvp8dcSsr1+Ko9cJOu RQL02ovPa3Deu23A= X-Received: by 2002:a05:600c:294a:: with SMTP id n10mr34117812wmd.38.1593767100021; Fri, 03 Jul 2020 02:05:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWzygOf0BaPzD8Ie+SB8Qpk7JFUuJoGebPHrqjXMvhAzP4JG2SXnIPIhHzpGCRFltq3Un+EQ== X-Received: by 2002:a05:600c:294a:: with SMTP id n10mr34117798wmd.38.1593767099878; Fri, 03 Jul 2020 02:04:59 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id w12sm13986438wrm.79.2020.07.03.02.04.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:04:59 -0700 (PDT) Date: Fri, 3 Jul 2020 05:04:57 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 33/41] vhost: introduce new VhostOps vhost_dev_start Message-ID: <20200703090252.368694-34-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu This patch introduces new VhostOps vhost_dev_start callback which allows the vhost_net set the start/stop status to backend Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-7-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- include/hw/virtio/vhost-backend.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 6f6670783f..b80f344cd6 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev, typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); +typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -152,6 +153,7 @@ typedef struct VhostOps { vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; + vhost_dev_start_op vhost_dev_start; } VhostOps; extern const VhostOps user_ops; From patchwork Fri Jul 3 09:05:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gCrlKEeg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqBq0Fd1z9sPF for ; Fri, 3 Jul 2020 19:18:27 +1000 (AEST) Received: from localhost ([::1]:52868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHpw-000380-Mq for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:18:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHd5-00015l-Sc for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:07 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55550 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 1jrHd4-0004bi-7t for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767105; 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=WXw9VMdMEtGhEWjld76yv/MTPIVm1m5S/D9V6O7qby8=; b=gCrlKEegnx9a1QfYol3Mw/yI/PJGkqU2nZFQE0OGro6OaPVyzQwzGWxozEA68FXCIBtETY hNscuc+XrGjqVj2BP4kRIhSSNw4kB+xMwcF3ZUzSMg9lsCjkI7TQAgJORW28OSnYd6sMH7 C2byOwNf0gasy86shmmOdyVEd/IRy+0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-178-k56v560xOQaC4XH4_FmF5w-1; Fri, 03 Jul 2020 05:05:03 -0400 X-MC-Unique: k56v560xOQaC4XH4_FmF5w-1 Received: by mail-wr1-f72.google.com with SMTP id o25so31021611wro.16 for ; Fri, 03 Jul 2020 02:05:03 -0700 (PDT) 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=WXw9VMdMEtGhEWjld76yv/MTPIVm1m5S/D9V6O7qby8=; b=cU5cWk/8IRtGhSTIqvJ1BdDiIH9yUnPiOlPgkvtpT1cQTrIzLG1EQLHoCxgHAtnT6i t3CfIyzOVrSpRnTivL7v5vc79psjUzSS7g/GkH0gjiWcf+LPjKmza0DBZRTXR4cdgdez X2ZjCvHtLylersIHvabCtKq2ZGrthhYM32gTKhAuI3hhkapnpM55DYh4oUsI8WY2xlA4 +rSGx7G/GuKmVdLgiCQOtNTE0Sj8GAZBD+zxHy8BaPYTch+hRk+a2GKWMd8WP8a0g3nt 6MXHYiJMMifBJ2ApnXD7ZzA2ebW5ypDvsgsxejOhcRzRU6QdTGRCwWlbxjb5ULasvG08 z5uw== X-Gm-Message-State: AOAM533KeoVYfVnBwmMfGDkHKXRMBOpxl6DeDq8A/2r88MX7merrHwhZ Jou/UqfRK6XQIV8aUO9uKNZJB6jmvSdPsiIjWnoIQaYhdXbYbaYg4p1gckPWBEEYx/vRo2Zexe6 56lokCuENS3Yn6mU= X-Received: by 2002:a5d:4751:: with SMTP id o17mr11948189wrs.345.1593767102457; Fri, 03 Jul 2020 02:05:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPEHcRrWOVqdpTOOiVsH6IspwJ2fyFXiaqK05R5HzNSazW2jxfT2SklWqKUuspvWQ0vZ3G9Q== X-Received: by 2002:a5d:4751:: with SMTP id o17mr11948177wrs.345.1593767102331; Fri, 03 Jul 2020 02:05:02 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 2sm12493814wmo.44.2020.07.03.02.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:01 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:00 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 34/41] vhost: implement vhost_dev_start method Message-ID: <20200703090252.368694-35-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu use the vhost_dev_start callback to send the status to backend Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-8-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- hw/virtio/vhost.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 10304b583e..32809e54b5 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1685,7 +1685,12 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) goto fail_log; } } - + if (hdev->vhost_ops->vhost_dev_start) { + r = hdev->vhost_ops->vhost_dev_start(hdev, true); + if (r) { + goto fail_log; + } + } if (vhost_dev_has_iommu(hdev) && hdev->vhost_ops->vhost_set_iotlb_callback) { hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); @@ -1723,6 +1728,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) /* should only be called after backend is connected */ assert(hdev->vhost_ops); + if (hdev->vhost_ops->vhost_dev_start) { + hdev->vhost_ops->vhost_dev_start(hdev, false); + } for (i = 0; i < hdev->nvqs; ++i) { vhost_virtqueue_stop(hdev, vdev, From patchwork Fri Jul 3 09:05:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OrqskPvu; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqDY2fsGz9sPF for ; Fri, 3 Jul 2020 19:19:57 +1000 (AEST) Received: from localhost ([::1]:32942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHrP-0006UI-3Y for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:19:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHd8-0001B6-5r for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:10 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:49190 helo=us-smtp-delivery-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 1jrHd6-0004bq-Cp for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767107; 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=h8govD67lanJJAmIgSTuxQeH9ZylAQ7cIEwKwJSkzkc=; b=OrqskPvurMM7QZVKm0WcbICIT8sBJH6O7JEA7M9F3VdsIeeXLTNhKISJxKgpSEv/wXf8h5 U7iOL8FE7Jcla7R8ODB9yn0J6PEO+YJN2NaG+19AXHeM3zIIofxDEr6BaLwHWz+0SHKIgh BFcFXvKZXQC10rcPY6qBdQ5Vq+2QGLk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-EydxFMhdMYGC0GKBdehszw-1; Fri, 03 Jul 2020 05:05:06 -0400 X-MC-Unique: EydxFMhdMYGC0GKBdehszw-1 Received: by mail-wr1-f69.google.com with SMTP id i14so30960236wru.17 for ; Fri, 03 Jul 2020 02:05:05 -0700 (PDT) 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=h8govD67lanJJAmIgSTuxQeH9ZylAQ7cIEwKwJSkzkc=; b=rCVYzL34eryrJUKbo7HZMMIFijuiPKcGs619XQl19F8+RhONF+WFA+SgAPy0CIaoSE Z6RYbdPTAefQ4itF5wfD4Nhlftf+16922CPj20LBjupKhRVtE0L5S6O2fSqDyLRGlKji UktlceqrQUzU2FItUsNLQdowZJq6w++3xykk35mJl0LItD4BLh6AelWlOd5UtMwRxSx/ 0O0BSMbaL95yLlmT7Nht4GyGweOnk/veP4hyxBXJ0dzMO2bFb6CUvZ9O4h+u4dB0SXK/ 0CVeP+bcBmWIYY3CeMP4+xax/ZeqbYsQYCH/TP0iKO+ThSTozs5bVXMgWwnwLSgHJt3H ngsA== X-Gm-Message-State: AOAM533TbFfmdnnJY/zvXurFr6dhFIv3hQxvKuU7PAuibH1/nA81qBBi qJuVtPQDhTufU67I6sSHaueOYV27r2/AIXyQEPx6EwPrWAwclmPHz1OUUTmWoWeKS+UuoQwXWVl t+2i5QJkrFOI0MXE= X-Received: by 2002:a7b:cd09:: with SMTP id f9mr37412149wmj.160.1593767104806; Fri, 03 Jul 2020 02:05:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxw9o7TRfLhPHdEA8xMwSlObOpYQ+u2d2VAOlL693TBRr/mKkxAYrXtSYnnMia9fXwBlayaw== X-Received: by 2002:a7b:cd09:: with SMTP id f9mr37412134wmj.160.1593767104651; Fri, 03 Jul 2020 02:05:04 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id q1sm13323187wro.82.2020.07.03.02.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:04 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:02 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 35/41] vhost: introduce new VhostOps vhost_vq_get_addr Message-ID: <20200703090252.368694-36-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu This patch introduces new VhostOps vhost_vq_get_addr_op callback to get the vring addr from the backend Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-9-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- include/hw/virtio/vhost-backend.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index b80f344cd6..fa84abac97 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -34,6 +34,7 @@ struct vhost_vring_state; struct vhost_vring_addr; struct vhost_scsi_target; struct vhost_iotlb_msg; +struct vhost_virtqueue; typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); @@ -113,6 +114,10 @@ typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); + +typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev, + struct vhost_vring_addr *addr, + struct vhost_virtqueue *vq); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -154,6 +159,7 @@ typedef struct VhostOps { vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; vhost_dev_start_op vhost_dev_start; + vhost_vq_get_addr_op vhost_vq_get_addr; } VhostOps; extern const VhostOps user_ops; From patchwork Fri Jul 3 09:05:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Dc/YFe3n; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqDJ3xLVz9sR4 for ; Fri, 3 Jul 2020 19:19:44 +1000 (AEST) Received: from localhost ([::1]:60092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHrC-00061r-7m for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:19:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHdB-0001Hi-Bj for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:13 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:37042 helo=us-smtp-delivery-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 1jrHd9-0004c0-Ew for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767110; 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=3ExkqCYE+MZcrtgAoyxaOOvh3MgXkaeP71bTYP6/+H0=; b=Dc/YFe3nU1mxe2jAQ9RPN8puu74cicKGc+tBBj6gACHpCE3uGiAAp5Y1kkSPgM7ez3TU3H U6Ny8CmpjRSAKO5c5yam6A71GeUslCi8yBCn6DO4zqPQsvc66T9RQIPpMhwo5loG71kGXo 4WM6nLY/IxZUvaHzhWzB56JJpeowWu4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-hVzYesiNNJm7LGu0v8JmBg-1; Fri, 03 Jul 2020 05:05:08 -0400 X-MC-Unique: hVzYesiNNJm7LGu0v8JmBg-1 Received: by mail-wm1-f71.google.com with SMTP id 65so14771735wmd.8 for ; Fri, 03 Jul 2020 02:05:08 -0700 (PDT) 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=3ExkqCYE+MZcrtgAoyxaOOvh3MgXkaeP71bTYP6/+H0=; b=og+EDe3m9CvqcQbLUg/aqk+rt9iH7SxJATieZAQJyyWCfh3f1V0Gykq/zxdNBVM3M2 e/HARdbbQvujUX3idc1hXqhxn1RXpFHnWedpgz/YUy8BZhJcRUnlwLRjDcC/injXh3Iq WBDpQPlCIqYbWlRFZ4ekSbqpFKi74nRtEcuYqyMTDNQh/k8hbbyZsxq3zLe/vqXQ7kis j0a7/UUYDXGevpMdhBc7DVsoDYimSaj4HOy/HlkifpqQOEhS2OlhNdkTEuzZucWlDO7w mBKDa/UdGv68WG4jWQkB3E1pHKyUkci9/x42RvRPBt9yYhwbxBTJO8XOdYFE/8Qr+XfD CUAg== X-Gm-Message-State: AOAM533IOlFOKR3JXcKGLq5DYzVOu8SxnIphgDET6t7iRuWwEUj+LbcA 4HfQPqbui5WzOF+jGR+YVUXq4w9aJyMJ4dQivR65wlz69n/Pq568r2FqTHE6N5b5w8T9uDAhoMy Q22RmNVCbYwg6CTM= X-Received: by 2002:a1c:4143:: with SMTP id o64mr2838340wma.11.1593767107090; Fri, 03 Jul 2020 02:05:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywwa0yMx9DCHIvQEsFAMlyXhDgw0mPGKsNi9muvCkmmtX8fHNf0jIULbV8dMJY5VDtyd2wGA== X-Received: by 2002:a1c:4143:: with SMTP id o64mr2838324wma.11.1593767106922; Fri, 03 Jul 2020 02:05:06 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id d10sm13689266wrx.66.2020.07.03.02.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:06 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:04 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 36/41] vhost: implement vhost_vq_get_addr method Message-ID: <20200703090252.368694-37-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu use vhost_vq_get_addr callback to get the vq address from backend Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-10-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- include/hw/virtio/vhost-backend.h | 4 ++++ hw/virtio/vhost.c | 28 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index fa84abac97..bfc24207e2 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -118,6 +118,9 @@ typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev, struct vhost_vring_addr *addr, struct vhost_virtqueue *vq); + +typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id); + typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -160,6 +163,7 @@ typedef struct VhostOps { vhost_set_inflight_fd_op vhost_set_inflight_fd; vhost_dev_start_op vhost_dev_start; vhost_vq_get_addr_op vhost_vq_get_addr; + vhost_get_device_id_op vhost_get_device_id; } VhostOps; extern const VhostOps user_ops; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 32809e54b5..1e083a8976 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -773,15 +773,25 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, struct vhost_virtqueue *vq, unsigned idx, bool enable_log) { - struct vhost_vring_addr addr = { - .index = idx, - .desc_user_addr = (uint64_t)(unsigned long)vq->desc, - .avail_user_addr = (uint64_t)(unsigned long)vq->avail, - .used_user_addr = (uint64_t)(unsigned long)vq->used, - .log_guest_addr = vq->used_phys, - .flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0, - }; - int r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr); + struct vhost_vring_addr addr; + int r; + memset(&addr, 0, sizeof(struct vhost_vring_addr)); + + if (dev->vhost_ops->vhost_vq_get_addr) { + r = dev->vhost_ops->vhost_vq_get_addr(dev, &addr, vq); + if (r < 0) { + VHOST_OPS_DEBUG("vhost_vq_get_addr failed"); + return -errno; + } + } else { + addr.desc_user_addr = (uint64_t)(unsigned long)vq->desc; + addr.avail_user_addr = (uint64_t)(unsigned long)vq->avail; + addr.used_user_addr = (uint64_t)(unsigned long)vq->used; + } + addr.index = idx; + addr.log_guest_addr = vq->used_phys; + addr.flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0; + r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr); if (r < 0) { VHOST_OPS_DEBUG("vhost_set_vring_addr failed"); return -errno; From patchwork Fri Jul 3 09:05:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GzXDLl34; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqG74SKCz9sPF for ; Fri, 3 Jul 2020 19:21:19 +1000 (AEST) Received: from localhost ([::1]:38178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHsj-0000SR-4X for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHdE-0001OB-42 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:16 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:45684 helo=us-smtp-delivery-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 1jrHdC-0004cT-5v for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767113; 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=zxsZyEl0Ic2zeqGPCHFNr5fX901vp9gn578GtCCySkg=; b=GzXDLl34WaNEJZhZSqccwFGR06/C0l8Tu1mrYK+hPop97riVRqGbaL0j2bkkqBeCOH3TiE eSEdzIeN/VS0I5roONxHUY2hRcw3BK/GPJFwnbzWZkzOMKGehWllbi3+guPmjAsdX9KcoT R8Lrqr2+DNtVGUYCybiCX7bHOuRvhOM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-q6ZgD4AKPQSjHoxyicTQGA-1; Fri, 03 Jul 2020 05:05:10 -0400 X-MC-Unique: q6ZgD4AKPQSjHoxyicTQGA-1 Received: by mail-wm1-f72.google.com with SMTP id v6so32317049wmg.1 for ; Fri, 03 Jul 2020 02:05:10 -0700 (PDT) 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=zxsZyEl0Ic2zeqGPCHFNr5fX901vp9gn578GtCCySkg=; b=AHgl3qEujd9538jWOdoqpbFZOKtdagzKdt+7+/8thH5s0N4gSNxm5dv0edfoGGnN/g nm3dB0odLomPqjhaUR06nTh+4KUw/miZEsAsaEzAi3wNw4jlmU8spVemZsTJE4xQgQ/x BgBh8cThbcJhhuvtDCciO94zbz7/8uleK1/cR7InErNrhawjlBZ8jifKDDDECvxNlfau Hz8oCDQJk4KDmaTsMDbRXrPRk7DI0Vr55INitj6lKUQ0RUecMomDF7xyI0EnU1Sm57Xg SEM5wIjK0FzzGeLdMCMXMeqrvI49LChtzA6D1z8fSYZ/MzrlNIPfFTdyr4Ku7TWCX2/+ EIbg== X-Gm-Message-State: AOAM53009/VDTlAOEUWNKued4hL4Ak+DOPiaB0edEv2l6jbVS4h8xPLN 01rSKdkFc5uKOon4vvCHc0quaKyn8rr58xBaH/nUxna1slKbeHLZC2faJwgrhqLOZM2Blr9URkG mQwKYwugE6J0lr9U= X-Received: by 2002:a5d:4992:: with SMTP id r18mr33929657wrq.323.1593767109631; Fri, 03 Jul 2020 02:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtr03rcNACSmb0UpIZQYQnkHGUcx0kffoXsoY7GeQbNs+qvVb11RIKvz60jek8LLTOiIuqsg== X-Received: by 2002:a5d:4992:: with SMTP id r18mr33929646wrq.323.1593767109478; Fri, 03 Jul 2020 02:05:09 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id w13sm13166619wrr.67.2020.07.03.02.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:08 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:07 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 37/41] vhost: introduce new VhostOps vhost_force_iommu Message-ID: <20200703090252.368694-38-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=207.211.31.81; envelope-from=mst@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 01:34:15 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu This patch introduces new VhostOps vhost_force_iommu callback to force enable features bit VIRTIO_F_IOMMU_PLATFORM. Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-11-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- include/hw/virtio/vhost-backend.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index bfc24207e2..e7cb8d028c 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -121,6 +121,8 @@ typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev, typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id); +typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev); + typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -164,6 +166,7 @@ typedef struct VhostOps { vhost_dev_start_op vhost_dev_start; vhost_vq_get_addr_op vhost_vq_get_addr; vhost_get_device_id_op vhost_get_device_id; + vhost_force_iommu_op vhost_force_iommu; } VhostOps; extern const VhostOps user_ops; From patchwork Fri Jul 3 09:05:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FreYzMVf; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqH23lQJz9sPF for ; Fri, 3 Jul 2020 19:22:06 +1000 (AEST) Received: from localhost ([::1]:41568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHtU-0001qN-7x for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:22:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHfx-0007XD-41 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:08:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:49476 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 1jrHfv-00055Z-Bt for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:08:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767282; 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=bXQcnI6PvYNrc0EdCBus9d90Kc/4/S8iNwGC64RK2O8=; b=FreYzMVfiSPcuR9AKj79AzKVKaMjSdErfa3yiGtBIknN6lyO+04pTOSRbOJF2QCGhkrpkC xkZTcXwWyTw3jNvIKRlas8UYTk/2JHrEdlMM5cWP6ED5RsrjOgzsbOrVWbhRXIaurHvTmg aWOaZFatbz8BGkcN9u6zNnWgwte1Ys0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-484-wLrpC6gKMPuH8GvHWPUkRg-1; Fri, 03 Jul 2020 05:05:13 -0400 X-MC-Unique: wLrpC6gKMPuH8GvHWPUkRg-1 Received: by mail-wm1-f72.google.com with SMTP id q20so24627333wme.3 for ; Fri, 03 Jul 2020 02:05:13 -0700 (PDT) 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=bXQcnI6PvYNrc0EdCBus9d90Kc/4/S8iNwGC64RK2O8=; b=KYUsEPpURYEl1kxDCRnH8i8sU2XYDGtgo5IyB51Itm7+HI2XTdyeoHOcrNmq8vpTnb uewUhOuhZxWPtB8zNQ4PHdwLfWRzkX9VG85GlZsXedXL/VsSi2pXnP6wNPmp5cUVQ8Hy in1y5aXmE4nF66WRUnzJ9DxnghYoneLlhiJv75Y7nA6LufAFnCgVicDdGxKZv0jHse/5 Pp3Tb9jvFnP4d9AqfHAkyzLwjZ+qrFOPHiG8KkQ8oxwITdIguxNyH/LTqFQKCiLZoBGP i93FaeKG3XoT6xWP82P+b6EoXgjuCMhaqEUQjZbbQX9O8dCz1WxCRLCzbGarqZgjybTS TaNQ== X-Gm-Message-State: AOAM531Tg1H/kSQu7r132vAaIHQYjOjSUaN3pYkUZV/W/UELWJc9mDcH D2GXSHifBwDacQlLzaihs6RPGgUuprV1vCqinwf0uZWHr5yLwfll9/q4ybeu/hfyeXMFJ4Yh+EV QYH2w9AbGy4PT1m8= X-Received: by 2002:a1c:1d93:: with SMTP id d141mr34477670wmd.14.1593767112055; Fri, 03 Jul 2020 02:05:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjpIdA3ZkX/TFOS5m4p7ZaCtC7ekXX+GbpvZSRjFZ+gORBbA3NkH+D1dza128U1TOjWm1J+Q== X-Received: by 2002:a1c:1d93:: with SMTP id d141mr34477653wmd.14.1593767111833; Fri, 03 Jul 2020 02:05:11 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id d63sm13641669wmc.22.2020.07.03.02.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:11 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:09 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 38/41] vhost: implement vhost_force_iommu method Message-ID: <20200703090252.368694-39-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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/03 02:53:25 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu use the vhost_force_iommu callback to force enable feature bit VIRTIO_F_IOMMU_PLATFORM Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-12-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- hw/virtio/vhost.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 1e083a8976..1a1384e7a6 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -810,6 +810,11 @@ static int vhost_dev_set_features(struct vhost_dev *dev, if (!vhost_dev_has_iommu(dev)) { features &= ~(0x1ULL << VIRTIO_F_IOMMU_PLATFORM); } + if (dev->vhost_ops->vhost_force_iommu) { + if (dev->vhost_ops->vhost_force_iommu(dev) == true) { + features |= 0x1ULL << VIRTIO_F_IOMMU_PLATFORM; + } + } r = dev->vhost_ops->vhost_set_features(dev, features); if (r < 0) { VHOST_OPS_DEBUG("vhost_set_features failed"); From patchwork Fri Jul 3 09:05:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cC2t/zq5; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqGN2mvqz9sPF for ; Fri, 3 Jul 2020 19:21:32 +1000 (AEST) Received: from localhost ([::1]:39290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHsw-0000uU-23 for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:21:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHdI-0001YB-C7 for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51858 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 1jrHdG-0004d1-Gj for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767117; 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=lL5Gr+1OC50JlOP4HvsRLOyw+1DMZM80TfKgTML516o=; b=cC2t/zq5/sTgf7LGtO28sVbFSbuukMxf4SK91a+FgFpe6L6L/EkGfOPJbg0Ot5MASv34jD 4rw598et98+PgQPkm+KYedcAsZ9fBcr2HClsD4kSw/XNM91pqdE0Y0Zd8h71osn/bb2ySJ bG3HRHrWh98ZxxfN84kUHc0rO7TXmdA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-w0oIFGEPNRSa9z6DL-RNzw-1; Fri, 03 Jul 2020 05:05:16 -0400 X-MC-Unique: w0oIFGEPNRSa9z6DL-RNzw-1 Received: by mail-wr1-f69.google.com with SMTP id o25so31021879wro.16 for ; Fri, 03 Jul 2020 02:05:16 -0700 (PDT) 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=lL5Gr+1OC50JlOP4HvsRLOyw+1DMZM80TfKgTML516o=; b=qDlmXFFWD1r9Bo+NkNHE0evcM8NLGuztL0AqUBXdMZkKIdIzyJIEW004DZc9OH4Et7 UX2dpFR/D2/edUivJe6xU9FQOH41IAVbqhXr5vGf4mso7GyfVH3RYhFb02oDYwu3XOpk lMM4RpJqmN0qS9S6pOoSPjF0U6WBYXccjWuzVvjqgk2W+D5VdArW+y9kT1aYu4++s3+a X5ZcBFgqfvpBLaT3D0EwVcMkIic0SY6MICB4b8hNR190bSM4TvzApJKl4eTReIS1qlqr XtMqUejekQJDcpNX6q23XyiBwjKoAw7+AwlRZuZ9A9z8XUBQzYtoCEAOgMAqroRfmD1T 9ziA== X-Gm-Message-State: AOAM531ZygJT7vyFSCz1SRjpJwXH0nrgWh3EjH/qyvDtwWA7rxrypW3p OUtBaBqEu4PJ+GNWRKdzcnphJsx9I/Vz/r2PLaIn3hwHZfe4mkIOZ73c1vCl6KzBamwN1QgjpbR 0bfTF3aUQx6rN/HA= X-Received: by 2002:a7b:c5d5:: with SMTP id n21mr35538742wmk.106.1593767114618; Fri, 03 Jul 2020 02:05:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqE3dzdHZcMxlcpdgDkxpfw5Qz5od0FMPxaGCfISCQt9I7/6UPtziHfyN95BgyNnjk4uIdTw== X-Received: by 2002:a7b:c5d5:: with SMTP id n21mr35538721wmk.106.1593767114448; Fri, 03 Jul 2020 02:05:14 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id m4sm13028664wmi.48.2020.07.03.02.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:13 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:12 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 39/41] vhost_net: introduce set_config & get_config Message-ID: <20200703090252.368694-40-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu This patch introduces set_config & get_config method which allows vhost_net set/get the config to backend Signed-off-by: Cindy Lu Message-Id: <20200701145538.22333-13-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- include/net/vhost_net.h | 5 +++++ hw/net/vhost_net-stub.c | 11 +++++++++++ hw/net/vhost_net.c | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 77e47398c4..172b0051d8 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -28,6 +28,11 @@ void vhost_net_cleanup(VHostNetState *net); uint64_t vhost_net_get_features(VHostNetState *net, uint64_t features); void vhost_net_ack_features(VHostNetState *net, uint64_t features); +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, + uint32_t config_len); + +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags); bool vhost_net_virtqueue_pending(VHostNetState *net, int n); void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, int idx, bool mask); diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index aac0e98228..a7f4252630 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -52,6 +52,17 @@ uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) return features; } +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, + uint32_t config_len) +{ + return 0; +} +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags) +{ + return 0; +} + void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { } diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 4096d64aaf..4561665f6b 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -110,6 +110,16 @@ uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) return vhost_get_features(&net->dev, vhost_net_get_feature_bits(net), features); } +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, + uint32_t config_len) +{ + return vhost_dev_get_config(&net->dev, config, config_len); +} +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags) +{ + return vhost_dev_set_config(&net->dev, data, offset, size, flags); +} void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { From patchwork Fri Jul 3 09:05:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322245 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U76BkEwI; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqJD6cv1z9sPF for ; Fri, 3 Jul 2020 19:23:08 +1000 (AEST) Received: from localhost ([::1]:45244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHuU-0003Qa-GJ for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHdO-0001nW-9E for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:26 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:48647 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 1jrHdK-0004dR-LO for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767122; 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=y5Gr5Ukx7zUi46vU2MndaaFzmywkCRZDO2bIKh6rRW0=; b=U76BkEwIUFts+NfOQKLxPE4QfucZRUL/mPrdSkYF7CGXsKtxRobsx75bJVhjQuufD4/DQe eFiPIJw2WjYJo6Co+TKux3cOY8qHO1w46WtaxLkFMJo+dpu5gF3dxkOjT4VlXzOlhvre47 A3Qdxso94F1t0PzwPb48abHxu20AKGs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-66-ibdZ67sZOqankZNiUQXU4w-1; Fri, 03 Jul 2020 05:05:19 -0400 X-MC-Unique: ibdZ67sZOqankZNiUQXU4w-1 Received: by mail-wm1-f70.google.com with SMTP id s134so34553484wme.6 for ; Fri, 03 Jul 2020 02:05:19 -0700 (PDT) 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=y5Gr5Ukx7zUi46vU2MndaaFzmywkCRZDO2bIKh6rRW0=; b=DwhNmIRuuwkj/ZgUPUhUqtEL4GZH7KAaQ2rbJJSVXjKs8d6qgqGVJS1YFTNCjK+XRD D22Z+5DzU0E7g5VJiBCrNDpDbU7RbuLtHuUI+nYkov5NWZfNJCi775a60nYbjLb/8spe OYWeHopu7uJmr4SIYj/DWOKbFoh1jVZW1ltuyYqO08+zdgsqgqAE9Ul4Oqbgl4EKij2/ baIHnS+UjM76lJZ8320F0gy9GyZQkiNUgE6uil215ovMrRvqCnPrwyX/86JsB+HX36d1 sampIsjvjSkVacgfp8KIXA/Xm8fMxTvdC7LTd17vhYf7jgJQZ8XE3cL4QGkvPTBtAKZp 3KTg== X-Gm-Message-State: AOAM532Xc5LswwyNWrblc3MhDga00GyTrICwGYXm0XjxMA+OyVcloXeA 4oVFknjDK0ILWdE4QzjPtcsNBMjrEoeaGWReDJDj/GdZnEQFOrGEn8Kcj82QH8oX+W+sFrK2Uf1 KRErqiLwGccdbE2M= X-Received: by 2002:a5d:4dc2:: with SMTP id f2mr36443894wru.399.1593767117760; Fri, 03 Jul 2020 02:05:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymKW8aC4xJE7d+N/112d7lQjXBJAx2wO9glbhWqppzyhlKqyLEyQVPXfSRSxCuHuvqW/AFEA== X-Received: by 2002:a5d:4dc2:: with SMTP id f2mr36443837wru.399.1593767117097; Fri, 03 Jul 2020 02:05:17 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id b62sm12760136wmh.38.2020.07.03.02.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:16 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:14 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 40/41] vhost-vdpa: introduce vhost-vdpa backend Message-ID: <20200703090252.368694-41-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Jason Wang , Peter Maydell , Lingshan zhu , Tiwei Bie , Cindy Lu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu Currently we have 2 types of vhost backends in QEMU: vhost kernel and vhost-user. The above patch provides a generic device for vDPA purpose, this vDPA device exposes to user space a non-vendor-specific configuration interface for setting up a vhost HW accelerator, this patch set introduces a third vhost backend called vhost-vdpa based on the vDPA interface. Vhost-vdpa usage: qemu-system-x86_64 -cpu host -enable-kvm \ ...... -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ Signed-off-by: Lingshan zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu Signed-off-by: Jason Wang Message-Id: <20200701145538.22333-14-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- configure | 21 ++ include/hw/virtio/vhost-backend.h | 4 +- include/hw/virtio/vhost-vdpa.h | 26 ++ include/hw/virtio/vhost.h | 7 + hw/net/vhost_net.c | 19 +- hw/net/virtio-net.c | 19 ++ hw/virtio/vhost-backend.c | 6 + hw/virtio/vhost-vdpa.c | 475 ++++++++++++++++++++++++++++++ docs/interop/index.rst | 1 + docs/interop/vhost-vdpa.rst | 17 ++ hw/virtio/Makefile.objs | 1 + qemu-options.hx | 12 + 12 files changed, 601 insertions(+), 7 deletions(-) create mode 100644 include/hw/virtio/vhost-vdpa.h create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 docs/interop/vhost-vdpa.rst diff --git a/configure b/configure index 4a22dcd563..3db7f20185 100755 --- a/configure +++ b/configure @@ -1575,6 +1575,10 @@ for opt do ;; --enable-vhost-user) vhost_user="yes" ;; + --disable-vhost-vdpa) vhost_vdpa="no" + ;; + --enable-vhost-vdpa) vhost_vdpa="yes" + ;; --disable-vhost-kernel) vhost_kernel="no" ;; --enable-vhost-kernel) vhost_kernel="yes" @@ -1883,6 +1887,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-crypto vhost-user-crypto backend support vhost-kernel vhost kernel backend support vhost-user vhost-user backend support + vhost-vdpa vhost-vdpa kernel backend support spice spice rbd rados block device (rbd) libiscsi iscsi support @@ -2394,6 +2399,10 @@ test "$vhost_user" = "" && vhost_user=yes if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then error_exit "vhost-user isn't available on win32" fi +test "$vhost_vdpa" = "" && vhost_vdpa=$linux +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then + error_exit "vhost-vdpa is only available on Linux" +fi test "$vhost_kernel" = "" && vhost_kernel=$linux if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then error_exit "vhost-kernel is only available on Linux" @@ -2422,6 +2431,11 @@ test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then error_exit "--enable-vhost-user-fs requires --enable-vhost-user" fi +#vhost-vdpa backends +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" +fi # OR the vhost-kernel and vhost-user values for simplicity if test "$vhost_net" = ""; then @@ -6936,6 +6950,7 @@ echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "vhost-user-fs support $vhost_user_fs" +echo "vhost-vdpa support $vhost_vdpa" echo "Trace backends $trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -7437,6 +7452,9 @@ fi if test "$vhost_net_user" = "yes" ; then echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak fi +if test "$vhost_net_vdpa" = "yes" ; then + echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak +fi if test "$vhost_crypto" = "yes" ; then echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak fi @@ -7452,6 +7470,9 @@ fi if test "$vhost_user" = "yes" ; then echo "CONFIG_VHOST_USER=y" >> $config_host_mak fi +if test "$vhost_vdpa" = "yes" ; then + echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak +fi if test "$vhost_user_fs" = "yes" ; then echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak fi diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index e7cb8d028c..8825bd278f 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -17,7 +17,8 @@ typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE = 0, VHOST_BACKEND_TYPE_KERNEL = 1, VHOST_BACKEND_TYPE_USER = 2, - VHOST_BACKEND_TYPE_MAX = 3, + VHOST_BACKEND_TYPE_VDPA = 3, + VHOST_BACKEND_TYPE_MAX = 4, } VhostBackendType; typedef enum VhostSetConfigType { @@ -170,6 +171,7 @@ typedef struct VhostOps { } VhostOps; extern const VhostOps user_ops; +extern const VhostOps vdpa_ops; int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type); diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h new file mode 100644 index 0000000000..6455663388 --- /dev/null +++ b/include/hw/virtio/vhost-vdpa.h @@ -0,0 +1,26 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef HW_VIRTIO_VHOST_VDPA_H +#define HW_VIRTIO_VHOST_VDPA_H + +#include "hw/virtio/virtio.h" + +typedef struct vhost_vdpa { + int device_fd; + uint32_t msg_type; + MemoryListener listener; +} VhostVDPA; + +extern AddressSpace address_space_memory; +extern int vhost_vdpa_get_device_id(struct vhost_dev *dev, + uint32_t *device_id); +#endif diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 085450c6f8..767a95ec0b 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -92,6 +92,13 @@ struct vhost_dev { const VhostDevConfigOps *config_ops; }; +struct vhost_net { + struct vhost_dev dev; + struct vhost_virtqueue vqs[2]; + int backend; + NetClientState *nc; +}; + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout); diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 4561665f6b..e165594cf3 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -17,8 +17,10 @@ #include "net/net.h" #include "net/tap.h" #include "net/vhost-user.h" +#include "net/vhost-vdpa.h" #include "standard-headers/linux/vhost_types.h" +#include "linux-headers/linux/vhost.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "qemu/error-report.h" @@ -33,12 +35,6 @@ #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" -struct vhost_net { - struct vhost_dev dev; - struct vhost_virtqueue vqs[2]; - int backend; - NetClientState *nc; -}; /* Features supported by host kernel. */ static const int kernel_feature_bits[] = { @@ -96,6 +92,11 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net) case NET_CLIENT_DRIVER_VHOST_USER: feature_bits = user_feature_bits; break; +#ifdef CONFIG_VHOST_NET_VDPA + case NET_CLIENT_DRIVER_VHOST_VDPA: + feature_bits = vdpa_feature_bits; + break; +#endif default: error_report("Feature bits not defined for this type: %d", net->nc->info->type); @@ -443,6 +444,12 @@ VHostNetState *get_vhost_net(NetClientState *nc) vhost_net = vhost_user_get_vhost_net(nc); assert(vhost_net); break; +#endif +#ifdef CONFIG_VHOST_NET_VDPA + case NET_CLIENT_DRIVER_VHOST_VDPA: + vhost_net = vhost_vdpa_get_vhost_net(nc); + assert(vhost_net); + break; #endif default: break; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index aff67a92df..0a54b1910a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -43,6 +43,7 @@ #include "monitor/qdev.h" #include "hw/pci/pci.h" #include "net_rx_pkt.h" +#include "hw/virtio/vhost.h" #define VIRTIO_NET_VM_VERSION 11 @@ -125,6 +126,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) VirtIONet *n = VIRTIO_NET(vdev); struct virtio_net_config netcfg; + int ret = 0; + memset(&netcfg, 0 , sizeof(struct virtio_net_config)); virtio_stw_p(vdev, &netcfg.status, n->status); virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues); virtio_stw_p(vdev, &netcfg.mtu, n->net_conf.mtu); @@ -138,6 +141,15 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) virtio_stl_p(vdev, &netcfg.supported_hash_types, VIRTIO_NET_RSS_SUPPORTED_HASHES); memcpy(config, &netcfg, n->config_size); + + NetClientState *nc = qemu_get_queue(n->nic); + if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { + ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, + n->config_size); + if (ret != -1) { + memcpy(config, &netcfg, n->config_size); + } + } } static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) @@ -153,6 +165,13 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) memcpy(n->mac, netcfg.mac, ETH_ALEN); qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); } + + NetClientState *nc = qemu_get_queue(n->nic); + if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { + vhost_net_set_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, + 0, n->config_size, + VHOST_SET_CONFIG_TYPE_MASTER); + } } static bool virtio_net_started(VirtIONet *n, uint8_t status) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 48905383f8..782b1d67d9 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -15,6 +15,7 @@ #include "qemu/main-loop.h" #include "standard-headers/linux/vhost_types.h" +#include "hw/virtio/vhost-vdpa.h" #ifdef CONFIG_VHOST_KERNEL #include #include @@ -285,6 +286,11 @@ int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type) case VHOST_BACKEND_TYPE_USER: dev->vhost_ops = &user_ops; break; +#endif +#ifdef CONFIG_VHOST_VDPA + case VHOST_BACKEND_TYPE_VDPA: + dev->vhost_ops = &vdpa_ops; + break; #endif default: error_report("Unknown vhost backend type"); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c new file mode 100644 index 0000000000..6f2b01c25e --- /dev/null +++ b/hw/virtio/vhost-vdpa.c @@ -0,0 +1,475 @@ +/* + * vhost-vdpa + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include +#include +#include +#include +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-backend.h" +#include "hw/virtio/virtio-net.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qemu/main-loop.h" +#include +#include "sysemu/kvm.h" + +static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section) +{ + return (!memory_region_is_ram(section->mr) && + !memory_region_is_iommu(section->mr)) || + /* + * Sizing an enabled 64-bit BAR can cause spurious mappings to + * addresses in the upper part of the 64-bit address space. These + * are never accessed by the CPU and beyond the address width of + * some IOMMU hardware. TODO: VDPA should tell us the IOMMU width. + */ + section->offset_within_address_space & (1ULL << 63); +} + +static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, + void *vaddr, bool readonly) +{ + struct vhost_msg_v2 msg; + int fd = v->device_fd; + int ret = 0; + + msg.type = v->msg_type; + msg.iotlb.iova = iova; + msg.iotlb.size = size; + msg.iotlb.uaddr = (uint64_t)vaddr; + msg.iotlb.perm = readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; + msg.iotlb.type = VHOST_IOTLB_UPDATE; + + if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { + error_report("failed to write, fd=%d, errno=%d (%s)", + fd, errno, strerror(errno)); + return -EIO ; + } + + return ret; +} + +static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, + hwaddr size) +{ + struct vhost_msg_v2 msg; + int fd = v->device_fd; + int ret = 0; + + msg.type = v->msg_type; + msg.iotlb.iova = iova; + msg.iotlb.size = size; + msg.iotlb.type = VHOST_IOTLB_INVALIDATE; + + if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { + error_report("failed to write, fd=%d, errno=%d (%s)", + fd, errno, strerror(errno)); + return -EIO ; + } + + return ret; +} + +static void vhost_vdpa_listener_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); + hwaddr iova; + Int128 llend, llsize; + void *vaddr; + int ret; + + if (vhost_vdpa_listener_skipped_section(section)) { + return; + } + + if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != + (section->offset_within_region & ~TARGET_PAGE_MASK))) { + error_report("%s received unaligned region", __func__); + return; + } + + iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); + llend = int128_make64(section->offset_within_address_space); + llend = int128_add(llend, section->size); + llend = int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); + + if (int128_ge(int128_make64(iova), llend)) { + return; + } + + memory_region_ref(section->mr); + + /* Here we assume that memory_region_is_ram(section->mr)==true */ + + vaddr = memory_region_get_ram_ptr(section->mr) + + section->offset_within_region + + (iova - section->offset_within_address_space); + + llsize = int128_sub(llend, int128_make64(iova)); + + ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize), + vaddr, section->readonly); + if (ret) { + error_report("vhost vdpa map fail!"); + if (memory_region_is_ram_device(section->mr)) { + /* Allow unexpected mappings not to be fatal for RAM devices */ + error_report("map ram fail!"); + return ; + } + goto fail; + } + + return; + +fail: + if (memory_region_is_ram_device(section->mr)) { + error_report("failed to vdpa_dma_map. pci p2p may not work"); + return; + + } + /* + * On the initfn path, store the first error in the container so we + * can gracefully fail. Runtime, there's not much we can do other + * than throw a hardware error. + */ + error_report("vhost-vdpa: DMA mapping failed, unable to continue"); + return; + +} + +static void vhost_vdpa_listener_region_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); + hwaddr iova; + Int128 llend, llsize; + int ret; + bool try_unmap = true; + + if (vhost_vdpa_listener_skipped_section(section)) { + return; + } + + if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != + (section->offset_within_region & ~TARGET_PAGE_MASK))) { + error_report("%s received unaligned region", __func__); + return; + } + + iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); + llend = int128_make64(section->offset_within_address_space); + llend = int128_add(llend, section->size); + llend = int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); + + if (int128_ge(int128_make64(iova), llend)) { + return; + } + + llsize = int128_sub(llend, int128_make64(iova)); + + if (try_unmap) { + ret = vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize)); + if (ret) { + error_report("vhost_vdpa dma unmap error!"); + } + } + + memory_region_unref(section->mr); +} +/* + * IOTLB API is used by vhost-vpda which requires incremental updating + * of the mapping. So we can not use generic vhost memory listener which + * depends on the addnop(). + */ +static const MemoryListener vhost_vdpa_memory_listener = { + .region_add = vhost_vdpa_listener_region_add, + .region_del = vhost_vdpa_listener_region_del, +}; + +static int vhost_vdpa_call(struct vhost_dev *dev, unsigned long int request, + void *arg) +{ + struct vhost_vdpa *v = dev->opaque; + int fd = v->device_fd; + + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); + + return ioctl(fd, request, arg); +} + +static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) +{ + uint8_t s; + + if (vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s)) { + return; + } + + s |= status; + + vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); +} + +static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) +{ + struct vhost_vdpa *v; + uint64_t features; + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); + + v = opaque; + dev->opaque = opaque ; + vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features); + dev->backend_features = features; + v->listener = vhost_vdpa_memory_listener; + v->msg_type = VHOST_IOTLB_MSG_V2; + + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + + return 0; +} + +static int vhost_vdpa_cleanup(struct vhost_dev *dev) +{ + struct vhost_vdpa *v; + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); + v = dev->opaque; + memory_listener_unregister(&v->listener); + + dev->opaque = NULL; + return 0; +} + +static int vhost_vdpa_memslots_limit(struct vhost_dev *dev) +{ + return INT_MAX; +} + +static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, + struct vhost_memory *mem) +{ + + if (mem->padding) { + return -1; + } + + return 0; +} + +static int vhost_vdpa_set_features(struct vhost_dev *dev, + uint64_t features) +{ + int ret; + ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); + uint8_t status = 0; + if (ret) { + return ret; + } + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); + vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); + + return !(status & VIRTIO_CONFIG_S_FEATURES_OK); +} + +int vhost_vdpa_get_device_id(struct vhost_dev *dev, + uint32_t *device_id) +{ + return vhost_vdpa_call(dev, VHOST_VDPA_GET_DEVICE_ID, device_id); +} + +static int vhost_vdpa_reset_device(struct vhost_dev *dev) +{ + uint8_t status = 0; + + return vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); +} + +static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) +{ + assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs); + + return idx - dev->vq_index; +} + +static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev) +{ + int i; + for (i = 0; i < dev->nvqs; ++i) { + struct vhost_vring_state state = { + .index = dev->vq_index + i, + .num = 1, + }; + vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state); + } + return 0; +} + +static int vhost_vdpa_set_config(struct vhost_dev *dev, const uint8_t *data, + uint32_t offset, uint32_t size, + uint32_t flags) +{ + struct vhost_vdpa_config *config; + int ret; + unsigned long config_size = offsetof(struct vhost_vdpa_config, buf); + config = g_malloc(size + config_size); + if (config == NULL) { + return -1; + } + config->off = offset; + config->len = size; + memcpy(config->buf, data, size); + ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG, config); + g_free(config); + return ret; +} + +static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, + uint32_t config_len) +{ + struct vhost_vdpa_config *v_config; + unsigned long config_size = offsetof(struct vhost_vdpa_config, buf); + int ret; + + v_config = g_malloc(config_len + config_size); + if (v_config == NULL) { + return -1; + } + v_config->len = config_len; + v_config->off = 0; + ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_CONFIG, v_config); + memcpy(config, v_config->buf, config_len); + g_free(v_config); + return ret; + } + +static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) +{ + struct vhost_vdpa *v = dev->opaque; + if (started) { + uint8_t status = 0; + memory_listener_register(&v->listener, &address_space_memory); + vhost_vdpa_set_vring_ready(dev); + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); + vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); + + return !(status & VIRTIO_CONFIG_S_DRIVER_OK); + } else { + vhost_vdpa_reset_device(dev); + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + memory_listener_unregister(&v->listener); + + return 0; + } +} + +static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log) +{ + return vhost_vdpa_call(dev, VHOST_SET_LOG_BASE, &base); +} + +static int vhost_vdpa_set_vring_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); +} + +static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_NUM, ring); +} + +static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); +} + +static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + return vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); +} + +static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, + struct vhost_vring_file *file) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); +} + +static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, + struct vhost_vring_file *file) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); +} + +static int vhost_vdpa_get_features(struct vhost_dev *dev, + uint64_t *features) +{ + return vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); +} + +static int vhost_vdpa_set_owner(struct vhost_dev *dev) +{ + return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL); +} + +static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr, struct vhost_virtqueue *vq) +{ + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); + addr->desc_user_addr = (uint64_t)(unsigned long)vq->desc_phys; + addr->avail_user_addr = (uint64_t)(unsigned long)vq->avail_phys; + addr->used_user_addr = (uint64_t)(unsigned long)vq->used_phys; + return 0; +} + +static bool vhost_vdpa_force_iommu(struct vhost_dev *dev) +{ + return true; +} + +const VhostOps vdpa_ops = { + .backend_type = VHOST_BACKEND_TYPE_VDPA, + .vhost_backend_init = vhost_vdpa_init, + .vhost_backend_cleanup = vhost_vdpa_cleanup, + .vhost_set_log_base = vhost_vdpa_set_log_base, + .vhost_set_vring_addr = vhost_vdpa_set_vring_addr, + .vhost_set_vring_num = vhost_vdpa_set_vring_num, + .vhost_set_vring_base = vhost_vdpa_set_vring_base, + .vhost_get_vring_base = vhost_vdpa_get_vring_base, + .vhost_set_vring_kick = vhost_vdpa_set_vring_kick, + .vhost_set_vring_call = vhost_vdpa_set_vring_call, + .vhost_get_features = vhost_vdpa_get_features, + .vhost_set_owner = vhost_vdpa_set_owner, + .vhost_set_vring_endian = NULL, + .vhost_backend_memslots_limit = vhost_vdpa_memslots_limit, + .vhost_set_mem_table = vhost_vdpa_set_mem_table, + .vhost_set_features = vhost_vdpa_set_features, + .vhost_reset_device = vhost_vdpa_reset_device, + .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_get_config = vhost_vdpa_get_config, + .vhost_set_config = vhost_vdpa_set_config, + .vhost_requires_shm_log = NULL, + .vhost_migration_done = NULL, + .vhost_backend_can_merge = NULL, + .vhost_net_set_mtu = NULL, + .vhost_set_iotlb_callback = NULL, + .vhost_send_device_iotlb_msg = NULL, + .vhost_dev_start = vhost_vdpa_dev_start, + .vhost_get_device_id = vhost_vdpa_get_device_id, + .vhost_vq_get_addr = vhost_vdpa_vq_get_addr, + .vhost_force_iommu = vhost_vdpa_force_iommu, +}; diff --git a/docs/interop/index.rst b/docs/interop/index.rst index 049387ac6d..006f986420 100644 --- a/docs/interop/index.rst +++ b/docs/interop/index.rst @@ -20,3 +20,4 @@ Contents: qemu-ga vhost-user vhost-user-gpu + vhost-vdpa diff --git a/docs/interop/vhost-vdpa.rst b/docs/interop/vhost-vdpa.rst new file mode 100644 index 0000000000..0c70ba01bc --- /dev/null +++ b/docs/interop/vhost-vdpa.rst @@ -0,0 +1,17 @@ +===================== +Vhost-vdpa Protocol +===================== + +Introduction +============= +vDPA(Virtual data path acceleration) device is a device that uses +a datapath which complies with the virtio specifications with vendor +specific control path. vDPA devices can be both physically located on +the hardware or emulated by software. + +This document describes the vDPA support in qemu + +Here is the kernel commit here +https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4c8cf31885f69e86be0b5b9e6677a26797365e1d + +TODO : More information will add later diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index a986708186..fc91719b4a 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -5,6 +5,7 @@ obj-y += virtio.o obj-$(CONFIG_VHOST) += vhost.o vhost-backend.o common-obj-$(call lnot,$(CONFIG_VHOST)) += vhost-stub.o obj-$(CONFIG_VHOST_USER) += vhost-user.o +obj-$(CONFIG_VHOST_VDPA) += vhost-vdpa.o common-obj-$(CONFIG_VIRTIO_RNG) += virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o diff --git a/qemu-options.hx b/qemu-options.hx index 196f468786..fa1b19de4c 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2418,6 +2418,10 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, #ifdef CONFIG_POSIX "-netdev vhost-user,id=str,chardev=dev[,vhostforce=on|off]\n" " configure a vhost-user network, backed by a chardev 'dev'\n" +#endif +#ifdef __linux__ + "-netdev vhost-vdpa,id=str,vhostdev=/path/to/dev\n" + " configure a vhost-vdpa network,Establish a vhost-vdpa netdev\n" #endif "-netdev hubport,id=str,hubid=n[,netdev=nd]\n" " configure a hub port on the hub with ID 'n'\n", QEMU_ARCH_ALL) @@ -2897,6 +2901,14 @@ SRST -netdev type=vhost-user,id=net0,chardev=chr0 \ -device virtio-net-pci,netdev=net0 +``-netdev vhost-vdpa,vhostdev=/path/to/dev`` + Establish a vhost-vdpa netdev. + + vDPA device is a device that uses a datapath which complies with + the virtio specifications with a vendor specific control path. + vDPA devices can be both physically located on the hardware or + emulated by software. + ``-netdev hubport,id=id,hubid=hubid[,netdev=nd]`` Create a hub port on the emulated hub with ID hubid. From patchwork Fri Jul 3 09:05:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1322249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dC0fr232; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yqL54gpMz9sPF for ; Fri, 3 Jul 2020 19:24:45 +1000 (AEST) Received: from localhost ([::1]:54022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrHw3-0007Jf-By for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2020 05:24:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrHdP-0001sJ-QE for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51539 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 1jrHdM-0004dk-PK for qemu-devel@nongnu.org; Fri, 03 Jul 2020 05:05:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593767124; 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=4lWrpFH2CiygCO5uciNVA5FaqB2VaYbCK0AZiDA9UeM=; b=dC0fr232nKPleewPy//UtgLzYptzlUYVRp9cu7AEWc9JatR+IDxCME0Owwr3rlNs/75vmA 8IlGYuN21IJFFAbtLlm3o8QVGt5GN0+xTW0qf6h6ynAb+NmV5AAsBaIqvxRYRFO0CEDCy3 u2jlFE6ZlurMhANz/EzSPtyW1ZdHpkw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-3my4vMv-OB2a-WOkJSudRA-1; Fri, 03 Jul 2020 05:05:22 -0400 X-MC-Unique: 3my4vMv-OB2a-WOkJSudRA-1 Received: by mail-wr1-f72.google.com with SMTP id j5so31095377wro.6 for ; Fri, 03 Jul 2020 02:05:22 -0700 (PDT) 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=4lWrpFH2CiygCO5uciNVA5FaqB2VaYbCK0AZiDA9UeM=; b=W6u/neug59BYNNGzvVfMlKtvpmGJiS4dTxZ19oy6tYr/sUTONFLHfJV0B2agkwK6Uy XG0aGYh9TxFCkKB/zeBqIznkxkPtQqD+bazQgqWNNDkuEuIXeX9ukiRDUv19Q2D44Bwe b+HWehcGmAKDvzWw2uDYQZA+VDaTKyamBAUPdkSSm/zY1ScxajnL1daqpU00LJ2/drDE Wk6SyFL/zxI+VTUhMUw+xe5mwZrpmAEWv1DF6f47ZA6+IFb447BRwLMwFAWxI0RpoEWZ sVm92X1cj0rg/w97zhqh/zyEbhlhTDRztiZEXUE9XPBAFV/JleGQJPyfrsNTwiwGaenV BEDQ== X-Gm-Message-State: AOAM532Au8phhxi+cwCgvg9ZbDcYEBgYOOQQ37pNB7qT//Q+bGbv2lko Ze4F6x+sxhu3YcfM8OPzqPQijEW9fHEa4f5jpPEhXaRrfEfb8Wg9VVQHdwHOt6srOdv/RdDldzF FkRKwe0h4pgGtnWM= X-Received: by 2002:adf:fa81:: with SMTP id h1mr37517276wrr.288.1593767120688; Fri, 03 Jul 2020 02:05:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyndo4k2CJKMNmigFNFENSZMbKA+5k3QpYp17PU0YGF22QZO0UIugjtWebpjI7nFBhdxRwCXQ== X-Received: by 2002:adf:fa81:: with SMTP id h1mr37517234wrr.288.1593767120301; Fri, 03 Jul 2020 02:05:20 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id g145sm4297039wmg.23.2020.07.03.02.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 02:05:19 -0700 (PDT) Date: Fri, 3 Jul 2020 05:05:17 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 41/41] vhost-vdpa: introduce vhost-vdpa net client Message-ID: <20200703090252.368694-42-mst@redhat.com> References: <20200703090252.368694-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200703090252.368694-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=mst@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/03 03:38:32 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: Peter Maydell , Cindy Lu , Tiwei Bie , Jason Wang , Markus Armbruster , Lingshan Zhu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu This patch set introduces a new net client type: vhost-vdpa. vhost-vdpa net client will set up a vDPA device which is specified by a "vhostdev" parameter. Signed-off-by: Lingshan Zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu Signed-off-by: Jason Wang Message-Id: <20200701145538.22333-15-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang --- qapi/net.json | 28 ++++- include/net/vhost-vdpa.h | 22 ++++ net/clients.h | 2 + net/net.c | 3 + net/vhost-vdpa.c | 228 +++++++++++++++++++++++++++++++++++++++ net/Makefile.objs | 2 +- 6 files changed, 282 insertions(+), 3 deletions(-) create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c diff --git a/qapi/net.json b/qapi/net.json index 9244c9af56..558d520a2f 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -428,16 +428,39 @@ '*vhostforce': 'bool', '*queues': 'int' } } +## +# @NetdevVhostVDPAOptions: +# +# Vhost-vdpa network backend +# +# vDPA device is a device that uses a datapath which complies with the virtio +# specifications with a vendor specific control path. +# +# @vhostdev: path of vhost-vdpa device +# (default:'/dev/vhost-vdpa-0') +# +# @queues: number of queues to be created for multiqueue vhost-vdpa +# (default: 1) +# +# Since: 5.1 +## +{ 'struct': 'NetdevVhostVDPAOptions', + 'data': { + '*vhostdev': 'str', + '*queues': 'int' } } + ## # @NetClientDriver: # # Available netdev drivers. # # Since: 2.7 +# +# @vhost-vdpa since 5.1 ## { 'enum': 'NetClientDriver', 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', - 'bridge', 'hubport', 'netmap', 'vhost-user' ] } + 'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] } ## # @Netdev: @@ -465,7 +488,8 @@ 'bridge': 'NetdevBridgeOptions', 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', - 'vhost-user': 'NetdevVhostUserOptions' } } + 'vhost-user': 'NetdevVhostUserOptions', + 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } ## # @NetFilterDirection: diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h new file mode 100644 index 0000000000..45e34b7cfc --- /dev/null +++ b/include/net/vhost-vdpa.h @@ -0,0 +1,22 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef VHOST_VDPA_H +#define VHOST_VDPA_H + +#define TYPE_VHOST_VDPA "vhost-vdpa" + +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); + +extern const int vdpa_feature_bits[]; + +#endif /* VHOST_VDPA_H */ diff --git a/net/clients.h b/net/clients.h index a6ef267e19..92f9b59aed 100644 --- a/net/clients.h +++ b/net/clients.h @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char *name, int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp); #endif /* QEMU_NET_CLIENTS_H */ diff --git a/net/net.c b/net/net.c index 9099a327dd..94dc546fb2 100644 --- a/net/net.c +++ b/net/net.c @@ -966,6 +966,9 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( #ifdef CONFIG_VHOST_NET_USER [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, #endif +#ifdef CONFIG_VHOST_NET_VDPA + [NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, +#endif #ifdef CONFIG_L2TPV3 [NET_CLIENT_DRIVER_L2TPV3] = net_init_l2tpv3, #endif diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c new file mode 100644 index 0000000000..bc0e0d2d35 --- /dev/null +++ b/net/vhost-vdpa.c @@ -0,0 +1,228 @@ +/* + * vhost-vdpa.c + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "clients.h" +#include "net/vhost_net.h" +#include "net/vhost-vdpa.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/option.h" +#include "qapi/error.h" +#include +#include +#include "standard-headers/linux/virtio_net.h" +#include "monitor/monitor.h" +#include "hw/virtio/vhost.h" + +/* Todo:need to add the multiqueue support here */ +typedef struct VhostVDPAState { + NetClientState nc; + struct vhost_vdpa vhost_vdpa; + VHostNetState *vhost_net; + uint64_t acked_features; + bool started; +} VhostVDPAState; + +const int vdpa_feature_bits[] = { + VIRTIO_F_NOTIFY_ON_EMPTY, + VIRTIO_RING_F_INDIRECT_DESC, + VIRTIO_RING_F_EVENT_IDX, + VIRTIO_F_ANY_LAYOUT, + VIRTIO_F_VERSION_1, + VIRTIO_NET_F_CSUM, + VIRTIO_NET_F_GUEST_CSUM, + VIRTIO_NET_F_GSO, + VIRTIO_NET_F_GUEST_TSO4, + VIRTIO_NET_F_GUEST_TSO6, + VIRTIO_NET_F_GUEST_ECN, + VIRTIO_NET_F_GUEST_UFO, + VIRTIO_NET_F_HOST_TSO4, + VIRTIO_NET_F_HOST_TSO6, + VIRTIO_NET_F_HOST_ECN, + VIRTIO_NET_F_HOST_UFO, + VIRTIO_NET_F_MRG_RXBUF, + VIRTIO_NET_F_MTU, + VIRTIO_F_IOMMU_PLATFORM, + VIRTIO_F_RING_PACKED, + VIRTIO_NET_F_GUEST_ANNOUNCE, + VHOST_INVALID_FEATURE_BIT +}; + +VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) +{ + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + return s->vhost_net; +} + +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc) +{ + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + s->acked_features = vhost_net_get_acked_features(s->vhost_net); + + return s->acked_features; +} + +static int vhost_vdpa_net_check_device_id(struct vhost_net *net) +{ + uint32_t device_id; + int ret; + struct vhost_dev *hdev; + + hdev = (struct vhost_dev *)&net->dev; + ret = hdev->vhost_ops->vhost_get_device_id(hdev, &device_id); + if (device_id != VIRTIO_ID_NET) { + return -ENOTSUP; + } + return ret; +} + +static void vhost_vdpa_del(NetClientState *ncs) +{ + VhostVDPAState *s; + assert(ncs->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + s = DO_UPCAST(VhostVDPAState, nc, ncs); + if (s->vhost_net) { + vhost_net_cleanup(s->vhost_net); + } +} + +static int vhost_vdpa_add(NetClientState *ncs, void *be) +{ + VhostNetOptions options; + struct vhost_net *net = NULL; + VhostVDPAState *s; + int ret; + + options.backend_type = VHOST_BACKEND_TYPE_VDPA; + assert(ncs->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + s = DO_UPCAST(VhostVDPAState, nc, ncs); + options.net_backend = ncs; + options.opaque = be; + options.busyloop_timeout = 0; + + net = vhost_net_init(&options); + if (!net) { + error_report("failed to init vhost_net for queue"); + goto err; + } + if (s->vhost_net) { + vhost_net_cleanup(s->vhost_net); + g_free(s->vhost_net); + } + s->vhost_net = net; + ret = vhost_vdpa_net_check_device_id(net); + if (ret) { + goto err; + } + return 0; +err: + if (net) { + vhost_net_cleanup(net); + } + vhost_vdpa_del(ncs); + return -1; +} + +static void vhost_vdpa_cleanup(NetClientState *nc) +{ + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + + if (s->vhost_net) { + vhost_net_cleanup(s->vhost_net); + g_free(s->vhost_net); + s->vhost_net = NULL; + } +} + +static bool vhost_vdpa_has_vnet_hdr(NetClientState *nc) +{ + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + + return true; +} + +static bool vhost_vdpa_has_ufo(NetClientState *nc) +{ + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + uint64_t features = 0; + features |= (1ULL << VIRTIO_NET_F_HOST_UFO); + features = vhost_net_get_features(s->vhost_net, features); + return !!(features & (1ULL << VIRTIO_NET_F_HOST_UFO)); + +} + +static NetClientInfo net_vhost_vdpa_info = { + .type = NET_CLIENT_DRIVER_VHOST_VDPA, + .size = sizeof(VhostVDPAState), + .cleanup = vhost_vdpa_cleanup, + .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, + .has_ufo = vhost_vdpa_has_ufo, +}; + +static int net_vhost_vdpa_init(NetClientState *peer, const char *device, + const char *name, const char *vhostdev) +{ + NetClientState *nc = NULL; + VhostVDPAState *s; + int vdpa_device_fd = -1; + int ret = 0; + assert(name); + nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); + snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); + nc->queue_index = 0; + s = DO_UPCAST(VhostVDPAState, nc, nc); + vdpa_device_fd = qemu_open(vhostdev, O_RDWR); + if (vdpa_device_fd == -1) { + return -errno; + } + s->vhost_vdpa.device_fd = vdpa_device_fd; + ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa); + assert(s->vhost_net); + return ret; +} + +static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp) +{ + const char *name = opaque; + const char *driver, *netdev; + + driver = qemu_opt_get(opts, "driver"); + netdev = qemu_opt_get(opts, "netdev"); + if (!driver || !netdev) { + return 0; + } + if (strcmp(netdev, name) == 0 && + !g_str_has_prefix(driver, "virtio-net-")) { + error_setg(errp, "vhost-vdpa requires frontend driver virtio-net-*"); + return -1; + } + return 0; +} + +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp) +{ + const NetdevVhostVDPAOptions *opts; + + assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA); + opts = &netdev->u.vhost_vdpa; + /* verify net frontend */ + if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net, + (char *)name, errp)) { + return -1; + } + return net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, opts->vhostdev); +} diff --git a/net/Makefile.objs b/net/Makefile.objs index c5d076d19c..5ab45545db 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o tap-obj-y ?= tap-stub.o common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) common-obj-$(CONFIG_WIN32) += tap-win32.o - +common-obj-$(CONFIG_VHOST_NET_VDPA) += vhost-vdpa.o vde.o-libs = $(VDE_LIBS) common-obj-$(CONFIG_CAN_BUS) += can/