From patchwork Mon Mar 20 23:08:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 741336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3vnCcm5dNQz9s3l for ; Tue, 21 Mar 2017 11:00:24 +1100 (AEDT) Received: from localhost ([::1]:35769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cq7Dq-0002p0-4A for incoming@patchwork.ozlabs.org; Mon, 20 Mar 2017 20:00:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cq6RA-0002DQ-Pj for qemu-devel@nongnu.org; Mon, 20 Mar 2017 19:10:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cq6Qz-0005M0-IZ for qemu-devel@nongnu.org; Mon, 20 Mar 2017 19:10:04 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:44881) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cq6Qz-0005Ku-6f for qemu-devel@nongnu.org; Mon, 20 Mar 2017 19:09:53 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2KN8Yvu109651 for ; Mon, 20 Mar 2017 19:09:52 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 29ak40pcbr-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Mar 2017 19:09:51 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Mar 2017 17:09:51 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Mar 2017 17:09:49 -0600 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2KN9n6S15270240; Mon, 20 Mar 2017 16:09:49 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2F4D6E041; Mon, 20 Mar 2017 17:09:48 -0600 (MDT) Received: from localhost (unknown [9.53.92.194]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id DB8406E03F; Mon, 20 Mar 2017 17:09:48 -0600 (MDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 20 Mar 2017 18:08:44 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490051325-3770-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1490051325-3770-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17032023-0012-0000-0000-000013E7D4A1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006819; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00836553; UDB=6.00411162; IPR=6.00614321; BA=6.00005224; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014732; XFM=3.00000013; UTC=2017-03-20 23:09:50 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17032023-0013-0000-0000-00004C578CBD Message-Id: <1490051325-3770-81-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-20_16:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703200196 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 80/81] s390x/css: reassign subchannel if schid is changed after migration 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: Cornelia Huck , Dong Jia Shi , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Dong Jia Shi The subchannel is a means to access a device. While the device number is assigned by the administrator, the subchannel number is assigned by the channel subsystem in an ascending order on cold and hot plug. When doing unplug and replug operations, the same device may end up on a different subchannel; for example - We start with a device fe.1.2222, which ends up at subchannel fe.1.0000. - Now we detach the device, attach a device fe.1.3333 (which would get the now-free subchannel fe.1.0000), re-attach fe.1.2222 (which ends up at subchannel fe.1.0001) and detach fe.1.3333. - We now have the same device (fe.1.2222) available to the guest; it just shows up on a different subchannel. In such a case, the subchannel numbers are different from what a QEMU would create during cold plug when parsing the command line. As this would cause a guest visible change on migration, we do restore the source system's value of the subchannel number on load. So we are now fine from the guest perspective. From the host perspective this will cause an inconsistent state in our internal data structures, though. For example, the subchannel 0 might not be at array position 0. This will lead to problems when we continue doing hot (un/re) plug operations. Let's fix this by cleaning up our internal data structures. Reported-by: Cornelia Huck Signed-off-by: Dong Jia Shi Cc: qemu-stable@nongnu.org Signed-off-by: Cornelia Huck (cherry picked from commit 3c788ebc6f6eef5ac6e9cb4a28c578abcf08247d) Signed-off-by: Michael Roth --- hw/s390x/css.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 0f2580d..91a9fa4 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1672,12 +1672,27 @@ void subch_device_save(SubchDev *s, QEMUFile *f) int subch_device_load(SubchDev *s, QEMUFile *f) { + SubchDev *old_s; + uint16_t old_schid = s->schid; int i; s->cssid = qemu_get_byte(f); s->ssid = qemu_get_byte(f); s->schid = qemu_get_be16(f); s->devno = qemu_get_be16(f); + /* Re-assign subch. */ + if (old_schid != s->schid) { + old_s = channel_subsys.css[s->cssid]->sch_set[s->ssid]->sch[old_schid]; + /* + * (old_s != s) means that some other device has its correct + * subchannel already assigned (in load). + */ + if (old_s == s) { + css_subch_assign(s->cssid, s->ssid, old_schid, s->devno, NULL); + } + /* It's OK to re-assign without a prior de-assign. */ + css_subch_assign(s->cssid, s->ssid, s->schid, s->devno, s); + } s->thinint_active = qemu_get_byte(f); /* SCHIB */ /* PMCW */