All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <graf@amazon.com>
To: Jim Mattson <jmattson@google.com>
Cc: Aaron Lewis <aaronlewis@google.com>,
	Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>,
	kvm list <kvm@vger.kernel.org>
Subject: Re: [PATCH v3 04/12] KVM: x86: Add ioctl for accepting a userspace provided MSR list
Date: Thu, 20 Aug 2020 23:49:36 +0200	[thread overview]
Message-ID: <c9ea8956-69e1-ae28-888a-06f230a84a53@amazon.com> (raw)
In-Reply-To: <CALMp9eT5_zq52kzQjSM2gK=oQ1UMFNZhNgK0px=Y2FLzxHxqhA@mail.gmail.com>

Hi Jim,

On 20.08.20 19:30, Jim Mattson wrote:
> 
> 
> On Wed, Aug 19, 2020 at 2:00 AM Alexander Graf <graf@amazon.com> wrote:
> 
>> Why would we still need this with the allow list and user space #GP
>> deflection logic in place?
> 
> Conversion to an allow list is cumbersome when you have a short deny
> list. Suppose that I want to implement the following deny list:
> {IA32_ARCH_CAPABILITIES, HV_X64_MSR_REFERENCE_TSC,
> MSR_GOOGLE_TRUE_TIME, MSR_GOOGLE_FDR_TRACE, MSR_GOOGLE_HBI}. What
> would the corresponding deny list look like? Given your current
> implementation, I don't think the corresponding allow list can
> actually be constructed. I want to allow 2^32-5 MSRs, but I can allow
> at most 122880, if I've done the math correctly. (10 ranges, each
> spanning at most 0x600 bytes worth of bitmap.)

There are only very few MSR ranges that actually data. So in your case, 
to allow all MSRs that Linux knows about in msr-index.h, you would need

   [0x00000000 - 0x00002000]
   [0x40000000 - 0x40000200]
   [0x4b564d00 - 0x4b564e00]
   [0x80868000 - 0x80868020]
   [0xc0000000 - 0xc0000200]
   [0xc0010000 - 0xc0012000]
   [0xc0020000 - 0xc0020010]

which are 7 regions. For good measure, you can probably pad every one of 
them to the full 0x3000 MSRs they can span.

For MSRs that KVM actually handles in-kernel (others don't need to be 
allowed), the list shrinks to 5:

   [0x00000000 - 0x00001000]
   [0x40000000 - 0x40000200]
   [0x4b564d00 - 0x4b564e00]
   [0xc0000000 - 0xc0000200]
   [0xc0010000 - 0xc0012000]

Let's extend them a bit to make reasoning easier:

   [0x00000000 - 0x00003000]
   [0x40000000 - 0x40003000]
   [0x4b564d00 - 0x4b567000]
   [0xc0000000 - 0xc0003000]
   [0xc0010000 - 0xc0013000]

What are the odds that you will want to implicitly (without a new CAP, 
that would need user space adjustments anyway) have a random new MSR 
handled in-kernel with an identifier that is outside of those ranges?

I'm fairly confident that trends towards 0.

The only real downside I can see is that we just wasted ~8kb of RAM. 
Nothing I would really get hung up on though.

> Perhaps we should adopt allow/deny rules similar to those accepted by
> most firewalls. Instead of ports, we have MSR indices. Instead of
> protocols, we have READ, WRITE, or READ/WRITE. Suppose that we
> supported up to <n> rules of the form: {start index, end index, access
> modes, allow or deny}? Rules would be processed in the order given,
> and the first rule that matched a given access would take precedence.
> Finally, userspace could specify the default behavior (either allow or
> deny) for any MSR access that didn't match any of the rules.
> 
> Thoughts?

That wouldn't scale well if you want to allow all architecturally useful 
MSRs in a purely allow list fashion. You'd have to create hundreds of 
rules - or at least a few dozen if you combine contiguous ranges.

If you really desperately believe a deny list is a better fit for your 
use case, we could redesign the interface differently:

struct msr_set_accesslist {
#define MSR_ACCESSLIST_DEFAULT_ALLOW 0
#define MSR_ACCESSLIST_DEFAULT_DENY  1
     u32 flags;
     struct {
         u32 flags;
         u32 nmsrs; /* MSRs in bitmap */
         u32 base; /* first MSR address to bitmap */
         void *bitmap; /* pointer to bitmap, 1 means allow, 0 deny */
     } lists[10];
};

which means in your use case, you can do

u64 deny = 0;
struct msr_set_accesslist access = {
     .flags = MSR_ACCESSLIST_DEFAULT_ALLOW,
     .lists = {
         {
             .nmsrs = 1,
             .base = IA32_ARCH_CAPABILITIES,
             .bitmap = &deny,
         }, {
         {
             .nmsrs = 1,
             .base = HV_X64_MSR_REFERENCE_TSC,
             .bitmap = &deny,
         }, {
         {
             .nmsrs = 1,
             /* can probably be combined with the ones below? */
             .base = MSR_GOOGLE_TRUE_TIME,
             .bitmap = &deny,
         }, {
         {
             .nmsrs = 1,
             .base = MSR_GOOGLE_FDR_TRACE,
             .bitmap = &deny,
         }, {
         {
             .nmsrs = 1,
             .base = MSR_GOOGLE_HBI,
             .bitmap = &deny,
         },
     }
};

msr_set_accesslist(kvm_fd, &access);

while I can do the same dance as before, but with a single call rather 
than multiple ones.

What do you think?


Alex



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879



  reply	other threads:[~2020-08-20 21:49 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-18 21:15 [PATCH v3 00/12] Allow userspace to manage MSRs Aaron Lewis
2020-08-18 21:15 ` [PATCH v3 01/12] KVM: x86: Deflect unknown MSR accesses to user space Aaron Lewis
2020-08-19  8:42   ` Alexander Graf
2020-08-18 21:15 ` [PATCH v3 02/12] KVM: x86: Introduce allow list for MSR emulation Aaron Lewis
2020-08-19  8:53   ` Alexander Graf
2020-08-31 10:39   ` Dan Carpenter
2020-08-31 10:39     ` Dan Carpenter
2020-08-31 10:39     ` Dan Carpenter
2020-09-01 19:13     ` Alexander Graf
2020-09-02  7:31       ` Dan Carpenter
2020-09-02  7:31         ` Dan Carpenter
2020-09-02  7:31         ` Dan Carpenter
2020-08-18 21:15 ` [PATCH v3 03/12] KVM: selftests: Add test for user space MSR handling Aaron Lewis
2020-08-18 21:15 ` [PATCH v3 04/12] KVM: x86: Add ioctl for accepting a userspace provided MSR list Aaron Lewis
2020-08-19  9:00   ` Alexander Graf
2020-08-20 17:30     ` Jim Mattson
2020-08-20 21:49       ` Alexander Graf [this message]
2020-08-20 22:28         ` Jim Mattson
2020-08-18 21:15 ` [PATCH v3 05/12] KVM: x86: Add support for exiting to userspace on rdmsr or wrmsr Aaron Lewis
2020-08-19 10:25   ` Alexander Graf
2020-08-20 18:17   ` Jim Mattson
2020-08-20 21:59     ` Alexander Graf
2020-08-20 22:55       ` Jim Mattson
2020-08-21 17:58         ` Jim Mattson
2020-08-24  1:35           ` Alexander Graf
2020-08-24 17:23             ` Jim Mattson
2020-08-24 18:09               ` Alexander Graf
2020-08-24 18:34                 ` Jim Mattson
2020-08-18 21:15 ` [PATCH v3 06/12] KVM: x86: Prepare MSR bitmaps for userspace tracked MSRs Aaron Lewis
2020-08-18 21:15 ` [PATCH v3 07/12] KVM: x86: Ensure the MSR bitmap never clears " Aaron Lewis
2020-08-19  1:12   ` kernel test robot
2020-08-19  1:12     ` kernel test robot
2020-08-19  1:12   ` [RFC PATCH] KVM: x86: vmx_set_user_msr_intercept() can be static kernel test robot
2020-08-19  1:12     ` kernel test robot
2020-08-19 15:26   ` [PATCH v3 07/12] KVM: x86: Ensure the MSR bitmap never clears userspace tracked MSRs Alexander Graf
2020-08-20  0:18     ` Aaron Lewis
2020-08-20 22:04       ` Alexander Graf
2020-08-20 22:35         ` Jim Mattson
2020-08-21 14:27           ` Aaron Lewis
2020-08-21 16:07             ` Alexander Graf
2020-08-21 16:43               ` Aaron Lewis
2020-08-26 15:48   ` kernel test robot
2020-08-26 15:48     ` kernel test robot
2020-08-18 21:15 ` [PATCH v3 08/12] selftests: kvm: Fix the segment descriptor layout to match the actual layout Aaron Lewis
2020-08-18 21:15 ` [PATCH v3 09/12] selftests: kvm: Clear uc so UCALL_NONE is being properly reported Aaron Lewis
2020-08-19  9:13   ` Andrew Jones
2020-08-18 21:15 ` [PATCH v3 10/12] selftests: kvm: Add exception handling to selftests Aaron Lewis
2020-08-18 21:15 ` [PATCH v3 11/12] selftests: kvm: Add a test to exercise the userspace MSR list Aaron Lewis
2020-08-18 21:15 ` [PATCH v3 12/12] selftests: kvm: Add emulated rdmsr, wrmsr tests Aaron Lewis

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=c9ea8956-69e1-ae28-888a-06f230a84a53@amazon.com \
    --to=graf@amazon.com \
    --cc=aaronlewis@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=oupton@google.com \
    --cc=pshier@google.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.