From patchwork Thu Apr 2 18:48:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11471259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F8F51668 for ; Thu, 2 Apr 2020 18:48:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D1A0206E9 for ; Thu, 2 Apr 2020 18:48:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="arvEbHvA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390052AbgDBSs6 (ORCPT ); Thu, 2 Apr 2020 14:48:58 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47882 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389105AbgDBSsb (ORCPT ); Thu, 2 Apr 2020 14:48:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585853310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bo/SIfmVuQxtNcfVHbbkR511KgXolpkFsV3XDhMlwBo=; b=arvEbHvAqLMl1YJezW81qlJxfrF92UbUcwN8mYARLODqVN4fGOz+xSUJN2SRVvc8euOZZC tgHWfQqhUhkCpOv7XoctpvaFZGKfKvSym5w+XySy5NvoFUTYd9pIbgrS7t34qVH6eR6vB+ bSW8OFSWQwrEQ+vYCfOwQbaImaW6zqQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-408-zGOKMzHDPR6yJnmedVHzOQ-1; Thu, 02 Apr 2020 14:48:29 -0400 X-MC-Unique: zGOKMzHDPR6yJnmedVHzOQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6946A8017F5; Thu, 2 Apr 2020 18:48:27 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B1D660BF3; Thu, 2 Apr 2020 18:48:25 +0000 (UTC) From: David Hildenbrand To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Heiko Carstens , Cornelia Huck , Janosch Frank , Christian Borntraeger , David Hildenbrand , stable@vger.kernel.org Subject: [PATCH v1 1/5] KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks Date: Thu, 2 Apr 2020 20:48:15 +0200 Message-Id: <20200402184819.34215-2-david@redhat.com> In-Reply-To: <20200402184819.34215-1-david@redhat.com> References: <20200402184819.34215-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In case we have a region 1 ASCE, our shadow/g3 address can have any value. Unfortunately, (-1UL << 64) is undefined and triggers sometimes, rejecting valid shadow addresses when trying to walk our shadow table hierarchy. The result is that the prefix cannot get mapped and will loop basically forever trying to map it (-EAGAIN loop). After all, the broken check is only a sanity check, our table shadowing code in kvm_s390_shadow_tables() already checks these conditions, injecting proper translation exceptions. Turn it into a WARN_ON_ONCE(). Fixes: 4be130a08420 ("s390/mm: add shadow gmap support") Cc: # v4.8+ Reported-by: Janosch Frank Signed-off-by: David Hildenbrand Tested-by: Janosch Frank --- arch/s390/mm/gmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index 2fbece47ef6f..f3dbc5bdde50 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -787,14 +787,18 @@ static void gmap_call_notifier(struct gmap *gmap, unsigned long start, static inline unsigned long *gmap_table_walk(struct gmap *gmap, unsigned long gaddr, int level) { + const int asce_type = gmap->asce & _ASCE_TYPE_MASK; unsigned long *table; if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4)) return NULL; if (gmap_is_shadow(gmap) && gmap->removed) return NULL; - if (gaddr & (-1UL << (31 + ((gmap->asce & _ASCE_TYPE_MASK) >> 2)*11))) + + if (WARN_ON_ONCE(asce_type != _ASCE_TYPE_REGION1) && + gaddr & (-1UL << (31 + (asce_type >> 2) * 11))) return NULL; + table = gmap->table; switch (gmap->asce & _ASCE_TYPE_MASK) { case _ASCE_TYPE_REGION1: From patchwork Thu Apr 2 18:48:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11471257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E296B1668 for ; Thu, 2 Apr 2020 18:48:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C023C20719 for ; Thu, 2 Apr 2020 18:48:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HhC0fdYM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389891AbgDBSs5 (ORCPT ); Thu, 2 Apr 2020 14:48:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:33370 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389894AbgDBSsd (ORCPT ); Thu, 2 Apr 2020 14:48:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585853312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J1iTHN+tnT2p+g/fi18lrfKuFFUGCiTi5w5obFOSEB4=; b=HhC0fdYMDipAnzG7GMxd4xvkNFeTtl4ybkCcV9Imsby0G7yNTez7ynRWb/nKRFrA8XI8Yu gKmG4TgBwmLwH9zf7q/NewmZMAjWGvs3M1NFTG4Fo6BZQhF8XNcPXhgQ8xSqz674rsjWRm Rswm9XOdz3kxSf60HCXEUoMvHJ2wwoU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-ggkVwfV3P3KDHLgJNeELUA-1; Thu, 02 Apr 2020 14:48:31 -0400 X-MC-Unique: ggkVwfV3P3KDHLgJNeELUA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C55AC1926DA5; Thu, 2 Apr 2020 18:48:29 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id B900360BF3; Thu, 2 Apr 2020 18:48:27 +0000 (UTC) From: David Hildenbrand To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Heiko Carstens , Cornelia Huck , Janosch Frank , Christian Borntraeger , David Hildenbrand , stable@vger.kernel.org Subject: [PATCH v1 2/5] KVM: s390: vsie: Fix delivery of addressing exceptions Date: Thu, 2 Apr 2020 20:48:16 +0200 Message-Id: <20200402184819.34215-3-david@redhat.com> In-Reply-To: <20200402184819.34215-1-david@redhat.com> References: <20200402184819.34215-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Whenever we get an -EFAULT, we failed to read in guest 2 physical address space. Such addressing exceptions are reported via a program intercept to the nested hypervisor. We faked the intercept, we have to return to guest 2. Instead, right now we would be returning -EFAULT from the intercept handler, eventually crashing the VM. Addressing exceptions can only happen if the g2->g3 page tables reference invalid g2 addresses (say, either a table or the final page is not accessible - so something that basically never happens in sane environments. Identified by manual code inspection. Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization") Cc: # v4.8+ Signed-off-by: David Hildenbrand Reviewed-by: Christian Borntraeger --- arch/s390/kvm/vsie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index 076090f9e666..4f6c22d72072 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -1202,6 +1202,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) scb_s->iprcc = PGM_ADDRESSING; scb_s->pgmilc = 4; scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4); + rc = 1; } return rc; } From patchwork Thu Apr 2 18:48:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11471255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7480792C for ; Thu, 2 Apr 2020 18:48:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 51E2D20719 for ; Thu, 2 Apr 2020 18:48:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hkKARblD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389923AbgDBSsz (ORCPT ); Thu, 2 Apr 2020 14:48:55 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:55806 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389925AbgDBSsf (ORCPT ); Thu, 2 Apr 2020 14:48:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585853315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/TA1qIm6g7bOjJwF/S4q/AnUgMbYOhvn3awtkZe9/dU=; b=hkKARblDfnEQkJBePTHDiQ9rjQswJz+rEBl0rVMkgR8pF9qnf1f/ssu0+SIBAjjHRGugoe ESymxc7xA/SYhptFhcoUljMfjaLKZvira1n1czPz2AyJC+qNChfMdX8hv+jw4+o6cIgjOg FX8gggI0Ab2eXzebaI0x+OqVajhXUPI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-99-w-A29iO4NzGTkB53sIYlYw-1; Thu, 02 Apr 2020 14:48:33 -0400 X-MC-Unique: w-A29iO4NzGTkB53sIYlYw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 046971926DA0; Thu, 2 Apr 2020 18:48:32 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E3E860BF3; Thu, 2 Apr 2020 18:48:29 +0000 (UTC) From: David Hildenbrand To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Heiko Carstens , Cornelia Huck , Janosch Frank , Christian Borntraeger , David Hildenbrand Subject: [PATCH v1 3/5] KVM: s390: vsie: Fix possible race when shadowing region 3 tables Date: Thu, 2 Apr 2020 20:48:17 +0200 Message-Id: <20200402184819.34215-4-david@redhat.com> In-Reply-To: <20200402184819.34215-1-david@redhat.com> References: <20200402184819.34215-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We have to properly retry again by returning -EINVAL immediately in case somebody else instantiated the table concurrently. We missed to add the goto in this function only. The code now matches the other, similar shadowing functions. We are overwriting an existing region 2 table entry. All allocated pages are added to the crst_list to be freed later, so they are not lost forever. However, when unshadowing the region 2 table, we wouldn't trigger unshadowing of the original shadowed region 3 table that we replaced. It would get unshadowed when the original region 3 table is modified. As it's not connected to the page table hierarchy anymore, it's not going to get used anymore. However, for a limited time, this page table will stick around, so it's in some sense a temporary memory leak. Identified by manual code inspection. I don't think this classifies as stable material. Fixes: 998f637cc4b9 ("s390/mm: avoid races on region/segment/page table shadowing") Signed-off-by: David Hildenbrand Reviewed-by: Christian Borntraeger --- arch/s390/mm/gmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index f3dbc5bdde50..fd32ab566f57 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -1844,6 +1844,7 @@ int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t, goto out_free; } else if (*table & _REGION_ENTRY_ORIGIN) { rc = -EAGAIN; /* Race with shadow */ + goto out_free; } crst_table_init(s_r3t, _REGION3_ENTRY_EMPTY); /* mark as invalid as long as the parent table is not protected */ From patchwork Thu Apr 2 18:48:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11471251 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5903B1668 for ; Thu, 2 Apr 2020 18:48:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35CB82078E for ; Thu, 2 Apr 2020 18:48:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eb162wYZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390012AbgDBSsk (ORCPT ); Thu, 2 Apr 2020 14:48:40 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:46863 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389905AbgDBSsi (ORCPT ); Thu, 2 Apr 2020 14:48:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585853317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Mna+DLBALS7Nv4a/6CqV2AmkqQOOKpm1xodEo/O7Gc=; b=eb162wYZL5Cs7rO9FmECy4Dz1IWoGoPvNLBJOwmlKsD7T2ggnBAToLHfxzAMfDNepojoJu 8Gt3llG6KUZnsrhxLDcUEmIl+baZe3KraJp4APr7xqp7qfIAxdOd9QMTFgJFvLHhsnPmQy l/QxgZaSH4Q4fmnBZ+yAhElMb48GoQs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-212-DwQOlVzKNAGajjkV7xcR-w-1; Thu, 02 Apr 2020 14:48:35 -0400 X-MC-Unique: DwQOlVzKNAGajjkV7xcR-w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C4B9107ACC9; Thu, 2 Apr 2020 18:48:34 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5243B60BF3; Thu, 2 Apr 2020 18:48:32 +0000 (UTC) From: David Hildenbrand To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Heiko Carstens , Cornelia Huck , Janosch Frank , Christian Borntraeger , David Hildenbrand Subject: [PATCH v1 4/5] KVM: s390: vsie: Move conditional reschedule Date: Thu, 2 Apr 2020 20:48:18 +0200 Message-Id: <20200402184819.34215-5-david@redhat.com> In-Reply-To: <20200402184819.34215-1-david@redhat.com> References: <20200402184819.34215-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's move it to the outer loop, in case we ever run again into long loops, trying to map the prefix. While at it, convert it to cond_resched(). Signed-off-by: David Hildenbrand --- arch/s390/kvm/vsie.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index 4f6c22d72072..ef05b4e167fb 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -1000,8 +1000,6 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) handle_last_fault(vcpu, vsie_page); - if (need_resched()) - schedule(); if (test_cpu_flag(CIF_MCCK_PENDING)) s390_handle_mcck(); @@ -1185,6 +1183,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) kvm_s390_vcpu_has_irq(vcpu, 0) || kvm_s390_vcpu_sie_inhibited(vcpu)) break; + cond_resched(); } if (rc == -EFAULT) { From patchwork Thu Apr 2 18:48:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11471253 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3122D92C for ; Thu, 2 Apr 2020 18:48:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0BE2B2080C for ; Thu, 2 Apr 2020 18:48:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DuErtYTM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390028AbgDBSsl (ORCPT ); Thu, 2 Apr 2020 14:48:41 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:60833 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390003AbgDBSsk (ORCPT ); Thu, 2 Apr 2020 14:48:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585853319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v7Q48lYxslciByEQ33ox9gAR58LiX+bslgB2j4RAZZg=; b=DuErtYTM+PQ7RkBZwhDtUPc960ubSlNRe3A//sZywqkvV8tYadsioHYcaTcTflhfV/hZeu KFio+MfLQAdKff8XfTDDLyOOP1Ea7H73d6oJ0FMVOjaFjQn/Pe+fo5IWdbMN4VfcT20hVF 15wqSMsb/JiBneo04eLekiGq3VNlhtc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-129-tcmxRi3mOCKRGGysVKZOQQ-1; Thu, 02 Apr 2020 14:48:38 -0400 X-MC-Unique: tcmxRi3mOCKRGGysVKZOQQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BDD7107ACC4; Thu, 2 Apr 2020 18:48:36 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8801460BF3; Thu, 2 Apr 2020 18:48:34 +0000 (UTC) From: David Hildenbrand To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Heiko Carstens , Cornelia Huck , Janosch Frank , Christian Borntraeger , David Hildenbrand Subject: [PATCH v1 5/5] KVM: s390: vsie: gmap_table_walk() simplifications Date: Thu, 2 Apr 2020 20:48:19 +0200 Message-Id: <20200402184819.34215-6-david@redhat.com> In-Reply-To: <20200402184819.34215-1-david@redhat.com> References: <20200402184819.34215-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's use asce_type where applicable. Also, simplify our sanity check for valid table levels and convert it into a WARN_ON_ONCE(). Check if we even have a valid gmap shadow as the very first step. Signed-off-by: David Hildenbrand --- arch/s390/mm/gmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index fd32ab566f57..3c801dae7988 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -790,17 +790,18 @@ static inline unsigned long *gmap_table_walk(struct gmap *gmap, const int asce_type = gmap->asce & _ASCE_TYPE_MASK; unsigned long *table; - if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4)) - return NULL; if (gmap_is_shadow(gmap) && gmap->removed) return NULL; + if (WARN_ON_ONCE(level > (asce_type >> 2) + 1)) + return NULL; + if (WARN_ON_ONCE(asce_type != _ASCE_TYPE_REGION1) && gaddr & (-1UL << (31 + (asce_type >> 2) * 11))) return NULL; table = gmap->table; - switch (gmap->asce & _ASCE_TYPE_MASK) { + switch (asce_type) { case _ASCE_TYPE_REGION1: table += (gaddr & _REGION1_INDEX) >> _REGION1_SHIFT; if (level == 4)