Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2920665lqz; Wed, 3 Apr 2024 12:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWvepPfGw7fSHjwAi+cXSwNwEvWTM/wslchT0qvKpexPFYt5WoRhVUC7+9sR6vaAuhu4cCIqMh7alMYFeHYP6mdqNSDBWvgp1pgsu89+Q== X-Google-Smtp-Source: AGHT+IHTJwAoRy3zhHa3EqAVADsyJM+EluDwuGNnz0z3JYrQ/kJ6ClmbD50ag3F/9JaX/dHq1B6A X-Received: by 2002:a05:6a20:7f96:b0:1a3:dc33:2e47 with SMTP id d22-20020a056a207f9600b001a3dc332e47mr757131pzj.4.1712172111902; Wed, 03 Apr 2024 12:21:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712172111; cv=pass; d=google.com; s=arc-20160816; b=N0nm08zP3vqwCJ3dpscCzsp1ZNkzlX6Q7g+F/R9ySlt7kV1f1C5fgqL6EbZk1VFF0/ Rash6MMsMCR13XepZBlq5dgcW8vXNjWpU3RsZboTHSeInRC8T99aoQh9+DUR4/5MDZTA 0b0eqrbcvfpGmKbhL9ltdvh96ewHImC5lAoebK29GrsLR3aBjXGccLAIGDKLkf0L9jXO 7y96WFVLTPf5tPSSlyjZBGLZn/i1EjSLrwYn3QAssSzum9nqBvfmD+NYt//yVhTmn57W NkvUM+m3W9TDmtuwI1JJV4B4Yk4lm1EwvnQfTTtx9gTkExmWOCsT+pLWBLBwmnoFtdzY z+HA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=Kzq7wE2LZl4SFXr3lgccRsGuVgsB6ehLKZYX2fNnhEI=; fh=+IIHimFCSiJnCL7HXQzWR7zvDe7tNuC3GDq5m0VXu/o=; b=coZKxm6uyF9nLCVuSs69/VH4U+Jxb3Rfg3mdCClrhX/0o7/AEcKlCImzynznecNM0m GXvq60c+W6HNTokQ6fe0FZd3NzaZ8rccnqDw7dITmzSKVny7KQLkei3xHwFbMJCcFmnQ RFIji0eP3oW2BWzX3N50rGH1VG5ZB2yBqfbBM9G+GEnXHnZBMyBAKT2SELyxwY2rIv5V TDcVE2DmGf5sP+m60sxD9NdlpMEmsuEB6VBeSniEUENkFIKQ13q+WHWo7AyinpjVnMki pLiRN8+RmJSs1frhBCzwzSICacaFwbqVNmxacx+nG1jLTLBiCmjcx+JfhUjTd2xMsVPr bqUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gjKQJ0Hb; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-130477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bx33-20020a056a02052100b005c67029a131si15050860pgb.220.2024.04.03.12.21.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 12:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gjKQJ0Hb; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-130477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9533CB27288 for ; Wed, 3 Apr 2024 18:55:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B5A4154BE8; Wed, 3 Apr 2024 18:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gjKQJ0Hb" Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 15D4E2F24 for ; Wed, 3 Apr 2024 18:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712170533; cv=none; b=tUlzf2ronvt16ll0TY16URojv6ztgmF7ZyhWMhh62oPLJSiMJzHuBXdDMcvMpEfviO+URI//uYkWHoTuVDb4f1j5dIzxLZ8Vr5thNl3YaRAu9IDSiyBHOEKCaa9aBCXbIC2nwu3jx0lg4mcJKQgIPok37kYS3zAk5am3HRF0gJ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712170533; c=relaxed/simple; bh=7XDPcjGhh21TD94uSUZErS3ioNLCHjs+I9ktpoDyyz4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z977rOD2v53Md57V4TdODroAf0ID836Gh1oQjUTk0gWkNKWHESr3p2ujo2vtre8SfNtUX4Yu6Y1hUIroqwyzAStQOFyJkSPlCymP0tFDnDSQMd3APMxb7HxjZDyaspPBGSGNKYv9ArzvwU0mrWa8LlwmgLfkmtplm+yj0DTN1zk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gjKQJ0Hb; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2a240c417d9so77597a91.3 for ; Wed, 03 Apr 2024 11:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712170531; x=1712775331; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Kzq7wE2LZl4SFXr3lgccRsGuVgsB6ehLKZYX2fNnhEI=; b=gjKQJ0HbCDHax4O0JbMqWZRRcq+C7V+QCHjNkc8TQ6zECYzyMavV94nNDvdAVKaCEM gUvqmN/N87eNwrXdvy45FhoyD9VV/8E7c18I/8gGB112Kk6FC1HoJQxgvh475fqcjFvm YlJH/pw2gHLN8NsPLZI49/LxXacdo9l8tj8Ew9AwO54NpmmwOLRJ4MiUb3t/4txb2kyl AnUpVvjnfB7n1uxqz2ZLM6tvR/m/VmvDmYgn08EPg+ZVTvY/hmYBJ/OqL/GelhkiS/IS lkWQaRs9VokXjUfAZfTpmGfCZ/Pu2CY+o81vJVdu5MIemdmh9cA9/oFL1rsMpWZ47E00 uPEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712170531; x=1712775331; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kzq7wE2LZl4SFXr3lgccRsGuVgsB6ehLKZYX2fNnhEI=; b=aypapTdzP1CU+5IaG0ZPS/sDUu4UREhuBNEBY70LiCQfX7i1+KBSj2zQ27LDM1fl46 ASRacuTunXfo/6H9kiC9+FqxRJb2jf6lMopPCh2sTJJVZkmZCiKCoYeRFW5AzXVbf8Ub qoeVvJSMlj0eYlfh9AUtynsoWkEV0mS8WqydO5Xp2MxMdl1bmpCCzOndMYE+DzuqElmw 4OmRzB8fZcPagx0fLjwFrC+4DZDxJDldIoecWJcJ+N2sTSCbiE5c/ECM0RYVa97hq+O0 +R1Kova7wvMuOuMceYZI/qSI9MYWx8mctWXWJWsW0/jQ719KsTTxKnFtgQ6Y2tMvQ4AR E9eQ== X-Forwarded-Encrypted: i=1; AJvYcCWXXp1IihQA3mfs8zZ7P2DBcczwgRFivFqtyPvAA66Sso223LJtihuQNt6NpYXYYTykxYgIeQ8IFG1BxH8kbV+gVJBZ6HVkRM63bgFe X-Gm-Message-State: AOJu0YzqLb431hAmAJRtkMwixPbIQqzVSB6YanBtLNp8/yokA1rg8Msa nObJvUPnVhBm7NxSjemNN/iEjn8balvmVeX1RpWhb2BUFo4kzne9vu/GX/ijpVvILVj+sEUnC3m pig== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:de01:b0:29b:c2b7:7d29 with SMTP id m1-20020a17090ade0100b0029bc2b77d29mr1023pjv.9.1712170531325; Wed, 03 Apr 2024 11:55:31 -0700 (PDT) Date: Wed, 3 Apr 2024 11:55:30 -0700 In-Reply-To: <20240403183420.GI2444378@ls.amr.corp.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240403183420.GI2444378@ls.amr.corp.intel.com> Message-ID: Subject: Re: [PATCH v19 097/130] KVM: x86: Split core of hypercall emulation to helper function From: Sean Christopherson To: Isaku Yamahata Cc: Chao Gao , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson , isaku.yamahata@linux.intel.com Content-Type: text/plain; charset="us-ascii" On Wed, Apr 03, 2024, 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: > > >@@ -10162,18 +10151,49 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > > > > > > WARN_ON_ONCE(vcpu->run->hypercall.flags & KVM_EXIT_HYPERCALL_MBZ); > > > vcpu->arch.complete_userspace_io = complete_hypercall_exit; > > >+ /* stat is incremented on completion. */ > > > > Perhaps we could use a distinct return value to signal that the request is redirected > > to userspace. This way, more cases can be supported, e.g., accesses to MTRR > > MSRs, requests to service TDs, etc. And then ... > > The convention here is the one for exit_handler vcpu_enter_guest() already uses. > If we introduce something like KVM_VCPU_CONTINUE=1, KVM_VCPU_EXIT_TO_USER=0, it > will touch many places. So if we will (I'm not sure it's worthwhile), the > cleanup should be done as independently. Yeah, this is far from the first time that someone has complained about KVM's awful 1/0 return magic. And every time we've looked at it, we've come to the conclusion that it's not worth the churn/risk. And if we really need to further overload the return value, we can, e.g. KVM already does this for MSR accesses: /* * Internal error codes that are used to indicate that MSR emulation encountered * an error that should result in #GP in the guest, unless userspace * handles it. */ #define KVM_MSR_RET_INVALID 2 /* in-kernel MSR emulation #GP condition */ #define KVM_MSR_RET_FILTERED 3 /* #GP due to userspace MSR filter */