From nobody Mon Feb 9 09:34:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1709033159; cv=none; d=zohomail.com; s=zohoarc; b=c8EIGcZdwRQWA9G2Lg27Ru7wPre0Xu4zitqwpZ2sNq8DT41IceanRd4T+4WDySiazU6sVuViPsDQRwDgC0DsMZbDJSF31FOZxLq90xh4fFeHkSrUgUD/pxOzmnuhy3xgWImh8+X4vuJwJlA1WjvlPJBGB0sfkw8NjeSYBG4xG6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709033159; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=adt3YzhrFcYBWzR8wX43amlG22Ma23x7ZH5fofejSpQ=; b=bTDkpIO+qgqWp/YK0vG6wCbVRLm+6UvJ6ckgFxkPZc7JePOPNkLFlivLAVac6KzOLnHMtzKBdCuSv3Mu0CWmc2x4Ya6T4qr9WmBYR+ZOyFBABnYtKnw3ashvmwpqkSARSU2mGZBms+y+MsMKOj2IFBM6iwJ25caPDqicBhctvi8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1709033159019798.7879182727942; Tue, 27 Feb 2024 03:25:59 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1709033161511100002 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 tho= se 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=C3=A9 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 l= ist. + * 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 contex= t. */ static LIST_HEAD(applied_list); =20 static unsigned int payload_cnt; @@ -111,12 +112,8 @@ bool is_patch(const void *ptr) const struct payload *data; bool r =3D false; =20 - /* - * 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 >=3D data->rw_addr && ptr < (data->rw_addr + data->rw_size)) || @@ -130,7 +127,7 @@ bool is_patch(const void *ptr) } =20 } - rcu_read_unlock(&rcu_applied_lock); + rcu_read_unlock(&rcu_payload_lock); =20 return r; } @@ -166,12 +163,8 @@ static const char *cf_check livepatch_symbols_lookup( const void *va =3D (const void *)addr; const char *n =3D NULL; =20 - /* - * 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 >=3D (data->text_addr + data->text_size) ) @@ -200,7 +193,7 @@ static const char *cf_check livepatch_symbols_lookup( n =3D data->symtab[best].name; break; } - rcu_read_unlock(&rcu_applied_lock); + rcu_read_unlock(&rcu_payload_lock); =20 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_livepat= ch_upload *upload) INIT_LIST_HEAD(&data->applied_list); =20 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) =20 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); =20 data->state =3D LIVEPATCH_STATE_APPLIED; } @@ -1427,12 +1417,7 @@ static int revert_payload(struct payload *data) =20 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); =20 data->reverted =3D true; data->state =3D LIVEPATCH_STATE_CHECKED; --=20 2.44.0