From patchwork Tue Feb 27 11:25:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13573567 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 E4F9FC54798 for ; Tue, 27 Feb 2024 11:25:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.686018.1067546 (Exim 4.92) (envelope-from ) id 1revaj-0007mO-FJ; Tue, 27 Feb 2024 11:25:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 686018.1067546; Tue, 27 Feb 2024 11:25:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1revaj-0007mH-CB; Tue, 27 Feb 2024 11:25:45 +0000 Received: by outflank-mailman (input) for mailman id 686018; Tue, 27 Feb 2024 11:25:44 +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 1revai-0007l8-83 for xen-devel@lists.xenproject.org; Tue, 27 Feb 2024 11:25:44 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f0a095c5-d562-11ee-a1ee-f123f15fe8a2; Tue, 27 Feb 2024 12:25:41 +0100 (CET) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-5101cd91017so6097290e87.2 for ; Tue, 27 Feb 2024 03:25:41 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id ow34-20020a05620a822200b00783f8693df1sm3495000qkn.37.2024.02.27.03.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:25:40 -0800 (PST) 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: f0a095c5-d562-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709033141; x=1709637941; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zbRmLbHcypo3JwhtnaEO0O2QVQTm0Ebx3zCXiOOR5V4=; b=c3GlLnhuurlM5WjFBDmPEqJWlVF8ym2CfaFqjLPRoDl+7hSVrX/klAj4/4Lc1JMS9L tHtvfepIxuGKDZJC+N2hGLvkGU/9AgF4yC8sCbq2qjBuwh8jaWBQtZw/fdZ8ygzhMMCF KEpetiMEQdcH2Kte/IoBlsGsQgUVpYN8SwgQ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709033141; x=1709637941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zbRmLbHcypo3JwhtnaEO0O2QVQTm0Ebx3zCXiOOR5V4=; b=JHyEho1WmQEpza3H/ylJLVsz72AjQ8njhCBpR7kxVELvOQhRvF/bob+g3g1L8NJLRp IVSu/5sN8kWgjEwHY1CXff4KnZHO+gdpIM5Hj+TR6Zm6B+yxDCezPnVwmSnYMeQFUEuX OzAyG1qTMWYPiq63pqWZQFEcLtab+a793GRCIMRkqWpuOd/wWh+1CaCz8+m3QNcAcnu8 eLIhv50481G9iiqgpAsnfVKwV5/06wRJ6niI0la1NatK2/ReVobsQjfwouUwrollZ8Vh RZwVfhyBLgvTUh/KMMwCpEAaNkg7forGudThc+Fb776gYlVLZwNungtD6Yp/sY1m1LmL 0tJA== X-Gm-Message-State: AOJu0YwZIKJ39vp1j5qGtx1ItdsswihkFWu1WEM9+JfAjgooj82NN3u6 X+bruyDNujcmAm7I1ZJGcWUbvjUSHqtGsATROTfSW0B+9UqfDgTc9oXiep4EkKJBQDGLFQ+++vt v X-Google-Smtp-Source: AGHT+IHPcPdLXOxgviX0WjqxhQH7g/pIM3M7XqU6ugPtHAfWzob4fpoIF5FsyyX+Mazt8klqsRoXZg== X-Received: by 2002:a19:6405:0:b0:512:acf1:6970 with SMTP id y5-20020a196405000000b00512acf16970mr5150205lfb.35.1709033140736; Tue, 27 Feb 2024 03:25:40 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Konrad Rzeszutek Wilk , Ross Lagerwall , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v2 1/5] xen/livepatch: register livepatch regions when loaded Date: Tue, 27 Feb 2024 12:25:24 +0100 Message-ID: <20240227112528.4540-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227112528.4540-1-roger.pau@citrix.com> References: <20240227112528.4540-1-roger.pau@citrix.com> MIME-Version: 1.0 Currently livepatch regions are registered as virtual regions only after the livepatch has been applied. This can lead to issues when using the pre-apply or post-revert hooks, as at that point the livepatch is not in the virtual regions list. If a livepatch pre-apply hook contains a WARN() it would trigger an hypervisor crash, as the code to handle the bug frame won't be able to find the instruction pointer that triggered the #UD in any of the registered virtual regions, and hence crash. Fix this by adding the livepatch payloads as virtual regions as soon as loaded, and only remove them once the payload is unloaded. This requires some changes to the virtual regions code, as the removal of the virtual regions is no longer done in stop machine context, and hence an RCU barrier is added in order to make sure there are no users of the virtual region after it's been removed from the list. Fixes: 8313c864fa95 ('livepatch: Implement pre-|post- apply|revert hooks') Signed-off-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- Changes since v1: - Add the virtual region in livepatch_upload(). - Make unregister_virtual_region() depend on CONFIG_LIVEPATCH. --- xen/common/livepatch.c | 4 ++-- xen/common/virtual_region.c | 42 ++++++++++++++----------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 2c4b84382798..d7f50e101858 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -1071,6 +1071,7 @@ static int build_symbol_table(struct payload *payload, static void free_payload(struct payload *data) { ASSERT(spin_is_locked(&payload_lock)); + unregister_virtual_region(&data->region); list_del(&data->list); payload_cnt--; payload_version++; @@ -1170,6 +1171,7 @@ static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload) INIT_LIST_HEAD(&data->list); INIT_LIST_HEAD(&data->applied_list); + register_virtual_region(&data->region); list_add_tail(&data->list, &payload_list); payload_cnt++; payload_version++; @@ -1386,7 +1388,6 @@ static inline void apply_payload_tail(struct payload *data) * The applied_list is iterated by the trap code. */ list_add_tail_rcu(&data->applied_list, &applied_list); - register_virtual_region(&data->region); data->state = LIVEPATCH_STATE_APPLIED; } @@ -1432,7 +1433,6 @@ static inline void revert_payload_tail(struct payload *data) * The applied_list is iterated by the trap code. */ list_del_rcu(&data->applied_list); - unregister_virtual_region(&data->region); data->reverted = true; data->state = LIVEPATCH_STATE_CHECKED; diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index ddac5c9147e5..e3a4dc8540df 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -23,14 +23,8 @@ static struct virtual_region core_init __initdata = { }; /* - * RCU locking. Additions are done either at startup (when there is only - * one CPU) or when all CPUs are running without IRQs. - * - * Deletions are bit tricky. We do it when Live Patch (all CPUs running - * without IRQs) or during bootup (when clearing the init). - * - * Hence we use list_del_rcu (which sports an memory fence) and a spinlock - * on deletion. + * RCU locking. Modifications to the list must be done in exclusive mode, and + * hence need to hold the spinlock. * * All readers of virtual_region_list MUST use list_for_each_entry_rcu. */ @@ -58,41 +52,36 @@ const struct virtual_region *find_text_region(unsigned long addr) void register_virtual_region(struct virtual_region *r) { - ASSERT(!local_irq_is_enabled()); + unsigned long flags; + spin_lock_irqsave(&virtual_region_lock, flags); list_add_tail_rcu(&r->list, &virtual_region_list); + spin_unlock_irqrestore(&virtual_region_lock, flags); } -static void remove_virtual_region(struct virtual_region *r) +/* + * Suggest inline so when !CONFIG_LIVEPATCH the function is not left + * unreachable after init code is removed. + */ +static void inline remove_virtual_region(struct virtual_region *r) { unsigned long flags; spin_lock_irqsave(&virtual_region_lock, flags); list_del_rcu(&r->list); spin_unlock_irqrestore(&virtual_region_lock, flags); - /* - * We do not need to invoke call_rcu. - * - * This is due to the fact that on the deletion we have made sure - * to use spinlocks (to guard against somebody else calling - * unregister_virtual_region) and list_deletion spiced with - * memory barrier. - * - * That protects us from corrupting the list as the readers all - * use list_for_each_entry_rcu which is safe against concurrent - * deletions. - */ } +#ifdef CONFIG_LIVEPATCH void unregister_virtual_region(struct virtual_region *r) { - /* Expected to be called from Live Patch - which has IRQs disabled. */ - ASSERT(!local_irq_is_enabled()); - remove_virtual_region(r); + + /* Assert that no CPU might be using the removed region. */ + rcu_barrier(); } -#if defined(CONFIG_LIVEPATCH) && defined(CONFIG_X86) +#ifdef CONFIG_X86 void relax_virtual_region_perms(void) { const struct virtual_region *region; @@ -117,6 +106,7 @@ void tighten_virtual_region_perms(void) rcu_read_unlock(&rcu_virtual_region_lock); } #endif +#endif void __init unregister_init_virtual_region(void) { From patchwork Tue Feb 27 11:25:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13573568 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 2F918C5478C for ; Tue, 27 Feb 2024 11:25:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.686019.1067558 (Exim 4.92) (envelope-from ) id 1revak-00083A-PQ; Tue, 27 Feb 2024 11:25:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 686019.1067558; Tue, 27 Feb 2024 11:25:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1revak-000833-Kk; Tue, 27 Feb 2024 11:25:46 +0000 Received: by outflank-mailman (input) for mailman id 686019; Tue, 27 Feb 2024 11:25:45 +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 1revaj-0007l8-Ih for xen-devel@lists.xenproject.org; Tue, 27 Feb 2024 11:25:45 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f21e9684-d562-11ee-a1ee-f123f15fe8a2; Tue, 27 Feb 2024 12:25:44 +0100 (CET) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-512e39226efso5576425e87.0 for ; Tue, 27 Feb 2024 03:25:44 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id on33-20020a05621444a100b0068fcd643b9dsm4026531qvb.22.2024.02.27.03.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:25:42 -0800 (PST) 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: f21e9684-d562-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709033143; x=1709637943; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=adt3YzhrFcYBWzR8wX43amlG22Ma23x7ZH5fofejSpQ=; b=AvxkxG2156hQiKaZqE94OZXt9Z/SOQkbKp05QHlbelojlxbS+IYbJDz6ORDOujv51G +Wxqwr1F08v2J50ydEsmk/Xx/Gq5BFqs668lUfAv0CtNU5hGZdCo8k00Vi2KGJkdSgct hNdy0MtI4nGAaKv0rjtCGiHiptkDSdSeI8EoM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709033143; x=1709637943; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=adt3YzhrFcYBWzR8wX43amlG22Ma23x7ZH5fofejSpQ=; b=jE+SQ20eku5AEKdICf+lRtq0AZGWdNfGom8LEHt4CwKE2RTSstz7Kc0VAEHuHaIAdY UnuHt2RWKPkW7M3CSsQbSl4CFJP+Gl3GasHyO9h4fhsG9wb+ZZEiY+qpCOb1zNKMNfV6 HE2xrwrXDHLOKy+B/59MkO7Xcrdvz3AbXhvwULpC9JjrcvYQBzGO+NvM4UrMdZfX1TIT GqV0Kat4wtG0cg89zNW0hI4AnrKqWQPbJf/Ti1wrZ3NICeBeJc5R8vW5yGTDH29nX2AG S+jYoy0wkkAUs8dlcL+shGLWksYLT23hOtG3j0WN8VLsQAgI4ehA2a7gVtVz8oijHtm0 nDCQ== X-Gm-Message-State: AOJu0Yw/r6V2W1q5ytZYg9Ji0kF5n0v5PjIaCDRFb36umnXaj/H1tbqy kPuvPjpU6v5kotacfCYzOYTlEEkxhS7sv1mporB47Et+SJYnXzxwlo/rGUVpdpJTZHYRCJQtIZc B X-Google-Smtp-Source: AGHT+IFrcnfBqjubkVqz3lZabcZvN3Ua4viJGKpy6BgXTXfWXX5iv7XXj2buKAEP1g7vqVfsLqFjNQ== X-Received: by 2002:ac2:5e85:0:b0:512:ed5f:3bf0 with SMTP id b5-20020ac25e85000000b00512ed5f3bf0mr5608169lfq.28.1709033143015; Tue, 27 Feb 2024 03:25:43 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Konrad Rzeszutek Wilk , Ross Lagerwall Subject: [PATCH v2 2/5] xen/livepatch: search for symbols in all loaded payloads Date: Tue, 27 Feb 2024 12:25:25 +0100 Message-ID: <20240227112528.4540-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227112528.4540-1-roger.pau@citrix.com> References: <20240227112528.4540-1-roger.pau@citrix.com> MIME-Version: 1.0 When checking if an address belongs to a patch, or when resolving a symbol, take into account all loaded livepatch payloads, even if not applied. This is required in order for the pre-apply and post-revert hooks to work properly, or else Xen won't detect the instruction pointer belonging to those hooks as being part of the currently active text. Move the RCU handling to be used for payload_list instead of applied_list, as now the calls from trap code will iterate over the payload_list. Fixes: 8313c864fa95 ('livepatch: Implement pre-|post- apply|revert hooks') Signed-off-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- xen/common/livepatch.c | 49 +++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index d7f50e101858..14295bae8704 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -36,13 +36,14 @@ * caller in schedule_work. */ static DEFINE_SPINLOCK(payload_lock); -static LIST_HEAD(payload_list); - /* - * Patches which have been applied. Need RCU in case we crash (and then - * traps code would iterate via applied_list) when adding entries on the list. + * Need RCU in case we crash (and then traps code would iterate via + * payload_list) when adding entries on the list. */ -static DEFINE_RCU_READ_LOCK(rcu_applied_lock); +static DEFINE_RCU_READ_LOCK(rcu_payload_lock); +static LIST_HEAD(payload_list); + +/* Patches which have been applied. Only modified from stop machine context. */ static LIST_HEAD(applied_list); static unsigned int payload_cnt; @@ -111,12 +112,8 @@ bool is_patch(const void *ptr) const struct payload *data; bool r = false; - /* - * Only RCU locking since this list is only ever changed during apply - * or revert context. And in case it dies there we need an safe list. - */ - rcu_read_lock(&rcu_applied_lock); - list_for_each_entry_rcu ( data, &applied_list, applied_list ) + rcu_read_lock(&rcu_payload_lock); + list_for_each_entry_rcu ( data, &payload_list, list ) { if ( (ptr >= data->rw_addr && ptr < (data->rw_addr + data->rw_size)) || @@ -130,7 +127,7 @@ bool is_patch(const void *ptr) } } - rcu_read_unlock(&rcu_applied_lock); + rcu_read_unlock(&rcu_payload_lock); return r; } @@ -166,12 +163,8 @@ static const char *cf_check livepatch_symbols_lookup( const void *va = (const void *)addr; const char *n = NULL; - /* - * Only RCU locking since this list is only ever changed during apply - * or revert context. And in case it dies there we need an safe list. - */ - rcu_read_lock(&rcu_applied_lock); - list_for_each_entry_rcu ( data, &applied_list, applied_list ) + rcu_read_lock(&rcu_payload_lock); + list_for_each_entry_rcu ( data, &payload_list, list ) { if ( va < data->text_addr || va >= (data->text_addr + data->text_size) ) @@ -200,7 +193,7 @@ static const char *cf_check livepatch_symbols_lookup( n = data->symtab[best].name; break; } - rcu_read_unlock(&rcu_applied_lock); + rcu_read_unlock(&rcu_payload_lock); return n; } @@ -1072,7 +1065,8 @@ static void free_payload(struct payload *data) { ASSERT(spin_is_locked(&payload_lock)); unregister_virtual_region(&data->region); - list_del(&data->list); + list_del_rcu(&data->list); + rcu_barrier(); payload_cnt--; payload_version++; free_payload_data(data); @@ -1172,7 +1166,7 @@ static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload) INIT_LIST_HEAD(&data->applied_list); register_virtual_region(&data->region); - list_add_tail(&data->list, &payload_list); + list_add_tail_rcu(&data->list, &payload_list); payload_cnt++; payload_version++; } @@ -1383,11 +1377,7 @@ static int apply_payload(struct payload *data) static inline void apply_payload_tail(struct payload *data) { - /* - * We need RCU variant (which has barriers) in case we crash here. - * The applied_list is iterated by the trap code. - */ - list_add_tail_rcu(&data->applied_list, &applied_list); + list_add_tail(&data->applied_list, &applied_list); data->state = LIVEPATCH_STATE_APPLIED; } @@ -1427,12 +1417,7 @@ static int revert_payload(struct payload *data) static inline void revert_payload_tail(struct payload *data) { - - /* - * We need RCU variant (which has barriers) in case we crash here. - * The applied_list is iterated by the trap code. - */ - list_del_rcu(&data->applied_list); + list_del(&data->applied_list); data->reverted = true; data->state = LIVEPATCH_STATE_CHECKED; From patchwork Tue Feb 27 11:25:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13573570 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 4A9C6C54798 for ; Tue, 27 Feb 2024 11:25:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.686020.1067567 (Exim 4.92) (envelope-from ) id 1revan-0008M8-4V; Tue, 27 Feb 2024 11:25:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 686020.1067567; Tue, 27 Feb 2024 11:25:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1revan-0008M1-1T; Tue, 27 Feb 2024 11:25:49 +0000 Received: by outflank-mailman (input) for mailman id 686020; Tue, 27 Feb 2024 11:25:47 +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 1reval-0007WG-7S for xen-devel@lists.xenproject.org; Tue, 27 Feb 2024 11:25:47 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f391e6f1-d562-11ee-afd6-a90da7624cb6; Tue, 27 Feb 2024 12:25:46 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-512fd840142so2473743e87.2 for ; Tue, 27 Feb 2024 03:25:46 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id qj24-20020a056214321800b0068f9fd1d688sm4018394qvb.21.2024.02.27.03.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:25:45 -0800 (PST) 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: f391e6f1-d562-11ee-afd6-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709033145; x=1709637945; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gyNyY8wN07OAJqlH/Vju+7fTgYfs6X4zDGd5JPLgEbI=; b=D6XIvQCJrAglvQtlVm3VzruKoSa+wJGOY9iSuMSRfO75lRyZ9ATsdfD8YVibjFi3TQ neKlcbMLLmCUhoEgDIDYJyam/VmhBtwrbN5LbAemBjh5oVx4ys/etJdsDqVll09WeCtb 2ZMpka2SHsQtnqVUg16L8PXLvag95N6Dobe90= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709033145; x=1709637945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gyNyY8wN07OAJqlH/Vju+7fTgYfs6X4zDGd5JPLgEbI=; b=qmP30Fc9FXXsCpCNhkXWf7JcrIEecUg9J4WHY3wHfgl7eoPfnoqZlTu9fMdJaX8XGM sZjd1ABpG3Yf/yDf/05mq4BJydppb+w6GzuMQeeuHQ5mKv9uA89eodcz081Iyw1/2vgl Vc2iqqkYT4ONY3K/EVt5Fw0qg05rkS/PEVshaYzKmA2oD///6bNE0i1cNBj/Jr0FWHNW 46E02tXPZ2TySLGhsF6rJb5sKPvyWkS1ffGzGivluO0nU8kyohYAB5CwdILWTreTm9ZU J/h/HiG6Ml0UJUJkOxbPyAZXOIkAQ+ELWQtVS6UEGZpTQvOWBlliBfONGTqd2jU3HoFp 5llg== X-Gm-Message-State: AOJu0Yxa9j5ebesyGK3dLJKvmkUOtbWn08c/kIN0VpxbUv7geL6h70Uo /ZguVoqVXeQ3nTwJi6TQKc6XlZT/0zs6p8D/VuqBQpJl7UdXNhBGYHDoHG3BnJZk82mrNOabaT3 H X-Google-Smtp-Source: AGHT+IFK2BifGhYTEE4PkQH9bmj7jJsbCai+7Q5HGiCe5i5wxZUV6bppAL1KpT0Cm+eNWRY2nGA/Sg== X-Received: by 2002:ac2:4a9e:0:b0:512:fb31:1ad1 with SMTP id l30-20020ac24a9e000000b00512fb311ad1mr3967371lfp.57.1709033145436; Tue, 27 Feb 2024 03:25:45 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Konrad Rzeszutek Wilk , Ross Lagerwall Subject: [PATCH v2 3/5] xen/livepatch: fix norevert test attempt to open-code revert Date: Tue, 27 Feb 2024 12:25:26 +0100 Message-ID: <20240227112528.4540-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227112528.4540-1-roger.pau@citrix.com> References: <20240227112528.4540-1-roger.pau@citrix.com> MIME-Version: 1.0 The purpose of the norevert test is to install a dummy handler that replaces the internal Xen revert code, and then perform the revert in the post-revert hook. For that purpose the usage of the previous common_livepatch_revert() is not enough, as that just reverts specific functions, but not the whole state of the payload. Remove both common_livepatch_{apply,revert}() and instead expose revert_payload{,_tail}() in order to perform the patch revert from the post-revert hook. Fixes: 6047104c3ccc ('livepatch: Add per-function applied/reverted state tracking marker') Signed-off-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- Changes since v1: - Check return value of revert_payload(). --- xen/common/livepatch.c | 41 +++++++++++++++++-- xen/include/xen/livepatch.h | 32 ++------------- .../livepatch/xen_action_hooks_norevert.c | 22 +++------- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 14295bae8704..5a7d5b7be0ad 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -1366,7 +1366,22 @@ static int apply_payload(struct payload *data) ASSERT(!local_irq_is_enabled()); for ( i = 0; i < data->nfuncs; i++ ) - common_livepatch_apply(&data->funcs[i], &data->fstate[i]); + { + const struct livepatch_func *func = &data->funcs[i]; + struct livepatch_fstate *state = &data->fstate[i]; + + /* If the action has been already executed on this function, do nothing. */ + if ( state->applied == LIVEPATCH_FUNC_APPLIED ) + { + printk(XENLOG_WARNING LIVEPATCH + "%s: %s has been already applied before\n", + __func__, func->name); + continue; + } + + arch_livepatch_apply(func, state); + state->applied = LIVEPATCH_FUNC_APPLIED; + } arch_livepatch_revive(); @@ -1382,7 +1397,7 @@ static inline void apply_payload_tail(struct payload *data) data->state = LIVEPATCH_STATE_APPLIED; } -static int revert_payload(struct payload *data) +int revert_payload(struct payload *data) { unsigned int i; int rc; @@ -1397,7 +1412,25 @@ static int revert_payload(struct payload *data) } for ( i = 0; i < data->nfuncs; i++ ) - common_livepatch_revert(&data->funcs[i], &data->fstate[i]); + { + const struct livepatch_func *func = &data->funcs[i]; + struct livepatch_fstate *state = &data->fstate[i]; + + /* + * If the apply action hasn't been executed on this function, do + * nothing. + */ + if ( !func->old_addr || state->applied == LIVEPATCH_FUNC_NOT_APPLIED ) + { + printk(XENLOG_WARNING LIVEPATCH + "%s: %s has not been applied before\n", + __func__, func->name); + continue; + } + + arch_livepatch_revert(func, state); + state->applied = LIVEPATCH_FUNC_NOT_APPLIED; + } /* * Since we are running with IRQs disabled and the hooks may call common @@ -1415,7 +1448,7 @@ static int revert_payload(struct payload *data) return 0; } -static inline void revert_payload_tail(struct payload *data) +void revert_payload_tail(struct payload *data) { list_del(&data->applied_list); diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index ad0eae28bd0d..d074a5bebecc 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -138,35 +138,11 @@ void arch_livepatch_post_action(void); void arch_livepatch_mask(void); void arch_livepatch_unmask(void); -static inline void common_livepatch_apply(const struct livepatch_func *func, - struct livepatch_fstate *state) -{ - /* If the action has been already executed on this function, do nothing. */ - if ( state->applied == LIVEPATCH_FUNC_APPLIED ) - { - printk(XENLOG_WARNING LIVEPATCH "%s: %s has been already applied before\n", - __func__, func->name); - return; - } - - arch_livepatch_apply(func, state); - state->applied = LIVEPATCH_FUNC_APPLIED; -} +/* Only for testing purposes. */ +struct payload; +int revert_payload(struct payload *data); +void revert_payload_tail(struct payload *data); -static inline void common_livepatch_revert(const struct livepatch_func *func, - struct livepatch_fstate *state) -{ - /* If the apply action hasn't been executed on this function, do nothing. */ - if ( !func->old_addr || state->applied == LIVEPATCH_FUNC_NOT_APPLIED ) - { - printk(XENLOG_WARNING LIVEPATCH "%s: %s has not been applied before\n", - __func__, func->name); - return; - } - - arch_livepatch_revert(func, state); - state->applied = LIVEPATCH_FUNC_NOT_APPLIED; -} #else /* diff --git a/xen/test/livepatch/xen_action_hooks_norevert.c b/xen/test/livepatch/xen_action_hooks_norevert.c index c17385519263..c5fbab174680 100644 --- a/xen/test/livepatch/xen_action_hooks_norevert.c +++ b/xen/test/livepatch/xen_action_hooks_norevert.c @@ -96,26 +96,14 @@ static int revert_hook(livepatch_payload_t *payload) static void post_revert_hook(livepatch_payload_t *payload) { - int i; + unsigned long flags; printk(KERN_DEBUG "%s: Hook starting.\n", __func__); - for (i = 0; i < payload->nfuncs; i++) - { - const struct livepatch_func *func = &payload->funcs[i]; - struct livepatch_fstate *fstate = &payload->fstate[i]; - - BUG_ON(revert_cnt != 1); - BUG_ON(fstate->applied != LIVEPATCH_FUNC_APPLIED); - - /* Outside of quiesce zone: MAY TRIGGER HOST CRASH/UNDEFINED BEHAVIOR */ - arch_livepatch_quiesce(); - common_livepatch_revert(payload); - arch_livepatch_revive(); - BUG_ON(fstate->applied == LIVEPATCH_FUNC_APPLIED); - - printk(KERN_DEBUG "%s: post reverted: %s\n", __func__, func->name); - } + local_irq_save(flags); + BUG_ON(revert_payload(payload)); + revert_payload_tail(payload); + local_irq_restore(flags); printk(KERN_DEBUG "%s: Hook done.\n", __func__); } From patchwork Tue Feb 27 11:25:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13573569 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 8903AC5478C for ; Tue, 27 Feb 2024 11:25:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.686021.1067577 (Exim 4.92) (envelope-from ) id 1revap-0000DS-Eq; Tue, 27 Feb 2024 11:25:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 686021.1067577; Tue, 27 Feb 2024 11:25:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1revap-0000DJ-Ao; Tue, 27 Feb 2024 11:25:51 +0000 Received: by outflank-mailman (input) for mailman id 686021; Tue, 27 Feb 2024 11:25:50 +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 1revao-0007l8-Ag for xen-devel@lists.xenproject.org; Tue, 27 Feb 2024 11:25:50 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f4f9fad6-d562-11ee-a1ee-f123f15fe8a2; Tue, 27 Feb 2024 12:25:48 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-512ab55fde6so5392930e87.2 for ; Tue, 27 Feb 2024 03:25:48 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id w25-20020ae9e519000000b00787a7e9c3e8sm3458446qkf.56.2024.02.27.03.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:25:47 -0800 (PST) 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: f4f9fad6-d562-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709033148; x=1709637948; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dfnDRWSsRLdZRck0ImeXNurgPdtQnzpZXT2sgnYgWu4=; b=uM1hH/OJnt121jcozicLyDoip+o+9jCeI9n6TkYjqbT+Xdqotq6z5nfHAfpa83iEvn o2SG3u9zI5cPlzxuY7PcFyERPZZLJDt2A81P8maKG6RHAhKxIEuItn3Yxf+oJl0QdBvl 3ILjgD3tKiErlSe58n1dRTIJ8UowV3DGpVe/g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709033148; x=1709637948; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dfnDRWSsRLdZRck0ImeXNurgPdtQnzpZXT2sgnYgWu4=; b=oPmEf4634BNmUaRj8S/9xcZ9C4OnfSgzAzH7HETiBWsVfg8J8PAMAGA+0Ji1ANClVY muiqdNTI3xU16rqynxwzKZlxJGKEebCnJOYi6h3dCO9Fyy9dUtHggO4SqwEqlrVGGvTz lrnjvpQgCzmSf8xJfszFtzN4CJRwFsPQcGgyM8D0k39DLyhFrljwmH88Oa5t9dhAkO3u 9Gd1wKlZ6Np8x40d2hXBlpGqqgHmhjTCl/y0FRKD+hGIfauDQ4pt+Ka/RR63btUkbjOg yQ58HqvrrpPHmKyJh+691FhZDjnElSg876LoUSZsbQOKZ1oSdQ5b78J3rSby8s5jGngC yUuw== X-Gm-Message-State: AOJu0YzdfccXPmRDkURVR0p4Lq23HTZ8HyoIVJIG2PdFfHlnh+e7scjP VF+OXHPFDUZQhIaZRrCMzcNZTl8BH0dEHI2mtNZLdZGqsp/n+uPupAXnqZ07VOIE6T1Nnhf5YWu o X-Google-Smtp-Source: AGHT+IFeyZ15xptCBWdoSu4rws/k7G4zdbWzKZJdYq04/EcuMOsIn9zH2PJQuPkeumcjTGJS1tHSOg== X-Received: by 2002:a05:6512:3da9:b0:511:5f38:76e with SMTP id k41-20020a0565123da900b005115f38076emr7669601lfv.1.1709033147736; Tue, 27 Feb 2024 03:25:47 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Konrad Rzeszutek Wilk , Ross Lagerwall Subject: [PATCH v2 4/5] xen/livepatch: properly build the noapply and norevert tests Date: Tue, 27 Feb 2024 12:25:27 +0100 Message-ID: <20240227112528.4540-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227112528.4540-1-roger.pau@citrix.com> References: <20240227112528.4540-1-roger.pau@citrix.com> MIME-Version: 1.0 It seems the build variables for those tests where copy-pasted from xen_action_hooks_marker-objs and not adjusted to use the correct source files. Fixes: 6047104c3ccc ('livepatch: Add per-function applied/reverted state tracking marker') Signed-off-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- xen/test/livepatch/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/test/livepatch/Makefile b/xen/test/livepatch/Makefile index c258ab0b5940..d987a8367f15 100644 --- a/xen/test/livepatch/Makefile +++ b/xen/test/livepatch/Makefile @@ -118,12 +118,12 @@ xen_action_hooks_marker-objs := xen_action_hooks_marker.o xen_hello_world_func.o $(obj)/xen_action_hooks_noapply.o: $(obj)/config.h extra-y += xen_action_hooks_noapply.livepatch -xen_action_hooks_noapply-objs := xen_action_hooks_marker.o xen_hello_world_func.o note.o xen_note.o +xen_action_hooks_noapply-objs := xen_action_hooks_noapply.o xen_hello_world_func.o note.o xen_note.o $(obj)/xen_action_hooks_norevert.o: $(obj)/config.h extra-y += xen_action_hooks_norevert.livepatch -xen_action_hooks_norevert-objs := xen_action_hooks_marker.o xen_hello_world_func.o note.o xen_note.o +xen_action_hooks_norevert-objs := xen_action_hooks_norevert.o xen_hello_world_func.o note.o xen_note.o EXPECT_BYTES_COUNT := 8 CODE_GET_EXPECT=$(shell $(OBJDUMP) -d --insn-width=1 $(1) | sed -n -e '/<'$(2)'>:$$/,/^$$/ p' | tail -n +2 | head -n $(EXPECT_BYTES_COUNT) | awk '{$$0=$$2; printf "%s", substr($$0,length-1)}' | sed 's/.\{2\}/0x&,/g' | sed 's/^/{/;s/,$$/}/g') From patchwork Tue Feb 27 11:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13573571 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 38A6AC54E51 for ; Tue, 27 Feb 2024 11:26:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.686022.1067586 (Exim 4.92) (envelope-from ) id 1revaq-0000UZ-Oj; Tue, 27 Feb 2024 11:25:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 686022.1067586; Tue, 27 Feb 2024 11:25:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1revaq-0000Tk-KK; Tue, 27 Feb 2024 11:25:52 +0000 Received: by outflank-mailman (input) for mailman id 686022; Tue, 27 Feb 2024 11:25:51 +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 1revap-0007WG-Kx for xen-devel@lists.xenproject.org; Tue, 27 Feb 2024 11:25:51 +0000 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [2a00:1450:4864:20::130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f63b87b1-d562-11ee-afd6-a90da7624cb6; Tue, 27 Feb 2024 12:25:51 +0100 (CET) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-512be9194b7so4262243e87.1 for ; Tue, 27 Feb 2024 03:25:51 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id jv2-20020a05622aa08200b0042e2002ed12sm3470912qtb.57.2024.02.27.03.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:25:49 -0800 (PST) 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: f63b87b1-d562-11ee-afd6-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709033150; x=1709637950; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xmVYxznNchZhLSEAgmjblx5ppkOHBquqKgG3mrrDbSE=; b=dZI/PR5/KCLcfnBdWWtfQzqiaSa8azfG2+hkv8d4pMAggF+oqPbrdsyGO5rOkK80xY xeJlNBGvO5ij2M8yGlhi2jWOTlsK3CVjZygfDw+psbGzC7tpowAdoeKRk2y5WcW6uNJ3 YUo/akddZIqh6vcifk4q9djZPXZff3mKDcbIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709033150; x=1709637950; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xmVYxznNchZhLSEAgmjblx5ppkOHBquqKgG3mrrDbSE=; b=gkB8amPkAedFVIiGKRVYzPFgESYmYUhSfnqbPjdGiebPxFaRUN+EObVkcpv7XZTLig hKaMwDcNGEioEd6vAU25IpbzC9e5CPyxwTvsOD17YC36Q/5+K264zjhyKmPngCNkkXkX gZGbuSapTU25Ke7THDfbvBkF+esq5lY/ivsdHJi2We0yw7AZ1MUj30ulJnB3nlSFm/6J 08vLaMWOYAnqIWBc7SMU7CVdumcTs3k1JxyDMwMVBx1z6wJ01NclZfCCpFn1WAft5zXL ZXbarjwJNj2DEH3fMGRsMc3al8+7NyBUnzIol72MRkdH6lDkT6b3WuyW6VPKVibebrhK VKzw== X-Gm-Message-State: AOJu0YyxALu1GPR35EdH3dNNrCKvdFBHNmi714DPdYp6d7Knk9cF+q4X jWez9KlfP5Yc+28wOgMPNBrjUAn2m5xlw1IYT5CvrnpNMVabhLWfs9S9h6xJlnTJRqXS0WWWM/4 e X-Google-Smtp-Source: AGHT+IFqfmLFdna5wALovZCB6WfEyZOIy2tNf0bS6nbC4SyizxjX2j1beaVKH42Pb2NkuS8nqDeZMA== X-Received: by 2002:a05:6512:6d0:b0:512:fd8a:d0e1 with SMTP id u16-20020a05651206d000b00512fd8ad0e1mr4295594lff.45.1709033150026; Tue, 27 Feb 2024 03:25:50 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Konrad Rzeszutek Wilk , Ross Lagerwall Subject: [PATCH v2 5/5] xen/livepatch: group and document payload hooks Date: Tue, 27 Feb 2024 12:25:28 +0100 Message-ID: <20240227112528.4540-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227112528.4540-1-roger.pau@citrix.com> References: <20240227112528.4540-1-roger.pau@citrix.com> MIME-Version: 1.0 Group the payload hooks between the pre/post handlers, and the apply/revert replacements. Also attempt to comment the context in which the hooks are executed. No functional change. Signed-off-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- Changes since v1: - New in this version. --- xen/include/xen/livepatch_payload.h | 37 ++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/xen/include/xen/livepatch_payload.h b/xen/include/xen/livepatch_payload.h index b9cd4f209670..472d6a4a63c1 100644 --- a/xen/include/xen/livepatch_payload.h +++ b/xen/include/xen/livepatch_payload.h @@ -82,6 +82,8 @@ struct payload { * collision. Since multiple hooks can be registered, the * .livepatch.hook.load section is a table of functions that will be * executed in series by the livepatch infrastructure at patch load time. + * + * Note the load hook is executed in quiesced context. */ #define LIVEPATCH_LOAD_HOOK(_fn) \ livepatch_loadcall_t *__weak \ @@ -96,14 +98,20 @@ struct payload { livepatch_unloadcall_t *__weak \ const livepatch_unload_data_##_fn __section(".livepatch.hooks.unload") = _fn; +/* + * Pre/Post action hooks. + * + * This hooks are executed before or after the livepatch application. Pre hooks + * can veto the application/revert of the livepatch. They are not executed in + * quiesced context. All of pre and post hooks are considered vetoing, and + * hence filling any of those will block the usage of the REPLACE action. + * + * Each of the hooks below can only be set once per livepatch payload. + */ #define LIVEPATCH_PREAPPLY_HOOK(_fn) \ livepatch_precall_t *__attribute__((weak, used)) \ const livepatch_preapply_data_##_fn __section(".livepatch.hooks.preapply") = _fn; -#define LIVEPATCH_APPLY_HOOK(_fn) \ - livepatch_actioncall_t *__attribute__((weak, used)) \ - const livepatch_apply_data_##_fn __section(".livepatch.hooks.apply") = _fn; - #define LIVEPATCH_POSTAPPLY_HOOK(_fn) \ livepatch_postcall_t *__attribute__((weak, used)) \ const livepatch_postapply_data_##_fn __section(".livepatch.hooks.postapply") = _fn; @@ -112,14 +120,27 @@ struct payload { livepatch_precall_t *__attribute__((weak, used)) \ const livepatch_prerevert_data_##_fn __section(".livepatch.hooks.prerevert") = _fn; -#define LIVEPATCH_REVERT_HOOK(_fn) \ - livepatch_actioncall_t *__attribute__((weak, used)) \ - const livepatch_revert_data_##_fn __section(".livepatch.hooks.revert") = _fn; - #define LIVEPATCH_POSTREVERT_HOOK(_fn) \ livepatch_postcall_t *__attribute__((weak, used)) \ const livepatch_postrevert_data_##_fn __section(".livepatch.hooks.postrevert") = _fn; +/* + * Action replacement hooks. + * + * The following hooks replace the hypervisor implementation for the livepatch + * application and revert routines. When filling the hooks below the native + * apply and revert routines will not be executed, so the provided hooks need + * to make sure the state of the payload after apply or revert is as expected + * by the livepatch logic. + */ +#define LIVEPATCH_APPLY_HOOK(_fn) \ + livepatch_actioncall_t *__attribute__((weak, used)) \ + const livepatch_apply_data_##_fn __section(".livepatch.hooks.apply") = _fn; + +#define LIVEPATCH_REVERT_HOOK(_fn) \ + livepatch_actioncall_t *__attribute__((weak, used)) \ + const livepatch_revert_data_##_fn __section(".livepatch.hooks.revert") = _fn; + #endif /* __XEN_LIVEPATCH_PAYLOAD_H__ */ /*