Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2034509ybb; Thu, 2 Apr 2020 11:49:35 -0700 (PDT) X-Google-Smtp-Source: APiQypKfu9dfvtCuQ2geUTCeGu8XXz6Z44krLJrgqKW+SZQQ5PLWpM6ktVJPrWpGtGMQd2SF9VgS X-Received: by 2002:a05:6830:1d67:: with SMTP id l7mr3379587oti.72.1585853375723; Thu, 02 Apr 2020 11:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585853375; cv=none; d=google.com; s=arc-20160816; b=H9mRe6Tiifh8lOQJcUjE7ADpm9vwW5paxX4S/AVtBri6DYvadxq9gvPOrpNzTJz5l5 0MKb4rZXdz9dnvtACSEgjo4MdjMRdwbUDOF9ih4Qg6fUOxecCkNVDwoPS8dpK4CWcnNP tghEjzUYVM585yplK2YcJ/QEB1xDU/KcqpUtCt8WFci+A7UU88Sg5fBKP30/eFTp8V8v XC+MDwf87gaLyN9GQsTcwGgypu10681lc7jxSFfYdfuwEW5Pcx6fniGh3vv+o15mGpuD 5+42wEZlZND1EjZeG/xo2Zkb2+JkexCzFEoamwhI46sVC6Bcw0wCN2bxON29/DXl+YQl lUkA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v7Q48lYxslciByEQ33ox9gAR58LiX+bslgB2j4RAZZg=; b=kmPh7WhABY+HxBEpjQ8oRNLG9KG+NKgRM3HKXTS05ydxh/BOS9nXrHMISpvIQ6uOqe RfjPwIHwWLodLkyc4oDM5jFb3eGqwGEhpCzsHpwcIXPuFVnDrkJWCy5FoqB3aUme/ZP7 eTQdV+Kb+bMrfA8A+N6zD0VsJCiSieswOmCs2mOLDfWX6L0Qkf4GjEhx1cldT2uBp93R 469pFHP30V9OeAmSHTtdjYcwr+hCdH9DKhxL8TPHGCH1S/Zc4rj8JdKJo702wI+5cxpu hzDeUeONq6rDtuUPIcAGPEoxUELM6MtMvAqFf+T+/gdpmN/4mq8fqan29kol95a9PLcX PBrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DuErtYTM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i189si980734oih.228.2020.04.02.11.49.22; Thu, 02 Apr 2020 11:49:35 -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=@redhat.com header.s=mimecast20190719 header.b=DuErtYTM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390003AbgDBSsm (ORCPT + 99 others); Thu, 2 Apr 2020 14:48:42 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:41407 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390010AbgDBSsk (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 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 =3D gmap->asce & _ASCE_TYPE_MASK; unsigned long *table; =20 - if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4)) - return NULL; if (gmap_is_shadow(gmap) && gmap->removed) return NULL; =20 + if (WARN_ON_ONCE(level > (asce_type >> 2) + 1)) + return NULL; + if (WARN_ON_ONCE(asce_type !=3D _ASCE_TYPE_REGION1) && gaddr & (-1UL << (31 + (asce_type >> 2) * 11))) return NULL; =20 table =3D gmap->table; - switch (gmap->asce & _ASCE_TYPE_MASK) { + switch (asce_type) { case _ASCE_TYPE_REGION1: table +=3D (gaddr & _REGION1_INDEX) >> _REGION1_SHIFT; if (level =3D=3D 4) --=20 2.25.1