From patchwork Tue Feb 25 15:12:28 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: 1244335 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=GFAUCiwZ; 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 48Rj9W1qHFz9sQt for ; Wed, 26 Feb 2020 02:13:03 +1100 (AEDT) Received: from localhost ([::1]:58418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btN-00063E-4x for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:13:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55109) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bt0-0005xs-6O for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bsz-0000oW-6v for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:38 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:57510 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bsz-0000oB-2w for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643556; 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=s3d4o92HiKW0GkrgYyraxaRI0YnnUbnRMpXEK0wLk1g=; b=GFAUCiwZQN33H2gvYuYGXA6HmfjRy1GeXgMjly7AwTv8i12ut02vEULyEpLzpeJ+yH9gNO XmZA3DTDNDiuJ14ejPNw+w6DfxH8esavuvq79axHmWu4ujq+BxSEdqhP2WeZx7IIf/uJUj ui2J9TArUzM/6svBGhNN6+l+SXaUhTg= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437-gXOnsF7tNUCKGtamaXiAtg-1; Tue, 25 Feb 2020 10:12:34 -0500 X-MC-Unique: gXOnsF7tNUCKGtamaXiAtg-1 Received: by mail-qv1-f70.google.com with SMTP id z9so13185437qvo.10 for ; Tue, 25 Feb 2020 07:12:34 -0800 (PST) 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=caX16DlQRmHBI59+o89Wqp82tnjVscp7M1/GhbqHicQ=; b=ZNGfJiSNPoh5UeIQDCDXppcXTrhVCRWvfwI7hSchOFG6ioHkUajoySxXrK4tvRNmI7 Arplfusb7+rYWRxfQIlPfb5U/kN5UiQyDipoxI3JIBGhRGJQ3RUTuRFpekin8o1fbjuW iG63LigW/tFCpHu4QOp0cMXiMtkFndWbfbF1BQZAgg56orYmCa+ZIplhDiJz7GubLcOF EY/tvJO/y1yGcEPs6JkTyyzdiaHTQRjDl79a3wK7fUcvm5U75e8s6ZrNT+AiqeVeiO8W 1QzWRw1+6jY4rwiBnxKRW6it1kzzmypEUYYsdXrq+lsuC1OqKYDfNLJqe5JIbICE10pF 5ePQ== X-Gm-Message-State: APjAAAW9lDTPuICK8rPikx8I0Fbz/LAnmHMgFee64Y4LrLtPRO2TyEbW +yP9UuCd5xw5IFZv5cZMb5+4DSfIAvePwC/Ngqmi2Fktk8i9v3tvteTItpN/UpGuXrDQ0YN0D+u Cxk8IiOLa7uq+vg4= X-Received: by 2002:aed:2284:: with SMTP id p4mr53136601qtc.329.1582643553898; Tue, 25 Feb 2020 07:12:33 -0800 (PST) X-Google-Smtp-Source: APXvYqx61SHuYU7fo49VdiMEpr4z/EteNFTlFvooc5ZWv5FM3wnBrA7Z7N8iNBTnJBxNBUZflhFbPQ== X-Received: by 2002:aed:2284:: with SMTP id p4mr53136583qtc.329.1582643553670; Tue, 25 Feb 2020 07:12:33 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id w1sm7770188qtk.31.2020.02.25.07.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:12:32 -0800 (PST) Date: Tue, 25 Feb 2020 10:12:28 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 01/32] bios-tables-test: tell people how to update Message-ID: <20200225151210.647797-2-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Paolo Bonzini , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" For now just a pointer to the source file. Signed-off-by: Michael S. Tsirkin Reviewed-by: Laurent Vivier Reviewed-by: Thomas Huth --- tests/qtest/bios-tables-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index b4752c644c..9c3c4680e4 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -426,7 +426,9 @@ static void test_acpi_asl(test_data *data) fprintf(stderr, "acpi-test: Warning! %.4s binary file mismatch. " - "Actual [aml:%s], Expected [aml:%s].\n", + "Actual [aml:%s], Expected [aml:%s].\n" + "See source file tests/qtest/bios-tables-test.c " + "for instructions on how to update expected files.\n", exp_sdt->aml, sdt->aml_file, exp_sdt->aml_file); all_tables_match = all_tables_match && From patchwork Tue Feb 25 15:12: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: 1244336 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=KIc9xlDg; 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 48Rj9f6nZTz9sPk for ; Wed, 26 Feb 2020 02:13:10 +1100 (AEDT) Received: from localhost ([::1]:58422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btU-0006FD-Qo for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:13:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55151) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bt6-0006Ao-LI for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bt5-0000se-Nj for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:44 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:23191 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bt5-0000sT-Jf for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643563; 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=6h6ExH4pUokuedAFNzn/YRJX66rcUuWYe4974bSpgXs=; b=KIc9xlDgeI7USKaiIHe9SKD5feDRcj1x5OKKysgGuSxJLNvV+vICQyCcSw21wNYFs+fEpn PPAnqEsEGKJB8vu9iQCUa1kB6fmdEje9+seA4mbgGGQ+dwcUsV88PK6h6yfZ+nnBysQyP2 3IeTYU5I0LBaxGMU77cwE1xNhBqoReE= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-342-QERZu72mPluvgNe4CjWP5A-1; Tue, 25 Feb 2020 10:12:40 -0500 X-MC-Unique: QERZu72mPluvgNe4CjWP5A-1 Received: by mail-qt1-f199.google.com with SMTP id g26so15138544qts.16 for ; Tue, 25 Feb 2020 07:12:40 -0800 (PST) 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=rBMXoO0qMiYn5SoVDdWygmuq7P3nv05NDp/olXioO30=; b=k4Jy3Xj4gYJAfwGZmVGulW9iaOVvYGZfHsdIbukKf6QbOxQcAzS2c3BgyHfBUq1tm7 hSe8weIpU129nJwDHwzMa8x+lpX+Ez2BOpP3o+MIGhCVPQPW72FfJvGnc1yS1dYJUVQd o5hdGlSF8fzycZjjGNM0FZTsdoQBcRgKh0hWyFdGO5GNYoOGt1WhYGqYPItcjLNpFfFi kmdxceoT3o3gcT3WOawu7IBno+b+FQVb1OEoRoPFC1yg0RhlUi3V1OeB3PLP7uSg1IGu dqHTfrAYBmT82We6+Hjvy/bYX2YCdTnb/ph1KNkR9hZnOVgYvfTSFg8CmhvLxRqQDNGz 82IQ== X-Gm-Message-State: APjAAAUpuKTfaWrgUkRRP9f/6jcgbJbnzO777BHWFtKRPwaQ9uX4wegt 55jE7wJRpYsEOP85bgA7WA32NN0ndyY4GVLUHTSZ/9VKIZtZxztylc8dQ6B667y+oEhR2CbcOFq GEHvUs5xRjiwMBZI= X-Received: by 2002:a37:2710:: with SMTP id n16mr56960409qkn.235.1582643559403; Tue, 25 Feb 2020 07:12:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzAfJrENgTaZ0An4gRYa8zt04aRCHiWZvLec6a7I2C14uzK9Yd1FR22zC2GsQMl/PBXEGxd4g== X-Received: by 2002:a37:2710:: with SMTP id n16mr56960337qkn.235.1582643558729; Tue, 25 Feb 2020 07:12:38 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id w18sm5225606qki.40.2020.02.25.07.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:12:38 -0800 (PST) Date: Tue, 25 Feb 2020 10:12:34 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 02/32] bios-tables-test: fix up DIFF generation Message-ID: <20200225151210.647797-3-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , Paolo Bonzini , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Turns out it goes to stdout which is suppressed even with V=1. Force DIFF output to stderr to make it visible. Signed-off-by: Michael S. Tsirkin --- tests/qtest/bios-tables-test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index 9c3c4680e4..1aed0ee7df 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -463,13 +463,19 @@ static void test_acpi_asl(test_data *data) "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s].\n", exp_sdt->aml, sdt->asl_file, sdt->aml_file, exp_sdt->asl_file, exp_sdt->aml_file); + fflush(stderr); if (getenv("V")) { const char *diff_cmd = getenv("DIFF"); if (diff_cmd) { - int ret G_GNUC_UNUSED; char *diff = g_strdup_printf("%s %s %s", diff_cmd, exp_sdt->asl_file, sdt->asl_file); + int out = dup(STDOUT_FILENO); + int ret G_GNUC_UNUSED; + + dup2(STDERR_FILENO, STDOUT_FILENO); ret = system(diff) ; + dup2(out, STDOUT_FILENO); + close(out); g_free(diff); } else { fprintf(stderr, "acpi-test: Warning. not showing " From patchwork Tue Feb 25 15:12:39 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: 1244337 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=P9DImOZO; 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 48Rj9t6ZKkz9sRQ for ; Wed, 26 Feb 2020 02:13:22 +1100 (AEDT) Received: from localhost ([::1]:58428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btg-0006Tu-Qq for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:13:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55163) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bt9-0006GE-Ij for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bt8-0000tl-KP for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:47 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:60904 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bt8-0000tV-GG for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643566; 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=SjaS3P94P86cbnJb7FE2dxVGEARWOCqkV6s3/6h3kVY=; b=P9DImOZOwKgfpFjMD6v+bYazwgvoJSPQ3C2dvSQhV7NdIAQDCb1486DcUGyRZbvzcTQ7VQ 2zLBAKVpZELy+q1dzXvVanH0LnmDLUNffmubU2PHpEdNBokSr6b3oldK+EIxxdqvFQb15J peCdjHCniqmzTm+nWN7VEFuh1R4xYOo= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-38-vfwCJJz_N7OkD0vquyFCDA-1; Tue, 25 Feb 2020 10:12:44 -0500 X-MC-Unique: vfwCJJz_N7OkD0vquyFCDA-1 Received: by mail-qk1-f198.google.com with SMTP id n130so10214177qke.19 for ; Tue, 25 Feb 2020 07:12:44 -0800 (PST) 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=J5D3o460P1rhFujFo85Es8Mk9QVxMsWvqSgvXhqC66U=; b=NmOHD6TQ7fkjY/1qkIuFY6VMn0MAu+KaJhwrSorHnbC5CKnaCO03nKn58N9FnhWSzD SjoFc3tRQOAw7my/CJkFrK32DVJrhGUXfU3CmGT2cVhF+KUnWHcINLJT5DyQ0t2Ddt1l LkuUITs/aXWhtUeOfsp8j+SFZwz2+N0Vt4Tq5Q0kcZgiwilGuBgxTDTENST/4lL7O8dz 49USMCBHTDLNpQ2Y15Hq14WxmfLaoQ9crj3Qsyqp+DO40MVTfyID4RRXoij8FX1ajl1s bxXVHo65YJh8nVS2bFi9I63QJfbzFS0agO1XRMOMLRKG5Jr4CEY6V9Y+JVc2kxG1Lqx7 0rrg== X-Gm-Message-State: APjAAAXZaqjRNDI/hn3XY1OSHa4afox6junBkEWEK13JfZsm742EYcsx BB8y/hN9lIW5d9t+vThFrM8iX8mLzJ/YhKu912n7rdK7jGqADH+P2fUc12y7g9QcmOibuayBiyS Z7ina7HNFMAtHNjM= X-Received: by 2002:aed:3324:: with SMTP id u33mr52520211qtd.322.1582643563684; Tue, 25 Feb 2020 07:12:43 -0800 (PST) X-Google-Smtp-Source: APXvYqynn7/+8ZltdmYi6IBqD4+4Uij0q5vOGxRokGddAQo3bE+6kbnyMJevv1OKQyoTkpVfP32ZKw== X-Received: by 2002:aed:3324:: with SMTP id u33mr52520182qtd.322.1582643563445; Tue, 25 Feb 2020 07:12:43 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id z34sm7652256qtd.42.2020.02.25.07.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:12:42 -0800 (PST) Date: Tue, 25 Feb 2020 10:12:39 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 03/32] bios-tables-test: default diff command Message-ID: <20200225151210.647797-4-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Paolo Bonzini , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Most people probably just want diff -u. So let's use that as the default. Signed-off-by: Michael S. Tsirkin --- tests/qtest/bios-tables-test.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index 1aed0ee7df..0a597bbacf 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -465,25 +465,18 @@ static void test_acpi_asl(test_data *data) exp_sdt->asl_file, exp_sdt->aml_file); fflush(stderr); if (getenv("V")) { - const char *diff_cmd = getenv("DIFF"); - if (diff_cmd) { - char *diff = g_strdup_printf("%s %s %s", diff_cmd, - exp_sdt->asl_file, sdt->asl_file); - int out = dup(STDOUT_FILENO); - int ret G_GNUC_UNUSED; + const char *diff_env = getenv("DIFF"); + const char *diff_cmd = diff_env ? diff_env : "diff -u"; + char *diff = g_strdup_printf("%s %s %s", diff_cmd, + exp_sdt->asl_file, sdt->asl_file); + int out = dup(STDOUT_FILENO); + int ret G_GNUC_UNUSED; - dup2(STDERR_FILENO, STDOUT_FILENO); - ret = system(diff) ; - dup2(out, STDOUT_FILENO); - close(out); - g_free(diff); - } else { - fprintf(stderr, "acpi-test: Warning. not showing " - "difference since no diff utility is specified. " - "Set 'DIFF' environment variable to a preferred " - "diff utility and run 'make V=1 check' again to " - "see ASL difference."); - } + dup2(STDERR_FILENO, STDOUT_FILENO); + ret = system(diff) ; + dup2(out, STDOUT_FILENO); + close(out); + g_free(diff); } } } From patchwork Tue Feb 25 15:12:44 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: 1244340 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=Y3Ou/hU/; 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 48RjCX33kLz9sPk for ; Wed, 26 Feb 2020 02:14:48 +1100 (AEDT) Received: from localhost ([::1]:58482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bv4-00017c-4z for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:14:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55178) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btE-0006Qg-MM for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6btD-0000vD-NC for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:52 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:48158 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6btD-0000v4-JW for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:12:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643571; 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=4HnVvdO9PVG27yQKQDqqOF3A6bmqC4jZ3lSftCc+CzU=; b=Y3Ou/hU/QaR3Wq8bMNLuNjRMs/eDUS+5zGOPI3jHSEUInrvJsXw4c7B/2TWAHYQ+ShR7Rl TrK8YlTjJDQpZ387LAn1g+Lv0xzLeLt6pRM1/UcfnSnFWCra1zMDq+q3H60LTIGtYmA5us l6McjNcK5DJeGWfD4nSsBDla/ogyKHE= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-321-2-NXI7iTPEO7_NEa2e-_kA-1; Tue, 25 Feb 2020 10:12:49 -0500 X-MC-Unique: 2-NXI7iTPEO7_NEa2e-_kA-1 Received: by mail-qv1-f70.google.com with SMTP id k2so13183170qvu.22 for ; Tue, 25 Feb 2020 07:12:49 -0800 (PST) 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=8uqNcJ577hXSJJzPx9aMtc0hri4nmxSoPvEVTfUrw5Y=; b=t0rvuKOXbuYFbMU01nV+xltmQswOzuo12WqYLzr/ToyMBAs28eMiVy+t16JuxKSJJ8 F/0nimJTnEoldBN/FNxmDjkJ6aycMWKYWMOwU6SIQBaDKmgzh/XtK25y7seCK84d2hgV CFz/j32C6WbT62zIu+9AFaq0uAP2C7D32ByyKj4PuNyhLcsK5yC3EtHV8WqedhIxN5Ia ino1WcEMFcbIe3p8g5zQfjPoMypjbFe0EKcNm6GYH+YpcnHLFJL+xMPGotNGEkrBynd7 CDZD53JR+rtj3sE2jKZTBsPu5qHQ8fGVsX2e+hteZDj+f1B7IYtUXdC9HPnQtnfP2ZRk iIIQ== X-Gm-Message-State: APjAAAWWhJ6rf5IbmJoMz1wvhRRTvZPmzeReVpLx3hsC8x4ACpx8/MNI /D1GqOSS0AjxIExNtgVlRO/6hs1G56kHi9tMV8jwVY7NSesTUPCf6zMtFbjjCOGvmn3hOtbOu9z 2fVQ7/qky8CkWK5s= X-Received: by 2002:aed:2510:: with SMTP id v16mr54191533qtc.306.1582643568390; Tue, 25 Feb 2020 07:12:48 -0800 (PST) X-Google-Smtp-Source: APXvYqwC/s628sfMqAm6nLwJBI8XnafBN05K2JPZArt2t7iXhNHjuMfMHf7iZpaYWWluWNCjc8jQbA== X-Received: by 2002:aed:2510:: with SMTP id v16mr54191508qtc.306.1582643568154; Tue, 25 Feb 2020 07:12:48 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id f59sm7596361qtb.75.2020.02.25.07.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:12:47 -0800 (PST) Date: Tue, 25 Feb 2020 10:12:44 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 04/32] rebuild-expected-aml.sh: remind about the process Message-ID: <20200225151210.647797-5-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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" Remind users of rebuild-expected-aml.sh about the process to follow. Suppress the warning if allowed file list exists - that's a big hint user is already aware of the process. Signed-off-by: Michael S. Tsirkin --- tests/data/acpi/rebuild-expected-aml.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/data/acpi/rebuild-expected-aml.sh b/tests/data/acpi/rebuild-expected-aml.sh index d44e511533..9cbaab1a4d 100755 --- a/tests/data/acpi/rebuild-expected-aml.sh +++ b/tests/data/acpi/rebuild-expected-aml.sh @@ -31,6 +31,13 @@ done eval `grep SRC_PATH= config-host.mak` +old_allowed_dif=`grep -v -e 'List of comma-separated changed AML files to ignore' ${SRC_PATH}/tests/qtest/bios-tables-test-allowed-diff.h` + 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." + +if [ -z "$old_allowed_dif" ]; then + echo "Note! Please do not commit expected files with source changes" + echo "Note! Please follow the process documented in ${SRC_PATH}/tests/qtest/bios-tables-test.c" +fi From patchwork Tue Feb 25 15:12: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: 1244338 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=XE6cTToW; 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 48RjB65stxz9sPk for ; Wed, 26 Feb 2020 02:13:34 +1100 (AEDT) Received: from localhost ([::1]:58434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bts-0006tC-Oe for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:13:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55214) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btP-0006os-F8 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6btN-0000ym-Fz for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:03 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:24519 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6btN-0000yY-BK for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643580; 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=/3tpoO/b13qxGCdroClG2tHi1hZJUztPTgTRGVuyGg8=; b=XE6cTToWJoVLaM3oodPc0FHJQ5Kmp+4h8fuzPm8/wtsws6AsBJM+wDw6SPxq5kHGaSTE2F WAsJQBb0li67RTRpYFtzvuFGkAWtZnrPPl60dbZvS9vwkS3HIUW/YApetdRWy3cdfMlANg 6vWg2TjJ9aR0ab9rJIqtcJRmmLBPA1g= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-N6RZ8Zu0M86-2MnNT-2DUQ-1; Tue, 25 Feb 2020 10:12:54 -0500 X-MC-Unique: N6RZ8Zu0M86-2MnNT-2DUQ-1 Received: by mail-qk1-f200.google.com with SMTP id 200so4935476qkd.10 for ; Tue, 25 Feb 2020 07:12:54 -0800 (PST) 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=PoUqLzU6INu2jZoEzWyNAufvBtw3qPKPkJ42k8ZdQek=; b=ANJ6sOTOrlRxoHE2ZCFdKxBtiIvwkCkCXcn81SJd6X3ynC0O5ns5Lw2nKHJAQVGFEp tAHkSBVaocPERZyquCQcT4PvdwNwuZB5bdnYg2pCQXvEvisWZY/DrnV7SrYKrzdVEmnm vZAKRrZH+TH+nHbA64AVjyVCKEtCHwWXfjWVe7vu/Ec/9yN27Or0IYWtNykJhP970xsl JxsUVEsXkPUP6w3u3m3EjIqjD3brUMFn3WKC8wGLWUYT8MTe9zGNT3pTcQUcxDBn11DZ WLAEGrhzpfWHh0KzfkwFYjL87nPtqcJ16bUJEg1V6EQSCscxjdQM0qVvMROQ8b6ckk+U lPsw== X-Gm-Message-State: APjAAAXMwp2rXOIZV7PVRKEtCMN/Jkeng/4urc88IN7oBHC4yM2Xrl1g btFnKml+No4JsXdRadA3AUxo6A5DDcRFqG0PGwqem9PqC3VBr+zoIYCPj0aTPASIdzEtZPNnEsQ XOuU2kyLbIfMHqxo= X-Received: by 2002:ad4:4d85:: with SMTP id cv5mr48754282qvb.171.1582643573751; Tue, 25 Feb 2020 07:12:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxxFCkYQdlA0Gwlr5wFpJb46HqO1ifLXXGsI1a80XgmhC9nTI8seSb2ggKG+Q6O9xd3obe/Mg== X-Received: by 2002:ad4:4d85:: with SMTP id cv5mr48754269qvb.171.1582643573539; Tue, 25 Feb 2020 07:12:53 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id b10sm1762359qtp.83.2020.02.25.07.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:12:52 -0800 (PST) Date: Tue, 25 Feb 2020 10:12:48 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 05/32] vhost-user-fs: do delete virtio_queues in unrealize Message-ID: <20200225151210.647797-6-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Pan Nengyuan , "Dr. David Alan Gilbert" , Stefan Hajnoczi , Euler Robot Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Pan Nengyuan Similar to other virtio device(https://patchwork.kernel.org/patch/11399237/), virtio queues forgot to delete in unrealize, and aslo error path in realize, this patch fix these memleaks, the leak stack is as follow: Direct leak of 57344 byte(s) in 1 object(s) allocated from: #0 0x7f15784fb970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970) #1 0x7f157790849d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d) #2 0x55587a1bf859 in virtio_add_queue /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:2333 #3 0x55587a2071d5 in vuf_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/vhost-user-fs.c:212 #4 0x55587a1ae360 in virtio_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:3531 #5 0x55587a63fb7b in device_set_realized /mnt/sdb/qemu-new/qemu_test/qemu/hw/core/qdev.c:891 #6 0x55587acf03f5 in property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:2238 #7 0x55587acfce0d in object_property_set_qobject /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qobject.c:26 #8 0x55587acf5c8c in object_property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:1390 #9 0x55587a8e22a2 in pci_qdev_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/pci/pci.c:2095 #10 0x55587a63fb7b in device_set_realized /mnt/sdb/qemu-new/qemu_test/qemu/hw/core/qdev.c:891 #11 0x55587acf03f5 in property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:2238 #12 0x55587acfce0d in object_property_set_qobject /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qobject.c:26 #13 0x55587acf5c8c in object_property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:1390 #14 0x55587a496d65 in qdev_device_add /mnt/sdb/qemu-new/qemu_test/qemu/qdev-monitor.c:679 Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Cc: "Dr. David Alan Gilbert" Cc: Stefan Hajnoczi Message-Id: <20200225075554.10835-2-pannengyuan@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-user-fs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 33b17848c2..4554d123b7 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -230,6 +230,10 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) err_virtio: vhost_user_cleanup(&fs->vhost_user); + virtio_del_queue(vdev, 0); + for (i = 0; i < fs->conf.num_request_queues; i++) { + virtio_del_queue(vdev, i + 1); + } virtio_cleanup(vdev); g_free(fs->vhost_dev.vqs); return; @@ -239,6 +243,7 @@ static void vuf_device_unrealize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserFS *fs = VHOST_USER_FS(dev); + int i; /* This will stop vhost backend if appropriate. */ vuf_set_status(vdev, 0); @@ -247,6 +252,10 @@ static void vuf_device_unrealize(DeviceState *dev, Error **errp) vhost_user_cleanup(&fs->vhost_user); + virtio_del_queue(vdev, 0); + for (i = 0; i < fs->conf.num_request_queues; i++) { + virtio_del_queue(vdev, i + 1); + } virtio_cleanup(vdev); g_free(fs->vhost_dev.vqs); fs->vhost_dev.vqs = NULL; From patchwork Tue Feb 25 15:12: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: 1244341 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=aF79g7JA; 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 48RjDC2BnGz9sPk for ; Wed, 26 Feb 2020 02:15:23 +1100 (AEDT) Received: from localhost ([::1]:58498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bvd-000200-4V for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:15:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55230) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btR-0006se-6R for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6btP-0000zy-VN for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:05 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44906 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6btP-0000zc-RJ for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643583; 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=xPFSbvv+WtlOtVos+MhqgsZmGBHXKy1YKRq49wrdV60=; b=aF79g7JA2YCE8TALamN7bHFhQnYq3xGs0aqC/dFQ7fGl9L8YXUDR0heUqa0V9OQj4eKAci 0DNwKHvbr7UVkmaUYWhEv2RK5dcdO439exGV0PySuUNAnI6RsGgEu0LpXqo1wsxA+A37Ea Ntv8qAH3MgaqKwYprt5FHUwbDh0c53U= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-ppcYxvESN1Sz_FkfuR6jMA-1; Tue, 25 Feb 2020 10:12:59 -0500 X-MC-Unique: ppcYxvESN1Sz_FkfuR6jMA-1 Received: by mail-qv1-f70.google.com with SMTP id d7so13196485qvq.12 for ; Tue, 25 Feb 2020 07:12:59 -0800 (PST) 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=X4na6KqmQ3c2V2WTi8kzbZFz4B5BaLaZ+cwVHA5c1dA=; b=hg/daR0/t9IDfEo7VNmBKmcrtei3biIm8YlHhNpjnTVt3i2VMykzoHVUZxryaVJqjP xFtdL2cWslwAS4S9N26gpKIWFcR20GblccxXd0OQj2lFM1CTo6a6YAM6ZSB2MxXmNQ5p yiulXTyWvAH9Uc3gfFtNBEvNK1VTY15RE+qbaNKN9jdPbjIQighB10IIBoLusZdvQQUq 4iEBRHkqDXz+77DNz6qTw2aTgxf5zeOgBKLbkcSOaDT1tZ5kB67fQIE3gZ/N/sGdzZOb 48kcCsMpfeLALUPncyKugawM6baD1o1mvG610TSSr+j62S0d5e6H+jfZ5J3fELiOHRkc 4v7g== X-Gm-Message-State: APjAAAW2m/6pfvccmA51k+jhX5tuoGIRwFoyjan7faU0wylEGlNZZRqd t2CXXtpG7YXEaLJ276e8B7wNzdA1llRLLsOnGCIKxHSRjlf+g4yOx0zSYdQwEe9I7oNtsto2tuD Pk8eGG7S0wBoU0mg= X-Received: by 2002:ae9:e413:: with SMTP id q19mr10633883qkc.248.1582643578384; Tue, 25 Feb 2020 07:12:58 -0800 (PST) X-Google-Smtp-Source: APXvYqyLPuQ/KTznrk4ef3sQqRpeSTzBa2ytk7WqONMjboVHht1+25o4ikLuqoSh3FK0QrhUVaG3xg== X-Received: by 2002:ae9:e413:: with SMTP id q19mr10633868qkc.248.1582643578189; Tue, 25 Feb 2020 07:12:58 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id n138sm466755qkn.33.2020.02.25.07.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:12:57 -0800 (PST) Date: Tue, 25 Feb 2020 10:12:54 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 06/32] vhost-user-fs: convert to the new virtio_delete_queue function Message-ID: <20200225151210.647797-7-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Pan Nengyuan , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Pan Nengyuan use the new virtio_delete_queue function to cleanup. Signed-off-by: Pan Nengyuan Cc: "Dr. David Alan Gilbert" Cc: Stefan Hajnoczi Message-Id: <20200225075554.10835-3-pannengyuan@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-fs.h | 2 ++ hw/virtio/vhost-user-fs.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-user-fs.h index 9ff1bdb7cf..6f3030d288 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -37,6 +37,8 @@ typedef struct { struct vhost_virtqueue *vhost_vqs; struct vhost_dev vhost_dev; VhostUserState vhost_user; + VirtQueue **req_vqs; + VirtQueue *hiprio_vq; /*< public >*/ } VHostUserFS; diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 4554d123b7..6136768875 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -209,11 +209,12 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) sizeof(struct virtio_fs_config)); /* Hiprio queue */ - virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); + fs->hiprio_vq = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); /* Request queues */ + fs->req_vqs = g_new(VirtQueue *, fs->conf.num_request_queues); for (i = 0; i < fs->conf.num_request_queues; i++) { - virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); + fs->req_vqs[i] = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); } /* 1 high prio queue, plus the number configured */ @@ -230,10 +231,11 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) err_virtio: vhost_user_cleanup(&fs->vhost_user); - virtio_del_queue(vdev, 0); + virtio_delete_queue(fs->hiprio_vq); for (i = 0; i < fs->conf.num_request_queues; i++) { - virtio_del_queue(vdev, i + 1); + virtio_delete_queue(fs->req_vqs[i]); } + g_free(fs->req_vqs); virtio_cleanup(vdev); g_free(fs->vhost_dev.vqs); return; @@ -252,10 +254,11 @@ static void vuf_device_unrealize(DeviceState *dev, Error **errp) vhost_user_cleanup(&fs->vhost_user); - virtio_del_queue(vdev, 0); + virtio_delete_queue(fs->hiprio_vq); for (i = 0; i < fs->conf.num_request_queues; i++) { - virtio_del_queue(vdev, i + 1); + virtio_delete_queue(fs->req_vqs[i]); } + g_free(fs->req_vqs); virtio_cleanup(vdev); g_free(fs->vhost_dev.vqs); fs->vhost_dev.vqs = NULL; From patchwork Tue Feb 25 15:12:58 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: 1244345 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=Px6uYsCw; 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 48RjGH3Fkmz9sRQ for ; Wed, 26 Feb 2020 02:17:11 +1100 (AEDT) Received: from localhost ([::1]:58554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bxN-0005Xs-7s for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:17:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55259) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btT-000700-Tc for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6btS-00011F-Sc for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:07 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:26811 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6btS-00010x-Ny for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643586; 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=5Sbkpo7K4fbQQabaezht/7HSdtDe1em0zHLb8IleaCg=; b=Px6uYsCws0IIew7ni92wcOhkvXI3tnIGryZizBZFfW/K+UP/pqukDdrNAUJnDkwkDsEFok 5f2mjWZTiMsPKWU8YelZoWALpr/Va1V55VkZg7vYUhFPtRNwgPJMdAmRQdexBn55cuyNZm xX81Vl/8rAzSNJgT1vVOkZCHku6KsZ8= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-LwIT6Wr3M7mzf3HeAQPe6g-1; Tue, 25 Feb 2020 10:13:03 -0500 X-MC-Unique: LwIT6Wr3M7mzf3HeAQPe6g-1 Received: by mail-qk1-f197.google.com with SMTP id c206so15297822qkg.6 for ; Tue, 25 Feb 2020 07:13:03 -0800 (PST) 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=HQCVFXmC4HNrtLa78+UIIIU3F1sBdIpmGro+wxgLStc=; b=HEC36zAgkN8m98c2hcAQG4026gUEJ7ZtQYqFhu7/RzDFcEnp9JeOTcHi2qiLsIFJlS Uwd6iVNZ0WxlcEd/qWywthVen4hzzVoXtR8RfpX6RKoK5g/OIilzmWQ5QCBzBM3u9TN3 nsFGsf2kX7Yal6JsIG5Rl4zOqkewyTnn/wWAHVDJMNWYXjyM1q7+xqiAxpCj0JeZLVUF PzSil542Jkw7FwlcZdsBn1scHKwG1LGL75YU4lgkFPcYhxXOVYlBshhOelVN4kmZ78J4 huFjD2HdoBKtVXjSUA2hO2oqDKyNCwpieMBrKmmyKxMbQ2RWFv7RiJ6D6WEV4oCsJ6kS 4EPw== X-Gm-Message-State: APjAAAULieMT1CPN7IXClmBd1qdggsRi/miyDpMO7dFreSa8KdSQDLaZ B4q6C3Rz10k0QF/x8HG+A6g5lzdpFRZmIT3ozC041Fm3oCCq6RYRmpPPL6SPQg/S9wvp8qzuO/h skNOK7jI9COF8gZ0= X-Received: by 2002:ac8:7b4c:: with SMTP id m12mr162295qtu.387.1582643582998; Tue, 25 Feb 2020 07:13:02 -0800 (PST) X-Google-Smtp-Source: APXvYqz1YDo7kjGJFWilPV4mKlxk3PPAchZLKewsrdOkSrp1Qt5Z9/pUYoWbE3+pManT7cmZ8kYWOA== X-Received: by 2002:ac8:7b4c:: with SMTP id m12mr162273qtu.387.1582643582790; Tue, 25 Feb 2020 07:13:02 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id w2sm7679134qto.73.2020.02.25.07.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:02 -0800 (PST) Date: Tue, 25 Feb 2020 10:12:58 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 07/32] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize Message-ID: <20200225151210.647797-8-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Philippe =?utf-8?q?Mathieu-D?= =?utf-8?b?YXVkw6k=?= , Pan Nengyuan , Euler Robot Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Pan Nengyuan Similar to other virtio-devices, rq_vq forgot to delete in virtio_pmem_unrealize, this patch fix it. This device has already maintained a vq pointer, thus we use the new virtio_delete_queue function directly to do the cleanup. Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Message-Id: <20200225075554.10835-4-pannengyuan@huawei.com> Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-pmem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c index 97287e923b..43399522f5 100644 --- a/hw/virtio/virtio-pmem.c +++ b/hw/virtio/virtio-pmem.c @@ -130,6 +130,7 @@ static void virtio_pmem_unrealize(DeviceState *dev, Error **errp) VirtIOPMEM *pmem = VIRTIO_PMEM(dev); host_memory_backend_set_mapped(pmem->memdev, false); + virtio_delete_queue(pmem->rq_vq); virtio_cleanup(vdev); } From patchwork Tue Feb 25 15:13:03 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: 1244349 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=fhJfjzvD; 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 48RjK26FqJz9sRQ for ; Wed, 26 Feb 2020 02:19:34 +1100 (AEDT) Received: from localhost ([::1]:58590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bzg-0000ZD-Kh for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:19:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55298) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bte-0007Ez-Fb for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6btc-00013W-DX for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:18 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59810 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6btc-00012g-99 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643591; 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=3B3Sa4xWvVmS4vX2SpY1eVnYbHxN4jErdc7je0hAjzI=; b=fhJfjzvDzF9Smni5k6NoH9cdG5FlQ4ocD9unss2GHJappiB9uoA+sWaqPqsA13HEVrWvzn mQbMxAjg9gTW60Ji06goqOdvZEbDc5S6YyHyKo1x3gyiqPhX1HP1QPZEX11pnbDTcvGRbY RZihhwsD+cscv1Uy4DMa6neBOEBvzZo= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-_bzD1zwwN-GWkLWUg8aN-g-1; Tue, 25 Feb 2020 10:13:09 -0500 X-MC-Unique: _bzD1zwwN-GWkLWUg8aN-g-1 Received: by mail-qt1-f197.google.com with SMTP id t4so15215721qtd.3 for ; Tue, 25 Feb 2020 07:13:09 -0800 (PST) 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=K82kJSX7CFx0xCCgPULemf4x4nZ22grma2KzCsjRDMY=; b=IgcjFHh2apxHjcvlx7lbVi86YQqeoFYIoL1nHx0qrOkyK2x86MuOH4Fvt1s0DdLSHL sQnDx+83qu1W3c9Ss3S8cM+QPfCfr0f1AoFjQoNNO9/CR8+A+GgKmOyttHqj6/e4sLy2 LjYHN/cDnYowTFyTZm+ZwtvyOuBdFC+xfLbQy/wnXB1N41ANkWuAgY2yVlbp1dDSiDVN CDvrK8g9FmF1jAh3O6rbzy9rNLOWMpqyifc5cUHcjkE0tjKSRtJnJ0v+Pcspnf0Rsqmm OxErDVsn7AC2raCk7R5EQcxG92xJL2f/ct5rhsOTvcWolPQ74EZEHtPX461Pv5ma1S7X 2ODw== X-Gm-Message-State: APjAAAV5raZYEnp55hwCUY1hrw932jjpsyn2I7AkhmVi+C7R8+Ik2hRs Zs9gO9HPkTZuUba1beqRimzVWVK9mY/zT2pn57TiHmYysJPw5q3YmfMEAAGX3FWeeT3g8BktbQE qt2cYLouVc0+evWM= X-Received: by 2002:a37:7a04:: with SMTP id v4mr21353237qkc.246.1582643588423; Tue, 25 Feb 2020 07:13:08 -0800 (PST) X-Google-Smtp-Source: APXvYqyBOZdAVNP7MItD9+3/9V40PAsTgI8S/+t/hoSwJZ/n9aMxynoidNV8f/WQV2LsfeEmU2rIsA== X-Received: by 2002:a37:7a04:: with SMTP id v4mr21353211qkc.246.1582643588207; Tue, 25 Feb 2020 07:13:08 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id g2sm6361781qka.42.2020.02.25.07.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:07 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:03 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 08/32] virtio-crypto: do delete ctrl_vq in virtio_crypto_device_unrealize Message-ID: <20200225151210.647797-9-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , "Gonglei \(Arei\)" , Pan Nengyuan , Euler Robot Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Pan Nengyuan Similar to other virtio-deivces, ctrl_vq forgot to delete in virtio_crypto_device_unrealize, this patch fix it. This device has aleardy maintained vq pointers. Thus, we use the new virtio_delete_queue function directly to do the cleanup. The leak stack: Direct leak of 10752 byte(s) in 3 object(s) allocated from: #0 0x7f4c024b1970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970) #1 0x7f4c018be49d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d) #2 0x55a2f8017279 in virtio_add_queue /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:2333 #3 0x55a2f8057035 in virtio_crypto_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio-crypto.c:814 #4 0x55a2f8005d80 in virtio_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:3531 #5 0x55a2f8497d1b in device_set_realized /mnt/sdb/qemu-new/qemu_test/qemu/hw/core/qdev.c:891 #6 0x55a2f8b48595 in property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:2238 #7 0x55a2f8b54fad in object_property_set_qobject /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qobject.c:26 #8 0x55a2f8b4de2c in object_property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:1390 #9 0x55a2f80609c9 in virtio_crypto_pci_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio-crypto-pci.c:58 Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Cc: "Gonglei (Arei)" Message-Id: <20200225075554.10835-5-pannengyuan@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-crypto.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 7351ab0a19..4c65114de5 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -831,12 +831,13 @@ static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp) max_queues = vcrypto->multiqueue ? vcrypto->max_queues : 1; for (i = 0; i < max_queues; i++) { - virtio_del_queue(vdev, i); + virtio_delete_queue(vcrypto->vqs[i].dataq); q = &vcrypto->vqs[i]; qemu_bh_delete(q->dataq_bh); } g_free(vcrypto->vqs); + virtio_delete_queue(vcrypto->ctrl_vq); virtio_cleanup(vdev); cryptodev_backend_set_used(vcrypto->cryptodev, false); From patchwork Tue Feb 25 15:13:08 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: 1244343 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=G9op1Aje; 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 48RjFk67hmz9sPk for ; Wed, 26 Feb 2020 02:16:42 +1100 (AEDT) Received: from localhost ([::1]:58540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bwu-0004IZ-Mk for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:16:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55316) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btf-0007Ju-Px for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bte-00014e-Jw for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:19 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:56520 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bte-00013k-GV for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643596; 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=NjdfC5cPcTj7xCSppU7CRy3um06hUEk/RHvT4NHcJJM=; b=G9op1Aje6UXyaoN8TH1YIyF8zv9av2w6BgwTCgfCJdmXTFbD1GgrCpLjnJmM3EKLGbaG7c 4/ZV6+GtIhvV7W1ZSH7LghlzDmfnxkSxAmWW65yLOLD/8FQ+NtYyEosxH2o9K2WbgLJ21l V4oTogM05ReIXqU/P275fBgY75ENaeA= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-6CU8SYAbNgWIuR3Tsn17MA-1; Tue, 25 Feb 2020 10:13:14 -0500 X-MC-Unique: 6CU8SYAbNgWIuR3Tsn17MA-1 Received: by mail-qt1-f199.google.com with SMTP id u40so15236483qtk.1 for ; Tue, 25 Feb 2020 07:13:14 -0800 (PST) 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=yx/d9Pi1yF7zdpvYgnvi6Hx1i6BxcPVN8IeOoA2COOE=; b=IojKLbM5i+GgyVNkxsD9LN41p2D8TkXfHSoBnmXaPIey1B60BDOvtCyRNpVwjy0Jgb 8QNP98AoG+bmeQqM7j0rb1V/NgWCCj7jHYN3IRpuW+UXJKRV4Mno9YGxWML6jYgmKCsL vTYOx5kKd8zzF+dIrFpLiT4dbL99vkt/0p4d6DuWNPGP4NjdhT+Cq3PPehgBpPtSq6ax dkB5ZcPGZaGS5VWwL63lO0fNuxhiZRBUMgf+SguJ+0PG31FXicx8eCPClnS6v+nA0Ung RmXMhFu/Xz4t8cDDNfk+8ZzTdR1Rjs5dBq5u9R+kWoFgGjZEzvDZNaNPeHSSgV3qmDPx h3qw== X-Gm-Message-State: APjAAAWc+lwshZUSXnoKyDt/G5tlXlQNbnK2UnhqMBeE8ITh2InOh5mu PnSw+F8eBJpc0KqYRh+IgCWjLKVIlRmfPPdNt8GLkd8+omXXgx8NW+vb07YIEt9u1E8Nlve3x1G BwAY2LML8AFI/X+s= X-Received: by 2002:a37:b11:: with SMTP id 17mr2709182qkl.384.1582643594116; Tue, 25 Feb 2020 07:13:14 -0800 (PST) X-Google-Smtp-Source: APXvYqx1Bx8sj51cx6qcGziyMuYuhqzSh00LZNm7YilIUiwjZ2W4paq0tvafub4o2LqgXwOGyPYuTg== X-Received: by 2002:a37:b11:: with SMTP id 17mr2709161qkl.384.1582643593881; Tue, 25 Feb 2020 07:13:13 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id l8sm7499378qtr.36.2020.02.25.07.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:12 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:08 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 09/32] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks Message-ID: <20200225151210.647797-10-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Pan Nengyuan , Max Reitz , Stefan Hajnoczi , Euler Robot Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Pan Nengyuan virtio queues forgot to delete in unrealize, and aslo error path in realize, this patch fix these memleaks, the leak stack is as follow: Direct leak of 114688 byte(s) in 16 object(s) allocated from: #0 0x7f24024fdbf0 in calloc (/lib64/libasan.so.3+0xcabf0) #1 0x7f2401642015 in g_malloc0 (/lib64/libglib-2.0.so.0+0x50015) #2 0x55ad175a6447 in virtio_add_queue /mnt/sdb/qemu/hw/virtio/virtio.c:2327 #3 0x55ad17570cf9 in vhost_user_blk_device_realize /mnt/sdb/qemu/hw/block/vhost-user-blk.c:419 #4 0x55ad175a3707 in virtio_device_realize /mnt/sdb/qemu/hw/virtio/virtio.c:3509 #5 0x55ad176ad0d1 in device_set_realized /mnt/sdb/qemu/hw/core/qdev.c:876 #6 0x55ad1781ff9d in property_set_bool /mnt/sdb/qemu/qom/object.c:2080 #7 0x55ad178245ae in object_property_set_qobject /mnt/sdb/qemu/qom/qom-qobject.c:26 #8 0x55ad17821eb4 in object_property_set_bool /mnt/sdb/qemu/qom/object.c:1338 #9 0x55ad177aeed7 in virtio_pci_realize /mnt/sdb/qemu/hw/virtio/virtio-pci.c:1801 Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Reviewed-by: Stefan Hajnoczi Message-Id: <20200224041336.30790-2-pannengyuan@huawei.com> Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/block/vhost-user-blk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index d8c459c575..2eba8b9db0 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -460,6 +460,9 @@ reconnect: virtio_err: g_free(s->vqs); g_free(s->inflight); + for (i = 0; i < s->num_queues; i++) { + virtio_del_queue(vdev, i); + } virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } @@ -468,6 +471,7 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserBlk *s = VHOST_USER_BLK(dev); + int i; virtio_set_status(vdev, 0); qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, @@ -476,6 +480,10 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp) vhost_dev_free_inflight(s->inflight); g_free(s->vqs); g_free(s->inflight); + + for (i = 0; i < s->num_queues; i++) { + virtio_del_queue(vdev, i); + } virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } From patchwork Tue Feb 25 15:13: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: 1244344 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=KoCLNAk2; 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 48RjG33Wpdz9sQt for ; Wed, 26 Feb 2020 02:16:59 +1100 (AEDT) Received: from localhost ([::1]:58550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bxB-0004uW-9I for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:16:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55335) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btm-0007d9-0o for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6btk-00016d-Qy for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:25 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39469 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6btk-00016K-Me for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643604; 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=GbXYhzT4HdCqyN2iskP5pyuuGP3IhftOdhWxCQdQeVU=; b=KoCLNAk21C1LLpIEYxyUpGeTOFLnXHVc8p38pIWh9LEp/3iQYx7B7buxqR+UNpPaO3PCBh gSUAthDQw5jvP6oHDK/bwFRVP8SEm459hJKS802o50cb716WBvYHbzc4sB46jlu0P34VFx M85QFDC+HKprgjAvIt76PvuXVqcpuxs= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-241-1pr1NmO4O4yHJ42nByxWhw-1; Tue, 25 Feb 2020 10:13:20 -0500 X-MC-Unique: 1pr1NmO4O4yHJ42nByxWhw-1 Received: by mail-qk1-f198.google.com with SMTP id q123so15343304qkb.1 for ; Tue, 25 Feb 2020 07:13:20 -0800 (PST) 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=XWpi8uIuYqDgAxSrNx/dNPfjKOUMUQTkfVlQ2qW7D7Y=; b=jTAEI3N322Z2O1oHsnrYi9vBQ07q9Eodyg0UekP0NOMlqgZ57tCzSU1fMJsQWJjar7 mmn+cu+0mXrlBtLoGbexVr/Hxef+A9vABjt5954stoBnbC6kwTSRK42ISPDtEOjZ3V/8 OIB2wSN/fNbYPsbKx2VGILvAKfoEIGMGIAXs9npQ3J52Ka1XRMO251WDzOMSo9LwAVDi wKV6s8RnS3sqjvwuRwRMWI1NA4h2BViBjfRPpA8VKYII6s3wV4xAMirZk4+Y6k5cHShg P0ZYF8z4pRpbGjJsiNRHLgdoMw7p3EUVnOR261DnOR7ztUwmqp4RP0lkH/ZAw4SinLUS x0aA== X-Gm-Message-State: APjAAAXPREH2K23o2BZnpBYE1nUdt3r5f6smLNLzre7b5wxHMfV6FEGI GfxVjTB5u1f2P3/nhZJsNi3O/4dNdNSWKg29VxgQRpo0A4dMKdN1FpslTLMZOGAlSw3raVObzvi sV8o7XKLg50sBbmU= X-Received: by 2002:a05:6214:1494:: with SMTP id bn20mr51323187qvb.43.1582643599414; Tue, 25 Feb 2020 07:13:19 -0800 (PST) X-Google-Smtp-Source: APXvYqwYrjURwrUF8SqAALIsRsrcflyHpX1TwEyCa35tge0RQnzsgo/Eo2WYpuxXb352YKUszu3SaA== X-Received: by 2002:a05:6214:1494:: with SMTP id bn20mr51323167qvb.43.1582643599203; Tue, 25 Feb 2020 07:13:19 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id c45sm7795604qtd.43.2020.02.25.07.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:18 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:14 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 10/32] vhost-user-blk: convert to new virtio_delete_queue Message-ID: <20200225151210.647797-11-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Pan Nengyuan , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Pan Nengyuan use the new virtio_delete_queue function to cleanup. Signed-off-by: Pan Nengyuan Message-Id: <20200224041336.30790-3-pannengyuan@huawei.com> Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-blk.h | 3 ++- hw/block/vhost-user-blk.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h index 108bfadeeb..05ea0ad183 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -36,7 +36,8 @@ typedef struct VHostUserBlk { struct vhost_dev dev; struct vhost_inflight *inflight; VhostUserState vhost_user; - struct vhost_virtqueue *vqs; + struct vhost_virtqueue *vhost_vqs; + VirtQueue **virtqs; guint watch; bool connected; } VHostUserBlk; diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 2eba8b9db0..12925a47ec 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -306,7 +306,7 @@ static int vhost_user_blk_connect(DeviceState *dev) s->connected = true; s->dev.nvqs = s->num_queues; - s->dev.vqs = s->vqs; + s->dev.vqs = s->vhost_vqs; s->dev.vq_index = 0; s->dev.backend_features = 0; @@ -420,13 +420,14 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config)); + s->virtqs = g_new(VirtQueue *, s->num_queues); for (i = 0; i < s->num_queues; i++) { - virtio_add_queue(vdev, s->queue_size, - vhost_user_blk_handle_output); + s->virtqs[i] = virtio_add_queue(vdev, s->queue_size, + vhost_user_blk_handle_output); } s->inflight = g_new0(struct vhost_inflight, 1); - s->vqs = g_new0(struct vhost_virtqueue, s->num_queues); + s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues); s->watch = 0; s->connected = false; @@ -458,11 +459,12 @@ reconnect: return; virtio_err: - g_free(s->vqs); + g_free(s->vhost_vqs); g_free(s->inflight); for (i = 0; i < s->num_queues; i++) { - virtio_del_queue(vdev, i); + virtio_delete_queue(s->virtqs[i]); } + g_free(s->virtqs); virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } @@ -478,12 +480,13 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp) NULL, NULL, NULL, false); vhost_dev_cleanup(&s->dev); vhost_dev_free_inflight(s->inflight); - g_free(s->vqs); + g_free(s->vhost_vqs); g_free(s->inflight); for (i = 0; i < s->num_queues; i++) { - virtio_del_queue(vdev, i); + virtio_delete_queue(s->virtqs[i]); } + g_free(s->virtqs); virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } From patchwork Tue Feb 25 15:13:19 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: 1244353 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=MKZXtcoa; 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 48RjM54t8qz9sPk for ; Wed, 26 Feb 2020 02:21:21 +1100 (AEDT) Received: from localhost ([::1]:58676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c1P-000445-Iw for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:21:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55358) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btq-0007pW-D0 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bto-000185-D4 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:30 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:46048 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bto-00017x-6x for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643607; 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=whxdbRDtGph1XoeAoFrZk0n29mBRrdB26RATWp05X0g=; b=MKZXtcoam2WgNdzEIg7wlCk/XYuZhfa5OgauxPksbZdutq9D7Xxufwz10UESbuGIx3N8Vw PF82GZxjr5koQ+UUlSyTUcXjzgRyXfCONVqXpSQOnT0ZmH3WUERBJFZwsE6oKZjXKVGJPI 3i6mz0B+ENBNbxAPZaoB+VafuhqTzxQ= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-347-nPQVuzrINfywwybnOiA2LQ-1; Tue, 25 Feb 2020 10:13:25 -0500 X-MC-Unique: nPQVuzrINfywwybnOiA2LQ-1 Received: by mail-qt1-f197.google.com with SMTP id k20so15206193qtm.11 for ; Tue, 25 Feb 2020 07:13:25 -0800 (PST) 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=Uprh1KuSZSNAbPYPYmNXeHJXKj7nePNYJVWS65yPTiI=; b=KU45ytiG5lkj129vBElWT/aPvG6R7EoYVmBHuxuR8jNkkkO01GMfIqzmjYLA2DeHDo YqF7Z//Kz8dBBPC/fJo09snL7tNewZFYY0NY4Zg8euBfq2F4JmNKpX/Qg+f2XjaCSKbX qUrOYTHdG63Pdfrb2Z8DehYsmaVrTyfuwUgjmE/i7XFf2IQcu3RwXFuA7Jt7Kw4TXOGf HJRrrMi31IuXj93rQVAOoZohbp1Ko8h3Yh0i/Q4JUjHpteNK96jby4FkRj52d0HAOnk2 vtk6MNVwIxsO39kEYj0iH8WJ/zqaa+bkCapsY4B3WZHdmglrcXQ5RsL7PhUGNpuZnSfe N7jw== X-Gm-Message-State: APjAAAVK82aDIlFmsUSD3+Q2gH2QeEZsWixj3D8JRGx75Kis5v7eykU2 dN2tsWyiZ84B/zxTFbNOBy3rxj8/YiBnNNMiIHLJ9rVyKORbLe94dMSTRxjDOE7s6DlUW1iO+b1 CO4FHP5ScCZi1md0= X-Received: by 2002:ad4:554b:: with SMTP id v11mr19595180qvy.0.1582643604823; Tue, 25 Feb 2020 07:13:24 -0800 (PST) X-Google-Smtp-Source: APXvYqyrSqfRQo9F/r9eJoHPhVyM2PkvMh/+S1QDSO5+UOkWhCAxREQdNBFA/9+uxU/lPlQcDE3BiQ== X-Received: by 2002:ad4:554b:: with SMTP id v11mr19595154qvy.0.1582643604480; Tue, 25 Feb 2020 07:13:24 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id o25sm7610681qkk.7.2020.02.25.07.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:23 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:19 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 11/32] virtio: gracefully handle invalid region caches Message-ID: <20200225151210.647797-12-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Michael Tsirkin , Cornelia Huck , Alexander Bulekov , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi The virtqueue code sets up MemoryRegionCaches to access the virtqueue guest RAM data structures. The code currently assumes that VRingMemoryRegionCaches is initialized before device emulation code accesses the virtqueue. An assertion will fail in vring_get_region_caches() when this is not true. Device fuzzing found a case where this assumption is false (see below). Virtqueue guest RAM addresses can also be changed from a vCPU thread while an IOThread is accessing the virtqueue. This breaks the same assumption but this time the caches could become invalid partway through the virtqueue code. The code fetches the caches RCU pointer multiple times so we will need to validate the pointer every time it is fetched. Add checks each time we call vring_get_region_caches() and treat invalid caches as a nop: memory stores are ignored and memory reads return 0. The fuzz test failure is as follows: $ qemu -M pc -device virtio-blk-pci,id=drv0,drive=drive0,addr=4.0 \ -drive if=none,id=drive0,file=null-co://,format=raw,auto-read-only=off \ -drive if=none,id=drive1,file=null-co://,file.read-zeroes=on,format=raw \ -display none \ -qtest stdio endianness outl 0xcf8 0x80002020 outl 0xcfc 0xe0000000 outl 0xcf8 0x80002004 outw 0xcfc 0x7 write 0xe0000000 0x24 0x00ffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffab5cffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffabffffffab0000000001 inb 0x4 writew 0xe000001c 0x1 write 0xe0000014 0x1 0x0d The following error message is produced: qemu-system-x86_64: /home/stefanha/qemu/hw/virtio/virtio.c:286: vring_get_region_caches: Assertion `caches != NULL' failed. The backtrace looks like this: #0 0x00007ffff5520625 in raise () at /lib64/libc.so.6 #1 0x00007ffff55098d9 in abort () at /lib64/libc.so.6 #2 0x00007ffff55097a9 in _nl_load_domain.cold () at /lib64/libc.so.6 #3 0x00007ffff5518a66 in annobin_assert.c_end () at /lib64/libc.so.6 #4 0x00005555559073da in vring_get_region_caches (vq=) at qemu/hw/virtio/virtio.c:286 #5 vring_get_region_caches (vq=) at qemu/hw/virtio/virtio.c:283 #6 0x000055555590818d in vring_used_flags_set_bit (mask=1, vq=0x5555575ceea0) at qemu/hw/virtio/virtio.c:398 #7 virtio_queue_split_set_notification (enable=0, vq=0x5555575ceea0) at qemu/hw/virtio/virtio.c:398 #8 virtio_queue_set_notification (vq=vq@entry=0x5555575ceea0, enable=enable@entry=0) at qemu/hw/virtio/virtio.c:451 #9 0x0000555555908512 in virtio_queue_set_notification (vq=vq@entry=0x5555575ceea0, enable=enable@entry=0) at qemu/hw/virtio/virtio.c:444 #10 0x00005555558c697a in virtio_blk_handle_vq (s=0x5555575c57e0, vq=0x5555575ceea0) at qemu/hw/block/virtio-blk.c:775 #11 0x0000555555907836 in virtio_queue_notify_aio_vq (vq=0x5555575ceea0) at qemu/hw/virtio/virtio.c:2244 #12 0x0000555555cb5dd7 in aio_dispatch_handlers (ctx=ctx@entry=0x55555671a420) at util/aio-posix.c:429 #13 0x0000555555cb67a8 in aio_dispatch (ctx=0x55555671a420) at util/aio-posix.c:460 #14 0x0000555555cb307e in aio_ctx_dispatch (source=, callback=, user_data=) at util/async.c:260 #15 0x00007ffff7bbc510 in g_main_context_dispatch () at /lib64/libglib-2.0.so.0 #16 0x0000555555cb5848 in glib_pollfds_poll () at util/main-loop.c:219 #17 os_host_main_loop_wait (timeout=) at util/main-loop.c:242 #18 main_loop_wait (nonblocking=) at util/main-loop.c:518 #19 0x00005555559b20c9 in main_loop () at vl.c:1683 #20 0x0000555555838115 in main (argc=, argv=, envp=) at vl.c:4441 Reported-by: Alexander Bulekov Cc: Michael Tsirkin Cc: Cornelia Huck Cc: Paolo Bonzini Signed-off-by: Stefan Hajnoczi Message-Id: <20200207104619.164892-1-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio.c | 99 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 2c5410e981..00d444699d 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -282,15 +282,19 @@ static void vring_packed_flags_write(VirtIODevice *vdev, /* Called within rcu_read_lock(). */ static VRingMemoryRegionCaches *vring_get_region_caches(struct VirtQueue *vq) { - VRingMemoryRegionCaches *caches = atomic_rcu_read(&vq->vring.caches); - assert(caches != NULL); - return caches; + return atomic_rcu_read(&vq->vring.caches); } + /* Called within rcu_read_lock(). */ static inline uint16_t vring_avail_flags(VirtQueue *vq) { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingAvail, flags); + + if (!caches) { + return 0; + } + return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa); } @@ -299,6 +303,11 @@ static inline uint16_t vring_avail_idx(VirtQueue *vq) { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingAvail, idx); + + if (!caches) { + return 0; + } + vq->shadow_avail_idx = virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa); return vq->shadow_avail_idx; } @@ -308,6 +317,11 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, int i) { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingAvail, ring[i]); + + if (!caches) { + return 0; + } + return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa); } @@ -323,6 +337,11 @@ static inline void vring_used_write(VirtQueue *vq, VRingUsedElem *uelem, { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingUsed, ring[i]); + + if (!caches) { + return; + } + virtio_tswap32s(vq->vdev, &uelem->id); virtio_tswap32s(vq->vdev, &uelem->len); address_space_write_cached(&caches->used, pa, uelem, sizeof(VRingUsedElem)); @@ -334,6 +353,11 @@ static uint16_t vring_used_idx(VirtQueue *vq) { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingUsed, idx); + + if (!caches) { + return 0; + } + return virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); } @@ -342,8 +366,12 @@ static inline void vring_used_idx_set(VirtQueue *vq, uint16_t val) { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingUsed, idx); - virtio_stw_phys_cached(vq->vdev, &caches->used, pa, val); - address_space_cache_invalidate(&caches->used, pa, sizeof(val)); + + if (caches) { + virtio_stw_phys_cached(vq->vdev, &caches->used, pa, val); + address_space_cache_invalidate(&caches->used, pa, sizeof(val)); + } + vq->used_idx = val; } @@ -353,8 +381,13 @@ static inline void vring_used_flags_set_bit(VirtQueue *vq, int mask) VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); VirtIODevice *vdev = vq->vdev; hwaddr pa = offsetof(VRingUsed, flags); - uint16_t flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); + uint16_t flags; + if (!caches) { + return; + } + + flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); virtio_stw_phys_cached(vdev, &caches->used, pa, flags | mask); address_space_cache_invalidate(&caches->used, pa, sizeof(flags)); } @@ -365,8 +398,13 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask) VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); VirtIODevice *vdev = vq->vdev; hwaddr pa = offsetof(VRingUsed, flags); - uint16_t flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); + uint16_t flags; + if (!caches) { + return; + } + + flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); virtio_stw_phys_cached(vdev, &caches->used, pa, flags & ~mask); address_space_cache_invalidate(&caches->used, pa, sizeof(flags)); } @@ -381,6 +419,10 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val) } caches = vring_get_region_caches(vq); + if (!caches) { + return; + } + pa = offsetof(VRingUsed, ring[vq->vring.num]); virtio_stw_phys_cached(vq->vdev, &caches->used, pa, val); address_space_cache_invalidate(&caches->used, pa, sizeof(val)); @@ -410,7 +452,11 @@ static void virtio_queue_packed_set_notification(VirtQueue *vq, int enable) VRingMemoryRegionCaches *caches; RCU_READ_LOCK_GUARD(); - caches = vring_get_region_caches(vq); + caches = vring_get_region_caches(vq); + if (!caches) { + return; + } + vring_packed_event_read(vq->vdev, &caches->used, &e); if (!enable) { @@ -597,6 +643,10 @@ static int virtio_queue_packed_empty_rcu(VirtQueue *vq) } cache = vring_get_region_caches(vq); + if (!cache) { + return 1; + } + vring_packed_desc_read_flags(vq->vdev, &desc.flags, &cache->desc, vq->last_avail_idx); @@ -777,6 +827,10 @@ static void virtqueue_packed_fill_desc(VirtQueue *vq, } caches = vring_get_region_caches(vq); + if (!caches) { + return; + } + vring_packed_desc_write(vq->vdev, &desc, &caches->desc, head, strict_order); } @@ -949,6 +1003,10 @@ static void virtqueue_split_get_avail_bytes(VirtQueue *vq, max = vq->vring.num; caches = vring_get_region_caches(vq); + if (!caches) { + goto err; + } + while ((rc = virtqueue_num_heads(vq, idx)) > 0) { MemoryRegionCache *desc_cache = &caches->desc; unsigned int num_bufs; @@ -1089,6 +1147,9 @@ static void virtqueue_packed_get_avail_bytes(VirtQueue *vq, max = vq->vring.num; caches = vring_get_region_caches(vq); + if (!caches) { + goto err; + } for (;;) { unsigned int num_bufs = total_bufs; @@ -1194,6 +1255,10 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, } caches = vring_get_region_caches(vq); + if (!caches) { + goto err; + } + desc_size = virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED) ? sizeof(VRingPackedDesc) : sizeof(VRingDesc); if (caches->desc.len < vq->vring.num * desc_size) { @@ -1387,6 +1452,11 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz) i = head; caches = vring_get_region_caches(vq); + if (!caches) { + virtio_error(vdev, "Region caches not initialized"); + goto done; + } + if (caches->desc.len < max * sizeof(VRingDesc)) { virtio_error(vdev, "Cannot map descriptor ring"); goto done; @@ -1509,6 +1579,11 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz) i = vq->last_avail_idx; caches = vring_get_region_caches(vq); + if (!caches) { + virtio_error(vdev, "Region caches not initialized"); + goto done; + } + if (caches->desc.len < max * sizeof(VRingDesc)) { virtio_error(vdev, "Cannot map descriptor ring"); goto done; @@ -1628,6 +1703,10 @@ static unsigned int virtqueue_packed_drop_all(VirtQueue *vq) VRingPackedDesc desc; caches = vring_get_region_caches(vq); + if (!caches) { + return 0; + } + desc_cache = &caches->desc; virtio_queue_set_notification(vq, 0); @@ -2412,6 +2491,10 @@ static bool virtio_packed_should_notify(VirtIODevice *vdev, VirtQueue *vq) VRingMemoryRegionCaches *caches; caches = vring_get_region_caches(vq); + if (!caches) { + return false; + } + vring_packed_event_read(vdev, &caches->avail, &e); old = vq->signalled_used; From patchwork Tue Feb 25 15:13:25 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: 1244359 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=KBSvPO+g; 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 48RjQv13lxz9sNg for ; Wed, 26 Feb 2020 02:24:39 +1100 (AEDT) Received: from localhost ([::1]:58754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c4b-0001ts-0z for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:24:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bu1-0008BI-TQ for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6btz-0001Dq-Qc for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:41 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30002 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6btz-0001CA-IH for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643618; 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=fxhD85QURMHEqGfAVjO06OKCuGPcyx+wfBWG1kQlMdk=; b=KBSvPO+gOPeawmWxNYUJEa27E9Gx0xl8/zvVH8NxIgNdvMp4zYmv00ac62qKSEFV3YpEPM xiB/eag+R+tkx+mMzytNwT+taMg6wSeF6K127emmNx4BSwA9go1PonsSae7do9zaMaSFQZ Q1EK0n26yvvAQ87S0G1p/ixM3olx0vg= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-fh5319sGPg6xm_wV-ILzpw-1; Tue, 25 Feb 2020 10:13:32 -0500 X-MC-Unique: fh5319sGPg6xm_wV-ILzpw-1 Received: by mail-qv1-f72.google.com with SMTP id f17so13173236qvi.6 for ; Tue, 25 Feb 2020 07:13:32 -0800 (PST) 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=Zhqx9qPWTMmN4vZaT6M30mfe2b5p6M/C9yj5xkhbUpA=; b=ry6ip2LEn0YoZDCHOof+5pgV0WsyV+GUzXr0a0BUYt9eMeAA+SJOFWP+Gc6baiXzDB OFUDT/N69nKwVZ8y8XaDW2kPy22AOrajjfx9OTnrMfp+nH6c1BuiXo+RIEG+E7ihCtrW VMChnL/svK09bpi5qxpuXyXmF49mQX+QP2tmkO5lA14A3Yyu6HrIo2BHbGnF6MK1dNpB QLmHtFY0blV1C0Cw6uUbLnoKvrSljJeqeDz4A0RS3jLfzetS8Uy3Q+bmlpweOrjlmD9O PwpqGNm1yDdKffSnJLvacVqoJUic9Gt+v2KwpYMijypGnteEWY15D2vOKBeF3DhJtCw2 HYaA== X-Gm-Message-State: APjAAAXidlvKN+ekHn6SNimjNUxPYdaf6sKF8wsyclY0K/XuTa7hZvgc VRDP/Inc7OKLMcAOqXKQJ1XVtM6QAAXQX8WSItJNluXZrTQFQwU9yqFtSHfm/UKhlN8bY0wUPOB soZvSfj4+osIkBm8= X-Received: by 2002:a37:66c8:: with SMTP id a191mr13318222qkc.0.1582643610071; Tue, 25 Feb 2020 07:13:30 -0800 (PST) X-Google-Smtp-Source: APXvYqyJ0A2iKK+8/QbOiUtIdA9ezTOOm8mpwIJ+bZ7qhIJsOgnMDDTn1DTkOvsfxZzBivkDyVswyw== X-Received: by 2002:a37:66c8:: with SMTP id a191mr13318180qkc.0.1582643609668; Tue, 25 Feb 2020 07:13:29 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id u76sm7464411qka.21.2020.02.25.07.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:28 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:25 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 12/32] virtio-iommu: Add skeleton Message-ID: <20200225151210.647797-13-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , Peter Xu , Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger This patchs adds the skeleton for the virtio-iommu device. Signed-off-by: Eric Auger Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-2-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-iommu.h | 57 +++++++ hw/virtio/virtio-iommu.c | 265 +++++++++++++++++++++++++++++++ hw/virtio/Kconfig | 5 + hw/virtio/Makefile.objs | 1 + hw/virtio/trace-events | 7 + 5 files changed, 335 insertions(+) create mode 100644 include/hw/virtio/virtio-iommu.h create mode 100644 hw/virtio/virtio-iommu.c diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h new file mode 100644 index 0000000000..d24ba63305 --- /dev/null +++ b/include/hw/virtio/virtio-iommu.h @@ -0,0 +1,57 @@ +/* + * virtio-iommu device + * + * Copyright (c) 2020 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + */ + +#ifndef QEMU_VIRTIO_IOMMU_H +#define QEMU_VIRTIO_IOMMU_H + +#include "standard-headers/linux/virtio_iommu.h" +#include "hw/virtio/virtio.h" +#include "hw/pci/pci.h" + +#define TYPE_VIRTIO_IOMMU "virtio-iommu-device" +#define VIRTIO_IOMMU(obj) \ + OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU) + +typedef struct IOMMUDevice { + void *viommu; + PCIBus *bus; + int devfn; + IOMMUMemoryRegion iommu_mr; + AddressSpace as; +} IOMMUDevice; + +typedef struct IOMMUPciBus { + PCIBus *bus; + IOMMUDevice *pbdev[0]; /* Parent array is sparse, so dynamically alloc */ +} IOMMUPciBus; + +typedef struct VirtIOIOMMU { + VirtIODevice parent_obj; + VirtQueue *req_vq; + VirtQueue *event_vq; + struct virtio_iommu_config config; + uint64_t features; + GHashTable *as_by_busptr; + PCIBus *primary_bus; + GTree *domains; + QemuMutex mutex; + GTree *endpoints; +} VirtIOIOMMU; + +#endif diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c new file mode 100644 index 0000000000..30579267d5 --- /dev/null +++ b/hw/virtio/virtio-iommu.c @@ -0,0 +1,265 @@ +/* + * virtio-iommu device + * + * Copyright (c) 2020 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + */ + +#include "qemu/osdep.h" +#include "qemu/iov.h" +#include "qemu-common.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio.h" +#include "sysemu/kvm.h" +#include "trace.h" + +#include "standard-headers/linux/virtio_ids.h" + +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/virtio-access.h" +#include "hw/virtio/virtio-iommu.h" + +/* Max size */ +#define VIOMMU_DEFAULT_QUEUE_SIZE 256 + +static int virtio_iommu_handle_attach(VirtIOIOMMU *s, + struct iovec *iov, + unsigned int iov_cnt) +{ + return VIRTIO_IOMMU_S_UNSUPP; +} +static int virtio_iommu_handle_detach(VirtIOIOMMU *s, + struct iovec *iov, + unsigned int iov_cnt) +{ + return VIRTIO_IOMMU_S_UNSUPP; +} +static int virtio_iommu_handle_map(VirtIOIOMMU *s, + struct iovec *iov, + unsigned int iov_cnt) +{ + return VIRTIO_IOMMU_S_UNSUPP; +} +static int virtio_iommu_handle_unmap(VirtIOIOMMU *s, + struct iovec *iov, + unsigned int iov_cnt) +{ + return VIRTIO_IOMMU_S_UNSUPP; +} + +static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOIOMMU *s = VIRTIO_IOMMU(vdev); + struct virtio_iommu_req_head head; + struct virtio_iommu_req_tail tail = {}; + VirtQueueElement *elem; + unsigned int iov_cnt; + struct iovec *iov; + size_t sz; + + for (;;) { + elem = virtqueue_pop(vq, sizeof(VirtQueueElement)); + if (!elem) { + return; + } + + if (iov_size(elem->in_sg, elem->in_num) < sizeof(tail) || + iov_size(elem->out_sg, elem->out_num) < sizeof(head)) { + virtio_error(vdev, "virtio-iommu bad head/tail size"); + virtqueue_detach_element(vq, elem, 0); + g_free(elem); + break; + } + + iov_cnt = elem->out_num; + iov = elem->out_sg; + sz = iov_to_buf(iov, iov_cnt, 0, &head, sizeof(head)); + if (unlikely(sz != sizeof(head))) { + tail.status = VIRTIO_IOMMU_S_DEVERR; + goto out; + } + qemu_mutex_lock(&s->mutex); + switch (head.type) { + case VIRTIO_IOMMU_T_ATTACH: + tail.status = virtio_iommu_handle_attach(s, iov, iov_cnt); + break; + case VIRTIO_IOMMU_T_DETACH: + tail.status = virtio_iommu_handle_detach(s, iov, iov_cnt); + break; + case VIRTIO_IOMMU_T_MAP: + tail.status = virtio_iommu_handle_map(s, iov, iov_cnt); + break; + case VIRTIO_IOMMU_T_UNMAP: + tail.status = virtio_iommu_handle_unmap(s, iov, iov_cnt); + break; + default: + tail.status = VIRTIO_IOMMU_S_UNSUPP; + } + qemu_mutex_unlock(&s->mutex); + +out: + sz = iov_from_buf(elem->in_sg, elem->in_num, 0, + &tail, sizeof(tail)); + assert(sz == sizeof(tail)); + + virtqueue_push(vq, elem, sizeof(tail)); + virtio_notify(vdev, vq); + g_free(elem); + } +} + +static void virtio_iommu_get_config(VirtIODevice *vdev, uint8_t *config_data) +{ + VirtIOIOMMU *dev = VIRTIO_IOMMU(vdev); + struct virtio_iommu_config *config = &dev->config; + + trace_virtio_iommu_get_config(config->page_size_mask, + config->input_range.start, + config->input_range.end, + config->domain_range.end, + config->probe_size); + memcpy(config_data, &dev->config, sizeof(struct virtio_iommu_config)); +} + +static void virtio_iommu_set_config(VirtIODevice *vdev, + const uint8_t *config_data) +{ + struct virtio_iommu_config config; + + memcpy(&config, config_data, sizeof(struct virtio_iommu_config)); + trace_virtio_iommu_set_config(config.page_size_mask, + config.input_range.start, + config.input_range.end, + config.domain_range.end, + config.probe_size); +} + +static uint64_t virtio_iommu_get_features(VirtIODevice *vdev, uint64_t f, + Error **errp) +{ + VirtIOIOMMU *dev = VIRTIO_IOMMU(vdev); + + f |= dev->features; + trace_virtio_iommu_get_features(f); + return f; +} + +/* + * Migration is not yet supported: most of the state consists + * of balanced binary trees which are not yet ready for getting + * migrated + */ +static const VMStateDescription vmstate_virtio_iommu_device = { + .name = "virtio-iommu-device", + .unmigratable = 1, +}; + +static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtIOIOMMU *s = VIRTIO_IOMMU(dev); + + virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU, + sizeof(struct virtio_iommu_config)); + + s->req_vq = virtio_add_queue(vdev, VIOMMU_DEFAULT_QUEUE_SIZE, + virtio_iommu_handle_command); + s->event_vq = virtio_add_queue(vdev, VIOMMU_DEFAULT_QUEUE_SIZE, NULL); + + s->config.page_size_mask = TARGET_PAGE_MASK; + s->config.input_range.end = -1UL; + s->config.domain_range.end = 32; + + virtio_add_feature(&s->features, VIRTIO_RING_F_EVENT_IDX); + virtio_add_feature(&s->features, VIRTIO_RING_F_INDIRECT_DESC); + virtio_add_feature(&s->features, VIRTIO_F_VERSION_1); + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_INPUT_RANGE); + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_DOMAIN_RANGE); + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_MAP_UNMAP); + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_BYPASS); + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_MMIO); + + qemu_mutex_init(&s->mutex); +} + +static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + + virtio_cleanup(vdev); +} + +static void virtio_iommu_device_reset(VirtIODevice *vdev) +{ + trace_virtio_iommu_device_reset(); +} + +static void virtio_iommu_set_status(VirtIODevice *vdev, uint8_t status) +{ + trace_virtio_iommu_device_status(status); +} + +static void virtio_iommu_instance_init(Object *obj) +{ +} + +static const VMStateDescription vmstate_virtio_iommu = { + .name = "virtio-iommu", + .minimum_version_id = 1, + .version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_VIRTIO_DEVICE, + VMSTATE_END_OF_LIST() + }, +}; + +static Property virtio_iommu_properties[] = { + DEFINE_PROP_LINK("primary-bus", VirtIOIOMMU, primary_bus, "PCI", PCIBus *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_iommu_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, virtio_iommu_properties); + dc->vmsd = &vmstate_virtio_iommu; + + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + vdc->realize = virtio_iommu_device_realize; + vdc->unrealize = virtio_iommu_device_unrealize; + vdc->reset = virtio_iommu_device_reset; + vdc->get_config = virtio_iommu_get_config; + vdc->set_config = virtio_iommu_set_config; + vdc->get_features = virtio_iommu_get_features; + vdc->set_status = virtio_iommu_set_status; + vdc->vmsd = &vmstate_virtio_iommu_device; +} + +static const TypeInfo virtio_iommu_info = { + .name = TYPE_VIRTIO_IOMMU, + .parent = TYPE_VIRTIO_DEVICE, + .instance_size = sizeof(VirtIOIOMMU), + .instance_init = virtio_iommu_instance_init, + .class_init = virtio_iommu_class_init, +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_iommu_info); +} + +type_init(virtio_register_types) diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index f87def27a6..d29525b36f 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -9,6 +9,11 @@ config VIRTIO_RNG default y depends on VIRTIO +config VIRTIO_IOMMU + bool + default y + depends on VIRTIO + config VIRTIO_PCI bool default y if PCI_DEVICES diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index de0f5fc39b..2fd9da7410 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -16,6 +16,7 @@ obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) += virtio-crypto-p obj-$(CONFIG_VIRTIO_PMEM) += virtio-pmem.o common-obj-$(call land,$(CONFIG_VIRTIO_PMEM),$(CONFIG_VIRTIO_PCI)) += virtio-pmem-pci.o obj-$(call land,$(CONFIG_VHOST_USER_FS),$(CONFIG_VIRTIO_PCI)) += vhost-user-fs-pci.o +obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o ifeq ($(CONFIG_VIRTIO_PCI),y) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index e28ba48da6..02d93d7f63 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -53,3 +53,10 @@ virtio_mmio_write_offset(uint64_t offset, uint64_t value) "virtio_mmio_write off virtio_mmio_guest_page(uint64_t size, int shift) "guest page size 0x%" PRIx64 " shift %d" virtio_mmio_queue_write(uint64_t value, int max_size) "mmio_queue write 0x%" PRIx64 " max %d" virtio_mmio_setting_irq(int level) "virtio_mmio setting IRQ %d" + +# hw/virtio/virtio-iommu.c +virtio_iommu_device_reset(void) "reset!" +virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx64 +virtio_iommu_device_status(uint8_t status) "driver status = %d" +virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x" +virtio_iommu_set_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x" From patchwork Tue Feb 25 15:13:30 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: 1244356 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=WORS+EI5; 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 48RjNj1wXGz9sPk for ; Wed, 26 Feb 2020 02:22:45 +1100 (AEDT) Received: from localhost ([::1]:58722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c2l-0007Na-6b for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:22:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55418) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6btz-00084z-Ne for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bty-0001Bp-8S for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:39 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:30942 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bty-0001Ba-3G for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643617; 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=2/w2N230joZaIbVFEeZj6pkIIAP2Uumpk89HeYYYv1Q=; b=WORS+EI5VuorYlDkWB++7HcgVtsnQ+7IHB9iCM1gCzZdkZ+yQyyAzZU2fhnVSL0oBxOdbT hpF9O8FQVD1JazqfCaA23ufG4Nuiuvue/RbqLmrBrBjLgF1P/gIyVpQZwQ2j/0qxHsbO84 dqjhuaQcFKvBJ5Tkw0WcwStCfvD+QUA= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-cBNmQxMxOT-wa691w4i5Hw-1; Tue, 25 Feb 2020 10:13:35 -0500 X-MC-Unique: cBNmQxMxOT-wa691w4i5Hw-1 Received: by mail-qt1-f198.google.com with SMTP id n4so15198545qtv.5 for ; Tue, 25 Feb 2020 07:13:35 -0800 (PST) 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=xgmvF32cDUq1wlORUl4l7hsilZtejs0VN2pRRuhnjaA=; b=aU+NiUIwlhTRICeROGNgb/7/tTQr5vV7Qv8O2G0FBdhwFKrTxfsXGC49XHxc1MMs7A qmmqvJPHJUVj3F9LJhm/AfkBg8QUQ6EqHLIJFS57xr+sWH2A/WA7Kaym7qaxa4tDK/IT pawXUW5TTK4BC8y+hK3rgPYlQfnjWrihDO97urp1sHHdLF2qHfqq7ZbqaBZpqowLVor2 pCPgqLEMxbdiz6OqBG10dBC1iNlIHqxGmX0MdrQy5CcD1baaMdzWGmFdYDSCfuNRcY7T /IXTxeuEIguatcjm/QAfnZ+NO5QmwJudMvW5RBbtm8DDMe727GYZh/vsbJ8E0xQ/uch4 duFg== X-Gm-Message-State: APjAAAXNQDUT+y25sMNe+zA11Qpt9cBwGwFfLsnFEHgG/phd/gdIPFAE Z3HvGIqYaSTH3FhCrLl4l9UNjC1jT2omd2FM2wE7FKtpwOR+2D0WwEB/IYJ5MHsl+W7WLImX2iM mPHwcLA8XOEgPhog= X-Received: by 2002:a37:b8c:: with SMTP id 134mr20113633qkl.217.1582643614691; Tue, 25 Feb 2020 07:13:34 -0800 (PST) X-Google-Smtp-Source: APXvYqyRyMiN62IyJO8Zce+jmUSWyszgch3TSbJbBYnnyJutT9RVr2HtMdPKAcIkh+xNLrxfo3Y9+A== X-Received: by 2002:a37:b8c:: with SMTP id 134mr20113597qkl.217.1582643614368; Tue, 25 Feb 2020 07:13:34 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id 11sm3941718qkr.101.2020.02.25.07.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:33 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:30 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 13/32] virtio-iommu: Decode the command payload Message-ID: <20200225151210.647797-14-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Jean-Philippe Brucker , Peter Xu , Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger This patch adds the command payload decoding and introduces the functions that will do the actual command handling. Those functions are not yet implemented. Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-3-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 76 +++++++++++++++++++++++++++++++++------- hw/virtio/trace-events | 4 +++ 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 30579267d5..86dcdc09a1 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -34,31 +34,83 @@ /* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 -static int virtio_iommu_handle_attach(VirtIOIOMMU *s, - struct iovec *iov, - unsigned int iov_cnt) +static int virtio_iommu_attach(VirtIOIOMMU *s, + struct virtio_iommu_req_attach *req) { + uint32_t domain_id = le32_to_cpu(req->domain); + uint32_t ep_id = le32_to_cpu(req->endpoint); + + trace_virtio_iommu_attach(domain_id, ep_id); + return VIRTIO_IOMMU_S_UNSUPP; } -static int virtio_iommu_handle_detach(VirtIOIOMMU *s, - struct iovec *iov, - unsigned int iov_cnt) + +static int virtio_iommu_detach(VirtIOIOMMU *s, + struct virtio_iommu_req_detach *req) { + uint32_t domain_id = le32_to_cpu(req->domain); + uint32_t ep_id = le32_to_cpu(req->endpoint); + + trace_virtio_iommu_detach(domain_id, ep_id); + return VIRTIO_IOMMU_S_UNSUPP; } -static int virtio_iommu_handle_map(VirtIOIOMMU *s, - struct iovec *iov, - unsigned int iov_cnt) + +static int virtio_iommu_map(VirtIOIOMMU *s, + struct virtio_iommu_req_map *req) { + uint32_t domain_id = le32_to_cpu(req->domain); + uint64_t phys_start = le64_to_cpu(req->phys_start); + uint64_t virt_start = le64_to_cpu(req->virt_start); + uint64_t virt_end = le64_to_cpu(req->virt_end); + uint32_t flags = le32_to_cpu(req->flags); + + trace_virtio_iommu_map(domain_id, virt_start, virt_end, phys_start, flags); + return VIRTIO_IOMMU_S_UNSUPP; } -static int virtio_iommu_handle_unmap(VirtIOIOMMU *s, - struct iovec *iov, - unsigned int iov_cnt) + +static int virtio_iommu_unmap(VirtIOIOMMU *s, + struct virtio_iommu_req_unmap *req) { + uint32_t domain_id = le32_to_cpu(req->domain); + uint64_t virt_start = le64_to_cpu(req->virt_start); + uint64_t virt_end = le64_to_cpu(req->virt_end); + + trace_virtio_iommu_unmap(domain_id, virt_start, virt_end); + return VIRTIO_IOMMU_S_UNSUPP; } +static int virtio_iommu_iov_to_req(struct iovec *iov, + unsigned int iov_cnt, + void *req, size_t req_sz) +{ + size_t sz, payload_sz = req_sz - sizeof(struct virtio_iommu_req_tail); + + sz = iov_to_buf(iov, iov_cnt, 0, req, payload_sz); + if (unlikely(sz != payload_sz)) { + return VIRTIO_IOMMU_S_INVAL; + } + return 0; +} + +#define virtio_iommu_handle_req(__req) \ +static int virtio_iommu_handle_ ## __req(VirtIOIOMMU *s, \ + struct iovec *iov, \ + unsigned int iov_cnt) \ +{ \ + struct virtio_iommu_req_ ## __req req; \ + int ret = virtio_iommu_iov_to_req(iov, iov_cnt, &req, sizeof(req)); \ + \ + return ret ? ret : virtio_iommu_ ## __req(s, &req); \ +} + +virtio_iommu_handle_req(attach) +virtio_iommu_handle_req(detach) +virtio_iommu_handle_req(map) +virtio_iommu_handle_req(unmap) + static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq) { VirtIOIOMMU *s = VIRTIO_IOMMU(vdev); diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 02d93d7f63..f7141aa2f6 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -60,3 +60,7 @@ virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx6 virtio_iommu_device_status(uint8_t status) "driver status = %d" virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x" virtio_iommu_set_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x" +virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" +virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" +virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d" +virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 From patchwork Tue Feb 25 15:13:35 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: 1244367 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=Wx9wi4e/; 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 48RjYt3dKGz9sPk for ; Wed, 26 Feb 2020 02:30:42 +1100 (AEDT) Received: from localhost ([::1]:58892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6cAS-00048S-DV for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:30:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56613) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bxL-0006Na-Cw for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:17:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bxJ-00035T-9e for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:17:07 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47264 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bxJ-00035J-2x for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:17:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643824; 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=NMAj9pjIkF3ld+iDd5GqS5f/z/G50hz2CU4TL13+qts=; b=Wx9wi4e/O/EBq0ndlThR5FBxeT/NMyHUHgE8PGActWtV6FDMRTNZUbsJhon49uSxofehIK tEtl4cN4jcIHBdxPF1LH/CZ+xkKRsMdqWuzsS5JZjdPMUOCRZC6PxOUwCK7h5gQlXldP+/ GNnhCUGeWdtW1M4itRgbhLgc2YsTxY0= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-217-kDOAVUyQPvmbiztJpjh5vg-1; Tue, 25 Feb 2020 10:13:40 -0500 X-MC-Unique: kDOAVUyQPvmbiztJpjh5vg-1 Received: by mail-qt1-f198.google.com with SMTP id l1so15127024qtp.21 for ; Tue, 25 Feb 2020 07:13:40 -0800 (PST) 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=RxHVBAY0Duy5OWppSLHQREt5mvI4Xg2rj5hPviwqVxI=; b=gu4QJlxbUoV48aL1BgSTnjdGkzO0/m00nqSZs17H7nox1H3WEiuQ3hNj3klmb3BzrK 6eOvUKC9+kmPh5MbVhsVTb8DD691yJYVmH9OSdZ/ySw/p4dHoZ7Axdc5n9RuxazAMLfr rjdckjUgVkKHBq+KBcNd+iwApLz5rtuYDPi/YPP7Y+QEXH7fnn9x+oHJgVQIlzgcU2+1 Xkz7vCVd7sPj/YH+60suRXjah0BvkML8JWS3SZBGgOXXTCXkMqrv9X3S77IJX0B2q6mz HxmT7avxeWpXa/Vj7VlpdxShAATwvSanmJYIaJ4ySWHu1EwH8ju0R2QXiMjrC6RS2lRX Nf/g== X-Gm-Message-State: APjAAAWjhYC+tRiXtelGyaBfeEFJJcMmDZu5blq0keotJ45cewjq7AJ+ zljbXgY4ZanuPzCxeaWu/xxb/rvCUCbtTu9Xfi27xGGysbEDwkina9vi5/mDGJTSUpCyAajHPdM RTgRfVh5Hh15Y6+I= X-Received: by 2002:a05:620a:785:: with SMTP id 5mr28307213qka.149.1582643619772; Tue, 25 Feb 2020 07:13:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxMFd3jnb+k/ewwaNrgBsMe56ADIr3BVBqblby66DIlemDWaeDKyzDMjGjdypS1EQAnQXBYUg== X-Received: by 2002:a05:620a:785:: with SMTP id 5mr28307166qka.149.1582643619339; Tue, 25 Feb 2020 07:13:39 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id g2sm7396431qkb.27.2020.02.25.07.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:38 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:35 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 14/32] virtio-iommu: Implement attach/detach command Message-ID: <20200225151210.647797-15-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Peter Xu , Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger This patch implements the endpoint attach/detach to/from a domain. Domain and endpoint internal datatypes are introduced. Both are stored in RB trees. The domain owns a list of endpoints attached to it. Also helpers to get/put end points and domains are introduced. As for the IOMMU memory regions, a callback is called on PCI bus enumeration that initializes for a given device on the bus hierarchy an IOMMU memory region. The PCI bus hierarchy is stored locally in IOMMUPciBus and IOMMUDevice objects. At the time of the enumeration, the bus number may not be computed yet. So operations that will need to retrieve the IOMMUdevice and its IOMMU memory region from the bus number and devfn, once the bus number is garanteed to be frozen, use an array of IOMMUPciBus, lazily populated. Signed-off-by: Eric Auger Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-4-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-iommu.h | 3 + hw/virtio/virtio-iommu.c | 311 ++++++++++++++++++++++++++++++- hw/virtio/trace-events | 6 + 3 files changed, 318 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h index d24ba63305..ae88f730cf 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -28,6 +28,8 @@ #define VIRTIO_IOMMU(obj) \ OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU) +#define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region" + typedef struct IOMMUDevice { void *viommu; PCIBus *bus; @@ -48,6 +50,7 @@ typedef struct VirtIOIOMMU { struct virtio_iommu_config config; uint64_t features; GHashTable *as_by_busptr; + IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX]; PCIBus *primary_bus; GTree *domains; QemuMutex mutex; diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 86dcdc09a1..d9fe83f530 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -23,6 +23,8 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio.h" #include "sysemu/kvm.h" +#include "qapi/error.h" +#include "qemu/error-report.h" #include "trace.h" #include "standard-headers/linux/virtio_ids.h" @@ -30,19 +32,236 @@ #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" /* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 +typedef struct VirtIOIOMMUDomain { + uint32_t id; + GTree *mappings; + QLIST_HEAD(, VirtIOIOMMUEndpoint) endpoint_list; +} VirtIOIOMMUDomain; + +typedef struct VirtIOIOMMUEndpoint { + uint32_t id; + VirtIOIOMMUDomain *domain; + QLIST_ENTRY(VirtIOIOMMUEndpoint) next; +} VirtIOIOMMUEndpoint; + +typedef struct VirtIOIOMMUInterval { + uint64_t low; + uint64_t high; +} VirtIOIOMMUInterval; + +static inline uint16_t virtio_iommu_get_bdf(IOMMUDevice *dev) +{ + return PCI_BUILD_BDF(pci_bus_num(dev->bus), dev->devfn); +} + +/** + * The bus number is used for lookup when SID based operations occur. + * In that case we lazily populate the IOMMUPciBus array from the bus hash + * table. At the time the IOMMUPciBus is created (iommu_find_add_as), the bus + * numbers may not be always initialized yet. + */ +static IOMMUPciBus *iommu_find_iommu_pcibus(VirtIOIOMMU *s, uint8_t bus_num) +{ + IOMMUPciBus *iommu_pci_bus = s->iommu_pcibus_by_bus_num[bus_num]; + + if (!iommu_pci_bus) { + GHashTableIter iter; + + g_hash_table_iter_init(&iter, s->as_by_busptr); + while (g_hash_table_iter_next(&iter, NULL, (void **)&iommu_pci_bus)) { + if (pci_bus_num(iommu_pci_bus->bus) == bus_num) { + s->iommu_pcibus_by_bus_num[bus_num] = iommu_pci_bus; + return iommu_pci_bus; + } + } + return NULL; + } + return iommu_pci_bus; +} + +static IOMMUMemoryRegion *virtio_iommu_mr(VirtIOIOMMU *s, uint32_t sid) +{ + uint8_t bus_n, devfn; + IOMMUPciBus *iommu_pci_bus; + IOMMUDevice *dev; + + bus_n = PCI_BUS_NUM(sid); + iommu_pci_bus = iommu_find_iommu_pcibus(s, bus_n); + if (iommu_pci_bus) { + devfn = sid & PCI_DEVFN_MAX; + dev = iommu_pci_bus->pbdev[devfn]; + if (dev) { + return &dev->iommu_mr; + } + } + return NULL; +} + +static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_data) +{ + VirtIOIOMMUInterval *inta = (VirtIOIOMMUInterval *)a; + VirtIOIOMMUInterval *intb = (VirtIOIOMMUInterval *)b; + + if (inta->high < intb->low) { + return -1; + } else if (intb->high < inta->low) { + return 1; + } else { + return 0; + } +} + +static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *ep) +{ + if (!ep->domain) { + return; + } + QLIST_REMOVE(ep, next); + ep->domain = NULL; +} + +static VirtIOIOMMUEndpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s, + uint32_t ep_id) +{ + VirtIOIOMMUEndpoint *ep; + + ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id)); + if (ep) { + return ep; + } + if (!virtio_iommu_mr(s, ep_id)) { + return NULL; + } + ep = g_malloc0(sizeof(*ep)); + ep->id = ep_id; + trace_virtio_iommu_get_endpoint(ep_id); + g_tree_insert(s->endpoints, GUINT_TO_POINTER(ep_id), ep); + return ep; +} + +static void virtio_iommu_put_endpoint(gpointer data) +{ + VirtIOIOMMUEndpoint *ep = (VirtIOIOMMUEndpoint *)data; + + if (ep->domain) { + virtio_iommu_detach_endpoint_from_domain(ep); + } + + trace_virtio_iommu_put_endpoint(ep->id); + g_free(ep); +} + +static VirtIOIOMMUDomain *virtio_iommu_get_domain(VirtIOIOMMU *s, + uint32_t domain_id) +{ + VirtIOIOMMUDomain *domain; + + domain = g_tree_lookup(s->domains, GUINT_TO_POINTER(domain_id)); + if (domain) { + return domain; + } + domain = g_malloc0(sizeof(*domain)); + domain->id = domain_id; + domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp, + NULL, (GDestroyNotify)g_free, + (GDestroyNotify)g_free); + g_tree_insert(s->domains, GUINT_TO_POINTER(domain_id), domain); + QLIST_INIT(&domain->endpoint_list); + trace_virtio_iommu_get_domain(domain_id); + return domain; +} + +static void virtio_iommu_put_domain(gpointer data) +{ + VirtIOIOMMUDomain *domain = (VirtIOIOMMUDomain *)data; + VirtIOIOMMUEndpoint *iter, *tmp; + + QLIST_FOREACH_SAFE(iter, &domain->endpoint_list, next, tmp) { + virtio_iommu_detach_endpoint_from_domain(iter); + } + g_tree_destroy(domain->mappings); + trace_virtio_iommu_put_domain(domain->id); + g_free(domain); +} + +static AddressSpace *virtio_iommu_find_add_as(PCIBus *bus, void *opaque, + int devfn) +{ + VirtIOIOMMU *s = opaque; + IOMMUPciBus *sbus = g_hash_table_lookup(s->as_by_busptr, bus); + static uint32_t mr_index; + IOMMUDevice *sdev; + + if (!sbus) { + sbus = g_malloc0(sizeof(IOMMUPciBus) + + sizeof(IOMMUDevice *) * PCI_DEVFN_MAX); + sbus->bus = bus; + g_hash_table_insert(s->as_by_busptr, bus, sbus); + } + + sdev = sbus->pbdev[devfn]; + if (!sdev) { + char *name = g_strdup_printf("%s-%d-%d", + TYPE_VIRTIO_IOMMU_MEMORY_REGION, + mr_index++, devfn); + sdev = sbus->pbdev[devfn] = g_malloc0(sizeof(IOMMUDevice)); + + sdev->viommu = s; + sdev->bus = bus; + sdev->devfn = devfn; + + trace_virtio_iommu_init_iommu_mr(name); + + memory_region_init_iommu(&sdev->iommu_mr, sizeof(sdev->iommu_mr), + TYPE_VIRTIO_IOMMU_MEMORY_REGION, + OBJECT(s), name, + UINT64_MAX); + address_space_init(&sdev->as, + MEMORY_REGION(&sdev->iommu_mr), TYPE_VIRTIO_IOMMU); + g_free(name); + } + return &sdev->as; +} + static int virtio_iommu_attach(VirtIOIOMMU *s, struct virtio_iommu_req_attach *req) { uint32_t domain_id = le32_to_cpu(req->domain); uint32_t ep_id = le32_to_cpu(req->endpoint); + VirtIOIOMMUDomain *domain; + VirtIOIOMMUEndpoint *ep; trace_virtio_iommu_attach(domain_id, ep_id); - return VIRTIO_IOMMU_S_UNSUPP; + ep = virtio_iommu_get_endpoint(s, ep_id); + if (!ep) { + return VIRTIO_IOMMU_S_NOENT; + } + + if (ep->domain) { + VirtIOIOMMUDomain *previous_domain = ep->domain; + /* + * the device is already attached to a domain, + * detach it first + */ + virtio_iommu_detach_endpoint_from_domain(ep); + if (QLIST_EMPTY(&previous_domain->endpoint_list)) { + g_tree_remove(s->domains, GUINT_TO_POINTER(previous_domain->id)); + } + } + + domain = virtio_iommu_get_domain(s, domain_id); + QLIST_INSERT_HEAD(&domain->endpoint_list, ep, next); + + ep->domain = domain; + + return VIRTIO_IOMMU_S_OK; } static int virtio_iommu_detach(VirtIOIOMMU *s, @@ -50,10 +269,28 @@ static int virtio_iommu_detach(VirtIOIOMMU *s, { uint32_t domain_id = le32_to_cpu(req->domain); uint32_t ep_id = le32_to_cpu(req->endpoint); + VirtIOIOMMUDomain *domain; + VirtIOIOMMUEndpoint *ep; trace_virtio_iommu_detach(domain_id, ep_id); - return VIRTIO_IOMMU_S_UNSUPP; + ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id)); + if (!ep) { + return VIRTIO_IOMMU_S_NOENT; + } + + domain = ep->domain; + + if (!domain || domain->id != domain_id) { + return VIRTIO_IOMMU_S_INVAL; + } + + virtio_iommu_detach_endpoint_from_domain(ep); + + if (QLIST_EMPTY(&domain->endpoint_list)) { + g_tree_remove(s->domains, GUINT_TO_POINTER(domain->id)); + } + return VIRTIO_IOMMU_S_OK; } static int virtio_iommu_map(VirtIOIOMMU *s, @@ -172,6 +409,27 @@ out: } } +static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, + IOMMUAccessFlags flag, + int iommu_idx) +{ + IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); + uint32_t sid; + + IOMMUTLBEntry entry = { + .target_as = &address_space_memory, + .iova = addr, + .translated_addr = addr, + .addr_mask = ~(hwaddr)0, + .perm = IOMMU_NONE, + }; + + sid = virtio_iommu_get_bdf(sdev); + + trace_virtio_iommu_translate(mr->parent_obj.name, sid, addr, flag); + return entry; +} + static void virtio_iommu_get_config(VirtIODevice *vdev, uint8_t *config_data) { VirtIOIOMMU *dev = VIRTIO_IOMMU(vdev); @@ -218,6 +476,13 @@ static const VMStateDescription vmstate_virtio_iommu_device = { .unmigratable = 1, }; +static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data) +{ + guint ua = GPOINTER_TO_UINT(a); + guint ub = GPOINTER_TO_UINT(b); + return (ua > ub) - (ua < ub); +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -226,6 +491,8 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU, sizeof(struct virtio_iommu_config)); + memset(s->iommu_pcibus_by_bus_num, 0, sizeof(s->iommu_pcibus_by_bus_num)); + s->req_vq = virtio_add_queue(vdev, VIOMMU_DEFAULT_QUEUE_SIZE, virtio_iommu_handle_command); s->event_vq = virtio_add_queue(vdev, VIOMMU_DEFAULT_QUEUE_SIZE, NULL); @@ -244,18 +511,43 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) virtio_add_feature(&s->features, VIRTIO_IOMMU_F_MMIO); qemu_mutex_init(&s->mutex); + + s->as_by_busptr = g_hash_table_new_full(NULL, NULL, NULL, g_free); + + if (s->primary_bus) { + pci_setup_iommu(s->primary_bus, virtio_iommu_find_add_as, s); + } else { + error_setg(errp, "VIRTIO-IOMMU is not attached to any PCI bus!"); + } } static void virtio_iommu_device_unrealize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtIOIOMMU *s = VIRTIO_IOMMU(dev); + + g_tree_destroy(s->domains); + g_tree_destroy(s->endpoints); virtio_cleanup(vdev); } static void virtio_iommu_device_reset(VirtIODevice *vdev) { + VirtIOIOMMU *s = VIRTIO_IOMMU(vdev); + trace_virtio_iommu_device_reset(); + + if (s->domains) { + g_tree_destroy(s->domains); + } + if (s->endpoints) { + g_tree_destroy(s->endpoints); + } + s->domains = g_tree_new_full((GCompareDataFunc)int_cmp, + NULL, NULL, virtio_iommu_put_domain); + s->endpoints = g_tree_new_full((GCompareDataFunc)int_cmp, + NULL, NULL, virtio_iommu_put_endpoint); } static void virtio_iommu_set_status(VirtIODevice *vdev, uint8_t status) @@ -301,6 +593,14 @@ static void virtio_iommu_class_init(ObjectClass *klass, void *data) vdc->vmsd = &vmstate_virtio_iommu_device; } +static void virtio_iommu_memory_region_class_init(ObjectClass *klass, + void *data) +{ + IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass); + + imrc->translate = virtio_iommu_translate; +} + static const TypeInfo virtio_iommu_info = { .name = TYPE_VIRTIO_IOMMU, .parent = TYPE_VIRTIO_DEVICE, @@ -309,9 +609,16 @@ static const TypeInfo virtio_iommu_info = { .class_init = virtio_iommu_class_init, }; +static const TypeInfo virtio_iommu_memory_region_info = { + .parent = TYPE_IOMMU_MEMORY_REGION, + .name = TYPE_VIRTIO_IOMMU_MEMORY_REGION, + .class_init = virtio_iommu_memory_region_class_init, +}; + static void virtio_register_types(void) { type_register_static(&virtio_iommu_info); + type_register_static(&virtio_iommu_memory_region_info); } type_init(virtio_register_types) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index f7141aa2f6..15595f8cd7 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -64,3 +64,9 @@ virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d" virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 +virtio_iommu_translate(const char *name, uint32_t rid, uint64_t iova, int flag) "mr=%s rid=%d addr=0x%"PRIx64" flag=%d" +virtio_iommu_init_iommu_mr(char *iommu_mr) "init %s" +virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d" +virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d" +virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d" +virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d" From patchwork Tue Feb 25 15:13:39 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: 1244348 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=eOA+UX7H; 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 48RjJh4wJxz9sPk for ; Wed, 26 Feb 2020 02:19:16 +1100 (AEDT) Received: from localhost ([::1]:58586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bzO-0008SH-K0 for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:19:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55481) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bu9-00005H-Fh for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bu8-0001HX-6K for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:49 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:37924 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bu8-0001H8-1L for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643627; 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=mlqnYTiCL5sSu8La8pKbwI5Hcn1vRF70/ll/0BpTLCk=; b=eOA+UX7H6Mw0PEqoAURBaBI2r4+4MBLl0DXsLH1X90g83iz8yH+P2FmvMw1ajJfKC1JKDk +vWAiX3EKsDdmqTJPTKugIVyCMoP/UIUHyA9DHFgPgvsOt/JIClFYVZR6EXmVECabuqYzU 5l32Y0l63wsr52ThKXUHp9NzZZmuBjs= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-8-TfgxmOKpMiupzwQv8Drznw-1; Tue, 25 Feb 2020 10:13:45 -0500 X-MC-Unique: TfgxmOKpMiupzwQv8Drznw-1 Received: by mail-qv1-f71.google.com with SMTP id j15so13146967qvp.21 for ; Tue, 25 Feb 2020 07:13:45 -0800 (PST) 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=lHLed9bH8w5j/vQYZvogfr5RN4RsIFaxj1zVa5/6ti0=; b=Ca1f4QHyfg+r78DY+EGNVO5W8opQqby/A6YjsoHPffh5UYm/r0FGSbQCT5md2ma+4J SzsUd9odSdejMYRIJnlO9E+3vB3nEas0pZwub4SFsrxVcNFOKAu/1qthYNhNx0qMwHuS 9y7/0n2rJ1/OvHFpGSIShrl49XwB1+EOYA3gE260FOHQoeSR1O5cBvDVrPF1F1SIUgXW 6XuHk9dYpMAZpMVhiEzgJ5ZWP7imrnqfl6NkTKq8EbQHBVRyF2LYzTrgnGuH2LtzoGe3 gzv6DnAqX+3DR3PET90RmJTU4VaTjSzw31kxnb6vs24GNEAqoq6u0+0bDBon7x4+ew6J XztA== X-Gm-Message-State: APjAAAWJ5UwRrzKTDJTtEblngItmw3t5zhT+3xrLc4aNOQ+oFc73j9Pc bET0y60x/idqxzpGjAqzbaODkJNwscacXKDN6kIJDOWdnpqQ3JK2PZI7VKVR4QCwqfaCRA/CRIJ 6p4zHcc6Zvoa5Wkg= X-Received: by 2002:a05:6214:b23:: with SMTP id w3mr51653307qvj.181.1582643624948; Tue, 25 Feb 2020 07:13:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxy/Frsjx/2JPAiD/TSQwnieL7OX6XSBenEGnO3cNZ0cRlwQ2qaFdcjXv+tDOJTYsRNH0CW1g== X-Received: by 2002:a05:6214:b23:: with SMTP id w3mr51653277qvj.181.1582643624685; Tue, 25 Feb 2020 07:13:44 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id 12sm5479644qkj.136.2020.02.25.07.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:43 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:39 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 15/32] virtio-iommu: Implement map/unmap Message-ID: <20200225151210.647797-16-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , Peter Xu , Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger This patch implements virtio_iommu_map/unmap. Signed-off-by: Eric Auger Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-5-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 63 ++++++++++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index d9fe83f530..844d34c270 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "qemu/iov.h" #include "qemu-common.h" #include "hw/qdev-properties.h" @@ -55,6 +56,11 @@ typedef struct VirtIOIOMMUInterval { uint64_t high; } VirtIOIOMMUInterval; +typedef struct VirtIOIOMMUMapping { + uint64_t phys_addr; + uint32_t flags; +} VirtIOIOMMUMapping; + static inline uint16_t virtio_iommu_get_bdf(IOMMUDevice *dev) { return PCI_BUILD_BDF(pci_bus_num(dev->bus), dev->devfn); @@ -301,10 +307,39 @@ static int virtio_iommu_map(VirtIOIOMMU *s, uint64_t virt_start = le64_to_cpu(req->virt_start); uint64_t virt_end = le64_to_cpu(req->virt_end); uint32_t flags = le32_to_cpu(req->flags); + VirtIOIOMMUDomain *domain; + VirtIOIOMMUInterval *interval; + VirtIOIOMMUMapping *mapping; + + if (flags & ~VIRTIO_IOMMU_MAP_F_MASK) { + return VIRTIO_IOMMU_S_INVAL; + } + + domain = g_tree_lookup(s->domains, GUINT_TO_POINTER(domain_id)); + if (!domain) { + return VIRTIO_IOMMU_S_NOENT; + } + + interval = g_malloc0(sizeof(*interval)); + + interval->low = virt_start; + interval->high = virt_end; + + mapping = g_tree_lookup(domain->mappings, (gpointer)interval); + if (mapping) { + g_free(interval); + return VIRTIO_IOMMU_S_INVAL; + } trace_virtio_iommu_map(domain_id, virt_start, virt_end, phys_start, flags); - return VIRTIO_IOMMU_S_UNSUPP; + mapping = g_malloc0(sizeof(*mapping)); + mapping->phys_addr = phys_start; + mapping->flags = flags; + + g_tree_insert(domain->mappings, interval, mapping); + + return VIRTIO_IOMMU_S_OK; } static int virtio_iommu_unmap(VirtIOIOMMU *s, @@ -313,10 +348,34 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, uint32_t domain_id = le32_to_cpu(req->domain); uint64_t virt_start = le64_to_cpu(req->virt_start); uint64_t virt_end = le64_to_cpu(req->virt_end); + VirtIOIOMMUMapping *iter_val; + VirtIOIOMMUInterval interval, *iter_key; + VirtIOIOMMUDomain *domain; + int ret = VIRTIO_IOMMU_S_OK; trace_virtio_iommu_unmap(domain_id, virt_start, virt_end); - return VIRTIO_IOMMU_S_UNSUPP; + domain = g_tree_lookup(s->domains, GUINT_TO_POINTER(domain_id)); + if (!domain) { + return VIRTIO_IOMMU_S_NOENT; + } + interval.low = virt_start; + interval.high = virt_end; + + while (g_tree_lookup_extended(domain->mappings, &interval, + (void **)&iter_key, (void**)&iter_val)) { + uint64_t current_low = iter_key->low; + uint64_t current_high = iter_key->high; + + if (interval.low <= current_low && interval.high >= current_high) { + g_tree_remove(domain->mappings, iter_key); + trace_virtio_iommu_unmap_done(domain_id, current_low, current_high); + } else { + ret = VIRTIO_IOMMU_S_RANGE; + break; + } + } + return ret; } static int virtio_iommu_iov_to_req(struct iovec *iov, diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 15595f8cd7..22162d6583 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -64,6 +64,7 @@ virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d" virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 +virtio_iommu_unmap_done(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 virtio_iommu_translate(const char *name, uint32_t rid, uint64_t iova, int flag) "mr=%s rid=%d addr=0x%"PRIx64" flag=%d" virtio_iommu_init_iommu_mr(char *iommu_mr) "init %s" virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d" From patchwork Tue Feb 25 15:13: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: 1244352 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=QMqIaKra; 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 48RjLs4s2vz9sPk for ; Wed, 26 Feb 2020 02:21:09 +1100 (AEDT) Received: from localhost ([::1]:58660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c1D-0003VF-AM for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:21:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55522) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6buE-0000Jz-ES for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buD-0001Jz-7k for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43702 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6buD-0001Jc-2n for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643632; 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=2Hdj7mMudGk1On0DfbPW0ZE9c8URLY6uwbzuI/qZJHc=; b=QMqIaKrayFywYXUFHmcrzaFMHVEwSr1rh5eFa7xdZoOZjVxxTwWvLh930sdAdXZ8T+gZra WFFViH90l3qgWknYPYQYlU/yEHRt+hDdce77pEiQsN9064XuDkBPhWf6w01GxSRbjj5Sz/ eKRhOwc9+uwhAjlWYPuc3aN8BZNGb+Y= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-457-HRWsKFzuOciHhzTA-vSiqg-1; Tue, 25 Feb 2020 10:13:50 -0500 X-MC-Unique: HRWsKFzuOciHhzTA-vSiqg-1 Received: by mail-qt1-f200.google.com with SMTP id o24so15208192qtr.17 for ; Tue, 25 Feb 2020 07:13:50 -0800 (PST) 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=24gCc88fSkegGYSyr5CnQiCms+AAwtwlqsX/zbg/vTA=; b=UbTFrNGsQdbHvDt05EdwYacQIYPH24Ogb2EAe7swIOBlmfML+6v+99ngvLRUPWd2Oq 7TtpR+9sguGtyBJ12/g41229yZ79dHQlr2wut0SI7xXqT+ww4Yzn175RsveVd+LntWnE 4pkEbtCe0MLCwtC35ogqXvbmLKY9QSNbF77aam9Wc3HmB9wceX336Sb19acYmhPLSPYB QsAoflT9/NIKsbTkexQn5FHBLBIKOn9HOtNDWf84oNjsbBTMcM/NElokV5jXmb4Q8zH5 wp64UXL6xSsX94KH6Ug+c3GJ6uq+thlISC07kCvtludUVgveWwOQDetmJnSBDO2VGgjQ 8xFw== X-Gm-Message-State: APjAAAX86PxQtdUibEdyojYHw/T0c4ZTht9niaVXFkRJe6AX19j+F+fJ Q5cFqmFn9Z9V9/Bg5u0TJJAg0hFCpHblTFNsBv0qEfmFLqyUl3cQ+7DSTHKCJ/C/dKYLI3yyqg2 7ejupiQFxP5cO+q4= X-Received: by 2002:a37:66c8:: with SMTP id a191mr13320071qkc.0.1582643629451; Tue, 25 Feb 2020 07:13:49 -0800 (PST) X-Google-Smtp-Source: APXvYqxEmiANRPLpoRJld98WMa5sG0h0/Gd5C64IcqE8o38i2boTgLwdCWz1iD/PmtLdop/fy30Hyg== X-Received: by 2002:a37:66c8:: with SMTP id a191mr13320048qkc.0.1582643629254; Tue, 25 Feb 2020 07:13:49 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id w53sm7684910qtb.91.2020.02.25.07.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:48 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:45 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 16/32] virtio-iommu: Implement translate Message-ID: <20200225151210.647797-17-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Jean-Philippe Brucker , Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger This patch implements the translate callback Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-6-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 60 +++++++++++++++++++++++++++++++++++++++- hw/virtio/trace-events | 1 + 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 844d34c270..59e9cd3d9a 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -473,19 +473,77 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, int iommu_idx) { IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMUInterval interval, *mapping_key; + VirtIOIOMMUMapping *mapping_value; + VirtIOIOMMU *s = sdev->viommu; + VirtIOIOMMUEndpoint *ep; + bool bypass_allowed; uint32_t sid; + bool found; + + interval.low = addr; + interval.high = addr + 1; IOMMUTLBEntry entry = { .target_as = &address_space_memory, .iova = addr, .translated_addr = addr, - .addr_mask = ~(hwaddr)0, + .addr_mask = (1 << ctz32(s->config.page_size_mask)) - 1, .perm = IOMMU_NONE, }; + bypass_allowed = virtio_vdev_has_feature(&s->parent_obj, + VIRTIO_IOMMU_F_BYPASS); + sid = virtio_iommu_get_bdf(sdev); trace_virtio_iommu_translate(mr->parent_obj.name, sid, addr, flag); + qemu_mutex_lock(&s->mutex); + + ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(sid)); + if (!ep) { + if (!bypass_allowed) { + error_report_once("%s sid=%d is not known!!", __func__, sid); + } else { + entry.perm = flag; + } + goto unlock; + } + + if (!ep->domain) { + if (!bypass_allowed) { + error_report_once("%s %02x:%02x.%01x not attached to any domain", + __func__, PCI_BUS_NUM(sid), + PCI_SLOT(sid), PCI_FUNC(sid)); + } else { + entry.perm = flag; + } + goto unlock; + } + + found = g_tree_lookup_extended(ep->domain->mappings, (gpointer)(&interval), + (void **)&mapping_key, + (void **)&mapping_value); + if (!found) { + error_report_once("%s no mapping for 0x%"PRIx64" for sid=%d", + __func__, addr, sid); + goto unlock; + } + + if (((flag & IOMMU_RO) && + !(mapping_value->flags & VIRTIO_IOMMU_MAP_F_READ)) || + ((flag & IOMMU_WO) && + !(mapping_value->flags & VIRTIO_IOMMU_MAP_F_WRITE))) { + error_report_once("%s permission error on 0x%"PRIx64"(%d): allowed=%d", + __func__, addr, flag, mapping_value->flags); + goto unlock; + } + entry.translated_addr = addr - mapping_key->low + mapping_value->phys_addr; + entry.perm = flag; + trace_virtio_iommu_translate_out(addr, entry.translated_addr, sid); + +unlock: + qemu_mutex_unlock(&s->mutex); return entry; } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 22162d6583..095aa8b509 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -71,3 +71,4 @@ virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d" virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d" 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" From patchwork Tue Feb 25 15:13:49 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: 1244342 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=PhFdCbsA; 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 48RjDZ3tyqz9sPk for ; Wed, 26 Feb 2020 02:15:42 +1100 (AEDT) Received: from localhost ([::1]:58522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bvw-0002ll-Dw for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:15:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55549) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6buJ-0000ZY-IR for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buI-0001Lp-9a for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:59 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:22064 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6buI-0001Lb-4T for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:13:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643637; 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=zCHf9L72V/C0Pq98N5gIZEjtBfCuRngk9tHaSFXAuXI=; b=PhFdCbsACqlK9pb2qAXMyjot0raJUMufrur2qCiy9n8RSjQQp+VYaUdpbb0PYXvNNd28VE PBrjlmTEs7iRLwDoFJUku3/er53witnC6wO58i3k/vpAYrn0OZPoCzAwXehpBH/yT3othR SAJlPu3Clk9I3eLfGiD1kwSv2eo4BRg= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-NB27zbEFOB2MVtkZdoM-iA-1; Tue, 25 Feb 2020 10:13:55 -0500 X-MC-Unique: NB27zbEFOB2MVtkZdoM-iA-1 Received: by mail-qv1-f70.google.com with SMTP id z39so13236120qve.5 for ; Tue, 25 Feb 2020 07:13:55 -0800 (PST) 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=fMIucinzsx9/9CFPWzNLF6NCV2892T+sCnYLhAijSBk=; b=jQUUNAuq52F7JcIm1I7NFmmXaf8jkJA+6U5LFgHp26N9EOuVhwehkoUax6od6pj/0/ KqanENPwjpt1oi+LldkvDAXZWEbrZdv4wblXtZRyFkYg3xc3me+ISAmhImW0LDQxsBZS XkK2SnRQrzJHXEAfs3/QXnCNEOv1q5b2pXNblCXRu5IU+NB1X7JmKs8qJkv5USSF+JAy 93UYumOYLKyOTQqaMR631fLTwEYl4cSc7nZz12KgJOm9AERVajfTm4FIeKz52xnzVK6t nMPVgmVHatLHBQPLhFCMyx8n+fYhN7qzEi79VT4l438Dr9endVagsytLP7knVoNMjA22 HsRg== X-Gm-Message-State: APjAAAXK6wAtxD00I/afAOFm1FMeXgyqWo0aYabsYD4LOfeJ49le2YA7 A8+RccsvUEjEXUjzKuD2A0FCXPeq05UV0Vpv4E5nihkBaXrPAs4thq/FPxtXNAVe5qJgQinD7Ma x0GqdMk67NAuk3IU= X-Received: by 2002:a05:620a:a45:: with SMTP id j5mr3382750qka.232.1582643634424; Tue, 25 Feb 2020 07:13:54 -0800 (PST) X-Google-Smtp-Source: APXvYqxeEFFweOo0MemvnAIUfrs+oT1K52n7zau9MirJzXNZ9P6Ywr3wX6GnUhb99tiRH1phd/CS3g== X-Received: by 2002:a05:620a:a45:: with SMTP id j5mr3382714qka.232.1582643634113; Tue, 25 Feb 2020 07:13:54 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id n23sm1414050qtr.87.2020.02.25.07.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:53 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:49 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 17/32] virtio-iommu: Implement fault reporting Message-ID: <20200225151210.647797-18-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Peter Xu , Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger The event queue allows to report asynchronous errors. The translate function now injects faults when relevant. Signed-off-by: Eric Auger Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-7-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 70 +++++++++++++++++++++++++++++++++++++--- hw/virtio/trace-events | 1 + 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 59e9cd3d9a..8509f64004 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -468,6 +468,48 @@ out: } } +static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason, + int flags, uint32_t endpoint, + uint64_t address) +{ + VirtIODevice *vdev = &viommu->parent_obj; + VirtQueue *vq = viommu->event_vq; + struct virtio_iommu_fault fault; + VirtQueueElement *elem; + size_t sz; + + memset(&fault, 0, sizeof(fault)); + fault.reason = reason; + fault.flags = cpu_to_le32(flags); + fault.endpoint = cpu_to_le32(endpoint); + fault.address = cpu_to_le64(address); + + elem = virtqueue_pop(vq, sizeof(VirtQueueElement)); + + if (!elem) { + error_report_once( + "no buffer available in event queue to report event"); + return; + } + + if (iov_size(elem->in_sg, elem->in_num) < sizeof(fault)) { + virtio_error(vdev, "error buffer of wrong size"); + virtqueue_detach_element(vq, elem, 0); + g_free(elem); + return; + } + + sz = iov_from_buf(elem->in_sg, elem->in_num, 0, + &fault, sizeof(fault)); + assert(sz == sizeof(fault)); + + trace_virtio_iommu_report_fault(reason, flags, endpoint, address); + virtqueue_push(vq, elem, sz); + virtio_notify(vdev, vq); + g_free(elem); + +} + static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, IOMMUAccessFlags flag, int iommu_idx) @@ -476,9 +518,10 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, VirtIOIOMMUInterval interval, *mapping_key; VirtIOIOMMUMapping *mapping_value; VirtIOIOMMU *s = sdev->viommu; + bool read_fault, write_fault; VirtIOIOMMUEndpoint *ep; + uint32_t sid, flags; bool bypass_allowed; - uint32_t sid; bool found; interval.low = addr; @@ -504,6 +547,9 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, if (!ep) { if (!bypass_allowed) { error_report_once("%s sid=%d is not known!!", __func__, sid); + virtio_iommu_report_fault(s, VIRTIO_IOMMU_FAULT_R_UNKNOWN, + VIRTIO_IOMMU_FAULT_F_ADDRESS, + sid, addr); } else { entry.perm = flag; } @@ -515,6 +561,9 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, error_report_once("%s %02x:%02x.%01x not attached to any domain", __func__, PCI_BUS_NUM(sid), PCI_SLOT(sid), PCI_FUNC(sid)); + virtio_iommu_report_fault(s, VIRTIO_IOMMU_FAULT_R_DOMAIN, + VIRTIO_IOMMU_FAULT_F_ADDRESS, + sid, addr); } else { entry.perm = flag; } @@ -527,15 +576,26 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, if (!found) { error_report_once("%s no mapping for 0x%"PRIx64" for sid=%d", __func__, addr, sid); + virtio_iommu_report_fault(s, VIRTIO_IOMMU_FAULT_R_MAPPING, + VIRTIO_IOMMU_FAULT_F_ADDRESS, + sid, addr); goto unlock; } - if (((flag & IOMMU_RO) && - !(mapping_value->flags & VIRTIO_IOMMU_MAP_F_READ)) || - ((flag & IOMMU_WO) && - !(mapping_value->flags & VIRTIO_IOMMU_MAP_F_WRITE))) { + read_fault = (flag & IOMMU_RO) && + !(mapping_value->flags & VIRTIO_IOMMU_MAP_F_READ); + write_fault = (flag & IOMMU_WO) && + !(mapping_value->flags & VIRTIO_IOMMU_MAP_F_WRITE); + + flags = read_fault ? VIRTIO_IOMMU_FAULT_F_READ : 0; + flags |= write_fault ? VIRTIO_IOMMU_FAULT_F_WRITE : 0; + if (flags) { error_report_once("%s permission error on 0x%"PRIx64"(%d): allowed=%d", __func__, addr, flag, mapping_value->flags); + flags |= VIRTIO_IOMMU_FAULT_F_ADDRESS; + virtio_iommu_report_fault(s, VIRTIO_IOMMU_FAULT_R_MAPPING, + flags | VIRTIO_IOMMU_FAULT_F_ADDRESS, + sid, addr); goto unlock; } entry.translated_addr = addr - mapping_key->low + mapping_value->phys_addr; diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 095aa8b509..e83500bee9 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -72,3 +72,4 @@ virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d" 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 From patchwork Tue Feb 25 15:13: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: 1244355 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=EJkuIlJR; 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 48RjNT2MQJz9sNg for ; Wed, 26 Feb 2020 02:22:33 +1100 (AEDT) Received: from localhost ([::1]:58710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c2Z-0006v7-2B for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:22:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55611) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6buR-0000mM-Gk for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buQ-0001Pi-Bj for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:07 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32491 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6buQ-0001PE-6E for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643644; 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=zqQOGMqpF8zLfZoLuq6v/gKM+lP+WgY9/qrFc0P3cXk=; b=EJkuIlJRf9zLopsR30BK+waW9c25uPiMJ/7iWzs5ZpFb7KnCThmfTOw3/kFKzs62DjgaaJ yROkenaA6OB2AjvffY2dsUpCrhrR5voTjB4/WD5etVWthaxZv9uwPZQsRcuuqZzQQCKrQO ATlwHjBXiTPqz9YdiQF2M1GHwiNbC6g= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-mJF-QnWwNpaFLo3yOum-wg-1; Tue, 25 Feb 2020 10:14:00 -0500 X-MC-Unique: mJF-QnWwNpaFLo3yOum-wg-1 Received: by mail-qv1-f72.google.com with SMTP id ce2so13168334qvb.23 for ; Tue, 25 Feb 2020 07:14:00 -0800 (PST) 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=RR/ShafzTvz59NAOcgecA6nlXnHQkJaS9Z0Tyemhwi0=; b=NrSVW1U9sjY9C549Dr8Tw6fEZFcUCOR3K6rou4Z/92qBeHv+FYaSaesx6BacfST8ep ks6JztMETAtQgWQ4kPeWMI78ao1JrKOcb4ARzBUK6R9FPLZZ696jRieuYAOTbsICcYNV XFqYP1sClFh5nF8m9a6KbzRZG1hsLpySOvMscjcdGKtwj4pBOaUw/bbCuxW8+4SAIo3G dH6F7MAWmqNTsAdMSAWeU3dd6PUXATOqdGW9WCTE4Z/93h+ijnubQHyqC2OMeUnsoUS9 rpNNm2NXTe2QmmqLuTFWprzdfrvE+gliihAAAu/IDmrOkGTnfIupEBf59/bOqXaAxgxz fjSQ== X-Gm-Message-State: APjAAAW7o7u9bxNj3CwL7h0LNjyS/0WbTrSZ+szemoKtBLGHxpEimf6S kAmLPNu/k2Y05cb1lrwmP/MKkPPWxyXteeX4dXMqrbnvKyid1g20lq8PDPxXh9s1WtjLaABERcn iKkGJN2folt8pCR8= X-Received: by 2002:ac8:7152:: with SMTP id h18mr54977072qtp.349.1582643639912; Tue, 25 Feb 2020 07:13:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxUICXfW1EfQhBNm85yUh2n5EDWEDM3kNdt8OlnNAcs6kwTbQ13Z14hWMC4XtF+xHrTC3T0MQ== X-Received: by 2002:ac8:7152:: with SMTP id h18mr54977042qtp.349.1582643639646; Tue, 25 Feb 2020 07:13:59 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id z21sm7540632qka.122.2020.02.25.07.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:13:58 -0800 (PST) Date: Tue, 25 Feb 2020 10:13:54 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 18/32] virtio-iommu: Support migration Message-ID: <20200225151210.647797-19-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Peter Xu , Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger Add Migration support. We rely on recently added gtree and qlist migration. We only migrate the domain gtree. The endpoint gtree is re-constructed in a post-load operation. Signed-off-by: Eric Auger Acked-by: Peter Xu Reviewed-by: Juan Quintela Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-8-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 109 +++++++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 8509f64004..4cee8083bc 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -643,16 +643,6 @@ static uint64_t virtio_iommu_get_features(VirtIODevice *vdev, uint64_t f, return f; } -/* - * Migration is not yet supported: most of the state consists - * of balanced binary trees which are not yet ready for getting - * migrated - */ -static const VMStateDescription vmstate_virtio_iommu_device = { - .name = "virtio-iommu-device", - .unmigratable = 1, -}; - static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data) { guint ua = GPOINTER_TO_UINT(a); @@ -736,9 +726,108 @@ static void virtio_iommu_instance_init(Object *obj) { } +#define VMSTATE_INTERVAL \ +{ \ + .name = "interval", \ + .version_id = 1, \ + .minimum_version_id = 1, \ + .fields = (VMStateField[]) { \ + VMSTATE_UINT64(low, VirtIOIOMMUInterval), \ + VMSTATE_UINT64(high, VirtIOIOMMUInterval), \ + VMSTATE_END_OF_LIST() \ + } \ +} + +#define VMSTATE_MAPPING \ +{ \ + .name = "mapping", \ + .version_id = 1, \ + .minimum_version_id = 1, \ + .fields = (VMStateField[]) { \ + VMSTATE_UINT64(phys_addr, VirtIOIOMMUMapping),\ + VMSTATE_UINT32(flags, VirtIOIOMMUMapping), \ + VMSTATE_END_OF_LIST() \ + }, \ +} + +static const VMStateDescription vmstate_interval_mapping[2] = { + VMSTATE_MAPPING, /* value */ + VMSTATE_INTERVAL /* key */ +}; + +static int domain_preload(void *opaque) +{ + VirtIOIOMMUDomain *domain = opaque; + + domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp, + NULL, g_free, g_free); + return 0; +} + +static const VMStateDescription vmstate_endpoint = { + .name = "endpoint", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(id, VirtIOIOMMUEndpoint), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_domain = { + .name = "domain", + .version_id = 1, + .minimum_version_id = 1, + .pre_load = domain_preload, + .fields = (VMStateField[]) { + VMSTATE_UINT32(id, VirtIOIOMMUDomain), + VMSTATE_GTREE_V(mappings, VirtIOIOMMUDomain, 1, + vmstate_interval_mapping, + VirtIOIOMMUInterval, VirtIOIOMMUMapping), + VMSTATE_QLIST_V(endpoint_list, VirtIOIOMMUDomain, 1, + vmstate_endpoint, VirtIOIOMMUEndpoint, next), + VMSTATE_END_OF_LIST() + } +}; + +static gboolean reconstruct_endpoints(gpointer key, gpointer value, + gpointer data) +{ + VirtIOIOMMU *s = (VirtIOIOMMU *)data; + VirtIOIOMMUDomain *d = (VirtIOIOMMUDomain *)value; + VirtIOIOMMUEndpoint *iter; + + QLIST_FOREACH(iter, &d->endpoint_list, next) { + iter->domain = d; + g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter); + } + return false; /* continue the domain traversal */ +} + +static int iommu_post_load(void *opaque, int version_id) +{ + VirtIOIOMMU *s = opaque; + + g_tree_foreach(s->domains, reconstruct_endpoints, s); + return 0; +} + +static const VMStateDescription vmstate_virtio_iommu_device = { + .name = "virtio-iommu-device", + .minimum_version_id = 1, + .version_id = 1, + .post_load = iommu_post_load, + .fields = (VMStateField[]) { + VMSTATE_GTREE_DIRECT_KEY_V(domains, VirtIOIOMMU, 1, + &vmstate_domain, VirtIOIOMMUDomain), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_virtio_iommu = { .name = "virtio-iommu", .minimum_version_id = 1, + .priority = MIG_PRI_IOMMU, .version_id = 1, .fields = (VMStateField[]) { VMSTATE_VIRTIO_DEVICE, From patchwork Tue Feb 25 15:14: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: 1244347 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=YYlpNOpe; 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 48RjJT3DHZz9sPk for ; Wed, 26 Feb 2020 02:19:04 +1100 (AEDT) Received: from localhost ([::1]:58583 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bzB-0008C3-TA for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:19:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55640) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6buW-0000oh-Nd for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buV-0001Rd-9V for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:12 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39901 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6buV-0001RF-5N for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643649; 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=tfB6vgxyzAB71+dIm3jms7txlRQYEIaRwa1XJn1djKE=; b=YYlpNOpe+iEm5ZVz7RPSsHQxKkR5ltSx9u87bDOU28DtS0MjO9DpQYd9BU2VELnDY0tSl3 i4d+bfeBRvnqgCxZ0+yirTj8un1dgnE0f90amC7px4RaTtfy+fev1HMIoY+UEsO+F0z/8l CdYezBEBDU6fxdPtyCXP1B8gvVYBnhU= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-97-FM88SSIFOaeNtvsGFWt9EA-1; Tue, 25 Feb 2020 10:14:06 -0500 X-MC-Unique: FM88SSIFOaeNtvsGFWt9EA-1 Received: by mail-qt1-f197.google.com with SMTP id x8so15203404qtq.14 for ; Tue, 25 Feb 2020 07:14:06 -0800 (PST) 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=XGike9/092nOdP42PsYQlAuujche/x1Md0Prv3YFBIc=; b=lHdEdu3cSCDMm2k/yF4O7Ptdtk1gWF7q03H0N6p3XEiio9FvGOG/jmjaA+5K+JqPmK QgSvS2Le2+QYVqALzkl8eReIaZVYHxsfdsCcbNmmdrp2XeMDafLSSI0fEXufLZtj6xvN 8G2PfNE3XbjLA0zQzsHEq9l2wCpPr1OVYNdFXqFQCe9UsUVqV0fGP9K3Q9/S4HhV9Ntd K5SsugTo7lam+KbLYyU63WFnC3Y9Y6PR8WUKIcj82uW0ZPfMo6U7qoqaq3ONuKFQrvT/ 0uniVJwN2YnDO+KCWmW7FugU4lSsB1VclUtGrF4sXOpAJHZvAw/qC3Xiph4UGFhgSA4s QZHA== X-Gm-Message-State: APjAAAVFC0EFyTQhNRxJIt1NlagxyuwkVl4pNiUJj3ibiV1PD0ppQ6et Wcvw3xPHkNdBTXwNyHk5M75nn4YB6fbq2lUymuYTSFODQcRO7wwtaG62y+wNNK7krGfynViBuDy znTEPD0h4x7jtazg= X-Received: by 2002:ad4:4e09:: with SMTP id dl9mr50610915qvb.137.1582643645292; Tue, 25 Feb 2020 07:14:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyQFcU9yHqTSX//5UtoPAjNEXVVTBlywml229kJ3cSw06/8yVtuUq3TlpRZMIv1uI8Jeozi2g== X-Received: by 2002:ad4:4e09:: with SMTP id dl9mr50610877qvb.137.1582643644938; Tue, 25 Feb 2020 07:14:04 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id y197sm7412603qka.65.2020.02.25.07.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:04 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:00 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 19/32] virtio-iommu-pci: Add virtio iommu pci support Message-ID: <20200225151210.647797-20-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Daniel =?utf-8?q?P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Jean-Philippe Brucker , Eric Auger , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger This patch adds virtio-iommu-pci, which is the pci proxy for the virtio-iommu device. Currently non DT integration is not yet supported by the kernel. So the machine must implement a hotplug handler for the virtio-iommu-pci device that creates the device tree iommu-map bindings as documented in kernel documentation: Documentation/devicetree/bindings/virtio/iommu.txt Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker Reviewed-by: Michael S. Tsirkin Message-Id: <20200214132745.23392-9-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/pci/pci.h | 1 + include/hw/virtio/virtio-iommu.h | 1 + hw/virtio/virtio-iommu-pci.c | 104 +++++++++++++++++++++++++++++++ qdev-monitor.c | 1 + hw/virtio/Makefile.objs | 1 + 5 files changed, 108 insertions(+) create mode 100644 hw/virtio/virtio-iommu-pci.c diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 2acd8321af..cfedf5a995 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -86,6 +86,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_VIRTIO_9P 0x1009 #define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012 #define PCI_DEVICE_ID_VIRTIO_PMEM 0x1013 +#define PCI_DEVICE_ID_VIRTIO_IOMMU 0x1014 #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h index ae88f730cf..6f67f1020a 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -25,6 +25,7 @@ #include "hw/pci/pci.h" #define TYPE_VIRTIO_IOMMU "virtio-iommu-device" +#define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-device-base" #define VIRTIO_IOMMU(obj) \ OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU) diff --git a/hw/virtio/virtio-iommu-pci.c b/hw/virtio/virtio-iommu-pci.c new file mode 100644 index 0000000000..3dfbf55b47 --- /dev/null +++ b/hw/virtio/virtio-iommu-pci.c @@ -0,0 +1,104 @@ +/* + * Virtio IOMMU PCI Bindings + * + * Copyright (c) 2019 Red Hat, Inc. + * Written by Eric Auger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +#include "qemu/osdep.h" + +#include "virtio-pci.h" +#include "hw/virtio/virtio-iommu.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "hw/boards.h" + +typedef struct VirtIOIOMMUPCI VirtIOIOMMUPCI; + +/* + * virtio-iommu-pci: This extends VirtioPCIProxy. + * + */ +#define VIRTIO_IOMMU_PCI(obj) \ + OBJECT_CHECK(VirtIOIOMMUPCI, (obj), TYPE_VIRTIO_IOMMU_PCI) + +struct VirtIOIOMMUPCI { + VirtIOPCIProxy parent_obj; + VirtIOIOMMU vdev; +}; + +static Property virtio_iommu_pci_properties[] = { + DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + + if (!qdev_get_machine_hotplug_handler(DEVICE(vpci_dev))) { + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + + error_setg(errp, + "%s machine fails to create iommu-map device tree bindings", + mc->name); + error_append_hint(errp, + "Check you machine implements a hotplug handler " + "for the virtio-iommu-pci device\n"); + error_append_hint(errp, "Check the guest is booted without FW or with " + "-no-acpi\n"); + return; + } + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_link(OBJECT(dev), + OBJECT(pci_get_bus(&vpci_dev->pci_dev)), + "primary-bus", errp); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void virtio_iommu_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); + k->realize = virtio_iommu_pci_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, virtio_iommu_pci_properties); + pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_IOMMU; + pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id = PCI_CLASS_OTHERS; + dc->hotpluggable = false; +} + +static void virtio_iommu_pci_instance_init(Object *obj) +{ + VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_IOMMU); +} + +static const VirtioPCIDeviceTypeInfo virtio_iommu_pci_info = { + .base_name = TYPE_VIRTIO_IOMMU_PCI, + .generic_name = "virtio-iommu-pci", + .transitional_name = "virtio-iommu-pci-transitional", + .non_transitional_name = "virtio-iommu-pci-non-transitional", + .instance_size = sizeof(VirtIOIOMMUPCI), + .instance_init = virtio_iommu_pci_instance_init, + .class_init = virtio_iommu_pci_class_init, +}; + +static void virtio_iommu_pci_register(void) +{ + virtio_pci_types_register(&virtio_iommu_pci_info); +} + +type_init(virtio_iommu_pci_register) + + diff --git a/qdev-monitor.c b/qdev-monitor.c index 8ce71a206b..dbbe92dfa1 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -67,6 +67,7 @@ static const QDevAlias qdev_alias_table[] = { { "virtio-input-host-ccw", "virtio-input-host", QEMU_ARCH_S390X }, { "virtio-input-host-pci", "virtio-input-host", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X }, + { "virtio-iommu-pci", "virtio-iommu", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X }, { "virtio-keyboard-ccw", "virtio-keyboard", QEMU_ARCH_S390X }, { "virtio-keyboard-pci", "virtio-keyboard", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X }, diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 2fd9da7410..4e4d39a0a4 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -29,6 +29,7 @@ obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon-pci.o +obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu-pci.o obj-$(CONFIG_VIRTIO_9P) += virtio-9p-pci.o obj-$(CONFIG_VIRTIO_SCSI) += virtio-scsi-pci.o obj-$(CONFIG_VIRTIO_BLK) += virtio-blk-pci.o From patchwork Tue Feb 25 15:14:05 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: 1244351 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=PL5rCmf6; 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 48RjLn1w9Fz9sNg for ; Wed, 26 Feb 2020 02:21:05 +1100 (AEDT) Received: from localhost ([::1]:58608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c18-0003Du-Iz for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:21:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55682) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bub-0000vY-Q6 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bua-0001Ty-6a for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:17 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:41486 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bua-0001TH-2m for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643654; 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=mH6Uh7KB+qDOlqySuiYCwzhwjo90oVgrXa4q2w401+k=; b=PL5rCmf6X6W48oX6r72hYCx/6zX42tbuPQXSGbRQciQsYMsbJHYqcdkkYymSTByzqst12E 0SDckxRU+M1rRYc4rFa0vfXUhoQqfrj64T0kHrezf5I5eaPqqK0BkTrrw/Dwpy3m5r7aUM Cu2NTjjk8bNmrgRPogmDG5sCXJ3nZsM= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-ewVEFSeKP0qgnAewsi8Vag-1; Tue, 25 Feb 2020 10:14:10 -0500 X-MC-Unique: ewVEFSeKP0qgnAewsi8Vag-1 Received: by mail-qv1-f69.google.com with SMTP id l1so13231501qvu.13 for ; Tue, 25 Feb 2020 07:14:10 -0800 (PST) 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=L8WBI983W+7RiE8lzDwmxcDHbYbc+B58tFNCqwSyA9I=; b=kuy3jiN+Ggx/h/AM4fE6V+FQZrpCIlS2oTp2yDCAMlH8EkCnatNAfPdCrPM0OqoDEw /X5zOQMu4HRPSuXiTcjh8vLLKJ/lw1uGaHoMU7MzKsMx729ejUWE0wIRsWCLME6pCGi2 u8LYsyg6BUlgOrLy6nw1v8+iyaE8TRc0FEVnGxMxXIstiY3ODRVGKcV+8iQzM/0JHcwT DN2qq7PbK7UahrXeJq3XRES9heufTRDZzMbOxWoFSMqh1TVJV9SrjH2PSUwW9j1yRZu9 IMAS0wL9fM3coFyqOly2rAWnhdCqlfit7aa5DlKAtGFvAvQ+9vrOQhuGxzPqzBIhNHWx JJ8w== X-Gm-Message-State: APjAAAU1Gqp8GMTdLj+wBylah722P/bmMPWakixkgRKJRCJsVKm3KP2F tbIZRLNHgV1uKdisltb5gtdNlLmgxIpp3T8vpp95LhARr6xd3RHmbnVgA/Hj7IgSwncUkI1djAB I2dJ0yGCupx2xbFk= X-Received: by 2002:a05:620a:31b:: with SMTP id s27mr57671603qkm.105.1582643649530; Tue, 25 Feb 2020 07:14:09 -0800 (PST) X-Google-Smtp-Source: APXvYqyq5g0qqU0QIGP+YNqaqREIX7kOrG4ar1aZMSyZTr1Ao89ktkh4eaPwLdriWS993Si5s5T2FA== X-Received: by 2002:a05:620a:31b:: with SMTP id s27mr57671570qkm.105.1582643649255; Tue, 25 Feb 2020 07:14:09 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id l19sm7379730qkl.3.2020.02.25.07.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:08 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:05 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 20/32] hw/arm/virt: Add the virtio-iommu device tree mappings Message-ID: <20200225151210.647797-21-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , qemu-arm@nongnu.org, Eric Auger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger Adds the "virtio,pci-iommu" node in the host bridge node and the RID mapping, excluding the IOMMU RID. This is done in the virtio-iommu-pci hotplug handler which gets called only if no firmware is loaded or if -no-acpi is passed on the command line. As non DT integration is not yet supported by the kernel we must make sure we are in DT mode. This limitation will be removed as soon as the topology description feature gets supported. Signed-off-by: Eric Auger Message-Id: <20200214132745.23392-10-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Peter Maydell --- include/hw/arm/virt.h | 2 ++ hw/arm/virt.c | 57 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 71508bf40c..02f500cb8e 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -125,8 +125,10 @@ typedef struct { bool virt; int32_t gic_version; VirtIOMMUType iommu; + uint16_t virtio_iommu_bdf; struct arm_boot_info bootinfo; MemMapEntry *memmap; + char *pciehb_nodename; const int *irqmap; int smp_cpus; void *fdt; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index f788fe27d6..cfe317922f 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -32,6 +32,7 @@ #include "qemu-common.h" #include "qemu/units.h" #include "qemu/option.h" +#include "monitor/qdev.h" #include "qapi/error.h" #include "hw/sysbus.h" #include "hw/boards.h" @@ -54,6 +55,7 @@ #include "qemu/error-report.h" #include "qemu/module.h" #include "hw/pci-host/gpex.h" +#include "hw/virtio/virtio-pci.h" #include "hw/arm/sysbus-fdt.h" #include "hw/platform-bus.h" #include "hw/qdev-properties.h" @@ -71,6 +73,7 @@ #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" #include "hw/acpi/generic_event_device.h" +#include "hw/virtio/virtio-iommu.h" #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -1180,6 +1183,30 @@ static void create_smmu(const VirtMachineState *vms, g_free(node); } +static void create_virtio_iommu_dt_bindings(VirtMachineState *vms, Error **errp) +{ + const char compat[] = "virtio,pci-iommu"; + uint16_t bdf = vms->virtio_iommu_bdf; + char *node; + + vms->iommu_phandle = qemu_fdt_alloc_phandle(vms->fdt); + + node = g_strdup_printf("%s/virtio_iommu@%d", vms->pciehb_nodename, bdf); + qemu_fdt_add_subnode(vms->fdt, node); + qemu_fdt_setprop(vms->fdt, node, "compatible", compat, sizeof(compat)); + qemu_fdt_setprop_sized_cells(vms->fdt, node, "reg", + 1, bdf << 8, 1, 0, 1, 0, + 1, 0, 1, 0); + + qemu_fdt_setprop_cell(vms->fdt, node, "#iommu-cells", 1); + qemu_fdt_setprop_cell(vms->fdt, node, "phandle", vms->iommu_phandle); + g_free(node); + + qemu_fdt_setprop_cells(vms->fdt, vms->pciehb_nodename, "iommu-map", + 0x0, vms->iommu_phandle, 0x0, bdf, + bdf + 1, vms->iommu_phandle, bdf + 1, 0xffff - bdf); +} + static void create_pcie(VirtMachineState *vms) { hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO].base; @@ -1258,7 +1285,7 @@ static void create_pcie(VirtMachineState *vms) } } - nodename = g_strdup_printf("/pcie@%" PRIx64, base); + nodename = vms->pciehb_nodename = g_strdup_printf("/pcie@%" PRIx64, base); qemu_fdt_add_subnode(vms->fdt, nodename); qemu_fdt_setprop_string(vms->fdt, nodename, "compatible", "pci-host-ecam-generic"); @@ -1301,13 +1328,16 @@ static void create_pcie(VirtMachineState *vms) if (vms->iommu) { vms->iommu_phandle = qemu_fdt_alloc_phandle(vms->fdt); - create_smmu(vms, pci->bus); - - qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map", - 0x0, vms->iommu_phandle, 0x0, 0x10000); + switch (vms->iommu) { + case VIRT_IOMMU_SMMUV3: + create_smmu(vms, pci->bus); + qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map", + 0x0, vms->iommu_phandle, 0x0, 0x10000); + break; + default: + g_assert_not_reached(); + } } - - g_free(nodename); } static void create_platform_bus(VirtMachineState *vms) @@ -1976,6 +2006,13 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { virt_memory_plug(hotplug_dev, dev, errp); } + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + PCIDevice *pdev = PCI_DEVICE(dev); + + vms->iommu = VIRT_IOMMU_VIRTIO; + vms->virtio_iommu_bdf = pci_get_bdf(pdev); + create_virtio_iommu_dt_bindings(vms, errp); + } } static void virt_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, @@ -1992,7 +2029,13 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine, (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM))) { return HOTPLUG_HANDLER(machine); } + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + VirtMachineState *vms = VIRT_MACHINE(machine); + if (!vms->bootinfo.firmware_loaded || !acpi_enabled) { + return HOTPLUG_HANDLER(machine); + } + } return NULL; } From patchwork Tue Feb 25 15:14: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: 1244358 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=bUg924mr; 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 48RjQm27Cwz9sPk for ; Wed, 26 Feb 2020 02:24:32 +1100 (AEDT) Received: from localhost ([::1]:58750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c4U-0001fc-6Q for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:24:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55707) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bud-000118-OF for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buc-0001VR-NN for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:19 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47811 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6buc-0001V4-IV for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643658; 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=qy9/687s6ZY1i4Ce3m2ls24YlJZNFW8NDWw91xMGiXM=; b=bUg924mriWRfDpDIArhGvnrrdpdasfeh92Xl3sctP5ntrWJY+wtlHQQjs+t3xAZsy94Vgr v2JoU+6L41DGhoWX+DsHYvpcT+zpuvhSLc5gn0k4KnIBU8IPQ44cjF5aDo8CppgHdg4843 vntpNmjlklOMfOGQ4kYd4sv38GbiSfY= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-z0uNVI0yOU6og1WqMMozIA-1; Tue, 25 Feb 2020 10:14:15 -0500 X-MC-Unique: z0uNVI0yOU6og1WqMMozIA-1 Received: by mail-qt1-f197.google.com with SMTP id r30so15155140qtb.10 for ; Tue, 25 Feb 2020 07:14:15 -0800 (PST) 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=66uA6nm0t2SlG2qj7xxlmLCKVkLyYwtKAF+OGhXadUo=; b=ga3v+KiubbLo/8AxRakDLVMxwongBJN6Xw8FqPVO6e9d+OPTuCl67hKaPzG4YEAPxe ZKqa2dcLvCWj6B+QzXV1FyOduexWhvQD2vokaUP236lgMV9+nBMgKIvo+S0okVQV4zj6 fTJyDuDDZvNOFjtgsUHjY0bDxsglHVmwf2FjnOIMzfdzYat5qvBmWapbucRhZye6Rl4Q CCLENPPu+MSfvJYU62LZ8Z4xE6eRTVl6azYZ22OQ+M9mLbAJgi8r4htLEbQZBJ4b1XMt gDfCjP2tyEXonlV4tmJ0//ne1uk8jF//3iD7aaIuEk5DR8yWtUoYnvZ5id3ZTR7FySUk CFKg== X-Gm-Message-State: APjAAAWK/h4J06UHdIKTq5n+Ed7XbOWl/CAvz+Wr0DFnrpjStE8GAhQt prVV4mDSDMGIFuGIFzlaLU0KTgO1KIl8YZ6i7uzsa32SNILil89n4Bv7MBECubgnUJFem8BHMCR uvru32Snf5OtJFoA= X-Received: by 2002:a37:4e53:: with SMTP id c80mr32516856qkb.58.1582643654872; Tue, 25 Feb 2020 07:14:14 -0800 (PST) X-Google-Smtp-Source: APXvYqxsvjMDSkILq0d6UvyzqEaN+plnS158t3MC6k4FkTYWDxGkTSxi2lHdn7LQMJs6l9mObvoO7g== X-Received: by 2002:a37:4e53:: with SMTP id c80mr32516822qkb.58.1582643654626; Tue, 25 Feb 2020 07:14:14 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id j17sm1710279qth.27.2020.02.25.07.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:13 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:09 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 21/32] MAINTAINERS: add virtio-iommu related files Message-ID: <20200225151210.647797-22-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Daniel =?utf-8?b?UC4gQmVycmFuZ8Op?= , Markus Armbruster , Eric Auger , Philippe =?utf-8?q?Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger Add a new "virtio-iommu" section with the new files related to this device. Signed-off-by: Eric Auger Message-Id: <20200214132745.23392-11-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Peter Maydell --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 195dd58cac..ff06934bb5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1631,6 +1631,12 @@ F: hw/input/virtio-input*.c F: include/hw/virtio/virtio-input.h F: contrib/vhost-user-input/* +virtio-iommu +M: Eric Auger +S: Maintained +F: hw/virtio/virtio-iommu*.c +F: include/hw/virtio/virtio-iommu.h + virtio-serial M: Laurent Vivier R: Amit Shah From patchwork Tue Feb 25 15:14: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: 1244365 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=JnW4u14v; 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 48RjVR71vPz9sNg for ; Wed, 26 Feb 2020 02:27:43 +1100 (AEDT) Received: from localhost ([::1]:58826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c7Z-0007xm-TZ for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:27:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56620) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bxM-0006Pj-5w for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:17:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bxL-00036E-4J for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:17:08 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:57456 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bxL-00035w-07 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:17:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643826; 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=GurCHGrxIX/gaMnymLT6OLHjIK8r0mHiQmdNJWYE8J8=; b=JnW4u14v3nD3hoR16Au0GZdGqFjaFSTa7+xqpX2jf7xLiMRzXkU6kq4V+OiVdlY6zlvQ1c EmnWKPxREZFipsT0mHSYIiXVlpQsPJlmO7GevZzMs7fcgbbe6JdnjnKvbIcWinuFEsDHvJ tUa2UVHMx0YiAzzWHDSojSkQLkym8xc= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-345-7lYUqz9oMVKmv98qf_w5_w-1; Tue, 25 Feb 2020 10:14:21 -0500 X-MC-Unique: 7lYUqz9oMVKmv98qf_w5_w-1 Received: by mail-qk1-f199.google.com with SMTP id n131so10467473qkn.17 for ; Tue, 25 Feb 2020 07:14:21 -0800 (PST) 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=HJYgPtUXb7oGIKTPBdg5GcKwNd69Hnwn26g3WEAmRrg=; b=G81fhUi8n8kLnSikIdzznBenzVUNjIGF3yPkLKqkGCB8GHsMQFZ0a/VNLf++oHT/fs cpLv3Ax5yWuAAQNq9YIlchiWejCh9UYEh08M59YoERk/ozib/zttVtIFOwEmeDn/TiHy HHYzkMpHmgtluYgV9F2yzQ9S5fyGnRFSkMKF/qEpJLxk9K77YEL+9TTbeIjghT8lK4ht G0OsM1IzJ4kDUl4Aqo581Savq+4Y2suqW7UOBAyzpSVkhyD8O6ooVluTIiE3v6cqMon6 z/HESD3B7RU6fkJwwFyHOE5dYdRVuM0PzYZzjB70wRg2fBmrHCxPY7So85lRDs4fRulJ iu/A== X-Gm-Message-State: APjAAAUO3QqGN2pj+LEjvUdwU1AqfnitOl8mWaGop+ZCuHRrQWIHo+vi kXB7f5lqgVIw6e2RAbs2OTowECLHyqy0FajLl2iELtlcng0VK10OglKFZxmy2Ct7nMvzl53BU9P nV/w7LZ/VVRxrYGs= X-Received: by 2002:ac8:664f:: with SMTP id j15mr40884080qtp.267.1582643660247; Tue, 25 Feb 2020 07:14:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwXS0HfsJy+Z94rJQN26WrMqRqEhcu0WZmJAz2Ipz+SNPVM9L/6d1VAmUxLYj6E6p29fBxKDg== X-Received: by 2002:ac8:664f:: with SMTP id j15mr40884052qtp.267.1582643660035; Tue, 25 Feb 2020 07:14:20 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id u49sm7744145qtb.37.2020.02.25.07.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:19 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:15 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 22/32] libvhost-user: implement VHOST_USER_PROTOCOL_F_REPLY_ACK Message-ID: <20200225151210.647797-23-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Johannes Berg , Gerd Hoffmann , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9?= Lureau , Xie Yongji Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Johannes Berg This is really simple, since we know whether a response is already requested or not, so we can just send a (successful) response when there isn't one already. Given that, it's not all _that_ useful but the master can at least be sure the message was processed, and we can exercise more code paths using the example code. Reviewed-by: Stefan Hajnoczi Signed-off-by: Johannes Berg Message-Id: <20200123081708.7817-2-johannes@sipsolutions.net> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/libvhost-user/libvhost-user.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index b89bf18501..533d55d82a 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -1199,7 +1199,8 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD | 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | - 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD; + 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD | + 1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK; if (have_userfault()) { features |= 1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT; @@ -1581,13 +1582,20 @@ vu_dispatch(VuDev *dev) { VhostUserMsg vmsg = { 0, }; int reply_requested; - bool success = false; + bool need_reply, success = false; if (!vu_message_read(dev, dev->sock, &vmsg)) { goto end; } + need_reply = vmsg.flags & VHOST_USER_NEED_REPLY_MASK; + reply_requested = vu_process_message(dev, &vmsg); + if (!reply_requested && need_reply) { + vmsg_set_reply_u64(&vmsg, 0); + reply_requested = 1; + } + if (!reply_requested) { success = true; goto end; From patchwork Tue Feb 25 15:14:20 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: 1244361 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=XnmmijoD; 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 48RjST5BDFz9sNg for ; Wed, 26 Feb 2020 02:26:01 +1100 (AEDT) Received: from localhost ([::1]:58778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c5v-0004lZ-NA for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:25:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55826) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bur-0001eF-DU for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buq-0001bz-3j for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:33 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:28600 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bup-0001bj-VI for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643671; 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=d/aiv3lhOmdIPftAE4AmweEgXAxc/uZrTam4P30LF8M=; b=XnmmijoDTQQ31CRfeHBQILXdNarLWPP3XN49Jfd8ySSLRmKWbtMZE4f5R1tNDjNPlX7yPM vqGD2iV/kPc2rcmX/KsyFOb6srOi1ZR7ZlktAOv/RKucRbfRxoAZLQmjNOk6E4EnZWPvJd IaNtCqqpRVPQE2GMT7j9ZbKf69iasAY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-sO4nz5sKMJ-VOKqxfk8dIQ-1; Tue, 25 Feb 2020 10:14:26 -0500 X-MC-Unique: sO4nz5sKMJ-VOKqxfk8dIQ-1 Received: by mail-qv1-f69.google.com with SMTP id g9so13200646qvy.20 for ; Tue, 25 Feb 2020 07:14:26 -0800 (PST) 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=VULHvANuJTAMzSo4WuZrwNg3YHlhkBLMkkXorsz6PrY=; b=PcdUsLyEQI0nUnSPqYM++YGqD1xNdRMtrQEkvEY7elU3MedOanKgw1tplaR2m3H1FJ +cB5UjXRXWfPeglh9iX+2K4YVYyulR+sONMK2nYIwaYX1p80IzOI8hzc63gBwCYW8byN Oo8ueGF8F6kaxFpq5JmTktVdBEW533N/Qsw7S+TlvFigKjWh6lx9+vpb7hlp20RMaVgm U9S+TAxlxEUqYJntJi9b6UMFANFXYkUOQjTZId9ooDRtVCC5ZwYriTPOX94xzOK2lf1I SCO/DAMAKidlFp6yMXQ4bgKA1IbVN5e7Cmca72ykqunzJsxGI1ozf/NM6Dlurdza+mwr UxqA== X-Gm-Message-State: APjAAAUKshlpbxetbn6Ypp3usgQbHLljj9hueWwDey/2QNF7TkasPHtS qkTFozmkjw3A0yPX3BYaAJmmHpG7gopYulLDgVwxaYi5++aIuuFJmuv37PMHisHVCFZm7RSG/E4 wcoR+u518Ew0eprI= X-Received: by 2002:a37:2710:: with SMTP id n16mr56970424qkn.235.1582643665270; Tue, 25 Feb 2020 07:14:25 -0800 (PST) X-Google-Smtp-Source: APXvYqyuzc/QbhQ1zmoOQmNmQ3c1NI7Lr53lr6I4hgaWc9wzJR8jSgiYD4a2OsjXG6ZzMByrogSKTA== X-Received: by 2002:a37:2710:: with SMTP id n16mr56970395qkn.235.1582643665023; Tue, 25 Feb 2020 07:14:25 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id q125sm2319071qke.116.2020.02.25.07.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:24 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:20 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 23/32] libvhost-user-glib: fix VugDev main fd cleanup Message-ID: <20200225151210.647797-24-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Gerd Hoffmann , Johannes Berg , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Johannes Berg If you try to make a device implementation that can handle multiple connections and allow disconnections (which requires overriding the VHOST_USER_NONE handling), then glib will warn that we remove a src while it's still on the mainloop, and will poll() an FD that doesn't exist anymore. Fix this by making vug_source_new() require pairing with the new vug_source_destroy() so we can keep the GSource referenced in the meantime. Note that this requires calling the new API in vhost-user-input. vhost-user-gpu also uses vug_source_new(), but never seems to free the result at all, so I haven't changed anything there. Fixes: 8bb7ddb78a1c ("libvhost-user: add glib source helper") Reviewed-by: Marc-André Lureau Signed-off-by: Johannes Berg Message-Id: <20200123081708.7817-3-johannes@sipsolutions.net> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/libvhost-user/libvhost-user-glib.h | 1 + contrib/libvhost-user/libvhost-user-glib.c | 15 ++++++++++++--- contrib/vhost-user-input/main.c | 6 ++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user-glib.h b/contrib/libvhost-user/libvhost-user-glib.h index 64d539d93a..1a79a4916e 100644 --- a/contrib/libvhost-user/libvhost-user-glib.h +++ b/contrib/libvhost-user/libvhost-user-glib.h @@ -31,5 +31,6 @@ void vug_deinit(VugDev *dev); GSource *vug_source_new(VugDev *dev, int fd, GIOCondition cond, vu_watch_cb vu_cb, gpointer data); +void vug_source_destroy(GSource *src); #endif /* LIBVHOST_USER_GLIB_H */ diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c index 99edd2f3de..824c7780de 100644 --- a/contrib/libvhost-user/libvhost-user-glib.c +++ b/contrib/libvhost-user/libvhost-user-glib.c @@ -91,7 +91,6 @@ vug_source_new(VugDev *gdev, int fd, GIOCondition cond, g_source_add_poll(gsrc, &src->gfd); id = g_source_attach(gsrc, NULL); g_assert(id); - g_source_unref(gsrc); return gsrc; } @@ -131,6 +130,16 @@ static void vug_watch(VuDev *dev, int condition, void *data) } } +void vug_source_destroy(GSource *src) +{ + if (!src) { + return; + } + + g_source_destroy(src); + g_source_unref(src); +} + bool vug_init(VugDev *dev, uint16_t max_queues, int socket, vu_panic_cb panic, const VuDevIface *iface) @@ -144,7 +153,7 @@ vug_init(VugDev *dev, uint16_t max_queues, int socket, } dev->fdmap = g_hash_table_new_full(NULL, NULL, NULL, - (GDestroyNotify) g_source_destroy); + (GDestroyNotify) vug_source_destroy); dev->src = vug_source_new(dev, socket, G_IO_IN, vug_watch, NULL); @@ -157,5 +166,5 @@ vug_deinit(VugDev *dev) g_assert(dev); g_hash_table_unref(dev->fdmap); - g_source_unref(dev->src); + vug_source_destroy(dev->src); } diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c index ef4b7769f2..6020c6f33a 100644 --- a/contrib/vhost-user-input/main.c +++ b/contrib/vhost-user-input/main.c @@ -187,7 +187,7 @@ vi_queue_set_started(VuDev *dev, int qidx, bool started) } if (!started && vi->evsrc) { - g_source_destroy(vi->evsrc); + vug_source_destroy(vi->evsrc); vi->evsrc = NULL; } } @@ -401,9 +401,7 @@ main(int argc, char *argv[]) vug_deinit(&vi.dev); - if (vi.evsrc) { - g_source_unref(vi.evsrc); - } + vug_source_destroy(vi.evsrc); g_array_free(vi.config, TRUE); g_free(vi.queue); return 0; From patchwork Tue Feb 25 15:14:25 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: 1244346 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=L0R7wRgj; 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 48RjH11CdQz9sNg for ; Wed, 26 Feb 2020 02:17:49 +1100 (AEDT) Received: from localhost ([::1]:58562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bxy-0006L6-LA for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:17:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55913) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6buy-0001rj-Gy for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buv-0001f4-D4 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:40 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31175 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6buv-0001ei-8f for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643676; 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=/oKgHpzvvYWsVdDfIdCVEbYUj7F09lISrJlwoM5pP5g=; b=L0R7wRgjShi1lPhbDbAswQlFNRQ3gYAcIBKdsAre9V3Bvrjcn+thlcf6ceLFeKw4ujlo7u zZP/rKCPLw/k/7pttQFJn8Qv85CFxpgvcOv53bO/v9qazPG9X/7AtlEOwRAEPQMBFM0ISk LNiu9y7Gm0W8UsyEJgeUBCPP6v/K+3M= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-0KQlMvgEOy6gFc45Je7Ffw-1; Tue, 25 Feb 2020 10:14:31 -0500 X-MC-Unique: 0KQlMvgEOy6gFc45Je7Ffw-1 Received: by mail-qk1-f199.google.com with SMTP id d2so1489145qko.3 for ; Tue, 25 Feb 2020 07:14:31 -0800 (PST) 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=RCsZu5eqrBUiXUZoz9bzfU4qWCKnd0BfjuIJHzusOXA=; b=qS/Adh6WGiCA0VNiYdEqQRK74N5fQ0+DgCpH7zSokzH2FQUQ0El5iqx9VjlxfImWnB MEXp+xl/j/FzHVoZay4mKov+bDPrrc79yEWGnvT6O26Gb9FAVVtIw6zjNDrMLJAGQl59 Nxw1Uql4R0OQGIxQVOxxWZsurGuJfoiGrZJj2qOhky0Vvi8NxJcz+hc4uA7Sv5YL85In 89ajf8YbriKmkzc2KRvopspT+QFBdWWbGL+4i7WvEO6ZklRMD9hybGHZX6E6XZ6UMWlf w+BcEM7asK4zQsxfvxQ+xa8x/3mzoG3+/ggV6yr0wnZEVj9z6WPOY7Z8jBMwhWJkLeNs tyVw== X-Gm-Message-State: APjAAAUGo/O9QlQ+JsmWQn4p18UaDm9hZGO/BxgvXpYMypCWDdzuehzA mLmLTyhZ2fh4dKlBookgxiB1wGVRmmPealGtK1EO4QYUAsiqkC0qrqh+aR7YCuiGXBRA2xfW78Y wzqTCHhPEVJfDUV8= X-Received: by 2002:ac8:f37:: with SMTP id e52mr3529468qtk.49.1582643670482; Tue, 25 Feb 2020 07:14:30 -0800 (PST) X-Google-Smtp-Source: APXvYqy6xNEIOQlp5/EPHVlPP/kQa4td64+IBH267Xv0OhSFhvLzNCasv5uo7xhtodZTr3VQoo5Gjg== X-Received: by 2002:ac8:f37:: with SMTP id e52mr3529442qtk.49.1582643670273; Tue, 25 Feb 2020 07:14:30 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id 11sm3942764qkr.101.2020.02.25.07.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:29 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:25 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 24/32] libvhost-user-glib: use g_main_context_get_thread_default() Message-ID: <20200225151210.647797-25-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , Stefan Hajnoczi , Johannes Berg , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Johannes Berg If we use NULL, we just get the main program default mainloop here. Using g_main_context_get_thread_default() has basically the same effect, but it lets us start different devices in different threads with different mainloops, which can be useful. Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-André Lureau Signed-off-by: Johannes Berg Message-Id: <20200123081708.7817-4-johannes@sipsolutions.net> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/libvhost-user/libvhost-user-glib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c index 824c7780de..53f1ca4cdd 100644 --- a/contrib/libvhost-user/libvhost-user-glib.c +++ b/contrib/libvhost-user/libvhost-user-glib.c @@ -89,7 +89,7 @@ vug_source_new(VugDev *gdev, int fd, GIOCondition cond, src->gfd.events = cond; g_source_add_poll(gsrc, &src->gfd); - id = g_source_attach(gsrc, NULL); + id = g_source_attach(gsrc, g_main_context_get_thread_default()); g_assert(id); return gsrc; From patchwork Tue Feb 25 15:14:30 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: 1244354 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=O2jJfMr9; 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 48RjNQ4gL1z9sPk for ; Wed, 26 Feb 2020 02:22:30 +1100 (AEDT) Received: from localhost ([::1]:58704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c2W-0006mv-HT for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:22:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55936) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6buz-0001ux-Kn for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6buy-0001hV-D9 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:41 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:29634 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6buy-0001fh-83 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643678; 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=PaVZ83rgHHJzvD04uhNEPYZywTa4yNbe9G1r2BQHUDs=; b=O2jJfMr9NpoOQ+dCOsKPvAPu/5wYTU2+THzKlWBr6dxxbYR0l2zdCZW2ET7eoQWnZPO1yk 8oE9FXVYQE3hf6jwe2GXhp8sklJnV6QSUJoSXIdq1Pn4iMIC+A+lLHmW//9hZ6utIvwZGE SNT0Z4PdZTLh9dPL1Qq1DQ8qOnnA+Pw= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-170-RsKhekESMMulHudztwt3GQ-1; Tue, 25 Feb 2020 10:14:36 -0500 X-MC-Unique: RsKhekESMMulHudztwt3GQ-1 Received: by mail-qt1-f200.google.com with SMTP id d9so15201930qtq.13 for ; Tue, 25 Feb 2020 07:14:36 -0800 (PST) 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=BEIFZp6ZV6EMxNZvhYr+RG8aqKLzp8+FfOWRj9nMRTw=; b=X5fo05QRanVIPwD9y+FbRjy27dccPkBkFMkkR6ByODXWRarw3i0Bc5yK4Pd6IiW152 xgZrhS0cNomNrnnBK0nBmlks0zGJ0cHhomz2hDaoARjG0EehMv4BbCyAnCG5dpvRVIy+ xLuE+9yVGyIQwLm8LxjmcVrr38JvL5zcUS/FAlpREMHUuKS7mwr32hteILCrsCJxcPrA b4rud904XXK0HFX7HKYBDqvLDg8gmQE+tpxbRBSzeC8dLUGuaqPZL767r3yyxasDQXBg U0rk699TMpuBCuFPJPd3DlYHS8W8Q4lNEcAwwToBlSwh0/DG6eJdsYElp9aL+MA8g2R8 46JA== X-Gm-Message-State: APjAAAWxJVqbJXhIuXV40R2x4NmKlyZ6Lq94DksTjF6OwKnvaK3a9cL8 zBqGBOzSxqDD3FEhrqdc5F2jA2hatXUfp/E2HVeDDB4n4Pw//IhF1LgHCZirWCLlaONKA794+Nw mlh3Do5YR0qkYpn0= X-Received: by 2002:aed:37a4:: with SMTP id j33mr3919252qtb.363.1582643675578; Tue, 25 Feb 2020 07:14:35 -0800 (PST) X-Google-Smtp-Source: APXvYqzTJ0QI3azMUZ1bYT7H35iT1Lt8umIsgba9SBNyIzNGt9m7DpqRQuBfbixJfZZ9V5ppy4Olcg== X-Received: by 2002:aed:37a4:: with SMTP id j33mr3919222qtb.363.1582643675326; Tue, 25 Feb 2020 07:14:35 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id d1sm7436695qkj.29.2020.02.25.07.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:34 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:30 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 25/32] libvhost-user: handle NOFD flag in call/kick/err better Message-ID: <20200225151210.647797-26-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Stefan Hajnoczi , Gerd Hoffmann , Johannes Berg , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Johannes Berg The code here is odd, for example will it print out invalid file descriptor numbers that were never sent in the message. Clean that up a bit so it's actually possible to implement a device that uses polling. Signed-off-by: Johannes Berg Message-Id: <20200123081708.7817-5-johannes@sipsolutions.net> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/libvhost-user/libvhost-user.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index 533d55d82a..3abc9689e5 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -948,6 +948,7 @@ static bool vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg) { int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; if (index >= dev->max_queues) { vmsg_close_fds(vmsg); @@ -955,8 +956,12 @@ vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg) return false; } - if (vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK || - vmsg->fd_num != 1) { + if (nofd) { + vmsg_close_fds(vmsg); + return true; + } + + if (vmsg->fd_num != 1) { vmsg_close_fds(vmsg); vu_panic(dev, "Invalid fds in request: %d", vmsg->request); return false; @@ -1053,6 +1058,7 @@ static bool vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) { int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); @@ -1066,8 +1072,8 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].kick_fd = -1; } - dev->vq[index].kick_fd = vmsg->fds[0]; - DPRINT("Got kick_fd: %d for vq: %d\n", vmsg->fds[0], index); + dev->vq[index].kick_fd = nofd ? -1 : vmsg->fds[0]; + DPRINT("Got kick_fd: %d for vq: %d\n", dev->vq[index].kick_fd, index); dev->vq[index].started = true; if (dev->iface->queue_set_started) { @@ -1147,6 +1153,7 @@ static bool vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg) { int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); @@ -1159,14 +1166,14 @@ vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].call_fd = -1; } - dev->vq[index].call_fd = vmsg->fds[0]; + dev->vq[index].call_fd = nofd ? -1 : vmsg->fds[0]; /* in case of I/O hang after reconnecting */ - if (eventfd_write(vmsg->fds[0], 1)) { + if (dev->vq[index].call_fd != -1 && eventfd_write(vmsg->fds[0], 1)) { return -1; } - DPRINT("Got call_fd: %d for vq: %d\n", vmsg->fds[0], index); + DPRINT("Got call_fd: %d for vq: %d\n", dev->vq[index].call_fd, index); return false; } @@ -1175,6 +1182,7 @@ static bool vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg) { int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); @@ -1187,7 +1195,7 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].err_fd = -1; } - dev->vq[index].err_fd = vmsg->fds[0]; + dev->vq[index].err_fd = nofd ? -1 : vmsg->fds[0]; return false; } From patchwork Tue Feb 25 15:14:35 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: 1244364 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=gviRT5Ct; 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 48RjVN1HtHz9sNg for ; Wed, 26 Feb 2020 02:27:40 +1100 (AEDT) Received: from localhost ([::1]:58822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c7V-0007rT-SY for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:27:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57668) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c2A-0006vm-F6 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:22:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6c27-0005ax-Fa for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:22:05 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:59399 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6c27-0005ai-AC for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:22:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582644122; 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=nZwaoT8ln7N1pwdGZSi/M96OJjKYOXxCelBD0UpRWYU=; b=gviRT5Ct7Pg0iOApOAwIFI/3L7HcQvFtdrnWd70QRHqZ6vxbXjZnkT/p47IKdV+GPCBZc0 KnGpWT6OQZecGyNrjFWYmQfT5ooEll1q73ttgAS1gfSAsgIYSnaK5ZE/7cL0Px5Vd3nFB+ nDtPR5T6Aro1UiXQFWgMleOO5SDabD0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-yUJE0GXJO-eAZ6k9OwhudQ-1; Tue, 25 Feb 2020 10:21:59 -0500 X-MC-Unique: yUJE0GXJO-eAZ6k9OwhudQ-1 Received: by mail-qk1-f197.google.com with SMTP id d2so1517141qko.3 for ; Tue, 25 Feb 2020 07:21:59 -0800 (PST) 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=XVBUwOrV9AJ3BOstgnwfQS2qsfQvMf0BYM163UrjERk=; b=uIcmAmyfv/gZcqcUGnHRbb9wEd5bzLVT32ln/Ox3/lwHiLUsEnzAq2feRfYa/STuhM WAt4jKOxIi2Tk1GBDCI7C2dCSxCGCD/vsT8vCrTAy0JgiAHvyom6gEgaHZcSlPHDP8+4 HeTW6l1jwajyXGZpuRg9Yzea8EzIwF+a8z9ixsgGHJDWzQhgKPGIDw+Ie4nlXDOOcJy2 2DafAnlSk+wKmqfXf+3iR/GwB6XoOt5kj8Nk52Mc3A824EIKTAn9UWE02WxNk12HaWG7 swmxnFjZ4TAtzxOT7QvT2JtDxYjyMmaZ3jRK78azzQwhH/O77S9ltfBI8eJ8uM0RgacM t2bQ== X-Gm-Message-State: APjAAAUIt0c6N7ua652bJ/uosdSLsBcsgkcMfkPzjV+r7rysIp164xpn rG4IGdTFW2DlB5/CfN2vV05stq8pCO09ibAZ9eCpQbRVWV7zjf7gc2u9MbUrvD2zjC7YZcH2/EG VzPKX3oVeg7MkWBw= X-Received: by 2002:ac8:7309:: with SMTP id x9mr56748388qto.338.1582644118196; Tue, 25 Feb 2020 07:21:58 -0800 (PST) X-Google-Smtp-Source: APXvYqzv9zOrNnODNqpU43O6DNRONArzFzC6ICK2uuIBkMuzYv6piGuHdqp/EQ/cTHXLD1o3luy25A== X-Received: by 2002:a05:620a:222d:: with SMTP id n13mr58434276qkh.268.1582643680224; Tue, 25 Feb 2020 07:14:40 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id o4sm510222qki.26.2020.02.25.07.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:39 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:35 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 26/32] docs: vhost-user: add in-band kick/call messages Message-ID: <20200225151210.647797-27-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Johannes Berg Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Johannes Berg For good reason, vhost-user is currently built asynchronously, that way better performance can be obtained. However, for certain use cases such as simulation, this is problematic. Consider an event-based simulation in which both the device and CPU have scheduled according to a simulation "calendar". Now, consider the CPU sending I/O to the device, over a vring in the vhost-user protocol. In this case, the CPU must wait for the vring interrupt to have been processed by the device, so that the device is able to put an entry onto the simulation calendar to obtain time to handle the interrupt. Note that this doesn't mean the I/O is actually done at this time, it just means that the handling of it is scheduled before the CPU can continue running. This cannot be done with the asynchronous eventfd based vring kick and call design. Extend the protocol slightly, so that a message can be used for kick and call instead, if VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS is negotiated. This in itself doesn't guarantee synchronisation, but both sides can also negotiate VHOST_USER_PROTOCOL_F_REPLY_ACK and thus get a reply to this message by setting the need_reply flag, and ensure synchronisation this way. To really use it in both directions, VHOST_USER_PROTOCOL_F_SLAVE_REQ is also needed. Since it is used for simulation purposes and too many messages on the socket can lock up the virtual machine, document that this should only be used together with the mentioned features. Signed-off-by: Johannes Berg Message-Id: <20200123081708.7817-6-johannes@sipsolutions.net> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/interop/vhost-user.rst | 122 ++++++++++++++++++++++++++++++------ 1 file changed, 104 insertions(+), 18 deletions(-) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index 5f8b3a456b..401652397c 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -2,6 +2,7 @@ Vhost-user Protocol =================== :Copyright: 2014 Virtual Open Systems Sarl. +:Copyright: 2019 Intel Corporation :Licence: This work is licensed under the terms of the GNU GPL, version 2 or later. See the COPYING file in the top-level directory. @@ -279,6 +280,9 @@ If *master* is unable to send the full message or receives a wrong reply it will close the connection. An optional reconnection mechanism can be implemented. +If *slave* detects some error such as incompatible features, it may also +close the connection. This should only happen in exceptional circumstances. + Any protocol extensions are gated by protocol feature bits, which allows full backwards compatibility on both master and slave. As older slaves don't support negotiating protocol features, a feature @@ -315,7 +319,8 @@ it until ring is started, or after it has been stopped. Client must start ring upon receiving a kick (that is, detecting that file descriptor is readable) on the descriptor specified by -``VHOST_USER_SET_VRING_KICK``, and stop ring upon receiving +``VHOST_USER_SET_VRING_KICK`` or receiving the in-band message +``VHOST_USER_VRING_KICK`` if negotiated, and stop ring upon receiving ``VHOST_USER_GET_VRING_BASE``. While processing the rings (whether they are enabled or not), client @@ -767,25 +772,49 @@ When reconnecting: #. Resubmit inflight ``DescStatePacked`` entries in order of their counter value +In-band notifications +--------------------- + +In some limited situations (e.g. for simulation) it is desirable to +have the kick, call and error (if used) signals done via in-band +messages instead of asynchronous eventfd notifications. This can be +done by negotiating the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` +protocol feature. + +Note that due to the fact that too many messages on the sockets can +cause the sending application(s) to block, it is not advised to use +this feature unless absolutely necessary. It is also considered an +error to negotiate this feature without also negotiating +``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` and ``VHOST_USER_PROTOCOL_F_REPLY_ACK``, +the former is necessary for getting a message channel from the slave +to the master, while the latter needs to be used with the in-band +notification messages to block until they are processed, both to avoid +blocking later and for proper processing (at least in the simulation +use case.) As it has no other way of signalling this error, the slave +should close the connection as a response to a +``VHOST_USER_SET_PROTOCOL_FEATURES`` message that sets the in-band +notifications feature flag without the other two. + Protocol features ----------------- .. code:: c - #define VHOST_USER_PROTOCOL_F_MQ 0 - #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 - #define VHOST_USER_PROTOCOL_F_RARP 2 - #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 - #define VHOST_USER_PROTOCOL_F_MTU 4 - #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 - #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 - #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7 - #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8 - #define VHOST_USER_PROTOCOL_F_CONFIG 9 - #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10 - #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11 - #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 - #define VHOST_USER_PROTOCOL_F_RESET_DEVICE 13 + #define VHOST_USER_PROTOCOL_F_MQ 0 + #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 + #define VHOST_USER_PROTOCOL_F_RARP 2 + #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 + #define VHOST_USER_PROTOCOL_F_MTU 4 + #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 + #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 + #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7 + #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8 + #define VHOST_USER_PROTOCOL_F_CONFIG 9 + #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10 + #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11 + #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 + #define VHOST_USER_PROTOCOL_F_RESET_DEVICE 13 + #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 Master message types -------------------- @@ -947,7 +976,12 @@ Master message types Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling should be used - instead of waiting for a kick. + instead of waiting for the kick. Note that if the protocol feature + ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` has been negotiated + this message isn't necessary as the ring is also started on the + ``VHOST_USER_VRING_KICK`` message, it may however still be used to + set an event file descriptor (which will be preferred over the + message) or to enable polling. ``VHOST_USER_SET_VRING_CALL`` :id: 13 @@ -960,7 +994,12 @@ Master message types Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling will be used - instead of waiting for the call. + instead of waiting for the call. Note that if the protocol features + ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` and + ``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` have been negotiated this message + isn't necessary as the ``VHOST_USER_SLAVE_VRING_CALL`` message can be + used, it may however still be used to set an event file descriptor + or to enable polling. ``VHOST_USER_SET_VRING_ERR`` :id: 14 @@ -972,7 +1011,12 @@ Master message types Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor - in the ancillary data. + in the ancillary data. Note that if the protocol features + ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` and + ``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` have been negotiated this message + isn't necessary as the ``VHOST_USER_SLAVE_VRING_ERR`` message can be + used, it may however still be used to set an event file descriptor + (which will be preferred over the message). ``VHOST_USER_GET_QUEUE_NUM`` :id: 17 @@ -1205,6 +1249,20 @@ Master message types Only valid if the ``VHOST_USER_PROTOCOL_F_RESET_DEVICE`` protocol feature is set by the backend. +``VHOST_USER_VRING_KICK`` + :id: 35 + :equivalent ioctl: N/A + :slave payload: vring state description + :master payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol + feature has been successfully negotiated, this message may be + submitted by the master to indicate that a buffer was added to + the vring instead of signalling it using the vring's kick file + descriptor or having the slave rely on polling. + + The state.num field is currently reserved and must be set to 0. + Slave message types ------------------- @@ -1261,6 +1319,34 @@ Slave message types ``VHOST_USER_PROTOCOL_F_HOST_NOTIFIER`` protocol feature has been successfully negotiated. +``VHOST_USER_SLAVE_VRING_CALL`` + :id: 4 + :equivalent ioctl: N/A + :slave payload: vring state description + :master payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol + feature has been successfully negotiated, this message may be + submitted by the slave to indicate that a buffer was used from + the vring instead of signalling this using the vring's call file + descriptor or having the master relying on polling. + + The state.num field is currently reserved and must be set to 0. + +``VHOST_USER_SLAVE_VRING_ERR`` + :id: 5 + :equivalent ioctl: N/A + :slave payload: vring state description + :master payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol + feature has been successfully negotiated, this message may be + submitted by the slave to indicate that an error occurred on the + specific vring, instead of signalling the error file descriptor + set by the master via ``VHOST_USER_SET_VRING_ERR``. + + The state.num field is currently reserved and must be set to 0. + .. _reply_ack: VHOST_USER_PROTOCOL_F_REPLY_ACK From patchwork Tue Feb 25 15:14: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: 1244363 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=HQ9hwR8s; 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 48RjV86hyBz9sNg for ; Wed, 26 Feb 2020 02:27:28 +1100 (AEDT) Received: from localhost ([::1]:58816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c7K-0007Vk-OV for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:27:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56062) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bvC-0002Qc-VV for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bvB-0001oG-45 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:54 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:49144 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bvA-0001o2-Uz for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643692; 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=l++BsqWy6N6vNodZEk7v6Kw66F2SSiMTtlt2r/wo72g=; b=HQ9hwR8skUj1zS0NNOoi5gWPjDwZ8rN6Y3MlU0Bm2IbBlChp6MEqokM5v7Kcse9yDdANbI VDsdt+YRumxNd+YIzGGQ1z2n8Rnlv0wcyIeRpkWR/xtG3Zc0lX8J70Tn+6nfX3nr94pl5s wo+xPrkmulIJu/iu7Wust2L+AwLaUzU= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-hGLZxvgSOS-dFnuXacV1dA-1; Tue, 25 Feb 2020 10:14:49 -0500 X-MC-Unique: hGLZxvgSOS-dFnuXacV1dA-1 Received: by mail-qv1-f69.google.com with SMTP id dc2so13218582qvb.7 for ; Tue, 25 Feb 2020 07:14:49 -0800 (PST) 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=ueZNy91f6vpalfK/xoKwpCSS7mTT4hlV5Y3nJIZ9/Zk=; b=uba1kWGyceQYpkaVPLmBj766+BEEjn8fhZJy2sj3XM8PiSHFmet5NWYzkg7DwDC4m9 xh71kONb6IZcEnjPqvfzGaG23fbQ8LfwH66myLehjVpFBqWX/R/4hGtzKzUYjGc6zgC1 TqJW+y/dYXxOolG48QlBbfpnSmsmGaaXzFOdSBowz7ANEmKTqrDhtEM2SKY7PpfMg7HT 3CIAk/C3+vLvyB0EZ1zGEV0YIAzX2yFp0piGi4vvpvyes7Ht74xEuOyaTRK1KVumUHdm O0coEDVKWZPWvZsDAiTxz9d02shrtQHtCEnV6nPEnLhXIKGX3Kdo6KcjNv6GYVZijE3/ Df9A== X-Gm-Message-State: APjAAAUsf7lRY4FbUP9o8yN+rADRXNMD+oGth0y8dMv57gQ6GMpxKMLO Sr3HImajD54cttrH1J1hg41+7g66WKtIakhS7gkAWbCYo0rFc6M7OfPyfbFhmjJXNgAY+F9jiXp qcECC7KailC3U/Sw= X-Received: by 2002:ac8:198c:: with SMTP id u12mr56228733qtj.225.1582643686884; Tue, 25 Feb 2020 07:14:46 -0800 (PST) X-Google-Smtp-Source: APXvYqy26XlEY3MIPBpDYN91g1BMIOEER1fpG7q5M5iCBAolGZIURfia3aJqOeu6xPTE6w9s7CCmeA== X-Received: by 2002:ac8:198c:: with SMTP id u12mr56228583qtj.225.1582643685440; Tue, 25 Feb 2020 07:14:45 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id p50sm7962368qtf.5.2020.02.25.07.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:44 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:40 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 27/32] libvhost-user: implement in-band notifications Message-ID: <20200225151210.647797-28-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Johannes Berg , "Dr. David Alan Gilbert" , Gerd Hoffmann , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9?= Lureau , Xie Yongji Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Johannes Berg Add support for VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS, but as it's not desired by default, don't enable it unless the device implementation opts in by returning it from its protocol features callback. Note that I updated vu_set_vring_err_exec(), but didn't add any sending of the VHOST_USER_SLAVE_VRING_ERR message as there's no write to the err_fd today either. This also adds vu_queue_notify_sync() which can be used to force a synchronous notification if inband notifications are supported. Previously, I had left out the slave->master direction handling of F_REPLY_ACK, this now adds some code to support it as well. Signed-off-by: Johannes Berg Message-Id: <20200123081708.7817-7-johannes@sipsolutions.net> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/libvhost-user/libvhost-user.h | 14 ++++ contrib/libvhost-user/libvhost-user.c | 103 +++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 3 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h index 5cb7708559..6fc8000e99 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -54,6 +54,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12, + VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS = 14, VHOST_USER_PROTOCOL_F_MAX }; @@ -95,6 +96,7 @@ typedef enum VhostUserRequest { VHOST_USER_GET_INFLIGHT_FD = 31, VHOST_USER_SET_INFLIGHT_FD = 32, VHOST_USER_GPU_SET_SOCKET = 33, + VHOST_USER_VRING_KICK = 35, VHOST_USER_MAX } VhostUserRequest; @@ -103,6 +105,8 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_IOTLB_MSG = 1, VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, + VHOST_USER_SLAVE_VRING_CALL = 4, + VHOST_USER_SLAVE_VRING_ERR = 5, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; @@ -528,6 +532,16 @@ bool vu_queue_empty(VuDev *dev, VuVirtq *vq); */ void vu_queue_notify(VuDev *dev, VuVirtq *vq); +/** + * vu_queue_notify_sync: + * @dev: a VuDev context + * @vq: a VuVirtq queue + * + * Request to notify the queue via callfd (skipped if unnecessary) + * or sync message if possible. + */ +void vu_queue_notify_sync(VuDev *dev, VuVirtq *vq); + /** * vu_queue_pop: * @dev: a VuDev context diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index 3abc9689e5..3bca996c62 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -136,6 +136,7 @@ vu_request_to_string(unsigned int req) REQ(VHOST_USER_GET_INFLIGHT_FD), REQ(VHOST_USER_SET_INFLIGHT_FD), REQ(VHOST_USER_GPU_SET_SOCKET), + REQ(VHOST_USER_VRING_KICK), REQ(VHOST_USER_MAX), }; #undef REQ @@ -163,7 +164,10 @@ vu_panic(VuDev *dev, const char *msg, ...) dev->panic(dev, buf); free(buf); - /* FIXME: find a way to call virtio_error? */ + /* + * FIXME: + * find a way to call virtio_error, or perhaps close the connection? + */ } /* Translate guest physical address to our virtual address. */ @@ -1203,6 +1207,14 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg) static bool vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) { + /* + * Note that we support, but intentionally do not set, + * VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS. This means that + * a device implementation can return it in its callback + * (get_protocol_features) if it wants to use this for + * simulation, but it is otherwise not desirable (if even + * implemented by the master.) + */ uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_MQ | 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD | 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | @@ -1235,6 +1247,25 @@ vu_set_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) dev->protocol_features = vmsg->payload.u64; + if (vu_has_protocol_feature(dev, + VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS) && + (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_REQ) || + !vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { + /* + * The use case for using messages for kick/call is simulation, to make + * the kick and call synchronous. To actually get that behaviour, both + * of the other features are required. + * Theoretically, one could use only kick messages, or do them without + * having F_REPLY_ACK, but too many (possibly pending) messages on the + * socket will eventually cause the master to hang, to avoid this in + * scenarios where not desired enforce that the settings are in a way + * that actually enables the simulation case. + */ + vu_panic(dev, + "F_IN_BAND_NOTIFICATIONS requires F_SLAVE_REQ && F_REPLY_ACK"); + return false; + } + if (dev->iface->set_protocol_features) { dev->iface->set_protocol_features(dev, features); } @@ -1495,6 +1526,34 @@ vu_set_inflight_fd(VuDev *dev, VhostUserMsg *vmsg) return false; } +static bool +vu_handle_vring_kick(VuDev *dev, VhostUserMsg *vmsg) +{ + unsigned int index = vmsg->payload.state.index; + + if (index >= dev->max_queues) { + vu_panic(dev, "Invalid queue index: %u", index); + return false; + } + + DPRINT("Got kick message: handler:%p idx:%d\n", + dev->vq[index].handler, index); + + if (!dev->vq[index].started) { + dev->vq[index].started = true; + + if (dev->iface->queue_set_started) { + dev->iface->queue_set_started(dev, index, true); + } + } + + if (dev->vq[index].handler) { + dev->vq[index].handler(dev, index); + } + + return false; +} + static bool vu_process_message(VuDev *dev, VhostUserMsg *vmsg) { @@ -1577,6 +1636,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg) return vu_get_inflight_fd(dev, vmsg); case VHOST_USER_SET_INFLIGHT_FD: return vu_set_inflight_fd(dev, vmsg); + case VHOST_USER_VRING_KICK: + return vu_handle_vring_kick(dev, vmsg); default: vmsg_close_fds(vmsg); vu_panic(dev, "Unhandled request: %d", vmsg->request); @@ -2038,8 +2099,7 @@ vring_notify(VuDev *dev, VuVirtq *vq) return !v || vring_need_event(vring_get_used_event(vq), new, old); } -void -vu_queue_notify(VuDev *dev, VuVirtq *vq) +static void _vu_queue_notify(VuDev *dev, VuVirtq *vq, bool sync) { if (unlikely(dev->broken) || unlikely(!vq->vring.avail)) { @@ -2051,11 +2111,48 @@ vu_queue_notify(VuDev *dev, VuVirtq *vq) return; } + if (vq->call_fd < 0 && + vu_has_protocol_feature(dev, + VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS) && + vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_REQ)) { + VhostUserMsg vmsg = { + .request = VHOST_USER_SLAVE_VRING_CALL, + .flags = VHOST_USER_VERSION, + .size = sizeof(vmsg.payload.state), + .payload.state = { + .index = vq - dev->vq, + }, + }; + bool ack = sync && + vu_has_protocol_feature(dev, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + + if (ack) { + vmsg.flags |= VHOST_USER_NEED_REPLY_MASK; + } + + vu_message_write(dev, dev->slave_fd, &vmsg); + if (ack) { + vu_message_read(dev, dev->slave_fd, &vmsg); + } + return; + } + if (eventfd_write(vq->call_fd, 1) < 0) { vu_panic(dev, "Error writing eventfd: %s", strerror(errno)); } } +void vu_queue_notify(VuDev *dev, VuVirtq *vq) +{ + _vu_queue_notify(dev, vq, false); +} + +void vu_queue_notify_sync(VuDev *dev, VuVirtq *vq) +{ + _vu_queue_notify(dev, vq, true); +} + static inline void vring_used_flags_set_bit(VuVirtq *vq, int mask) { From patchwork Tue Feb 25 15:14:46 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: 1244366 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=Mv4e5Vwr; 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 48RjWz0HQvz9sRQ for ; Wed, 26 Feb 2020 02:29:03 +1100 (AEDT) Received: from localhost ([::1]:58838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c8q-0001c1-UC for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:29:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56085) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bvG-0002R8-GY for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bvE-0001qY-Kz for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:46770 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bvE-0001pg-Gz for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:14:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643695; 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=CczPzEBWhhpjWKucs1+Hoc+p5ZrBciU/h88CuRi6XY8=; b=Mv4e5VwrLwN4U1vK4DmfhLhit6xungcAFFdNTWQKS82NtafmEFoxXnrgaMUz5C/y8gJmh0 Qwgh7cgksyYTZWdiKu0ni4m0bxco8TZxgMMseA+8N+yFOPUgdFDwzM+BPF97nMS32uRJRy C7Yr1QIJUDfzU5LTnvsr/AT0WoobLsw= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-RaFU9gQdPBi9U8SyW6i-MQ-1; Tue, 25 Feb 2020 10:14:52 -0500 X-MC-Unique: RaFU9gQdPBi9U8SyW6i-MQ-1 Received: by mail-qt1-f198.google.com with SMTP id z25so15190798qto.8 for ; Tue, 25 Feb 2020 07:14:52 -0800 (PST) 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=i0G0n0Ave2olUcIJuOrc5QTfak11CeuD33nep9puVrE=; b=mOopvqu2s1s/hOxMagFwey65cYBErxvt0qbFKbwKfBG3H+/93tnVBxKl3D4uinHzKs KUOvoTt9jGDyv1wvFGgHh1bW51U/tD1763KUXS2/BEJw5kzL8wMUFQuTrhg8LXPXHAl9 yVmIIkO0wWszFAViQ3/6/yVt6suwkPfYJGwz6xr0Y9UimhOpHtGG9nyu4Lvs1ltPtqtK OPWNSEqvnTUaj0anlXF74CR1xixKpaVckqj57patEcYBe4IMZmiiH2zBbfeu+oqviJwi 87CmAVaCEA9f4Vl0hTRzDbS+kl0qsOREzqFdSZ7lhv7dnLEpTPfPENuInhWZaBG9FORU bKGg== X-Gm-Message-State: APjAAAVhrnzxB01HkRNGgT9hCsoPztwTfhM42FOapfYIt4ME/QxWkD4s 0y1+h/FUDJ3jzZ8VQxseVM7C7sB/xFEO6C+JLB8RjkSzzyuezGVTQg3Tm2sBrGjja1164S4rw1x hNMsyWphVwyS4HjU= X-Received: by 2002:ac8:498f:: with SMTP id f15mr53954496qtq.123.1582643691373; Tue, 25 Feb 2020 07:14:51 -0800 (PST) X-Google-Smtp-Source: APXvYqwGVt7dN13aXum412QJ+5kYWa+gxbxrriNZS5ebQzvewP5dAOtGXwuFpCAZWY7hhu6OFBN67w== X-Received: by 2002:ac8:498f:: with SMTP id f15mr53954472qtq.123.1582643691128; Tue, 25 Feb 2020 07:14:51 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id i28sm7891147qtc.57.2020.02.25.07.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:50 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:46 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 28/32] acpi: cpuhp: document CPHP_GET_CPU_ID_CMD command Message-ID: <20200225151210.647797-29-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , Laszlo Ersek , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov Commit 3a61c8db9d25 introduced CPHP_GET_CPU_ID_CMD command but did not sufficiently describe it. Fix it by adding missing command documentation. Fixes: 3a61c8db9d25 ("acpi: cpuhp: add CPHP_GET_CPU_ID_CMD command") Signed-off-by: Igor Mammedov Reviewed-by: Laszlo Ersek Message-Id: <1580306781-228371-1-git-send-email-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/specs/acpi_cpu_hotplug.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/specs/acpi_cpu_hotplug.txt b/docs/specs/acpi_cpu_hotplug.txt index a8ce5e7402..9bb22d1270 100644 --- a/docs/specs/acpi_cpu_hotplug.txt +++ b/docs/specs/acpi_cpu_hotplug.txt @@ -94,6 +94,8 @@ write access: register in QEMU 2: following writes to 'Command data' register set OST status register in QEMU + 3: following reads from 'Command data' and 'Command data 2' return + architecture specific CPU ID value for currently selected CPU. other values: reserved [0x6-0x7] reserved [0x8] Command data: (DWORD access) From patchwork Tue Feb 25 15:14: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: 1244350 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=itxEuUF8; 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 48RjKT1qmvz9sNg for ; Wed, 26 Feb 2020 02:19:57 +1100 (AEDT) Received: from localhost ([::1]:58596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c03-0001Oc-4A for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:19:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56145) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bvO-0002ae-8i for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bvN-0001zN-9d for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:06 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:29926 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bvN-0001ys-58 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643704; 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=FMRhQ/mUb+ufDOWEKs47dVntkMzI4SGR916thXkoGdQ=; b=itxEuUF8vWYXURK45bSgjKaz0KRRL0GqB1WRnoLUWysDGZtTYMplSYkiXZ+A/q6wXQUR5V WRQFHvWHpmbkJBeG+/Y+WNyj9aYm4l0FGhrtr6lHpjvxf1vUb43ggN1VgjQ1AyWazZks4V vUnfaWRH7412PGkaPCVBNGrCvHTlYuc= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-P1TuutaOPLOYV3RwtJKoAA-1; Tue, 25 Feb 2020 10:15:00 -0500 X-MC-Unique: P1TuutaOPLOYV3RwtJKoAA-1 Received: by mail-qv1-f69.google.com with SMTP id v3so13249523qvm.2 for ; Tue, 25 Feb 2020 07:14:57 -0800 (PST) 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=9KYoAzz21glog7o+enMMiTE7eLNGzgQi6YqNld1TBIY=; b=XXFq6aKKqEVwPmAE/+YFpGrhlbV7nmDPbosSzsmjLheuloMLwP/E+AmkgqjCHYEJJ0 NTQ1ob53IAMSBz0vsQkM80vnQjIBBy7k7ay7kJUVdI6Lv7L9izkuCnjwTrmD0s+0rIOJ FbA97tYwALcnza3uKSomeIPaMAzi7DugGrrAXMvH2M7LV3pCGF5/2xP4+H3UKSr6cSk4 yHb/zjLCOVDaCc81p5r+DFm85ubJRG3Ci9VTeumsDBifkM0hacEmy6xYiH2jx0mDQFCr 39nyj/18mUSuhoQm3aN3uYRA18DSiuLHyavxWTjPZDifcW86MQU52q7BOM+bLKis2NUW wa8A== X-Gm-Message-State: APjAAAXL8hd2YizXoCQ9p9kCpxyj83tL/LO5SZxy8iH0BSLckVseIK9G vzSzYLROqFt0QAfGz2iP4CD2t4f5DloPOffVp7gP26S/HlMuK6zXbKK+WeoQvplmc1H0bB8VXyC GKsn1EJ+xK6NM3IA= X-Received: by 2002:ae9:e207:: with SMTP id c7mr54105002qkc.128.1582643696845; Tue, 25 Feb 2020 07:14:56 -0800 (PST) X-Google-Smtp-Source: APXvYqw6IYjuv6XMdVw6LPfvZxwGdWx2Niu1HKyIUy0enhfAvbYDpcq2+7ls9EkcF1nzaIRCgeDioA== X-Received: by 2002:ae9:e207:: with SMTP id c7mr54104926qkc.128.1582643696016; Tue, 25 Feb 2020 07:14:56 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id u5sm3133820qkf.32.2020.02.25.07.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:14:55 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:51 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 29/32] vhost-user: only set slave channel for first vq Message-ID: <20200225151210.647797-30-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Adrian Moreno , marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Adrian Moreno When multiqueue is enabled, a vhost_dev is created for each queue pair. However, only one slave channel is needed. Fixes: 4bbeeba023f2 (vhost-user: add slave-req-fd support) Cc: marcandre.lureau@redhat.com Signed-off-by: Adrian Moreno Message-Id: <20200121214553.28459-1-amorenoz@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-user.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 2e81f5514f..35baf4f347 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1458,9 +1458,11 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque) "VHOST_USER_PROTOCOL_F_LOG_SHMFD feature."); } - err = vhost_setup_slave_channel(dev); - if (err < 0) { - return err; + if (dev->vq_index == 0) { + err = vhost_setup_slave_channel(dev); + if (err < 0) { + return err; + } } u->postcopy_notifier.notify = vhost_user_postcopy_notifier; From patchwork Tue Feb 25 15:14:56 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: 1244362 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=fb5SHJlv; 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 48RjSl4DG0z9sNg for ; Wed, 26 Feb 2020 02:26:15 +1100 (AEDT) Received: from localhost ([::1]:58794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c69-0005LI-FW for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:26:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56156) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bvP-0002c1-EK for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bvO-00020E-7e for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:07 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:44416 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bvN-0001zd-RM for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643705; 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=G6c8L9eQw051eaC/4+i0vqRJfgJb3JB+2EyTASZyViM=; b=fb5SHJlvHg0pukXcjT5TFqeUs0Ep3aIoxunoaPisPyTgmz5ZHGDk9kvuiENsz9GSvcvB0Z ciKEmhDci0hXmT5KwBfOxVimnxq2zkFq4Rayh8UeFsUJA5B0mxPqqKQlMfiqbTY4Aoz5VC dU5KDVkPTmYN3clhI412QXkeJMPyec8= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-MJjGBozAOOWPI5MV2Fu4PA-1; Tue, 25 Feb 2020 10:15:03 -0500 X-MC-Unique: MJjGBozAOOWPI5MV2Fu4PA-1 Received: by mail-qv1-f72.google.com with SMTP id dr18so13232069qvb.14 for ; Tue, 25 Feb 2020 07:15:02 -0800 (PST) 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=mLvYfpxhMKRcFnvE2egjwCdKSrBCyKI8mHWugLjsqSQ=; b=tgqHwjvNkuZA/FtgFbkwWkJ5nTedmz58bbZXbnQ47SuB0A/TTzAodfM5YP0iffUDo1 75ajo7PWjrWxO05W4njJowG5OcEeJ0COdh4ElPud6L/TeiZ67mWN+7+vipX/oHqJ92Iq eNmuUnyK/0nRt5B4lHX4+kFxorrFahqHVXnbXqeoxvTaZEnbLpD9qCr9kxwx1x7zQhnw rz3DqSpCV0WY94whViWCeXBMYOSRK11SZEk+LsVMmkIUAqld1CIX2z8hWkKIAwePso1z QJq1zPXURRFcmkVjCVfPuKVN0HY7lK0ndXflmdnzCnI+yRXCqkJSOOdXnIOkHtbg5tRH j1jA== X-Gm-Message-State: APjAAAUPCB163SUYUDuSJdGzvrfXeghdgEnJRWglwriiSSicK/iwJ8EH Fp1QA1ia/I3BZpmCZ2vhfz+2cOzQ9qh8CnHtp6mc+s7gL9Ik831VA43W9pE5l7wRytgQiK0/b6S G8z10161TT0umLmE= X-Received: by 2002:a37:a84f:: with SMTP id r76mr9094502qke.101.1582643701996; Tue, 25 Feb 2020 07:15:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzcM8OayS2VzLI0ns83pmppUBHCT9tR2BS8cVl7IPH7aOIZ8CLhUU8BIA2tx5p2TC6SDckCxw== X-Received: by 2002:a37:a84f:: with SMTP id r76mr9094469qke.101.1582643701737; Tue, 25 Feb 2020 07:15:01 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id b7sm7668455qtj.78.2020.02.25.07.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:15:00 -0800 (PST) Date: Tue, 25 Feb 2020 10:14:56 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 30/32] tests/vhost-user-bridge: move to contrib/ Message-ID: <20200225151210.647797-31-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Juan Quintela , "Dr . David Alan Gilbert" , Stefan Hajnoczi , Philippe =?utf-8?q?Mathieu-Dau?= =?utf-8?b?ZMOp?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier vhost-user-bridge is not a test. Move it to contrib/ and add it to the tools list. It will be built only if tools (--enable-tools) and vhost-user (--enable-vhost-user) are enabled (both are set by default). Suggested-by: Dr. David Alan Gilbert Signed-off-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20200207095412.794912-1-lvivier@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- configure | 3 +++ Makefile | 3 +++ tests/vhost-user-bridge.c => contrib/vhost-user-bridge/main.c | 0 Makefile.objs | 1 + contrib/vhost-user-bridge/Makefile.objs | 1 + docs/devel/migration.rst | 2 +- tests/Makefile.include | 1 - 7 files changed, 9 insertions(+), 2 deletions(-) rename tests/vhost-user-bridge.c => contrib/vhost-user-bridge/main.c (100%) create mode 100644 contrib/vhost-user-bridge/Makefile.objs diff --git a/configure b/configure index 48d6f89d57..de2b82b93c 100755 --- a/configure +++ b/configure @@ -6288,6 +6288,9 @@ if test "$want_tools" = "yes" ; then if [ "$curl" = "yes" ]; then tools="elf2dmp\$(EXESUF) $tools" fi + if [ "$vhost_user" = "yes" ]; then + tools="vhost-user-bridge\$(EXESUF) $tools" + fi fi if test "$softmmu" = yes ; then if test "$linux" = yes; then diff --git a/Makefile b/Makefile index aa9cc0b584..218b8259a4 100644 --- a/Makefile +++ b/Makefile @@ -445,6 +445,7 @@ dummy := $(call unnest-vars,, \ libvhost-user-obj-y \ vhost-user-scsi-obj-y \ vhost-user-blk-obj-y \ + vhost-user-bridge-obj-y \ vhost-user-input-obj-y \ vhost-user-gpu-obj-y \ qga-vss-dll-obj-y \ @@ -688,6 +689,8 @@ vhost-user-scsi$(EXESUF): $(vhost-user-scsi-obj-y) libvhost-user.a $(call LINK, $^) vhost-user-blk$(EXESUF): $(vhost-user-blk-obj-y) libvhost-user.a $(call LINK, $^) +vhost-user-bridge$(EXESUF): $(vhost-user-bridge-obj-y) libvhost-user.a + $(call LINK, $^) rdmacm-mux$(EXESUF): LIBS += "-libumad" rdmacm-mux$(EXESUF): $(rdmacm-mux-obj-y) $(COMMON_LDADDS) diff --git a/tests/vhost-user-bridge.c b/contrib/vhost-user-bridge/main.c similarity index 100% rename from tests/vhost-user-bridge.c rename to contrib/vhost-user-bridge/main.c diff --git a/Makefile.objs b/Makefile.objs index 8a1cbe8000..c282ff77dd 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -107,6 +107,7 @@ vhost-user-scsi.o-cflags := $(LIBISCSI_CFLAGS) vhost-user-scsi.o-libs := $(LIBISCSI_LIBS) vhost-user-scsi-obj-y = contrib/vhost-user-scsi/ vhost-user-blk-obj-y = contrib/vhost-user-blk/ +vhost-user-bridge-obj-y = contrib/vhost-user-bridge/ rdmacm-mux-obj-y = contrib/rdmacm-mux/ vhost-user-input-obj-y = contrib/vhost-user-input/ vhost-user-gpu-obj-y = contrib/vhost-user-gpu/ diff --git a/contrib/vhost-user-bridge/Makefile.objs b/contrib/vhost-user-bridge/Makefile.objs new file mode 100644 index 0000000000..36a8d9b49a --- /dev/null +++ b/contrib/vhost-user-bridge/Makefile.objs @@ -0,0 +1 @@ +vhost-user-bridge-obj-y = main.o diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index e88918f763..d00424460e 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -807,7 +807,7 @@ The Linux kernel userfault support works on `/dev/shm` memory and on `hugetlbfs` for hugetlbfs which may be a problem in some configurations). The vhost-user code in QEMU supports clients that have Postcopy support, -and the `vhost-user-bridge` (in `tests/`) and the DPDK package have changes +and the `vhost-user-bridge` (in `contrib/`) and the DPDK package have changes to support postcopy. The client needs to open a userfaultfd and register the areas diff --git a/tests/Makefile.include b/tests/Makefile.include index edcbd475aa..2dc95c52c8 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -588,7 +588,6 @@ include $(SRC_PATH)/tests/qtest/Makefile.include tests/test-qga$(EXESUF): qemu-ga$(EXESUF) tests/test-qga$(EXESUF): tests/test-qga.o $(qtest-obj-y) -tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-obj-y) libvhost-user.a SPEED = quick From patchwork Tue Feb 25 15:15: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: 1244357 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=SmcH+XmX; 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 48RjQW5z7Cz9sNg for ; Wed, 26 Feb 2020 02:24:18 +1100 (AEDT) Received: from localhost ([::1]:58744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c4G-00015X-2h for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:24:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56187) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bvU-0002ki-PF for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bvT-00024e-Pz for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:12 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:55477 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bvT-00023r-Kd for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643710; 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=e+2ubfbEqLiNZyFIpP2Z+jeoSNKaTGCUsXcUvlVb6BQ=; b=SmcH+XmX0bD+93Ggke+LY4VNhmKb2kTI3v1dp/dYrwxdmaa/G5NWk5gP/s/hpLnVO1XapG qkMRFe0BJtFBDgbZcmr7cnAfy6W1Fp5Imx0tRrz2o+Lhc7BnqZiBtPaDYqJ1Enz7u4uRie EiV+KnSrVPNj5SQvDceVzb19o5ZT66Q= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-481-qNi1Kg1xP-uYtFn2iMONMg-1; Tue, 25 Feb 2020 10:15:08 -0500 X-MC-Unique: qNi1Kg1xP-uYtFn2iMONMg-1 Received: by mail-qt1-f200.google.com with SMTP id j5so4857813qtp.19 for ; Tue, 25 Feb 2020 07:15:08 -0800 (PST) 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=c2crKeR2n2YvQ5rYnZd1NJPOMK8zXZOtMWZi9s0fZkM=; b=ITwrnfjXSD9CgG8dixm1sE50ipHcP4If2m20QBvbHfu7DZvyAC14/zW+iomRpUI/9l rlBO6hgihdcdlZXlzeujWUhw3vpHGjBVWMEtqm4RZg4XTDqYx3FqSMEtB0ztn/1kJx5N PHunoGwYsqiicMShZ745MDjpBA0qjS1wvfAofyNdgWUXYKebel3HAV70S59sjWO9HWXg DhGK1gl3JASTrs2tL9CvKY/HaM7vTTVKZBlEx6q2gvXW9a2VT8NlUheaq5uZCJice1ZZ VPL+zcCu0hvsmUgP2JU/UQJLacEjBrsNKbAt30/UKEz8P2Ib1Zh4Kp0qXCTdx4QxIJIS RCRw== X-Gm-Message-State: APjAAAWPrVJu/KOOxPRhieZf5+mo3yD5nww5GasTF4bOad4mjj3hKqwv TAqvZaeBRbZGLSFeSZWd6uHLmFwi0ERGmlreu0jjOsjoXIH/LkiaX/0CEIzWlzQAHotuv1QMk0/ EmS4ZI16cmEnPn54= X-Received: by 2002:ac8:1a8c:: with SMTP id x12mr56686242qtj.297.1582643707887; Tue, 25 Feb 2020 07:15:07 -0800 (PST) X-Google-Smtp-Source: APXvYqx7LbWoyyK9MoLk8toBltaGld046Gy5z24rpUEqBNjgJR5n4NzAfYJ6FqJ/fdrwFIgWokXShA== X-Received: by 2002:ac8:1a8c:: with SMTP id x12mr56686183qtj.297.1582643707487; Tue, 25 Feb 2020 07:15:07 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id j127sm7471687qkc.36.2020.02.25.07.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:15:06 -0800 (PST) Date: Tue, 25 Feb 2020 10:15:02 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 31/32] virtiofsd: add it to the tools list Message-ID: <20200225151210.647797-32-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Juan Quintela , Alex =?utf-8?q?Benn=C3=A9e?= , "Dr . David Alan Gilbert" , Stefan Hajnoczi , 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: Laurent Vivier it will be built only when tools are enabled (always enabled by default) Signed-off-by: Laurent Vivier Reviewed-by: Dr. David Alan Gilbert Message-Id: <20200207095412.794912-2-lvivier@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Juan Quintela Reviewed-by: Stefan Hajnoczi --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 218b8259a4..ba8ffc9331 100644 --- a/Makefile +++ b/Makefile @@ -327,7 +327,7 @@ HELPERS-y += vhost-user-gpu$(EXESUF) vhost-user-json-y += contrib/vhost-user-gpu/50-qemu-gpu.json endif -ifeq ($(CONFIG_LINUX)$(CONFIG_SECCOMP)$(CONFIG_LIBCAP_NG),yyy) +ifeq ($(CONFIG_LINUX)$(CONFIG_SECCOMP)$(CONFIG_LIBCAP_NG)$(CONFIG_TOOLS),yyyy) HELPERS-y += virtiofsd$(EXESUF) vhost-user-json-y += tools/virtiofsd/50-qemu-virtiofsd.json endif @@ -697,7 +697,7 @@ rdmacm-mux$(EXESUF): $(rdmacm-mux-obj-y) $(COMMON_LDADDS) $(call LINK, $^) # relies on Linux-specific syscalls -ifeq ($(CONFIG_LINUX)$(CONFIG_SECCOMP)$(CONFIG_LIBCAP_NG),yyy) +ifeq ($(CONFIG_LINUX)$(CONFIG_SECCOMP)$(CONFIG_LIBCAP_NG)$(CONFIG_TOOLS),yyyy) virtiofsd$(EXESUF): $(virtiofsd-obj-y) libvhost-user.a $(COMMON_LDADDS) $(call LINK, $^) endif From patchwork Tue Feb 25 15:15:08 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: 1244360 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=Dvwu6Brc; 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 48RjS54y10z9sPk for ; Wed, 26 Feb 2020 02:25:41 +1100 (AEDT) Received: from localhost ([::1]:58770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6c5b-0004LH-IR for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2020 10:25:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56309) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6bve-00038t-Qv for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6bvb-0002B3-6R for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:22 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:46825 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6bvb-0002AX-1C for qemu-devel@nongnu.org; Tue, 25 Feb 2020 10:15:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582643718; 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=KUkymaXxsrUBHOeYB4neDB0KIBMTPed4qcRzCegXv08=; b=Dvwu6BrcZcfVQoU+e923dnYUmP2gMhN9ELaC/JNybLSCgtBGgUGYiHwoiKtaRndMIWhGGY wUpqid+J1bW/sp3H4dMixcyyjdB61Hb1VX66MN+viyfEtCqavA7WEDmLfZy0PUU10JaJ2G 37Fl+64ry+woHB/mGGpu3psMOQ3fB7A= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-Jz5AhUd2PIqNZ4mmaqn_iw-1; Tue, 25 Feb 2020 10:15:13 -0500 X-MC-Unique: Jz5AhUd2PIqNZ4mmaqn_iw-1 Received: by mail-qv1-f70.google.com with SMTP id v19so13182506qvk.16 for ; Tue, 25 Feb 2020 07:15:13 -0800 (PST) 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=XaK3jxvT8IURsZc2FPYAI9xgrRGt+WXCR/pHTLcG0Wc=; b=CpPYskhi7eKkjhoJZEE+oIGF4ZRWHWBr7aqc6oqGAXdzNluKRZBZT0CfWkDJA5jYSK HyAz5OKuu1Cy1scvHYqQ5y+w9R40WMwvahvACpCVYMISqN9GT31lrpbplOGtWtSv4wl6 KN05xovh2TjV4+vgoebDs0vxyyWzQQim7b1/vO0PRgBGEPsFJ+ouR8eelBQJwjtVgax6 aZe44oH63Xh3b9WGG0jVuEqmVF6cfSJRJfqzPC0W6KC1jYC7es5C8OiMtXEfMlWbz3ZG nGNCTgEjpK9cZfhFkRzom4pffpRhfPQ/rkTgVxBLKJryyrQWWvNTh3cUQ9fdV14bd/h/ ru5g== X-Gm-Message-State: APjAAAVoLiIFEE4TRTCC+cTsdvPE0ocdFoFH6Mc9rel7HWoIBKKLnEeQ 0zaT9i4LDP2tz3ds2xdDOwkBGZPgb76BVeJKmnHN+3eGwY85Fv3uW2C7XDh8CM2IJQ8PTPQkYUE 6cR3H85qrVme8Jns= X-Received: by 2002:ae9:dcc1:: with SMTP id q184mr54488720qkf.480.1582643712565; Tue, 25 Feb 2020 07:15:12 -0800 (PST) X-Google-Smtp-Source: APXvYqy3rA58e4itkje2BrTsKcsd1eLqGM6ZBB6h6iTmFdMyPPol443KVMkbQj62IQvnh0M6U/YNFg== X-Received: by 2002:ae9:dcc1:: with SMTP id q184mr54488678qkf.480.1582643712072; Tue, 25 Feb 2020 07:15:12 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id y91sm7795014qtd.13.2020.02.25.07.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 07:15:11 -0800 (PST) Date: Tue, 25 Feb 2020 10:15:08 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 32/32] Fixed assert in vhost_user_set_mem_table_postcopy Message-ID: <20200225151210.647797-33-mst@redhat.com> References: <20200225151210.647797-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200225151210.647797-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Peter Turschmid , Raphael Norwitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Raphael Norwitz The current vhost_user_set_mem_table_postcopy() implementation populates each region of the VHOST_USER_SET_MEM_TABLE message without first checking if there are more than VHOST_MEMORY_MAX_NREGIONS already populated. This can cause memory corruption if too many regions are added to the message during the postcopy step. This change moves an existing assert up such that attempting to construct a VHOST_USER_SET_MEM_TABLE message with too many memory regions will gracefully bring down qemu instead of corrupting memory. Signed-off-by: Raphael Norwitz Signed-off-by: Peter Turschmid Message-Id: <1579143426-18305-2-git-send-email-raphael.norwitz@nutanix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 35baf4f347..08e7e63790 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -443,6 +443,7 @@ static int vhost_user_set_mem_table_postcopy(struct vhost_dev *dev, &offset); fd = memory_region_get_fd(mr); if (fd > 0) { + assert(fd_num < VHOST_MEMORY_MAX_NREGIONS); trace_vhost_user_set_mem_table_withfd(fd_num, mr->name, reg->memory_size, reg->guest_phys_addr, @@ -455,7 +456,6 @@ static int vhost_user_set_mem_table_postcopy(struct vhost_dev *dev, msg.payload.memory.regions[fd_num].guest_phys_addr = reg->guest_phys_addr; msg.payload.memory.regions[fd_num].mmap_offset = offset; - assert(fd_num < VHOST_MEMORY_MAX_NREGIONS); fds[fd_num++] = fd; } else { u->region_rb_offset[i] = 0;