Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2787377lqz; Wed, 3 Apr 2024 08:35:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWJIkNGxedWAEzzKcdemSX6k97hQ35ehSMpDNoBfcbk5d4gTGdifQzgle6HkenS4hAYVfrzdEYl50vjvV6gkQcKlvKFjoduu2x/RDTcQg== X-Google-Smtp-Source: AGHT+IG2EyhghYUeUHW3+AF4FKt7v+etV3v3xt6jvMztJAEgsfozZUfGkhzcHDotKI9geCcs+a6+ X-Received: by 2002:a05:6a00:27a0:b0:6ea:7b29:3ab7 with SMTP id bd32-20020a056a0027a000b006ea7b293ab7mr16923991pfb.23.1712158554060; Wed, 03 Apr 2024 08:35:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712158554; cv=pass; d=google.com; s=arc-20160816; b=xAulKC4wqS/p4dpQ4h3qEp0eN0ltrLiLQfN6LJlKHuhRhQYkDsYxhnuWZiP3mOj6Jy AYsnIyBPFPfXmkwGtwl8vcfb1QwgZGAE1Tuo634Yl2X+2A7kmUe2oS2Bezl+EBSJbYYB bbDwMto2DuMhRWUwIjZE4kDIYUvUqL+bJqlHipsLKzlS8XdslcEYN+PIZKY1teoXt72V CgTcY/DjPUYmABrMCMWHgLXrlCHkMIGVROLoPgoXn/+SKfevh1Gqmrqrf/5ho0zzBJW/ y71kSYHoM1wGyvLmHmLZekRozsg4DIZHP0YRRoT5bPu3K1y9SNEF3xi1q0flcknn+72B 2dOA== 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=2CFD4RCP3K0RMlQFKNQ4bqH2ptR6QIZ6/qTQHfdpY2E=; fh=zqZI7+RT7l3WD06IsZj+nyBf10inGFihwjjccZurXYQ=; b=ZZEc0AmzDO2NvLw9LgwqxKgXXCrTLbv+tvOlVo9Aru7IY2N0fdf5eiyTwUtgbFc8Xk pAO5BU7ZNt4dk86ZJma65rhbnYNmaRenFhU9WeGw1kgA9ZYD85OtCbTU8LCuCLq2Utwt ep+JughA2OYvxfji6m6KhqxRy0z5p2YsYstp/NzRynvWRModYP4KVKNAO69TBnErltqJ 1yp7eurhBMVcytDCfDpPA3Cprtow2hWOtcLQiJS0TiSLBKNZRDMEH5+fiTMWDhkx68HE 7lC2A6vn1pujjxcVQZKiSydl5I4dSi8AvHH4pYKMX9Z5bOu1P+VzcH+BPn88Nsrnitie p7Cg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=G648maVc; 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-130026-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130026-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 e16-20020a631e10000000b005dc81eca355si13113212pge.487.2024.04.03.08.35.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 08:35:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130026-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=G648maVc; 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-130026-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130026-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 67AFEB28858 for ; Wed, 3 Apr 2024 15:04:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EBE0114A088; Wed, 3 Apr 2024 15:04:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G648maVc" Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 B27C4149DF5 for ; Wed, 3 Apr 2024 15:04:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712156647; cv=none; b=TsX2CCfiZwaXBzudjEkuqN2rObP6lisYTJwRt8f30oIdzBrENxMgzAqj5PCa6BD3974F/htoNZ/KEO81kE3E7wDRKZAbTpwuTorziwi8/lYm91pCj9Uw7d4fFgChSd380svGFVHxgDXjpVEI0NXb8zr8Ob2Jp3Bg8pw/2rpm46A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712156647; c=relaxed/simple; bh=+5o5zP59wSQFL2zykRGCByfv1vZWjUga5Qtwrzw0JwY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=txTBSc8LwEcZKXUDapsMqKavEKcq9vYxFzycm5FS9Jcz9tySDOBnQ5qd7q4b99jLvyFFyjhxVMoP7H2AjxrNIx2hgnpUXowDgu+50GDtmgY7N+xjzP3M/ingIZR8XuzMEP9hw0Smu71ZydvdW3Bq0KyIOSzU/N1esb94FyMncwA= 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=G648maVc; arc=none smtp.client-ip=209.85.215.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-pg1-f201.google.com with SMTP id 41be03b00d2f7-5c5c8ef7d0dso5130361a12.2 for ; Wed, 03 Apr 2024 08:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712156645; x=1712761445; 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=2CFD4RCP3K0RMlQFKNQ4bqH2ptR6QIZ6/qTQHfdpY2E=; b=G648maVcCuqMdJjD3BhjFGk04BFV7JMTXMkesad7JagzXoXw7W+37RLbCVSmwa/93Z BJvyQnMqq1Yzespxyzcd8n2Nc7/JM8cXdWi8fHX2xgCAynmY8U+mHYv6wWdWYofmLEqO 9++ERlJoNpebu6/xmq+pTT6YCzRr8F5wjoikS/9XZ3JAbwFNbCbNcYjgYg9hXMsr2Vwt RsTRFj+m4X+n2nJxVhgK9lN21Gr+RmbHUdLL3/W5wNg2dW1kfoUATI7PJ9gY0fQOCvQr QtOgsZAr4mIT7CgwGqk//ma3fMzLIRM9HpmntQM0whBQ77maJ6j793IkB8+ihJreHnzR o+nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712156645; x=1712761445; 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=2CFD4RCP3K0RMlQFKNQ4bqH2ptR6QIZ6/qTQHfdpY2E=; b=KRJm730DrP/ctoG/R2tDr/0UeMbDeHkoPolyxqlHGAHuPI1uQ+9C1uY/OzzNvr0uTX 23l+wV0E5sHH5zjG2f+xO6O3u7j+Uw+G8XL0Q1offd2hFj4MTy+ryASlhyM6NmzdWcau rTYZfHteV6QrIkWfWmBlHkaAKMTL3vBDHV/4VW3PEEczzHoDsanoOUbegvJaV64/4QCS P/+oPWTlPLyiAXfcb/TZ+EvK9W8R2eAWqljesvBSQBlEM/LFkHTBFiuibJ1nJlF0/j/h kn2Z3gnQ1C9Xz24aod6eh8h7mrDAdgwDnvQJAtKcaka5oxs9zYQ5cMf2yoZnbmOJx1n8 0kow== X-Forwarded-Encrypted: i=1; AJvYcCV4+bFB81T1GRhaJnajvsvQ+4rxQDQQHB7quYeh/X/Hzb5UIPHUR5VNfijml80BO+13iqm8mhwJd89vF+VvEOSx++Gv+kalK8Ul8Tti X-Gm-Message-State: AOJu0YyeS3AJSNZtx3lR+qMX2sfSLwD8YzaGZstovjyGlvzSGlDeneZ4 JePgtJ4O0CjRTRxwNA99ai1++w2JWdh2DcAWNzWDbdKtcwiIgDokNS0Vy3cNAM2u6Ke+C42KKVv uHg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:db11:b0:1e0:d205:2da2 with SMTP id m17-20020a170902db1100b001e0d2052da2mr597057plx.3.1712156644742; Wed, 03 Apr 2024 08:04:04 -0700 (PDT) Date: Wed, 3 Apr 2024 08:04:03 -0700 In-Reply-To: <522cbfe6e5a351f88480790fe3c3be36c82ca4b1.1708933498.git.isaku.yamahata@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <522cbfe6e5a351f88480790fe3c3be36c82ca4b1.1708933498.git.isaku.yamahata@intel.com> Message-ID: Subject: Re: [PATCH v19 027/130] KVM: TDX: Define TDX architectural definitions From: Sean Christopherson To: isaku.yamahata@intel.com Cc: 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 , Xiaoyao Li Content-Type: text/plain; charset="us-ascii" On Mon, Feb 26, 2024, isaku.yamahata@intel.com wrote: > +union tdx_vcpu_state_details { > + struct { > + u64 vmxip : 1; > + u64 reserved : 63; > + }; > + u64 full; > +}; No unions please. KVM uses unions in a few places where they are the lesser of all evils, but in general, unions are frowned upon. Bitfields in particular are strongly discourage, as they are a nightmare to read/review and tend to generate bad code. E.g. for this one, something like (names aren't great) static inline bool tdx_has_pending_virtual_interrupt(struct kvm_vcpu *vcpu) { return & TDX_VCPU_STATE_VMXIP; } > +union tdx_sept_entry { > + struct { > + u64 r : 1; > + u64 w : 1; > + u64 x : 1; > + u64 mt : 3; > + u64 ipat : 1; > + u64 leaf : 1; > + u64 a : 1; > + u64 d : 1; > + u64 xu : 1; > + u64 ignored0 : 1; > + u64 pfn : 40; > + u64 reserved : 5; > + u64 vgp : 1; > + u64 pwa : 1; > + u64 ignored1 : 1; > + u64 sss : 1; > + u64 spp : 1; > + u64 ignored2 : 1; > + u64 sve : 1; Yeah, NAK to these unions. They are crappy duplicates of existing definitions, e.g. it took me a few seconds to realize SVE is SUPPRESS_VE, which is far too long. > + }; > + u64 raw; > +}; > +enum tdx_sept_entry_state { > + TDX_SEPT_FREE = 0, > + TDX_SEPT_BLOCKED = 1, > + TDX_SEPT_PENDING = 2, > + TDX_SEPT_PENDING_BLOCKED = 3, > + TDX_SEPT_PRESENT = 4, > +}; > + > +union tdx_sept_level_state { > + struct { > + u64 level : 3; > + u64 reserved0 : 5; > + u64 state : 8; > + u64 reserved1 : 48; > + }; > + u64 raw; > +}; Similar thing here. Depending on what happens with the SEAMCALL argument mess, the code can look somethign like: static u8 tdx_get_sept_level(struct tdx_module_args *out) { return out->rdx & TDX_SEPT_LEVEL_MASK; } static u8 tdx_get_sept_state(struct tdx_module_args *out) { return (out->rdx & TDX_SEPT_STATE_MASK) >> TDX_SEPT_STATE_SHIFT; } > +union tdx_md_field_id { > + struct { > + u64 field : 24; > + u64 reserved0 : 8; > + u64 element_size_code : 2; > + u64 last_element_in_field : 4; > + u64 reserved1 : 3; > + u64 inc_size : 1; > + u64 write_mask_valid : 1; > + u64 context : 3; > + u64 reserved2 : 1; > + u64 class : 6; > + u64 reserved3 : 1; > + u64 non_arch : 1; > + }; > + u64 raw; > +}; > + > +#define TDX_MD_ELEMENT_SIZE_CODE(_field_id) \ > + ({ union tdx_md_field_id _fid = { .raw = (_field_id)}; \ > + _fid.element_size_code; }) Yeah, no thanks. MASK + SHIFT will do just fine.