[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86/hvm: print valid CR4 bits in case of error


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Thu, 8 Jun 2023 10:04:22 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8SG/mQjHi1IESN+dMkY0nPEfRAyKCI6s7zJCk2PQWOc=; b=Jc4k3lV4AbABNxn4R8vvo/hJ8KnKHja/B1JTS30nEItisfdSeeZ+QgpvBZxMnLHcHd4xsvsAHCPRo3O94rwSC8tZAnRtiG7DltjPfsjnU9n2M3J2aYqPDQ9PJkYjme83sDejbtsrZtlRC9jVg1mHJwiSsMnkkMxQ//KXjwoXW2Y0G+QzhC8HtidKI7ACf0jFN+DSKZMyzKturjNoJp+steMumrgh9v01zy3HqPhJADg9LUjvjiwcuRZHRkmEHen24U9bVhgsYkX5BNWOwYXCrLsIqnbDqizs7Sz6GVsQQb8qfRD+YJ8spO0MCTbM9OfouN4c+ImwW81jin7RB22hIQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d6uk1vKTaNMU+GLPRElpnny7m8SIQdq6oVuEWymBNBEsEdGGmZnu1fq7J3wj+BJOqKGf7jF5J5foMVnJe6/OleJ6P5t/KsWKd+/Di6cOArN8eMDAdzeE50u3ZhpVtsKf9PA9GpsQVDHQFFR6/2HB8suOTzRWYPRXHk3Vmk8Gacg3M5DNJtz/qF0gFx8WeLshr0jx4d9XnWJw8eBuvj3lkiSNRykG0zE/qa9iuEgQbLHEMG2p7t6q31FtOK0nohu/t5pEsXthRJGeQ8QRx4JI6kAVOKwJ5qzoGEJGs3QfuvhotVSOOcxx2hhGcTBmQt/ydoTlMaJGqTgbTNHzsv65xw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 08 Jun 2023 08:05:01 +0000
  • Ironport-data: A9a23:x8zrFKzv8CDP82akL0V6t+cRxyrEfRIJ4+MujC+fZmUNrF6WrkUHy GIYCj2GbPyMZzOnctAiOYvjo0kEuJOAzodkQQpq+SAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHfykTrafYEidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw/zF8EsHUMja4mtC5QRgPaAT5TcyqlFOZH4hDfDpR5fHatE88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IOM0SQqkEqSh8ai87XAME0e0ZP4whlqvgqo Dl7WT5cfi9yVkHEsLx1vxC1iEiSN4UekFPMCSDXXcB+UyQq2pYjqhljJBheAGEWxgp4KU8Xz MIzbzYPVSqaiOaL+52qVLBIgtt2eaEHPKtH0p1h5RfwKK98BLzmHeDN79Ie2yosjMdTG/qYf 9AedTdkcBXHZVtIJ0sTD5U92uyvgxETcRUB8A7T+fVxvjmVlVMsuFTuGIO9ltiiX8Jak1zev mvb12/4HgsbJJqUzj/tHneE37aVxX+gA9xMfFG+3uMzjESX5G82NCVIU1eis924oUC7evsKf iT4/QJr98De7neDXtT7GhG1vnOAlhodQMZLVf037hmXzajZ6BrfAXILJhZDYtE7sM49RRQxy 0SE2djuAFRHr7m9WX+bsLCOoluP1TM9KGYDYWoISFUD6ty6+oUr1EuQE5BkDbK/icDzFXfo2 TeWoSMihrIVy8kWy6G8+lOBiDWpznTUcjMICszsdjrNxmtEiESNPuRENXCzAS58Ebuk
  • Ironport-hdrordr: A9a23:v5I0K6Ema33+RNcepLqELMeALOsnbusQ8zAXPiBKJCC9E/bo8v xG+c5w6faaslkssR0b9+xoW5PwI080l6QU3WB5B97LMDUO0FHCEGgI1/qA/9SPIUzDHu4279 YbT0B9YueAcGSTW6zBkXWF+9VL+qj5zEix792uq0uE1WtRGtldBwESMHf9LmRGADNoKLAeD5 Sm6s9Ot1ObCA8qhpTSPAhiYwDbzee77a7bXQ==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Jun 08, 2023 at 09:57:41AM +0200, Roger Pau Monné wrote:
> On Wed, Jun 07, 2023 at 04:48:42PM +0100, Andrew Cooper wrote:
> > On 07/06/2023 2:46 pm, Roger Pau Monne wrote:
> > > Some of the current users of hvm_cr4_guest_valid_bits() to check
> > > whether a CR4 value is correct don't print the valid mask, and thus
> > > the resulting error messages are not as helpful as they could be.
> > >
> > > Amend callers to always print the value of hvm_cr4_guest_valid_bits(),
> > > and take the opportunity of also adjusting all the users to use the
> > > same print formatter.
> > >
> > > No functional change intended.
> > >
> > > Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> > > ---
> > >  xen/arch/x86/hvm/domain.c       | 4 ++--
> > >  xen/arch/x86/hvm/hvm.c          | 8 ++++----
> > >  xen/arch/x86/hvm/svm/svmdebug.c | 2 +-
> > >  3 files changed, 7 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c
> > > index deec74fdb4f5..8951230a9f52 100644
> > > --- a/xen/arch/x86/hvm/domain.c
> > > +++ b/xen/arch/x86/hvm/domain.c
> > > @@ -266,8 +266,8 @@ int arch_set_info_hvm_guest(struct vcpu *v, const 
> > > vcpu_hvm_context_t *ctx)
> > >  
> > >      if ( v->arch.hvm.guest_cr[4] & ~hvm_cr4_guest_valid_bits(d) )
> > >      {
> > > -        gprintk(XENLOG_ERR, "Bad CR4 value: %#016lx\n",
> > > -                v->arch.hvm.guest_cr[4]);
> > > +        gprintk(XENLOG_ERR, "Bad CR4 value: %#016lx (valid: %016lx)\n",
> > > +                v->arch.hvm.guest_cr[4], hvm_cr4_guest_valid_bits(d));
> > 
> > I suspect you want to call this once and store it in a variable.
> > 
> > It's a non-inline function which also isn't marked attr_const, so it
> > will get called twice.
> 
> I wasn't specially concerned about this, it's an error path where the
> second call will happen, and there's already a printk which will make
> the cost of calling hvm_cr4_guest_valid_bits() negligible compared to
> the printk.
> 
> > Also, if you're extending like this, then you actually want
> > 
> > (valid %lx, rejected %lx)
> > 
> > passing in cr4 ^ valid for rejected.  It's almost always 1 bit which is
> > rejected at a time, and the xor form is easier to read, not least
> > because it matches the X86_CR4_blah constant of the bad feature.

But cr4 ^ valid is not correct to represent rejected bits, what about
valid bits not set by the guest?  Those would also appear in the
rejected mask for no reason.  I think we want to print cr4 & ~valid,
like used in the validity checks.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.