Received: by 2002:adf:ef42:0:0:0:0:0 with SMTP id c2csp336417wrp; Tue, 3 Sep 2019 04:45:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzscIbgOXyvwDuaarJGjKQsUhI9Zs4L43SjFIFB7ERAD6lsxLD6Zxi2qSBat+iiQbzTP/gI X-Received: by 2002:a0c:d7ce:: with SMTP id g14mr21132319qvj.2.1567511151084; Tue, 03 Sep 2019 04:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567511151; cv=none; d=google.com; s=arc-20160816; b=OqvdifYvo19XQDW5OHcYInLNlupvnCvt6vyGRBBPE1/MvVS7MLOeJ7XGSecwqTHoUt nBLMIvQVP1Q6655KJJaKa6EBBVhWXT9gyg+guF/ay5GAPIPGtv0cYnsPCttde66pCj5M FoszYll44vz76cAmkuk7mC5nTlK8QvsR7A8ybHLcr7pzOWFY3AvnmSChhSnEW7GaeZ0x cOkKOPCkVhrmNONSyYJ+gOIBEbCSvNAJfewpW8HveTtGiww6KMwXwuHzNjfPHn+a8pFy 8eC04TBhneZo3HhNFWNosTIzoPyxE0hZ09/DPaGlSKTvUsJEkgtH37b9JmrQkbyOpkKw S2ig== 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:subject :content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:to; bh=KLhW8jyqhyqCZAS53wUWe2QdQVKJG7NCYXZVjx6KG40=; b=mkX7oKjVEvnbcPbHFgtZgeJ6ItLcmvUi5T2Cc4kMCGIWDEGKV9ZKLquKEDXrARjnHH QSKLgbmd1dFL+SXOZCTLVH33x+M8jPC4X6QVti6lrNc8HajN2Lcja5VkHuy7YXqeOoBF 2+pkFrzgQis3wTmMTtOVMX2Q8j/RpV9wOkhx6ZDV2tO3sRwS9Yn0BVXv+oPx8CM8zreX YmznwvjqPk7n5B4lGzMj8Ic/w2lc4Kn2+mVJCg8E0GPJTwfra617LWNnj3eQ/jQK1nbl r7Keb608N1qSZdrV+Yxs/IFTtpJOtkpE7lp7NH6COplo+MswvpdvVd073nuYX+r8QmOI DtXA== ARC-Authentication-Results: i=1; mx.google.com; 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 3si9693096qkj.256.2019.09.03.04.45.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Sep 2019 04:45:51 -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; 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]:44358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i57Fr-000376-UZ for alex.bennee@linaro.org; Tue, 03 Sep 2019 07:45:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54720) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i57Fg-00035x-HL for qemu-arm@nongnu.org; Tue, 03 Sep 2019 07:45:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i57Fe-0004a8-Rd for qemu-arm@nongnu.org; Tue, 03 Sep 2019 07:45:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53730) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i57Fe-0004ZX-KC; Tue, 03 Sep 2019 07:45:34 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 710561E2E6; Tue, 3 Sep 2019 11:45:33 +0000 (UTC) Received: from [10.36.116.67] (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0497E60A35; Tue, 3 Sep 2019 11:45:23 +0000 (UTC) To: Peter Xu References: <20190730172137.23114-1-eric.auger@redhat.com> <20190730172137.23114-10-eric.auger@redhat.com> <20190819082424.GB13560@xz-x1> From: Auger Eric Message-ID: Date: Tue, 3 Sep 2019 13:45:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190819082424.GB13560@xz-x1> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 03 Sep 2019 11:45:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-arm] [PATCH for-4.2 v10 09/15] virtio-iommu: Implement translate 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@linaro.org, kevin.tian@intel.com, mst@redhat.com, tn@semihalf.com, qemu-devel@nongnu.org, alex.williamson@redhat.com, qemu-arm@nongnu.org, jean-philippe@linaro.org, bharat.bhushan@nxp.com, eric.auger.pro@gmail.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: PaYkOjLuvEOX Hi Peter, On 8/19/19 10:24 AM, Peter Xu wrote: > On Tue, Jul 30, 2019 at 07:21:31PM +0200, Eric Auger wrote: >> @@ -464,19 +464,75 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, >> int iommu_idx) >> { >> IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); >> + VirtIOIOMMU *s = sdev->viommu; >> uint32_t sid; >> + viommu_endpoint *ep; >> + viommu_mapping *mapping; >> + viommu_interval interval; >> + bool bypass_allowed; >> + >> + interval.low = addr; >> + interval.high = addr + 1; >> >> IOMMUTLBEntry entry = { >> .target_as = &address_space_memory, >> .iova = addr, >> .translated_addr = addr, >> - .addr_mask = ~(hwaddr)0, >> + .addr_mask = (1 << ctz32(s->config.page_size_mask)) - 1, >> .perm = IOMMU_NONE, >> }; >> >> + bypass_allowed = virtio_has_feature(s->acked_features, >> + VIRTIO_IOMMU_F_BYPASS); >> + >> sid = virtio_iommu_get_sid(sdev); >> >> trace_virtio_iommu_translate(mr->parent_obj.name, sid, addr, flag); >> + qemu_mutex_lock(&s->mutex); >> + >> + ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(sid)); >> + if (!ep) { >> + if (!bypass_allowed) { >> + error_report("%s sid=%d is not known!!", __func__, sid); > > Maybe use error_report_once() to avoid DOS attack? Also would it be > good to unify the debug prints? I see both error_report() and > qemu_log_mask() are used in the whole patchset. Or is that attempted? I switched to error_report_once() I understand that qemu_log_mask() should be used whenever the root cause is a bad action of the guest OS (in below case, the EP was not attached to any domain). Above, there is an EP that attempts to talk through the IOMMU and this was not expected (rather a platform description issue or a qemu bug). Thanks Eric > >> + } else { >> + entry.perm = flag; >> + } >> + goto unlock; >> + } >> + >> + if (!ep->domain) { >> + if (!bypass_allowed) { >> + qemu_log_mask(LOG_GUEST_ERROR, >> + "%s %02x:%02x.%01x not attached to any domain\n", >> + __func__, PCI_BUS_NUM(sid), >> + PCI_SLOT(sid), PCI_FUNC(sid)); >> + } else { >> + entry.perm = flag; >> + } >> + goto unlock; >> + } >> + >> + mapping = g_tree_lookup(ep->domain->mappings, (gpointer)(&interval)); >> + if (!mapping) { >> + qemu_log_mask(LOG_GUEST_ERROR, >> + "%s no mapping for 0x%"PRIx64" for sid=%d\n", >> + __func__, addr, sid); >> + goto unlock; >> + } >> + >> + if (((flag & IOMMU_RO) && !(mapping->flags & VIRTIO_IOMMU_MAP_F_READ)) || >> + ((flag & IOMMU_WO) && !(mapping->flags & VIRTIO_IOMMU_MAP_F_WRITE))) { >> + qemu_log_mask(LOG_GUEST_ERROR, >> + "Permission error on 0x%"PRIx64"(%d): allowed=%d\n", >> + addr, flag, mapping->flags); >> + goto unlock; >> + } >> + entry.translated_addr = addr - mapping->virt_addr + mapping->phys_addr; >> + entry.perm = flag; >> + trace_virtio_iommu_translate_out(addr, entry.translated_addr, sid); >> + >> +unlock: >> + qemu_mutex_unlock(&s->mutex); >> return entry; >> } >> >> -- >> 2.20.1 >> > > Regards, >