Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1447393rdd; Wed, 10 Jan 2024 22:09:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAaY6XG6DVqdw/Q4HAuG+srHuDDwYydBeYJ/1IvuYS/vzjfZl07XBq5KCryVMdMN5vniQK X-Received: by 2002:a17:907:970c:b0:a2a:6ff5:b111 with SMTP id jg12-20020a170907970c00b00a2a6ff5b111mr373777ejc.149.1704953396235; Wed, 10 Jan 2024 22:09:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704953396; cv=none; d=google.com; s=arc-20160816; b=Wp7rQKh3VsbNTwG2gDwnhSnfm66KAjrT+O7FNArw7FmnAABkUigUHSyhgPMbVe1uZs e7I5Z3gumjnShl7Vq5Nnrs3b6iCRr3s5kJcHk/Wl2KjW8KCj3QYaknnMF9g7OHgtuC/n awqvYMGWS6nQOkX2fO2ltPjS6IOrpzdPHna29mhh3d5Bre9DlaCGhU0uZCIIl+CI/7TN XbpWJR4xmu+YXotUl92XiF2XZlo6Po3a1dQT3kmYdDR7BAJ3syGB6WQ0o2Y/ujC4G5/t pPS3lPz0gNQnpu2N4EiPdf7p6CWvg7AqWnksK+fJAPG02y/5B1W8n5o63rUB0gvU3sg8 iJkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=3fodukQ4MbvQPnf2hpiDrMo420xpzoy49af9WX+hGGc=; fh=o21vhqUckBhZPB0tnLFE8x1jjJWz7Scm2klc6ZpXYNI=; b=GGAtu8JhJm1cO4AuV2P2Mws7+c6bWDMx6tKXWpnSpmHybiYpcIAFUN/xI9S55lx9R3 rzGBieMEvXgQ0AAwv+wUJaCAIREa/R2M3/6fVO6XZYD1QqYR3ID3j5+ROPb39XSUHPLe 2j8vPbK/ZBIBZrByPPFglqDO8h9uX7oG6+gdNJEK27txCiMabee4zWglBPd+Nv0pJHBx aySfnHL5lYhmhCURvQNxuHriBfX1n/LSdwl4atm783jfAlxFUXNs3q7AF93P2EawytGC RITw/NxSaNTms/MGXK62hiv7W9T/g4q/Dd9/geBwXCRLKERFaBBGe4D0WeIuFRRJJtpb OChQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=chwlfIhv; spf=pass (google.com: domain of linux-kernel+bounces-23081-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23081-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id rs3-20020a170907036300b00a2a225f0283si188717ejb.657.2024.01.10.22.09.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 22:09:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23081-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=chwlfIhv; spf=pass (google.com: domain of linux-kernel+bounces-23081-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23081-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 am.mirrors.kernel.org (Postfix) with ESMTPS id CCAA31F2291B for ; Thu, 11 Jan 2024 06:09:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C9B6257C; Thu, 11 Jan 2024 06:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="chwlfIhv" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) (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 B9BE62106; Thu, 11 Jan 2024 06:09:44 +0000 (UTC) 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=1704953384; x=1736489384; h=message-id:date:mime-version:subject:from:to:cc: references:in-reply-to:content-transfer-encoding; bh=KGtYZsJC4TBgZKJwilqWl0QJw+fI3o8R6G423oC0iYY=; b=chwlfIhv4T6iMk26aqu6HVuamhLPJFVm2g/fN4frPbS8+4wDwfPFVPLT 7hv18spcn7BOEv5/Z8j2ebkt64r7vogrmQaOy9hHwMHobr8GqqcefbNbx +1NZxUD19lCYJ1+Bj76/3Iq3L2ISFtiIFUUtN3ZksTe2tTjVl6ZyoZ5Ln jl3suZQEamsuiASwyPT5Dlwslt6l7mq3MxVe2dNoBjGbsQaJkJ8eXJ3kq WFHlqdSRHa3WR9Y2ZmQHFihwiSAy+VTeGX1G7ddKdVlBzBGVkC0nSQQ64 srd63/D//lLrOfkjkPSHjdhNCj1+DnAiINR/ojlcr6OGSOOU5gvti7XjA A==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="429936063" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="429936063" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 22:09:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="782504102" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="782504102" Received: from zhaohaif-mobl.ccr.corp.intel.com (HELO [10.93.8.238]) ([10.93.8.238]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 22:09:40 -0800 Message-ID: Date: Thu, 11 Jan 2024 14:09:37 +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 Subject: Re: [RFC PATCH v10 5/5] iommu/vt-d: don't loop for timeout ATS Invalidation request forever From: Ethan Zhao To: Baolu Lu , kevin.tian@intel.com, bhelgaas@google.com, dwmw2@infradead.org, will@kernel.org, robin.murphy@arm.com, lukas@wunner.de Cc: linux-pci@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20231228170504.720794-1-haifeng.zhao@linux.intel.com> <20231228170504.720794-3-haifeng.zhao@linux.intel.com> <53c563ad-b47b-4962-abc7-f0da3a7181d6@linux.intel.com> <65312590-01e1-4f53-a0dc-fc22f75379cd@linux.intel.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/11/2024 11:44 AM, Ethan Zhao wrote: > > On 1/11/2024 10:31 AM, Baolu Lu wrote: >> On 1/10/24 4:40 PM, Ethan Zhao wrote: >>> >>> On 1/10/2024 1:28 PM, Baolu Lu wrote: >>>> On 12/29/23 1:05 AM, Ethan Zhao wrote: >>>>> When the ATS Invalidation request timeout happens, the >>>>> qi_submit_sync() >>>>> will restart and loop for the invalidation request forever till it is >>>>> done, it will block another Invalidation thread such as the fq_timer >>>>> to issue invalidation request, cause the system lockup as following >>>>> >>>>> [exception RIP: native_queued_spin_lock_slowpath+92] >>>>> >>>>> RIP: ffffffffa9d1025c RSP: ffffb202f268cdc8 RFLAGS: 00000002 >>>>> >>>>> RAX: 0000000000000101 RBX: ffffffffab36c2a0 RCX: 0000000000000000 >>>>> >>>>> RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffab36c2a0 >>>>> >>>>> RBP: ffffffffab36c2a0 R8: 0000000000000001 R9: 0000000000000000 >>>>> >>>>> R10: 0000000000000010 R11: 0000000000000018 R12: 0000000000000000 >>>>> >>>>> R13: 0000000000000004 R14: ffff9e10d71b1c88 R15: ffff9e10d71b1980 >>>>> >>>>> ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018 >>>>> >>>>> (the left part of exception see the hotplug case of ATS capable >>>>> device) >>>>> >>>>> If one endpoint device just no response to the ATS Invalidation >>>>> request, >>>>> but is not gone, it will bring down the whole system, to avoid such >>>>> case, don't try the timeout ATS Invalidation request forever. >>>>> >>>>> Signed-off-by: Ethan Zhao >>>>> --- >>>>>   drivers/iommu/intel/dmar.c | 2 +- >>>>>   1 file changed, 1 insertion(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c >>>>> index 0a8d628a42ee..9edb4b44afca 100644 >>>>> --- a/drivers/iommu/intel/dmar.c >>>>> +++ b/drivers/iommu/intel/dmar.c >>>>> @@ -1453,7 +1453,7 @@ int qi_submit_sync(struct intel_iommu >>>>> *iommu, struct qi_desc *desc, >>>>>       reclaim_free_desc(qi); >>>>>       raw_spin_unlock_irqrestore(&qi->q_lock, flags); >>>>>   -    if (rc == -EAGAIN) >>>>> +    if (rc == -EAGAIN && type !=QI_DIOTLB_TYPE && type != >>>>> QI_DEIOTLB_TYPE) >>>>>           goto restart; >>>>>         if (iotlb_start_ktime) >>>> >>>> Above is also unnecessary if qi_check_fault() returns -ETIMEDOUT, >>>> instead of -EAGAIN. Or did I miss anything? >>> >>> It is pro if we fold it into qi_check_fault(), the con is we have to >>> add >>> >>> more parameter to qi_check_fault(), no need check invalidation type >>> >>> of QI_DIOTLB_TYPE&QI_DEIOTLB_TYPE in qi_check_fault() ? >> >> No need to check the request type as multiple requests might be batched >> together in a single call. This is also the reason why I asked you to >> add a flag bit to this helper and make the intention explicit, say, >> >> "This includes requests to interact with a PCI endpoint. The device may >>  become unavailable at any time, so do not attempt to retry if ITE is >>  detected and the device has gone away." > > That is to say, the usage of this function finally becomes that way, > > the user space interface could submit request with mixed iotlb & devtlb > > invalidation together in the queue or seperated iotlb/devtlb > invalidation. > > we depend on caller to pass the QI_OPT_CHECK_ENDPOINT as option > > bit to bail out even there is other iotlb invalidation in the same > batch ? > > then is user's call to choose retry the iotbl /devtlb invalidation or > not. > > if the caller hits the case the endpoint dead, the caller will get > -ETIMEDOUT/ > > -ENOTCONN as returned value, but no real ITE in its interested list, to > > tell userland user what happened, we fake a DMA_FSTS_ITE for user ? > > given we wouldn't read a ITE from DMA_FSTS_REG that moment. > > > 1. checking the first request for devTLB invalidation will miss chance to > >    check endpoint state if the iotlb & devtlb invalidation were mixed. > >    here explict option bit would be better.  while valid pdev does the > >    same thing.  so if pdev passed, no need to check for QI_DIOTLB_TYPE > >    || QI_EIOTLB_TYPE in qi_submit_sync() & qi_check_fault(). > > > 2. seems not perfect to drop or retry whole batch of request if there is > >   devtlb invalidation within the batch, let caller to choose the later > action > >   is simpler than making the qi_submit_sync() too complex. > > > 3. fake a DMA_FSTS_ITE for user's interested list on behalf of hardware > >   is better than no error/ fault feedback to user even it is predicted > not > >   happened yet. > > See Intel VT-d spec r4.1, section 4.3 & section 6.5.2.10 We should keep the original retry logic intact, in order to not break the fault handling flow. only breaks the loop when endpoint device is gone with returned error code to reflect the reality.  not -ETIMEOUT, that is not triggered yet, but will hit ITE later about previous request, and software should handle it smoothly to let the other subsequent requests could be done in next try. Thanks, Ethan > my cents. > > > Thanks, > > Ethan > > > >> >> Best regards, >> baolu >