Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1728183

Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host

From gengdongjiu <gengdongjiu@huawei.com>
Newsgroups linux.kernel
Subject Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host
Date 2017-09-07 14:00 +0200
Message-ID <un3Ds-7Vp-13@gated-at.bofh.it> (permalink)
References <umXHH-3QW-3@gated-at.bofh.it> <un1ii-6qW-5@gated-at.bofh.it> <un1UZ-6Xn-5@gated-at.bofh.it> <un24G-71m-25@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 2017/9/7 18:13, Marc Zyngier wrote:
> On 07/09/17 11:05, gengdongjiu wrote:
>> Hi James,
>>
>> On 2017/9/7 17:20, James Morse wrote:
>>> Hi Dongjiu Geng,
>>>
>>> On 07/09/17 06:54, Dongjiu Geng wrote:
>>>> In VHE mode, host kernel runs in the EL2 and can enable
>>>> 'User Access Override' when fs==KERNEL_DS so that it can
>>>> access kernel memory. However, PSTATE.UAO is set to 0 on
>>>> an exception taken from EL1 to EL2. Thus when VHE is used
>>>> and exception taken from a guest UAO will be disabled and
>>>> host will use the incorrect PSTATE.UAO. So check and reset
>>>> the PSTATE.UAO when switching to host.
>>>
>>> This would only be a problem if KVM were calling into world-switch with
>>> fs==KERNEL_DS. I can't see where this happens.
>>  Not only KVM, may also kernel sets the fs == KERNEL_DS before calling into world-switch
> 
> How? Please describe the exact sequence of event that lead to this
> situation with the current code base.

Hi Marc,

   Different tasks have different fs, such as USER_DS or KERNEL_DS. In the context switch, it will restore the
task's fs. Thus, that depends on task itself, as shown below code. UAO is different with PAN, PAN will be always enabled if
hardware CPU supports PAN feature, but UAO is dynamical change.

/*
 * Thread switching.
 */
__notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev,
				struct task_struct *next)
{
	struct task_struct *last;

	fpsimd_thread_switch(next);
	tls_thread_switch(next);
	hw_breakpoint_thread_switch(next);
	contextidr_thread_switch(next);
	entry_task_switch(next);
	uao_thread_switch(next);
 	..........
}

/* Restore the UAO state depending on next's addr_limit */
void uao_thread_switch(struct task_struct *next)
{
	if (IS_ENABLED(CONFIG_ARM64_UAO)) {
		if (task_thread_info(next)->addr_limit == KERNEL_DS)
			asm(ALTERNATIVE("nop", SET_PSTATE_UAO(1), ARM64_HAS_UAO));
		else
			asm(ALTERNATIVE("nop", SET_PSTATE_UAO(0), ARM64_HAS_UAO));
	}
}

> 
> 	M.
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host Dongjiu Geng <gengdongjiu@huawei.com> - 2017-09-07 07:40 +0200
  Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host James Morse <james.morse@arm.com> - 2017-09-07 11:30 +0200
    Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host gengdongjiu <gengdongjiu@huawei.com> - 2017-09-07 12:10 +0200
      Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host Marc Zyngier <marc.zyngier@arm.com> - 2017-09-07 12:20 +0200
        Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host gengdongjiu <gengdongjiu@huawei.com> - 2017-09-07 14:00 +0200
          Re: [PATCH] arm64: KVM: VHE: reset PSTATE.UAO when switch to host Marc Zyngier <marc.zyngier@arm.com> - 2017-09-07 14:10 +0200

csiph-web