Received: by 2002:a19:ad09:0:0:0:0:0 with SMTP id t9csp816310lfc; Wed, 26 Aug 2020 07:41:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyqOUHS4x6TmMpISJ6Q6e83h+Bidvgvl43r3EFdE3AreC64/1UP1I1gJjEZwgHR9RJhtVr X-Received: by 2002:a25:3c07:: with SMTP id j7mr19706113yba.49.1598452890730; Wed, 26 Aug 2020 07:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598452890; cv=none; d=google.com; s=arc-20160816; b=QKMbCJ2ckujkiGnMEMrJWm/f7dwMvGmH349w8gC/F+J+kWJQrYLt1TMBu4RYku8s07 9uPrvP3jbB4qK0M3X+xih87UR+gT8UQIfwEKV4BjBD2DfCCDXrW52G0WzbzUHt8eFFfz BBFOvCMQDD9/CaMuau1HnNpgdFgrlma+I9Rv3qLKJx0s3erB5WtiGrQVgxIsniIT32io BgnmikensPDk9nI4LTJUCwDTIc7eKEfzcAggrY1W3hcCTNYx7v7t9/K8K1jq4Pv38FGP 42O6r1T4/aeHHTjrdYy4HgIT7+/1eviHqbCSWaX/37wIcM/VQYbNanB3A17u0wpKQD18 zDNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=g3dbNdcxxhQJeQFXVm5XbSPMbQBlA/yaWTXFikvO7So=; b=ZgDMq92G2Cw3tecDhtLuWU+T11yZqVgUDljJufOpIALJMCRS8CxzoewibOMaDnwA5f hJPmVpfOgf+VMA1L9rihu18+K/suOWVdtqVKXMe3mOAv8eNhSKIXJkkEtHf3kz/cjw9k Q3JQ7P7F3tcqofYKAfqqt8fFBvQhusUOHl+cppCD6yMWsToqlSyYecfXMv9iaJcsVzr4 5yLeUeDe9/qZo4LEOORcdBYDTqeQ6PpngsP5x8l6we3umKNrfnSxZi3F2pSKGbyiKaH/ VvilQcKwkNIR77og3KrG0avrvd+wQLSCwQQnfF8Gz3HNocpPd3UQ9/2bOJUY9nSdbjLU 0XqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=chlioOrU; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d5si2307712ybk.135.2020.08.26.07.41.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Aug 2020 07:41:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=chlioOrU; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:34162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAwcD-0004eE-Vp for alex.bennee@linaro.org; Wed, 26 Aug 2020 10:41:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kAwa0-0000GU-W6 for qemu-arm@nongnu.org; Wed, 26 Aug 2020 10:39:13 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:49740 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 1kAwZx-0006MN-Sh for qemu-arm@nongnu.org; Wed, 26 Aug 2020 10:39:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598452749; 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=g3dbNdcxxhQJeQFXVm5XbSPMbQBlA/yaWTXFikvO7So=; b=chlioOrU+Z19cBzDq/eSManqKyCycUr3OcqJpRgcLb2mvziEQNOlCJvTNnzs0luMB4QS3t fF2a8rVlDGdgCeoI4QKVEuU4Nwxw9vQh2OFVNt8NaUYJ+DCvA9Wl/lx4rG8zAZCfUm0VCI fH0aINCZtN+Qa5l/EiDgTHFNzVEjU3g= 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-267-boRpaYidMAWIyRUdxiGzbw-1; Wed, 26 Aug 2020 10:39:05 -0400 X-MC-Unique: boRpaYidMAWIyRUdxiGzbw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A71C425D1; Wed, 26 Aug 2020 14:39:04 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-115-59.ams2.redhat.com [10.36.115.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6917776E00; Wed, 26 Aug 2020 14:38:52 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org, Peter Xu Subject: [RFC v6 10/13] memory: Notify IOMMU IOTLB based on entry type, not permissions Date: Wed, 26 Aug 2020 16:36:48 +0200 Message-Id: <20200826143651.7915-11-eperezma@redhat.com> In-Reply-To: <20200826143651.7915-1-eperezma@redhat.com> References: <20200625191651.5817-1-eperezma@redhat.com> <20200826143651.7915-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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: 8bit Received-SPF: pass client-ip=207.211.31.120; envelope-from=eperezma@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/26 03:56:58 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.959, 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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@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 , Juan Quintela , Jason Wang , "Michael S. Tsirkin" , Eric Auger , qemu-arm@nongnu.org, =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Avi Kivity , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: LFebSc4qvDfB This way the intention is much clearer. Signed-off-by: Eugenio Pérez --- softmmu/memory.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 961c25b42f..3e68442ca6 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1890,10 +1890,27 @@ void memory_region_unregister_iommu_notifier(MemoryRegion *mr, memory_region_update_iommu_notify_flags(iommu_mr, NULL); } +static IOMMUNotifierFlag notifier_type_iommu(const IOMMUNotifier *notifier) +{ + return notifier->notifier_flags & IOMMU_NOTIFIER_ALL; +} + +static bool memory_region_notify(const IOMMUNotifier *notifier, + const IOMMUTLBEntry *entry) +{ + switch(entry->type) { + case IOMMU_IOTLB_MAP: + return notifier_type_iommu(notifier) == IOMMU_NOTIFIER_MAP; + case IOMMU_IOTLB_UNMAP: + return notifier_type_iommu(notifier) == IOMMU_NOTIFIER_UNMAP; + default: + return false; + }; +} + void memory_region_notify_iommu_one(IOMMUNotifier *notifier, IOMMUTLBEntry *entry) { - IOMMUNotifierFlag request_flags; hwaddr entry_end = entry->iova + entry->addr_mask; /* @@ -1906,13 +1923,7 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier, assert(entry->iova >= notifier->start && entry_end <= notifier->end); - if (entry->perm & IOMMU_RW) { - request_flags = IOMMU_NOTIFIER_MAP; - } else { - request_flags = IOMMU_NOTIFIER_UNMAP; - } - - if (notifier->notifier_flags & request_flags) { + if (memory_region_notify(notifier, entry)) { notifier->notify(notifier, entry); } } -- 2.18.1