Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4038006ybg; Fri, 25 Oct 2019 12:25:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0Eo2L7ovmMH8FraFWyg7pzq8LD5gZ60k7y1l86J3Dblu103a4Vo3EAA8CVt5xy3hCDA62 X-Received: by 2002:a50:959a:: with SMTP id w26mr5788061eda.214.1572031531343; Fri, 25 Oct 2019 12:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572031531; cv=none; d=google.com; s=arc-20160816; b=h/5ZTSmo4MdLxcDmeqk1KstAJtawgzcR2PyLdKkDjlKMI22WKz1SQs2tDuklvbDeon ldqL/A70i/dLajV/I/i1PQJz5/M0RpJZuBtjfPOey5Kmdcr6KVDJzvqf86VlLrJGmcAX L64/qdC/EX6GG8vMZnUZNoEbBoybBRoOPRO6PqaCsba6XQ0BQvEtZ/io2g1/PD0rJ/gt hICRRJ6Vf8hv+PD5nPksnyQxHcmvIryWaugxG315EAnTkmMiXAFplFlLnWQisnG4AkSU ZItPp+Dz6ZJQRzQ1PMCMkM/NsFCwT0FoOL19UadAuYi3N4YE0j8E9lr/L48SWfE6XcnU QYrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=O+tNoeo7hAfUizkaPOI8/abyUdx+v+Co+syiVJFepPg=; b=fE+hlsUsyGwAiwr4Lx+fD7CCrDDmTWReLTMj1zq3I1Bjr/vPH2W9flhIL2xQZJFup2 mxeIj7kPDJNN7g9U1KV4soBhoM4H92ElayTn36P9erCwYKtmzNbOIkPIN9sU0JM3CVzV ur4xutrxXz9+akQY4RDp99awLBmzMl/bqDwMJUUfxo/BPNUrlc09Ej0iNIDiuPrvvR0l 9y06+PmILGyGpqRU5xBUWND9JqPbaOHFO128liPjSIQ2a4PJqPA5iAASBZFChPIVgjQh D2hIWQ5SPsyTsWFaccM8wF34VhFjgX56eUCIP4pko0i/jWkSAeLZ35ounM5m6Q6DriAU 4ZQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DVFJVAku; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ly18si1795124ejb.374.2019.10.25.12.25.06; Fri, 25 Oct 2019 12:25:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DVFJVAku; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406105AbfJYHEj (ORCPT + 99 others); Fri, 25 Oct 2019 03:04:39 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35709 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406111AbfJYHEi (ORCPT ); Fri, 25 Oct 2019 03:04:38 -0400 Received: by mail-wm1-f65.google.com with SMTP id v6so839284wmj.0 for ; Fri, 25 Oct 2019 00:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=O+tNoeo7hAfUizkaPOI8/abyUdx+v+Co+syiVJFepPg=; b=DVFJVAkuo3g9Yp1Ux+WgPsK3AU0Pq9woqz1WO0SkMX8gt75R3QrFY4h7fCaNyWPoRU z5T52wXXCAtDGVgapk2+aXOcugz7s095+94YJpLDb4vLocY3wjuT9xcgKzokPsyvvgHh 5hwemuw8dQ3UMtVnfTsVX0F9mBCcln8jWWAHxJgaGpPq5Cp3UvWVHm0LzqcmxkmK5AxL 2DznUlT/ENdMS+uGHLVNaTPx/6TTcljhulAgDcJ5neS5mgP/aK2iC3sfj6+lN8GWugWq eiVjcmKos44OEZM2NUVQ6DQOT704X4U4KnLFRuPaBLzxf8YLchhzFJwbAfKuhhbz21aR bvKw== 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:user-agent; bh=O+tNoeo7hAfUizkaPOI8/abyUdx+v+Co+syiVJFepPg=; b=MkV7oUK/yOidiu0l8JdHyBwPCQkM4dkU3bzqRNxqN25nXbhvCiQ3Z5wb+cqqMYmfgb AKMwYxpjO9Ci2txMmgVTjFV1ieN71AflFZyV+7Ge6hAVV11TZvo72jxBZ2PoC/GQq9Jt fJVN6IKUgI+qMKbEmAqyCV33DGji2H57fb65kMfjoZyJGwm/JDiKzJIhsLc5KHIdrm1F NuSFsUHAxN3e/kPAucif234Yay/GGLxYABCz56HdJDgAGAAUuaG3n9H2LWJo02TLX69T c3xge7+R2LiccavNBhdDqbzCetmB7uKJuIwrrnZphiEfA9WUknzWiCw0AkZaYpaUg5rj Qqmw== X-Gm-Message-State: APjAAAV6Ye1jOCBqhdN+HPwVU1dFmBny2uWSTy97VPA1nSJzHrzQYrn5 rNghDziKvY1zHLm1HCT7UbCNwQ== X-Received: by 2002:a1c:9dd3:: with SMTP id g202mr2026082wme.43.1571987076112; Fri, 25 Oct 2019 00:04:36 -0700 (PDT) Received: from lophozonia ([85.195.192.192]) by smtp.gmail.com with ESMTPSA id b5sm1121600wmj.18.2019.10.25.00.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:04:35 -0700 (PDT) Date: Fri, 25 Oct 2019 09:04:33 +0200 From: Jean-Philippe Brucker To: "zhangfei.gao@foxmail.com" Cc: Jerome Glisse , Zhangfei Gao , francois.ozog@linaro.org, Herbert Xu , Arnd Bergmann , Greg Kroah-Hartman , Zaibo Xu , ilias.apalodimas@linaro.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Wangzhou , grant.likely@arm.com, "haojian . zhuang" , Kenneth Lee , linux-accelerators@lists.ozlabs.org, kenneth-lee-2012@foxmail.com Subject: Re: [PATCH v6 2/3] uacce: add uacce driver Message-ID: <20191025070433.GB503659@lophozonia> References: <1571214873-27359-1-git-send-email-zhangfei.gao@linaro.org> <1571214873-27359-3-git-send-email-zhangfei.gao@linaro.org> <20191016172802.GA1533448@lophozonia> <20191023165814.GB4163@redhat.com> <5db257c6.1c69fb81.bfe34.a4afSMTPIN_ADDED_BROKEN@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5db257c6.1c69fb81.bfe34.a4afSMTPIN_ADDED_BROKEN@mx.google.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Oct 25, 2019 at 10:02:36AM +0800, zhangfei.gao@foxmail.com wrote: > > It already exist it is call mmu notifier, you can register an mmu notifier > > and get callback once the mm exit. > Currently we register mm_exit for sva path, as suggested by Jean. Yes that's called from a release() mmu_notifier callback. > static struct iommu_sva_ops uacce_sva_ops = { >         .mm_exit = uacce_sva_exit, > }; > iommu_sva_set_ops(handle, &uacce_sva_ops); > > Still not certain do we have to register mm_exit for both case, > sva and !sva, since it is a common situation. I was wondering about that. For !SVA, since all DMA memory is mapped through mmap, you'll be notified by the vma->vm_ops->close() callback when the mm disappears, so I don't think you need a mm release notifier. However that callback will just remove the IOMMU mappings and invalidate TLBs, but the queue might still be running and since no fault handler is registered, the IOMMU driver will flood the kernel logs with translation faults. Similarly, the user can simply start the queue and call munmap() for the same result, or even just program the queue with invalid DMA addresses. What we could do is when !SVA, register an IOMMU fault handler (the shiny new iommu_register_device_fault_handler()) and consume all faults ourselves. That will at least prevent userspace from flooding the kernel logs. Even better, as soon as we get a fault notification, we could stop the queue associated to that DMA address to prevent further faults, though we'll still receive those that are already pending in the fault queue. Thanks, Jean