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 66A91C6FA86 for ; Mon, 26 Sep 2022 23:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbiIZX1r (ORCPT ); Mon, 26 Sep 2022 19:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbiIZX1o (ORCPT ); Mon, 26 Sep 2022 19:27:44 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B059B6EF2A for ; Mon, 26 Sep 2022 16:27:42 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id y136so8185894pfb.3 for ; Mon, 26 Sep 2022 16:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=R4uQtEJE5e59CjrqKVswdXws/gcA7psIs8btH21+MPI=; b=GgFgwZi+ddAl59t5WyglkquklNhracaGBrF6jU0NtDfgG0IgyUN+puhncM4Se+w3hN 3ew+w2WAJPxrfTMHOqMoH5NrrG6IkW5+egKVHdTceHhmZygy1KIcyJjeClsgKVlkj5ex oneWUpdx17BO4/PyBE6g+cJ8tE6d/72orSPDJT/z2Dn5cNhJcTxeiz73K/6cipRmQmPg 5WSDE+Crbf2mdPFXkZYYQykqzOJxfF2M7gXPNUdqAk6rST36q6aTR2pVw3SdsdUcI5Zd 7j5360faOwyI019TWu9zwCPdBHpnL9pJ3m2PtS+Z9jLoDEfpk2kTstRnVY5XOIb1KKxO K6qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=R4uQtEJE5e59CjrqKVswdXws/gcA7psIs8btH21+MPI=; b=wF1wJFW714pLqmAQYGvwdeyxWGvRJfzEoETHRril5DZ9E/y2FDz89Ghf9Rb+rdedfa jDX2mmKqrr3C7+G8mQgkO/q+5WvmfCyn+khIQVMzn2lNiDyLahGWmvRSPtIRZtt/RxUX 0u7+j5GzjB12HMNkLRyt/99UMDxg6qZ4DupZgdqVYepGa8y9L2TQIQATMSLdtJa+aV2r cQXhFWzBcOhGbp/hJqX+84EB0V0IqdDUFkQML/iUxFPzUwLHhkYsUyHYBRu5K50R16wq ty8ubZgzISib1bP+U8DiAThBJUmtZkjQWfgYGYNjnpH3vUNsHypeaf5BpfvGNYKcW5mU 3rKg== X-Gm-Message-State: ACrzQf0fYwfdikinZMxEDjfPqwDjrqlmxcavUoRCmVb8gpabGftF6ZTC rWW/2oIpt2BlkqcMuNh6qMn4A5O/3g0mjE0oJuzx7g== X-Google-Smtp-Source: AMsMyM4Y0+nAEAfTHn3/Q+IPC10tZSPdNyafhAmVC2i9miBgZKk8ZEBtq5Y706fIgaHIfrIlYaLC0/EtPvVCFzYpGnY= X-Received: by 2002:a63:1a51:0:b0:43b:e496:f2f4 with SMTP id a17-20020a631a51000000b0043be496f2f4mr22517497pgm.99.1664234861996; Mon, 26 Sep 2022 16:27:41 -0700 (PDT) MIME-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> <20220915000448.1674802-5-vannapurve@google.com> In-Reply-To: From: Vishal Annapurve Date: Mon, 26 Sep 2022 16:27:31 -0700 Message-ID: Subject: Re: [V2 PATCH 4/8] KVM: selftests: x86: Precompute the result for is_{intel,amd}_cpu() To: David Matlack Cc: x86 , kvm list , LKML , linux-kselftest@vger.kernel.org, Paolo Bonzini , shuah , Ben Gardon , Sean Christopherson , Oliver Upton , peterx@redhat.com, Vitaly Kuznetsov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Sep 21, 2022 at 2:19 PM David Matlack wrote: > > On Thu, Sep 15, 2022 at 12:04:44AM +0000, Vishal Annapurve wrote: > > Cache the vendor CPU type in a global variable so that multiple calls > > to is_intel_cpu() do not need to re-execute CPUID. > > > > Add cpu vendor check in kvm_hypercall() so that it executes correct > > vmcall/vmmcall instruction when running on Intel/AMD hosts. This avoids > > exit to KVM which anyway tries to patch the instruction according to > > the cpu type. > > The commit shortlog makes no mention (nor even implies) that this commit > adds AMD support to kvm_hypercall(). Please break this commit up into 2. > One to precompute the result of is_{intel,amd}_cpu() and one to add AMD > support to kvm_hypercall(). > > If you really want to keep this as one commit (I don't know what the > benefit would be), please change the shortlog and commit message to > focus on the kvm_hypercall() change, as that is the real goal of this > commit. The precomputation is arguably and implementation detail. e.g. > is_amd_cpu is used by guest code within fix_hypercall_test.c, just caching the result will break the guest code execution. I have clubbed these two changes together in order to ensure that is_amd_cpu works fine for both host userspace and guest vm logic. > KVM: selftest: Add support for AMD to kvm_hypercall() > > Make it possible to use kvm_hypercall() on AMD by checking if running > on an AMD CPU and, if so, using vmmcall instead of vmcall. In order to > avoid executing CPUID in the guest on every call t kvm_hypercall() > (which would be slow), pre-compute the result of is_{intel,amd}_cpu() > as part of kvm_selftest_arch_init() and sync it into the guest > after loading the ELF image. > > But again, it'd be cleaner just to split it up. Caching the result of > is_{intel,amd}_cpu() is useful in its own right, independent of the > kvm_hypercall() change. > > > > > ... > > > > @@ -1314,8 +1321,10 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) > > > > void kvm_selftest_arch_init(void) > > { > > + is_cpu_amd = cpu_vendor_string_is("AuthenticAMD"); > > } > > > > void kvm_arch_post_vm_elf_load(struct kvm_vm *vm) > > { > > + sync_global_to_guest(vm, is_cpu_amd); > > } > > -- > > 2.37.2.789.g6183377224-goog > >