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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 C7815C5517A for ; Wed, 11 Nov 2020 13:58:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1CA1420756 for ; Wed, 11 Nov 2020 13:58:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OIo6Gpxu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CA1420756 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2F8B26B0074; Wed, 11 Nov 2020 08:58:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A9C96B0078; Wed, 11 Nov 2020 08:58:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 198706B007B; Wed, 11 Nov 2020 08:58:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id DAEFC6B0074 for ; Wed, 11 Nov 2020 08:58:01 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 76CF5180AD802 for ; Wed, 11 Nov 2020 13:58:01 +0000 (UTC) X-FDA: 77472291162.06.bun23_540bdf7272fe Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 480711003C064 for ; Wed, 11 Nov 2020 13:58:01 +0000 (UTC) X-HE-Tag: bun23_540bdf7272fe X-Filterd-Recvd-Size: 6927 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Nov 2020 13:58:00 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id r17so2649264wrw.1 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=LmvAAwNqQfzQs0B/fJ6qxzhGdD6PFA3E4ZDR9NBd1zmuhKHWWK5CfxyXmWHQev0ER2 OYU9WT9olTSkINX0ZxYy6aomPZn6cwXpNJnf3mGrJkJygv4EodQU+/lwDKl48ErhSsF7 jThYKvWR3Tae/c8A4J8FZJNh3hFTs4ULBudDxv7n1y7uO45nhu9iFMB9Xp7xGQoKF8iV JhFlSl28V/3FCjt4SmLmOMq38c0C5523Abm5TKQQgjbFSK+taelJawFuNot+YbzAIuQH E7Oy95NxKeE/6LGvc7WFKW66OgbflbQeacJRziOsOhD32aF2D7FbxKhJcUdXzFAQsGid TNhQ== X-Gm-Message-State: AOAM531tCcTijpecolHT/qCH5fmTDwvZcMi5QN5d4NA51TaENu+7YjlK QtnGDvmFuADvEep6815eV6fSjA== 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 Cc: 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 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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