Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp72935ybt; Mon, 6 Jul 2020 04:24:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYEbu5Gn34CA+Od+IWKRUGvpA7aZi9jEaykZ/TvcKaNrrnQG3/8DUadl64YFQyJFRCxZtc X-Received: by 2002:a17:906:4341:: with SMTP id z1mr36868067ejm.392.1594034694932; Mon, 06 Jul 2020 04:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594034694; cv=none; d=google.com; s=arc-20160816; b=x/TmBH6NMfNT1DN5HHnDIJdCuqP98YcGK3nyNtTmQ/eV//UIctSkCfX6ob2/gc2y8X iSeL7fSyNzrjRmvpv14EGg8dK0q3lXa6OfWlh4sarcCRa7I9uWP0iXDyA220BqeLMBU+ rgFJWu8KFAOzfzy3EOv71WvkJfsQquNiqZOnGlM9oKpWgnB6D1hxagR6ZOx94yLqF3fs SFLZDu7b9yoVyVMuOLYO41ZmnGPUX0eYxkKuyrqGfA2Ucw+kWs9Q7gS4v/xxMxmYLeWD FMV27DkvxfUGaRaMcUpjXqCte88vFPhOJcSySK2Fp+sR47+C49DZ2quBILHWvqo30ZpO cq4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:ironport-sdr :dkim-signature; bh=9tRtqDZLMrvbqJ2Vj8OwHtxpJtafAcWtsKShid5vN1U=; b=ASnmG0kTCidqPZK+a8xgAFV89UDnPHlwe9t2xE6lGozdEz3+0coCertZSFC46J3mYZ FpnIcjxCeTDerNVYjuo+R1KgReJp9Tjai75V7WEd3lu31aBcc2Xc5PY/cUh9QS+QUbTi Kz4JkWkh/vviRD/mGiks9cvcO81b6Fd4KqSA53n8G5eiE74QVAbbqPpZ9Fkc8QI+2qXY sujk8U2+nnbEjx1jDHem59awRzsx3O/9F3rgTBV5m82BrgTrQLAnAbf9k091mYaNMa74 Xn7d0pkSNKIUw6jujb8sCl6dqN1l2yErRZTJw8lHXHoP5/7Mg2YPmRmCW0o2/91nKG1O Wghw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=HPoN0Eq3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bu27si12630054edb.542.2020.07.06.04.24.32; Mon, 06 Jul 2020 04:24:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=HPoN0Eq3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728954AbgGFLWG (ORCPT + 99 others); Mon, 6 Jul 2020 07:22:06 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:28491 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728441AbgGFLWG (ORCPT ); Mon, 6 Jul 2020 07:22:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1594034524; x=1625570524; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=9tRtqDZLMrvbqJ2Vj8OwHtxpJtafAcWtsKShid5vN1U=; b=HPoN0Eq3kloWISvgsSFmiLOT19tcKMeHCBRTrk/ukQ2S4kcWAcNjRWHy JpNMmvGnmN5uk5cvQyfgl6psk3x7eF0xp6Q4vfqhi5qYKIuNx9UPLlnZR 8+Pp6KA63yHFcUjezekpCRR56Idmrcmg/Z5jBDpmZaik+P+eXg7wHODUS Q=; IronPort-SDR: U77jrStpRVg4aekzEui1h93s0Vh9d4UXkJ93uhZ1ZK8QWBQPrczzBPeEIV72HcaX6/+ApcLu6g 8CHEnRnjLK2g== X-IronPort-AV: E=Sophos;i="5.75,318,1589241600"; d="scan'208";a="40194238" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 06 Jul 2020 11:22:03 +0000 Received: from EX13MTAUWC001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com (Postfix) with ESMTPS id 3BFC9A1B4C; Mon, 6 Jul 2020 11:22:01 +0000 (UTC) Received: from EX13D20UWC001.ant.amazon.com (10.43.162.244) by EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 6 Jul 2020 11:22:00 +0000 Received: from 38f9d3867b82.ant.amazon.com (10.43.161.145) by EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 6 Jul 2020 11:21:53 +0000 Subject: Re: [PATCH v4 12/18] nitro_enclaves: Add logic for enclave start To: Andra Paraschiv , CC: Anthony Liguori , Benjamin Herrenschmidt , Colm MacCarthaigh , "Bjoern Doebel" , David Woodhouse , "Frank van der Linden" , Greg KH , Martin Pohlack , Matt Wilson , "Paolo Bonzini" , Balbir Singh , "Stefano Garzarella" , Stefan Hajnoczi , Stewart Smith , Uwe Dannowski , , References: <20200622200329.52996-1-andraprs@amazon.com> <20200622200329.52996-13-andraprs@amazon.com> From: Alexander Graf Message-ID: Date: Mon, 6 Jul 2020 13:21:49 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200622200329.52996-13-andraprs@amazon.com> Content-Language: en-US X-Originating-IP: [10.43.161.145] X-ClientProxiedBy: EX13D03UWC003.ant.amazon.com (10.43.162.79) To EX13D20UWC001.ant.amazon.com (10.43.162.244) Content-Type: text/plain; charset="windows-1252"; format="flowed" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22.06.20 22:03, Andra Paraschiv wrote: > After all the enclave resources are set, the enclave is ready for > beginning to run. > = > Add ioctl command logic for starting an enclave after all its resources, > memory regions and CPUs, have been set. > = > The enclave start information includes the local channel addressing - > vsock CID - and the flags associated with the enclave. > = > Signed-off-by: Alexandru Vasile > Signed-off-by: Andra Paraschiv > --- > Changelog > = > v3 -> v4 > = > * Use dev_err instead of custom NE log pattern. > * Update the naming for the ioctl command from metadata to info. > * Check for minimum enclave memory size. > = > v2 -> v3 > = > * Remove the WARN_ON calls. > * Update static calls sanity checks. > = > v1 -> v2 > = > * Add log pattern for NE. > * Check if enclave state is init when starting an enclave. > * Remove the BUG_ON calls. > --- > drivers/virt/nitro_enclaves/ne_misc_dev.c | 114 ++++++++++++++++++++++ > 1 file changed, 114 insertions(+) > = > diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nit= ro_enclaves/ne_misc_dev.c > index 17ccb6cdbd75..d9794f327169 100644 > --- a/drivers/virt/nitro_enclaves/ne_misc_dev.c > +++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c > @@ -703,6 +703,45 @@ static int ne_set_user_memory_region_ioctl(struct ne= _enclave *ne_enclave, > return rc; > } > = > +/** > + * ne_start_enclave_ioctl - Trigger enclave start after the enclave reso= urces, > + * such as memory and CPU, have been set. > + * > + * This function gets called with the ne_enclave mutex held. > + * > + * @ne_enclave: private data associated with the current enclave. > + * @enclave_start_info: enclave info that includes enclave cid and flags. > + * > + * @returns: 0 on success, negative return value on failure. > + */ > +static int ne_start_enclave_ioctl(struct ne_enclave *ne_enclave, > + struct ne_enclave_start_info *enclave_start_info) > +{ > + struct ne_pci_dev_cmd_reply cmd_reply =3D {}; > + struct enclave_start_req enclave_start_req =3D {}; > + int rc =3D -EINVAL; > + > + enclave_start_req.enclave_cid =3D enclave_start_info->enclave_cid; > + enclave_start_req.flags =3D enclave_start_info->flags; > + enclave_start_req.slot_uid =3D ne_enclave->slot_uid; I think it's easier to read if you do the initialization straight in the = variable declaation: struct enclave_start_req enclave_start_req =3D { .enclave_cid =3D enclave_start_info->cid, .flags =3D enclave_start_info->flags, .slot_uid =3D ne_enclave->slot_uid, }; > + > + rc =3D ne_do_request(ne_enclave->pdev, ENCLAVE_START, &enclave_start_re= q, > + sizeof(enclave_start_req), &cmd_reply, > + sizeof(cmd_reply)); > + if (rc < 0) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "Error in enclave start [rc=3D%d]\n", rc); > + > + return rc; > + } > + > + ne_enclave->state =3D NE_STATE_RUNNING; > + > + enclave_start_info->enclave_cid =3D cmd_reply.enclave_cid; > + > + return 0; > +} > + > static long ne_enclave_ioctl(struct file *file, unsigned int cmd, > unsigned long arg) > { > @@ -818,6 +857,81 @@ static long ne_enclave_ioctl(struct file *file, unsi= gned int cmd, > return rc; > } > = > + case NE_START_ENCLAVE: { > + struct ne_enclave_start_info enclave_start_info =3D {}; > + int rc =3D -EINVAL; > + > + if (copy_from_user(&enclave_start_info, (void *)arg, > + sizeof(enclave_start_info))) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "Error in copy from user\n"); No need to print anything here > + > + return -EFAULT; > + } > + > + mutex_lock(&ne_enclave->enclave_info_mutex); > + > + if (ne_enclave->state !=3D NE_STATE_INIT) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "Enclave isn't in init state\n"); > + > + mutex_unlock(&ne_enclave->enclave_info_mutex); > + > + return -EINVAL; Can this be its own return value instead? > + } > + > + if (!ne_enclave->nr_mem_regions) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "Enclave has no mem regions\n"); > + > + mutex_unlock(&ne_enclave->enclave_info_mutex); > + > + return -ENOMEM; > + } > + > + if (ne_enclave->mem_size < NE_MIN_ENCLAVE_MEM_SIZE) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "Enclave memory is less than %ld\n", > + NE_MIN_ENCLAVE_MEM_SIZE); > + > + mutex_unlock(&ne_enclave->enclave_info_mutex); > + > + return -ENOMEM; > + } > + > + if (!ne_enclave->nr_vcpus) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "Enclave has no vcpus\n"); > + > + mutex_unlock(&ne_enclave->enclave_info_mutex); > + > + return -EINVAL; Same here. > + } > + > + if (!cpumask_empty(ne_enclave->cpu_siblings)) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "CPU siblings not used\n"); > + > + mutex_unlock(&ne_enclave->enclave_info_mutex); > + > + return -EINVAL; Same here. > + } > + > + rc =3D ne_start_enclave_ioctl(ne_enclave, &enclave_start_info); > + > + mutex_unlock(&ne_enclave->enclave_info_mutex); > + > + if (copy_to_user((void *)arg, &enclave_start_info, This needs to be __user void *, no? Alex > + sizeof(enclave_start_info))) { > + dev_err_ratelimited(ne_misc_dev.this_device, > + "Error in copy to user\n"); > + > + return -EFAULT; > + } > + > + return rc; > + } > + > default: > return -ENOTTY; > } > = Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879