Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3000987ybi; Mon, 17 Jun 2019 14:24:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl77QCKew/q9kvqP2K+ixTDPgSJcu0lD5y6MWCctAy4NIxAb3K+D7z99OFAefon5SbCUin X-Received: by 2002:a17:902:bd94:: with SMTP id q20mr23914078pls.307.1560806676347; Mon, 17 Jun 2019 14:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560806676; cv=none; d=google.com; s=arc-20160816; b=jl1PK5HtnwbNMLsICvGOmGLKCgVNvJBYxx5pJgYuXE2r0sXXsvMVCi7duMb0dLJboc QXGSxrSOH5f8mFguo9xSEwu+gv5M62EhRFNec2ggTM02BBbt6l5FvGcP0M6Vi9dit4RT 5vTKhxqXD2zgZLDLdGDsilV2qXUnfEfzbAtb3N5I58IbO8qpq2Z7Fu0SPE0lH3RV6jTH zqnXnFsK/6X0bkpbplxS+JA4cNWvz/I0vfxx6TsXY/j0YdY9fnAw3q9nDjDY26TBUoxs yGd5k4gkvBDs3e88DADeN8AiUOz7LtQ+J6awaAx+ozaRC+NhWZwqCzf2LQ+mE9dC0vu7 iPpg== 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=Mn0CoKuEbs+mimEgnYyG3p4P06t88NHpslRhA43a+Hk=; b=SWqJevPrDtr0LymOktR17XNTGSeB9TxQxAaE2/ml1sHnh1HDU6W8YxlAavQhvc/EO9 Mw/DtM2WKc6x8L26zGdm36E4lpXRE5tJidrUxX1oohZL1Yhu8SwAR2FFWtmk5hznQ8l6 LITZ4fxaKlKcmXARS/+3KsetBPlYKuPgXRIk2vj+t5kWJvmQ9Bt9EY1gq5dlqx1h0hgA 5QJz7U+398xUu5hKZA539ZJMBZHPMhSg1Yzcemg/HSp9k8K7IowS8SLlxYg8Vgjqfucp VEZj4r27h0bpwLZpsFsH+XUVpEN5a5oqcLEw2sVrIPUPKfjwKu612y41XocHD6/1sruw 7rgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R4hBs+D0; 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 a129si12499544pgc.79.2019.06.17.14.24.21; Mon, 17 Jun 2019 14:24:36 -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=R4hBs+D0; 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 S1729712AbfFQVXY (ORCPT + 99 others); Mon, 17 Jun 2019 17:23:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:48416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729308AbfFQVXU (ORCPT ); Mon, 17 Jun 2019 17:23:20 -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 98627208E4; Mon, 17 Jun 2019 21:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806600; bh=m9Q9Vlgl+kNwOg3Xk7nW9kRT4PszanSRflTUJekU/bQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R4hBs+D0sBP9PhaSQjFD/11tabiOfHHx1XRIdHxk+3PhwxShadyCriuY1b/hAydRf py82SMYVb7BahHbX67Hgduz5VjXJuiZiCC9BjRfq6k5ljTBVU0qwOJogq9LQajOnH8 G/Qb7yY6LtoB5Sr9wZg1+zyCw6rTgtLM1+dhnaJo= 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 5.1 091/115] KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION Date: Mon, 17 Jun 2019 23:09:51 +0200 Message-Id: <20190617210804.577765445@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@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 c4180ecfbb2a..ee35f1112db9 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -4413,21 +4413,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