From patchwork Wed Dec 2 11:03:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1409652 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MCo9EFna; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CmGgQ36qHz9sVw for ; Wed, 2 Dec 2020 22:18:40 +1100 (AEDT) Received: from localhost ([::1]:54144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkQ9d-0000Yj-Kt for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2020 06:18:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkPv0-00031l-Kh for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkPuz-0002ut-0o for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606907008; 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=MCo9EFnaA2c/zW23cLHn+J4S/HWZo/dlo3WiEwUHAxSGBi3EERcOHetKzd+w5KfKeOxr3h OkNpCc+s0ShxrPufpAT3dDgERSX6JT9r3VHlRymZv/rOV+/R6gb4A4gSQMe2AAoHV6diTF lDrDTyx72SpT5VmzhaDUxJrFlDeXTrY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-g5CwY4g0Ni63cTCCNpolhg-1; Wed, 02 Dec 2020 06:03:26 -0500 X-MC-Unique: g5CwY4g0Ni63cTCCNpolhg-1 Received: by mail-wr1-f69.google.com with SMTP id b12so3304590wru.15 for ; Wed, 02 Dec 2020 03:03:26 -0800 (PST) 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=RlXaaX8R2jmcb0bov/YA/POrTRfeorFy6a7kQUpdddaK3xd9+DsKT8pZW21zRN3hMc bTFd4sFNGEWHjckJURlKU8bX1vtBSk8Oocwypwtb4HnrdHuLzrXt4mU3jOKEyBi5r3/S I4v0LFqN03HjNMFLAQxpHLn8KVSdPbBZiWJ82DmzpV7cqDgLzyQ4EWFxvS/D/ayndzYI rqbK+4ykM11Efyx6uGzzNg5Le/DuiBLqt1JCWXsQHfHj6s1BrEXs/Xy1YMMbH5ukwYMr I3TiVLHNjxmVhPq3sWK4GILN3fPouYJqgSZiy6HCviLfWfeQbnWLZasbXs4JKPqDoKJQ DO7g== X-Gm-Message-State: AOAM533HYYb1ytfjT4WltckveD2N+BLAUioAveRik0Z2mB+QkDajCpk1 f27p2Ejtzg3btevs1pbDb+13oNVSXe7scMWMchaTn0JJrFMrsqP9weko7/vNSULFFnyfuc5sRl8 1I9fQtL1g6I6l3grHVyofq4im6dJMdSZS+Vp0OCCOWhvXVdviw+70xcxwkIXJ X-Received: by 2002:adf:a549:: with SMTP id j9mr2716547wrb.199.1606907005498; Wed, 02 Dec 2020 03:03:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRZGmsqZ80Aj5NqXQhVY1vaZpvY1Pnn5jQ4J/5DSm7RX2LtlT1AB2jArH32E4pWvLTpG9H4Q== X-Received: by 2002:adf:a549:: with SMTP id j9mr2716514wrb.199.1606907005247; Wed, 02 Dec 2020 03:03:25 -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 u26sm1665480wmm.24.2020.12.02.03.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:03:24 -0800 (PST) Date: Wed, 2 Dec 2020 06:03:23 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 6/6] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type Message-ID: <20201202101655.122214-7-mst@redhat.com> References: <20201202101655.122214-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201202101655.122214-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-Disposition: inline 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: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eugenio Pérez 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érez 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 *notifier, { IOMMUTLBEntry *entry = &event->entry; hwaddr entry_end = entry->iova + entry->addr_mask; + IOMMUTLBEntry tmp = *entry; if (event->type == IOMMU_NOTIFIER_UNMAP) { assert(entry->perm == IOMMU_NONE); @@ -1960,10 +1961,16 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier, return; } - assert(entry->iova >= notifier->start && entry_end <= notifier->end); + if (notifier->notifier_flags & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) { + /* Crop (iova, addr_mask) to range */ + tmp.iova = MAX(tmp.iova, notifier->start); + tmp.addr_mask = MIN(entry_end, notifier->end) - tmp.iova; + } else { + assert(entry->iova >= notifier->start && entry_end <= notifier->end); + } if (event->type & notifier->notifier_flags) { - notifier->notify(notifier, entry); + notifier->notify(notifier, &tmp); } }