From patchwork Wed Oct 21 07:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 318845 Delivered-To: patch@linaro.org Received: by 2002:a92:d1d1:0:0:0:0:0 with SMTP id u17csp1955463ilg; Wed, 21 Oct 2020 00:32:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4SKdKdE1FmoURecXYDZbwMpvCl0mjpxM5iwJTpRdwPNK9eTCZVR5o4/3efWnZC/UB/v8O X-Received: by 2002:a17:906:a282:: with SMTP id i2mr2088537ejz.39.1603265555755; Wed, 21 Oct 2020 00:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603265555; cv=none; d=google.com; s=arc-20160816; b=b9b5HnE219/SUhfVN8t+a419dX2zOrlLqQcl+7V/hR1BdFqDPguhLHbUwAyL6UKsNF xKYsMcv6ENdKLqyyGheOfO/gA+zhe6FM4rkQiNGcMxNL2hqApYCQGbMo9bTGt/KUoSi3 geZfaABPpMOTruOEZq+mv175PnsNhErRHvJTJ6flXGfaRzy4F8tbw1K9KHxjA34jkWii uy5mKgFecG3mrYbQRMqlq3CbCMC2lmo2dl3l6f/tUWlZdw/5pq+6r2HMxNf19piGxxpx ETkYNwei/y/+pLQJzW2SsFWv4D1RSdkHQKOnvGALxrp4OGZQorOd3A7XJxBoOPiY60ym XEEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=LwvNCplxuXVa8+oHVfp7+upkqwMaZ2efTzBwFxKsp1g=; b=btMyn2+bSxsx7vznLi/T/SAAabnasewmAK5detfkd25qCVO6rJZg5Qx2x1W0c++eUi iH8gvH1AfDlzYFWnZPcxjOLCaICBMygxA6qE2Gd290K6PFmqK1T0dGxKjPBDuyxnKBto KoUfZrvV3ywujKJLQUT3pCYdMnecPRMjO90ldRekwwdiikKzm3CsddcF/oD78CvX+rN1 SZaXxxPyz0lIhuilMLuI2Mb6NZgwp6KaHtuMRTtI4uYDgE5E1I+T7NI4RiQYjtnGdERN EKTZauGMufK5OmFFoqn5QSyw2mIZE4xeUodqp7IvS8p+COfVcNUn4TOHTAOiLiJ8kehs iiTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xsM5x5P7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id x18si752185ejn.61.2020.10.21.00.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 00:32:35 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xsM5x5P7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 51C3D81281; Wed, 21 Oct 2020 09:32:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xsM5x5P7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6362081B79; Wed, 21 Oct 2020 09:32:31 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B1353806C5 for ; Wed, 21 Oct 2020 09:32:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x443.google.com with SMTP id h5so1763648wrv.7 for ; Wed, 21 Oct 2020 00:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LwvNCplxuXVa8+oHVfp7+upkqwMaZ2efTzBwFxKsp1g=; b=xsM5x5P7FrnRZBZIjflC3b1tGcRwnyVk7oO4e55e3INUQ7D/Ek7V9TSxSRBm7LCw0w NqrGJKVlweZAH+GHKNeKKrnOwIXLf329DklY6AY1Ohcz+d5MeTa/Og+0tncMVM0kxHUE 77gTVIk18t2s+r1EnFUgAI23b3QycxbaeIRLG0FJIkBf4+iUh4UIIBRRoyAhwsLKfWwg AMAs/4GO7DQ3Oh+1dgz9841xZgXfHQPFNviMalCAzBBIbsHyoqjC9Q1l/zQYwaAxlPqS SVf7KqiUSYtJwU9a1EtI1su0dNuiPeOP1gxaWNiwU7eOv7DibmIf6ZLtnxipyzrFudY9 EjVA== 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:mime-version :content-transfer-encoding; bh=LwvNCplxuXVa8+oHVfp7+upkqwMaZ2efTzBwFxKsp1g=; b=TPqgO0oEHpEeigzw2uEcCM3y2HD/pHwIaU6K8wTFpAYhNmqUdfhSJUscLYa+dcRDuY ubK/ZEcTZDyJ/OYebzExawPZdheQ1Tltiji78+0A63Kraejw6XGJb3lmLyUcYJTOhWTw PuMQn24q3HG8mJqTc6RlMCjS8ONaDFQGaRrX11dzolbK0Tk/urPobQuegB/NewXPztcD xoD84ZtzgysQigBm7K1acCppV73pWCnGsEkqaUdxEvtN/KaODA2lZZQYh/OIpQAK9zyM dtFGCsMVbfqKDgZ/y912s9/Xh1ZBtvLO2P8UzyK9WaPXxNTV0x0/xSdKCst0wZW6jbwE +B5w== X-Gm-Message-State: AOAM533jXY4mH7NRVmQtwldw/TF7FZg9fXy2eokMXN82cc7lrr9zmF8q jQjZfJZXh995i3LlDNBXd70LI+lufvFhOQ== X-Received: by 2002:adf:f88a:: with SMTP id u10mr2960747wrp.1.1603265547837; Wed, 21 Oct 2020 00:32:27 -0700 (PDT) Received: from apalos.home ([2a02:587:4615:c071:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id d30sm2254914wrc.19.2020.10.21.00.32.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 00:32:27 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de, xypron.glpk@gmx.de Cc: agraf@csgraf.de, Ilias Apalodimas Subject: [PATCH] efi_loader: Disable devices before handing over control Date: Wed, 21 Oct 2020 10:32:24 +0300 Message-Id: <20201021073224.1871106-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean U-Boot Driver Model is supposed to remove devices with either DM_REMOVE_ACTIVE_DMA or DM_REMOVE_OS_PREPARE flags set, before exiting. Our bootm command does that by explicitly calling calling "dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);" and we also disable any USB devices. The EFI equivalent is doing none of those at the moment. As a result probing an fTPM driver now renders it unusable in Linux. During our (*probe) callback we open a session with OP-TEE, which is supposed to close with our (*remove) callback. Since the (*remove) is never called, once we boot into Linux and try to probe the device again we are getting a busy error response. We also never free So let's fix this by mimicking what bootm does and disconnect devices when efi_exit_boot_services() is called. Note that for the OP-TEE case and in particular any subsequent bootloader that wants to use a device (e.g GRUB) will need to call exit_boot_services() in order to close the session. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_boottime.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.28.0 diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index bf78176217c6..25e6cf0fe719 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include DECLARE_GLOBAL_DATA_PTR; @@ -1994,7 +1996,10 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, list_del(&evt->link); } + if IS_ENABLED(CONFIG_USB_DEVICE) + udc_disconnect(); board_quiesce_devices(); + dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL); /* Patch out unsupported runtime function */ efi_runtime_detach();