From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29F0FC77B73 for ; Wed, 19 Apr 2023 08:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GKMkfCN79yWsxcMOYDFX/b0DPad2rWV7s39fBwh1ek0=; b=GRj7SQH8D8IrZX 3Ksps+ai4Fj+JP7dRjVv9g5Hno1+ZWOzhfB6XdiLDou3eoUPxw+RYZUSknaki9LnsG0mvfDrYPchk VtufiuhJgii7+V0loQ0SUR9YejSA2MNWCRBOCFVXoCwUL1W7foywR45rX5tRw5HKl9ay6vCgXelw3 ew/PW343SPdp4vMABYaJeKS4sPdA7gbsnK+UIdvUXTzO2UUO7gfNS8iCXdYMzCfCYM2aK1CLzmR/q S39pCejz8KGGBpdZuTEiTA5zOHpdnNfudZk7z3cgqKQxyC4ba1OX8Ou8r8SE3wpFA9oaruanybwfL aO3t7FCkEBlEGEOyPIBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pp3dw-004g5F-2Q; Wed, 19 Apr 2023 08:58:24 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pp3du-004g3q-0e for linux-arm-kernel@lists.infradead.org; Wed, 19 Apr 2023 08:58:23 +0000 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 B3E0C6163D; Wed, 19 Apr 2023 08:58:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B7E5C433EF; Wed, 19 Apr 2023 08:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681894701; bh=mBy7r4l2S8sicYbRnowa3lQqGGdm/51Xuq6XArqu3Zk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bobUFuFPQIIKHJelLDSsryC4Q5j9L7duxM1U0wdbCnHMb6jHGNVChnXC4GvQx2BlO jcvYNbBVew1IC9cGV409dehjC4MHIy1bAMg/tqmpMXc/LifTPfeeuYkOiCW00IXAIY 00E1a+S5U6h/9VMiqHAzVfyNSNbRTXlbZim2glBIbHs/Rlh3XGTtJhC65G2IN+sNml hX79mWsy9kipjJxnXvXRRuMZQXWCVo60uWcgJerMwLU9rx4gisqp/FrH6T/qGxEWtU dk7H8P8obKQuR1YcCmzfkIHb4bPm/rzMe+pVN0s79Q6SGmOz3fQTL65jjQBD+U+eOV WIp7eTYMOi13Q== Date: Wed, 19 Apr 2023 09:58:15 +0100 From: Will Deacon To: Marc Zyngier Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Catalin Marinas , Quentin Perret , Mostafa Saleh , stable@vger.kernel.org Subject: Re: [PATCH v2] KVM: arm64: Make vcpu flag updates non-preemptible Message-ID: <20230419085814.GA928@willie-the-truck> References: <20230418125737.2327972-1-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230418125737.2327972-1-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230419_015822_277747_D020D0A6 X-CRM114-Status: GOOD ( 18.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Apr 18, 2023 at 01:57:37PM +0100, Marc Zyngier wrote: > Per-vcpu flags are updated using a non-atomic RMW operation. > Which means it is possible to get preempted between the read and > write operations. > > Another interesting thing to note is that preemption also updates > flags, as we have some flag manipulation in both the load and put > operations. > > It is thus possible to lose information communicated by either > load or put, as the preempted flag update will overwrite the flags > when the thread is resumed. This is specially critical if either > load or put has stored information which depends on the physical > CPU the vcpu runs on. > > This results in really elusive bugs, and kudos must be given to > Mostafa for the long hours of debugging, and finally spotting > the problem. > > Fix it by disabling preemption during the RMW operation, which > ensures that the state stays consistent. Also upgrade vcpu_get_flag > path to use READ_ONCE() to make sure the field is always atomically > accessed. > > Fixes: e87abb73e594 ("KVM: arm64: Add helpers to manipulate vcpu flags among a set") > Reported-by: Mostafa Saleh > Signed-off-by: Marc Zyngier > Cc: stable@vger.kernel.org > --- > > Notes: > v2: add READ_ONCE() on the read path, expand commit message Acked-by: Will Deacon Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel