From nobody Mon Feb 9 10:29:59 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=1607545586; cv=none; d=zohomail.com; s=zohoarc; b=F3jE2S507e3fYbjiZfzJo6sutkfvcxRGs6T6gbZfzIRbWmD8fWYm8YuFxMgtoy9Ir+csHt7gLDHxqHWrlqJQA778/W9ojcYUJvPvP5f7bLcI1lbXyW6dlXuCMJDhUSIHVWe9XgKD41E5dVY6+/6RvQey7GtRqmEekDPvnYZqA+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607545586; 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=zxJ3f9AkcimEoHVGFWIULEfxtXcI3G+nN2yyJC0qTJU=; b=S7haN9oMSYOSF7Zc8lmULrkdbtye39Wdw1THzg0L3xx7L/sNr4dup3QgVpr2br12tjKQ/KOsHwy5OWPyeacBglaGAtkkNepd71uRvPavUIlXjdO+44sxgOfPceCzVXNOgsLHiyeZ2P8uDTgKvTf5vc2no3OvjQCr3SRDHRFesEA= 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 1607545586241392.2607108754861; Wed, 9 Dec 2020 12:26:26 -0800 (PST) Received: from localhost ([::1]:39690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kn4Fg-00060H-Ho for importer@patchew.org; Wed, 09 Dec 2020 13:31:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kn3rt-0001QJ-TO for qemu-devel@nongnu.org; Wed, 09 Dec 2020 13:07:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kn3rr-0007iz-6R for qemu-devel@nongnu.org; Wed, 09 Dec 2020 13:07:13 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-9-ONaq8ufYNzC251S1rZI1zQ-1; Wed, 09 Dec 2020 13:07:07 -0500 Received: by mail-wr1-f70.google.com with SMTP id j5so948927wro.12 for ; Wed, 09 Dec 2020 10:07:07 -0800 (PST) Received: from redhat.com (bzq-79-176-44-197.red.bezeqint.net. [79.176.44.197]) by smtp.gmail.com with ESMTPSA id z17sm4486307wrh.88.2020.12.09.10.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 10:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607537230; 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=zxJ3f9AkcimEoHVGFWIULEfxtXcI3G+nN2yyJC0qTJU=; b=TJ7u0oAF2K0iZ7jdUymuFu0V7ZFUYPobowPmI4eiUyv9kuxdBUJtmL6YZCNfzXCkdLau+Z ks9uS4TXIRu6+1zGNktfEkPq8C6vuH7GDzfu2TUxRLqc++77aD2x4OZY0mE0Tn1OoqfmIs +ToDYyESqJ4VBbz2H4rJ+KtHzeuJLxQ= X-MC-Unique: ONaq8ufYNzC251S1rZI1zQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=zxJ3f9AkcimEoHVGFWIULEfxtXcI3G+nN2yyJC0qTJU=; b=ZBgcuIMOXKJa7uhOvhB2JuRtVV+byVUDqKJUTABjlbggKG13sq+7Jt6BZuEvB7OCdC thQdAEAceCtUQ3I0liY9iMYMazaVOkLY69y+FvPXyrGphbaD5AmUDpMKGeT1VoZNNxyv g3sBDc9Sl7SFneOucD1cZS2LIiTY2vxRaKCZ9hUaGAPkdb8vdQqJg67F1zfNIulQoUgX SxfR6M1oW73vJr4b16R5mpg2z+3OHEO5UjBFIwhvJ9HpcqsCxnwgatnlft9BHv1jDUVA IJiOkYKQAfTWE4QuHcFPwyPg3cYhFSgdsJ3m9GEFPwPQw24vwqZM1JZSxoP0vTPDcSph Yh0Q== X-Gm-Message-State: AOAM531HqztssMGc1EdaHT/pV91dsdcMF8YTITbgTbZPJf+zOF4K5NcF UPGAcdwGIgXBb17GiwT1d868zJMm+e7SYBsPvGbR1kIcjVpyowG3q1z/DsSMGmjLEAzpzoMVttY CJL1S7aNSMZSGPqYcp7mm+GRYkwZ1rhneVvej+CU5kMLmvTd0tfgqOhMTwLUB X-Received: by 2002:adf:dd90:: with SMTP id x16mr3950373wrl.85.1607537226087; Wed, 09 Dec 2020 10:07:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVC6oR2ZrKX9VPHlDs/pKJHwvwr60/ZT4uH5qmXowcMrZ6PGPpOO6b2UuGEPaLD+c/UtLTEA== X-Received: by 2002:adf:dd90:: with SMTP id x16mr3950348wrl.85.1607537225821; Wed, 09 Dec 2020 10:07:05 -0800 (PST) Date: Wed, 9 Dec 2020 13:07:03 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 06/65] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type Message-ID: <20201209180546.721296-7-mst@redhat.com> References: <20201209180546.721296-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201209180546.721296-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=0.001, RCVD_IN_MSPIKE_WL=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 , Juan Quintela , Jason Wang , Peter Xu , Eugenio =?utf-8?B?UMOpcmV6?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Eugenio P=C3=A9rez 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 Message-Id: <20201116165506.31315-6-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- softmmu/memory.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 6ca87e8d73..22bacbbc78 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1947,6 +1947,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); @@ -1960,10 +1961,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 MST