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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22FF0C6FA82 for ; Thu, 8 Sep 2022 23:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbiIHXeV (ORCPT ); Thu, 8 Sep 2022 19:34:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231321AbiIHXeA (ORCPT ); Thu, 8 Sep 2022 19:34:00 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9ED310D702 for ; Thu, 8 Sep 2022 16:31:40 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id k16-20020a635a50000000b0042986056df6so8604pgm.2 for ; Thu, 08 Sep 2022 16:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date; bh=JKmSonQmRzAcZ2JyL8gtNHIBqDCeLYTwlzg2gSIdvM0=; b=GUJlgXLHsr6D8omv7M3cD1H16BPrGusKkNgNtDezDYjBMZPmiFdjj+ZItVy3yoOCMO ajWuHPMCJqfchqiRHIC79a7ISuzd2WF7/9OCDsigF1DV2NiZFDjmbfrexbMOwJ+XqT0r J1rMrJZDU/r9fZQ1iICWEaZoP3zrAqfB72v2vMbiA7rPyeVfbrfdnJF+hB58Mf61IXQI KF+tLXBaKRtqy2fbeFMcyXL0ai/T8gtPQxxxuv7jYGGaN8uMXlSxGlpBlnqh1QcoQrOa IwwOg4eaEYso0GIZSFZz0JKd7frbq0hXwp29EYXByg20nGKKa6He/7u2dZoyMw9G1Ra3 lr1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date; bh=JKmSonQmRzAcZ2JyL8gtNHIBqDCeLYTwlzg2gSIdvM0=; b=W0Y5GcCM4BD/nPfqc0LKj47PikViYQT0rykoBMl+7dyzorlG6iVGqKYacpUqG1NjUE Jp2Fc1no0Q/Y+kB8jLJVIZq6tqAMvyk8HubqJ1DZkRoME9GHh+cxcS0zs3jTe0eSLnoQ cU429Sn2DENtBX6t7AyjibnyKg/weeJPIoXLBEqaqFSNdLlvMhR7pnT08aJuVKT4cRQb kaGD3yslWCcsrf7ldPXZDmLGb8RP1buLRRoKICyUUMOXqNbit1Acp8I9wxtYSBmCG/OA fcSUEvGebEgoydz/Wv7sUfiywz7SE2kIxpj6MHztB5KQx2XrrW3nEPMMWTd1blaIHG3h JIGA== X-Gm-Message-State: ACgBeo14O5gsbu+6OTHVVcXk2QGbsn9Z7rFMNXk2AEg8T/07Y4+h18jG yTX1fIzHDt5APStIjZCcG3EO9lmwm3w= X-Google-Smtp-Source: AA6agR595BqUn7XSJx8WoBTd5F0VJTT47Upv3fJDl++hnlnXKL88yujnE3ju9NbIO+chawyTNugQJ/vBy1Q= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:22c7:b0:539:efbb:a9f2 with SMTP id f7-20020a056a0022c700b00539efbba9f2mr11388082pfj.54.1662679899238; Thu, 08 Sep 2022 16:31:39 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 8 Sep 2022 23:31:29 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220908233134.3523339-1-seanjc@google.com> Subject: [PATCH 0/5] KVM: selftests: Fix "fix hypercall test" build errors From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jones , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After a toolchain upgrade (I think), the x86 fix_hypercall_test started throwing warnings due to -Werror=array-bounds rightly complaining that the test is generating an out-of-bounds array access. The "obvious" fix is to replace the memcpy() with a memcmp() and compare only the exact size of the hypercall instruction. That worked, until I fiddled with the code a bit more and suddenly the test started jumping into the weeds due to gcc generating a call to the external memcmp() through the PLT, which isn't supported in the selftests. To fix that mess, which has been a pitfall for quite some time, provide implementations of memcmp(), memcpy(), and memset() to effectively override the compiler built-ins. My thought is to start with the helpers that are most likely to be used in guest code, and then add more as needed. Tested on x86 and ARM, compile tested on RISC-V and s390. Full testing on RISC-V and s390 would be welcome, the seemingly benign addition of memxxx() helpers managed to break ARM due to gcc generating an infinite loop for memset() (see patch 1 for details). Sean Christopherson (5): KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest use KVM: selftests: Compare insn opcodes directly in fix_hypercall_test KVM: selftests: Remove unnecessary register shuffling in fix_hypercall_test KVM: selftests: Explicitly verify KVM doesn't patch hypercall if quirk==off KVM: selftests: Dedup subtests of fix_hypercall_test tools/testing/selftests/kvm/Makefile | 8 +- .../selftests/kvm/include/kvm_util_base.h | 10 ++ tools/testing/selftests/kvm/lib/kvm_string.c | 33 +++++ .../selftests/kvm/x86_64/fix_hypercall_test.c | 124 ++++++++---------- 4 files changed, 107 insertions(+), 68 deletions(-) create mode 100644 tools/testing/selftests/kvm/lib/kvm_string.c base-commit: 29250ba51bc1cbe8a87e923f76978b87c3247a8c -- 2.37.2.789.g6183377224-goog