Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp77430rdb; Mon, 15 Jan 2024 12:47:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IF58116B5+v15/7XKtiUq5yA9QgPX9PVChlx/hQHgsoTAhzTH+3ae+4jLaHmZ9JafrsYtvs X-Received: by 2002:a05:6512:490:b0:50e:7be8:4704 with SMTP id v16-20020a056512049000b0050e7be84704mr2385537lfq.81.1705351663617; Mon, 15 Jan 2024 12:47:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705351663; cv=none; d=google.com; s=arc-20160816; b=BGnDdjfON7vjpfksz6w/YLa/FeL38RNTLVHVyaiQnbJBYToAvtx9ZEqkWmU0W1JiER mzLEjc1WgzpH0/5LhWjgjqOj5G3lfHleVQovoXp6HEgTgNadt81TkajJFumQc9Px8dXR pcpOzB/PL0t2UPCj+CzJZweC87kMu367cd4t5xuzjSZbbbNDqWfWZsZz+BvNZYGgCXLZ 4/q6g/uhr+G8CE4casrJFMd5dwlTb8mb6sYHKWn5HkRUgtgbPM611WygziMi2FBtrSat atuW6DZrxRUUpG83pGDOVd5gt0kSWB/Bv7G3Irs4/9plSipXm1s6Tn8Ydq/p+TUasebf xxBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=TVY6gJjvwhH/ULoloQ3TbejbwKrrbUPZG3A9u663HrE=; fh=6nNrzpmlEPgbX36dzLF1sv/9Q/dUHTbeCsqOLXtHOIg=; b=rFlGpi6ofycibenPocT3vxhTRuyrjOpQSmL/LNmNTbAXBzvHM5b6TV8pMInsd28B0x 3srkBpEEjfK3+OJG2ZfhoQufRlvXed3PZtVLmqCbLWSJb582dc+QuE9ZC32a955Bw0QJ xbzjFEYen8t3hPS7LmX/UjDOXgLtvndnqH4y5lV+KiA7R7OApK9+T9LXGlizc307hJrO sa7wEa7/G5Q51dW8ee/1Cs3RkHKxX9f8wcCTUr+VK7nzUjqTRDM4EI3/urnekNXW2cIX lsZTeJkZqBwTNR7eR4pWXI9M8xroPr7wY1423t7jT+TO+H/V2qZSsarTMl2KkEvbvH5G GtKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=NPa52H9b; spf=pass (google.com: domain of linux-kernel+bounces-26491-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26491-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v1-20020a170906180100b00a232a3191f0si4026918eje.254.2024.01.15.12.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 12:47:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26491-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=NPa52H9b; spf=pass (google.com: domain of linux-kernel+bounces-26491-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26491-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4936A1F22B05 for ; Mon, 15 Jan 2024 20:47:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55D531AACF; Mon, 15 Jan 2024 20:47:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="NPa52H9b" Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70AC21AABC for ; Mon, 15 Jan 2024 20:47:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 73AC340E01A9; Mon, 15 Jan 2024 20:47:27 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 77EnVeJyFhvV; Mon, 15 Jan 2024 20:47:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1705351644; bh=TVY6gJjvwhH/ULoloQ3TbejbwKrrbUPZG3A9u663HrE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NPa52H9blg3O9/d3LIMQfpSI254TJ0oH0cn6fSs+PMNoEPW+JBScuwIbCANvQtWPZ d0TPqza/v03p28MZEreBcavm/Dap4GYCAxhR1JyxeZsY2OG2fH6RVrnDK7/yueY8Ej Kq2rMt+SIC5IepyaULUnFehPhS2gK1kayp7bjwwAzoXWbHiedI+qiJjVPqWlDDC4mZ iuYgZPxrvnMpHPz0NOCeknpar+ic/3am6JID36WBLZor8Fg0QHJ/OxNsYdlqeiTeqC ANHX4nBYzWgU/iKFIfvFC3b/yDMLQA8By1Q7NXRFmrUDcdDzUFXUD/KBAOg2k25xlg 71YhlGXei1O2rA+tyW9iDWwkQ1fGM6IVwGeHWY3qBAOe23/R0yC15hOma2uh7czaFl 3NdQfX/GpY3YNCaqaXK/i7FMbAVJp86nIZ/PO9BU++Gtdx56yFY71WP2jFojKLub0b MCFSSMgT2dy3GLiTHlTShJosK5YoFOQtFRdeYkcTmBzrVNyKeqw5rG9x5TgmCIIAsF ONwwNbAw2vCnkm21Rn5f86JfYFg0OmpBLnQb2bdiATFkZPF3PysuxuATHh225Md5Uk JaqzciAiZfybjjKmWIZ7k189MO59dGbJjD2kC0del34fGTRtdFj7m+vNFqHZR5bFXv ACaC98vfCf8np1xbnkp0mqvg= Received: from zn.tnic (pd9530f8c.dip0.t-ipconnect.de [217.83.15.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id DC5B740E00C5; Mon, 15 Jan 2024 20:46:39 +0000 (UTC) Date: Mon, 15 Jan 2024 21:46:34 +0100 From: Borislav Petkov To: Kevin Loughlin Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Tom Lendacky , Michael Kelley , Pankaj Gupta , Stephen Rothwell , Arnd Bergmann , Steve Rutherford , Alexander Shishkin , Hou Wenlong , Vegard Nossum , Josh Poimboeuf , Yuntao Wang , Wang Jinchao , David Woodhouse , Brian Gerst , Hugh Dickins , Ard Biesheuvel , Joerg Roedel , Randy Dunlap , Bjorn Helgaas , Dionna Glaze , Brijesh Singh , Michael Roth , "Kirill A. Shutemov" , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-coco@lists.linux.dev, Ashish Kalra , Andi Kleen , Adam Dunlap , Peter Gonda , Jacob Xu , Sidharth Telang Subject: Re: [RFC PATCH v2] x86/sev: enforce RIP-relative accesses in early SEV/SME code Message-ID: <20240115204634.GHZaWZqsVyU_fvn_RW@fat_crate.local> References: <20240111223650.3502633-1-kevinloughlin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240111223650.3502633-1-kevinloughlin@google.com> On Thu, Jan 11, 2024 at 10:36:50PM +0000, Kevin Loughlin wrote: > SEV/SME code can execute prior to page table fixups for kernel > relocation. However, as with global variables accessed in > __startup_64(), the compiler is not required to generate RIP-relative > accesses for SEV/SME global variables, causing certain flavors of SEV > hosts and guests built with clang to crash during boot. So, about that. If I understand my gcc toolchain folks correctly: mcmodel=kernel - everything fits into the high 31 bit of the address space -fPIE/PIC - position independent And supplied both don't make a whole lotta of sense: if you're building position-independent, then mcmodel=kernel would be overridden by the first. I have no clue why clang enabled it... So, *actually* the proper fix here should be not to add this "fixed_up" gunk everywhere but remove mcmodel=kernel from the build and simply do -fPIE/PIC. I'd say... I could also be missing something obvious ofc. > Fixes: 95d33bfaa3e1 ("x86/sev: Register GHCB memory when SEV-SNP is active") > Fixes: ee0bfa08a345 ("x86/compressed/64: Add support for SEV-SNP CPUID table in #VC handlers") > Fixes: 1cd9c22fee3a ("x86/mm/encrypt: Move page table helpers into separate translation unit") > Fixes: c9f09539e16e ("x86/head/64: Check SEV encryption before switching to kernel page-table") > Fixes: b577f542f93c ("x86/coco: Add API to handle encryption mask") > Tested-by: Kevin Loughlin You don't need to add your Tested-by tag - it is kinda assumed that people submit patches *after* testing them. Although I have a gazillion examples where that is not the case... :-\ > Signed-off-by: Kevin Loughlin -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette