Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3548510pxb; Sun, 7 Feb 2021 13:35:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJycP1OMXHeF1cOUEH0i1iBJgaKnWFRXirKjgRDQbHsBDLxDlXhyM4ZpDrQmw1d4KlsUjSBY X-Received: by 2002:a50:ff0d:: with SMTP id a13mr14032347edu.321.1612733735322; Sun, 07 Feb 2021 13:35:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612733735; cv=none; d=google.com; s=arc-20160816; b=Pg4UCtEQ3HuviEFMwZe2pqux/IXLnFRwsCrIccnIEc0bSreYXSDvqW6AWZOoDETOoC VjL8Ng9oAPCmZVln9VDKl1all00WYDYrWnrTW4/qaaZlb0zGoDAh7GU1yiZC+we/0N2e APPt0DbP0HtJp+V41q6WDIh10ryQi/hw+03LaBKV6ygOzyxfvhYQ4T+CNpd5rljolQpM o9ul03VSocF4RroA9/fev1WywzH3/mNuHkv+YUbbSwiYgDCV6uR+aIhg62alrYDrQYW3 hDsXqtgVe/ryXjSPf5P+qZVCvhaEGIH7ZgRCZ5GLlHSFVdlA5GV4iLj6mNa60F7z/Fp7 rWGA== 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=aoVgsGlH598afd0lbb1Y8WmNyzc/QKJmKMLmLlzylZI=; b=eKJC8kXo4uHibHNde6qLUyL848wLXIMN9376VIEeiTHJuop3GQpCuzbZUS5oK+bUci GP9zjrfYVQcne7+Vunt0WZW5vb40eQTr3kB35paDLh9qhqRu5T8jaN+jgOa1NT3QccNL rkB2YpbytTGo2z8sIbXiunQA/N647INialnrVLzl9C0YFbj1U1+fYkcwxKEuwV06Riin RKvtEUqW/XHt9Bxll2/7jzG36Qy9Fob/WU+mezCRmIHNJzOEXZLKeCURcjswy00Mjlp+ oPuaaMVDct967gE2jIOyD8Gnv7hvOyGl3Xw9X19In9Nd/mPR6LiZDCOD4P7Jk8BXyz1m 5H6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p+XqyuVy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o22si9462314ejg.184.2021.02.07.13.35.12; Sun, 07 Feb 2021 13:35:35 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=p+XqyuVy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbhBGVdP (ORCPT + 99 others); Sun, 7 Feb 2021 16:33:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:50104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbhBGVcz (ORCPT ); Sun, 7 Feb 2021 16:32:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 798D564E2A; Sun, 7 Feb 2021 21:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612733535; bh=RivXxiZn9Zzrs/dCzu2v4UlfD0jPwYaefogKeTQvQFg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=p+XqyuVy29AD6v9C+SrhkPnOPenQO+PCZeBqjV6eUa7N7Ad23AFC7i0wG8vXBFY3H FIxlax2BVY7Kmx6I/Y4ipHkO2FRjtIhgA5JkAMvHctAGsjoiN9bdBmbN2L7PPXipPW Df+2eN6fW97KcLtiYDrAaB/xQ9Cx3WeOWfjxpKbTFqyQM5zyAgXdmCOEtkQSzXfIsP jnK0lK0Nb5af0MYn7INxZVIfIAOZB8wKS1BELc4VLn96yR5WsxAc+EM1Se893Fgw8p 5CdVHieFfpEg84fKEqmM9uEBXIskbUnAP4pMzHhfrH4ng4kzv7PPh4hZvrJhKzOq7j pXvuxW2O6K9CQ== Date: Sun, 7 Feb 2021 23:32:06 +0200 From: Jarkko Sakkinen To: Dave Hansen , Borislav Petkov Cc: linux-sgx@vger.kernel.org, Haitao Huang , Dave Hansen , Thomas Gleixner , Ingo Molnar , x86@kernel.org, "H. Peter Anvin" , Jethro Beekman , Sean Christopherson , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] x86/sgx: Maintain encl->refcount for each encl->mm_list entry Message-ID: References: <20210205182840.2260-1-jarkko@kernel.org> <20210205182840.2260-2-jarkko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 07, 2021 at 11:29:49PM +0200, Jarkko Sakkinen wrote: > On Fri, Feb 05, 2021 at 11:36:57AM -0800, Dave Hansen wrote: > > On 2/5/21 10:28 AM, Jarkko Sakkinen wrote: > > > This has been shown in tests: > > > > > > [ +0.000008] WARNING: CPU: 3 PID: 7620 at kernel/rcu/srcutree.c:374 cleanup_srcu_struct+0xed/0x100 > > > > > > There are two functions that drain encl->mm_list: > > > > > > - sgx_release() (i.e. VFS release) removes the remaining mm_list entries. > > > - sgx_mmu_notifier_release() removes mm_list entry for the registered > > > process, if it still exists. > > > > Jarkko, I like your approach. This actually has the potential to be a > > lot more understandable than the fix we settled on before. > > Yeah, it's more like by-the-book use of refcount, each processs gets > a reference. This way things should be always serialized correctly. > > > But I think the explanation needs some tweaking, and I think I can take > > it a step further to make it even more straightforward. The issue here > > isn't *really* mm_list, it's this: > > > > encl_mm->encl = encl; > > Agreed. > > This was also in center of thinking when I did this new patch. > > > That literally establishes a encl_mm to encl reference and needs a > > reference count. That reference remains until 'encl_mm' is freed. I > > don't think mm_list needs to even be taken into account. > > > > The most straightforward way to fix this is to take a refcount at > > "encl_mm->encl = encl" and release it at kfree(encl_mm). That makes a > > *lot* of logical sense to me, and it's also trivial to audit. > > > > Totally untested patch attached (adapted directly from yours). > > I tested this version, and it also seems to work. Boris, can you > pick this refined version from Dave's attachment or do you prefer > that I do a re-send? Nevermind. I'll send a proper patch (just noticed that the attachment did have short summary). /Jarkko