Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp273609pxb; Wed, 20 Jan 2021 06:49:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWxLZvJs9MN90ic43ceA/V4n4QEXa+JSHQ7LAXyCKy4U974Gu/D7EIcB0Gei3MPWTn32fW X-Received: by 2002:a05:6402:5112:: with SMTP id m18mr7797450edd.129.1611154146353; Wed, 20 Jan 2021 06:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611154146; cv=none; d=google.com; s=arc-20160816; b=ZZaQQY6etf+KiPjp+lAZuoz1okrK4pvHeHhtpuxZiO0yIpdoiabf10vKR3VWNGXGGU UFBFVZUlQdCieek2Posd1zUB6li0SvLRitOh13Ugmv6/wqJ0PMlIwseIWzYXHF4fXWZT haTxwXk2A6aitEiMVFdNU46KYGisrKZM8/+C5DwWygpMSimzrV6BEy1HUB2Cv7Q/PsyB FIigyqCMmtEUotQAiW4L4TbDnNPxB4iyxGwcPHZbwAmb3VE/6KoW0ppc/QG8NRYJEtDD 0aQDiSqVjeIirryIctWEhspVHnQoVvIaTjEwLORrlwb7/6Dovr+cw+PshtgN2znm/AeF jvGw== 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=vXw7UbW0/nN48nJz/2tjXI0ayRPj51MoIrDh+0sOWoA=; b=sSgCfElFoJ1MPJS3ruSpCQX9oVPzLLwVdeYUL0bYS3nmW9gZEGoKqbumVgpl3F2JWM cF42BATI6nqldWNAL+CfcanlqqE2HpVIRY4K+kGkSvzZMcB4PatTGlyd+JFabNX7QAYi GvQjsXt2iYkN7wkNgUPiLznYTLYfT8t1AHfu0oBAlIIhMOaMNKnsZB9lIuQGFUZ4lg7w VtCOD3+jBhLAR66sMThza8UBhyPXTPvbQVLC7qMVjh2Ne3qmh8sHnth+iV9SfRea/A0V K672SVnslGrNahZjGNhEQPtbVdSk1GVqulBtylyBP+kSjv5ZiXE6g2WWKsagbg38DR+W D3lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fkSuyQs8; 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 x9si780923eje.522.2021.01.20.06.48.31; Wed, 20 Jan 2021 06:49:06 -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=fkSuyQs8; 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 S2390521AbhATOiZ (ORCPT + 99 others); Wed, 20 Jan 2021 09:38:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:41668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390099AbhATOhR (ORCPT ); Wed, 20 Jan 2021 09:37:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A8FE22245C; Wed, 20 Jan 2021 14:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611153397; bh=gIx6Byc8LjKVM2fxtZc3MbFvHCR2ATctdI9B+bQjgWA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fkSuyQs8KSB/KtNGKxIrVGEifND+44NVHwWeNayUTerkL80A0LoOgfjJoX2lY7xWu Jjb0CRRjYi0vPSmrA0VC/ZpTt8zoq0WTd+lrjb801soxlOecDQ6uQ3nt2LdqUqR2Pz bQnYfuUJFtLVjBACmcPG3CyitoIgoj6VftlYiMfceXHsyoeFEe0mxJbGhBaS7OwLmp ApXp3/YG2LzIogMHRT16xfteWpqpp3FsMf8MNpT+UIap3qFkiwGt++1GlmynUQ8Q7J fU+LNDLUQmKQKbWsLyJAC7qBYCsxZwH1in5DlB9M8LwYwF3CpeXMoS3pMSoKF+ufCD iW7tB/rQMxsyw== Date: Wed, 20 Jan 2021 16:36:31 +0200 From: Jarkko Sakkinen To: Tianjia Zhang Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Andrew Morton , Shuah Khan , haitao.huang@intel.com, Kai Huang , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Jia Zhang Subject: Re: [PATCH] x86/sgx: Fix free_cnt counting logic in epc section Message-ID: References: <20210118133347.99158-1-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210118133347.99158-1-tianjia.zhang@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 18, 2021 at 09:33:47PM +0800, Tianjia Zhang wrote: > Increase `section->free_cnt` in sgx_sanitize_section() is > more reasonable, which is called in ksgxd kernel thread, > instead of assigning it to epc section pages number at > initialization. Although this is unlikely to fail, these > pages cannot be allocated after initialization, and which > need to be reset by ksgxd. > > Reported-by: Jia Zhang > Signed-off-by: Tianjia Zhang There is nothing broken in the logic. Convince me otherwise. I.e. what is exactly broken, and how? /Jarkko > --- > arch/x86/kernel/cpu/sgx/main.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c > index c519fc5f6948..9e9a3cf7c00b 100644 > --- a/arch/x86/kernel/cpu/sgx/main.c > +++ b/arch/x86/kernel/cpu/sgx/main.c > @@ -48,9 +48,10 @@ static void sgx_sanitize_section(struct sgx_epc_section *section) > struct sgx_epc_page, list); > > ret = __eremove(sgx_get_epc_virt_addr(page)); > - if (!ret) > + if (!ret) { > list_move(&page->list, §ion->page_list); > - else > + section->free_cnt += 1; > + } else > list_move_tail(&page->list, &dirty); > > spin_unlock(§ion->lock); > @@ -646,7 +647,6 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, > list_add_tail(§ion->pages[i].list, §ion->init_laundry_list); > } > > - section->free_cnt = nr_pages; > return true; > } > > -- > 2.19.1.3.ge56e4f7 > >