Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6266532rwb; Tue, 9 Aug 2022 12:04:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR5KMsh1VufHz7uP3GfIAYvWBGzMW7oxh8MFmki6TH2VSz5bexpOkIRwVYOsXdL19TvcXyYn X-Received: by 2002:a65:578f:0:b0:41c:629f:43b9 with SMTP id b15-20020a65578f000000b0041c629f43b9mr20017666pgr.557.1660071838643; Tue, 09 Aug 2022 12:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071838; cv=none; d=google.com; s=arc-20160816; b=OXKsayiCxAcKC18adNf7JgjfYTxK6q3EJ9ZH+pE5c3SGzuXwT3YxwK3SbIXb6tF75J PogQ305uXN8oQut3jinC+rRz54yCkMNIgZXswnWB2Oz8nh7ydKJMt1so6NfGpzIV1f5a 5zCfKaYfCT8sv8M/W6WchM3j+spqGIyo/fV3/NhHCvO24RrTG+ZTPUZPXBArhWcIFsyA sFTp1XTPSOlVlhK68RwrXMmBJCIQeuVTlNA/S1/H8UOWis9on/96kq7DrF1NTQRVZ2RE v49jKh0Z1dtueC658Q0o4ky+ML66kXmHy2ZOG7lp4fnuw4BhS4Thlp5afMfUp28m8osb eyFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fBZj+g/GqzsT0u3i1PZjRTGC8lJ523a9AdpCzJXYtPY=; b=Uvrf8ijBOi/wXTgjXNE8oitNzJJtDnnEPqauCIS5cYZqNjJwxR9qWVOD3alEDfklmv IhSfSB5CSo0b7n7+G4SstTwKlcnA+QA2FtaMrLPHAhGiPx4NyuH9lslq0pX7Pp/ISRlS FxtGHVeB6mZ2dJQqbkct4jJCL28lU/WKF8tKxKh8+c4geQ0xy0gB2BiUtpJUQ2fSxe/J 98scvzdXPAbeYgzA6Mgf2WRxgMdExV79ZYHMdwZE8PF1qW1x4dEs6ErMC4KNV1Fw6pRl lxfS0X5e9Z6BWqeIP8/n1LZwUZNediwTU2wGix0GxV+iJ+JMSmpzXduEyP6Z4lqS/CdR P22A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1iIU4bgg; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a170902e74c00b0016eef21566dsi3656226plf.198.2022.08.09.12.03.18; Tue, 09 Aug 2022 12:03:58 -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=@linuxfoundation.org header.s=korg header.b=1iIU4bgg; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344853AbiHISHr (ORCPT + 99 others); Tue, 9 Aug 2022 14:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245168AbiHISHD (ORCPT ); Tue, 9 Aug 2022 14:07:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B282286C9; Tue, 9 Aug 2022 11:03:06 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8BBFBB8171A; Tue, 9 Aug 2022 18:03:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEAE5C433D7; Tue, 9 Aug 2022 18:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660068184; bh=wRLfI31WrZ59IkEj+z6Z5ZZev9x2pVNmX2cjKkCxs74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1iIU4bggJNWtjqOccjNZ01lAY8fJ/etxgtu4quSna9I+rHERwpUXZh0sgG8l9QzGb 3gQKR/U7eMAJYKQXR18luYyevhFg9iQciheAtqpg6Mw4/d513PpF76042Sci793GMa pxXR9jp/fM8LFPg4+5a5HynLBQiewtGT76gB1aPE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ricardo Koller , Reiji Watanabe , Raghavendra Rao Ananta , Andrew Jones , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.4 11/15] selftests: KVM: Handle compiler optimizations in ucall Date: Tue, 9 Aug 2022 20:00:29 +0200 Message-Id: <20220809175510.695751738@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809175510.312431319@linuxfoundation.org> References: <20220809175510.312431319@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 From: Raghavendra Rao Ananta [ Upstream commit 9e2f6498efbbc880d7caa7935839e682b64fe5a6 ] The selftests, when built with newer versions of clang, is found to have over optimized guests' ucall() function, and eliminating the stores for uc.cmd (perhaps due to no immediate readers). This resulted in the userspace side always reading a value of '0', and causing multiple test failures. As a result, prevent the compiler from optimizing the stores in ucall() with WRITE_ONCE(). Suggested-by: Ricardo Koller Suggested-by: Reiji Watanabe Signed-off-by: Raghavendra Rao Ananta Message-Id: <20220615185706.1099208-1-rananta@google.com> Reviewed-by: Andrew Jones Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- tools/testing/selftests/kvm/lib/aarch64/ucall.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c index 6cd91970fbad..3b2a426070c4 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c @@ -73,20 +73,19 @@ void ucall_uninit(struct kvm_vm *vm) void ucall(uint64_t cmd, int nargs, ...) { - struct ucall uc = { - .cmd = cmd, - }; + struct ucall uc = {}; va_list va; int i; + WRITE_ONCE(uc.cmd, cmd); nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS; va_start(va, nargs); for (i = 0; i < nargs; ++i) - uc.args[i] = va_arg(va, uint64_t); + WRITE_ONCE(uc.args[i], va_arg(va, uint64_t)); va_end(va); - *ucall_exit_mmio_addr = (vm_vaddr_t)&uc; + WRITE_ONCE(*ucall_exit_mmio_addr, (vm_vaddr_t)&uc); } uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc) -- 2.35.1