From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=44.245.243.92 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795977325; b=0FwqWPnaIM6SzLLxRCJavxox1qEznAn0+2cbfOwyQ37W0Q/mUbXxOX31EuT1R0nbFUrZ fWZ1DcUGsZ7dx9KDPDOPoLL2Rh/d9sEQsAePOtnwFMzANbL5rOeQcCEp9+5DqAgX6b4pS 7SuImjO20sJ/5eDu4V+QXpJHL/cT8GT0KBF8UIK88x/yUtL+21G4zkxM7KiRxUq+geAvZ bw0vj0KPMm7cz17bd8EQs2aR4qxkQvdgAa2ha19dVx/ZDlbsbYUb9SCYgYd0pDHKNq9EG F6CCeSgqAUYaybOHYRXWdejPcnWa+MQGqTmPpV1h505ZxJoXpHXArB+bnPs5+nGK0Mw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795977325; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=dpjNhBbOeeMIRA0yJlCg88Aml+TpmebJNWqt85PYkgM=; b=BGRBFLx4bJf54YUK0m/a2dEUNb4kDjLDHNHbSVAWP1AzjXeVDN4skHCrdh8UKpQVcUcx FJxvEaw/tOHUswvJIGjszWk2vwNJZw7oi7TbJrY+3gAz7mmiZsBx6QCJmPvf4aOehwlOs zse/9VJ/JoY4cN0CNvjBL4+PpFvhVlocw07DfsWV64F9SWdvV0rjfuiLgNos3vZZgxjgV fnn8JU4ThbMSYNolF/W+vAwQM+eHUagy4hnMTpts83s0VBtFhlCmJHR8Ktlv/qSQohOCX 3/MLeC1b/mVBN4n1P6Hg4jqaxgZcn1fQt/P5jnu5Gn2oEKYcFjAVoxPTqiWa3Yw/WhQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.com; spf=pass smtp.mailfrom=amazon.de; dkim=pass header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=KYXkqlkp; arc=none smtp.remote-ip=44.245.243.92 Received: from pdx-out-001.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-001.esa.us-west-2.outbound.mail-perimeter.amazon.com [44.245.243.92]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA57E606A323; Sun, 29 Nov 2026 18:35:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA57E606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=KYXkqlkp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1795977324; x=1827513324; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dpjNhBbOeeMIRA0yJlCg88Aml+TpmebJNWqt85PYkgM=; b=KYXkqlkp7TRgOZgbxyJhR3eGoewpXf8HDLQI9jgNIYv3tA4sd8IbLJI6 lzeqqCrxxjeR6ob2Q9jCwmcBio40E6O5XdWGmnbw+CUOoPENThUnclLzc O1tqDFYgP7XaOYwrCEJ6NbEtVPIoYeqJEwbl/qn7Gkt8Hw7Lo/gKrTvy5 ADdzOp3ylP7/Gb9OGJg5aUDmU7NQ3h6hefgcNjM6ms4bspflRazoocMCp X1C/Kp0SkM1rPwL4A4Q3d7ZQD63RD4CD7AkVA8n41LQHtAQWu3MPSGMj0 m6icqV5MaWtr8VWzmf5QhKUPyAralM9AihdXErDTxqH3JV9tvkP9nWRxc w==; X-CSE-ConnectionGUID: m8ZhxS0IREK2NkUqrT4GIA== X-CSE-MsgGUID: NZ1+B8klRxWTADYEVux+pQ== X-IronPort-AV: E=Sophos;i="6.27,241,1787011200"; d="scan'208";a="34940370" Received: from ip-10-5-6-203.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.6.203]) by internal-pdx-out-001.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 18:35:24 +0000 Received: from EX19MTAUWC001.ant.amazon.com [205.251.233.53:21481] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.37.107:2525] with esmtp (Farcaster) id 37d03722-cac0-4b5a-baa1-861995f49e2b; Sun, 29 Nov 2026 18:35:24 +0000 (UTC) X-Farcaster-Flow-ID: 37d03722-cac0-4b5a-baa1-861995f49e2b Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Sun, 29 Nov 2026 18:35:23 +0000 Received: from ip-10-253-83-51.amazon.com (172.19.99.218) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Sun, 29 Nov 2026 18:35:20 +0000 From: Alexander Graf To: Greg Kroah-Hartman , Arnd Bergmann CC: The AWS Nitro Enclaves Team , , Paolo Bonzini , "Stefano Garzarella" , Stefan Hajnoczi , Marek Szyprowski , Robin Murphy , Andrew Morton , "David Hildenbrand" , Mike Rapoport , "Jonathan Corbet" , Shuah Khan , "Randy Dunlap" , , , , , , , , , Subject: [PATCH v2 23/23] nitro_enclaves: Time the wait for the device to turn off by the clock Date: Sun, 29 Nov 2026 18:21:52 +0000 Message-ID: <33be2afe4194ec3006c927fe46e4eaac7348a07e.1795965039.git.graf@amazon.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWA002.ant.amazon.com (10.13.139.96) To EX19D001UWA001.ant.amazon.com (10.13.138.214) Unbind, shutdown and the next probe give the nitro_enclaves device NE_DEFAULT_TIMEOUT_MSECS, 120 s, to turn off. The device turns off only once it has stopped every enclave and scrubbed its memory, which can take as long as a single ENCLAVE_STOP. ne_pci_dev_disable() also counts the wait in 10 ms steps of msleep_interruptible(). At HZ=100 each step sleeps two jiffies, so the wait takes 240 s, and with a signal pending it does not sleep at all. Allow the device NE_FREE_TIMEOUT_MSECS, 10 minutes, as for ENCLAVE_STOP, and poll the register with readx_poll_timeout(), which keeps a ktime deadline. Kiro, an AI coding assistant, found this while timing an unbind on hardware. Fixes: 89308c11ae3b ("nitro_enclaves: Init PCI device driver") Signed-off-by: Alexander Graf --- drivers/virt/nitro_enclaves/ne_pci_dev.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/virt/nitro_enclaves/ne_pci_dev.c b/drivers/virt/nitro_enclaves/ne_pci_dev.c index cd8e934e968c3..edc72d4f623e5 100644 --- a/drivers/virt/nitro_enclaves/ne_pci_dev.c +++ b/drivers/virt/nitro_enclaves/ne_pci_dev.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -550,8 +551,7 @@ static void ne_pci_dev_disable(struct pci_dev *pdev) { u8 dev_disable_reply = 0; struct ne_pci_dev *ne_pci_dev = pci_get_drvdata(pdev); - const unsigned int sleep_time = 10; /* 10 ms */ - unsigned int sleep_time_count = 0; + int rc; iowrite8(NE_ENABLE_OFF, ne_pci_dev->iomem_base + NE_ENABLE); @@ -560,17 +560,12 @@ static void ne_pci_dev_disable(struct pci_dev *pdev) * state is not immediately set to disabled and going through a * transitory state of disabling. */ - while (sleep_time_count < NE_DEFAULT_TIMEOUT_MSECS) { - dev_disable_reply = ioread8(ne_pci_dev->iomem_base + NE_ENABLE); - if (dev_disable_reply == NE_ENABLE_OFF) - return; - - msleep_interruptible(sleep_time); - sleep_time_count += sleep_time; - } - - dev_disable_reply = ioread8(ne_pci_dev->iomem_base + NE_ENABLE); - if (dev_disable_reply != NE_ENABLE_OFF) + rc = readx_poll_timeout(ioread8, ne_pci_dev->iomem_base + NE_ENABLE, + dev_disable_reply, + dev_disable_reply == NE_ENABLE_OFF, + 10 * USEC_PER_MSEC, + NE_FREE_TIMEOUT_MSECS * USEC_PER_MSEC); + if (rc < 0) dev_err(&pdev->dev, "Error in pci dev disable cmd\n"); } -- 2.47.1