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=-8.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 CAB1EC388F9 for ; Wed, 11 Nov 2020 23:11:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 26A5E20797 for ; Wed, 11 Nov 2020 23:11:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26A5E20797 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2A3636B0036; Wed, 11 Nov 2020 18:11:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 251826B005D; Wed, 11 Nov 2020 18:11:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 141E86B0068; Wed, 11 Nov 2020 18:11:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id D85B96B0036 for ; Wed, 11 Nov 2020 18:11:47 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7865F180AD801 for ; Wed, 11 Nov 2020 23:11:47 +0000 (UTC) X-FDA: 77473686654.28.flesh91_4b15d3227301 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 5D9356D63 for ; Wed, 11 Nov 2020 23:11:47 +0000 (UTC) X-HE-Tag: flesh91_4b15d3227301 X-Filterd-Recvd-Size: 6048 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Nov 2020 23:11:46 +0000 (UTC) IronPort-SDR: luEt3gPMlx0H8ry1Jc7wJ1CFOMGVekV2ekYjuRGeWIuGkfiw+9xSX8weEtWttYYQbg+Xu3ZLst DDF6upbsW/zg== X-IronPort-AV: E=McAfee;i="6000,8403,9802"; a="167648406" X-IronPort-AV: E=Sophos;i="5.77,470,1596524400"; d="scan'208";a="167648406" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 15:11:44 -0800 IronPort-SDR: 2SigUd3RC6BHd0NrZjhiVcNkd4/T5ldcTrknfGqqjnYMA+dH0hh6VxbwKoY75rW1jfqAHhP1bp TkxPMdnvvBtw== X-IronPort-AV: E=Sophos;i="5.77,470,1596524400"; d="scan'208";a="541993746" Received: from lmwang8-mobl.ccr.corp.intel.com (HELO [10.254.209.85]) ([10.254.209.85]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 15:11:39 -0800 Cc: baolu.lu@linux.intel.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, joro@8bytes.org, catalin.marinas@arm.com, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, Jonathan.Cameron@huawei.com, jacob.jun.pan@linux.intel.com, christian.koenig@amd.com, felix.kuehling@amd.com, zhangfei.gao@linaro.org, jgg@ziepe.ca, xuzaibo@huawei.com, fenghua.yu@intel.com, hch@infradead.org Subject: Re: [PATCH v7 04/24] iommu: Add a page fault handler To: Jean-Philippe Brucker References: <20200519175502.2504091-1-jean-philippe@linaro.org> <20200519175502.2504091-5-jean-philippe@linaro.org> <20201111135740.GA2622074@myrica> From: Lu Baolu Message-ID: <8e630294-8199-68e3-d55a-68e6484d953a@linux.intel.com> Date: Thu, 12 Nov 2020 07:11:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.2 MIME-Version: 1.0 In-Reply-To: <20201111135740.GA2622074@myrica> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Jean, On 2020/11/11 21:57, Jean-Philippe Brucker wrote: > 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 for the explanation. I am also working on converting Intel VT-d to use this framework (and the sva helpers). So far so good. Best regards, baolu