Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1627676lqt; Wed, 20 Mar 2024 09:18:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUqStNR9RGUq0t7HaOcYlNvOqOOMw50Bv+9ws8vp2SX3pJnLDOYZPyN6OuapstVc8O48pcEBJe8hi6uB8rP55jGHiQcHiByv2XirU+0Vw== X-Google-Smtp-Source: AGHT+IFKrfQgq3cPFfLtP+ZpjtIF+U/1zbOd0w+05oEqArRX4KXKAl4eA3UEcFhIZMIwSLWMbXOr X-Received: by 2002:a17:902:b216:b0:1e0:c9a:38c7 with SMTP id t22-20020a170902b21600b001e00c9a38c7mr5444065plr.32.1710951511531; Wed, 20 Mar 2024 09:18:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710951511; cv=pass; d=google.com; s=arc-20160816; b=FJj3Qbn3dUDRU94Ut1i+X5ibJnWS+QTWCEJ4S93y848SYf3smL2ljMbT8O5OUEy8Tr ZuO2Q3y+76E8+jLPIwbYyAEgITcC7m5dA2GbvQbjSZnSyvV/oYNjbmZv6DeAi5LOCc9M tvsgBZ9A8Wv82KzKlVEKF5JmEl+i8nUKs0oJKmUuuV61xP7Q5nNm63jPsWclVoFSf4ft 19Xe2Auqbv9UWT217lCRUZIuZ7+QVEApevC98sdT0BAUnUwvYmDlB7sHZk0BTNZ+rREJ V1EbNddz74UPGOsHOoFG2ze6KXGF8q0wFmN7xlwqKlW1wSL+qnWxFB7/L7C/WiKVs8S/ mt8A== ARC-Message-Signature: i=2; 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=gPaxdZtGi+vrxyHPHQWLp6bp9a33yYmK1eJvzUSwf4c=; fh=dUPHoNx/p/s4wYFQhL9/KtXM3HrsXZxTYJ5B+cWy42g=; b=cd5yQbXi6jEtRQAXFTzXEDyrOTqnIDCVYvBmMQqXcl4xH+1KOGBa+na5pBk/JhNc++ UgDXq6G8b2O6lnmhPXjg7k8yOQ+bjg0o0ziIswXejOgdtg67MfNqS8pkrMUrG1VMZ2EO nfYACApx39jEGqCsGEiXxyOTsiD1XFPtCSQrpv1KFPq/FxmQ/qJKjQpra2HcPXRMx+b9 IAiDnnG5Nh8pPpO4+FDhyWyJQdehZbix58R0RHdR2+bQBKN4BvFrRIgtMeUjoNrGnP8V IwuFvHiRs1EPoXcvZZ9fVCHisQ19nieY8i9ufYOSqcew85s+FT9hEQLSbxduFQ382O3i DLBQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-109153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109153-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j10-20020a17090276ca00b001dcb3207229si12971711plt.209.2024.03.20.09.18.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 09:18:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-109153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109153-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5C8D7283A57 for ; Wed, 20 Mar 2024 16:18:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25F6054F96; Wed, 20 Mar 2024 16:18:17 +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 A20F747F77 for ; Wed, 20 Mar 2024 16:18:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710951496; cv=none; b=uRFJT759BNSSU6laElNEFrGQqa9P5U/8s/QnCY1W4NBZlu8EDfB6fkDBeDsfPa5LRVD0pKw6wLzmXYGyEYQAzl2pWI5LEQY6nnGSq2UI/XDpnywXAi3e/6hPmggPDQ8cvRhcE86ch1TwFOAhDkKJ5jE5iElTuLgo7c7FD0Yfayg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710951496; c=relaxed/simple; bh=AA0UbQWWMDspRIn9QaELn/NgyElXsCyXOzsAvqZsR5Q=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=SkWe1Yay7eHZkXg2yAMQZD3dTTTP3ja3hMPGVgE6Zf4Y+vrx+45YYaIVjUe7RfXWgIoQ6KJODUYSBMNLvW0Lda8scfuxb9u5lKLijXin4h6plgVSkU63WaIJahUoxHCvxDy07TYyD+3gAcebGArjuEi6lJ2zs1/pVQaWJWfdwsw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 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.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4V0DJX73Pzz6K6Sy; Thu, 21 Mar 2024 00:17:32 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 7E5E7140B3C; Thu, 21 Mar 2024 00:18:05 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 20 Mar 2024 16:18:05 +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; Wed, 20 Mar 2024 16:18:05 +0000 From: Shameerali Kolothum Thodi To: Lu Baolu , Jason Gunthorpe , "Kevin Tian" , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , "Joel Granados" CC: "iommu@lists.linux.dev" , "virtualization@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v3 4/8] iommufd: Add iommufd fault object Thread-Topic: [PATCH v3 4/8] iommufd: Add iommufd fault object Thread-Index: AQHaTQcNFocLBOqngUqDZu3K/gB7pbFBJJkw Date: Wed, 20 Mar 2024 16:18:05 +0000 Message-ID: References: <20240122073903.24406-1-baolu.lu@linux.intel.com> <20240122073903.24406-5-baolu.lu@linux.intel.com> In-Reply-To: <20240122073903.24406-5-baolu.lu@linux.intel.com> 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: Lu Baolu > Sent: Monday, January 22, 2024 7:39 AM > To: Jason Gunthorpe ; Kevin Tian ; Jo= erg > Roedel ; Will Deacon ; Robin Murphy > ; Jean-Philippe Brucker ; > Nicolin Chen ; Yi Liu ; Jacob Pa= n > ; Joel Granados > Cc: iommu@lists.linux.dev; virtualization@lists.linux-foundation.org; lin= ux- > kernel@vger.kernel.org; Lu Baolu > Subject: [PATCH v3 4/8] iommufd: Add iommufd fault object >=20 > An iommufd fault object provides an interface for delivering I/O page > faults to user space. These objects are created and destroyed by user > space, and they can be associated with or dissociated from hardware page > table objects during page table allocation or destruction. >=20 > User space interacts with the fault object through a file interface. This > interface offers a straightforward and efficient way for user space to > handle page faults. It allows user space to read fault messages > sequentially and respond to them by writing to the same file. The file > interface supports reading messages in poll mode, so it's recommended tha= t > user space applications use io_uring to enhance read and write efficiency= . >=20 > A fault object can be associated with any iopf-capable iommufd_hw_pgtable > during the pgtable's allocation. All I/O page faults triggered by devices > when accessing the I/O addresses of an iommufd_hw_pgtable are routed > through the fault object to user space. Similarly, user space's responses > to these page faults are routed back to the iommu device driver through > the same fault object. >=20 > Signed-off-by: Lu Baolu [...] > +static __poll_t iommufd_fault_fops_poll(struct file *filep, > + struct poll_table_struct *wait) > +{ > + struct iommufd_fault *fault =3D filep->private_data; > + __poll_t pollflags =3D 0; > + > + poll_wait(filep, &fault->wait_queue, wait); > + mutex_lock(&fault->mutex); > + if (!list_empty(&fault->deliver)) > + pollflags =3D EPOLLIN | EPOLLRDNORM; > + mutex_unlock(&fault->mutex); > + > + return pollflags; > +} > + > +static const struct file_operations iommufd_fault_fops =3D { > + .owner =3D THIS_MODULE, > + .open =3D nonseekable_open, > + .read =3D iommufd_fault_fops_read, > + .write =3D iommufd_fault_fops_write, > + .poll =3D iommufd_fault_fops_poll, > + .llseek =3D no_llseek, > +}; Hi I am trying to enable Qemu vSVA support on ARM with this series. I am using io_uring APIs with the fault fd to handle the page fault in the Qemu. Please find the implementation here[1]. This is still a work in progress=20 and is based on Nicolin's latest nested Qemu branch. And I am running into a problem when we have the poll interface added for the fault fd in kernel. What I have noticed is that, -read interface works fine and I can receive struct tiommu_hwpt_pgfault dat= a. -But once Guest handles the page faults and returns the page response, the write to fault fd never reaches the kernel. The sequence is like below= , =20 sqe =3D io_uring_get_sqe(ring); io_uring_prep_write(sqe, hwpt->fault_fd, resp, sizeof(*resp), 0); io_uring_sqe_set_data(sqe, resp); io_uring_submit(ring); ret =3D io_uring_wait_cqe(ring, &cqe);=20 .... Please find the function here[2] The above cqe wait never returns and hardware times out without receiving page response. My understanding of io_uring default op is that it tries to= =20 issue an sqe as non-blocking first. But it looks like the above write seque= nce ends up in kernel poll_wait() as well.Not sure how we can avoid that for write. All works fine if I comment out the poll for the fault_fd from the kernel. But then of course Qemu ends up repeatedly reading the ring Queue for any pending page fault. It might be something I am missing in my understanding of io_uring APIs. Just thought of checking with you if you have any Qemu implementation using io_uring APIs to test this. Also appreciate any pointers in resolving this. Thanks, Shameer [1] https://github.com/hisilicon/qemu/tree/iommufd_vsmmu-02292024-vsva-wip [2] https://github.com/hisilicon/qemu/blob/2b984fb5c692a03e6f5463d005670d2e= 2a2c7304/hw/arm/smmuv3.c#L1310