mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roman Kisel <romank@linux.microsoft.com>
To: Michael Kelley <mhklinux@outlook.com>,
	Saurabh Singh Sengar <ssengar@microsoft.com>,
	Naman Jain <namjain@linux.microsoft.com>,
	KY Srinivasan <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>
Cc: Anirudh Rayabharam <anrayabh@linux.microsoft.com>,
	Saurabh Sengar <ssengar@linux.microsoft.com>,
	Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>,
	Nuno Das Neves <nunodasneves@linux.microsoft.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>
Subject: Re: [PATCH] Drivers: hv: Introduce mshv_vtl driver
Date: Thu, 8 May 2025 08:34:00 -0700	[thread overview]
Message-ID: <718eaa5a-a021-469d-9053-f622a53422b9@linux.microsoft.com> (raw)
In-Reply-To: <SN6PR02MB4157D124B1AF145E06431BD2D48BA@SN6PR02MB4157.namprd02.prod.outlook.com>



On 5/7/2025 9:03 PM, Michael Kelley wrote:
> From: Roman Kisel <romank@linux.microsoft.com> Sent: Wednesday, May 7, 2025 12:21 PM
>>
>> On 5/7/2025 6:02 AM, Saurabh Singh Sengar wrote:
>>>
>> [..]
>>
>>>> +	}
>>>> +
>>>> +	local_irq_save(flags);
>>>> +	in = *this_cpu_ptr(hyperv_pcpu_input_arg);
>>>> +	out = *this_cpu_ptr(hyperv_pcpu_output_arg);
>>>> +
>>>> +	if (copy_from_user(in, (void __user *)hvcall.input_ptr,
>>>> hvcall.input_size)) {
>>>
>>> Here is an issue related to usage of user copy functions when interrupt are disabled.
>>> It was reported by Michael K here:
>>>
>>> https://github.com/microsoft/OHCL-Linux-Kernel/issues/33
>>
>>   From the practical point of view, that memory will be touched by the
>> user mode by virtue of Rust requiring initialization so the a possible
>> page fault would be resolved before the IOCTL. OpenHCL runs without swap
>> so the the memory will not be paged out to require page faults to be
>> brought in back.
>>
>> I do agree that might be turned into a footgun by the user land if
>> they malloc a page w/o prefaulting (so it's just a VA range, not backed
>> with the physical page), and then send its address straight over here
>> right after w/o writing any data to it. Perhaps likelier with the output
>> data. Anyway, yes, relying on the user land doing sane things isn't
>> the best approach to the kernel programming.
>>
>> If we're inclined to fix this, I'd encourage to take an approach that
>> works for the confidential VMs as well so we don't have to fix that
>> again when start upstreaming what we have for SNP and TDX. The
>> allocation *must* be visible to the hypervisor in the confidential
>> scenarios.
>>
>> Or, maybe we could avoid the allocations by reading the first byte
>> of the user land buffer to "pre-fault" the page outside of the
>> scope that disables interrupts. Why allocate if we can avoid that?
>> Could set up also the SMP remote calls to run this on the desired
>> CPU.
>>
>> Summarizing for the case you want to change this:
>>
>> 1. Keep interrupts disabled when reading/writing to/from the Hyper-V
>>      driver allocated input and output pages.
>> 2. If you decide to allocate separate pages, make sure they are
>>      visible to the hypervisor in the confidential scenarios. I know
>>      we're not talking SNP and TDX here just yet but it would be
>>      a waste of time imho to build something here and scrape that
>>      later. The issues with allocations are:
>>          a) If allocating on-demand, we might fail the hypercall
>>             because of OOM. That's certainly bad as the whole VM
>>             will break down.
>>          b) If allocating for the whole lifetime of the VM,
>>             let us remember that we avoid using hypercalls
>>             due to their runtime cost. We'll be keeping around
>>             2 pages per CPU for the few times we need them.
>> 3. Consider reading a byte from the user land buffers to make the page
>>      fault happen outside of disabling interrupts. There is no
>>      outswap (maybe could have disabling swap in Kconfig) so the page
>>      will stay in the memory.
>>
>> If you're not changing this, feel free to keep my "Reviewed-by".
>>
> 
> Regardless of what might be done to prevent a page fault, I don't
> see an option to not fix this. copy_from_user() contains a call to
> might_fault(), which in turn calls might_sleep(). The intent of these
> runtime "annotations" is precisely for the kernel to check for such
> errors and complain about them. The complaining is suppressed unless
> CONFIG_DEBUG_ATOMIC_SLEEP is set, but we want to be able to
> set that option for debugging purposes and not have this code
> generating complaints.

I outlined the practical point of view above to emphasize that the
existing code works very well (millions of VMs, and there is health
monitoring in place) thanks to running as a firmware and the tooling.
The VTL2 driver is run and useful only in that environment.

I agree that this approach might raise eyebrows and, as evidenced,
entails some arguing. If you must insist, perhaps for the sake of that
code looking more conventional for the reader we could tweak this.
If that's the choice, keeping this path lean should be the goal in
my opinion.

> 
> Michael

-- 
Thank you,
Roman


  reply	other threads:[~2025-05-08 15:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06  8:49 Naman Jain
2025-05-06 15:48 ` Roman Kisel
2025-05-07 10:19 ` Saurabh Singh Sengar
2025-05-07 11:21   ` Naman Jain
2025-05-07 20:31     ` Roman Kisel
2025-05-08  3:00       ` Saurabh Singh Sengar
2025-05-08 15:44         ` Roman Kisel
2025-05-08 17:44           ` Wei Liu
2025-05-08 18:13             ` Roman Kisel
2025-05-07 13:02 ` Saurabh Singh Sengar
2025-05-07 19:20   ` Roman Kisel
2025-05-08  2:59     ` Saurabh Singh Sengar
2025-05-09 18:07       ` Roman Kisel
2025-05-08  4:03     ` Michael Kelley
2025-05-08 15:34       ` Roman Kisel [this message]
2025-05-08 18:03     ` Wei Liu
2025-05-09 18:02       ` [EXTERNAL] " Saurabh Singh Sengar
2025-05-09 18:05         ` Roman Kisel
2025-05-12  4:57           ` Naman Jain
2025-05-13 15:30           ` Michael Kelley
2025-05-13 16:34             ` Naman Jain
2025-05-12  4:55   ` Naman Jain
2025-05-10 20:55 ` [External] : " ALOK TIWARI
2025-05-12 14:04   ` Naman Jain

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=718eaa5a-a021-469d-9053-f622a53422b9@linux.microsoft.com \
    --to=romank@linux.microsoft.com \
    --cc=anrayabh@linux.microsoft.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=namjain@linux.microsoft.com \
    --cc=nunodasneves@linux.microsoft.com \
    --cc=skinsburskii@linux.microsoft.com \
    --cc=ssengar@linux.microsoft.com \
    --cc=ssengar@microsoft.com \
    --cc=wei.liu@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

all inboxes | Powered by JetHome®