Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6530303pxv; Thu, 29 Jul 2021 17:34:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFoZmjXEBMUGmbR5ox+7X97/0FIK2l4mveV4Ayp7GJS/3OjW9InEiFI8ffBLAnamJfjSxv X-Received: by 2002:a92:509:: with SMTP id q9mr5511699ile.239.1627605293295; Thu, 29 Jul 2021 17:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627605293; cv=none; d=google.com; s=arc-20160816; b=OHr94rxFr6HNr3fmta1Z51an5yuIv3Wr9mrs6eySVefR7DCQI7uWZfpPAFjKV6JfF7 vtnrjFVs4IfRJqlEOg5KxxrUeRkg/+5//r70MpsDfYNFHFOgN+GngXV5wClL3qlAbNZ6 iGLBnKkwXDFsxYeD9vu/0VsdZyDXoizu9h2VekORjoFy4p35rysXa1PRiVGoc9eYGTPR 3l3pWS2iFm3kzv9hyIX6keK1Yhc8mG4P45N3qkld68hOb4ackfUmJ3xAYpQi86GYkqnk F2EH6j432uxRuImV6LsFMnnjL0q29yZ2gh/9BdwFpshALF54TKjVDqxtBYQ7WJat00mG nGhA== 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=m5yW3ipoL1DAyMw7yVF7NLhmnVns2Twei6oIWRrNTSU=; b=HSAoD1Lvo+zzHyRMZW0erD2uWpFEbqU9q+hW31r3P6aVpqmPH2MwY8xyyNSLAOqmDK CAbAIXPngQF4JhxkaylK/TZ12uhEX9h6uZTHgBR4TS/7Pe9EQtxx1//kIZFMYGv8HW6B axTzQ2F7BvQtqQ95gF2HMm2LkEbJUSblFDsVJqZZ/ITSfQWBZbFDUtOfKCM5ZvCWS3kY YcNOi/3OLhlUe1AJNbDmZolriCH76I1dmifsn1PmoyCQqWBb2gq7JEeQ8oxj3R9fGVfG 2WGkRWeHQ6uz56T+pBQGa/pv1wNaKXGVcJAh4bGF93c7s8eFrc9uLQgd3UIb47bWVfcM zLgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DZHP12hX; 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 n11si5680251ilt.138.2021.07.29.17.34.41; Thu, 29 Jul 2021 17:34:53 -0700 (PDT) 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=DZHP12hX; 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 S229750AbhG3AeC (ORCPT + 99 others); Thu, 29 Jul 2021 20:34:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:58554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbhG3AeC (ORCPT ); Thu, 29 Jul 2021 20:34:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 99AD260F21; Fri, 30 Jul 2021 00:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627605238; bh=d9GQl5EJTvuOzzjdzsLOUFVFQ1w35Dm5T2hYbZADpB8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DZHP12hXIfTDhQb+DNrCpfqjU558IuAuyX6JapTF21RYrhHEpxCNnkinkT275hYlv BZpLy9/OUkT5vwaB5jvvXhxtk990WKj6ANNtDPaOeVtCqbDvmRLYpg1AmknMjcMsZV GfPzhvlyPfb0rrynPV5Z4MNDaEBtMlLT+AVPtf3r/CZgNtSXOZVNNCc8NuyJkZnkQ6 b03LsyYPADtLbc4WDG9oyxsLpe3d6ZQ75As3NbiXR0NWjzuLtyW1B8UQs4Ol0H21gy MFFLutgqIiKmvCQ4cvJ9hde4B3+9ygfNahAG1WR47Ut1LTunDs2YmijbbWo9nsQkb1 PeA4ClBUpHjvA== Date: Fri, 30 Jul 2021 03:33:54 +0300 From: Jarkko Sakkinen To: Dave Hansen Cc: Tony Luck , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/7] x86/sgx: Provide indication of life-cycle of EPC pages Message-ID: <20210730003354.xahfbqnjnkexvxh6@kernel.org> References: <20210719182009.1409895-1-tony.luck@intel.com> <20210728204653.1509010-1-tony.luck@intel.com> <20210728204653.1509010-2-tony.luck@intel.com> <17054ca5-0ef7-4b28-ab26-b1b96aa7403f@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <17054ca5-0ef7-4b28-ab26-b1b96aa7403f@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 03:12:03PM -0700, Dave Hansen wrote: > On 7/28/21 1:46 PM, Tony Luck wrote: > > +++ b/arch/x86/kernel/cpu/sgx/main.c > > @@ -581,7 +581,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) > > for ( ; ; ) { > > page = __sgx_alloc_epc_page(); > > if (!IS_ERR(page)) { > > - page->owner = owner; > > + page->owner = owner ? owner : page; > > break; > > } > > I'm a little worried about this. > > Let's say we get confused about the type of the page and dereference > page->owner. If it's NULL, we get a nice oops. If it's a real, valid > pointer, we get real valid memory back that we can scribble on. > > Wouldn't it be safer to do something like: > > page->owner = owner ? owner : (void *)-1; > > -1 is non-NULL, but also invalid, which makes it harder for us to poke > ourselves in the eye. Works for me. /Jarkko