From: "Huang, Kai" <kai.huang@intel.com>
To: "corbet@lwn.net" <corbet@lwn.net>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"bp@alien8.de" <bp@alien8.de>,
"shuah@kernel.org" <shuah@kernel.org>,
"sathyanarayanan.kuppuswamy@linux.intel.com"
<sathyanarayanan.kuppuswamy@linux.intel.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"x86@kernel.org" <x86@kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>
Cc: "linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"Yu, Guorui" <guorui.yu@linux.alibaba.com>,
"qinkun@apache.org" <qinkun@apache.org>,
"wander@redhat.com" <wander@redhat.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"chongc@google.com" <chongc@google.com>,
"Aktas, Erdem" <erdemaktas@google.com>,
"kirill.shutemov@linux.intel.com"
<kirill.shutemov@linux.intel.com>,
"Luck, Tony" <tony.luck@intel.com>,
"dionnaglaze@google.com" <dionnaglaze@google.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"Du, Fan" <fan.du@intel.com>
Subject: Re: [PATCH v2 1/3] x86/tdx: Add TDX Guest event notify interrupt support
Date: Fri, 14 Apr 2023 13:34:37 +0000 [thread overview]
Message-ID: <632a9a27abb5da053caedbbc6bcb7d5e15b2322c.camel@intel.com> (raw)
In-Reply-To: <20230413034108.1902712-2-sathyanarayanan.kuppuswamy@linux.intel.com>
On Wed, 2023-04-12 at 20:41 -0700, Kuppuswamy Sathyanarayanan wrote:
> Host-guest event notification via configured interrupt vector is useful
> in cases where a guest makes an asynchronous request and needs a
> callback from the host to indicate the completion or to let the host
> notify the guest about events like device removal. One usage example is,
> callback requirement of GetQuote asynchronous hypercall.
>
> In TDX guest, SetupEventNotifyInterrupt hypercall can be used by the
> guest to specify which interrupt vector to use as an event-notify
> vector from the VMM. Details about the SetupEventNotifyInterrupt
> hypercall can be found in TDX Guest-Host Communication Interface
> (GHCI) Specification, section "VP.VMCALL<SetupEventNotifyInterrupt>".
>
> As per design, VMM will post the event completion IRQ using the same
> CPU on which SetupEventNotifyInterrupt hypercall request is received.
> So allocate an IRQ vector from "x86_vector_domain", and set the CPU
> affinity of the IRQ vector to the CPU on which
> SetupEventNotifyInterrupt hypercall is made.
>
> Add tdx_register_event_irq_cb()/tdx_unregister_event_irq_cb()
> interfaces to allow drivers register/unregister event noficiation
^
to register/unregister
> handlers.
>
>
[...]
> +/* Reserve an IRQ from x86_vector_domain for TD event notification */
> +static int __init tdx_event_irq_init(void)
> +{
> + struct irq_alloc_info info;
> + struct irq_cfg *cfg;
> + int irq;
> +
> + if (!cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
> + return 0;
> +
> + init_irq_alloc_info(&info, NULL);
> +
> + /*
> + * Event notification vector will be delivered to the CPU
> + * in which TDVMCALL_SETUP_NOTIFY_INTR hypercall is requested.
^
on which (to be consistent with the changelog)
> + * So set the IRQ affinity to the current CPU (CPU 0).
> + */
> + info.mask = cpumask_of(0);
I think we should use smp_processor_id() to get the CPU id even for BSP.
> +
> + irq = irq_domain_alloc_irqs(x86_vector_domain, 1, cpu_to_node(0), &info);
> + if (irq <= 0) {
> + pr_err("Event notification IRQ allocation failed %d\n", irq);
> + return -EIO;
> + }
> +
> + irq_set_handler(irq, handle_edge_irq);
> +
> + /* Since the IRQ affinity is set, it cannot be balanced */
> + if (request_irq(irq, tdx_event_irq_handler, IRQF_NOBALANCING,
> + "tdx_event_irq", NULL)) {
> + pr_err("Event notification IRQ request failed\n");
> + goto err_free_domain_irqs;
> + }
Firstly, this comment isn't right. The @info->mask is only used to allocate the
vector of the IRQ, but it doesn't have anything to do with IRQ affinity.
irq_domain_alloc_irqs() will set the IRQ to have the default affinity in fact.
The comment should be something like below instead:
/*
* The IRQ cannot be migrated because VMM always injects the vector
* event to the cpu on which the SetupEventNotifyInterrupt TDVMCALL
* is called. Set the IRQ with IRQF_NOBALANCING to prevent its
affinity
* from being changed.
*/
That also being said, you actually haven't set IRQ's affinity to the BSP yet
before request_irq(). IIUC you can either:
1) Explicitly call irq_set_affinity() after irq_domain_alloc_irqs() to set
affinity to BSP; or
2) Use __irq_domain_alloc_irqs(), which allows you to set the affinity directly,
to allocate the IRQ instead of irq_domain_alloc_irqs().
struct irq_affinity_desc desc;
cpumask_set_cpu(smp_processor_id(), &desc.mask);
irq = __irq_domain_alloc_irqs(..., &desc);
Personally I think 2) is more straightforward.
Using 2) also allows you to alternatively set desc.is_managed to 1 to set the
IRQ as kernel managed. This will prevent userspace from changing IRQ affinity.
Kernel can still change the affinity, though, but no other kernel code will do
that.
So both kernel managed affinity IRQ and IRQF_NOBALANCING should work. I have no
opinion on this.
And IIUC if you already set IRQ's affinity to BSP before request_irq(), then you
don't need to do:
info.mask = cpumask_of(0);
before allocating the IRQ as the vector will be allocated in request_irq() on
the BSP anyway.
> +
> + cfg = irq_cfg(irq);
> +
> + /*
> + * Since tdx_event_irq_init() is triggered via early_initcall(),
> + * it will called before secondary CPUs bringup. Since there is
> + * only one CPU, it complies with the requirement of executing
> + * the TDVMCALL_SETUP_NOTIFY_INTR hypercall on the same CPU where
> + * the IRQ vector is allocated.
IMHO this is unnecessary complicated.
In fact, IMHO we can just have one simple comment at the very beginning to
explain the whole thing:
/*
* TDX guest uses SetupEventNotifyInterrupt TDVMCALL to allow the
* hypervisor to notify the TDX guest when needed, for instance,
* when VMM finishes the GetQuote request from the TDX guest.
*
* The VMM always notifies the TDX guest via the vector specified in
the
* SetupEventNotifyInterrupt TDVMCALL to the cpu on which the TDVMCALL
* is called. For simplicity, just allocate an IRQ (and a vector)
* directly from x86_vector_domain for such notification and pin the
* IRQ to the BSP.
*/
And then all the code follows.
> + *
> + * Register callback vector address with VMM. More details
> + * about the ABI can be found in TDX Guest-Host-Communication
> + * Interface (GHCI), sec titled
> + * "TDG.VP.VMCALL<SetupEventNotifyInterrupt>".
> + */
> + if (_tdx_hypercall(TDVMCALL_SETUP_NOTIFY_INTR, cfg->vector, 0, 0, 0)) {
> + pr_err("Event notification hypercall failed\n");
> + goto err_free_irqs;
> + }
> +
> + tdx_event_irq = irq;
> +
> + return 0;
> +
> +err_free_irqs:
> + free_irq(irq, NULL);
> +err_free_domain_irqs:
> + irq_domain_free_irqs(irq, 1);
> +
> + return -EIO;
> +}
> +early_initcall(tdx_event_irq_init)
> +
>
[...]
next prev parent reply other threads:[~2023-04-14 13:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 3:41 [PATCH v2 0/3] TDX Guest Quote generation support Kuppuswamy Sathyanarayanan
2023-04-13 3:41 ` [PATCH v2 1/3] x86/tdx: Add TDX Guest event notify interrupt support Kuppuswamy Sathyanarayanan
2023-04-14 13:34 ` Huang, Kai [this message]
2023-04-25 23:47 ` Sathyanarayanan Kuppuswamy
2023-04-26 1:59 ` Huang, Kai
2023-04-26 6:07 ` Sathyanarayanan Kuppuswamy
2023-04-28 13:50 ` Huang, Kai
2023-04-13 3:41 ` [PATCH v2 2/3] virt: tdx-guest: Add Quote generation support Kuppuswamy Sathyanarayanan
2023-04-26 15:40 ` Dionna Amalie Glaze
2023-04-27 18:27 ` Sathyanarayanan Kuppuswamy
2023-04-28 1:29 ` Dionna Amalie Glaze
2023-04-28 13:49 ` Huang, Kai
2023-05-01 6:03 ` Sathyanarayanan Kuppuswamy
2023-05-01 12:48 ` Huang, Kai
2023-05-04 7:12 ` Sathyanarayanan Kuppuswamy
2023-05-04 12:00 ` Huang, Kai
2023-05-02 22:27 ` Chong Cai
2023-04-13 3:41 ` [PATCH v2 3/3] selftests/tdx: Test GetQuote TDX attestation feature Kuppuswamy Sathyanarayanan
2023-04-26 15:47 ` Dionna Amalie Glaze
2023-04-27 19:10 ` Sathyanarayanan Kuppuswamy
2023-04-27 19:56 ` Dave Hansen
2023-04-27 19:53 ` Dave Hansen
2023-05-10 0:10 ` [PATCH v2 0/3] TDX Guest Quote generation support Erdem Aktas
2023-05-10 0:14 ` Sathyanarayanan Kuppuswamy
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=632a9a27abb5da053caedbbc6bcb7d5e15b2322c.camel@intel.com \
--to=kai.huang@intel.com \
--cc=bp@alien8.de \
--cc=chongc@google.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=dionnaglaze@google.com \
--cc=erdemaktas@google.com \
--cc=fan.du@intel.com \
--cc=guorui.yu@linux.alibaba.com \
--cc=hpa@zytor.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=qinkun@apache.org \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=wander@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox