From patchwork Wed Oct 18 16:11:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KqgbqUCP"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHDf3Vbcz9sBd for ; Thu, 19 Oct 2017 03:13:54 +1100 (AEDT) Received: from localhost ([::1]:45451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qye-0003Lv-HN for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:13:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qxs-0003If-3R for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxp-0001wG-Gf for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:04 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:46844) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxp-0001va-Ag for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:01 -0400 Received: by mail-wm0-x244.google.com with SMTP id m72so10990723wmc.1 for ; Wed, 18 Oct 2017 09:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=scCKsNH4J0RGckTFtiaE0Eobbnc6y5GrGsWHH6SJ+yk=; b=KqgbqUCPuYFKpeAC7NtcVxXxs0lO5D7z9w+BzPitvBaldD9N9IE0DXZAp/8Rww6v1p SLj0LuAo23iPwGi/y6P3d46n8eRCrq5N8SR7zQPBQjw5/lTd9++W3u32cW3sX/TpWLeq UMt3Iq877eJ2eruN4tzVcwij0/LvkOD278hw/YnlJS4nmRIhEq+A/wHqIB0z6GBB8I6e YF6PlMPHixibW/RiTKVom+FzF/1sE1Iq/PDQuHa7a6fcpJ0bhoEhdLZ4dvrqWL/H942T L6rB1YvGeDjS6U1bDEHqN4HmRpIDfnP+iTbAhlGS2zJ0eMW195yzssKnLmp8MPHFKbJK 3VSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=scCKsNH4J0RGckTFtiaE0Eobbnc6y5GrGsWHH6SJ+yk=; b=P4LKunB7NPwHDe7528ddZ5xwwTnQ1uzwobAp3qx7oAGWTbfBgbhchN2z/IMaC8R9xU SyPS9NrZ9pqbyByipt/z1FT9L6kHrWZcCoE0/go/AOV6jrWGoGWf5n1PcCnGznrF+2oK lI50vx2+UtKsHKAMjbDJPyYjILTLKS5ZopxPfny7aNKwJdGq5B5FF9pMoEnFoaQm3Gto wm0P0xJYZuswamLaR+dOMyDaHpnCHDcgqga+J2ktqzaln1Wd5YjRZNd73tJrpiGLxZ4D FHJ7PncV6cMKkmlZjeXyKYPaTZstb/yGamt5ctjL3Fn6SCUYcNWnnfGHUh/BFLP8veIC RqJw== X-Gm-Message-State: AMCzsaXM/K88pP5c1adCAGUCGUcSrbRMOp1bcra7IWKMzbghA8Rg5J8e WqKRivnhI7ySighiC27DCrYaRPua X-Google-Smtp-Source: ABhQp+TemW8ORepzTNwA5xaa2rAoulLM73LBDezYp9RW5kdCljOFsrqQ4S7MMagmSXxCSA607I8I7A== X-Received: by 10.28.16.209 with SMTP id 200mr7072485wmq.35.1508343179857; Wed, 18 Oct 2017 09:12:59 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.12.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:12:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:11:53 +0200 Message-Id: <1508343141-31835-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 01/29] checkpatch: refine mode selection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" stgit produces patch files that lack the ".patch" extensions. Others might be using ".diff" too. But since we are already limiting source files to only a handful of extensions, we can reuse that in the mode selection code. While at it, do not match "../foo" as a branch name. Reviewed-by: Daniel P. Berrange Signed-off-by: Paolo Bonzini --- scripts/checkpatch.pl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0c41f12..ce9f08e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -11,6 +11,8 @@ use warnings; my $P = $0; $P =~ s@.*/@@g; +our $SrcFile = qr{\.(?:h|c|cpp|s|S|pl|py|sh)$}; + my $V = '0.31'; use Getopt::Long qw(:config no_auto_abbrev); @@ -101,30 +103,29 @@ if ($#ARGV < 0) { } if (!defined $chk_branch && !defined $chk_patch && !defined $file) { - $chk_branch = $ARGV[0] =~ /\.\./ ? 1 : 0; - $chk_patch = $chk_branch ? 0 : - $ARGV[0] =~ /\.patch$/ || $ARGV[0] eq "-" ? 1 : 0; - $file = $chk_branch || $chk_patch ? 0 : 1; + $chk_branch = $ARGV[0] =~ /.\.\./ ? 1 : 0; + $file = $ARGV[0] =~ /$SrcFile/ ? 1 : 0; + $chk_patch = $chk_branch || $file ? 0 : 1; } elsif (!defined $chk_branch && !defined $chk_patch) { if ($file) { $chk_branch = $chk_patch = 0; } else { - $chk_branch = $ARGV[0] =~ /\.\./ ? 1 : 0; + $chk_branch = $ARGV[0] =~ /.\.\./ ? 1 : 0; $chk_patch = $chk_branch ? 0 : 1; } } elsif (!defined $chk_branch && !defined $file) { if ($chk_patch) { $chk_branch = $file = 0; } else { - $chk_branch = $ARGV[0] =~ /\.\./ ? 1 : 0; + $chk_branch = $ARGV[0] =~ /.\.\./ ? 1 : 0; $file = $chk_branch ? 0 : 1; } } elsif (!defined $chk_patch && !defined $file) { if ($chk_branch) { $chk_patch = $file = 0; } else { - $chk_patch = $ARGV[0] =~ /\.patch$/ || $ARGV[0] eq "-" ? 1 : 0; - $file = $chk_patch ? 0 : 1; + $file = $ARGV[0] =~ /$SrcFile/ ? 1 : 0; + $chk_patch = $file ? 0 : 1; } } elsif (!defined $chk_branch) { $chk_branch = $chk_patch || $file ? 0 : 1; @@ -1443,7 +1444,7 @@ sub process { } # check we are in a valid source file if not then ignore this hunk - next if ($realfile !~ /\.(h|c|cpp|s|S|pl|py|sh)$/); + next if ($realfile !~ /$SrcFile/); #90 column limit if ($line =~ /^\+/ && From patchwork Wed Oct 18 16:11:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827691 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gimo6ZRb"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHDT4sFlz9sBd for ; Thu, 19 Oct 2017 03:13:45 +1100 (AEDT) Received: from localhost ([::1]:45448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyV-0003Il-MC for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:13:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qxs-0003Ie-3E for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxq-0001y9-JM for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:04 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:56502) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxq-0001wk-Cr for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:02 -0400 Received: by mail-wm0-x241.google.com with SMTP id l68so11139631wmd.5 for ; Wed, 18 Oct 2017 09:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=klWq4XmcCh31Q92/klrC4sVEBNIgXAH0TgnUXm/Dx3o=; b=Gimo6ZRbJp30HQEuaVrIIcXlSChjUaZtTuL32mPLG4kZHrP/ivFQbWmIyL9641gbpV 1RGhhJbzpfmh20bcBZV3W8H2CBTlAZj/PDEHXRcF4Z8UxAsMW/I1IZvtoxp8/oAPn4lG kXlR4S1jcOxUCWrsoSOGfbhedgSog9EhdQ25mR9Qo8YxzAln20dTVvHPNAvN0lOfy+Uv JvyoZJYAlYRiUl7+H/57sYyj+AKB76R/Kxojxg4FxnyAKFNR4YiHAanRboL6KFXQsznf CySqgka4ftK5kkVZ3CtrjDRKYVKFyHOXpxml1ZjOb24rJlSDJg905Bmg2Gry0X3z+VwW Y18w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=klWq4XmcCh31Q92/klrC4sVEBNIgXAH0TgnUXm/Dx3o=; b=lt3M4E80WwOm7M5yBdk0EChcttBtoGC3C2CIWBP2TWk8yNlz9tR1FH6dfdW8wsmBkI MAQOrI0Bo8NHBpOdNO33ylxPqbRXiwvUZF5NihZJsAw5GDCQo+OOeiFqRqDDj/To5aQG IDpXC+ry6CA0PKEsXkys4EfNu8hCaY8PGK4lW1hE0HOpJVfDb9MhCl7Hb3k69gLSfaVU t47lIYUIiZ2eWHfj8oVmwqr7eVsDBZs562uL1CjPDL0RkGwHCSUi9CYeQVXUKVmgW3c5 86ec01NuvId4A5baP3EmtjGM5ZrZMgJLsnFscVePu7tf2WncuLDk6HNwikV6j22T/+c7 f1Fg== X-Gm-Message-State: AMCzsaWjJ3mCYc6oWEdC/UvYDBSaheVQNk6y5/Tm4T06CmewI4e9E9pY /d1O62ndX/2Nac0/RkQf6TFqrFeV X-Google-Smtp-Source: ABhQp+RIG+D4sg+fRCGHR3B3CrWGL1rYRZPlelD/DVmVfjGTPVYwe5LiIbaoQC3Y9XbeYY9avxF+Rw== X-Received: by 10.28.149.204 with SMTP id x195mr7036396wmd.78.1508343181035; Wed, 18 Oct 2017 09:13:01 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.12.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:11:54 +0200 Message-Id: <1508343141-31835-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 02/29] scsi-disk: support reporting of rotation rate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Daniel P. Berrange" The Linux kernel will query the SCSI "Block device characteristics" VPD to determine the rotations per minute of the disk. If this has the value 1, it is taken to be an SSD and so Linux sets the 'rotational' flag to 0 for the I/O queue and will stop using that disk as a source of random entropy. Other operating systems may also take into account rotation rate when setting up default behaviour. Mgmt apps should be able to set the rotation rate for virtualized block devices, based on characteristics of the host storage in use, so that the guest OS gets sensible behaviour out of the box. This patch thus adds a 'rotation-rate' parameter for 'scsi-hd' and 'scsi-block' device types. For the latter, this parameter will be ignored unless the host device has TYPE_DISK. Signed-off-by: Daniel P. Berrange Message-Id: <20171004114008.14849-2-berrange@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 6e841fb..a518080 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -104,6 +104,14 @@ typedef struct SCSIDiskState char *product; bool tray_open; bool tray_locked; + /* + * 0x0000 - rotation rate not reported + * 0x0001 - non-rotating medium (SSD) + * 0x0002-0x0400 - reserved + * 0x0401-0xffe - rotations per minute + * 0xffff - reserved + */ + uint16_t rotation_rate; } SCSIDiskState; static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed); @@ -605,6 +613,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[buflen++] = 0x83; // device identification if (s->qdev.type == TYPE_DISK) { outbuf[buflen++] = 0xb0; // block limits + outbuf[buflen++] = 0xb1; /* block device characteristics */ outbuf[buflen++] = 0xb2; // thin provisioning } break; @@ -747,6 +756,15 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[43] = max_io_sectors & 0xff; break; } + case 0xb1: /* block device characteristics */ + { + buflen = 8; + outbuf[4] = (s->rotation_rate >> 8) & 0xff; + outbuf[5] = s->rotation_rate & 0xff; + outbuf[6] = 0; + outbuf[7] = 0; + break; + } case 0xb2: /* thin provisioning */ { buflen = 8; @@ -2911,6 +2929,7 @@ static Property scsi_hd_properties[] = { DEFAULT_MAX_UNMAP_SIZE), DEFINE_PROP_UINT64("max_io_size", SCSIDiskState, max_io_size, DEFAULT_MAX_IO_SIZE), + DEFINE_PROP_UINT16("rotation_rate", SCSIDiskState, rotation_rate, 0), DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_END_OF_LIST(), }; @@ -2982,6 +3001,7 @@ static const TypeInfo scsi_cd_info = { static Property scsi_block_properties[] = { DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \ DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.blk), + DEFINE_PROP_UINT16("rotation_rate", SCSIDiskState, rotation_rate, 0), DEFINE_PROP_END_OF_LIST(), }; From patchwork Wed Oct 18 16:11:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Iu0W6twm"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHLs5JGzz9t4c for ; Thu, 19 Oct 2017 03:19:17 +1100 (AEDT) Received: from localhost ([::1]:45473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r3r-0007yD-LM for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:19:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qxv-0003KH-R2 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxr-000207-Rw for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:07 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:54681) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxr-0001yw-Kr for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:03 -0400 Received: by mail-wm0-x243.google.com with SMTP id i124so11136520wmf.3 for ; Wed, 18 Oct 2017 09:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=4kL1Dliyp/0R32lNw7XM2KP90RVoK9P2+EsGgOEHBDs=; b=Iu0W6twmNpOPBtnHh+inPTrHSYC8aZ89u3mRCGSu/f1v7La4I9bldv9crfYZtsqKzA 499B5nW0YGjPvNVTl5YsfAQwW5IQ1yxT9D8xH1G8SG7wAozkhuHTWCwzZRuctAVGi1yu a2TgihnoHXZrJ2sSojw8pEiq0U/pVjPqV6IV0x9yn2okK+RiWeLK9etCW4ubJdgfQDmH jTJRN0jgrBn9kmiYXPP8FICG0wb4NtkcKXcrY0gXMLKkz6h2UwhqcqSAY9FbTUagwvVg W5Z3c9M6mnjnt6+ST9BIgjXrjXWFItbQZqa8DUk2lFPcbHWUMpfuDCj4z2UUB5AYIZWo chDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4kL1Dliyp/0R32lNw7XM2KP90RVoK9P2+EsGgOEHBDs=; b=Q2gR77NE0nNv5xWUvxwELzixr6EMA8EhZBznX2QSwtKG5A4PH9u10lhB3mE4ONXLdL PzoAv9ONEa14FVmLDOcfp0OJJ/C3zl1eyE+MJshgaxtFdSReyV0oXGkypgUakx3vBUK3 BWvjIfuMbvwh9qSkvWoPWEVH4TXW3eZ4YTNTGXbm9AcQmkQSOSnUsW9itreJAtxi4kZC T4DUlScGWCgVTQUlsVsklzZUFNTvTrHL4ghBQpkQvE3YerZ32SrWZhB2pzrrnLDNjxaY lJVW83zpov3UAAzEDm8p167If04Pxbkeh8UOpZzBRm+o3lF/AM6YtH4+Ay5ksZjX3DKV 1O0A== X-Gm-Message-State: AMCzsaUVD4bAT0aQ1Jtx/orsFhlKFPZstEgz5TTWNTDKLMKOHe+WsOWq tekuFgdyFtca2x/OHudF82HYn/ih X-Google-Smtp-Source: ABhQp+RRdbfpQEw/r4JEuZLo4COEOG96kHr0EME9oV84+0ktbB0p3xZLpzyRu8vGp3I2B9JsC5C2hg== X-Received: by 10.28.67.133 with SMTP id q127mr7372642wma.71.1508343182288; Wed, 18 Oct 2017 09:13:02 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:11:55 +0200 Message-Id: <1508343141-31835-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 03/29] ide: support reporting of rotation rate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Daniel P. Berrange" The Linux kernel will query the ATA IDENTITY DEVICE data, word 217 to determine the rotations per minute of the disk. If this has the value 1, it is taken to be an SSD and so Linux sets the 'rotational' flag to 0 for the I/O queue and will stop using that disk as a source of random entropy. Other operating systems may also take into account rotation rate when setting up default behaviour. Mgmt apps should be able to set the rotation rate for virtualized block devices, based on characteristics of the host storage in use, so that the guest OS gets sensible behaviour out of the box. This patch thus adds a 'rotation-rate' parameter for 'ide-hd' device types. Signed-off-by: Daniel P. Berrange Message-Id: <20171004114008.14849-3-berrange@redhat.com> Reviewed-by: John Snow Signed-off-by: Paolo Bonzini --- hw/ide/core.c | 1 + hw/ide/qdev.c | 1 + include/hw/ide/internal.h | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/hw/ide/core.c b/hw/ide/core.c index 5f1cd3b..a04766a 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -208,6 +208,7 @@ static void ide_identify(IDEState *s) if (dev && dev->conf.discard_granularity) { put_le16(p + 169, 1); /* TRIM support */ } + put_le16(p + 217, dev->rotation_rate); /* Nominal media rotation rate */ ide_identify_size(s); s->identify_set = 1; diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index d60ac25..a5181b4 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -299,6 +299,7 @@ static Property ide_hd_properties[] = { DEFINE_BLOCK_CHS_PROPERTIES(IDEDrive, dev.conf), DEFINE_PROP_BIOS_CHS_TRANS("bios-chs-trans", IDEDrive, dev.chs_trans, BIOS_ATA_TRANSLATION_AUTO), + DEFINE_PROP_UINT16("rotation_rate", IDEDrive, dev.rotation_rate, 0), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index e641012..31851b4 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -508,6 +508,14 @@ struct IDEDevice { char *serial; char *model; uint64_t wwn; + /* + * 0x0000 - rotation rate not reported + * 0x0001 - non-rotating medium (SSD) + * 0x0002-0x0400 - reserved + * 0x0401-0xffe - rotations per minute + * 0xffff - reserved + */ + uint16_t rotation_rate; }; /* These are used for the error_status field of IDEBus */ From patchwork Wed Oct 18 16:11:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827695 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iBBVN9rk"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHFK4jzQz9sBd for ; Thu, 19 Oct 2017 03:14:29 +1100 (AEDT) Received: from localhost ([::1]:45453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qzD-0003vk-Jl for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:14:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qxu-0003J0-72 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxt-00020o-2A for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:06 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:55350) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxs-00020J-Q3 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:04 -0400 Received: by mail-wr0-x242.google.com with SMTP id z99so3131120wrc.12 for ; Wed, 18 Oct 2017 09:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7x0fglactsA6+HYytnZwRnjgbOZeztFZFbaxicuuzJw=; b=iBBVN9rkUNle4zvIVZAsNhX1J5ojfGkw0H4EVyvbIGv3Op6lZu5OaeuBKx17pUQZMo aB2WeKNCB78vBBO55pSGRgQb5G9EVjxPMXGK6zaDwgO6rXbLrHMp3l15WW7wY/ykpvoq KbOTgXzkSxm9iGpzZ44VRkRYbWSt/4we3AE9AORpi21DCT8GKH/01YmsBiLypQKFyf10 TjjBcat6O9tPCXSjnzDzVXe2H+fXmLzu0mtHG/d5ZdfIw49PLH9AM82GeUEgZKb/gWar gClMILaBAoITnM+Pjl7MEDuyt1PGyYSizjYzPbWxzVs04ZqwWL6kWEGDXGAuODKRAGmW zuKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=7x0fglactsA6+HYytnZwRnjgbOZeztFZFbaxicuuzJw=; b=Bf4/bYJeNriK/bTaJWRNPt0Y/PK8A6OjZQIiCiHEjVWKrzCovMJFSIZr1ti6Mmv1fq dh4ezpuhGeYtxNRoPQ8x1Meq3l3bQAjJSCxkEC+0BHT72eCvNAi0kJemNWr80sumbIO+ 8ankeTPlsjq9WtnSUTYJksY+06rYfmAks9jgVgcqJy7/RVS1MPheBvHmLnzjpbPrnxQ+ qa+aJBylE6TcLJzGIOyrOMpQ+bRNZ87oSC3iIUx2r3TFOylWwwmZC4TFJBqF0Qh2O/gg fgcsETRY9KcQKGtacL4Vovg85gF58drMd+YRz194Ij/seXj9SJeXTTzPae7k1+0Dbz8y 3XAA== X-Gm-Message-State: AMCzsaVyz0gMQ4OSWmd4fo37QnVXgGBlTGCXbCTP8QTkhIODeqFlwGIG D8JDzcNPrqh6AECu0RqyOWkYQyTm X-Google-Smtp-Source: ABhQp+Q8eJEOxwkNh2B1H00l3f0329ImeRDP5RZ4rL12IKlvm4UdEwojLLcg756uTEOUC6SPk5OMVQ== X-Received: by 10.223.129.228 with SMTP id 91mr7627296wra.233.1508343183449; Wed, 18 Oct 2017 09:13:03 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:11:56 +0200 Message-Id: <1508343141-31835-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 04/29] char: don't skip client cleanup if 'connected' flag is unset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Daniel P. Berrange" The tcp_chr_free_connection & tcp_chr_disconnect methods both skip all of their cleanup work unless the 's->connected' flag is set. This flag is set when the incoming client connection is ready to use. Crucially this is *after* the TLS handshake has been completed. So if the TLS handshake fails and we try to cleanup the failed client, all the cleanup is skipped as 's->connected' is still false. The only important thing that should be skipped in this case is sending of the CHR_EVENT_CLOSED, because we never got as far as sending the corresponding CHR_EVENT_OPENED. Every other bit of cleanup can be robust against being called even when s->connected is false. Signed-off-by: Daniel P. Berrange Message-Id: <20171005155057.7664-1-berrange@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Marc-AndrĂ© Lureau Signed-off-by: Paolo Bonzini --- chardev/char-socket.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index e65148f..53eda8e 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -332,10 +332,6 @@ static void tcp_chr_free_connection(Chardev *chr) SocketChardev *s = SOCKET_CHARDEV(chr); int i; - if (!s->connected) { - return; - } - if (s->read_msgfds_num) { for (i = 0; i < s->read_msgfds_num; i++) { close(s->read_msgfds[i]); @@ -394,22 +390,25 @@ static void update_disconnected_filename(SocketChardev *s) s->is_listen, s->is_telnet); } +/* NB may be called even if tcp_chr_connect has not been + * reached, due to TLS or telnet initialization failure, + * so can *not* assume s->connected == true + */ static void tcp_chr_disconnect(Chardev *chr) { SocketChardev *s = SOCKET_CHARDEV(chr); - - if (!s->connected) { - return; - } + bool emit_close = s->connected; tcp_chr_free_connection(chr); - if (s->listen_ioc) { + if (s->listen_ioc && s->listen_tag == 0) { s->listen_tag = qio_channel_add_watch( QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, NULL); } update_disconnected_filename(s); - qemu_chr_be_event(chr, CHR_EVENT_CLOSED); + if (emit_close) { + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); + } if (s->reconnect_time) { qemu_chr_socket_restart_timer(chr); } From patchwork Wed Oct 18 16:11:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827699 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vdt+osUg"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHHg5Xpfz9sBd for ; Thu, 19 Oct 2017 03:16:31 +1100 (AEDT) Received: from localhost ([::1]:45465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r1B-0005iN-MF for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:16:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qxv-0003Jt-AH for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxu-00021J-5S for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:07 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:52862) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxt-00020v-Rr for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:06 -0400 Received: by mail-wm0-x241.google.com with SMTP id k4so11169200wmc.1 for ; Wed, 18 Oct 2017 09:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=G9iKOFk7lNPoWYFrZb8yBL8lmECMmE8w+4VZJbXfpO4=; b=vdt+osUgQfnZfos8y+OerWj3hKIcI0oTnhZ7i9w/kHJANuRGTq9rL8f0taZbFpPkts ujeNfHWodChm2gG6wegrZDnAZzOyJFP2xkz54BLFBKH3Wck0b+BAXg0/OaZ7GwG+F14Z jm2PuhLYyWWVG3roYWntFdw/hmeMQotz8Dhv5irxFTQHtIWa3NVHAWlqy/ZKmrpe1AJe j2LMCRVbWm5YcGojt+1SOooSO/rtiT8sX6w11ztJLe6z+0oBAU55/biD1ms4Ml0EEHLu JpkVGUJHGO2aU5h1aoDcbqF/5qXFwXD0PEBg6X/gAPW718dZ6vFImjr6PdCa1A6cJV9X k9zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=G9iKOFk7lNPoWYFrZb8yBL8lmECMmE8w+4VZJbXfpO4=; b=U2laPi9eXm07qiYT74qAmq3mQW3M4CWqm85NHzA+W0mW+dBkWd1leWJfm0wgZ/9oYQ amE/F7yy+a9Gvvnt9DSgeOkusuENWZOLFoXANd3gnvyR3lb5irCkSOScPdO0cl+vtNqh GviZHcAeJ2PNKQ0Pxv2dxRlvgej0aVUIU9QnYesf5BoR4F1A6RpSf+F/Cy6VWhjOzwFT zxuz9o5Y+NJ6Wwi83rUpB4FtWVll3/+26pY/qO9gz6k9BkKLtdL9Mz2HpsHQ2jwaF9GP bI0EgZV/UA+707vuZjr645mZUgvbvp+jjKGk6peFZmUhnCP3GnllJdvU+HovDsWhKOyu RMwA== X-Gm-Message-State: AMCzsaW5Xla2T9x0AHJsdbbwrk01TfRLXj5AIeAQUfKUfctPAenblX9v fy1zY4PADYgmFOE2N9/301tpqNtt X-Google-Smtp-Source: ABhQp+Shkl3RSuodYiSY+C1bXUVQwIqUTESqW6P3RtH7NFsuqnA7Z1JrUVKbwDckge5vdrVDE/etJQ== X-Received: by 10.28.41.70 with SMTP id p67mr7079636wmp.110.1508343184499; Wed, 18 Oct 2017 09:13:04 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:11:57 +0200 Message-Id: <1508343141-31835-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 05/29] exec: add page_mask for flatview_do_translate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Coquelin , Peter Xu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Xu The function is originally used for flatview_space_translate() and what we care about most is (xlat, plen) range. However for iotlb requests, we don't really care about "plen", but the size of the page that "xlat" is located on. While, plen cannot really contain this information. A simple example to show why "plen" is not good for IOTLB translations: E.g., for huge pages, it is possible that guest mapped 1G huge page on device side that used this GPA range: 0x100000000 - 0x13fffffff Then let's say we want to translate one IOVA that finally mapped to GPA 0x13ffffe00 (which is located on this 1G huge page). Then here we'll get: (xlat, plen) = (0x13fffe00, 0x200) So the IOTLB would be only covering a very small range since from "plen" (which is 0x200 bytes) we cannot tell the size of the page. Actually we can really know that this is a huge page - we just throw the information away in flatview_do_translate(). This patch introduced "page_mask" optional parameter to capture that page mask info. Also, I made "plen" an optional parameter as well, with some comments for the whole function. No functional change yet. Signed-off-by: Peter Xu Signed-off-by: Maxime Coquelin Message-Id: <20171010094247.10173-2-maxime.coquelin@redhat.com> Signed-off-by: Paolo Bonzini --- exec.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/exec.c b/exec.c index 6378714..ca520ac 100644 --- a/exec.c +++ b/exec.c @@ -465,11 +465,29 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x return section; } -/* Called from RCU critical section */ +/** + * flatview_do_translate - translate an address in FlatView + * + * @fv: the flat view that we want to translate on + * @addr: the address to be translated in above address space + * @xlat: the translated address offset within memory region. It + * cannot be @NULL. + * @plen_out: valid read/write length of the translated address. It + * can be @NULL when we don't care about it. + * @page_mask_out: page mask for the translated address. This + * should only be meaningful for IOMMU translated + * addresses, since there may be huge pages that this bit + * would tell. It can be @NULL if we don't care about it. + * @is_write: whether the translation operation is for write + * @is_mmio: whether this can be MMIO, set true if it can + * + * This function is called from RCU critical section + */ static MemoryRegionSection flatview_do_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, - hwaddr *plen, + hwaddr *plen_out, + hwaddr *page_mask_out, bool is_write, bool is_mmio, AddressSpace **target_as) @@ -478,11 +496,17 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv, MemoryRegionSection *section; IOMMUMemoryRegion *iommu_mr; IOMMUMemoryRegionClass *imrc; + hwaddr page_mask = (hwaddr)(-1); + hwaddr plen = (hwaddr)(-1); + + if (plen_out) { + plen = *plen_out; + } for (;;) { section = address_space_translate_internal( flatview_to_dispatch(fv), addr, &addr, - plen, is_mmio); + &plen, is_mmio); iommu_mr = memory_region_get_iommu(section->mr); if (!iommu_mr) { @@ -494,7 +518,8 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv, IOMMU_WO : IOMMU_RO); addr = ((iotlb.translated_addr & ~iotlb.addr_mask) | (addr & iotlb.addr_mask)); - *plen = MIN(*plen, (addr | iotlb.addr_mask) - addr + 1); + page_mask &= iotlb.addr_mask; + plen = MIN(plen, (addr | iotlb.addr_mask) - addr + 1); if (!(iotlb.perm & (1 << is_write))) { goto translate_fail; } @@ -505,6 +530,19 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv, *xlat = addr; + if (page_mask == (hwaddr)(-1)) { + /* Not behind an IOMMU, use default page size. */ + page_mask = ~TARGET_PAGE_MASK; + } + + if (page_mask_out) { + *page_mask_out = page_mask; + } + + if (plen_out) { + *plen_out = plen; + } + return *section; translate_fail: @@ -523,7 +561,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, /* This can never be MMIO. */ section = flatview_do_translate(address_space_to_flatview(as), addr, - &xlat, &plen, is_write, false, &as); + &xlat, &plen, NULL, is_write, false, &as); /* Illegal translation */ if (section.mr == &io_mem_unassigned) { @@ -567,7 +605,8 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, AddressSpace *as = NULL; /* This can be MMIO, so setup MMIO bit. */ - section = flatview_do_translate(fv, addr, xlat, plen, is_write, true, &as); + section = flatview_do_translate(fv, addr, xlat, plen, NULL, + is_write, true, &as); mr = section.mr; if (xen_enabled() && memory_access_is_direct(mr, is_write)) { From patchwork Wed Oct 18 16:11:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KoMQ4io/"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHHh3Rp0z9t4c for ; Thu, 19 Oct 2017 03:16:32 +1100 (AEDT) Received: from localhost ([::1]:45466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r1C-0005jZ-EN for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:16:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qxw-0003KR-1T for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxv-000223-1v for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:07 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:50703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxu-00021Q-S9 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:06 -0400 Received: by mail-wr0-x244.google.com with SMTP id q42so5603205wrb.7 for ; Wed, 18 Oct 2017 09:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=cUH7mb5z9knGjAMb+DdxjrvHoWTzFS+KeiGHVuRa9fU=; b=KoMQ4io/pPKODpghcUR3YSHyqRgofLGu5LRhau6qinANTRxRpzxANBOrt0vDZt//Fn LQtF76RudJk8AeEQYcsRqZbRMsgw5gr/QyuNS3TtQz1RlzLHXM5YiGigxuBvPT+Wu3Ym +uaL4X1J5Xhqn2VXkQnmItz54S6+m8d/VBf8IyWyO2CJv0T8orF1RxvZeEJMpc4W8+6r c5RZNCRPRwIJhsjzwflfMk/6ynbFj5o3BbuXtvNvENFMldDUL6DCNefMW7WNTb4Z6JeT kmisRK2S3cP6oW7WlWGktYq8xcijSwb50IdwSv+vsEnnHsgwhS7VLYD+GPscJb1dMuAw 5n0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=cUH7mb5z9knGjAMb+DdxjrvHoWTzFS+KeiGHVuRa9fU=; b=h+4bhs5nFFGpBDawpSgq5qktoJmAaVyXAN4PkbzB96DUIVrRxY0MMRjg8dUhZ+ZfO4 HXBzX0nR7pxa23VS6Q9sFZ+LQXPxrRWnoUIMjGSO/YGgMvFjNPsoNYYfEo/Sr8atzC+a 5D97QBh5IBg4hrdSsWFBd52wr/rmaELjt3vCchdIPeVA+KMPJEP1QM9BumjYBKXjWFia mUcPidi9z9zZHqLb08UZOIHqEYekPPxLGBWvAA+vnHCkX4g9EOS+bEqjE/sNnHIsGEkD 7yuYh5D6AoXDJyNUPM9ESRktV02t5aCh5xEGCbNJBopNlUTjmr8jCBR8I296s9VAmblh g8DA== X-Gm-Message-State: AMCzsaVmlzILHxqEinKycmkOF4AO0rIJDxOataZwZfzALBGyh/nE9ilj zQF+q3Zu8NVj+5tW7eFrs/LNtLS1 X-Google-Smtp-Source: ABhQp+SK2E655g1Sm5u2FvEKOIVn81ydVMjCI1m7RZXEfaHkMBPvNQxRtb7BQ3ugmm1EYBRHx4qUXw== X-Received: by 10.223.157.136 with SMTP id p8mr7739320wre.28.1508343185529; Wed, 18 Oct 2017 09:13:05 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:11:58 +0200 Message-Id: <1508343141-31835-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PULL 06/29] exec: simplify address_space_get_iotlb_entry X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Coquelin , Peter Xu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Xu This patch let address_space_get_iotlb_entry() to use the newly introduced page_mask parameter in flatview_do_translate(). Then we will be sure the IOTLB can be aligned to page mask, also we should nicely support huge pages now when introducing a764040. Fixes: a764040 ("exec: abstract address_space_do_translate()") Signed-off-by: Peter Xu Signed-off-by: Maxime Coquelin Acked-by: Michael S. Tsirkin Message-Id: <20171010094247.10173-3-maxime.coquelin@redhat.com> Signed-off-by: Paolo Bonzini --- exec.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/exec.c b/exec.c index ca520ac..6579e7a 100644 --- a/exec.c +++ b/exec.c @@ -554,14 +554,14 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, bool is_write) { MemoryRegionSection section; - hwaddr xlat, plen; + hwaddr xlat, page_mask; - /* Try to get maximum page mask during translation. */ - plen = (hwaddr)-1; - - /* This can never be MMIO. */ - section = flatview_do_translate(address_space_to_flatview(as), addr, - &xlat, &plen, NULL, is_write, false, &as); + /* + * This can never be MMIO, and we don't really care about plen, + * but page mask. + */ + section = flatview_do_translate(address_space_to_flatview(as), addr, &xlat, + NULL, &page_mask, is_write, false, &as); /* Illegal translation */ if (section.mr == &io_mem_unassigned) { @@ -572,22 +572,11 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, xlat += section.offset_within_address_space - section.offset_within_region; - if (plen == (hwaddr)-1) { - /* - * We use default page size here. Logically it only happens - * for identity mappings. - */ - plen = TARGET_PAGE_SIZE; - } - - /* Convert to address mask */ - plen -= 1; - return (IOMMUTLBEntry) { .target_as = as, - .iova = addr & ~plen, - .translated_addr = xlat & ~plen, - .addr_mask = plen, + .iova = addr & ~page_mask, + .translated_addr = xlat & ~page_mask, + .addr_mask = page_mask, /* IOTLBs are for DMAs, and DMA only allows on RAMs. */ .perm = IOMMU_RW, }; From patchwork Wed Oct 18 16:11:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827698 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WzaM8cc/"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHHY3Dgkz9sBd for ; Thu, 19 Oct 2017 03:16:23 +1100 (AEDT) Received: from localhost ([::1]:45464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r13-0005bS-8Q for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:16:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qxx-0003Lt-7y for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxw-000230-8g for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:09 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:48174) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxw-00022S-2b; Wed, 18 Oct 2017 12:13:08 -0400 Received: by mail-wr0-x241.google.com with SMTP id u5so5598328wrc.5; Wed, 18 Oct 2017 09:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=j6snm7Mxl/TR6V0B/Deyl2CRYI3S4gv9UCNboBmntqo=; b=WzaM8cc/V9HHnyQaYXbzoe2GSDwI9edGUweHrDZlQ6B9COE5KHjKh5/1R23kgqwo+d S/pGkfdjVbSnr6eZTW2F4c0n2J/8hBjoVa3d2Gaq81zSefftldGqS9mnO+C4CSMd3fQc 6v7lB+WPuSBKY/pkew0Eo6PoWY0++zH5joa0zXH5Pa7LwamTnMLPfKmRc2dNwQF9EUJj JLsG3Ux2BUGA71RvO08b1HCFAd717f9bV8X3jKTRJhuNioKfoX4J4UgM0ITQGS8PnbKM BEXZoKp0FF8NX3SBuJMn2fIjvGrmi6XpgIov5ypi1Ln4Jx5MviR8tZD0XgcUmp0nv+6S 4+9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=j6snm7Mxl/TR6V0B/Deyl2CRYI3S4gv9UCNboBmntqo=; b=rpPTMFnFkox4yYDgr9XAymmQe8VE3+FF2Nsoc7bHl5FjOOuM2teYSSTuJtKld18Nqc OEwuiNmv5Xoefg9LUQhpD5GnXxRjQe7sz7/v1Viw3VR2BYpsKHM8LDJ23QNLsUPsJB9k p7o6KeLVMQV0jCoxbRpQFqbM5M72nd59kuprr44wYyaZqzDziq9BWq0/mSlzR7LumsrT zwudwlIB7ObMCIcSiB9ciDdw2ihGtxn0mSkMkUdsTJMiDw+mR4Z3l3xX+xNCoobImfPB m8v8GTD9LIGhttxMY3+EmNQN2yZViIwn1VCYjG71rMlz5jb+SH0Bqvy1dvqyXFMZ5r53 AlVA== X-Gm-Message-State: AMCzsaWWALCuYIvlxmC8K1pWs4jsdyZyVCLY4DSvPPvZyOWGVlNowdtX cek0f8Q0mnNspsqXiq22thdwt4qu X-Google-Smtp-Source: ABhQp+S9zXjEYvcNs8jqrNo5lyvDt3emTVp46yVmIg2DE7bJyI7d4Uwkz/NeUuR9OLqWwBTuYA1Plw== X-Received: by 10.223.185.105 with SMTP id b38mr7438382wrg.262.1508343186621; Wed, 18 Oct 2017 09:13:06 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:11:59 +0200 Message-Id: <1508343141-31835-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PULL 07/29] memory: fix off-by-one error in memory_region_notify_one() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Coquelin , qemu-stable@nongnu.org, Peter Xu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Maxime Coquelin This patch fixes an off-by-one error that could lead to the notifyee to receive notifications for ranges it is not registered to. The bug has been spotted by code review. Fixes: bd2bfa4c52e5 ("memory: introduce memory_region_notify_one()") Cc: qemu-stable@nongnu.org Cc: Peter Xu Signed-off-by: Maxime Coquelin Message-Id: <20171010094247.10173-4-maxime.coquelin@redhat.com> Reviewed-by: Peter Xu Signed-off-by: Paolo Bonzini --- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 5e6351a..b637c12 100644 --- a/memory.c +++ b/memory.c @@ -1892,7 +1892,7 @@ void memory_region_notify_one(IOMMUNotifier *notifier, * Skip the notification if the notification does not overlap * with registered range. */ - if (notifier->start > entry->iova + entry->addr_mask + 1 || + if (notifier->start > entry->iova + entry->addr_mask || notifier->end < entry->iova) { return; } From patchwork Wed Oct 18 16:12:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827710 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="prMMJmug"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHM44qRfz9t4c for ; Thu, 19 Oct 2017 03:19:28 +1100 (AEDT) Received: from localhost ([::1]:45475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r42-00087L-4x for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:19:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy1-0003Qo-HD for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxx-00023t-KE for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:13 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:46874) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxx-00023A-Cc for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:09 -0400 Received: by mail-wr0-x243.google.com with SMTP id l1so5596207wrc.3 for ; Wed, 18 Oct 2017 09:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=lkv7uQTBkV1XHwf2c1XBGKpbagoDuXZqZU30akWlSOE=; b=prMMJmugFP84LmoV4+VVt3bhlddEbcL8IT7X9aJvdzAUM5NyrKFBAIe/g2oGrWLyKa s4iRfHYFhpUDeszyjfdX0c9jW4FQT2CUQpUg0Qm16y+f4Au8B3emjT9DdUcDL2FrIa/O 4DIBLlP3/h6r9BnnTVPHjB2jN9du9yU2tkQ/3YMlaRKXl/WmP8IyH5Mm4m8UV6jvX0ya WglFY9OFI8ch5+IPiYYM0gzg7a26I/DsKYjj2MV8NVe1L602S90sYrS84D1Ls/l4pdiD lZZadts9ohlgjtpR3f198paMPmL1QGyexeyPqWVkJ06NpbgxxagAOq1E282AZJYvw746 nI6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=lkv7uQTBkV1XHwf2c1XBGKpbagoDuXZqZU30akWlSOE=; b=sgX88EuMBIRAXgx2X0wC4Ir/Z0HsDEDnw6x/9eEXIjyOv8TufFGPuQb58qGeo0bcUF +jQ/MmGR9OAZt8V5+/3HFUm8nzEEfswwBxepQG38FtB3Odck2owZbgIdzT6nG39ri8Oh QAavH5ly1C71Z3++KqMR79TvyiE7+SsXbVpegJdi1pZmP6fUdb+Z2VE3IUHv81f9DOnj YYl7bOvYehLZlSCBlzXylyvNjLkGF1vra25kbdfu+5zvRdrJPHb+FayPLk50ofkJ9byz OaYzVg4SpCfksdPsc9YOCL4TVf1/ylG3VP78B45yx0+8yZ8qkf8dEJTg2UdNGJpEiSOT eS/A== X-Gm-Message-State: AMCzsaV8CLaBsBOHUxBdweOi8cZJwBLLwoDh+kQ5gXM/ceEieaIN0akz 0edovlbmdoSpMW/KUck3dNpESN6h X-Google-Smtp-Source: ABhQp+Q+g80tzbteyQTF6QqBIjd+tH+WWMlC6Q/HM2qXeuSz2ZUzJc7XAquAtgBCrk9d//GPaU27Jw== X-Received: by 10.223.198.82 with SMTP id u18mr7667403wrg.5.1508343187768; Wed, 18 Oct 2017 09:13:07 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:00 +0200 Message-Id: <1508343141-31835-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PULL 08/29] pc: make sure that plugged CPUs are of the same type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov heterogeneous cpus are not supported and hotplugging different cpu model crashes QEMU: qemu-system-x86_64 -cpu qemu64 -smp 1,maxcpus=2 (qemu) device_add host-x86_64-cpu,socket-id=1,core-id=0,thread-id=0,id=foo (qemu) info cpus error: failed to get MSR 0x38d qemu-system-x86_64: target/i386/kvm.c:2121: kvm_get_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed. Aborted (core dumped) Gracefully fail hotplug process in case of user mistake. Reported-by: Greg Kurz Signed-off-by: Igor Mammedov Message-Id: <1507638879-200718-1-git-send-email-imammedo@redhat.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 05985d4..8e307f7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1876,8 +1876,15 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, CPUArchId *cpu_slot; X86CPUTopoInfo topo; X86CPU *cpu = X86_CPU(dev); + MachineState *ms = MACHINE(hotplug_dev); PCMachineState *pcms = PC_MACHINE(hotplug_dev); + if(!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) { + error_setg(errp, "Invalid CPU type, expected cpu type: '%s'", + ms->cpu_type); + return; + } + /* if APIC ID is not set, set it based on socket/core/thread properties */ if (cpu->apic_id == UNASSIGNED_APIC_ID) { int max_socket = (max_cpus - 1) / smp_threads / smp_cores; From patchwork Wed Oct 18 16:12:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b0CWabay"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHMb4ckVz9sBd for ; Thu, 19 Oct 2017 03:19:55 +1100 (AEDT) Received: from localhost ([::1]:45476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r4T-0008Tk-KP for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:19:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy2-0003S7-Qf for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxy-00024Y-Ig for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:14 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:44641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxy-000242-Bu for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:10 -0400 Received: by mail-wr0-x243.google.com with SMTP id l24so5604078wre.1 for ; Wed, 18 Oct 2017 09:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aVZHDatyJyG91/k0eNy6Ne9RWl8gpRWIp31TTHlT2Qk=; b=b0CWabayNOrkrQc9cGmNpsbYMaNd2os7Bdlp7DUAzIl7HKKliUx2khpUdh8JZCFIpy K3FkWL1spdp+lntbaMSePLJgujQlSxbh3/sP04e9CxUGweN8zt4nwN2PgfAgpHiIG2Zz XUlPC8P77JzfS7Bpzc6o4DiED4MTgZhbzygnw7P/N5n6SuYw/ui26fY6M72y6vjk+tWH NwFFvrRAKf9lvpd+xncUR1IcBd9XyE9olib4udjByOPyKKL0AL90aaMYE6r3Ub6Lyay3 aAtTnea1KXsZlRnWWOwOB+8rOZKh/agr1FdhqVBquwmmbHvFpZWpyvWOiTX6f68/wLOz Wcdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aVZHDatyJyG91/k0eNy6Ne9RWl8gpRWIp31TTHlT2Qk=; b=M0luTSpj5PNxxtasftgbE0oIVqVr5qA0FaDSjJGFpvdv8PllBheBtlhCTmapF0BO6S 2c1RjF5WyTTl8hQNVLmKP1TdN+o2lo8kQ6dH5LCpygwWgIqZjxI4kbYVYr6H5Czm7Yxn yMwKRiDfmhHKCbMDhCsg9VlZ7yIsRmfDh4B6UkQrtAxSGOzfpXzjC4ZKBbo35BAdzND/ hX+jycs9wM6rsBHBVbtpBGkDaKLji+M0pi9Ixu9rtf7DsUw7A66BOUBw2xT/5AF7ZUYx sD4bvozYRJGn86kaFR8ZL9UzxBxVvwYJi8Z1YGXosXHEgdUmYReAtAh3EAGCKFCwVWKT SJ/Q== X-Gm-Message-State: AMCzsaV1swn0OnSWhJsLmXmiFxSkgTpdhW0DQ44cNxWOLcPqdnAzaoLZ Dzxy6C7c5xavFzEtigAzf4UitJE3 X-Google-Smtp-Source: ABhQp+RDSoOSxe0envzegBnEwQilCfCidi6Ec7O/hw5xq5CE10Q2ErfPabjn4IHjW5uyQHMShmpRzw== X-Received: by 10.223.184.204 with SMTP id c12mr7439801wrg.197.1508343188941; Wed, 18 Oct 2017 09:13:08 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:01 +0200 Message-Id: <1508343141-31835-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PULL 09/29] disas: Always initialize read_memory_inner_func properly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Thomas Huth I've recently seen this with valgrind while running the HMP tester: ==22373== Conditional jump or move depends on uninitialised value(s) ==22373== at 0x4A41FD: arm_disas_set_info (cpu.c:504) ==22373== by 0x3867A7: monitor_disas (disas.c:390) ==22373== by 0x38E80E: memory_dump (monitor.c:1339) ==22373== by 0x38FA43: handle_hmp_command (monitor.c:3123) ==22373== by 0x38FB9E: qmp_human_monitor_command (monitor.c:613) ==22373== by 0x4E3124: qmp_marshal_human_monitor_command (qmp-marshal.c:1736) ==22373== by 0x769678: do_qmp_dispatch (qmp-dispatch.c:104) ==22373== by 0x769678: qmp_dispatch (qmp-dispatch.c:131) ==22373== by 0x38B734: handle_qmp_command (monitor.c:3853) ==22373== by 0x76ED07: json_message_process_token (json-streamer.c:105) ==22373== by 0x78D40A: json_lexer_feed_char (json-lexer.c:323) ==22373== by 0x78D4CD: json_lexer_feed (json-lexer.c:373) ==22373== by 0x38A08D: monitor_qmp_read (monitor.c:3895) And indeed, in monitor_disas, the read_memory_inner_func variable was not initialized, but arm_disas_set_info() expects this to be NULL or a valid pointer. Let's properly set this to NULL in the INIT_DISASSEMBLE_INFO to fix it in all functions that use the disassemble_info struct. Fixes: f7478a92dd9ee2276bfaa5b7317140d3f9d6a53b ("Fix Thumb-1 BE32 execution") Signed-off-by: Thomas Huth Message-Id: <1506524313-20037-1-git-send-email-thuth@redhat.com> --- disas.c | 1 - include/disas/bfd.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/disas.c b/disas.c index d6a1eb9..54eea3f 100644 --- a/disas.c +++ b/disas.c @@ -190,7 +190,6 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code, s.cpu = cpu; s.info.read_memory_func = target_read_memory; - s.info.read_memory_inner_func = NULL; s.info.buffer_vma = code; s.info.buffer_length = size; s.info.print_address_func = generic_print_address; diff --git a/include/disas/bfd.h b/include/disas/bfd.h index b01e002..d99da68 100644 --- a/include/disas/bfd.h +++ b/include/disas/bfd.h @@ -479,6 +479,7 @@ int generic_symbol_at_address(bfd_vma, struct disassemble_info *); (INFO).buffer_vma = 0, \ (INFO).buffer_length = 0, \ (INFO).read_memory_func = buffer_read_memory, \ + (INFO).read_memory_inner_func = NULL, \ (INFO).memory_error_func = perror_memory, \ (INFO).print_address_func = generic_print_address, \ (INFO).print_insn = NULL, \ From patchwork Wed Oct 18 16:12:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827702 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QoXzPqHS"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHJM6Pb2z9t4c for ; Thu, 19 Oct 2017 03:17:07 +1100 (AEDT) Received: from localhost ([::1]:45467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r1l-0006Dz-Ps for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:17:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy1-0003Qk-Fj for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qxz-000256-SN for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:13 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:45110) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qxz-00024m-I8 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:11 -0400 Received: by mail-wr0-x244.google.com with SMTP id k7so5595489wre.2 for ; Wed, 18 Oct 2017 09:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=lT02MsR3lMkbJgyDiU2upC4PgyPaYUKxbmxkPY3p27I=; b=QoXzPqHSL9APTIIUdvlPCtb/OqjqfLsqEZ77KWmzpzypl2t3QhO5D9DoixewffQLY3 Fv68tnBUXxnxGyxxy2QXaXDYyXIvPf8H72Jc0ONKcLvCGxq3idy35f0+ORBEAXMNtGeo KzoWCDoKYriOhNnxEGRzXjQw+mSH0/kxHEaPvhFmhZB5xLV7wkZ23n45kwz3s4y7RrYd kt2YcF6llpsNqEQq18FTobxYRDeA0vBk5tju6Lz4pd6dE0k/kb5d1+YUT6mcaOujhQZB oY8zOnjstjGHcALT+qGfc6ePBwwkwNES1NenWTb9HQyP8uugkfXQGv6J5pY/2myXyMDr wdjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=lT02MsR3lMkbJgyDiU2upC4PgyPaYUKxbmxkPY3p27I=; b=hu41I5LSisMq3wFTSO4E+cxrMd8YDYUiBur9zu5D0hI7TF4c6GlDEsOIf83UqP9bug 4BfyRk4ElyXG6kWcm3sfY5/GgnYoug+ptEplo7XPPeUzeYWlkygjGqzgs38vERTM79A9 sa75QP4snxmlHIRr3RFBVgHPnZK+iV07QQ47XAA1yK3b4Gz1hFFgHADW1gJg+XpwBxs8 dRQtA4cXeQ83oW0A2NTH4JITN+FMfqFa39dLIoZBWQhrlH3FfTwSnviQ2sLU+iXAbMEI I4QO+J72bMxb/QiZBe8ezfEKlv16rPoE0cnYeUr1ZjbbGfwEN/LHn3IHaveRNnEk1sYo v3Jg== X-Gm-Message-State: AMCzsaVDl3bV5YE1wQntlbPBt71Xe3QRaFgEift1CZA5vZeFH/Lo047E bebnTIZV1YIks2xlARQDxRRvxmgm X-Google-Smtp-Source: ABhQp+TZy1ufNg1km8igCRCHDcaoZ27QI59If0uD82sXAchGeR/42j2+WMEBZf5stFp9fvec5pSCpg== X-Received: by 10.223.132.135 with SMTP id 7mr7663074wrg.74.1508343190159; Wed, 18 Oct 2017 09:13:10 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:02 +0200 Message-Id: <1508343141-31835-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PULL 10/29] build: remove CONFIG_LIBDECNUMBER X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It is used by all PPC targets; we can give the directory its own Makefile.objs file, and include it directly from target/ppc. target/s390 can do the same when it starts using it. Signed-off-by: Paolo Bonzini --- Makefile.target | 6 ------ default-configs/ppc-linux-user.mak | 1 - default-configs/ppc-softmmu.mak | 1 - default-configs/ppc64-linux-user.mak | 1 - default-configs/ppc64-softmmu.mak | 1 - default-configs/ppc64abi32-linux-user.mak | 1 - default-configs/ppc64le-linux-user.mak | 1 - default-configs/ppcemb-softmmu.mak | 1 - libdecnumber/Makefile.objs | 5 +++++ target/ppc/Makefile.objs | 1 + 10 files changed, 6 insertions(+), 13 deletions(-) create mode 100644 libdecnumber/Makefile.objs diff --git a/Makefile.target b/Makefile.target index a4b292d..e4244c1 100644 --- a/Makefile.target +++ b/Makefile.target @@ -102,12 +102,6 @@ obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o -obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/decContext.o -obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/decNumber.o -obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/dpd/decimal32.o -obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/dpd/decimal64.o -obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/dpd/decimal128.o - ######################################################### # Linux user emulator target diff --git a/default-configs/ppc-linux-user.mak b/default-configs/ppc-linux-user.mak index 260ba41..6273df2 100644 --- a/default-configs/ppc-linux-user.mak +++ b/default-configs/ppc-linux-user.mak @@ -1,2 +1 @@ # Default configuration for ppc-linux-user -CONFIG_LIBDECNUMBER=y diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak index d7a3755..bb225c6 100644 --- a/default-configs/ppc-softmmu.mak +++ b/default-configs/ppc-softmmu.mak @@ -46,7 +46,6 @@ CONFIG_E500=y CONFIG_OPENPIC_KVM=$(call land,$(CONFIG_E500),$(CONFIG_KVM)) CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y -CONFIG_LIBDECNUMBER=y CONFIG_SM501=y # For PReP CONFIG_SERIAL_ISA=y diff --git a/default-configs/ppc64-linux-user.mak b/default-configs/ppc64-linux-user.mak index e731ce0..422d3fb 100644 --- a/default-configs/ppc64-linux-user.mak +++ b/default-configs/ppc64-linux-user.mak @@ -1,2 +1 @@ # Default configuration for ppc64-linux-user -CONFIG_LIBDECNUMBER=y diff --git a/default-configs/ppc64-softmmu.mak b/default-configs/ppc64-softmmu.mak index 9086475..d1b3a6d 100644 --- a/default-configs/ppc64-softmmu.mak +++ b/default-configs/ppc64-softmmu.mak @@ -51,7 +51,6 @@ CONFIG_E500=y CONFIG_OPENPIC_KVM=$(call land,$(CONFIG_E500),$(CONFIG_KVM)) CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y -CONFIG_LIBDECNUMBER=y CONFIG_SM501=y # For pSeries CONFIG_XICS=$(CONFIG_PSERIES) diff --git a/default-configs/ppc64abi32-linux-user.mak b/default-configs/ppc64abi32-linux-user.mak index c244d07..1c657ec 100644 --- a/default-configs/ppc64abi32-linux-user.mak +++ b/default-configs/ppc64abi32-linux-user.mak @@ -1,2 +1 @@ # Default configuration for ppc64abi32-linux-user -CONFIG_LIBDECNUMBER=y diff --git a/default-configs/ppc64le-linux-user.mak b/default-configs/ppc64le-linux-user.mak index 4ba4eae..63f4269 100644 --- a/default-configs/ppc64le-linux-user.mak +++ b/default-configs/ppc64le-linux-user.mak @@ -1,2 +1 @@ # Default configuration for ppc64le-linux-user -CONFIG_LIBDECNUMBER=y diff --git a/default-configs/ppcemb-softmmu.mak b/default-configs/ppcemb-softmmu.mak index 635923a..13917fb 100644 --- a/default-configs/ppcemb-softmmu.mak +++ b/default-configs/ppcemb-softmmu.mak @@ -15,5 +15,4 @@ CONFIG_PTIMER=y CONFIG_I8259=y CONFIG_XILINX=y CONFIG_XILINX_ETHLITE=y -CONFIG_LIBDECNUMBER=y CONFIG_SM501=y diff --git a/libdecnumber/Makefile.objs b/libdecnumber/Makefile.objs new file mode 100644 index 0000000..d81db04 --- /dev/null +++ b/libdecnumber/Makefile.objs @@ -0,0 +1,5 @@ +obj-y += decContext.o +obj-y += decNumber.o +obj-y += dpd/decimal32.o +obj-y += dpd/decimal64.o +obj-y += dpd/decimal128.o diff --git a/target/ppc/Makefile.objs b/target/ppc/Makefile.objs index f92ba67..e8fa18c 100644 --- a/target/ppc/Makefile.objs +++ b/target/ppc/Makefile.objs @@ -15,5 +15,6 @@ obj-y += int_helper.o obj-y += timebase_helper.o obj-y += misc_helper.o obj-y += mem_helper.o +obj-y += ../../libdecnumber/ obj-$(CONFIG_USER_ONLY) += user_only_helper.o obj-y += gdbstub.o From patchwork Wed Oct 18 16:12:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RUlpu27a"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHQG5X3Pz9t3R for ; Thu, 19 Oct 2017 03:22:12 +1100 (AEDT) Received: from localhost ([::1]:45487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r6e-0001q1-4Q for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:22:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy5-0003Up-1a for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy0-00025n-V4 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:17 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:45707) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy0-00025H-Oj; Wed, 18 Oct 2017 12:13:12 -0400 Received: by mail-wm0-x244.google.com with SMTP id q124so10973294wmb.0; Wed, 18 Oct 2017 09:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=v8+T0oUggxeVpxIEYFSesKXuNP4adeLsRtsAco2h01E=; b=RUlpu27aCCKB8I8+r36WTzKV5NmOIFx6Iz5VzxjC+76O3LRMSZ80+IXyuEChFSGpfI +e8fiXEuiE+yxfBVgJZfVanQDsJI9hU10q9FP/vqHUwSvxe9JHRWLz3ZNKpyenB2g5tf x/ozVIkZ+H8Ui9PWjqBlv7bW+L7BQPRDJeza7eQDptJY1Tqq7QzhzElKxPZWn8pM8m9X ZdpHZLeBHCJM0GoIAbULd+M0hAu+nJ/bBAcFVshYtg2k7vHLFCPJGfTU7zaiREdsaaui O40ddIZp23fdMjkNU7z2Iz3QxuzCbyv/NQaXPH/mQHeni/72rnu3g7oJjHcATBHIX+Ig 3kWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=v8+T0oUggxeVpxIEYFSesKXuNP4adeLsRtsAco2h01E=; b=rKtVQZdf4lDDtm8K6s19R1nBEob2oL8Cxbyy03e0xxw90/hMrR7n4ItJaBwUcPFou0 JEt5E03k8ipwba9DxMzlNU0QCyCaVIUFMlDv9DJ2Ka2EoVeNcekEJtlTDsIql6gUyopc P+Nf+bvPHhU7UXvZsE5RFsrHBF4QByAjRIwMh8dIcvdyGj3+NRyE5psdRrt5Na6iztD7 VzMu+sNm6AghcvwrafWEkcK08fI9AsIbiO7zJNsjRXqPfpWKZXjgJZ9YX8LV3cggc/vA ETjxvYLo4bfx+4oH4yCVuKdo7BJSzGNPBHsQBRhK8zveL5Sz9PlVcwmCgLMo646G2PYV cPLw== X-Gm-Message-State: AMCzsaXjrM9sfcfTZUdl1XKoWZPX0RjMRp+cn0q+kPNJyVDv7By0VqX3 yOhQ2yLHZTfhNGxgyQyyElLMPaJG X-Google-Smtp-Source: ABhQp+Tn7aCWLkkw9vqh2V9GNguCX2uGcV4KM/kOq1txbsGyiglMep9CHIjxfpzh5NdFYg7nf5goJw== X-Received: by 10.28.230.216 with SMTP id e85mr7775381wmi.86.1508343191503; Wed, 18 Oct 2017 09:13:11 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:03 +0200 Message-Id: <1508343141-31835-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 11/29] nios2: define tcg_env X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This should be done by all target and, since commit 53f6672bcf ("gen-icount: use tcg_ctx.tcg_env instead of cpu_env", 2017-06-30), is causing the NIOS2 target to hang. This is because the test for "should I exit to the main loop" was being done with the correct offset to the icount decrementer, but using TCG temporary 0 (the frame pointer) rather than the env pointer. Cc: qemu-stable@nongnu.org Cc: Marek Vasut Reported-by: Thomas Huth Signed-off-by: Paolo Bonzini --- target/nios2/translate.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 6b09618..54fbe89 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -948,6 +948,7 @@ void nios2_tcg_init(void) int i; cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); + tcg_ctx.tcg_env = cpu_env; for (i = 0; i < NUM_CORE_REGS; i++) { cpu_R[i] = tcg_global_mem_new(cpu_env, From patchwork Wed Oct 18 16:12:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DKkPjtbY"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHQQ3H51z9sBd for ; Thu, 19 Oct 2017 03:22:22 +1100 (AEDT) Received: from localhost ([::1]:45489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r6q-0001xK-GO for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:22:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy4-0003Ug-UT for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy2-00027P-M5 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:16 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:47834) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy2-00026l-AS for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:14 -0400 Received: by mail-wm0-x241.google.com with SMTP id t69so10985818wmt.2 for ; Wed, 18 Oct 2017 09:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0CLq1UGtPC1wXTZjTtDBDAfQxq/8zfzEquXbzkGu7uI=; b=DKkPjtbYoMbRGzCScVKc7FotpX8G9U7unr8gTfWCroUOt9KK4rjX80otgshAooykpl f0RUp6+NhhMxlLk2Sq15vVliknEJaJ04xWKv9mY6mIQN/23v1uy/T5nYLUSwq88pISGx kJp0bedNgeUSX/wQCKjX8kA9F+p02v2/c7iQkUB3ku0z6uZtlpVkcMvX061WdZvTfi81 8fmNG6XnCOVczAsTj8AkWH4R0Rl7mLdlZD9tXp3KUrqZTwWBazjKvA0EoxIwVtPx5GP4 OMl2d/RAuYWRwpc+FJK+vY/l29mVf6Dq6xq0FEbwIyieLXhffQzJBma+lN9EG5Ai/CTW WKwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=0CLq1UGtPC1wXTZjTtDBDAfQxq/8zfzEquXbzkGu7uI=; b=fYyia0f1sbnv4dtVPuIlJDTyHPz/qVqtcamKw11JzO3Oye3HMfnQjXvVOLO9mQFQvy RM5hkz4mMh4+JT3/yhuq6HwfPgOJA3O63Qb9KkEUzpzVvViysz/dO4CXA+lCKYQDm+4k VIyTxVELCtBK2jLCWC6O0obQ23OPByYxYPgpRMCkKs8lZU3FEln+rDQ4ZOFCoSqm9myv m4tnqUFCgZ7B6IDwn1KMVAGr8j/vD6ptuqFrrfAEvudsFXEXghSR+cD7qS+zzg7tszI/ 8Ga/sfKCG0TkMP5I4i1+JPhhOqyYu/gxGvHQu5McPqjTNpolYtJt9fG8PFs6Sz3ok4qK pcUg== X-Gm-Message-State: AMCzsaWgeCqV0tRoeuzzSbCqiyX3XreAQyLmBZDnIBxa/qyCLjVzMCZ8 Qp81ZRbSGjqXNJ7HRtc4puXWyFmB X-Google-Smtp-Source: ABhQp+QaMGjvImkG3ojSywNKaQc8AfcWcT5i41y4J0gUWnQgo4J4qdJ209bYIl8MmPiIJidaGkA6iw== X-Received: by 10.28.4.150 with SMTP id 144mr6994538wme.79.1508343192711; Wed, 18 Oct 2017 09:13:12 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:04 +0200 Message-Id: <1508343141-31835-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 12/29] docs/devel/loads-stores.rst: Document our various load and store APIs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell QEMU has a wide selection of different functions for doing loads and stores; provide some overview documentation of what they do and how to pick which one to use. Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Message-Id: <1507813181-11860-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- docs/devel/loads-stores.rst | 396 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 396 insertions(+) create mode 100644 docs/devel/loads-stores.rst diff --git a/docs/devel/loads-stores.rst b/docs/devel/loads-stores.rst new file mode 100644 index 0000000..6a990cc --- /dev/null +++ b/docs/devel/loads-stores.rst @@ -0,0 +1,396 @@ +.. + Copyright (c) 2017 Linaro Limited + Written by Peter Maydell + +=================== +Load and Store APIs +=================== + +QEMU internally has multiple families of functions for performing +loads and stores. This document attempts to enumerate them all +and indicate when to use them. It does not provide detailed +documentation of each API -- for that you should look at the +documentation comments in the relevant header files. + + +``ld*_p and st*_p`` +~~~~~~~~~~~~~~~~~~~ + +These functions operate on a host pointer, and should be used +when you already have a pointer into host memory (corresponding +to guest ram or a local buffer). They deal with doing accesses +with the desired endianness and with correctly handling +potentially unaligned pointer values. + +Function names follow the pattern: + +load: ``ld{type}{sign}{size}_{endian}_p(ptr)`` + +store: ``st{type}{size}_{endian}_p(ptr, val)`` + +``type`` + - (empty) : integer access + - ``f`` : float access + +``sign`` + - (empty) : for 32 or 64 bit sizes (including floats and doubles) + - ``u`` : unsigned + - ``s`` : signed + +``size`` + - ``b`` : 8 bits + - ``w`` : 16 bits + - ``l`` : 32 bits + - ``q`` : 64 bits + +``endian`` + - ``he`` : host endian + - ``be`` : big endian + - ``le`` : little endian + +The ``_{endian}`` infix is omitted for target-endian accesses. + +The target endian accessors are only available to source +files which are built per-target. + +Regexes for git grep + - ``\`` + - ``\`` + +``cpu_{ld,st}_*`` +~~~~~~~~~~~~~~~~~ + +These functions operate on a guest virtual address. Be aware +that these functions may cause a guest CPU exception to be +taken (e.g. for an alignment fault or MMU fault) which will +result in guest CPU state being updated and control longjumping +out of the function call. They should therefore only be used +in code that is implementing emulation of the target CPU. + +These functions may throw an exception (longjmp() back out +to the top level TCG loop). This means they must only be used +from helper functions where the translator has saved all +necessary CPU state before generating the helper function call. +It's usually better to use the ``_ra`` variants described below +from helper functions, but these functions are the right choice +for calls made from hooks like the CPU do_interrupt hook or +when you know for certain that the translator had to save all +the CPU state that ``cpu_restore_state()`` would restore anyway. + +Function names follow the pattern: + +load: ``cpu_ld{sign}{size}_{mmusuffix}(env, ptr)`` + +store: ``cpu_st{size}_{mmusuffix}(env, ptr, val)`` + +``sign`` + - (empty) : for 32 or 64 bit sizes + - ``u`` : unsigned + - ``s`` : signed + +``size`` + - ``b`` : 8 bits + - ``w`` : 16 bits + - ``l`` : 32 bits + - ``q`` : 64 bits + +``mmusuffix`` is one of the generic suffixes ``data`` or ``code``, or +(for softmmu configs) a target-specific MMU mode suffix as defined +in the target's ``cpu.h``. + +Regexes for git grep + - ``\`` + - ``\`` + +``cpu_{ld,st}_*_ra`` +~~~~~~~~~~~~~~~~~~~~ + +These functions work like the ``cpu_{ld,st}_*`` functions except +that they also take a ``retaddr`` argument. This extra argument +allows for correct unwinding of any exception that is taken, +and should generally be the result of GETPC() called directly +from the top level HELPER(foo) function (i.e. the return address +in the generated code). + +These are generally the preferred way to do accesses by guest +virtual address from helper functions; see the documentation +of the non-``_ra`` variants for when those would be better. + +Calling these functions with a ``retaddr`` argument of 0 is +equivalent to calling the non-``_ra`` version of the function. + +Function names follow the pattern: + +load: ``cpu_ld{sign}{size}_{mmusuffix}_ra(env, ptr, retaddr)`` + +store: ``cpu_st{sign}{size}_{mmusuffix}_ra(env, ptr, val, retaddr)`` + +Regexes for git grep + - ``\`` + - ``\`` + +``helper_*_{ld,st}*mmu`` +~~~~~~~~~~~~~~~~~~~~~~~~ + +These functions are intended primarily to be called by the code +generated by the TCG backend. They may also be called by target +CPU helper function code. Like the ``cpu_{ld,st}_*_ra`` functions +they perform accesses by guest virtual address; the difference is +that these functions allow you to specify an ``opindex`` parameter +which encodes (among other things) the mmu index to use for the +access. This is necessary if your helper needs to make an access +via a specific mmu index (for instance, an "always as non-privileged" +access) rather than using the default mmu index for the current state +of the guest CPU. + +The ``opindex`` parameter should be created by calling ``make_memop_idx()``. + +The ``retaddr`` parameter should be the result of GETPC() called directly +from the top level HELPER(foo) function (or 0 if no guest CPU state +unwinding is required). + +**TODO** The names of these functions are a bit odd for historical +reasons because they were originally expected to be called only from +within generated code. We should rename them to bring them +more in line with the other memory access functions. + +load: ``helper_{endian}_ld{sign}{size}_mmu(env, addr, opindex, retaddr)`` + +load (code): ``helper_{endian}_ld{sign}{size}_cmmu(env, addr, opindex, retaddr)`` + +store: ``helper_{endian}_st{size}_mmu(env, addr, val, opindex, retaddr)`` + +``sign`` + - (empty) : for 32 or 64 bit sizes + - ``u`` : unsigned + - ``s`` : signed + +``size`` + - ``b`` : 8 bits + - ``w`` : 16 bits + - ``l`` : 32 bits + - ``q`` : 64 bits + +``endian`` + - ``le`` : little endian + - ``be`` : big endian + - ``ret`` : target endianness + +Regexes for git grep + - ``\`` + - ``\`` + +``address_space_*`` +~~~~~~~~~~~~~~~~~~~ + +These functions are the primary ones to use when emulating CPU +or device memory accesses. They take an AddressSpace, which is the +way QEMU defines the view of memory that a device or CPU has. +(They generally correspond to being the "master" end of a hardware bus +or bus fabric.) + +Each CPU has an AddressSpace. Some kinds of CPU have more than +one AddressSpace (for instance ARM guest CPUs have an AddressSpace +for the Secure world and one for NonSecure if they implement TrustZone). +Devices which can do DMA-type operations should generally have an +AddressSpace. There is also a "system address space" which typically +has all the devices and memory that all CPUs can see. (Some older +device models use the "system address space" rather than properly +modelling that they have an AddressSpace of their own.) + +Functions are provided for doing byte-buffer reads and writes, +and also for doing one-data-item loads and stores. + +In all cases the caller provides a MemTxAttrs to specify bus +transaction attributes, and can check whether the memory transaction +succeeded using a MemTxResult return code. + +``address_space_read(address_space, addr, attrs, buf, len)`` + +``address_space_write(address_space, addr, attrs, buf, len)`` + +``address_space_rw(address_space, addr, attrs, buf, len, is_write)`` + +``address_space_ld{sign}{size}_{endian}(address_space, addr, attrs, txresult)`` + +``address_space_st{size}_{endian}(address_space, addr, val, attrs, txresult)`` + +``sign`` + - (empty) : for 32 or 64 bit sizes + - ``u`` : unsigned + +(No signed load operations are provided.) + +``size`` + - ``b`` : 8 bits + - ``w`` : 16 bits + - ``l`` : 32 bits + - ``q`` : 64 bits + +``endian`` + - ``le`` : little endian + - ``be`` : big endian + +The ``_{endian}`` suffix is omitted for byte accesses. + +Regexes for git grep + - ``\`` + - ``\`` + - ``\`` + +``{ld,st}*_phys`` +~~~~~~~~~~~~~~~~~ + +These are functions which are identical to +``address_space_{ld,st}*``, except that they always pass +``MEMTXATTRS_UNSPECIFIED`` for the transaction attributes, and ignore +whether the transaction succeeded or failed. + +The fact that they ignore whether the transaction succeeded means +they should not be used in new code, unless you know for certain +that your code will only be used in a context where the CPU or +device doing the access has no way to report such an error. + +``load: ld{sign}{size}_{endian}_phys`` + +``store: st{size}_{endian}_phys`` + +``sign`` + - (empty) : for 32 or 64 bit sizes + - ``u`` : unsigned + +(No signed load operations are provided.) + +``size`` + - ``b`` : 8 bits + - ``w`` : 16 bits + - ``l`` : 32 bits + - ``q`` : 64 bits + +``endian`` + - ``le`` : little endian + - ``be`` : big endian + +The ``_{endian}_`` infix is omitted for byte accesses. + +Regexes for git grep + - ``\`` + - ``\`` + +``cpu_physical_memory_*`` +~~~~~~~~~~~~~~~~~~~~~~~~~ + +These are convenience functions which are identical to +``address_space_*`` but operate specifically on the system address space, +always pass a ``MEMTXATTRS_UNSPECIFIED`` set of memory attributes and +ignore whether the memory transaction succeeded or failed. +For new code they are better avoided: + +* there is likely to be behaviour you need to model correctly for a + failed read or write operation +* a device should usually perform operations on its own AddressSpace + rather than using the system address space + +``cpu_physical_memory_read`` + +``cpu_physical_memory_write`` + +``cpu_physical_memory_rw`` + +Regexes for git grep + - ``\`` + +``cpu_physical_memory_write_rom`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This function performs a write by physical address like +``address_space_write``, except that if the write is to a ROM then +the ROM contents will be modified, even though a write by the guest +CPU to the ROM would be ignored. + +Note that unlike ``cpu_physical_memory_write()`` this function takes +an AddressSpace argument, but unlike ``address_space_write()`` this +function does not take a ``MemTxAttrs`` or return a ``MemTxResult``. + +**TODO**: we should probably clean up this inconsistency and +turn the function into ``address_space_write_rom`` with an API +matching ``address_space_write``. + +``cpu_physical_memory_write_rom`` + + +``cpu_memory_rw_debug`` +~~~~~~~~~~~~~~~~~~~~~~~ + +Access CPU memory by virtual address for debug purposes. + +This function is intended for use by the GDB stub and similar code. +It takes a virtual address, converts it to a physical address via +an MMU lookup using the current settings of the specified CPU, +and then performs the access (using ``address_space_rw`` for +reads or ``cpu_physical_memory_write_rom`` for writes). +This means that if the access is a write to a ROM then this +function will modify the contents (whereas a normal guest CPU access +would ignore the write attempt). + +``cpu_memory_rw_debug`` + +``dma_memory_*`` +~~~~~~~~~~~~~~~~ + +These behave like ``address_space_*``, except that they perform a DMA +barrier operation first. + +**TODO**: We should provide guidance on when you need the DMA +barrier operation and when it's OK to use ``address_space_*``, and +make sure our existing code is doing things correctly. + +``dma_memory_read`` + +``dma_memory_write`` + +``dma_memory_rw`` + +Regexes for git grep + - ``\`` + +``pci_dma_*`` and ``{ld,st}*_pci_dma`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +These functions are specifically for PCI device models which need to +perform accesses where the PCI device is a bus master. You pass them a +``PCIDevice *`` and they will do ``dma_memory_*`` operations on the +correct address space for that device. + +``pci_dma_read`` + +``pci_dma_write`` + +``pci_dma_rw`` + +``load: ld{sign}{size}_{endian}_pci_dma`` + +``store: st{size}_{endian}_pci_dma`` + +``sign`` + - (empty) : for 32 or 64 bit sizes + - ``u`` : unsigned + +(No signed load operations are provided.) + +``size`` + - ``b`` : 8 bits + - ``w`` : 16 bits + - ``l`` : 32 bits + - ``q`` : 64 bits + +``endian`` + - ``le`` : little endian + - ``be`` : big endian + +The ``_{endian}_`` infix is omitted for byte accesses. + +Regexes for git grep + - ``\`` + - ``\`` + - ``\`` From patchwork Wed Oct 18 16:12:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tCtzlL8N"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHQw1n33z9t4c for ; Thu, 19 Oct 2017 03:22:48 +1100 (AEDT) Received: from localhost ([::1]:45490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r7G-0002Oy-5o for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:22:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy4-0003Ua-RZ for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy3-00028h-Rq for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:16 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:51625) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy3-00027f-L8 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:15 -0400 Received: by mail-wm0-x243.google.com with SMTP id f4so11175278wme.0 for ; Wed, 18 Oct 2017 09:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=aDylqhh1pKmDqhtyi0SH/LUML93N/S50BLNZnQWS5CY=; b=tCtzlL8NsRmdWS4c2xu7Y1totoxwwt9lbf30qt/0qbLYtt8bts5cn48LJxLet36Ek3 q5FnPEWqHOp2/yyflRyOfwgwi0tGLPSpcyWXbrZBT5SbZHD3PrdrphE+xeDNbqP1dgam XYW/lDzxVicbdbKufXlPdzJyX2+mMDKE5i190e3xvZnptU6WPevdEdDBP2yJJkJ8a8AZ AyyVvw6JulisCRRSOwSHTNRBwhcm0VMqSNBfdDH3dyk9xpumls2oslMVXFYb9S6AXvOS WTbNKeJiaTH0amThTe+2re2LT9DgrBPrgxkwe1nwKMTinMgXWgOi7lFh/U/yLkqD0cIF YgSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=aDylqhh1pKmDqhtyi0SH/LUML93N/S50BLNZnQWS5CY=; b=eN3vaSOWtiyG+0aGUPa4e45zfCMiq15Lg8gr5t/jswwSLXBBtl0c9A7yjB1kgGJIHM gtPssWH0K9+of4Nm9iyiRa7nV9hOk4iC6GkpMFQtaChG52sruvomWpAMwCjGhysq5u5D PAbizcAQUrV0qjHNMfMN1/rWDAodqXds04angMSTfgNWvYh6PGVzTm4b5fajbh4ORMGw zYP04Wzx4fuqutpmE0Bz/CskFYqLFSTipyo+bmr2L/N/oVC2o0Wwyf8zZdYN28lmIl4x 24qziB7M02T5yppmdMlmnZDmsOnHken4k4EOYDQ92TYz01ObzGRWFbHusi4NT4khZ43L skhQ== X-Gm-Message-State: AMCzsaVZFVQpxUhHwGOXHSoo5iG+hSHUALQhimrmuSdQrQyWuxSdGApk aQOuiadqPX38q6bhJkpEAmZ8mfpG X-Google-Smtp-Source: ABhQp+THrN9nqiERrOZnx02hZ81Kol4h8kNAFqk/CtksM54akQqfm5Q5T+LMASlQINVDRO0lq32X9g== X-Received: by 10.28.149.204 with SMTP id x195mr7037065wmd.78.1508343194375; Wed, 18 Oct 2017 09:13:14 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:05 +0200 Message-Id: <1508343141-31835-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 13/29] tco: add trace events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add trace events to the PCH watchdog timer, it can be useful to see how the guest is using it. Signed-off-by: Paolo Bonzini Message-Id: <1507816448-86665-1-git-send-email-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- hw/acpi/tco.c | 11 +++++++++-- hw/acpi/trace-events | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/acpi/tco.c b/hw/acpi/tco.c index 05b9d7b..a914396 100644 --- a/hw/acpi/tco.c +++ b/hw/acpi/tco.c @@ -12,6 +12,7 @@ #include "hw/i386/ich9.h" #include "hw/acpi/tco.h" +#include "trace.h" //#define DEBUG @@ -41,8 +42,11 @@ enum { static inline void tco_timer_reload(TCOIORegs *tr) { - tr->expire_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + - ((int64_t)(tr->tco.tmr & TCO_TMR_MASK) * TCO_TICK_NSEC); + int ticks = tr->tco.tmr & TCO_TMR_MASK; + int64_t nsec = (int64_t)ticks * TCO_TICK_NSEC; + + trace_tco_timer_reload(ticks, nsec / 1000000); + tr->expire_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + nsec; timer_mod(tr->tco_timer, tr->expire_time); } @@ -59,6 +63,9 @@ static void tco_timer_expired(void *opaque) ICH9LPCState *lpc = container_of(pm, ICH9LPCState, pm); uint32_t gcs = pci_get_long(lpc->chip_config + ICH9_CC_GCS); + trace_tco_timer_expired(tr->timeouts_no, + lpc->pin_strap.spkr_hi, + !!(gcs & ICH9_CC_GCS_NO_REBOOT)); tr->tco.rld = 0; tr->tco.sts1 |= TCO_TIMEOUT; if (++tr->timeouts_no == 2) { diff --git a/hw/acpi/trace-events b/hw/acpi/trace-events index e3b41e9..df0024f 100644 --- a/hw/acpi/trace-events +++ b/hw/acpi/trace-events @@ -30,3 +30,7 @@ cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_write_ost_ev(uint32_t slot, uint32_t ev) "idx[0x%"PRIx32"] OST EVENT: 0x%"PRIx32 cpuhp_acpi_write_ost_status(uint32_t slot, uint32_t st) "idx[0x%"PRIx32"] OST STATUS: 0x%"PRIx32 + +# hw/acpi/tco.c +tco_timer_reload(int ticks, int msec) "ticks=%d (%d ms)" +tco_timer_expired(int timeouts_no, bool strap, bool no_reboot) "timeouts_no=%d no_reboot=%d/%d" From patchwork Wed Oct 18 16:12:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kLIrO96N"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHTl1nzhz9sBd for ; Thu, 19 Oct 2017 03:25:15 +1100 (AEDT) Received: from localhost ([::1]:45499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r9d-0004K8-8h for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:25:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy9-0003Zi-O6 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy6-0002BG-Hg for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:21 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:44681) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy6-0002AO-49 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:18 -0400 Received: by mail-wm0-x234.google.com with SMTP id 196so13113047wma.1 for ; Wed, 18 Oct 2017 09:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=DWzuCtMSa/2ZgCIoIpooxeBL6LUrH/EyK+ormLsAxX4=; b=kLIrO96Ndq2wxtLLPoc1hXDjW4P9+2Gw9oBqYbqwxTmorawqtvoF06qlTCaGn/fm7y s0YiX4QAK6III1s365ViyXSCgghG2+EkSQV7vGMkvovayflRJhyq0qeCS8DJrud0UJda 6bwhxUbIt5owDEhxxuMxAS4/3SPvwtn6gLbVsXzjCfuKCF2z4ozktGoOc4koFfqEyHEn NMA5EUtoQ+1WsqgwK+B3/Phu01JPbhS6Awm+ZLF3hzBcewHdCosqQNpCdr+CNqaAp/MN vgfapw+u9uG9pql5sk+eay594xHRS2G7SBNhiiTt+1q7ORaD2MUAOdbdMwMyBarTgSnO g34Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=DWzuCtMSa/2ZgCIoIpooxeBL6LUrH/EyK+ormLsAxX4=; b=LmwBCpDBSSWK8BlJdFAdRuH2Dkmn5ps44y4758YXUjF4tkTL7vwwCh6drTvJkHrU2Y Qg8gAu4/uF5yV996lflT4NsTAiR2Lfd2Onr5tKIs2dylU+TYANKNkX3RDMujWs20RTFs 97M8FkN7iVzA268hhtu0LDVuJAB1ztcdcevafXC30YZ8n+sMq4Pgk0Esr0ykDbMWoeDA kIhEn9MRk3UGLbJW+7MW6XydIYo7q99LD4y91tofWfwTGZunXdoAueQybIWrWeoursra XzbHGyZhfMk7bqzGvpN1amr2Rk9OeDX6OKudBdd8NS75hZXSZbRf3+vs5F3a4AKBTLZr JzlA== X-Gm-Message-State: AMCzsaV6rUlSHzsrBMdr1f1PB5yRzEXMgjMa3im1ulRVSu22xrDPi+3K 8qEoeVRO22Tdkt+khFinnT7h9BDa X-Google-Smtp-Source: ABhQp+Qb/W/SrfnNTQWQ++XIUIFRys7J5rmAKgZdwQ7GMFCEB6AukNv6TOxQvOkcUWVTUBCu61YTWg== X-Received: by 10.28.55.2 with SMTP id e2mr7284543wma.60.1508343196206; Wed, 18 Oct 2017 09:13:16 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:06 +0200 Message-Id: <1508343141-31835-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [PULL 14/29] target/i386: introduce x86_ld*_code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" These take care of advancing s->pc, and will provide a unified point where to check for the 15-byte instruction length limit. Signed-off-by: Paolo Bonzini --- target/i386/translate.c | 228 ++++++++++++++++++++++++++---------------------- 1 file changed, 125 insertions(+), 103 deletions(-) diff --git a/target/i386/translate.c b/target/i386/translate.c index 5d61fa9..4a938c2 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -1863,6 +1863,41 @@ static void gen_shifti(DisasContext *s1, int op, TCGMemOp ot, int d, int c) } } +static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes) +{ + uint64_t pc = s->pc; + + s->pc += num_bytes; + return pc; +} + +static inline uint8_t x86_ldub_code(CPUX86State *env, DisasContext *s) +{ + return cpu_ldub_code(env, advance_pc(env, s, 1)); +} + +static inline int16_t x86_ldsw_code(CPUX86State *env, DisasContext *s) +{ + return cpu_ldsw_code(env, advance_pc(env, s, 2)); +} + +static inline uint16_t x86_lduw_code(CPUX86State *env, DisasContext *s) +{ + return cpu_lduw_code(env, advance_pc(env, s, 2)); +} + +static inline uint32_t x86_ldl_code(CPUX86State *env, DisasContext *s) +{ + return cpu_ldl_code(env, advance_pc(env, s, 4)); +} + +#ifdef TARGET_X86_64 +static inline uint64_t x86_ldq_code(CPUX86State *env, DisasContext *s) +{ + return cpu_ldq_code(env, advance_pc(env, s, 8)); +} +#endif + /* Decompose an address. */ typedef struct AddressParts { @@ -1900,7 +1935,7 @@ static AddressParts gen_lea_modrm_0(CPUX86State *env, DisasContext *s, case MO_32: havesib = 0; if (rm == 4) { - int code = cpu_ldub_code(env, s->pc++); + int code = x86_ldub_code(env, s); scale = (code >> 6) & 3; index = ((code >> 3) & 7) | REX_X(s); if (index == 4) { @@ -1914,8 +1949,7 @@ static AddressParts gen_lea_modrm_0(CPUX86State *env, DisasContext *s, case 0: if ((base & 7) == 5) { base = -1; - disp = (int32_t)cpu_ldl_code(env, s->pc); - s->pc += 4; + disp = (int32_t)x86_ldl_code(env, s); if (CODE64(s) && !havesib) { base = -2; disp += s->pc + s->rip_offset; @@ -1923,12 +1957,11 @@ static AddressParts gen_lea_modrm_0(CPUX86State *env, DisasContext *s, } break; case 1: - disp = (int8_t)cpu_ldub_code(env, s->pc++); + disp = (int8_t)x86_ldub_code(env, s); break; default: case 2: - disp = (int32_t)cpu_ldl_code(env, s->pc); - s->pc += 4; + disp = (int32_t)x86_ldl_code(env, s); break; } @@ -1945,15 +1978,13 @@ static AddressParts gen_lea_modrm_0(CPUX86State *env, DisasContext *s, if (mod == 0) { if (rm == 6) { base = -1; - disp = cpu_lduw_code(env, s->pc); - s->pc += 2; + disp = x86_lduw_code(env, s); break; } } else if (mod == 1) { - disp = (int8_t)cpu_ldub_code(env, s->pc++); + disp = (int8_t)x86_ldub_code(env, s); } else { - disp = (int16_t)cpu_lduw_code(env, s->pc); - s->pc += 2; + disp = (int16_t)x86_lduw_code(env, s); } switch (rm) { @@ -2103,19 +2134,16 @@ static inline uint32_t insn_get(CPUX86State *env, DisasContext *s, TCGMemOp ot) switch (ot) { case MO_8: - ret = cpu_ldub_code(env, s->pc); - s->pc++; + ret = x86_ldub_code(env, s); break; case MO_16: - ret = cpu_lduw_code(env, s->pc); - s->pc += 2; + ret = x86_lduw_code(env, s); break; case MO_32: #ifdef TARGET_X86_64 case MO_64: #endif - ret = cpu_ldl_code(env, s->pc); - s->pc += 4; + ret = x86_ldl_code(env, s); break; default: tcg_abort(); @@ -3041,7 +3069,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, gen_helper_enter_mmx(cpu_env); } - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7); if (is_xmm) reg |= rex_r; @@ -3250,8 +3278,8 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, if (b1 == 1 && reg != 0) goto illegal_op; - field_length = cpu_ldub_code(env, s->pc++) & 0x3F; - bit_index = cpu_ldub_code(env, s->pc++) & 0x3F; + field_length = x86_ldub_code(env, s) & 0x3F; + bit_index = x86_ldub_code(env, s) & 0x3F; tcg_gen_addi_ptr(cpu_ptr0, cpu_env, offsetof(CPUX86State,xmm_regs[reg])); if (b1 == 1) @@ -3380,7 +3408,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, if (b1 >= 2) { goto unknown_op; } - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); if (is_xmm) { tcg_gen_movi_tl(cpu_T0, val); tcg_gen_st32_tl(cpu_T0, cpu_env, offsetof(CPUX86State,xmm_t0.ZMM_L(0))); @@ -3537,7 +3565,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, case 0x1c4: s->rip_offset = 1; gen_ldst_modrm(env, s, modrm, MO_16, OR_TMP0, 0); - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); if (b1) { val &= 7; tcg_gen_st16_tl(cpu_T0, cpu_env, @@ -3553,7 +3581,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, if (mod != 3) goto illegal_op; ot = mo_64_32(s->dflag); - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); if (b1) { val &= 7; rm = (modrm & 7) | REX_B(s); @@ -3616,7 +3644,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, if ((b & 0xf0) == 0xf0) { goto do_0f_38_fx; } - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); rm = modrm & 7; reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; @@ -3693,7 +3721,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, do_0f_38_fx: /* Various integer extensions at 0f 38 f[0-f]. */ b = modrm | (b1 << 8); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; switch (b) { @@ -4054,7 +4082,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, case 0x03a: case 0x13a: b = modrm; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); rm = modrm & 7; reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; @@ -4077,7 +4105,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, if (mod != 3) gen_lea_modrm(env, s, modrm); reg = ((modrm >> 3) & 7) | rex_r; - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); switch (b) { case 0x14: /* pextrb */ tcg_gen_ld8u_tl(cpu_T0, cpu_env, offsetof(CPUX86State, @@ -4225,7 +4253,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, gen_ldq_env_A0(s, op2_offset); } } - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); if ((b & 0xfc) == 0x60) { /* pcmpXstrX */ set_cc_op(s, CC_OP_EFLAGS); @@ -4244,7 +4272,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, case 0x33a: /* Various integer extensions at 0f 3a f[0-f]. */ b = modrm | (b1 << 8); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; switch (b) { @@ -4256,7 +4284,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, } ot = mo_64_32(s->dflag); gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); - b = cpu_ldub_code(env, s->pc++); + b = x86_ldub_code(env, s); if (ot == MO_64) { tcg_gen_rotri_tl(cpu_T0, cpu_T0, b & 63); } else { @@ -4351,7 +4379,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, } switch(b) { case 0x0f: /* 3DNow! data insns */ - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); sse_fn_epp = sse_op_table5[val]; if (!sse_fn_epp) { goto unknown_op; @@ -4365,7 +4393,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, break; case 0x70: /* pshufx insn */ case 0xc6: /* pshufx insn */ - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); /* XXX: introduce a new table? */ @@ -4374,7 +4402,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, break; case 0xc2: /* compare insns */ - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); if (val >= 8) goto unknown_op; sse_fn_epp = sse_op_table4[val][b1]; @@ -4443,8 +4471,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (s->pc - pc_start > 14) { goto illegal_op; } - b = cpu_ldub_code(env, s->pc); - s->pc++; + b = x86_ldub_code(env, s); /* Collect prefixes. */ switch (b) { case 0xf3: @@ -4501,7 +4528,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) static const int pp_prefix[4] = { 0, PREFIX_DATA, PREFIX_REPZ, PREFIX_REPNZ }; - int vex3, vex2 = cpu_ldub_code(env, s->pc); + int vex3, vex2 = x86_ldub_code(env, s); if (!CODE64(s) && (vex2 & 0xc0) != 0xc0) { /* 4.1.4.6: In 32-bit mode, bits [7:6] must be 11b, @@ -4523,17 +4550,17 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) rex_r = (~vex2 >> 4) & 8; if (b == 0xc5) { vex3 = vex2; - b = cpu_ldub_code(env, s->pc++); + b = x86_ldub_code(env, s); } else { #ifdef TARGET_X86_64 s->rex_x = (~vex2 >> 3) & 8; s->rex_b = (~vex2 >> 2) & 8; #endif - vex3 = cpu_ldub_code(env, s->pc++); + vex3 = x86_ldub_code(env, s); rex_w = (vex3 >> 7) & 1; switch (vex2 & 0x1f) { case 0x01: /* Implied 0f leading opcode bytes. */ - b = cpu_ldub_code(env, s->pc++) | 0x100; + b = x86_ldub_code(env, s) | 0x100; break; case 0x02: /* Implied 0f 38 leading opcode bytes. */ b = 0x138; @@ -4585,7 +4612,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x0f: /**************************/ /* extended op code */ - b = cpu_ldub_code(env, s->pc++) | 0x100; + b = x86_ldub_code(env, s) | 0x100; goto reswitch; /**************************/ @@ -4607,7 +4634,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) switch(f) { case 0: /* OP Ev, Gv */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); @@ -4628,7 +4655,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_op(s, op, ot, opreg); break; case 1: /* OP Gv, Ev */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; reg = ((modrm >> 3) & 7) | rex_r; rm = (modrm & 7) | REX_B(s); @@ -4662,7 +4689,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); op = (modrm >> 3) & 7; @@ -4708,7 +4735,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xf7: ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); op = (modrm >> 3) & 7; @@ -4940,7 +4967,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xff: /* GRP5 */ ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); op = (modrm >> 3) & 7; @@ -5048,7 +5075,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x85: ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); @@ -5120,7 +5147,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x69: /* imul Gv, Ev, I */ case 0x6b: ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; if (b == 0x69) s->rip_offset = insn_const_size(ot); @@ -5172,7 +5199,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x1c0: case 0x1c1: /* xadd Ev, Gv */ ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; gen_op_mov_v_reg(ot, cpu_T0, reg); @@ -5204,7 +5231,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) TCGv oldv, newv, cmpv; ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; oldv = tcg_temp_new(); @@ -5256,7 +5283,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) } break; case 0x1c7: /* cmpxchg8b */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; if ((mod == 3) || ((modrm & 0x38) != 0x8)) goto illegal_op; @@ -5318,7 +5345,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_push_v(s, cpu_T0); break; case 0x8f: /* pop Ev */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; ot = gen_pop_T0(s); if (mod == 3) { @@ -5337,9 +5364,8 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xc8: /* enter */ { int level; - val = cpu_lduw_code(env, s->pc); - s->pc += 2; - level = cpu_ldub_code(env, s->pc++); + val = x86_lduw_code(env, s); + level = x86_ldub_code(env, s); gen_enter(s, val, level); } break; @@ -5396,7 +5422,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x88: case 0x89: /* mov Gv, Ev */ ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; /* generate a generic store */ @@ -5405,7 +5431,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xc6: case 0xc7: /* mov Ev, Iv */ ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; if (mod != 3) { s->rip_offset = insn_const_size(ot); @@ -5422,14 +5448,14 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x8a: case 0x8b: /* mov Ev, Gv */ ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); gen_op_mov_reg_v(ot, reg, cpu_T0); break; case 0x8e: /* mov seg, Gv */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = (modrm >> 3) & 7; if (reg >= 6 || reg == R_CS) goto illegal_op; @@ -5447,7 +5473,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) } break; case 0x8c: /* mov Gv, seg */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = (modrm >> 3) & 7; mod = (modrm >> 6) & 3; if (reg >= 6) @@ -5472,7 +5498,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) /* s_ot is the sign+size of source */ s_ot = b & 8 ? MO_SIGN | ot : ot; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); @@ -5508,7 +5534,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) break; case 0x8d: /* lea */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; if (mod == 3) goto illegal_op; @@ -5532,8 +5558,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) switch (s->aflag) { #ifdef TARGET_X86_64 case MO_64: - offset_addr = cpu_ldq_code(env, s->pc); - s->pc += 8; + offset_addr = x86_ldq_code(env, s); break; #endif default: @@ -5570,8 +5595,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (dflag == MO_64) { uint64_t tmp; /* 64 bit case */ - tmp = cpu_ldq_code(env, s->pc); - s->pc += 8; + tmp = x86_ldq_code(env, s); reg = (b & 7) | REX_B(s); tcg_gen_movi_tl(cpu_T0, tmp); gen_op_mov_reg_v(MO_64, reg, cpu_T0); @@ -5595,7 +5619,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x86: case 0x87: /* xchg Ev, Gv */ ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; if (mod == 3) { @@ -5632,7 +5656,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) op = R_GS; do_lxx: ot = dflag != MO_16 ? MO_32 : MO_16; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; if (mod == 3) @@ -5660,7 +5684,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) grp2: { ot = mo_b_d(b, dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; op = (modrm >> 3) & 7; @@ -5679,7 +5703,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_shift(s, op, ot, opreg, OR_ECX); } else { if (shift == 2) { - shift = cpu_ldub_code(env, s->pc++); + shift = x86_ldub_code(env, s); } gen_shifti(s, op, ot, opreg, shift); } @@ -5713,7 +5737,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) shift = 0; do_shiftd: ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); reg = ((modrm >> 3) & 7) | rex_r; @@ -5726,7 +5750,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_op_mov_v_reg(ot, cpu_T1, reg); if (shift) { - TCGv imm = tcg_const_tl(cpu_ldub_code(env, s->pc++)); + TCGv imm = tcg_const_tl(x86_ldub_code(env, s)); gen_shiftd_rm_T1(s, ot, opreg, op, imm); tcg_temp_free(imm); } else { @@ -5743,7 +5767,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); break; } - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; rm = modrm & 7; op = ((b & 7) << 3) | ((modrm >> 3) & 7); @@ -6328,7 +6352,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xe4: case 0xe5: ot = mo_b_d32(b, dflag); - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); tcg_gen_movi_tl(cpu_T0, val); gen_check_io(s, ot, pc_start - s->cs_base, SVM_IOIO_TYPE_MASK | svm_is_rep(prefixes)); @@ -6347,7 +6371,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xe6: case 0xe7: ot = mo_b_d32(b, dflag); - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); tcg_gen_movi_tl(cpu_T0, val); gen_check_io(s, ot, pc_start - s->cs_base, svm_is_rep(prefixes)); @@ -6407,8 +6431,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) /************************/ /* control */ case 0xc2: /* ret im */ - val = cpu_ldsw_code(env, s->pc); - s->pc += 2; + val = x86_ldsw_code(env, s); ot = gen_pop_T0(s); gen_stack_update(s, val + (1 << ot)); /* Note that gen_pop_T0 uses a zero-extending load. */ @@ -6425,8 +6448,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_jr(s, cpu_T0); break; case 0xca: /* lret im */ - val = cpu_ldsw_code(env, s->pc); - s->pc += 2; + val = x86_ldsw_code(env, s); do_lret: if (s->pe && !s->vm86) { gen_update_cc_op(s); @@ -6563,7 +6585,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) break; case 0x190 ... 0x19f: /* setcc Gv */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); gen_setcc1(s, b, cpu_T0); gen_ldst_modrm(env, s, modrm, MO_8, OR_TMP0, 1); break; @@ -6572,7 +6594,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) goto illegal_op; } ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; gen_cmovcc1(env, s, ot, b, modrm, reg); break; @@ -6689,7 +6711,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) /* bit operations */ case 0x1ba: /* bt/bts/btr/btc Gv, im */ ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); op = (modrm >> 3) & 7; mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); @@ -6703,7 +6725,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_op_mov_v_reg(ot, cpu_T0, rm); } /* load shift */ - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); tcg_gen_movi_tl(cpu_T1, val); if (op < 4) goto unknown_op; @@ -6722,7 +6744,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) op = 3; do_btx: ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); @@ -6827,7 +6849,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x1bc: /* bsf / tzcnt */ case 0x1bd: /* bsr / lzcnt */ ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); gen_extu(ot, cpu_T0); @@ -6907,7 +6929,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xd4: /* aam */ if (CODE64(s)) goto illegal_op; - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); if (val == 0) { gen_exception(s, EXCP00_DIVZ, pc_start - s->cs_base); } else { @@ -6918,7 +6940,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0xd5: /* aad */ if (CODE64(s)) goto illegal_op; - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); gen_helper_aad(cpu_env, tcg_const_i32(val)); set_cc_op(s, CC_OP_LOGICB); break; @@ -6952,7 +6974,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_interrupt(s, EXCP03_INT3, pc_start - s->cs_base, s->pc - s->cs_base); break; case 0xcd: /* int N */ - val = cpu_ldub_code(env, s->pc++); + val = x86_ldub_code(env, s); if (s->vm86 && s->iopl != 3) { gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); } else { @@ -7007,7 +7029,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (CODE64(s)) goto illegal_op; ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = (modrm >> 3) & 7; mod = (modrm >> 6) & 3; if (mod == 3) @@ -7186,7 +7208,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) } break; case 0x100: - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; op = (modrm >> 3) & 7; switch(op) { @@ -7251,7 +7273,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) break; case 0x101: - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); switch (modrm) { CASE_MODRM_MEM_OP(0): /* sgdt */ gen_svm_check_intercept(s, pc_start, SVM_EXIT_GDTR_READ); @@ -7596,7 +7618,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) /* d_ot is the size of destination */ d_ot = dflag; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; mod = (modrm >> 6) & 3; rm = (modrm & 7) | REX_B(s); @@ -7625,7 +7647,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) t1 = tcg_temp_local_new(); t2 = tcg_temp_local_new(); ot = MO_16; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = (modrm >> 3) & 7; mod = (modrm >> 6) & 3; rm = modrm & 7; @@ -7670,7 +7692,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (!s->pe || s->vm86) goto illegal_op; ot = dflag != MO_16 ? MO_32 : MO_16; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; gen_ldst_modrm(env, s, modrm, MO_16, OR_TMP0, 0); t0 = tcg_temp_local_new(); @@ -7690,7 +7712,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) } break; case 0x118: - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; op = (modrm >> 3) & 7; switch(op) { @@ -7709,7 +7731,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) } break; case 0x11a: - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); if (s->flags & HF_MPX_EN_MASK) { mod = (modrm >> 6) & 3; reg = ((modrm >> 3) & 7) | rex_r; @@ -7799,7 +7821,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_nop_modrm(env, s, modrm); break; case 0x11b: - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); if (s->flags & HF_MPX_EN_MASK) { mod = (modrm >> 6) & 3; reg = ((modrm >> 3) & 7) | rex_r; @@ -7901,7 +7923,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_nop_modrm(env, s, modrm); break; case 0x119: case 0x11c ... 0x11f: /* nop (multi byte) */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); gen_nop_modrm(env, s, modrm); break; case 0x120: /* mov reg, crN */ @@ -7909,7 +7931,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (s->cpl != 0) { gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); } else { - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); /* Ignore the mod bits (assume (modrm&0xc0)==0xc0). * AMD documentation (24594.pdf) and testing of * intel 386 and 486 processors all show that the mod bits @@ -7966,7 +7988,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (s->cpl != 0) { gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); } else { - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); /* Ignore the mod bits (assume (modrm&0xc0)==0xc0). * AMD documentation (24594.pdf) and testing of * intel 386 and 486 processors all show that the mod bits @@ -8012,7 +8034,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (!(s->cpuid_features & CPUID_SSE2)) goto illegal_op; ot = mo_64_32(dflag); - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; if (mod == 3) goto illegal_op; @@ -8021,7 +8043,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) gen_ldst_modrm(env, s, modrm, ot, reg, 1); break; case 0x1ae: - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); switch (modrm) { CASE_MODRM_MEM_OP(0): /* fxsave */ if (!(s->cpuid_features & CPUID_FXSR) @@ -8219,7 +8241,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) break; case 0x10d: /* 3DNow! prefetch(w) */ - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; if (mod == 3) goto illegal_op; @@ -8241,7 +8263,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) if (!(s->cpuid_ext_features & CPUID_EXT_POPCNT)) goto illegal_op; - modrm = cpu_ldub_code(env, s->pc++); + modrm = x86_ldub_code(env, s); reg = ((modrm >> 3) & 7) | rex_r; if (s->prefix & PREFIX_DATA) { From patchwork Wed Oct 18 16:12:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827709 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oRqmOPKk"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHLv4qzYz9t5q for ; Thu, 19 Oct 2017 03:19:19 +1100 (AEDT) Received: from localhost ([::1]:45474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r3t-0007zU-No for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:19:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qy7-0003XY-KL for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy6-0002BT-JQ for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:19 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:53411) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy6-0002Ac-DO for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:18 -0400 Received: by mail-wm0-x241.google.com with SMTP id q132so11154409wmd.2 for ; Wed, 18 Oct 2017 09:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=8NJYsvPa79vJzgRs1BSiIgNGCAueXWS/ntKKEjCqtZQ=; b=oRqmOPKkX8HW6txQKAaCOTgTdTMFoJrfirR3NIQQUNThiWFA976bu5bz60UkHab/BY ljczrOXhuTdZ9CrYjqPoluT55HETpXcML5byT+NFiI3DXxIb9oUApNhtMXZ9kU+2llC1 uQoZfAcxVegCXEN4hbBew+0FFdoC7acwxcmLVYrvB5YO+dqIu5jJEe37KKb46Mb/a7jX yRZn0KQ5TeNo0lS6a+QGkBDzaOupb3zxtRW8HAeMpbhi6Yl81QmmfWXuaw6STZylWWJd GE8g2Bw1P+6ZWDrd2stC2ep4pILZ6NSId3mNmWW2vj7Ynf3dAxqaAasQpZW9BBa8z1it Q66g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=8NJYsvPa79vJzgRs1BSiIgNGCAueXWS/ntKKEjCqtZQ=; b=K3O8nx1EXpRKFsvBwtXn8dK3G8VhdIBqspFOFH/9QhfFQTJtOyYWQPQcr0fAimxxAw +SdoeLhVuFkKo1ZAHMYTHHjEBA001/KsQBZTh6VWIDRsx7AWHzoQKDd4A1lWXIEQF6oy yWPOY7lpWkXww/vONQHW0YvrVnS8ZdJQbDBMP7JpznPhG7xvK+UE08wXCE9NAfyx1eOS M43PhtVwZbru16QSHZ897A0uFfAni7VdS6K2b4XdILsonMk7fH92eGEud0rRId9e+S9M c2AWq05TCzPY/281E+q3RJ4RsnEHgCIzMHwPK1g4bJtherx5NUqZgE5ztPZHfZz3sDvh dEOw== X-Gm-Message-State: AMCzsaWWAihe7jfN+Du5sBQ0pykwCzgfSXuCCR85h49HwIfAlvuAebqD SP0Csa1KllQ62hUlb1u+vMNtgR8D X-Google-Smtp-Source: ABhQp+RdpEDGP4ccTKXYPBFjtP4FpDJ6YrU2ForXrw8siX2wobwdN9fWKAnHSz90STHmM35MVB+QJg== X-Received: by 10.28.140.13 with SMTP id o13mr4412727wmd.150.1508343197066; Wed, 18 Oct 2017 09:13:17 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:07 +0200 Message-Id: <1508343141-31835-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 15/29] target/i386: trap on instructions longer than >15 bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Besides being more correct, arbitrarily long instruction allow the generation of a translation block that spans three pages. This confuses the generator and even allows ring 3 code to poison the translation block cache and inject code into other processes that are in guest ring 3. This is an improved (and more invasive) fix for commit 30663fd ("tcg/i386: Check the size of instruction being translated", 2017-03-24). In addition to being more precise (and generating the right exception, which is #GP rather than #UD), it distinguishes better between page faults and too long instructions, as shown by this test case: #include #include #include int main() { char *x = mmap(NULL, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0); memset(x, 0x66, 4096); x[4096] = 0x90; x[4097] = 0xc3; char *i = x + 4096 - 15; mprotect(x + 4096, 4096, PROT_READ|PROT_WRITE); ((void(*)(void)) i) (); } ... which produces a #GP without the mprotect, and a #PF with it. Signed-off-by: Paolo Bonzini --- target/i386/translate.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/target/i386/translate.c b/target/i386/translate.c index 4a938c2..5f24a2d 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -136,6 +136,7 @@ typedef struct DisasContext { int cpuid_ext3_features; int cpuid_7_0_ebx_features; int cpuid_xsave_features; + sigjmp_buf jmpbuf; } DisasContext; static void gen_eob(DisasContext *s); @@ -1863,11 +1864,27 @@ static void gen_shifti(DisasContext *s1, int op, TCGMemOp ot, int d, int c) } } +#define X86_MAX_INSN_LENGTH 15 + static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes) { uint64_t pc = s->pc; s->pc += num_bytes; + if (unlikely(s->pc - s->pc_start > X86_MAX_INSN_LENGTH)) { + /* If the instruction's 16th byte is on a different page than the 1st, a + * page fault on the second page wins over the general protection fault + * caused by the instruction being too long. + * This can happen even if the operand is only one byte long! + */ + if (((s->pc - 1) ^ (pc - 1)) & TARGET_PAGE_MASK) { + volatile uint8_t unused = + cpu_ldub_code(env, (s->pc - 1) & TARGET_PAGE_MASK); + (void) unused; + } + siglongjmp(s->jmpbuf, 1); + } + return pc; } @@ -4463,14 +4480,12 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) s->rip_offset = 0; /* for relative ip address */ s->vex_l = 0; s->vex_v = 0; - next_byte: - /* x86 has an upper limit of 15 bytes for an instruction. Since we - * do not want to decode and generate IR for an illegal - * instruction, the following check limits the instruction size to - * 25 bytes: 14 prefix + 1 opc + 6 (modrm+sib+ofs) + 4 imm */ - if (s->pc - pc_start > 14) { - goto illegal_op; + if (sigsetjmp(s->jmpbuf, 0) != 0) { + gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); + return s->pc; } + + next_byte: b = x86_ldub_code(env, s); /* Collect prefixes. */ switch (b) { From patchwork Wed Oct 18 16:12:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827733 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UlNt1hdf"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHXc341qz9t5s for ; Thu, 19 Oct 2017 03:27:43 +1100 (AEDT) Received: from localhost ([::1]:45514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rC0-0006oy-IB for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:27:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyA-0003au-Qz for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy7-0002DL-Jb for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:22 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:46875) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy7-0002Bu-DQ for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:19 -0400 Received: by mail-wr0-x243.google.com with SMTP id l1so5596789wrc.3 for ; Wed, 18 Oct 2017 09:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kg2Xn8DmE9dorLESsBaXlAgw44RU8mJp384WSLMIbbw=; b=UlNt1hdfk5W3ydPoFfDi2d7QaLaMs3h64Ecni5M5FDP1agArxSatB08drrbhrKlFMu PMuHj6zjMMzUd05Pzu5OT4DxvwS78eHLTkSHxEndUnj8t60rHLLZbNISmutX3Ikk99JX 3t2FpCsLGzseg+bsoooJvbD/Gstop1K5C/a/+LQSgpktMZ8TX6TZ4HwZfIRnv2GZ/9FO LhqFYfnpPjvyNON8++QSkr3T25Dvt6yS+HgDX7wnPG1C0i9Eznwl7B8vyBHOfO9hTP/k at1beb6aWIg6JlYiLzVseuDQO8W7Pz3p6gh1aAzzghCj1v7N+fvwQp3gZpDq87WA/1Af PPaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Kg2Xn8DmE9dorLESsBaXlAgw44RU8mJp384WSLMIbbw=; b=bxB9VZPnfHHDfJ1aPB+vvBKzcJ+GNvm1egnhhPE5G7joEvleBwpn4wFi8BJJc/lToy AMxcjZHNYqodKRJc67KcUndURTUtE+XAMYP8tBsBXhZa/UovEb+F0E6JXbKo/Ghj+wrT C4SSKlBoybc1bKW4w++ILe9qnUPi+fNPXsvHNtGQ2EmWG0vBjcZOcKldp95Hzln9nYE7 PbUdMJ1hUeoyXsKUEiOAycwRd6sgv7X452JWojScvfUYWJdHPnGV7L5Q8cNeS88XGJKH e4WBnMcOqDlG6Da3mLDYgEpPq3Od7WTwopKWkxQ0Yf/wsLyhWDGANJ1eXmI4rbWso3pb AuqQ== X-Gm-Message-State: AMCzsaW0ctmiBIkOruxzjbQWLyBR0s8byc2hzBEH68JnCuSbLZsTtkQw KMRJ4lpcy85FeXq6AGqbDdkM7tGw X-Google-Smtp-Source: ABhQp+Qq+i4JLald2KGLk2zrUo/gIkd7KrwrLijSiaadiy6LC6QBE8RWkpsYqsNUtdPyWdi4jlIZLw== X-Received: by 10.223.184.36 with SMTP id h33mr7639155wrf.38.1508343198194; Wed, 18 Oct 2017 09:13:18 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:08 +0200 Message-Id: <1508343141-31835-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PULL 16/29] memory: call log_start after region_add X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand It might be confusing for some listener implementations that implement both, region_add and log_start (e.g. KVM) if we call log_start before an actual region was added using region_add. This makes current KVM code trigger an assertion ("kvm_section_update_flags: error finding slot"). So let's just reverse the order instead of tolerating log_start on yet unknown regions. Reported-by: Thomas Huth Signed-off-by: David Hildenbrand Message-Id: <20171016144302.24284-2-david@redhat.com> Tested-by: Joe Clifford Signed-off-by: Paolo Bonzini --- memory.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/memory.c b/memory.c index b637c12..3e1558a 100644 --- a/memory.c +++ b/memory.c @@ -2607,12 +2607,12 @@ static void listener_add_address_space(MemoryListener *listener, .offset_within_address_space = int128_get64(fr->addr.start), .readonly = fr->readonly, }; - if (fr->dirty_log_mask && listener->log_start) { - listener->log_start(listener, §ion, 0, fr->dirty_log_mask); - } if (listener->region_add) { listener->region_add(listener, §ion); } + if (fr->dirty_log_mask && listener->log_start) { + listener->log_start(listener, §ion, 0, fr->dirty_log_mask); + } } if (listener->commit) { listener->commit(listener); From patchwork Wed Oct 18 16:12:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827726 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Dm3E36NS"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHTQ6SwMz9sBd for ; Thu, 19 Oct 2017 03:24:58 +1100 (AEDT) Received: from localhost ([::1]:45497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r9M-00047l-Ty for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:24:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyA-0003av-R3 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy8-0002Ep-Tp for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:22 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:55192) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy8-0002EH-MG for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:20 -0400 Received: by mail-wr0-x243.google.com with SMTP id o44so5582844wrf.11 for ; Wed, 18 Oct 2017 09:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7LdjNNfUhFt1Su9uCAt7E70S53s10GgPR8psl4266gg=; b=Dm3E36NSW9A55vPacnS5rJb+Shb/FkI9HgG5pW8xq/ph64KqH9EC0ZEQ89rDCIkZkc Zji6kibbgk+mD4pk9nEVs1skeSyfMC81DqODPj1VBkoQ9d2b9Xr78lDHRP6+Ffhap91T hoSMXo3BGGF0MXIxQVk4edY+qhdMOZKozKHrv3S9snQoJmLG2IFnNEHN/8gh1yutSOgn 1JCwCRMTsuVANyde1soqqTrzesZy+MEBtvOYvvuuEcukOY16mO26+ZbA/fRdh0YM4Hok V4KyDldyoXX9ZhrEyZWzkomawOi1OvAAoShFmrzCp1uLOvlULVcT9OSAqmfsKNjcW93w ru8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7LdjNNfUhFt1Su9uCAt7E70S53s10GgPR8psl4266gg=; b=VPQyarPw+5UlNqlgYwhr+0Wjgypt8ORU7kI8Hza9Y4K9jqtiKabHcHJWsbPZ0yTqxy 8mXP8iN8BEXpgGdgoI6PIZtka0poqSEiw5eV4OdbwUQiP80y4uAUXjU1XUSgJK3tozoG +dAR6K+sC/v0NWnjVR+OtEqD+Y7qiubwoBqz/jAcxQqG2SmcUMRm1lItN8J5RvPAFVVt ksaIxnWUw7T6vk1GEFqIFyWDYzd9BSIwabHvjXJvTPziVME2rLSk+M+ZlWC8Lr4bMcSD 2Vgjs7cxtJvfAgsWrcpU73qOLzaM0QwafS9bpBM05UIH3C0TYvn29GwSbJH5ODahuZYu HxLQ== X-Gm-Message-State: AMCzsaW9rXQawxfYR3KZDwQiHOnE1w7yAmcZ8OAX7SZPFXUaR+rONxtx eS/LhvcTCgZvYytCnFmyzIExnnu2 X-Google-Smtp-Source: ABhQp+RnS/sc97ffqyG0p6h1wZU4iGaxHlWP3f9lMQjQMukEN/R1sMpVUsumQv0lnIkGJDRCSxAdQA== X-Received: by 10.223.139.82 with SMTP id v18mr7800154wra.55.1508343199441; Wed, 18 Oct 2017 09:13:19 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:09 +0200 Message-Id: <1508343141-31835-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PULL 17/29] kvm: fix alignment of ram address X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Fix the wrong calculation of the delta, used to align the ram address. This only strikes if alignment has to be done. Reported-by: Joe Clifford Fixes: 5ea69c2e3614 ("kvm: factor out alignment of memory section") Signed-off-by: David Hildenbrand Message-Id: <20171016144302.24284-3-david@redhat.com> Tested-by: Joe Clifford Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 90c88b5..fae1eca 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -717,8 +717,9 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, return; } + /* use aligned delta to align the ram address */ ram = memory_region_get_ram_ptr(mr) + section->offset_within_region + - (section->offset_within_address_space - start_addr); + (start_addr - section->offset_within_address_space); mem = kvm_lookup_matching_slot(kml, start_addr, size); if (!add) { From patchwork Wed Oct 18 16:12:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YTxOrsTK"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHZ06GKpz9t5q for ; Thu, 19 Oct 2017 03:28:56 +1100 (AEDT) Received: from localhost ([::1]:45524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rDC-0001ob-VH for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:28:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyA-0003aw-Rp for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qy9-0002Fd-QE for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:22 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:45112) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qy9-0002F5-KF for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:21 -0400 Received: by mail-wr0-x241.google.com with SMTP id k7so5596060wre.2 for ; Wed, 18 Oct 2017 09:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7Zij4P9FSMz57ob2a+YZ+pioRBJdgcj+btZWJa04WOM=; b=YTxOrsTK4Kzy8yfK8CW+gx/ckPBu54SD+QUmq7tYfriKw1aakJG7TmeGt8LOsZeIZY MY4EwyFaNS4RW64BCTwAKY5XL/ya/9aTriS5TWKlRy0dIHMjEh7xuuocLY6BAhQ+NmaB p9cKABAg8x0+tW19b+OjgPA9VDksN85uXJCwCkQGS7JaH+Rq49ZYEwoRNOT7j+ewqeC0 ph7zKYFL/SEpwJPNusjJ+FPVyUnEinJxQK+q+4UaX/JhNAJpY+Jp+emenCRy8Aai3/H7 oeCGP2hUVpxqf6AGSrW5kJD2AJatZMrBw0OJzC2oDVZ8zAcbXr7+8V/LQZhQr6Rbj/ib tcEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7Zij4P9FSMz57ob2a+YZ+pioRBJdgcj+btZWJa04WOM=; b=ivwGrTyxx/OxgFdZTxwWLtCRS7j0wJrpwCNDcV/fitGxMI3HX/DgOi8kUAx+h+QpxH FezxdWsmU6Bn8RkCbsO4IyO4gEbDxILLyv4rOxZNsYxwcAmtDoaKbr9OQbb7bjxgei2r cQx6j2fW5bhcK6NZnmsYRDm91WQScyVV4ri+tymTDa43dC2YLgHHorP04caBZGLWy6Z8 CHqraMP7dvf5ddIZY64b0MtgrcjZZdb+KwuOGtafOmDxzge8OMOJ1Nm8NIpkM7WAvzXA p48Y2QAr6a7DHXikSaGl6NUdla6SUyCM2oK7ZpSgemMaMESvohbZtBgPYqmY/IzDbOrP MNOQ== X-Gm-Message-State: AMCzsaXSEQA1/6hjypZuJakg2FpMCLiSj7OdX10+dbyhqeVPRQqPE8zw pWutstn0+rDQPfnUdjqHv7eOGB7X X-Google-Smtp-Source: ABhQp+QcSln339LbbxEmrVzEmRvyxbpDcKPwI2vKUYJY1RP9zUWTcIhJj+qrr8vpzBgCc4DJTE2uIg== X-Received: by 10.223.135.143 with SMTP id b15mr8093489wrb.24.1508343200447; Wed, 18 Oct 2017 09:13:20 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:10 +0200 Message-Id: <1508343141-31835-19-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PULL 18/29] kvm: tolerate non-existing slot for log_start/log_stop/log_sync X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand If we want to trap every access to a section, we might not have a slot. So let's just tolerate if we don't have one. Signed-off-by: David Hildenbrand Message-Id: <20171016144302.24284-4-david@redhat.com> Tested-by: Joe Clifford Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index fae1eca..f5fa3e2 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -394,8 +394,8 @@ static int kvm_section_update_flags(KVMMemoryListener *kml, mem = kvm_lookup_matching_slot(kml, start_addr, size); if (!mem) { - fprintf(stderr, "%s: error finding slot\n", __func__); - abort(); + /* We don't have a slot if we want to trap every access. */ + return 0; } return kvm_slot_update_flags(kml, mem, section->mr); @@ -470,8 +470,8 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, if (size) { mem = kvm_lookup_matching_slot(kml, start_addr, size); if (!mem) { - fprintf(stderr, "%s: error finding slot\n", __func__); - abort(); + /* We don't have a slot if we want to trap every access. */ + return 0; } /* XXX bad kernel interface alert From patchwork Wed Oct 18 16:12:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FOZAeCL5"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHQG5X1Jz9sBd for ; Thu, 19 Oct 2017 03:22:12 +1100 (AEDT) Received: from localhost ([::1]:45488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r6f-0001rY-Cf for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:22:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyC-0003cJ-27 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyB-0002Go-94 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:24 -0400 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:54394) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyB-0002G0-37 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:23 -0400 Received: by mail-wr0-x22e.google.com with SMTP id o44so5582984wrf.11 for ; Wed, 18 Oct 2017 09:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=JhBHSWJhStEVLu8+gu9M06/OcL8RSZfqu8BC4X58VkI=; b=FOZAeCL5A089Tlgg84JKpn/C2Wsq0wuh35sClhGD3a+75DUCFV9HEBbcXOoTSbM6Wx x324SZdQFWi+aJBnKi9YC8JcOIQ57HXQyGU1OsaFi+LnSbd17Nt7GFR2ZvFYXxSQwXQe NgocQfNFv0DdUlnQu5ENe1Pk/xANzyPYPeTIGywxx7xcNFBAnPgTrFCkFUxpbd/l55F9 FsibTiH+3qQSFt9EV5eZtk6OTiMgxt5vjRPJ0VRRFcP20ep91b7pjw3B35KeMo9tke/q n0n65yHpRpl3ccXMuyu1a91hl8fY1qFD0UNCm8/hbwCT9hvBSijXUjzTqK7/G8i1vbgJ AyrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=JhBHSWJhStEVLu8+gu9M06/OcL8RSZfqu8BC4X58VkI=; b=TFYZW06itUeXup//JbStvR1BUtHvJpjpSZXVHPbDVgMTSdFjFkfldo4C9EK0mAkosD HlMb21vtjMdgnAM2F1TmvGWvnF0FZCtsjVhxl0nzxDCM3WIB02GnUdc0JizwsLjR+Mou K/U7cbTNh/5naVIZlQczoKFMWib2YbkzrAMdeFPJLWz3aF9AjqQb8J3WLTXMi//+ZNQu eaNuhRtShv+RqVjfYPETlhjbAR1P4eXbhOg6JPZg2HlMH2H5zxIsmBI2l4YVmxeKF2AC HovGxyTC/K02l4hVLy/U8cvX+nNtJOul5HbyAd4qDb4/D3IZMzuvFIhfFDcnX2KDOc5G oF6Q== X-Gm-Message-State: AMCzsaXM2u9JnTpmExrgqfYXCmYYJjIhYBlnrq8+45vpL5ZDF1EWzNIU SvLn4YALMfC2mn2Aa6O8IoelipJx X-Google-Smtp-Source: ABhQp+SLDYLfkdDj3yYK27E8y6h5U8HNhOPl2lncuLEZNGIAiEqTq4ydfBwPLcRddnbAPchdoWE1rg== X-Received: by 10.223.129.228 with SMTP id 91mr7628294wra.233.1508343201791; Wed, 18 Oct 2017 09:13:21 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:11 +0200 Message-Id: <1508343141-31835-20-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22e Subject: [Qemu-devel] [PULL 19/29] kvm: fix error message when failing to unregister slot X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand "overlapping" is a leftover, let's drop it. Signed-off-by: David Hildenbrand Message-Id: <20171016144302.24284-5-david@redhat.com> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index f5fa3e2..559c544 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -734,7 +734,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->memory_size = 0; err = kvm_set_user_memory_region(kml, mem); if (err) { - fprintf(stderr, "%s: error unregistering overlapping slot: %s\n", + fprintf(stderr, "%s: error unregistering slot: %s\n", __func__, strerror(-err)); abort(); } From patchwork Wed Oct 18 16:12:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Zqehz8v5"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHTT3QZNz9sBd for ; Thu, 19 Oct 2017 03:25:01 +1100 (AEDT) Received: from localhost ([::1]:45498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4r9P-00049Y-7o for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:24:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyG-0003gq-31 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyC-0002Hf-5o for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:28 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:48423) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyB-0002H0-Ut for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:24 -0400 Received: by mail-wm0-x243.google.com with SMTP id i124so10878405wmf.3 for ; Wed, 18 Oct 2017 09:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=lEeh+L3dg10p3y+9Itnphsu+fDCIsvCXUyVlDEImqa4=; b=Zqehz8v5DRoEzY6OOQhCBQWw9AY+JjOVmUbBMht2fxOhq9ecroUe38fgvqD2IaR+k1 mbV09BHWHVBPk82lj7cZYyezvtrh050f1dFW+xSOF/wbpYqAojsZZR1DiUDoW28F8ats AhKP9/OGLUgTSaYsPkeCiQ86571F5yIFMiStTr8WzmHBg3ghmL1hkUeFNBFq68jQgkKN BjH6JezoVsaoGGIazf6s2EF/hvCR3DpaaRZCxm4ZGBYnk8tEnJpOElA7BXN+bqMQhTmc nnu/ZS7KLp7amMvr7arqTNDjV4GYqObl1/y6UmfN7RjC6h9DO87J62JnsbBgFieMOJrW VqGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=lEeh+L3dg10p3y+9Itnphsu+fDCIsvCXUyVlDEImqa4=; b=AvdBxdNdh8xqbk/AmkvSGNqfKTYPn/wGHxllZ5JR6KS5PGLvY4KzZ2D9SDq3qqby2a +5AYgBXnO6IIANyKTWlj1ZmAwdULfSXLcohgK2rk8cJSjYCOjOR8hSdiaFtXoueUN7Br 2mbOvDYvhKdWc+bGk6TTi75D+cBVpGup3OpFd/R+aNQ/ODmpOpvFewl13cw817dNMFOS RnTZtAcYODil7RCXJVE2ZZiXPvNcBMImv/D2ay9xNL/juxA8So40BAPN10bQfLPzgFZ6 Wg6NOVQF3fk5b7Bny2av/zxhzgoLvHjsJZPgOxIC2beFfCLeN7fR3mdUhZWKA6pJEKkb 6gng== X-Gm-Message-State: AMCzsaXa4vFljUkLBLEbmk7Iy+Wo88s5a5Dv+L7JwTtrBXen4H2uW8/x GR130tHsfoBMw+FGJlVF8Gd6f27x X-Google-Smtp-Source: ABhQp+TjEL+hzvBPWVUQVr4/hIApr+nNlSN9UAkavMJ56y+gbge5YTM+Fs09VU1N45YEtWBykqXY2A== X-Received: by 10.28.97.194 with SMTP id v185mr7315194wmb.117.1508343202712; Wed, 18 Oct 2017 09:13:22 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:12 +0200 Message-Id: <1508343141-31835-21-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 20/29] kvm: region_add and region_del is not called on updates X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Attributes are not updated via region_add()/region_del(). Attribute changes lead to a delete first, followed by a new add. If this would ever not be the case, we would get an error when trying to register the new slot. Signed-off-by: David Hildenbrand Message-Id: <20171016144302.24284-6-david@redhat.com> Tested-by: Joe Clifford Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 559c544..2835bb3 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -721,8 +721,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram = memory_region_get_ram_ptr(mr) + section->offset_within_region + (start_addr - section->offset_within_address_space); - mem = kvm_lookup_matching_slot(kml, start_addr, size); if (!add) { + mem = kvm_lookup_matching_slot(kml, start_addr, size); if (!mem) { return; } @@ -741,12 +741,6 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, return; } - if (mem) { - /* update the slot */ - kvm_slot_update_flags(kml, mem, mr); - return; - } - /* register the new slot */ mem = kvm_alloc_slot(kml); mem->memory_size = size; From patchwork Wed Oct 18 16:12:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RFfq6Quf"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHc02yKbz9t3h for ; Thu, 19 Oct 2017 03:30:40 +1100 (AEDT) Received: from localhost ([::1]:45537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rEs-0005yR-Gm for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:30:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyE-0003f3-Dc for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyD-0002Ig-B5 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:26 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:46876) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyD-0002Hs-4k for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:25 -0400 Received: by mail-wr0-x242.google.com with SMTP id l1so5597054wrc.3 for ; Wed, 18 Oct 2017 09:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ucdXRXyTu5MLVExw/mJigWlp1rfO0jy71UIwhoYvtGo=; b=RFfq6QufuAdbw9o20ScZ+zhIiAhpJ41aEvvyOh4TL/N9JlRPXUMI3Nhxufhn6EU4OS AIqYcT8zrBM8sxxmnYKFC9tMA1VbRzDlgBHG7IheTzR/48gzFg+195JunKffZfv2f0/t VKtIDSRbnSblYIhRMsONrAxcqfWPylZRCrvtOEfXbwNpAoY+aafgRBoUuuZX70ZyYLHa vGXs5rffSDLs7YS+ybOIxw7CbbDlglxp4Z7WLqSPKGEwT9dbRvmFBtws1udi5VfAXpLN D4b+hqLVjxpyEtzhrs0vOJQJYipKNZOKtl/tWAgISHgTa5SZ/2vtfTjLmpa4pUewi5iO 30/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ucdXRXyTu5MLVExw/mJigWlp1rfO0jy71UIwhoYvtGo=; b=qQDFIj8NtJ8MYarkVl4eS77kgdEhc3Zbu1NGqJOSqPsp8whY0wQ6GXQUReFtvTLHVR 8+4uCmuxf9mOOCwr3r80N8/b8RcwDWzBm6O5Hdr6FMgpGZKjps6nkaLJLyBA70+3Lc+T xaDWRy4PCg1oS0HyBLFTqJ1WtTVgSOfMQZzMZk3SDMH7wDWfJ3kzY+7OXBPUZyYeP3rY TSIAzPcGoCUA1xffdFWLW7u4hBdj+tZKFV2O7LNkmOF7PbPxTLZDbenIkBReOOOUe8po UvkA6JyfjYZpDRXjD5srw2meXXj27rZyie13XTV7pJ/tO3pFnT7ZeIgYVgikvBs255KF Kr7g== X-Gm-Message-State: AMCzsaU0fI9GclYIvL78zU3VNIy68WT1vSGNZIgtotbZz7VgWU2wH2Vw viQ6zJRwOWGaZMnI/gAc/mOewUQv X-Google-Smtp-Source: ABhQp+TC1gsrJVyy6G2b5TmvM+T3dKH9kYv5Id8t9tVq6O30bw5fUkWLnKHA7xlg2bblfzoSq9zLOw== X-Received: by 10.223.134.84 with SMTP id 20mr7903141wrw.60.1508343203903; Wed, 18 Oct 2017 09:13:23 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:13 +0200 Message-Id: <1508343141-31835-22-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 21/29] kvm: simplify kvm_align_section() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Use ROUND_UP and simplify the code a bit. Signed-off-by: David Hildenbrand Message-Id: <20171016144302.24284-7-david@redhat.com> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 2835bb3..f290f48 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -197,26 +197,20 @@ static hwaddr kvm_align_section(MemoryRegionSection *section, hwaddr *start) { hwaddr size = int128_get64(section->size); - hwaddr delta; - - *start = section->offset_within_address_space; + hwaddr delta, aligned; /* kvm works in page size chunks, but the function may be called with sub-page size and unaligned start address. Pad the start address to next and truncate size to previous page boundary. */ - delta = qemu_real_host_page_size - (*start & ~qemu_real_host_page_mask); - delta &= ~qemu_real_host_page_mask; - *start += delta; + aligned = ROUND_UP(section->offset_within_address_space, + qemu_real_host_page_size); + delta = aligned - section->offset_within_address_space; + *start = aligned; if (delta > size) { return 0; } - size -= delta; - size &= qemu_real_host_page_mask; - if (*start & ~qemu_real_host_page_mask) { - return 0; - } - return size; + return (size - delta) & qemu_real_host_page_mask; } int kvm_physical_memory_addr_from_host(KVMState *s, void *ram, From patchwork Wed Oct 18 16:12:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Pei4Bptz"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHf01lhBz9t3h for ; Thu, 19 Oct 2017 03:32:24 +1100 (AEDT) Received: from localhost ([::1]:45545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rGY-0007BQ-Ct for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:32:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyF-0003fv-8r for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyE-0002Je-DI for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:27 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:49832) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyE-0002Iy-7B for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:26 -0400 Received: by mail-wr0-x243.google.com with SMTP id g90so5590900wrd.6 for ; Wed, 18 Oct 2017 09:13:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=u+z6IPa+UZ/0t4LvCVUDvAhWy9kYN+GJbCkGL/Ppdq0=; b=Pei4BptzT9RXmvRbxmxBKqJBxhnYNBQC3DTypiHg7Ucm7wEGwZtQ1pSlmQvgkMjjLV k5wsuVub1DeNvoMIpwk/qQKm7ioWYfNwpNrwP1x8mR8BneA1PO26mgwClvM6H2+gNAGC lhLBh1aNH4zoynu51i0VCbZPNSS5+a4M4oNKbfNn5a1fStxinl0Wl4UO4aMpDLDgol/N iRFdWX/cHWO51xp8y0QbUZ1Gk7ONGiiXkMYAjhz8sMqXLvqa4TS3PNISQ5lAWssfHT8A ZlE/eXV/4OYId1Auvgo/ueKKeCgNwFF6XmtXno6fZsiQmsW1toBAykl8J8kkrEp59MxZ 13tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=u+z6IPa+UZ/0t4LvCVUDvAhWy9kYN+GJbCkGL/Ppdq0=; b=nHEWs40qRZ2e4XrUZE9IlqFw1Rlb5eJ/Yqk2rS6tD1g1PzuTyyfsadTxewF9KdJZht WxsdDG+JZtTbIy0XScjyitu5e2e7o78vwb6JQIUCw0N92Hx+Fe5zCbMkB5IgD1xoj1CQ CBriBB9VvpLR02TeuSzMDROC8tEoyXIjm1fQGUNYGiVAf/EDkf/E/zSIni54oMHgscky NjDx6+plWb7+hnN2NUTkW5ETowuf7SYN4X6Xlmu6IWqTji7wV4SPFV3PnnM8WzoRalGx QR0mVS3mg5KVWRe0Cjf+OCJ2U+Ip7TAYLN9alcBh4nPDjq2RXYBEw794wBt4bAyYJJYf 4xeQ== X-Gm-Message-State: AMCzsaUt2FKPoMJOP376POgX2rAvSRoB6/3f5w8ls2f2PKqLEMoNZx1N zWeQGVvx61L15FyxHf65aN8NSmfB X-Google-Smtp-Source: ABhQp+S6wW4+JsAPPjZKrCOGmHd6ky6KbGH6ll99884/w3NXERskFK/chV76y4oH2t5z6F7LAAeFaw== X-Received: by 10.223.130.194 with SMTP id 60mr7866001wrc.168.1508343204949; Wed, 18 Oct 2017 09:13:24 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:14 +0200 Message-Id: <1508343141-31835-23-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PULL 22/29] memory: reuse section_from_flat_range() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We can use section_from_flat_range() instead of manually initializing. Signed-off-by: David Hildenbrand Message-Id: <20171016144302.24284-8-david@redhat.com> Signed-off-by: Paolo Bonzini --- memory.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/memory.c b/memory.c index 3e1558a..e26e5a3 100644 --- a/memory.c +++ b/memory.c @@ -2599,14 +2599,8 @@ static void listener_add_address_space(MemoryListener *listener, view = address_space_get_flatview(as); FOR_EACH_FLAT_RANGE(fr, view) { - MemoryRegionSection section = { - .mr = fr->mr, - .fv = view, - .offset_within_region = fr->offset_in_region, - .size = fr->addr.size, - .offset_within_address_space = int128_get64(fr->addr.start), - .readonly = fr->readonly, - }; + MemoryRegionSection section = section_from_flat_range(fr, view); + if (listener->region_add) { listener->region_add(listener, §ion); } From patchwork Wed Oct 18 16:12:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="H7+GxJvg"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHkV0S2Kz9t3h for ; Thu, 19 Oct 2017 03:36:18 +1100 (AEDT) Received: from localhost ([::1]:45561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rKK-0001nk-0U for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:36:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyK-0003mF-Sn for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyF-0002KO-CU for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:32 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:43205) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyF-0002Jo-5h for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:27 -0400 Received: by mail-wr0-x244.google.com with SMTP id p46so5598582wrb.0 for ; Wed, 18 Oct 2017 09:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=xQkevP55ChWBa/a7K0986jznmGSkPZwnb+jIGGxp/x0=; b=H7+GxJvgouh5TdCjoadjoo++orQWFOGxWJsvjiEXWpI/RXFMw8Hwi+x715dVwmRehs 1dbcjrAJaQ3Y1KQwzEVhN54rSUTTQgx+yLwx4cPlPGycASpjjTrpEdtiT7tEwv+HwmJW mw5P4sg+LGJtsQNOvxXHm6ZQsj2f1LhgyhuipnrfoBRgfpNdwouyDZiG6Iy+VkkmelJi A0VmseW+IfaT1mcjOA0krcg+RxIIWnY8gXOXseZf+n9orVv7PPqGKmK7MoyWuz5VNVFX KRQBJuo0uOr3Q9pd34sLUdgqZnoypqthhTyYsoDCKyOg9EI+0LuXY+JsIZ9AlJdKHB+p hKPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=xQkevP55ChWBa/a7K0986jznmGSkPZwnb+jIGGxp/x0=; b=c9fN5TMYgmI4KzzR21FVLtpBqEbwOhgDh2wL2JEe9ddmLGD4hB9+hK2vIquvTKevzH g6DWxFD3IwynlFe8U1VuY35jM2LuKk0IoI/x030Gza8l5QoRfVAk2nXwCRyGdwojWWX8 jtDzrHBYmBpht3gGjKaMDVOpS6UEA0evt2Jf5/myTlVH2RpPAjt/bi+of0i6h4mJp9E8 uOpTLAQCsIklC03jGfyKJOxd6m1MmyCxbD49+g7E6rod+Hl3ICb90oY+dWUT0wQueAhs tLl4u/gaDg4kRQT9d80VBPTI2BIqWs0gdQK80zETZAz9aL0Zn2uaNHZfTiwJGqz8whK8 T3zg== X-Gm-Message-State: AMCzsaVp4oibadYAiRk/Jq7yj5WhgwWnbkms4uNGBXj14Ba+xEbLPoRH QBP7ANwTpoIrtUA7F+kDMEBDQIJz X-Google-Smtp-Source: ABhQp+Qfx5+3rR8ITxwyw5Vq4b33QQ0VGZKCxae1KuNVB/FSy/sZ5HVS/YHG5nnLQVw574qUZnoNfQ== X-Received: by 10.223.198.82 with SMTP id u18mr7668379wrg.5.1508343205902; Wed, 18 Oct 2017 09:13:25 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:15 +0200 Message-Id: <1508343141-31835-24-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PULL 23/29] notdirty_mem_write: implement 8-byte accesses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Baumann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Andrew Baumann Aligned 8-byte memory writes by a 64-bit target on a 64-bit host should always turn into atomic 8-byte writes on the host, however if we missed in the softmmu, and the TLB line was marked as not dirty, then we would end up tearing the 8-byte write into two 4-byte writes in access_with_adjusted_size(). Signed-off-by: Andrew Baumann Message-Id: <20171013181913.7556-1-Andrew.Baumann@microsoft.com> Signed-off-by: Paolo Bonzini --- exec.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/exec.c b/exec.c index 6579e7a..b58bc4e 100644 --- a/exec.c +++ b/exec.c @@ -2376,6 +2376,9 @@ static void notdirty_mem_write(void *opaque, hwaddr ram_addr, case 4: stl_p(qemu_map_ram_ptr(NULL, ram_addr), val); break; + case 8: + stq_p(qemu_map_ram_ptr(NULL, ram_addr), val); + break; default: abort(); } @@ -2406,6 +2409,16 @@ static const MemoryRegionOps notdirty_mem_ops = { .write = notdirty_mem_write, .valid.accepts = notdirty_mem_accepts, .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 1, + .max_access_size = 8, + .unaligned = false, + }, + .impl = { + .min_access_size = 1, + .max_access_size = 8, + .unaligned = false, + }, }; /* Generate a debug exception if a watchpoint has been hit. */ From patchwork Wed Oct 18 16:12:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DoVTv5Ao"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHXd6nyCz9t5s for ; Thu, 19 Oct 2017 03:27:45 +1100 (AEDT) Received: from localhost ([::1]:45515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rC4-0006rK-0F for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:27:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyJ-0003kP-B6 for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyG-0002L3-Ez for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:31 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:44429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyG-0002Kc-8v for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:28 -0400 Received: by mail-wm0-x244.google.com with SMTP id 196so13113553wma.1 for ; Wed, 18 Oct 2017 09:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=RWsqiWoA5iSNMDibtMF1R35fOUZ5R+O+SSe3WXMzmpw=; b=DoVTv5Aokgzgllf+ihQ4afpwgVxB0mz4PqD9C26iuvtl/DMzW9p7GFLiCfRcYEg+jF fFUk/bLD0vG0cbFRYjO69+HXIYvVfPAlYdqjRtMOmRnoXXi1MpJVWiKAyHfR6S2jhL9h ImJYGBZQicecnxKNfsU56QKy3SeaGTNBPdNhi+NgQvC8QlxEHIwOVElbuzEJhTXHui6R xT6tEaFAPcoA5s8OBYijcQyMYmf85h5Dwf41o2kmVttteIBU+kPA+QSHG8ti7iKoX3BU +ugZQw0yILe7L2R0FWjMUN9NnX7UGWh9/rXnCPN5IJ6eljrKVE1ZzM4jPztUgnG/krrO c5vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=RWsqiWoA5iSNMDibtMF1R35fOUZ5R+O+SSe3WXMzmpw=; b=kHR7ZGeOeQNvuqrrAm8xsxWBy+aOyKr42OpIjyENyTElVvzDXwtlC4GIVGCvUFuz6e 2iYtabFJtSIGh6j8e6bYp+Y89qj5LSzWD4eVdkRNEucAdrTcAVk96XuZ8utatOf5cXA/ 1yauP7o5yxV8kzp+8GzAuPcQ+kvCjtwhq2CdrczqX6CKKX1soNJw+WCNngQayaPszGhv JDd/zuAAgudNUXz5bujWfgpjwxFMR1fn8SCFI8KIbGTOY8rE+PjUtJLrD6DQBcrXtROU zaEaxXynoI5kkdsgufhyTChYlBiFUU+Dv0Gv5XmVcDgYdvQUgpqHZzh7j+GIH6HHTgLE 7F0Q== X-Gm-Message-State: AMCzsaWYXCHoef1hIB6cypRGwxrFMMOUxO/qQy2ZbSBqZj7G4WsN8/IQ L9AIaQ6x1H84K7hnZxRstFut0PEB X-Google-Smtp-Source: ABhQp+Qcp1hwj0ajkJKSpb2a+y1YAEvX97NNhV4wlReoBWM+AnR9awefmf8G1E7r1SvMJrugI/EThQ== X-Received: by 10.28.113.212 with SMTP id d81mr7419052wmi.152.1508343206992; Wed, 18 Oct 2017 09:13:26 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:16 +0200 Message-Id: <1508343141-31835-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 24/29] watch_mem_write: implement 8-byte accesses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Aligned 8-byte memory writes by a 64-bit target on a 64-bit host should always turn into atomic 8-byte writes on the host, however a write write watchpoint would end up tearing the 8-byte write into two 4-byte writes in access_with_adjusted_size(). Reported-by: Andrew Baumann Signed-off-by: Paolo Bonzini --- exec.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/exec.c b/exec.c index b58bc4e..db5ae23 100644 --- a/exec.c +++ b/exec.c @@ -2503,6 +2503,9 @@ static MemTxResult watch_mem_read(void *opaque, hwaddr addr, uint64_t *pdata, case 4: data = address_space_ldl(as, addr, attrs, &res); break; + case 8: + data = address_space_ldq(as, addr, attrs, &res); + break; default: abort(); } *pdata = data; @@ -2528,6 +2531,9 @@ static MemTxResult watch_mem_write(void *opaque, hwaddr addr, case 4: address_space_stl(as, addr, val, attrs, &res); break; + case 8: + address_space_stq(as, addr, val, attrs, &res); + break; default: abort(); } return res; @@ -2537,6 +2543,16 @@ static const MemoryRegionOps watch_mem_ops = { .read_with_attrs = watch_mem_read, .write_with_attrs = watch_mem_write, .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 1, + .max_access_size = 8, + .unaligned = false, + }, + .impl = { + .min_access_size = 1, + .max_access_size = 8, + .unaligned = false, + }, }; static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, From patchwork Wed Oct 18 16:12:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CXkfvzbS"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHgg6XQmz9t3h for ; Thu, 19 Oct 2017 03:33:51 +1100 (AEDT) Received: from localhost ([::1]:45550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rHx-00005l-S4 for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:33:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyJ-0003kS-BU for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyH-0002Lk-EH for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:31 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:47837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyH-0002LH-7k for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:29 -0400 Received: by mail-wm0-x241.google.com with SMTP id t69so10986885wmt.2 for ; Wed, 18 Oct 2017 09:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=Ep4GtLNcB5wAitNxgiGlY5UKMCUBYHsaT3f7Yd8HOJc=; b=CXkfvzbS9m1kXZnwAsy9Td1KXESljZVn09VqxATZRAaRJgxDVneWw6L/BhmahTqLej /NFnQhoUaOvM12UjrTyKeoKqLkhdg6Kyf7VG4OFBjp/PxZxKq1dODsIPSQuco5yB8wVT S/cH+5YtoyDkKk4g1TXJJC2hhyqOKbccWnYkodPxgeBLtyyuULOMh+tVzu+T2djpDHVv C3WQTmFxmzPDe6u2zbE5bQypTtWsul4BvoowjJL3HpMeItt0M1Sm97ylDSqBIktQzQKV B/WB4rmZdWNX9XK1vnQCHO8jgGsG/919fBVCv9V1BAgnBBvPo7lhnHHvH25Bn2z0cO1Q 5UTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=Ep4GtLNcB5wAitNxgiGlY5UKMCUBYHsaT3f7Yd8HOJc=; b=JoUuJjqnCkFoR8oJUDSh1cuERl7KyIOGtk3qTIzndx6w637XIk4dO8A1gAfvV8kFJ+ xURTaVVSCbzeiNgvVtnIo21LoRX+sPpggzikunfpzusctHRDGqwsT8SRC55E/YvdDQRR heE/nZgXgGIYhG6m55VJd8kKAsO3bifvMdrsxcTY3cMSsd4GgXxvQ81UE13dj0HpGACq Dnor6Fm6TDnhzAle5Oi2NYS8VCu14ddZjvB0KBY9mgKZR/ODcvAdKY8n/ZZaxSOZ4tNO ZObAGPjxTDZgP8aHBTeuQxuZZZfcQK5CmdR7VUrBVcHgVZkvduTskR5+lbh+NIRrb1bQ 3iqQ== X-Gm-Message-State: AMCzsaXpl2JuO5MIVxjT0BC3IXJSTIC4BU/A/s/YFbmRJFEewDRjKb5n i5joQj5K63U3doOlEOjx0yLvxdQk X-Google-Smtp-Source: ABhQp+QYV6oOBXe2s79d7dLvwXMJZU0xdnL62woSLnz5LvGFeN7ZB7Nw+ptX4gOHYXJT/pJAd0fIVQ== X-Received: by 10.28.207.130 with SMTP id f124mr7600584wmg.88.1508343208006; Wed, 18 Oct 2017 09:13:28 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:17 +0200 Message-Id: <1508343141-31835-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 25/29] qemu-pr-helper: use new libmultipath API X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" libmultipath has recently changed its API. The new API supports multi-threaded clients better. Unfortunately there is no backwards-compatibility, so we just switch to the new one. Running QEMU compiled with the new library on the old library will likely crash, while doing the opposite will cause QEMU not to start at all (because udev, get_multipath_config and put_multipath_config are undefined). Signed-off-by: Paolo Bonzini --- configure | 12 ++++++++++-- scsi/qemu-pr-helper.c | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/configure b/configure index 6587e80..7766e74 100755 --- a/configure +++ b/configure @@ -3312,9 +3312,17 @@ if test "$mpath" != "no" ; then #include unsigned mpath_mx_alloc_len = 1024; int logsink; +static struct config *multipath_conf; +extern struct udev *udev; +extern struct config *get_multipath_config(void); +extern void put_multipath_config(struct config *conf); +struct udev *udev; +struct config *get_multipath_config(void) { return multipath_conf; } +void put_multipath_config(struct config *conf) { } + int main(void) { - struct udev *udev = udev_new(); - mpath_lib_init(udev); + udev = udev_new(); + multipath_conf = mpath_lib_init(); return 0; } EOF diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index d581848..dd97851 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -276,15 +276,26 @@ static void dm_init(void) /* Variables required by libmultipath and libmpathpersist. */ QEMU_BUILD_BUG_ON(PR_HELPER_DATA_SIZE > MPATH_MAX_PARAM_LEN); +static struct config *multipath_conf; unsigned mpath_mx_alloc_len = PR_HELPER_DATA_SIZE; int logsink; +struct udev *udev; -static void multipath_pr_init(void) +extern struct config *get_multipath_config(void); +struct config *get_multipath_config(void) { - static struct udev *udev; + return multipath_conf; +} +extern void put_multipath_config(struct config *conf); +void put_multipath_config(struct config *conf) +{ +} + +static void multipath_pr_init(void) +{ udev = udev_new(); - mpath_lib_init(udev); + multipath_conf = mpath_lib_init(); } static int is_mpath(int fd) From patchwork Wed Oct 18 16:12:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827741 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rI95fUi4"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHj60xLlz9t3h for ; Thu, 19 Oct 2017 03:35:06 +1100 (AEDT) Received: from localhost ([::1]:45553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rJA-000119-8I for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:35:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyK-0003le-BX for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyI-0002Ms-Rh for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:32 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:47837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyI-0002MR-Jl for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:30 -0400 Received: by mail-wm0-x243.google.com with SMTP id t69so10986970wmt.2 for ; Wed, 18 Oct 2017 09:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=tk2Fs/9zmKUDCr8hdo0/S9ySET54dJRzEl/OO9z8Yho=; b=rI95fUi4j5Aqwtchw+9QO1sVfsvVHUtpfQs7LrTOEpy9mWsY1QMmVbhHKD+SWyE3fU xMB9Z0SsZ4EgIq6KNNQwgCWiMiN0q5vyXbcOPRFBBpJ5UCCOmWNR5RLLbR061wuqmP71 O1gKTfvxT9njnmbludN6zAfgkqnwlNKVrexycpJ9L04BtZA32tsq3alao5hEEJgY54ZM 0SRCTMrs+p8d4AJnatFCCQSo/R4uNCeztrSLpbZpxukpNxK5A9cuRKvJq1MrkNcWZiiH vI7jyz1BdxmdwnUxioxlxCAMfSp1jxY+fHDVen5ivf8YjZtNhWjblk1Y9MpO5LGondOx Jptg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=tk2Fs/9zmKUDCr8hdo0/S9ySET54dJRzEl/OO9z8Yho=; b=r2Ps3RkAFroh3Gle23Kn0VZ6aQl+xtkbChZK1Bug53dWlQMXAkaMiECvJ4KpKVKTVN 7W+qhatk7ZTp6DZIYZOTtiWKnCG0XLtQYkGbik88s2nqEbYmteWTs3YJiU2NHnmR4n2O Gvz0j2Ia/eBiBdp/b85r7wLWZPqsdn/38lnbdJVN+yPX6rMeMmTyExk5Z2LxSl8PagWX aM0ond62bUEEqXKLxR+HCgHlRMle0ajoH3FH5uGQDLfEDwb80zzRxpfETJPAky1BA0lK LMpoT4/Zqc1hPaEqocwmyqgz6JjkltHzBJCAkFGRLTrSY4xl8FffPHa3Ruer2h7mehC4 6t/g== X-Gm-Message-State: AMCzsaWSE9hy9JnaBHzwiLBgP4dQQIH6jJU9rKSu/hc2qSqEu5E2k1kD xltGnGipdMmTACNNqKy21GMV08Cy X-Google-Smtp-Source: ABhQp+Q3AJwKTWoX9QQnGlmkjKUxJCbVw2LdCtniEVgprdSCSMbU+spmJKBOAPcWIx7/Oe/No9PCvA== X-Received: by 10.28.149.204 with SMTP id x195mr7037788wmd.78.1508343209341; Wed, 18 Oct 2017 09:13:29 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:18 +0200 Message-Id: <1508343141-31835-27-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 26/29] qdev: store DeviceState's canonical path to use when unparenting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz , Michael Roth , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Roth device_unparent(dev, ...) is called when a device is unparented, either directly, or as a result of a parent device being finalized, and handles some final cleanup for the device. Part of this includes emiting a DEVICE_DELETED QMP event to notify management, which includes the device's path in the composition tree as provided by object_get_canonical_path(). object_get_canonical_path() assumes the device is still connected to the machine/root container, and will assert otherwise, but in some situations this isn't the case: If the parent is finalized as a result of object_unparent(), it will still be attached to the composition tree at the time any children are unparented as a result of that same call to object_unparent(). However, in some cases, object_unparent() will complete without finalizing the parent device, due to lingering references that won't be released till some time later. One such example is if the parent has MemoryRegion children (which take a ref on their parent), who in turn have AddressSpace's (which take a ref on their regions), since those AddressSpaces get cleaned up asynchronously by the RCU thread. In this case qdev:device_unparent() may be called for a child Device that no longer has a path to the root/machine container, causing object_get_canonical_path() to assert. Fix this by storing the canonical path during realize() so the information will still be available for device_unparent() in such cases. Cc: Michael S. Tsirkin Cc: Paolo Bonzini Signed-off-by: Michael Roth Signed-off-by: Greg Kurz Signed-off-by: Michael Roth Tested-by: Eric Auger Reviewed-by: David Gibson Message-Id: <20171016222315.407-2-mdroth@linux.vnet.ibm.com> [Clear dev->canonical_path at the post_realize_fail label, which is cleaner. Suggested by David Gibson. - Paolo] Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 17 ++++++++++++++--- include/hw/qdev-core.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 606ab53..0019a49 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -928,6 +928,13 @@ static void device_set_realized(Object *obj, bool value, Error **errp) goto post_realize_fail; } + /* + * always free/re-initialize here since the value cannot be cleaned up + * in device_unrealize due to its usage later on in the unplug path + */ + g_free(dev->canonical_path); + dev->canonical_path = object_get_canonical_path(OBJECT(dev)); + if (qdev_get_vmsd(dev)) { if (vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev, dev->instance_id_alias, @@ -984,6 +991,8 @@ child_realize_fail: } post_realize_fail: + g_free(dev->canonical_path); + dev->canonical_path = NULL; if (dc->unrealize) { dc->unrealize(dev, NULL); } @@ -1102,10 +1111,12 @@ static void device_unparent(Object *obj) /* Only send event if the device had been completely realized */ if (dev->pending_deleted_event) { - gchar *path = object_get_canonical_path(OBJECT(dev)); + g_assert(dev->canonical_path); - qapi_event_send_device_deleted(!!dev->id, dev->id, path, &error_abort); - g_free(path); + qapi_event_send_device_deleted(!!dev->id, dev->id, dev->canonical_path, + &error_abort); + g_free(dev->canonical_path); + dev->canonical_path = NULL; } qemu_opts_del(dev->opts); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 0891461..0a71bf8 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -153,6 +153,7 @@ struct DeviceState { /*< public >*/ const char *id; + char *canonical_path; bool realized; bool pending_deleted_event; QemuOpts *opts; From patchwork Wed Oct 18 16:12:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hmVf9PMH"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHlz1Wcyz9t3h for ; Thu, 19 Oct 2017 03:37:35 +1100 (AEDT) Received: from localhost ([::1]:45567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rLZ-0002cl-BZ for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:37:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyL-0003mV-4O for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyJ-0002Nb-Rg for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:33 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:52865) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyJ-0002N0-LT for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:31 -0400 Received: by mail-wm0-x242.google.com with SMTP id k4so11170990wmc.1 for ; Wed, 18 Oct 2017 09:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dyq7PVjTcPTpCpet7JydeWQ/uQ50XAyGbQOgtFoFXkg=; b=hmVf9PMHX451SeRuP8NWjdPJWrz1MkUC3jKWKbdWl52f+RH5xeodTdJCY9hhhr+P4h eSiGD5r9yKR9eM4TVIeVKPzuDtlltqbhpg1agAhKVPVa7JcYhfyj7QmDYanZ9JsSRfVO ncTgJQDTOUy0p0hkLk5H0lixWSEgDNDT7sThpQ6DgKOBMQY5SuKP17cvcA/q1NI5jzZj Ketv0KYeP7lv6l8BlTRbn6rN6vFDc0fbEFPU5Yz60VfnEMUz/es0F6zlBm5EXwoZ5pze 8lqFgE6QR07BZnw1V6RBPz3/N9ELqr7Thtcb9warRdm0BvJ+9k+f6QITB2dnYLQOLhNu 1aKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dyq7PVjTcPTpCpet7JydeWQ/uQ50XAyGbQOgtFoFXkg=; b=hwVL6a7QLteXk2EzhzfeGb2e5y3/774qVj2CagoJ2rnXRjoWHKZB8Wes7E0jd5+rtp 8WDHuSgnoIPkDAdDKOkm+Y4H0zpVJ1LXWo1keHsKFtaWP8QUyw1QqQxMZq5EmY41lmmB 7MNfV2SV3aj4DK6vYPTVB2pHPSixjg31wokH+UmXc4IVHE1qm44TEIN/fWhUEr9bvZF4 hxujHEI48AQGCX8XYqs9vWIPAQPu7hZX1Lg1w2jvIHo0WcnlbYzHlhj/nZ9EcfwABEeM FJwgr483xwrs6EQFu6H9p6twUYLKb7oOEHFJxqvxRWJxfxn2M5iDIVW3xg7H3jcg2KH/ RiTQ== X-Gm-Message-State: AMCzsaWss6WzbCHmdAfQEB+f4+hNuT6XjUUux74uaLSaiCwLH1wX/kw/ 4AsrCOcAUB4w8wyeFCp4n/PB2r7F X-Google-Smtp-Source: ABhQp+RPOIaMrxkFuCbomwMXxOROkCyL0AbcnCYbaeGmVAdEk4VoB16TJbQuyINSPO/9s+dQp0jbRQ== X-Received: by 10.28.210.72 with SMTP id j69mr7233702wmg.75.1508343210300; Wed, 18 Oct 2017 09:13:30 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:19 +0200 Message-Id: <1508343141-31835-28-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PULL 27/29] Revert "qdev: Free QemuOpts when the QOM path goes away" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Roth This reverts commit abed886ec60cf239a03515cf0b30fb11fa964c44. This patch originally addressed an issue where a DEVICE_DELETED event could be emitted (in device_unparent()) before a Device's QemuOpts were cleaned up (in device_finalize()), leading to a "duplicate ID" error if management attempted to immediately add a device with the same ID in response to the DEVICE_DELETED event. An alternative will be implemented in a subsequent patch where we defer the DEVICE_DELETED event until device_finalize(), which would also prevent the race, so we revert the original fix in preparation. Signed-off-by: Michael Roth Reviewed-by: Greg Kurz Tested-by: Eric Auger Reviewed-by: David Gibson Message-Id: <20171016222315.407-3-mdroth@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 0019a49..418cdac 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -1069,6 +1069,7 @@ static void device_finalize(Object *obj) NamedGPIOList *ngl, *next; DeviceState *dev = DEVICE(obj); + qemu_opts_del(dev->opts); QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_REMOVE(ngl, node); @@ -1118,9 +1119,6 @@ static void device_unparent(Object *obj) g_free(dev->canonical_path); dev->canonical_path = NULL; } - - qemu_opts_del(dev->opts); - dev->opts = NULL; } static void device_class_init(ObjectClass *class, void *data) From patchwork Wed Oct 18 16:12:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hBdRx+BT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHZx5kM7z9t4c for ; Thu, 19 Oct 2017 03:29:45 +1100 (AEDT) Received: from localhost ([::1]:45525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rDz-0004Lx-Sd for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:29:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyL-0003nD-UN for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyK-0002OL-Qe for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:33 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:47837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyK-0002Nj-Jp for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:32 -0400 Received: by mail-wm0-x244.google.com with SMTP id t69so10987129wmt.2 for ; Wed, 18 Oct 2017 09:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dWMFHlsyz+SdFl9nzqDk9kAeT6KDC42jxcHpOQNeqO8=; b=hBdRx+BTae+d5fHpR11MwRbnfjCxkemrgpuxsJcZ9+pvZvIcFmpFChoCB3166RMmuo Lq6FIu0uph13dYyj3E2oKOIxShdEB2aBfpG4oD7vDzxbylnRzCwYycIbqKBVJSaALJwd vXLlcyyElUynWaU2Ak7D47KOl1RhZ8lsUrcM096b0O2JSXxBfvr19leQicpX2NaPf7kf AJYHi6p9XQ1ml7ukJ4MM1ulemBkx+wlwpOvG5xFANCW0f77SgB7dXZNfnzxY9WUUInEA mfjSDP0oPnbdhWpvT2OYdEIW/F8pkHF1r0gs6B7vk5Io4hOWgqW/gvVLbnWC1zm7p2Kg VfHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dWMFHlsyz+SdFl9nzqDk9kAeT6KDC42jxcHpOQNeqO8=; b=Vk/bvhmXqt8HYuhdJlKtIYy//y/8CuScMg3h68+ImY1OCdFjPHPNA/vkj1KaQjMmJC sgOS4mWLDWemMRKQnZLc70a6JMM4nPqb+B19Yt15Ur0Rd1AbTmWmYxfKiRIKw0oRJPNv Ny22UdxWTp/UhySoJ16KR3vRyGdAp9FH6Ub+PYLBbmC44iX6DwpfULXMoEQUmPUk7bQQ HtKevJpE0LLicwvCeFyvPRD8yjBU5Y0QOx4hWoMDig6EMEjjtPnytz+szUiwpMR7if2J N1ttfxiwOqohG831oqY/gTssiND1Gdz8s8NCjGgE8Y6xkG9PsNWpUVI2RXym8CO2+RuE 84oA== X-Gm-Message-State: AMCzsaW0+eDQZAbV64GeGO/ssuUOTbIwWKnYq/J97tqEUlISQqB6TpsT XO25DjJRzll4VL4LBLuTjq0KrXiK X-Google-Smtp-Source: ABhQp+T5RZrcxGEaSWyUGgKsY4OkdNDLrajJjkMKSzb3iRNEKXmCwZivGUpxDZPHczrrNaoVCyj3gg== X-Received: by 10.28.199.75 with SMTP id x72mr7244345wmf.119.1508343211356; Wed, 18 Oct 2017 09:13:31 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:20 +0200 Message-Id: <1508343141-31835-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 28/29] qdev: defer DEVICE_DEL event until instance_finalize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Roth DEVICE_DEL is currently emitted when a Device is unparented, as opposed to when it is finalized. The main design motivation for this seems to be that after unparent()/unrealize(), the Device is no longer visible to the guest, and thus the operation is complete from the perspective of management. However, there are cases where remaining host-side cleanup is also pertinent to management. The is generally handled by treating these resources as aspects of the "backend", which can be managed via separate interfaces/events, such as blockdev_add/del, netdev_add/del, object_add/del, etc, but some devices do not have this level of compartmentalization, namely vfio-pci, and possibly to lend themselves well to it. In the case of vfio-pci, the "backend" cleanup happens as part of the finalization of the vfio-pci device itself, in particular the cleanup of the VFIO group FD. Failing to wait for this cleanup can result in tools like libvirt attempting to rebind the device to the host while it's still being used by VFIO, which can result in host crashes or other misbehavior depending on the host driver. Deferring DEVICE_DEL still affords us the ability to manage backends explicitly, while also addressing cases like vfio-pci's, so we implement that approach here. An alternative proposal involving having VFIO emit a separate event to denote completion of host-side cleanup was discussed, but the prevailing opinion seems to be that it is not worth the added complexity, and leaves the issue open for other Device implementations to solve in the future. Signed-off-by: Michael Roth Reviewed-by: Greg Kurz Tested-by: Eric Auger Reviewed-by: David Gibson Message-Id: <20171016222315.407-4-mdroth@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 418cdac..1111295 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -1069,7 +1069,6 @@ static void device_finalize(Object *obj) NamedGPIOList *ngl, *next; DeviceState *dev = DEVICE(obj); - qemu_opts_del(dev->opts); QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_REMOVE(ngl, node); @@ -1080,6 +1079,18 @@ static void device_finalize(Object *obj) * here */ } + + /* Only send event if the device had been completely realized */ + if (dev->pending_deleted_event) { + g_assert(dev->canonical_path); + + qapi_event_send_device_deleted(!!dev->id, dev->id, dev->canonical_path, + &error_abort); + g_free(dev->canonical_path); + dev->canonical_path = NULL; + } + + qemu_opts_del(dev->opts); } static void device_class_base_init(ObjectClass *class, void *data) @@ -1109,16 +1120,6 @@ static void device_unparent(Object *obj) object_unref(OBJECT(dev->parent_bus)); dev->parent_bus = NULL; } - - /* Only send event if the device had been completely realized */ - if (dev->pending_deleted_event) { - g_assert(dev->canonical_path); - - qapi_event_send_device_deleted(!!dev->id, dev->id, dev->canonical_path, - &error_abort); - g_free(dev->canonical_path); - dev->canonical_path = NULL; - } } static void device_class_init(ObjectClass *class, void *data) From patchwork Wed Oct 18 16:12:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 827729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EQBlCPwT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHHVh670Sz9sBd for ; Thu, 19 Oct 2017 03:26:04 +1100 (AEDT) Received: from localhost ([::1]:45508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4rAP-00059H-H6 for incoming@patchwork.ozlabs.org; Wed, 18 Oct 2017 12:26:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4qyM-0003o2-KE for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4qyL-0002P1-OX for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:34 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:56826) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4qyL-0002OY-IF for qemu-devel@nongnu.org; Wed, 18 Oct 2017 12:13:33 -0400 Received: by mail-wm0-x234.google.com with SMTP id l68so11141825wmd.5 for ; Wed, 18 Oct 2017 09:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EXiE3rgF6oCR2xcKCJ7ddKHCNihNHTfi/21E8EA/Mho=; b=EQBlCPwT1wXoD/7pmfaE4z6fFBcXqvgGJMd4SlVuXu/ehVVfyyO0mFwLT8nm+IzFI1 7s7WgTtWK+4odRyMDuJS8KJVzhTXbmv6fyiTFpckNVTBBMRkR73z4enmX/mfQR4/UzZ8 0UnqGHvvxxIbnmrq5BXU7NWa8ZLpU/kmGxGAPJ+KrO6ir3Uw+PcpkyGD4+5/Xd5jCy2h 4CJSvUfyYaLHmVmtDIT3mPd1cgGcQh4UtEmxb8skVX1V92Uge6l9oJ+jphA8w+BPreN2 izFaPQEmhGwbsuI+2skdbMXFcVL5sNzp41vnsaReYzPTUWo8o7X2tndkw3bJ/oCZrIxS qK0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EXiE3rgF6oCR2xcKCJ7ddKHCNihNHTfi/21E8EA/Mho=; b=H93MzYoCYTkJZmxJqqSZEEstxR4NmMEwk85AkctMQtfelaFsfiU+ykRjGy5WVYIaRm PmZIkFSaapqeFNc/EaPPWPhrDRhG4NWWXhqBynqXAaRa+4sy2kKkZWnAY5i5Oq33dbON mNQJXfGrAtJUXtBWQNJOHdHol3aAsDuyTV4/cFH23kEx/6Tp6BFI2NTuEXReS3L2Z3ME AYuPB9u3tjiyj3OH0wgrrB5yrizLMupY1Vk6V0HXZroiiUJnJ7rFUd+OEQpYQ95n9MTO Zw10OsWAvfFBEQMHNO2/JTuPkPGocrBlVifUi9tKCfa1U+ln7wsvkWNipw6THgjxMUGA bjug== X-Gm-Message-State: AMCzsaVki+lq1BSrp9HwZ2s2B4z2RUEN6sRRgpvsdIdl0Q8OtynNdgKv ZP+fBYcr/7bYIKcDXXmYPXvAR2WS X-Google-Smtp-Source: ABhQp+Q9Vul2FqapuprWjBwbBdiHo39k19dkihXLzBICSIr2g6MH1YVp2M0aJKJvbRGtngxmy5ykCA== X-Received: by 10.28.67.133 with SMTP id q127mr7374232wma.71.1508343212337; Wed, 18 Oct 2017 09:13:32 -0700 (PDT) Received: from 640k.lan (94-39-155-245.adsl-ull.clienti.tiscali.it. [94.39.155.245]) by smtp.gmail.com with ESMTPSA id 69sm13436794wmm.2.2017.10.18.09.13.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 09:13:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Oct 2017 18:12:21 +0200 Message-Id: <1508343141-31835-30-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> References: <1508343141-31835-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [PULL 29/29] scsi: reject configurations with logical block size > physical block size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Kanda Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Kanda Logical block size of a SCSI disk should never be larger than physical block size. From an ATA/SCSI perspective, it makes no sense to have the logical block size greater than the physical block size, and it cannot even be effectively expressed in the command set. The whole point of adding the physical block size to the ATA/SCSI command set was to communicate a desire for a larger block size (than logical), while maintaining backwards compatibility with legacy 512 byte block size. When setting logical_block_size > physical_block_size, QEMU cannot express it in READ CAPACITY(16) output, and all it can do is set the physical block exponent to 0 (i.e. logical_block_size == physical_block_size). Reporting the error properly, however, is better. Signed-off-by: Mark Kanda Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Martin K. Petersen Message-Id: <1508185024-5840-1-git-send-email-mark.kanda@oracle.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index a518080..1243117 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2347,6 +2347,14 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) blkconf_serial(&s->qdev.conf, &s->serial); blkconf_blocksizes(&s->qdev.conf); + + if (s->qdev.conf.logical_block_size > + s->qdev.conf.physical_block_size) { + error_setg(errp, + "logical_block_size > physical_block_size not supported"); + return; + } + if (dev->type == TYPE_DISK) { blkconf_geometry(&dev->conf, NULL, 65535, 255, 255, &err); if (err) {