Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp815069pxb; Tue, 12 Apr 2022 14:12:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0Z99C3uniyV3cUTwddEQkcPAhsD1coHd3WoCsFPFrhgf/PmDfmZwYXH963EFpY6/abw6v X-Received: by 2002:a65:6051:0:b0:39d:1b00:e473 with SMTP id a17-20020a656051000000b0039d1b00e473mr14908465pgp.578.1649797956297; Tue, 12 Apr 2022 14:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649797956; cv=none; d=google.com; s=arc-20160816; b=sRwAXJuAbG+OIXxhduh0teT4k8d4xwHPY4K3ii9oOra2Y08n5My0zTzWSb73feacHy wJzQOK6/qn6Et1m16hn4ywL/A+MeNnCkSmDhJ9TOPD8VT9/iPSvnFj89K6Q4JMaa8Ao4 K1h42tlh9GDAAIuky9VHsyaQynXyLhoHxBdnx5xgYeTBK5O/1Ecg/AmdPZOkaeq4goUz 3MfUB1FWigLH0jRUZxgpB8cpnDNwkQipqElLghTmELIxmpvoBH779lN3kGvKcn+b8ACb 1hvXnz8e+fT1b5HoMxiGoDyKpZuz01wAFxMJZmGWgxOx2HQastt0VbJQgSLI3d6NR8Lu 1tXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dPdu8Eiipa0SimY9s3UtwwUyWmEESIKixwaOvVsXgGk=; b=rtqAR07Qcybw3xjgBnivsjdFdHs0Cs3p+lYbRU0lbM3VzLbhqAL8pfrAFUw1OUFjs+ nCZj0PU2zuC2V5m+duNvNh0fW7pzEKarAvtqfCnY/JNig17ODDoYCEXuDqZHMRR6lEuW 7qxXH23+9nKtmwEVQ4nHkwvjinpqEO0HLn3AW/V/TCimh9fMDMwTh61OaXb49gIka4CG LERhJ/wuW67tAVcNnPrGN4mRSqY8wtTYY/ogxDMceeuILckUuI+7XasGx5kSfFbrNnmv Q55ZdNk+yYDrwPqD6EBMZjuqrr/AJmOrH6n+9Waquiiw3Bw1+TEk9tvBrVuLiXpnctzv oqdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fPoN4PzX; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id w9-20020a17090a8a0900b001caa43d9645si11973754pjn.95.2022.04.12.14.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 14:12:36 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fPoN4PzX; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2A573E7F73; Tue, 12 Apr 2022 13:28:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347625AbiDKPJV (ORCPT + 99 others); Mon, 11 Apr 2022 11:09:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343773AbiDKPJT (ORCPT ); Mon, 11 Apr 2022 11:09:19 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD20DEE8 for ; Mon, 11 Apr 2022 08:07:03 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id nt14-20020a17090b248e00b001ca601046a4so18715128pjb.0 for ; Mon, 11 Apr 2022 08:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dPdu8Eiipa0SimY9s3UtwwUyWmEESIKixwaOvVsXgGk=; b=fPoN4PzXw5Nx0S16GH9zAA+N8qLMX77QH+IQL+Zro+uR5vWA6DYNpt+eA/Uykb4APB WvP+K888IGg5bWeBYo6xzTQUKqqbVBwoJjbblyalY/8FU2uumMLDW8eZA4DNwiGrkcYp iq7Vxnwr81oH96Y2xMlPpU+ssf9D9N8k900dgevGPB1KYn8kjhx0falLkyj/lzxmvgoc i3gBzCLTJeK+qdWEh1ISMXL+z3Vq3FFQM5qu3fYLKHoQ5zj4BCfAcZGDIFUvQT4VerGo 54eAV4pI3R1ZM+kOS04YHmgAPR16sp8rrRKH1sxuY+UWhexKq7ksyNxSGhPNLKglRrxP ZKDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dPdu8Eiipa0SimY9s3UtwwUyWmEESIKixwaOvVsXgGk=; b=tQispa1qK5TvCMxkGPXMJrQcGRfCLF3j9Zlbi35LipTOWmO0XJAPj724v5ENOUx/Jo U8ZCOpsyX0tJ18TGWAednWf2e9NNdy91Rp7LiQcyqwKLgqRydZxDZzog097UTl5C4qQA EgNKFqouRHIqN4S5KWXCyUds8bfQYPcOLDAwYA21E97/Lp8Fodd8cjrdWcznsze3e0Ej MD/ANCavik8c7qRiEMLNXo//GeGRA/mn5ASnHmLkEjQkfZiIl7tg5+aI1ogjkxcTI+gU lL/LUGlUzo21pKd8QCK87yF33buPsOZ7eIDZbmiGgkV+5CyljaRDLvCWIbSQwMjVrMTD KdFg== X-Gm-Message-State: AOAM533NsOQk196AMJwvZG5LL3yVsQCLjzj2Ev2WQzUCwFdU3wPsS2fM eoJuVj+gYyEjGzRW5ik25W8Qbg== X-Received: by 2002:a17:90a:7004:b0:1cb:55d6:9f23 with SMTP id f4-20020a17090a700400b001cb55d69f23mr16547316pjk.187.1649689622903; Mon, 11 Apr 2022 08:07:02 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id a9-20020aa78649000000b004fe3d6c1731sm22743924pfo.175.2022.04.11.08.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 08:07:02 -0700 (PDT) Date: Mon, 11 Apr 2022 15:06:58 +0000 From: Sean Christopherson To: Alexandru Elisei Cc: Will Deacon , Peter Gonda , kvm list , Paolo Bonzini , LKML , Anup Patel , maz@kernel.org Subject: Re: [PATCH v4.1] KVM, SEV: Add KVM_EXIT_SHUTDOWN metadata for SEV-ES Message-ID: References: <20220407210233.782250-1-pgonda@google.com> <20220411091213.GA2120@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 11, 2022, Alexandru Elisei wrote: > Hi, > > On Mon, Apr 11, 2022 at 10:12:13AM +0100, Will Deacon wrote: > > Hi Sean, > > > > Cheers for the heads-up. > > > > [+Marc and Alex as this looks similar to [1]] > > > > On Fri, Apr 08, 2022 at 05:01:21PM +0000, Sean Christopherson wrote: > > > system_event.flags is broken (at least on x86) due to the prior 'type' field not > > > being propery padded, e.g. userspace will read/write garbage if the userspace > > > and kernel compilers pad structs differently. > > > > > > struct { > > > __u32 type; > > > __u64 flags; > > > } system_event; > > > > On arm64, I think the compiler is required to put the padding between type > > and flags so that both the struct and 'flags' are 64-bit aligned [2]. Does > > x86 not offer any guarantees on the overall structure alignment? > > This is also my understanding. The "Procedure Call Standard for the Arm > 64-bit Architecture" [1] has these rules for structs (called "aggregates"): AFAIK, all x86 compilers will pad structures accordingly, but a 32-bit userspace running against a 64-bit kernel will have different alignment requirements, i.e. won't pad, and x86 supports CONFIG_KVM_COMPAT=y. And I have no idea what x86's bizarre x32 ABI does. > > > Our plan to unhose this is to change the struct as follows and use bit 31 in the > > > 'type' to indicate that ndata+data are valid. > > > > > > struct { > > > __u32 type; > > > __u32 ndata; > > > __u64 data[16]; > > > } system_event; > > > > > > Any objection to updating your architectures to use a helper to set the bit and > > > populate ndata+data accordingly? It'll require a userspace update, but v5.18 > > > hasn't officially released yet so it's not kinda sort not ABI breakage. > > > > It's a bit annoying, as we're using the current structure in Android 13 :/ > > Obviously, if there's no choice then upstream shouldn't worry, but it means > > we'll have to carry a delta in crosvm. Specifically, the new 'ndata' field > > is going to be unusable for us because it coincides with the padding. Yeah, it'd be unusuable for existing types. One idea is that we could define the ABI to be that the RESET and SHUTDOWN types have an implicit ndata=1 on arm64 and RISC-V. That would allow keeping the flags interpretation and so long as crosvm doesn't do something stupid like compile with "pragma pack" (does clang even support that?), there's no delta necessary for Android. > Just a thought, but wouldn't such a drastical change be better implemented > as a new exit_reason and a new associated struct? Maybe? I wasn't aware that arm64/RISC-V picked up usage of "flags" when I suggested this, but I'm not sure it would have changed anything. We could add SYSTEM_EVENT2 or whatever, but since there's no official usage of flags, it seems a bit gratutious.