From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E177C433FE for ; Fri, 15 Oct 2021 23:07:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AFFFC6120C for ; Fri, 15 Oct 2021 23:07:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AFFFC6120C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 27C77900002; Fri, 15 Oct 2021 19:07:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2054E6B0072; Fri, 15 Oct 2021 19:07:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05B0F900002; Fri, 15 Oct 2021 19:07:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id E92AF6B006C for ; Fri, 15 Oct 2021 19:07:54 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A144A184600A5 for ; Fri, 15 Oct 2021 23:07:54 +0000 (UTC) X-FDA: 78700211268.40.0FB0AD0 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 584D7F00039B for ; Fri, 15 Oct 2021 23:07:54 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id c4so2829984pgv.11 for ; Fri, 15 Oct 2021 16:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=z8yUxq3fwATXAZvZ+lWfldcPLRgo3vd2F+DRsUdb+9k=; b=ix1CjFYFwAMKBDbre51KYojeJClAoFUDAmAZKy2BsC10T6sCVLpQf4ukVbh7B5AN9q 4ZT55TPN9AF48veuBQhveJQ7XLca0OmozymLRD//nZ9oMxVn37TTeSZVoG/1TlyhHAIg yFkOdHRc05+olH3sZp+S+lWLouBdj41M3bFcvxrxFTmf65yp+fsnGsAq7XXoudrz6CQN NIeOYcSDKzJ7voUJ+NSc9/cQdDNWc49AHboi2G6kL0VWKKe5w8IZvXzmJp80ywXjn1HC Jc4OChl6ssgf/UONOvvMhRlYYfQoUmSQTfEj3jH4LT8kYvaqtAy2iq0y6ecNorK7FErx teSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=z8yUxq3fwATXAZvZ+lWfldcPLRgo3vd2F+DRsUdb+9k=; b=U8UjQS4E+SojeM2D1X09iCADhV7/i7eD1+Uz+KrlkQlSTo/HKNZRLRyvA6eyftSgSq Ou8KOnIMqwIRRcXJlr1QMAa6vrDHZtHmOJFHb2G2R76rAI/v4mhW4bVZ//XHc48RjiiK 0VVeAO3ig/87sSqeJkhBtq+LaXSzgVuV0CPp76dUbnZcHU3a57Pq4BD2v37fGr1Na2im 1zNcK++k3FbNj2n7FCjqeUb1QI+LSGv2XV1Ua6AhmT76inWNXiueLgGI1jXogauGNiEo 7RQ/92w3pVAaQKb06mq4BN9StGiVFDsVjRDCUyPh8sqKukyHPvETdLCN/xFcW0u4V/ws 3/Eg== X-Gm-Message-State: AOAM533zBFJcxxUfvaFJq+b5Y6S7c9gfwbQHkN7fDxL8LF/HMp8rFJbu xB86tSVYoZbbRVj+fzfMmLZ2UcBZJPzTlw== X-Google-Smtp-Source: ABdhPJy4h2FNfbZgu1Koh9jPi8vcK+UEVktIVGNRQks2Obn4rAQmVHFwRnOt+GjpUTS3c3BaPXtImg== X-Received: by 2002:a63:fc65:: with SMTP id r37mr11313850pgk.28.1634339273037; Fri, 15 Oct 2021 16:07:53 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id y1sm5854838pfo.104.2021.10.15.16.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Oct 2021 16:07:52 -0700 (PDT) Date: Fri, 15 Oct 2021 23:07:48 +0000 From: Sean Christopherson To: Tony Luck Cc: "Rafael J. Wysocki" , naoya.horiguchi@nec.com, Andrew Morton , Jarkko Sakkinen , Dave Hansen , Cathy Zhang , linux-sgx@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org, Reinette Chatre Subject: Re: [PATCH v9 3/7] x86/sgx: Initial poison handling for dirty and free pages Message-ID: References: <20211001164724.220532-1-tony.luck@intel.com> <20211011185924.374213-1-tony.luck@intel.com> <20211011185924.374213-4-tony.luck@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211011185924.374213-4-tony.luck@intel.com> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 584D7F00039B X-Stat-Signature: ui6yy7ngy57h6j5ojfzbsf84zc1mpdye Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ix1CjFYF; spf=pass (imf17.hostedemail.com: domain of seanjc@google.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1634339274-264467 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Oct 11, 2021, Tony Luck wrote: > A memory controller patrol scrubber can report poison in a page > that isn't currently being used. > > Add "poison" field in the sgx_epc_page that can be set for an > sgx_epc_page. Check for it: > 1) When sanitizing dirty pages > 2) When freeing epc pages > > Poison is a new field separated from flags to avoid having to make > all updates to flags atomic, or integrate poison state changes into > some other locking scheme to protect flags. Explain why atomic would be needed. I lived in this code for a few years and still had to look at the source to remember that the reclaimer can set flags without taking node->lock. > In both cases place the poisoned page on a list of poisoned epc pages > to make sure it will not be reallocated. > > Reviewed-by: Jarkko Sakkinen > Tested-by: Reinette Chatre > Signed-off-by: Tony Luck > --- > arch/x86/kernel/cpu/sgx/main.c | 14 +++++++++++++- > arch/x86/kernel/cpu/sgx/sgx.h | 3 ++- > 2 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c > index 09fa42690ff2..653bace26100 100644 > --- a/arch/x86/kernel/cpu/sgx/main.c > +++ b/arch/x86/kernel/cpu/sgx/main.c > @@ -43,6 +43,7 @@ static nodemask_t sgx_numa_mask; > static struct sgx_numa_node *sgx_numa_nodes; > > static LIST_HEAD(sgx_dirty_page_list); > +static LIST_HEAD(sgx_poison_page_list); > > /* > * Reset post-kexec EPC pages to the uninitialized state. The pages are removed > @@ -62,6 +63,12 @@ static void __sgx_sanitize_pages(struct list_head *dirty_page_list) > > page = list_first_entry(dirty_page_list, struct sgx_epc_page, list); > > + if (page->poison) { Does this need READ_ONCE (and WRITE_ONCE in the writer) to prevent reloading page->poison since the sanitizer doesn't hold node->lock, i.e. page->poison can be set any time? Honest question, I'm terrible with memory ordering rules... > + list_del(&page->list); > + list_add(&page->list, &sgx_poison_page_list); list_move() > + continue; > + } > + > ret = __eremove(sgx_get_epc_virt_addr(page)); > if (!ret) { > /* > @@ -626,7 +633,11 @@ void sgx_free_epc_page(struct sgx_epc_page *page) > > spin_lock(&node->lock); > > - list_add_tail(&page->list, &node->free_page_list); > + page->owner = NULL; > + if (page->poison) > + list_add(&page->list, &sgx_poison_page_list); sgx_poison_page_list is a global list, whereas node->lock is, well, per node. On a system with multiple EPCs, this could corrupt sgx_poison_page_list if multiple poisoned pages from different nodes are freed simultaneously. > + else > + list_add_tail(&page->list, &node->free_page_list); > sgx_nr_free_pages++; > page->flags = 0; > > @@ -658,6 +669,7 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, > section->pages[i].section = index; > section->pages[i].flags = SGX_EPC_PAGE_IN_USE; > section->pages[i].owner = NULL; > + section->pages[i].poison = 0; > list_add_tail(§ion->pages[i].list, &sgx_dirty_page_list); > } > > diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h > index f9202d3d6278..a990a4c9a00f 100644 > --- a/arch/x86/kernel/cpu/sgx/sgx.h > +++ b/arch/x86/kernel/cpu/sgx/sgx.h > @@ -31,7 +31,8 @@ > > struct sgx_epc_page { > unsigned int section; > - unsigned int flags; > + u16 flags; > + u16 poison; > struct sgx_encl_page *owner; > struct list_head list; > }; > > -- > 2.31.1 >