Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp674527rdb; Mon, 15 Jan 2024 09:44:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrxEKQIiXXbXtTKZd7Hb55J2LUqJ8l8rzHSjI+PpOjJDscoQ3lmzfs3HW5xtd9fxWifG8M X-Received: by 2002:a19:9115:0:b0:50e:4fd8:d293 with SMTP id t21-20020a199115000000b0050e4fd8d293mr2699881lfd.124.1705340670126; Mon, 15 Jan 2024 09:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705340670; cv=none; d=google.com; s=arc-20160816; b=wmBnZeFvcrnncxEucKkySsGCAm7NFdKceq7lObTnfrQ6bqhGJtR+duBEpOqc/h69ub TAUsgWt/Flba/9/j8ybsmutXeZ4QJarFJPRGf6Bp05TmQymoxHiNwTPUZIJ8KFbqugWq pvG363BgJSSIgy7ofH3s+JpliwhCo/33Kj+k1QOrfugWfIunxNtkI3i6dK7QZiM3Kp2q +g9v1woa1lWL3JOIME3sQ1TBJBfmvLESxYsKORu4ihrhfR5+iHmnZYpcIhx4cphu9yv7 cSvxW6MvZWMobTscHkjxQOs6/vu9k8ZFWTUdbjT5kKXLnUxGi4cpOL44vpJrl++bRv7x 3B0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:content-language:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=EM9tKxGYbV43sizhEjV+dDgI+UNPxNDmokQdFpzTGVs=; fh=CBWUdxY87wBhl3qnzFpWimHtb+XCFEl4+0FE1O4CUCc=; b=VsSMFUlRJ5GtWN9vePsAwBpwSAgMxM7O29Kttrt2TeeM7yPz00XAbt9b1Upx1sL1D8 VgWPT8e70oeNOVXxfBGzBOZ1tFvgPsn2+VQ6P1sfv5Z0lIM9ZxoQxmbhZUrxubA8SVW6 zSnE33A7VDGfa5qlCPPccaRk8P1sS1y/tP8vbq7H6ORDdZXSLIBI1a1/2D4XE3UTTYu2 gCiOlyr954YTLQ3AZ3Y/td8y3Go2zo01UwM+qaeZn5pUnWLGnGCOripNfUsbiuJmaTm+ Znw2SfhisJCwjdzwKw1DfoBd1IO8E/WUL4FOd6GwF3kWj110BGCMM6E68cXafZ2vBCsv NXPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z14-20020a170906074e00b00a2c10619c55si3881587ejb.441.2024.01.15.09.44.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 09:44:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AA7A61F228B1 for ; Mon, 15 Jan 2024 17:44:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B39D81804E; Mon, 15 Jan 2024 17:44:19 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3517B182A1; Mon, 15 Jan 2024 17:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TDKFZ6Xz5z6J9SV; Tue, 16 Jan 2024 01:41:38 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (unknown [7.191.162.67]) by mail.maildlp.com (Postfix) with ESMTPS id B08F6140594; Tue, 16 Jan 2024 01:44:13 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 15 Jan 2024 17:44:13 +0000 Received: from lhrpeml500005.china.huawei.com ([7.191.163.240]) by lhrpeml500005.china.huawei.com ([7.191.163.240]) with mapi id 15.01.2507.035; Mon, 15 Jan 2024 17:44:13 +0000 From: Shameerali Kolothum Thodi To: Jason Gunthorpe CC: Lu Baolu , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , "iommu@lists.linux.dev" , "linux-kselftest@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v2 4/6] iommufd: Deliver fault messages to user space Thread-Topic: [PATCH v2 4/6] iommufd: Deliver fault messages to user space Thread-Index: AQHaB7erJOXV16DWQEa9TDH5jPoMHrDW7X2wgASoGYCAAA4dMA== Date: Mon, 15 Jan 2024 17:44:13 +0000 Message-ID: References: <20231026024930.382898-1-baolu.lu@linux.intel.com> <20231026024930.382898-5-baolu.lu@linux.intel.com> <20240115164723.GB50608@ziepe.ca> In-Reply-To: <20240115164723.GB50608@ziepe.ca> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 > -----Original Message----- > From: Jason Gunthorpe > Sent: Monday, January 15, 2024 4:47 PM > To: Shameerali Kolothum Thodi > Cc: Lu Baolu ; Kevin Tian ; > Joerg Roedel ; Will Deacon ; Robin > Murphy ; Jean-Philippe Brucker philippe@linaro.org>; Nicolin Chen ; Yi Liu > ; Jacob Pan ; > iommu@lists.linux.dev; linux-kselftest@vger.kernel.org; > virtualization@lists.linux-foundation.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH v2 4/6] iommufd: Deliver fault messages to user space >=20 > On Fri, Jan 12, 2024 at 05:46:13PM +0000, Shameerali Kolothum Thodi wrote= : > > > > > > > -----Original Message----- > > > From: Lu Baolu > > > Sent: Thursday, October 26, 2023 3:49 AM > > > To: Jason Gunthorpe ; Kevin Tian = ; > Joerg > > > Roedel ; Will Deacon ; Robin > Murphy > > > ; Jean-Philippe Brucker philippe@linaro.org>; > > > Nicolin Chen ; Yi Liu ; Jaco= b > Pan > > > > > > Cc: iommu@lists.linux.dev; linux-kselftest@vger.kernel.org; > > > virtualization@lists.linux-foundation.org; linux-kernel@vger.kernel.o= rg; > Lu > > > Baolu > > > Subject: [PATCH v2 4/6] iommufd: Deliver fault messages to user space > > > > > [...] > > > > Hi, > > > > > +static ssize_t hwpt_fault_fops_write(struct file *filep, > > > + const char __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + size_t response_size =3D sizeof(struct iommu_hwpt_page_response); > > > + struct hw_pgtable_fault *fault =3D filep->private_data; > > > + struct iommu_hwpt_page_response response; > > > + struct iommufd_hw_pagetable *hwpt; > > > + struct iopf_group *iter, *group; > > > + struct iommufd_device *idev; > > > + size_t done =3D 0; > > > + int rc =3D 0; > > > + > > > + if (*ppos || count % response_size) > > > + return -ESPIPE; > > > + > > > + mutex_lock(&fault->mutex); > > > + while (!list_empty(&fault->response) && count > done) { > > > + rc =3D copy_from_user(&response, buf + done, response_size); > > > + if (rc) > > > + break; > > > + > > > + /* Get the device that this response targets at. */ > > > + idev =3D container_of(iommufd_get_object(fault->ictx, > > > + response.dev_id, > > > + IOMMUFD_OBJ_DEVICE), > > > + struct iommufd_device, obj); > > > + if (IS_ERR(idev)) { > > > + rc =3D PTR_ERR(idev); > > > + break; > > > + } > > > + > > > + /* > > > + * Get the hw page table that this response was generated > for. > > > + * It must match the one stored in the fault data. > > > + */ > > > + hwpt =3D container_of(iommufd_get_object(fault->ictx, > > > + response.hwpt_id, > > > + > > > IOMMUFD_OBJ_HW_PAGETABLE), > > > + struct iommufd_hw_pagetable, obj); > > > + if (IS_ERR(hwpt)) { > > > + iommufd_put_object(&idev->obj); > > > + rc =3D PTR_ERR(hwpt); > > > + break; > > > + } > > > + > > > + if (hwpt !=3D fault->hwpt) { > > > + rc =3D -EINVAL; > > > + goto put_obj; > > > + } > > > + > > > + group =3D NULL; > > > + list_for_each_entry(iter, &fault->response, node) { > > > + if (response.grpid !=3D iter->last_fault.fault.prm.grpid) > > > + continue; > > > + > > > + if (idev->dev !=3D iter->dev) > > > + continue; > > > + > > > + if ((iter->last_fault.fault.prm.flags & > > > + IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) > && > > > + response.pasid !=3D iter->last_fault.fault.prm.pasid) > > > + continue; > > > > I am trying to get vSVA working with this series and got hit by the abo= ve > check. > > On ARM platforms, page responses to stall events(CMD_RESUME) do not > have > > an associated pasid. I think, either we need to check here using > > IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID or remove the check > > as it will be eventually done in iommu_page_response(). >=20 > That doesn't sound right.. >=20 > The PASID is the only information we have for userspace to identify > the domain that is being faulted. It cannot be optional on the request > side. >=20 Yes, it is valid on the request side. But this is on the response side. > If it is valid when userspace does read() then it should be valid when > userspace does write() too. >=20 > It is the only way the kernel can actually match request and response > here. The kernel currently checks the pasid only if IOMMU_FAULT_PAGE_RESPONSE_NEE= DS_PASID is set. https://lore.kernel.org/linux-iommu/20200616144712.748818-1-jean-philippe@l= inaro.org/ > So, I think you have a userspace issue to not provide the right > pasid?? This is not just ARM stall resume case, but for some PCI devices as well as= per the above commit log. So do we really need to track this in userspace ? Thanks, Shameer