From patchwork Fri Mar 24 14:52:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9643031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A86C8601E9 for ; Fri, 24 Mar 2017 14:52:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A4692522B for ; Fri, 24 Mar 2017 14:52:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D3CD25F31; Fri, 24 Mar 2017 14:52:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3C7072522B for ; Fri, 24 Mar 2017 14:52:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A579B803B1; Fri, 24 Mar 2017 07:52:47 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5A7A0803B1 for ; Fri, 24 Mar 2017 07:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490367166; x=1521903166; h=from:to:cc:subject:date:message-id; bh=GRjUHrtbEk1IScU4MFpGad0qIcvCAwoh9Y9OrDcpwzg=; b=uHw3eTbOY379/iU/3ONmwZD0JJjTa5ZeXlwUjdKtu0HCL9FhX+VpoZT4 bLxBM3Vq0bqX/6QdJFcq5lmNABFO1g==; Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Mar 2017 07:52:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,215,1486454400"; d="scan'208";a="70313066" Received: from sjchrist-ts.jf.intel.com ([10.54.74.20]) by orsmga004.jf.intel.com with ESMTP; 24 Mar 2017 07:52:45 -0700 From: Sean Christopherson To: intel-sgx-kernel-dev@lists.01.org Date: Fri, 24 Mar 2017 07:52:43 -0700 Message-Id: <1490367163-25400-1-git-send-email-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [intel-sgx-kernel-dev] [PATCH] intel_sgx: dec ctx->epc_cnt iff __eremove succeeds X-BeenThere: intel-sgx-kernel-dev@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Project: Intel® Software Guard Extensions for Linux*: https://01.org/intel-software-guard-extensions" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-sgx-kernel-dev-bounces@lists.01.org Sender: "intel-sgx-kernel-dev" X-Virus-Scanned: ClamAV using ClamSMTP sgx_free_page decrements ctx->epc_cnt prior to calling __eremove. If ERMOVE fails and the caller passed SGX_FREE_RETURN_ERROR then epc_cnt will be decremented without actually freeing the page. Signed-off-by: Sean Christopherson --- drivers/platform/x86/intel_sgx_page_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/intel_sgx_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c index e4f6b95..852066c 100644 --- a/drivers/platform/x86/intel_sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx_page_cache.c @@ -539,8 +539,6 @@ int sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl, void *epc; int ret; - atomic_dec(&encl->tgid_ctx->epc_cnt); - epc = sgx_get_epc_page(entry); ret = __eremove(epc); sgx_put_epc_page(epc); @@ -552,6 +550,8 @@ int sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl, sgx_crit(encl, "EREMOVE returned %d\n", ret); } + atomic_dec(&encl->tgid_ctx->epc_cnt); + spin_lock(&sgx_free_list_lock); list_add(&entry->free_list, &sgx_free_list); sgx_nr_free_pages++;