qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Janosch Frank <frankja@linux.ibm.com>
To: David Hildenbrand <david@redhat.com>, qemu-devel@nongnu.org
Cc: borntraeger@de.ibm.com, qemu-s390x@nongnu.org, cohuck@redhat.com
Subject: Re: [PATCH v8 2/2] s390x: protvirt: Support unpack facility
Date: Tue, 10 Mar 2020 10:23:49 +0100	[thread overview]
Message-ID: <a7f478fa-3181-63fc-ce65-4006d64098b0@linux.ibm.com> (raw)
In-Reply-To: <100bd846-61f1-973b-b97f-753463646e68@redhat.com>


[-- Attachment #1.1: Type: text/plain, Size: 8036 bytes --]

On 3/10/20 10:00 AM, David Hildenbrand wrote:
> On 10.03.20 09:32, Janosch Frank wrote:
>> The unpack facility provides the means to setup a protected guest. A
>> protected guest can not be introspected by the hypervisor or any
>> user/administrator of the machine it is running on.
>>
>> Protected guests are encrypted at rest and need a special boot
>> mechanism via diag308 subcode 8 and 10.
>>
>> Code 8 sets the PV specific IPLB which is retained seperately from
>> those set via code 5.
>>
>> Code 10 is used to unpack the VM into protected memory, verify its
>> integrity and start it.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> Co-developed-by: Christian Borntraeger <borntraeger@de.ibm.com> [Changes
>> to machine]
> 
> [...]
> 
> 
>> diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c
>> new file mode 100644
>> index 0000000000..ba6409246e
>> --- /dev/null
>> +++ b/hw/s390x/pv.c
>> @@ -0,0 +1,104 @@
>> +/*
>> + * Secure execution functions
> 
> Protected virtualization ;)

Ack

> 
>> + *
>> + * Copyright IBM Corp. 2020
>> + * Author(s):
>> + *  Janosch Frank <frankja@linux.ibm.com>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or (at
>> + * your option) any later version. See the COPYING file in the top-level
>> + * directory.
>> + */
> 
> [...]
> 
>>  S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
>>  {
>> @@ -238,9 +240,11 @@ static void s390_create_sclpconsole(const char *type, Chardev *chardev)
>>  static void ccw_init(MachineState *machine)
>>  {
>>      int ret;
>> +    S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
>>      VirtualCssBus *css_bus;
>>      DeviceState *dev;
>>  
>> +    ms->pv = false;
> 
> As discussed, not needed.

Ack

> 
>>      s390_sclp_init();
>>      /* init memory + setup max page size. Required for the CPU model */
>>      s390_memory_init(machine->ram);
>> @@ -316,10 +320,88 @@ static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
>>      s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
>>  }
>>  
>> +static void s390_machine_unprotect(S390CcwMachineState *ms)
>> +{
>> +    CPUState *t;
>> +
>> +    s390_pv_vm_disable();
>> +    CPU_FOREACH(t) {
>> +        S390_CPU(t)->env.pv = false;
>> +    }
> 
> See below, would be great if we can get rid of env.pv IMHO.
> 
> [...]

I'll have a look

> 
>> +    case S390_RESET_PV: /* Subcode 10 */
>> +        subsystem_reset();
>> +        s390_crypto_reset();
>> +
>> +        CPU_FOREACH(t) {
>> +            if (t == cs) {
>> +                continue;
>> +            }
>> +            run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
>> +        }
>> +        run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
>> +
>> +        if (s390_machine_protect(ms)) {
>> +            s390_machine_inject_pv_error(cs);
>> +            /*
>> +             * Continue after the diag308 so the guest knows something
>> +             * went wrong.
>> +             */
>> +            s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
>> +            return;
> 
> Didn't you want to squash in that hunk from the other patch? (I remember
> seeing a goto)

I chose to leave it this way so we don't jump around with the goto

> 
>> +        }
>> +
>>          run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
>>          break;
>>      default:
> 
> [...]
> 
>>  
>> +#if !defined(CONFIG_USER_ONLY)
>> +static bool machine_is_pv(MachineState *ms)
>> +{
>> +    static S390CcwMachineState *ccw;
>> +    Object *obj;
>> +
>> +    if (ccw)
>> +	    return ccw->pv;
> 
> missing {}
> 
>> +
>> +    /* we have to bail out for the "none" machine */
>> +    obj = object_dynamic_cast(OBJECT(ms), TYPE_S390_CCW_MACHINE);
>> +     if (!obj) {
>> +        return false;
>> +    }
>> +    ccw = S390_CCW_MACHINE(obj);
>> +    return ccw->pv;
>> +}
>> +#endif
> 
> Now that we talked about cached values, what about
> 
> #if !defined(CONFIG_USER_ONLY)
> static bool s390_is_pv(void)
> {
>     static S390CcwMachineState *ccw;
>     Object *obj;
> 
>     if (ccw) {
>         return ccw->pv;
>     }
> 
>     /* we have to bail out for the "none" machine */
>     obj = object_dynamic_cast(qdev_get_machine(),
>                               TYPE_S390_CCW_MACHINE);
>     if (!obj) {
>         return false;
>     }
>     ccw = S390_CCW_MACHINE(obj);
>     return ccw->pv;
> }
> #endif
> 
> and drop all env->pv checks, replacing them by s390_is_pv(). (sorry,
> should have recommended that earlier)

Fine by me.
@Christian: Opinions?

> 
>> +
>>  static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
>>  {
>>      CPUState *cs = CPU(dev);
>> @@ -205,6 +226,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
>>          goto out;
>>      }
>>  
>> +    cpu->env.pv = machine_is_pv(ms);
>>      /* sync cs->cpu_index and env->core_id. The latter is needed for TCG. */
>>      cs->cpu_index = cpu->env.core_id;
>>  #endif
>> diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
>> index 1d17709d6e..7e4d9d267c 100644
>> --- a/target/s390x/cpu.h
>> +++ b/target/s390x/cpu.h
>> @@ -114,6 +114,7 @@ struct CPUS390XState {
>>  
>>      /* Fields up to this point are cleared by a CPU reset */
>>      struct {} end_reset_fields;
>> +    bool pv; /* protected virtualization */
>>  
>>  #if !defined(CONFIG_USER_ONLY)
>>      uint32_t core_id; /* PoP "CPU address", same as cpu_index */
>> diff --git a/target/s390x/cpu_features_def.inc.h b/target/s390x/cpu_features_def.inc.h
>> index 31dff0d84e..60db28351d 100644
>> --- a/target/s390x/cpu_features_def.inc.h
>> +++ b/target/s390x/cpu_features_def.inc.h
>> @@ -107,6 +107,7 @@ DEF_FEAT(DEFLATE_BASE, "deflate-base", STFL, 151, "Deflate-conversion facility (
>>  DEF_FEAT(VECTOR_PACKED_DECIMAL_ENH, "vxpdeh", STFL, 152, "Vector-Packed-Decimal-Enhancement Facility")
>>  DEF_FEAT(MSA_EXT_9, "msa9-base", STFL, 155, "Message-security-assist-extension-9 facility (excluding subfunctions)")
>>  DEF_FEAT(ETOKEN, "etoken", STFL, 156, "Etoken facility")
>> +DEF_FEAT(UNPACK, "unpack", STFL, 161, "Unpack facility")
> 
> Random thought: The naming of that facility could have been improved to
> something that gives users/readers an idea what it's actually doing.

That's the name from our specifications and with those feature bits we
normally use the facility names from those docs, no?
Something like "protected guest boot facility" would certainly have been
better to understand.

> 
> 
> [...]
> 
>> @@ -128,17 +142,31 @@ out:
>>          g_free(iplb);
>>          return;
>>      case DIAG308_STORE:
>> +    case DIAG308_PV_STORE:
>>          if (diag308_parm_check(env, r1, addr, ra, true)) {
>>              return;
>>          }
>> -        iplb = s390_ipl_get_iplb();
>> +        if (subcode == DIAG308_PV_STORE) {
>> +            iplb = s390_ipl_get_iplb_pv();
>> +        } else {
>> +            iplb = s390_ipl_get_iplb();
>> +        }
>>          if (iplb) {
>>              cpu_physical_memory_write(addr, iplb, be32_to_cpu(iplb->len));
>>              env->regs[r1 + 1] = DIAG_308_RC_OK;
>>          } else {
>>              env->regs[r1 + 1] = DIAG_308_RC_NO_CONF;
>>          }
>> -        return;
>> +        break;
> 
> return->break is unrelated, but we do have a wild mixture already.

I removed it here and in the move diag structures over SIDA patch.
After this has been merged I can do a cleanup patch if wanted.

> 
>> +    case DIAG308_PV_START:
>> +        iplb = s390_ipl_get_iplb_pv();
>> +        if (!iplb) {
>> +            env->regs[r1 + 1] = DIAG_308_RC_NO_PV_CONF;
>> +            return;
>> +        }
>> +
>> +        s390_ipl_reset_request(cs, S390_RESET_PV);
>> +        break;
>>      default:
>>          s390_program_interrupt(env, PGM_SPECIFICATION, ra);
>>          break;
>>
> 
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2020-03-10  9:25 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 11:21 [PATCH v7 00/15] s390x: Protected Virtualization support Janosch Frank
2020-03-09 11:21 ` [PATCH v7 01/15] Sync pv Janosch Frank
2020-03-09 11:21 ` [PATCH v7 02/15] s390x: protvirt: Support unpack facility Janosch Frank
2020-03-09 13:37   ` David Hildenbrand
2020-03-09 14:40     ` Christian Borntraeger
2020-03-09 14:42       ` David Hildenbrand
2020-03-10  9:27       ` Christian Borntraeger
2020-03-09 15:42     ` Janosch Frank
2020-03-09 15:48       ` David Hildenbrand
2020-03-10  8:32     ` [PATCH v8 1/2] s390x: ipl: Consolidate iplb validity check into one function Janosch Frank
2020-03-10  8:32       ` [PATCH v8 2/2] s390x: protvirt: Support unpack facility Janosch Frank
2020-03-10  9:00         ` David Hildenbrand
2020-03-10  9:23           ` Janosch Frank [this message]
2020-03-10  9:28             ` David Hildenbrand
2020-03-10  9:24           ` Christian Borntraeger
2020-03-10  8:40       ` [PATCH v8 1/2] s390x: ipl: Consolidate iplb validity check into one function David Hildenbrand
2020-03-10  9:05       ` Christian Borntraeger
2020-03-10  9:09         ` [PATCH v8] " Janosch Frank
2020-03-10  9:11           ` Christian Borntraeger
2020-03-10  9:20             ` David Hildenbrand
2020-03-10  9:21           ` Christian Borntraeger
2020-03-09 14:28   ` [PATCH v7 02/15] s390x: protvirt: Support unpack facility Viktor Mihajlovski
2020-03-09 14:46     ` Janosch Frank
2020-03-09 11:21 ` [PATCH v7 03/15] s390x: protvirt: Add migration blocker Janosch Frank
2020-03-09 13:41   ` David Hildenbrand
2020-03-09 13:51     ` Janosch Frank
2020-03-09 14:15       ` David Hildenbrand
2020-03-09 11:21 ` [PATCH v7 04/15] s390x: protvirt: Inhibit balloon when switching to protected mode Janosch Frank
2020-03-09 13:42   ` David Hildenbrand
2020-03-09 14:00     ` Janosch Frank
2020-03-09 11:21 ` [PATCH v7 05/15] s390x: protvirt: KVM intercept changes Janosch Frank
2020-03-09 11:21 ` [PATCH v7 06/15] s390x: Add SIDA memory ops Janosch Frank
2020-03-09 11:21 ` [PATCH v7 07/15] s390x: protvirt: Move STSI data over SIDAD Janosch Frank
2020-03-09 11:21 ` [PATCH v7 08/15] s390x: protvirt: SCLP interpretation Janosch Frank
2020-03-09 15:27   ` David Hildenbrand
2020-03-09 16:05     ` Janosch Frank
2020-03-10  8:42     ` [PATCH v8] " Janosch Frank
2020-03-10  9:01       ` David Hildenbrand
2020-03-09 11:22 ` [PATCH v7 09/15] s390x: protvirt: Set guest IPL PSW Janosch Frank
2020-03-09 11:22 ` [PATCH v7 10/15] s390x: protvirt: Move diag 308 data over SIDA Janosch Frank
2020-03-09 11:22 ` [PATCH v7 11/15] s390x: protvirt: Disable address checks for PV guest IO emulation Janosch Frank
2020-03-09 11:22 ` [PATCH v7 12/15] s390x: protvirt: Move IO control structures over SIDA Janosch Frank
2020-03-09 11:22 ` [PATCH v7 13/15] s390x: protvirt: Handle SIGP store status correctly Janosch Frank
2020-03-09 11:22 ` [PATCH v7 14/15] docs: Add protvirt docs Janosch Frank
2020-03-09 11:22 ` [PATCH v7 15/15] s390x: Add unpack facility feature to GA1 Janosch Frank

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=a7f478fa-3181-63fc-ce65-4006d64098b0@linux.ibm.com \
    --to=frankja@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.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;
as well as URLs for NNTP newsgroup(s).