Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp135803ybx; Wed, 6 Nov 2019 14:28:37 -0800 (PST) X-Google-Smtp-Source: APXvYqxo+CkX6yn9Gs3j7XVJ8O/caQ9ovzcyo5VR8uD2o2bgKXtUn7slt3Zl+qSy3gMhnTS8FEki X-Received: by 2002:a05:6402:19:: with SMTP id d25mr138088edu.186.1573079317482; Wed, 06 Nov 2019 14:28:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573079317; cv=none; d=google.com; s=arc-20160816; b=cGxukvB7GPCrIC61+ShBimI/2co8fqfLaRZ9RFk92UY/EkXnSf5zfmYUAGzX7OKcd2 dkJFYKdQhwJWRdriJxa6OVq6L8ncyPfRPhC3p7u2394QUAenSKRkACyYi5xhlQkTAT6M KZt6WffG/fADGKHzXnUlrasrmukkzO954iplCf2TNbhE4TAKmWNR+R0tsw49/pR3/wDg RQd/D/t0is5d4ZzoCvMvDHHWw5Ap2rEHkWMUX1SkK/mWsUUoQ1RQol6AOHwn0jgHLg/8 Wp/BFvmPEFg9ZLUqmWr2siA0corRI749vX028XsFCYmVD7baIwI/ej5Giyvh4/vV7+K1 Gu8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=PoSMAam0MPupaB4ef51eViQORTFAbxLJtMh/mRWXBQ0=; b=pV0idgyJ3NlDYQqbnvO2PDxuZSCNpQAWbvxlBnG+FsKcQQMpxBkSRTmdFxenseg1og 9zXf558LJ/oW7XaAU3P24cBTOEnuBFVDhXgBealt9BaHNZpdn7WhEXpEOsyHhQopNI8w UM+9emtvjUKvXpyobtM+GGm9RxGUUWPy1LV4EZw2lk64dZmXMqzgpkuGtgLU9ca9QICy M7EgdtaYbvox22ldI9B3s5lPJc4DtyNCY9Lw5zeMBd7BJgAmrMDXw6RbiEHcTvIVF1nD BC/Xo0WABxQ/IJk6ga3x+A24YTCo3WDHk6sui/9dYVyJ4BqwzFak6nAGv6ZAqmrveZKC B5DA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si182554ejx.132.2019.11.06.14.28.12; Wed, 06 Nov 2019 14:28:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732791AbfKFW1J (ORCPT + 99 others); Wed, 6 Nov 2019 17:27:09 -0500 Received: from mga17.intel.com ([192.55.52.151]:26990 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727154AbfKFW1I (ORCPT ); Wed, 6 Nov 2019 17:27:08 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2019 14:27:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,275,1569308400"; d="scan'208";a="353613712" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by orsmga004.jf.intel.com with ESMTP; 06 Nov 2019 14:27:07 -0800 Date: Wed, 6 Nov 2019 14:27:07 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Alexander Graf , Radim =?utf-8?B?S3LEjW3DocWZ?= , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Liran Alon Subject: Re: [PATCH v2 00/14] KVM: x86: Remove emulation_result enums Message-ID: <20191106222707.GB21617@linux.intel.com> References: <20190827214040.18710-1-sean.j.christopherson@intel.com> <8dec39ac-7d69-b1fd-d07c-cf9d014c4af3@redhat.com> <686b499e-7700-228e-3602-8e0979177acb@amazon.com> <20191106005806.GK23297@linux.intel.com> <3d827e8b-a04e-0a93-4bb4-e0e9d59036da@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3d827e8b-a04e-0a93-4bb4-e0e9d59036da@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 06, 2019 at 01:17:40PM +0100, Paolo Bonzini wrote: > On 06/11/19 01:58, Sean Christopherson wrote: > >> enum kvm_return { > >> KVM_RET_USER_EXIT = 0, > >> KVM_RET_GUEST = 1, > >> }; > >> > >> and then consistently use them as return values? That way anyone who has not > >> worked on kvm before can still make sense of the code. > > Hmm, I think it'd make more sense to use #define instead of enum to > > hopefully make it clear that they aren't the *only* values that can be > > returned. That'd also prevent anyone from changing the return types from > > 'int' to 'enum kvm_return', which IMO would hurt readability overall. > > > > And maybe KVM_EXIT_TO_USERSPACE and KVM_RETURN_TO_GUEST? > > That would be quite some work. Right now there is some consistency > between all of: > > - x86_emulate_instruction and its callers > > - vcpu->arch.complete_userspace_io > > - vcpu_enter_guest/vcpu_block > > - kvm_x86_ops->handle_exit > > so it would be very easy to end up with a half-int-half-enum state that > is more confusing than before... Ya, my thought was to update the obvious cases, essentially the ones you listed above, to use the define. So almost intentionally end up in a half-n-half state, at least in the short term, the thought being that the extra annotation would do more harm than good. But there's really no way to determine whether or not it would actually be a net positive without writing the code... > I'm more worried about cases where we have functions returning either 0 > or -errno, but 0 lets you enter the guest. I'm not sure if the only one > is kvm_mmu_reload or there are others. There are lots of those, e.g. basically all of the helpers for nested consistency checks.