Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81585C433DB for ; Wed, 10 Mar 2021 09:34:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0FB6C64FF2 for ; Wed, 10 Mar 2021 09:34:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FB6C64FF2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.95931.181146 (Exim 4.92) (envelope-from ) id 1lJvE1-0004Y1-EZ; Wed, 10 Mar 2021 09:33:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 95931.181146; Wed, 10 Mar 2021 09:33:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJvE1-0004Xu-BA; Wed, 10 Mar 2021 09:33:53 +0000 Received: by outflank-mailman (input) for mailman id 95931; Wed, 10 Mar 2021 09:33:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJvDz-0004Xn-FR for xen-devel@lists.xenproject.org; Wed, 10 Mar 2021 09:33:51 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d9b2f481-325c-4347-b85b-6796d5aa0264; Wed, 10 Mar 2021 09:33:50 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d9b2f481-325c-4347-b85b-6796d5aa0264 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1615368830; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=vUE9Zwwbm825ZnVQZ/NF2c62gs4Cjq8UGLO+t/md7EA=; b=T/jXuDLdOOAFEUt81uDpIQf1wIVObDzrLrno4ox2E7GzZyy5gByTe7Nu xDiO0CzpWTn2sviAty7mUKK2/6iDdxtGji6+Ib+MZ1Nm8Xgbr+/5a0bw3 e7PUcsGTcLPseMSsgnLAiHl3Bz5zmgBFKzO/7+K+AI9x2eQgyITKyTcJS 4=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: 1R+wBfQouc/GyzeMVpI50Rd7lJ/u1+pEVibCeJoVQoFE8CCP5Xt4s7/9GUVFIXcvtNy9UKeYwa rwuVROwQ/Fk4hLVzM36yotT9FVKzdD8z9KEtF51nYNEo5VI1gj1DvMD23cPEEVt0oG5jbiEZ8W m71jxb4FIyqUM5sCEWjfZQNRlUHOK3jhRwvtgDo9V/H6+6aga3TWc6HFv3RpLCJwup6O3woB5G uNreCh+38ErlOP5uPTp/Ii4J0mP8Wh8NS9jL9zUGfVpiJ/JgrLkIngIkthy73MfWWEgdl84nEa 7gk= X-SBRS: 5.2 X-MesageID: 38933019 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.81,237,1610427600"; d="scan'208";a="38933019" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cWS6NvuUmh/LZVubQs7IAWi5jlvol/+g7ICPn9V2uHQVIPwQ0+WULdVeg1delJXbDNx/3UR98lSN60vWs5kHxwrOWix3O2TE8JuGg4Sk7IfepSglrZ37LhuS3twXBUDJoA8q2cHno6+bQ7rgTJZGvzJGInYbc+tKDNGnJ33k87XkkF2o/oiuOj++PTnGA8XEzBmcRHrmmGtbEkAjZdEgB6eUKmjKYj0gvIT1WUeTdzyUxu8mfUz5hgaNZwzURdLzMzYlXW30mqvx4iZRXmn6W2ffsD/zFqg7GlfYdh4E1zeUuthUdiR3iFWudFpmIHcyXk6d22zefuGKC8Yy8t+C0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mkYzQmaI74fUYW98c90Ctctx2PFPCJPbIhEfdEsz2ig=; b=eZKnp8ss3zSZU6q2s5VngqcRNjk5TTyG47dTNZ4VIWjnnwXcbjqCdtEvdIe2+8xLLPvC2E5c54C5EWe5zH5QlcPz8W/oCqAB4/2e8EINHTOgC91dy/TB1sSpy4NtXgvMS9N9bQYxQXdOE1BzN6uyoU7Ilew2RGuDJIcHTd1+NgiWm4rs+18JiZlKxiIHFL9/r6NJD0BPDT45PcpOTnbLohXLaietGZeru27TG0laWwRgZjaGn8PoQ6LII+ztR/Qg0XVmCjYh2wkEsUtYdjgs1cmHjNfaxU4uNQfZtmr9n4LsoDS8SNtPDNzKcM46OnnKRvXqLetdpayYbr3nnyDlBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mkYzQmaI74fUYW98c90Ctctx2PFPCJPbIhEfdEsz2ig=; b=G0pHbQaA9PDpyTPf4XSNZ62B7ZwRhPzV4pD8ASW/bKOMLYDuvYL522BtQW98F+za6Yot/4sJakbPveXOLmUkrNWgz1nzESZc6QLJB9iNxHQPhnO5jHaMXp/ojWfmifs/DhcEY7Dhmm+Av8c716yAWz0axvmdAFa9NSi+qUwd4/w= Date: Wed, 10 Mar 2021 10:33:17 +0100 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Andrew Cooper CC: , Ian Jackson , "Wei Liu" , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Anthony PERARD , Christian Lindig , David Scott , Jun Nakajima , Kevin Tian , Boris Ostrovsky Subject: Re: [PATCH v3 for-4.15] x86/msr: introduce an option for compatible MSR behavior selection Message-ID: References: <20210309105634.7200-1-roger.pau@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: LO4P123CA0329.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18c::10) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aa3d6e46-b1ed-476a-5adb-08d8e3a78d0b X-MS-TrafficTypeDiagnostic: DM6PR03MB4683: X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eG90uArd5XY4rNTE7ZAMh8N1PLYYuLnb8WR0cgO1IiLkVk4roTqtwoGRT13Wj82XgJPVJNmdIlAqJpg5kX4c88hUaTYlRvXcTg2enxQr8fCYnvh46A005wp1E+I4egK3VH06H8zbqIRfmJ5qi0CQQi216t7l7tqTabO1EsTHUzvzWYxOX/8Y4WEQcwVL6okHKJIIUKfeSB9sWJ9CF0NMzxlppBD1+PYTlC4lZwRDNf/Y1EikbsAmv0cYeAOLBQ6efhbo1HfOQn7iUcwVBY7J5lruG1OjNmaTSP+sQNvqqIgmBKNbCPFLHwCpJrYsmIfj0nFZcUhQMbNaF8QskDQC1ERk9lParpbaJs1h1fQvwVcmn8ETgGtiqes5NqgECSst8nxiZdCAz2/SSHkZsn1+ZLtidGOBLca8XmVZuJ5vtfQY7E7BAzaVMY/SjhunHhEeNZrEJse35mITxMeWJTUMWt7G4gcvqaVl+njMibz7YU4++UlLrAAV9cJWwQZ3GV7QOGOMX79fnSBNDnqwkCTE0A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(7916004)(4636009)(366004)(136003)(39850400004)(396003)(346002)(376002)(16526019)(186003)(6496006)(7416002)(6636002)(2906002)(66946007)(83380400001)(33716001)(5660300002)(9686003)(53546011)(66556008)(26005)(66476007)(478600001)(4326008)(8676002)(316002)(6666004)(85182001)(54906003)(6486002)(86362001)(956004)(8936002)(6862004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?ZXZZcVkwUlVNekJxMnY5bjJWdWhEREVUUnI5SUo4alZFeXUyNVFDTmFsWUgz?= =?utf-8?B?ZjUxMCtXb0hYcC9yS2FzS29aRTArQXRxMzdWLzBIUlN1V2hWdUNET2U1aHU3?= =?utf-8?B?dDlw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PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2021 09:33:24.0550 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 10A6TqebKqXD85pF1i3qA+HAEZ48YPYofTk+tNPjpqVQSI3aNvQjWf+QBdcvsz+Wc1KXuuGT+1dOCB1g7QlOUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4683 X-OriginatorOrg: citrix.com On Tue, Mar 09, 2021 at 07:13:26PM +0000, Andrew Cooper wrote: > On 09/03/2021 10:56, Roger Pau Monne wrote: > > Introduce an option to allow selecting a behavior similar to the pre > > Xen 4.15 one for accesses to MSRs not explicitly handled. Since commit > > 84e848fd7a162f669 and 322ec7c89f6640e accesses to MSRs not explicitly > > handled by Xen result in the injection of a #GP to the guest. This > > is a behavior change since previously a #GP was only injected if > > accessing the MSR on the real hardware would also trigger a #GP, or if > > the attempted to be set bits wouldn't match the hardware values (for > > PV). > > > > This seems to be problematic for some guests, so introduce an option > > to fallback to this kind of legacy behavior without leaking the > > underlying MSR values to the guest. > > > > When the option is set, for both PV and HVM don't inject a #GP to the > > guest on MSR read if reading the underlying MSR doesn't result in a > > #GP, do the same for writes and simply discard the value to be written > > on that case. > > > > Note that for guests restored or migrated from previous Xen versions > > the option is enabled by default, in order to keep a compatible > > MSR behavior. Such compatibility is done at the libxl layer, to avoid > > higher-level toolstacks from having to know the details about this flag. > > > > Signed-off-by: Roger Pau Monné > > Thankyou for doing this.  By and large, Reviewed-by: Andrew Cooper > , subject to some pandoc syntax fixes below. Thanks. > However, I think it is worth saying explicitly that the reasons behind > the changes in 84e848fd7a162f669 and 322ec7c89f6640e (not leaking > hardware MSRs, and not breaking #GP-probing) are still legitimate, and > this influences the change in behaviour between msr_relaxed and 4.14 > (i.e. read-as-zero rather than leaking). Right, I tried to convey this fact by using "compatible" behavior instead of "legacy" one, as the behavior provided by msr_relaxed is not exactly the same as what you would get on 4.14. I've added the following at the end of the first paragraph: "The reasons for not leaking hardware MSR values and injecting a #GP are fully valid, so the solution proposed here should be considered a temporary workaround until all the required MSRs are properly handled." > > diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc > > index 4737c92bfe..6cf61a5c57 100644 > > --- a/docs/misc/xen-command-line.pandoc > > +++ b/docs/misc/xen-command-line.pandoc > > @@ -740,7 +740,7 @@ Specify the bit width of the DMA heap. > > > > ### dom0 > > = List of [ pv | pvh, shadow=, verbose=, > > - cpuid-faulting= ] > > + cpuid-faulting=, msr-relaxed= ] > > > > Applicability: x86 > > > > @@ -789,6 +789,21 @@ Controls for how dom0 is constructed on x86 systems. > > restore the pre-4.13 behaviour. If specifying `no-cpuid-faulting` fixes > > an issue in dom0, please report a bug. > > > > +* msr-relaxed: Select whether to use a relaxed behavior for accesses to MSRs > > + not explicitly handled by Xen instead of injecting a #GP to dom0. > > + Such access mode will force Xen to replicate the behavior from the hardware > > + it's currently running on in order to decide whether a #GP is injected to > > + dom0 for MSR reads. Note that dom0 is never allowed to read the value of > > + unhandled MSRs, this option only changes whether a #GP might be injected > > + or not. For writes a #GP won't be injected as long as reading the > > + underlying MSR doesn't result in a #GP. > > I don't find this overly clear to follow, and it also misses stating the > default explicitly.  How about: > > ---8<--- > The `msr-relaxed` boolean is an interim option, and defaults to false. > > In Xen 4.15, the default behaviour for unhandled MSRs has been changed, > to avoid leaking host data into guests, and to avoid breaking guest > logic which uses \#GP probing to identify the availability of MSRs. > > However, this new stricter behaviour has the possibility to break > guests, and a more 4.14-like behaviour can be selected by specifying > `dom0=msr-relaxed`. > > If using this option is necessary to fix an issue, please report a bug. > ---8<--- OK, this seems to be less verbose that what I previously had, but I'm fine with it. I assume this should also be changed in xl.cfg then? > Other pending Sphinx work is drawing together the "how to contact us" > information, so the various "please report a bug"s through this document > will turn into links. > > > diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c > > index 23bbb6e8c1..d217c223b0 100644 > > --- a/xen/arch/x86/setup.c > > +++ b/xen/arch/x86/setup.c > > @@ -749,6 +749,7 @@ static struct domain *__init create_dom0(const module_t *image, > > .max_grant_frames = -1, > > .max_maptrack_frames = -1, > > .max_vcpus = dom0_max_vcpus(), > > + .arch.domain_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, > > Can I request > > .arch = { >     .domain_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, > }, > > please, to reduce the patch complexity of further additions inside .arch. Sure. > > diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h > > index 629cb2ba40..f9d0e33b94 100644 > > --- a/xen/include/public/arch-x86/xen.h > > +++ b/xen/include/public/arch-x86/xen.h > > @@ -304,6 +304,14 @@ struct xen_arch_domainconfig { > > XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ > > XEN_X86_EMU_VPCI) > > uint32_t emulation_flags; > > + > > +/* > > + * Select whether to use a relaxed behavior for accesses to MSRs not explicitly > > + * handled by Xen instead of injecting a #GP to the guest. Note this option > > + * doesn't allow the guest to read or write to the underlying MSR. > > + */ > > +#define XEN_X86_MSR_RELAXED (1u << 0) > > + uint32_t domain_flags; > > The domain prefix is somewhat redundant, given the name of the structure > or the hypercall it is used for.  OTOH, 'flags' on its own probably > isn't ok.  Thoughts on misc_flags? I'm fine with it, will change unless Jan objects to the name. Thanks, Roger.