From patchwork Wed Apr 19 10:44:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13216630 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BDEEFC6FD18 for ; Wed, 19 Apr 2023 10:44:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.523319.813259 (Exim 4.92) (envelope-from ) id 1pp5Ij-00051p-KV; Wed, 19 Apr 2023 10:44:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 523319.813259; Wed, 19 Apr 2023 10:44:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5Ij-00051i-Hn; Wed, 19 Apr 2023 10:44:37 +0000 Received: by outflank-mailman (input) for mailman id 523319; Wed, 19 Apr 2023 10:44:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5Ii-0003M4-Bn for xen-devel@lists.xenproject.org; Wed, 19 Apr 2023 10:44:36 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2060d.outbound.protection.outlook.com [2a01:111:f400:7e1b::60d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2c56b75d-de9f-11ed-8611-37d641c3527e; Wed, 19 Apr 2023 12:44:34 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AS8PR04MB7671.eurprd04.prod.outlook.com (2603:10a6:20b:299::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Wed, 19 Apr 2023 10:44:33 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae%2]) with mapi id 15.20.6298.045; Wed, 19 Apr 2023 10:44:33 +0000 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: 2c56b75d-de9f-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SF3nigEobWvO4lZQvPg+fseXc0vqkXnOzT7Y66cbs3o4KzggUqnRa4N3ul0pGawJ/WYCByJSMDe1o8iVXV2yLUYJ29hFAQjE089vYsVQyHZ3VO8ZNQfdcd+Q/F+CjzHVPIZsvjnd5Y+U1Hf7/A1rFOcYiuRdv/L8o3ULnG/r9VnwJVntYWC9t740XAT+oMZFWT9gEMxNUiO2W1yUys1xvgIHpo8ahF38cbInlrCtlLGCdcpIKPGT9NplwxzwOrKcglxGoZpH8Ow+LDGpK4YKeY0IUlNvr9qRP3QuVV/N33mdmcXPjfvr82F3O3aPqhmnWXFTDsjR0Py22k2+yAolNw== 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=XejQV07T8V2gYiQel4lhjkXlJAuuZk41L4stliIWs7I=; b=Hk/G0cOXWuIFoXbBkcN+W/iNWM3OXPMjIpOxtcV3WtkN+wxQkOnV7hXsPcdUEIAAZSrnekgEWYuy9CGkAj8GKgYS+xAAs/2ye8SQaQ5tuwNwuhDEydlRHP+jdD0C/BBdP0QVxOizuEV7VKcGo+nbrndyD1GLOqkJEEdx2HvN0CpowfGfsbSk69hnrovWWDhaHnvDzROFS1Q0IU7QhtaYNyXiKldRbgdaoRgvx5gUIl7N0NO5gQhvdggUUIC+Akfm2McqzxF0yrh2RfrC/AYewtjzY2n1aRsTmHeq1MXkZhGBuZ/8MurSonYsLU+8jOYXoGjVwtKgizXi88HjEyvX2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XejQV07T8V2gYiQel4lhjkXlJAuuZk41L4stliIWs7I=; b=51Nud44WJbSocPCFTtFgaf3+mGifwESn3rwb4M+PSahBQ6txqCeMNrTilwhzZZR+Y8kan9v4vnvCHtyN0uhls2eg1+24J6m6BENVb3peVb+UwKibZ48Y4IXa95239xM6jO7bLGIMC28zFgEpz6xCFy9BixftRhWIeXZ5X7gHnRwmbuarp5SKmM8iet+vA8P9hy7xUtpzuloNjMBhktPmHD7kdAv9Jio8DmcfJzAglwksW848ZKziizLQM2P0mPCSjCZtlV1r6C17/dDh+TFTiKvAVvS3Gopo8N2UHwBf8U41qwW/icfjf1xcn2IjxvZI5kFM3pMmsaCbUr8SXf3qBA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 19 Apr 2023 12:44:31 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH 1/5] x86: support cache-writeback in flush_area_local() et al Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> In-Reply-To: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> X-ClientProxiedBy: FR2P281CA0014.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::24) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AS8PR04MB7671:EE_ X-MS-Office365-Filtering-Correlation-Id: ba16c0b1-374f-4801-4c25-08db40c30fc4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ciu6ZyWfasZVyJmuWnkVBQJiPDT5DjlRSVPs+SQaHrhoSd05ScrROU7/77mCiHF1HyyTKjdkMChRQS63R2EAJBT7Wm71JUdC/iQnqyR7hutfBOUfdxKQbn31DKVSQgicdSUwsUOR3aQr5zdRsAOiIPfOQBn5Bjfoqpxch3WVveJXZEj8XXIgbDIto87TUaVfFPZhjBsGdzns86gsbCx6vLubFxSG0nhwAJBTcp8gNwmwTRPfyh4d4tRBD9ZWLu7scknYpb+YibJRzDzMl/BwcvS64zYbyIWs19Tg/wXAouNjibssiKDoFIM7pYVbtcKb+/ZZK350PUAB5y1BbYN0ZvwflEhUMlyaJyK6cpnJPwQ0nZ3V4NWOL2Qf4CrxJ6KWu+uC/bnzmn8z7cxN/LpbvXaoegKOZbHSk5qip7lak11cTpL6kt7dP+yh0Peqiwax8FaT6rh1V5RdeHtAFelLFsqjnngQ8Q4CLrPUGgWu4V5/nC9cUjxgJgkPzVVOZXpOnEPcMsuJtZTBXX7kPUqLT706+g6iAztFBoDod4Epvk+KYo79ckD6dsaEqm6YA+vW8Di2sNywGw+EirojtsCuat2bb1zj2HQkz12OXB9vbT32IUxIjS8zgFNQg9/lO7fv1USM2IRbKtgp2DnMY1XOIg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(396003)(346002)(39860400002)(376002)(366004)(451199021)(5660300002)(86362001)(2616005)(83380400001)(31696002)(6512007)(186003)(6506007)(26005)(38100700002)(8676002)(8936002)(54906003)(478600001)(6486002)(316002)(41300700001)(36756003)(4326008)(6916009)(66946007)(66556008)(31686004)(66476007)(2906002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?BrlxgEdxlJTQ3NuY2YoF+aOu2SgB?= =?utf-8?q?hJQ7moGLDNuZjdsxfGh0KP26YKAWyk3bd2/vVgVk9fYSY1oBdZJ1zG6IZc9xvvwp+?= =?utf-8?q?u7q0vx/dqfHnJ3mbUDlS2Ei0DhKsz+kx33GvCmoxcUgM+i3kVntLKwBgb20bvrw1h?= =?utf-8?q?OwTw2XCSziVXHNvixq24u6zvCmT4/LKQ1rBXzLPVl871O/opfs33XcN1EfrTZpim9?= =?utf-8?q?NL3DqlXpdGI1wnoQyDVv4TYoe0sZLIL0OrZQy76eyM/g3x55VMecDU3dTYukOUYY4?= =?utf-8?q?Ouxp5cysld6rLenEX9wA7GQizSOO7wcytzM7if3GOJy5qRpnBIxTa+d0+aYh7V+L1?= =?utf-8?q?ui97FAvqyeeoIkcdTiVhIo/ZrffSZgVgo/b1YUGS98WmrWubaGHlTx8XDLrkKCAHs?= =?utf-8?q?C0MaRt1IZCBLWEclLxgSp3zxEdW1DJmL880R/s+CC5v+SZtxg/5S3BBwvaAX3HpLu?= =?utf-8?q?nBpENYI6FeADS6D8CMA929H3A7x0q+Krn4tw1nwvKAj0H7BzDrgf5GHz/mG/BBjJY?= =?utf-8?q?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6zJlXp3nOqlH6qIsO4+lhKJTtTZxUo8EQ0f5z10zTSMGQ2Hlb?= =?utf-8?q?38UZx+qtklWhP7mzoiI+pisz22e8fUcn0jv3Peqa/6WpgIfu9ucsB2abphhd2rkYn?= =?utf-8?q?4IF2iyWWqzxn?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba16c0b1-374f-4801-4c25-08db40c30fc4 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 10:44:33.1687 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IRRue+sUY+I8P8BDp0byCHD8lvAkP0uzAogYwwyxJk/V677Intc9VjfQo5iG+AOburzZslRtz7ERuHj3a1j56g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7671 The majority of the present callers really aren't after invalidating cache contents, but only after writeback. Make this available by simply extending the FLUSH_CACHE handling accordingly. No feature checks are required here: cache_writeback() falls back to cache_flush() as necessary, while WBNOINVD degenerates to WBINVD on older hardware. Signed-off-by: Jan Beulich --- a/xen/arch/x86/flushtlb.c +++ b/xen/arch/x86/flushtlb.c @@ -232,7 +232,7 @@ unsigned int flush_area_local(const void if ( flags & FLUSH_HVM_ASID_CORE ) hvm_flush_guest_tlbs(); - if ( flags & FLUSH_CACHE ) + if ( flags & (FLUSH_CACHE | FLUSH_WRITEBACK) ) { const struct cpuinfo_x86 *c = ¤t_cpu_data; unsigned long sz = 0; @@ -245,13 +245,16 @@ unsigned int flush_area_local(const void c->x86_clflush_size && c->x86_cache_size && sz && ((sz >> 10) < c->x86_cache_size) ) { - cache_flush(va, sz); - flags &= ~FLUSH_CACHE; + if ( flags & FLUSH_CACHE ) + cache_flush(va, sz); + else + cache_writeback(va, sz); + flags &= ~(FLUSH_CACHE | FLUSH_WRITEBACK); } - else - { + else if ( flags & FLUSH_CACHE ) wbinvd(); - } + else + wbnoinvd(); } if ( flags & FLUSH_ROOT_PGTBL ) --- a/xen/arch/x86/include/asm/flushtlb.h +++ b/xen/arch/x86/include/asm/flushtlb.h @@ -135,6 +135,8 @@ void switch_cr3_cr4(unsigned long cr3, u #else # define FLUSH_NO_ASSIST 0 #endif + /* Write back data cache contents */ +#define FLUSH_WRITEBACK 0x10000 /* Flush local TLBs/caches. */ unsigned int flush_area_local(const void *va, unsigned int flags); @@ -194,7 +196,11 @@ static inline int clean_and_invalidate_d } static inline int clean_dcache_va_range(const void *p, unsigned long size) { - return clean_and_invalidate_dcache_va_range(p, size); + unsigned int order = get_order_from_bytes(size); + + /* sub-page granularity support needs to be added if necessary */ + flush_area_local(p, FLUSH_WRITEBACK | FLUSH_ORDER(order)); + return 0; } unsigned int guest_flush_tlb_flags(const struct domain *d); From patchwork Wed Apr 19 10:45:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13216631 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 55946C6FD18 for ; Wed, 19 Apr 2023 10:45:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.523323.813269 (Exim 4.92) (envelope-from ) id 1pp5JT-0005eo-1Q; Wed, 19 Apr 2023 10:45:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 523323.813269; Wed, 19 Apr 2023 10:45:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5JS-0005eh-Ua; Wed, 19 Apr 2023 10:45:22 +0000 Received: by outflank-mailman (input) for mailman id 523323; Wed, 19 Apr 2023 10:45:22 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5JS-0005YA-FM for xen-devel@lists.xenproject.org; Wed, 19 Apr 2023 10:45:22 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on0611.outbound.protection.outlook.com [2a01:111:f400:fe0c::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 487bdbbf-de9f-11ed-b21f-6b7b168915f2; Wed, 19 Apr 2023 12:45:21 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM7PR04MB7013.eurprd04.prod.outlook.com (2603:10a6:20b:116::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Wed, 19 Apr 2023 10:45:19 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae%2]) with mapi id 15.20.6298.045; Wed, 19 Apr 2023 10:45:19 +0000 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: 487bdbbf-de9f-11ed-b21f-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N1M6CcxgYf2nBnLDT8Bl4VTGt/j/hf7cbiDpKE7i3HdlVhhwPhePaaHybCTt5Gkjz1NntW3Mshbvvu/ZgpynAQrVRKN/R396+c2deX65pfX7Of1zJF9Af9RiPaTo3js1C9ki0wdIQRyXfG740pncavtHrRACJezJRc+f/8AHiqLuF7w9JoTwjziMAQBG5DnJz97YtbaHyG/sFl6vaIPaMpSoJ5enJaAkrr1oWJOWlh0co6DF3msLy1BKUfJEW+VLLnOMKOXSv55qovm6SXK5Bts8UseP+5OCfVgTyKx0S4q0VSPZ+Xn6OPypQxOz5f8R5mziefJpn0GJGPkGcg1TCw== 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=4aXdXTyOcO8LUb03EjxFppTt+3a/uazHmqVhanxapU8=; b=hXeIYrCYHsKEgQylQ6MxH/bQHs/KMtYlp4FCjhAQk5XP9JvWizQnPkw7GEdMN8lYjTuhb0mtGC1JbBO8MHH7sU7FCQypAbrR6u+bAb7ZrdIb8ZshV4/weVfqgHhM2MFXl3IKzUUqLC9YpkGMEBaFjJLysJyKpceyfp35UlgZcj4gZ/BezqhUS9n4NFzjjgGPocR2ZvgG+2pjTbkEldEj1AkQGj8hsNMKAgcZm9j8pzMXF9GmzEqBTqZSzDI/VWQpGIZ8S11plIWnZMpAjdDon1zQ4aP7gWX7pEuXFvasCSiZ9vEWC+dX2wZRjQIjWxYl8vhvWiNSVkSXjWtVlWMVsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4aXdXTyOcO8LUb03EjxFppTt+3a/uazHmqVhanxapU8=; b=1E+oRGNTHTkqsodGsAw3Qs9R+WTGN8snrVKr5xmC18eozKoYpe1KfBWvpuyWJfnTYjQ6r1dcwf2KLs7h3IGaNMRHIhkzc1dXnXa6KiIR8mks065G2FuCHp/FuLRNwFpnlnNmvgm92l9pdnmlS8ChNxTFuuw9MkFSPxmR6JkezWObGJd21qU/bT6/hyZvia1Z09rz473MV8KHzrvp7NEB9buMg2LmcG3QweJTfRxCv11h8lagrCdAv2vJis7uPQDz/P/yX0zN1hYFu+daBHsww+9FG9Z7sXczUru9ByGn0OZ5+kPsMPPSfYhRsxMm0t+EMknviaYDtAUpOFMZ/D7eow== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <78858961-9c8c-af8d-286d-f90981f85e07@suse.com> Date: Wed, 19 Apr 2023 12:45:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH 2/5] x86/HVM: restrict guest-induced WBINVD to cache writeback Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Kevin Tian , Jun Nakajima References: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> In-Reply-To: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> X-ClientProxiedBy: FR2P281CA0017.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::27) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AM7PR04MB7013:EE_ X-MS-Office365-Filtering-Correlation-Id: 24010689-b390-419c-f5fa-08db40c32b60 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WjOd2uMuEeDuagaAURUeHgfUZHWpAQrPusNvXmlOUKd3Iep3i+j7VsySTEc3LVhGSvA6/QC+hlC99lqIkx46pZ5B2I8Uf8dHJERuJ1GjYraEF4CDoObm7ZmOpjnL9S9qq5aqWQkRgeKcdFchOoTZFi4xaHOKcjIq46ib1Ppi51HRaauNFEuFAsulHSzUozRH2xz/zPzBSn0tXzp+t8O50uN23Q0lasGAIPPNWN46pqWkhwNwHC0PNVHhTUzF+FbKw3JjMORsXl7+l7hR/yyrU6X/QsPJ7oTYBl41IbTw4mI2svW+mJp/RlqbM76aB8x/TNygscytd8kOQfJjngtDa8n7+aJ4Arn7PpzicEIW0p3mR9r3sPeYLszda7kPnt024a6aUTbOeqvZ1S3yhgbWJ4yt09M2E3CUpzHZwKfuKGd+XPrytNddKpYAAPHln/UeOMcFFBLGmN2GpBn1SnMzadVxPaUY8CwDxYmQGDW7dZnv7s6tmtaHbmCN7wmc/4YcDNqgj98isU2YD/n38qBOo+pE/ZWne98cCdt4PDsvCcD3ZZIQu8Gtzs50tFjS+gUiwk7dxhEoYBvWAK544KH3yMKLRt7JdbPaJGOCD5BaJmgc6YHn85bCSDwmgFLu8YtEJnTGxrn5JbEvHc960Xa21Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(39850400004)(396003)(346002)(376002)(366004)(451199021)(5660300002)(86362001)(2616005)(83380400001)(31696002)(6512007)(186003)(6506007)(26005)(38100700002)(8676002)(8936002)(54906003)(478600001)(6486002)(316002)(41300700001)(36756003)(4326008)(6916009)(66946007)(66556008)(31686004)(66476007)(2906002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AW/t71LvkmD6zspHkm3p+ie0YKL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?utf-8?q?cxMmKXSE4D6AXPATTB/mZIecaCgz4g8D+Pd1CBPAnTj1P2rxzeUA8nxxkt0f+7PMW?= =?utf-8?q?l+pmz5U2dtXO+5A7WryGu95D1FJKYyy2tYQsJTEZP3kqzKKG7r57WcRssdhKlKvLf?= =?utf-8?q?FvLBVBdFFjOOr+5H1mc1hNfOGPb57ZdPytRETGGFhTjMXE7pgQ4of3eDi4/nVr6Qa?= =?utf-8?q?UvI9C6MhjI97y7w4Z0NA4MMHp+Ak2bkMdw6r9qFr6OKErzD8KiI5XhtGzmEkKGocn?= =?utf-8?q?keK5lDrxEaTIdk8Ftf/Cx5C1dkbp7doiGqGufLOyw1qJMvXt8aczeb4NkOnjtmJA2?= =?utf-8?q?iWBwC1lLKe4J4t7yiIS3/2rB+SRCLW8Uj0aKTNZLuoUgPotjo5KmuvElr9RPSYYqM?= =?utf-8?q?SdiCFOOURwqE5KwtDbjo8JopFyYKYKAANPBzG0ps6idTz/sCYIUV8o+oNCfeikdjr?= =?utf-8?q?7d6tUinJJpOIipWgr9KUXLHqsWr/Z/tJgb5RAwZ0UfYw0Rr6j8z7FGuFOrNhUoZ6x?= =?utf-8?q?cgcbtGi9ANcWTAMw+V6X9fI8oroHBI9ocJy/oKSgAjFrl8QyWwwvcNAEQ4dvOALeF?= =?utf-8?q?THTsm1+EzuYvej0eW9FLKCXXjYDakj8opij9KtuuB64nM0Jg31sFR9QH7Ayhh59me?= =?utf-8?q?XszAdTpYIpGC?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24010689-b390-419c-f5fa-08db40c32b60 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 10:45:19.7709 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: woSSJO5IQrDxjEhbK8FqYNOrKO3DAW0eTQv+TxYLJfqLVSAyziidfWQ0QKABtXZYR4cdW3sTCVz+F+HbTi+Xgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7013 We allow its use for writeback purposes only anyway, so let's also carry these out that way on capable hardware. With it now known that WBNOINVD uses the same VM exit code as WBINVD for both SVM and VT-x, we can now also expose the feature that way without further distinguishing the specific cases of those VM exits. Note that on SVM this builds upon INSTR_WBINVD also covering WBNOINVD, as the decoder won't set prefix related bits for this encoding in the resulting canonicalized opcode. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2364,7 +2364,7 @@ static void svm_vmexit_mce_intercept( static void cf_check svm_wbinvd_intercept(void) { if ( cache_flush_permitted(current->domain) ) - flush_all(FLUSH_CACHE); + flush_all(FLUSH_WRITEBACK); } static void svm_vmexit_do_invalidate_cache(struct cpu_user_regs *regs, --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1881,12 +1881,12 @@ void cf_check vmx_do_resume(void) { /* * For pass-through domain, guest PCI-E device driver may leverage the - * "Non-Snoop" I/O, and explicitly WBINVD or CLFLUSH to a RAM space. - * Since migration may occur before WBINVD or CLFLUSH, we need to - * maintain data consistency either by: - * 1: flushing cache (wbinvd) when the guest is scheduled out if + * "Non-Snoop" I/O, and explicitly WB{NO,}INVD or CL{WB,FLUSH} RAM space. + * Since migration may occur before WB{NO,}INVD or CL{WB,FLUSH}, we need + * to maintain data consistency either by: + * 1: flushing cache (wbnoinvd) when the guest is scheduled out if * there is no wbinvd exit, or - * 2: execute wbinvd on all dirty pCPUs when guest wbinvd exits. + * 2: execute wbnoinvd on all dirty pCPUs when guest wbinvd exits. * If VT-d engine can force snooping, we don't need to do these. */ if ( has_arch_pdevs(v->domain) && !iommu_snoop @@ -1894,7 +1894,7 @@ void cf_check vmx_do_resume(void) { int cpu = v->arch.hvm.vmx.active_cpu; if ( cpu != -1 ) - flush_mask(cpumask_of(cpu), FLUSH_CACHE); + flush_mask(cpumask_of(cpu), FLUSH_WRITEBACK); } vmx_clear_vmcs(v); --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3714,9 +3714,9 @@ static void cf_check vmx_wbinvd_intercep return; if ( cpu_has_wbinvd_exiting ) - flush_all(FLUSH_CACHE); + flush_all(FLUSH_WRITEBACK); else - wbinvd(); + wbnoinvd(); } static void ept_handle_violation(ept_qual_t q, paddr_t gpa) --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -238,7 +238,7 @@ XEN_CPUFEATURE(EFRO, 7*32+10) / /* AMD-defined CPU features, CPUID level 0x80000008.ebx, word 8 */ XEN_CPUFEATURE(CLZERO, 8*32+ 0) /*A CLZERO instruction */ XEN_CPUFEATURE(RSTR_FP_ERR_PTRS, 8*32+ 2) /*A (F)X{SAVE,RSTOR} always saves/restores FPU Error pointers */ -XEN_CPUFEATURE(WBNOINVD, 8*32+ 9) /* WBNOINVD instruction */ +XEN_CPUFEATURE(WBNOINVD, 8*32+ 9) /*S WBNOINVD instruction */ XEN_CPUFEATURE(IBPB, 8*32+12) /*A IBPB support only (no IBRS, used by AMD) */ XEN_CPUFEATURE(IBRS, 8*32+14) /*S MSR_SPEC_CTRL.IBRS */ XEN_CPUFEATURE(AMD_STIBP, 8*32+15) /*S MSR_SPEC_CTRL.STIBP */ From patchwork Wed Apr 19 10:45:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13216632 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 62D43C6FD18 for ; Wed, 19 Apr 2023 10:46:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.523327.813279 (Exim 4.92) (envelope-from ) id 1pp5K6-0006DH-AC; Wed, 19 Apr 2023 10:46:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 523327.813279; Wed, 19 Apr 2023 10:46:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5K6-0006DA-7A; Wed, 19 Apr 2023 10:46:02 +0000 Received: by outflank-mailman (input) for mailman id 523327; Wed, 19 Apr 2023 10:46:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5K4-0006CV-KF for xen-devel@lists.xenproject.org; Wed, 19 Apr 2023 10:46:00 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on0621.outbound.protection.outlook.com [2a01:111:f400:fe0c::621]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5f2ec1c3-de9f-11ed-b21f-6b7b168915f2; Wed, 19 Apr 2023 12:46:00 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM7PR04MB7013.eurprd04.prod.outlook.com (2603:10a6:20b:116::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Wed, 19 Apr 2023 10:45:58 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae%2]) with mapi id 15.20.6298.045; Wed, 19 Apr 2023 10:45:58 +0000 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: 5f2ec1c3-de9f-11ed-b21f-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K125paLkDc1s2CPG5UUnfiMudzOIk6DAsR9/8y6vXMWj4SrmpQruwSVisRexo6Rlfpqoi2ftM0VcPgw8e0c5EhYe27UmlbSYuUpJgVlH1ymuORoN5WCgBA07W/3GWaQtoMlRcLTYobMnDIQUYtG+le5er0AVaJQvXBiwO3MlesnjnyUKSELZPeWGCTITiAKuyKbklQHA7LWByIjDxuWnh2/Y+InEOYFwQGGCjPa0tFVmPv1kVocBXqlprLOh4aa9OB38sEqK8XWhtkWiclX4xRhLPHmhe9vjl/5CNYNSYAf0XjH11XGd48w2S8L7GgBnZfuM9GeLF1UrarqxGOfFLg== 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=AgoBtbMdStYg/E8daXMr1Bc+OTEzf/aiDaWtJfzyYEE=; b=cFWQUhPUAgwQh80aKGonFr6PpoQ+BcYVAeZT4kRUh1Zkg7m7M9pglpmrRqEwjLk9i8SzsVMtNgr+2w/qJhVySCMeVY8LrBqroKs/JKMKnvXfLcRWur8AavgbMJ6xtgJQJHtARiBeiITF34203/5cr0/ucpT95gO61GSK/i634uJCt+gEhlwC1s7KxFffGX8kMF0cWwKb4xJkC1UWJlqozQhPFfhW4qqdBB6yG5ke6q096W0+fyRoGlz/4mePbL+yTuhD1yai9w3BdteGSoe/+6OgmyKhSz6HdAEZ2ksfr6Vd3jP9l+I4yJLDOCmgAH4yj15uW9PXqW1ZnDmpXAFQzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AgoBtbMdStYg/E8daXMr1Bc+OTEzf/aiDaWtJfzyYEE=; b=HfOc5E/a53WNqQkgSMWRVmuEMPw06FcsuRGCRyG3p7QKZ/+Jjd95OZqI/nU/n9AhWJPV/aUhIOMF3emA3OlMjuXS1DXISVMh6sIaucMMcRZC43LukVhbq02BVx3ccTWEELPDTjL36b82/udoXpj8dLSEhMuvZRKZRh/orrn7ol00us22eTUdB6IHyka7S0uGKFnev1M2YDO6ntXmTrvcVa72YspODTpa5aTflSkqga+R0Ar2Z6RXXHIU5yF0hj7sY3Ax1VsZkMs1SIFCAAHVbc6iGdLu2QUA6kDd5c8i2XkbLS1W8/JtQ/lOWhNch4C765OqLQFj6a9XRNY33idFyA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <0e60520c-d660-1a83-3f57-3466a0ad617b@suse.com> Date: Wed, 19 Apr 2023 12:45:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH 3/5] x86/PV: restrict guest-induced WBINVD (or alike) to cache writeback Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> In-Reply-To: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> X-ClientProxiedBy: FR2P281CA0126.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9d::20) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AM7PR04MB7013:EE_ X-MS-Office365-Filtering-Correlation-Id: 42850444-faec-4451-0e09-08db40c3428a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mlAYDtB9+UlHT5sxw06Ju+CZj7eD0ICRjgu9Z4vP1bvZQcfedeQ3LRZ69/XD5T9bp6IGB66vxcuxXA8MgEu/wKReVSkGBu1nOgB3YNfXeuKgI5wvfKcSV/RcZy30bKkFTr4pjS2a2NJ6L4hzKlm7v/UNkmO7qxuukUpbzQZdxIphGPYL5RTWnUxu4CqR7WDbqWi9V3gVdFxdsqdNbm8GBFOYDo+tAc2esESg2l2+rjetyksNNHbHIeAv9bibtGxXI1bMMmMcYHfdE50FFG3NOHpJwaho0hYoQcUwqvKKVO85Ra57gl/RtIGCZv+hQ3IyxBgPntLM69oVupQsU3eK47SUI1GpkTFbBMlXsVyZOCO1dRpcyx0BO8yEmB92FBBEm//Rqeq2xg3cRZp+62wLuYQNSDEbt8mqGoFMVd7upirhpzOtxldSrcwF6dm3zpHGtPOzTxC+Nxp0IGHP07pgXgm2qWp4s9QsvKotENsSDdBnC8VeHzUhPJghXw1JiZJgM+ULKtE2etOrxHsN+qlggIpwSRDpghoqnDjmF/e1txT7swaRdzXQYU0wHLQFDhRGtUN+yEiwM4XSPcIGF/MQJ3ivp6MqtLwonW1+3/6werlfyxnMYceLbBtNWC2epnKLIOVDRo2amZ0QbWztnhC0KA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(39850400004)(396003)(346002)(376002)(366004)(451199021)(5660300002)(86362001)(2616005)(83380400001)(31696002)(6512007)(186003)(6506007)(26005)(38100700002)(8676002)(8936002)(54906003)(478600001)(6486002)(316002)(41300700001)(36756003)(4326008)(6916009)(66946007)(66556008)(31686004)(66476007)(2906002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?T9lvQlA4OCGvL0d/bBD+aQhtkIcc?= =?utf-8?q?h95DXbEl1krpYCO/1D1gfs8nrKanuaGvAaenZJkrIzoStb5nI0sdZ6q7XbL1NBpY1?= =?utf-8?q?/YlmSHtDHihQ/LYloPupCgJmAL8dKNPRprc7QZj12Qv4Kz6W9dWrRx/xr6BZVZAKJ?= =?utf-8?q?yHX6JGfZULLo2hOWD/FuVA5SoSjQ2hmPOIDnaqTDx760y2XSL9t/LmL0PaxGdJz6Z?= =?utf-8?q?u5aKXQAoqn2sDAhod2G2kkIj8W7+rTIQBMJ9a4XjD5aw+DQXqM2AnfL+YpchUV3Dm?= =?utf-8?q?1pGkTQ0anp0Lt/fmlQDv8QpjpgW2H9N5eccAPTZjiGEu6n8U3bLtJXm0WBCeUoyHe?= =?utf-8?q?Ek//j55yquqV2bOWnrU1Wil2XXZMMZ/8dM7Ok/7La9HBVQQxD119kOLJHiNB4pQQD?= =?utf-8?q?UC0GhbK+xwRZYZuQS4TLX3diJk6zv8Cry8d5WGULAVSaLgWDxwqCxZ8zU6660AsR3?= =?utf-8?q?HRRnXDymfO17Oqqyu+VN7VVJGMSNjNMHo87cW2jqAanOA0TgMonM6HyT1hF9xspqf?= =?utf-8?q?PIh1N/OCyZTWlrnMb1mnkyU022JSG1HqO7yKWRHh5MOmjR2q/mLIESyfDdDRkZZYy?= =?utf-8?q?xl7W/nPS6EFnUiDKX5SGEjGle7rutnqbnJoFXBKGPOFUNNz5f+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rWQktlxKS/aiDK5pKQ?= =?utf-8?q?UZtthSOp8CCP?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42850444-faec-4451-0e09-08db40c3428a X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 10:45:58.3667 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iNvkjVHBMHpDudxfPFXpZAdYoLCYQK3QRGnGWg/QY0szfAO0j1Zh5Nch+1tZgUMVV+ryjclHgQl+xTY6pKZxrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7013 We allow its use for writeback purposes only anyway, so let's also carry these out that way on capable hardware. We can then also expose the WBNOINVD feature, as there's no difference to WBINVD anymore. Note that respective emulation logic has already been in place since ad3abc47dd23 ("x86emul: support WBNOINVD"). Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3772,7 +3772,7 @@ long do_mmuext_op( else if ( unlikely(!cache_flush_permitted(currd)) ) rc = -EACCES; else - wbinvd(); + wbnoinvd(); break; case MMUEXT_FLUSH_CACHE_GLOBAL: @@ -3788,7 +3788,7 @@ long do_mmuext_op( if ( !cpumask_intersects(mask, per_cpu(cpu_sibling_mask, cpu)) ) __cpumask_set_cpu(cpu, mask); - flush_mask(mask, FLUSH_CACHE); + flush_mask(mask, FLUSH_WRITEBACK); } else rc = -EINVAL; --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -1196,10 +1196,8 @@ static int cf_check cache_op( * newer linux uses this in some start-of-day timing loops. */ ; - else if ( op == x86emul_wbnoinvd /* && cpu_has_wbnoinvd */ ) - wbnoinvd(); else - wbinvd(); + wbnoinvd(); return X86EMUL_OKAY; } --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -238,7 +238,7 @@ XEN_CPUFEATURE(EFRO, 7*32+10) / /* AMD-defined CPU features, CPUID level 0x80000008.ebx, word 8 */ XEN_CPUFEATURE(CLZERO, 8*32+ 0) /*A CLZERO instruction */ XEN_CPUFEATURE(RSTR_FP_ERR_PTRS, 8*32+ 2) /*A (F)X{SAVE,RSTOR} always saves/restores FPU Error pointers */ -XEN_CPUFEATURE(WBNOINVD, 8*32+ 9) /*S WBNOINVD instruction */ +XEN_CPUFEATURE(WBNOINVD, 8*32+ 9) /*A WBNOINVD instruction */ XEN_CPUFEATURE(IBPB, 8*32+12) /*A IBPB support only (no IBRS, used by AMD) */ XEN_CPUFEATURE(IBRS, 8*32+14) /*S MSR_SPEC_CTRL.IBRS */ XEN_CPUFEATURE(AMD_STIBP, 8*32+15) /*S MSR_SPEC_CTRL.STIBP */ From patchwork Wed Apr 19 10:46:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13216633 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2994FC6FD18 for ; Wed, 19 Apr 2023 10:46:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.523330.813299 (Exim 4.92) (envelope-from ) id 1pp5KU-000738-Vr; Wed, 19 Apr 2023 10:46:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 523330.813299; Wed, 19 Apr 2023 10:46:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5KU-000731-Re; Wed, 19 Apr 2023 10:46:26 +0000 Received: by outflank-mailman (input) for mailman id 523330; Wed, 19 Apr 2023 10:46:25 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5KS-0006CV-VX for xen-devel@lists.xenproject.org; Wed, 19 Apr 2023 10:46:24 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on061e.outbound.protection.outlook.com [2a01:111:f400:fe0e::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6dd92642-de9f-11ed-b21f-6b7b168915f2; Wed, 19 Apr 2023 12:46:24 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM7PR04MB7013.eurprd04.prod.outlook.com (2603:10a6:20b:116::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Wed, 19 Apr 2023 10:46:23 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae%2]) with mapi id 15.20.6298.045; Wed, 19 Apr 2023 10:46:23 +0000 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: 6dd92642-de9f-11ed-b21f-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iZHNvWxjZhlshU9FWzDmjFI4NCjQyVdHO4eLwswL7ROeDq9qxakyyvzc5dvg4d6oxutn+8gplwj/9JkVgrpKmsm0aYCVB38XkAJ2KU0jBxIe1l3PM39iIqDmuj8rq6kIH/10lGYVChY734k5dMacRP2XsH17rABEBIsdZpVBJf22ToMYpRDkGzVWSFMVQBie5tT69r+Fhuoou101TmrWYO+oEk5iYjBhhhZAX9Nd1GsugV1L5ab2VgbMzOMxTFskWzD56ko7sbGsqjIm6jEpJiAcuuTLc2KieN62BgBuRxZqDC14wT+e6/wBTYeu/2Iz2nYfs80RTVrGoMyoPch8nA== 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=tq9WHKGqRr1z/PValrjLOh415pqYopf5CMM1Py5K+Iw=; b=NwHfGoCRIHh3pURNKg2sXz5jlvVPWcKrwTuM2vrKsKU6P6JTaeKslJGmfYnDdhkEr3I2UqNnlx9fpED7quBExRlAA3bnG8zLXaT248TerrSxEUH1VUCq2OHzc7LShM7ljq66mDpZ3xhkoyVA1nWHgUmS0qW7fl2Nr0FcsAjH6mcc54/VnWbleS6yxw1k2XHuo42Lb6NY2qyUsqJky2vnXjJML3MywCsDY8liqx3/HO2Ws91vnbpNSypHkPr4wSRbC4FyXKRngUokgCyg4itznc7t/niZc2k1tynstiGNqbXWmoBiR9LZFa0B0h8M5vMqGfMEKlqZO1DdrERq6x6WGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tq9WHKGqRr1z/PValrjLOh415pqYopf5CMM1Py5K+Iw=; b=igKjTYW6eq1St33CBa9YYBklQHM8GsLA7uraQFVMRKOWpFyaXtAgNGioi7L4YGo4N/4t2yv1wRYbnbnS5HZrzo5CUxWZxKFHp44I8Qo4vsicnepMSmev3YvnjsefRCJJo6CY356pLzyx2Xg3v6ble/jsfDzuVtunvi4xU/ASSE3lEEkeDrcELw3eStCxfP1pv5jYiJjv4QSWDhDsTWmB59+epSoUCerIC9pL3zNaWl8NpJ8B+RaylbabxwEuLNayYLTKfzd4PYk6K4f0I7L3fokJt7cLzeudlyrclcUtk8cY9a6xQfBShHOSz22f5W+/ObG2JvkRc9gZazQI2NXKng== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 19 Apr 2023 12:46:21 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH 4/5] VT-d: restrict iommu_flush_all() to cache writeback Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Kevin Tian References: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> In-Reply-To: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> X-ClientProxiedBy: FR0P281CA0263.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b5::6) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AM7PR04MB7013:EE_ X-MS-Office365-Filtering-Correlation-Id: 22352383-79f2-464a-ab91-08db40c35158 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qh1WnuqT5me8oDW6t0ajcZaYYk9SsQUn1+Cm8vAzfayfAXimO4Rs6csHRjNnkE9i0rXDf0MJrPV7+Ew0hvaRYOadp0MwKL/4YU8hfoEZMxII16F1Mo5zsOYfMqN2FWwJoi/0cVpshgYE6Anp1oxsw4TMY+owUdz2jWd3T4MyQ2LghDjX9QdD/nGLeeM2P4E8L3DJoqlxAgUGZgAbUmRMyawN98Es6MZtYDfGyNlAB8It+Jdo60qiUb7tvL/keivTYQshsa4D1H9B222urZLQkyIY2JsTNWAAyB08OnGZNkVHDylUSfzhF0WPFfuGyjkFMlGm02G/ekg04rOU9zDOyBlOGaDh1M3Vd1bl8Urrw+h90z+YljPKpZDloYOxwap8si9gKrNoXnqJtIGtKhygKqA1pOu9zeAiDJx/rhiizFpmsa9wsA+U+z1juSe/W4ADkGCYj9OrwmSckm47zS4DUAf7p+fS4hEpv67ek3I7h+gLoJLjRttnmIKarHCK6+/paRu0N9id4suI8TBO39CphPiwa/l+QY71GehRcvgEINoq8Oh2FdhAq4k1SJBMn2yCqz+odW99piBesiESGFYTE/X9yQGqI78qa+xlHTmke8EmJSJmueXOAmdPtIqBFA/wgGEq++Ap65GUKS4pBQfAAg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(39850400004)(396003)(346002)(376002)(366004)(451199021)(5660300002)(86362001)(2616005)(83380400001)(31696002)(6512007)(186003)(6506007)(26005)(38100700002)(8676002)(8936002)(54906003)(478600001)(6486002)(316002)(41300700001)(36756003)(4326008)(6916009)(66946007)(66556008)(31686004)(66476007)(2906002)(4744005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?k/trYYeMaX2Q1ecvRwpExHeBD3Mg?= =?utf-8?q?XlVzWcWgb4iWBHjrJc5ST+UE0s4y5Y5ofawedYYy+IV6XUZ5lJJ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?utf-8?q?0dWjVego18BIqpFi8Z59lOZPBCejjlvWRv1VyGpk2VGOyNF62v1qTGPK68fGZ+D9u?= =?utf-8?q?xtNwz63aA+7EGZmx4HG8MkgcJqW5kYfpr254E3Q6Ps++Wa2TdGIY9b+qNDGSH63ZH?= =?utf-8?q?7179GLSv/cW3bfvaVrnu01N60gyodGwYE1HJEyrzjmwrL8Y1wv0N6w/9c0AEFPj0n?= =?utf-8?q?MmHTn1HmsaxjDT1wkDOKuDdI04euqFrBl3rykgJOct/0dKTnDEPOEqJa2nW81kagM?= =?utf-8?q?EkseQ3eqw8guWIE4QCDfWlsZ0VzahF16fB8uq7B/pIfp67hOba+/UP1+9TtA11Jnu?= =?utf-8?q?v90hWsANK4GzjFbrEJyjkEFnG3TnqXLu1iiplEwm569S85GzXImtB+8eql7yx20Do?= =?utf-8?q?CVbGSaamPpade4unFCuWRL4kX+8oEPt0G9FEP00UuSY+0NEuEQDCCcl+q7cAk7pKm?= =?utf-8?q?W84FP4kX893JiRUYglO12BW8nE3xwpKP5YzKak6XCfoKeF2I0ztEqzcNgSklrZHlu?= =?utf-8?q?kdKhc+slosRu9IDOowkAy7zt0IwFRxIc859E2llMbOLrqL2h2MwRMDvc4/qKTLEhL?= =?utf-8?q?/dJUADLFFWfW?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22352383-79f2-464a-ab91-08db40c35158 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 10:46:23.1947 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PhMQsbeKyzqu18/ZP+15HtTiIOfYZr0nFxJLaPK+J74gfTKfyjfEcTswglgDw2pyt3S+2hH68bHw99RMgfQzFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7013 We don't need to invalidate caches here; all we're after is that earlier writes have made it to main memory (and aiui even that just in case). Signed-off-by: Jan Beulich --- This, aiui, being an analogue to uses of iommu_sync_cache() (just not range restricted), I wonder whether it shouldn't be conditional upon iommu_non_coherent. Then again I'm vaguely under the impression that we had been here before, possibly even as far as questioning the need for this call altogether. --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -693,7 +693,7 @@ static int __must_check iommu_flush_all( bool_t flush_dev_iotlb; int rc = 0; - flush_local(FLUSH_CACHE); + flush_local(FLUSH_WRITEBACK); for_each_drhd_unit ( drhd ) { From patchwork Wed Apr 19 10:46:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13216634 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 69663C6FD18 for ; Wed, 19 Apr 2023 10:47:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.523340.813309 (Exim 4.92) (envelope-from ) id 1pp5L3-0007rh-79; Wed, 19 Apr 2023 10:47:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 523340.813309; Wed, 19 Apr 2023 10:47:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5L3-0007rW-4Q; Wed, 19 Apr 2023 10:47:01 +0000 Received: by outflank-mailman (input) for mailman id 523340; Wed, 19 Apr 2023 10:47:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp5L2-0006CV-4b for xen-devel@lists.xenproject.org; Wed, 19 Apr 2023 10:47:00 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0602.outbound.protection.outlook.com [2a01:111:f400:fe02::602]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 82aa2f45-de9f-11ed-b21f-6b7b168915f2; Wed, 19 Apr 2023 12:46:59 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PA4PR04MB9272.eurprd04.prod.outlook.com (2603:10a6:102:2a7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Wed, 19 Apr 2023 10:46:58 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::52b2:f58:e19:56ae%2]) with mapi id 15.20.6298.045; Wed, 19 Apr 2023 10:46:58 +0000 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: 82aa2f45-de9f-11ed-b21f-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YJXEa/xQOLzSclZZsD042z7q+zZyZm60WvljSk4/1lYTZWm1UrAi24fca/YNGzE6KjLDg9EdMJW01zv93bUHhaqUB7iNcibnzOm/H53dFWWzxGbsqwKbkjGKjRaJFgSjrDGavmv5jOPGJy8pHRgjYdzESJGkRnNz2A73ONgN2gN8ZH3oGkkkDj9I0KZExiKHTOuTcQXJm1vDmKaCDgsbyZM1E3wpH+1W5PBteNsN31PB2g3nwy17djmMHh4cnoHLGTqc37HXORX76UM8zzmrlg1s66ZqCVXW6BCo2aaRJyle7zCJfOH0TLgSxW70R6SXsbW+tejmFRViEWAu+kw5/g== 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=R7uQczNK/4mpSt5b9zhiriwBYD9oXL4EeN1Uwl2RegA=; b=jb5qkX000ImTuxlilqXO5HUKCE1GOraIe2kna+dlZgwgwi/uVql3vJhqKMWaCfIrebOy2inbLf1RXMbzCGTxY3ifved3Q33cWbgJIQvP/D1ddK+fZTZyaJ2WKPj/WeozQ773k6K4K8/RZ8mL0FVnSohSOTmQScWgEv7qxTuRUZ5r884xE3OfyXkwS6O+6aZTEKUZGQfE32OLopiGwvh26veVWLYUwABeWLjrncsuQfYY7w9a3R4zuUC7bmFLqpXMThO4OBA3Kc2EOFFiRJ9uqMW9V+D3/qoKgCXK5ajQp/JcEh4QDqnSeLfzNeF90hhZnRW420qYmDiWw4fCJi5fQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R7uQczNK/4mpSt5b9zhiriwBYD9oXL4EeN1Uwl2RegA=; b=CbFgW3ZQItvcUoFrDKcNOOz/yIV4LywC4G6xCJMAUXtuyMLjLbO4kwH6POA7uGp96shILOoY1QTJQ6Vbp4LY62n0gOBCpjEQvWk4uVpVnYaZqtugtaWRa2HTJ8ghqvVquGmdqhFwXgbnKoN72WYZuQmZ86A3MQ0zzPebybnL+V6/CSjAKAL5LIJlYMg4H8KVHKP70CxJjWS9+yuKPWsxUZXaV3DrkTlRcj8bkxZJf0iIMC8yLWLjMhhFdgl7k4pVHpimthVrlgXDN8JAG+Gv7JHRFf1b2hHi5mP83ZnM5qQjVx90xb69RKnmiKrni4hx0VQ7kXEuWPLs4vxHhXDWww== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <18fcf499-a2ae-ab48-a66f-ca0499097e8a@suse.com> Date: Wed, 19 Apr 2023 12:46:56 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH 5/5] x86/HVM: limit cache writeback overhead Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Kevin Tian , Jun Nakajima References: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> In-Reply-To: <4b42e920-f007-186c-d838-a0294bfa86b5@suse.com> X-ClientProxiedBy: FR3P281CA0141.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::14) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|PA4PR04MB9272:EE_ X-MS-Office365-Filtering-Correlation-Id: ba814f8b-5957-4809-610d-08db40c3660c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YRA9wm5W+WiTVRPqwm+QPdxYdYqUIFLsSR0gIQUgfamTAseIesmpMRSHQoqM9juQVfEyzu9vrwByxZYO8pRzsMFuADZQwEZaY1I7RoC3GqbZF10Iej+pcMdaoRdShh9rgYAOU9BlCSPyEeS6y99cNNke7dibKzcFUnFNZ68ZzL8Auk9vXw2rUYq5jJ5OaYGqBnktCxpQr3qPYEj1vLG6gogHKiI/BjzW97hA3Za0xUCDTRK8f5aHbpYxhoeJN5N6Zxmvs+gIV08JDZf4ExzyV0DtsWcObWHmsSwcpXBkmS3P3XNqoNwcUQPOsxNsQAQp8cIVfiPbU8s+jEq+I2gnAPyAHATyskdj8bqn1EuYLcf7fZc6RWvbEgEpJCCYovA2EUt5sRnMXEkN/Fyvs7Mw+MTAHdLFbnI31YDkj+cI1nKo8ZSRTb4zZTeV+89v3G5tDWAF6y9chlVEWNxuYMfRGNm8wPaxRd5GkWvv7BhMN6cYY7SXLbIog0wOKT8sr3i2DM5OeDj8HtsOI76vtVs2PE/spo1+9aMbkzZX4R6sAfVzsLE9IGqZ6YGl9YEv+YTInxY+p/AQqKhXsK5UcCbiMkuRFYSCO2qoXmJ1jmgkZOfVVnJvV+6IBzraeDpS+zFspnn+yMTra0XP/PY8jAS3fQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(39860400002)(396003)(136003)(346002)(366004)(451199021)(66476007)(478600001)(38100700002)(8936002)(8676002)(316002)(41300700001)(6916009)(4326008)(66946007)(66556008)(54906003)(186003)(2906002)(6512007)(36756003)(26005)(83380400001)(6506007)(86362001)(31696002)(2616005)(31686004)(5660300002)(6486002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?sXs3fAUsAOm1gyicJZOtTc+cHQw+?= =?utf-8?q?/FkfiNOoiiLlU4be05i1aQdbuOi4KFivaveIAMXbkExQ54/G1zTJ5jlavZGMlKRjB?= =?utf-8?q?enlfqN5zPUGa3RUTIWCiPYU9y/8zc0npAYrWkCuMIc+tntnBcf4wNipRy/nP+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=?utf-8?q?R1wuXeoYyZBpo1G+7GEGbKOu8Hlp1s4JvIKJK5ih2UHn4/0HwIHVlZMTsEBCf42vZ?= =?utf-8?q?A2jfOr+R7KP3N++KSp0tAbd8OrVBP+UBGv9PN316lSAOS4+RZUptK0MqmgsGXKHUO?= =?utf-8?q?aJ/d2xuHL+euB+7MNwLKJh1q9ste5BfJz/aOSrzKjCHnKEN0T5zx1xRIjL+f1Q7s9?= =?utf-8?q?stb7m0bJ08q0FMw5ZbhuxaNG2cuyA/rMgeD/vII24mHwwPM+Jy0gfG9IRw8PPZ595?= =?utf-8?q?72fwzyIzun1NIMJNvzU+6RrGZ41EzIRozyWemighj6rDv6+8t0i0kDZ8ExbY+T14B?= =?utf-8?q?1OzNMc6FtGzokBXSC9WUhD2NRDIWuW2nDx+AkS7YMeCn/hmmvRZ59K+IBdhSBDh8Y?= =?utf-8?q?LtmDAXl4VdisvLpNnSttWyCjrVC19NVYiRUzBgDBoEuNmIOwMYrBzL0bRqpylWzEw?= =?utf-8?q?NImvJFD77g8ECeGNBVxX3Ky+ETcNZM0HDSO2+7Rins4oY5TGHVqxdFHX6btZNpbJa?= =?utf-8?q?R8uBVLr45hlG?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba814f8b-5957-4809-610d-08db40c3660c X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 10:46:57.9280 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: k6Khoj9pc60HiNVQA0ybCULb6DXIyh9KQLJ9s2WHQxVgnw+7wpqzz51G7waPWtWXFhtu+0WYxKIfyxFeE4zupg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9272 There's no need to write back caches on all CPUs upon seeing a WBINVD exit; ones that a vCPU hasn't run on since the last writeback (or since it was started) can't hold data which may need writing back. Signed-off-by: Jan Beulich --- With us not running AMD IOMMUs in non-coherent ways, I wonder whether svm_wbinvd_intercept() really needs to do anything (or whether it couldn't check iommu_snoop just like VMX does, knowing that as of c609108b2190 ["x86/shadow: make iommu_snoop usage consistent with HAP's"] that's always set; this would largely serve as grep fodder then, to make sure this code is updated once / when we do away with this global variable, and it would be the penultimate step to being able to fold SVM's and VT-x'es functions). --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -537,6 +537,8 @@ void hvm_do_resume(struct vcpu *v) v->arch.hvm.inject_event.vector = HVM_EVENT_VECTOR_UNSET; } + __cpumask_set_cpu(v->processor, v->arch.hvm.cache_dirty_mask); + if ( unlikely(v->arch.vm_event) && v->arch.monitor.next_interrupt_enabled ) { struct x86_event info; @@ -1592,6 +1594,10 @@ int hvm_vcpu_initialise(struct vcpu *v) if ( rc ) goto fail6; + rc = -ENOMEM; + if ( !zalloc_cpumask_var(&v->arch.hvm.cache_dirty_mask) ) + goto fail6; + rc = ioreq_server_add_vcpu_all(d, v); if ( rc != 0 ) goto fail6; @@ -1621,6 +1627,7 @@ int hvm_vcpu_initialise(struct vcpu *v) hvm_vcpu_cacheattr_destroy(v); fail1: viridian_vcpu_deinit(v); + FREE_CPUMASK_VAR(v->arch.hvm.cache_dirty_mask); return rc; } @@ -1628,6 +1635,8 @@ void hvm_vcpu_destroy(struct vcpu *v) { viridian_vcpu_deinit(v); + FREE_CPUMASK_VAR(v->arch.hvm.cache_dirty_mask); + ioreq_server_remove_vcpu_all(v->domain, v); if ( hvm_altp2m_supported() ) --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2363,8 +2363,14 @@ static void svm_vmexit_mce_intercept( static void cf_check svm_wbinvd_intercept(void) { - if ( cache_flush_permitted(current->domain) ) - flush_all(FLUSH_WRITEBACK); + struct vcpu *curr = current; + + if ( !cache_flush_permitted(curr->domain) ) + return; + + flush_mask(curr->arch.hvm.cache_dirty_mask, FLUSH_WRITEBACK); + cpumask_copy(curr->arch.hvm.cache_dirty_mask, + cpumask_of(curr->processor)); } static void svm_vmexit_do_invalidate_cache(struct cpu_user_regs *regs, --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3710,11 +3710,17 @@ static void vmx_do_extint(struct cpu_use static void cf_check vmx_wbinvd_intercept(void) { - if ( !cache_flush_permitted(current->domain) || iommu_snoop ) + struct vcpu *curr = current; + + if ( !cache_flush_permitted(curr->domain) || iommu_snoop ) return; if ( cpu_has_wbinvd_exiting ) - flush_all(FLUSH_WRITEBACK); + { + flush_mask(curr->arch.hvm.cache_dirty_mask, FLUSH_WRITEBACK); + cpumask_copy(curr->arch.hvm.cache_dirty_mask, + cpumask_of(curr->processor)); + } else wbnoinvd(); } --- a/xen/arch/x86/include/asm/hvm/vcpu.h +++ b/xen/arch/x86/include/asm/hvm/vcpu.h @@ -161,6 +161,8 @@ struct hvm_vcpu { struct svm_vcpu svm; }; + cpumask_var_t cache_dirty_mask; + struct tasklet assert_evtchn_irq_tasklet; struct nestedvcpu nvcpu;