From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0A43C55ABD for ; Wed, 11 Nov 2020 13:58:41 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EBD120829 for ; Wed, 11 Nov 2020 13:58:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZTT91cRU"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OIo6Gpxu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EBD120829 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KO0fVUCSIaHeI6rjbju420gmCPbUSQubW4t8VEYPvC8=; b=ZTT91cRUVpAlK/MblCdPZ6S7X thhOQMKM4g08FbjeRpOod/DVJlIVrGv0tqObsSZWDlnEDa/wV2yQesCswwybHyj7yaiTer5+zf5yO CzXbVU7GMlqjNRfy8/OuQbIZ2em/llobotzCA95B5Vpf+1TSwHjTbAS3f2ks1Is+zMaG5ayE3eX6P 66S66x0ob6WBIKlynBYWalYlvl1eWHg+J3cFihr9nrgbTrBCWMxn5YMEG4N2dCzHD2NbP81ObFan5 qfslUbkwI0AlCYl2Xde+z3nCt42MkC2AQsX7S0hYUR4jzrzezFBmLBadBiNyZ3bnlo5o2Fnm/KOpE PLtpY59ug==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcqdT-0001x4-LL; Wed, 11 Nov 2020 13:58:07 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcqdP-0001uf-U7 for linux-arm-kernel@lists.infradead.org; Wed, 11 Nov 2020 13:58:05 +0000 Received: by mail-wr1-x441.google.com with SMTP id k2so2637368wrx.2 for ; Wed, 11 Nov 2020 05:58:00 -0800 (PST) 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:in-reply-to; bh=nQxC580B2FGMz7fwoWGS/qV6OQLc0KLPED3qOpuBky8=; b=OIo6GpxukW3iK2MLSyvALt9frkeXd0ZXiyBWhhzmAxpU0yk9P7jOnHruqZKBQccZFO pi2tyWBjPtyBjL5dZIjocD5ciZf7y4jaSEPp7AQg7jVQhBrcZUkooG6dMykqfIKrnwAm cmTpHvTYivjJDMqffwVQNg3EIBx4N6ItwiIASsWC7oJFIABzF84mUeLhNduPpkE/B5fD zU74Wu3AXxpByDpPLbPJvtqj5iCgSkmn2qtMTKJ496VYWlXJFryVRfSUhAyN/CXGuD78 QJiksGLXHFV1oaOcVmLLsBMjUdF+nYRlOKoiB/1ocK79gkEdbrKkmG95wo2oynjwhkmg RIqg== 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:in-reply-to; bh=nQxC580B2FGMz7fwoWGS/qV6OQLc0KLPED3qOpuBky8=; b=hs7N8nPZrCc9AWkHH2kvbFqGbsAcbFGBeheBj2Ys1xLL6upPBPBvKb5d/BzxXQgw+x fC6RUY3W75NsUTxWwkwyRfagM2qdC3CcO7ifUHgp2wVZBYJASyWCBwieE5Jz8Ki5+Zz6 oScH2PyVvi4b1T1QjAhKVja/VzPzEeUQC6unbqbq16Rj6uxIjfqBVMgGTJya8YbP8Qpb fc83qVi11fENrlSkTNgMPnsLBEMMhprqOt/NjnRtZszfZMtXv7ktfs7pB6rKJfvQCHaw mhLAgkJOcBJ2h81qWNOz+o8nATiD2MwlD95ArHUt8ixEAklNOXdyzLDBLgmPqpcMUBOl G/Vg== X-Gm-Message-State: AOAM533mgG68WjenH3V2rDubkz2BmTfwwHB2D3lr2dNM7U84hU1MHcyN BwgzpTmTeIV6jvICuZgrYdKKVg== X-Google-Smtp-Source: ABdhPJz8B46qAy3mH7K7M4xppHiXb//CHwuj/RA8IyjLL/yHeGrjXZ21yZsM7l6s4djLyiLVXJ69Cg== X-Received: by 2002:adf:e3cf:: with SMTP id k15mr13899007wrm.259.1605103079627; Wed, 11 Nov 2020 05:57:59 -0800 (PST) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id b14sm2550433wrq.47.2020.11.11.05.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 05:57:58 -0800 (PST) Date: Wed, 11 Nov 2020 14:57:40 +0100 From: Jean-Philippe Brucker To: Lu Baolu Subject: Re: [PATCH v7 04/24] iommu: Add a page fault handler Message-ID: <20201111135740.GA2622074@myrica> References: <20200519175502.2504091-1-jean-philippe@linaro.org> <20200519175502.2504091-5-jean-philippe@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201111_085804_044245_8DBF171D X-CRM114-Status: GOOD ( 24.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, jgg@ziepe.ca, linux-pci@vger.kernel.org, joro@8bytes.org, Jonathan.Cameron@huawei.com, robin.murphy@arm.com, fenghua.yu@intel.com, hch@infradead.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, zhangfei.gao@linaro.org, catalin.marinas@arm.com, felix.kuehling@amd.com, xuzaibo@huawei.com, will@kernel.org, christian.koenig@amd.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Baolu, Thanks for the review. I'm only now reworking this and realized I've never sent a reply, sorry about that. On Wed, May 20, 2020 at 02:42:21PM +0800, Lu Baolu wrote: > Hi Jean, > > On 2020/5/20 1:54, Jean-Philippe Brucker wrote: > > Some systems allow devices to handle I/O Page Faults in the core mm. For > > example systems implementing the PCIe PRI extension or Arm SMMU stall > > model. Infrastructure for reporting these recoverable page faults was > > added to the IOMMU core by commit 0c830e6b3282 ("iommu: Introduce device > > fault report API"). Add a page fault handler for host SVA. > > > > IOMMU driver can now instantiate several fault workqueues and link them > > to IOPF-capable devices. Drivers can choose between a single global > > workqueue, one per IOMMU device, one per low-level fault queue, one per > > domain, etc. > > > > When it receives a fault event, supposedly in an IRQ handler, the IOMMU > > driver reports the fault using iommu_report_device_fault(), which calls > > the registered handler. The page fault handler then calls the mm fault > > handler, and reports either success or failure with iommu_page_response(). > > When the handler succeeded, the IOMMU retries the access. > > > > The iopf_param pointer could be embedded into iommu_fault_param. But > > putting iopf_param into the iommu_param structure allows us not to care > > about ordering between calls to iopf_queue_add_device() and > > iommu_register_device_fault_handler(). > > > > Signed-off-by: Jean-Philippe Brucker [...] > > +static enum iommu_page_response_code > > +iopf_handle_single(struct iopf_fault *iopf) > > +{ > > + vm_fault_t ret; > > + struct mm_struct *mm; > > + struct vm_area_struct *vma; > > + unsigned int access_flags = 0; > > + unsigned int fault_flags = FAULT_FLAG_REMOTE; > > + struct iommu_fault_page_request *prm = &iopf->fault.prm; > > + enum iommu_page_response_code status = IOMMU_PAGE_RESP_INVALID; > > + > > + if (!(prm->flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID)) > > + return status; > > + > > + mm = iommu_sva_find(prm->pasid); > > + if (IS_ERR_OR_NULL(mm)) > > + return status; > > + > > + down_read(&mm->mmap_sem); > > + > > + vma = find_extend_vma(mm, prm->addr); > > + if (!vma) > > + /* Unmapped area */ > > + goto out_put_mm; > > + > > + if (prm->perm & IOMMU_FAULT_PERM_READ) > > + access_flags |= VM_READ; > > + > > + if (prm->perm & IOMMU_FAULT_PERM_WRITE) { > > + access_flags |= VM_WRITE; > > + fault_flags |= FAULT_FLAG_WRITE; > > + } > > + > > + if (prm->perm & IOMMU_FAULT_PERM_EXEC) { > > + access_flags |= VM_EXEC; > > + fault_flags |= FAULT_FLAG_INSTRUCTION; > > + } > > + > > + if (!(prm->perm & IOMMU_FAULT_PERM_PRIV)) > > + fault_flags |= FAULT_FLAG_USER; > > + > > + if (access_flags & ~vma->vm_flags) > > + /* Access fault */ > > + goto out_put_mm; > > + > > + ret = handle_mm_fault(vma, prm->addr, fault_flags); > > + status = ret & VM_FAULT_ERROR ? IOMMU_PAGE_RESP_INVALID : > > Do you mind telling why it's IOMMU_PAGE_RESP_INVALID but not > IOMMU_PAGE_RESP_FAILURE? PAGE_RESP_FAILURE maps to PRI Response code "Response Failure" which indicates a catastrophic error and causes the function to disable PRI. Instead PAGE_RESP_INVALID maps to PRI Response code "Invalid request", which tells the function that the address is invalid and there is no point retrying this particular access. Thanks, Jean _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel