Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6266366rwb; Tue, 9 Aug 2022 12:04:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR5gPBC3vtM5EnLMXXpe3xtwCmE1pry0UuUHcprGJYRrR3zegsTlNqSr7IHqBgh/AhFfsFbk X-Received: by 2002:a17:90b:4a07:b0:1f5:1aff:4ab with SMTP id kk7-20020a17090b4a0700b001f51aff04abmr36518485pjb.216.1660071846895; Tue, 09 Aug 2022 12:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071846; cv=none; d=google.com; s=arc-20160816; b=dFgSGbo4vkYWgxhsPD6fWMVTheapFDw+EPW6jAE0j+80ynQk33sUDapuLRtn0VtoBB iuyWB5k1in1VHGDekgLx+IiyMGWugT5PfELIwwb9dEPrbpMYIfh8TsOgQVBrxNDzHAOL B4EwAdIvgUmQhatZYITRalY7HzYUe+imcDi2awI98xUMekHTpMTtwiy53C0oy3QBjRyM yo6FGGRmEEKKzilnRKWVcWV3PLOoIZYlUSSFin0pU2DmcnSoyQip3BQ47xIq1c+6rbr4 CaLdN+aRLj2BKufN7qxAXKFb7LTk0MvL/2luAiOBpGWg1NGScIjzHElGjNeSDCUUZJ74 79XA== 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=DVGEulTiQ51fhBzvjJWU5GyAiPJrR/SCuxr9C5XAGpA=; b=c8437mxRofBWRbhzJr3WEo9zQLwfKnLdJIh7B+skM27oKYJRGCSCKxdXW0c1EN1pI2 +xJxJsjNk+Cv8JgBEfFDNSX+RSeTOvLOtPUsy22u2a2ntIyvJqxqo/Pj7soYMt8XUUhx WZ7w+Z6tkmnb+2oB6YHncdXPmqgFRIv6KNCqyDVlLkahWFPq0GWqG5y9DCN7eDCl/hSC LABqTGR0rn4xXPqyKezse3SsvtCd/z3fqOSBZBkdUgDApBdIBq0XfKM2EjZ+cYibLhJ9 KvMmKANUpV9L6roJ5XDvZyvkxrVoO55l5DlFYgybwplNLTEHr1rjqWHjYtf6udJjtCyh Q6Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zfTYSnci; 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 w16-20020a056a0014d000b0052f0fa0c853si463480pfu.241.2022.08.09.12.03.45; Tue, 09 Aug 2022 12:04:06 -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=zfTYSnci; 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 S1343923AbiHISYA (ORCPT + 99 others); Tue, 9 Aug 2022 14:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347005AbiHISVs (ORCPT ); Tue, 9 Aug 2022 14:21:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16BD231342; Tue, 9 Aug 2022 11:08:14 -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 7961DB81978; Tue, 9 Aug 2022 18:07:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1882C433B5; Tue, 9 Aug 2022 18:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660068432; bh=Q9TQo1YpqN5c0AN7PcviO9s8yzNZpGDadJSGpTvGND8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zfTYSnciBE64iArhPgp2RoAnbNFztxpuXWzyYRj1kGcGyrZ0kRjsRJRpquF14nx4g fLB6EAXGxk0IK5MywQ3TGwfXfAfM/Gr0t015TcVXUPzYavoUnMBAvgyVU5Mc2MP53q 5VqIk6ddU0jE1pVlhYNxpySHrMaCoLXtERQ/oBjE= 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.18 17/35] selftests: KVM: Handle compiler optimizations in ucall Date: Tue, 9 Aug 2022 20:00:46 +0200 Message-Id: <20220809175515.675440462@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809175515.046484486@linuxfoundation.org> References: <20220809175515.046484486@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 e0b0164e9af8..be1d9728c4ce 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