From nobody Mon Feb 9 09:09:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599150190; cv=none; d=zohomail.com; s=zohoarc; b=DDnpMHtRLI4akzgLBUYD8I8kSPSouZqAMZaxJR0sIoCC2eM6AW811wZV/o+JV5w7O++X+1xZaDzt39zWYtaQAZYVygTRSQAHaxeGQ38wDCJWTtt2aE2RStm6ki3/FrJVHPn/u591y6J9MTJK2/92G5+u+5AoiD8hZ5ST3puvm6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599150190; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pi4j9IwYca8Ff7bM22GVmBPYTiBZQNG/6icR4yOdY5I=; b=ZL8aTfZCcIPB1IVEP6wrst+1KrHI3Ic36g0gf7jk/hWNhMJjuvLf+aejI4TPF3U/1QaqRnTZ8jLDlgo+5h8h44vSdSz8jIGI+GVAkUZvIogKWBc1fYV8B0qIGTIK5oCXHifpRvkfMhFBHjOOJ2om3aU+uHpZsapCTZEhPrIKgHU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599150190695688.5016315023164; Thu, 3 Sep 2020 09:23:10 -0700 (PDT) Received: from localhost ([::1]:38826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDs0z-0003IF-Oi for importer@patchew.org; Thu, 03 Sep 2020 12:23:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDruM-0004P7-6W for qemu-devel@nongnu.org; Thu, 03 Sep 2020 12:16:18 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30905 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDruI-0000mr-4T for qemu-devel@nongnu.org; Thu, 03 Sep 2020 12:16:17 -0400 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-264-siiQPCEsOZCQKclMkNbeTA-1; Thu, 03 Sep 2020 12:16:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEF2F8015A8; Thu, 3 Sep 2020 16:16:09 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-236.ams2.redhat.com [10.36.112.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5230A5C1C2; Thu, 3 Sep 2020 16:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599149773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pi4j9IwYca8Ff7bM22GVmBPYTiBZQNG/6icR4yOdY5I=; b=SKaq0HA7FS/xSUhG4N57ozfQRSroQXyaQC0PGhBswttEyIbw0GWwb7kZgJiYsun5sRvTqu nk4FyD10LF4nbsQbwoAIyDRWLF5gRgi49KsBckzEO108mJoDTDxDZe36fgn8Jb2X5JtCcd cJ3DFt5bAwXubvxTnSrgLfbs4W1f/+4= X-MC-Unique: siiQPCEsOZCQKclMkNbeTA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: Peter Xu , qemu-devel@nongnu.org Subject: [PATCH 5/5] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type Date: Thu, 3 Sep 2020 18:14:46 +0200 Message-Id: <20200903161446.29615-6-eperezma@redhat.com> In-Reply-To: <20200903161446.29615-1-eperezma@redhat.com> References: <20200625191651.5817-1-eperezma@redhat.com> <20200903161446.29615-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=eperezma@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 01:58:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Yan Zhao , Eduardo Habkost , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Eric Auger , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Avi Kivity , Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Device IOTLB invalidations can unmap arbitrary ranges, eiter outside of the memory region or even [0, ~0ULL] for all the space. The assertion could be hit by a guest, and rhel7 guest effectively hit it. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Peter Xu Reviewed-by: Juan Quintela --- softmmu/memory.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 8694fc7cf7..e723fcbaa1 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1895,6 +1895,7 @@ void memory_region_notify_iommu_one(IOMMUNotifier *no= tifier, { IOMMUTLBEntry *entry =3D &event->entry; hwaddr entry_end =3D entry->iova + entry->addr_mask; + IOMMUTLBEntry tmp =3D *entry; =20 if (event->type =3D=3D IOMMU_NOTIFIER_UNMAP) { assert(entry->perm =3D=3D IOMMU_NONE); @@ -1908,10 +1909,18 @@ void memory_region_notify_iommu_one(IOMMUNotifier *= notifier, return; } =20 - assert(entry->iova >=3D notifier->start && entry_end <=3D notifier->en= d); + if (notifier->notifier_flags & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) { + /* Crop (iova, addr_mask) to range */ + tmp.iova =3D MAX(tmp.iova, notifier->start); + tmp.addr_mask =3D MIN(entry_end, notifier->end) - tmp.iova; + /* Confirm no underflow */ + assert(MIN(entry_end, notifier->end) >=3D tmp.iova); + } else { + assert(entry->iova >=3D notifier->start && entry_end <=3D notifier= ->end); + } =20 if (event->type & notifier->notifier_flags) { - notifier->notify(notifier, entry); + notifier->notify(notifier, &tmp); } } =20 --=20 2.18.1