Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1319420imi; Fri, 1 Jul 2022 07:24:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1segQLOujRc19Pp4wijmVHFysk4gt5AmzuyglfvDLZB4DPGR+MsX4/9rAxnUaZeQG2X9hUH X-Received: by 2002:a63:3e47:0:b0:40c:f2dd:bc4 with SMTP id l68-20020a633e47000000b0040cf2dd0bc4mr12316690pga.47.1656685480537; Fri, 01 Jul 2022 07:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656685480; cv=none; d=google.com; s=arc-20160816; b=PWVWJ31MXNl4ypFuM9tZRWQpHOA0jT8QLHNOLnllwwXQ6bMLpQrJpWgrhwJCpGhzoI MV7SpjEf1X7klGEbF/jaf5ML8KOHHeA+toq92ES8JUxbF3kt0PpuoZETb6jSMNlYXhm+ +r54FAjTbF6C9FsJTPHPh2CU8JAVE/wYf/OgHRpmd0I1mJcBQQXE4PQVokZeH1xeB4f2 OHVpGxlmF31XseX8O/nJ6RUSYVJtQjsnoBPbN3szgJPBlltENcrxX4AXiO/1C4G4xci1 iZ9U4Kn6rZNSTsWYTOq6zfkDaUzG3AJ9IwO/EI6J5hX6WPuKjc24Bn5dezHkTgd14xpV j2AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=j0GH8YSHluiH3wmhkXxdZz/Cat1KWlJtP1yJih5687Y=; b=xxeaqWQWFhPg7huX7IP4pr3GU11/qZ5z3J0rT2dAohkQVyIyvRRYC95kXfuB9m0Nmz Oark8Ck8RhHDSRIbmjzYTaQ6qwgcV/qvVdKD1KvsTTj2f/EAeRj0vcwKHuNGjXEaHLPU bpmoK6jqfG3hZHX7I9nGmyWVHZwEXXNYZJEStqI1xQs9EaPP4y5CTqFxw9WcOOLYrjBG F4yJoPEhJ4s7mD2FFMZEc4qfDpaYEJZEULnXa9vJAP9OhcryBHsfYXJLdyq7cR88FKZR Tus+vFzrB0mKA7aWEAtju7DV2lhsy5DpClpEPvHo9aph+xCGtXAfbgCQdfy60NiGyR57 DWCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DYUk7YKd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s78-20020a632c51000000b0040db5dc1750si8057001pgs.853.2022.07.01.07.24.17; Fri, 01 Jul 2022 07:24:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DYUk7YKd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231617AbiGANsz (ORCPT + 99 others); Fri, 1 Jul 2022 09:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231349AbiGANsy (ORCPT ); Fri, 1 Jul 2022 09:48:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6983C23145 for ; Fri, 1 Jul 2022 06:48:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 060ED620CD for ; Fri, 1 Jul 2022 13:48:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55B7CC3411E; Fri, 1 Jul 2022 13:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656683332; bh=y43yH/lmHwnyz4T4E/zryI9/gGjztLN53lDudkMy/5A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DYUk7YKdJn/QEgQVVX0K3M+ZKMVmHXxdGwxy1UoyU+z/EPw9IYdNcnQRET1sPVbst LADGCPwVY0cn+FuJIJMma1hv5RSmxTIOyWLJeORPPqKAzzM3o3Ajv7RaaZEUNb4gJX rmQbg8/NuQ8m8E4L+eYyw0aZetAF+V8pk7bZmjVVdaMBQmsRcWFw/LXo72S8J3y0ES tPC0xtUbl++V6Gh8jQDPUFnHIQlcASDlim98+e5cCyHwsClZ5v0AkTHBigGWQJbNEm iUKJ1ZBpyYbGO9NtTPjvDX5/QDJcitkr4OQganc1yYSA6RexUpoxpcqycxkKl6Pr5d yqROX8U1Ms3qQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1o7H0s-004bML-06; Fri, 01 Jul 2022 14:48:50 +0100 Date: Fri, 01 Jul 2022 14:48:49 +0100 Message-ID: <87letd0wqm.wl-maz@kernel.org> From: Marc Zyngier To: Schspa Shi Cc: james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Fix 64 bit mmio handle In-Reply-To: References: <20220630161220.53449-1-schspa@gmail.com> <87mtdu15ok.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: schspa@gmail.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 01 Jul 2022 13:22:21 +0100, Schspa Shi wrote: > > > Marc Zyngier writes: > > > On 2022-06-30 17:50, Schspa Shi wrote: > >> Marc Zyngier writes: > >> > >>> On Thu, 30 Jun 2022 17:12:20 +0100, > >>> Schspa Shi wrote: > >>>> If the len is 8 bytes, we can't get the correct sign extend for > >>>> be system. > >>> I'm afraid you'll have to give me a bit more details. > >>> > >>>> Fix the mask type len and the comparison of length. > >>>> Signed-off-by: Schspa Shi > >>>> --- > >>>> arch/arm64/kvm/mmio.c | 4 ++-- > >>>> 1 file changed, 2 insertions(+), 2 deletions(-) > >>>> diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c > >>>> index 3dd38a151d2a6..0692f8b18f35c 100644 > >>>> --- a/arch/arm64/kvm/mmio.c > >>>> +++ b/arch/arm64/kvm/mmio.c > >>>> @@ -81,8 +81,8 @@ unsigned long kvm_mmio_read_buf(const void > >>>> *buf, unsigned > >>>> int len) > >>>> int kvm_handle_mmio_return(struct kvm_vcpu *vcpu) > >>>> { > >>>> unsigned long data; > >>>> + unsigned long mask; > >>>> unsigned int len; > >>>> - int mask; > >>>> /* Detect an already handled MMIO return */ > >>>> if (unlikely(!vcpu->mmio_needed)) > >>>> @@ -97,7 +97,7 @@ int kvm_handle_mmio_return(struct kvm_vcpu > >>>> *vcpu) > >>>> data = kvm_mmio_read_buf(run->mmio.data, len); > >>>> if (kvm_vcpu_dabt_issext(vcpu) && > >>>> - len < sizeof(unsigned long)) { > >>>> + len <= sizeof(unsigned long)) { > >>> If you're reading an 8 byte quantity, what is there to > >>> sign-extend? > >>> Sign extension only makes sense if what you're reading is > >>> *smaller* > >>> than the size of the register you are targeting. > >>> > >> Yes, you are correct, sorry for my bad patch. > >> Please ignore this patch. > >> > >>> I must be missing something. And how is that related to running > >>> BE? BE > >>> in the host? The guest? > >> I mean BE is for guest running with BE mode. > > > > So what problem did you see? If you have noticed something going > > wrong, I'd like to get it fixed. > > > > I have running some static code analysis software upon Kernel code. > Seeing there is possible overflow. > > maks << 1U << ((len * 8) -1); > > The AI don't know, len is only the value of 1, 2, 4, and make this > a warnings > > I tring to analysis this, but didn't realize the real scenario of > sign extension, and finally sent this problematic patch. > > I do see some uninitialized memory reads (the values are not used > in the end, just as temporary space for API execution), > do we need to fix these? You need to be more descriptive here. What uninitialised reads? In general, pointing at the code and providing a full description of what you think is incorrect would really help... M. -- Without deviation from the norm, progress is not possible.