Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2431858rdb; Wed, 21 Feb 2024 07:31:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQ/2AINbTyGAL4LhoLRxwtF1IyERUuLSU7mFrlzw5h7HW3DwpoF4b35MgQfuYgv0WZEAT7Bx8e47qGSNVj+lojQRnwX6NY31ZFXy4imQ== X-Google-Smtp-Source: AGHT+IF1+nLD3pwuquN9p87JLgQsj/gEY1WvNTn3Sl1M9iLxgK3nddGiWUZK8dCLTYWReF4bdoGt X-Received: by 2002:a17:906:d9b:b0:a3f:5b2d:b135 with SMTP id m27-20020a1709060d9b00b00a3f5b2db135mr534272eji.1.1708529479514; Wed, 21 Feb 2024 07:31:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708529479; cv=pass; d=google.com; s=arc-20160816; b=s+clnc4xX/dulYsG4ywR/URPY3EXQ09BjRqiv8bUBcmdgYpAp5PmG40Rm5xI+k4xbh X6fWHGdhFW4cq+lRLiFxQ36ID6MaCutqjMN72Riat1GGN9YExONJBI9OPziRFswXCTgg Ckir8WocXlfKiG6kg9jKLEwnBqzY1+Vl+E2+EFAQPOgVI1Fo2SZUZKwrXKKVVADU7ELD TB9TX+v200HtCkyrsLqN3vH0Sz216gffzBL0nFET6ar3l+xsAPLaGJ22IRdL3HyZxudV MiLFSp7Tp9cav9PD+HH1XndvVZbsPFNp7V2HDgJXEu5KCbUC+rLkLRQAZovrZeQKOBkB cZRA== ARC-Message-Signature: i=2; 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=c8vitvLSu3BTqhP5sHDKjXQCZ2zP56e0qTlYZFKdquc=; fh=X/Rf2fbtQahR4ImKeZxY4zhGzWT49L7Pygewprd9ME8=; b=dxWPqfiP3tsV/PayuLvGLYrf4QpWYR6JfN4Uy9i/HjmW1OeeBwsijZwj06Q0AVgAew Yg/zqaUGe4s6L61m/f3IzkOmpYhksQ/8wgx52qfQFrGgVX9vd0pIuESckRWX3E+SnSQp MSvHaNvHMr78Spyu2OmI9HwPCLRMKM7Tyyo8j3H2lwdbGJQ3ou8DSxdKZupbfTQWr6eW 9BK6U5yVcrhIQwGqukNRBqU29q3DK8PCTwJJPiWhD+cd+COr6XqQ/q+8lrD1PtWT/x9C /sQcD5m0vRonRHrpurG6lcnHsjsmdlaFSocVkEIFjEhB4mX8BNDaumgSffK++WfqUcG/ ss8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=mmJQK06I; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-74996-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74996-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hr35-20020a1709073fa300b00a3e82780adcsi3392609ejc.1047.2024.02.21.07.31.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:31:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74996-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; dkim=pass header.i=@ziepe.ca header.s=google header.b=mmJQK06I; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-74996-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74996-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 43A0B1F2527E for ; Wed, 21 Feb 2024 15:31:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F99A80629; Wed, 21 Feb 2024 15:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="mmJQK06I" Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 D06A27F7FD for ; Wed, 21 Feb 2024 15:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708529472; cv=none; b=uOgxiJ1/O5/J8yIuEuwMhcCb5mH432Mm73iKskbl6bLtZoUj0kEGvujvQe2J7yUCoI9SZNRheP7YZBJjyPr82kxLuZKUcft6adWtpDqzbjpPUAuVDhY7oYgkMBjHBairxKBxoYyZlTOhGpPIpXI2bz1/o/yFAFBCijSeS8BxlJ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708529472; c=relaxed/simple; bh=jfPSTOMFsVKRVNj7i8lkM+J2021KR6bAVax6Lo6yiIM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GXWCykl5h8NyeE3L05Sr3B4fizrVk5qwX9BT32D96ep/CxfyLdL1gknRSDftxXylzG+TjV41RqsWmaRw7qS60O4OyhdRBSLdt6CddA4o0ECZnNAVeh4bqxfnrgId8BZ0YOCgyZkBMNCs45NjL+rgRrxUUELc7H9PAcCMc/gKCgc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=mmJQK06I; arc=none smtp.client-ip=209.85.222.178 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-qk1-f178.google.com with SMTP id af79cd13be357-7838af983c1so491808185a.3 for ; Wed, 21 Feb 2024 07:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1708529469; x=1709134269; 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=c8vitvLSu3BTqhP5sHDKjXQCZ2zP56e0qTlYZFKdquc=; b=mmJQK06IbHLsFZq0E2JWBzGlRGtftqJ09T+fBYOtuW2WNPcyH2nEMBiah4Q1GpJowW BaoEKiYdCY/ELiZOeVxQFH+GVWw/9H3eO4pH5MKu2bCY6/w/yH16WHCSBRvimZmsLHJl 7791vzaASCH9nYXtUb31zoMQVxRAAmUzXiJKlbZbE99CZZhAs7ME/NGRse+zKdubciT8 a+kBdpmONJZGKT5ewfdTtZVYY8/vreLg/2RwTVf1+1TM2sek9fmMX2s3bRpvX9+150pY 8nCFdbwv0ifgWSt2XqUJqvNNN6z0cjUbhSzj+PUcuUG13OumxFHdob/jEmr90sBxqAyq I2fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708529469; x=1709134269; 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=c8vitvLSu3BTqhP5sHDKjXQCZ2zP56e0qTlYZFKdquc=; b=JYgziH6jDk1H3FLvt9VsyBDek7Sa4pVznBM7UZXqG0d2shvsAGpRA6oFXIEazWvrUx szbX0Jv9/QLXOOPc9ujtcRGJDQ7wHSLbsjjXKhEx4NhCCE9ECP0sxH16RAmA7rggW0if svrcL48ztO/Ffd7KXzz8//ULSkhUBY177wyr0nY3hRKikIZB42fdL01c/q+ox5dh6X1b Y5o3Mo7ERs/V6t43mBT5uL58JPcSjAfUfCAetvL6vSaXkYbFlLC7shCT38V+jbXBV6g+ 2judzZP/MZO1/lS+T433bVOnBe+QLjdBfpRDC+/eo8gst6yeccTFbmPSH09aqez5J/dQ fJ+A== X-Forwarded-Encrypted: i=1; AJvYcCUZEJYzWZ2hYybSbLRjSuX4XaX3sR/csJaE5Tn/Pvf+L8mLIvaXyU4ZWxGmlckSPp5SfFm8QZ/YPDf1QHmb/RSwkdRoHEtfhBmVtz/w X-Gm-Message-State: AOJu0Yyk8DPbl20cQY+TUc8Dm227K/f+kK5tcN2ETYe1NLtt6JmTBp23 C2CGbakEv1DY+ct2Wn6ShvYoKHSko3EgSANbDiG0f+BSa3O33qw0epUJxvUM0lM= X-Received: by 2002:ae9:f80f:0:b0:786:2d19:93cc with SMTP id x15-20020ae9f80f000000b007862d1993ccmr20111512qkh.73.1708529469737; Wed, 21 Feb 2024 07:31:09 -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 oo8-20020a05620a530800b00783f8693df1sm4420166qkn.37.2024.02.21.07.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:31:08 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rcoYu-00BOuq-6n; Wed, 21 Feb 2024 11:31:08 -0400 Date: Wed, 21 Feb 2024 11:31:08 -0400 From: Jason Gunthorpe To: Baolu Lu Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Huang Jiaqing , Ethan Zhao , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] iommu/vt-d: Use device rbtree in iopf reporting path Message-ID: <20240221153108.GA13491@ziepe.ca> References: <20240215072249.4465-1-baolu.lu@linux.intel.com> <20240215072249.4465-3-baolu.lu@linux.intel.com> <20240215175534.GD1299735@ziepe.ca> <67391b2d-b441-4d43-aa46-2a30c95420a3@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: <67391b2d-b441-4d43-aa46-2a30c95420a3@linux.intel.com> On Sun, Feb 18, 2024 at 03:02:00PM +0800, Baolu Lu wrote: > A device hot removing goes through at least the following steps: > > - Disable PRI. > - Drain all outstanding I/O page faults. > - Stop DMA. > - Unload the device driver. > - Call iommu_release_device() upon the BUS_NOTIFY_REMOVED_DEVICE event. > > This sequence ensures that a device cannot generate an I/O page fault > after PRI has been disabled. So in reality it's impossible for a device > to generate an I/O page fault before disabling PRI and then go through > the long journey to reach iommu_release_device() before > iopf_get_dev_fault_param() is called in page fault interrupt handling > thread. Why is this impossible? Seems like a classic race.. Flush the HW page fault queue as part of the above to ensure there is no concurrent iopf_get_dev_fault_param() on the now PRI disabled BDF. > Considering this behavior, adding a comment to the code explaining the > sequence and removing put_device() may be a simpler solution? A comment is definitely needed Jason