Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3017498imu; Mon, 17 Dec 2018 11:44:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/UvbJHQ8V/vFIo0voo82t7VI5niF56W1deSW/hdKNl8CD777/atQBLbKmfMyKmQ2Y2aCCa8 X-Received: by 2002:a63:b0a:: with SMTP id 10mr10072000pgl.423.1545075883226; Mon, 17 Dec 2018 11:44:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545075883; cv=none; d=google.com; s=arc-20160816; b=A/XeiDdgZEgvlqVNwVxd/y7a+SR4e+R6q+uq4Om75TyThsVjvN3I0ks3Abojmy2L6b wS488DYxpY3Li7Aqkh49pukK0TdRb3KTLPNxp8U7kx6KqxsoiDR/0ZZN1po4ZI6q1jrI KnEQv1+YrWICXr8PQCR2azBk9UeMDstiQsKeJH3F8lRNpYMCUgqywn0tS+/51aY+e052 ZayECtd5DkbwfsIkdLh9tKnssBwcmULM4osZZpc9vJDO++E26k91j0LsK3m/VGHfBzhJ opWg1gvg/PSx1gvxergfCmpf7aoksZzGPORXlXHztL/ZCN3nwWknR5E7k3UepzcdWnYl z7Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=+EkC4y+DVr+vXMCgR+xbhZlsgcsI2uINnmTTUFUIKTA=; b=DfhywEJJ1hvJbPwHTtqBVAduZ+3rCE3HOOaOhb/nAbxn271EFMpBcGXrXacvOZv4ms ZN2yAJpNIABgpwnuKVONDtahgME9aNxJJl9IbM/oigat2uFTTNCUTG5V0O2UCBT7uOy/ px5d0vk+bJm9vu7aNt2YIz/u4vCkdJLyZc1tfJJGg8IzDfYEILZiXc4d+IKYsGS0ipHS dBUAQ+oxLZ3BnbEevES+xT2ni2Mn6/he/kAXXblgyxjC/ymSSxl/0SzG7hndopJtN78m YC3s//7iwT13Z86/DrbcrxE7rIKbwdONxtRefPuvN5WTLOygfb0/1xz8Ehvg3K7rjpwY g3bQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si11895260pff.161.2018.12.17.11.44.27; Mon, 17 Dec 2018 11:44:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388515AbeLQSBM (ORCPT + 99 others); Mon, 17 Dec 2018 13:01:12 -0500 Received: from mga09.intel.com ([134.134.136.24]:39083 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727650AbeLQSBM (ORCPT ); Mon, 17 Dec 2018 13:01:12 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2018 10:01:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,366,1539673200"; d="scan'208";a="111132883" Received: from quwen-mobl.ccr.corp.intel.com (HELO localhost) ([10.249.254.215]) by orsmga003.jf.intel.com with ESMTP; 17 Dec 2018 10:01:03 -0800 Date: Mon, 17 Dec 2018 20:01:02 +0200 From: Jarkko Sakkinen To: Dave Hansen Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org, linux-sgx@vger.kernel.org, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, haitao.huang@linux.intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, mark.shanahan@intel.com, luto@amacapital.net, Suresh Siddha , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v17 18/23] platform/x86: Intel SGX driver Message-ID: <20181217180102.GA12560@linux.intel.com> References: <20181116010412.23967-1-jarkko.sakkinen@linux.intel.com> <20181116010412.23967-19-jarkko.sakkinen@linux.intel.com> <7d5cde02-4649-546b-0f03-2d6414bb80b5@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7d5cde02-4649-546b-0f03-2d6414bb80b5@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 17, 2018 at 09:45:40AM -0800, Dave Hansen wrote: > > +struct sgx_encl *sgx_encl_alloc(struct sgx_secs *secs) > > +{ > ... > > + kref_init(&encl->refcount); > > + INIT_LIST_HEAD(&encl->add_page_reqs); > > + INIT_RADIX_TREE(&encl->page_tree, GFP_KERNEL); > > + mutex_init(&encl->lock); > > + INIT_WORK(&encl->add_page_work, sgx_add_page_worker); > > + > > + encl->mm = current->mm; <---------------------------------> + encl->base = secs->base; > > + encl->size = secs->size; > > + encl->ssaframesize = secs->ssa_frame_size; > > + encl->backing = backing; > > + > > + return encl; > > +} > > How is this OK without taking a reference on the mm? > > I have a feeling a bunch of your bugs with the mmu notifiers and so > forth are because the refcounting is wrong here. > > Sean's SGX_ENCL_MM_RELEASED would, I think be unnecessary if you just > take a refcount here and release it when the enclave is destroyed. Right, atomic_inc(encl->mm->count) here and once when releasing. The we would not even need the whole mmu notifier in the first place. /Jarkko