All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Michael Kelley <mikelley@microsoft.com>
Cc: "linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>
Subject: Re: ** POTENTIAL FRAUD ALERT - RED HAT ** Checking Hyper-V hypercall status
Date: Tue, 09 Feb 2021 17:50:46 +0100	[thread overview]
Message-ID: <87lfbxmbh5.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <MWHPR21MB159399C0A82E28CE9A9B93DBD78E9@MWHPR21MB1593.namprd21.prod.outlook.com>

Michael Kelley <mikelley@microsoft.com> writes:

> As noted in a previous email, we don't have a consistent
> pattern for checking Hyper-V hypercall status.  Existing code and
> recent new code uses a number of variants.  The variants work, but
> a consistent pattern would improve the readability of the code, and
> be more conformant to what the Hyper-V TLFS says about hypercall
> status.  In particular, the 64 bit hypercall status contains fields that
> the TLFS says should be ignored -- evidently they are not guaranteed
> to be zero (though I've never seen otherwise).
>
> I'd propose the following helper functions to go in
> asm-generic/mshyperv.h.  The function names are relatively short
> for readability:
>
> static inline u64 hv_result(u64 status)
> {
> 	return status & HV_HYPERCALL_RESULT_MASK;
> }
>
> static inline bool hv_result_success(u64 status)
> {
> 	return hv_result(status) == HV_STATUS_SUCCESS;
> }
>
> static inline unsigned int hv_repcomp(u64 status)
> {
> 	return (status & HV_HYPERCALL_REP_COMP_MASK) >>
> 			HV_HYPERCALL_REP_COMP_OFFSET;
> }
>
> The hv_do_hypercall() function (and its 'rep' and 'fast' variants) should
> always assign the result to a u64 local variable, which is the return
> type of the functions.  Then the above functions can act on that local
> variable.  Here are some examples:
>
> 	u64		status;
> 	unsigned int	completed;
>
> 	status = hv_do_hypercall(<some args>);
> 	if (!hv_result_success(status)) {
> 		<handle error case>
> 	}
>
> 	status = hv_do_rep_hypercall(<some args>);
> 	if (hv_result(status) == HV_STATUS_INSUFFICIENT_MEMORY) {
> 		<deposit more memory pages>
> 		goto retry;
> 	} else if (!hv_result_success(status)) {
> 		<handle error case>
> 	}
> 	completed = hv_repcomp(status);
>
>
> Thoughts?

Personally, I like it and think it's going to be sufficient.

Alternatively, I can suggest we introduce something like 

struct hv_result {
	u64 status:16;
	u64 rsvd1:16;
	u64 reps_comp:12;
	u64 rsvd1:20;
};

and make hv_do_rep_hypercall() return it. So the code above will look
like:

	struct hv_result result;

	result = hv_do_rep_hypercall(<some args>);
        if (result.status) == HV_STATUS_INSUFFICIENT_MEMORY) {
                <deposit more memory pages>
                goto retry;
        } else if (result.status != HV_STATUS_SUCCESS) {
                <handle error case>
        }
        completed = result.reps_comp;

-- 
Vitaly


  reply	other threads:[~2021-02-09 16:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 15:45 Checking Hyper-V hypercall status Michael Kelley
2021-02-09 16:50 ` Vitaly Kuznetsov [this message]
2021-02-10 16:45 ` Wei Liu

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=87lfbxmbh5.fsf@vitty.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    /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.