Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1616807rdb; Wed, 31 Jan 2024 04:19:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNUnDQliN+4Fq1LaJVxEP9rj1qlrPf1wEqobnqsEljKAKQEKqdciU47zjWANRRkBw2hsme X-Received: by 2002:a05:6a20:a616:b0:19c:a020:248 with SMTP id bb22-20020a056a20a61600b0019ca0200248mr1194642pzb.17.1706703586361; Wed, 31 Jan 2024 04:19:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706703586; cv=pass; d=google.com; s=arc-20160816; b=zTMR+xuBJCobhlL7cbaStmCIEcZMmRdWVSKylrgj/Gw4JDUDZpb4D545JEYmwaIiUL DqtUDOf41CpKPC4+RsYF0Jnf8RvSRVCwC+3zaOANLDfPv+tLdtwWVZP6D7B4cg/gmSmF jrquSbGhVPM6sCtaa2pfYXa/kgYmsWGtBtMfVCDxOmha+GqPAK2/WVQqh1mxJb+i3T07 retNWETeKgX9PqBfpJD+Y4C3LrgSMyZJNoN/ba43cUfxItEuSToFpTR2H7PMXWagD1se weAOgmgBFqykYHBnViDsAQ61lBhZI6GeztdHOygemUupgkl7U33C7a/iwaKEcnYTnDZ2 TY0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=od3Z50C6QwZKaDmgylIaS5WQbjsmFqJdE43KCEwEDy0=; fh=wub1OUYgw3D7wLs/RB2i5Bvmy9EcuYVLOje6sGt8uVE=; b=dFNqw4uLU54sZ+ZaRo/QkF3j2aEpUTKEaligTfxJxK7tyShDX5pAqcsM6flRzXv62q dV5hPsSCjeSqI7Y1Gr9PO769SbUbh5irVuJM7gQymLLmbneQOUfysYccPi5W323f21F+ MA3x2nw3o1W/oKUHcCK8r1gsPFDP51QMRsa+2F5NtjnHYarmer/WBo3TYeJ5spzk3dKy 6HKFGki6SreTAOsl8RKmaMM2qLguCjFv8ixirTo319qNYk+jcyJLy9pyIsYQXVIGPBWI /WwoLw8h6o5AVn1J5UnUhe/6qLJAA6IOYqW4ZrEywseVmAUbqEeUDYzVMZ/qYVrvrgIv eFMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KaWI4yUS; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45813-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45813-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVIDFAJogSDTUEnSHZ3CUkHaVAuKjJvoiZyOVpfWK0ddjrD5NAM7Y9lpYzXYm1onuvt0oon2OxYfkD/TmskUDbxKZlTXIfv8edjyp3mfA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z16-20020a63e550000000b005d8b67aca77si7918768pgj.782.2024.01.31.04.19.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 04:19:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45813-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KaWI4yUS; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45813-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45813-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 48FF2B258C2 for ; Wed, 31 Jan 2024 06:21:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71BF83EA67; Wed, 31 Jan 2024 06:21:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KaWI4yUS" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 F29293E481; Wed, 31 Jan 2024 06:21:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706682088; cv=none; b=BGpJvapJOsmOSiMIDgaRi9iWliyO7ds8RNFmTLPScnnX7mAOgpMT7JBHOGuB8iih+RHtl1hAHvRdGBGaQ4IS8xGyYwbmq5OTwNsNZXYPngWMeNiJ2XxgMTV0OLOt+5PFwLJUrUp6Ku5qtH2q4jVTtvpw6f/s3E4GU6JX/72DaOM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706682088; c=relaxed/simple; bh=BFal/c7OdPWIXpcKKVgoT+h8Uly3mTIFcWBHU8qcqPc=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=SUSH3/W80CbpfPLwgPPUfGbTLiVjYifl2RwT4B2dAoJ0H6mClaWxz02FVfllVCVzWuHj3ChIIQRH3iivM3VTIInwDSRMw9nOoBQafv7X9EGT3tfw2ElisPWRLQ+WwqjQHZHQYK8JHYPFKxRY4xZzMqiygKlAtPMbPFbMa/OfZNM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KaWI4yUS; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706682087; x=1738218087; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=BFal/c7OdPWIXpcKKVgoT+h8Uly3mTIFcWBHU8qcqPc=; b=KaWI4yUS7aDiFgNzqm2DN3a0d+v0lNWDZSsQ3+qrRR09/EArXmZMCuyL O+NSpok14vmV5hFNaijh8A4+ITzVbKrdeF8pS7YTi5WP+3QRo6XPxpTwv lZSiyUCNH3w1zXVunAfmKPWyI5RuFw1k+MkNlzxr/spUoGD/uSdTApX50 C3C65IXDjj5ezhMKxXfN8UwBb3AxgPUlDnxD45b76jBTJTN+knH0zGNjc XXfH4Do49iBrLOqsfbQViK6mkrprCa0ysWqdyACpWPKV/O22y6RYaNQ1Q IXtYo2wIriXzZCUQq55yOO79fo8AM0WMwSZDwphgWEEXdb/rbDVV/BUvH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3347747" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3347747" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 22:21:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="36759621" Received: from wwang17-mobl.ccr.corp.intel.com (HELO [10.249.175.9]) ([10.249.175.9]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 22:21:22 -0800 Message-ID: <6a48f023-2701-4f2f-8077-14fe348794dd@linux.intel.com> Date: Wed, 31 Jan 2024 14:21:20 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, "Tian, Kevin" , "Liu, Yi L" , "bhelgaas@google.com" , "robin.murphy@arm.com" , "dwmw2@infradead.org" , "will@kernel.org" , "lukas@wunner.de" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-pci@vger.kernel.org" Subject: Re: [PATCH v12 5/5] iommu/vt-d: improve ITE fault handling if target device isn't present To: Jason Gunthorpe , Ethan Zhao References: <20240129034924.817005-1-haifeng.zhao@linux.intel.com> <20240129034924.817005-6-haifeng.zhao@linux.intel.com> <7adec292-9d38-41ab-a982-bd840b24f3ab@intel.com> <0aee453c-e98f-4b72-8107-31d4731abcdb@linux.intel.com> <500c4582-ec05-4a9e-9b68-d2ae19aed49b@linux.intel.com> <20240130162958.GF50608@ziepe.ca> Content-Language: en-US From: Baolu Lu In-Reply-To: <20240130162958.GF50608@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/1/31 0:29, Jason Gunthorpe wrote: > On Tue, Jan 30, 2024 at 04:15:33PM +0800, Ethan Zhao wrote: >> Some tricky situations: >> >> 1. The ATS invalidation request is issued from driver driver, while it is >> in handling, device is removed. this momment, the device instance still >> exists in the bus list. yes, if searching it by BDF, could get it. >> >> 2. The ATS invalidation request is issued from iommu_bus_notifier() >> for surprise removal reason, as shown in above calltrace, device was >> already removed from bus list. if searching it by BDF, return NULL. >> >> 3. The ATS invlidation request is issued from iommu_bus_notifier() >> for safe removal, when is in handling, device is removed or link >> is down. also as #2, device was already removed from bus list. >> if searching it by BDF. got NULL. >> ... >> >> so, searching device by BDF, only works for the ATS invalidation >> request is from device driver. > In the good path, where the hot removal is expected and this is about > coordinating, the IOMMU driver should do an orderly shutdown of the > ATS mechanism: > > 1 Write to PCI config space to disable the ATS > 2 Make the IOMMU respond to ATS requests with UR and set it to BLOCKED > 3 Issue a flush of the ATC > 4 Wait for all outstanding ATC flushes to complete > > If it is a bad/surprise path where the device is already gone then: > > 1 should automatically not do anything, possibly timing out > 2 must succeed > 3 should time out > 4 should "complete" in that the ATC flushes are all timed out > > IMHO all you need to do is not crash/lockup while processing the ATC > timeouts. If this is a surprise path then the ATC timeout might > already happened before the iommu driver remove notifier event happens. > > If the driver needs to translate from the IOMMU device table index > into a struct device it is probably best to do that inside the driver. > > eg ARM maintains a rbtree in the iommu dev data. (see > arm_smmu_insert_master) An rbtree for IOMMU device data for the VT-d driver would be beneficial. It also benefits other paths of fault handling, such as the I/O page fault handling path, where it currently still relies on the PCI subsystem to convert a RID value into a pci_device structure. Given that such an rbtree would be helpful for multiple individual drivers that handle PCI devices, it seems valuable to implement it in the core? Best regards, baolu