From nobody Mon Feb 9 05:41:52 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=1605546244; cv=none; d=zohomail.com; s=zohoarc; b=nn4Le82eEbCBty5aL0nb0QqIm7ApvSbqegU47FZjA8onTXHm3jxFslH77XFsyxUR1+12pSMIdX1UNFND5+hYvzp2NmCoO+lWR6KGTTgGSRXGkSk46x3RsP/MIVvOoEa55rhYj9B7OrJ+Uzpal1eOZgUNfBm6tk+bDwxB1fSx5UQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605546244; 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=te/LGP4MEKOHFzI2ew2SXawtf+K8KzijGMWYw/0CPKs=; b=MO/WWgdi2Nfpy49JQSdBJQG3hu1i97Z633boxKQuJoFvqsErFM/mZmFZb/ocDZ2gKRFx88qCTAL42nL2MmB9R+3SWIOw7TR8iwnCb8L/IKrdHXOFoPKfeqw7C69KFQw/hwD36zvmjMjiaYdsTSAp6GiLrAtCo6TCL2nW3dFfjzk= 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 1605546244800322.3687328564479; Mon, 16 Nov 2020 09:04:04 -0800 (PST) Received: from localhost ([::1]:39222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kehv9-0003Dv-7j for importer@patchew.org; Mon, 16 Nov 2020 12:04:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kehpL-0005zo-L8 for qemu-devel@nongnu.org; Mon, 16 Nov 2020 11:58:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kehpI-000854-RF for qemu-devel@nongnu.org; Mon, 16 Nov 2020 11:58:03 -0500 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-6-V6T__JIQPEyr3SvD7M6xag-1; Mon, 16 Nov 2020 11:57:57 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D6CC1008550; Mon, 16 Nov 2020 16:57:55 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-115-134.ams2.redhat.com [10.36.115.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10FD55D9CC; Mon, 16 Nov 2020 16:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605545878; 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=te/LGP4MEKOHFzI2ew2SXawtf+K8KzijGMWYw/0CPKs=; b=F9fTRa9LYOVAixMZqBuEXyvSQst3FVCBI7uVeFBGFlwtdq6LJsKgbJN4igZPIs1pFSJDKT xWKILWbQSwjpYUWuNPjlMFlp6zQAb/feu1h/bOZvW50fDAww4LbDqtBAgRIEiQNGS67bkL tc6pEYMsFgvcxqJFac2wWX+S7CHbbvs= X-MC-Unique: V6T__JIQPEyr3SvD7M6xag-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S. Tsirkin" , Peter Xu , qemu-devel@nongnu.org Subject: [PATCH v3 5/5] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type Date: Mon, 16 Nov 2020 17:55:06 +0100 Message-Id: <20201116165506.31315-6-eperezma@redhat.com> In-Reply-To: <20201116165506.31315-1-eperezma@redhat.com> References: <20201116165506.31315-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 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=63.128.21.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/16 04:46:27 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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 , Matthew Rosato , David Hildenbrand , Jason Wang , Aleksandar Rikalo , Juan Quintela , Halil Pasic , Christian Borntraeger , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Avi Kivity , Richard Henderson , Thomas Huth , Yan Zhao , Eduardo Habkost , Richard Henderson , Eric Auger , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, David Gibson , Cornelia Huck , qemu-ppc@nongnu.org, Paolo Bonzini 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 Acked-by: Jason Wang --- softmmu/memory.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index ca281edaea..f1b6ba35f2 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1937,6 +1937,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); @@ -1950,10 +1951,16 @@ 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; + } 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.4