From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 5C60DC433E8 for ; Wed, 15 Jul 2020 19:46:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DAD620657 for ; Wed, 15 Jul 2020 19:46:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="OR1zQspN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727818AbgGOTqi (ORCPT ); Wed, 15 Jul 2020 15:46:38 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:54165 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727787AbgGOTqd (ORCPT ); Wed, 15 Jul 2020 15:46:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1594842393; x=1626378393; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ImiGmcZ27FUlDyrCp/ZgAiR0YbmpF34TzvQZM4zdpH0=; b=OR1zQspNHgbTqAxrmDCiu4Om4OX9YOg+gazjcrC29ll1qzBGaK/IJd46 wGDmmPmJ+nL5TtRycEjNorHvl1bTlDT5z09Cnw4Zf8a1IMlW7nmBr0if7 BI3h6fzjNGOEngIIFmeuQjjG/F0DH50wV9MS8rmTiUmaRZH9Lnt8YADzB Q=; IronPort-SDR: hs1HapnBFfKzp/b6R3E2pPhTJYBAf8SNlRr+Zvlg6Sb4ozMykiTDcSFJsVzpKfUYTG2M2Z6z1N D0YSvb8d9SMg== X-IronPort-AV: E=Sophos;i="5.75,356,1589241600"; d="scan'208";a="60147289" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 15 Jul 2020 19:46:30 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com (Postfix) with ESMTPS id E3F15A07AE; Wed, 15 Jul 2020 19:46:27 +0000 (UTC) Received: from EX13D16EUB001.ant.amazon.com (10.43.166.28) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 Jul 2020 19:46:26 +0000 Received: from 38f9d34ed3b1.ant.amazon.com (10.43.161.214) by EX13D16EUB001.ant.amazon.com (10.43.166.28) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 Jul 2020 19:46:16 +0000 From: Andra Paraschiv To: CC: Anthony Liguori , Benjamin Herrenschmidt , Colm MacCarthaigh , "David Duncan" , Bjoern Doebel , "David Woodhouse" , Frank van der Linden , Alexander Graf , Greg KH , "Karen Noel" , Martin Pohlack , Matt Wilson , Paolo Bonzini , Balbir Singh , Stefano Garzarella , "Stefan Hajnoczi" , Stewart Smith , "Uwe Dannowski" , Vitaly Kuznetsov , , , Andra Paraschiv , Alexander Graf Subject: [PATCH v5 03/18] nitro_enclaves: Define enclave info for internal bookkeeping Date: Wed, 15 Jul 2020 22:45:25 +0300 Message-ID: <20200715194540.45532-4-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20200715194540.45532-1-andraprs@amazon.com> References: <20200715194540.45532-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.214] X-ClientProxiedBy: EX13D46UWB002.ant.amazon.com (10.43.161.70) To EX13D16EUB001.ant.amazon.com (10.43.166.28) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Nitro Enclaves driver keeps an internal info per each enclave. This is needed to be able to manage enclave resources state, enclave notifications and have a reference of the PCI device that handles command requests for enclave lifetime management. Signed-off-by: Alexandru-Catalin Vasile Signed-off-by: Andra Paraschiv Reviewed-by: Alexander Graf --- Changelog v4 -> v5 * Include enclave cores field in the enclave metadata. * Update the vCPU ids data structure to be a cpumask instead of a list. v3 -> v4 * Add NUMA node field for an enclave metadata as the enclave memory and CPUs need to be from the same NUMA node. v2 -> v3 * Remove the GPL additional wording as SPDX-License-Identifier is already in place. v1 -> v2 * Add enclave memory regions and vcpus count for enclave bookkeeping. * Update ne_state comments to reflect NE_START_ENCLAVE ioctl naming update. --- drivers/virt/nitro_enclaves/ne_misc_dev.h | 106 ++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 drivers/virt/nitro_enclaves/ne_misc_dev.h diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.h b/drivers/virt/nitro_enclaves/ne_misc_dev.h new file mode 100644 index 000000000000..91e4dd254c68 --- /dev/null +++ b/drivers/virt/nitro_enclaves/ne_misc_dev.h @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + */ + +#ifndef _NE_MISC_DEV_H_ +#define _NE_MISC_DEV_H_ + +#include +#include +#include +#include +#include +#include +#include + +/* Entry in memory regions list. */ +struct ne_mem_region { + struct list_head mem_region_list_entry; + + /* Number of pages that make up the memory region. */ + unsigned long nr_pages; + + /* Pages that make up the user space memory region. */ + struct page **pages; +}; + +/* Per-enclave data used for enclave lifetime management. */ +struct ne_enclave { + /* Available CPU cores for the enclave. */ + cpumask_var_t *avail_cpu_cores; + + /* The size of the available cores array. */ + unsigned int avail_cpu_cores_size; + + /* Mutex for accessing this internal state. */ + struct mutex enclave_info_mutex; + + struct list_head enclave_list_entry; + + /** + * Wait queue used for out-of-band event notifications + * triggered from the PCI device event handler to the enclave + * process via the poll function. + */ + wait_queue_head_t eventq; + + /* Variable used to determine if the out-of-band event was triggered. */ + bool has_event; + + /** + * The maximum number of memory regions that can be handled by the + * lower levels. + */ + u64 max_mem_regions; + + /* Enclave memory regions list. */ + struct list_head mem_regions_list; + + /* Enclave memory size. */ + u64 mem_size; + + /* Enclave process abstraction mm data struct. */ + struct mm_struct *mm; + + /* Number of memory regions associated with the enclave. */ + u64 nr_mem_regions; + + /* Number of vcpus associated with the enclave. */ + u64 nr_vcpus; + + /* NUMA node of the enclave memory and CPUs. */ + u32 numa_node; + + /* PCI device used for enclave lifetime management. */ + struct pci_dev *pdev; + + /* Slot unique id mapped to the enclave. */ + u64 slot_uid; + + /* Enclave state, updated during enclave lifetime. */ + u16 state; + + /* Enclave vCPUs. */ + cpumask_var_t vcpu_ids; +}; + +/* States available for an enclave. */ +enum ne_state { + /* NE_START_ENCLAVE ioctl was never issued for the enclave. */ + NE_STATE_INIT = 0, + + /** + * NE_START_ENCLAVE ioctl was issued and the enclave is running + * as expected. + */ + NE_STATE_RUNNING = 2, + + /* Enclave exited without userspace interaction. */ + NE_STATE_STOPPED = U16_MAX, +}; + +/* Nitro Enclaves (NE) misc device */ +extern struct miscdevice ne_misc_dev; + +#endif /* _NE_MISC_DEV_H_ */ -- 2.20.1 (Apple Git-117) Amazon Development Center (Romania) S.R.L. registered office: 27A Sf. Lazar Street, UBC5, floor 2, Iasi, Iasi County, 700045, Romania. Registered in Romania. Registration number J22/2621/2005.