From patchwork Thu Jan 25 11:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 192040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1580315dyi; Thu, 25 Jan 2024 03:50:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5SSviNt3fTEuRGuWn03xrB74xKeUQBTMbaymTqAAj3DQfC9vZjKBqIgwAhFKMx07emk1y X-Received: by 2002:a17:902:d891:b0:1d4:b50d:dba9 with SMTP id b17-20020a170902d89100b001d4b50ddba9mr886224plz.71.1706183424162; Thu, 25 Jan 2024 03:50:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706183424; cv=pass; d=google.com; s=arc-20160816; b=EuM5TWmZhaqr44obOlkZ0dhbqMjod1oKpBPIhA5gA+79cyiIlJOmikPmQce9P/S3ZM N3JDctTqpnzm/lsQf/QelVxr6u3lryEQEq4jFQumcynphi4yrBls1FnRl/jGYx46dOB/ 4jcpOTbd+QHfVNLVFSvqW/maT4tD9q6kBkGz0PcVzR239QqHfWRI4pe8Pkmky6ycjgM3 SmTUmZycijxKh2fa1ZpZDCXp3vBCsQNq++QfzQ5FRL+ZCR6pr8M8a8rNNl1/Fn6ujVzb lZlx9JKj0xrT/Oq0akm1kxmIRwv3ifRggnehgLi1hS0qukPoou8bZ6R3J7SfWRX2HWWn BkpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=hBUWnFeDK9kwJnQ8v39o1YEuf+vNzkyqOxxuFopn5io=; fh=Mjd69IxHltS/Jba8SYEPy4aDMrScq2KBDxG2XjETtWk=; b=osBrI23Tbyup8VVThDUky5GyXXfLDNsbZDbZ0EULKJRf1xqQgmldwl/+oPItbNQ77b ug4tVNfqghqkGTZ5uYba1S/GvCSYATLvN+wiyulqc5OzYWwNmStZh3EPsoBWhmgHQ66m dBwIAiF9DcfqFkqgXiMW7VmsGX+R9DOVT12070cFNGXKXLMe2QvtCldon5vp7LDKJOu8 lAWfB/0Q+5rI43L9fOTInGbdicORdFrEuiBEdmJcI/rCTXfztZPui1eCvtU52o6iwsWa ftD+5rXspdeYyhXN6qk5la1r1RiYyp4JTvzaQskjAKTfMxVBbXb1RlW5xwEOyqK0b4Z5 8kOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DfgQR618; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-38520-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38520-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d13-20020a170903230d00b001d7166e8ef9si12119277plh.226.2024.01.25.03.50.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 03:50:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38520-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DfgQR618; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-38520-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38520-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 224BB287A87 for ; Thu, 25 Jan 2024 11:37:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E80315A783; Thu, 25 Jan 2024 11:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DfgQR618" Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F414C59156 for ; Thu, 25 Jan 2024 11:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706182397; cv=none; b=gS6RiDKUz4kZLcGsqKTuJcRX5ENiItf+bsvuOlHw9N4aOnRdv92XvHibIkTl4H6g1g8xKVpUXOw2OqS2vHoceb7IADn324XSUY+dKyGOE0DgmVpjqo5BRXJVEcrcUMG1imE9epJZHkbUwtVBloC8urhIjbw+vD8j0l/NM1lBuAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706182397; c=relaxed/simple; bh=P7SsUUZGFAoKRtQbrSSh80tauvm72OXVWNmZkHlq190=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Lg+rBeUFc59EwFDrez6qOwf5xulcJz6ipilQBf/PWvd1fuPrgji14KJdqu+vG0Lrj4GFFjmG5KQVpdq2rtOkgdFGCT9vdhoswnRiiBuZ9PPp8B9faM0MINdhiaXGKRa25WUy//fQXHD9sK6r8vKzKiH2lQWcSeL+G9ttDkfiCz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DfgQR618; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-40ed389a4dbso1313125e9.2 for ; Thu, 25 Jan 2024 03:33:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706182394; x=1706787194; darn=vger.kernel.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=hBUWnFeDK9kwJnQ8v39o1YEuf+vNzkyqOxxuFopn5io=; b=DfgQR618KVP9F9t3DuWRIAiCRRXQtg1odKkiO4gDT2Hl4pmtnL61E9g23dXvk/J7GD Fvttl5fiRd3KxTQfFUfxj9cg1SJiHjtAbs7KeQze4TuSh8qgPA6F0PE0C6iebjLC1X7t 59tl16FCWi3q3+cx4ac/TsRvYibARXRoID3HYC7Mw1999UKU+ChySSOkGyYr6AfCvOPe HZvxUT8j1g74HITP9jzfyMFt5YgNIGRZIMV1Pwj4Q9Ql08+1Jj/v0KcyrOZxPA5b9D8K EMBkr3nXE5XFMwI2esO8UcJGagZFId07+nOsaIXSPfhIJKsaIxjEDLjRdy3YpSQxPprJ FZYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706182394; x=1706787194; 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=hBUWnFeDK9kwJnQ8v39o1YEuf+vNzkyqOxxuFopn5io=; b=j+2OjXxFGkLiqxmXfMBSP79BPGEK78yf/6m7FaSgwo5yTrff/ZmBMDbxKyrFRwJhvC 4VfCxpTKmH9Ssz8QWnyCCw2FqLps17+cqZ5YUti+yCiIczv9qeIGO0g5THO4vZ0qjH4I xH09PJlFKf4XHP19yc4y+E0xm0KCGc9sXRdxq3fRLxsmkNLax3y0xW4IoJMi7MUzqviO TLmCx3ZpS2FDjeJZnd1WSTjbvgAIFP1l+i7CCg3zKJcTO8NcxyUKF+xTOh0aNF+Kgdye zXjsJ+TMkomtokAvsXoxiuNZuIglKKIqzAV571Qm6apeO6dq9O72WUmyzQeE0KG3aIg9 d20Q== X-Gm-Message-State: AOJu0YylXfiUxdiCkn5wIxzevtBwc9Zq2N0h4bMSZ7Ds+Ov3BBb1BfFz CPeijEKhKcuDAZ1HIJ7BWqwzLDzAo/RrO4FfUCShnTlql1zvFP97c8sykVs28LZOA90ZAxi0b2T swQWvqJHFiMShTfVg4ewdmjSs10b9w7c7TwoQQz0agdttX4+xVEebG3GDfSNNf0H2HGbbvqt8Zr dqdqilBo20QGBQ597w82xjw+rJzLpjMA== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:1e03:b0:40e:d31f:4cf8 with SMTP id ay3-20020a05600c1e0300b0040ed31f4cf8mr16460wmb.3.1706182394116; Thu, 25 Jan 2024 03:33:14 -0800 (PST) Date: Thu, 25 Jan 2024 12:28:35 +0100 In-Reply-To: <20240125112818.2016733-19-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240125112818.2016733-19-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3710; i=ardb@kernel.org; h=from:subject; bh=JT1olNiwpLiAazvRYxL/s0mN0D+4v2kwCKTsMENT5/8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWTG5Om96fFG3IbTStkj79Symr2m+K3+H2fZ6N1zjRVN wPZNXs7SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQ2VjP893miFvbly6s19kvZ X+/6Hxq4oTuqS/Xx3b/1m3/WqujxPGf4p6Slc1LTL3iz04Wers3bufROzWqd1m7CrXkmqbRDa1c LMwA= X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240125112818.2016733-35-ardb+git@google.com> Subject: [PATCH v2 16/17] x86/sev: Drop inline asm LEA instructions for RIP-relative references From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Justin Stitt , Brian Gerst , linux-arch@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789062990014925475 X-GMAIL-MSGID: 1789062990014925475 From: Ard Biesheuvel The SEV code that may run early is now built with -fPIC and so there is no longer a need for explicit RIP-relative references in inline asm, given that is what the compiler will emit as well. Signed-off-by: Ard Biesheuvel --- arch/x86/mm/mem_encrypt_identity.c | 37 +++----------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index 20b23da4a26d..2d857e3a560a 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -86,10 +86,6 @@ struct sme_populate_pgd_data { */ static char sme_workarea[2 * PMD_SIZE] __section(".init.scratch"); -static char sme_cmdline_arg[] __initdata = "mem_encrypt"; -static char sme_cmdline_on[] __initdata = "on"; -static char sme_cmdline_off[] __initdata = "off"; - static void __pitext sme_clear_pgd(struct sme_populate_pgd_data *ppd) { unsigned long pgd_start, pgd_end, pgd_size; @@ -333,14 +329,6 @@ void __pitext sme_encrypt_kernel(struct boot_params *bp) } #endif - /* - * We're running identity mapped, so we must obtain the address to the - * SME encryption workarea using rip-relative addressing. - */ - asm ("lea sme_workarea(%%rip), %0" - : "=r" (workarea_start) - : "p" (sme_workarea)); - /* * Calculate required number of workarea bytes needed: * executable encryption area size: @@ -350,7 +338,7 @@ void __pitext sme_encrypt_kernel(struct boot_params *bp) * pagetable structures for the encryption of the kernel * pagetable structures for workarea (in case not currently mapped) */ - execute_start = workarea_start; + execute_start = workarea_start = (unsigned long)sme_workarea; execute_end = execute_start + (PAGE_SIZE * 2) + PMD_SIZE; execute_len = execute_end - execute_start; @@ -517,9 +505,9 @@ static int __pitext __strncmp(const char *cs, const char *ct, size_t count) void __pitext sme_enable(struct boot_params *bp) { - const char *cmdline_ptr, *cmdline_arg, *cmdline_on, *cmdline_off; unsigned int eax, ebx, ecx, edx; unsigned long feature_mask; + const char *cmdline_ptr; bool active_by_default; unsigned long me_mask; char buffer[16]; @@ -590,21 +578,6 @@ void __pitext sme_enable(struct boot_params *bp) goto out; } - /* - * Fixups have not been applied to phys_base yet and we're running - * identity mapped, so we must obtain the address to the SME command - * line argument data using rip-relative addressing. - */ - asm ("lea sme_cmdline_arg(%%rip), %0" - : "=r" (cmdline_arg) - : "p" (sme_cmdline_arg)); - asm ("lea sme_cmdline_on(%%rip), %0" - : "=r" (cmdline_on) - : "p" (sme_cmdline_on)); - asm ("lea sme_cmdline_off(%%rip), %0" - : "=r" (cmdline_off) - : "p" (sme_cmdline_off)); - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT)) active_by_default = true; else @@ -613,12 +586,12 @@ void __pitext sme_enable(struct boot_params *bp) cmdline_ptr = (const char *)((u64)bp->hdr.cmd_line_ptr | ((u64)bp->ext_cmd_line_ptr << 32)); - if (cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)) < 0) + if (cmdline_find_option(cmdline_ptr, "mem_encrypt", buffer, sizeof(buffer)) < 0) return; - if (!__strncmp(buffer, cmdline_on, sizeof(buffer))) + if (!__strncmp(buffer, "on", sizeof(buffer))) sme_me_mask = me_mask; - else if (!__strncmp(buffer, cmdline_off, sizeof(buffer))) + else if (!__strncmp(buffer, "off", sizeof(buffer))) sme_me_mask = 0; else sme_me_mask = active_by_default ? me_mask : 0;