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)