Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2765817pxy; Tue, 3 Aug 2021 14:47:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBghY7yW6V2ZQNfc5PktO1aS0FvnVutxNfDavCM7mTHxRuuC1F9x64NB+VjDXhI8k7FeKG X-Received: by 2002:a92:a010:: with SMTP id e16mr6872ili.138.1628027242915; Tue, 03 Aug 2021 14:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628027242; cv=none; d=google.com; s=arc-20160816; b=tJpmX+S+fnzeQEaqK6lqKABZxGwtBDPIfc7pM8mgs24E24px1a+W3/z9sd3rc3bnQV 17V9mcRy7qpbPol7fmDaXxqiyG50AC8XLmtSM33QwO84dBlI3T4H4H1knlpFsKghJ9ui +/P/8eFjcrMNbbCNzjghrmzqJwZV2GGqJgV+dhbK2bAM8W6puv5ReRk9LB4FpOR4yiKo EEAQdQ/17MTXL+qnIheZ5fdeRPn1BXBjDQG+frD3WZeiuDiVb6GViUcWoBlriSRvEuLT 4gb0taAH9GXTqURHdOe7+3wyq0qOnVk2MgdFbEFm0SA973c+daaZT2zC694DDxAn7nLj SnbQ== 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=+CGFH2KuXULxjiGsSPbBmX3Z4HJgTBGPotNROlzN7oA=; b=rJZ4XP5nFn+47s03+C2pcpSTPgtFf7njxYbc3GjVfAFuwadS9I67Qvv4ZBjAfSO9wV 3ECnwOPfR5Uiup/olumKhELinjKoqCUtCRIV5y1rVrBbrSoULm7rGBrychqg+He8DHdO xnZOkgC3TaB3RRTNzAnfuSRBGJcGv7sbrf6NAtdCNdgk+gB0dVMeocWZB7DKxXIbM+ks o+GwxJMIOp9R2iqd7fWk3NZVwPjqVoCK2mHGA6yTtAQI8RXViIZ2TmxdmUJf2qspRUwH /yizaMBqNXAZXsZBrElvJqCgoGzVDRdTSLcWe/MdmkangNGbnns+00fTSTzDG6T8sDaJ YMsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="H/SNoopr"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si139872jad.101.2021.08.03.14.47.11; Tue, 03 Aug 2021 14:47:22 -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=@infradead.org header.s=casper.20170209 header.b="H/SNoopr"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbhHCVfo (ORCPT + 99 others); Tue, 3 Aug 2021 17:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231929AbhHCVfo (ORCPT ); Tue, 3 Aug 2021 17:35:44 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1A32C061757 for ; Tue, 3 Aug 2021 14:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+CGFH2KuXULxjiGsSPbBmX3Z4HJgTBGPotNROlzN7oA=; b=H/SNooprUGPWyJ6gAapA29Ymxe 89vwATnDaX4E3F8Vuz2X6+8122oyuPdvLjI4obaTc63TbEeSeJPzzKeClCr6f3t1zyMyQv3xOoNDw 1f2kCM6I+8BbNUhvKxeWH2QIUGQJ4xXf7+ys5jTfFYen1x3JEdrc22iZN+viX+3h5h7hM6AHmFIFP 9nTwwr7TW6IGgCtSYsKR1DkSRPKYtItSG/dtQlQRl+c2+oLgfRW6SoOg07xtZWuLpc9nkpwoLAwkk NmZJBOSMGMG1o74g7BygKsQGZsD7l+ZXe8hnirUibJUOds2ETuH9QMB7B3ybnLfWkuudIhCc5B4Zj 47bN07eQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mB23Q-00572u-ST; Tue, 03 Aug 2021 21:34:35 +0000 Date: Tue, 3 Aug 2021 22:34:28 +0100 From: Matthew Wilcox To: "Luck, Tony" Cc: "Hansen, Dave" , Sean Christopherson , Jarkko Sakkinen , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "Liam R. Howlett" Subject: Re: [PATCH v3 2/7] x86/sgx: Add infrastructure to identify SGX EPC pages Message-ID: References: <20210719182009.1409895-1-tony.luck@intel.com> <20210728204653.1509010-1-tony.luck@intel.com> <20210728204653.1509010-3-tony.luck@intel.com> <141602a3-ef61-01f0-4a3c-69f8e7012fcd@intel.com> <20210730003809.hp3nmqmgyysa45nz@kernel.org> <20210730184400.GA1521057@agluck-desk2.amr.corp.intel.com> <259e12df49b9495cb6b326e52c9ffe51@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <259e12df49b9495cb6b326e52c9ffe51@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 30, 2021 at 11:35:38PM +0000, Luck, Tony wrote: > > xa_store_range(&epc_page_ranges, > > section->phys_addr, > > section->end_phys_addr, ...); > > > > ... you did it based on PFNs: > > > > xa_store_range(&epc_page_ranges, > > section->phys_addr >> PAGE_SHIFT, > > section->end_phys_addr >> PAGE_SHIFT, ...); > > > > SGX sections are at *least* page-aligned, so this should be fine. > > I found xa_dump() (hidden inside #ifdef XA_DEBUG) > > Trying both with and without the >> PAGE_SHIFT made no difference > to the number of lines of console output that xa_dump() spits out. > 266 either way. > > There are only two ranges on this system > > [ 11.937592] sgx: EPC section 0x8000c00000-0x807f7fffff > [ 11.945811] sgx: EPC section 0x10000c00000-0x1007fffffff > > So I'm a little bit sad that xarray appears to have broken them up > into a bunch of pieces. That's inherent in the (current) back end data structure, I'm afraid. As a radix tree, it can only look up based on the N bits available at each level of the tree, so if your entry is an aligned power-of-64, everything is nice and neat, and you're a single entry at one level of the tree. If you're an arbitrary range, things get more complicated, and I have to do a little dance to redirect the lookup towards the canonical entry. Liam and I are working on a new replacement data structure called the Maple Tree, but it's not yet ready to replace the radix tree back end. It looks like it would be perfect for your case; there would be five entries in it, stored in one 256-byte node: NULL 0x8000bfffff p1 0x807f7fffff NULL 0x10000c00000 p2 0x1007fffffff NULL 0xffff'ffff'ffff'ffff It would actually turn into a linear scan, because that's just the fastest way to find something in a list of five elements. A third range would take us to a list of seven elements, which still fits in a single node. Once we get to more than that, you'd have a two-level tree, which would work until you have more than ~20 ranges. We could do better for your case by storing 10x (start, end, p) in each leaf node, but we're (currently) optimising for VMAs which tend to be tightly packed, meaning that an implicit 'start' element is a better choice as it gives us 15x (end, p) pairs.