From patchwork Thu Dec 21 12:12:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Borntraeger X-Patchwork-Id: 10127571 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 9F5CC6019C for ; Thu, 21 Dec 2017 12:13:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9862129065 for ; Thu, 21 Dec 2017 12:13:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D4DA2928F; Thu, 21 Dec 2017 12:13:12 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34CE929065 for ; Thu, 21 Dec 2017 12:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753450AbdLUMNI (ORCPT ); Thu, 21 Dec 2017 07:13:08 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48768 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753087AbdLUMND (ORCPT ); Thu, 21 Dec 2017 07:13:03 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBLC9TEF104844 for ; Thu, 21 Dec 2017 07:13:03 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f0a7yqyja-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 21 Dec 2017 07:13:02 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Dec 2017 12:13:00 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 21 Dec 2017 12:12:57 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBLCCuHm61669548; Thu, 21 Dec 2017 12:12:56 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56D66AE056; Thu, 21 Dec 2017 12:05:29 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1AA36AE051; Thu, 21 Dec 2017 12:05:29 +0000 (GMT) Received: from oc7330422307.ibm.com (unknown [9.152.224.219]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 21 Dec 2017 12:05:28 +0000 (GMT) Subject: Re: [PATCH 0/2] KVM: s390: fixups for cmma migration (kvm/master) To: David Hildenbrand , KVM Cc: Cornelia Huck , linux-s390 , Claudio Imbrenda References: <20171221090416.17351-1-borntraeger@de.ibm.com> <36afdadb-994b-22b8-70fd-ff99efb859a3@redhat.com> From: Christian Borntraeger Date: Thu, 21 Dec 2017 13:12:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <36afdadb-994b-22b8-70fd-ff99efb859a3@redhat.com> Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 17122112-0040-0000-0000-000003FC9673 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122112-0041-0000-0000-000025FFBFE7 Message-Id: <32605f3e-b533-d059-88a7-f49380215cf8@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-21_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712210164 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 12/21/2017 01:03 PM, David Hildenbrand wrote: > On 21.12.2017 12:57, David Hildenbrand wrote: >> On 21.12.2017 10:04, Christian Borntraeger wrote: >>> This is targetted as minimal fixups. Claudio is reworking this >>> to handle this better in general (e.g. memory wholes). >>> >>> I will wait for a review for patch2 (which is new) and then spin >>> a pull request as we now have 2 patches for master >>> >>> Christian Borntraeger (2): >>> KVM: s390: fix cmma migration for multiple memory slots >>> KVM: s390: prevent buffer overrun on memory hotplug during migration >>> >>> arch/s390/kvm/kvm-s390.c | 9 +++++---- >>> arch/s390/kvm/priv.c | 2 +- >>> 2 files changed, 6 insertions(+), 5 deletions(-) >>> >> >> [waking up from vacation mode] >> >> Sorry to say, but I guess there is more. >> >> do_essa() can race with >> kvm_s390_vm_set_migration(KVM_S390_VM_MIGRATION_STOP). >> >> CPU0: handle_essa() >> -> vcpu->kvm->arch.migration_state == true >> -> do_essa() >> CPU1: kvm_s390_vm_set_migration(KVM_S390_VM_MIGRATION_STOP) >> -> vcpu->kvm->arch.migration_state = false; >> -> vfree(mgs->pgste_bitmap) >> CPU0: test_and_set_bit(gfn, ms->pgste_bitmap) >> -> access to freed data structure >> >> The kvm_s390_sync_request_broadcast(kvm, KVM_REQ_STOP_MIGRATION) will >> only make sure that all CPUs have left SIE mode, not that the request >> has been processed. >> >> Does that make sense? >> >> [going back to vacation mode] >> > > FWIW, doesn't apply the same thing to kvm_s390_get_cmma_bits(), too? I > can't find locking while quickly glimpsing over it. But I might be wrong. If there is a bug in a piece of code it is certainly a good idea to look deeper.... I think we can prevent both bugs by something like Need to have a look. diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 8951ad4d33be..6ee12afced5a 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -841,6 +841,7 @@ static int kvm_s390_vm_stop_migration(struct kvm *kvm) if (kvm->arch.use_cmma) { kvm_s390_sync_request_broadcast(kvm, KVM_REQ_STOP_MIGRATION); + synchronize_srcu(&kvm->srcu); vfree(mgs->pgste_bitmap); } kfree(mgs);