From patchwork Wed Jan 11 00:44:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 3838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3050136wrt; Tue, 10 Jan 2023 16:49:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXtCkqPDrwLkisitbOG6/xapkjqug9yluINm/RjGzAuNaDo1UltURu98RWNDNW/RmG/XrVus X-Received: by 2002:a17:90a:ea86:b0:228:cbe0:bee5 with SMTP id h6-20020a17090aea8600b00228cbe0bee5mr4758476pjz.32.1673398198217; Tue, 10 Jan 2023 16:49:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673398198; cv=none; d=google.com; s=arc-20160816; b=thYpAS4lgTflHbaQ04ss6/acnfx7EDDCi0c6OEXXbLkPWcVkgctj72s/j0c1p5pEl3 Zirxg1LslskimrQCpbASRfu7hjymch7Vul24M6ME7aruoqkSTd3V6FQ6csZOpx/dONKS YxpfJdfSuQaNof4uHm9xjzaQkOgOkKOvOYw+QHxJTS75y9nuV23NNu2mEEfFrN7XFeHw v2d1NBNU4c0m+uEG0c2zjWrsaHUJRzSzqq4OG967qk0uOAGkKugu0LTSYtPfpaNKWgs5 VcOyVmLMNUeQzhlHEkxT9h4JHCVx+n1Q91ChVPqy9LyewkUF3ohw6gJtonL213jZrLBK YAUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=ibE48hPASiaydGO50HigqaPix7Fk3GewkWKsH3rEx8o=; b=LMY2ECgL94ACHBqJPLHQX7BNoZI2bPbUiwhNmLEYuoVIz7LsHLuy1Kmuxz90SPbrvF 1SlRDt+zSlXM3rSckCTfIky81z3Q2GPqNUeyQqlMIV7/P3nEU8yuP++gjXigKMZ/AR8U HUgTxiLo4uaZOszZsx6SKM/5AvESB4yYecpy0CcwtSuVM1ahfuynOEaNidJudcOe3vVA +HMkh93A9zsfUAe9LT1TrI9saJhxOrXz6Zl0y8rvzWscEAKjnAk1cfTNLk1K1f4E5ths Pr7TOgNkUDZECByCtkhWtr0YmMYamx5xvzIMqgxHQS85m67SGiQdzU8oElM/eQmWIgtZ ZhMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QDMREWCk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob5-20020a17090b390500b002194574db1csi18642728pjb.142.2023.01.10.16.49.46; Tue, 10 Jan 2023 16:49:58 -0800 (PST) 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=@google.com header.s=20210112 header.b=QDMREWCk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235737AbjAKApK (ORCPT + 99 others); Tue, 10 Jan 2023 19:45:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235691AbjAKApE (ORCPT ); Tue, 10 Jan 2023 19:45:04 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CF935933A for ; Tue, 10 Jan 2023 16:45:02 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4d4b54d0731so15854947b3.18 for ; Tue, 10 Jan 2023 16:45:02 -0800 (PST) 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:from:to:cc:subject :date:message-id:reply-to; bh=ibE48hPASiaydGO50HigqaPix7Fk3GewkWKsH3rEx8o=; b=QDMREWCkJW7xwXSdwyB+jy0Hy0ipF0VIiK4k8kJDtxq6zgowXQk/i6IjWKL6ha9eeM DWfA0Ozh3fxTNwO7PyKRchI1VCSMDQdUvbY3qk0Jd/SHc7YhFQyiQtTy8hJ8kKpU9fbk UEzGzch7+uPo/8/Yog51+NlZbO1J9sat3igfRISSaIPPwbu7pWEkTQyxfuSFV19nuyKW xOqVLLufpTspm/t+e5Fy4BQT7ZKxN1KNLwlJJHqDkSwgxj4ItZne6csXl3BPvnFZYQM1 PmAnTJSQ3TuvKqJ9fY8Sxe6KusmVjjUWnDOAQ+BHaN6uX/zpdE+Yg6Sq8/8NmNW9jj/K MEzA== 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:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ibE48hPASiaydGO50HigqaPix7Fk3GewkWKsH3rEx8o=; b=3x5xUGaEdySlEwSonVX6ux1PlidB/2AHCJHVwYtxvI79ZwwbBUiDrV6+1OKxzazSWH hlvZQfBKPLUT7FrltLqnjJArftocPtPmL6NZJy96pYzEqb2JfYCHT9N7mtmUVKaSMX4A UDLUxg+XcnEDSLKV9dAcQk638tpatGg1lMpmwLdrF0XPaMffD57Fw1Z9u44cz4qA5M6U BjZf7lklRJ5MHjQwdYqCjs+c6WD/+v2qAhd+2uwiipf2wq4jzkw0DkCuPbqDZRrHaHc/ /61dfbICDt5S98+yNEnvpJt10xV6cBLkG+JyTZjLFzDyxIuTjcQO5Qbs3acYUve2ghVb J5kA== X-Gm-Message-State: AFqh2koIkUwIHWoW0QdDT+tfb2x/XoXwE4F2/jcPQMD1YWyg3V6KVDBi Glahrb2EHnaBgz7xGAXtOUmWh5mmY7Dt1fZb X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a25:2e0e:0:b0:7bf:e2b8:af73 with SMTP id u14-20020a252e0e000000b007bfe2b8af73mr805623ybu.98.1673397901764; Tue, 10 Jan 2023 16:45:01 -0800 (PST) Date: Wed, 11 Jan 2023 00:44:42 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111004445.416840-1-vannapurve@google.com> Subject: [V5 PATCH 0/3] Execute hypercalls according to host cpu From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, pgonda@google.com, andrew.jones@linux.dev, Vishal Annapurve X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754685188875064314?= X-GMAIL-MSGID: =?utf-8?q?1754685188875064314?= Confidential VMs(CVMs) need to execute hypercall instruction as per the CPU type. Normally KVM emulates the vmcall/vmmcall instruction by patching the guest code at runtime. Such a guest memory manipulation by KVM is not allowed with CVMs and is also undesirable in general. This series adds support of executing hypercall as per the host cpu vendor. CPU vendor is queried early during selftest setup and guest setup to be reused later. Changes in v5: 1) Incorporated suggestions from Sean - * Rename the APIs to have "this_cpu*" prefix to better convey the intent of callers to query cpu vendor of the current cpu * Squash patches together to cache, share cpu vendor type and replace current callers of "this_cpu*" with checking the saved host cpu vendor in a single patch. Changes in v4: 1) Incoporated suggestions from Sean - * Added APIs to query host cpu type * Shared the host cpu type with guests to avoid querying the cpu type again * Modified kvm_hypercall to execute vmcall/vmmcall according to host cpu type. 2) Dropped the separate API for kvm_hypercall. v4: https://lore.kernel.org/lkml/20221228192438.2835203-1-vannapurve@google.com/ Vishal Annapurve (3): KVM: selftests: x86: Use "this_cpu" prefix for cpu vendor queries KVM: selftests: x86: Cache host CPU vendor (AMD vs. Intel) KVM: selftests: x86: Use host's native hypercall instruction in kvm_hypercall() .../selftests/kvm/include/x86_64/processor.h | 28 +++++++++-- .../selftests/kvm/lib/x86_64/processor.c | 46 ++++++++----------- .../selftests/kvm/x86_64/fix_hypercall_test.c | 4 +- .../selftests/kvm/x86_64/mmio_warning_test.c | 2 +- .../kvm/x86_64/pmu_event_filter_test.c | 4 +- .../vmx_exception_with_invalid_guest_state.c | 2 +- 6 files changed, 51 insertions(+), 35 deletions(-)