From patchwork Wed Jun 15 18:57:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12882843 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 89614C43334 for ; Wed, 15 Jun 2022 18:58:29 +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:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=lP1/QnaXvbPTsYYWhhsO/uz/J3v0B1Ehuc1ZOemZwa0=; b=vbQ lmf1L2oLg2HefVEAm3H1/voYGWnQaLTgQufqZUwpFKPTqt1cLqobAYRP6maK3C6SWdd/phK6q/Lz1 k1tCNCecWb7KdCqSHDEooLAzYDogfKZV5F1hqy5/6HX3UyzIpd5802kSUzctHnN7LFYfVZ9n1pq0B ePpLFVenjyNFhFtImF8izHguCr9XMFXn5FzX2wFVgbQkdf7m4aQWXweXVswRcYJGN/j+7nG/TW2Oa vythYUKs/0NHuW6YiL4HsMuxY0MjJbYoxqdTC2etatkws5RFXVcO5Zo4sLmWppFx7oAY1gWF8VjnX 0HJDalQ5g3PPlN3JdIk53G6W8kGs+DQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1YCf-00FzxG-NC; Wed, 15 Jun 2022 18:57:21 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1YCc-00Fzv6-I9 for linux-arm-kernel@lists.infradead.org; Wed, 15 Jun 2022 18:57:19 +0000 Received: by mail-pj1-x1049.google.com with SMTP id t11-20020a17090a2f8b00b001ea6a226d21so1431510pjd.8 for ; Wed, 15 Jun 2022 11:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=JOfZ+gB0dYMw5zlfGsNpFQnCHYNIGhGPLB/fJ5JUiU8=; b=SmOp6Z2zPaMf+7HW3xlQs45Fjh1wQY3JcE955U5EzRHsTUkE/IVL5RlhOgVgPtTUSd 40TLB+kwbienuX8Dx2E0wGxELrUEYzz+rLJg+3O0i9zwkTixcET9vp4JBVjxgbrJBAnu +cYumohJ/0Z1hODaPf0Ii6qP1SyuhGSKXz4inlCZbL9c2knCQta/33jC2LQmQ/aeD1/y Tnpe70f0H+Jx5LGBbpe/TeG9QpvYq8ogcKYRc6PcX+ZPg4yqL5EsPmDFbBWLlmCrK4+l wTu6a0wUtxmkc1JTA20jJsnPffMTnk8/bBUa5UdrL8N2SVS1KlYBk5kkxZrRKRWiYilI BvRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=JOfZ+gB0dYMw5zlfGsNpFQnCHYNIGhGPLB/fJ5JUiU8=; b=R6QLDi02RAtGs04cYJqeNqoHO9Pnl/iGeNQnKORzlADbUBzwSgZTC0cEUpCt2mqdrh 3N5dEj87y7qKQ3oQLIw0es7HXondTrGphfgG7Hf67ISxLZNGC2emLg3puJm2s7csAf1d ryGtS0/dkZ2lKfT3RbV3p+sbDDpvMUuIgjLOy8CMvT0UzTWzfdM7J07oaQT+7f8063yR Z3h+OCreSX2QZIPKccGC4SF/kdOacWbURGfQ5prbeYu7su6fhICkhRQE1YBsc8U0etWU sn9E/gLsGUxxT1S7o0JCndAVLE1tBOwPBaRE290PT0XJ2cncgwwEz8ctprlZQpzIkJpv F0PA== X-Gm-Message-State: AJIora/wUH4y/VYq1tW0mUM6QMKkavSCwK6KNB4ypcdCQiRBAIA60+Vh DyHUgkZSFu9JY5ZnCVXeDiUF9zb60gdJ X-Google-Smtp-Source: AGRyM1tnQw7CJaekFPc8SBXFz+VUADNRt0rkCQV5Q4hm28pSqTrYYIgOQmS9We429pxh9Gldc5o2PJ/GLIXf X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:74c3:b0:167:6811:40 with SMTP id f3-20020a17090274c300b0016768110040mr1022512plt.120.1655319436857; Wed, 15 Jun 2022 11:57:16 -0700 (PDT) Date: Wed, 15 Jun 2022 18:57:06 +0000 Message-Id: <20220615185706.1099208-1-rananta@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH] selftests: KVM: Handle compiler optimizations in ucall From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Colton Lewis , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220615_115718_641190_228FE49A X-CRM114-Status: GOOD ( 11.51 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Andrew Jones --- 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)