Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3057077pxb; Tue, 19 Jan 2021 12:35:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnZEeFfRyCIWlCGCRXehffAON1HQl5begsQSrPOFJTqq/WDYXuLHq/+h1o4ulYKU5IA0lU X-Received: by 2002:a17:906:3388:: with SMTP id v8mr4149820eja.104.1611088517451; Tue, 19 Jan 2021 12:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611088517; cv=none; d=google.com; s=arc-20160816; b=NdMp3Pb9aT/oSnjTHc1ktITCstGHQ0c20lalMY5feYaRtPmRHuVWBY91+vGBmYwOsF zLJUfsbEyIrBgOUDay5cKj/5pjWXvDWlb79208PXRQYzo0URyf1/6roomBCM4US6cksK GgNazq1ZGu9koP8HgbYUp+2JruNltOtmeEikB4TI9Ei9puyTlHsV7z+bme95Yf6vTXFL UgHecyDwjAez4tNotQzObI6qY6WzIyshudS84JzrVOLEstQA/vG2d2GxFsaJHwIax8Ji /ycsPH9KsSV6NZtWGicPXok4mZxgFl/jG31tjtOf5doCXh3FRZb0fQMeaeiH0ol9/WDT O+Nw== 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=PIgo1AoKq/QNkl9sdqmNCwvTTcuChuuT7IVQW1TPqHU=; b=0NStJJSuf6OTTwbfo6gdzV4e5Z+GGCsLZ8lOa6KnzrrgQmtZeXXAMZrX5xdmqDJJri bAjFLoVRAW4kXQVJ8eustXk+/52mjF5uESBxZpqTVot92gomDX0h4K64mMYKUk5E4kcL 4/JrLpWz+l766c3TSklUCG4dCVBmvANHRVdOYv75DjuPHr1XjmFw4mo4BhYJdCcMaJEf xOot86Y6Pe/8+5VDz/iXIBrucV4oyb4KvbCWiqF67N0gihxl41kmFS8FYwja63vt629o pomMYavfIxAkb0JtqO5QpNd5u0Mj7yH5M5jBFaOmuParS+BGp/t2y0lOANSDbTIXjTyW 6xvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XCX8haXo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v17si6023999eda.444.2021.01.19.12.34.52; Tue, 19 Jan 2021 12:35:17 -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=@google.com header.s=20161025 header.b=XCX8haXo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729738AbhASU1l (ORCPT + 99 others); Tue, 19 Jan 2021 15:27:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729879AbhASUZ0 (ORCPT ); Tue, 19 Jan 2021 15:25:26 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2103EC061757 for ; Tue, 19 Jan 2021 12:24:44 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id b5so658419pjl.0 for ; Tue, 19 Jan 2021 12:24:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=PIgo1AoKq/QNkl9sdqmNCwvTTcuChuuT7IVQW1TPqHU=; b=XCX8haXoigSPZNeJRbH+qv688CZq5/UyppWpQdrMjVLWBGmHTsUeojs9xqrJ1UNRpX adChEPtxT3v/RpLbyp917BxfRPL+B1TYS/Y3Pt8Ebcci9kYo6v2EdKMKFn+h7YPDafnz oDyUWlBwkA/fA7yJt95Ie9bWRd54658cyCiBrZCb6iEgwvMTasedX/K2+Y0sR01Mmhwr Sy1pvX2oSngUSICr2xWyi8eTo8569NE0hqQVTv6AnXeaim8qXH8357Ftx8uCizocqHuk qU+8xm8eKvcfhEYLl59Ki5r7YfA8nC88FbzRbakerXFWtnRSaUuXIfk9RAddEQICmORl DPqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PIgo1AoKq/QNkl9sdqmNCwvTTcuChuuT7IVQW1TPqHU=; b=gIPL+Dy/T71Q99kB+LWgloTgwM88BAj1GZhrdWiqNGOJ3pEWi08IvWAcLtG2w4C8tL 2WzWedhoY45lhu2jY7fxQrVyU6I4qYHa+yk0nyqr00PrS5vuxjf+yuZ62fNbVDEKxWf9 XJnlWCEDwsY0FTuJOV+DRy60nCEVmapr8KEDZNBwB5oYgEJx8CUo6if8rn3C6gIs6lqZ yLiYz0shlyM+wtbhJthqT0yMiF8VVM+OM0gkTzhVdF55+b1LZIvrpLn5acKJCHrpxglB hoNZZ+/glRXCuZBygC1piJRZ6qd9uK8a8OFX4Iz1u/BuUXFUpqF5pCUSbVuxB5X51yoy WCTA== X-Gm-Message-State: AOAM530UvmvSQ9lEo0Y6HdlkGj5gK2n7jwJUcJTb7Mv07+e82ZE2uWrP dCzeNm1gHCLurQwBkHj76kV80g== X-Received: by 2002:a17:902:ce81:b029:de:6b3c:fcd2 with SMTP id f1-20020a170902ce81b02900de6b3cfcd2mr6433539plg.67.1611087883265; Tue, 19 Jan 2021 12:24:43 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id p15sm19706701pgl.19.2021.01.19.12.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 12:24:42 -0800 (PST) Date: Tue, 19 Jan 2021 12:24:35 -0800 From: Sean Christopherson To: Tianjia Zhang Cc: Jarkko Sakkinen , 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, 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 Reviewed-by: Sean Christopherson > --- > 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 Nit: the the "else" should also have curly braces. > list_move_tail(&page->list, &dirty); > > spin_unlock(§ion->lock); FWIW, taking section->lock could be moved inside the !ret flow so that EREMOVE is done without holding the lock. I've no idea if that'd actually change anything in practice, but it's theoretically possible that ksgxd hasn't finished sanitizing the EPC when userspace starts creating enclaves. > @@ -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 >