[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <42eac268-9b3a-b444-8288-76d57faf0826@oracle.com>
Date: Fri, 12 Jul 2019 09:43:59 +0200
From: Alexandre Chartre <alexandre.chartre@...cle.com>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: pbonzini@...hat.com, rkrcmar@...hat.com, mingo@...hat.com,
bp@...en8.de, hpa@...or.com, dave.hansen@...ux.intel.com,
luto@...nel.org, peterz@...radead.org, kvm@...r.kernel.org,
x86@...nel.org, linux-mm@...ck.org, linux-kernel@...r.kernel.org,
konrad.wilk@...cle.com, jan.setjeeilers@...cle.com,
liran.alon@...cle.com, jwadams@...gle.com, graf@...zon.de,
rppt@...ux.vnet.ibm.com
Subject: Re: [RFC v2 01/26] mm/x86: Introduce kernel address space isolation
On 7/11/19 11:33 PM, Thomas Gleixner wrote:
> On Thu, 11 Jul 2019, Alexandre Chartre wrote:
>> +/*
>> + * When isolation is active, the address space doesn't necessarily map
>> + * the percpu offset value (this_cpu_off) which is used to get pointers
>> + * to percpu variables. So functions which can be invoked while isolation
>> + * is active shouldn't be getting pointers to percpu variables (i.e. with
>> + * get_cpu_var() or this_cpu_ptr()). Instead percpu variable should be
>> + * directly read or written to (i.e. with this_cpu_read() or
>> + * this_cpu_write()).
>> + */
>> +
>> +int asi_enter(struct asi *asi)
>> +{
>> + enum asi_session_state state;
>> + struct asi *current_asi;
>> + struct asi_session *asi_session;
>> +
>> + state = this_cpu_read(cpu_asi_session.state);
>> + /*
>> + * We can re-enter isolation, but only with the same ASI (we don't
>> + * support nesting isolation). Also, if isolation is still active,
>> + * then we should be re-entering with the same task.
>> + */
>> + if (state == ASI_SESSION_STATE_ACTIVE) {
>> + current_asi = this_cpu_read(cpu_asi_session.asi);
>> + if (current_asi != asi) {
>> + WARN_ON(1);
>> + return -EBUSY;
>> + }
>> + WARN_ON(this_cpu_read(cpu_asi_session.task) != current);
>> + return 0;
>> + }
>> +
>> + /* isolation is not active so we can safely access the percpu pointer */
>> + asi_session = &get_cpu_var(cpu_asi_session);
>
> get_cpu_var()?? Where is the matching put_cpu_var() ? get_cpu_var()
> contains a preempt_disable ...
>
> What's wrong with a simple this_cpu_ptr() here?
>
Oups, my mistake, I should be using this_cpu_ptr(). I will replace all get_cpu_var()
with this_cpu_ptr().
>> +void asi_exit(struct asi *asi)
>> +{
>> + struct asi_session *asi_session;
>> + enum asi_session_state asi_state;
>> + unsigned long original_cr3;
>> +
>> + asi_state = this_cpu_read(cpu_asi_session.state);
>> + if (asi_state == ASI_SESSION_STATE_INACTIVE)
>> + return;
>> +
>> + /* TODO: Kick sibling hyperthread before switching to kernel cr3 */
>> + original_cr3 = this_cpu_read(cpu_asi_session.original_cr3);
>> + if (original_cr3)
>
> Why would this be 0 if the session is active?
>
Correct, original_cr3 won't be 0. I think this is a remain from a previous version
where original_cr3 was handled differently.
>> + write_cr3(original_cr3);
>> +
>> + /* page-table was switched, we can now access the percpu pointer */
>> + asi_session = &get_cpu_var(cpu_asi_session);
>
> See above.
>
Will fix that.
Thanks,
alex.
>> + WARN_ON(asi_session->task != current);
>> + asi_session->state = ASI_SESSION_STATE_INACTIVE;
>> + asi_session->asi = NULL;
>> + asi_session->task = NULL;
>> + asi_session->original_cr3 = 0;
>> +}
>
> Thanks,
>
> tglx
>
Powered by blists - more mailing lists