Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp643105rdb; Mon, 15 Jan 2024 08:47:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEi1Um6cvbHhgjm3Ud1dvYsvB8xI34kbgofxkkZ5SHiFjp6F4sh0/KCMYHOcOcWcXlQD5vv X-Received: by 2002:a05:6871:28a4:b0:209:b23:b990 with SMTP id bq36-20020a05687128a400b002090b23b990mr3203709oac.64.1705337263544; Mon, 15 Jan 2024 08:47:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705337263; cv=none; d=google.com; s=arc-20160816; b=cugEFT8Zo1CgZn2SCXMi6nOcSo0pEZzTwP1xFChtYeJ3i9ECFYVkzuVF/IbBA+u8gd OxwUOZofPyM62W6BcG9OQupLcJGcAeyKlycBn2gCDy5I6yfhYyHfBGAyjm46F8cOGAft 7PYpaW4S1/PxPrSJetv9AewpuRSAr+b0hw2SF9O+jp104pvnVxr2oBFAhwXMCHHHzs/c m87wWXDOPuRbQeOokuHk0PB0UA+2cAlaKKSPyC7vcJh+RZ+BMKuP+/TjaxGmfYOhFwqJ jfAa4m8kMhSXOdFIa9i3ob4r6RGcaoSRKRw0wuPSbzPvdynXkXGrRZ8cWhkOyYvD18Fr PWQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2crKgiTXcC8UeiyKNQE9cMBlk/o9KLy3IDkuGS6sULY=; fh=0mbG92jHgBxwQEr8PNrEFCJOgdGC4ALxSM2tBqI6lgo=; b=xZ769VtUrV7+ixZ92FnbFkpmG7UHa1rQEJwSHhs3LoFFU3/2GLBAQOkodbtLU+AVdF mDllNzXfT+K+2ZvuKAEbdTmbFBs2D4fNXa/2pqLluXG4i+MIx1+RTmRgCUOqkOA+WmQy EviU5Z9nztpjVhNwntxZJslkS7eXYRAa3vihnkut8pSpKvvftm2KkmxBJsBaFsSpC6mi WWIbE+XydnYFWC0Q+ldHQybZtHKEF8q70u1nGlNW4ipYLyK5f7go/6ytA7HV2Pi9U9m8 lVPqlr4SjsMAIrZVBI/WN6+t7lv8XYuNFHiAzJc5egfjuNMSpLXRdAXOEdtmJTUcTnJp kfLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=CXTf4ULA; spf=pass (google.com: domain of linux-kernel+bounces-26273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26273-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m9-20020a654389000000b005cec914cfe3si9154718pgp.882.2024.01.15.08.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 08:47:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=CXTf4ULA; spf=pass (google.com: domain of linux-kernel+bounces-26273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26273-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A86BEB20C29 for ; Mon, 15 Jan 2024 16:47:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E21917BDD; Mon, 15 Jan 2024 16:47:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="CXTf4ULA" Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D55A817BBB for ; Mon, 15 Jan 2024 16:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-42987bc95ffso62273171cf.1 for ; Mon, 15 Jan 2024 08:47:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1705337244; x=1705942044; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=2crKgiTXcC8UeiyKNQE9cMBlk/o9KLy3IDkuGS6sULY=; b=CXTf4ULANBlsxZH7fNrB1jHo8dsybZRvmn/EjjxEh5KnfABZN9bZP0941evoYudrr9 lXHtL/ZPsnc43eRgTP4YzRQWaeulBc7pZOrsSNUAwEYPLu23TM7kiHLPN1phL9Mk171o xNwq+psMRxKXTchZ1aAqJVYRntT+T+KE9WvWaF94GsuvaPJ8inFA6h29AwS3Lo5EwSRn xch7dkqd8KzQhYnO0PgwKVJXi+4HUIpeaLL6SkXDS59lKU1AZ4Lr6zBzidXrue+QzQqh 075QbzLJARYzcaQg+rlLfRu2HBC4noVa8lH2UAvrSa8PYP06xMgqaYA4kRQUCtnx9g1Z r45g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705337244; x=1705942044; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2crKgiTXcC8UeiyKNQE9cMBlk/o9KLy3IDkuGS6sULY=; b=B1OvbtK7z74MWemeWFUcxrRP2ES6Za5ClhTVDImlBq1oMLZEl7pmQ0ye1hTL17vvf8 JmJYf+xHq9MGsTN/nXhJIyPtjWnbfnOyG+yomqKe3rtkWUcFGWNIFWREgFXhcZ4pLCFa et+b4Qvgn+ZL6gFvvhm37I1Z5qLAyeL/g9HACKjThANmuTDJ5V3cSti0CDdQiNmzii6B 3hdkJhUMes8SK8NiqvvINsJpuV8hGrIsW/iSqOCtc6plHLIiwHlveBmw4Gdd73QIjFkV sedFTGMokbh6ZcLFotQmzlvENrUXh4UN9OIiGg7DNFwWHGsv7kxumG+PN4+lSKIAt34Y sAZQ== X-Gm-Message-State: AOJu0YxcDuhehjsQHQLRAUqDaXbgmOzV/iA9Dt8o27DfSAWdBUwinD+b bx1osPjvw7Foq7cKIQwbpj8WzTxnFhMVuA== X-Received: by 2002:a05:622a:11ca:b0:429:ffda:679c with SMTP id n10-20020a05622a11ca00b00429ffda679cmr139180qtk.25.1705337244703; Mon, 15 Jan 2024 08:47:24 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id eh18-20020a05622a579200b00425b3fd33f2sm4023338qtb.90.2024.01.15.08.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 08:47:24 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rPQ7P-003tM0-9N; Mon, 15 Jan 2024 12:47:23 -0400 Date: Mon, 15 Jan 2024 12:47:23 -0400 From: Jason Gunthorpe To: Shameerali Kolothum Thodi 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 Message-ID: <20240115164723.GB50608@ziepe.ca> References: <20231026024930.382898-1-baolu.lu@linux.intel.com> <20231026024930.382898-5-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 ; > > Nicolin Chen ; Yi Liu ; Jacob Pan > > > > Cc: iommu@lists.linux.dev; linux-kselftest@vger.kernel.org; > > virtualization@lists.linux-foundation.org; linux-kernel@vger.kernel.org; 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 = sizeof(struct iommu_hwpt_page_response); > > + struct hw_pgtable_fault *fault = 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 = 0; > > + int rc = 0; > > + > > + if (*ppos || count % response_size) > > + return -ESPIPE; > > + > > + mutex_lock(&fault->mutex); > > + while (!list_empty(&fault->response) && count > done) { > > + rc = copy_from_user(&response, buf + done, response_size); > > + if (rc) > > + break; > > + > > + /* Get the device that this response targets at. */ > > + idev = container_of(iommufd_get_object(fault->ictx, > > + response.dev_id, > > + IOMMUFD_OBJ_DEVICE), > > + struct iommufd_device, obj); > > + if (IS_ERR(idev)) { > > + rc = 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 = 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 = PTR_ERR(hwpt); > > + break; > > + } > > + > > + if (hwpt != fault->hwpt) { > > + rc = -EINVAL; > > + goto put_obj; > > + } > > + > > + group = NULL; > > + list_for_each_entry(iter, &fault->response, node) { > > + if (response.grpid != iter->last_fault.fault.prm.grpid) > > + continue; > > + > > + if (idev->dev != iter->dev) > > + continue; > > + > > + if ((iter->last_fault.fault.prm.flags & > > + IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) && > > + response.pasid != iter->last_fault.fault.prm.pasid) > > + continue; > > I am trying to get vSVA working with this series and got hit by the above 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(). That doesn't sound right.. 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. If it is valid when userspace does read() then it should be valid when userspace does write() too. It is the only way the kernel can actually match request and response here. So, I think you have a userspace issue to not provide the right pasid?? Jason