From nobody Thu Nov 28 23:40:25 2024 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=google.com ARC-Seal: i=1; a=rsa-sha256; t=1727347330; cv=none; d=zohomail.com; s=zohoarc; b=FwVwk3oc3ID2dNe/nS59WDhmO9nm9jNzqpSd5q0ORI9YFZYj848xFtiYtJhtNfSoWSh6Wzy/zVoBYQBSPI50M1nsYG8UXl1EJWl9jislIHQU81VHKjxnxbVzdihiAtKtiPApGBdXgDeMVb5S7riVn6F0trniGsVbla2oiz2fPSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727347330; h=Content-Type: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=TwoP1rcUlc5IEWvZoDzQ3o2b6cQ+HDztqml72ZvJe/8=; b=VKtU9ku7c9wbZUJcOHInafs5AHesWFPQuzGPgwenG+W3oCdnr1ZR+FoHf76Uf/JLuA3PILkoW7W1L/dg19PCM6p1btJwJJMDx6c5XMuIjHGNmHcb9rFHB427qV/Jx2RFvTpPcb0tRMHibasG2JYl4StqCGT/9kziuAX6kYLE54I= 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 17273473305196.400782879525536; Thu, 26 Sep 2024 03:42:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805303.1216363 (Exim 4.92) (envelope-from ) id 1stlwZ-0003gA-5c; Thu, 26 Sep 2024 10:41:55 +0000 Received: by outflank-mailman (output) from mailman id 805303.1216363; Thu, 26 Sep 2024 10:41:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stlwZ-0003g1-1Y; Thu, 26 Sep 2024 10:41:55 +0000 Received: by outflank-mailman (input) for mailman id 805303; Thu, 26 Sep 2024 10:41:53 +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 1stlwX-0003PD-7F for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 10:41:53 +0000 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [2607:f8b0:4864:20::1149]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f0f0000b-7bf3-11ef-a0ba-8be0dac302b0; Thu, 26 Sep 2024 12:41:52 +0200 (CEST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6de0b23f4c5so11273067b3.1 for ; Thu, 26 Sep 2024 03:41:52 -0700 (PDT) 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: f0f0000b-7bf3-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727347311; x=1727952111; darn=lists.xenproject.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TwoP1rcUlc5IEWvZoDzQ3o2b6cQ+HDztqml72ZvJe/8=; b=PPedG0qk0tfIYEQrKQph4LgquD03MY4RfJQTe1p0uczGCBmAopCU0JmIGH5HSvpuyF XSx5c6WOlE+09Pr1Yy+jzb5K5/AH6ypjPICTAY3cMH7hq5XHZJPKi8SHVSGzLyL5tGri RZx9X63EFv0pPr8pStSEX0EAPSFgsYf5GWJwG+l5EIdW6crwxWuMwWu1gf0Ki/PbYIS6 XzM5C2D+0J9gKsHrfpZoH9EGbVTpl9gOfCNxPZJuED8s8saOW5g2wXfQ+FrVNWPLvH3S 7qj9UttAXruDZN7CJoWCNqAQJM22DloRKHaGZRiFZiDVobjJL+X2pd8/WpBFMcqNp7db +c4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727347311; x=1727952111; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TwoP1rcUlc5IEWvZoDzQ3o2b6cQ+HDztqml72ZvJe/8=; b=asTJEYVEePRac3wisxStr8J3VcRF83Dl9N0/7pSGtcrxT21oUJGIxnIS6HcGf7tYI3 2HVhmIdNrLf6dDvNXNuoQRGvCiCC2SZ6YE4OGA2Z4WjUArKAZz+Kzd9F1hVAPuwfaxGE tlgwiwRNm6aUCghUB5TyQTUmcEsHy8q11DhWnCCTdGJADP1oiwoLqKBEzfHXARKn9rZ3 VfySW3hS495K957YibEEs7/bBy4LGUPY3VPZfoVJCPnF59LJtmHbvP64vKYhMBrC5WhI vQfOwMad0hRBt5/xGgZHWWpFny9TBvtOVIGPPfNrapgSeocFwQuwz1UoXmxbuz/SL+cB dYFw== X-Forwarded-Encrypted: i=1; AJvYcCU7s35pbR2MFxjFfwez2hfNafcpY5fxJJiQ94lJZmodRIXtNitov4yc1+OLWue3X5/C+dmJ7O35DHw=@lists.xenproject.org X-Gm-Message-State: AOJu0YyLkf05qMEE59qh1YKjrrIPAou6dj916PsCmkhoIMCoNp+h3WQO iImqGTfTKSl0r232Vd1wbRMoRaUA2XoPnRb1VobcI0XYDepfwmZ8lZ9cgvHFewZSgvSyRQ== X-Google-Smtp-Source: AGHT+IGFcogBWg0YNHvYrp22ksYkslUYaSpidn/WqA3QXt5WaLA/ISxC26Dr6MxOSXjYzk1lqyi8vs0/ X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:7203:b0:6dc:836a:e272 with SMTP id 00721157ae682-6e22ec9e35fmr540887b3.0.1727347311481; Thu, 26 Sep 2024 03:41:51 -0700 (PDT) Date: Thu, 26 Sep 2024 12:41:15 +0200 In-Reply-To: <20240926104113.80146-7-ardb+git@google.com> Mime-Version: 1.0 References: <20240926104113.80146-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1549; i=ardb@kernel.org; h=from:subject; bh=nGFC7zN3evy7O6d/rvxHyA6d64EhlpFJ+bJvxzbH5PE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIe2rlfekYxbphgk37j1fI2+6+6JyzKRrSvf5uPkYr2770 /vy3/atHaUsDGIcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAiV4oY/uneq+0IOFzKn64x 6dHOnxXrpRKSfhs4zFp0WuTkvae5c6cxMhxm0Y98ri366awCh9g15YlN/ov+djz78lvU7gN3WcX 8FTwA X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240926104113.80146-8-ardb+git@google.com> Subject: [PATCH 1/5] x86/pvh: Call C code via the kernel virtual mapping From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Jason Andryuk , Juergen Gross , Boris Ostrovsky , x86@kernel.org, xen-devel@lists.xenproject.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1727347330942116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Calling C code via a different mapping than it was linked at is problematic, because the compiler assumes that RIP-relative and absolute symbol references are interchangeable. GCC in particular may use RIP-relative per-CPU variable references even when not using -fpic. So call xen_prepare_pvh() via its kernel virtual mapping on x86_64, so that those RIP-relative references produce the correct values. This matches the pre-existing behavior for i386, which also invokes xen_prepare_pvh() via the kernel virtual mapping before invoking startup_32 with paging disabled again. Fixes: 7243b93345f7 ("xen/pvh: Bootstrap PVH guest") Tested-by: Jason Andryuk Reviewed-by: Jason Andryuk Signed-off-by: Ard Biesheuvel --- arch/x86/platform/pvh/head.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 64fca49cd88f..98ddd552885a 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -172,7 +172,13 @@ SYM_CODE_START_LOCAL(pvh_start_xen) movq %rbp, %rbx subq $_pa(pvh_start_xen), %rbx movq %rbx, phys_base(%rip) - call xen_prepare_pvh + + /* Call xen_prepare_pvh() via the kernel virtual mapping */ + leaq xen_prepare_pvh(%rip), %rax + addq $__START_KERNEL_map, %rax + ANNOTATE_RETPOLINE_SAFE + call *%rax + /* * Clear phys_base. __startup_64 will *add* to its value, * so reset to 0. --=20 2.46.0.792.g87dc391469-goog From nobody Thu Nov 28 23:40:25 2024 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=google.com ARC-Seal: i=1; a=rsa-sha256; t=1727347336; cv=none; d=zohomail.com; s=zohoarc; b=PCvd4nj19y/ehnexsJA9RGEp9rWmx0arUubrUV9+zoeKO716S+XdzMmECkiZ8IXorJcGcXSLiYfhw+mLxOe493GNnTlof8RYOP5pZvOR4wjZGqePJrrkPnEpxRkv7mlnweTeNMXAhUF/nNsm7fv2vjIIDDWw9ogtp9qjKpmWHB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727347336; h=Content-Type: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=iGUWykkQN0qvnmtiNNnHPsRB647HBGhIOvWdjI4gnIE=; b=KIA1cxTrL+mdR8c7+bB43hgNTb128+GHf2uAeyFbhqbHczF9OVglg54hDkHWVQeDlqFtO6p4mERc2AeYr5DS2mgXOjCw3VbfHZlBJU0x35Q3kg6v3uUNi0WINs/fQ4WNa5XoOOyOGa9da1Kl56q7AAR1zpyaS33jkgxic8xMX64= 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 172734733585684.88865819982823; Thu, 26 Sep 2024 03:42:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805304.1216373 (Exim 4.92) (envelope-from ) id 1stlwa-0003vf-Bt; Thu, 26 Sep 2024 10:41:56 +0000 Received: by outflank-mailman (output) from mailman id 805304.1216373; Thu, 26 Sep 2024 10:41:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stlwa-0003vY-8a; Thu, 26 Sep 2024 10:41:56 +0000 Received: by outflank-mailman (input) for mailman id 805304; Thu, 26 Sep 2024 10:41:55 +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 1stlwZ-0003PD-9I for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 10:41:55 +0000 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [2a00:1450:4864:20::44a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f27938ae-7bf3-11ef-a0ba-8be0dac302b0; Thu, 26 Sep 2024 12:41:54 +0200 (CEST) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-37ccc188d6aso477081f8f.2 for ; Thu, 26 Sep 2024 03:41:54 -0700 (PDT) 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: f27938ae-7bf3-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727347314; x=1727952114; darn=lists.xenproject.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iGUWykkQN0qvnmtiNNnHPsRB647HBGhIOvWdjI4gnIE=; b=4r2BqoD67WQ099RItlQm64rEL1/F10o8akgCrpJ3+XWDWyn5RrYk5yQbXlD/775o2K OYaOVkAeSJFerW/e1+SeDKZXKB+c54nIUDcC1Flw98cp0YPVZRtnAjRp8udaELjLQoVA Jwz6iPt6fZFNKTAc9FKZXx4H0T3id5LRafyPDExK7R3ejKJzYwEuIDIpfs8eCE4zEtyk a3lXP3RpTtjliBNYoD8uL/41VUCnejNH0IytIuzIjKNED5H7C+H3IdBVNfoQONE7+WPi EyUJadXmRNDX8QkGgqkwh+YpBG3hjTwkzh6vC1jFIsUO57wZiAhdIftSe25bp9+qqwKr 3u0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727347314; x=1727952114; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iGUWykkQN0qvnmtiNNnHPsRB647HBGhIOvWdjI4gnIE=; b=ArSpRGNnRVPcWMr+FoH5HuwjXp5HFmoMvFZhoeKUwbftLQN+oGj6XpUXYhrQncX3Ir kl0HFNPZndVsXbRxJFLlzmGiWWjQ1MV+daftBRFY94Add78Zh7w3LbN8p2ZEi4ko+zjd QP/IZ28/nHYwbEaItvd75Z5+/vLE3I0XhBE9x5NIP+Pi0zyk2bwg/QzKcrTQc7T14exb 3NvncXZX7WabCAwVocGGbbDT2lxRRGgMeIsAdn2Ow1ET2jKRkQl0RNffOIve0lNcuOrn jJNsDN/Ro9MfAjMuC/1RJl089XNEwJ6rrX95SPUEw+lAl69SC1bLMK49iE9tFq0BHGrJ W75Q== X-Forwarded-Encrypted: i=1; AJvYcCWWeqYPEgVkRUEb27sZCQEAy52xNNHh8Og08EUIDXNs9B1LeUU5SdWxVyDGmUzCbsxq91bQ0kUTNIQ=@lists.xenproject.org X-Gm-Message-State: AOJu0Yy18Mqq/gwvG7bzuBQB7Y381yQBnAtjirH40mk1WTmh/U4OrzxA VD6YdyL25rYf27j6jQGjoOOjZCg2mUj88GzbfgMkqvIeHGda+J0mpmEJPqJ3msQUAKcbZg== X-Google-Smtp-Source: AGHT+IEW8daEir8doMTYKMTvqxc57QBSWijUw3aucG3twtEOjb20bOmmyd2zxDXhxhBNFQdIHerVpIzL X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:adf:f5cc:0:b0:374:ba5c:d59 with SMTP id ffacd0b85a97d-37cc22c28c9mr3799f8f.0.1727347313937; Thu, 26 Sep 2024 03:41:53 -0700 (PDT) Date: Thu, 26 Sep 2024 12:41:16 +0200 In-Reply-To: <20240926104113.80146-7-ardb+git@google.com> Mime-Version: 1.0 References: <20240926104113.80146-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=738; i=ardb@kernel.org; h=from:subject; bh=duJbwDYusVICSqLA5fZPaN2Y/gts1cbjl01DSFcZijg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIe2rle/zunAFTQ8uo0anZz3lB82OHO8LP3L+2lmd1bueh fjq+tl0lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIk8O8XwT5P3of6psH2Nt6wt 14S9Tru+QX3jdqMNE9bvFVnYGfCEdT0jwxaP/S0RDQ9cdv5L82B1q3ql4Zzkajwh8LCzSIzBPTM mXgA= X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240926104113.80146-9-ardb+git@google.com> Subject: [PATCH 2/5] x86/pvh: Use correct size value in GDT descriptor From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Jason Andryuk , Juergen Gross , Boris Ostrovsky , x86@kernel.org, xen-devel@lists.xenproject.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1727347336886116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The size field in a GDT descriptor is offset by 1, so subtract 1 from the calculated range. Signed-off-by: Ard Biesheuvel Reviewed-by: Jason Andryuk Tested-by: Jason Andryuk --- arch/x86/platform/pvh/head.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 98ddd552885a..f09e0fb832e4 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -223,7 +223,7 @@ SYM_CODE_END(pvh_start_xen) .section ".init.data","aw" .balign 8 SYM_DATA_START_LOCAL(gdt) - .word gdt_end - gdt_start + .word gdt_end - gdt_start - 1 .long _pa(gdt_start) /* x86-64 will overwrite if relocated. */ .word 0 SYM_DATA_END(gdt) --=20 2.46.0.792.g87dc391469-goog From nobody Thu Nov 28 23:40:25 2024 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=google.com ARC-Seal: i=1; a=rsa-sha256; t=1727347341; cv=none; d=zohomail.com; s=zohoarc; b=YNrTpm9lGlO99B0PaM+sYgNb1irLeEKXDQxYLbOr5DlUiFQ8QqxBZkx5zRWgpLjnwvLDrvO8gPdyX7iKiOeKl6ofcGqvVvqKejajNJySiLKJPnnEVw5HIqwgCmdWkk7JRU6NyWswlYgQI2eu5chCO71oG7uy8ZXuSkjgq6KwNPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727347341; h=Content-Type: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=ownyzv9FvJUARNva8kkWN7DdL7kgRVlMI6W55f3d3tc=; b=DE21JF1/tO4lLyEPgQRW+qY+qutaxFt51r1g1F/P1c8RIhCB38yQ3q9DXWwDtFTd+yJ0kdqe0p/uniZHWYiS29R0DKjpwsWlBV2u2P1ZaBWmQ7X5HQt1br8uxCm8iHDFdV6Dka344SaikQMOs7OCuZqogjCxp0V9FD68r0gZBK4= 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 1727347341242125.7400553276724; Thu, 26 Sep 2024 03:42:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805305.1216383 (Exim 4.92) (envelope-from ) id 1stlwc-0004ET-KM; Thu, 26 Sep 2024 10:41:58 +0000 Received: by outflank-mailman (output) from mailman id 805305.1216383; Thu, 26 Sep 2024 10:41:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stlwc-0004EI-HD; Thu, 26 Sep 2024 10:41:58 +0000 Received: by outflank-mailman (input) for mailman id 805305; Thu, 26 Sep 2024 10:41:57 +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 1stlwb-0003PD-O5 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 10:41:57 +0000 Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [2a00:1450:4864:20::649]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f3f055e3-7bf3-11ef-a0ba-8be0dac302b0; Thu, 26 Sep 2024 12:41:57 +0200 (CEST) Received: by mail-ej1-x649.google.com with SMTP id a640c23a62f3a-a8a92ab4cdbso56161766b.0 for ; Thu, 26 Sep 2024 03:41:57 -0700 (PDT) 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: f3f055e3-7bf3-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727347317; x=1727952117; darn=lists.xenproject.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ownyzv9FvJUARNva8kkWN7DdL7kgRVlMI6W55f3d3tc=; b=CmAYAotApeoeWCzZrzHiW6RnaYdDMjS1vFAHGwqiWcpyOveFdVzvGHtdpEVX/vReS4 uPNH9Gskd8bX311dzJsE/ZFXQrc+t8KQLoB0EK66U4k2w4w6ksGWjq09TCZ+3UHTJ0S8 2aoyLA/Lk47HU70uSqjKOJCOumcgCacJaQCxOfyTGy5Vs1OOpei2ok6CALoinECDCUCg 8RntlxcB5XHHtPd2G3bqzSOQfQZPXVfyg/aGKwfDwNeEFgh0XYXX4DzduqjYn2FObSTa x01W/tWRV2NJmwmOELpQkeYuV8F67hmE95QVZvcRh5CWoHSGntMsT+iSf4jAtGorxwcv stHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727347317; x=1727952117; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ownyzv9FvJUARNva8kkWN7DdL7kgRVlMI6W55f3d3tc=; b=NCZEIFoOrTPdaMMUdaEp/ABVnyfBVpejGOZw+nu9zsHqJPDfQzyNhRh+nnM+/SouI+ T6gR0pxRzixyN7QwCx2JDwszkmXelkcDABrSPN2/J7Xtz4+dfsZ/9jU+ARQbvRqhxBv0 wp6Tx176+utaW4kQdiJZ/R/6PhtT9NvH2g8v65xDBtPgbyINmJgX53aK+SzKKjpypb2J jEWCCterXOs8j6aVb56tjA/ZM22/6wGPYomTV0DlRVRh9EqBdGDwBOA0e++YHGTOsavU Ubccqp/rkllQ4F05FHbWDZAtG/t2HCitj5Wqe5EyPcXbtvf3bMmih7rZW+UBKB3G1TXQ nVMg== X-Forwarded-Encrypted: i=1; AJvYcCXLUvQBSZuURMWUX986wGjUYWN96LHMP6EOmwLtS9jkjpgTIe1gbpVbK8si48kK92rzi172/dkHKIo=@lists.xenproject.org X-Gm-Message-State: AOJu0Yzx14Rfocrk17ENveYtl3vHQdxRuUiK9UD6bn/sg6Z7YhVvSBCj BCuy1iGpdTo/ju+Ead+7+DdY/xYLoMLm3KnnJh0KXdMtaQ7NPymJYn8RQ+nfOlye2p9vSA== X-Google-Smtp-Source: AGHT+IGy82jujwPzArGAUf1MuUGtrrrgAoLRL/QZd4vc5rXaUoeqVqj+O60HWt1N3meFf9X0ymoxcaJv X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a17:906:1642:b0:a7d:e176:71d1 with SMTP id a640c23a62f3a-a93a05c19a3mr293266b.9.1727347316493; Thu, 26 Sep 2024 03:41:56 -0700 (PDT) Date: Thu, 26 Sep 2024 12:41:17 +0200 In-Reply-To: <20240926104113.80146-7-ardb+git@google.com> Mime-Version: 1.0 References: <20240926104113.80146-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=904; i=ardb@kernel.org; h=from:subject; bh=SK89jirZxlyhNPfrfzxj4qoYkybGiruH5hLSJPLATEs=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIe2rlZ/E9V0L29KWOv/h8NISPt5Qf6nif2NoSM088ZqgV b0Oy9Z1lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIl81WD4Z7rxIf/2XQpOzxxi q5977XTzWHJUoKvkSs5y83eJYekuDxkZev2uM8t8FD0tYzvjxseQtEWvZX8cSOZMLDU648yRJyn GDwA= X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240926104113.80146-10-ardb+git@google.com> Subject: [PATCH 3/5] x86/pvh: Omit needless clearing of phys_base From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Jason Andryuk , Juergen Gross , Boris Ostrovsky , x86@kernel.org, xen-devel@lists.xenproject.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1727347342897116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Since commit d9ec1158056b ("x86/boot/64: Use RIP_REL_REF() to assign 'phys_base'") phys_base is assigned directly rather than added to, so it is no longer necessary to clear it after use. Signed-off-by: Ard Biesheuvel Reviewed-by: Jason Andryuk Tested-by: Jason Andryuk --- arch/x86/platform/pvh/head.S | 7 ------- 1 file changed, 7 deletions(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index f09e0fb832e4..592747f2d731 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -179,13 +179,6 @@ SYM_CODE_START_LOCAL(pvh_start_xen) ANNOTATE_RETPOLINE_SAFE call *%rax =20 - /* - * Clear phys_base. __startup_64 will *add* to its value, - * so reset to 0. - */ - xor %rbx, %rbx - movq %rbx, phys_base(%rip) - /* startup_64 expects boot_params in %rsi. */ lea pvh_bootparams(%rip), %rsi jmp startup_64 --=20 2.46.0.792.g87dc391469-goog From nobody Thu Nov 28 23:40:25 2024 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=google.com ARC-Seal: i=1; a=rsa-sha256; t=1727347341; cv=none; d=zohomail.com; s=zohoarc; b=VjVXfdy4ahb8cDY4xXNvozYq5skrfg+AHHKXc1Iq/3VI7px44zWcnGpt4xr8PstbDpLZshSiCr6Lg4x02OB2oD/qDmGXVeU6MN+S6MniAi+ljoUgPGd3abVGKYy+KSvog9gLdI5T7rl6kpfCiBFsoT9uPA9AHj493wiS0N4UR78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727347341; h=Content-Type: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=wVQAOpFtZ+IFLD65Dag6PltLcshQiZuKZHS02xe9k5U=; b=M0RPsrbcoN5Sv6C7Az+lme7GO9UjuCvIur4T0BExvi2OyQOEv1/C9tDLnd851t9mkpquM4q43MDuc80SuhOQatGGY5XlEOGGW1u6aS8tlCj7leIOwGUnYy7XtpoLsxcIOiRltKOsRYjXQGuK6vhFIQYz5ggdoJQGY+hTZzMeVuo= 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 1727347341478589.2149191653359; Thu, 26 Sep 2024 03:42:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805306.1216393 (Exim 4.92) (envelope-from ) id 1stlwh-0004dD-RG; Thu, 26 Sep 2024 10:42:03 +0000 Received: by outflank-mailman (output) from mailman id 805306.1216393; Thu, 26 Sep 2024 10:42:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stlwh-0004d3-OJ; Thu, 26 Sep 2024 10:42:03 +0000 Received: by outflank-mailman (input) for mailman id 805306; Thu, 26 Sep 2024 10:42:02 +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 1stlwg-0003NZ-Cu for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 10:42:02 +0000 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [2607:f8b0:4864:20::114a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f59e4404-7bf3-11ef-99a2-01e77a169b0f; Thu, 26 Sep 2024 12:42:00 +0200 (CEST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e230808388so11262237b3.0 for ; Thu, 26 Sep 2024 03:42:00 -0700 (PDT) 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: f59e4404-7bf3-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727347319; x=1727952119; darn=lists.xenproject.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wVQAOpFtZ+IFLD65Dag6PltLcshQiZuKZHS02xe9k5U=; b=xXQDoImyuZtfONSN9x+fiwECyckkWeZMLq0brxnJrcSU63eaEsipO0E6gDlbEkt+SH 83pKvPu9K/4e1EDhgB++57q37vy8Zzw9tEIf7XUBiANSthrPmpq424WjsKlB03aSWkt7 oUOkaLTeaZIEy0WZeCU+mk/p/8XgSdfuXI00KqKLx8NcBC4/FGn5vGx9rt/Psx+IltLG HhSMT44GogenNZioNYNIIBrUPlxdYlB1VvtBU4ivXz+I2bIJzXBAveGX5Qp4gwSNEVEI UzH3HUILNJqmP9kUHzn+4Pdi/m1RFugkzcSsOLDTV5BCGIoec7O5DIiph2oT7rdmcsqi Wayw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727347319; x=1727952119; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wVQAOpFtZ+IFLD65Dag6PltLcshQiZuKZHS02xe9k5U=; b=VNn6yvCbNJxHhCFCtmgml3cpiCEFwKpo5aWtsJcL6zXQeTk+atK+bP9OIy6X5rrjzU mDUUcMcViI4fIU0GSRpx7juvIosthOyTpkM78Kwp3vLAWBSD/xnsCg9/y3kJ+4cNrIha DbzdNvj4GzXBlN9TzEi9wSzDMNDPxlFpzh5kNoidzC4Iq4Hq/B5DJ4XnAehZ9iOXy1SB NooVhheIfozW7FDandfEvR3gNhAoPfoMJcMsI59WLBMO4sqb1j13qtarVeriHbz0P6PU xoWsoYCHKoR5IKPpvVnd8vLa3MThuXenPImRSe5DEmxartwIAMMFBo3EbhSPdCysjGCr ydrQ== X-Forwarded-Encrypted: i=1; AJvYcCWvzv0mKkEjdY+Uj6IAgB2TRv8y2e3R/cnLiCsUXLOPtDXGCanpHyZLiFh6TGTSXZ6HdZ8xckCmP0o=@lists.xenproject.org X-Gm-Message-State: AOJu0Ywhqc+fVbC1tPUSWaGipfwtDRRc3GQW4Nmnhuqy2rGWjEfQ397S sRO/wQt4R7Vm4WiTQsgIbsP6CFeAyj9fsHZRm2fbRCV9IH3TaJvZ1xNC8nQN9AIYLbsN8w== X-Google-Smtp-Source: AGHT+IGFqzFJ5DM6fuJFCR9nZvBpCXoaxNKegwYh6rQwKhd8Opr932KfMh+UgrKPITetFqVET84sn/lt X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:d85:b0:6db:e107:75a2 with SMTP id 00721157ae682-6e21da5c761mr677017b3.4.1727347319432; Thu, 26 Sep 2024 03:41:59 -0700 (PDT) Date: Thu, 26 Sep 2024 12:41:18 +0200 In-Reply-To: <20240926104113.80146-7-ardb+git@google.com> Mime-Version: 1.0 References: <20240926104113.80146-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4265; i=ardb@kernel.org; h=from:subject; bh=V807GS2Tj3E3lwWN+K0J1jVOybFlVVUTSd+sKKD/vLg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIe2rVcAFH7mbsx6l51p3OK/XkT7d39ii1zab++TUyPqe6 dzqXu87SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwERMtjIy/Lorcfi/7fSyDmlr bgmlmHNfalct0FVotHljq82yv2j2Z4b/tTuXXZiuvNlx21qDp+Kncn/93HKUh2/Hq8SWB7kzTk5 nZQQA X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240926104113.80146-11-ardb+git@google.com> Subject: [PATCH 4/5] x86/xen: Avoid relocatable quantities in Xen ELF notes From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Jason Andryuk , Juergen Gross , Boris Ostrovsky , x86@kernel.org, xen-devel@lists.xenproject.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1727347342958116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Xen puts virtual and physical addresses into ELF notes that are treated by the linker as relocatable by default. Doing so is not only pointless, given that the ELF notes are only intended for consumption by Xen before the kernel boots. It is also a KASLR leak, given that the kernel's ELF notes are exposed via the world readable /sys/kernel/notes. So emit these constants in a way that prevents the linker from marking them as relocatable. This involves place-relative relocations (which subtract their own virtual address from the symbol value) and linker provided absolute symbols that add the address of the place to the desired value. While at it, switch to a 32-bit field for XEN_ELFNOTE_PHYS32_ENTRY, which better matches the intent as well as the Xen documentation and source code. Signed-off-by: Ard Biesheuvel --- arch/x86/kernel/vmlinux.lds.S | 12 ++++++++++++ arch/x86/platform/pvh/head.S | 6 +++--- arch/x86/tools/relocs.c | 1 + arch/x86/xen/xen-head.S | 6 ++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 6e73403e874f..dce17afcc186 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -528,3 +528,15 @@ INIT_PER_CPU(irq_stack_backing_store); #endif =20 #endif /* CONFIG_X86_64 */ + +#ifdef CONFIG_XEN_PV +xen_elfnote_entry_offset =3D + ABSOLUTE(xen_elfnote_entry) + ABSOLUTE(startup_xen); +xen_elfnote_hypercall_page_offset =3D + ABSOLUTE(xen_elfnote_hypercall_page) + ABSOLUTE(hypercall_page); +#endif + +#ifdef CONFIG_PVH +xen_elfnote_phys32_entry_offset =3D + ABSOLUTE(xen_elfnote_phys32_entry) + ABSOLUTE(pvh_start_xen - LOAD_OFFSET= ); +#endif diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 592747f2d731..e2ab4c74f596 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -52,7 +52,7 @@ #define PVH_CS_SEL (PVH_GDT_ENTRY_CS * 8) #define PVH_DS_SEL (PVH_GDT_ENTRY_DS * 8) =20 -SYM_CODE_START_LOCAL(pvh_start_xen) +SYM_CODE_START(pvh_start_xen) UNWIND_HINT_END_OF_STACK cld =20 @@ -299,5 +299,5 @@ SYM_DATA_END(pvh_level2_kernel_pgt) .long KERNEL_IMAGE_SIZE - 1) #endif =20 - ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, - _ASM_PTR (pvh_start_xen - __START_KERNEL_map)) + ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .global xen_elfnote_phys32_entry; + xen_elfnote_phys32_entry: .long xen_elfnote_phys32_entry_offset - .) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index c101bed61940..3ede19ca8432 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -56,6 +56,7 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = =3D { [S_ABS] =3D "^(xen_irq_disable_direct_reloc$|" "xen_save_fl_direct_reloc$|" + "xen_elfnote_.+_offset$|" "VDSO|" "__kcfi_typeid_|" "__crc_)", diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index 758bcd47b72d..3deaae3601f7 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -94,7 +94,8 @@ SYM_CODE_END(xen_cpu_bringup_again) ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE, _ASM_PTR __START_KERNEL_map) /* Map the p2m table to a 512GB-aligned user address. */ ELFNOTE(Xen, XEN_ELFNOTE_INIT_P2M, .quad (PUD_SIZE * PTRS_PER_PUD)) - ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, _ASM_PTR startup_xen) + ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, .globl xen_elfnote_entry; + xen_elfnote_entry: _ASM_PTR xen_elfnote_entry_offset - .) ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .ascii "!writable_page_tables") ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz "yes") ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID, @@ -115,7 +116,8 @@ SYM_CODE_END(xen_cpu_bringup_again) #else # define FEATURES_DOM0 0 #endif - ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR hypercall_page) + ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .globl xen_elfnote_hypercall_pag= e; + xen_elfnote_hypercall_page: _ASM_PTR xen_elfnote_hypercall_page_offset -= .) ELFNOTE(Xen, XEN_ELFNOTE_SUPPORTED_FEATURES, .long FEATURES_PV | FEATURES_PVH | FEATURES_DOM0) ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic") --=20 2.46.0.792.g87dc391469-goog From nobody Thu Nov 28 23:40:25 2024 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=google.com ARC-Seal: i=1; a=rsa-sha256; t=1727347347; cv=none; d=zohomail.com; s=zohoarc; b=UqM0s8hA6euy30TKWKSdm97JoaGLN6ONHBsCgOYkn2iJ99aCz2KUrT45JW9awNcp68lg2KvsesaXwUU6OENexNQEtAZuPxpHbcn7pPlAVnFJheYpMct37VgAjlj1N4Y9FzVYrgqbntKry4TntHbKsgMuFtkH0L5PLeFs0C0lDIs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727347347; h=Content-Type: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=GQvQh3ouoZ2SzJYUdvKa6rkKBNpFrAMDmjZmjc8fkmc=; b=PX4zM17HTu29yyo1Chv230Z5mY3hIE6WLOmeSLYHhmk1A9zpQxdUiXKKJ6QSYZ1bXqHTB/GZnWmxU1rr53EhOEe5AeArNkvncz+DxGKF9/qn7B0vdqEiQ0fFpwellU/86mPyHpEJ/2LYjYHD49DCrRpHndCOkKvnIXaq/EsDYxM= 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 1727347347751948.4333476599567; Thu, 26 Sep 2024 03:42:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805307.1216403 (Exim 4.92) (envelope-from ) id 1stlwk-0004xy-4C; Thu, 26 Sep 2024 10:42:06 +0000 Received: by outflank-mailman (output) from mailman id 805307.1216403; Thu, 26 Sep 2024 10:42:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stlwk-0004wz-0P; Thu, 26 Sep 2024 10:42:06 +0000 Received: by outflank-mailman (input) for mailman id 805307; Thu, 26 Sep 2024 10:42:04 +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 1stlwi-0003NZ-K2 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 10:42:04 +0000 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [2607:f8b0:4864:20::114a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f706624b-7bf3-11ef-99a2-01e77a169b0f; Thu, 26 Sep 2024 12:42:03 +0200 (CEST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e2261adfdeso4169447b3.2 for ; Thu, 26 Sep 2024 03:42:02 -0700 (PDT) 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: f706624b-7bf3-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727347322; x=1727952122; darn=lists.xenproject.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GQvQh3ouoZ2SzJYUdvKa6rkKBNpFrAMDmjZmjc8fkmc=; b=ANPjzwKjmGcQLd2kTwoxepe1d9f7J432BKdRXqah5kcqTx6CzWC/WcFeYSUNuk5KM1 YNZib2GxHsdnqKNGDBPHdjgpCWU9twGDMzCwPAeMVgfBPUEmXsmW+CcG3yNNFXMq1NhK /ZK5f5ZwElaTtNlJ7ynlJYdPK5pe7NJ6QdgC1HkiEuQlrHGrvppJUtZZnibsiXibOUd9 ayIfKCXeq9bRy7GQg8UkveU593B97x8zNHWqAMwsKVF5aAxNd+FEY1vZFIq2n8yWH8EQ NnpGzPUrNNCN2w1/Ug9yyL4KrtAI85+Mvg1jYZFf4TZqLYKjTqQjvo2hHtSpCdIVFTwW AH7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727347322; x=1727952122; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GQvQh3ouoZ2SzJYUdvKa6rkKBNpFrAMDmjZmjc8fkmc=; b=Fovv3H3gTcMF6gGkyeuGMLq3K1WDshm2DX7VFYepCq9aNwc4u/Jp01u/88fRqOWMlQ yy3mOpH3RNRILgN5noz5t21W5gB9GpjTG8R2jUqAkZJk/YzgsvcYp4XuJ3i7HSnMH3PJ ZGgllejf3gyQfJvvTkWeRU1tJhl/wUpG1HBu2jFPcU1thie2Wp6c+8oUYayOKEF4V+a2 dnZGGV5av9AugexwgtxLWVnPXbreHMmmZg7SefQtHRjyBQOXwD7k9xu+39SVRBJfC1aH JSVL2o3woLiFVqAXcAqa/Wh1GOcNxnoO65eR6IGzsHnYY3xbzeDMnrbljZ8Zzbcu9OfE gOFw== X-Forwarded-Encrypted: i=1; AJvYcCVgR4OB+DsZ+pBb/vvzNvFwOW4BRwRLhrLz1pNpraYqtJl2Rv7ea32KFNftO5z1ZhqNr2PZKc8eeLE=@lists.xenproject.org X-Gm-Message-State: AOJu0Yy01+qLWjnqsNG99fTyyHkzh7f00AOlDHd05gD4gC7jFH4hlakH SpvPKkxzYlx+9QMek2ZrqICGkG+731wFYz8gUOnBrr+dbooef3g959Sm+hWruBrrroYt/A== X-Google-Smtp-Source: AGHT+IED/HqLFtACdNSCzdIAMjiljzdhHUspe8O6E5X9FAgkcVHwbKoR9oANRkary8b012uJsnNNw6L8 X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:f90:b0:6c1:298e:5a7 with SMTP id 00721157ae682-6e21d9f2676mr435227b3.5.1727347321787; Thu, 26 Sep 2024 03:42:01 -0700 (PDT) Date: Thu, 26 Sep 2024 12:41:19 +0200 In-Reply-To: <20240926104113.80146-7-ardb+git@google.com> Mime-Version: 1.0 References: <20240926104113.80146-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3415; i=ardb@kernel.org; h=from:subject; bh=x+U+qNnjscbrHmx6YcgJLNHMT4vROYkFANObHeQgRKE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIe2rVaBDx855y79etX3zniOruepu3tutT/4kaaac3H/9q VdHYvucjlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRJfGMDLPeRdoFyOhyOd2c ffqUd8zxMz2p+foPmpSu3uKavKRtKQ8jw34thinbRFa/qD6buU/y9AuTvefMZK90ymw9clHjOvd cYw4A X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240926104113.80146-12-ardb+git@google.com> Subject: [PATCH 5/5] x86/pvh: Avoid absolute symbol references in .head.text From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Jason Andryuk , Juergen Gross , Boris Ostrovsky , x86@kernel.org, xen-devel@lists.xenproject.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1727347348960116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The .head.text section contains code that may execute from a different address than it was linked at. This is fragile, given that the x86 ABI can refer to global symbols via absolute or relative references, and the toolchain assumes that these are interchangeable, which they are not in this particular case. For this reason, all absolute symbol references are being removed from code that is emitted into .head.text. Subsequently, build time validation may be added that ensures that no absolute ELF relocations exist at all in that ELF section. In the case of the PVH code, the absolute references are in 32-bit code, which get emitted with R_X86_64_32 relocations, and these are even more problematic going forward, as it prevents running the linker in PIE mode. So update the 64-bit code to avoid _pa(), and to only rely on relative symbol references: these are always 32-bits wide, even in 64-bit code, and are resolved by the linker at build time. Signed-off-by: Ard Biesheuvel Reviewed-by: Jason Andryuk Tested-by: Jason Andryuk --- arch/x86/platform/pvh/head.S | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index e2ab4c74f596..b2742259ed60 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -6,7 +6,9 @@ =20 .code32 .text +#ifdef CONFIG_X86_32 #define _pa(x) ((x) - __START_KERNEL_map) +#endif #define rva(x) ((x) - pvh_start_xen) =20 #include @@ -72,8 +74,7 @@ SYM_CODE_START(pvh_start_xen) movl $0, %esp =20 leal rva(gdt)(%ebp), %eax - leal rva(gdt_start)(%ebp), %ecx - movl %ecx, 2(%eax) + addl %eax, 2(%eax) lgdt (%eax) =20 mov $PVH_DS_SEL,%eax @@ -103,10 +104,23 @@ SYM_CODE_START(pvh_start_xen) btsl $_EFER_LME, %eax wrmsr =20 + /* + * Reuse the non-relocatable symbol emitted for the ELF note to + * subtract the build time physical address of pvh_start_xen() from + * its actual runtime address, without relying on absolute 32-bit ELF + * relocations, as these are not supported by the linker when running + * in -pie mode, and should be avoided in .head.text in general. + */ mov %ebp, %ebx - subl $_pa(pvh_start_xen), %ebx /* offset */ + subl rva(xen_elfnote_phys32_entry)(%ebp), %ebx jz .Lpagetable_done =20 + /* + * Store the resulting load offset in phys_base. __pa() needs + * phys_base set to calculate the hypercall page in xen_pvh_init(). + */ + movl %ebx, rva(phys_base)(%ebp) + /* Fixup page-tables for relocation. */ leal rva(pvh_init_top_pgt)(%ebp), %edi movl $PTRS_PER_PGD, %ecx @@ -165,14 +179,6 @@ SYM_CODE_START(pvh_start_xen) xor %edx, %edx wrmsr =20 - /* - * Calculate load offset and store in phys_base. __pa() needs - * phys_base set to calculate the hypercall page in xen_pvh_init(). - */ - movq %rbp, %rbx - subq $_pa(pvh_start_xen), %rbx - movq %rbx, phys_base(%rip) - /* Call xen_prepare_pvh() via the kernel virtual mapping */ leaq xen_prepare_pvh(%rip), %rax addq $__START_KERNEL_map, %rax @@ -217,7 +223,7 @@ SYM_CODE_END(pvh_start_xen) .balign 8 SYM_DATA_START_LOCAL(gdt) .word gdt_end - gdt_start - 1 - .long _pa(gdt_start) /* x86-64 will overwrite if relocated. */ + .long gdt_start - gdt .word 0 SYM_DATA_END(gdt) SYM_DATA_START_LOCAL(gdt_start) --=20 2.46.0.792.g87dc391469-goog