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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 07968C433DF for ; Tue, 7 Jul 2020 04:39:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B7DEE20738 for ; Tue, 7 Jul 2020 04:39:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="L5Hcz9Nf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7DEE20738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5465A6B002C; Tue, 7 Jul 2020 00:39:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F7DD6B002D; Tue, 7 Jul 2020 00:39:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E5646B002E; Tue, 7 Jul 2020 00:39:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id 284436B002C for ; Tue, 7 Jul 2020 00:39:24 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AF9A8181AC9C6 for ; Tue, 7 Jul 2020 04:39:23 +0000 (UTC) X-FDA: 77010025806.16.face43_4309a2426eb1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 864EB100E6903 for ; Tue, 7 Jul 2020 04:39:23 +0000 (UTC) X-HE-Tag: face43_4309a2426eb1 X-Filterd-Recvd-Size: 4725 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jul 2020 04:39:23 +0000 (UTC) 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=9Fn0Sg12AGqPvCet6/i3cv1zgohdxMq/STaY/sGGKBM=; b=L5Hcz9Nfo/DNgz2qozusOJmZHe 6yxUrH93tLHZbhy98UmvJDnpk9Y24OKFN4qqQ/Td8wKicNYtqRomjKM9dOGxzQod0nHXGvuRzvlCz MIwmIylU70LmPziuuj+aRsoMlk5qRDcAjDOVW9UscpZidiktVdQFFIQgRFTnV0p7EjipJ0RONLfoW yb3LvUHaViGZLc+ewmuBdz8E/NU30C+049ft+YFzTtGvpfxduQN0iz94zTXnfMgjiWkT/KvNit0Nz ZD1Z9Yea+wyvH6LJDU7aAM6cFYfi/ZAZoxuUUTfTzjaPCSDEY+edAUIdBbCEa95nA0OAczWB4vVgD 3E4+MfRw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsfNo-0006OJ-8J; Tue, 07 Jul 2020 04:39:04 +0000 Date: Tue, 7 Jul 2020 05:39:04 +0100 From: Matthew Wilcox To: Sean Christopherson Cc: Jarkko Sakkinen , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Jethro Beekman , Haitao Huang , Chunyang Hui , Jordan Hand , Nathaniel McCallum , Seth Moore , Suresh Siddha , andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com Subject: Re: [PATCH v34 11/24] x86/sgx: Add SGX enclave driver Message-ID: <20200707043904.GJ25523@casper.infradead.org> References: <20200707030204.126021-1-jarkko.sakkinen@linux.intel.com> <20200707030204.126021-12-jarkko.sakkinen@linux.intel.com> <20200707033617.GF25523@casper.infradead.org> <20200707041151.GE143804@linux.intel.com> <20200707042904.GD5208@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200707042904.GD5208@linux.intel.com> X-Rspamd-Queue-Id: 864EB100E6903 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jul 06, 2020 at 09:29:04PM -0700, Sean Christopherson wrote: > > > > + idx_start = PFN_DOWN(start); > > > > + idx_end = PFN_DOWN(end - 1); > > > > + > > > > + for (idx = idx_start; idx <= idx_end; ++idx) { > > > > + mutex_lock(&encl->lock); > > > > + page = radix_tree_lookup(&encl->page_tree, idx); > > > > + mutex_unlock(&encl->lock); > > > > + > > > > + if (!page || (~page->vm_max_prot_bits & vm_prot_bits)) > > > > + return -EACCES; > > > > > > You should really use an iterator here instead of repeated lookups. > > > xas_for_each() will probably be what you want. > > > > Thank you for your remarks. I'll look into using xarray for this. > > Question for Matthew: > > To enforce the "page must be populated" rule, is there a clean way to retrieve > the index of the current entry? Our entries/pages don't have information > about their index. Or should we just count the number of entries and check > 'em at the end? E.g. > > xas_for_each(...) { > if (~page->vm_max_prot_bits & vm_prot_bits) > return -EACCES; > nr_entries++; > } > > if (nr_entries != (end_index - start_index)) > return -EACCES; Probably best just to steal the implementation from here: pgoff_t page_cache_next_miss(struct address_space *mapping, pgoff_t index, unsigned long max_scan) { XA_STATE(xas, &mapping->i_pages, index); while (max_scan--) { void *entry = xas_next(&xas); if (!entry || xa_is_value(entry)) break; if (xas.xa_index == 0) break; } return xas.xa_index; } although I think you have a simpler task. XA_STATE(xas, ..., start_index); for (;;) { struct page *page = xas_next(&xas); if (!page || (~page->vm_max_prot_bits & vm_prot_bits)) return -EACCES; } return 0; should do the trick, I think.