Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp953559ybt; Tue, 7 Jul 2020 04:26:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoasCPdbUIE/5svMNOElBTnvu7oR9lOih8QpiYayD7+uAiOxU6CYEMHRoCqF7yPOCt8siU X-Received: by 2002:a17:907:20c4:: with SMTP id qq4mr45950968ejb.85.1594121193117; Tue, 07 Jul 2020 04:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594121193; cv=none; d=google.com; s=arc-20160816; b=O8aTN4n6vOlDdDM8Uy6sz0IY6nSZ+5dDtHoQwsaH3A4AN5UkoJsLmEjT08JhraADAz NjucnBfLH7BsXBovqCM4DLQLohuhAAbfY848irbtTk4oQ0ansa1CFcttd8Hsj1cSFUzU VWECmLxz1cSQkETl2hmMhEg9kB+nsVO6R35sUgeLYwflnHs3IxMW9VB5xzpearWYmVZV UPpDLG9S13VlgLJ3ssChUrzj8m0nQnLUNZnolCfvwhRoPbLbKw/J2yWD5//y1Z4NvjGY PQvy27VBbZwyRkQzJiLHMKfXNawCRpjgmSIqy90Wh7QCpZPPZSAh/cRZmfGGqnHq9QJG w+rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Z+HTaDJORry76de6xJh2nNWpDzvXRte/7hWFD6xg3L0=; b=rDT/JjKOl8obAImO+HJBIx+gjW5cIE/bHC4NjQRy3J2Rb1N+2qiA0wF+kGw/OsqOG5 Kk5lz9K4mSP8vqmaKhEbeohEZaXNHZdxOGYYPXPnn7LxxsS0CDQHivTinu8HSY/Z9bLv V0WgjQtvIwCJMU1/bGsoKLiZTmaz9B+BBRHI9yT2MElz8GtO01Cb2qtlFWd0C78pvXNT gNaNp6oWGJj4TM9s6jX/RYO5Wp5IIVFlyZTbNCBdTrjEiPLwSuj/PX7+lnvX5L+vz6zI wcUqpKTp6ZTxGhEwU96EHV4BIGpHRzlpmWkeC/jkkkscV73zu6W4kjOfU7Pvw2ezGuZ5 71wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zFs2OsBC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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. [23.128.96.18]) by mx.google.com with ESMTP id h6si14029641ejg.220.2020.07.07.04.26.09; Tue, 07 Jul 2020 04:26:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zFs2OsBC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1728122AbgGGLX6 (ORCPT + 99 others); Tue, 7 Jul 2020 07:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbgGGLX6 (ORCPT ); Tue, 7 Jul 2020 07:23:58 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0F97C061755 for ; Tue, 7 Jul 2020 04:23:57 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id h28so38072435edz.0 for ; Tue, 07 Jul 2020 04:23:57 -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:in-reply-to; bh=Z+HTaDJORry76de6xJh2nNWpDzvXRte/7hWFD6xg3L0=; b=zFs2OsBCi8DqKxj1YR0JHMK7UjSD/oZ/Z7BDnr1ZUxpIoAaPD4S4IKK4hGDeddFjTt 3BGApI+F1fzdkFWT7exYU5xyhldcg7eLpeBuLLhJ+aXC5j8cN3+H/i5LrHVnap88M9dH W34FYzJkfIjh/aDMP9w8uU0X6SEe9f3nCfiKHej0GGxTEieXobrFZ5elrhd7Q4athgmt K8jd2P2nrdufj2lG76LEKtKxltV8v5QSXfHnH3VFLr4WQvymX2Y2EdwHEr6pgZ10Ue4E 4hMYcgs1r5y1LAAd6lkwxqLFOJMEXIuCVdwCqAKlyfTHjvcB6L4J0Vy2Z6FtePyO6I9E EHdA== 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=Z+HTaDJORry76de6xJh2nNWpDzvXRte/7hWFD6xg3L0=; b=tt4y4HFpDLX7lqYgRhrvYw8RICLgjrDK/IcnKZMICQyCVloaRWlMJs/w/vG8mRBWJ/ 2mhn8hrm6p6wbBbR251klQqnO/dC6YP0KH6CgZV0UR3Jy7UptLQeoUoFY2/OnooeOnK8 ZrFIGeMR08Ukr5zFahivhk/qzzbGdValT3FlaVGf+be0Oo3ERDuEioEc8HE8f23/yKko jF3si49Hu9pz+bdoh8NlpOXTA+KF1LZXrn5xyHYI9dVyDr2MvuIhue1vFHQolUVLX6pM O2y2gcgwGzZALSaEL/ehjs+ZpM1rPBjv5UMHrw5nO5mogz2Q66cHa91VJB1zkxD+ywAM K32w== X-Gm-Message-State: AOAM5307yvYcTd4+kuPzYU+J/2zHqOpno/vfsSPngaHrSeJE0sn5WDT4 PE+q3TLHB12sP1+P4C3o+jxKsA== X-Received: by 2002:aa7:da46:: with SMTP id w6mr50895220eds.261.1594121036582; Tue, 07 Jul 2020 04:23:56 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id s1sm25488302edy.1.2020.07.07.04.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 04:23:56 -0700 (PDT) Date: Tue, 7 Jul 2020 13:23:44 +0200 From: Jean-Philippe Brucker To: Lu Baolu Cc: iommu@lists.linux-foundation.org, Kevin Tian , Ashok Raj , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/4] iommu/vt-d: Report page request faults for guest SVA Message-ID: <20200707112344.GB159413@myrica> References: <20200706002535.9381-1-baolu.lu@linux.intel.com> <20200706002535.9381-4-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200706002535.9381-4-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 06, 2020 at 08:25:34AM +0800, Lu Baolu wrote: > A pasid might be bound to a page table from a VM guest via the iommu > ops.sva_bind_gpasid. In this case, when a DMA page fault is detected > on the physical IOMMU, we need to inject the page fault request into > the guest. After the guest completes handling the page fault, a page > response need to be sent back via the iommu ops.page_response(). > > This adds support to report a page request fault. Any external module > which is interested in handling this fault should regiester a notifier > callback. > > Co-developed-by: Jacob Pan > Signed-off-by: Jacob Pan > Co-developed-by: Liu Yi L > Signed-off-by: Liu Yi L > Signed-off-by: Lu Baolu > --- [...] > +static int > +intel_svm_prq_report(struct device *dev, struct page_req_dsc *desc) > +{ > + struct iommu_fault_event event; > + u8 bus, devfn; > + > + memset(&event, 0, sizeof(struct iommu_fault_event)); > + bus = PCI_BUS_NUM(desc->rid); > + devfn = desc->rid & 0xff; > + > + /* Fill in event data for device specific processing */ > + event.fault.type = IOMMU_FAULT_PAGE_REQ; > + event.fault.prm.addr = desc->addr; > + event.fault.prm.pasid = desc->pasid; > + event.fault.prm.grpid = desc->prg_index; > + event.fault.prm.perm = prq_to_iommu_prot(desc); > + > + /* > + * Set last page in group bit if private data is present, > + * page response is required as it does for LPIG. > + */ > + if (desc->lpig) > + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE; > + if (desc->pasid_present) > + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; Do you also need to set IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID? I added the flag to deal with devices that do not want a PASID value in their PRI response (bit 15 in the PCIe Page Request Status Register): https://lore.kernel.org/linux-iommu/20200616144712.748818-1-jean-philippe@linaro.org/ (applied by Joerg for v5.9) Grepping for pci_prg_resp_pasid_required() in intel/iommu.c it seems to currently reject devices that do not want a PASID in a PRI response, so I think you can set this flag unconditionally for now. Thanks, Jean > + if (desc->priv_data_present) { > + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE; > + event.fault.prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PRIV_DATA; > + memcpy(event.fault.prm.private_data, desc->priv_data, > + sizeof(desc->priv_data)); > + } > + > + return iommu_report_device_fault(dev, &event); > +}