From patchwork Tue Mar 5 12:11:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13582305 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 C2D69C54E49 for ; Tue, 5 Mar 2024 12:11:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.688769.1073324 (Exim 4.92) (envelope-from ) id 1rhTdo-0007Oj-Gj; Tue, 05 Mar 2024 12:11:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 688769.1073324; Tue, 05 Mar 2024 12:11:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rhTdo-0007NG-Cn; Tue, 05 Mar 2024 12:11:28 +0000 Received: by outflank-mailman (input) for mailman id 688769; Tue, 05 Mar 2024 12:11:27 +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 1rhTdn-0007LZ-Fl for xen-devel@lists.xenproject.org; Tue, 05 Mar 2024 12:11:27 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7d2d291d-dae9-11ee-a1ee-f123f15fe8a2; Tue, 05 Mar 2024 13:11:25 +0100 (CET) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a45a15f2bafso74917266b.0 for ; Tue, 05 Mar 2024 04:11:25 -0800 (PST) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id gg4-20020a170906e28400b00a45b1194dacsm11429ejb.126.2024.03.05.04.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:11:24 -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: 7d2d291d-dae9-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709640685; x=1710245485; 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=PYhS+zW0jQOXj6T42uFUoaBTcCdbr7cDELY4xsIeX+0=; b=Qms27CZ2ENS6dBrvfKSWqb4oPJieyU6ihDFHRlBRfUB/g6iftqwh2wgJg/9jxQON8o ZYDsyXNfFgKGTKdsKWo6A6s7Hy3haQUumZS2wie+ufp88rdYsH7DLokJcVhJ/w2thZIV nCF5VkHpb/VAcMMVh3ABTYHFRDoKyTE1wG0rg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709640685; x=1710245485; 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=PYhS+zW0jQOXj6T42uFUoaBTcCdbr7cDELY4xsIeX+0=; b=u2VluPVt9osoClaR8HVxb2rTMyXA4c1troXWc24DA7gcv9dHxcN4OtNcurJR/x/uVb 1yEobwgthHFfWIAemcG4HJ4h+GN4UMJR5LP3SPXdhnExIvYwCb+BGmGHkl3UJ5V0Wfiy 9vE/g8cQ4FmJ49o9wLrAg2tMxecvuiqI4F+TrL+iDfuTFSnIsUbl4HEZWQ/DAsUMsG5q aDC0hOBGkfEOfBD7BkYX2UK+iDLpn2D39IQYg4n311OygzuiSHTQMPv7HyurQFSZtF9L 5+MKdzHzIK/MJ9PPSIPQZpawM4ak/syiJIGF2aocD7cEq3vy6DFIcU6UxxmbWZ5sNhxi Jwug== X-Gm-Message-State: AOJu0YzG7Hxe5Z6S+8lw61LnfjdhsaNtmDpcG8Y6hywD4w9otxfVrb6X Qk1xoOgAdmdpFQ8EqvTgZlkqm5zWOUFUxsC3/ndhxXG4LSCu7xz5GRM0svSw6OjF6l8xCBtiTei E X-Google-Smtp-Source: AGHT+IFKUyzpwhCGvtaIMMqNDhJ0YRjW8uNvEgiydyOBwEO+msMV0to3klQOpaGxv6joRGhIOplAaQ== X-Received: by 2002:a17:906:d209:b0:a44:5927:3e67 with SMTP id w9-20020a170906d20900b00a4459273e67mr9061563ejz.23.1709640685070; Tue, 05 Mar 2024 04:11:25 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Konrad Rzeszutek Wilk , Ross Lagerwall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH 1/3] xen/virtual-region: Rename start/end fields Date: Tue, 5 Mar 2024 12:11:19 +0000 Message-Id: <20240305121121.3527944-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240305121121.3527944-1-andrew.cooper3@citrix.com> References: <20240305121121.3527944-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 ... to text_{start,end}. We're about to introduce another start/end pair. As minor cleanup, replace ROUNDUP(x, PAGE_SIZE) with the more consice PAGE_ALIGN() ahead of duplicating the example. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- CC: Konrad Rzeszutek Wilk CC: Ross Lagerwall CC: Jan Beulich CC: Roger Pau Monné --- xen/common/livepatch.c | 4 ++-- xen/common/virtual_region.c | 19 ++++++++++--------- xen/include/xen/virtual_region.h | 5 +++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 5a7d5b7be0ad..888beb273244 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -785,8 +785,8 @@ static int prepare_payload(struct payload *payload, region = &payload->region; region->symbols_lookup = livepatch_symbols_lookup; - region->start = payload->text_addr; - region->end = payload->text_addr + payload->text_size; + region->text_start = payload->text_addr; + region->text_end = payload->text_addr + payload->text_size; /* Optional sections. */ for ( i = 0; i < BUGFRAME_NR; i++ ) diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index cefef3e47e73..b74030d70065 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -11,15 +11,15 @@ static struct virtual_region core = { .list = LIST_HEAD_INIT(core.list), - .start = _stext, - .end = _etext, + .text_start = _stext, + .text_end = _etext, }; /* Becomes irrelevant when __init sections are cleared. */ static struct virtual_region core_init __initdata = { .list = LIST_HEAD_INIT(core_init.list), - .start = _sinittext, - .end = _einittext, + .text_start = _sinittext, + .text_end = _einittext, }; /* @@ -39,7 +39,8 @@ const struct virtual_region *find_text_region(unsigned long addr) rcu_read_lock(&rcu_virtual_region_lock); list_for_each_entry_rcu ( iter, &virtual_region_list, list ) { - if ( (void *)addr >= iter->start && (void *)addr < iter->end ) + if ( (void *)addr >= iter->text_start && + (void *)addr < iter->text_end ) { region = iter; break; @@ -88,8 +89,8 @@ void relax_virtual_region_perms(void) rcu_read_lock(&rcu_virtual_region_lock); list_for_each_entry_rcu( region, &virtual_region_list, list ) - modify_xen_mappings_lite((unsigned long)region->start, - ROUNDUP((unsigned long)region->end, PAGE_SIZE), + modify_xen_mappings_lite((unsigned long)region->text_start, + PAGE_ALIGN((unsigned long)region->text_end), PAGE_HYPERVISOR_RWX); rcu_read_unlock(&rcu_virtual_region_lock); } @@ -100,8 +101,8 @@ void tighten_virtual_region_perms(void) rcu_read_lock(&rcu_virtual_region_lock); list_for_each_entry_rcu( region, &virtual_region_list, list ) - modify_xen_mappings_lite((unsigned long)region->start, - ROUNDUP((unsigned long)region->end, PAGE_SIZE), + modify_xen_mappings_lite((unsigned long)region->text_start, + PAGE_ALIGN((unsigned long)region->text_end), PAGE_HYPERVISOR_RX); rcu_read_unlock(&rcu_virtual_region_lock); } diff --git a/xen/include/xen/virtual_region.h b/xen/include/xen/virtual_region.h index d05362071135..c76e7d7932ff 100644 --- a/xen/include/xen/virtual_region.h +++ b/xen/include/xen/virtual_region.h @@ -12,8 +12,9 @@ struct virtual_region { struct list_head list; - const void *start; /* Virtual address start. */ - const void *end; /* Virtual address end. */ + + const void *text_start; /* .text virtual address start. */ + const void *text_end; /* .text virtual address end. */ /* If this is NULL the default lookup mechanism is used. */ symbols_lookup_t *symbols_lookup; From patchwork Tue Mar 5 12:11:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13582304 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 34944C54E41 for ; Tue, 5 Mar 2024 12:11:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.688770.1073340 (Exim 4.92) (envelope-from ) id 1rhTdq-0007oF-NV; Tue, 05 Mar 2024 12:11:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 688770.1073340; Tue, 05 Mar 2024 12:11:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rhTdq-0007o8-Jy; Tue, 05 Mar 2024 12:11:30 +0000 Received: by outflank-mailman (input) for mailman id 688770; Tue, 05 Mar 2024 12:11:28 +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 1rhTdo-0007Lm-SV for xen-devel@lists.xenproject.org; Tue, 05 Mar 2024 12:11:28 +0000 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [2a00:1450:4864:20::533]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7e1e1807-dae9-11ee-afda-a90da7624cb6; Tue, 05 Mar 2024 13:11:27 +0100 (CET) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-564372fb762so7173760a12.0 for ; Tue, 05 Mar 2024 04:11:27 -0800 (PST) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id gg4-20020a170906e28400b00a45b1194dacsm11429ejb.126.2024.03.05.04.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:11:25 -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: 7e1e1807-dae9-11ee-afda-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709640686; x=1710245486; 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=TlpNxqFoSSL8NwQwwcPUu6ZlDVgEwc5H6nYzlIRPqfQ=; b=Cz7201utjqDyr5WU93gcP0Tsqi5T5JHC4DvXtJIcVtnweOj1aRX3Kzsj5RjuzUGI1o PwLEvzUCmCdo/OjjsuuunhQQG3DZr1MHX7fIfh+3L0rWYrLWBA2Fl+ZFNM/PNHt/tx4Y GX3li/q9A6a115XguLgmoY0kOyVQWS4nmmTZQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709640686; x=1710245486; 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=TlpNxqFoSSL8NwQwwcPUu6ZlDVgEwc5H6nYzlIRPqfQ=; b=AVdmAmO6z4j4dgNco1hUamWwa0sU5WoX1knf1bpwkLsUi7gHMnsbJ4Xq3PPAS4ekak PvfYAVvnoNNrpBxHZtjlw0Rb7KZsQKkNKH6Iwfq7XWwuThbILFlCZrI8i0+PF1bM8Jpu uzxAewSLVTGSEJUISiqh8pAqNtBloDCGRhajTFSemr/CNDACpVr4BN95UaHISCRt4aTm cwI8lDUMzdXsn7XsQ/IQ/Y7R8Vuzx5YbNgamQTIX4wgnGH2nB/PvCkzdVSvCvwFtdNQP xe/eCrlAB2HVui3dMUXzL9NQxF/lM1aDsciagXGz6nKDbLNauQuOaqxO9/n4PMyev9yk /IkQ== X-Gm-Message-State: AOJu0YzkBtt/UcHzZEvsFp91a2+1moQ37UzIN7edjhsrxRtgsKkBNxmm ALR3BVfS4KhmLVDNQ3IzTjo15zr2U4jpJnE2Hhv53+tHpS3oQSRBB/hktqDUyVqN1X2BCuzv+dV E X-Google-Smtp-Source: AGHT+IGKF7MVptTJX8bpq+u++FqTm0yMW4c9pc8bxMUAAdOp88S7xT4NB26ZY7rr8aWOTnoRyXfkKA== X-Received: by 2002:a17:906:408d:b0:a45:69f5:c3c9 with SMTP id u13-20020a170906408d00b00a4569f5c3c9mr3304715ejj.6.1709640686294; Tue, 05 Mar 2024 04:11:26 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Konrad Rzeszutek Wilk , Ross Lagerwall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH 2/3] xen/virtual-region: Include rodata pointers Date: Tue, 5 Mar 2024 12:11:20 +0000 Message-Id: <20240305121121.3527944-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240305121121.3527944-1-andrew.cooper3@citrix.com> References: <20240305121121.3527944-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 These are optional. .init doesn't distinguish types of data like this, and livepatches don't necesserily have any .rodata either. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- CC: Konrad Rzeszutek Wilk CC: Ross Lagerwall CC: Jan Beulich CC: Roger Pau Monné --- xen/common/livepatch.c | 6 ++++++ xen/common/virtual_region.c | 2 ++ xen/include/xen/virtual_region.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 888beb273244..cabfb6391117 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -788,6 +788,12 @@ static int prepare_payload(struct payload *payload, region->text_start = payload->text_addr; region->text_end = payload->text_addr + payload->text_size; + if ( payload->ro_size ) + { + region->rodata_start = payload->ro_addr; + region->rodata_end = payload->ro_addr + payload->ro_size; + } + /* Optional sections. */ for ( i = 0; i < BUGFRAME_NR; i++ ) { diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index b74030d70065..d2efe9e11492 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -13,6 +13,8 @@ static struct virtual_region core = { .list = LIST_HEAD_INIT(core.list), .text_start = _stext, .text_end = _etext, + .rodata_start = _srodata, + .rodata_end = _erodata, }; /* Becomes irrelevant when __init sections are cleared. */ diff --git a/xen/include/xen/virtual_region.h b/xen/include/xen/virtual_region.h index c76e7d7932ff..7712f6ad3632 100644 --- a/xen/include/xen/virtual_region.h +++ b/xen/include/xen/virtual_region.h @@ -16,6 +16,9 @@ struct virtual_region const void *text_start; /* .text virtual address start. */ const void *text_end; /* .text virtual address end. */ + const void *rodata_start; /* .rodata virtual address start (optional). */ + const void *rodata_end; /* .rodata virtual address end. */ + /* If this is NULL the default lookup mechanism is used. */ symbols_lookup_t *symbols_lookup; From patchwork Tue Mar 5 12:11:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13582303 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 11060C54798 for ; Tue, 5 Mar 2024 12:11:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.688771.1073349 (Exim 4.92) (envelope-from ) id 1rhTds-00084M-Up; Tue, 05 Mar 2024 12:11:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 688771.1073349; Tue, 05 Mar 2024 12:11:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rhTds-00084F-RY; Tue, 05 Mar 2024 12:11:32 +0000 Received: by outflank-mailman (input) for mailman id 688771; Tue, 05 Mar 2024 12:11:31 +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 1rhTdr-0007LZ-06 for xen-devel@lists.xenproject.org; Tue, 05 Mar 2024 12:11:31 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7f3db319-dae9-11ee-a1ee-f123f15fe8a2; Tue, 05 Mar 2024 13:11:29 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a456ab934eeso256224266b.0 for ; Tue, 05 Mar 2024 04:11:29 -0800 (PST) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id gg4-20020a170906e28400b00a45b1194dacsm11429ejb.126.2024.03.05.04.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:11:26 -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: 7f3db319-dae9-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1709640688; x=1710245488; 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=oWpJEehPtMQOOKNL57tqrOWjao0ovLuzVCpvgDqElsg=; b=EITX2FJVa2gnDq/9ajeQv79PjPFUeL4L0KCgcKQkGPZeF6nL3CJs/fd0twmNI8WO/o Q89YpwUN+0j3GbwOTE+1CNBzn8RJursVj50gSR/ckv0V9XQZhirLCHldrSIHtibs+Uqy 2zM+QP3PghllzrNu0JJpbkqJWzbeWjQsDZQVA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709640688; x=1710245488; 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=oWpJEehPtMQOOKNL57tqrOWjao0ovLuzVCpvgDqElsg=; b=Ggk6bNaoRX2jl+A5wmF0qcs2eerD/MhNCyCeQziRiQLEz9ws410Z0RxvRHdLibLAhZ KVWu5AlnsdByejCXi0jW1PD3jH9A73eP2SBtXd3ZePuOt2sU36SlBeO90M6JqTSsqMRf J9F4M75pXwwjX8VccstAhpJV18TVB4TItYUs3RCgq69ky+OE2cvwwX5ykMQ6SjmHYxY5 FR44ZfTPBNBbCKpOo218BChNh2D75ZxJ78CAIZiet6YiFztghlYkDK05Uwq3rl+biJEb y4B0ELwodTSgyG53Woe9aT48wWQviBBJp7LUMhvBCSxKUti/EGYUQDNvkXCEEghIuoSE 7bxA== X-Gm-Message-State: AOJu0Yw1KuKw0JNX9a1fDocWo/wLKmZYqZVCUQavX42pKzpzTb3b9bvt Gvzu7EnGuBCn2y4zGR7bBCKrPgxIXWZo4mMcEPhkmkcFK3GqXdcJk8ehWsZ1B6XUjHmAaNaOxq+ i X-Google-Smtp-Source: AGHT+IGZeAV7JmDHAFpT5RByDKtjLsj2hMKVaMz3gNdeOh4RUIz2opvOrxF9jr5pTaYTgsS3wc4Zdg== X-Received: by 2002:a17:906:6bd7:b0:a45:aefb:2145 with SMTP id t23-20020a1709066bd700b00a45aefb2145mr322620ejs.29.1709640687910; Tue, 05 Mar 2024 04:11:27 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Konrad Rzeszutek Wilk , Ross Lagerwall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH 3/3] x86/livepatch: Relax permissions on rodata too Date: Tue, 5 Mar 2024 12:11:21 +0000 Message-Id: <20240305121121.3527944-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240305121121.3527944-1-andrew.cooper3@citrix.com> References: <20240305121121.3527944-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 This reinstates the capability to patch .rodata in load/unload hooks, which was lost when we stopped using CR0.WP=0 to patch. This turns out to be rather less of a large TODO than I thought at the time. Fixes: 8676092a0f16 ("x86/livepatch: Fix livepatch application when CET is active") Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monné Reviewed-by: Ross Lagerwall --- CC: Konrad Rzeszutek Wilk CC: Ross Lagerwall CC: Jan Beulich CC: Roger Pau Monné --- xen/arch/x86/livepatch.c | 4 ++-- xen/common/virtual_region.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index ee539f001b73..4f76127e1f77 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -62,7 +62,7 @@ int arch_livepatch_safety_check(void) int noinline arch_livepatch_quiesce(void) { /* - * Relax perms on .text to be RWX, so we can modify them. + * Relax perms on .text/.rodata, so we can modify them. * * This relaxes perms globally, but all other CPUs are waiting on us. */ @@ -75,7 +75,7 @@ int noinline arch_livepatch_quiesce(void) void noinline arch_livepatch_revive(void) { /* - * Reinstate perms on .text to be RX. This also cleans out the dirty + * Reinstate perms on .text/.rodata. This also cleans out the dirty * bits, which matters when CET Shstk is active. * * The other CPUs waiting for us could in principle have re-walked while diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index d2efe9e11492..f45812483b8e 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -91,9 +91,15 @@ void relax_virtual_region_perms(void) rcu_read_lock(&rcu_virtual_region_lock); list_for_each_entry_rcu( region, &virtual_region_list, list ) + { modify_xen_mappings_lite((unsigned long)region->text_start, PAGE_ALIGN((unsigned long)region->text_end), PAGE_HYPERVISOR_RWX); + if ( region->rodata_start ) + modify_xen_mappings_lite((unsigned long)region->rodata_start, + ROUNDUP((unsigned long)region->rodata_end, PAGE_SIZE), + PAGE_HYPERVISOR_RW); + } rcu_read_unlock(&rcu_virtual_region_lock); } @@ -103,9 +109,15 @@ void tighten_virtual_region_perms(void) rcu_read_lock(&rcu_virtual_region_lock); list_for_each_entry_rcu( region, &virtual_region_list, list ) + { modify_xen_mappings_lite((unsigned long)region->text_start, PAGE_ALIGN((unsigned long)region->text_end), PAGE_HYPERVISOR_RX); + if ( region->rodata_start ) + modify_xen_mappings_lite((unsigned long)region->rodata_start, + ROUNDUP((unsigned long)region->rodata_end, PAGE_SIZE), + PAGE_HYPERVISOR_RO); + } rcu_read_unlock(&rcu_virtual_region_lock); } #endif /* CONFIG_X86 */