lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 6 Jun 2023 15:00:11 +0800
From:   Youling Tang <tangyouling@...ngson.cn>
To:     Tianrui Zhao <zhaotianrui@...ngson.cn>
Cc:     linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
        Paolo Bonzini <pbonzini@...hat.com>,
        Huacai Chen <chenhuacai@...nel.org>,
        WANG Xuerui <kernel@...0n.name>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        loongarch@...ts.linux.dev, Jens Axboe <axboe@...nel.dk>,
        Mark Brown <broonie@...nel.org>,
        Alex Deucher <alexander.deucher@....com>,
        Oliver Upton <oliver.upton@...ux.dev>, maobibo@...ngson.cn,
        Xi Ruoyao <xry111@...111.site>
Subject: Re: [PATCH v12 26/31] LoongArch: KVM: Implement kvm exception vector



On 05/30/2023 09:52 AM, Tianrui Zhao wrote:
> Implement kvm exception vector, using _kvm_fault_tables array to save
> the handle function pointer and it is used when vcpu handle exit.
>
> Signed-off-by: Tianrui Zhao <zhaotianrui@...ngson.cn>
> ---
>  arch/loongarch/kvm/exit.c | 48 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
>
> diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
> index 10f9922a7e76..625045fc95c8 100644
> --- a/arch/loongarch/kvm/exit.c
> +++ b/arch/loongarch/kvm/exit.c
> @@ -657,3 +657,51 @@ static int _kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
>  	kvm_own_fpu(vcpu);
>  	return RESUME_GUEST;
>  }
> +
> +/*
> + * Loongarch KVM callback handling for not implemented guest exiting
> + */
> +static int _kvm_fault_ni(struct kvm_vcpu *vcpu)
> +{
> +	unsigned long estat, badv;
> +	unsigned int exccode, inst;
> +
> +	/*
> +	 *  Fetch the instruction.
> +	 */
> +	badv = vcpu->arch.badv;
> +	estat = vcpu->arch.host_estat;
> +	exccode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
> +	inst = vcpu->arch.badi;
> +	kvm_err("Exccode: %d PC=%#lx inst=0x%08x BadVaddr=%#lx estat=%#lx\n",
> +			exccode, vcpu->arch.pc, inst, badv, read_gcsr_estat());
> +	kvm_arch_vcpu_dump_regs(vcpu);
> +	vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> +
> +	return RESUME_HOST;
> +}
> +
> +static exit_handle_fn _kvm_fault_tables[EXCCODE_INT_START] = {
> +	[EXCCODE_TLBL]		= _kvm_handle_read_fault,
> +	[EXCCODE_TLBI]		= _kvm_handle_read_fault,
> +	[EXCCODE_TLBNR]		= _kvm_handle_read_fault,
> +	[EXCCODE_TLBNX]		= _kvm_handle_read_fault,
> +	[EXCCODE_TLBS]		= _kvm_handle_write_fault,
> +	[EXCCODE_TLBM]		= _kvm_handle_write_fault,
> +	[EXCCODE_FPDIS]		= _kvm_handle_fpu_disabled,
> +	[EXCCODE_GSPR]		= _kvm_handle_gspr,
> +};
It can be modified as follows and remove _kvm_init_fault().

static exit_handle_fn _kvm_fault_tables[EXCCODE_INT_START] = {
	[0 ... EXCCODE_INT_START - 1]	= _kvm_fault_ni,

	[EXCCODE_TLBL]			= _kvm_handle_read_fault,
	[EXCCODE_TLBI]			= _kvm_handle_read_fault,
	[EXCCODE_TLBNR]			= _kvm_handle_read_fault,
	[EXCCODE_TLBNX]			= _kvm_handle_read_fault,
	[EXCCODE_TLBS]			= _kvm_handle_write_fault,
	[EXCCODE_TLBM]			= _kvm_handle_write_fault,
	[EXCCODE_FPDIS]			= _kvm_handle_fpu_disabled,
	[EXCCODE_GSPR]			= _kvm_handle_gspr,
};

Thanks,
Youling

> +
> +int _kvm_handle_fault(struct kvm_vcpu *vcpu, int fault)
> +{
> +	return _kvm_fault_tables[fault](vcpu);
> +}
> +
> +void _kvm_init_fault(void)
> +{
> +	int i;
> +
> +	for (i = 0; i < EXCCODE_INT_START; i++)
> +		if (!_kvm_fault_tables[i])
> +			_kvm_fault_tables[i] = _kvm_fault_ni;
> +}
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ