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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74E04C433EF for ; Sun, 7 Nov 2021 19:42:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48C15610D2 for ; Sun, 7 Nov 2021 19:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233234AbhKGTp0 (ORCPT ); Sun, 7 Nov 2021 14:45:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:43368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbhKGTpZ (ORCPT ); Sun, 7 Nov 2021 14:45:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B5A260FE8; Sun, 7 Nov 2021 19:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636314162; bh=LuLjGJGRrEpXf/URA8wRsWotsM2/2iMdP4iGfBZKpxc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Np2qyfnBYepSgmfVFgvoL3sE9y9AvPz9VHDiJwhS+4+v42wq+DlTP0uzCL4TCovax kl9u4EAoFTfmlpi0gRRsZc6VfifYj+MCYvyJrjwtIyHJigFhOwa2/g3OzTaivdFnIJ I0IWCfksIousu482xkQcnWIMn8zW+S6cb7epqLxVIzw4b5rvLVgwnssK7/dnjL4QGQ Spm+UlgBIcFMUt9w/OUTUSUm99nWrSpzHFqNRfjiQsnt2syrneUmLHJOYiq2RSrEVF AKZIO1mhqVLTRVbPUHvEUhURZ3OXpdiQyHVBowW/v7JOpgn+I+Pnq9Q7vhRy6XG2Rp IIS4GNJqhppHA== Date: Sun, 7 Nov 2021 21:42:39 +0200 From: Jarkko Sakkinen To: Dave Hansen Cc: Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Jethro Beekman , Sean Christopherson , reinette.chatre@intel.com, tony.luck@intel.com, nathaniel@profian.com, stable@vger.kernel.org, Borislav Petkov , linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/sgx: Free backing memory after faulting the enclave page Message-ID: References: <20211103232238.110557-1-jarkko@kernel.org> <6831ed3c-c5b1-64f7-2ad7-f2d686224b7e@intel.com> <55eb8f3649590289a0f2b1ebe7583b6da3ff70ee.camel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org On Thu, Nov 04, 2021 at 08:29:49AM -0700, Dave Hansen wrote: > On 11/4/21 8:25 AM, Jarkko Sakkinen wrote: > > On Thu, 2021-11-04 at 08:13 -0700, Dave Hansen wrote: > >> On 11/4/21 8:04 AM, Jarkko Sakkinen wrote: > >>>> Do we also need to deal with truncating the PCMD?  (For those watching > >>>> along at home, there are two things SGX swaps to RAM: the actual page > >>>> data and also some metadata that ensures page integrity and helps > >>>> prevent things like rolling back to old versions of swapped pages) > >>> Yes. > >>> > >>> This can be achieved by iterating through all of the enclave pages, > >>> which share the same shmem page for storing their PCMD's, as the one > >>> being faulted back. If none of those pages is swapped, the PCMD page can > >>> safely truncated. > >> I was thinking we could just read the page.  If it's all 0's, truncate it. > > Hmm... did ELDU zero PCMD as a side-effect? > > I don't think so, but there's nothing stopping us from doing it ourselves. Ok. > > It should be fairly effecient just to check the pages by using > > encl->page_tree. > > That sounds more complicated and slower than what I suggested. You > could even just check the refcount on the page. I _think_ page cache > pages have a refcount of 2. So, look for the refcount that means "no > more PCMD in this page", and just free it if so. Umh, so... there is total 32 PCMD's per one page. /Jarkko