Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3003540ybi; Mon, 17 Jun 2019 14:28:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7M5fxSOXFp9dNuS1MOUZMrcdGBcK4ufIaCdWwcH1zaoPlY0J62zbSQAB4/MGT/VIH2TPR X-Received: by 2002:aa7:8b17:: with SMTP id f23mr81058053pfd.194.1560806893394; Mon, 17 Jun 2019 14:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560806893; cv=none; d=google.com; s=arc-20160816; b=znHGS6zQo2lFeB9FF+6PRI4rmo8T3E1O+I8wASaj19wepI9VKuiWIjyEWNxyRjkLUC k+EaeX+cID3bht1qFgLDqwSYnjxPOwkNsIz2uzrQ4Qay9gVCInE+H2OlGofQNQz3GEmH pPeW5uyEZo3TR8qLHnnL9bTtFDPHF1bxk2MbcvOReDGkvGakVp39IkzZyZ/Pv7GVdSP+ qce0hkl6SJxJr4yxez9+YZzXkMF/mSKLRaY3e/CFDTauq69aMow4fRiXkNuNamzK96Sp SxeGKRQAHe6wwLMYtuEixmanD1RI+Ew54ZyGputI9MlQ3cjF3+2FIkV6Hm63T0gDMY7P h6fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YVOgOTxlBOrf/87PgFK8k3Eyf5e7ju+iudSrgR0w+qc=; b=D+pvHpI63112y6hZx5kVinbgXAtgcAmYVYRa067mR0vm30nTlkltePj6NDe/Ekm5S+ Gs/0oaDxf9px5UQkImg4bvL1UDneOwk97F5v6w+AaFnKo0S5gkxJgzhE51xZBK75xRTH l8KKwbbqmcQwhTXLQ6pnpRwUGTuUyvGF26CDRabw/7kmQRMFfiSfXfkDTQP4K/qRz1L1 aB/Kz9j33L9i73jmH19l0gwLzYMOZ5bHKyPpKdZGH3HhXIQHgMtdSi073LblvXK9v9WE GdqEWxa6idh/bCxK19xsc6PgsaZNmVTLLR03d3b2I+5nPiowqMTwv9/VDihkg/62QyT9 BDUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nbRoq3KK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 144si11212753pfw.63.2019.06.17.14.27.58; Mon, 17 Jun 2019 14:28:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nbRoq3KK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730216AbfFQV00 (ORCPT + 99 others); Mon, 17 Jun 2019 17:26:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:52990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730206AbfFQV0Z (ORCPT ); Mon, 17 Jun 2019 17:26:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0EC5E208E4; Mon, 17 Jun 2019 21:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806784; bh=PYGiTt8MpIDsZNgyoWFGVDQh32OC3KrOSb8YjtYAEOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nbRoq3KKjKe1ohyZhNJNAfzdWA5nnTi0n28szepM1hsJw0sNwFNq5EsFP12yAp/fS 4tY89aVFwEkLOMoUNH8dFUXVL8QUdsoN20yt+blIkh46WHkbGkquoTa6CO8Tz2Eb87 3mL21Ed6ohYoTqlryIKaF5tDttA46/PuwOlgjMbc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Borntraeger , Paolo Bonzini , Sasha Levin Subject: [PATCH 4.19 55/75] KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION Date: Mon, 17 Jun 2019 23:10:06 +0200 Message-Id: <20190617210754.921362750@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210752.799453599@linuxfoundation.org> References: <20190617210752.799453599@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 19ec166c3f39fe1d3789888a74cc95544ac266d4 ] kselftests exposed a problem in the s390 handling for memory slots. Right now we only do proper memory slot handling for creation of new memory slots. Neither MOVE, nor DELETION are handled properly. Let us implement those. Signed-off-by: Christian Borntraeger Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/s390/kvm/kvm-s390.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index f538e3fac7ad..fc7de27960e7 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -4156,21 +4156,28 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, const struct kvm_memory_slot *new, enum kvm_mr_change change) { - int rc; - - /* If the basics of the memslot do not change, we do not want - * to update the gmap. Every update causes several unnecessary - * segment translation exceptions. This is usually handled just - * fine by the normal fault handler + gmap, but it will also - * cause faults on the prefix page of running guest CPUs. - */ - if (old->userspace_addr == mem->userspace_addr && - old->base_gfn * PAGE_SIZE == mem->guest_phys_addr && - old->npages * PAGE_SIZE == mem->memory_size) - return; + int rc = 0; - rc = gmap_map_segment(kvm->arch.gmap, mem->userspace_addr, - mem->guest_phys_addr, mem->memory_size); + switch (change) { + case KVM_MR_DELETE: + rc = gmap_unmap_segment(kvm->arch.gmap, old->base_gfn * PAGE_SIZE, + old->npages * PAGE_SIZE); + break; + case KVM_MR_MOVE: + rc = gmap_unmap_segment(kvm->arch.gmap, old->base_gfn * PAGE_SIZE, + old->npages * PAGE_SIZE); + if (rc) + break; + /* FALLTHROUGH */ + case KVM_MR_CREATE: + rc = gmap_map_segment(kvm->arch.gmap, mem->userspace_addr, + mem->guest_phys_addr, mem->memory_size); + break; + case KVM_MR_FLAGS_ONLY: + break; + default: + WARN(1, "Unknown KVM MR CHANGE: %d\n", change); + } if (rc) pr_warn("failed to commit memory region\n"); return; -- 2.20.1