All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Hansen, Dave" <dave.hansen@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "jgross@suse.com" <jgross@suse.com>,
	"seanjc@google.com" <seanjc@google.com>,
	"x86@kernel.org" <x86@kernel.org>, "bp@alien8.de" <bp@alien8.de>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"Yamahata, Isaku" <isaku.yamahata@intel.com>
Subject: Re: [PATCH 2/5] x86/virt/tdx: Move TDMR metadata fields map table to local variable
Date: Mon, 6 May 2024 08:04:51 +0000	[thread overview]
Message-ID: <aeccabf25c5c4e5e721f0ee5a83892061a6b2d76.camel@intel.com> (raw)
In-Reply-To: <b78a383d-27bb-43e3-8e61-f8a6b25b2708@intel.com>

On Fri, 2024-05-03 at 09:01 -0700, Dave Hansen wrote:
> On 3/1/24 03:20, Kai Huang wrote:
> > The kernel reads all TDMR related global metadata fields based on a
> > table which maps the metadata fields to the corresponding members of
> > 'struct tdx_tdmr_sysinfo'.
> > 
> > Currently this table is a static variable.  But this table is only used
> > by the function which reads these metadata fields and becomes useless
> > after reading is done.
> 
> Is this intended to be a problem statement?  _How_ is this a problem?
> 
> > Change the table to function local variable.  This also saves the
> > storage of the table from the kernel image.
> 
> I'm confused how this would happen.  Could you please explain your logic
> a bit here?

I think I failed to notice one thing, that although this patch can
eliminate the (static) @fields[] array in the data section, it generates
more code in the function get_tdx_tdmr_sysinfo() in order to build the
same array in the stack.

I did experiment and compared the generated code with or without the code
change in this patch:

before:

	fields:
	        .quad   -7998392933915033592	/* metadata field ID */
	        .long   0
	        .zero   4
	        .quad   -7998392933915033591
	        .long   2
	        .zero   4
	        .quad   -7998392933915033584
	        .long   4
	        .zero   4
	        .quad   -7998392933915033583
	        .long   6
	        .zero   4
	        .quad   -7998392933915033582
	        .long   8
	        .zero   4
	get_tdx_tdmr_sysinfo:
	        pushq   %rbp
	        movq    %rsp, %rbp
	        subq    $24, %rsp
	        movq    %rdi, -24(%rbp)
	        movl    $0, -4(%rbp)
	        jmp     .L8

		......

after:

	get_tdx_tdmr_sysinfo:
	        pushq   %rbp
	        movq    %rsp, %rbp
	        subq    $112, %rsp
	        movq    %rdi, -104(%rbp)
	        movabsq $-7998392933915033592, %rax
	        movq    %rax, -96(%rbp)
	        movl    $0, -88(%rbp)
	        movabsq $-7998392933915033591, %rax
	        movq    %rax, -80(%rbp)
	        movl    $2, -72(%rbp)
	        movabsq $-7998392933915033584, %rax
	        movq    %rax, -64(%rbp)
	        movl    $4, -56(%rbp)
	        movabsq $-7998392933915033583, %rax
	        movq    %rax, -48(%rbp)
	        movl    $6, -40(%rbp)
	        movabsq $-7998392933915033582, %rax
	        movq    %rax, -32(%rbp)
	        movl    $8, -24(%rbp)
	        movl    $0, -4(%rbp)
	        jmp     .L8

		......

So looks we cannot assume moving the static array to function local
variable can always save the storage.

I think the point is the compiler has to keep those constants (metadata
field ID and offset) somewhere in the object file, no matter they are in
the data section or in the code in text section, and no matter how does
the compiler generate the code.

The more reasonable benefit of this patch is to make the name scope of the
@fields[] array be only visible in the get_tdx_tdmr_sysinfo() but not the
entire file.

Thanks for the insight.  I hope the above is all I missed, or am I still
missing anything?

Anyway as replied to Rick I'll drop this patch from this series.




  reply	other threads:[~2024-05-06  8:05 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 11:20 [PATCH 0/5] TDX host: Provide TDX module metadata reading APIs Kai Huang
2024-03-01 11:20 ` [PATCH 1/5] x86/virt/tdx: Rename _offset to _member for TD_SYSINFO_MAP() macro Kai Huang
2024-05-03  0:07   ` Edgecombe, Rick P
2024-05-06 11:34     ` Huang, Kai
2024-03-01 11:20 ` [PATCH 2/5] x86/virt/tdx: Move TDMR metadata fields map table to local variable Kai Huang
2024-05-03  0:09   ` Edgecombe, Rick P
2024-05-03  0:18     ` Huang, Kai
2024-05-03  0:29       ` Edgecombe, Rick P
2024-05-03  0:54         ` Huang, Kai
2024-05-03 16:01   ` Dave Hansen
2024-05-06  8:04     ` Huang, Kai [this message]
2024-03-01 11:20 ` [PATCH 3/5] x86/virt/tdx: Unbind global metadata read with 'struct tdx_tdmr_sysinfo' Kai Huang
2024-05-03  0:12   ` Edgecombe, Rick P
2024-05-03  0:52     ` Huang, Kai
2024-05-03 19:03       ` Edgecombe, Rick P
2024-05-06 11:15         ` Huang, Kai
2024-03-01 11:20 ` [PATCH 4/5] x86/virt/tdx: Support global metadata read for all element sizes Kai Huang
2024-03-16  0:49   ` Isaku Yamahata
2024-03-20 12:24     ` Huang, Kai
2024-05-03  0:19   ` Edgecombe, Rick P
2024-05-03  1:14     ` Huang, Kai
2024-05-03 12:10       ` Huang, Kai
2024-05-03 12:26         ` Huang, Kai
2024-05-03 18:32           ` Edgecombe, Rick P
2024-05-06 10:59             ` Huang, Kai
2024-03-01 11:20 ` [PATCH 5/5] x86/virt/tdx: Export global metadata read infrastructure Kai Huang
2024-03-13  3:44   ` Xiaoyao Li
2024-03-15  0:24     ` Huang, Kai
2024-03-15  2:10       ` Xiaoyao Li
2024-05-03  0:21   ` Edgecombe, Rick P
2024-05-03  2:17     ` Huang, Kai
2024-05-03 18:31       ` Edgecombe, Rick P
2024-05-06 11:35         ` Huang, Kai
2024-05-06 15:43   ` Dave Hansen
2024-05-06 22:13     ` Huang, Kai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aeccabf25c5c4e5e721f0ee5a83892061a6b2d76.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=hpa@zytor.com \
    --cc=isaku.yamahata@intel.com \
    --cc=jgross@suse.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.