Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1163571lqd; Thu, 25 Apr 2024 07:42:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPiXgQktXUMmoEF0igogiY9F5d0AFeDutSSjM0NiQBcP9Vq7RJJ2Ec+eJYWy9D78LzT7e9iHwv5Z1sWRXqL3mIdGOt7zkR4podoAYzDw== X-Google-Smtp-Source: AGHT+IFSUueuKo7dgoHzRDOUHzAo4PKQCgda1dWWBp5mvYP9x2nNOfpKRxVsG13vJR2VGoiDNZYj X-Received: by 2002:a50:d4cb:0:b0:56e:3293:3777 with SMTP id e11-20020a50d4cb000000b0056e32933777mr5746753edj.17.1714056145631; Thu, 25 Apr 2024 07:42:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714056145; cv=pass; d=google.com; s=arc-20160816; b=0NMqqXoX6DdXTn9qJMDlNE9TgJZxSimNoS4ZEIrIDyYJ5pj2GUOfy4lKWHKvsw7BLk 42LZSq9KSP2G8c8AlBb3q0CgeY8kYT+gR1cdK+Ooe7yP8yOW51EnEbaothQ8NhIZL/YG PVx06E/JJXDIa7uxRFNLpWCttxkmC8xPDiMtmpvcdlZNvi+39IgCOzRQ8ngAZpF7838W cFC2UWRLU2G5N8T5hbV2zdTNGC2LIHjX+q50Zw9GDYcketjTl2CiftMiwFtMp1QBKX7W EuWw89oH4ZYlfSI3QCrAsHTZgV9LvDfq2Z72A6dHi+YHx7qv8WPMMNYjpnkogA5RdxQJ z4JQ== 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=lDWCaTYULwF8F3zi592tmuoj8LcUAihXwO8QYVH28dw=; fh=5Ib8uJpHAZVvNBmCNX1FCoDj8d6sn+NhWJcsQkHf10g=; b=g3TQxXtefcQkSsCrw3AZImVAiBS9Rzi2wPic/WxZ0Z9LGGYZYT+5QkSxfgbagiYyoQ ZksMXGeedkBtjgqkche5AjGwmsLKqfy3KZj2Fv4ia3UMhGdmFdcDCET83N0z0T+BrcWw CljnF+OklWjiv6GV/hkzJAZuQzong4prriowpPbMT4kjg6vO5Jz6/lxbTwkl9um4I/8c Ntv06giQw8yTNncPx1GJJN89qMbOkkXhfjwJRPV8+ePqGEcLOKZXeHGji+ePVH72qgXh kpFd9adyIydwrgTM8izHoaskokWderjXIRZJns05DG+IPpEZT0llTqhfYHSNuNVvJPdT QV5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x4Wwt5C6; 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-158728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158728-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m9-20020a056402050900b0057215cc4d46si4141237edv.413.2024.04.25.07.42.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 07:42:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x4Wwt5C6; 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-158728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158728-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 34AF51F236AE for ; Thu, 25 Apr 2024 14:42:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74E5114A611; Thu, 25 Apr 2024 14:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="x4Wwt5C6" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 40E40149C79 for ; Thu, 25 Apr 2024 14:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714056127; cv=none; b=DuYhZvtjZ4xGG5JicH+osOUF4aJzjCv66YQRNwtFvrYuivIbaFUwsMAjx9ffbQjnk265ltjzsD3hVTCfA63f1+6YhCcW3qiVjDYWPAoYpSsdkAsf7K/XwPjEmYkAO1TU7RxKcd56gNh500IK0qi3qwzaKXIDFYN2KhczNB+MEoo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714056127; c=relaxed/simple; bh=2HTb1/D2zJKsTz0x8dg2JPZ7AoAiGX0TfTBOVZ7lUok=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PzN+LZUWT6kBj0oT+4VPb6IC7WiftppBpHDl4as3l8GH58c6Z7q/Es++6e2NANXiXv6C3oANUafEELUk+Jg6pLmA13xmURJS8PGK6brgBpiUwcqU7acxu7c+zTFdlTi0ty35ro6d8bSygn1J5k2H42rQI+pqoREPLlz05WACpaU= 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=x4Wwt5C6; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-de5823bd7eeso2353032276.0 for ; Thu, 25 Apr 2024 07:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714056125; x=1714660925; 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=lDWCaTYULwF8F3zi592tmuoj8LcUAihXwO8QYVH28dw=; b=x4Wwt5C6hHRlcYDRs995liII8ZAoKfJ/K+N8bnJmVXX2igKQ7cMdCugkF51lNBM9Op P6hjJKUzNHAb9hkUtPhOWcFZHYjm97E3EZ+J6bJrLpKmgg4mQ5uJrHN4IQwHGbNpvxEP S2JwivEI1xD1IuUD422B+FRmrHvRpNFUWuWK03UBJA1l70O9wYS+WByYZGStRykVZh2/ 9EzKxkpElQH1Qd367hEAjELuWkofggcE7SgC6WEeQZGMK9d3fIRJBT+tT2xfSpeVj1aA FDmQ9TN2CzewaSN/aAzpySL4zYwCk+KlJpscn6sbBp2Mi8qR9u1KuOWCmi+u2OsSuM7I Gx3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714056125; x=1714660925; 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=lDWCaTYULwF8F3zi592tmuoj8LcUAihXwO8QYVH28dw=; b=B7U2LGAKH+8UgQIUzXKhvugL4kY797TSKYb0enAW/T+s/CWxUtOSMPRTr77rMdYU1j ehOigMnuVCNlTAY5YeqHDtBEOXMdeZNtwYplDt+1MaUeKEvLxks4OY6qsvQPWExPv0j2 pQRg/SvOJzW9TxGMZEkCHf8pQ0FCWt/Lm5uKDyImRd/zQBlc2a+/OP0ad9NahuEdltyq E/zKXZb4bFt4GLBZ5O6GUFUT1s34aBkSyRC48N5FC8D6o8FVKPr8vNJ++3J49rBjwhbD DVI9Sz7UCxp96ViO8RAybUJl417o5q8+PeqfCN+eQtkNM5DEb+6TwnhFTg8PN5HwIQpt Vuhw== X-Forwarded-Encrypted: i=1; AJvYcCXmEQEc5FZJeX+a8QopTAzgUNu6KwuEmbGx8gd0S7vNBuoaEuVVKAPPaSycXTOV65zWnJXPn63mBdr0XGYvzkFMR0I/KOzWipwu+pEM X-Gm-Message-State: AOJu0Ywb37wzqNuwc0+yfgAV0H4+Sgw2Dv+12+ysV9ySHXHN5nrYw8en wWwdMiYCzKm0JWFqSVwxWrFU4M41VT/exs0knGwCKpsCQZ3gWDeRg9NaQgdVAgL7eHh6JJxuWGW L3A== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:c12:b0:de4:6624:b763 with SMTP id fs18-20020a0569020c1200b00de46624b763mr945449ybb.0.1714056125345; Thu, 25 Apr 2024 07:42:05 -0700 (PDT) Date: Thu, 25 Apr 2024 07:42:03 -0700 In-Reply-To: <64cc46778ccc93e28ec8d39b3b4e31842154f382.camel@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240309012725.1409949-1-seanjc@google.com> <20240309012725.1409949-9-seanjc@google.com> <1e063b73-0f9a-4956-9634-2552e6e63ee1@intel.com> <64cc46778ccc93e28ec8d39b3b4e31842154f382.camel@intel.com> Message-ID: Subject: Re: [PATCH v6 8/9] KVM: VMX: Open code VMX preemption timer rate mask in its accessor From: Sean Christopherson To: Kai Huang Cc: Xiaoyao Li , "luto@kernel.org" , Xin3 Li , "x86@kernel.org" , "dave.hansen@linux.intel.com" , "peterz@infradead.org" , Zhao1 Liu , "mingo@redhat.com" , "tglx@linutronix.de" , "bp@alien8.de" , "pbonzini@redhat.com" , "kvm@vger.kernel.org" , Shan Kang , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="us-ascii" On Thu, Apr 25, 2024, Kai Huang wrote: > On Wed, 2024-04-24 at 13:06 -0700, Sean Christopherson wrote: > > > > static inline u32 vmx_basic_vmcs_mem_type(u64 vmx_basic) > > > > { > > > > return (vmx_basic & GENMASK_ULL(53, 50)) >> > > > > VMX_BASIC_MEM_TYPE_SHIFT; > > > > } > > > > > > > > looks not intuitive than original patch. > > > > > > Yeah, agreed, that's taking the worst of both worlds. I'll update patch 5 to drop > > > VMX_BASIC_MEM_TYPE_SHIFT when effectively "moving" it into vmx_basic_vmcs_mem_type(). > > > > Drat. Finally getting back to this, dropping VMX_BASIC_MEM_TYPE_SHIFT doesn't > > work because it's used by nested_vmx_setup_basic(), as is VMX_BASIC_VMCS_SIZE_SHIFT, > > which is presumably why past me kept them around. > > > > I'm leaning towards keeping things as proposed in this series. I don't see us > > gaining a third copy, or even a third user, i.e. I don't think we are creating a > > future problem by open coding the shift in vmx_basic_vmcs_mem_type(). And IMO > > code like this > > > > return (vmx_basic & VMX_BASIC_MEM_TYPE_MASK) >> > > VMX_BASIC_MEM_TYPE_SHIFT; > > > > is an unnecessary obfuscation when there is literally one user (the accessor). > > > > Another idea would be to delete VMX_BASIC_MEM_TYPE_SHIFT and VMX_BASIC_VMCS_SIZE_SHIFT, > > and either open code the values or use local const variables, but that also seems > > like a net negative, e.g. splits the effective definitions over too many locations. > > Alternatively, we can add macros like below to close to > vmx_basic_vmcs_size() etc, so it's straightforward to see. > > +#define VMX_BSAIC_VMCS12_SIZE ((u64)VMCS12_SIZE << 32) > +#define VMX_BASIC_MEM_TYPE_WB (MEM_TYPE_WB << 50) Hmm, it's a bit hard to see it's specifically VMCS12 size, and given that prior to this series, VMX_BASIC_MEM_TYPE_WB = 6, I'm hesitant to re-introduce/redefine that macro with a different value. What if we add a helper in vmx.h to encode the VMCS info? Then the #defines for the shifts can go away because the open coded shifts are colocated and more obviously related. E.g. static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype) { return revision | ((u64)size << 32) | ((u64)memtype << 50); } and static void nested_vmx_setup_basic(struct nested_vmx_msrs *msrs) { /* * This MSR reports some information about VMX support. We * should return information about the VMX we emulate for the * guest, and the VMCS structure we give it - not about the * VMX support of the underlying hardware. */ msrs->basic = vmx_basic_encode_vmcs_info(VMCS12_REVISION, VMCS12_SIZE, X86_MEMTYPE_WB); msrs->basic |= VMX_BASIC_TRUE_CTLS if (cpu_has_vmx_basic_inout()) msrs->basic |= VMX_BASIC_INOUT; }