From: Jarkko Sakkinen <jarkko@kernel.org>
To: Reinette Chatre <reinette.chatre@intel.com>
Cc: linux-sgx@vger.kernel.org,
Haitao Huang <haitao.huang@linux.intel.com>,
Vijay Dhanraj <vijay.dhanraj@intel.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Paul Menzel <pmenzel@molgen.mpg.de>,
stable@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/6] x86/sgx: Do not consider unsanitized pages an error
Date: Fri, 2 Sep 2022 02:56:58 +0300 [thread overview]
Message-ID: <YxFGykqMb+TD4L4l@kernel.org> (raw)
In-Reply-To: <84b8eb06-7b77-675f-5bc8-292fe27dd2f5@intel.com>
On Thu, Sep 01, 2022 at 03:34:10PM -0700, Reinette Chatre wrote:
> Hi Jarkko,
>
> On 9/1/2022 2:53 PM, Jarkko Sakkinen wrote:
> > On Wed, Aug 31, 2022 at 01:39:53PM -0700, Reinette Chatre wrote:
> >> On 8/31/2022 10:38 AM, Jarkko Sakkinen wrote:
>
> >> I think I am missing something here. A lot of logic is added here but I
> >> do not see why it is necessary. ksgxd() knows via kthread_should_stop() if
> >> the reclaimer was canceled. I am thus wondering, could the above not be
> >> simplified to something similar to V1:
> >>
> >> @@ -388,6 +393,8 @@ void sgx_reclaim_direct(void)
> >>
> >> static int ksgxd(void *p)
> >> {
> >> + unsigned long left_dirty;
> >> +
> >> set_freezable();
> >>
> >> /*
> >> @@ -395,10 +402,10 @@ static int ksgxd(void *p)
> >> * required for SECS pages, whose child pages blocked EREMOVE.
> >> */
> >> __sgx_sanitize_pages(&sgx_dirty_page_list);
> >
> > IMHO, would make sense also to have here:
> >
> > if (!kthread_should_stop())
> > return 0;
> >
>
> Would this not prematurely stop the thread when it should not be?
>
> >> - __sgx_sanitize_pages(&sgx_dirty_page_list);
> >>
> >> - /* sanity check: */
> >> - WARN_ON(!list_empty(&sgx_dirty_page_list));
> >> + left_dirty = __sgx_sanitize_pages(&sgx_dirty_page_list);
> >> + if (left_dirty && !kthread_should_stop())
> >> + pr_err("%lu unsanitized pages\n", left_dirty);
> >
> > That would be incorrect, if the function returned
> > because of kthread stopped.
>
>
> I should have highlighted this but in my example I changed
> left_dirty to be "unsigned long" with the intention that the
> "return -ECANCELED" is replaced with "return 0".
It wasn't supposed to be, it's an error. Thanks for spotting
that.
>
> __sgx_sanitize_pages() returns 0 when it exits because of
> kthread stopped.
>
> To elaborate I was thinking about:
>
> +static unsigned long __sgx_sanitize_pages(struct list_head *dirty_page_list)
> {
> + unsigned long left_dirty = 0;
> struct sgx_epc_page *page;
> LIST_HEAD(dirty);
> int ret;
>
> - /* dirty_page_list is thread-local, no need for a lock: */
> while (!list_empty(dirty_page_list)) {
> if (kthread_should_stop())
> - return;
> + return 0;
>
> page = list_first_entry(dirty_page_list, struct sgx_epc_page, list);
>
> @@ -92,12 +95,14 @@ static void __sgx_sanitize_pages(struct list_head *dirty_page_list)
> } else {
> /* The page is not yet clean - move to the dirty list. */
> list_move_tail(&page->list, &dirty);
> + left_dirty++;
> }
>
> cond_resched();
> }
>
> list_splice(&dirty, dirty_page_list);
> + return left_dirty;
> }
>
>
> and then with what I had in previous email the checks should work:
>
> @@ -388,6 +393,8 @@ void sgx_reclaim_direct(void)
>
> static int ksgxd(void *p)
> {
> + unsigned long left_dirty;
> +
> set_freezable();
>
> /*
> @@ -395,10 +402,10 @@ static int ksgxd(void *p)
> * required for SECS pages, whose child pages blocked EREMOVE.
> */
> __sgx_sanitize_pages(&sgx_dirty_page_list);
> - __sgx_sanitize_pages(&sgx_dirty_page_list);
>
> - /* sanity check: */
> - WARN_ON(!list_empty(&sgx_dirty_page_list));
> + left_dirty = __sgx_sanitize_pages(&sgx_dirty_page_list);
> + if (left_dirty && !kthread_should_stop())
> + pr_err("%lu unsanitized pages\n", left_dirty);
>
> while (!kthread_should_stop()) {
> if (try_to_freeze())
>
>
> >
> > If you do the check here you already have a window
> > where kthread could have been stopped anyhow.
> >
> > So even this would be less correct:
> >
> > if (kthreas_should_stop()) {
> > return 0;
> > } else if (left_dirty) {
> > pr_err("%lu unsanitized pages\n", left_dirty);
> > }
> >
> > So in the end you end as complicated and less correct
> > fix. This all is explained in the commit message.
> >
> > If you unconditionally print error, you don't have
> > a meaning for the number of unsanitized pags.
>
> Understood that the goal is to only print the
> number of unsanitized pages if ksgxd has not been
> stopped prematurely.
Yeah, and thus give as useful information for sysadmin/developer
as we can.
BR, Jarkko
next prev parent reply other threads:[~2022-09-01 23:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220831173829.126661-1-jarkko@kernel.org>
2022-08-31 17:38 ` [PATCH v2 2/6] x86/sgx: Do not consider unsanitized pages an error Jarkko Sakkinen
2022-08-31 20:39 ` Reinette Chatre
2022-09-01 10:50 ` Huang, Kai
2022-09-01 21:47 ` jarkko
2022-09-01 21:53 ` Jarkko Sakkinen
2022-09-01 21:56 ` Jarkko Sakkinen
2022-09-01 22:01 ` Jarkko Sakkinen
2022-09-01 22:34 ` Reinette Chatre
2022-09-01 23:56 ` Jarkko Sakkinen [this message]
2022-09-02 13:26 ` Jarkko Sakkinen
2022-09-02 15:53 ` Jarkko Sakkinen
2022-09-02 16:08 ` Reinette Chatre
2022-09-02 16:30 ` Jarkko Sakkinen
2022-09-02 17:38 ` Reinette Chatre
2022-09-02 19:20 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YxFGykqMb+TD4L4l@kernel.org \
--to=jarkko@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=haitao.huang@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pmenzel@molgen.mpg.de \
--cc=reinette.chatre@intel.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=vijay.dhanraj@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox