Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp822902lqt; Thu, 6 Jun 2024 22:18:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVB5mkkxWyDVKFjKoh4nDi4cKNQxb3UliHsvgatIC9+BRyZ9MwDQlSzRR2BlexAr3UAmu8cIYmK5DNPpLL/UGt1KHJPiD5+PKQ014Dw+A== X-Google-Smtp-Source: AGHT+IFste2LpQhYvahfjY19kM6rJj8jU136sAdA5xK+vqsYFjsgzEQLQQYli20vyq27bSKWi1sp X-Received: by 2002:a05:620a:2446:b0:792:baa3:fb3c with SMTP id af79cd13be357-7953c4417abmr180695285a.42.1717737498669; Thu, 06 Jun 2024 22:18:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717737498; cv=pass; d=google.com; s=arc-20160816; b=WbsuDKJt5mEmu9dVvAn1L1fm/PSjoxSL8BAHZ8fJ8ZutwQRnjU2Q+WZsZyfhyoHtcs WqPWx+JtTYDJqyYVXroaRYgPXpUrR6zOS4Hcfc8sUTLq6/YaBlfHXJ+dc4Q19wwAGtDx 7dtwxy22cZlX7cNq11TlX/u+HNfRbvX3NYWYEwKxPpcLy0d4F0KeD6lWA7FxNncv0ygN nNQpnyvfYhh/iSW4kubkSG7vlHcujPJ7A5Zf+YHuoJ19Jkp5RjU4f2jBbOsb6V7sT7Rh 2bnjO53qlsJ4hRiV2vFxKUf5t8JGKEU4yKtz1/0vBl6UJl31UkM2aIZFWjsjC+EXae1w Q7Xw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=B5W2Nv+UImujN12YJ4otFyCpCSzcEj5c4HLiL4+sD5Y=; fh=ZBKRUoX8UR6NDDrN2fI/3jvm7S/No/QIkR1AcJSnkYI=; b=bGNMjb/vBHA+a/2Ou9q89lRzLHoFFHVxbxEYhUXX/yFfs6alkVq7faKNylDiNHSzOl gfsYg+DwozzqmovmAmdxmkcWZIcuyG1/Jb3MaejBB/u46GHBAaUmtVJjUIRx6hd3XIXv U0g5ACmY95aU0nxPhoVW48gAu9RtnX/+UgobYGLT7rjFeLQpgRmXmBbMMRokzbxSs2Yh EllqCf9wgvmbn1XAo9e105j3lNgIX9AhdErnBfobSGDqi1wo3fAdq1CF61iCKrX7l7zE eFVeL4UGYoyGWezRBt8patX/e0hcpvv9Km54mQ+fvG7muKlZoGy4jUUQGOJ2dn2yOcEW ljSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=ZvbUn5j6; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-205147-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205147-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-795331cac81si40051185a.293.2024.06.06.22.18.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 22:18:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205147-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=ZvbUn5j6; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-205147-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205147-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 03B271C23A73 for ; Thu, 6 Jun 2024 23:19:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98BA013E41A; Thu, 6 Jun 2024 23:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="ZvbUn5j6" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 353074E1D6 for ; Thu, 6 Jun 2024 23:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717715945; cv=none; b=nvphEzFI5s09HAr+w2au5u1Rv5HiKROialM9QHEJauzHWbgpQPh+seOHbsXL0wVVtHih+oecvIh7EKktGJgx9rIEoXdxIKwNsyLBKJ5eqc5abYDYgjrOSRy2+eyFtIA4p+xRH6JdH83IKGcxAFkvGCL5o4vKiQLk/FbA2+UDW+Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717715945; c=relaxed/simple; bh=KopYV/PxRKfVKnIeeW/2XvxTVqfdsZhYvuOqTaBPIlY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dSis1b3nnwJDzfdb+Oi8ya8+E4v1xcm4iRt6Gb7ZNx+2tKD8WBJicMlcBH0uzk67jUZ68jPbJ/NSonLhjdYomld9pzaA42ORsiYK5e/37DLi/csfDjKIboyQU0U+ezA69/F+WklmkpjG+VulGeHivsDpqaqUKZwwfFBhwvkYvOo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=ZvbUn5j6; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f480624d0fso13949455ad.1 for ; Thu, 06 Jun 2024 16:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1717715943; x=1718320743; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=B5W2Nv+UImujN12YJ4otFyCpCSzcEj5c4HLiL4+sD5Y=; b=ZvbUn5j6+tXpyHhAqH4vrsela0/Z3Ak9a7fLNVO4ZTE4Neh2ui0HeI0BtCsZUFyD5G hAhs4BhyMmCy9D8+oWouADYSUhG2FO9s50I8JqgO9n0JBPy4UKauot94Tw+4+2gcU5lb ONnaxACTaZk9xgLkm2l8YJQQ1OHT8ScMNHFLY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717715943; x=1718320743; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=B5W2Nv+UImujN12YJ4otFyCpCSzcEj5c4HLiL4+sD5Y=; b=SMlojllQ3AmvDACf2BSLliILki8188XpubblrA/9exCkIH3e2mOqbjULKJS0sfWaHA /wa1nxmbqji1v8ty08361gpIn38hBq5JXSgYE4U+rlB7v5Pn0x6+ge5PJ6hlVB3R+IaG WxIUSCDv3M6FZRKYRPH5HjGOJgx9ASjAyTR1vXl/peK2uF83/hcNWt22dILb3Zf7PZcp Vp85SoJt81maq6Za3V7IFokfXAwOLsAMia2UjzSvhO6rrHB4heOdzozeyollBMrIpNrQ 8WTQE8zEpXT2pWSPmjyrl6V10uOOUFXnp6aI/VJSzkcgVDVCYnJQ+Xbhsj7lre4tS92f 8BpA== X-Gm-Message-State: AOJu0Yz6xtESDAuGJQln9si5PpGFvupPoE35Bg/VgGCiGg/9DKbgeiKi Plo7ukcNjrlt1tiMeQ2qQPJnVcRTDoy+Kbo3fqSSqRQFg4zlZsZ2Y09Py8L19A== X-Received: by 2002:a17:903:2407:b0:1f6:6c74:e5c1 with SMTP id d9443c01a7336-1f6d02c0e82mr14328785ad.4.1717715943397; Thu, 06 Jun 2024 16:19:03 -0700 (PDT) Received: from [10.66.192.68] ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd76d20asm20950295ad.93.2024.06.06.16.18.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Jun 2024 16:19:03 -0700 (PDT) Message-ID: <3d6ec46c-53c2-4a13-90ff-eb419863c1d5@broadcom.com> Date: Thu, 6 Jun 2024 16:18:57 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 1/8] x86/vmware: Introduce VMware hypercall API To: Borislav Petkov Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de, x86@kernel.org, netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, zackr@vmware.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, timothym@vmware.com, akaher@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com, horms@kernel.org, kirill.shutemov@linux.intel.com References: <20240523191446.54695-1-alexey.makhalov@broadcom.com> <20240523191446.54695-2-alexey.makhalov@broadcom.com> <20240527170734.GCZlS91uXD68HRN1na@fat_crate.local> <9ca6230c-740c-4f1a-8fdf-73f74cf025a1@broadcom.com> <20240603175844.GKZl4EVGUxp2aQZnYJ@fat_crate.local> Content-Language: en-US From: Alexey Makhalov Autocrypt: addr=alexey.makhalov@broadcom.com; keydata= xsFNBGVo9lkBEACeouRIm6Q3QTvjcnPczfBqgLffURstVJz5nqjnrNR4T+8dwNrZB8PTgOWA QdGV4bIyqtNG7UHQuZ7sVKr2tx0gYJyQ5uZgncEHB5YIuhQ/CyAHrVmO+5/0/xWCLI0g44rF ZJqsYw2JQ2+vayTWbR65rkOiKL8GOVFNZanDg80BRh6qCmCEMXd/tymxvgnvWpHtxMgukexk 4vV9nV4XhxRVYdpLk8mBxsh+AEbHE+nbWgIuJDrmrZDGI2Dha7JFoB0Mi6hbbYd9BdkcHKQ7 6c+S1xOrZL3jX7OIFhb4NNnEOhh8/+BDlyby478p6YsimNa7TgAUbrygGyfVG8usrZy8SvO+ vUbVQwqjcJaCK1xazK12dfuZm2kSMJUrJqa9ng6OMjkE2/WrtnK8ruFNSCdytzbuheT0nYUJ Uwy84cU4p2K/N2C4vYjcn+IT+l1BFr5FViKYruoRLVH6zK/WOoZjA+Fc6tdM5nC1pgSB9c7h XLQqDSzYPzk3nqeHWG1qJ0Hu7pscIrjxyNTIZ5le0TlpblJdoRcL5maDNw22yle8m4D18ERF VrqNoqwW8fObMCHb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Qp8HbVxGNo7 AlDn1qtoHzvJHSQG51tbXWfLIi1ek3tpwJWj08+Zo+M47X6B65g7wdrwCiiFfclhXhI1eJNy fqqZgi3rxgu4sc5lmR846emZ/Tx85/nizqWCv7xUBxQwmhRPZRW+37vS2OLpyrTtBj3/tEM9 m9GMmTZqaJFeK7WCpprJV4jNHpWZuNAsQrdK1MrceIxb0/6wYe0xK79lScxms+zs9pGTrO4U 5RoS4gXK65ECcBH8/mumV6oBmLrNxKUrzTczdo9PnkmRyZcAa6AndbjmQDznwxvTZu2LjMPC EuY0 In-Reply-To: <20240603175844.GKZl4EVGUxp2aQZnYJ@fat_crate.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/3/24 10:58 AM, Borislav Petkov wrote: > On Wed, May 29, 2024 at 05:44:32PM -0700, Alexey Makhalov wrote: >> While most of the vmware_hypercall callers are executed after alternative >> patching applied, there are small amount of hypercalls running before that. >> Only for them we have the logic of analyzing vmware_hypercall_mode as a >> default alternative code. And there are 2 constraints: >> 1. vmcall/vmmcall are not supported by old ESXi/Workstation/Fusion. We have >> to use in/out instructions. After the end of support of old hypervisors the >> alternative can be simplified as follow: >> ALTERNATIVE("vmcall", "vmmcall", X86_FEATURE_VMW_VMMCALL); >> 2. SEV-ES enabled VMs should use _only_ vmcall/vmmcall as in/out >> instructions cause faults. >> >> Another approach that we discussed internally was to use >> ALTERNATIVE_2("movw %[port], %%dx; "inl (%%dx), %%eax", "vmcall", >> X86_FEATURE_VMW_VMCALL, "vmmcall", X86_FEATURE_VMW_VMMCALL) for >> vmware_hypercallX family of functions, _and_ to have a separate API >> vmware_sev_hypercallX, with the silly dance without an alternative inside, >> to be used only by early boot code, before alternative application. But, >> it's error prone when things come to boot time related code movements or >> rearrangements as it puts additional requirement for SEV-ES >> understanding/testing for VMware guests. > > Right, so since we're exporting that alternatives_patched thing already, > you might also try to do: > > if (unlikely(!alternatives_patched)) > return slow_hypercall_X_in_c(); > > asm_inline volatile(VMWARE_HYPERCALL... > > where that slow_hypercall_X_in_c()* set of APIs does the checks in C. > > And the VMWARE_HYPERCALL thing is a lot simpler then. > > All in all, you'll have a lot less unreadable asm to pay attention to > and those APIs should be all easy and readable. > Thanks for the idea. I improved the condition to eliminate slow path for modules such as vmmouse, vmwgfx. if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) return vmware_hypercall_slow(...); It also drops the need for exporting vmware_hypercall_mode or vmware_hypercall_slow symbols. Will post just Patch0001 for review here before sending v11 out.