From patchwork Thu May 6 13:59:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12242191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11BF8C433ED for ; Thu, 6 May 2021 14:00:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B62666103E for ; Thu, 6 May 2021 14:00:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B62666103E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.123548.233072 (Exim 4.92) (envelope-from ) id 1leeYK-0008I7-0d; Thu, 06 May 2021 14:00:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 123548.233072; Thu, 06 May 2021 14:00:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leeYJ-0008Hv-TA; Thu, 06 May 2021 14:00:31 +0000 Received: by outflank-mailman (input) for mailman id 123548; Thu, 06 May 2021 14:00:30 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leeYI-0003iB-O2 for xen-devel@lists.xenproject.org; Thu, 06 May 2021 14:00:30 +0000 Received: from mail-qk1-x72c.google.com (unknown [2607:f8b0:4864:20::72c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d772169a-d0f4-4cdc-a684-7476d154bdc6; Thu, 06 May 2021 14:00:03 +0000 (UTC) Received: by mail-qk1-x72c.google.com with SMTP id 197so4935247qkl.12 for ; Thu, 06 May 2021 07:00:03 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:6095:81da:832e:3929]) by smtp.gmail.com with ESMTPSA id 189sm2069992qkh.99.2021.05.06.07.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 07:00:01 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d772169a-d0f4-4cdc-a684-7476d154bdc6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ybgo2iqpAthKznwUf2rKB8sj2C1FVcmokKqjDDD9c5k=; b=QEMn2z8Au1zTcK9KWNUAWf4/pwLJGCha5xCHPbaVcHvwTs/0WGeDRi+dSSLkj+PFGd 4DPTDrPpCoBGdEGFejSupnuB+2ecOeU06MvzCQFF4Z4YIc0V09aZGj5Jea66cvYjABzy upkTZ1/LVmbDH46CpQSVtDMmhaQRMlMJ50/DPtppaq76ByrVqcXk7PZVdjbnqRBYfrK6 o5uIPQNEnoCso1VhvhvrN8PTVvJsleyC5gE2wrCqOomdQP6iHpSBulGhGXC4/z5+jybO zE41gDLiMQffA77a8KAFAyKdaMoJhCp5S+VEkXRu+IFYewK60CD6hvfCjuscdjXREmzS D3PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ybgo2iqpAthKznwUf2rKB8sj2C1FVcmokKqjDDD9c5k=; b=X4L74DWmgglI3gIgXV84TsVIHfaiZc2Gz1qwQINdvk7hQ7E0p7DTwxqTI1MKJE2HJS Kwr5wVqtXaxTq0wOAznR/zocitG/C7yM917IfYU2U3+hGr23mhUEseBPznzMMRzH0h5M YWWz/zq0Y/d9Hl1mPu9Ox4RzNniqIqKTZkivb42Y4MkHF+5pa38sUNzDK4hjUbHbbJjO 3VgQUBD9pksXMeEM8LeFLJyn19l0kP6Ch/hZ6HxPCUS1ohDuww3wm1UM3feahMsem/tf g4y21C6oHM3y9jeLUS7sCxghL1drxPVZbVT/+taHqXYBbzo3eWQSH5NdQpA++zLNMOSA 7JqA== X-Gm-Message-State: AOAM530+lpr04dCiaNyEpN1GVx9HBD8mvQQlYG8MPnW3cKRUXJCfSIeM V9dvm/FR/NTogq689ZgKD2VmLqa5aWA= X-Google-Smtp-Source: ABdhPJwYESUQtl/XOHs0n5w17jqWUNLlZiVMYKCuK2J/fCzM3i3lA5rxNuBIThjTw2IEM0dxq30QDw== X-Received: by 2002:a37:45d3:: with SMTP id s202mr4141671qka.424.1620309602421; Thu, 06 May 2021 07:00:02 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Daniel De Graaf , Quan Xu , Samuel Thibault , Samuel Thibault Subject: [PATCH v2 08/13] vtpmmgr: Shutdown more gracefully Date: Thu, 6 May 2021 09:59:18 -0400 Message-Id: <20210506135923.161427-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210506135923.161427-1-jandryuk@gmail.com> References: <20210506135923.161427-1-jandryuk@gmail.com> MIME-Version: 1.0 vtpmmgr uses the default, weak app_shutdown, which immediately calls the shutdown hypercall. This short circuits the vtpmmgr clean up logic. We need to perform the clean up to actually Flush our key out of the tpm. Setting do_shutdown is one step in that direction, but vtpmmgr will most likely be waiting in tpmback_req_any. We need to call shutdown_tpmback to cancel the wait inside tpmback and perform the shutdown. Signed-off-by: Jason Andryuk Reviewed-by: Samuel Thibault Reviewed-by: Daniel P. Smith --- stubdom/vtpmmgr/vtpmmgr.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stubdom/vtpmmgr/vtpmmgr.c b/stubdom/vtpmmgr/vtpmmgr.c index 9fddaa24f8..46ea018921 100644 --- a/stubdom/vtpmmgr/vtpmmgr.c +++ b/stubdom/vtpmmgr/vtpmmgr.c @@ -67,11 +67,21 @@ int hw_is_tpm2(void) return (hardware_version.hw_version == TPM2_HARDWARE) ? 1 : 0; } +static int do_shutdown; + +void app_shutdown(unsigned int reason) +{ + printk("Shutdown requested: %d\n", reason); + do_shutdown = 1; + + shutdown_tpmback(); +} + void main_loop(void) { tpmcmd_t* tpmcmd; uint8_t respbuf[TCPA_MAX_BUFFER_LENGTH]; - while(1) { + while (!do_shutdown) { /* Wait for requests from a vtpm */ vtpmloginfo(VTPM_LOG_VTPM, "Waiting for commands from vTPM's:\n"); if((tpmcmd = tpmback_req_any()) == NULL) {