From patchwork Mon Mar 20 08:58:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 9633223 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 21E146020B for ; Mon, 20 Mar 2017 08:59:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1240728174 for ; Mon, 20 Mar 2017 08:59:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06ED82818B; Mon, 20 Mar 2017 08:59:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD63828174 for ; Mon, 20 Mar 2017 08:59:13 +0000 (UTC) Received: from localhost ([::1]:59911 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpt9k-0005ZA-Ql for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Mar 2017 04:59:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpt9W-0005Xu-5B for qemu-devel@nongnu.org; Mon, 20 Mar 2017 04:58:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpt9T-00029l-5y for qemu-devel@nongnu.org; Mon, 20 Mar 2017 04:58:58 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58293) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpt9S-00029G-St for qemu-devel@nongnu.org; Mon, 20 Mar 2017 04:58:55 -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 v2K8s01I084577 for ; Mon, 20 Mar 2017 04:58:53 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 29906v1k2v-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Mar 2017 04:58:52 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Mar 2017 08:58:50 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Mar 2017 08:58:48 -0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2K8wmMX40108286; Mon, 20 Mar 2017 08:58:48 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E63242056; Mon, 20 Mar 2017 08:58:22 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3399D42045; Mon, 20 Mar 2017 08:58:22 +0000 (GMT) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.55]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 20 Mar 2017 08:58:22 +0000 (GMT) From: Cornelia Huck To: peter.maydell@linaro.org Date: Mon, 20 Mar 2017 09:58:44 +0100 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170320085844.15178-1-cornelia.huck@de.ibm.com> References: <20170320085844.15178-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17032008-0040-0000-0000-000003682643 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17032008-0041-0000-0000-00001F55D4AB Message-Id: <20170320085844.15178-2-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-20_07:, , 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-1703200082 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL for-2.9 1/1] 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: qemu-devel@nongnu.org, qemu-stable@nongnu.org, agraf@suse.de, borntraeger@de.ibm.com, Cornelia Huck , Dong Jia Shi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- hw/s390x/css.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index e32b2a4d42..37caa98195 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1675,12 +1675,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 */