From patchwork Tue Mar 18 09:19:00 2025 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: 14020625 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 DFA74C35FF8 for ; Tue, 18 Mar 2025 09:19:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918729.1323372 (Exim 4.92) (envelope-from ) id 1tuT6V-0001F4-8l; Tue, 18 Mar 2025 09:19:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918729.1323372; Tue, 18 Mar 2025 09:19:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuT6V-0001Ex-3k; Tue, 18 Mar 2025 09:19:19 +0000 Received: by outflank-mailman (input) for mailman id 918729; Tue, 18 Mar 2025 09:19:17 +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 1tuT6T-0001Er-UB for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 09:19:17 +0000 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [2a00:1450:4864:20::434]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 10b0e049-03da-11f0-9aba-95dc52dad729; Tue, 18 Mar 2025 10:19:16 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3914aba1ce4so4418508f8f.2 for ; Tue, 18 Mar 2025 02:19:17 -0700 (PDT) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43d393bb288sm19711245e9.29.2025.03.18.02.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 02:19:15 -0700 (PDT) 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: 10b0e049-03da-11f0-9aba-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1742289556; x=1742894356; 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=BQyj+8gxcUxgHvEe1NNFlxycQRcd7X/ZYftV2VeVJ7c=; b=A9GuLNcy2g2v/24u0uujKWbjGuJy/7LYLnOvY46Tao0hii193VgLyaPgIyvPSe+a9/ uVBNQ1ROe1L6D2/jhi4F/p7rDqeozOTyfSbW42F/EUD0ylArI74U1ij0qz29CnbqQaE5 Yncy0zr2phUAoWz66WNlIa7haWBJ4sAgqbItI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742289556; x=1742894356; 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=BQyj+8gxcUxgHvEe1NNFlxycQRcd7X/ZYftV2VeVJ7c=; b=ANRagqtsyheDK5tbecfLQJVrWiE7BzL38IixkxKA3G3VSb1hVzgfmwB8DlyrfxkDmS nUfQyw7o3b1DQCEmjLAnu2y7b8x5KMmG30ALDFGdsNdqtGPzRlHnJyTVVp/lomYl+3Mk /KztPALL7LvVCVRQXK7WE5ngKZjdAyqxNZbSL3MHyE6xqTl4y4IOQjuNLaBY8oZkmAwH ifijyck2fPbu9AXoBsv8lFN65W5Z+wPheixQoZxkPDGD2ZVxVpHCuDfYtnpL4Yso97tK 2ZhDs94y+w+VduxhV0qIeESziwA42kpFWve0h7b5vCHmZP0A3HAE1Wmp4qjjR6Jd4Rod ZaRg== X-Gm-Message-State: AOJu0YwIBF5lxcUBzirU01qCUuh8OIFA0N8fi3Cr+YhCtfMbYNGOlmVE KiXT6BhNQ326QenHA4WSerOiUNLWR9CwKa56RDwwFKt0ra98DB1j1n1Ky0s+GUVeq3RzHnWLUdm N X-Gm-Gg: ASbGncsn88iNCTUgcnv/BRucppnerNVbA1BV7ZZQcFFmVzg9fazEMhAIhFH7pmjtxAa cJ8+22fCg+C5lnwerK+AyRN2RTtRs3jbDONT1hRvEY1ejm4pP3RtcnNtTrtw9rBlNyDN/8S6gc/ 1yGn/7ik7WTqinhsQbWlr5pTSxc7WVL2PjS01VKOvhnq3gweL/MfZhzUnx5jFwOp8G5MssXLfK/ O+sdhrdHKGY5x5sFWDwVCWoxAJVOMDInshRfc5bujtJ3XHG82yZ5V7kX6lDDR9B7QGGtcfqOSTG 7aIRg/F4NQcvrpsNj4d8NPmPzwbqkEeOavpAWVQOfdAq/7qQIQ== X-Google-Smtp-Source: AGHT+IFsuf7KZ/j+CxSESP9fbL8OO6NYlxurqpb9EgVujHuhByPLEYUbGuBWsDeoV3CvlsEQF8UN8Q== X-Received: by 2002:a5d:598c:0:b0:391:476f:d3b7 with SMTP id ffacd0b85a97d-3971f510ec0mr15075554f8f.49.1742289556108; Tue, 18 Mar 2025 02:19:16 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v2 1/5] x86/wait: prevent duplicated assembly labels Date: Tue, 18 Mar 2025 10:19:00 +0100 Message-ID: <20250318091904.52903-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318091904.52903-1-roger.pau@citrix.com> References: <20250318091904.52903-1-roger.pau@citrix.com> MIME-Version: 1.0 When enabling UBSAN with clang, the following error is triggered during the build: common/wait.c:154:9: error: symbol '.L_wq_resume' is already defined 154 | "push %%rbx; push %%rbp; push %%r12;" | ^ :1:121: note: instantiated into assembly here 1 | push %rbx; push %rbp; push %r12;push %r13; push %r14; push %r15;sub %esp,%ecx;cmp $4096, %ecx;ja .L_skip;mov %rsp,%rsi;.L_wq_resume: rep movsb;mov %rsp,%rsi;.L_skip:pop %r15; pop %r14; pop %r13;pop %r12; pop %rbp; pop %rbx | ^ common/wait.c:154:9: error: symbol '.L_skip' is already defined 154 | "push %%rbx; push %%rbp; push %%r12;" | ^ :1:159: note: instantiated into assembly here 1 | push %rbx; push %rbp; push %r12;push %r13; push %r14; push %r15;sub %esp,%ecx;cmp $4096, %ecx;ja .L_skip;mov %rsp,%rsi;.L_wq_resume: rep movsb;mov %rsp,%rsi;.L_skip:pop %r15; pop %r14; pop %r13;pop %r12; pop %rbp; pop %rbx | ^ 2 errors generated. The inline assembly block in __prepare_to_wait() is duplicated, thus leading to multiple definitions of the otherwise unique labels inside the assembly block. GCC extended-asm documentation notes the possibility of duplicating asm blocks: > Under certain circumstances, GCC may duplicate (or remove duplicates of) > your assembly code when optimizing. This can lead to unexpected duplicate > symbol errors during compilation if your asm code defines symbols or > labels. Using ‘%=’ (see AssemblerTemplate) may help resolve this problem. Workaround the issue by latching esp to a local variable, this prevents clang duplicating the inline asm blocks. Suggested-by: Jan Beulich Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper --- Changes since v1: - Use approach suggested by Jan. --- xen/common/wait.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/common/wait.c b/xen/common/wait.c index cb6f5ff3c20a..9a11dccb5de5 100644 --- a/xen/common/wait.c +++ b/xen/common/wait.c @@ -124,6 +124,11 @@ static void __prepare_to_wait(struct waitqueue_vcpu *wqv) struct cpu_info *cpu_info = get_cpu_info(); struct vcpu *curr = current; unsigned long dummy; + /* + * Latch esp to a local variable to prevent clang from duplicating the + * inline assembly block when UBSAN is enabled. + */ + void *esp = NULL; ASSERT(wqv->esp == NULL); @@ -166,12 +171,12 @@ static void __prepare_to_wait(struct waitqueue_vcpu *wqv) ".L_skip:" "pop %%r15; pop %%r14; pop %%r13;" "pop %%r12; pop %%rbp; pop %%rbx" - : "=&S" (wqv->esp), "=&c" (dummy), "=&D" (dummy) + : "=&S" (esp), "=&c" (dummy), "=&D" (dummy) : "0" (0), "1" (cpu_info), "2" (wqv->stack), [sz] "i" (PAGE_SIZE) : "memory", "rax", "rdx", "r8", "r9", "r10", "r11" ); - if ( unlikely(wqv->esp == NULL) ) + if ( unlikely(esp == NULL) ) { gdprintk(XENLOG_ERR, "Stack too large in %s\n", __func__); domain_crash(curr->domain); @@ -179,6 +184,7 @@ static void __prepare_to_wait(struct waitqueue_vcpu *wqv) for ( ; ; ) do_softirq(); } + wqv->esp = esp; } static void __finish_wait(struct waitqueue_vcpu *wqv) From patchwork Tue Mar 18 09:19:01 2025 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: 14020624 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 A463CC35FF9 for ; Tue, 18 Mar 2025 09:19:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918730.1323382 (Exim 4.92) (envelope-from ) id 1tuT6W-0001TE-FQ; Tue, 18 Mar 2025 09:19:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918730.1323382; Tue, 18 Mar 2025 09:19:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuT6W-0001T6-Cf; Tue, 18 Mar 2025 09:19:20 +0000 Received: by outflank-mailman (input) for mailman id 918730; Tue, 18 Mar 2025 09:19:19 +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 1tuT6V-0001Er-7O for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 09:19:19 +0000 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [2a00:1450:4864:20::32a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 11ab39c7-03da-11f0-9aba-95dc52dad729; Tue, 18 Mar 2025 10:19:18 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43948f77f1aso21498055e9.0 for ; Tue, 18 Mar 2025 02:19:18 -0700 (PDT) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43d1fe60b91sm129211135e9.31.2025.03.18.02.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 02:19:16 -0700 (PDT) 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: 11ab39c7-03da-11f0-9aba-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1742289557; x=1742894357; 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=kJrfgSgOCfJAjejXjwBF2RetzOVLR6TOxhOTSZtrq7M=; b=AXfMUBSyZtDQegyQDomRhFGSwvLxc8jd8wWaOpmbtKw8ykyDa11zP/VyRJZqgAWkSX 1Gsbjx7z7ZwnpKq2FZHma8PYfyZcR6Q/k4HmajoiMoAGpeczelUmboTZG/fTSH9mqhVK M4NuKf6rtzDPcT9MYbb6KBQkFNSbURD5x8bIk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742289557; x=1742894357; 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=kJrfgSgOCfJAjejXjwBF2RetzOVLR6TOxhOTSZtrq7M=; b=cqBbZMrUMBLIW7rCSg29L6r6K703Wq77QDmXBPQN/y6GFyAxyyoqQ1AdAntTsJELan kpdhcIwa9HjvyBUDvn2wD8IksaqGBbDNcOFhF3bfl3U+XMKK6FA1iW22XPwKWhixqOQ6 JG4BdSz+PsBqO6NrWm4EDcjvJ40Z6jEMwrN2opGXGD3zFDDmE8Fi/cx3EIs4Acmdq8AA FnLjmBBDtLwvdn4lEpt5NP0hBc4W182NquuF1Pnwo4oJ9SNFClQs5J3GVvdbHUtA+eK+ MdWKr9GZrQ4w+h+8lWaF7i6xsEa7Tly37CxCcWgLTGk9LTzchyhi6ahtUiHuGtRIZOkJ jsIw== X-Gm-Message-State: AOJu0Yzz9OhsjIrI3uZquZqbAXMrEw35xd/DuLEegDGCb7jiJJNM2fpO l9flg4fDbf0VQ8fceCSCI+xKZKRRZqhaNKR2SXxzJJuFeIKTOSX8m5atssCx6KMMYnqNvs+YDtx I X-Gm-Gg: ASbGnctstSzZzEgUvcgd8N2wzJcKT06Fdi0LHWWETdS/eD/FQ1ccpnmbErAcORMQl3M Lwh3iiTp5aotPd7Sd0w/CVlKKGmp/Kt1kKXrTqmf0xtqRPuWezXqx+TLco6dgJn0PhZLbLrBkn4 IDxxSteK33HvbQuTvker/ljQUV9/Tz+troXqPkr4mBj96GZHJH4rE2EUAtMIuBeR8sugKYQWyMB qY5muFu2PO4PdTzZiVXhhZCncs/AD5wMOV4TfZq15/ksgcyBd+Mb2B5bPjivH8zVi9m0QJ4SmRP ETjUzwcT7e2vilIEJATEtxszieEfPq5gnl0X5P1f0cfdDDPy2w== X-Google-Smtp-Source: AGHT+IFMkceX6oq4VjB2zOMmMrOjarqH8kophX5VOaq2q0cqLz6dtfKN9iw0JKDaeoMiK0jGtDBRWg== X-Received: by 2002:a05:600c:3c9e:b0:43c:f513:9591 with SMTP id 5b1f17b1804b1-43d3b993e94mr12025615e9.14.1742289557208; Tue, 18 Mar 2025 02:19:17 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v2 2/5] x86/vga: fix mapping of the VGA text buffer Date: Tue, 18 Mar 2025 10:19:01 +0100 Message-ID: <20250318091904.52903-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318091904.52903-1-roger.pau@citrix.com> References: <20250318091904.52903-1-roger.pau@citrix.com> MIME-Version: 1.0 The call to ioremap_wc() in video_init() will always fail, because video_init() is called ahead of vm_init_type(), and so the underlying __vmap() call will fail to allocate the linear address space. Fix by reverting to the previous behavior and using ioremap() for the VGA text buffer. Fixes: 81d195c6c0e2 ('x86: introduce ioremap_wc()') Signed-off-by: Roger Pau Monné --- Changes since v1: - No not attempt to adjust the directmap VGA text buffer mappings to be WC, just revert to the previous usage of UC- mappings for the whole VGA hole. --- xen/drivers/video/vga.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/drivers/video/vga.c b/xen/drivers/video/vga.c index b4d018326128..ee6cf0a7079a 100644 --- a/xen/drivers/video/vga.c +++ b/xen/drivers/video/vga.c @@ -71,7 +71,7 @@ void __init video_init(void) { case XEN_VGATYPE_TEXT_MODE_3: if ( page_is_ram_type(paddr_to_pfn(0xB8000), RAM_TYPE_CONVENTIONAL) || - ((video = ioremap_wc(0xB8000, 0x8000)) == NULL) ) + ((video = ioremap(0xB8000, 0x8000)) == NULL) ) return; outw(0x200a, 0x3d4); /* disable cursor */ columns = vga_console_info.u.text_mode_3.columns; @@ -158,7 +158,7 @@ void __init video_endboot(void) if ( !vgacon_keep ) { memset(video, 0, columns * lines * 2); - iounmap(video); + /* No iounmap(), as it's a directmap mapping. */ video = ZERO_BLOCK_PTR; } break; From patchwork Tue Mar 18 09:19:02 2025 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: 14020622 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 5379FC28B28 for ; Tue, 18 Mar 2025 09:19:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918731.1323392 (Exim 4.92) (envelope-from ) id 1tuT6X-0001iP-OK; Tue, 18 Mar 2025 09:19:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918731.1323392; Tue, 18 Mar 2025 09:19:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuT6X-0001iG-L8; Tue, 18 Mar 2025 09:19:21 +0000 Received: by outflank-mailman (input) for mailman id 918731; Tue, 18 Mar 2025 09:19:19 +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 1tuT6V-0001Er-Sr for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 09:19:19 +0000 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [2a00:1450:4864:20::42e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 12263b2a-03da-11f0-9aba-95dc52dad729; Tue, 18 Mar 2025 10:19:19 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3914bc3e01aso3543019f8f.2 for ; Tue, 18 Mar 2025 02:19:19 -0700 (PDT) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-395c83b6b43sm17746582f8f.35.2025.03.18.02.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 02:19:18 -0700 (PDT) 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: 12263b2a-03da-11f0-9aba-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1742289558; x=1742894358; 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=YuDcf9Cv9x3i1U+A49P9TQaxoQRqLFIPfBAq0blwaPE=; b=QLwngdLGpw5wRhuRoOAW9Ie9ZF0iwB62KyCJ0lkSMIRuVUKnH7Xus3RvpRGJULxJ9s 7v2dtcoEAyWATa0t2skWcuWbjlD91pEMMpDajWg75pxl9iZHMVF2/hiWEkV7Hcziufm/ 7JuhD2bRkWQba4DHZfL0FGvm2/y/1F8kYLSgo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742289558; x=1742894358; 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=YuDcf9Cv9x3i1U+A49P9TQaxoQRqLFIPfBAq0blwaPE=; b=Qs0OcSNnz+aUK06UHjVu3KVXrZaJOFQsM3PIg08W3hoNxPNUCeL2+aPtGAsevQ+4TQ 1tdTgNasY4Co6QtOqpbG5h1EB9KNIlgz7ui9D5NM06TVh6U0v9nr/REBCjZhHOjdEmBI rppZTK1YJ+50rWDPkuef7N2qOCZXyf6ayYJ/Zs0D1KMiGHd9hX3M33Ct99JusLT0POO3 NxGOp32MhJbxRSAenVhOPrPUu1v+PbVlUzzXe8Aly7pv6+cq0T+RWx4Sv8HsS3p+nZw4 YlaKsrGC8tYxN60BI4tZCqnAxujLuPhNSb89oeCxKy2gq9ZsgA6+c7e/uHkMNHlVZNQF Mwlg== X-Gm-Message-State: AOJu0YzT2lAJGKYYRxacUEhl/Hvu+ETFBejQ7FWyH9mhHLceLX7Dmyp2 BlsXmPpmWJzdFJ5oRZK1XjOwCExf2BtWfW71oMA+5uL21QgSjUdAgNZPoKe/FF+go+umw+gguTI h X-Gm-Gg: ASbGncvhKsQsdXu9Tg42E8DL4BAG0aVuStZOif7NmP6DVNdmHJz7p73NHEEicg4zTYx L/pBVXOQxltXxrcfOd5dHm26qd1BR6weobGUJyNR2LXMu3V7JjIjGFUGMfy3b9ISZL/QeQl0LGO nI75/wetvqhPCi7X1LDZwAnIcAdtSphEwQNssSkBbohLIGNG8GLJvOb18TGcPLawZ5ECsk58Yqf hZ8+enC/e3AHZnL8GmoZpGfmPXKvfNgquBMaGbCky1lZDODMtuyhu85ehqDSqM45iHz3z1pvHxM ODu0k3L/yIU472oAt6kNianYX8J5paV1a5B6qylUvOQjSTaBhw== X-Google-Smtp-Source: AGHT+IGZhmwKpQwnvPKnE1JfFtguTAnacOSX1U3j5ss9YEvo5SJPno3RZX52vQX8KS78wbMIjF0zZA== X-Received: by 2002:a05:6000:2c8:b0:390:eebc:6f32 with SMTP id ffacd0b85a97d-3971f7f9affmr19335621f8f.48.1742289558626; Tue, 18 Mar 2025 02:19:18 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v2 3/5] x86/xlat: fix UB pointer arithmetic in COMPAT_ARG_XLAT_VIRT_BASE Date: Tue, 18 Mar 2025 10:19:02 +0100 Message-ID: <20250318091904.52903-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318091904.52903-1-roger.pau@citrix.com> References: <20250318091904.52903-1-roger.pau@citrix.com> MIME-Version: 1.0 UBSAN complains with: UBSAN: Undefined behaviour in common/compat/memory.c:90:9 pointer operation overflowed ffff820080000000 to 0000020080000000 [...] Xen call trace: [] R common/ubsan/ubsan.c#ubsan_epilogue+0xa/0xc0 [] F lib/xxhash64.c#__ubsan_handle_pointer_overflow+0xcb/0x100 [] F lib/xxhash64.c#compat_memory_op+0xf1/0x4d20 [] F lib/xxhash64.c#hvm_memory_op+0x55/0xe0 [] F lib/xxhash64.c#hvm_hypercall+0xae8/0x21b0 [] F lib/xxhash64.c#svm_vmexit_handler+0x1252/0x2450 [] F lib/xxhash64.c#svm_stgi_label+0x5/0x15 Adjust the calculations in COMPAT_ARG_XLAT_VIRT_BASE to subtract from the per-domain area to obtain the mirrored linear address in the 4th slot, instead of overflowing the per-domain linear address. Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper --- Changes since v1: - New in this version. --- xen/arch/x86/include/asm/x86_64/uaccess.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/include/asm/x86_64/uaccess.h b/xen/arch/x86/include/asm/x86_64/uaccess.h index c6fa3fd381bc..f933707e109f 100644 --- a/xen/arch/x86/include/asm/x86_64/uaccess.h +++ b/xen/arch/x86/include/asm/x86_64/uaccess.h @@ -9,9 +9,9 @@ * a secondary mapping installed, which needs to be used for such accesses in * the PV case, and will also be used for HVM to avoid extra conditionals. */ -#define COMPAT_ARG_XLAT_VIRT_BASE ((void *)ARG_XLAT_START(current) + \ - (PERDOMAIN_ALT_VIRT_START - \ - PERDOMAIN_VIRT_START)) +#define COMPAT_ARG_XLAT_VIRT_BASE ((void *)ARG_XLAT_START(current) - \ + (PERDOMAIN_VIRT_START - \ + PERDOMAIN_ALT_VIRT_START)) #define COMPAT_ARG_XLAT_SIZE (2*PAGE_SIZE) struct vcpu; int setup_compat_arg_xlat(struct vcpu *v); From patchwork Tue Mar 18 09:19:03 2025 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: 14020623 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 4791EC282EC for ; Tue, 18 Mar 2025 09:19:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918732.1323402 (Exim 4.92) (envelope-from ) id 1tuT6Y-0001xs-Va; Tue, 18 Mar 2025 09:19:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918732.1323402; Tue, 18 Mar 2025 09:19:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuT6Y-0001xZ-RM; Tue, 18 Mar 2025 09:19:22 +0000 Received: by outflank-mailman (input) for mailman id 918732; Tue, 18 Mar 2025 09:19:22 +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 1tuT6Y-0001pb-Dj for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 09:19:22 +0000 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [2a00:1450:4864:20::42b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 12f21450-03da-11f0-9899-31a8f345e629; Tue, 18 Mar 2025 10:19:20 +0100 (CET) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-39141ffa9fcso4565944f8f.0 for ; Tue, 18 Mar 2025 02:19:20 -0700 (PDT) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-395cb7ea197sm17267527f8f.84.2025.03.18.02.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 02:19:19 -0700 (PDT) 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: 12f21450-03da-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1742289560; x=1742894360; 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=uvu5eIZtMQ2sjDw7pRYIO1mjfh/0Xg7gt34ETQV6Y38=; b=RAznACR7A6JqGxfEt0mjEomlqUYjy6MnmbRpaavvVuJasGZdMYlLlEIVM1niI5PR7q BmVE5UTywNDkObFiBDMimC13mikoJ9Bx/CBDzt2sSnndDIu+zzFxArSFeM0DyhZJh82f ZVO1bukoqOlNLroYfQe+hE4Ucyzv/teggYmZA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742289560; x=1742894360; 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=uvu5eIZtMQ2sjDw7pRYIO1mjfh/0Xg7gt34ETQV6Y38=; b=O5yPR7U3sKRhM3hq61pArvIJNdnfWL5b9jb0a8p/uJpbgSCWWwOo3bvsVyGYurHQsp YPZDfl4NSmsMnI7fSEm/7MhUxpuzgn/xiFR3yTWCjbOGJT8eIGUM7OmTzAN9x8GNoF4z XCtB+uyBol8Q69OMbaMcKNXFMI+L5jHqZ21QT7Sv3/cA9Z0+9HMcp0NzHREYyoH0ke1j tBSrK5zjIleMXOVko/1jojrkfKeTriKxsXApuE81KE/mXGJE4sWqOiaTccFBbnzyzG+A aO/fx8NpGV0iXNoG4jI32Irv5w6M4XY92f8r1ePkp0vPBTdQoW5Xa44/SlFES5SrDS2e JwSw== X-Gm-Message-State: AOJu0YxdgesyWxzHbxgzAFDwuR1nmYEkwrzbykJ14dJaCR9v760wXvlD zvTulKadlNQltGWJYWLFbIoFwONXKvVbouMsE7sjvW5jOvyF4nesVLBqX9++cHrpHUnjoxrCFR7 h X-Gm-Gg: ASbGncs9b5Insx9/NDUwiu2R6RtTKkNItfqxVs+i9tjoIREBm5BVS2yYPIf1NLR5tsE xPxUm8ljzP2i1tlddY2HpswwZf9oqjhq1gQ3NVVZbMukhhXRcyVzcbOPgtyz31ruiu9YjJk2Ogr SH3Bd0sy3OWhgFZ1GKNhcUF5G12suhW+OEWO+lGpSOdz1UMirdUpqHOjI0lVlCFfI/j3TOqLyoN XlUIc6ISyKRarw/1Pi7TT66T6glrTAxpPHZ1Oqby/x8MSmEmK5xJVDhCO+8CyTB/fv3ZoeJsLsT 714qCmAKXm5U/XKWqtKnoiAlmldUbGduxs58/dYvZ31tpocaKg== X-Google-Smtp-Source: AGHT+IGZoxRERBI2o5PdcYEf0GTFklKZscfnxI6ptTAwbkD0XhjdjMKBMAO21xu5GZUvgQ2Sxr70gg== X-Received: by 2002:a05:6000:4023:b0:391:487f:2828 with SMTP id ffacd0b85a97d-3996b445302mr2703349f8f.10.1742289559732; Tue, 18 Mar 2025 02:19:19 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Tim Deegan Subject: [PATCH v2 4/5] x86/shadow: fix UB pointer arithmetic in sh_mfn_is_a_page_table() Date: Tue, 18 Mar 2025 10:19:03 +0100 Message-ID: <20250318091904.52903-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318091904.52903-1-roger.pau@citrix.com> References: <20250318091904.52903-1-roger.pau@citrix.com> MIME-Version: 1.0 UBSAN complains with: UBSAN: Undefined behaviour in arch/x86/mm/shadow/private.h:515:30 pointer operation overflowed ffff82e000000000 to ffff82dfffffffe0 [...] Xen call trace: [] R common/ubsan/ubsan.c#ubsan_epilogue+0xa/0xc0 [] F lib/xxhash64.c#__ubsan_handle_pointer_overflow+0xcb/0x100 [] F arch/x86/mm/shadow/guest_2.c#sh_page_fault__guest_2+0x1e350 [] F lib/xxhash64.c#svm_vmexit_handler+0xdf3/0x2450 [] F lib/xxhash64.c#svm_stgi_label+0x5/0x15 Fix by moving the call to mfn_to_page() after the check of whether the passed gmfn is valid. This avoid the call to mfn_to_page() with an INVALID_MFN parameter. While there make the page local variable const, it's not modified by the function. Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper , but the backtrace --- Changes since v1: - New in this version. --- xen/arch/x86/mm/shadow/private.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm/shadow/private.h b/xen/arch/x86/mm/shadow/private.h index a5fc3a7676eb..cef9dbef2e77 100644 --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -512,13 +512,14 @@ static inline unsigned long __backpointer(const struct page_info *sp) static inline int sh_mfn_is_a_page_table(mfn_t gmfn) { - struct page_info *page = mfn_to_page(gmfn); + const struct page_info *page; struct domain *owner; unsigned long type_info; if ( !mfn_valid(gmfn) ) return 0; + page = mfn_to_page(gmfn); owner = page_get_owner(page); if ( owner && shadow_mode_refcounts(owner) && (page->count_info & PGC_shadowed_pt) ) From patchwork Tue Mar 18 09:19:04 2025 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: 14020627 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 059ACC282EC for ; Tue, 18 Mar 2025 09:19:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918733.1323412 (Exim 4.92) (envelope-from ) id 1tuT6a-0002E8-7P; Tue, 18 Mar 2025 09:19:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918733.1323412; Tue, 18 Mar 2025 09:19:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuT6a-0002DB-2g; Tue, 18 Mar 2025 09:19:24 +0000 Received: by outflank-mailman (input) for mailman id 918733; Tue, 18 Mar 2025 09:19:23 +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 1tuT6Z-0001pb-7G for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 09:19:23 +0000 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [2a00:1450:4864:20::32a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 13a5018d-03da-11f0-9899-31a8f345e629; Tue, 18 Mar 2025 10:19:21 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43cfba466b2so31014145e9.3 for ; Tue, 18 Mar 2025 02:19:21 -0700 (PDT) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43d1ffbcef5sm128109935e9.9.2025.03.18.02.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 02:19:20 -0700 (PDT) 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: 13a5018d-03da-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1742289561; x=1742894361; 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=gnMyX9kFHyXzrDrfsJ2RlCItrD8ia9EDnLZKJ/omKus=; b=I7tanCAz2GCxrp0jEh/xE12/ZcqV4ndnSKBuaYG+hWgdqCV9u/8xGnnm/kkeGdIjRU r/q6lfxqB2PYn26e7XRHaU8MOkDcW8NDWG2ndad0FvMec0PGbB171noJqec8tM31hh0/ qwSps+el/ZgimMXBcMdH2lEZM/L9Megvrafpk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742289561; x=1742894361; 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=gnMyX9kFHyXzrDrfsJ2RlCItrD8ia9EDnLZKJ/omKus=; b=HV53aaLKdk7jehWVJoMkgijFRS3hmXicy1DZGxgnKxKLD3mh5KHl5dro1I4xQZe6NT JJLeW+2tKfk2xHOUtwO4AbQXHOwufxvaQm06Bw6KA2x5WjUeTKBaHCs9q++C96attc9B zfFqd3mrCmQjs517uIMGPkY6TthfuQqbSe5E3t8o2rQ9EfoaXgQH2X4ZsX/35j0MkNKo 2le6p8/XeRlVGcF+PvbTtfqF9KcQnn87M/Z+niNFlpiDpCSL4fLxGJgr0kZdAXpymzyS D0aSz0YX3tGG6oA001B3P+W88SELgYeG2rfM5PYqOQXMGico74NdLilAETC2vhUxacnN 6mvA== X-Gm-Message-State: AOJu0YyegHofS9BkXSjskWDVfCIftF2QQzyuJ/EB202VYQLz1Yvs8eMc 2HKzAvsjMsargmgyU9Vp//RmaKJWrVrMALtNuWBE9VJvNwQfbq8ru75ozO+ma1wc9P/oSYqsPaT c X-Gm-Gg: ASbGnctI45SvuE7IeormYaBkfuQ8r5INLSdcdFyj0B2ixdYkePYln7wmTcP9rpYA6Jc p0/QpCnR4PT66UZylwmvIxBz3qe+3rVbSdynvRWcTNe84Z5owMccqVbxaHeUnPEMFzFAlfpegKY Tbvsx2YmsnvsLxj2jaxcWEvZL6KFIvlS8KRqZZ3zFQUsdgfqtDt/R+vfedFxpVJxw7BEtfgpyh7 dMJqnVYAkMXH4/Lt02smqMrQVdR4OLQHcTFPZSd/AQKiQDRtsqdvoR96eYdpReoZEd6svUJ5pzL qLe1fd/sCjF2RGOANu2war5PlS7YH70wuf+NYe0mHDTBELV/Erw2/lzcxD2n X-Google-Smtp-Source: AGHT+IFx1B/uo+A+eLee+hmEmUSpjHQS6B/JBzEUIWCCZ2fncEVgSrIgPpwpISI15sBHu35V31+6rw== X-Received: by 2002:a05:600c:4e51:b0:43c:f8fe:dd82 with SMTP id 5b1f17b1804b1-43d3b9ba9d4mr12535915e9.18.1742289560796; Tue, 18 Mar 2025 02:19:20 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini , Doug Goldstein Subject: [PATCH v2 5/5] kconfig/randconfig: enable UBSAN for randconfig Date: Tue, 18 Mar 2025 10:19:04 +0100 Message-ID: <20250318091904.52903-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318091904.52903-1-roger.pau@citrix.com> References: <20250318091904.52903-1-roger.pau@citrix.com> MIME-Version: 1.0 Introduce an additional Kconfig check to only offer the option if the compiler supports -fsanitize=undefined. We no longer use Travis CI, so the original motivation for not enabling UBSAN might no longer present. Regardless, the option won't be present in the first place if the compiler doesn't support -fsanitize=undefined. Signed-off-by: Roger Pau Monné Reviewed-by: Andrew Cooper --- xen/Kconfig | 4 ++++ xen/Kconfig.debug | 2 +- xen/tools/kconfig/allrandom.config | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xen/Kconfig b/xen/Kconfig index 72fdb8376087..2128f0ccfc0b 100644 --- a/xen/Kconfig +++ b/xen/Kconfig @@ -37,6 +37,10 @@ config CC_HAS_VISIBILITY_ATTRIBUTE config CC_SPLIT_SECTIONS bool +# Compiler supports -fsanitize=undefined +config CC_HAS_UBSAN + def_bool $(cc-option,-fsanitize=undefined) + # Set code alignment. # # Allow setting on a boolean basis, and then convert such selection to an diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index c4a8d86912e0..f7cc5ffaabd7 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -98,7 +98,7 @@ config SCRUB_DEBUG config UBSAN bool "Undefined behaviour sanitizer" - depends on HAS_UBSAN + depends on HAS_UBSAN && CC_HAS_UBSAN help Enable undefined behaviour sanitizer. It uses compiler to insert code snippets so that undefined behaviours in C are detected during runtime. diff --git a/xen/tools/kconfig/allrandom.config b/xen/tools/kconfig/allrandom.config index 76f74320b5b0..c7753ac4addb 100644 --- a/xen/tools/kconfig/allrandom.config +++ b/xen/tools/kconfig/allrandom.config @@ -1,4 +1,3 @@ # Explicit option choices not subject to regular RANDCONFIG CONFIG_GCOV_FORMAT_AUTODETECT=y -CONFIG_UBSAN=n