From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 479EDC433EF for ; Tue, 7 Dec 2021 14:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bTWEv+O3pfzxUusVF5br7L1corxXbDEuM4ADGbrbEXE=; b=MNj6hAJ5vPavcT vfmtTTKFuKE/V35OiwV9p3jiqCgtC25w/yfMZGd5jZ9BLuNjrON0Y2L00vicMHBGk55fURCoVNrrE IjdRVV6MMXCnzSscyPmICmohTERTjCoojfIu4t5/fwlh8y1PFGgxP+z5VQyhBR5KFkRzxYFjvOdFN bw0g9ziGmMFCk8uc/2/2/16Ad+zVYkqoEOVhdi/oIRSAhjA9qJ7ZMLQ5HJ+uL1+jE6cxcBZjQ4DSv pwx7oeWnJ+e/V7Fxs8ol/vHdrnUh8wepJSxGZhhIzwja4fmKMFncbEWNl5lDhq2nrx1nO3ANpqngX LdG1ijwiueHeNepqFqHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mubpM-0091q6-U2; Tue, 07 Dec 2021 14:52:24 +0000 Received: from mail-he1eur04on062a.outbound.protection.outlook.com ([2a01:111:f400:fe0d::62a] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mubIg-008tiT-JA for linux-arm-kernel@lists.infradead.org; Tue, 07 Dec 2021 14:18:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0yuVmnWT5foV4We9MNI+orPcMfkfwOTXlcKMdShoiUc=; b=B6Qe/wSYRd0yHEj/JIGai3E5IM9dmqnQu5tg5708OKYZ3sJnftGgTKxKdoE4wvkhTCneELdu6UlCA3zxsm0KjI7PmNmScgpJuSXVaRZTwZh5hTlYvjEYQLBODgy+g4nayEx6JafrJOEBvSA6fz46+jpPEwohyya9DGaPVRQIg14= Received: from AS9P194CA0012.EURP194.PROD.OUTLOOK.COM (2603:10a6:20b:46d::31) by AM9PR08MB6051.eurprd08.prod.outlook.com (2603:10a6:20b:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.16; Tue, 7 Dec 2021 14:18:25 +0000 Received: from VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46d:cafe::4d) by AS9P194CA0012.outlook.office365.com (2603:10a6:20b:46d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.14 via Frontend Transport; Tue, 7 Dec 2021 14:18:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT013.mail.protection.outlook.com (10.152.19.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.13 via Frontend Transport; Tue, 7 Dec 2021 14:18:25 +0000 Received: ("Tessian outbound c61f076cbd30:v110"); Tue, 07 Dec 2021 14:18:25 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 71455f1b59d87d45 X-CR-MTA-TID: 64aa7808 Received: from c599a97cee9b.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 1E3ED5D3-8593-444F-9D7B-5401D0B63D9F.1; Tue, 07 Dec 2021 14:17:59 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c599a97cee9b.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 07 Dec 2021 14:17:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fQd47YwbRqnh/qW3AHQVt2W3gCz/AV2RanFexJcBErvbap6ku+D8RYlPn9gxwzNSuT6pCcLcJwpkVRhvJgA0Zc50nP2UEewbzH6fjV5ezG5qkZUh2NgRloLbwSosyIXKDjf0irIG6mMau8AIkdYFyoo680suriA5Jmvr12zszs6LIco2jAsupMBz/GAxfaqeEgrLurzqj6FL00n73+dDR0emxDZgMUl7EMWjlMf6WajLpaDsJhp1P5o0jfyALYhhYDUbUYLeoZ3UyYiqhZZbtsGSqJSRkjeRDqLykr5JZMjBI9r4uWq7Kdvfk/M0CQFdXfyppq5b2dA45lsBbQmA2w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0yuVmnWT5foV4We9MNI+orPcMfkfwOTXlcKMdShoiUc=; b=gmg/ZQLQu/rXr1+1AtbdnpLUKmSuTM4CCgs9+w4sI6eZ7Ani99GUmQ/l8X3NYGwK2eVHqJkCDd+B2VZbzjggX2MS/ujiXf9wXVZwKUFB/tf70P8xG1kzmDNRfkXbSf3DT6lEWdCz/7LtN1BbrTESaJNBjhRT1ejcgtUM8AGiVRAwbxrDRVD/HRtKs7Bufbd3dywcbkWIsgmSDVNYwha7zw+WwscVFA1nK2D22i2P5yhLJvzEBDBF4OHj9LvNvYDrK9JtFHb1D8PwcUGsBD88bxbOGRfKUCIEa611y1i4sWYx0xR+TCDBlJtpn+iaa9MBzMQrxtoF/wOrg7/RFZ58rA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0yuVmnWT5foV4We9MNI+orPcMfkfwOTXlcKMdShoiUc=; b=B6Qe/wSYRd0yHEj/JIGai3E5IM9dmqnQu5tg5708OKYZ3sJnftGgTKxKdoE4wvkhTCneELdu6UlCA3zxsm0KjI7PmNmScgpJuSXVaRZTwZh5hTlYvjEYQLBODgy+g4nayEx6JafrJOEBvSA6fz46+jpPEwohyya9DGaPVRQIg14= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB6860.eurprd08.prod.outlook.com (2603:10a6:10:2ae::19) by DB6PR0801MB1784.eurprd08.prod.outlook.com (2603:10a6:4:39::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.19; Tue, 7 Dec 2021 14:17:57 +0000 Received: from DB9PR08MB6860.eurprd08.prod.outlook.com ([fe80::84a:5981:c268:f896]) by DB9PR08MB6860.eurprd08.prod.outlook.com ([fe80::84a:5981:c268:f896%9]) with mapi id 15.20.4755.021; Tue, 7 Dec 2021 14:17:57 +0000 Date: Tue, 7 Dec 2021 14:17:56 +0000 From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, will@kernel.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: tglx@linutronix.de, mingo@redhat.com Subject: Re: [PATCH v2 4/4] KVM: arm64: Refuse to run VCPU if the PMU doesn't match the physical CPU Message-ID: References: <20211206170223.309789-1-alexandru.elisei@arm.com> <20211206170223.309789-5-alexandru.elisei@arm.com> Content-Disposition: inline In-Reply-To: <20211206170223.309789-5-alexandru.elisei@arm.com> X-ClientProxiedBy: LNXP265CA0072.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::36) To DB9PR08MB6860.eurprd08.prod.outlook.com (2603:10a6:10:2ae::19) MIME-Version: 1.0 Received: from monolith.localdoman (82.38.32.78) by LNXP265CA0072.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.17 via Frontend Transport; Tue, 7 Dec 2021 14:17:56 +0000 X-MS-Office365-Filtering-Correlation-Id: 383db6fa-1937-4bd3-63e5-08d9b98c6ed2 X-MS-TrafficTypeDiagnostic: DB6PR0801MB1784:EE_|VE1EUR03FT013:EE_|AM9PR08MB6051:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: aATjeU1GAx9PfE1kCN/vzUG8mX15ojxl3GCo9CPqyn5ANRwqNKV4pVMQq/FCPUssCTziiopyO2dQpo3rnlnFXD0LyYFB0vgV/j2smbYfQ6It0k0HlOuExL+QubWCqnFhZ/rL75TaNYpNN2gOL2XPUvRTEP4vUhxyhXC0KfPd6mIRyYxjmI3+CqvjkXvYHAGxsUULiTvBtzJb45A9nVfQefBy7ZL4HgLeYD5ttqWGQfl63BKE5a9pQ7ecugirfNTXukd2nRaRGwb8GEvdlYbDp40gYL6weu85n/pmqOrlDpTB+yhEncDJevXYkrD2rvJxYXQcS+fFMG6hES1O6VMrxRqldhjkjNoooM29J4w37fQTU1uA2RlGo2vFZ+uAsANl2C/s2XbAD5m2tMm4gu2Cm0qv9xNMuFPVzCXp1mg2lKSaQDrOuJUA4FAq0A92e37B8+fppM7vm0J5FqAPf/9/jJFZR9z+vus3KehUUVMpBhLVUPkr8/ZDLNN5G+3ueOe4y1Qn1wCRWSv0dXv52yS+BEGKCMiRpoyxxkhL4dyDRcLiCcTo6msJuOkA53Z+IoSK0vPCz2jpQaKMXxF5gCdGmkqYkBtQRZPLTnkkeGZ0vVvVZlggTwtNElVLuI1ZhyXABC+s1OKqCIa9pOkNZdspq+gGXtZqTCn2r8jORsHtqbDtjV9tBvfRvlOLiv1NTDCvTSodbC9jVAn0wc7L0jehxQ/TAOm/Ez/0Nkn3GUDXkLEfIsGmBhyJe6fmDrfSBUkWGFzAe3L2ON9V2QFE08LDcw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB6860.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(55016003)(86362001)(83380400001)(4326008)(38100700002)(38350700002)(7696005)(8936002)(2906002)(316002)(44832011)(956004)(966005)(52116002)(8676002)(9686003)(66946007)(5660300002)(66476007)(66556008)(26005)(186003)(508600001)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1784 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 859e1269-f5af-4e8e-34a1-08d9b98c5db0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +Yat2G06YSqAK+sRaF58WiPS7TSe+UTgvQ+BQTiDOlajgyna3KsSRVFq+gWARq8e/5trq+NY2srRNQMYvLW20aGVTB9K04AUjkDMtpCkpKHfsDEE4fGRPNe4lG7D9ol9BRtnoa1EfV487mrGOVO5dsM48/tZXpgJdif21Zc8dPXzxKg2cClI5edbPlZxsn+cvHjLUEnl6Jz03X1EO4+HCjHS4mv000Z3Fr6Y7n+L3MvDT5KIASKOS4zZWnD9WHfVI2rgOlDqlutnaTPf/NcpXTWGIZHM/S0TvAZOt5rg7j0a/PRj8xFBWSh9xfdZBJgFT3AAY4HYiH3H6pnzQeYr9N5pUBBd9oU9t73iI3m7uJ0P00P9HLmsZkeJbNZO7jBgnQgo38RNUGEgFYz6KnjgE1T/ayE66aHlwBJz2nB62fTZ82Wd/9t105Hl5iTpWUDIgJ3jNJaTN2WLq3lQrj40c6j4leDE1KyIy+ohq8euxhi4j/QWBY5fzsm5lhwml+Gf4B8tsjgs3+JNMbetRTuPXojEuRGCbXfeiE9x+9h3laeCzQAeUcJIHE4xRxJ5slcWqeBXG5B5djopZtSpewidHpvFfzbga7HspeRh1ZXG+stNCzC5qt/9/VHrEXoO+dot7XrBoGCC/+mGnOzw2u5bGcYex+7jbFbozfxzl2lqXFt4ZvUE2qvootIjRTbS9xKd0oNlafjV09WukpjA7MqHMX4msrd4uq6gZn2ex16gz/BVbGtjIbgsh/PQW+PJ3M78+bgZYCXfnkJNDOjYnPK7ZA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(5660300002)(86362001)(44832011)(356005)(956004)(47076005)(81166007)(966005)(4326008)(508600001)(70586007)(7696005)(8936002)(36860700001)(70206006)(8676002)(2906002)(336012)(9686003)(82310400004)(316002)(107886003)(6506007)(26005)(55016003)(83380400001)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2021 14:18:25.3915 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 383db6fa-1937-4bd3-63e5-08d9b98c6ed2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211207_061834_921872_4275DF9D X-CRM114-Status: GOOD ( 33.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On Mon, Dec 06, 2021 at 05:02:23PM +0000, Alexandru Elisei wrote: > Userspace can assign a PMU to a VCPU with the KVM_ARM_VCPU_PMU_V3_SET_PMU > device ioctl. If the VCPU is scheduled on a physical CPU which has a > different PMU, the perf events needed to emulate a guest PMU won't be > scheduled in and the guest performance counters will stop counting. Treat > it as an userspace error and refuse to run the VCPU in this situation. > > The VCPU is flagged as being scheduled on the wrong CPU in vcpu_load(), but > the flag is cleared when the KVM_RUN enters the non-preemptible section > instead of in vcpu_put(); this has been done on purpose so the error > condition is communicated as soon as possible to userspace, otherwise > vcpu_load() on the wrong CPU followed by a vcpu_put() would clear the flag. > > Suggested-by: Marc Zyngier > Signed-off-by: Alexandru Elisei > --- > I agonized for hours about the best name for the VCPU flag and the > accessors. If someone has a better idea, please tell me and I'll change > them. > > Documentation/virt/kvm/devices/vcpu.rst | 6 +++++- > arch/arm64/include/asm/kvm_host.h | 12 ++++++++++++ > arch/arm64/include/uapi/asm/kvm.h | 3 +++ > arch/arm64/kvm/arm.c | 19 +++++++++++++++++++ > arch/arm64/kvm/pmu-emul.c | 1 + > 5 files changed, 40 insertions(+), 1 deletion(-) > > diff --git a/Documentation/virt/kvm/devices/vcpu.rst b/Documentation/virt/kvm/devices/vcpu.rst > index c82be5cbc268..9ae47b7c3652 100644 > --- a/Documentation/virt/kvm/devices/vcpu.rst > +++ b/Documentation/virt/kvm/devices/vcpu.rst > @@ -128,7 +128,11 @@ systems where there are at least two CPU PMUs on the system. > > Note that KVM will not make any attempts to run the VCPU on the physical CPUs > associated with the PMU specified by this attribute. This is entirely left to > -userspace. > +userspace. However, attempting to run the VCPU on a physical CPU not supported > +by the PMU will fail and KVM_RUN will return with > +exit_reason = KVM_EXIT_FAIL_ENTRY and populate the fail_entry struct by setting > +hardare_entry_failure_reason field to KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED and > +the cpu field to the processor id. > > 2. GROUP: KVM_ARM_VCPU_TIMER_CTRL > ================================= > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 2a5f7f38006f..0c453f2e48b6 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -385,6 +385,8 @@ struct kvm_vcpu_arch { > u64 last_steal; > gpa_t base; > } steal; > + > + cpumask_var_t supported_cpus; > }; > > /* Pointer to the vcpu's SVE FFR for sve_{save,load}_state() */ > @@ -420,6 +422,7 @@ struct kvm_vcpu_arch { > #define KVM_ARM64_EXCEPT_MASK (7 << 9) /* Target EL/MODE */ > #define KVM_ARM64_DEBUG_STATE_SAVE_SPE (1 << 12) /* Save SPE context if active */ > #define KVM_ARM64_DEBUG_STATE_SAVE_TRBE (1 << 13) /* Save TRBE context if active */ > +#define KVM_ARM64_ON_UNSUPPORTED_CPU (1 << 14) /* Physical CPU not in supported_cpus */ > > #define KVM_GUESTDBG_VALID_MASK (KVM_GUESTDBG_ENABLE | \ > KVM_GUESTDBG_USE_SW_BP | \ > @@ -460,6 +463,15 @@ struct kvm_vcpu_arch { > #define vcpu_has_ptrauth(vcpu) false > #endif > > +#define vcpu_on_unsupported_cpu(vcpu) \ > + ((vcpu)->arch.flags & KVM_ARM64_ON_UNSUPPORTED_CPU) > + > +#define vcpu_set_on_unsupported_cpu(vcpu) \ > + ((vcpu)->arch.flags |= KVM_ARM64_ON_UNSUPPORTED_CPU) > + > +#define vcpu_clear_on_unsupported_cpu(vcpu) \ > + ((vcpu)->arch.flags &= ~KVM_ARM64_ON_UNSUPPORTED_CPU) > + > #define vcpu_gp_regs(v) (&(v)->arch.ctxt.regs) > > /* > diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h > index 1d0a0a2a9711..d49f714f48e6 100644 > --- a/arch/arm64/include/uapi/asm/kvm.h > +++ b/arch/arm64/include/uapi/asm/kvm.h > @@ -414,6 +414,9 @@ struct kvm_arm_copy_mte_tags { > #define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS > #define KVM_PSCI_RET_DENIED PSCI_RET_DENIED > > +/* run->fail_entry.hardware_entry_failure_reason codes. */ > +#define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0) > + > #endif > > #endif /* __ARM_KVM_H__ */ > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index e4727dc771bf..1124c3efdd94 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -327,6 +327,10 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) > > vcpu->arch.mmu_page_cache.gfp_zero = __GFP_ZERO; > > + if (!zalloc_cpumask_var(&vcpu->arch.supported_cpus, GFP_KERNEL)) > + return -ENOMEM; > + cpumask_copy(vcpu->arch.supported_cpus, cpu_possible_mask); > + > /* Set up the timer */ > kvm_timer_vcpu_init(vcpu); > > @@ -354,6 +358,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) > if (vcpu->arch.has_run_once && unlikely(!irqchip_in_kernel(vcpu->kvm))) > static_branch_dec(&userspace_irqchip_in_use); > > + free_cpumask_var(vcpu->arch.supported_cpus); > kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); > kvm_timer_vcpu_terminate(vcpu); > kvm_pmu_vcpu_destroy(vcpu); > @@ -432,6 +437,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > if (vcpu_has_ptrauth(vcpu)) > vcpu_ptrauth_disable(vcpu); > kvm_arch_vcpu_load_debug_state_flags(vcpu); > + > + if (!cpumask_test_cpu(smp_processor_id(), vcpu->arch.supported_cpus)) > + vcpu_set_on_unsupported_cpu(vcpu); > } > > void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) > @@ -822,6 +830,17 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > */ > preempt_disable(); > > + if (unlikely(vcpu_on_unsupported_cpu(vcpu))) { > + vcpu_clear_on_unsupported_cpu(vcpu); > + run->exit_reason = KVM_EXIT_FAIL_ENTRY; > + run->fail_entry.hardware_entry_failure_reason > + = KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED; > + run->fail_entry.cpu = smp_processor_id(); I just realised that this is wrong for the same reason that KVM doesn't clear the unsupported CPU flag on vcpu_put: a vcpu_put/load that happened after the vcpu_load that set the flag and before preemption is disabled could mean that now the thread is executing on a different physical CPU than the physical CPU that caused the flag to be set. To make things worse, this CPU might even be in supported_cpus, which would be extremely confusing for someone trying to descipher what went wrong. I see three solutions here: 1. Drop setting the fail_entry.cpu field. 2. Make vcpu_put clear the flag, which means that if the flag is set here then the VCPU is definitely executing on the wrong physical CPU and smp_processor_id() will be useful. 3. Carry the unsupported CPU ID information in a new field in struct kvm_vcpu_arch. I honestly don't have a preference. Maybe slightly towards solution number 2, as it makes the code symmetrical and removes the subtletly around when the VCPU flag is cleared. But this would be done at the expense of userspace possibly finding out a lot later (or never) that something went wrong. Thoughts? Thanks, Alex > + ret = 0; > + preempt_enable(); > + break; > + } > + > kvm_pmu_flush_hwstate(vcpu); > > local_irq_disable(); > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index 618138c5f792..471fe0f734ed 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -954,6 +954,7 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id) > arm_pmu = entry->arm_pmu; > if (arm_pmu->pmu.type == pmu_id) { > kvm_pmu->arm_pmu = arm_pmu; > + cpumask_copy(vcpu->arch.supported_cpus, &arm_pmu->supported_cpus); > ret = 0; > goto out_unlock; > } > -- > 2.34.1 > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel