Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp939201lqo; Wed, 8 May 2024 22:52:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVjfI5AfLiljOsPHnUtrA359wBIJfVJUiC6ZRIrs5WQOXtGMSwuHugmv6jBygqdnvTjiR6s0HHk9cip4Tk6EvQeATIEDJUCSs1krbUdXQ== X-Google-Smtp-Source: AGHT+IEr6Dxjgg/LwxCrUFrFLVSNjwbT5wOa6K2d6EHGp5DCGA92VeRV++J9nRjFdNU6I7fhkxti X-Received: by 2002:a05:620a:4150:b0:792:9d4c:6431 with SMTP id af79cd13be357-792b285bd91mr563915185a.56.1715233971364; Wed, 08 May 2024 22:52:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715233971; cv=pass; d=google.com; s=arc-20160816; b=iKkBGF0mMnpG5AWMfIMqK7tvdwOcTjnjhiq2lHXnJ0apKHEQpWrThKvHEHdf5t+f8P /UVKiunfwszAuhE0NQP+HNPO5CNHUQsIIzcwAnWjlYdV1FqdDSl/+KuyWK02xIKXJjwz cCTfayEi/w4sqlxJfhL+nFJQSkD71oLoAff4aC8HXM3RKzDHjGHYtJYtwB19UvNIPx3G TCtK6r8V53iNbp+Mtc6k+oi7z/aRoQbMUZcxOQqrwh2jHqLvV0f+ThKAl3HvSsQjnbzy TwJs3g7NsqKbREziyHPKt5Da1jgX+ge5OLlRZaWe6IX+c4HTjWlC5VJysJMCNUH5h0mJ QChg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=0aNaBtO3wymE0miS3fDK/VipspfzyvvyrZJX2CAiv10=; fh=axVZgUd/khiJrBbFv0Pz79iaKsOdXUjSRKQnB7ejtQ0=; b=To1UT9c5oNujCTNfYp7BWFwJ5CRMu9VA2bwqEcCJJWTMmrSpUtNtB/NiSUaQegzgD1 YZcdzc26IvSUT8puV3D/z6rMcwMToGHQCpaFpOWGEjM18dfeQ7A9lIHSoDGSlKlHamBy GVp7JuUp1G8pMkrx/IuIUd42IxQwUvH6QVpWO13LAxdYHP8mj/1nvJ1y0P2aqA1EKdcb 6UCDyg36C8QmtWNHcY5FjM4nUrcRKvq6pV7e2ZyD4RGjap+Fy65hr23wushN6VUOCZa+ 1QGYWLf8p2kMwTpfm8TcmmFMRqYrT2fOZVSevpDCvT2bzSnHxSymYIkFhwkbpaniE7JS Z02g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="M3j9/MRu"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-174090-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174090-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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-792bf30a8f9si60925685a.262.2024.05.08.22.52.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 22:52:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174090-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=@intel.com header.s=Intel header.b="M3j9/MRu"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-174090-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174090-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 1C35F1C21D15 for ; Thu, 9 May 2024 03:26:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C8451482FF; Thu, 9 May 2024 03:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="M3j9/MRu" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DCEB13B5A9; Thu, 9 May 2024 03:26:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715225182; cv=none; b=af5fn/QNMwDjLpnCyjZ/MUFBZAAyv0JcH4KR/A0h7rVixy7sbmiLW7NMwUw2zKL+Ii6az1Cmiv6ocT4V+m1Hbc4Ljti4/3pHCmMof/vpMKUrcwRF0Gm6b7WFr+EXA2/oazFtqz3AkAL2gAP+9RlLgXSWtdIavTrYrVJ49icK17g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715225182; c=relaxed/simple; bh=lzuT4z6a9h6QUPjj6mXTlc70SHZOnKy2AEOR8TPJIso=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EXLuAnHbClSC6NfFQya1cH3exCMI7AwPbCy3pmS5hhliOCVkPE06sNaIyLDyU9IZhfP25fUScJVN5cKASiiSU6sMAbVcDMJI3TJn1ncSpnZ61qItZ6cbso2jmCFYios8Yp+hWCylXyfDUbRZ3SvDqKKkfBqm+2V4Fa+G8y2a7hc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=M3j9/MRu; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715225180; x=1746761180; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=lzuT4z6a9h6QUPjj6mXTlc70SHZOnKy2AEOR8TPJIso=; b=M3j9/MRu06rtoH3nMjaIElw7To0nl9/01HE+3aB9Eo1DQb2TkIRGInM3 BnNELu8pm/v2mozaQ74CieDxtYFzz8N4WUx+QCmi8IPAAJktPL4HwED9H dw9ouUlLvYjngsi+ytAGDmBU5QgWpJmocHPUmPBUzRwIFC43QFsTRF3oX ytvYxZaE8dNRE+cs3l74I78ejgwtK850rRu+OmmHQIff6YHRdWO1LHfBC b8b+63Z0WPDG8kCJKoSrv2v7vFt/oYxXJiQSqFI+37DHuMcVYOAvBtTFB 2gX7v5vxV9Hm+JSG+oGMWZAcp2dxg8w/IsrSfTrtKM+YZlEyq9cdEMjxU g==; X-CSE-ConnectionGUID: xLG4SS6ZSEy0KWQqoDILeg== X-CSE-MsgGUID: qGuxJexHRZC6VzV2g24WsQ== X-IronPort-AV: E=McAfee;i="6600,9927,11067"; a="36502860" X-IronPort-AV: E=Sophos;i="6.08,146,1712646000"; d="scan'208";a="36502860" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 20:26:20 -0700 X-CSE-ConnectionGUID: ydmmEwPyQh6tgRLtlGYBYg== X-CSE-MsgGUID: 9imKpPHkRZ6p62ZLMDK67Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,146,1712646000"; d="scan'208";a="66533744" Received: from unknown (HELO [10.238.8.173]) ([10.238.8.173]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 20:26:16 -0700 Message-ID: Date: Thu, 9 May 2024 11:26:13 +0800 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 v19 097/130] KVM: x86: Split core of hypercall emulation to helper function To: Isaku Yamahata , Chao Gao Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson , isaku.yamahata@linux.intel.com References: <20240403183420.GI2444378@ls.amr.corp.intel.com> From: Binbin Wu In-Reply-To: <20240403183420.GI2444378@ls.amr.corp.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 4/4/2024 2:34 AM, Isaku Yamahata wrote: > On Fri, Mar 29, 2024 at 11:24:55AM +0800, > Chao Gao wrote: > >> On Mon, Feb 26, 2024 at 12:26:39AM -0800, isaku.yamahata@intel.com wrote: >>> + >>> +int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) >>> +{ >>> + unsigned long nr, a0, a1, a2, a3, ret; >>> + int op_64_bit; >>> + int cpl; >>> + >>> + if (kvm_xen_hypercall_enabled(vcpu->kvm)) >>> + return kvm_xen_hypercall(vcpu); >>> + >>> + if (kvm_hv_hypercall_enabled(vcpu)) >>> + return kvm_hv_hypercall(vcpu); >>> + >>> + nr = kvm_rax_read(vcpu); >>> + a0 = kvm_rbx_read(vcpu); >>> + a1 = kvm_rcx_read(vcpu); >>> + a2 = kvm_rdx_read(vcpu); >>> + a3 = kvm_rsi_read(vcpu); >>> + op_64_bit = is_64_bit_hypercall(vcpu); >>> + cpl = static_call(kvm_x86_get_cpl)(vcpu); >>> + >>> + ret = __kvm_emulate_hypercall(vcpu, nr, a0, a1, a2, a3, op_64_bit, cpl); >>> + if (nr == KVM_HC_MAP_GPA_RANGE && !ret) >>> + /* MAP_GPA tosses the request to the user space. */ >> no need to check what the request is. Just checking the return value will suffice. > This is needed to avoid updating rax etc. KVM_HC_MAP_GPA_RANGE is only an > exception to go to the user space. This check is a bit weird, but I couldn't > find a good way. To be generic, I think we can use "vcpu->kvm->arch.hypercall_exit_enabled & (1 << nr)" to check if it needs to exit to userspace. i.e., +       ... +       ret = __kvm_emulate_hypercall(vcpu, nr, a0, a1, a2, a3, op_64_bit, cpl); +       if (!ret && (vcpu->kvm->arch.hypercall_exit_enabled & (1 << nr))) +               /* The hypercall is requested to exit to userspace. */ +               return 0; > >>> + return 0; >>> + >>> if (!op_64_bit) >>> ret = (u32)ret; >>> kvm_rax_write(vcpu, ret); >>> >>> - ++vcpu->stat.hypercalls; >>> return kvm_skip_emulated_instruction(vcpu); >>> } >>> EXPORT_SYMBOL_GPL(kvm_emulate_hypercall); >>> -- >>> 2.25.1 >>> >>>