Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp558440pxb; Thu, 5 Nov 2020 07:12:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhClsVIXOzwRUfKrNREGXZbUuYhFVJpM/eWl7XjapzEo+97qbjzEG7LMskJp8lupAZBW1l X-Received: by 2002:a17:907:420d:: with SMTP id oh21mr2774319ejb.429.1604589173257; Thu, 05 Nov 2020 07:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604589173; cv=none; d=google.com; s=arc-20160816; b=QtFybXrcD5ABL1P0mN8Kr5r3nbBaRrQ7PQvC6b7EjK9lr3y4JKOSoH0CHWLuy6PZvX Kp1l1xcG+FGZ6aZOYSVTeQZVblw96NeEHJ1/pCpz6jNFPt70+2urRvL0SLsfv+nOJeyI GtPXv2BPoL1+YbdzYWLroW9S0Ddht/ChqYQwugN0bJ4TVT7DRTa32zRPTI9LwWi7YU5f 6h4/XdL9pPAuLTKg8IkKuU4/vcXvUwGTWpUxkurRi2XnnM+5tGnyOsUhvSeefzdougq5 gNbdS1taf+YeVAlgTcFc8hVd26aNlm62vV7lTxDICZnVdmJ/+KpvsOzpDLctzjZZamSC S3yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SNONstbNvXEZ9XiIXgtxs4kO9p+En2BqYsKM95T00+c=; b=f5kpyp3iJ4/Gi4T2pKUhXmPESCkw8uUYs/6QuPD2USUZG0Qg4yJjBVLKLBGyq10J4w KUjaKwONeF5L+8fZGYVw1n6aVxhW27FsmWNh/tMe6Q146TBpoPsZWxajh1bXCTQdW861 QMkPnnJ+JoI0u6EQEYXx+R/NQOOG+L2t1KN8cbKPmE8qmubh8KD7JSEzTwctJJqXg6b9 wj0kTu6WNEe7rEDRooIk+2Fy7/5dTrOX6Z4iQME/sd14hv3TQ7tN3ok2W3UBw3We1c3b udpb+sxjVwJ//ZisJL2q0x5F4OW0H9TLEgzDgQRBdNb3tLBmP5sv0ebdrZfwFn0eotXi dK6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=NDqrJZpf; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si1325167ejy.148.2020.11.05.07.12.28; Thu, 05 Nov 2020 07:12:53 -0800 (PST) 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=@alien8.de header.s=dkim header.b=NDqrJZpf; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731171AbgKEPIz (ORCPT + 99 others); Thu, 5 Nov 2020 10:08:55 -0500 Received: from mail.skyhub.de ([5.9.137.197]:53862 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731050AbgKEPIy (ORCPT ); Thu, 5 Nov 2020 10:08:54 -0500 Received: from zn.tnic (p200300ec2f0ee5009a3ef9f4dfadca8f.dip0.t-ipconnect.de [IPv6:2003:ec:2f0e:e500:9a3e:f9f4:dfad:ca8f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id AA5111EC02C1; Thu, 5 Nov 2020 16:08:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1604588932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=SNONstbNvXEZ9XiIXgtxs4kO9p+En2BqYsKM95T00+c=; b=NDqrJZpfZMhASoS5ddG9pJaiKrova5DbT+9vUdcT4HVdT62a1HKc63cmVZJEK1LetaazJS Z7IJtRRWbe99qK9OpRzcJx24TdSK50TU0aBNPyv6s+AWmP1U3U1a1KcmhPDFoEpcajkkIZ d/I01iO9UzuXSXu5GPLajxfU9NT/fIk= Date: Thu, 5 Nov 2020 16:08:39 +0100 From: Borislav Petkov To: Jarkko Sakkinen Cc: x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Jethro Beekman , Darren Kenny , Sean Christopherson , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com, mikko.ylinen@intel.com Subject: Re: [PATCH v40 09/24] x86/sgx: Add SGX page allocator functions Message-ID: <20201105150839.GB25636@zn.tnic> References: <20201104145430.300542-1-jarkko.sakkinen@linux.intel.com> <20201104145430.300542-10-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201104145430.300542-10-jarkko.sakkinen@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 04, 2020 at 04:54:15PM +0200, Jarkko Sakkinen wrote: > The previous patch initialized a simple SGX page allocator. Add functions > for runtime allocation and free. > > This allocator and its algorithms are as simple as it gets. They do a > linear search across all EPC sections and find the first free page. They > are not NUMA aware and only hand out individual pages. The SGX hardware > does not support large pages, so something more complicated like a buddy > allocator is unwarranted. > > The free function (sgx_free_epc_page()) implicitly calls ENCLS[EREMOVE], > which returns the page to the uninitialized state. This ensures that the > page is ready for use at the next allocation. > > Acked-by: Jethro Beekman > Reviewed-by: Darren Kenny > Co-developed-by: Sean Christopherson > Signed-off-by: Sean Christopherson > Signed-off-by: Jarkko Sakkinen > --- > arch/x86/kernel/cpu/sgx/main.c | 62 ++++++++++++++++++++++++++++++++++ > arch/x86/kernel/cpu/sgx/sgx.h | 3 ++ > 2 files changed, 65 insertions(+) > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c > index 956055a0eff6..b9ac438a13a4 100644 > --- a/arch/x86/kernel/cpu/sgx/main.c > +++ b/arch/x86/kernel/cpu/sgx/main.c > @@ -85,6 +85,68 @@ static bool __init sgx_page_reclaimer_init(void) > return true; > } > > +static struct sgx_epc_page *__sgx_alloc_epc_page_from_section(struct sgx_epc_section *section) > +{ > + struct sgx_epc_page *page; > + > + if (list_empty(§ion->page_list)) > + return NULL; > + > + page = list_first_entry(§ion->page_list, struct sgx_epc_page, list); > + list_del_init(&page->list); > + > + return page; > +} > + > +/** > + * __sgx_alloc_epc_page() - Allocate an EPC page > + * > + * Iterate through EPC sections and borrow a free EPC page to the caller. When a > + * page is no longer needed it must be released with sgx_free_epc_page(). > + * > + * Return: > + * an EPC page, > + * -errno on error > + */ > +struct sgx_epc_page *__sgx_alloc_epc_page(void) > +{ > + struct sgx_epc_section *section; > + struct sgx_epc_page *page; > + int i; > + > + for (i = 0; i < sgx_nr_epc_sections; i++) { > + section = &sgx_epc_sections[i]; > + spin_lock(§ion->lock); > + page = __sgx_alloc_epc_page_from_section(section); > + spin_unlock(§ion->lock); Something for a future cleanup: you can put that logic into __sgx_alloc_epc_page_from_section() and simplify this one call site. But not now - you can do that later or if v41 needs to be sent out... Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette